yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

ArielG-NVCapability System: Implicit capability upgrade warning/error (#4241)8813c6105

master
1.2 KiB34 linesraw
1// atomic-float-byte-address-buffer-cross.slang
2
3//TEST:SIMPLE(filecheck=CHECK_SPV): -profile cs_6_5 -entry computeMain -target spirv-assembly
4//TEST:SIMPLE(filecheck=CHECK_SPV): -profile cs_6_5 -entry computeMain -target spirv-assembly -emit-spirv-via-glsl
5//TEST:SIMPLE(filecheck=CHECK_GLSL): -profile cs_6_5 -entry computeMain -target glsl
6// We can't do this test, because it relies on nvAPI
7//DISABLE_TEST:CROSS_COMPILE: -profile cs_6_5 -entry computeMain -target dxil
8
9RWByteAddressBuffer outputBuffer;
10
11RWStructuredBuffer<float> anotherBuffer;
12
13// CHECK_SPV: OpAtomicFAddEXT
14// CHECK_SPV: OpAtomicFAddEXT
15// CHECK_GLSL: atomicAdd
16// CHECK_GLSL: atomicAdd
17// CHECK_HLSL: NvInterlockedAddFp32
18// CHECK_HLSL: NvInterlockedAddFp32
19
20[numthreads(16, 1, 1)]
21void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
22{
23    uint tid = dispatchThreadID.x;
24    int idx = int((tid & 3) ^ (tid >> 2)); 
25
26    const float delta = anotherBuffer[idx & 3];
27
28    float previousValue = 0;
29    outputBuffer.InterlockedAddF32((idx << 2), 1.0f, previousValue);
30    
31    // The sum of values in anotherBuffer should also be added
32    int anotherIdx = int(tid >> 2);
33    outputBuffer.InterlockedAddF32(anotherIdx << 2, delta);
34}