From 070f042e10466fecf2bbef8a6bf304b5b58646f8 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 16 Nov 2022 20:41:28 -0800 Subject: [PATCH] spirv: Implement SPV_KHR_subgroup_rotate MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Map SpvOpGroupNonUniformRotateKHR to nir_intrinsic_rotate. Reviewed-by: Ian Romanick Reviewed-by: Timur Kristóf Part-of: --- src/compiler/shader_info.h | 1 + src/compiler/spirv/spirv_to_nir.c | 7 ++++++- src/compiler/spirv/vtn_private.h | 3 +++ src/compiler/spirv/vtn_subgroup.c | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index fd673d1..2e3caa0 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -101,6 +101,7 @@ struct spirv_supported_capabilities { bool subgroup_basic; bool subgroup_dispatch; bool subgroup_quad; + bool subgroup_rotate; bool subgroup_shuffle; bool subgroup_uniform_control_flow; bool subgroup_vote; diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 2c9c75b..78fbc5f 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -2484,7 +2484,7 @@ vtn_mem_semantics_to_nir_var_modes(struct vtn_builder *b, return modes; } -static nir_scope +nir_scope vtn_scope_to_nir_scope(struct vtn_builder *b, SpvScope scope) { nir_scope nir_scope; @@ -4885,6 +4885,10 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode, spv_check_supported(shader_viewport_mask_nv, cap); break; + case SpvCapabilityGroupNonUniformRotateKHR: + spv_check_supported(subgroup_rotate, cap); + break; + default: vtn_fail("Unhandled capability: %s (%u)", spirv_capability_to_string(cap), cap); @@ -6234,6 +6238,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, case SpvOpSubgroupShuffleDownINTEL: case SpvOpSubgroupShuffleUpINTEL: case SpvOpSubgroupShuffleXorINTEL: + case SpvOpGroupNonUniformRotateKHR: vtn_handle_subgroup(b, opcode, w, count); break; diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index fb4cd12..28ada26 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -600,6 +600,9 @@ const struct glsl_type * 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); + struct vtn_image_pointer { nir_deref_instr *image; nir_ssa_def *coord; diff --git a/src/compiler/spirv/vtn_subgroup.c b/src/compiler/spirv/vtn_subgroup.c index b025661..5fac2ae 100644 --- a/src/compiler/spirv/vtn_subgroup.c +++ b/src/compiler/spirv/vtn_subgroup.c @@ -342,6 +342,20 @@ vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode, break; } + case SpvOpGroupNonUniformRotateKHR: { + const nir_scope scope = vtn_scope_to_nir_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."); + + struct vtn_ssa_value *value = vtn_ssa_value(b, w[4]); + struct vtn_ssa_value *delta = vtn_ssa_value(b, w[5]); + vtn_push_nir_ssa(b, w[2], + vtn_build_subgroup_instr(b, nir_intrinsic_rotate, + value, delta->def, scope, cluster_size)->def); + break; + } + case SpvOpGroupNonUniformQuadBroadcast: vtn_push_ssa_value(b, w[2], vtn_build_subgroup_instr(b, nir_intrinsic_quad_broadcast, -- 2.7.4