Skip to content

Commit 621f976

Browse files
V-FEXrtllvm-beanz
andauthored
Implement firstbithigh test (#210)
Adds tests for `firstbithigh` Fixes #151 --------- Co-authored-by: Chris B <[email protected]>
1 parent 8415e05 commit 621f976

File tree

3 files changed

+291
-0
lines changed

3 files changed

+291
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<uint16_t4> In1 : register(t0);
4+
StructuredBuffer<int16_t4> In2 : register(t1);
5+
RWStructuredBuffer<uint32_t4> Out : register(u2);
6+
7+
[numthreads(1,1,1)]
8+
void main() {
9+
Out[0] = firstbithigh(In1[0]);
10+
uint32_t4 Out1 = {firstbithigh(In1[0].xyz), firstbithigh(In1[0].w)};
11+
uint32_t4 Out2 = {firstbithigh(In2[0].xy), firstbithigh(In2[0].zw)};
12+
Out[1]= Out1;
13+
Out[2] = Out2;
14+
}
15+
16+
//--- pipeline.yaml
17+
18+
---
19+
Shaders:
20+
- Stage: Compute
21+
Entry: main
22+
DispatchSize: [1, 1, 1]
23+
Buffers:
24+
- Name: In1
25+
Format: Hex16
26+
Stride: 8
27+
Data: [
28+
0x0000,
29+
0x0009,
30+
0x0001,
31+
0xFFFF,
32+
]
33+
- Name: In2
34+
Format: Int16
35+
Stride: 8
36+
# For signed, negative values the index of the first 0 from MSB is returned instead.
37+
Data: [
38+
-1, # All 1s -> return not found terminal
39+
-8,
40+
9,
41+
0
42+
]
43+
- Name: Out
44+
Format: UInt32
45+
Stride: 16
46+
ZeroInitSize: 48
47+
- Name: ExpectedOut # The result we expect
48+
Format: UInt32
49+
Stride: 16
50+
# All bits set (4294967295) is returned when no bit is set on the input
51+
Data: [4294967295, 3, 0, 15, 4294967295, 3, 0, 15, 4294967295, 2, 3, 4294967295]
52+
Results:
53+
- Result: Test1
54+
Rule: BufferExact
55+
Actual: Out
56+
Expected: ExpectedOut
57+
DescriptorSets:
58+
- Resources:
59+
- Name: In1
60+
Kind: StructuredBuffer
61+
DirectXBinding:
62+
Register: 0
63+
Space: 0
64+
VulkanBinding:
65+
Binding: 0
66+
- Name: In2
67+
Kind: StructuredBuffer
68+
DirectXBinding:
69+
Register: 1
70+
Space: 0
71+
VulkanBinding:
72+
Binding: 1
73+
- Name: Out
74+
Kind: RWStructuredBuffer
75+
DirectXBinding:
76+
Register: 2
77+
Space: 0
78+
VulkanBinding:
79+
Binding: 2
80+
...
81+
#--- end
82+
83+
# REQUIRES: Int16
84+
85+
# No bit set terminal is returned as 4294901776 instead of 4294967295
86+
# XFAIL: DXC-Metal
87+
# Fails with 'gpu-exec: error: Failed to materializeAll.:'
88+
# XFAIL: Clang-Metal
89+
90+
# https://github.com/llvm/llvm-project/issues/145752
91+
# XFAIL: Clang-DirectX
92+
93+
# 16/64 bit firstbithigh doesn't have a DXC-Vulkan lowering
94+
# https://github.com/microsoft/DirectXShaderCompiler/blob/48d6e3c635f0ab3ae79580c37003e6faeca6c671/tools/clang/test/CodeGenSPIRV/intrinsics.firstbitlow.64bit.hlsl#L5
95+
# UNSUPPORTED: DXC-Vulkan
96+
97+
# RUN: split-file %s %t
98+
# RUN: %dxc_target -T cs_6_5 -enable-16bit-types -Fo %t.o %t/source.hlsl
99+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<uint4> In1 : register(t0);
4+
StructuredBuffer<int4> In2 : register(t1);
5+
RWStructuredBuffer<uint4> Out : register(u2);
6+
7+
[numthreads(1,1,1)]
8+
void main() {
9+
Out[0] = firstbithigh(In1[0]);
10+
uint32_t4 Out1 = {firstbithigh(In1[0].xyz), firstbithigh(In1[0].w)};
11+
uint32_t4 Out2 = {firstbithigh(In2[0].xy), firstbithigh(In2[0].zw)};
12+
Out[1]= Out1;
13+
Out[2] = Out2;
14+
}
15+
16+
//--- pipeline.yaml
17+
18+
---
19+
Shaders:
20+
- Stage: Compute
21+
Entry: main
22+
DispatchSize: [1, 1, 1]
23+
Buffers:
24+
- Name: In1
25+
Format: Hex32
26+
Stride: 16
27+
Data: [
28+
0x00000000,
29+
0x00000009,
30+
0x00000001,
31+
0xFFFFFFFF,
32+
]
33+
- Name: In2
34+
Format: Int32
35+
Stride: 16
36+
# For signed, negative values the index of the first 0 from MSB is returned instead.
37+
Data: [
38+
-1, # All 1s -> return not found terminal
39+
-8,
40+
9,
41+
0
42+
]
43+
- Name: Out
44+
Format: UInt32
45+
Stride: 16
46+
ZeroInitSize: 48
47+
- Name: ExpectedOut # The result we expect
48+
Format: UInt32
49+
Stride: 16
50+
# All bits set (4294967295) is returned when no bit is set on the input
51+
Data: [4294967295, 3, 0, 31, 4294967295, 3, 0, 31, 4294967295, 2, 3, 4294967295]
52+
Results:
53+
- Result: Test1
54+
Rule: BufferExact
55+
Actual: Out
56+
Expected: ExpectedOut
57+
DescriptorSets:
58+
- Resources:
59+
- Name: In1
60+
Kind: StructuredBuffer
61+
DirectXBinding:
62+
Register: 0
63+
Space: 0
64+
VulkanBinding:
65+
Binding: 0
66+
- Name: In2
67+
Kind: StructuredBuffer
68+
DirectXBinding:
69+
Register: 1
70+
Space: 0
71+
VulkanBinding:
72+
Binding: 1
73+
- Name: Out
74+
Kind: RWStructuredBuffer
75+
DirectXBinding:
76+
Register: 2
77+
Space: 0
78+
VulkanBinding:
79+
Binding: 2
80+
...
81+
#--- end
82+
83+
# https://github.com/llvm/llvm-project/issues/145752
84+
# XFAIL: Clang-DirectX || Clang-Metal
85+
86+
# RUN: split-file %s %t
87+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
88+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<uint64_t4> In1 : register(t0);
4+
StructuredBuffer<int64_t4> In2 : register(t1);
5+
RWStructuredBuffer<uint32_t4> Out : register(u2);
6+
7+
[numthreads(1,1,1)]
8+
void main() {
9+
Out[0] = firstbithigh(In1[0]);
10+
uint32_t4 Out1 = {firstbithigh(In1[0].xyz), firstbithigh(In1[0].w)};
11+
uint32_t4 Out2 = {firstbithigh(In2[0].xy), firstbithigh(In2[0].zw)};
12+
Out[1]= Out1;
13+
Out[2] = Out2;
14+
}
15+
16+
//--- pipeline.yaml
17+
18+
---
19+
Shaders:
20+
- Stage: Compute
21+
Entry: main
22+
DispatchSize: [1, 1, 1]
23+
Buffers:
24+
- Name: In1
25+
Format: Hex64
26+
Stride: 32
27+
Data: [
28+
0x0000000000000000,
29+
0x0000000000000009,
30+
0x0000000000000001,
31+
0xFFFFFFFFFFFFFFFF,
32+
]
33+
- Name: In2
34+
Format: Int64
35+
Stride: 32
36+
# For signed, negative values the index of the first 0 from MSB is returned instead.
37+
Data: [
38+
-1, # All 1s -> return not found terminal
39+
-8,
40+
9,
41+
0
42+
]
43+
- Name: Out
44+
Format: UInt32
45+
Stride: 16
46+
ZeroInitSize: 48
47+
- Name: ExpectedOut # The result we expect
48+
Format: UInt32
49+
Stride: 16
50+
# All bits set (4294967295) is returned when no bit is set on the input
51+
Data: [4294967295, 3, 0, 63, 4294967295, 3, 0, 63, 4294967295, 2, 3, 4294967295]
52+
Results:
53+
- Result: Test1
54+
Rule: BufferExact
55+
Actual: Out
56+
Expected: ExpectedOut
57+
DescriptorSets:
58+
- Resources:
59+
- Name: In1
60+
Kind: StructuredBuffer
61+
DirectXBinding:
62+
Register: 0
63+
Space: 0
64+
VulkanBinding:
65+
Binding: 0
66+
- Name: In2
67+
Kind: StructuredBuffer
68+
DirectXBinding:
69+
Register: 1
70+
Space: 0
71+
VulkanBinding:
72+
Binding: 1
73+
- Name: Out
74+
Kind: RWStructuredBuffer
75+
DirectXBinding:
76+
Register: 2
77+
Space: 0
78+
VulkanBinding:
79+
Binding: 2
80+
...
81+
#--- end
82+
83+
# REQUIRES: Int64
84+
85+
# Fails with 'gpu-exec: error: Failed to materializeAll.:'
86+
# XFAIL: Metal
87+
88+
# 16/64 bit firstbithigh doesn't have a DXC-Vulkan lowering
89+
# https://github.com/microsoft/DirectXShaderCompiler/blob/48d6e3c635f0ab3ae79580c37003e6faeca6c671/tools/clang/test/CodeGenSPIRV/intrinsics.firstbitlow.64bit.hlsl#L5
90+
# UNSUPPORTED: DXC-Vulkan
91+
92+
# https://github.com/microsoft/DirectXShaderCompiler/issues/7502
93+
# WARP firstbithigh(s64 -1) should return -1 but returns 32
94+
# XFAIL: DirectX-WARP
95+
96+
# https://github.com/llvm/llvm-project/issues/143171
97+
# XFAIL: Clang-Vulkan
98+
99+
# https://github.com/llvm/llvm-project/issues/145752
100+
# XFAIL: Clang-DirectX
101+
102+
# RUN: split-file %s %t
103+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
104+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)