yum-mirror/slang

Making it easier to work with shaders

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

jarcherNVAdd warnings for overflows of integer types (#8281)5055de0bb

master
1.7 KiB37 linesraw
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    int64_t previousValue = 0;
27    outputBuffer.InterlockedAddI64((idx << 3), 1, previousValue);
28    
29    int anotherIdx = tid >> 2;
30    outputBuffer.InterlockedAddI64(anotherIdx << 3, 3);
31    
32    // Bit logical
33    outputBuffer.InterlockedOrU64((idx << 3), (uint64_t(2) << 32) | (tid << 4));
34    outputBuffer.InterlockedXorU64((idx << 3), tid << 8);
35    outputBuffer.InterlockedAndU64((idx << 3), (uint64_t(tid | 2) << 32) |  0xffffffffffffffffULL);
36}
37