From: Nicolai Hähnle Date: Thu, 5 Oct 2017 17:39:33 +0000 (+0200) Subject: st/glsl_to_tgsi: ignore GL_TEXTURE_SRGB_DECODE_EXT for samplers used with texelFetch*() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0e26e767d2f13397d862b9a8fb921610a721cf19;p=mesa.git st/glsl_to_tgsi: ignore GL_TEXTURE_SRGB_DECODE_EXT for samplers used with texelFetch*() 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 Reviewed-by: Marek Olšák --- diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 2802a0e3605..8206793de9c 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -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 */ diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 90828bb4cf9..c350a098097 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -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; } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 25ea52924d2..077319db6bc 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -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); } diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index e01268bbbea..4b365c84817 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -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; + } } } diff --git a/src/mesa/state_tracker/st_sampler_view.c b/src/mesa/state_tracker/st_sampler_view.c index 99c4f74ae08..0d7b63af75a 100644 --- a/src/mesa/state_tracker/st_sampler_view.c +++ b/src/mesa/state_tracker/st_sampler_view.c @@ -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 = diff --git a/src/mesa/state_tracker/st_sampler_view.h b/src/mesa/state_tracker/st_sampler_view.h index 392206be4f7..cf46513f1b4 100644 --- a/src/mesa/state_tracker/st_sampler_view.h +++ b/src/mesa/state_tracker/st_sampler_view.h @@ -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, diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index f749fb0a9fc..7d8303615e9 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -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; diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 4f41aac53cf..8b549b86085 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -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,