yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//TEST_CATEGORY(wave, 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 -capability cuda_sm_7_0 -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 int idx = int(dispatchThreadID.x); 23 24 int value = 0; 25 26 for (int i = 0; i < 4; ++i) 27 { 28 // Scalar 29 30 // The landId is 'dynamic' but it also uniform across the wave (as required by spec) 31 const int laneId = inputBuffer[i]; 32 33 value += WaveReadLaneAt(idx, laneId); 34 35 // vector 36 37 { 38 float2 v = float2(idx + 1, idx + 2); 39 float2 readValue = WaveReadLaneAt(v, (laneId + 1) & 3); 40 41 value += int(readValue[0] + readValue[1]); 42 } 43 44 // matrix 45 { 46 matrix<int, 2, 2> v = matrix<int, 2, 2>(idx, idx - 1, idx * 3, idx - 2); 47 48 matrix<int, 2, 2> readValue = WaveReadLaneAt(v, (laneId - 1) & 3); 49 50 value += int(readValue[0][0] + readValue[0][1] + readValue[1][0] + readValue[1][1]); 51 } 52 } 53 54 outputBuffer[idx] = value; 55}