Skip to content

Commit 66988cc

Browse files
tcorringhamTim Corringham
andauthored
Add test for f32tof16() (#675)
Add a test for all supported variants of f32tof16(): uint f32tof16(float) uint2 f32tof16(float2) uint3 f32tof16(float3) uint4 f32tof16(float4) Fixes #100 --------- Co-authored-by: Tim Corringham <tcorring@amd.com>
1 parent 5323475 commit 66988cc

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/Feature/HLSLLib/f32tof16.test

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<float> In : register(t0);
4+
5+
RWStructuredBuffer<uint> Out : register(u1);
6+
7+
[numthreads(1,1,1)]
8+
void main() {
9+
for (uint i = 0; i < 7; i++)
10+
Out[i] = f32tof16(In[i]);
11+
12+
float2 F2;
13+
F2.x = In[7];
14+
F2.y = In[8];
15+
uint2 U2 = f32tof16(F2);
16+
Out[7] = U2.x;
17+
Out[8] = U2.y;
18+
19+
float3 F3;
20+
F3.x = In[9];
21+
F3.y = In[10];
22+
F3.z = In[11];
23+
uint3 U3 = f32tof16(F3);
24+
Out[9] = U3.x;
25+
Out[10] = U3.y;
26+
Out[11] = U3.z;
27+
28+
float4 F4;
29+
F4.x = In[12];
30+
F4.y = In[13];
31+
F4.z = In[14];
32+
F4.w = In[15];
33+
uint4 U4 = f32tof16(F4);
34+
Out[12] = U4.x;
35+
Out[13] = U4.y;
36+
Out[14] = U4.z;
37+
Out[15] = U4.w;
38+
}
39+
40+
//--- pipeline.yaml
41+
42+
---
43+
Shaders:
44+
- Stage: Compute
45+
Entry: main
46+
DispatchSize: [1, 1, 1]
47+
Buffers:
48+
- Name: In
49+
Format: Float32
50+
Stride: 4
51+
Data: [ 0, 6.0e-08, 6.09756e-05, 6.10352e-05, 0.333252,
52+
0.999512, 1, 1.00098, 65504, 3.14159, 1, -0, inf, -inf,
53+
-0.824219, 42.0 ]
54+
- Name: Out
55+
Format: UInt32
56+
Stride: 4
57+
FillSize: 64
58+
- Name: ExpectedOut # The result we expect
59+
Format: UInt32
60+
Stride: 4
61+
Data: [ 0x0, 0x0001, 0x03ff, 0x0400, 0x3555, 0x3bff, 0x3c00, 0x3c01, 0x7bff, 0x4248, 0x3c00, 0x8000, 0x7c00, 0xfc00, 0xba98, 0x5140]
62+
Results:
63+
- Result: Test1
64+
Rule: BufferExact
65+
Actual: Out
66+
Expected: ExpectedOut
67+
DescriptorSets:
68+
- Resources:
69+
- Name: In
70+
Kind: StructuredBuffer
71+
DirectXBinding:
72+
Register: 0
73+
Space: 0
74+
VulkanBinding:
75+
Binding: 0
76+
- Name: Out
77+
Kind: RWStructuredBuffer
78+
DirectXBinding:
79+
Register: 1
80+
Space: 0
81+
VulkanBinding:
82+
Binding: 1
83+
...
84+
#--- end
85+
86+
87+
# RUN: split-file %s %t
88+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
89+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)