Description
- Implement
InterlockedExchange
clang builtin, - Link
InterlockedExchange
clang builtin withhlsl_intrinsics.h
- Add sema checks for
InterlockedExchange
toCheckHLSLBuiltinFunctionCall
inSemaChecking.cpp
- Add codegen for
InterlockedExchange
toEmitHLSLBuiltinExpr
inCGBuiltin.cpp
- Add codegen tests to
clang/test/CodeGenHLSL/builtins/InterlockedExchange.hlsl
- Add sema tests to
clang/test/SemaHLSL/BuiltIns/InterlockedExchange-errors.hlsl
- Create the
int_dx_InterlockedExchange
intrinsic inIntrinsicsDirectX.td
- Create the
DXILOpMapping
ofint_dx_InterlockedExchange
to78
inDXIL.td
- Create the
InterlockedExchange.ll
andInterlockedExchange_errors.ll
tests inllvm/test/CodeGen/DirectX/
- Create the
int_spv_InterlockedExchange
intrinsic inIntrinsicsSPIRV.td
- In SPIRVInstructionSelector.cpp create the
InterlockedExchange
lowering and map it toint_spv_InterlockedExchange
inSPIRVInstructionSelector::selectIntrinsic
. - Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/InterlockedExchange.ll
DirectX
DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
---|---|---|---|
78 | AtomicBinOp | 6.0 | () |
SPIR-V
OpAtomicExchange:
Description:
Perform the following steps atomically with respect to any other atomic
accesses within Scope to the same location:
- load through Pointer to get an Original Value,
- get a New Value from copying Value, and
- store the New Value back through Pointer.
The instruction’s result is the Original Value.
Result Type must be a scalar of integer type or
floating-point type.
The type of Value must be the same as Result Type. The type of the
value pointed to by Pointer must be the same as Result Type.
Memory is a memory Scope.
Word Count | Opcode | Results | Operands | ||||
---|---|---|---|---|---|---|---|
7 |
229 |
<id> |
<id> |
Scope <id> |
Memory Semantics
<id> |
<id> |
Test Case(s)
Example 1
//dxc InterlockedExchange_test.hlsl -T lib_6_8 -enable-16bit-types -O0
RWStructuredBuffer<int64_t> buffer : register(u0);
[numthreads(1, 1, 1)]
export void fn(uint3 dispatchThreadID : SV_DispatchThreadID, int64_t p1, int64_t p2) {
int index = dispatchThreadID.x;
return InterlockedExchange(buffer[index], p1, p2);
}
Example 2
//dxc InterlockedExchange_1_test.hlsl -T lib_6_8 -enable-16bit-types -O0
RWStructuredBuffer<float> buffer : register(u0);
[numthreads(1, 1, 1)]
export void fn(uint3 dispatchThreadID : SV_DispatchThreadID, float p1, float p2) {
int index = dispatchThreadID.x;
return InterlockedExchange(buffer[index], p1, p2);
}
Example 3
//dxc InterlockedExchange_2_test.hlsl -T lib_6_8 -enable-16bit-types -O0
RWStructuredBuffer<int> buffer : register(u0);
[numthreads(1, 1, 1)]
export void fn(uint3 dispatchThreadID : SV_DispatchThreadID, int p1, uint p2) {
int index = dispatchThreadID.x;
return InterlockedExchange(buffer[index], p1, p2);
}
HLSL:
Assigns value to dest and returns the original value.
Syntax
void InterlockedExchange(
in R dest,
in T value,
out T original_value
);
Parameters
-
dest [in]
-
Type: R
The destination address.
-
value [in]
-
Type: T
The input value.
-
original_value [out]
-
Type: T
The original value.
Return value
This function does not return a value.
Remarks
This operation can only be performed on scalar-typed resources and shared memory variables. There are two possible uses for this function. The first is when R is a shared memory variable type. In this case, the function performs the operation on the shared memory register referenced by dest. The second scenario is when R is a resource variable type. In this scenario, the function performs the operation on the resource location referenced by dest. This operation is only available when R is readable and writable.
Interlocked operations do not imply any memory fence/barrier.
Minimum Shader Model
This function is supported in the following shader models.
Shader Model | Supported |
---|---|
Shader Model 5 and higher shader models | yes |
This function is supported in the following types of shaders:
Vertex | Hull | Domain | Geometry | Pixel | Compute |
---|---|---|---|---|---|
x | x | x | x | x | x |
See also
Metadata
Metadata
Assignees
Type
Projects
Status