Skip to content

Commit c2873f4

Browse files
author
Tim Foley
authored
Mark f32tof16 and f16tof32 as HLSL intrinsics (shader-slang#1526)
Fixes GitLab issue 85 These functions are intrinsic for HLSL, but were not marked as such, leading to emitting code that manually loops for the vector case. The looping code resulted in lower performance for some users, because apparently dxc was unable (or unwilling?) to unroll the loop, and ended up generating temporary ("stack-allocated") arrays for the vectors produced. As a longer-term solution, we may need to consider how the `VECTOR_MAP...` and `MATRIX_MAP...` idioms used in the stdlib get lowered, so that we can emit fully-unrolled versions in cases where the vector/matrix shape is known at the time we generate code. This PR does not attempt to address that larger issue.
1 parent 5c56479 commit c2873f4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

source/slang/hlsl.meta.slang

+4
Original file line numberDiff line numberDiff line change
@@ -1477,9 +1477,11 @@ matrix<T,N,M> exp2(matrix<T,N,M> x)
14771477
// Convert 16-bit float stored in low bits of integer
14781478
__target_intrinsic(glsl, "unpackHalf2x16($0).x")
14791479
__glsl_version(420)
1480+
__target_intrinsic(hlsl)
14801481
float f16tof32(uint value);
14811482

14821483
__generic<let N : int>
1484+
__target_intrinsic(hlsl)
14831485
vector<float, N> f16tof32(vector<uint, N> value)
14841486
{
14851487
VECTOR_MAP_UNARY(float, N, f16tof32, value);
@@ -1488,9 +1490,11 @@ vector<float, N> f16tof32(vector<uint, N> value)
14881490
// Convert to 16-bit float stored in low bits of integer
14891491
__target_intrinsic(glsl, "packHalf2x16(vec2($0,0.0))")
14901492
__glsl_version(420)
1493+
__target_intrinsic(hlsl)
14911494
uint f32tof16(float value);
14921495

14931496
__generic<let N : int>
1497+
__target_intrinsic(hlsl)
14941498
vector<uint, N> f32tof16(vector<float, N> value)
14951499
{
14961500
VECTOR_MAP_UNARY(uint, N, f32tof16, value);

0 commit comments

Comments
 (0)