agx: generalize preloaded cache
we'll need it for more regs
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28483>
diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c
index 7fbad35..e5930d6 100644
--- a/src/asahi/compiler/agx_compile.c
+++ b/src/asahi/compiler/agx_compile.c
@@ -55,29 +55,27 @@
}
static agx_index
-agx_cached_preload(agx_context *ctx, agx_index *cache, unsigned base,
- enum agx_size size)
+agx_cached_preload(agx_context *ctx, unsigned base, enum agx_size size)
{
- if (agx_is_null(*cache)) {
+ if (agx_is_null(ctx->preloaded[base])) {
agx_block *block = agx_start_block(ctx);
agx_builder b = agx_init_builder(ctx, agx_before_block(block));
- *cache = agx_preload(&b, agx_register(base, size));
+ ctx->preloaded[base] = agx_preload(&b, agx_register(base, size));
}
- return *cache;
+ return ctx->preloaded[base];
}
static agx_index
agx_vertex_id(agx_builder *b)
{
- return agx_cached_preload(b->shader, &b->shader->vertex_id, 10, AGX_SIZE_32);
+ return agx_cached_preload(b->shader, 10, AGX_SIZE_32);
}
static agx_index
agx_instance_id(agx_builder *b)
{
- return agx_cached_preload(b->shader, &b->shader->instance_id, 12,
- AGX_SIZE_32);
+ return agx_cached_preload(b->shader, 12, AGX_SIZE_32);
}
#define VARYING_NUM_COMPONENTS (VARYING_SLOT_MAX * 4)
diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h
index 667bef1..a3e526e 100644
--- a/src/asahi/compiler/agx_compiler.h
+++ b/src/asahi/compiler/agx_compiler.h
@@ -478,10 +478,10 @@
* components, populated by a split. */
struct hash_table_u64 *allocated_vec;
- /* During instruction selection, preloaded values,
- * or NULL if it hasn't been preloaded
+ /* During instruction selection, preloaded values or NULL if it hasn't been
+ * preloaded.
*/
- agx_index vertex_id, instance_id;
+ agx_index preloaded[AGX_NUM_REGS];
/* Beginning of our stack allocation used for spilling, below that is
* NIR-level scratch.