[Mesa-dev] [RFC 09/10] i965/surface_formats: add support for 2D ASTC surface formats

Nanley Chery nanleychery at gmail.com
Tue May 19 17:48:17 PDT 2015


From: Nanley Chery <nanley.g.chery at intel.com>

Intel surface formats default to LDR unless there is hardware
support for HDR and the texture is able to be processed in HDR mode.

Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
---
 src/mesa/drivers/dri/i965/brw_defines.h         | 36 +++++++++++++
 src/mesa/drivers/dri/i965/brw_surface_formats.c | 67 ++++++++++++++++++++++++-
 2 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h
index dedc381..6d5ec02 100644
--- a/src/mesa/drivers/dri/i965/brw_defines.h
+++ b/src/mesa/drivers/dri/i965/brw_defines.h
@@ -266,6 +266,7 @@
 
 /* Surface state DW0 */
 #define GEN8_SURFACE_IS_ARRAY                       (1 << 28)
+
 #define GEN8_SURFACE_VALIGN_4                       (1 << 16)
 #define GEN8_SURFACE_VALIGN_8                       (2 << 16)
 #define GEN8_SURFACE_VALIGN_16                      (3 << 16)
@@ -504,6 +505,40 @@
 #define BRW_SURFACEFORMAT_R8G8B8_UINT                    0x1C8
 #define BRW_SURFACEFORMAT_R8G8B8_SINT                    0x1C9
 #define BRW_SURFACEFORMAT_RAW                            0x1FF
+
+#define GEN9_SURFACE_ASTC_HDR_FORMAT_BIT                 0x100
+#define GEN9_SURFACE_ASTC_ENABLE                         0x200
+
+/* The following formats have GEN9_SURFACE_ASTC_ENABLE built in: */
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_4x4_U8sRGB         0x200
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_5x4_U8sRGB         0x208
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_5x5_U8sRGB         0x209
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_6x5_U8sRGB         0x211
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_6x6_U8sRGB         0x212
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_8x5_U8sRGB         0x221
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_8x6_U8sRGB         0x222
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_8x8_U8sRGB         0x224
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x5_U8sRGB        0x231
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x6_U8sRGB        0x232
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x8_U8sRGB        0x234
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x10_U8sRGB       0x236
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_12x10_U8sRGB       0x23E
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_12x12_U8sRGB       0x23F
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_4x4_FLT16          0x240
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_5x4_FLT16          0x248
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_5x5_FLT16          0x249
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_6x5_FLT16          0x251
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_6x6_FLT16          0x252
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_8x5_FLT16          0x261
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_8x6_FLT16          0x262
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_8x8_FLT16          0x264
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x5_FLT16         0x271
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x6_FLT16         0x272
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x8_FLT16         0x274
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_10x10_FLT16        0x276
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_12x10_FLT16        0x27E
+#define BRW_SURFACEFORMAT_ASTC_LDR_2D_12x12_FLT16        0x27F
+
 #define BRW_SURFACE_FORMAT_SHIFT	18
 #define BRW_SURFACE_FORMAT_MASK		INTEL_MASK(26, 18)
 
@@ -519,6 +554,7 @@
 #define BRW_SURFACE_BUFFER  4
 #define BRW_SURFACE_NULL    7
 
+
 #define GEN7_SURFACE_IS_ARRAY           (1 << 28)
 #define GEN7_SURFACE_VALIGN_2           (0 << 16)
 #define GEN7_SURFACE_VALIGN_4           (1 << 16)
diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c b/src/mesa/drivers/dri/i965/brw_surface_formats.c
index 0501606..83313d8 100644
--- a/src/mesa/drivers/dri/i965/brw_surface_formats.c
+++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c
@@ -307,6 +307,34 @@ const struct surface_format_info surface_formats[] = {
    SF( x,  x,  x,  x,  x,  x,  x,  x,  x, ETC2_EAC_SRGB8_A8)
    SF( x,  x,  x,  x,  x,  x,  x,  x,  x, R8G8B8_UINT)
    SF( x,  x,  x,  x,  x,  x,  x,  x,  x, R8G8B8_SINT)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_4x4_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_5x4_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_5x5_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_6x5_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_6x6_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_8x5_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_8x6_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_8x8_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x5_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x6_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x8_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x10_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_12x10_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_12x12_FLT16)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_4x4_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_5x4_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_5x5_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_6x5_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_6x6_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_8x5_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_8x6_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_8x8_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x5_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x6_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x8_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_10x10_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_12x10_U8sRGB)
+   SF(90, 90,  x,  x,  x,  x,  x,  x,  x, ASTC_LDR_2D_12x12_U8sRGB)
 };
 #undef x
 #undef Y
@@ -503,6 +531,35 @@ brw_format_for_mesa_format(mesa_format mesa_format)
       [MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT] = BRW_SURFACEFORMAT_BC6H_SF16,
       [MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT] = BRW_SURFACEFORMAT_BC6H_UF16,
 
+      [MESA_FORMAT_ASTC_4x4_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_4x4_FLT16,
+      [MESA_FORMAT_ASTC_5x4_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_5x4_FLT16,
+      [MESA_FORMAT_ASTC_5x5_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_5x5_FLT16,
+      [MESA_FORMAT_ASTC_6x5_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_6x5_FLT16,
+      [MESA_FORMAT_ASTC_6x6_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_6x6_FLT16,
+      [MESA_FORMAT_ASTC_8x5_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_8x5_FLT16,
+      [MESA_FORMAT_ASTC_8x6_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_8x6_FLT16,
+      [MESA_FORMAT_ASTC_8x8_RGBA]           = BRW_SURFACEFORMAT_ASTC_LDR_2D_8x8_FLT16,
+      [MESA_FORMAT_ASTC_10x5_RGBA]          = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x5_FLT16,
+      [MESA_FORMAT_ASTC_10x6_RGBA]          = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x6_FLT16,
+      [MESA_FORMAT_ASTC_10x8_RGBA]          = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x8_FLT16,
+      [MESA_FORMAT_ASTC_10x10_RGBA]         = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x10_FLT16,
+      [MESA_FORMAT_ASTC_12x10_RGBA]         = BRW_SURFACEFORMAT_ASTC_LDR_2D_12x10_FLT16,
+      [MESA_FORMAT_ASTC_12x12_RGBA]         = BRW_SURFACEFORMAT_ASTC_LDR_2D_12x12_FLT16,
+      [MESA_FORMAT_ASTC_4x4_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_4x4_U8sRGB,
+      [MESA_FORMAT_ASTC_5x4_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_5x4_U8sRGB,
+      [MESA_FORMAT_ASTC_5x5_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_5x5_U8sRGB,
+      [MESA_FORMAT_ASTC_6x5_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_6x5_U8sRGB,
+      [MESA_FORMAT_ASTC_6x6_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_6x6_U8sRGB,
+      [MESA_FORMAT_ASTC_8x5_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_8x5_U8sRGB,
+      [MESA_FORMAT_ASTC_8x6_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_8x6_U8sRGB,
+      [MESA_FORMAT_ASTC_8x8_SRGB8_ALPHA8]   = BRW_SURFACEFORMAT_ASTC_LDR_2D_8x8_U8sRGB,
+      [MESA_FORMAT_ASTC_10x5_SRGB8_ALPHA8]  = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x5_U8sRGB,
+      [MESA_FORMAT_ASTC_10x6_SRGB8_ALPHA8]  = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x6_U8sRGB,
+      [MESA_FORMAT_ASTC_10x8_SRGB8_ALPHA8]  = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x8_U8sRGB,
+      [MESA_FORMAT_ASTC_10x10_SRGB8_ALPHA8] = BRW_SURFACEFORMAT_ASTC_LDR_2D_10x10_U8sRGB,
+      [MESA_FORMAT_ASTC_12x10_SRGB8_ALPHA8] = BRW_SURFACEFORMAT_ASTC_LDR_2D_12x10_U8sRGB,
+      [MESA_FORMAT_ASTC_12x12_SRGB8_ALPHA8] = BRW_SURFACEFORMAT_ASTC_LDR_2D_12x12_U8sRGB,
+
       [MESA_FORMAT_A_SNORM8] = 0,
       [MESA_FORMAT_L_SNORM8] = 0,
       [MESA_FORMAT_L8A8_SNORM] = 0,
@@ -732,6 +789,7 @@ translate_tex_format(struct brw_context *brw,
                      mesa_format mesa_format,
 		     GLenum srgb_decode)
 {
+   GLuint brw_fmt;
    struct gl_context *ctx = &brw->ctx;
    if (srgb_decode == GL_SKIP_DECODE_EXT)
       mesa_format = _mesa_get_srgb_format_linear(mesa_format);
@@ -769,8 +827,13 @@ translate_tex_format(struct brw_context *brw,
       return brw_format_for_mesa_format(mesa_format);
 
    default:
-      assert(brw_format_for_mesa_format(mesa_format) != 0);
-      return brw_format_for_mesa_format(mesa_format);
+      brw_fmt = brw_format_for_mesa_format(mesa_format);
+      assert(brw_fmt != 0);
+      if (brw_fmt & GEN9_SURFACE_ASTC_ENABLE &&
+          ctx->Extensions.KHR_texture_compression_astc_hdr &&
+          _mesa_get_format_color_encoding(mesa_format) == GL_LINEAR)
+         brw_fmt |= GEN9_SURFACE_ASTC_HDR_FORMAT_BIT;
+      return brw_fmt;
    }
 }
 
-- 
2.4.1



More information about the mesa-dev mailing list