[Mesa-dev] [PATCH 21/24] st/mesa: samplers only need to track whether GLSL >= 130

Marek Olšák maraeo at gmail.com
Mon Jun 12 18:18:52 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_atom_texture.c | 16 +++++++++-------
 src/mesa/state_tracker/st_sampler_view.c | 23 ++++++++++++-----------
 src/mesa/state_tracker/st_sampler_view.h |  2 +-
 src/mesa/state_tracker/st_texture.h      |  2 +-
 4 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index f696f0e..9d2564f 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -48,21 +48,21 @@
 #include "st_cb_texture.h"
 #include "pipe/p_context.h"
 #include "util/u_format.h"
 #include "util/u_inlines.h"
 #include "cso_cache/cso_context.h"
 
 
 static void
 update_single_texture(struct st_context *st,
                       struct pipe_sampler_view **sampler_view,
-		      GLuint texUnit, unsigned glsl_version)
+		      GLuint texUnit, bool glsl130_or_later)
 {
    struct gl_context *ctx = st->ctx;
    const struct gl_sampler_object *samp;
    struct gl_texture_object *texObj;
    struct st_texture_object *stObj;
    GLboolean retval;
 
    samp = _mesa_get_samplerobj(ctx, texUnit);
 
    texObj = ctx->Texture.Unit[texUnit]._Current;
@@ -78,35 +78,36 @@ update_single_texture(struct st_context *st,
    retval = st_finalize_texture(ctx, st->pipe, texObj, 0);
    if (!retval) {
       /* out of mem */
       *sampler_view = NULL;
       return;
    }
 
    /* Check a few pieces of state outside the texture object to see if we
     * need to force revalidation.
     */
-   if (stObj->prev_glsl_version != glsl_version ||
+   if (stObj->prev_glsl130_or_later != glsl130_or_later ||
        stObj->prev_sRGBDecode != samp->sRGBDecode) {
 
       st_texture_release_all_sampler_views(st, stObj);
 
-      stObj->prev_glsl_version = glsl_version;
+      stObj->prev_glsl130_or_later = glsl130_or_later;
       stObj->prev_sRGBDecode = samp->sRGBDecode;
    }
 
    if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
        stObj->pt->screen->resource_changed)
          stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
 
    *sampler_view =
-      st_get_texture_sampler_view_from_stobj(st, stObj, samp, glsl_version);
+      st_get_texture_sampler_view_from_stobj(st, stObj, samp,
+                                             glsl130_or_later);
 }
 
 
 
 static void
 update_textures(struct st_context *st,
                 enum pipe_shader_type shader_stage,
                 const struct gl_program *prog,
                 struct pipe_sampler_view **sampler_views,
                 unsigned *out_num_textures)
@@ -115,31 +116,32 @@ update_textures(struct st_context *st,
    GLbitfield samplers_used = prog->SamplersUsed;
    GLbitfield free_slots = ~prog->SamplersUsed;
    GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
    GLuint unit;
 
    if (samplers_used == 0x0 && old_max == 0)
       return;
 
    unsigned num_textures = 0;
 
+   /* prog->sh.data is NULL if it's ARB_fragment_program */
+   bool glsl130 = (prog->sh.data ? prog->sh.data->Version : 0) >= 130;
+
    /* loop over sampler units (aka tex image units) */
    for (unit = 0; samplers_used || unit < old_max;
         unit++, samplers_used >>= 1) {
       struct pipe_sampler_view *sampler_view = NULL;
 
       if (samplers_used & 1) {
-         /* prog->sh.data is NULL if it's ARB_fragment_program */
-         unsigned glsl_version = prog->sh.data ? prog->sh.data->Version : 0;
          const GLuint texUnit = prog->SamplerUnits[unit];
 
-         update_single_texture(st, &sampler_view, texUnit, glsl_version);
+         update_single_texture(st, &sampler_view, texUnit, glsl130);
          num_textures = unit + 1;
       }
 
       pipe_sampler_view_reference(&(sampler_views[unit]), sampler_view);
    }
 
    /* For any external samplers with multiplaner YUV, stuff the additional
     * sampler views we need at the end.
     *
     * Trying to cache the sampler view in the stObj looks painful, so just
diff --git a/src/mesa/state_tracker/st_sampler_view.c b/src/mesa/state_tracker/st_sampler_view.c
index e8a46a72..7a6993e 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -183,21 +183,21 @@ swizzle_swizzle(unsigned swizzle1, unsigned swizzle2)
  *
  * In the case of depth textures, the GL_DEPTH_MODE state determines the
  * texture swizzle.
  *
  * This result must be composed with the user-specified swizzle to get
  * the final swizzle.
  */
 static unsigned
 compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
                                enum pipe_format actualFormat,
-                               unsigned glsl_version)
+                               bool glsl130_or_later)
 {
    switch (baseFormat) {
    case GL_RGBA:
       return SWIZZLE_XYZW;
    case GL_RGB:
       if (util_format_has_alpha(actualFormat))
          return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
       else
          return SWIZZLE_XYZW;
    case GL_RG:
@@ -250,21 +250,21 @@ compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
           * them to return 0, breaking them completely.
           *
           * A proper fix would increase code complexity and that's not worth
           * it for a rarely used feature such as the GL_ALPHA depth mode
           * in GL3. Therefore, change GL_ALPHA to GL_INTENSITY for all
           * shaders that use GLSL 1.30 or later.
           *
           * BTW, it's required that sampler views are updated when
           * shaders change (check_sampler_swizzle takes care of that).
           */
-         if (glsl_version && glsl_version >= 130)
+         if (glsl130_or_later)
             return SWIZZLE_XXXX;
          else
             return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
                                  SWIZZLE_ZERO, SWIZZLE_X);
       case GL_RED:
          return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
                               SWIZZLE_ZERO, SWIZZLE_ONE);
       default:
          assert(!"Unexpected depthMode");
          return SWIZZLE_XYZW;
@@ -272,21 +272,21 @@ compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
    default:
       assert(!"Unexpected baseFormat");
       return SWIZZLE_XYZW;
    }
 }
 
 
 static unsigned
 get_texture_format_swizzle(const struct st_context *st,
                            const struct st_texture_object *stObj,
-                           unsigned glsl_version)
+                           bool glsl130_or_later)
 {
    GLenum baseFormat = _mesa_base_tex_image(&stObj->base)->_BaseFormat;
    unsigned tex_swizzle;
    GLenum depth_mode = stObj->base.DepthMode;
 
    /* In ES 3.0, DEPTH_TEXTURE_MODE is expected to be GL_RED for textures
     * with depth component data specified with a sized internal format.
     */
    if (_mesa_is_gles3(st->ctx) &&
        (baseFormat == GL_DEPTH_COMPONENT ||
@@ -295,39 +295,40 @@ get_texture_format_swizzle(const struct st_context *st,
       const struct gl_texture_image *firstImage =
          _mesa_base_tex_image(&stObj->base);
       if (firstImage->InternalFormat != GL_DEPTH_COMPONENT &&
           firstImage->InternalFormat != GL_DEPTH_STENCIL &&
           firstImage->InternalFormat != GL_STENCIL_INDEX)
          depth_mode = GL_RED;
    }
    tex_swizzle = compute_texture_format_swizzle(baseFormat,
                                                 depth_mode,
                                                 stObj->pt->format,
-                                                glsl_version);
+                                                glsl130_or_later);
 
    /* Combine the texture format swizzle with user's swizzle */
    return swizzle_swizzle(stObj->base._Swizzle, tex_swizzle);
 }
 
 
 /**
  * Return TRUE if the texture's sampler view swizzle is not equal to
  * the texture's swizzle.
  *
  * \param stObj  the st texture object,
  */
 MAYBE_UNUSED static boolean
 check_sampler_swizzle(const struct st_context *st,
                       const struct st_texture_object *stObj,
-		      const struct pipe_sampler_view *sv, unsigned glsl_version)
+                      const struct pipe_sampler_view *sv,
+                      bool glsl130_or_later)
 {
-   unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl_version);
+   unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl130_or_later);
 
    return ((sv->swizzle_r != GET_SWZ(swizzle, 0)) ||
            (sv->swizzle_g != GET_SWZ(swizzle, 1)) ||
            (sv->swizzle_b != GET_SWZ(swizzle, 2)) ||
            (sv->swizzle_a != GET_SWZ(swizzle, 3)));
 }
 
 
 static unsigned
 last_level(const struct st_texture_object *stObj)
@@ -386,24 +387,24 @@ get_sampler_view_format(struct st_context *st,
       break;
    }
    return format;
 }
 
 
 static struct pipe_sampler_view *
 st_create_texture_sampler_view_from_stobj(struct st_context *st,
 					  struct st_texture_object *stObj,
 					  enum pipe_format format,
-                                          unsigned glsl_version)
+                                          bool glsl130_or_later)
 {
    struct pipe_sampler_view templ;
-   unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl_version);
+   unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl130_or_later);
 
    u_sampler_view_default_template(&templ, stObj->pt, format);
 
    templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel;
    templ.u.tex.last_level = last_level(stObj);
    assert(templ.u.tex.first_level <= templ.u.tex.last_level);
    if (stObj->layer_override) {
       templ.u.tex.first_layer = templ.u.tex.last_layer = stObj->layer_override;
    } else {
       templ.u.tex.first_layer = stObj->base.MinLayer;
@@ -418,54 +419,54 @@ st_create_texture_sampler_view_from_stobj(struct st_context *st,
    templ.swizzle_a = GET_SWZ(swizzle, 3);
 
    return st->pipe->create_sampler_view(st->pipe, stObj->pt, &templ);
 }
 
 
 struct pipe_sampler_view *
 st_get_texture_sampler_view_from_stobj(struct st_context *st,
                                        struct st_texture_object *stObj,
                                        const struct gl_sampler_object *samp,
-                                       unsigned glsl_version)
+                                       bool glsl130_or_later)
 {
    struct pipe_sampler_view **sv;
 
    if (!stObj || !stObj->pt) {
       return NULL;
    }
 
    sv = st_texture_get_sampler_view(st, stObj);
 
    if (*sv) {
       /* Debug check: make sure that the sampler view's parameters are
        * what they're supposed to be.
        */
       MAYBE_UNUSED struct pipe_sampler_view *view = *sv;
       assert(stObj->pt == view->texture);
-      assert(!check_sampler_swizzle(st, stObj, view, glsl_version));
+      assert(!check_sampler_swizzle(st, stObj, view, glsl130_or_later));
       assert(get_sampler_view_format(st, stObj, samp) == view->format);
       assert(gl_target_to_pipe(stObj->base.Target) == view->target);
       assert(stObj->base.MinLevel + stObj->base.BaseLevel ==
              view->u.tex.first_level);
       assert(last_level(stObj) == view->u.tex.last_level);
       assert(stObj->layer_override || stObj->base.MinLayer == view->u.tex.first_layer);
       assert(stObj->layer_override || last_layer(stObj) == view->u.tex.last_layer);
       assert(!stObj->layer_override ||
              (stObj->layer_override == view->u.tex.first_layer &&
               stObj->layer_override == view->u.tex.last_layer));
    }
    else {
       /* create new sampler view */
       enum pipe_format format = get_sampler_view_format(st, stObj, samp);
 
       *sv = st_create_texture_sampler_view_from_stobj(st, stObj,
-                                                      format, glsl_version);
+                                                      format, glsl130_or_later);
 
    }
 
    return *sv;
 }
 
 
 struct pipe_sampler_view *
 st_get_buffer_sampler_view_from_stobj(struct st_context *st,
                                       struct st_texture_object *stObj)
diff --git a/src/mesa/state_tracker/st_sampler_view.h b/src/mesa/state_tracker/st_sampler_view.h
index b08ca4a..392206b 100644
--- a/src/mesa/state_tracker/st_sampler_view.h
+++ b/src/mesa/state_tracker/st_sampler_view.h
@@ -66,17 +66,17 @@ st_texture_release_all_sampler_views(struct st_context *st,
                                      struct st_texture_object *stObj);
 
 void
 st_texture_free_sampler_views(struct st_texture_object *stObj);
 
 
 struct pipe_sampler_view *
 st_get_texture_sampler_view_from_stobj(struct st_context *st,
                                        struct st_texture_object *stObj,
                                        const struct gl_sampler_object *samp,
-                                       unsigned glsl_version);
+                                       bool glsl130_or_later);
 
 struct pipe_sampler_view *
 st_get_buffer_sampler_view_from_stobj(struct st_context *st,
                                       struct st_texture_object *stObj);
 
 #endif /* ST_SAMPLER_VIEW_H */
diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h
index 070b593..970f3db 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -114,21 +114,21 @@ struct st_texture_object
    /* When non-zero, samplers should use this layer instead of the one
     * specified by the GL state.
     *
     * This is used for VDPAU interop, where imported pipe_resources may be
     * array textures (containing layers with different fields) even though the
     * GL state describes one non-array texture per field.
     */
    uint layer_override;
 
    /** The glsl version of the shader seen during the previous validation */
-   unsigned prev_glsl_version;
+   bool prev_glsl130_or_later;
    /** 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 the
      * pipe_resource *pt above.
      */
     bool needs_validation;
 };
 
-- 
2.7.4



More information about the mesa-dev mailing list