From a4a51f22b14609d025c5884e2912f1b5306ed61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= Date: Thu, 8 Aug 2024 00:50:40 -0400 Subject: [PATCH] gallium: add PIPE_CAP_ASTC_DECODE_MODE and expose extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mesa will expose GL_EXT_texture_compression_astc_decode_mode extension if the cap is enabled by the driver. Signed-off-by: Louis-Francis Ratté-Boulianne Reviewed-by: Marek Olšák Part-of: --- docs/features.txt | 1 + docs/gallium/screen.rst | 1 + src/gallium/auxiliary/util/u_screen.c | 1 + src/gallium/include/pipe/p_defines.h | 5 +++++ src/gallium/include/pipe/p_state.h | 3 ++- src/mesa/main/consts_exts.h | 1 + src/mesa/main/extensions_table.h | 1 + src/mesa/main/mtypes.h | 3 +++ src/mesa/main/texobj.c | 1 + src/mesa/main/texparam.c | 20 ++++++++++++++++++++ src/mesa/state_tracker/st_extensions.c | 1 + src/mesa/state_tracker/st_sampler_view.c | 16 ++++++++++++++++ 12 files changed, 53 insertions(+), 1 deletion(-) diff --git a/docs/features.txt b/docs/features.txt index c09cab2b95c..66741b288ab 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -331,6 +331,7 @@ Khronos, ARB, and OES extensions that are not part of any OpenGL or OpenGL ES ve GL_EXT_semaphore_win32 DONE (zink, d3d12) GL_EXT_shader_group_vote DONE (all drivers that support GL_ARB_shader_group_vote) GL_EXT_sRGB_write_control DONE (all drivers that support GLES 3.0+) + GL_EXT_texture_compression_astc_decode_mode DONE (core only) GL_EXT_texture_norm16 DONE (freedreno, r600, radeonsi, nvc0i, softpipe, zink, iris, crocus) GL_EXT_texture_sRGB_R8 DONE (all drivers that support GLES 3.0+) GL_KHR_blend_equation_advanced_coherent DONE (freedreno/a6xx, panfrost, zink, asahi, iris/gen9+) diff --git a/docs/gallium/screen.rst b/docs/gallium/screen.rst index 36ad32c1284..6ef8562b10d 100644 --- a/docs/gallium/screen.rst +++ b/docs/gallium/screen.rst @@ -649,6 +649,7 @@ The integer capabilities: * ``PIPE_CAP_HAS_CONST_BW``: Whether the driver only supports non-data-dependent layouts (ie. not bandwidth compressed formats like AFBC, UBWC, etc), or supports ``PIPE_BIND_CONST_BW`` to disable data-dependent layouts on requested resources. * ``PIPE_CAP_PERFORMANCE_MONITOR``: Whether GL_AMD_performance_monitor should be exposed. * ``PIPE_CAP_TEXTURE_SAMPLER_INDEPENDENT``: Whether sampler views and sampler states are independent objects, meaning both can be freely mixed and matched by the frontend. This isn't required for OpenGL where on the shader level those are the same object. However for proper gallium nine and OpenCL support this is required. +* ``PIPE_CAP_ASTC_DECODE_MODE``: Whether the driver supports ASTC decode precision. The :ext:`GL_KHR_texture_compression_astc_decode_mode` extension will only get exposed if :ext:`GL_KHR_texture_compression_astc_ldr` is also supported. .. _pipe_capf: diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c index ff2f91abcf0..929e2e798f0 100644 --- a/src/gallium/auxiliary/util/u_screen.c +++ b/src/gallium/auxiliary/util/u_screen.c @@ -549,6 +549,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen, case PIPE_CAP_VALIDATE_ALL_DIRTY_STATES: case PIPE_CAP_NULL_TEXTURES: case PIPE_CAP_ASTC_VOID_EXTENTS_NEED_DENORM_FLUSH: + case PIPE_CAP_ASTC_DECODE_MODE: case PIPE_CAP_HAS_CONST_BW: return 0; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 6d29cdb3eda..1427faf31a8 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -953,6 +953,7 @@ enum pipe_cap PIPE_CAP_HAS_CONST_BW, PIPE_CAP_PERFORMANCE_MONITOR, PIPE_CAP_TEXTURE_SAMPLER_INDEPENDENT, + PIPE_CAP_ASTC_DECODE_MODE, PIPE_CAP_LAST, /* XXX do not add caps after PIPE_CAP_LAST! */ }; @@ -1328,6 +1329,10 @@ enum pipe_perf_counter_data_type PIPE_PERF_COUNTER_DATA_TYPE_DOUBLE, }; +#define PIPE_ASTC_DECODE_FORMAT_FLOAT16 0 +#define PIPE_ASTC_DECODE_FORMAT_UNORM8 1 +#define PIPE_ASTC_DECODE_FORMAT_RGB9E5 2 + #define PIPE_UUID_SIZE 16 #define PIPE_LUID_SIZE 8 diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 3a5b751c665..f851b2c6c6a 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -483,7 +483,8 @@ struct pipe_sampler_view /* Put the refcount on its own cache line to prevent "False sharing". */ EXCLUSIVE_CACHELINE(struct pipe_reference reference); - enum pipe_format format:14; /**< typed PIPE_FORMAT_x */ + enum pipe_format format:12; /**< typed PIPE_FORMAT_x */ + unsigned astc_decode_format:2; /**< intermediate format used for ASTC textures */ bool is_tex2d_from_buf:1; /**< true if union is tex2d_from_buf */ enum pipe_texture_target target:5; /**< PIPE_TEXTURE_x */ unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */ diff --git a/src/mesa/main/consts_exts.h b/src/mesa/main/consts_exts.h index 203aefb8349..760d275bc24 100644 --- a/src/mesa/main/consts_exts.h +++ b/src/mesa/main/consts_exts.h @@ -192,6 +192,7 @@ struct gl_extensions GLboolean EXT_shadow_samplers; GLboolean EXT_texture_array; GLboolean EXT_texture_buffer_object; + GLboolean EXT_texture_compression_astc_decode_mode; GLboolean EXT_texture_compression_latc; GLboolean EXT_texture_compression_s3tc; GLboolean EXT_texture_compression_s3tc_srgb; diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h index d219b740e2c..7534ec851b9 100644 --- a/src/mesa/main/extensions_table.h +++ b/src/mesa/main/extensions_table.h @@ -313,6 +313,7 @@ EXT(EXT_texture_array , EXT_texture_array EXT(EXT_texture_border_clamp , dummy_true , x , x , x , ES2, 2014) EXT(EXT_texture_buffer , OES_texture_buffer , x , x , x , 31, 2014) EXT(EXT_texture_buffer_object , EXT_texture_buffer_object , GLL, x , x , x , 2007) +EXT(EXT_texture_compression_astc_decode_mode, EXT_texture_compression_astc_decode_mode, GLL, GLC, x , 30, 2017) EXT(EXT_texture_compression_bptc , ARB_texture_compression_bptc , x , x , x , 30, 2017) EXT(EXT_texture_compression_dxt1 , ANGLE_texture_compression_dxt , GLL, GLC, ES1, ES2, 2004) EXT(EXT_texture_compression_latc , EXT_texture_compression_latc , GLL, x , x , x , 2006) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 9a56e96c2bb..cd6788da78f 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -972,6 +972,9 @@ struct gl_texture_object /** GL_EXT_texture_storage_compression */ GLint CompressionRate; /**< Fixed-rate compression bitrate */ + /** GL_EXT_texture_compression_astc_decode_mode */ + GLenum16 AstcDecodePrecision; /**< ASTC decoding precision */ + /* The texture must include at levels [0..lastLevel] once validated: */ GLuint lastLevel; diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index 5ad4b8c98dc..436e082b763 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -411,6 +411,7 @@ _mesa_initialize_texture_object( struct gl_context *ctx, ? MESA_FORMAT_L_UNORM8 : MESA_FORMAT_R_UNORM8; obj->Attrib.ImageFormatCompatibilityType = GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE; obj->CompressionRate = GL_SURFACE_COMPRESSION_FIXED_RATE_NONE_EXT; + obj->AstcDecodePrecision = GL_RGBA16F; /* GL_ARB_bindless_texture */ _mesa_init_texture_handles(obj); diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 43bb956561a..aee3d94f16f 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -702,6 +702,19 @@ set_tex_parameteri(struct gl_context *ctx, return GL_TRUE; + case GL_TEXTURE_ASTC_DECODE_PRECISION_EXT: + if (!_mesa_has_EXT_texture_compression_astc_decode_mode(ctx)) + goto invalid_pname; + + if (texObj->AstcDecodePrecision == params[0]) + return GL_FALSE; + + if (params[0] != GL_RGBA16F && params[0] != GL_RGBA8) + goto invalid_param; + + texObj->AstcDecodePrecision = params[0]; + return GL_TRUE; + default: goto invalid_pname; } @@ -911,6 +924,7 @@ texparam_invalidates_sampler_views(GLenum pname) case GL_TEXTURE_SWIZZLE_RGBA: case GL_TEXTURE_BUFFER_SIZE: case GL_TEXTURE_BUFFER_OFFSET: + case GL_TEXTURE_ASTC_DECODE_PRECISION_EXT: return true; default: return false; @@ -2803,6 +2817,12 @@ get_tex_parameteriv(struct gl_context *ctx, *params = obj->CompressionRate; break; + case GL_TEXTURE_ASTC_DECODE_PRECISION_EXT: + if (!_mesa_has_EXT_texture_compression_astc_decode_mode(ctx)) + goto invalid_pname; + *params = obj->AstcDecodePrecision; + break; + default: goto invalid_pname; } diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index b900e0ae52d..e03c6a0eb39 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -834,6 +834,7 @@ void st_init_extensions(struct pipe_screen *screen, #endif { o(EXT_shader_samples_identical), PIPE_CAP_SHADER_SAMPLES_IDENTICAL }, { o(EXT_texture_array), PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS }, + { o(EXT_texture_compression_astc_decode_mode), PIPE_CAP_ASTC_DECODE_MODE }, { o(EXT_texture_filter_anisotropic), PIPE_CAP_ANISOTROPIC_FILTER }, { o(EXT_texture_filter_minmax), PIPE_CAP_SAMPLER_REDUCTION_MINMAX }, { o(EXT_texture_mirror_clamp), PIPE_CAP_TEXTURE_MIRROR_CLAMP }, diff --git a/src/mesa/state_tracker/st_sampler_view.c b/src/mesa/state_tracker/st_sampler_view.c index 5978c11c12d..a9a771dcc5c 100644 --- a/src/mesa/state_tracker/st_sampler_view.c +++ b/src/mesa/state_tracker/st_sampler_view.c @@ -452,6 +452,19 @@ st_get_sampler_view_format(const struct st_context *st, return format; } +static unsigned +gl_astc_decode_precision_to_pipe(GLint precision) +{ + switch (precision) { + case GL_RGBA8: + return PIPE_ASTC_DECODE_FORMAT_UNORM8; + case GL_RGB9_E5: + return PIPE_ASTC_DECODE_FORMAT_RGB9E5; + case GL_RGBA16F: + default: + return PIPE_ASTC_DECODE_FORMAT_FLOAT16; + } +} static struct pipe_sampler_view * st_create_texture_sampler_view_from_stobj(struct st_context *st, @@ -488,6 +501,9 @@ st_create_texture_sampler_view_from_stobj(struct st_context *st, templ.swizzle_b = GET_SWZ(swizzle, 2); templ.swizzle_a = GET_SWZ(swizzle, 3); + templ.astc_decode_format = + gl_astc_decode_precision_to_pipe(texObj->AstcDecodePrecision); + return st->pipe->create_sampler_view(st->pipe, texObj->pt, &templ); }