From ca001e1a418190fb311f327d7aceab7a5afc38b2 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Wed, 12 Nov 2025 23:34:26 -0500 Subject: [PATCH 1/2] [Matrix] Add single subscript test 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. --- test/Basic/matrix_single_subscript_load.test | 71 +++++++++++++++++++ test/Basic/matrix_single_subscript_store.test | 71 +++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 test/Basic/matrix_single_subscript_load.test create mode 100644 test/Basic/matrix_single_subscript_store.test diff --git a/test/Basic/matrix_single_subscript_load.test b/test/Basic/matrix_single_subscript_load.test new file mode 100644 index 00000000..096febc6 --- /dev/null +++ b/test/Basic/matrix_single_subscript_load.test @@ -0,0 +1,71 @@ +#--- source.hlsl +RWBuffer In : register(u0); +RWBuffer Out : register(u1); + +[numthreads(1,1,1)] +void main() { + 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]); + + for (int i = 0; i < 4; i++) { + int4 B; + if (i % 2 == 0) + B = A[i]; + else if (i % 3 == 0) + B = A[i].abgr; + else + B.grab = A[i]; + for (int j = 0; j < 4; j++) { + Out[i*4 + j] = B[j]; + } + } +} +//--- 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: 64 + - Name: ExpectedOut + Format: Int32 + Data: [ 1, 2, 3, 4, 6, 5, 8, 7, 9, 10, 11, 12, 16, 15, 14, 13 ] +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 + +# XFAIL: Clang +# 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_single_subscript_store.test b/test/Basic/matrix_single_subscript_store.test new file mode 100644 index 00000000..82309f70 --- /dev/null +++ b/test/Basic/matrix_single_subscript_store.test @@ -0,0 +1,71 @@ +#--- source.hlsl +RWBuffer In : register(u0); +RWBuffer Out : register(u1); + +[numthreads(1,1,1)] +void main() { + int4 vec = int4(In[0], In[1], In[2], + In[3]); + int4x4 A; + for(int i = 0; i < 4; i++) { + if(i % 2 == 0) + A[i].rbag = vec; + // A[3] is exactly In Buffer + else if(i % 3 == 0) + A[i] = vec; + // A[1] is reverse In Buffer + else + A[i] = vec.abgr; + } + const uint COLS = 4; + for(int i = 0; i < 16; i++) { + uint row = i / COLS; + uint col = i % COLS; + Out[i] = A[row][col]; + } +} +//--- pipeline.yaml + +--- +Shaders: + - Stage: Compute + Entry: main + DispatchSize: [1, 1, 1] +Buffers: + - Name: In + Format: Int32 + Data: [ 1, 2, 3, 4] + - Name: Out + Format: Int32 + FillSize: 64 + - Name: ExpectedOut + Format: Int32 + Data: [ 1, 4, 2, 3, 4, 3, 2, 1, 1, 4, 2, 3, 1, 2, 3, 4 ] +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 + +# XFAIL: Clang +# 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 4628e863b837784b1548dc68aa942ad556b202b2 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Tue, 18 Nov 2025 17:39:40 -0500 Subject: [PATCH 2/2] address pr feedback --- test/Basic/matrix_single_subscript_load.test | 19 +++++++++---------- test/Basic/matrix_single_subscript_store.test | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/test/Basic/matrix_single_subscript_load.test b/test/Basic/matrix_single_subscript_load.test index 096febc6..91a18f2a 100644 --- a/test/Basic/matrix_single_subscript_load.test +++ b/test/Basic/matrix_single_subscript_load.test @@ -4,21 +4,20 @@ RWBuffer Out : register(u1); [numthreads(1,1,1)] void main() { - 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]); + 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]); for (int i = 0; i < 4; i++) { int4 B; if (i % 2 == 0) B = A[i]; else if (i % 3 == 0) - B = A[i].abgr; - else - B.grab = A[i]; + B = A[i].bagr; + else // i == 1 + B.agrb = A[i]; // equivalent: B = A[1].bgar + for (int j = 0; j < 4; j++) { Out[i*4 + j] = B[j]; } @@ -40,7 +39,7 @@ Buffers: FillSize: 64 - Name: ExpectedOut Format: Int32 - Data: [ 1, 2, 3, 4, 6, 5, 8, 7, 9, 10, 11, 12, 16, 15, 14, 13 ] + Data: [ 1, 2, 3, 4, 7, 6, 8, 5, 9, 10, 11, 12, 15, 16, 14, 13 ] Results: - Result: Out Rule: BufferExact diff --git a/test/Basic/matrix_single_subscript_store.test b/test/Basic/matrix_single_subscript_store.test index 82309f70..6989ba3f 100644 --- a/test/Basic/matrix_single_subscript_store.test +++ b/test/Basic/matrix_single_subscript_store.test @@ -4,8 +4,8 @@ RWBuffer Out : register(u1); [numthreads(1,1,1)] void main() { - int4 vec = int4(In[0], In[1], In[2], - In[3]); + int4 vec = int4(In[0], In[1], In[2], In[3]); + int4x4 A; for(int i = 0; i < 4; i++) { if(i % 2 == 0) @@ -15,7 +15,7 @@ void main() { A[i] = vec; // A[1] is reverse In Buffer else - A[i] = vec.abgr; + A[i] = vec.bagr; } const uint COLS = 4; for(int i = 0; i < 16; i++) { @@ -34,13 +34,13 @@ Shaders: Buffers: - Name: In Format: Int32 - Data: [ 1, 2, 3, 4] + Data: [1, 2, 3, 4] - Name: Out Format: Int32 FillSize: 64 - Name: ExpectedOut Format: Int32 - Data: [ 1, 4, 2, 3, 4, 3, 2, 1, 1, 4, 2, 3, 1, 2, 3, 4 ] + Data: [ 1, 4, 2, 3, 3, 4, 2, 1, 1, 4, 2, 3, 1, 2, 3, 4 ] Results: - Result: Out Rule: BufferExact