panfrost: Refactor texture targets
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 17 Jun 2019 21:26:08 +0000 (14:26 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 18 Jun 2019 16:59:28 +0000 (09:59 -0700)
This combines the two cmdstream bits "is_3d" and "is_not_cubemap" into a
single 2-bit texture target selection, noticing it's the same as the
2-bit selection in Midgard and Bifrost texturing ops. Accordingly, we
share this definition and add the missing entry for 1D/buffer textures.

This requires a nontrivial (but functionally similar) refactor of all
parts of the driver to use the new definitions appropriately.
Theoretically, this should add support for buffer textures, but that's
obviously not tested and probably wouldn't work.

While doing so, we notice the sRGB enable bit, which we document and
decode as well here so we don't forget about it.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/include/panfrost-job.h
src/gallium/drivers/panfrost/midgard/disassemble.c
src/gallium/drivers/panfrost/midgard/midgard.h
src/gallium/drivers/panfrost/midgard/midgard_compile.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pandecode/decode.c

index 12200c373f1270518c5e3d7cec24629e9a7a9885..b982b887a47035372999f9af4ddc338bee5fa70e 100644 (file)
@@ -1120,20 +1120,26 @@ enum mali_wrap_mode {
         MALI_WRAP_MIRRORED_REPEAT = 0xC
 };
 
+/* Shared across both command stream and Midgard, and even with Bifrost */
+
+enum mali_texture_type {
+        MALI_TEX_CUBE = 0x0,
+        MALI_TEX_1D = 0x1,
+        MALI_TEX_2D = 0x2,
+        MALI_TEX_3D = 0x3
+};
+
 /* 8192x8192 */
 #define MAX_MIP_LEVELS (13)
 
 /* Cubemap bloats everything up */
-#define MAX_FACES (6)
+#define MAX_CUBE_FACES (6)
 
 /* For each pointer, there is an address and optionally also a stride */
 #define MAX_ELEMENTS (2)
 
 /* Corresponds to the type passed to glTexImage2D and so forth */
 
-/* For usage1 */
-#define MALI_TEX_3D (0x04)
-
 /* Flags for usage2 */
 #define MALI_TEX_MANUAL_STRIDE (0x20)
 
@@ -1141,8 +1147,11 @@ struct mali_texture_format {
         unsigned swizzle : 12;
         enum mali_format format : 8;
 
-        unsigned usage1 : 3;
-        unsigned is_not_cubemap : 1;
+        unsigned srgb : 1;
+        unsigned unknown1 : 1;
+
+        enum mali_texture_type type : 2;
+
         unsigned usage2 : 8;
 } __attribute__((packed));
 
@@ -1174,7 +1183,7 @@ struct mali_texture_descriptor {
         uint32_t unknown6;
         uint32_t unknown7;
 
-        mali_ptr payload[MAX_MIP_LEVELS * MAX_FACES * MAX_ELEMENTS];
+        mali_ptr payload[MAX_MIP_LEVELS * MAX_CUBE_FACES * MAX_ELEMENTS];
 } __attribute__((packed));
 
 /* Used as part of filter_mode */
index 501846fab1c7e03edfdadf1bb9c57084f67a812d..58cfa131be5af1ea5606c10bc94bedc46c8de17c 100644 (file)
@@ -1038,13 +1038,13 @@ print_texture_format(int format)
         printf(".");
 
         switch (format) {
-                DEFINE_CASE(TEXTURE_2D, "2d");
-                DEFINE_CASE(TEXTURE_3D, "3d");
-                DEFINE_CASE(TEXTURE_CUBE, "cube");
+                DEFINE_CASE(MALI_TEX_1D, "1d");
+                DEFINE_CASE(MALI_TEX_2D, "2d");
+                DEFINE_CASE(MALI_TEX_3D, "3d");
+                DEFINE_CASE(MALI_TEX_CUBE, "cube");
 
         default:
-                printf("fmt_%d", format);
-                break;
+                unreachable("Bad format");
         }
 }
 
@@ -1096,6 +1096,8 @@ print_texture_word(uint32_t *word, unsigned tabs)
         /* Specific format in question */
         print_texture_format(texture->format);
 
+        assert(texture->zero == 0);
+
         /* Instruction "modifiers" parallel the ALU instructions. */
 
         if (texture->shadow)
index a9b05e8a28531776b69428d557ad82029e1b8b85..43fc3a6477458e884656f49132787dac22070ac9 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include "panfrost-job.h"
 
 #define MIDGARD_DBG_MSGS               0x0001
 #define MIDGARD_DBG_SHADERS            0x0002
@@ -543,11 +544,6 @@ __attribute__((__packed__))
 #define TEXTURE_OP_LOD 0x12             /* textureLod */
 #define TEXTURE_OP_TEXEL_FETCH 0x14     /* texelFetch */
 
-/* Texture format types, found in format */
-#define TEXTURE_CUBE 0x00
-#define TEXTURE_2D 0x02
-#define TEXTURE_3D 0x03
-
 typedef struct
 __attribute__((__packed__))
 {
@@ -566,7 +562,8 @@ __attribute__((__packed__))
         unsigned cont  : 1;
         unsigned last  : 1;
 
-        unsigned format    : 4;
+        enum mali_texture_type format : 2;
+        unsigned zero : 2;
 
         /* Is a register used to specify the
          * LOD/bias/offset? If set, use the `bias` field as
index 304bcf8ddfa0988f12a9761d32c66be3ff8beab8..1cc551b603c7c49cf2746ec7f914636608f98fbb 100644 (file)
@@ -1366,15 +1366,19 @@ static unsigned
 midgard_tex_format(enum glsl_sampler_dim dim)
 {
         switch (dim) {
+        case GLSL_SAMPLER_DIM_1D:
+        case GLSL_SAMPLER_DIM_BUF:
+                return MALI_TEX_1D;
+
         case GLSL_SAMPLER_DIM_2D:
         case GLSL_SAMPLER_DIM_EXTERNAL:
-                return TEXTURE_2D;
+                return MALI_TEX_2D;
 
         case GLSL_SAMPLER_DIM_3D:
-                return TEXTURE_3D;
+                return MALI_TEX_3D;
 
         case GLSL_SAMPLER_DIM_CUBE:
-                return TEXTURE_CUBE;
+                return MALI_TEX_CUBE;
 
         default:
                 DBG("Unknown sampler dim type\n");
index 65f9255dd725fc765637a935e79f6f3cdc7e6089..954287f4df8c2b3eb13e57ae07ba3d978c95e98c 100644 (file)
@@ -2096,6 +2096,32 @@ panfrost_set_stencil_ref(
         ctx->dirty |= PAN_DIRTY_FS;
 }
 
+static enum mali_texture_type
+panfrost_translate_texture_type(enum pipe_texture_target t)
+{
+        switch (t) {
+                case PIPE_BUFFER:
+                case PIPE_TEXTURE_1D:
+                case PIPE_TEXTURE_1D_ARRAY:
+                        return MALI_TEX_1D;
+
+                case PIPE_TEXTURE_2D:
+                case PIPE_TEXTURE_2D_ARRAY:
+                case PIPE_TEXTURE_RECT:
+                        return MALI_TEX_2D;
+
+                case PIPE_TEXTURE_3D:
+                        return MALI_TEX_3D;
+
+                case PIPE_TEXTURE_CUBE:
+                case PIPE_TEXTURE_CUBE_ARRAY:
+                        return MALI_TEX_CUBE;
+
+                default:
+                        unreachable("Unknown target");
+        }
+}
+
 static struct pipe_sampler_view *
 panfrost_create_sampler_view(
         struct pipe_context *pctx,
@@ -2195,8 +2221,8 @@ panfrost_create_sampler_view(
                         .swizzle = panfrost_translate_swizzle_4(desc->swizzle),
                         .format = format,
 
-                        .usage1 = (texture->target == PIPE_TEXTURE_3D) ? MALI_TEX_3D : 0,
-                        .is_not_cubemap = texture->target != PIPE_TEXTURE_CUBE,
+                        .srgb = false,
+                        .type = panfrost_translate_texture_type(texture->target),
 
                         .usage2 = usage2_layout
                 },
index 1f2564e45dcf832fca51768ac429a18b50bf72b8..01c9d45c3fd8433d37cbb38602d2fdd3fa0f3f75 100644 (file)
@@ -407,6 +407,22 @@ pandecode_wrap_mode_name(enum mali_wrap_mode op)
 }
 #undef DEFINE_CASE
 
+#define DEFINE_CASE(name) case MALI_TEX_## name: return "MALI_TEX_" #name
+static char *
+pandecode_texture_type(enum mali_texture_type type)
+{
+        switch (type) {
+                DEFINE_CASE(1D);
+                DEFINE_CASE(2D);
+                DEFINE_CASE(3D);
+                DEFINE_CASE(CUBE);
+
+        default:
+                unreachable("Unknown case");
+        }
+}
+#undef DEFINE_CASE
+
 static inline char *
 pandecode_decode_fbd_type(enum mali_fbd_type type)
 {
@@ -1520,9 +1536,9 @@ pandecode_replay_vertex_tiler_postfix_pre(const struct mali_vertex_tiler_postfix
 
                                         pandecode_replay_swizzle(f.swizzle);
                                        pandecode_prop("format = %s", pandecode_format_name(f.format));
-
-                                        pandecode_prop("usage1 = 0x%" PRIx32, f.usage1);
-                                        pandecode_prop("is_not_cubemap = %" PRId32, f.is_not_cubemap);
+                                       pandecode_prop("type = %s", pandecode_texture_type(f.type));
+                                        pandecode_prop("srgb = %" PRId32, f.srgb);
+                                        pandecode_prop("unknown1 = %" PRId32, f.unknown1);
                                         pandecode_prop("usage2 = 0x%" PRIx32, f.usage2);
 
                                         pandecode_indent--;
@@ -1555,7 +1571,7 @@ pandecode_replay_vertex_tiler_postfix_pre(const struct mali_vertex_tiler_postfix
                                         bool manual_stride = f.usage2 & MALI_TEX_MANUAL_STRIDE;
 
                                         /* Miptree for each face */
-                                        if (!f.is_not_cubemap)
+                                        if (f.type == MALI_TEX_CUBE)
                                                 bitmap_count *= 6;
 
                                         /* Array of textures */