lima: split pixel and texel format tables
authorVasily Khoruzhick <anarsoul@gmail.com>
Thu, 19 Mar 2020 02:21:57 +0000 (19:21 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 20 Mar 2020 17:00:10 +0000 (17:00 +0000)
This is preparation for the next commit where we may need different
swap_r_b flags for pixel and texel formats.

Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4241>

src/gallium/drivers/lima/lima_format.c
src/gallium/drivers/lima/lima_format.h
src/gallium/drivers/lima/lima_job.c
src/gallium/drivers/lima/lima_texture.c

index 524d12773e8c6f6e616f58a9732c30a92ad33fed..fad0f8976ef84b0cb6d3b93c9dae7d85ddf58955 100644 (file)
@@ -47,7 +47,6 @@
 #define LIMA_TEXEL_FORMAT_Z24X8        0x2c
 /* This format is only used for depth/stencil reload */
 #define LIMA_TEXEL_FORMAT_Z24S8_RLD    0x32
-#define LIMA_TEXEL_FORMAT_NONE         -1
 
 #define LIMA_PIXEL_FORMAT_B5G6R5       0x00
 #define LIMA_PIXEL_FORMAT_B5G5R5A1     0x01
 #define LIMA_PIXEL_FORMAT_B8G8R8A8     0x03
 #define LIMA_PIXEL_FORMAT_Z16          0x0e
 #define LIMA_PIXEL_FORMAT_Z24S8        0x0f
-#define LIMA_PIXEL_FORMAT_NONE         -1
 
 struct lima_format {
    bool present;
-   int texel;
-   int pixel;
+   int format;
    bool swap_r_b;
    uint32_t channel_layout;
 };
 
-#define LIMA_FORMAT(pipe, tex, pix, swap, ch_layout)      \
-   [PIPE_FORMAT_##pipe] = {                               \
-      .present = true, .texel = LIMA_TEXEL_FORMAT_##tex,  \
-      .pixel = LIMA_PIXEL_FORMAT_##pix, .swap_r_b = swap, \
-      .channel_layout = ch_layout,                        \
+#define LIMA_TEXEL_FORMAT(pipe, tex, swap)                  \
+   [PIPE_FORMAT_##pipe] = {                                 \
+      .present = true, .format = LIMA_TEXEL_FORMAT_##tex,   \
+      .swap_r_b = swap                                      \
    }
 
-static const struct lima_format lima_format_table[] = {
-   LIMA_FORMAT(R8G8B8A8_UNORM,     RGBA_8888, B8G8R8A8, true,  0x8888),
-   LIMA_FORMAT(B8G8R8A8_UNORM,     RGBA_8888, B8G8R8A8, false, 0x8888),
-   LIMA_FORMAT(R8G8B8A8_SRGB,      RGBA_8888, B8G8R8A8, true,  0x8888),
-   LIMA_FORMAT(B8G8R8A8_SRGB,      RGBA_8888, B8G8R8A8, false, 0x8888),
-   LIMA_FORMAT(R8G8B8X8_UNORM,     RGBX_8888, B8G8R8A8, true,  0x8888),
-   LIMA_FORMAT(B8G8R8X8_UNORM,     RGBX_8888, B8G8R8A8, false, 0x8888),
-   LIMA_FORMAT(B5G6R5_UNORM,       BGR_565,   B5G6R5,   false, 0x8565),
-   /* BGRA_5551 seems to need channel layout 0x8565, it's not a typo */
-   LIMA_FORMAT(B5G5R5A1_UNORM,     BGRA_5551, B5G5R5A1, false, 0x8565),
-   LIMA_FORMAT(B4G4R4A4_UNORM,     BGRA_4444, B4G4R4A4, false, 0x8444),
-   LIMA_FORMAT(Z24_UNORM_S8_UINT,  Z24X8,     Z24S8,    false, 0x0000),
-   LIMA_FORMAT(Z24X8_UNORM,        Z24X8,     Z24S8,    false, 0x0000),
-   LIMA_FORMAT(L16_UNORM,          L16,       NONE,     false, 0x0000),
-   LIMA_FORMAT(L8_UNORM,           L8,        NONE,     false, 0x0000),
-   LIMA_FORMAT(A16_UNORM,          A16,       NONE,     false, 0x0000),
-   LIMA_FORMAT(A8_UNORM,           A8,        NONE,     false, 0x0000),
-   LIMA_FORMAT(I16_UNORM,          I16,       NONE,     false, 0x0000),
-   LIMA_FORMAT(I8_UNORM,           I8,        NONE,     false, 0x0000),
-   LIMA_FORMAT(L8A8_UNORM,         L8A8,      NONE,     false, 0x0000),
-   LIMA_FORMAT(ETC1_RGB8,          ETC1_RGB8, NONE,     false, 0x8888),
+#define LIMA_PIXEL_FORMAT(pipe, pix, swap, ch_layout)       \
+   [PIPE_FORMAT_##pipe] = {                                 \
+      .present = true, .format = LIMA_PIXEL_FORMAT_##pix,   \
+      .swap_r_b = swap, .channel_layout = ch_layout         \
+   }
+
+static const struct lima_format lima_texel_formats[] = {
+   LIMA_TEXEL_FORMAT(R8G8B8A8_UNORM,     RGBA_8888, true),
+   LIMA_TEXEL_FORMAT(B8G8R8A8_UNORM,     RGBA_8888, false),
+   LIMA_TEXEL_FORMAT(R8G8B8A8_SRGB,      RGBA_8888, true),
+   LIMA_TEXEL_FORMAT(B8G8R8A8_SRGB,      RGBA_8888, false),
+   LIMA_TEXEL_FORMAT(R8G8B8X8_UNORM,     RGBX_8888, true),
+   LIMA_TEXEL_FORMAT(B8G8R8X8_UNORM,     RGBX_8888, false),
+   LIMA_TEXEL_FORMAT(B5G6R5_UNORM,       BGR_565,   false),
+   LIMA_TEXEL_FORMAT(B5G5R5A1_UNORM,     BGRA_5551, false),
+   LIMA_TEXEL_FORMAT(B4G4R4A4_UNORM,     BGRA_4444, false),
+   LIMA_TEXEL_FORMAT(Z24_UNORM_S8_UINT,  Z24X8,     false),
+   LIMA_TEXEL_FORMAT(Z24X8_UNORM,        Z24X8,     false),
+   LIMA_TEXEL_FORMAT(L16_UNORM,          L16,       false),
+   LIMA_TEXEL_FORMAT(L8_UNORM,           L8,        false),
+   LIMA_TEXEL_FORMAT(A16_UNORM,          A16,       false),
+   LIMA_TEXEL_FORMAT(A8_UNORM,           A8,        false),
+   LIMA_TEXEL_FORMAT(I16_UNORM,          I16,       false),
+   LIMA_TEXEL_FORMAT(I8_UNORM,           I8,        false),
+   LIMA_TEXEL_FORMAT(L8A8_UNORM,         L8A8,      false),
+   LIMA_TEXEL_FORMAT(ETC1_RGB8,          ETC1_RGB8, false),
+};
+
+static const struct lima_format lima_pixel_formats[] = {
+   LIMA_PIXEL_FORMAT(R8G8B8A8_UNORM,     B8G8R8A8, true,  0x8888),
+   LIMA_PIXEL_FORMAT(B8G8R8A8_UNORM,     B8G8R8A8, false, 0x8888),
+   LIMA_PIXEL_FORMAT(R8G8B8A8_SRGB,      B8G8R8A8, true,  0x8888),
+   LIMA_PIXEL_FORMAT(B8G8R8A8_SRGB,      B8G8R8A8, false, 0x8888),
+   LIMA_PIXEL_FORMAT(R8G8B8X8_UNORM,     B8G8R8A8, true,  0x8888),
+   LIMA_PIXEL_FORMAT(B8G8R8X8_UNORM,     B8G8R8A8, false, 0x8888),
+   LIMA_PIXEL_FORMAT(B5G6R5_UNORM,       B5G6R5,   false, 0x8565),
+   LIMA_PIXEL_FORMAT(B5G5R5A1_UNORM,     B5G5R5A1, false, 0x8565),
+   LIMA_PIXEL_FORMAT(B4G4R4A4_UNORM,     B4G4R4A4, false, 0x8444),
+   LIMA_PIXEL_FORMAT(Z24_UNORM_S8_UINT,  Z24S8,    false, 0x0000),
+   LIMA_PIXEL_FORMAT(Z24X8_UNORM,        Z24S8,    false, 0x0000),
 };
 
 static const struct lima_format *
-get_format(enum pipe_format f)
+get_texel_format(enum pipe_format f)
+{
+   if (f >= ARRAY_SIZE(lima_texel_formats) ||
+       !lima_texel_formats[f].present)
+      return NULL;
+
+   return lima_texel_formats + f;
+}
+
+static const struct lima_format *
+get_pixel_format(enum pipe_format f)
 {
-   if (f >= ARRAY_SIZE(lima_format_table) ||
-       !lima_format_table[f].present)
+   if (f >= ARRAY_SIZE(lima_pixel_formats) ||
+       !lima_pixel_formats[f].present)
       return NULL;
 
-   return lima_format_table + f;
+   return lima_pixel_formats + f;
 }
 
 bool
 lima_format_texel_supported(enum pipe_format f)
 {
-   const struct lima_format *lf = get_format(f);
+   const struct lima_format *lf = get_texel_format(f);
 
    if (!lf)
       return false;
 
-   return lf->texel != LIMA_TEXEL_FORMAT_NONE;
+   return true;
 }
 
 bool
 lima_format_pixel_supported(enum pipe_format f)
 {
-   const struct lima_format *lf = get_format(f);
+   const struct lima_format *lf = get_pixel_format(f);
 
    if (!lf)
       return false;
 
-   return lf->pixel != LIMA_PIXEL_FORMAT_NONE;
+   return true;
 }
 
 int
 lima_format_get_texel(enum pipe_format f)
 {
-   return lima_format_table[f].texel;
+   return lima_texel_formats[f].format;
 }
 
 int
@@ -148,17 +173,23 @@ lima_format_get_texel_reload(enum pipe_format f)
 int
 lima_format_get_pixel(enum pipe_format f)
 {
-   return lima_format_table[f].pixel;
+   return lima_pixel_formats[f].format;
+}
+
+bool
+lima_format_get_texel_swap_rb(enum pipe_format f)
+{
+   return lima_texel_formats[f].swap_r_b;
 }
 
 bool
-lima_format_get_swap_rb(enum pipe_format f)
+lima_format_get_pixel_swap_rb(enum pipe_format f)
 {
-   return lima_format_table[f].swap_r_b;
+   return lima_pixel_formats[f].swap_r_b;
 }
 
 uint32_t
 lima_format_get_channel_layout(enum pipe_format f)
 {
-   return lima_format_table[f].channel_layout;
+   return lima_pixel_formats[f].channel_layout;
 }
index 29faaac3a7bd000ce55638e7ff9b177fc72cbd28..856f8ba5acb98a05d05934494f6b27d096a2e2d3 100644 (file)
@@ -33,7 +33,8 @@ bool lima_format_pixel_supported(enum pipe_format f);
 int lima_format_get_texel(enum pipe_format f);
 int lima_format_get_pixel(enum pipe_format f);
 int lima_format_get_texel_reload(enum pipe_format f);
-bool lima_format_get_swap_rb(enum pipe_format f);
+bool lima_format_get_texel_swap_rb(enum pipe_format f);
+bool lima_format_get_pixel_swap_rb(enum pipe_format f);
 uint32_t lima_format_get_channel_layout(enum pipe_format f);
 
 #endif
index c628ff0a4e6af23b88e60cd5b62e57d626bac03e..58dba52042939cf504b7220cd3541a2db3bbefc1 100644 (file)
@@ -804,7 +804,7 @@ lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *frame_reg,
    int level = cbuf->u.tex.level;
    unsigned layer = cbuf->u.tex.first_layer;
    uint32_t format = lima_format_get_pixel(cbuf->format);
-   bool swap_channels = lima_format_get_swap_rb(cbuf->format);
+   bool swap_channels = lima_format_get_pixel_swap_rb(cbuf->format);
 
    struct lima_pp_frame_reg *frame = (void *)frame_reg;
    frame->channel_layout = lima_format_get_channel_layout(cbuf->format);
index a6cbb97d6356b4e37b696f92c1bcf0e9ee690a52..0258aa23ec9d76bed857e86f930798237e6f6dcb 100644 (file)
@@ -83,7 +83,7 @@ lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc,
    }
 
    desc->format = lima_format_get_texel(prsc->format);
-   desc->swap_r_b = lima_format_get_swap_rb(prsc->format);
+   desc->swap_r_b = lima_format_get_texel_swap_rb(prsc->format);
    desc->width  = width;
    desc->height = height;
    desc->unknown_3_1 = 1;