From 6e69c3369c9f8d7214ab7bfdb8a210cacedec90f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 31 Mar 2022 11:08:17 -0400 Subject: [PATCH] pan/bi: Don't lower vertex_id for malloc IDVS Based on hardware behaviour, it appears vertex_id is zero-based with the legacy geometry flow but not with the new malloc IDVS flow. Since the geometry flow is per-shader (not per-machine), there's not a good way to communicate this to NIR. Rather than trying to shoehorn this obscure detail into NIR, just do the lowering ourselves instead of in NIR. It's not much more code anyway. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 19 +++++++++++++++++-- src/panfrost/bifrost/bifrost_compile.h | 1 - 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index bcc8e0c7031..15b5807aae5 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -1555,8 +1555,23 @@ bi_emit_intrinsic(bi_builder *b, nir_intrinsic_instr *instr) BI_VARYING_NAME_POINT, BI_VECSIZE_V2); break; - case nir_intrinsic_load_vertex_id_zero_base: - bi_mov_i32_to(b, dst, bi_vertex_id(b)); + /* It appears vertex_id is zero-based with Bifrost geometry flows, but + * not with Valhall's memory-allocation IDVS geometry flow. Ostensibly + * we support the legacy geometry flow even on Valhall, so + * vertex_id_zero_based isn't a machine property for us. Don't set it, + * and lower here if needed. + */ + case nir_intrinsic_load_vertex_id: + if (b->shader->malloc_idvs) { + bi_mov_i32_to(b, dst, bi_vertex_id(b)); + } else { + bi_index first = bi_load_sysval(b, + PAN_SYSVAL_VERTEX_INSTANCE_OFFSETS, + 1, 0); + + bi_iadd_u32_to(b, dst, bi_vertex_id(b), first, false); + } + break; case nir_intrinsic_load_instance_id: diff --git a/src/panfrost/bifrost/bifrost_compile.h b/src/panfrost/bifrost/bifrost_compile.h index 9e409389dc0..7a8d24c03f5 100644 --- a/src/panfrost/bifrost/bifrost_compile.h +++ b/src/panfrost/bifrost/bifrost_compile.h @@ -91,7 +91,6 @@ static const nir_shader_compiler_options bifrost_nir_options = { .lower_uniforms_to_ubo = true, .has_cs_global_id = true, - .vertex_id_zero_based = true, .lower_cs_local_index_to_id = true, .max_unroll_iterations = 32, .force_indirect_unrolling = (nir_var_shader_in | nir_var_shader_out | nir_var_function_temp),