yum-mirror/slang

Making it easier to work with shaders

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

Anders LeinoEnable a bunch of WGPU tests (#5513)43df1da01

master
1.2 KiB34 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
3
4void writeToArray<U, T : IRWArray<U>>(inout T array, int index, U value) { array[index] = value; }
5void writeToBuffer<U, T : IRWArray<U>>(T array, int index, U value) { array[index] = value; }
6U readFromArray<U, T:IArray<U>>(T array, int index) { return array[index]; }
7
8//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
9RWStructuredBuffer<float> outputBuffer;
10
11[numthreads(1, 1, 1)]
12void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
13{
14    float arr[3] = { 1.0, 2.0, 3.0 };
15    float4 v = float4(1.0, 2.0, 3.0, 4.0);
16    float2x2 m = float2x2(1.0, 2.0, 3.0, 4.0);
17
18    // CHECK: 1.0
19    writeToBuffer(outputBuffer, 0, 1.0f);
20
21    // CHECK: 4.0
22    writeToArray(arr, 0, 4.0f);
23    outputBuffer[1] = readFromArray(arr, 0);
24
25    // CHECK: 3.0
26    writeToArray(v, 3, 3.0f);
27    outputBuffer[2] = readFromArray(v, 3);
28
29    // CHECK: 30.0
30    writeToArray(m, 1, float2(10.0f, 20.0f));
31    outputBuffer[3] = readFromArray(m, 1).x + readFromArray(m, 1).y;
32
33    writeToBuffer(outputBuffer, 0, readFromArray(outputBuffer, 0));
34}