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 <kenneth@whitecape.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Nicolai Hähnle
2017-10-05 19:39:33 +02:00
parent bce3055c69
commit 0e26e767d2
8 changed files with 63 additions and 17 deletions
+1
View 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 */
+35 -4
View 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;
}
+3 -1
View 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);
}
@@ -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;
}
}
}
+12 -7
View 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 =
+2 -1
View 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,
+2 -1
View 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;
+4 -3
View 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,