From 485e17e01e3a1ed7e96ada3c2b962a166eeaba12 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 26 Jan 2024 14:27:13 -0400 Subject: [PATCH] asahi: allocate preamble scratch needed for preamble spilling Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_batch.c | 3 +++ src/gallium/drivers/asahi/agx_state.c | 26 ++++++++++++++++---------- src/gallium/drivers/asahi/agx_state.h | 8 ++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_batch.c b/src/gallium/drivers/asahi/agx_batch.c index 5c80bd41aa0..875025459e3 100644 --- a/src/gallium/drivers/asahi/agx_batch.c +++ b/src/gallium/drivers/asahi/agx_batch.c @@ -139,6 +139,9 @@ agx_batch_init(struct agx_context *ctx, batch->vs_scratch = false; batch->fs_scratch = false; batch->cs_scratch = false; + batch->vs_preamble_scratch = 0; + batch->fs_preamble_scratch = 0; + batch->cs_preamble_scratch = 0; /* We need to emit prim state at the start. Max collides with all. */ batch->reduced_prim = MESA_PRIM_COUNT; diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 1178d34c9e3..2bdc0badcad 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -3183,26 +3183,30 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs, cfg.unk_2 = (stage == PIPE_SHADER_FRAGMENT) ? 2 : 3; } - uint32_t spill_bucket = 0; + uint32_t max_scratch_size = + MAX2(cs->info.scratch_size, cs->info.preamble_scratch_size); - if (cs->info.scratch_size > 0) { - spill_bucket = agx_scratch_get_bucket(cs->info.scratch_size); + if (max_scratch_size > 0) { + unsigned preamble_size = (cs->info.preamble_scratch_size > 0) ? 1 : 0; switch (stage) { case PIPE_SHADER_FRAGMENT: - agx_scratch_alloc(&ctx->scratch_fs, cs->info.scratch_size, - max_subgroups); + agx_scratch_alloc(&ctx->scratch_fs, max_scratch_size, max_subgroups); batch->fs_scratch = true; + batch->fs_preamble_scratch = + MAX2(batch->fs_preamble_scratch, preamble_size); break; case PIPE_SHADER_VERTEX: - agx_scratch_alloc(&ctx->scratch_vs, cs->info.scratch_size, - max_subgroups); + agx_scratch_alloc(&ctx->scratch_vs, max_scratch_size, max_subgroups); batch->vs_scratch = true; + batch->vs_preamble_scratch = + MAX2(batch->vs_preamble_scratch, preamble_size); break; default: - agx_scratch_alloc(&ctx->scratch_cs, cs->info.scratch_size, - max_subgroups); + agx_scratch_alloc(&ctx->scratch_cs, max_scratch_size, max_subgroups); batch->cs_scratch = true; + batch->cs_preamble_scratch = + MAX2(batch->cs_preamble_scratch, preamble_size); break; } } @@ -3210,7 +3214,9 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs, agx_usc_pack(&b, REGISTERS, cfg) { cfg.register_count = cs->info.nr_gprs; cfg.unk_1 = (stage == PIPE_SHADER_FRAGMENT); - cfg.spill_size = spill_bucket; + cfg.spill_size = cs->info.scratch_size + ? agx_scratch_get_bucket(cs->info.scratch_size) + : 0; } if (stage == PIPE_SHADER_FRAGMENT) { diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index 2f4af7047c5..7aa6e130c35 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -390,6 +390,14 @@ struct agx_batch { bool vs_scratch; bool fs_scratch; bool cs_scratch; + + /* Whether each stage has preambles using scratch, and if so which bucket. + * This just needs to be zero/nonzero for correctness, the magnitude in + * buckets is for statistics. + */ + unsigned vs_preamble_scratch; + unsigned fs_preamble_scratch; + unsigned cs_preamble_scratch; }; struct agx_zsa {