yum-mirror/slang

Making it easier to work with shaders

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

Jay KwakImplement MapElement for CoopMat (#7159)984d7f22f

master
2.7 KiB68 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=0 -render-feature cooperative-matrix-per-element-operations
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=1 -render-feature cooperative-matrix-per-element-operations
3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=2 -render-feature cooperative-matrix-per-element-operations
4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=3 -render-feature cooperative-matrix-per-element-operations
5//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=4 -render-feature cooperative-matrix-per-element-operations
6
7//CHECK:type: int32_t
8//CHECK-NEXT:9
9//CHECK-NEXT:12
10//CHECK-NEXT:15
11//CHECK-NEXT:14
12
13//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4),name=input1
14StructuredBuffer<int> input1;
15
16//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4),name=input2
17StructuredBuffer<int> input2;
18
19//TEST_INPUT:ubuffer(data=[2 3 4 1], stride=4),name=input3
20StructuredBuffer<int> input3;
21
22//TEST_INPUT:ubuffer(stride=4, count=256):out,name=outputBuffer
23RWStructuredBuffer<int32_t> outputBuffer;
24
25using namespace linalg;
26
27typealias CoopMatType = CoopMat<int, MemoryScope.Subgroup, 16, 16, CoopMatMatrixUse.MatrixAccumulator>;
28
29int MapOp(uint32_t row, uint32_t col, int a, int b, int c)
30{
31    return a + b + c + 1 + 2 + 3;
32}
33
34[numthreads(32, 1, 1)]
35void computeMain()
36{
37    let stride = 16;
38    let mat1 = CoopMatType.Load<CoopMatMatrixLayout.RowMajor>(input1, 0, stride);
39    let mat2 = CoopMatType.Load<CoopMatMatrixLayout.RowMajor>(input2, 0, stride);
40    let mat3 = CoopMatType.Load<CoopMatMatrixLayout.RowMajor>(input3, 0, stride);
41
42    // Testing the capturing lambda
43    int c0 = 1;
44    int c1 = 2;
45    int c2 = 3;
46
47    CoopMatType result;
48
49#if TEST_MODE == 0
50    result = makeTuple(mat1, mat2, mat3).MapElement(MapOp);
51
52#elif TEST_MODE == 1
53    let f = ((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + 1 + 2 + 3);
54    result = makeTuple(mat1, mat2, mat3).MapElement(f);
55
56#elif TEST_MODE == 2
57    result = makeTuple(mat1, mat2, mat3).MapElement((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + 1 + 2 + 3);
58
59#elif TEST_MODE == 3
60    let f = ((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + c0 + c1 + c2);
61    result = makeTuple(mat1, mat2, mat3).MapElement(f);
62
63#elif TEST_MODE == 4
64    result = makeTuple(mat1, mat2, mat3).MapElement((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + c0 + c1 + c2);
65#endif
66
67    result.Store<CoopMatMatrixLayout.RowMajor>(outputBuffer, 0, stride);
68}