freedreno/a6xx: Rewrite the format table format/swap helpers.

We need to take a tiling mode to in order to support 1555 like turnip
does, and I like this naming better.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13046>
This commit is contained in:
Emma Anholt 2021-10-01 16:46:54 -07:00 committed by Marge Bot
parent 1ce837d6f4
commit ebaeddcbb3
11 changed files with 76 additions and 53 deletions

View File

@ -353,27 +353,51 @@ static const struct fd6_format formats[PIPE_FORMAT_COUNT] = {
};
/* clang-format on */
static enum a3xx_color_swap
fd6_pipe2swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
{
if (!formats[format].present)
return WZYX;
if (tile_mode)
return WZYX;
return formats[format].swap;
}
/* convert pipe format to vertex buffer format: */
enum a6xx_format
fd6_pipe2vtx(enum pipe_format format)
fd6_vertex_format(enum pipe_format format)
{
if (!formats[format].present)
return FMT6_NONE;
return formats[format].vtx;
}
enum a3xx_color_swap
fd6_vertex_swap(enum pipe_format format)
{
return fd6_pipe2swap(format, TILE6_LINEAR);
}
/* convert pipe format to texture sampler format: */
enum a6xx_format
fd6_pipe2tex(enum pipe_format format)
fd6_texture_format(enum pipe_format format, enum a6xx_tile_mode tile_mode)
{
if (!formats[format].present)
return FMT6_NONE;
return formats[format].tex;
}
enum a3xx_color_swap
fd6_texture_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
{
return fd6_pipe2swap(format, tile_mode);
}
/* convert pipe format to MRT / copydest format used for render-target: */
enum a6xx_format
fd6_pipe2color(enum pipe_format format)
fd6_color_format(enum pipe_format format, enum a6xx_tile_mode tile_mode)
{
if (!formats[format].present)
return FMT6_NONE;
@ -381,11 +405,9 @@ fd6_pipe2color(enum pipe_format format)
}
enum a3xx_color_swap
fd6_pipe2swap(enum pipe_format format)
fd6_color_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
{
if (!formats[format].present)
return WZYX;
return formats[format].swap;
return fd6_pipe2swap(format, tile_mode);
}
enum a6xx_depth_format

View File

@ -35,10 +35,17 @@
#include "adreno_common.xml.h"
#include "a6xx.xml.h"
enum a6xx_format fd6_pipe2vtx(enum pipe_format format);
enum a6xx_format fd6_pipe2tex(enum pipe_format format);
enum a6xx_format fd6_pipe2color(enum pipe_format format);
enum a3xx_color_swap fd6_pipe2swap(enum pipe_format format);
enum a6xx_depth_format fd6_pipe2depth(enum pipe_format format);
enum a6xx_format fd6_vertex_format(enum pipe_format format) ATTRIBUTE_CONST;
enum a3xx_color_swap fd6_vertex_swap(enum pipe_format format) ATTRIBUTE_CONST;
enum a6xx_format fd6_texture_format(enum pipe_format format,
enum a6xx_tile_mode tile_mode) ATTRIBUTE_CONST;
enum a3xx_color_swap fd6_texture_swap(enum pipe_format format,
enum a6xx_tile_mode tile_mode) ATTRIBUTE_CONST;
enum a6xx_format fd6_color_format(enum pipe_format format,
enum a6xx_tile_mode tile_mode) ATTRIBUTE_CONST;
enum a3xx_color_swap fd6_color_swap(enum pipe_format format,
enum a6xx_tile_mode tile_mode) ATTRIBUTE_CONST;
#endif /* FD6_FORMAT_TABLE_H */

View File

@ -126,7 +126,7 @@ ok_dims(const struct pipe_resource *r, const struct pipe_box *b, int lvl)
static bool
ok_format(enum pipe_format pfmt)
{
enum a6xx_format fmt = fd6_pipe2color(pfmt);
enum a6xx_format fmt = fd6_color_format(pfmt, TILE6_LINEAR);
if (util_format_is_compressed(pfmt))
return true;
@ -252,7 +252,7 @@ static void
emit_blit_setup(struct fd_ringbuffer *ring, enum pipe_format pfmt,
bool scissor_enable, union pipe_color_union *color)
{
enum a6xx_format fmt = fd6_pipe2color(pfmt);
enum a6xx_format fmt = fd6_color_format(pfmt, TILE6_LINEAR);
bool is_srgb = util_format_is_srgb(pfmt);
enum a6xx_2d_ifmt ifmt = fd6_ifmt(fmt);
@ -533,9 +533,9 @@ emit_blit_dst(struct fd_ringbuffer *ring, struct pipe_resource *prsc,
enum pipe_format pfmt, unsigned level, unsigned layer)
{
struct fd_resource *dst = fd_resource(prsc);
enum a6xx_format fmt = fd6_pipe2color(pfmt);
enum a6xx_format fmt = fd6_color_format(pfmt, dst->layout.tile_mode);
enum a6xx_tile_mode tile = fd_resource_tile_mode(prsc, level);
enum a3xx_color_swap swap = fd6_resource_swap(dst, pfmt);
enum a3xx_color_swap swap = fd6_color_swap(pfmt, dst->layout.tile_mode);
uint32_t pitch = fd_resource_pitch(dst, level);
bool ubwc_enabled = fd_resource_ubwc_enabled(dst, level);
unsigned off = fd_resource_offset(dst, level, layer);
@ -571,10 +571,10 @@ emit_blit_src(struct fd_ringbuffer *ring, const struct pipe_blit_info *info,
unsigned layer, unsigned nr_samples)
{
struct fd_resource *src = fd_resource(info->src.resource);
enum a6xx_format sfmt = fd6_pipe2tex(info->src.format);
enum a6xx_format sfmt = fd6_texture_format(info->src.format, src->layout.tile_mode);
enum a6xx_tile_mode stile =
fd_resource_tile_mode(info->src.resource, info->src.level);
enum a3xx_color_swap sswap = fd6_resource_swap(src, info->src.format);
enum a3xx_color_swap sswap = fd6_texture_swap(info->src.format, src->layout.tile_mode);
uint32_t pitch = fd_resource_pitch(src, info->src.level);
bool subwc_enabled = fd_resource_ubwc_enabled(src, info->src.level);
unsigned soff = fd_resource_offset(src, info->src.level, layer);
@ -718,7 +718,7 @@ emit_clear_color(struct fd_ringbuffer *ring, enum pipe_format pfmt,
}
OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);
switch (fd6_ifmt(fd6_pipe2color(pfmt))) {
switch (fd6_ifmt(fd6_color_format(pfmt, TILE6_LINEAR))) {
case R2D_UNORM8:
case R2D_UNORM8_SRGB:
/* The r2d ifmt is badly named, it also covers the signed case: */
@ -856,7 +856,7 @@ fd6_resolve_tile(struct fd_batch *batch, struct fd_ringbuffer *ring,
emit_blit_dst(ring, psurf->texture, psurf->format, psurf->u.tex.level,
psurf->u.tex.first_layer);
enum a6xx_format sfmt = fd6_pipe2color(psurf->format);
enum a6xx_format sfmt = fd6_color_format(psurf->format, TILE6_LINEAR);
enum a3xx_msaa_samples samples = fd_msaa_samples(batch->framebuffer.samples);
OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);

View File

@ -86,7 +86,7 @@ fd6_vertex_state_create(struct pipe_context *pctx, unsigned num_elements,
for (int32_t i = 0; i < num_elements; i++) {
const struct pipe_vertex_element *elem = &elements[i];
enum pipe_format pfmt = elem->src_format;
enum a6xx_format fmt = fd6_pipe2vtx(pfmt);
enum a6xx_format fmt = fd6_vertex_format(pfmt);
bool isint = util_format_is_pure_integer(pfmt);
debug_assert(fmt != FMT6_NONE);
@ -95,7 +95,7 @@ fd6_vertex_state_create(struct pipe_context *pctx, unsigned num_elements,
A6XX_VFD_DECODE_INSTR_FORMAT(fmt) |
COND(elem->instance_divisor,
A6XX_VFD_DECODE_INSTR_INSTANCED) |
A6XX_VFD_DECODE_INSTR_SWAP(fd6_pipe2swap(pfmt)) |
A6XX_VFD_DECODE_INSTR_SWAP(fd6_vertex_swap(pfmt)) |
A6XX_VFD_DECODE_INSTR_UNK30 |
COND(!isint, A6XX_VFD_DECODE_INSTR_FLOAT));
OUT_RING(ring,

View File

@ -111,6 +111,7 @@ setup_border_colors(struct fd_texture_stateobj *tex,
enum pipe_format format = view->format;
const struct util_format_description *desc =
util_format_description(format);
const struct fd_resource *rsc = fd_resource(view->texture);
e->rgb565 = 0;
e->rgb5a1 = 0;
@ -120,7 +121,7 @@ setup_border_colors(struct fd_texture_stateobj *tex,
unsigned char swiz[4];
fd6_tex_swiz(format, swiz, view->swizzle_r, view->swizzle_g,
fd6_tex_swiz(format, rsc->layout.tile_mode, swiz, view->swizzle_r, view->swizzle_g,
view->swizzle_b, view->swizzle_a);
for (j = 0; j < 4; j++) {

View File

@ -52,7 +52,7 @@ fd6_pipe2swiz(unsigned swiz)
}
void
fd6_tex_swiz(enum pipe_format format, unsigned char *swiz, unsigned swizzle_r,
fd6_tex_swiz(enum pipe_format format, enum a6xx_tile_mode tile_mode, unsigned char *swiz, unsigned swizzle_r,
unsigned swizzle_g, unsigned swizzle_b, unsigned swizzle_a)
{
const struct util_format_description *desc = util_format_description(format);
@ -68,7 +68,7 @@ fd6_tex_swiz(enum pipe_format format, unsigned char *swiz, unsigned swizzle_r,
} else if (format == PIPE_FORMAT_R8G8_R8B8_UNORM || format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
unsigned char fswiz[4] = {PIPE_SWIZZLE_Z, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_1};
util_format_compose_swizzles(fswiz, uswiz, swiz);
} else if (fd6_pipe2swap(format) != WZYX) {
} else if (fd6_texture_swap(format, TILE6_LINEAR) != WZYX) {
/* Formats with a non-pass-through swap are permutations of RGBA
* formats. We program the permutation using the swap and don't
* need to compose the format swizzle with the user swizzle.
@ -91,11 +91,11 @@ fd6_tex_const_0(struct pipe_resource *prsc, unsigned level,
struct fd_resource *rsc = fd_resource(prsc);
unsigned char swiz[4];
fd6_tex_swiz(format, swiz, swizzle_r, swizzle_g, swizzle_b, swizzle_a);
fd6_tex_swiz(format, rsc->layout.tile_mode, swiz, swizzle_r, swizzle_g, swizzle_b, swizzle_a);
return A6XX_TEX_CONST_0_FMT(fd6_pipe2tex(format)) |
return A6XX_TEX_CONST_0_FMT(fd6_texture_format(format, rsc->layout.tile_mode)) |
A6XX_TEX_CONST_0_SAMPLES(fd_msaa_samples(prsc->nr_samples)) |
A6XX_TEX_CONST_0_SWAP(fd6_resource_swap(rsc, format)) |
A6XX_TEX_CONST_0_SWAP(fd6_texture_swap(format, rsc->layout.tile_mode)) |
A6XX_TEX_CONST_0_TILE_MODE(fd_resource_tile_mode(prsc, level)) |
COND(util_format_is_srgb(format), A6XX_TEX_CONST_0_SRGB) |
A6XX_TEX_CONST_0_SWIZ_X(fd6_pipe2swiz(swiz[0])) |

View File

@ -36,7 +36,7 @@
enum a6xx_tex_swiz fd6_pipe2swiz(unsigned swiz);
void fd6_tex_swiz(enum pipe_format format, unsigned char *swiz,
void fd6_tex_swiz(enum pipe_format format, enum a6xx_tile_mode tile_mode, unsigned char *swiz,
unsigned swizzle_r, unsigned swizzle_g, unsigned swizzle_b,
unsigned swizzle_a);
@ -45,10 +45,4 @@ uint32_t fd6_tex_const_0(struct pipe_resource *prsc, unsigned level,
unsigned swizzle_g, unsigned swizzle_b,
unsigned swizzle_a);
static inline uint32_t
fd6_resource_swap(struct fd_resource *rsc, enum pipe_format format)
{
return rsc->layout.tile_mode ? WZYX : fd6_pipe2swap(format);
}
#endif /* FD6_UTIL_H_ */

View File

@ -81,7 +81,6 @@ emit_mrt(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb,
unsigned max_layer_index = 0;
for (i = 0; i < pfb->nr_cbufs; i++) {
enum a6xx_format format = 0;
enum a3xx_color_swap swap = WZYX;
bool sint = false, uint = false;
struct fd_resource *rsc = NULL;
@ -89,7 +88,6 @@ emit_mrt(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb,
uint32_t stride = 0;
uint32_t array_stride = 0;
uint32_t offset;
uint32_t tile_mode;
if (!pfb->cbufs[i])
continue;
@ -102,7 +100,8 @@ emit_mrt(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb,
uint32_t base = gmem ? gmem->cbuf_base[i] : 0;
slice = fd_resource_slice(rsc, psurf->u.tex.level);
format = fd6_pipe2color(pformat);
uint32_t tile_mode = fd_resource_tile_mode(psurf->texture, psurf->u.tex.level);
enum a6xx_format format = fd6_color_format(pformat, tile_mode);
sint = util_format_is_pure_sint(pformat);
uint = util_format_is_pure_uint(pformat);
@ -114,9 +113,8 @@ emit_mrt(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb,
stride = fd_resource_pitch(rsc, psurf->u.tex.level);
array_stride = fd_resource_layer_stride(rsc, psurf->u.tex.level);
swap = fd6_resource_swap(rsc, pformat);
swap = fd6_color_swap(pformat, rsc->layout.tile_mode);
tile_mode = fd_resource_tile_mode(psurf->texture, psurf->u.tex.level);
max_layer_index = psurf->u.tex.last_layer - psurf->u.tex.first_layer;
debug_assert((offset + slice->size0) <= fd_bo_size(rsc->bo));
@ -987,12 +985,12 @@ emit_blit(struct fd_batch *batch, struct fd_ringbuffer *ring, uint32_t base,
debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer);
enum a6xx_format format = fd6_pipe2color(pfmt);
uint32_t tile_mode = fd_resource_tile_mode(&rsc->b.b, psurf->u.tex.level);
enum a6xx_format format = fd6_color_format(pfmt, tile_mode);
uint32_t stride = fd_resource_pitch(rsc, psurf->u.tex.level);
uint32_t size = fd_resource_slice(rsc, psurf->u.tex.level)->size0;
enum a3xx_color_swap swap = fd6_resource_swap(rsc, pfmt);
enum a3xx_color_swap swap = fd6_color_swap(pfmt, rsc->layout.tile_mode);
enum a3xx_msaa_samples samples = fd_msaa_samples(rsc->b.b.nr_samples);
uint32_t tile_mode = fd_resource_tile_mode(&rsc->b.b, psurf->u.tex.level);
OUT_REG(ring,
A6XX_RB_BLIT_DST_INFO(.tile_mode = tile_mode, .samples = samples,
@ -1052,7 +1050,7 @@ emit_clears(struct fd_batch *batch, struct fd_ringbuffer *ring)
// XXX I think RB_CLEAR_COLOR_DWn wants to take into account SWAP??
union pipe_color_union swapped;
switch (fd6_pipe2swap(pfmt)) {
switch (fd6_color_swap(pfmt, TILE6_LINEAR)) {
case WZYX:
swapped.ui[0] = color->ui[0];
swapped.ui[1] = color->ui[1];
@ -1085,7 +1083,7 @@ emit_clears(struct fd_batch *batch, struct fd_ringbuffer *ring)
OUT_RING(ring,
A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR) |
A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) |
A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_pipe2color(pfmt)));
A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_color_format(pfmt, TILE6_LINEAR)));
OUT_PKT4(ring, REG_A6XX_RB_BLIT_INFO, 1);
OUT_RING(ring,
@ -1137,7 +1135,7 @@ emit_clears(struct fd_batch *batch, struct fd_ringbuffer *ring)
OUT_RING(ring,
A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR) |
A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) |
A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_pipe2color(pfmt)));
A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_color_format(pfmt, TILE6_LINEAR)));
OUT_PKT4(ring, REG_A6XX_RB_BLIT_INFO, 1);
OUT_RING(ring, A6XX_RB_BLIT_INFO_GMEM |

View File

@ -260,7 +260,7 @@ emit_image_ssbo(struct fd_ringbuffer *ring, struct fd6_image *img)
enum a6xx_tile_mode tile_mode = fd_resource_tile_mode(img->prsc, img->level);
bool ubwc_enabled = fd_resource_ubwc_enabled(rsc, img->level);
OUT_RING(ring, A6XX_IBO_0_FMT(fd6_pipe2tex(img->pfmt)) |
OUT_RING(ring, A6XX_IBO_0_FMT(fd6_texture_format(img->pfmt, rsc->layout.tile_mode)) |
A6XX_IBO_0_TILE_MODE(tile_mode));
OUT_RING(ring,
A6XX_IBO_1_WIDTH(img->width) | A6XX_IBO_1_HEIGHT(img->height));

View File

@ -58,7 +58,7 @@ ok_ubwc_format(struct pipe_screen *pscreen, enum pipe_format pfmt)
break;
}
switch (fd6_pipe2color(pfmt)) {
switch (fd6_color_format(pfmt, TILE6_LINEAR)) {
case FMT6_10_10_10_2_UINT:
case FMT6_10_10_10_2_UNORM_DEST:
case FMT6_11_11_10_FLOAT:

View File

@ -76,12 +76,15 @@ fd6_screen_is_format_supported(struct pipe_screen *pscreen,
return false;
if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
(fd6_pipe2vtx(format) != FMT6_NONE)) {
(fd6_vertex_format(format) != FMT6_NONE)) {
retval |= PIPE_BIND_VERTEX_BUFFER;
}
bool has_color = fd6_color_format(format, TILE6_LINEAR) != FMT6_NONE;
bool has_tex = fd6_texture_format(format, TILE6_LINEAR) != FMT6_NONE;
if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
(fd6_pipe2tex(format) != FMT6_NONE) &&
has_tex &&
(target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) {
retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
}
@ -89,8 +92,7 @@ fd6_screen_is_format_supported(struct pipe_screen *pscreen,
if ((usage &
(PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) &&
(fd6_pipe2color(format) != FMT6_NONE) &&
(fd6_pipe2tex(format) != FMT6_NONE)) {
has_color && has_tex) {
retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |
PIPE_BIND_COMPUTE_RESOURCE);
@ -102,8 +104,7 @@ fd6_screen_is_format_supported(struct pipe_screen *pscreen,
}
if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
(fd6_pipe2depth(format) != (enum a6xx_depth_format) ~0) &&
(fd6_pipe2tex(format) != FMT6_NONE)) {
(fd6_pipe2depth(format) != (enum a6xx_depth_format) ~0) && has_tex) {
retval |= PIPE_BIND_DEPTH_STENCIL;
}