From e1c774bfeb17958790f4986a10a767940ddd29de Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Tue, 23 Apr 2024 23:36:42 +1000 Subject: [PATCH] vkd3d-shader/spirv: Implement the WAVE_READ_LANE_FIRST instruction. --- libs/vkd3d-shader/spirv.c | 27 +++++++++++++++++++++++++++ tests/hlsl/wave-ops-float.shader_test | 4 ++-- tests/hlsl/wave-ops-uint.shader_test | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 6b75cfb1..78f2f208 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -1791,6 +1791,14 @@ static uint32_t vkd3d_spirv_build_op_group_nonuniform_shuffle(struct vkd3d_spirv vkd3d_spirv_get_op_scope_subgroup(builder), val_id, lane_id); } +static uint32_t vkd3d_spirv_build_op_group_nonuniform_broadcast_first(struct vkd3d_spirv_builder *builder, + uint32_t result_type, uint32_t val_id) +{ + vkd3d_spirv_enable_capability(builder, SpvCapabilityGroupNonUniformBallot); + return vkd3d_spirv_build_op_tr2(builder, &builder->function_stream, SpvOpGroupNonUniformBroadcastFirst, + result_type, vkd3d_spirv_get_op_scope_subgroup(builder), val_id); +} + static uint32_t vkd3d_spirv_build_op_glsl_std450_tr1(struct vkd3d_spirv_builder *builder, enum GLSLstd450 op, uint32_t result_type, uint32_t operand) { @@ -9969,6 +9977,22 @@ static void spirv_compiler_emit_wave_read_lane_at(struct spirv_compiler *compile spirv_compiler_emit_store_dst(compiler, dst, val_id); } +static void spirv_compiler_emit_wave_read_lane_first(struct spirv_compiler *compiler, + const struct vkd3d_shader_instruction *instruction) +{ + struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; + const struct vkd3d_shader_dst_param *dst = instruction->dst; + const struct vkd3d_shader_src_param *src = instruction->src; + uint32_t type_id, val_id; + + type_id = vkd3d_spirv_get_type_id_for_data_type(builder, dst->reg.data_type, + vsir_write_mask_component_count(dst->write_mask)); + val_id = spirv_compiler_emit_load_src(compiler, src, dst->write_mask); + val_id = vkd3d_spirv_build_op_group_nonuniform_broadcast_first(builder, type_id, val_id); + + spirv_compiler_emit_store_dst(compiler, dst, val_id); +} + /* This function is called after declarations are processed. */ static void spirv_compiler_emit_main_prolog(struct spirv_compiler *compiler) { @@ -10344,6 +10368,9 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, case VKD3DSIH_WAVE_READ_LANE_AT: spirv_compiler_emit_wave_read_lane_at(compiler, instruction); break; + case VKD3DSIH_WAVE_READ_LANE_FIRST: + spirv_compiler_emit_wave_read_lane_first(compiler, instruction); + break; case VKD3DSIH_DCL: case VKD3DSIH_DCL_HS_MAX_TESSFACTOR: case VKD3DSIH_DCL_INPUT_CONTROL_POINT_COUNT: diff --git a/tests/hlsl/wave-ops-float.shader_test b/tests/hlsl/wave-ops-float.shader_test index efa7dbc4..b54f5ac1 100644 --- a/tests/hlsl/wave-ops-float.shader_test +++ b/tests/hlsl/wave-ops-float.shader_test @@ -111,7 +111,7 @@ void main(uint id : SV_GroupIndex) } [test] -todo dispatch 4 1 1 +dispatch 4 1 1 probe uav 1 (0) rgba (7.0, 2.0, 8.0, 5.0) probe uav 1 (1) rgba (7.0, 2.0, 8.0, 5.0) probe uav 1 (2) rgba (7.0, 2.0, 8.0, 5.0) @@ -451,7 +451,7 @@ float4 main(float4 pos : SV_Position) : SV_Target [test] clear rtv 0 0.25 0.5 0.75 1.0 -todo draw quad +draw quad probe rtv 0 (0, 0) rgba (0.25, 0.5, 0.75, 1.0) probe rtv 0 (1, 0) rgba (1.0, 0.0, 0.0, 1.0) probe rtv 0 (0, 1) rgba (1.0, 0.0, 0.0, 1.0) diff --git a/tests/hlsl/wave-ops-uint.shader_test b/tests/hlsl/wave-ops-uint.shader_test index 49dbd1c2..0be5cdf6 100644 --- a/tests/hlsl/wave-ops-uint.shader_test +++ b/tests/hlsl/wave-ops-uint.shader_test @@ -139,7 +139,7 @@ void main(uint id : SV_GroupIndex) } [test] -todo dispatch 4 1 1 +dispatch 4 1 1 probe uav 1 (0) rui (23) probe uav 1 (1) rui (23) probe uav 1 (2) rui (23)