mesa: implement EXT_EGL_image_storage_compression extension

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27109>
This commit is contained in:
Louis-Francis Ratté-Boulianne
2023-11-01 00:24:09 -04:00
committed by Marge Bot
parent e34ce71792
commit 2498d67382
4 changed files with 55 additions and 14 deletions

View File

@@ -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)

View File

@@ -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:
*
* "<attrib_list> must be NULL or a pointer to the value GL_NONE."
* Attributes that can be specified in <attrib_list> 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);
}

View File

@@ -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);

View File

@@ -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,