From b6b980a904838260540541dcbb34c72de8437b67 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 8 Feb 2024 11:56:42 +0100 Subject: [PATCH] mesa/main: work around chrome/firefox bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to flawed logic, Chromium and Firefox thinks EXT_texture_storage allows using GL_BGRA8_EXT for *all* texturing, including things like glTexSubImage2D, which it does not. However, this bug was introduced in Chromium back in 2016, and there's also a lot of Electron apps that bundle outdated versions of Chromium. This means it's going to be a *mess* to fix this properly while staying within the spec. I've opened a ticket with Khronos to consider changing the spec to make this legal, because it seems most other OpenGL implementations allow it. But in the mean time, let's complain a bit, but accept the behavior. This way people can at least run browsers with hardware acceleration again. If we decide to change the spec, we can remove this wording. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10550 Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/glformats.c | 21 +++++++++++++++++++-- src/mesa/main/glformats.h | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c index 15f089cc9fc..f5a871388fa 100644 --- a/src/mesa/main/glformats.c +++ b/src/mesa/main/glformats.c @@ -2745,7 +2745,7 @@ gles_effective_internal_format_for_format_and_type(GLenum format, * are required for complete checking between format and type. */ static GLenum -_mesa_gles_check_internalformat(const struct gl_context *ctx, +_mesa_gles_check_internalformat(struct gl_context *ctx, GLenum internalFormat) { switch (internalFormat) { @@ -2900,6 +2900,22 @@ _mesa_gles_check_internalformat(const struct gl_context *ctx, if (!_mesa_is_gles3(ctx)) return GL_INVALID_VALUE; return GL_NO_ERROR; + + case GL_BGRA8_EXT: { + /* This is technically speaking out-of-spec. But too many + * applications seems to depend on it, so let's allow it + * together with a small complaint */ + static bool warned = false; + if (!warned) { + _mesa_warning(ctx, + "internalformat = GL_BGRA8_EXT invalid by spec, but too many " + "applications depend on it to error. Please fix the software " + "that causes this problem."); + warned = true; + } + return GL_NO_ERROR; + } + default: return GL_INVALID_VALUE; } @@ -2911,7 +2927,7 @@ _mesa_gles_check_internalformat(const struct gl_context *ctx, * \return error code, or GL_NO_ERROR. */ GLenum -_mesa_gles_error_check_format_and_type(const struct gl_context *ctx, +_mesa_gles_error_check_format_and_type(struct gl_context *ctx, GLenum format, GLenum type, GLenum internalFormat) { @@ -2980,6 +2996,7 @@ _mesa_gles_error_check_format_and_type(const struct gl_context *ctx, if (type != GL_UNSIGNED_BYTE || (internalFormat != GL_BGRA && internalFormat != GL_RGBA8 && + internalFormat != GL_BGRA8_EXT && internalFormat != GL_SRGB8_ALPHA8)) return GL_INVALID_OPERATION; break; diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h index a402a835962..391898d64e7 100644 --- a/src/mesa/main/glformats.h +++ b/src/mesa/main/glformats.h @@ -139,7 +139,7 @@ _mesa_es_error_check_format_and_type(const struct gl_context *ctx, unsigned dimensions); extern GLenum -_mesa_gles_error_check_format_and_type(const struct gl_context *ctx, +_mesa_gles_error_check_format_and_type(struct gl_context *ctx, GLenum format, GLenum type, GLenum internalFormat); extern GLint