summaryrefslogtreecommitdiff
path: root/tests/hlsl-intrinsic/byte-address-buffer/byte-address-half-atomics.slang
blob: d23a675b251324c70bab0dd3c8da528fb58a53fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// byte-address-half-atomics.slang
// test the atomics on half types.

// Disabled because validation layer doesn't like vector atomics, although nv driver does allow it.
//DISABLED_TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -compute -profile cs_6_2 -render-features half -shaderobj -emit-spirv-directly -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -compute -profile cs_6_2 -render-features half -shaderobj -emit-spirv-directly -output-using-type
//TEST:SIMPLE(filecheck=SPIRV):-target spirv -entry computeMain -stage compute -emit-spirv-directly -skip-spirv-validation
//TEST:SIMPLE(filecheck=HLSL):-target hlsl -entry computeMain -profile cs_6_3
//TEST_INPUT:set tmpBuffer = ubuffer(data=[0 0 0 0], stride=4)
RWByteAddressBuffer tmpBuffer;

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
    half originalValue;
    
    // SPIRV: OpAtomicFAddEXT
    // HLSL: NvInterlockedAddFp16x2
    tmpBuffer.InterlockedAddF16(0, 1.0h, originalValue);
    tmpBuffer.InterlockedAddF16(2, 2.0h, originalValue);
    
    half2 v = tmpBuffer.Load<half2>(0);
    
    // CHECK: 1.0
    outputBuffer[0] = v.x;
    // CHECK: 2.0
    outputBuffer[1] = v.y;
    // CHECK: 0.0
    outputBuffer[3] = originalValue;
}