yum-mirror/slang

Making it easier to work with shaders

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

Yong HeWarning on lossy implicit casts. (#2367)adaea0e99

master
2.0 KiB56 linesraw
1// bound-check-zero-index.slang
2
3// Check 'zero indexing' bound check feature, supported by CPU and CUDA
4
5// Currently zero index bound checking doesn't appear to be working properly for CUDA.
6//TEST(compute):COMPARE_COMPUTE:-cuda -shaderobj -Xslang... -DSLANG_ENABLE_BOUND_ZERO_INDEX -X.
7//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj -Xslang... -DSLANG_ENABLE_BOUND_ZERO_INDEX -X.
8
9//TEST_INPUT:ubuffer(data=[1 2 3 4]):name=byteAddressBuffer
10ByteAddressBuffer byteAddressBuffer;
11
12//TEST_INPUT:ubuffer(data=[0x10 0x20 0x30 0x40]):name=rwByteAddressBuffer
13RWByteAddressBuffer rwByteAddressBuffer;
14
15//TEST_INPUT:ubuffer(data=[0x100 0x200 0x300 0x400], stride=4):name=structuredBuffer
16StructuredBuffer<int> structuredBuffer;
17
18//TEST_INPUT:ubuffer(data=[0x1000 0x2000 0x3000 0x4000], stride=4):name=rwStructuredBuffer
19RWStructuredBuffer<int> rwStructuredBuffer;
20
21//TEST_INPUT:ubuffer(data=[-1 -1 -1 -1], stride=4):out,name=outputBuffer
22RWStructuredBuffer<int> outputBuffer;
23
24//TEST_INPUT:ubuffer(data=[-1 -1 -1 -1], stride=4):out,name=outputBuffer2
25RWStructuredBuffer<int> outputBuffer2;
26
27[numthreads(4, 1, 1)]
28void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
29{
30	int tid = dispatchThreadID.x;
31    
32    int fixedArray[3] = { 2, 5, 9};
33    
34    int total = 0;
35    total += byteAddressBuffer.Load<int>(tid * 4);
36    total += byteAddressBuffer.Load<int>(-tid * 4);
37    
38    total += rwByteAddressBuffer.Load<int>(tid * 4);
39    total += rwByteAddressBuffer.Load<int>(-tid * 4);
40    
41    total += structuredBuffer[tid];
42    total += structuredBuffer[-tid];
43    
44    total += rwStructuredBuffer[tid];
45    total += rwStructuredBuffer[-tid];
46    
47    total += fixedArray[tid];
48    total += fixedArray[-tid];
49    
50    outputBuffer[tid] = total;
51    
52    // NOTE! Different threads could access this if being performed in parallel.
53    // So undeterministic if we write to same index (because out of range) when running in parallel
54    // By just adding one, all indices should be hit once
55    outputBuffer2[tid + 1] = total;
56}