From b89f0bc7300c8952562e2a9e6ce0d458542a4875 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Fri, 18 Apr 2025 04:21:36 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Generate vsir for HLSL_IR_SYNC operations. The following table shows how each intrinsic maps to d3d assembly and the flags that appear in the tpf bytecode, in binary. GroupMemoryBarrier() sync_g 0010 GroupMemoryBarrierWithGroupSync() sync_g_t 0011 DeviceMemoryBarrier() sync_uglobal 1000 DeviceMemoryBarrierWithGroupSync() sync_uglobal_t 1001 AllMemoryBarrier() sync_uglobal_g 1010 AllMemoryBarrierWithGroupSync() sync_uglobal_g_t 1011 --- libs/vkd3d-shader/hlsl_codegen.c | 15 ++++++++++++++- libs/vkd3d-shader/tpf.c | 1 + tests/hlsl/barriers.shader_test | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 5d99e3a11..3909f504b 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -11278,6 +11278,19 @@ static bool sm4_generate_vsir_instr_jump(struct hlsl_ctx *ctx, } } +static bool sm4_generate_vsir_instr_sync(struct hlsl_ctx *ctx, + struct vsir_program *program, const struct hlsl_ir_sync *sync) +{ + const struct hlsl_ir_node *instr = &sync->node; + struct vkd3d_shader_instruction *ins; + + if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_SYNC, 0, 0))) + return false; + ins->flags = sync->sync_flags; + + return true; +} + static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *block, struct vsir_program *program); static void sm4_generate_vsir_instr_if(struct hlsl_ctx *ctx, struct vsir_program *program, struct hlsl_ir_if *iff) @@ -11429,7 +11442,7 @@ static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *blo break; case HLSL_IR_SYNC: - hlsl_fixme(ctx, &instr->loc, "Sync instructions."); + sm4_generate_vsir_instr_sync(ctx, program, hlsl_ir_sync(instr)); break; default: diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index c29bedfaa..48814ffc7 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4213,6 +4213,7 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_ case VKD3DSIH_IMM_ATOMIC_UMIN: case VKD3DSIH_IMM_ATOMIC_OR: case VKD3DSIH_IMM_ATOMIC_XOR: + case VKD3DSIH_SYNC: case VKD3DSIH_IMUL: case VKD3DSIH_INE: case VKD3DSIH_INEG: diff --git a/tests/hlsl/barriers.shader_test b/tests/hlsl/barriers.shader_test index 98f0fea5b..0daa23518 100644 --- a/tests/hlsl/barriers.shader_test +++ b/tests/hlsl/barriers.shader_test @@ -2,7 +2,7 @@ shader model >= 5.0 % This is just a parsing test. -[compute shader todo] +[compute shader] [numthreads(1024, 1, 1)] void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID) {