get_color_read_type: make sure format/type combo is legal for gles

The GLES spec limits the valid combinations of format and type that
may be returned by queries and/or used by ReadPixel. The list of valid
combinations appears in table 8.2 of the GLES 3.2 spec. Our code for
reporting the type and format of the current framebuffer, however,
does not verify that the combination is legal for GLES. For example,
RGBA and UNSIGNED_SHORT_1_5_5_5_REV is not a valid GLES combination,
but it's what we were returning for a panthor 16 bit frame buffer.

We can fix this either by changing the format or type that we return
(internally we can handle any format/type combination). We advertise the
read_format_bgra extension, so we could return GL_BGRA for the format.
However, very few applications (including notably the Khronos CTS for GLES)
cope well with BGRA. So instead we change the type to a non-_REV one
so that the combination appears in the GLES spec table of legal values.

Cc: mesa-stable
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29144>
(cherry picked from commit 4d298673da)
This commit is contained in:
Eric R. Smith 2024-05-10 11:07:54 -03:00 committed by Eric Engestrom
parent 40e1c62b96
commit 11fa599bcd
2 changed files with 28 additions and 5 deletions

View file

@ -3244,7 +3244,7 @@
"description": "get_color_read_type: make sure format/type combo is legal for gles",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -973,13 +973,36 @@ _mesa_get_color_read_type(struct gl_context *ctx,
GLenum data_type;
GLuint comps;
_mesa_uncompressed_format_to_type_and_comps(format, &data_type, &comps);
_mesa_uncompressed_format_to_type_and_comps(format, &data_type,
&comps);
if (_mesa_is_gles(ctx)) {
/* GLES allows only a limited set of format/type combinations for
reading, namely the ones specified in table 8.2 of the GLES 3.2
spec. In particular *_REV types are not allowed. The
EXT_read_format_bgra extension does add some *_REV types, but
only in conjunction with BGRA formats, and we return BGRA
from _mesa_get_color_read_format for very few cases. Work
around that here.
Note that EXT_texture_type_2_10_10_10_REV does add support
for that texture type and RGBA, so exclude that from our test.
*/
GLenum data_format = _mesa_get_color_read_format(ctx, fb, caller);
if (data_format == GL_RGBA) {
switch (data_type) {
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
data_type = GL_UNSIGNED_SHORT_4_4_4_4;
break;
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
data_type = GL_UNSIGNED_SHORT_5_5_5_1;
break;
default:
break;
}
}
}
return data_type;
}
}
/**
* Returns the read renderbuffer for the specified format.
*/