From: Alyssa Rosenzweig Date: Mon, 17 Jun 2019 21:26:08 +0000 (-0700) Subject: panfrost: Refactor texture targets X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=83c02a5ea99cd1c9b196cb79f00e6dda5ffe738c;p=mesa.git panfrost: Refactor texture targets 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 --- diff --git a/src/gallium/drivers/panfrost/include/panfrost-job.h b/src/gallium/drivers/panfrost/include/panfrost-job.h index 12200c373f1..b982b887a47 100644 --- a/src/gallium/drivers/panfrost/include/panfrost-job.h +++ b/src/gallium/drivers/panfrost/include/panfrost-job.h @@ -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 */ diff --git a/src/gallium/drivers/panfrost/midgard/disassemble.c b/src/gallium/drivers/panfrost/midgard/disassemble.c index 501846fab1c..58cfa131be5 100644 --- a/src/gallium/drivers/panfrost/midgard/disassemble.c +++ b/src/gallium/drivers/panfrost/midgard/disassemble.c @@ -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) diff --git a/src/gallium/drivers/panfrost/midgard/midgard.h b/src/gallium/drivers/panfrost/midgard/midgard.h index a9b05e8a285..43fc3a64774 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard.h +++ b/src/gallium/drivers/panfrost/midgard/midgard.h @@ -29,6 +29,7 @@ #include #include +#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 diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c index 304bcf8ddfa..1cc551b603c 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c +++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c @@ -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"); diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 65f9255dd72..954287f4df8 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -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 }, diff --git a/src/gallium/drivers/panfrost/pandecode/decode.c b/src/gallium/drivers/panfrost/pandecode/decode.c index 1f2564e45dc..01c9d45c3fd 100644 --- a/src/gallium/drivers/panfrost/pandecode/decode.c +++ b/src/gallium/drivers/panfrost/pandecode/decode.c @@ -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 */