vkd3d-shader/hlsl: Implement the InterlockedExchange() intrinsic.

This commit is contained in:
Shaun Ren 2025-01-16 16:16:42 -05:00 committed by Henri Verbeet
parent 3fb47373a1
commit b447fdce51
Notes: Henri Verbeet 2025-01-20 16:18:51 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Elizabeth Figura (@zfigura)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1330
6 changed files with 15 additions and 3 deletions

View File

@ -3509,6 +3509,7 @@ static void dump_ir_interlocked(struct vkd3d_string_buffer *buffer, const struct
[HLSL_INTERLOCKED_ADD] = "add",
[HLSL_INTERLOCKED_AND] = "and",
[HLSL_INTERLOCKED_CMP_EXCH] = "cmp_exch",
[HLSL_INTERLOCKED_EXCH] = "exch",
};
VKD3D_ASSERT(interlocked->op < ARRAY_SIZE(op_names));

View File

@ -956,6 +956,7 @@ enum hlsl_interlocked_op
HLSL_INTERLOCKED_ADD,
HLSL_INTERLOCKED_AND,
HLSL_INTERLOCKED_CMP_EXCH,
HLSL_INTERLOCKED_EXCH,
};
/* Represents an interlocked operation.

View File

@ -5388,7 +5388,8 @@ static bool intrinsic_interlocked(struct hlsl_ctx *ctx, enum hlsl_interlocked_op
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE,
"Interlocked functions can only be used in shader model 5.0 or higher.");
if (op != HLSL_INTERLOCKED_CMP_EXCH && params->args_count != 2 && params->args_count != 3)
if (op != HLSL_INTERLOCKED_CMP_EXCH && op != HLSL_INTERLOCKED_EXCH
&& params->args_count != 2 && params->args_count != 3)
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Unexpected number of arguments to function '%s': expected 2 or 3, but got %u.",
@ -5509,6 +5510,12 @@ static bool intrinsic_InterlockedCompareStore(struct hlsl_ctx *ctx,
return intrinsic_interlocked(ctx, HLSL_INTERLOCKED_CMP_EXCH, params, loc, "InterlockedCompareStore");
}
static bool intrinsic_InterlockedExchange(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
return intrinsic_interlocked(ctx, HLSL_INTERLOCKED_EXCH, params, loc, "InterlockedExchange");
}
static const struct intrinsic_function
{
const char *name;
@ -5526,6 +5533,7 @@ intrinsic_functions[] =
{"InterlockedAnd", -1, true, intrinsic_InterlockedAnd},
{"InterlockedCompareExchange", 4, true, intrinsic_InterlockedCompareExchange},
{"InterlockedCompareStore", 3, true, intrinsic_InterlockedCompareStore},
{"InterlockedExchange", 3, true, intrinsic_InterlockedExchange},
{"abs", 1, true, intrinsic_abs},
{"acos", 1, true, intrinsic_acos},
{"all", 1, true, intrinsic_all},

View File

@ -10010,6 +10010,7 @@ static bool sm4_generate_vsir_instr_interlocked(struct hlsl_ctx *ctx,
[HLSL_INTERLOCKED_ADD] = VKD3DSIH_IMM_ATOMIC_IADD,
[HLSL_INTERLOCKED_AND] = VKD3DSIH_IMM_ATOMIC_AND,
[HLSL_INTERLOCKED_CMP_EXCH] = VKD3DSIH_IMM_ATOMIC_CMP_EXCH,
[HLSL_INTERLOCKED_EXCH] = VKD3DSIH_IMM_ATOMIC_EXCH,
};
struct hlsl_ir_node *cmp_value = interlocked->cmp_value.node, *value = interlocked->value.node;

View File

@ -4073,6 +4073,7 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_
case VKD3DSIH_IMIN:
case VKD3DSIH_IMM_ATOMIC_AND:
case VKD3DSIH_IMM_ATOMIC_CMP_EXCH:
case VKD3DSIH_IMM_ATOMIC_EXCH:
case VKD3DSIH_IMM_ATOMIC_IADD:
case VKD3DSIH_IMUL:
case VKD3DSIH_INE:

View File

@ -217,7 +217,7 @@ size (buffer, 5)
% The value fields of other Interlocked functions are always uint.
[compute shader fail(sm<5) todo(sm>=5)]
[compute shader fail(sm<5)]
RWBuffer<uint> u : register(u1);
RWBuffer<int> s : register(u2);
@ -245,7 +245,7 @@ void main()
[test]
uniform 0 uint 0xffffffff
uniform 1 float -1
todo(sm<6) dispatch 1 1 1
todo(glsl | msl) dispatch 1 1 1
if(sm<6) probe uav 1 (0) rui (0xffffffff)
if(sm>=6) probe uav 1 (0) rui (0xfffffffd)
probe uav 1 (1) rui (0)