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 <alyssa.rosenzweig@collabora.com>
This commit is contained in:
Alyssa Rosenzweig 2019-06-17 14:26:08 -07:00
parent bfca21b622
commit 83c02a5ea9
6 changed files with 81 additions and 27 deletions

View file

@ -1120,20 +1120,26 @@ enum mali_wrap_mode {
MALI_WRAP_MIRRORED_REPEAT = 0xC 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 */ /* 8192x8192 */
#define MAX_MIP_LEVELS (13) #define MAX_MIP_LEVELS (13)
/* Cubemap bloats everything up */ /* 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 */ /* For each pointer, there is an address and optionally also a stride */
#define MAX_ELEMENTS (2) #define MAX_ELEMENTS (2)
/* Corresponds to the type passed to glTexImage2D and so forth */ /* Corresponds to the type passed to glTexImage2D and so forth */
/* For usage1 */
#define MALI_TEX_3D (0x04)
/* Flags for usage2 */ /* Flags for usage2 */
#define MALI_TEX_MANUAL_STRIDE (0x20) #define MALI_TEX_MANUAL_STRIDE (0x20)
@ -1141,8 +1147,11 @@ struct mali_texture_format {
unsigned swizzle : 12; unsigned swizzle : 12;
enum mali_format format : 8; enum mali_format format : 8;
unsigned usage1 : 3; unsigned srgb : 1;
unsigned is_not_cubemap : 1; unsigned unknown1 : 1;
enum mali_texture_type type : 2;
unsigned usage2 : 8; unsigned usage2 : 8;
} __attribute__((packed)); } __attribute__((packed));
@ -1174,7 +1183,7 @@ struct mali_texture_descriptor {
uint32_t unknown6; uint32_t unknown6;
uint32_t unknown7; 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)); } __attribute__((packed));
/* Used as part of filter_mode */ /* Used as part of filter_mode */

View file

@ -1038,13 +1038,13 @@ print_texture_format(int format)
printf("."); printf(".");
switch (format) { switch (format) {
DEFINE_CASE(TEXTURE_2D, "2d"); DEFINE_CASE(MALI_TEX_1D, "1d");
DEFINE_CASE(TEXTURE_3D, "3d"); DEFINE_CASE(MALI_TEX_2D, "2d");
DEFINE_CASE(TEXTURE_CUBE, "cube"); DEFINE_CASE(MALI_TEX_3D, "3d");
DEFINE_CASE(MALI_TEX_CUBE, "cube");
default: default:
printf("fmt_%d", format); unreachable("Bad format");
break;
} }
} }
@ -1096,6 +1096,8 @@ print_texture_word(uint32_t *word, unsigned tabs)
/* Specific format in question */ /* Specific format in question */
print_texture_format(texture->format); print_texture_format(texture->format);
assert(texture->zero == 0);
/* Instruction "modifiers" parallel the ALU instructions. */ /* Instruction "modifiers" parallel the ALU instructions. */
if (texture->shadow) if (texture->shadow)

View file

@ -29,6 +29,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "panfrost-job.h"
#define MIDGARD_DBG_MSGS 0x0001 #define MIDGARD_DBG_MSGS 0x0001
#define MIDGARD_DBG_SHADERS 0x0002 #define MIDGARD_DBG_SHADERS 0x0002
@ -543,11 +544,6 @@ __attribute__((__packed__))
#define TEXTURE_OP_LOD 0x12 /* textureLod */ #define TEXTURE_OP_LOD 0x12 /* textureLod */
#define TEXTURE_OP_TEXEL_FETCH 0x14 /* texelFetch */ #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 typedef struct
__attribute__((__packed__)) __attribute__((__packed__))
{ {
@ -566,7 +562,8 @@ __attribute__((__packed__))
unsigned cont : 1; unsigned cont : 1;
unsigned last : 1; unsigned last : 1;
unsigned format : 4; enum mali_texture_type format : 2;
unsigned zero : 2;
/* Is a register used to specify the /* Is a register used to specify the
* LOD/bias/offset? If set, use the `bias` field as * LOD/bias/offset? If set, use the `bias` field as

View file

@ -1366,15 +1366,19 @@ static unsigned
midgard_tex_format(enum glsl_sampler_dim dim) midgard_tex_format(enum glsl_sampler_dim dim)
{ {
switch (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_2D:
case GLSL_SAMPLER_DIM_EXTERNAL: case GLSL_SAMPLER_DIM_EXTERNAL:
return TEXTURE_2D; return MALI_TEX_2D;
case GLSL_SAMPLER_DIM_3D: case GLSL_SAMPLER_DIM_3D:
return TEXTURE_3D; return MALI_TEX_3D;
case GLSL_SAMPLER_DIM_CUBE: case GLSL_SAMPLER_DIM_CUBE:
return TEXTURE_CUBE; return MALI_TEX_CUBE;
default: default:
DBG("Unknown sampler dim type\n"); DBG("Unknown sampler dim type\n");

View file

@ -2096,6 +2096,32 @@ panfrost_set_stencil_ref(
ctx->dirty |= PAN_DIRTY_FS; 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 * static struct pipe_sampler_view *
panfrost_create_sampler_view( panfrost_create_sampler_view(
struct pipe_context *pctx, struct pipe_context *pctx,
@ -2195,8 +2221,8 @@ panfrost_create_sampler_view(
.swizzle = panfrost_translate_swizzle_4(desc->swizzle), .swizzle = panfrost_translate_swizzle_4(desc->swizzle),
.format = format, .format = format,
.usage1 = (texture->target == PIPE_TEXTURE_3D) ? MALI_TEX_3D : 0, .srgb = false,
.is_not_cubemap = texture->target != PIPE_TEXTURE_CUBE, .type = panfrost_translate_texture_type(texture->target),
.usage2 = usage2_layout .usage2 = usage2_layout
}, },

View file

@ -407,6 +407,22 @@ pandecode_wrap_mode_name(enum mali_wrap_mode op)
} }
#undef DEFINE_CASE #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 * static inline char *
pandecode_decode_fbd_type(enum mali_fbd_type type) 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_replay_swizzle(f.swizzle);
pandecode_prop("format = %s", pandecode_format_name(f.format)); pandecode_prop("format = %s", pandecode_format_name(f.format));
pandecode_prop("type = %s", pandecode_texture_type(f.type));
pandecode_prop("usage1 = 0x%" PRIx32, f.usage1); pandecode_prop("srgb = %" PRId32, f.srgb);
pandecode_prop("is_not_cubemap = %" PRId32, f.is_not_cubemap); pandecode_prop("unknown1 = %" PRId32, f.unknown1);
pandecode_prop("usage2 = 0x%" PRIx32, f.usage2); pandecode_prop("usage2 = 0x%" PRIx32, f.usage2);
pandecode_indent--; 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; bool manual_stride = f.usage2 & MALI_TEX_MANUAL_STRIDE;
/* Miptree for each face */ /* Miptree for each face */
if (!f.is_not_cubemap) if (f.type == MALI_TEX_CUBE)
bitmap_count *= 6; bitmap_count *= 6;
/* Array of textures */ /* Array of textures */