Skip to content

Commit 87610f6

Browse files
chuckgenomeTim Foley
authored and
Tim Foley
committed
Add GLSL intrinsics for f32tof16() and f16tof32() (shader-slang#883)
1 parent 325b721 commit 87610f6

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

source/slang/hlsl.meta.slang

+10-2
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,20 @@ __generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> exp2(vector<T
717717
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> exp2(matrix<T,N,M> x);
718718

719719
// Convert 16-bit float stored in low bits of integer
720+
__target_intrinsic(glsl, "unpackHalf2x16($0).x")
720721
float f16tof32(uint value);
721-
__generic<let N : int> vector<float,N> f16tof32(vector<uint,N> value);
722+
723+
__generic<let N : int>
724+
__target_intrinsic(glsl, "unpackHalf2x16($0).x")
725+
vector<float,N> f16tof32(vector<uint,N> value);
722726

723727
// Convert to 16-bit float stored in low bits of integer
728+
__target_intrinsic(glsl, "packHalf2x16(vec2($0,0.0))")
724729
uint f32tof16(float value);
725-
__generic<let N : int> vector<uint,N> f32tof16(vector<float,N> value);
730+
731+
__generic<let N : int>
732+
__target_intrinsic(glsl, "packHalf2x16(vec2($0,0.0))")
733+
vector<uint,N> f32tof16(vector<float,N> value);
726734

727735
// Flip surface normal to face forward, if needed
728736
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> faceforward(vector<T,N> n, vector<T,N> i, vector<T,N> ng);

source/slang/hlsl.meta.slang.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,20 @@ SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> ex
793793
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> exp2(matrix<T,N,M> x);\n")
794794
SLANG_RAW("\n")
795795
SLANG_RAW("// Convert 16-bit float stored in low bits of integer\n")
796+
SLANG_RAW("__target_intrinsic(glsl, \"unpackHalf2x16($0).x\")\n")
796797
SLANG_RAW("float f16tof32(uint value);\n")
797-
SLANG_RAW("__generic<let N : int> vector<float,N> f16tof32(vector<uint,N> value);\n")
798+
SLANG_RAW("\n")
799+
SLANG_RAW("__generic<let N : int>\n")
800+
SLANG_RAW("__target_intrinsic(glsl, \"unpackHalf2x16($0).x\")\n")
801+
SLANG_RAW("vector<float,N> f16tof32(vector<uint,N> value);\n")
798802
SLANG_RAW("\n")
799803
SLANG_RAW("// Convert to 16-bit float stored in low bits of integer\n")
804+
SLANG_RAW("__target_intrinsic(glsl, \"packHalf2x16(vec2($0,0.0))\")\n")
800805
SLANG_RAW("uint f32tof16(float value);\n")
801-
SLANG_RAW("__generic<let N : int> vector<uint,N> f32tof16(vector<float,N> value);\n")
806+
SLANG_RAW("\n")
807+
SLANG_RAW("__generic<let N : int>\n")
808+
SLANG_RAW("__target_intrinsic(glsl, \"packHalf2x16(vec2($0,0.0))\")\n")
809+
SLANG_RAW("vector<uint,N> f32tof16(vector<float,N> value);\n")
802810
SLANG_RAW("\n")
803811
SLANG_RAW("// Flip surface normal to face forward, if needed\n")
804812
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> faceforward(vector<T,N> n, vector<T,N> i, vector<T,N> ng);\n")
@@ -1513,7 +1521,7 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
15131521

15141522
sb << "};\n";
15151523
}
1516-
SLANG_RAW("#line 1440 \"hlsl.meta.slang\"")
1524+
SLANG_RAW("#line 1448 \"hlsl.meta.slang\"")
15171525
SLANG_RAW("\n")
15181526
SLANG_RAW("\n")
15191527
SLANG_RAW("\n")

0 commit comments

Comments
 (0)