I'v been looking into glslang recently, and I noticed that almost all HLSL intrinsic functions don't support half-type directly. For example, there are float max(float, float)
, int max(int, int)
but no half max(half, half)
. The Microsoft document also indicates that float
and int
component type are supported, they don't mension half
: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-max
But in shader, if you write half res = max(1.0h, 2.0h)
, the shader compiles with no error. So does this max
actually promote the two half parameters to float, get a float result and implicitly cast the result to half?
half
is mapped to float
on current HLSL, so your code actually calculates values using floats. More info here:
But then the D3D10 era came along with its unified shader cores, and suddenly fp16 math was no more. None of the desktop hardware supported it anymore, and so HLSL went ahead and mapped the half type to float and called it day.
If you want to use real 16-bit values, you could try using min16float
instead of half
.