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>
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 */
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;
*sampler_view =
st_get_texture_sampler_view_from_stobj(st, stObj, samp,
- glsl130_or_later);
+ glsl130_or_later,
+ ignore_srgb_decode);
}
{
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;
/* 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;
}
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);
}
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;
+ }
}
}
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;
}
/* 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 */
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);
}
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 =
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,
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;
/** 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;
};
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,