st/glsl_to_tgsi: ignore GL_TEXTURE_SRGB_DECODE_EXT for samplers used with texelFetch*()
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 5 Oct 2017 17:39:33 +0000 (19:39 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 11 Oct 2017 21:16:20 +0000 (23:16 +0200)
See the comment for the relevant spec quote.

Fixes dEQP-GLES31.functional.srgb_texture_decode.skip_decode.srgba8.texel_fetch

v2: note the interaction between ARB_bindless_texture and EXT_texture_sRGB_decode
    as a TODO

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_atom_texture.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_sampler_view.c
src/mesa/state_tracker/st_sampler_view.h
src/mesa/state_tracker/st_texture.c
src/mesa/state_tracker/st_texture.h

index 2802a0e3605bb57da908ab6860ce3d6ae428be2b..8206793de9c7057b77e923a425f33cb923699278 100644 (file)
@@ -2088,6 +2088,7 @@ struct gl_program
    GLbitfield TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];  /**< TEXTURE_x_BIT bitmask */
    GLbitfield SamplersUsed;   /**< Bitfield of which samplers are used */
    GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
+   GLbitfield TexelFetchSamplers; /**< Texture units used for texelFetch*(). */
    GLbitfield ExternalSamplersUsed; /**< Texture units used for samplerExternalOES */
 
    /* Fragement shader only fields */
index 90828bb4cf94707834de32473f56ffe2238d1513..c350a0980973edbd67e7455683d0c2c700c0c76d 100644 (file)
@@ -58,7 +58,8 @@
 void
 st_update_single_texture(struct st_context *st,
                          struct pipe_sampler_view **sampler_view,
-                         GLuint texUnit, bool glsl130_or_later)
+                         GLuint texUnit, bool glsl130_or_later,
+                         bool ignore_srgb_decode)
 {
    struct gl_context *ctx = st->ctx;
    const struct gl_sampler_object *samp;
@@ -90,7 +91,8 @@ st_update_single_texture(struct st_context *st,
 
    *sampler_view =
       st_get_texture_sampler_view_from_stobj(st, stObj, samp,
-                                             glsl130_or_later);
+                                             glsl130_or_later,
+                                             ignore_srgb_decode);
 }
 
 
@@ -104,6 +106,7 @@ update_textures(struct st_context *st,
 {
    const GLuint old_max = *out_num_textures;
    GLbitfield samplers_used = prog->SamplersUsed;
+   GLbitfield texel_fetch_samplers = prog->TexelFetchSamplers;
    GLbitfield free_slots = ~prog->SamplersUsed;
    GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
    GLuint unit;
@@ -118,13 +121,41 @@ update_textures(struct st_context *st,
 
    /* loop over sampler units (aka tex image units) */
    for (unit = 0; samplers_used || unit < old_max;
-        unit++, samplers_used >>= 1) {
+        unit++, samplers_used >>= 1, texel_fetch_samplers >>= 1) {
       struct pipe_sampler_view *sampler_view = NULL;
 
       if (samplers_used & 1) {
          const GLuint texUnit = prog->SamplerUnits[unit];
 
-         st_update_single_texture(st, &sampler_view, texUnit, glsl130);
+         /* The EXT_texture_sRGB_decode extension says:
+          *
+          *    "The conversion of sRGB color space components to linear color
+          *     space is always performed if the texel lookup function is one
+          *     of the texelFetch builtin functions.
+          *
+          *     Otherwise, if the texel lookup function is one of the texture
+          *     builtin functions or one of the texture gather functions, the
+          *     conversion of sRGB color space components to linear color space
+          *     is controlled by the TEXTURE_SRGB_DECODE_EXT parameter.
+          *
+          *     If the TEXTURE_SRGB_DECODE_EXT parameter is DECODE_EXT, the
+          *     conversion of sRGB color space components to linear color space
+          *     is performed.
+          *
+          *     If the TEXTURE_SRGB_DECODE_EXT parameter is SKIP_DECODE_EXT,
+          *     the value is returned without decoding. However, if the texture
+          *     is also [statically] accessed with a texelFetch function, then
+          *     the result of texture builtin functions and/or texture gather
+          *     functions may be returned with decoding or without decoding."
+          *
+          * Note: the "statically" will be added to the language per
+          *       https://cvs.khronos.org/bugzilla/show_bug.cgi?id=14934
+          *
+          * So we simply ignore the setting entirely for samplers that are
+          * (statically) accessed with a texelFetch function.
+          */
+         st_update_single_texture(st, &sampler_view, texUnit, glsl130,
+                                  texel_fetch_samplers & 1);
          num_textures = unit + 1;
       }
 
index 25ea52924d27b32918b5d74987615a3e6a677eb5..077319db6bcc3b15e492d12157b687cc1d5195ea 100644 (file)
@@ -3087,7 +3087,9 @@ st_NewTextureHandle(struct gl_context *ctx, struct gl_texture_object *texObj,
          return 0;
 
       st_convert_sampler(st, texObj, sampObj, 0, &sampler);
-      view = st_get_texture_sampler_view_from_stobj(st, stObj, sampObj, 0);
+
+      /* TODO: Clarify the interaction of ARB_bindless_texture and EXT_texture_sRGB_decode */
+      view = st_get_texture_sampler_view_from_stobj(st, stObj, sampObj, 0, true);
    } else {
       view = st_get_buffer_sampler_view_from_stobj(st, stObj);
    }
index e01268bbbeaacb9567da6849577f97ebefe7a275..4b365c84817bdbf64c41535cf147be12cef17bb2 100644 (file)
@@ -4478,6 +4478,10 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
             if (inst->tex_shadow) {
                prog->ShadowSamplers |= 1 << (inst->resource.index + i);
             }
+
+            if (inst->op == TGSI_OPCODE_TXF || inst->op == TGSI_OPCODE_TXF_LZ) {
+               prog->TexelFetchSamplers |= 1u << idx;
+            }
          }
       }
 
index 99c4f74ae08f1c209dc9ccc7b3f100153be53847..0d7b63af75a1f532041f884d98abb4618c2844c9 100644 (file)
@@ -334,7 +334,7 @@ last_layer(const struct st_texture_object *stObj)
 static enum pipe_format
 get_sampler_view_format(struct st_context *st,
                         const struct st_texture_object *stObj,
-                        const struct gl_sampler_object *samp)
+                        bool srgb_skip_decode)
 {
    enum pipe_format format;
 
@@ -351,7 +351,7 @@ get_sampler_view_format(struct st_context *st,
    }
 
    /* If sRGB decoding is off, use the linear format */
-   if (samp->sRGBDecode == GL_SKIP_DECODE_EXT)
+   if (srgb_skip_decode)
       format = util_format_linear(format);
 
    /* Use R8_UNORM for video formats */
@@ -408,24 +408,29 @@ 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,
-                                       bool glsl130_or_later)
+                                       bool glsl130_or_later,
+                                       bool ignore_srgb_decode)
 {
    struct st_sampler_view *sv;
    struct pipe_sampler_view *view;
+   bool srgb_skip_decode = false;
 
    sv = st_texture_get_sampler_view(st, stObj);
    view = sv->view;
 
+   if (!ignore_srgb_decode && samp->sRGBDecode == GL_SKIP_DECODE_EXT)
+      srgb_skip_decode = true;
+
    if (view &&
        sv->glsl130_or_later == glsl130_or_later &&
-       sv->sRGBDecode == samp->sRGBDecode) {
+       sv->srgb_skip_decode == srgb_skip_decode) {
       /* 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->view;
       assert(stObj->pt == view->texture);
       assert(!check_sampler_swizzle(st, stObj, view, glsl130_or_later));
-      assert(get_sampler_view_format(st, stObj, samp) == view->format);
+      assert(get_sampler_view_format(st, stObj, srgb_skip_decode) == view->format);
       assert(gl_target_to_pipe(stObj->base.Target) == view->target);
       assert(stObj->level_override ||
              stObj->base.MinLevel + stObj->base.BaseLevel == view->u.tex.first_level);
@@ -438,10 +443,10 @@ st_get_texture_sampler_view_from_stobj(struct st_context *st,
    }
    else {
       /* create new sampler view */
-      enum pipe_format format = get_sampler_view_format(st, stObj, samp);
+      enum pipe_format format = get_sampler_view_format(st, stObj, srgb_skip_decode);
 
       sv->glsl130_or_later = glsl130_or_later;
-      sv->sRGBDecode = samp->sRGBDecode;
+      sv->srgb_skip_decode = srgb_skip_decode;
 
       pipe_sampler_view_release(st->pipe, &sv->view);
       view = sv->view =
index 392206be4f71db2086a058222222d4a9d6373d89..cf46513f1b45857027b27865da5c31eaaded4f22 100644 (file)
@@ -73,7 +73,8 @@ 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,
-                                       bool glsl130_or_later);
+                                       bool glsl130_or_later,
+                                       bool ignore_srgb_decode);
 
 struct pipe_sampler_view *
 st_get_buffer_sampler_view_from_stobj(struct st_context *st,
index f749fb0a9fc383fc748fe0ca27d2adb5504bf14b..7d8303615e90fa739d547acd49799f21916b381e 100644 (file)
@@ -515,7 +515,8 @@ st_create_texture_handle_from_unit(struct st_context *st,
    struct pipe_sampler_view *view;
    struct pipe_sampler_state sampler = {0};
 
-   st_update_single_texture(st, &view, texUnit, prog->sh.data->Version >= 130);
+   /* TODO: Clarify the interaction of ARB_bindless_texture and EXT_texture_sRGB_decode */
+   st_update_single_texture(st, &view, texUnit, prog->sh.data->Version >= 130, true);
    if (!view)
       return 0;
 
index 4f41aac53cfb4f575983aaa5e62bc379d6e3928b..8b549b86085dc3d76935f9640fde6fdcbe471629 100644 (file)
@@ -56,8 +56,8 @@ struct st_sampler_view {
 
    /** The glsl version of the shader seen during validation */
    bool glsl130_or_later;
-   /** The value of the sampler's sRGBDecode state during validation */
-   GLenum sRGBDecode;
+   /** Derived from the sampler's sRGBDecode state during validation */
+   bool srgb_skip_decode;
 };
 
 
@@ -309,7 +309,8 @@ st_convert_sampler_from_unit(const struct st_context *st,
 void
 st_update_single_texture(struct st_context *st,
                          struct pipe_sampler_view **sampler_view,
-                         GLuint texUnit, bool glsl130_or_later);
+                         GLuint texUnit, bool glsl130_or_later,
+                         bool ignore_srgb_decode);
 
 void
 st_make_bound_samplers_resident(struct st_context *st,