From 3fb47373a1e25e2bc6e4a8bd2f562e99f844368e Mon Sep 17 00:00:00 2001 From: Shaun Ren Date: Thu, 12 Dec 2024 18:44:24 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Implement the InterlockedCompareStore() intrinsic. --- libs/vkd3d-shader/hlsl.y | 10 +++++++++- libs/vkd3d-shader/hlsl_codegen.c | 1 + libs/vkd3d-shader/tpf.c | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 46d36ebf..8df61cba 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -5403,7 +5403,8 @@ static bool intrinsic_interlocked(struct hlsl_ctx *ctx, enum hlsl_interlocked_op { cmp_val = params->args[1]; val = params->args[2]; - orig_val = params->args[3]; + if (params->args_count == 4) + orig_val = params->args[3]; } else { @@ -5502,6 +5503,12 @@ static bool intrinsic_InterlockedCompareExchange(struct hlsl_ctx *ctx, return intrinsic_interlocked(ctx, HLSL_INTERLOCKED_CMP_EXCH, params, loc, "InterlockedCompareExchange"); } +static bool intrinsic_InterlockedCompareStore(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + return intrinsic_interlocked(ctx, HLSL_INTERLOCKED_CMP_EXCH, params, loc, "InterlockedCompareStore"); +} + static const struct intrinsic_function { const char *name; @@ -5518,6 +5525,7 @@ intrinsic_functions[] = {"InterlockedAdd", -1, true, intrinsic_InterlockedAdd}, {"InterlockedAnd", -1, true, intrinsic_InterlockedAnd}, {"InterlockedCompareExchange", 4, true, intrinsic_InterlockedCompareExchange}, + {"InterlockedCompareStore", 3, true, intrinsic_InterlockedCompareStore}, {"abs", 1, true, intrinsic_abs}, {"acos", 1, true, intrinsic_acos}, {"all", 1, true, intrinsic_all}, diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 2d017c88..0c57ce04 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -10002,6 +10002,7 @@ static bool sm4_generate_vsir_instr_interlocked(struct hlsl_ctx *ctx, { [HLSL_INTERLOCKED_ADD] = VKD3DSIH_ATOMIC_IADD, [HLSL_INTERLOCKED_AND] = VKD3DSIH_ATOMIC_AND, + [HLSL_INTERLOCKED_CMP_EXCH] = VKD3DSIH_ATOMIC_CMP_STORE, }; static const enum vkd3d_shader_opcode imm_opcodes[] = diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 891618bc..34977933 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4027,6 +4027,7 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_ case VKD3DSIH_ADD: case VKD3DSIH_ATOMIC_AND: + case VKD3DSIH_ATOMIC_CMP_STORE: case VKD3DSIH_ATOMIC_IADD: case VKD3DSIH_AND: case VKD3DSIH_BREAK: