asahi: Add helper to get layer id in internal program
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 15 Sep 2023 20:20:15 +0000 (16:20 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 1 Oct 2023 16:32:12 +0000 (12:32 -0400)
For background/EOT only.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/asahi/lib/agx_nir_lower_tilebuffer.c
src/asahi/lib/agx_tilebuffer.h

index 81d3227..4bb6b05 100644 (file)
@@ -205,6 +205,15 @@ load_memory(nir_builder *b, unsigned bindless_base, unsigned nr_samples,
    }
 }
 
+nir_def *
+agx_internal_layer_id(nir_builder *b)
+{
+   /* In the background and end-of-tile programs, the layer ID is available as
+    * sr2, the Z component of the workgroup index.
+    */
+   return nir_channel(b, nir_load_workgroup_id(b), 2);
+}
+
 static nir_def *
 tib_impl(nir_builder *b, nir_instr *instr, void *data)
 {
index 13b317d..6f9a484 100644 (file)
@@ -22,6 +22,8 @@ extern "C" {
 
 /* Forward declarations to keep the header lean */
 struct nir_shader;
+struct nir_def;
+struct nir_builder;
 struct agx_usc_builder;
 
 struct agx_tile_size {
@@ -88,6 +90,8 @@ bool agx_nir_lower_tilebuffer(struct nir_shader *shader,
                               uint8_t *colormasks, unsigned *bindless_base,
                               bool *translucent);
 
+struct nir_def *agx_internal_layer_id(struct nir_builder *b);
+
 struct agx_msaa_state {
    uint8_t nr_samples;