Skip to content

Commit d33b0e5

Browse files
authored
Feature tests for cbuffers (#46)
This adds tests using cbuffers in a variety of shapes. There are a few caveats: - These are currently all disabled on Metal - there seem to be issues with bindings that prevent these from working. - The 16 bit vector test is XFAIL'd on intel because it crashes on the runner. - Tests that rely on the DirectX cbuffer layout are disabled for Vulkan, because DXC does not use that layout when targetting SPIR-V.
1 parent 3f0446e commit d33b0e5

14 files changed

+807
-4
lines changed

lib/API/DX/DXFeatures.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ D3D_FEATURE_ENUM(directx::RootSignature, HighestRootSignatureVersion)
2929
#endif
3030

3131
#ifdef D3D_FEATURE_BOOL
32+
D3D_FEATURE_BOOL(Native16BitShaderOpsSupported)
33+
D3D_FEATURE_BOOL(Int64ShaderOps)
34+
D3D_FEATURE_BOOL(DoublePrecisionFloatShaderOps)
3235
D3D_FEATURE_BOOL(WaveOps)
3336
#undef D3D_FEATURE_BOOL
3437
#endif
@@ -38,4 +41,4 @@ D3D_FEATURE_UINT(WaveLaneCountMin)
3841
D3D_FEATURE_UINT(WaveLaneCountMax)
3942
D3D_FEATURE_UINT(TotalLaneCount)
4043
#undef D3D_FEATURE_UINT
41-
#endif
44+
#endif

lib/API/VK/Device.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,17 @@ class VKDevice : public offloadtest::Device {
166166

167167
private:
168168
void queryCapabilities() {
169-
VkPhysicalDeviceFeatures Features;
170-
vkGetPhysicalDeviceFeatures(Device, &Features);
169+
170+
VkPhysicalDeviceFeatures2 Features{};
171+
Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
172+
VkPhysicalDeviceVulkan11Features Features11{};
173+
Features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
174+
VkPhysicalDeviceVulkan12Features Features12{};
175+
Features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
176+
177+
Features.pNext = &Features11;
178+
Features11.pNext = &Features12;
179+
vkGetPhysicalDeviceFeatures2(Device, &Features);
171180

172181
Caps.insert(std::make_pair(
173182
"APIMajorVersion",
@@ -180,8 +189,15 @@ class VKDevice : public offloadtest::Device {
180189
VK_API_VERSION_MINOR(Props.apiVersion))));
181190

182191
#define VULKAN_FEATURE_BOOL(Name) \
192+
Caps.insert(std::make_pair( \
193+
#Name, make_capability<bool>(#Name, Features.features.Name)));
194+
#define VULKAN11_FEATURE_BOOL(Name) \
195+
Caps.insert( \
196+
std::make_pair(#Name, make_capability<bool>(#Name, Features11.Name)));
197+
#include "VKFeatures.def"
198+
#define VULKAN12_FEATURE_BOOL(Name) \
183199
Caps.insert( \
184-
std::make_pair(#Name, make_capability<bool>(#Name, Features.Name)));
200+
std::make_pair(#Name, make_capability<bool>(#Name, Features12.Name)));
185201
#include "VKFeatures.def"
186202
}
187203

lib/API/VK/VKFeatures.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ VULKAN_FEATURE_BOOL(variableMultisampleRate)
5757
VULKAN_FEATURE_BOOL(inheritedQueries)
5858
#undef VULKAN_FEATURE_BOOL
5959
#endif
60+
61+
#ifdef VULKAN11_FEATURE_BOOL
62+
#undef VULKAN11_FEATURE_BOOL
63+
#endif
64+
65+
#ifdef VULKAN12_FEATURE_BOOL
66+
VULKAN12_FEATURE_BOOL(shaderFloat16)
67+
#undef VULKAN12_FEATURE_BOOL
68+
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#--- source.hlsl
2+
3+
cbuffer CBArrays : register(b0) {
4+
uint16_t c1[2][2];
5+
float16_t c2[1];
6+
}
7+
8+
struct Arrays {
9+
uint16_t c1[2][2];
10+
float16_t c2[1];
11+
};
12+
13+
RWStructuredBuffer<Arrays> Out : register(u0);
14+
15+
[numthreads(1,1,1)]
16+
void main() {
17+
Out[0].c1 = c1;
18+
Out[0].c2 = c2;
19+
}
20+
21+
//--- pipeline.yaml
22+
23+
---
24+
Shaders:
25+
- Stage: Compute
26+
Entry: main
27+
DispatchSize: [1, 1, 1]
28+
Buffers:
29+
- Name: CBArrays
30+
Format: Hex16
31+
Data: [
32+
0x0001, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A,
33+
0xffff, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A,
34+
0x1234, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A,
35+
0x0002, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A,
36+
0x3c00, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A, 0x5A5A
37+
]
38+
- Name: Out
39+
Format: Hex16
40+
# Warp doesn't seem to be able to handle a stride of 10 so we use 12 here
41+
Stride: 12
42+
ZeroInitSize: 12
43+
DescriptorSets:
44+
- Resources:
45+
- Name: CBArrays
46+
Kind: ConstantBuffer
47+
DirectXBinding:
48+
Register: 0
49+
Space: 0
50+
- Name: Out
51+
Kind: RWStructuredBuffer
52+
DirectXBinding:
53+
Register: 0
54+
Space: 0
55+
...
56+
#--- end
57+
58+
# REQUIRES: Half, Int16
59+
# DXC's vulkan support does not layout cbuffers compatibly with DXIL
60+
# UNSUPPORTED: Vulkan
61+
62+
# RUN: split-file %s %t
63+
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
64+
# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s
65+
66+
# CHECK: - Name: CBArrays
67+
# CHECK: Format: Hex16
68+
69+
# CHECK: - Name: Out
70+
# CHECK: Format: Hex16
71+
# CHECK: Data: [
72+
73+
# CHECK: 0x1,
74+
# CHECK-NOT: 0x5A5A,
75+
# CHECK: 0xFFFF,
76+
# CHECK-NOT: 0x5A5A,
77+
# CHECK: 0x1234,
78+
# CHECK-NOT: 0x5A5A,
79+
# CHECK: 0x2,
80+
# CHECK-NOT: 0x5A5A,
81+
82+
# CHECK: 0x3C00,
83+
# CHECK-NOT: 0x5A5A
84+
85+
# CHECK: ]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#--- source.hlsl
2+
3+
cbuffer CBArrays : register(b0) {
4+
double2 c1[2];
5+
uint64_t3 c2[2];
6+
int64_t c3[2];
7+
}
8+
9+
struct Arrays {
10+
double2 c1[2];
11+
uint64_t3 c2[2];
12+
int64_t c3[2];
13+
};
14+
15+
RWStructuredBuffer<Arrays> Out : register(u0);
16+
17+
[numthreads(1,1,1)]
18+
void main() {
19+
Out[0].c1 = c1;
20+
Out[0].c2 = c2;
21+
Out[0].c3 = c3;
22+
}
23+
24+
//--- pipeline.yaml
25+
26+
---
27+
Shaders:
28+
- Stage: Compute
29+
Entry: main
30+
DispatchSize: [1, 1, 1]
31+
Buffers:
32+
- Name: CBArrays
33+
Format: Hex64
34+
Data: [
35+
0x3ff0000000000000, 0x4008000000000000,
36+
0x5ff0000000000000, 0x6008000000000000,
37+
0x1234123412341234, 0x4321432143214321,
38+
0x0000000000000001, 0x5A5A5A5A5A5A5A5A,
39+
0x0000000000000001, 0x1234123412341234,
40+
0x4321432143214321, 0x5A5A5A5A5A5A5A5A,
41+
0x0000000000000001, 0x5A5A5A5A5A5A5A5A,
42+
0x0000000000000002, 0x5A5A5A5A5A5A5A5A
43+
]
44+
- Name: Out
45+
Format: Hex64
46+
Stride: 96
47+
ZeroInitSize: 96
48+
DescriptorSets:
49+
- Resources:
50+
- Name: CBArrays
51+
Kind: ConstantBuffer
52+
DirectXBinding:
53+
Register: 0
54+
Space: 0
55+
- Name: Out
56+
Kind: RWStructuredBuffer
57+
DirectXBinding:
58+
Register: 0
59+
Space: 0
60+
...
61+
#--- end
62+
63+
# DXC's vulkan support does not layout cbuffers compatibly with DXIL
64+
# UNSUPPORTED: Vulkan
65+
66+
# RUN: split-file %s %t
67+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
68+
# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s
69+
70+
# CHECK: - Name: CBArrays
71+
# CHECK: Format: Hex64
72+
73+
# CHECK: - Name: Out
74+
# CHECK: Format: Hex64
75+
# CHECK: Data: [
76+
77+
# CHECK: 0x3FF0000000000000,
78+
# CHECK: 0x4008000000000000,
79+
# CHECK: 0x5FF0000000000000,
80+
# CHECK: 0x6008000000000000,
81+
82+
# CHECK: 0x1234123412341234,
83+
# CHECK: 0x4321432143214321,
84+
# CHECK: 0x1,
85+
# CHECK-NOT: 0x5A5A5A5A5A5A5A5A,
86+
# CHECK: 0x1,
87+
# CHECK: 0x1234123412341234,
88+
# CHECK: 0x4321432143214321,
89+
# CHECK-NOT: 0x5A5A5A5A5A5A5A5A,
90+
91+
# CHECK: 0x1,
92+
# CHECK: 0x2
93+
# CHECK-NOT: 0x5A5A5A5A5A5A5A5A
94+
95+
# CHECK: ]

test/Feature/CBuffer/arrays.test

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#--- source.hlsl
2+
3+
cbuffer CBArrays : register(b0) {
4+
float c1[2];
5+
int4 c2[2][2];
6+
bool c3[2];
7+
}
8+
9+
struct Arrays {
10+
float c1[2];
11+
int4 c2[2][2];
12+
bool c3[2];
13+
};
14+
15+
RWStructuredBuffer<Arrays> Out : register(u0);
16+
17+
[numthreads(1,1,1)]
18+
void main() {
19+
Out[0].c1 = c1;
20+
Out[0].c2 = c2;
21+
Out[0].c3 = c3;
22+
}
23+
24+
//--- pipeline.yaml
25+
26+
---
27+
Shaders:
28+
- Stage: Compute
29+
Entry: main
30+
DispatchSize: [1, 1, 1]
31+
Buffers:
32+
- Name: CBArrays
33+
Format: Hex32
34+
Data: [
35+
0x3f800000, 0x5A5A5A5A, 0x5A5A5A5A, 0x5A5A5A5A,
36+
0x40800000, 0x5A5A5A5A, 0x5A5A5A5A, 0x5A5A5A5A,
37+
0x00000001, 0x00000002, 0x00000003, 0x00000004,
38+
0x00000005, 0x00000006, 0x00000007, 0x00000008,
39+
0x00000009, 0x0000000A, 0x0000000B, 0x0000000C,
40+
0x0000000D, 0x0000000E, 0x0000000F, 0x00000010,
41+
0x00000000, 0x5A5A5A5A, 0x5A5A5A5A, 0x5A5A5A5A,
42+
0x00000001, 0x5A5A5A5A, 0x5A5A5A5A, 0x5A5A5A5A,
43+
]
44+
- Name: Out
45+
Format: Hex32
46+
Stride: 80
47+
ZeroInitSize: 80
48+
DescriptorSets:
49+
- Resources:
50+
- Name: CBArrays
51+
Kind: ConstantBuffer
52+
DirectXBinding:
53+
Register: 0
54+
Space: 0
55+
- Name: Out
56+
Kind: RWStructuredBuffer
57+
DirectXBinding:
58+
Register: 0
59+
Space: 0
60+
...
61+
#--- end
62+
63+
# DXC's vulkan support does not layout cbuffers compatibly with DXIL
64+
# UNSUPPORTED: Vulkan
65+
66+
# RUN: split-file %s %t
67+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
68+
# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s
69+
70+
# CHECK: - Name: CBArrays
71+
# CHECK: Format: Hex32
72+
73+
# CHECK: - Name: Out
74+
# CHECK: Format: Hex32
75+
# CHECK: Data: [
76+
77+
# CHECK: 0x3F800000,
78+
# CHECK: 0x40800000,
79+
# CHECK-NOT: 0x5A5A5A5A,
80+
81+
# CHECK: 0x1,
82+
# CHECK: 0x2,
83+
# CHECK: 0x3,
84+
# CHECK: 0x4,
85+
# CHECK: 0x5,
86+
# CHECK: 0x6,
87+
# CHECK: 0x7,
88+
# CHECK: 0x8,
89+
# CHECK: 0x9,
90+
# CHECK: 0xA,
91+
# CHECK: 0xB,
92+
# CHECK: 0xC,
93+
# CHECK: 0xD,
94+
# CHECK: 0xE,
95+
# CHECK: 0xF,
96+
# CHECK: 0x10,
97+
98+
# CHECK: 0x0,
99+
# CHECK-NOT: 0x5A5A5A5A,
100+
101+
# CHECK: 0x1
102+
# CHECK-NOT: 0x5A5A5A5A
103+
104+
# CHECK: ]

test/Feature/CBuffer/lit.local.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if 'Clang' in config.available_features:
2+
config.unsupported = True
3+
4+
# CBuffer bindings seem to be broken under metal
5+
# https://github.com/llvm-beanz/offload-test-suite/issues/55
6+
if 'Metal' in config.available_features:
7+
config.unsupported = True

0 commit comments

Comments
 (0)