ec054dad7f
Emit synthetic functions before function constants. Support use of spvQuantizeToF16() in function constants for numerical behavior consistency with the op code. Ensure subnormal results from OpQuantizeToF16 are flushed to zero per SPIR-V spec. Adjust SPIRV-Cross unit test reference shaders to accommodate these changes. Any MSL reference shader that inclues a synthetic function is affected, since the location it is emitted has changed.
35 lines
945 B
Plaintext
35 lines
945 B
Plaintext
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
|
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
using namespace metal;
|
|
|
|
template <typename F> struct SpvHalfTypeSelector;
|
|
template <> struct SpvHalfTypeSelector<float> { public: using H = half; };
|
|
template<uint N> struct SpvHalfTypeSelector<vec<float, N>> { using H = vec<half, N>; };
|
|
template<typename F, typename H = typename SpvHalfTypeSelector<F>::H>
|
|
[[clang::optnone]] F spvQuantizeToF16(F fval)
|
|
{
|
|
H hval = H(fval);
|
|
hval = select(copysign(H(0), hval), hval, isnormal(hval) || isinf(hval) || isnan(hval));
|
|
return F(hval);
|
|
}
|
|
|
|
struct SSBO0
|
|
{
|
|
float scalar;
|
|
float2 vec2_val;
|
|
float3 vec3_val;
|
|
float4 vec4_val;
|
|
};
|
|
|
|
kernel void main0(device SSBO0& _4 [[buffer(0)]])
|
|
{
|
|
_4.scalar = spvQuantizeToF16(_4.scalar);
|
|
_4.vec2_val = spvQuantizeToF16(_4.vec2_val);
|
|
_4.vec3_val = spvQuantizeToF16(_4.vec3_val);
|
|
_4.vec4_val = spvQuantizeToF16(_4.vec4_val);
|
|
}
|
|
|