Skip to content

Commit 83b8448

Browse files
authored
Fixes array tests to be more portable (#420)
The resource array tests are failing on some of the new hardware we're bringing up this is for a couple reasons. The main issues stem from the use of RWBuffer, which may or may not be clamped. This required wider tolerances for floating point values and caused some integer values to come back wrong. This update switches the tests to RWStructuredBuffer instead and adjusts some of the test checks. Fixes #335, Fixes #336
1 parent 4bc4320 commit 83b8448

8 files changed

+101
-73
lines changed

test/Feature/ResourceArrays/array-global.test

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
// results compare for array BufC and BufD.
88

99
[[vk::binding(0)]]
10-
RWBuffer<int> A[2] : register(u0);
10+
RWStructuredBuffer<int> A[2] : register(u0);
1111

1212
[[vk::binding(1)]]
1313
RWStructuredBuffer<int> B[4] : register(u4);
1414

1515
[[vk::binding(2)]]
16-
RWBuffer<int> C[2] : register(u8);
16+
RWStructuredBuffer<int> C[2] : register(u8);
1717

1818
[[vk::binding(3)]]
19-
RWBuffer<float> D[2] : register(u10);
19+
RWStructuredBuffer<float> D[2] : register(u10);
2020

2121
[numthreads(4,2,1)]
2222
void main(uint GI : SV_GroupIndex) {
@@ -27,7 +27,7 @@ void main(uint GI : SV_GroupIndex) {
2727
C[i][GI] = A[i][GI] * 2;
2828
}
2929
for (int i = 0; i < 2; i++) {
30-
D[i][GI] = (float)A[i][GI] / 3.14159f;
30+
D[i][GI] = (float)A[i][GI] / 1.5f;
3131
}
3232
}
3333

@@ -50,6 +50,15 @@ Buffers:
5050
ArraySize: 4
5151
ZeroInitSize: 32
5252

53+
- Name: ExpectedBufB
54+
Format: Int32
55+
ArraySize: 4
56+
Data:
57+
- [ 0, 1, 2, 3, 4, 5, 6, 7 ]
58+
- [ 0, 2, 4, 6, 8, 10, 12, 14 ]
59+
- [ 0, 3, 6, 9, 12, 15, 18, 21 ]
60+
- [ 0, 4, 8, 12, 16, 20, 24, 28 ]
61+
5362
- Name: BufC
5463
Format: Int32
5564
ArraySize: 2
@@ -58,7 +67,7 @@ Buffers:
5867
- Name: ExpectedBufC
5968
Format: Int32
6069
ArraySize: 2
61-
Data:
70+
Data:
6271
- [ 0, 2, 4, 6, 8, 10, 12, 14 ]
6372
- [ 2, 4, 6, 8, 10, 12, 14, 16 ]
6473

@@ -71,24 +80,31 @@ Buffers:
7180
Format: Float32
7281
ArraySize: 2
7382
Data:
74-
- [ 0, 0.32, 0.64, 0.94, 1.27, 1.59, 1.91, 2.23 ]
75-
- [ 0.32, 0.64, 0.95, 1.27, 1.59, 1.91, 2.23, 2.54 ]
83+
- [ 0x0.0000000000000p+0, 0x1.5555560000000p-1, 0x1.5555560000000p+0, 0x1.0000000000000p+1, 0x1.5555560000000p+1, 0x1.aaaaac0000000p+1, 0x1.0000000000000p+2, 0x1.2aaaac0000000p+2 ]
84+
# [ 0, 0.666667, 1.33333, 2, 2.66667, 3.33333, 4, 4.66667 ]
85+
- [ 0x1.5555560000000p-1, 0x1.5555560000000p+0, 0x1.0000000000000p+1, 0x1.5555560000000p+1, 0x1.aaaaac0000000p+1, 0x1.0000000000000p+2, 0x1.2aaaac0000000p+2, 0x1.5555560000000p+2 ]
86+
# [ 0.666667, 1.33333, 2, 2.66667, 3.33333, 4, 4.66667, 5.33333 ]
7687
Results:
88+
- Result: BufB
89+
Rule: BufferExact
90+
Actual: BufB
91+
Expected: ExpectedBufB
92+
7793
- Result: BufC
7894
Rule: BufferExact
7995
Actual: BufC
8096
Expected: ExpectedBufC
8197

8298
- Result: BufD
83-
Rule: BufferFloatEpsilon
84-
Epsilon: 0.05
99+
Rule: BufferFloatULP
100+
ULPT: 5
85101
Actual: BufD
86102
Expected: ExpectedBufD
87103

88104
DescriptorSets:
89105
- Resources:
90106
- Name: BufA
91-
Kind: RWBuffer
107+
Kind: RWStructuredBuffer
92108
DirectXBinding:
93109
Register: 0
94110
Space: 0
@@ -102,14 +118,14 @@ DescriptorSets:
102118
VulkanBinding:
103119
Binding: 1
104120
- Name: BufC
105-
Kind: RWBuffer
121+
Kind: RWStructuredBuffer
106122
DirectXBinding:
107123
Register: 8
108124
Space: 0
109125
VulkanBinding:
110126
Binding: 2
111127
- Name: BufD
112-
Kind: RWBuffer
128+
Kind: RWStructuredBuffer
113129
DirectXBinding:
114130
Register: 10
115131
Space: 0
@@ -126,10 +142,10 @@ DescriptorSets:
126142
# XFAIL: Clang-Vulkan && !VK_KHR_shader_float_controls2
127143

128144
# RUN: split-file %s %t
129-
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
130-
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -Fo %t.o %t/source.hlsl %}
145+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
131146
# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s
132147

148+
// These checks added to verify YAML printing of arrays.
133149
// CHECK: Name: BufB
134150
// CHECK: Format: Int32
135151
// CHECK: ArraySize: 4
@@ -143,6 +159,5 @@ DescriptorSets:
143159
// CHECK: Format: Float32
144160
// CHECK: ArraySize: 2
145161
// CHECK: Data:
146-
// CHECK: - [ 0, 0.31831, 0.63662, 0.95493, 1.27324, 1.59155, 1.90986, 2.22817 ]
147-
// CHECK: - [ 0.31831, 0.63662, 0.95493, 1.27324, 1.59155, 1.90986, 2.22817,
148-
// CHECK: 2.54648 ]
162+
// CHECK: - [ 0, 0.666667, 1.33333, 2, 2.66667, 3.33333, 4, 4.66667 ]
163+
// CHECK: - [ 0.666667, 1.33333, 2, 2.66667, 3.33333, 4, 4.66667, 5.33333 ]

test/Feature/ResourceArrays/array-local.test

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
// This test verified handling of resource arrays used as a local
44
// variable and function argument.
55

6-
RWBuffer<float> BufA : register(u0);
7-
RWBuffer<float> BufB : register(u1);
8-
RWBuffer<float> Out : register(u2);
6+
RWStructuredBuffer<float> BufA : register(u0);
7+
RWStructuredBuffer<float> BufB : register(u1);
8+
RWStructuredBuffer<float> Out : register(u2);
99

10-
float foo(RWBuffer<float> ArgArray[2], uint Index) {
10+
float foo(RWStructuredBuffer<float> ArgArray[2], uint Index) {
1111
return ArgArray[0][Index] + ArgArray[1][Index] * 10;
1212
}
1313

1414
float bar(uint Index) {
15-
RWBuffer<float> LocalArray[2];
15+
RWStructuredBuffer<float> LocalArray[2];
1616
LocalArray[0] = BufA;
1717
LocalArray[1] = BufB;
1818
return foo(LocalArray, Index);
@@ -48,29 +48,29 @@ Buffers:
4848

4949
Results:
5050
- Result: BufOut
51-
Rule: BufferFloatEpsilon
52-
Epsilon: 0.0001
51+
Rule: BufferFloatULP
52+
ULPT: 5
5353
Actual: BufOut
5454
Expected: ExpectedOut
5555

5656
DescriptorSets:
5757
- Resources:
5858
- Name: BufA
59-
Kind: RWBuffer
59+
Kind: RWStructuredBuffer
6060
DirectXBinding:
6161
Register: 0
6262
Space: 0
6363
VulkanBinding:
6464
Binding: 0
6565
- Name: BufB
66-
Kind: RWBuffer
66+
Kind: RWStructuredBuffer
6767
DirectXBinding:
6868
Register: 1
6969
Space: 0
7070
VulkanBinding:
7171
Binding: 1
7272
- Name: BufOut
73-
Kind: RWBuffer
73+
Kind: RWStructuredBuffer
7474
DirectXBinding:
7575
Register: 2
7676
Space: 0
@@ -85,7 +85,10 @@ DescriptorSets:
8585
# Bug https://github.com/llvm/llvm-project/issues/154669
8686
# XFAIL: Clang-Vulkan
8787

88+
# DXC-Vulkan support for arrays of RWStructuredBuffer are pretty broken.
89+
# Tracked by https://github.com/microsoft/DirectXShaderCompiler/issues/7727
90+
# XFAIL: DXC-Vulkan
91+
8892
# RUN: split-file %s %t
89-
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
90-
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -Fo %t.o %t/source.hlsl %}
93+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
9194
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/ResourceArrays/array-local2.test

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
// The test verifies that this modification of local array B does not affect
77
// array A.
88

9-
RWBuffer<int> X : register(u0);
10-
RWBuffer<int> Y : register(u1);
9+
RWStructuredBuffer<int> X : register(u0);
10+
RWStructuredBuffer<int> Y : register(u1);
1111

12-
void SomeFn(RWBuffer<int> B[2], uint Idx, int Val0) {
12+
void SomeFn(RWStructuredBuffer<int> B[2], uint Idx, int Val0) {
1313
B[0] = Y;
1414
B[0][Idx] = Val0;
1515
}
1616

1717
[numthreads(4,1,1)]
1818
void main(uint GI : SV_GroupIndex) {
19-
RWBuffer<int> A[2] = {X, Y};
19+
RWStructuredBuffer<int> A[2] = {X, Y};
2020
SomeFn(A, GI, 1);
2121
A[0][GI] = 2;
2222
}
@@ -58,14 +58,14 @@ Results:
5858
DescriptorSets:
5959
- Resources:
6060
- Name: BufX
61-
Kind: RWBuffer
61+
Kind: RWStructuredBuffer
6262
DirectXBinding:
6363
Register: 0
6464
Space: 0
6565
VulkanBinding:
6666
Binding: 0
6767
- Name: BufY
68-
Kind: RWBuffer
68+
Kind: RWStructuredBuffer
6969
DirectXBinding:
7070
Register: 1
7171
Space: 0
@@ -79,13 +79,16 @@ DescriptorSets:
7979
# Bug https://github.com/microsoft/DirectXShaderCompiler/issues/7678
8080
# XFAIL: DXC-DirectX
8181

82+
# DXC-Vulkan support for arrays of RWStructuredBuffer are pretty broken.
83+
# Tracked by https://github.com/microsoft/DirectXShaderCompiler/issues/7727
84+
# XFAIL: DXC-Vulkan
85+
8286
# Resource arrays are not yet supported on Metal
8387
# UNSUPPORTED: Metal
8488

8589
# Bug https://github.com/llvm/llvm-project/issues/154669
8690
# XFAIL: Clang-Vulkan
8791

8892
# RUN: split-file %s %t
89-
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
90-
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -Fo %t.o %t/source.hlsl %}
93+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
9194
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/ResourceArrays/multi-dim-array-global.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// This test verified handling of global multi-dimensional resource arrays.
44

5-
RWBuffer<int> In[2][3] : register(u0);
6-
RWBuffer<int> Out[2][3] : register(u6);
5+
RWStructuredBuffer<int> In[2][3] : register(u0);
6+
RWStructuredBuffer<int> Out[2][3] : register(u6);
77

88
[numthreads(4,1,1)]
99
void main(uint GI : SV_GroupIndex) {
@@ -57,12 +57,12 @@ Results:
5757
DescriptorSets:
5858
- Resources:
5959
- Name: BufIn
60-
Kind: RWBuffer
60+
Kind: RWStructuredBuffer
6161
DirectXBinding:
6262
Register: 0
6363
Space: 0
6464
- Name: BufOut
65-
Kind: RWBuffer
65+
Kind: RWStructuredBuffer
6666
DirectXBinding:
6767
Register: 6
6868
Space: 0

test/Feature/ResourceArrays/multi-dim-array-local.test

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
// This test verified handling of multi-dimensional resource arrays
44
// used as a local variable and function argument
55

6-
RWBuffer<float> BufA : register(u0);
7-
RWBuffer<float> BufB : register(u1);
8-
RWBuffer<float> Out : register(u2);
6+
RWStructuredBuffer<float> BufA : register(u0);
7+
RWStructuredBuffer<float> BufB : register(u1);
8+
RWStructuredBuffer<float> Out : register(u2);
99

10-
float foo(RWBuffer<float> A[2][3], uint Index) {
10+
float foo(RWStructuredBuffer<float> A[2][3], uint Index) {
1111
return A[0][0][Index] + (A[0][1][Index] + 1) * 10 + (A[0][2][Index] + 2) * 100 +
1212
A[1][0][Index] + (A[1][1][Index] + 0.1) / 10 + (A[1][2][Index] + 0.2) / 100;
1313
}
1414

1515
float bar(uint Index) {
16-
RWBuffer<float> LocalArray[2][3];
16+
RWStructuredBuffer<float> LocalArray[2][3];
1717
for (int i = 0; i < 3; i++) {
1818
LocalArray[0][i] = BufA;
1919
LocalArray[1][i] = BufB;
@@ -51,25 +51,25 @@ Buffers:
5151
876.678, 987.789 ]
5252
Results:
5353
- Result: BufOut
54-
Rule: BufferFloatEpsilon
55-
Epsilon: 0.001
54+
Rule: BufferFloatULP
55+
ULPT: 10
5656
Actual: BufOut
5757
Expected: ExpectedOut
5858

5959
DescriptorSets:
6060
- Resources:
6161
- Name: BufA
62-
Kind: RWBuffer
62+
Kind: RWStructuredBuffer
6363
DirectXBinding:
6464
Register: 0
6565
Space: 0
6666
- Name: BufB
67-
Kind: RWBuffer
67+
Kind: RWStructuredBuffer
6868
DirectXBinding:
6969
Register: 1
7070
Space: 0
7171
- Name: BufOut
72-
Kind: RWBuffer
72+
Kind: RWStructuredBuffer
7373
DirectXBinding:
7474
Register: 2
7575
Space: 0
@@ -83,6 +83,5 @@ DescriptorSets:
8383
# UNSUPPORTED: Metal
8484

8585
# RUN: split-file %s %t
86-
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
87-
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -Fo %t.o %t/source.hlsl %}
86+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
8887
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)