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 <saroj.kumar@amd.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33358>
This commit is contained in:
Saroj Kumar 2025-02-03 10:59:03 +05:30 committed by Marge Bot
parent 124a2b612d
commit 57d47f717a
9 changed files with 59 additions and 4 deletions

View file

@ -1636,6 +1636,11 @@
</function>
</category>
<category name="GL_EXT_protected_textures" number="256">
<enum name="CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT" value="0x00000010"/>
<enum name="TEXTURE_PROTECTED_EXT" value="0x8BFA" />
</category>
<xi:include href="EXT_texture_storage_compression.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
</OpenGLAPI>

View file

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

View file

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

View file

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

View file

@ -1058,6 +1058,8 @@ struct gl_texture_object
* the pipe_resource *pt above.
*/
bool needs_validation;
GLboolean IsProtected;
};

View file

@ -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;
}
@ -2844,6 +2870,12 @@ get_tex_parameteriv(struct gl_context *ctx,
*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;
}

View file

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

View file

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

View file

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