asahi: pack tilebuffer usc word ahead-of-time

reduce draw time overhead.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29179>
This commit is contained in:
Alyssa Rosenzweig 2024-04-20 21:31:27 -04:00 committed by Marge Bot
parent 289cc5f5dd
commit 22292afd3c
3 changed files with 35 additions and 26 deletions

View File

@ -46,6 +46,19 @@ agx_select_tile_size(unsigned bytes_per_pixel)
unreachable("No supported tile size meets the bytes per pixel requirement");
}
static unsigned
agx_shared_layout_from_tile_size(struct agx_tile_size t)
{
if (t.width == 32 && t.height == 32)
return AGX_SHARED_LAYOUT_32X32;
else if (t.width == 32 && t.height == 16)
return AGX_SHARED_LAYOUT_32X16;
else if (t.width == 16 && t.height == 16)
return AGX_SHARED_LAYOUT_16X16;
else
unreachable("Invalid tile size");
}
struct agx_tilebuffer_layout
agx_build_tilebuffer_layout(const enum pipe_format *formats, uint8_t nr_cbufs,
uint8_t nr_samples, bool layered)
@ -120,6 +133,8 @@ agx_build_tilebuffer_layout(const enum pipe_format *formats, uint8_t nr_cbufs,
tib.sample_size_B = ALIGN_POT(offset_B, 8);
tib.tile_size = agx_select_tile_size(tib.sample_size_B * nr_samples);
agx_tilebuffer_pack_usc(&tib);
return tib;
}
@ -142,19 +157,6 @@ agx_tilebuffer_supports_mask(struct agx_tilebuffer_layout *tib, unsigned rt)
return agx_internal_format_supports_mask((enum agx_internal_formats)fmt);
}
static unsigned
agx_shared_layout_from_tile_size(struct agx_tile_size t)
{
if (t.width == 32 && t.height == 32)
return AGX_SHARED_LAYOUT_32X32;
else if (t.width == 32 && t.height == 16)
return AGX_SHARED_LAYOUT_32X16;
else if (t.width == 16 && t.height == 16)
return AGX_SHARED_LAYOUT_16X16;
else
unreachable("Invalid tile size");
}
uint32_t
agx_tilebuffer_total_size(struct agx_tilebuffer_layout *tib)
{
@ -163,13 +165,18 @@ agx_tilebuffer_total_size(struct agx_tilebuffer_layout *tib)
}
void
agx_usc_tilebuffer(struct agx_usc_builder *b, struct agx_tilebuffer_layout *tib)
agx_tilebuffer_pack_usc(struct agx_tilebuffer_layout *tib)
{
agx_usc_pack(b, SHARED, cfg) {
cfg.uses_shared_memory = true;
cfg.layout = agx_shared_layout_from_tile_size(tib->tile_size);
cfg.sample_stride_in_8_bytes = tib->sample_size_B / 8;
cfg.sample_count = tib->nr_samples;
cfg.bytes_per_threadgroup = agx_tilebuffer_total_size(tib);
agx_pack(&tib->usc, USC_SHARED, cfg) {
if (tib->nr_samples > 0) {
cfg.uses_shared_memory = true;
cfg.layout = agx_shared_layout_from_tile_size(tib->tile_size);
cfg.sample_stride_in_8_bytes = tib->sample_size_B / 8;
cfg.sample_count = tib->nr_samples;
cfg.bytes_per_threadgroup = agx_tilebuffer_total_size(tib);
} else {
cfg.layout = AGX_SHARED_LAYOUT_VERTEX_COMPUTE;
cfg.bytes_per_threadgroup = 65536;
}
}
}

View File

@ -9,6 +9,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "util/format/u_formats.h"
#include "agx_pack.h"
#ifdef __cplusplus
extern "C" {
@ -23,7 +24,6 @@ extern "C" {
struct nir_shader;
struct nir_def;
struct nir_builder;
struct agx_usc_builder;
struct agx_tile_size {
uint8_t width;
@ -57,6 +57,9 @@ struct agx_tilebuffer_layout {
/* Selected tile size */
struct agx_tile_size tile_size;
/* USC word corresponding to this configuration of the tilebuffer */
struct agx_usc_shared_packed usc;
};
/*
@ -104,9 +107,6 @@ bool agx_nir_lower_alpha_to_coverage(struct nir_shader *shader,
bool agx_nir_lower_alpha_to_one(struct nir_shader *shader);
void agx_usc_tilebuffer(struct agx_usc_builder *b,
struct agx_tilebuffer_layout *tib);
uint32_t agx_tilebuffer_total_size(struct agx_tilebuffer_layout *tib);
enum pipe_format
@ -115,6 +115,8 @@ agx_tilebuffer_physical_format(struct agx_tilebuffer_layout *tib, unsigned rt);
bool agx_tilebuffer_supports_mask(struct agx_tilebuffer_layout *tib,
unsigned rt);
void agx_tilebuffer_pack_usc(struct agx_tilebuffer_layout *tib);
#ifdef __cplusplus
} /* extern C */
#endif

View File

@ -2977,7 +2977,7 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs,
}
if (stage == PIPE_SHADER_FRAGMENT) {
agx_usc_tilebuffer(&b, &batch->tilebuffer_layout);
agx_usc_push_packed(&b, SHARED, &batch->tilebuffer_layout.usc);
} else if (stage == PIPE_SHADER_COMPUTE || stage == PIPE_SHADER_TESS_CTRL) {
unsigned size = cs->b.info.local_size + variable_shared_mem;
@ -3167,7 +3167,7 @@ agx_build_meta(struct agx_batch *batch, bool store, bool partial_render)
}
}
agx_usc_tilebuffer(&b, &batch->tilebuffer_layout);
agx_usc_push_packed(&b, SHARED, &batch->tilebuffer_layout.usc);
/* Get the shader */
key.reserved_preamble = uniforms;