mesa: texture format check mismatch for msaa
Looking at spec@arb_texture_multisample@arb_texture_multisample-dsa-texelfetch
, I've found an annoying mismatch in how textures are checked for msaa support vs how they're created.
When checking msaa format support, mesa does this:
- call through to
st_QuerySamplesForFormat()
- use
if (_mesa_is_depth_or_stencil_format(internalFormat))
bind = PIPE_BIND_DEPTH_STENCIL;
else
bind = PIPE_BIND_RENDER_TARGET;
- run through the sample counts until format support is detected
When allocating the texture, however, mesa does this:
- call through to
default_bindings()
static GLuint
default_bindings(struct st_context *st, enum pipe_format format)
{
struct pipe_screen *screen = st->screen;
const unsigned target = PIPE_TEXTURE_2D;
unsigned bindings;
if (util_format_is_depth_or_stencil(format))
bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL;
else
bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
if (screen->is_format_supported(screen, format, target, 0, 0, bindings))
return bindings;
else {
/* Try non-sRGB. */
format = util_format_linear(format);
if (screen->is_format_supported(screen, format, target, 0, 0, bindings))
return bindings;
else
return PIPE_BIND_SAMPLER_VIEW;
}
}
- allocate potentially using a bind that was never checked for support
By contrast, this ends up falling back to PIPE_BIND_SAMPLER_VIEW if rendering isn't supported, which is a viable case for multisample textures. This is also how a number of formats (e.g., PIPE_FORMAT_R9G9B9E5_FLOAT) need to be tested in order to accurately detect support. It is not, however, currently possible to accurately report to gallium that only sampling is supported for a format, because if your driver doesn't return support for rendering to a given format, you never get that format for sampling.
I'm not sure how to "properly" fix this. It seems like st_QuerySamplesForFormat
should use the same mechanism, but there's a lot of drivers out there and I don't want to break multisampling.