From 22292afd3cbdff5ae604aba5e6657dfd10593697 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 20 Apr 2024 21:31:27 -0400 Subject: [PATCH] asahi: pack tilebuffer usc word ahead-of-time reduce draw time overhead. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_tilebuffer.c | 47 +++++++++++++++------------ src/asahi/lib/agx_tilebuffer.h | 10 +++--- src/gallium/drivers/asahi/agx_state.c | 4 +-- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/asahi/lib/agx_tilebuffer.c b/src/asahi/lib/agx_tilebuffer.c index 280a1505b5c..72adb2dcde7 100644 --- a/src/asahi/lib/agx_tilebuffer.c +++ b/src/asahi/lib/agx_tilebuffer.c @@ -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; + } } } diff --git a/src/asahi/lib/agx_tilebuffer.h b/src/asahi/lib/agx_tilebuffer.h index 03d3b200cce..c6be543702a 100644 --- a/src/asahi/lib/agx_tilebuffer.h +++ b/src/asahi/lib/agx_tilebuffer.h @@ -9,6 +9,7 @@ #include #include #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 diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 8269b647167..0391657f19f 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -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;