lima: add RGBA5551 and RGBA4444 formats
authorVasily Khoruzhick <anarsoul@gmail.com>
Wed, 26 Feb 2020 07:26:36 +0000 (23:26 -0800)
committerVasily Khoruzhick <anarsoul@gmail.com>
Mon, 2 Mar 2020 20:48:44 +0000 (12:48 -0800)
We also need to set channel_layout in pp_frame reg (previously known as
foureight) depending on cbuf format.

Reviewed-by: Andreas Baierl <ichgeh@imkreisrum.de>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3972>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3972>

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

index e57139af660c56b6613caa93794c20f5f076f125..126a9a5c59c85e3972250ce2cb8e83670f79a17c 100644 (file)
@@ -23,6 +23,7 @@
  *
  */
 
+#include <stdint.h>
 #include <stdlib.h>
 
 #include <util/macros.h>
@@ -33,6 +34,8 @@
 #define LIMA_TEXEL_FORMAT_A8           0x0a
 #define LIMA_TEXEL_FORMAT_I8           0x0b
 #define LIMA_TEXEL_FORMAT_BGR_565      0x0e
+#define LIMA_TEXEL_FORMAT_BGRA_5551    0x0f
+#define LIMA_TEXEL_FORMAT_BGRA_4444    0x10
 #define LIMA_TEXEL_FORMAT_L8A8         0x11
 #define LIMA_TEXEL_FORMAT_L16          0x12
 #define LIMA_TEXEL_FORMAT_A16          0x13
@@ -45,6 +48,8 @@
 #define LIMA_TEXEL_FORMAT_NONE         -1
 
 #define LIMA_PIXEL_FORMAT_B5G6R5       0x00
+#define LIMA_PIXEL_FORMAT_B5G5R5A1     0x01
+#define LIMA_PIXEL_FORMAT_B4G4R4A4     0x02
 #define LIMA_PIXEL_FORMAT_B8G8R8A8     0x03
 #define LIMA_PIXEL_FORMAT_Z16          0x0e
 #define LIMA_PIXEL_FORMAT_Z24S8        0x0f
@@ -55,34 +60,39 @@ struct lima_format {
    int texel;
    int pixel;
    bool swap_r_b;
+   uint32_t channel_layout;
 };
 
-#define LIMA_FORMAT(pipe, tex, pix, swap)                \
-   [PIPE_FORMAT_##pipe] = {                              \
-      .present = true, .texel = LIMA_TEXEL_FORMAT_##tex, \
+#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,                        \
    }
 
 static const struct lima_format lima_format_table[] = {
-   LIMA_FORMAT(R8G8B8A8_UNORM,     RGBA_8888, B8G8R8A8, true),
-   LIMA_FORMAT(B8G8R8A8_UNORM,     RGBA_8888, B8G8R8A8, false),
-   LIMA_FORMAT(R8G8B8A8_SRGB,      RGBA_8888, B8G8R8A8, true),
-   LIMA_FORMAT(B8G8R8A8_SRGB,      RGBA_8888, B8G8R8A8, false),
-   LIMA_FORMAT(R8G8B8X8_UNORM,     RGBX_8888, B8G8R8A8, true),
-   LIMA_FORMAT(B8G8R8X8_UNORM,     RGBX_8888, B8G8R8A8, false),
-   LIMA_FORMAT(B5G6R5_UNORM,       BGR_565,   B5G6R5,   false),
-   LIMA_FORMAT(Z24_UNORM_S8_UINT,  Z24S8,     Z24S8,    false),
-   LIMA_FORMAT(Z24X8_UNORM,        Z24S8,     Z24S8,    false),
+   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,  Z24S8,     Z24S8,    false, 0x0000),
+   LIMA_FORMAT(Z24X8_UNORM,        Z24S8,     Z24S8,    false, 0x0000),
    /* Blob uses L16 for Z16 */
-   LIMA_FORMAT(Z16_UNORM,          L16,       Z16,      false),
-   LIMA_FORMAT(L16_UNORM,          L16,       NONE,     false),
-   LIMA_FORMAT(L8_UNORM,           L8,        NONE,     false),
-   LIMA_FORMAT(A16_UNORM,          A16,       NONE,     false),
-   LIMA_FORMAT(A8_UNORM,           A8,        NONE,     false),
-   LIMA_FORMAT(I16_UNORM,          I16,       NONE,     false),
-   LIMA_FORMAT(I8_UNORM,           I8,        NONE,     false),
-   LIMA_FORMAT(L8A8_UNORM,         L8A8,      NONE,     false),
-   LIMA_FORMAT(ETC1_RGB8,          ETC1_RGB8, NONE,     false),
+   LIMA_FORMAT(Z16_UNORM,          L16,       Z16,      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),
 };
 
 static const struct lima_format *
@@ -134,3 +144,9 @@ lima_format_get_swap_rb(enum pipe_format f)
 {
    return lima_format_table[f].swap_r_b;
 }
+
+uint32_t
+lima_format_get_channel_layout(enum pipe_format f)
+{
+   return lima_format_table[f].channel_layout;
+}
index 3caa0994573303e255ff7899b7728c15cd04c72d..e3d7e9f9441e79a4efe1b50cc67fbe0877339d97 100644 (file)
@@ -33,5 +33,6 @@ 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);
 bool lima_format_get_swap_rb(enum pipe_format f);
+uint32_t lima_format_get_channel_layout(enum pipe_format f);
 
 #endif
index acf365cbcc2005cff8bb6beefa78a12c1c8e637b..4d35640592f9ecb165ee86583291d6a13af17d06 100644 (file)
@@ -63,7 +63,7 @@ struct lima_pp_frame_reg {
    uint32_t onscreen;
    uint32_t blocking;
    uint32_t scale;
-   uint32_t foureight;
+   uint32_t channel_layout;
 };
 
 struct lima_pp_wb_reg {
index 7cdf585c77fa803d3c54a501e8b954b5bb9aa543..3a00d6892426b3efc0942428f46b1ac64cfb7e97 100644 (file)
@@ -763,7 +763,8 @@ lima_pack_wb_zsbuf_reg(struct lima_job *job, uint32_t *wb_reg, int wb_idx)
 }
 
 static void
-lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *wb_reg, int wb_idx)
+lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *frame_reg,
+                      uint32_t *wb_reg, int wb_idx)
 {
    struct lima_job_fb_info *fb = &job->fb;
    struct pipe_surface *cbuf = job->key.cbuf;
@@ -773,6 +774,9 @@ lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *wb_reg, int wb_idx)
    uint32_t format = lima_format_get_pixel(cbuf->format);
    bool swap_channels = lima_format_get_swap_rb(cbuf->format);
 
+   struct lima_pp_frame_reg *frame = (void *)frame_reg;
+   frame->channel_layout = lima_format_get_channel_layout(cbuf->format);
+
    struct lima_pp_wb_reg *wb = (void *)wb_reg;
    wb[wb_idx].type = 0x02; /* 2 for color buffer */
    wb[wb_idx].address = res->bo->va + res->levels[level].offset + layer * res->levels[level].layer_stride;
@@ -824,10 +828,12 @@ lima_pack_pp_frame_reg(struct lima_job *job, uint32_t *frame_reg,
    frame->dubya = 0x77;
    frame->onscreen = 1;
    frame->blocking = (fb->shift_min << 28) | (fb->shift_h << 16) | fb->shift_w;
-   frame->foureight = 0x8888;
+
+   /* Set default layout to 8888 */
+   frame->channel_layout = 0x8888;
 
    if (job->key.cbuf && (job->resolve & PIPE_CLEAR_COLOR0))
-      lima_pack_wb_cbuf_reg(job, wb_reg, wb_idx++);
+      lima_pack_wb_cbuf_reg(job, frame_reg, wb_reg, wb_idx++);
 
    if (job->key.zsbuf &&
        (job->resolve & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)))