yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)Enable metal tests (#8446)8086adc90

master
3.8 KiB120 linesraw
1//TEST:SIMPLE(filecheck=METAL): -target metal -stage compute -entry computeMain
2//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage compute -entry computeMain
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -mtl -shaderobj
4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -vk -shaderobj
5
6//TEST_INPUT:ubuffer(data=[1 0], stride=4):name inputBuffer
7//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
8RWStructuredBuffer<int> inputBuffer;
9RWStructuredBuffer<int> outputBuffer;
10
11// Global bool constants to avoid constant folding
12static bool trueVal;
13static bool falseVal;
14
15struct matrixWrapper {
16    bool2x2 mat1 = bool2x2(falseVal, falseVal, falseVal, falseVal);
17    bool2x3 mat2 = bool2x3(trueVal, trueVal, falseVal, falseVal, falseVal, trueVal);
18}
19
20bool elementAnd(bool2x2 matrix)
21{
22    return trueVal
23        && matrix[0][0]
24        && matrix[0][1]
25        && matrix[1][0]
26        && matrix[1][1];
27}
28
29// METAL: array<bool2, int(2)>
30// METALLIB: @computeMain
31
32[numthreads(1, 1, 1)]
33void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
34{
35    // Load true/false values from input buffer to avoid constant folding
36    trueVal = inputBuffer[0] != 0;
37    falseVal = inputBuffer[1] != 0;
38    
39    // Test bool matrix construction
40    bool2x2 mat1 = bool2x2(trueVal, falseVal, falseVal, trueVal);
41    bool3x3 mat2 = bool3x3(
42        trueVal, falseVal, trueVal,
43        falseVal, trueVal, falseVal,
44        trueVal, falseVal, trueVal
45    );
46    bool2x4 mat3 = bool2x4(
47        trueVal, falseVal, trueVal, falseVal,
48        trueVal, falseVal, trueVal, falseVal
49    );
50    
51    // Test bool matrix element access
52    bool val1 = mat1[0][0];
53    bool val2 = mat2[2][1];
54    
55    // Test bool matrix row access
56    bool2 row = mat1[1];
57    bool3 row3 = mat2[0];
58    
59    // Test logical operations
60    bool2x2 not_mat = !mat1;
61    bool2x2 and_mat = mat1 && bool2x2(trueVal, trueVal, falseVal, falseVal);
62    
63    // Test element assignment
64    mat1[0][1] = trueVal;
65    mat2[1][2] = falseVal;
66
67    // Test passing bool matrices to functions
68    bool anded = elementAnd(mat1);
69
70    // Test structs with bool matrix fields
71    matrixWrapper wrapper = {};
72    
73    // Test any/all operations
74    bool2x2 all_true = bool2x2(trueVal, trueVal, trueVal, trueVal);
75    bool2x2 all_false = bool2x2(falseVal, falseVal, falseVal, falseVal);
76    bool2x2 mixed = bool2x2(trueVal, falseVal, trueVal, falseVal);
77    
78    bool test_all_true = all(all_true);      // all elements true -> true
79    bool test_all_false = all(all_false);    // all elements false -> false
80    bool test_all_mixed = all(mixed);        // some elements false -> false
81    bool test_any_true = any(all_true);      // some elements true -> true
82    bool test_any_false = any(all_false);    // no elements true -> false
83    bool test_any_mixed = any(mixed);        // some elements true -> true
84
85    // Store results
86    outputBuffer[0] = val1;
87    // BUF: 1
88    outputBuffer[1] = val2;
89    // BUF-NEXT: 0
90    outputBuffer[2] = row.x;
91    // BUF-NEXT: 0
92    outputBuffer[3] = row.y;
93    // BUF-NEXT: 1
94    outputBuffer[4] = row3.y;
95    // BUF-NEXT: 0
96    outputBuffer[5] = not_mat[0][0];
97    // BUF-NEXT: 0
98    outputBuffer[6] = and_mat[0][0];
99    // BUF-NEXT: 1
100    outputBuffer[7] = mat1[0][1];
101    // BUF-NEXT: 1 
102    outputBuffer[8] = mat3[0][1];
103    // BUF-NEXT: 0 
104    outputBuffer[9] = anded;
105    // BUF-NEXT: 0 
106    outputBuffer[10] = wrapper.mat1[0][0] || wrapper.mat2[0][0];
107    // BUF-NEXT: 1
108    outputBuffer[11] = test_all_true;
109    // BUF-NEXT: 1
110    outputBuffer[12] = test_all_false;
111    // BUF-NEXT: 0
112    outputBuffer[13] = test_all_mixed;
113    // BUF-NEXT: 0
114    outputBuffer[14] = test_any_true;
115    // BUF-NEXT: 1
116    outputBuffer[15] = test_any_false;
117    // BUF-NEXT: 0
118    outputBuffer[16] = test_any_mixed;
119    // BUF-NEXT: 1
120}