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