Skip to content

Commit 8167a5b

Browse files
authored
[Matrix] Add single subscript test (#503)
fixes #502 https://godbolt.org/z/xaEE44cbE Test 3 cases (loads and stores): 1. single subscript as an l-value swizzle 2. single subscript where the store/load takes a vector r-value swizzle 3. single subscript where we store/load the vector as is.
1 parent 3ab7781 commit 8167a5b

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-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+
12+
for (int i = 0; i < 4; i++) {
13+
int4 B;
14+
if (i % 2 == 0)
15+
B = A[i];
16+
else if (i % 3 == 0)
17+
B = A[i].bagr;
18+
else // i == 1
19+
B.agrb = A[i]; // equivalent: B = A[1].bgar
20+
21+
for (int j = 0; j < 4; j++) {
22+
Out[i*4 + j] = B[j];
23+
}
24+
}
25+
}
26+
//--- pipeline.yaml
27+
28+
---
29+
Shaders:
30+
- Stage: Compute
31+
Entry: main
32+
DispatchSize: [1, 1, 1]
33+
Buffers:
34+
- Name: In
35+
Format: Int32
36+
Data: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
37+
- Name: Out
38+
Format: Int32
39+
FillSize: 64
40+
- Name: ExpectedOut
41+
Format: Int32
42+
Data: [ 1, 2, 3, 4, 7, 6, 8, 5, 9, 10, 11, 12, 15, 16, 14, 13 ]
43+
Results:
44+
- Result: Out
45+
Rule: BufferExact
46+
Actual: Out
47+
Expected: ExpectedOut
48+
DescriptorSets:
49+
- Resources:
50+
- Name: In
51+
Kind: RWBuffer
52+
DirectXBinding:
53+
Register: 0
54+
Space: 0
55+
VulkanBinding:
56+
Binding: 0
57+
- Name: Out
58+
Kind: RWBuffer
59+
DirectXBinding:
60+
Register: 1
61+
Space: 0
62+
VulkanBinding:
63+
Binding: 1
64+
...
65+
#--- end
66+
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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
int4 vec = int4(In[0], In[1], In[2], In[3]);
8+
9+
int4x4 A;
10+
for(int i = 0; i < 4; i++) {
11+
if(i % 2 == 0)
12+
A[i].rbag = vec;
13+
// A[3] is exactly In Buffer
14+
else if(i % 3 == 0)
15+
A[i] = vec;
16+
// A[1] is reverse In Buffer
17+
else
18+
A[i] = vec.bagr;
19+
}
20+
const uint COLS = 4;
21+
for(int i = 0; i < 16; i++) {
22+
uint row = i / COLS;
23+
uint col = i % COLS;
24+
Out[i] = A[row][col];
25+
}
26+
}
27+
//--- pipeline.yaml
28+
29+
---
30+
Shaders:
31+
- Stage: Compute
32+
Entry: main
33+
DispatchSize: [1, 1, 1]
34+
Buffers:
35+
- Name: In
36+
Format: Int32
37+
Data: [1, 2, 3, 4]
38+
- Name: Out
39+
Format: Int32
40+
FillSize: 64
41+
- Name: ExpectedOut
42+
Format: Int32
43+
Data: [ 1, 4, 2, 3, 3, 4, 2, 1, 1, 4, 2, 3, 1, 2, 3, 4 ]
44+
Results:
45+
- Result: Out
46+
Rule: BufferExact
47+
Actual: Out
48+
Expected: ExpectedOut
49+
DescriptorSets:
50+
- Resources:
51+
- Name: In
52+
Kind: RWBuffer
53+
DirectXBinding:
54+
Register: 0
55+
Space: 0
56+
VulkanBinding:
57+
Binding: 0
58+
- Name: Out
59+
Kind: RWBuffer
60+
DirectXBinding:
61+
Register: 1
62+
Space: 0
63+
VulkanBinding:
64+
Binding: 1
65+
...
66+
#--- end
67+
68+
# XFAIL: Clang
69+
# RUN: split-file %s %t
70+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
71+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)