From 8f0696781ff36c971413b05a70be9ab115b1da5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Wed, 12 Aug 2020 23:35:04 +0200 Subject: [PATCH] v3dv/pipeline: use derefs for ubo/ssbo There are some potential advantages for that. Even if we are not taking advantage of them, it would be interesting to be using this path now, specially as non-deref path could be removed at some point. Note that instead of returning for both resource_index and vulkan_descriptor a vec2, we return a scalar for the first one, as it is what the v3d backend expect (like for get_ssbo_size). For this to work, we reconfigure the vec2 at vulkan_descriptor using the index and an unused 0 value. As far as I see turnip avoids that by lowering too load_ssbo/ubo, so it just gets the index lowered (that in their case it is a vec3 with a fixed 0 on the third component), but for now it is easier doing this. v2: return a single-component for the index, to avoid the backend needing to handle it (Eric, Jason). Part-of: --- src/broadcom/vulkan/v3dv_pipeline.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 46a4eee9972..0924550b73c 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -366,6 +366,10 @@ preprocess_nir(nir_shader *nir, }); } + NIR_PASS_V(nir, nir_lower_explicit_io, + nir_var_mem_ubo | nir_var_mem_ssbo, + nir_address_format_32bit_index_offset); + NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_in | nir_var_shader_out | nir_var_system_value | nir_var_mem_shared, NULL); @@ -611,6 +615,12 @@ lower_vulkan_resource_index(nir_builder *b, break; } + /* Since we use the deref pass, both vulkan_resource_index and + * vulkan_load_descriptor returns a vec2. But for the index the backend + * expect just one scalar (like with get_ssbo_size), so lets return here + * just it. Then on load_descriptor we would recreate the vec2, keeping the + * second component (unused right now) to zero. + */ nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(nir_imm_int(b, index))); nir_instr_remove(&instr->instr); @@ -861,6 +871,17 @@ lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, lower_vulkan_resource_index(b, instr, pipeline, layout); return true; + case nir_intrinsic_load_vulkan_descriptor: { + /* We are not using it, as loading the descriptor happens as part of the + * load/store instruction, so the simpler is just doing a no-op. We just + * lower the desc back to a vec2, as it is what load_ssbo/ubo expects. + */ + nir_ssa_def *desc = nir_vec2(b, instr->src[0].ssa, nir_imm_int(b, 0)); + nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(desc)); + nir_instr_remove(&instr->instr); + return true; + } + case nir_intrinsic_image_deref_load: case nir_intrinsic_image_deref_store: case nir_intrinsic_image_deref_atomic_add: