panfrost: Allow passing an explicit UBO index for the sysval UBO
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 5 Mar 2021 12:20:03 +0000 (13:20 +0100)
committerMarge Bot <eric+marge@anholt.net>
Thu, 11 Mar 2021 15:10:58 +0000 (15:10 +0000)
UBO index assignment is a bit special in Vulkan, it's based on the
descriptor set layout, which doesn't know about shaders' internal UBOs
(our sysval UBOs). Extend the backend compilers so we can place sysval
UBOs where we want: after all explicit UBOs.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9517>

src/panfrost/bifrost/bifrost_compile.c
src/panfrost/lib/pan_shader.c
src/panfrost/midgard/midgard_compile.c
src/panfrost/util/pan_ir.h

index cea0801..59533b8 100644 (file)
@@ -325,6 +325,8 @@ static bi_instr *
 bi_load_sysval_to(bi_builder *b, bi_index dest, int sysval,
                 unsigned nr_components, unsigned offset)
 {
+        unsigned sysval_ubo =
+                MAX2(b->shader->inputs->sysval_ubo, b->shader->nir->info.num_ubos);
         unsigned uniform =
                 pan_lookup_sysval(b->shader->sysval_to_id,
                                   &b->shader->info->sysvals,
@@ -333,7 +335,7 @@ bi_load_sysval_to(bi_builder *b, bi_index dest, int sysval,
 
         return bi_load_to(b, nr_components * 32, dest,
                         bi_imm_u32(idx),
-                        bi_imm_u32(b->shader->nir->info.num_ubos), BI_SEG_UBO);
+                        bi_imm_u32(sysval_ubo), BI_SEG_UBO);
 }
 
 static void
index bed64b0..88179ce 100644 (file)
@@ -226,7 +226,10 @@ pan_shader_compile(const struct panfrost_device *dev,
         info->outputs_written = s->info.outputs_written;
 
         /* Sysvals have dedicated UBO */
-        info->ubo_count = s->info.num_ubos + (info->sysvals.sysval_count ? 1 : 0);
+        if (info->sysvals.sysval_count)
+                info->ubo_count = MAX2(s->info.num_ubos + 1, inputs->sysval_ubo + 1);
+        else
+                info->ubo_count = s->info.num_ubos;
 
         info->attribute_count += util_bitcount(s->info.images_used);
         info->writes_global = s->info.writes_memory;
index 0a901f7..d075bd8 100644 (file)
@@ -1445,6 +1445,8 @@ emit_sysval_read(compiler_context *ctx, nir_instr *instr,
         nir_dest nir_dest;
 
         /* Figure out which uniform this is */
+        unsigned sysval_ubo =
+                MAX2(ctx->inputs->sysval_ubo, ctx->nir->info.num_ubos);
         int sysval = panfrost_sysval_for_instr(instr, &nir_dest);
         unsigned dest = nir_dest_index(&nir_dest);
         unsigned uniform =
@@ -1453,7 +1455,7 @@ emit_sysval_read(compiler_context *ctx, nir_instr *instr,
         /* Emit the read itself -- this is never indirect */
         midgard_instruction *ins =
                 emit_ubo_read(ctx, instr, dest, (uniform * 16) + offset, NULL, 0,
-                                ctx->nir->info.num_ubos);
+                              sysval_ubo);
 
         ins->mask = mask_of(nr_components);
 }
index 37bf877..794007e 100644 (file)
@@ -125,6 +125,7 @@ struct panfrost_compile_inputs {
                 float constants[4];
                 uint64_t bifrost_blend_desc;
         } blend;
+        unsigned sysval_ubo;
         bool shaderdb;
         bool no_ubo_to_push;