yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
1.9 KiB57 linesraw
1//TEST_CATEGORY(wave-mask, compute)
2//DISABLE_TEST:COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
3//DISABLE_TEST:COMPARE_COMPUTE_EX:-slang -compute -shaderobj
4//TEST:COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -shaderobj -render-feature hardware-device
5// Disabled on VK because glsl can't do WaveReadLaneAt on matrix. 
6//DISABLE_TEST(vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
7//TEST:COMPARE_COMPUTE_EX:-cuda -compute -shaderobj
8
9//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
10RWStructuredBuffer<int> outputBuffer;
11
12// Note from HLSL: `The input lane index must be uniform across the wave.`. 
13// The same restriction applies to glsl/SPIR-V 1.5
14// So we are going to use the input buffer to achieve this.
15
16//TEST_INPUT:ubuffer(data=[1 2 3 0], stride=4):name inputBuffer
17RWStructuredBuffer<int> inputBuffer;
18
19[numthreads(4, 1, 1)]
20void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
21{
22    WaveMask mask = 0xf;
23    
24    int idx = int(dispatchThreadID.x);
25    
26    int value = 0;
27    
28    for (int i = 0; i < 4; ++i)
29    {
30        // Scalar
31        
32        // The laneId is 'dynamic' but it also uniform across the wave (as required by spec)
33        const int laneId = inputBuffer[i];
34        
35        value += WaveMaskReadLaneAt(mask, idx, laneId);
36        
37        // vector
38        
39        {
40            float2 v = float2(idx + 1, idx + 2);
41            float2 readValue = WaveMaskReadLaneAt(mask, v, (laneId + 1) & 3);
42            
43            value += int(readValue[0] + readValue[1]);
44        }
45            
46        // matrix
47        {
48            matrix<int, 2, 2> v = matrix<int, 2, 2>(idx, idx - 1, idx * 3, idx - 2);
49            
50            matrix<int, 2, 2> readValue = WaveMaskReadLaneAt(mask, v, (laneId - 1) & 3);
51            
52            value += int(readValue[0][0] + readValue[0][1] + readValue[1][0] + readValue[1][1]);
53        }
54    }
55    
56    outputBuffer[idx] = value;
57}