lima: add texel format table
authorVasily Khoruzhick <anarsoul@gmail.com>
Wed, 7 Aug 2019 02:54:04 +0000 (19:54 -0700)
committerVasily Khoruzhick <anarsoul@gmail.com>
Fri, 9 Aug 2019 02:17:20 +0000 (19:17 -0700)
Introduce a table for supported texel formats and use it to check
whether format is supported and for converting pipe format to lima
texel format.

Reviewed-by: Qiang Yu <yuq825@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
src/gallium/drivers/lima/lima_screen.c
src/gallium/drivers/lima/lima_texture.c
src/gallium/drivers/lima/lima_texture.h

index 8e337425f7add310e8f4453971ccac7e44dbc4df..13b5599c1a867cfed27878dc78e29046a5e9dbbe 100644 (file)
@@ -38,6 +38,7 @@
 #include "lima_program.h"
 #include "lima_bo.h"
 #include "lima_fence.h"
+#include "lima_texture.h"
 #include "ir/lima_ir.h"
 
 #include "xf86drm.h"
@@ -320,22 +321,8 @@ lima_screen_is_format_supported(struct pipe_screen *pscreen,
       }
    }
 
-   if (usage & PIPE_BIND_SAMPLER_VIEW) {
-      switch (format) {
-      case PIPE_FORMAT_R8G8B8X8_UNORM:
-      case PIPE_FORMAT_R8G8B8A8_UNORM:
-      case PIPE_FORMAT_B8G8R8X8_UNORM:
-      case PIPE_FORMAT_B8G8R8A8_UNORM:
-      case PIPE_FORMAT_A8B8G8R8_SRGB:
-      case PIPE_FORMAT_B8G8R8A8_SRGB:
-      case PIPE_FORMAT_Z16_UNORM:
-      case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-      case PIPE_FORMAT_Z24X8_UNORM:
-         break;
-      default:
-         return false;
-      }
-   }
+   if (usage & PIPE_BIND_SAMPLER_VIEW)
+      return lima_texel_format_supported(format);
 
    return true;
 }
index ead5e79a02ee7f96884532186aa9c0dc8b51729c..d2f317b5e1a741c924257b2e4a7b7ad89add94a8 100644 (file)
 
 #include <drm-uapi/lima_drm.h>
 
+#define LIMA_TEXEL_FORMAT_L8           0x09
+#define LIMA_TEXEL_FORMAT_A8           0x0a
+#define LIMA_TEXEL_FORMAT_I8           0x0b
 #define LIMA_TEXEL_FORMAT_BGR_565      0x0e
-#define LIMA_TEXEL_FORMAT_Z16          0x12
+#define LIMA_TEXEL_FORMAT_L8A8         0x11
+#define LIMA_TEXEL_FORMAT_L16          0x12
+#define LIMA_TEXEL_FORMAT_A16          0x13
+#define LIMA_TEXEL_FORMAT_I16          0x14
 #define LIMA_TEXEL_FORMAT_RGB_888      0x15
 #define LIMA_TEXEL_FORMAT_RGBA_8888    0x16
 #define LIMA_TEXEL_FORMAT_RGBX_8888    0x17
 
 #define lima_tex_list_size 64
 
-static uint32_t pipe_format_to_lima(enum pipe_format pformat)
+typedef struct {
+   bool present;
+   uint32_t lima_format;
+   bool swap_r_b;
+} lima_format;
+
+#define LIMA_FORMAT(pipe, lima, swap) \
+        [PIPE_FORMAT_##pipe] = { .present = true, .lima_format = lima, \
+                                 .swap_r_b = swap }
+
+static const lima_format lima_format_table[] = {
+   LIMA_FORMAT(R8G8B8A8_UNORM, LIMA_TEXEL_FORMAT_RGBA_8888, true),
+   LIMA_FORMAT(B8G8R8A8_UNORM, LIMA_TEXEL_FORMAT_RGBA_8888, false),
+   LIMA_FORMAT(R8G8B8A8_SRGB, LIMA_TEXEL_FORMAT_RGBA_8888, true),
+   LIMA_FORMAT(B8G8R8A8_SRGB, LIMA_TEXEL_FORMAT_RGBA_8888, false),
+   LIMA_FORMAT(R8G8B8X8_UNORM, LIMA_TEXEL_FORMAT_RGBX_8888, true),
+   LIMA_FORMAT(B8G8R8X8_UNORM, LIMA_TEXEL_FORMAT_RGBX_8888, false),
+   LIMA_FORMAT(R8G8B8_UNORM, LIMA_TEXEL_FORMAT_RGB_888, true),
+   LIMA_FORMAT(B5G6R5_UNORM, LIMA_TEXEL_FORMAT_BGR_565, false),
+   LIMA_FORMAT(Z24_UNORM_S8_UINT, LIMA_TEXEL_FORMAT_Z24S8, false),
+   LIMA_FORMAT(Z24X8_UNORM, LIMA_TEXEL_FORMAT_Z24S8, false),
+   /* Blob uses L16 for Z16 */
+   LIMA_FORMAT(Z16_UNORM, LIMA_TEXEL_FORMAT_L16, false),
+   LIMA_FORMAT(L16_UNORM, LIMA_TEXEL_FORMAT_L16, false),
+   LIMA_FORMAT(L8_UNORM, LIMA_TEXEL_FORMAT_L8, false),
+   LIMA_FORMAT(A16_UNORM, LIMA_TEXEL_FORMAT_A16, false),
+   LIMA_FORMAT(A8_UNORM, LIMA_TEXEL_FORMAT_A8, false),
+   LIMA_FORMAT(I16_UNORM, LIMA_TEXEL_FORMAT_I16, false),
+   LIMA_FORMAT(I8_UNORM, LIMA_TEXEL_FORMAT_I8, false),
+   LIMA_FORMAT(L8A8_UNORM, LIMA_TEXEL_FORMAT_L8A8, false),
+};
+
+bool
+lima_texel_format_supported(enum pipe_format pformat)
 {
-   unsigned swap_chans = 0, flag1 = 0, format;
+   if (pformat >= ARRAY_SIZE(lima_format_table))
+      return false;
 
-   switch (pformat) {
-   case PIPE_FORMAT_R8G8B8A8_UNORM:
-      swap_chans = 1;
-   case PIPE_FORMAT_B8G8R8A8_UNORM:
-      format = LIMA_TEXEL_FORMAT_RGBA_8888;
-      break;
-   case PIPE_FORMAT_R8G8B8X8_UNORM:
-      swap_chans = 1;
-   case PIPE_FORMAT_B8G8R8X8_UNORM:
-      format = LIMA_TEXEL_FORMAT_RGBX_8888;
-      break;
-   case PIPE_FORMAT_R8G8B8_UNORM:
-      swap_chans = 1;
-      format = LIMA_TEXEL_FORMAT_RGB_888;
-      break;
-   case PIPE_FORMAT_B5G6R5_UNORM:
-      format = LIMA_TEXEL_FORMAT_BGR_565;
-      break;
-   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-   case PIPE_FORMAT_Z24X8_UNORM:
-      format = LIMA_TEXEL_FORMAT_Z24S8;
-      break;
-   case PIPE_FORMAT_Z16_UNORM:
-      format = LIMA_TEXEL_FORMAT_Z16;
-      break;
-   default:
-      assert(0);
-      break;
-   }
-
-   return (swap_chans << 7) | (flag1 << 6) | format;
+   return lima_format_table[pformat].present;
 }
 
 void
@@ -100,7 +110,11 @@ lima_texture_desc_set_res(struct lima_context *ctx, uint32_t *desc,
       height = u_minify(height, first_level);
    }
 
-   desc[0] |= pipe_format_to_lima(prsc->format);
+   assert(prsc->format < ARRAY_SIZE(lima_format_table));
+   assert(lima_format_table[prsc->format].present);
+
+   desc[0] |= lima_format_table[prsc->format].lima_format;
+   desc[0] |= lima_format_table[prsc->format].swap_r_b ? (1 << 7) : 0;
    desc[2] |= (width << 22);
    desc[3] |= 0x10000 | (height << 3) | (width >> 10);
 
index bf7d735c16867950015462b67bff10b2f1bcafaf..14cf466ecd611e507480816fe00e3e720d9516b6 100644 (file)
@@ -31,5 +31,6 @@ void lima_texture_desc_set_res(struct lima_context *ctx, uint32_t *desc,
                                struct pipe_resource *prsc,
                                unsigned first_level, unsigned last_level);
 void lima_update_textures(struct lima_context *ctx);
+bool lima_texel_format_supported(enum pipe_format pformat);
 
 #endif