Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions test/Basic/Matrix/matrix_elementwise_cast.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#--- source.hlsl
RWBuffer<float> In : register(u0);
RWBuffer<int> MatOut : register(u1);
RWBuffer<int> ArrOut : register(u2);
RWBuffer<int> StructOut : register(u3);

struct S {
int A,B,C;
float X,Y,Z;
};

[numthreads(6,1,1)]
void main(uint GI : SV_GroupIndex) {
float2x3 A = float2x3(In[0], In[1], In[2],
In[3], In[4], In[5]);
float Arr[2][3] = {In[0], In[1], In[2],
In[3], In[4], In[5]};

S s = {(int)In[0], (int)In[1], (int)In[2],
In[3], In[4], In[5]};

const uint COLS = 3; // float2x3 => 2 rows, 3 columns
uint row = GI / COLS; // 0..1
uint col = GI % COLS; // 0..2

int2x3 B = (int2x3)A;
int2x3 C = (int2x3)Arr;
int2x3 D = (int2x3)s;

MatOut[GI] = B[row][col];
ArrOut[GI] = C[row][col];
StructOut[GI] = D[row][col];
}
//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Data: [ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6]
- Name: MatOut
Format: Int32
FillSize: 24
- Name: ArrOut
Format: Int32
FillSize: 24
- Name: StructOut
Format: Int32
FillSize: 24
- Name: ExpectedOut
Format: Int32
Data: [ 1, 2, 3, 4, 5, 6 ]
Results:
- Result: MatOut
Rule: BufferExact
Actual: MatOut
Expected: ExpectedOut
- Result: ArrOut
Rule: BufferExact
Actual: ArrOut
Expected: ExpectedOut
- Result: StructOut
Rule: BufferExact
Actual: StructOut
Expected: ExpectedOut
DescriptorSets:
- Resources:
- Name: In
Kind: RWBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: MatOut
Kind: RWBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: ArrOut
Kind: RWBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: StructOut
Kind: RWBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
...
#--- end

# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
78 changes: 78 additions & 0 deletions test/Basic/Matrix/matrix_elementwise_vector_cast.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#--- source.hlsl
RWBuffer<float> In : register(u0);
RWBuffer<float> FloatMatOut : register(u1);
RWBuffer<int> IntMatOut : register(u2);

[numthreads(4,1,1)]
void main(uint GI : SV_GroupIndex) {
float4 V = float4(In[0], In[1],In[2], In[3]);
float2x2 M = (float2x2)V;
int2x2 M2 = (int2x2)V;
const uint COLS = 2; // float2x2 => 2 rows, 2 columns
uint row = GI / COLS; // 0..1
uint col = GI % COLS; // 0..2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
uint col = GI % COLS; // 0..2
uint col = GI % COLS; // 0..1


FloatMatOut[GI] = M[row][col];
IntMatOut[GI] = M2[row][col];
}
//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Data: [ 1.1, 2.2, 3.3, 4.4]
- Name: FloatMatOut
Format: Float32
FillSize: 16
- Name: IntMatOut
Format: Int32
FillSize: 16
- Name: ExpectedFloatOut
Format: Float32
Data: [ 1.1, 2.2, 3.3, 4.4]
- Name: ExpectedIntOut
Format: Int32
Data: [ 1, 2, 3, 4 ]
Results:
- Result: FloatMatOut
Rule: BufferExact
Actual: FloatMatOut
Expected: ExpectedFloatOut
- Result: IntMatOut
Rule: BufferExact
Actual: IntMatOut
Expected: ExpectedIntOut
DescriptorSets:
- Resources:
- Name: In
Kind: RWBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: FloatMatOut
Kind: RWBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: IntMatOut
Kind: RWBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
...
#--- end

# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
61 changes: 61 additions & 0 deletions test/Basic/Matrix/matrix_trunc_cast.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#--- source.hlsl
RWBuffer<int> In : register(u0);
RWBuffer<int> Out : register(u1);

[numthreads(4,1,1)]
void main(uint GI : SV_GroupIndex) {
int4x4 A = int4x4(In[0], In[1], In[2], In[3],
In[4], In[5], In[6], In[7],
In[8], In[9], In[10], In[11],
In[12], In[13], In[14], In[15]);

int2x2 B = (int2x2)A;
const uint COLS = 2; // int2x3 => 2 rows, 2 columns
uint row = GI / COLS; // 0..1
uint col = GI % COLS; // 0..1
Out[GI] = B[row][col];
}
//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Data: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
- Name: Out
Format: Int32
FillSize: 16
- Name: ExpectedOut
Format: Int32
Data: [1, 2, 5, 6]
Results:
- Result: Out
Rule: BufferExact
Actual: Out
Expected: ExpectedOut
DescriptorSets:
- Resources:
- Name: In
Kind: RWBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Out
Kind: RWBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
...
#--- end

# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
Loading