yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
93f5d13fc
master
1// atomics-groupshared.slang 2 3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 4//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj 5//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -shaderobj 6//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -shaderobj 7//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl 8// Not supported in WGSL: Use of traditional atomics intrinsics (InterlockedXXX functions) 9//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -wgpu 10 11//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 12 13RWStructuredBuffer<uint> outputBuffer; 14 15groupshared uint shared[4]; 16 17uint test(uint val) 18{ 19 uint originalValue; 20 21 shared[val] = 0; 22 23 GroupMemoryBarrierWithGroupSync(); 24 25 uint originalSum = 0; 26 27 InterlockedAdd(shared[val], val, originalValue); 28 originalSum += originalValue; 29 30 InterlockedAdd(shared[val ^ 1], val*16, originalValue); 31 originalSum += originalValue; 32 33 InterlockedAdd(shared[val ^ 2], val*16*16, originalValue); 34 originalSum += originalValue; 35 36 GroupMemoryBarrierWithGroupSync(); 37 38 return shared[val] ^ originalSum; 39} 40 41[numthreads(4, 1, 1)] 42void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 43{ 44 uint tid = dispatchThreadID.x; 45 uint val = test(tid); 46 outputBuffer[tid] = val; 47}