From 73c1d7e8c9cda09165546d836048e4a2cef89e0d Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Tue, 5 Feb 2019 11:36:59 -0500 Subject: [PATCH] mesa: add GL_AMD_compressed_ATC_texture support Signed-off-by: Ilia Mirkin Signed-off-by: Jonathan Marek Reviewed-by: Roland Scheidegger --- src/mapi/glapi/gen/es_EXT.xml | 6 ++++++ src/mesa/main/extensions_table.h | 1 + src/mesa/main/format_info.py | 2 ++ src/mesa/main/formats.c | 3 +++ src/mesa/main/formats.csv | 5 +++++ src/mesa/main/formats.h | 7 +++++++ src/mesa/main/glformats.c | 5 +++++ src/mesa/main/glheader.h | 6 ++++++ src/mesa/main/mtypes.h | 1 + src/mesa/main/texcompress.c | 32 ++++++++++++++++++++++++++++++++ src/mesa/main/teximage.c | 5 ++++- src/mesa/swrast/s_texfetch.c | 6 +++++- 12 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/mapi/glapi/gen/es_EXT.xml b/src/mapi/glapi/gen/es_EXT.xml index 917fed62f98..5fa518d7a09 100644 --- a/src/mapi/glapi/gen/es_EXT.xml +++ b/src/mapi/glapi/gen/es_EXT.xml @@ -565,6 +565,12 @@ + + + + + + diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h index 3077068dd80..ec6f8a81353 100644 --- a/src/mesa/main/extensions_table.h +++ b/src/mesa/main/extensions_table.h @@ -8,6 +8,7 @@ EXT(3DFX_texture_compression_FXT1 , TDFX_texture_compression_FXT1 , GLL, GLC, x , x , 1999) +EXT(AMD_compressed_ATC_texture , AMD_compressed_ATC_texture , x , x , ES1, ES2, 2008) EXT(AMD_conservative_depth , ARB_conservative_depth , GLL, GLC, x , x , 2009) EXT(AMD_depth_clamp_separate , AMD_depth_clamp_separate , GLL, GLC, x , x , 2009) EXT(AMD_draw_buffers_blend , ARB_draw_buffers_blend , GLL, GLC, x , x , 2009) diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py index 00e27b3fba5..94017bfae0f 100644 --- a/src/mesa/main/format_info.py +++ b/src/mesa/main/format_info.py @@ -126,6 +126,8 @@ def get_channel_bits(fmat, chan_name): elif fmat.layout == 'astc': bits = 16 if 'RGBA' in fmat.name else 8 return bits if fmat.has_channel(chan_name) else 0 + elif fmat.layout == 'atc': + return 8 if fmat.has_channel(chan_name) else 0 else: assert False else: diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index cf2d2bc555a..b47bed97d20 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -712,11 +712,14 @@ _mesa_get_uncompressed_format(mesa_format format) case MESA_FORMAT_ETC1_RGB8: case MESA_FORMAT_ETC2_RGB8: case MESA_FORMAT_ETC2_SRGB8: + case MESA_FORMAT_ATC_RGB: return MESA_FORMAT_BGR_UNORM8; case MESA_FORMAT_ETC2_RGBA8_EAC: case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: + case MESA_FORMAT_ATC_RGBA_EXPLICIT: + case MESA_FORMAT_ATC_RGBA_INTERPOLATED: return MESA_FORMAT_A8B8G8R8_UNORM; case MESA_FORMAT_ETC2_R11_EAC: case MESA_FORMAT_ETC2_SIGNED_R11_EAC: diff --git a/src/mesa/main/formats.csv b/src/mesa/main/formats.csv index cb821fec62f..90d9bf07ece 100644 --- a/src/mesa/main/formats.csv +++ b/src/mesa/main/formats.csv @@ -372,3 +372,8 @@ MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5 , astc , 5, 5, 5, x128, , , MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5 , astc , 6, 5, 5, x128, , , , xyzw, srgb MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5 , astc , 6, 6, 5, x128, , , , xyzw, srgb MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6 , astc , 6, 6, 6, x128, , , , xyzw, srgb + +# ATC compressed formats +MESA_FORMAT_ATC_RGB , atc , 4, 4, 1, x64 , , , , xyz1, rgb +MESA_FORMAT_ATC_RGBA_EXPLICIT , atc , 4, 4, 1, x128, , , , xyzw, rgb +MESA_FORMAT_ATC_RGBA_INTERPOLATED , atc , 4, 4, 1, x128, , , , xyzw, rgb diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h index 15c561225d6..08039067a6c 100644 --- a/src/mesa/main/formats.h +++ b/src/mesa/main/formats.h @@ -71,6 +71,7 @@ enum mesa_format_layout { MESA_FORMAT_LAYOUT_ETC2, MESA_FORMAT_LAYOUT_BPTC, MESA_FORMAT_LAYOUT_ASTC, + MESA_FORMAT_LAYOUT_ATC, MESA_FORMAT_LAYOUT_OTHER, }; @@ -657,6 +658,12 @@ typedef enum MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5, MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5, MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6, + + /* ATC compressed formats */ + MESA_FORMAT_ATC_RGB, + MESA_FORMAT_ATC_RGBA_EXPLICIT, + MESA_FORMAT_ATC_RGBA_INTERPOLATED, + MESA_FORMAT_COUNT } mesa_format; diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c index ea72cab5b3e..bd087848803 100644 --- a/src/mesa/main/glformats.c +++ b/src/mesa/main/glformats.c @@ -1142,6 +1142,9 @@ _mesa_is_color_format(GLenum format) case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: + case GL_ATC_RGB_AMD: + case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: + case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: /* generic integer formats */ case GL_RED_INTEGER_EXT: case GL_GREEN_INTEGER_EXT: @@ -1393,6 +1396,8 @@ _mesa_is_compressed_format(const struct gl_context *ctx, GLenum format) _mesa_has_EXT_texture_compression_bptc(ctx); case MESA_FORMAT_LAYOUT_ASTC: return _mesa_has_KHR_texture_compression_astc_ldr(ctx); + case MESA_FORMAT_LAYOUT_ATC: + return _mesa_has_AMD_compressed_ATC_texture(ctx); default: return GL_FALSE; } diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h index 5764b83ffbb..a3294d89d18 100644 --- a/src/mesa/main/glheader.h +++ b/src/mesa/main/glheader.h @@ -142,6 +142,12 @@ typedef int GLclampx; #define GL_SR8_EXT 0x8FBD #endif +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + /** * Internal token to represent a GLSL shader program (a collection of * one or more shaders that get linked together). Note that GLSL diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 297d3be8098..6efd9758417 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -4308,6 +4308,7 @@ struct gl_extensions GLboolean OES_texture_view; GLboolean OES_viewport_array; /* vendor extensions */ + GLboolean AMD_compressed_ATC_texture; GLboolean AMD_framebuffer_multisample_advanced; GLboolean AMD_depth_clamp_separate; GLboolean AMD_performance_monitor; diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index 2406cc5cf7e..48d794ddfd2 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -106,6 +106,7 @@ _mesa_gl_compressed_format_base_format(GLenum format) case GL_PALETTE4_R5_G6_B5_OES: case GL_PALETTE8_RGB8_OES: case GL_PALETTE8_R5_G6_B5_OES: + case GL_ATC_RGB_AMD: return GL_RGB; case GL_COMPRESSED_RGBA: @@ -131,6 +132,8 @@ _mesa_gl_compressed_format_base_format(GLenum format) case GL_PALETTE4_RGB5_A1_OES: case GL_PALETTE8_RGBA8_OES: case GL_PALETTE8_RGBA4_OES: + case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: + case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: return GL_RGBA; case GL_COMPRESSED_ALPHA: @@ -455,6 +458,20 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES; } + /* The GL_AMD_compressed_ATC_texture spec says: + * + * "New State + * + * The queries for NUM_COMPRESSED_TEXTURE_FORMATS and + * COMPRESSED_TEXTURE_FORMATS include ATC_RGB_AMD, + * ATC_RGBA_EXPLICIT_ALPHA_AMD, and ATC_RGBA_INTERPOLATED_ALPHA_AMD." + */ + if (_mesa_has_AMD_compressed_ATC_texture(ctx)) { + formats[n++] = GL_ATC_RGB_AMD; + formats[n++] = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD; + formats[n++] = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; + } + assert(n <= ARRAY_SIZE(discard_formats)); return n; @@ -643,6 +660,13 @@ _mesa_glenum_to_compressed_format(GLenum format) case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES: return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6; + case GL_ATC_RGB_AMD: + return MESA_FORMAT_ATC_RGB; + case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: + return MESA_FORMAT_ATC_RGBA_EXPLICIT; + case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: + return MESA_FORMAT_ATC_RGBA_INTERPOLATED; + default: return MESA_FORMAT_NONE; } @@ -831,6 +855,14 @@ _mesa_compressed_format_to_glenum(struct gl_context *ctx, return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES; case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES; + + case MESA_FORMAT_ATC_RGB: + return GL_ATC_RGB_AMD; + case MESA_FORMAT_ATC_RGBA_EXPLICIT: + return GL_ATC_RGBA_EXPLICIT_ALPHA_AMD; + case MESA_FORMAT_ATC_RGBA_INTERPOLATED: + return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; + default: _mesa_problem(ctx, "Unexpected mesa texture format in" " _mesa_compressed_format_to_glenum()"); diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index a43915e18d9..1efdd7dd902 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -176,7 +176,7 @@ oes_float_internal_format(const struct gl_context *ctx, /** * Install gl_texture_image in a gl_texture_object according to the target * and level parameters. - * + * * \param tObj texture object. * \param target texture target. * \param level image level. @@ -1366,6 +1366,9 @@ compressedteximage_only_format(GLenum format) case GL_PALETTE8_R5_G6_B5_OES: case GL_PALETTE8_RGBA4_OES: case GL_PALETTE8_RGB5_A1_OES: + case GL_ATC_RGB_AMD: + case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: + case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: return true; default: return false; diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c index e8f4eb598a5..ed8df7bab64 100644 --- a/src/mesa/swrast/s_texfetch.c +++ b/src/mesa/swrast/s_texfetch.c @@ -464,7 +464,11 @@ texfetch_funcs[] = FETCH_NULL(SRGB8_ALPHA8_ASTC_5x5x5), FETCH_NULL(SRGB8_ALPHA8_ASTC_6x5x5), FETCH_NULL(SRGB8_ALPHA8_ASTC_6x6x5), - FETCH_NULL(SRGB8_ALPHA8_ASTC_6x6x6) + FETCH_NULL(SRGB8_ALPHA8_ASTC_6x6x6), + + FETCH_NULL(ATC_RGB), + FETCH_NULL(ATC_RGBA_EXPLICIT), + FETCH_NULL(ATC_RGBA_INTERPOLATED) }; -- 2.30.2