From 2498d6738275eeb0e64814cc841596a37293fac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= Date: Wed, 1 Nov 2023 00:24:09 -0400 Subject: [PATCH] mesa: implement EXT_EGL_image_storage_compression extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Louis-Francis Ratté-Boulianne Reviewed-by: Erik Faye-Lund Part-of: --- src/mesa/main/extensions_table.h | 1 + src/mesa/main/teximage.c | 50 ++++++++++++++++++++----- src/mesa/state_tracker/st_cb_eglimage.c | 16 ++++++-- src/mesa/state_tracker/st_cb_eglimage.h | 2 +- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h index 4772879cd49..a5f47a69d64 100644 --- a/src/mesa/main/extensions_table.h +++ b/src/mesa/main/extensions_table.h @@ -214,6 +214,7 @@ EXT(ATI_texture_float , ARB_texture_float EXT(ATI_texture_mirror_once , ATI_texture_mirror_once , GLL, GLC, x , x , 2006) EXT(EXT_EGL_image_storage , EXT_EGL_image_storage , GLL, GLC , x , 30, 2018) +EXT(EXT_EGL_image_storage_compression , EXT_EGL_image_storage , GLL, GLC , x , 30, 2021) EXT(EXT_EGL_sync , dummy_true , GLL, GLC, x , x , 2019) EXT(EXT_abgr , dummy_true , GLL, GLC, x , x , 1995) EXT(EXT_base_instance , ARB_base_instance , x , x , x , 30, 2014) diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index bbfc343940f..9f86ca780b9 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -3544,7 +3544,7 @@ static void egl_image_target_texture(struct gl_context *ctx, struct gl_texture_object *texObj, GLenum target, GLeglImageOES image, bool tex_storage, - const char *caller) + bool tex_compression, const char *caller) { struct gl_texture_image *texImage; FLUSH_VERTICES(ctx, 0, 0); @@ -3578,8 +3578,8 @@ egl_image_target_texture(struct gl_context *ctx, struct st_egl_image stimg; bool native_supported; - if (!st_get_egl_image(ctx, image, PIPE_BIND_SAMPLER_VIEW, caller, - &stimg, &native_supported)) { + if (!st_get_egl_image(ctx, image, PIPE_BIND_SAMPLER_VIEW, tex_compression, + caller, &stimg, &native_supported)) { _mesa_unlock_texture(ctx, texObj); return; } @@ -3638,26 +3638,55 @@ _mesa_EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) } if (valid_target) { - egl_image_target_texture(ctx, NULL, target, image, false, func); + egl_image_target_texture(ctx, NULL, target, image, false, false, func); } else { _mesa_error(ctx, GL_INVALID_ENUM, "%s(target=%d)", func, target); } } +static bool +parse_surface_compression(GLint attrib, bool *compression) +{ + switch (attrib) { + case GL_SURFACE_COMPRESSION_FIXED_RATE_DEFAULT_EXT: + *compression = true; + break; + case GL_SURFACE_COMPRESSION_FIXED_RATE_NONE_EXT: + *compression = false; + break; + default: + return false; + } + return true; +} + + static void egl_image_target_texture_storage(struct gl_context *ctx, struct gl_texture_object *texObj, GLenum target, GLeglImageOES image, const GLint *attrib_list, const char *caller) { + bool tex_compression = false; + /* - * EXT_EGL_image_storage: + * EXT_EGL_image_storage_compression: * - * " must be NULL or a pointer to the value GL_NONE." + * Attributes that can be specified in include + * SURFACE_COMPRESSION_EXT. */ - if (attrib_list && attrib_list[0] != GL_NONE) { - _mesa_error(ctx, GL_INVALID_VALUE, "%s(image=%p)", caller, image); - return; + for (int i = 0; attrib_list && attrib_list[i] != GL_NONE; ++i) { + switch (attrib_list[i]) { + case GL_SURFACE_COMPRESSION_EXT: + if (!parse_surface_compression(attrib_list[++i], &tex_compression)) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(image=%p)", caller, image); + return; + } + break; + default: + _mesa_error(ctx, GL_INVALID_VALUE, "%s(image=%p)", caller, image); + return; + } } /* @@ -3691,7 +3720,8 @@ egl_image_target_texture_storage(struct gl_context *ctx, } if (valid_target) { - egl_image_target_texture(ctx, texObj, target, image, true, caller); + egl_image_target_texture(ctx, texObj, target, image, true, + tex_compression, caller); } else { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(target=%d)", caller, target); } diff --git a/src/mesa/state_tracker/st_cb_eglimage.c b/src/mesa/state_tracker/st_cb_eglimage.c index e5054abece4..bd375bda578 100644 --- a/src/mesa/state_tracker/st_cb_eglimage.c +++ b/src/mesa/state_tracker/st_cb_eglimage.c @@ -229,8 +229,8 @@ is_i420_as_r8_g8_b8_420_supported(struct pipe_screen *screen, */ bool st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle, - unsigned usage, const char *error, struct st_egl_image *out, - bool *native_supported) + unsigned usage, bool tex_compression, const char *error, + struct st_egl_image *out, bool *native_supported) { struct st_context *st = st_context(ctx); struct pipe_screen *screen = st->screen; @@ -257,6 +257,14 @@ st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle, return false; } + if (out->texture->compression_rate != PIPE_COMPRESSION_FIXED_RATE_NONE && + !tex_compression) { + /* texture is fixed-rate compressed but a uncompressed one is expected */ + pipe_resource_reference(&out->texture, NULL); + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(fixed-rate compression not enabled)", error); + return false; + } + ctx->Shared->HasExternallySharedImages = true; return true; } @@ -299,7 +307,7 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx, struct st_egl_image stimg; bool native_supported; - if (st_get_egl_image(ctx, image_handle, PIPE_BIND_RENDER_TARGET, + if (st_get_egl_image(ctx, image_handle, PIPE_BIND_RENDER_TARGET, false, "glEGLImageTargetRenderbufferStorage", &stimg, &native_supported)) { struct pipe_context *pipe = st_context(ctx)->pipe; @@ -490,6 +498,8 @@ st_bind_egl_image(struct gl_context *ctx, if (stimg->yuv_range == __DRI_YUV_FULL_RANGE) texObj->yuv_full_range = true; + texObj->CompressionRate = stimg->texture->compression_rate; + texObj->level_override = stimg->level; texObj->layer_override = stimg->layer; _mesa_update_texture_object_swizzle(ctx, texObj); diff --git a/src/mesa/state_tracker/st_cb_eglimage.h b/src/mesa/state_tracker/st_cb_eglimage.h index 379e6646303..c4233911d22 100644 --- a/src/mesa/state_tracker/st_cb_eglimage.h +++ b/src/mesa/state_tracker/st_cb_eglimage.h @@ -36,7 +36,7 @@ st_init_eglimage_functions(struct dd_function_table *functions, bool has_egl_image_validate); bool st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle, - unsigned usage, const char *error, + unsigned usage, bool tex_compression, const char *error, struct st_egl_image *out, bool *native_supported); void st_bind_egl_image(struct gl_context *ctx, struct gl_texture_object *texObj,