Skip to content

Commit e683e20

Browse files
committed
[Matrix] Add basic single subscript tests
fixes #630 This change just does single subscript gets\sets. It reserves swizzle use to only when a matrix single index is constant in the subscript.
1 parent 88f018a commit e683e20

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#--- source.hlsl
2+
RWBuffer<int> In : register(u0);
3+
RWBuffer<int> Out : register(u1);
4+
5+
[numthreads(1,1,1)]
6+
void main() {
7+
int4x4 A = int4x4(In[0], In[1], In[2], In[3],
8+
In[4], In[5], In[6], In[7],
9+
In[8], In[9], In[10], In[11],
10+
In[12], In[13], In[14], In[15]);
11+
int4x4 B;
12+
13+
B[0] = A[3];
14+
B[1].rbag = A[1];
15+
B[2] = A[2].bagr;
16+
B[3] = A[0];
17+
18+
const uint COLS = 4;
19+
for(int i = 0; i < 16; i++) {
20+
uint row = i / COLS;
21+
uint col = i % COLS;
22+
Out[i] = B[row][col];
23+
}
24+
}
25+
//--- pipeline.yaml
26+
27+
---
28+
Shaders:
29+
- Stage: Compute
30+
Entry: main
31+
DispatchSize: [1, 1, 1]
32+
Buffers:
33+
- Name: In
34+
Format: Int32
35+
Data: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
36+
- Name: Out
37+
Format: Int32
38+
FillSize: 64
39+
- Name: ExpectedOut
40+
Format: Int32
41+
Data: [ 13, 14, 15, 16, 5, 8, 6, 7, 11, 12, 10, 9, 1, 2, 3, 4 ]
42+
Results:
43+
- Result: Out
44+
Rule: BufferExact
45+
Actual: Out
46+
Expected: ExpectedOut
47+
DescriptorSets:
48+
- Resources:
49+
- Name: In
50+
Kind: RWBuffer
51+
DirectXBinding:
52+
Register: 0
53+
Space: 0
54+
VulkanBinding:
55+
Binding: 0
56+
- Name: Out
57+
Kind: RWBuffer
58+
DirectXBinding:
59+
Register: 1
60+
Space: 0
61+
VulkanBinding:
62+
Binding: 1
63+
...
64+
#--- end
65+
66+
# Bug: https://github.com/llvm/llvm-project/issues/172805
67+
# XFAIL: Clang
68+
# RUN: split-file %s %t
69+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
70+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#--- source.hlsl
2+
RWBuffer<int> In : register(u0);
3+
RWBuffer<int> Index : register(u1);
4+
RWBuffer<int> Out : register(u2);
5+
RWBuffer<int> Out2 : register(u3);
6+
7+
int4 getMatrix(int4x4 M, int index) {
8+
return M[index];
9+
}
10+
11+
[numthreads(1,1,1)]
12+
void main() {
13+
int4 A = int4(In[0], In[1], In[2], In[3]);
14+
int4 B = int4(In[4], In[5], In[6], In[7]);
15+
int4 C = int4(In[8], In[9], In[10], In[11]);
16+
int4 D = int4(In[12], In[13], In[14], In[15]);
17+
18+
int4x4 Mat;
19+
Mat[Index[0]] = A;
20+
Mat[Index[1]] = B;
21+
Mat[Index[2]] = C;
22+
Mat[Index[3]] = D;
23+
24+
int4x4 Mat2;
25+
Mat2[Index[3]] = getMatrix(Mat, Index[0]);
26+
Mat2[Index[2]] = getMatrix(Mat, Index[1]);
27+
Mat2[Index[1]] = getMatrix(Mat, Index[2]);
28+
Mat2[Index[0]] = getMatrix(Mat, Index[3]);
29+
30+
const uint COLS = 4;
31+
for(int i = 0; i < 16; i++) {
32+
uint row = i / COLS;
33+
uint col = i % COLS;
34+
Out[i] = Mat[row][col];
35+
Out2[i] = Mat2[row][col];
36+
}
37+
38+
39+
}
40+
//--- pipeline.yaml
41+
42+
---
43+
Shaders:
44+
- Stage: Compute
45+
Entry: main
46+
DispatchSize: [1, 1, 1]
47+
Buffers:
48+
- Name: In
49+
Format: Int32
50+
Data: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
51+
- Name: Index
52+
Format: Int32
53+
Data: [ 2, 0, 3, 1 ]
54+
- Name: Out
55+
Format: Int32
56+
FillSize: 64
57+
- Name: ExpectedOut
58+
Format: Int32
59+
Data: [ 5, 6, 7, 8, 13, 14, 15, 16, 1, 2, 3, 4, 9, 10, 11, 12]
60+
- Name: Out2
61+
Format: Int32
62+
FillSize: 64
63+
- Name: ExpectedOut2
64+
Format: Int32
65+
Data: [ 9, 10, 11, 12, 1, 2, 3, 4, 13, 14, 15, 16, 5, 6, 7, 8]
66+
Results:
67+
- Result: Out
68+
Rule: BufferExact
69+
Actual: Out
70+
Expected: ExpectedOut
71+
- Result: Out2
72+
Rule: BufferExact
73+
Actual: Out2
74+
Expected: ExpectedOut2
75+
DescriptorSets:
76+
- Resources:
77+
- Name: In
78+
Kind: RWBuffer
79+
DirectXBinding:
80+
Register: 0
81+
Space: 0
82+
VulkanBinding:
83+
Binding: 0
84+
- Name: Index
85+
Kind: RWBuffer
86+
DirectXBinding:
87+
Register: 1
88+
Space: 0
89+
VulkanBinding:
90+
Binding: 1
91+
- Name: Out
92+
Kind: RWBuffer
93+
DirectXBinding:
94+
Register: 2
95+
Space: 0
96+
VulkanBinding:
97+
Binding: 2
98+
- Name: Out2
99+
Kind: RWBuffer
100+
DirectXBinding:
101+
Register: 3
102+
Space: 0
103+
VulkanBinding:
104+
Binding: 3
105+
...
106+
#--- end
107+
108+
# Unimplemented: https://github.com/llvm/llvm-project/issues/170534
109+
# XFAIL: Vulkan && Clang
110+
111+
# RUN: split-file %s %t
112+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
113+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)