MSL: invalid code generated when atan2 and saturate are used in mixed precision environment
BlurryLight opened this issue · 1 comments
BlurryLight commented
the following hlsl generate invalid msl:
https://godbolt.org/z/7aM4j9Tnb
dxc args: -T ps_6_6 -E PSMain -spirv -enable-16bit-types
float4 PSMain(PSInput input) : SV_Target0
{
return saturate(atan2(1.0h, 2.0h));
}
which generate invalid msl: https://shader-playground.timjones.io/ebece9aee93af143eb7801593f8cf51a
fragment PSMain_out PSMain()
{
PSMain_out out = {};
out.out_var_SV_Target0 = float4(float(clamp(precise::atan2(half(1.0), half(2.0)), half(0.0), half(1.0))));
return out;
}
the error msg is "error: call to 'clamp' is ambiguous",
because it tries to call a function clamp(float,half,half)
.
Potential cause
it seems spirv-cross always emits precise::atan2
instead of the relaxed precision version.
Lines 10415 to 10416 in 0640756
HansKristian-Work commented
Problem is that there is no half overload in MSL, even for fast:: variant. Trivial to workaround I suppose.