From 3559efb9bf5cb69c9ddad377ed121685954f10f1 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 5 Mar 2021 13:20:03 +0100 Subject: [PATCH] panfrost: Allow passing an explicit UBO index for the sysval UBO 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 Reviewed-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 4 +++- src/panfrost/lib/pan_shader.c | 5 ++++- src/panfrost/midgard/midgard_compile.c | 4 +++- src/panfrost/util/pan_ir.h | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index cea08011765..59533b826ac 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -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 diff --git a/src/panfrost/lib/pan_shader.c b/src/panfrost/lib/pan_shader.c index bed64b04b6c..88179ce85bf 100644 --- a/src/panfrost/lib/pan_shader.c +++ b/src/panfrost/lib/pan_shader.c @@ -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; diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 0a901f7dd1f..d075bd8b62f 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -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); } diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h index 37bf877cb21..794007e64a4 100644 --- a/src/panfrost/util/pan_ir.h +++ b/src/panfrost/util/pan_ir.h @@ -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;