yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1// No atomic support on CPU 2//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj 3// No support for int64_t on DX11 4//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 5// No support for int64_t on fxc - we need SM6.0 and dxil 6// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/hlsl-shader-model-6-0-features-for-direct3d-12 7//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -nvapi-slot u0 -shaderobj 8//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -render-features atomic-int64 -compile-arg -O2 -shaderobj 9//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -render-features atomic-int64 -shaderobj 10//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj 11 12// The test doesn't directly use this, but having this defined makes the 0 slot available if NVAPI is going to be used 13// Only strictly necessary on the D3D12 path 14//TEST_INPUT:ubuffer(data=[0 0 0 0 ], stride=4):name=nvapiBuffer 15RWStructuredBuffer<int> nvapiBuffer; 16 17//TEST_INPUT:ubuffer(data=[0 1 2 3 4 5 6 7]):out,name=outputBuffer 18RWByteAddressBuffer outputBuffer; 19 20[numthreads(16, 1, 1)] 21void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 22{ 23 int tid = dispatchThreadID.x; 24 int idx = (tid & 3) ^ (tid >> 2); 25 26 // Try directly reading 27 uint2 currentValue2 = outputBuffer.Load2(idx << 3); 28 uint64_t currentValue = uint64_t(currentValue2.y) | currentValue2.x; 29 30 while (true) 31 { 32 // This is probably not a great way to do this - InterlockedAddI64 would be better 33 // but we are doing this to test CAS. 34 35 uint64_t readValue; 36 outputBuffer.InterlockedCompareExchangeU64(idx << 3, currentValue, currentValue + 1, readValue); 37 38 if (readValue == currentValue) 39 { 40 break; 41 } 42 43 currentValue = readValue; 44 } 45}