From fd5293cc439ac8cf35f17bf596b6393a0f9929c1 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Fri, 25 Jun 2021 14:02:07 -0700 Subject: [PATCH] turnip: Short-circuit if ladder generation for constant index SSBO/UBOs. The compiler *can* eventually chew through all the copy prop, constant folding, and dead_cf necessary to use just our constant index, but we can save a whole lot of hassle by chasing the MOVs up front and finding the constant. dEQP-VK.ubo.3_level_array.scalar.row_major_mat4.both goes from 2.0s to 1.6s on a release build (3.1s to 2.1s for a debug build like we use in CI). Part-of: --- src/freedreno/vulkan/tu_shader.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c index cfd110e0531..af9926ebc1d 100644 --- a/src/freedreno/vulkan/tu_shader.c +++ b/src/freedreno/vulkan/tu_shader.c @@ -279,7 +279,7 @@ lower_ssbo_ubo_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin) /* The bindless base is part of the instruction, which means that part of * the "pointer" has to be constant. We solve this in the same way the blob * does, by generating a bunch of if-statements. In the usual case where - * the descriptor set is constant this will get optimized out. + * the descriptor set is constant we can skip that, though). */ unsigned buffer_src; @@ -290,11 +290,19 @@ lower_ssbo_ubo_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin) buffer_src = 0; } - nir_ssa_def *base_idx = nir_channel(b, intrin->src[buffer_src].ssa, 0); + nir_ssa_scalar scalar_idx = nir_ssa_scalar_resolved(intrin->src[buffer_src].ssa, 0); nir_ssa_def *descriptor_idx = nir_channel(b, intrin->src[buffer_src].ssa, 1); nir_ssa_def *results[MAX_SETS + 1] = { NULL }; + if (nir_ssa_scalar_is_const(scalar_idx)) { + nir_ssa_def *bindless = + nir_bindless_resource_ir3(b, 32, descriptor_idx, .desc_set = nir_ssa_scalar_as_uint(scalar_idx)); + nir_instr_rewrite_src_ssa(&intrin->instr, &intrin->src[buffer_src], bindless); + return; + } + + nir_ssa_def *base_idx = nir_channel(b, scalar_idx.def, scalar_idx.comp); for (unsigned i = 0; i < MAX_SETS + 1; i++) { /* if (base_idx == i) { ... */ nir_if *nif = nir_push_if(b, nir_ieq_imm(b, base_idx, i));