yum-mirror/slang

Making it easier to work with shaders

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

Ellie HermaszewskaSPIR-V image operations (#3163)2c2294d33

master
1.7 KiB62 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly -output-using-type
2
3//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
4RWStructuredBuffer<int> outputBuffer;
5
6// CHECK:      8
7// CHECK-NEXT: 13
8// CHECK-NEXT: 18
9// CHECK-NEXT: 23
10
11//
12// This test tests the __truncate operator
13//
14[numthreads(4, 1, 1)]
15void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
16{
17    int i = dispatchThreadID.x;
18    int n = outputBuffer[i];
19
20    int scalar = n;
21
22    // 1-vectors are not valid in SPIR-V
23    // vector<int, 1> vector1 = vector<int, 1>(n);
24
25    vector<int, 4> vector4 = n + vector<int, 4>(0,1,2,3);
26    //int expected = 0 + n + n + (n + (n+1) + (n+2));
27
28    int r = 0;
29    spirv_asm
30    {
31        // scalar to scalar
32        __truncate $$int %a1 $$int $scalar;
33        %r1 : $$int = OpIAdd %a1 $r;
34
35        // scalar to 1-vector
36        // __truncate $$vector<int,1> %a2 $$int $scalar;
37        // %x1 : $$int = OpCompositeExtract %a2 0;
38        // %r2 : $$int = OpIAdd %x1 %r1;
39        %r2 : $$int = OpCopyObject %r1;
40
41        // 1-vector to scalar
42        // __truncate $$int %a3 $$vector<int,1> $vector1;
43        // %r3 : $$int = OpIAdd %a3 %r2;
44        %r3 : $$int = OpCopyObject %r2;
45
46        // n-vector to scalar
47        __truncate $$int %a4 $$vector<int,4> $vector4;
48        %r4 : $$int = OpIAdd %a4 %r3;
49
50        // n-vector to m-vector
51        __truncate $$vector<int,3> %a5 $$vector<int,4> $vector4;
52        %x2 : $$int = OpCompositeExtract %a5 0;
53        %x3 : $$int = OpCompositeExtract %a5 1;
54        %x4 : $$int = OpCompositeExtract %a5 2;
55        %r5 : $$int = OpIAdd %x2 %r4;
56        %r6 : $$int = OpIAdd %x3 %r5;
57        %r7 : $$int = OpIAdd %x4 %r6;
58
59        OpStore &r %r7
60    };
61    outputBuffer[i] = r;
62}