From 089a0cf4ef8bafbf58a5c6aaed5301372fa125bb Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 7 Jun 2023 11:01:09 -0700 Subject: [PATCH] spirv: Refactor and rename scope translation helper This will make the change from nir_scope to mesa_scope later less noisy. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/spirv/spirv_to_nir.c | 29 ++++++++++------------------- src/compiler/spirv/vtn_private.h | 2 +- src/compiler/spirv/vtn_subgroup.c | 2 +- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index c25606691ba..f6d739e8d61 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -2570,9 +2570,8 @@ vtn_mem_semantics_to_nir_var_modes(struct vtn_builder *b, } nir_scope -vtn_scope_to_nir_scope(struct vtn_builder *b, SpvScope scope) +vtn_translate_scope(struct vtn_builder *b, SpvScope scope) { - nir_scope nir_scope; switch (scope) { case SpvScopeDevice: vtn_fail_if(b->options->caps.vk_memory_model && @@ -2580,37 +2579,29 @@ vtn_scope_to_nir_scope(struct vtn_builder *b, SpvScope scope) "If the Vulkan memory model is declared and any instruction " "uses Device scope, the VulkanMemoryModelDeviceScope " "capability must be declared."); - nir_scope = NIR_SCOPE_DEVICE; - break; + return NIR_SCOPE_DEVICE; case SpvScopeQueueFamily: vtn_fail_if(!b->options->caps.vk_memory_model, "To use Queue Family scope, the VulkanMemoryModel capability " "must be declared."); - nir_scope = NIR_SCOPE_QUEUE_FAMILY; - break; + return NIR_SCOPE_QUEUE_FAMILY; case SpvScopeWorkgroup: - nir_scope = NIR_SCOPE_WORKGROUP; - break; + return NIR_SCOPE_WORKGROUP; case SpvScopeSubgroup: - nir_scope = NIR_SCOPE_SUBGROUP; - break; + return NIR_SCOPE_SUBGROUP; case SpvScopeInvocation: - nir_scope = NIR_SCOPE_INVOCATION; - break; + return NIR_SCOPE_INVOCATION; case SpvScopeShaderCallKHR: - nir_scope = NIR_SCOPE_SHADER_CALL; - break; + return NIR_SCOPE_SHADER_CALL; default: vtn_fail("Invalid memory scope"); } - - return nir_scope; } static void @@ -2621,14 +2612,14 @@ vtn_emit_scoped_control_barrier(struct vtn_builder *b, SpvScope exec_scope, nir_memory_semantics nir_semantics = vtn_mem_semantics_to_nir_mem_semantics(b, semantics); nir_variable_mode modes = vtn_mem_semantics_to_nir_var_modes(b, semantics); - nir_scope nir_exec_scope = vtn_scope_to_nir_scope(b, exec_scope); + nir_scope nir_exec_scope = vtn_translate_scope(b, exec_scope); /* Memory semantics is optional for OpControlBarrier. */ nir_scope nir_mem_scope; if (nir_semantics == 0 || modes == 0) nir_mem_scope = NIR_SCOPE_NONE; else - nir_mem_scope = vtn_scope_to_nir_scope(b, mem_scope); + nir_mem_scope = vtn_translate_scope(b, mem_scope); nir_scoped_barrier(&b->nb, .execution_scope=nir_exec_scope, .memory_scope=nir_mem_scope, .memory_semantics=nir_semantics, .memory_modes=modes); @@ -2646,7 +2637,7 @@ vtn_emit_scoped_memory_barrier(struct vtn_builder *b, SpvScope scope, if (nir_semantics == 0 || modes == 0) return; - nir_scoped_barrier(&b->nb, .memory_scope=vtn_scope_to_nir_scope(b, scope), + nir_scoped_barrier(&b->nb, .memory_scope=vtn_translate_scope(b, scope), .memory_semantics=nir_semantics, .memory_modes=modes); } diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index e3b7b67ab6b..2bdd7c163e0 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -532,7 +532,7 @@ vtn_type_get_nir_type(struct vtn_builder *b, struct vtn_type *type, enum vtn_variable_mode mode); nir_scope -vtn_scope_to_nir_scope(struct vtn_builder *b, SpvScope scope); +vtn_translate_scope(struct vtn_builder *b, SpvScope scope); struct vtn_image_pointer { nir_deref_instr *image; diff --git a/src/compiler/spirv/vtn_subgroup.c b/src/compiler/spirv/vtn_subgroup.c index eef50f22f9e..c227ee22a2a 100644 --- a/src/compiler/spirv/vtn_subgroup.c +++ b/src/compiler/spirv/vtn_subgroup.c @@ -341,7 +341,7 @@ vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode, } case SpvOpGroupNonUniformRotateKHR: { - const nir_scope scope = vtn_scope_to_nir_scope(b, vtn_constant_uint(b, w[3])); + const nir_scope scope = vtn_translate_scope(b, vtn_constant_uint(b, w[3])); const uint32_t cluster_size = count > 6 ? vtn_constant_uint(b, w[6]) : 0; vtn_fail_if(cluster_size && !IS_POT(cluster_size), "Behavior is undefined unless ClusterSize is at least 1 and a power of 2.");