From bdc56fc58d3dd3964bbf3871163230258a6a747c Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Tue, 25 Nov 2025 21:17:35 -0500 Subject: [PATCH 1/2] [Matrix] Add elementwise and trunc casts fixes #506 This PR is a partner pr to https://github.com/llvm/llvm-project/pull/168915 It should not run until after the llvm pr merges. That way I won't have XFAIL the clang code. 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. --- .../{ => Matrix}/matrix_m-based_getter.test | 0 .../{ => Matrix}/matrix_one-based_getter.test | 0 .../matrix_scalar_arithmetic.test | 0 .../matrix_scalar_constructor.test | 0 .../matrix_single_subscript_load.test | 0 .../matrix_single_subscript_store.test | 0 .../matrix_swizzle_one_based.test | 0 .../matrix_swizzle_zero_based.test | 0 test/Basic/matrix_elementwise_cast.test | 105 ++++++++++++++++++ .../Basic/matrix_elementwise_vector_cast.test | 78 +++++++++++++ test/Basic/matrix_trunc_cast.test | 61 ++++++++++ 11 files changed, 244 insertions(+) rename test/Basic/{ => Matrix}/matrix_m-based_getter.test (100%) rename test/Basic/{ => Matrix}/matrix_one-based_getter.test (100%) rename test/Basic/{ => Matrix}/matrix_scalar_arithmetic.test (100%) rename test/Basic/{ => Matrix}/matrix_scalar_constructor.test (100%) rename test/Basic/{ => Matrix}/matrix_single_subscript_load.test (100%) rename test/Basic/{ => Matrix}/matrix_single_subscript_store.test (100%) rename test/Basic/{ => Matrix}/matrix_swizzle_one_based.test (100%) rename test/Basic/{ => Matrix}/matrix_swizzle_zero_based.test (100%) create mode 100644 test/Basic/matrix_elementwise_cast.test create mode 100644 test/Basic/matrix_elementwise_vector_cast.test create mode 100644 test/Basic/matrix_trunc_cast.test diff --git a/test/Basic/matrix_m-based_getter.test b/test/Basic/Matrix/matrix_m-based_getter.test similarity index 100% rename from test/Basic/matrix_m-based_getter.test rename to test/Basic/Matrix/matrix_m-based_getter.test diff --git a/test/Basic/matrix_one-based_getter.test b/test/Basic/Matrix/matrix_one-based_getter.test similarity index 100% rename from test/Basic/matrix_one-based_getter.test rename to test/Basic/Matrix/matrix_one-based_getter.test diff --git a/test/Basic/matrix_scalar_arithmetic.test b/test/Basic/Matrix/matrix_scalar_arithmetic.test similarity index 100% rename from test/Basic/matrix_scalar_arithmetic.test rename to test/Basic/Matrix/matrix_scalar_arithmetic.test diff --git a/test/Basic/matrix_scalar_constructor.test b/test/Basic/Matrix/matrix_scalar_constructor.test similarity index 100% rename from test/Basic/matrix_scalar_constructor.test rename to test/Basic/Matrix/matrix_scalar_constructor.test diff --git a/test/Basic/matrix_single_subscript_load.test b/test/Basic/Matrix/matrix_single_subscript_load.test similarity index 100% rename from test/Basic/matrix_single_subscript_load.test rename to test/Basic/Matrix/matrix_single_subscript_load.test diff --git a/test/Basic/matrix_single_subscript_store.test b/test/Basic/Matrix/matrix_single_subscript_store.test similarity index 100% rename from test/Basic/matrix_single_subscript_store.test rename to test/Basic/Matrix/matrix_single_subscript_store.test diff --git a/test/Basic/matrix_swizzle_one_based.test b/test/Basic/Matrix/matrix_swizzle_one_based.test similarity index 100% rename from test/Basic/matrix_swizzle_one_based.test rename to test/Basic/Matrix/matrix_swizzle_one_based.test diff --git a/test/Basic/matrix_swizzle_zero_based.test b/test/Basic/Matrix/matrix_swizzle_zero_based.test similarity index 100% rename from test/Basic/matrix_swizzle_zero_based.test rename to test/Basic/Matrix/matrix_swizzle_zero_based.test diff --git a/test/Basic/matrix_elementwise_cast.test b/test/Basic/matrix_elementwise_cast.test new file mode 100644 index 00000000..2b801306 --- /dev/null +++ b/test/Basic/matrix_elementwise_cast.test @@ -0,0 +1,105 @@ +#--- source.hlsl +RWBuffer In : register(u0); +RWBuffer MatOut : register(u1); +RWBuffer ArrOut : register(u2); +RWBuffer 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 diff --git a/test/Basic/matrix_elementwise_vector_cast.test b/test/Basic/matrix_elementwise_vector_cast.test new file mode 100644 index 00000000..8f40d0cd --- /dev/null +++ b/test/Basic/matrix_elementwise_vector_cast.test @@ -0,0 +1,78 @@ +#--- source.hlsl +RWBuffer In : register(u0); +RWBuffer FloatMatOut : register(u1); +RWBuffer 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 + + 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 diff --git a/test/Basic/matrix_trunc_cast.test b/test/Basic/matrix_trunc_cast.test new file mode 100644 index 00000000..04aeef2f --- /dev/null +++ b/test/Basic/matrix_trunc_cast.test @@ -0,0 +1,61 @@ +#--- source.hlsl +RWBuffer In : register(u0); +RWBuffer 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 From b9f5dbc54e3967ee9690b56cc4ff0e2c198a3811 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Tue, 25 Nov 2025 21:26:20 -0500 Subject: [PATCH 2/2] move matrix cast tests under correct directory --- test/Basic/{ => Matrix}/matrix_elementwise_cast.test | 0 test/Basic/{ => Matrix}/matrix_elementwise_vector_cast.test | 0 test/Basic/{ => Matrix}/matrix_trunc_cast.test | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename test/Basic/{ => Matrix}/matrix_elementwise_cast.test (100%) rename test/Basic/{ => Matrix}/matrix_elementwise_vector_cast.test (100%) rename test/Basic/{ => Matrix}/matrix_trunc_cast.test (100%) diff --git a/test/Basic/matrix_elementwise_cast.test b/test/Basic/Matrix/matrix_elementwise_cast.test similarity index 100% rename from test/Basic/matrix_elementwise_cast.test rename to test/Basic/Matrix/matrix_elementwise_cast.test diff --git a/test/Basic/matrix_elementwise_vector_cast.test b/test/Basic/Matrix/matrix_elementwise_vector_cast.test similarity index 100% rename from test/Basic/matrix_elementwise_vector_cast.test rename to test/Basic/Matrix/matrix_elementwise_vector_cast.test diff --git a/test/Basic/matrix_trunc_cast.test b/test/Basic/Matrix/matrix_trunc_cast.test similarity index 100% rename from test/Basic/matrix_trunc_cast.test rename to test/Basic/Matrix/matrix_trunc_cast.test