Skip to content
78 changes: 78 additions & 0 deletions test/Feature/ResourceArrays/multi-dim-array-subset.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#--- source.hlsl

// Verify handling of subsets of multi-dimensional resource arrays
// used in a function argument.

RWStructuredBuffer<float> In[4][2] : register(u0);
RWStructuredBuffer<float> Out : register(u0, space1);

float foo(RWStructuredBuffer<float> A[2], uint Index) {
return A[0][Index] + A[1][Index];
}

[numthreads(4,1,1)]
void main(uint GI : SV_GroupIndex) {
for (int i = 0; i < 4; i++) {
Out[i] = foo(In[i], i);
}
}

//--- pipeline.yaml
---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: BufIn
Format: Float32
ArraySize: 8
Data:
- [ 1.0, 2.0, 3.0, 4.0 ]
- [ 0.1, 0.2, 0.3, 0.4 ]
- [ 5.0, 6.0, 7.0, 8.0 ]
- [ 0.5, 0.6, 0.7, 0.8 ]
- [ 10.0, 11.0, 12.0, 13.0 ]
- [ 0.10, 0.11, 0.12, 0.13 ]
- [ 14.0, 15.0, 16.0, 17.0 ]
- [ 0.14, 0.15, 0.16, 0.17 ]

- Name: BufOut
Format: Float32
FillSize: 16

- Name: ExpectedOut
Format: Float32
Data: [ 1.1, 6.6, 12.12, 17.17 ]

Results:
- Result: BufOut
Rule: BufferFloatULP
ULPT: 1 # Float addition should be within 1 ULP on all hardware.
Actual: BufOut
Expected: ExpectedOut

DescriptorSets:
- Resources:
- Name: BufIn
Kind: RWStructuredBuffer
DirectXBinding:
Register: 0
Space: 0
- Name: BufOut
Kind: RWStructuredBuffer
DirectXBinding:
Register: 0
Space: 1
...
#--- end

# Vulkan does not support multi-dimensional resource arrays
# UNSUPPORTED: Vulkan

# Resource arrays are not yet supported on Metal
# UNSUPPORTED: Metal

# 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
65 changes: 65 additions & 0 deletions test/Feature/ResourceArrays/multi-dim-unbounded-array.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#--- source.hlsl

// Verify handling of unbounded multi-dimensional resource array.

RWStructuredBuffer<int> Buf[][2] : register(u0);

[numthreads(1,1,1)]
void main(uint3 GTI : SV_GroupThreadID, uint GI : SV_GroupIndex) {
for (int i = 0; i < 4; i++) {
Buf[1][0][i] = Buf[0][0][i] + Buf[0][1][i];
Buf[1][1][i] = Buf[0][0][i] * Buf[0][1][i];
Buf[0][0][i] += Buf[0][1][i];
}
}

//--- pipeline.yaml
---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: Buf
Format: Int32
ArraySize: 4
Data:
- [ 0, 1, 2, 3 ]
- [ 1, 2, 3, 4 ]
- [ 0, 0, 0, 0 ]
- [ 0, 0, 0, 0 ]

- Name: ExpectedBuf
Format: Int32
ArraySize: 4
Data:
- [ 1, 3, 5, 7 ]
- [ 1, 2, 3, 4 ]
- [ 1, 3, 5, 7 ]
- [ 0, 2, 6, 12 ]

Results:
- Result: Buf
Rule: BufferExact
Actual: Buf
Expected: ExpectedBuf

DescriptorSets:
- Resources:
- Name: Buf
Kind: RWStructuredBuffer
DirectXBinding:
Register: 0
Space: 0
...
#--- end

# Resource arrays are not yet supported on Metal
# UNSUPPORTED: Metal

# Vulkan does not support multi-dimensional resource arrays
# UNSUPPORTED: Vulkan

# 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
62 changes: 62 additions & 0 deletions test/Feature/ResourceArrays/unbounded-array.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#--- source.hlsl

// Verify handling of unbounded resource array.

[[vk::binding(0)]]
RWBuffer<int> Buf[] : register(u0);

[numthreads(4,2,1)]
void main(uint GI : SV_GroupIndex) {
for (int i = 0; i < 4; i++) {
Buf[1][i] = Buf[0][i] * 2;
Buf[2][i] = Buf[0][i] + Buf[1][i];
}
}

//--- pipeline.yaml
---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: Buf
Format: Int32
ArraySize: 3
Data:
- [ 1, 2, 3, 4 ]
- [ 0, 0, 0, 0 ]
- [ 0, 0, 0, 0 ]

- Name: ExpectedBuf
Format: Int32
ArraySize: 3
Data:
- [ 1, 2, 3, 4 ]
- [ 2, 4, 6, 8 ]
- [ 3, 6, 9, 12 ]

Results:
- Result: Buf
Rule: BufferExact
Actual: Buf
Expected: ExpectedBuf

DescriptorSets:
- Resources:
- Name: Buf
Kind: RWBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
...
#--- end

# Resource arrays are not yet supported on Metal
# UNSUPPORTED: Metal

# 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