Skip to content

Commit 1901531

Browse files
authored
[Matrix] Add elementwise and trunc casts (#512)
fixes #506 This PR is a partner pr to llvm/llvm-project#168915. It adds 3 types of tests elementwise casts, vector elementwise casts, and trunc casts. It also moves the existing matrix tests into a Matrix folder for better organization.
1 parent dfa7a1d commit 1901531

11 files changed

+252
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#--- source.hlsl
2+
RWBuffer<float> In : register(u0);
3+
RWBuffer<int> MatOut : register(u1);
4+
RWBuffer<int> ArrOut : register(u2);
5+
RWBuffer<int> StructOut : register(u3);
6+
7+
struct S {
8+
int A,B,C;
9+
float X,Y,Z;
10+
};
11+
12+
[numthreads(6,1,1)]
13+
void main(uint GI : SV_GroupIndex) {
14+
float2x3 A = float2x3(In[0], In[1], In[2],
15+
In[3], In[4], In[5]);
16+
float Arr[2][3] = {In[0], In[1], In[2],
17+
In[3], In[4], In[5]};
18+
19+
S s = {(int)In[0], (int)In[1], (int)In[2],
20+
In[3], In[4], In[5]};
21+
22+
const uint COLS = 3; // float2x3 => 2 rows, 3 columns
23+
uint row = GI / COLS; // 0..1
24+
uint col = GI % COLS; // 0..2
25+
26+
int2x3 B = (int2x3)A;
27+
int2x3 C = (int2x3)Arr;
28+
int2x3 D = (int2x3)s;
29+
30+
MatOut[GI] = B[row][col];
31+
ArrOut[GI] = C[row][col];
32+
StructOut[GI] = D[row][col];
33+
}
34+
//--- pipeline.yaml
35+
36+
---
37+
Shaders:
38+
- Stage: Compute
39+
Entry: main
40+
DispatchSize: [1, 1, 1]
41+
Buffers:
42+
- Name: In
43+
Format: Float32
44+
Data: [ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6]
45+
- Name: MatOut
46+
Format: Int32
47+
FillSize: 24
48+
- Name: ArrOut
49+
Format: Int32
50+
FillSize: 24
51+
- Name: StructOut
52+
Format: Int32
53+
FillSize: 24
54+
- Name: ExpectedOut
55+
Format: Int32
56+
Data: [ 1, 2, 3, 4, 5, 6 ]
57+
Results:
58+
- Result: MatOut
59+
Rule: BufferExact
60+
Actual: MatOut
61+
Expected: ExpectedOut
62+
- Result: ArrOut
63+
Rule: BufferExact
64+
Actual: ArrOut
65+
Expected: ExpectedOut
66+
- Result: StructOut
67+
Rule: BufferExact
68+
Actual: StructOut
69+
Expected: ExpectedOut
70+
DescriptorSets:
71+
- Resources:
72+
- Name: In
73+
Kind: RWBuffer
74+
DirectXBinding:
75+
Register: 0
76+
Space: 0
77+
VulkanBinding:
78+
Binding: 0
79+
- Name: MatOut
80+
Kind: RWBuffer
81+
DirectXBinding:
82+
Register: 1
83+
Space: 0
84+
VulkanBinding:
85+
Binding: 1
86+
- Name: ArrOut
87+
Kind: RWBuffer
88+
DirectXBinding:
89+
Register: 2
90+
Space: 0
91+
VulkanBinding:
92+
Binding: 2
93+
- Name: StructOut
94+
Kind: RWBuffer
95+
DirectXBinding:
96+
Register: 3
97+
Space: 0
98+
VulkanBinding:
99+
Binding: 3
100+
...
101+
#--- end
102+
# Unimplemented: https://github.com/llvm/llvm-project/issues/170534
103+
# XFAIL: Vulkan && Clang
104+
105+
# RUN: split-file %s %t
106+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
107+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#--- source.hlsl
2+
RWBuffer<float> In : register(u0);
3+
RWBuffer<float> FloatMatOut : register(u1);
4+
RWBuffer<int> IntMatOut : register(u2);
5+
6+
[numthreads(4,1,1)]
7+
void main(uint GI : SV_GroupIndex) {
8+
float4 V = float4(In[0], In[1],In[2], In[3]);
9+
float2x2 M = (float2x2)V;
10+
int2x2 M2 = (int2x2)V;
11+
const uint COLS = 2; // float2x2 => 2 rows, 2 columns
12+
uint row = GI / COLS; // 0..1
13+
uint col = GI % COLS; // 0..1
14+
15+
FloatMatOut[GI] = M[row][col];
16+
IntMatOut[GI] = M2[row][col];
17+
}
18+
//--- pipeline.yaml
19+
20+
---
21+
Shaders:
22+
- Stage: Compute
23+
Entry: main
24+
DispatchSize: [1, 1, 1]
25+
Buffers:
26+
- Name: In
27+
Format: Float32
28+
Data: [ 1.1, 2.2, 3.3, 4.4]
29+
- Name: FloatMatOut
30+
Format: Float32
31+
FillSize: 16
32+
- Name: IntMatOut
33+
Format: Int32
34+
FillSize: 16
35+
- Name: ExpectedFloatOut
36+
Format: Float32
37+
Data: [ 1.1, 2.2, 3.3, 4.4]
38+
- Name: ExpectedIntOut
39+
Format: Int32
40+
Data: [ 1, 2, 3, 4 ]
41+
Results:
42+
- Result: FloatMatOut
43+
Rule: BufferExact
44+
Actual: FloatMatOut
45+
Expected: ExpectedFloatOut
46+
- Result: IntMatOut
47+
Rule: BufferExact
48+
Actual: IntMatOut
49+
Expected: ExpectedIntOut
50+
DescriptorSets:
51+
- Resources:
52+
- Name: In
53+
Kind: RWBuffer
54+
DirectXBinding:
55+
Register: 0
56+
Space: 0
57+
VulkanBinding:
58+
Binding: 0
59+
- Name: FloatMatOut
60+
Kind: RWBuffer
61+
DirectXBinding:
62+
Register: 1
63+
Space: 0
64+
VulkanBinding:
65+
Binding: 1
66+
- Name: IntMatOut
67+
Kind: RWBuffer
68+
DirectXBinding:
69+
Register: 2
70+
Space: 0
71+
VulkanBinding:
72+
Binding: 2
73+
...
74+
#--- end
75+
76+
# Unimplemented: https://github.com/llvm/llvm-project/issues/170538
77+
# XFAIL: Vulkan && Clang
78+
79+
# RUN: split-file %s %t
80+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
81+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)