From 57d47f717a7adaf4b6430ad5cb682160f9a30e2e Mon Sep 17 00:00:00 2001 From: Saroj Kumar Date: Mon, 3 Feb 2025 10:59:03 +0530 Subject: [PATCH] mesa: Add GL_EXT_protected_textures support Add support for GL_EXT_protected_textures to create protected texture in OpenGL ES 3.2. This enables allocating standard GL textures as protected surfaces. This allows use-cases such as depth, stencil, or mipmapped textures to be supported as destinations for rendering within a protected context. Signed-off-by: Saroj Kumar Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mapi/glapi/gen/es_EXT.xml | 5 ++++ src/mesa/main/consts_exts.h | 1 + src/mesa/main/extensions_table.h | 1 + src/mesa/main/glthread_marshal.h | 1 + src/mesa/main/mtypes.h | 2 ++ src/mesa/main/texparam.c | 36 ++++++++++++++++++++++++-- src/mesa/main/texstorage.c | 9 +++++-- src/mesa/state_tracker/st_cb_texture.c | 6 +++++ src/mesa/state_tracker/st_extensions.c | 2 ++ 9 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/mapi/glapi/gen/es_EXT.xml b/src/mapi/glapi/gen/es_EXT.xml index bd968869989..75895a2e2cb 100644 --- a/src/mapi/glapi/gen/es_EXT.xml +++ b/src/mapi/glapi/gen/es_EXT.xml @@ -1636,6 +1636,11 @@ + + + + + diff --git a/src/mesa/main/consts_exts.h b/src/mesa/main/consts_exts.h index f11824c512b..1a9be719da1 100644 --- a/src/mesa/main/consts_exts.h +++ b/src/mesa/main/consts_exts.h @@ -178,6 +178,7 @@ struct gl_extensions GLboolean EXT_memory_object_win32; GLboolean EXT_multisampled_render_to_texture; GLboolean EXT_packed_float; + GLboolean EXT_protected_textures; GLboolean EXT_provoking_vertex; GLboolean EXT_render_snorm; GLboolean EXT_semaphore; diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h index 13c7a3f7d05..276c6e4c5a3 100644 --- a/src/mesa/main/extensions_table.h +++ b/src/mesa/main/extensions_table.h @@ -281,6 +281,7 @@ EXT(EXT_pixel_buffer_object , dummy_true EXT(EXT_point_parameters , dummy_true , GLL, x , x , x , 1997) EXT(EXT_polygon_offset_clamp , ARB_polygon_offset_clamp , GLL, GLC, ES1, ES2, 2014) EXT(EXT_primitive_bounding_box , OES_primitive_bounding_box , x , x , x , 31, 2014) +EXT(EXT_protected_textures , EXT_protected_textures , x , x , x , 30, 2017) EXT(EXT_provoking_vertex , EXT_provoking_vertex , GLL, GLC, x , x , 2009) EXT(EXT_read_format_bgra , dummy_true , x , x , ES1, ES2, 2009) EXT(EXT_render_snorm , EXT_render_snorm , x , x , x, 30, 2014) diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h index b7dbfc35f4b..e5e53717187 100644 --- a/src/mesa/main/glthread_marshal.h +++ b/src/mesa/main/glthread_marshal.h @@ -196,6 +196,7 @@ _mesa_tex_param_enum_to_count(GLenum pname) case GL_TEXTURE_SPARSE_ARB: case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB: case GL_NUM_SPARSE_LEVELS_ARB: + case GL_TEXTURE_PROTECTED_EXT: return 1; case GL_TEXTURE_CROP_RECT_OES: case GL_TEXTURE_SWIZZLE_RGBA: diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 52a3c36451a..15bff7bd6fd 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1058,6 +1058,8 @@ struct gl_texture_object * the pipe_resource *pt above. */ bool needs_validation; + + GLboolean IsProtected; }; diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 41b3c667a17..dcb03f8cac9 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -676,7 +676,17 @@ set_tex_parameteri(struct gl_context *ctx, return GL_TRUE; } goto invalid_pname; - + case GL_TEXTURE_PROTECTED_EXT: + if (_mesa_has_EXT_protected_textures(ctx)) { + if (params[0] != GL_TRUE && params[0] != GL_FALSE) { + _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)", + suffix); + return GL_FALSE; + } + texObj->IsProtected = params[0]; + return GL_TRUE; + } + goto invalid_pname; case GL_TEXTURE_SPARSE_ARB: case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB: if (!_mesa_has_ARB_sparse_texture(ctx)) @@ -901,7 +911,17 @@ set_tex_parameterf(struct gl_context *ctx, return GL_TRUE; } goto invalid_pname; - + case GL_TEXTURE_PROTECTED_EXT: + if (_mesa_has_EXT_protected_textures(ctx)) { + if (params[0] != GL_TRUE && params[0] != GL_FALSE) { + _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)", + suffix); + return GL_FALSE; + } + texObj->IsProtected = params[0]; + return GL_TRUE; + } + goto invalid_pname; default: goto invalid_pname; } @@ -2547,6 +2567,12 @@ get_tex_parameterfv(struct gl_context *ctx, *params = (GLfloat) obj->NumSparseLevels; break; + case GL_TEXTURE_PROTECTED_EXT: + if (!_mesa_has_EXT_protected_textures(ctx)) + goto invalid_pname; + *params = (GLfloat) obj->IsProtected; + break; + default: goto invalid_pname; } @@ -2843,6 +2869,12 @@ get_tex_parameteriv(struct gl_context *ctx, goto invalid_pname; *params = obj->AstcDecodePrecision; break; + + case GL_TEXTURE_PROTECTED_EXT: + if (!_mesa_has_EXT_protected_textures(ctx)) + goto invalid_pname; + *params = obj->IsProtected; + break; default: goto invalid_pname; diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c index a76ad382bc9..55746c08fec 100644 --- a/src/mesa/main/texstorage.c +++ b/src/mesa/main/texstorage.c @@ -421,6 +421,12 @@ tex_storage_error_check(struct gl_context *ctx, return GL_TRUE; } + if (texObj->IsSparse && texObj->IsProtected) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sStorage%uD(protected)", + suffix, dims); + return GL_TRUE; + } + /* additional checks for depth textures */ if (!_mesa_legal_texture_base_format_for_target(ctx, target, internalformat)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sStorage%uD(bad target for texture)", @@ -559,8 +565,7 @@ texture_storage(struct gl_context *ctx, GLuint dims, /* clear all image fields for [levels] */ clear_texture_fields(ctx, texObj); } - } - else { + } else { if (!no_error) { if (!dimensionsOK) { _mesa_error(ctx, GL_INVALID_VALUE, diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index f332234305c..93b455725ef 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -3285,6 +3285,9 @@ st_finalize_texture(struct gl_context *ctx, if (!tObj->pt && !tObj->NullTexture) { GLuint bindings = default_bindings(st, firstImageFormat); + if (tObj->IsProtected) + bindings |= PIPE_BIND_PROTECTED; + tObj->pt = st_texture_create(st, gl_target_to_pipe(tObj->Target), firstImageFormat, @@ -3450,6 +3453,9 @@ st_texture_storage(struct gl_context *ctx, bindings |= PIPE_BIND_SHARED; } + if (texObj->IsProtected) + bindings |= PIPE_BIND_PROTECTED; + if (num_samples > 0) { /* Find msaa sample count which is actually supported. For example, * if the user requests 1x but only 4x or 8x msaa is supported, we'll diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 1fcc254daeb..775f00caa4b 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -1821,4 +1821,6 @@ void st_init_extensions(struct pipe_screen *screen, screen->caps.doubles && !(nir_options->lower_doubles_options & nir_lower_fp64_full_software)) extensions->NV_copy_depth_to_color = true; + if (screen->caps.device_protected_surface || screen->caps.device_protected_context) + extensions->EXT_protected_textures = true; }