OSDN Git Service

st/mesa: skip texture validation logic when nothing has changed
authorTimothy Arceri <tarceri@itsqueeze.com>
Sat, 10 Jun 2017 04:52:46 +0000 (14:52 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 13 Jun 2017 01:24:32 +0000 (11:24 +1000)
Based on the same logic in the i965 driver 2f225f61451abd51 and
16060c5adcd4.

perf reports st_finalize_texture() going from 0.60% -> 0.16% with
this change when running the Xonotic benchmark from PTS.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_manager.c
src/mesa/state_tracker/st_texture.h

index 99c59f7..443bb7b 100644 (file)
@@ -154,6 +154,8 @@ st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
    DBG("%s\n", __func__);
    _mesa_initialize_texture_object(ctx, &obj->base, name, target);
 
+   obj->needs_validation = true;
+
    return &obj->base;
 }
 
@@ -606,6 +608,8 @@ st_AllocTextureImageBuffer(struct gl_context *ctx,
 
    assert(!stImage->pt); /* xxx this might be wrong */
 
+   stObj->needs_validation = true;
+
    etc_fallback_allocate(st, stImage);
 
    /* Look if the parent texture object has space for this image */
@@ -2485,6 +2489,16 @@ st_finalize_texture(struct gl_context *ctx,
    firstImage = st_texture_image_const(stObj->base.Image[cubeMapFace][stObj->base.BaseLevel]);
    assert(firstImage);
 
+   /* Skip the loop over images in the common case of no images having
+    * changed.  But if the GL_BASE_LEVEL or GL_MAX_LEVEL change to something we
+    * haven't looked at, then we do need to look at those new images.
+    */
+   if (!stObj->needs_validation &&
+       stObj->base.BaseLevel >= stObj->validated_first_level &&
+       stObj->lastLevel <= stObj->validated_last_level) {
+      return GL_TRUE;
+   }
+
    /* If both firstImage and stObj point to a texture which can contain
     * all active images, favour firstImage.  Note that because of the
     * completeness requirement, we know that the image dimensions
@@ -2631,6 +2645,10 @@ st_finalize_texture(struct gl_context *ctx,
       }
    }
 
+   stObj->validated_first_level = stObj->base.BaseLevel;
+   stObj->validated_last_level = stObj->lastLevel;
+   stObj->needs_validation = false;
+
    return GL_TRUE;
 }
 
@@ -2712,6 +2730,11 @@ st_AllocTextureStorage(struct gl_context *ctx,
       }
    }
 
+   /* The texture is in a validated state, so no need to check later. */
+   stObj->needs_validation = false;
+   stObj->validated_first_level = 0;
+   stObj->validated_last_level = levels - 1;
+
    return GL_TRUE;
 }
 
@@ -2810,6 +2833,11 @@ st_TextureView(struct gl_context *ctx,
     */
    st_texture_release_all_sampler_views(st, tex);
 
+   /* The texture is in a validated state, so no need to check later. */
+   tex->needs_validation = false;
+   tex->validated_first_level = 0;
+   tex->validated_last_level = numLevels - 1;
+
    return GL_TRUE;
 }
 
index f4c78ae..085f54e 100644 (file)
@@ -592,6 +592,8 @@ st_context_teximage(struct st_context_iface *stctxi,
    pipe_resource_reference(&stImage->pt, tex);
    stObj->surface_format = pipe_format;
 
+   stObj->needs_validation = true;
+
    _mesa_dirty_texobj(ctx, texObj);
    _mesa_unlock_texture(ctx, texObj);
 
index 1b4d1a3..c02d135 100644 (file)
@@ -84,6 +84,9 @@ struct st_texture_object
     */
    GLuint lastLevel;
 
+   unsigned int validated_first_level;
+   unsigned int validated_last_level;
+
    /* On validation any active images held in main memory or in other
     * textures will be copied to this texture and the old storage freed.
     */
@@ -121,6 +124,12 @@ struct st_texture_object
    unsigned prev_glsl_version;
    /** The value of the sampler's sRGBDecode state at the previous validation */
    GLenum prev_sRGBDecode;
+
+    /**
+     * Set when the texture images of this texture object might not all be in
+     * the pipe_resource *pt above.
+     */
+    bool needs_validation;
 };