[Mesa-dev] [PATCH 4/6] st/mesa: re-arrange st_finalize_texture

Nicolai Hähnle nhaehnle at gmail.com
Fri Oct 6 20:38:14 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Move the early-out for surface-based textures earlier. This narrows the
scope of the locking added in a follow-up commit.

Fix one remaining case of initializing a surface-based texture
without properly finalizing it.
---
 src/mesa/state_tracker/st_cb_texture.c | 16 ++++++++--------
 src/mesa/state_tracker/st_manager.c    |  3 +++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index bac2a0289f5..6d9e40baa95 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -2465,50 +2465,50 @@ st_finalize_texture(struct gl_context *ctx,
        * incomplete.  In that case, we'll have set stObj->lastLevel before
        * we get here.
        */
       if (stObj->base.Sampler.MinFilter == GL_LINEAR ||
           stObj->base.Sampler.MinFilter == GL_NEAREST)
          stObj->lastLevel = stObj->base.BaseLevel;
       else
          stObj->lastLevel = stObj->base._MaxLevel;
    }
 
-   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 this texture comes from a window system, there is nothing else to do. */
+   if (stObj->surface_based) {
+      return GL_TRUE;
+   }
+
+   firstImage = st_texture_image_const(stObj->base.Image[cubeMapFace][stObj->base.BaseLevel]);
+   assert(firstImage);
+
    /* 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
     * will match.
     */
    if (firstImage->pt &&
        firstImage->pt != stObj->pt &&
        (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
       pipe_resource_reference(&stObj->pt, firstImage->pt);
       st_texture_release_all_sampler_views(st, stObj);
    }
 
-   /* If this texture comes from a window system, there is nothing else to do. */
-   if (stObj->surface_based) {
-      return GL_TRUE;
-   }
-
    /* Find gallium format for the Mesa texture */
    firstImageFormat =
       st_mesa_format_to_pipe_format(st, firstImage->base.TexFormat);
 
    /* Find size of level=0 Gallium mipmap image, plus number of texture layers */
    {
       unsigned width;
       uint16_t height, depth;
 
       st_gl_texture_dims_to_pipe_dims(stObj->base.Target,
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index 50bc3c33c62..c0baa4f06c2 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -41,20 +41,21 @@
 #include "util/hash_table.h"
 #include "st_texture.h"
 
 #include "st_context.h"
 #include "st_debug.h"
 #include "st_extensions.h"
 #include "st_format.h"
 #include "st_cb_fbo.h"
 #include "st_cb_flush.h"
 #include "st_manager.h"
+#include "st_sampler_view.h"
 
 #include "state_tracker/st_gl_api.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_screen.h"
 #include "util/u_format.h"
 #include "util/u_pointer.h"
 #include "util/u_inlines.h"
 #include "util/u_atomic.h"
 #include "util/u_surface.h"
@@ -725,20 +726,22 @@ st_context_teximage(struct st_context_iface *stctxi,
          if (depth != 1)
             depth <<= 1;
          level--;
       }
    }
    else {
       _mesa_clear_texture_image(ctx, texImage);
       width = height = depth = 0;
    }
 
+   pipe_resource_reference(&stObj->pt, tex);
+   st_texture_release_all_sampler_views(st, stObj);
    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);
 
    return TRUE;
 }
-- 
2.11.0



More information about the mesa-dev mailing list