SPIRV-Cross/reference/shaders-msl/frag/scalar-refract-reflect.frag
Bill Hollings 40141ffddf MSL: Selectively enable fast-math in MSL code to match Vulkan CTS results.
Based on CTS testing, math optimizations between MSL and Vulkan are inconsistent.
In some cases, enabling MSL's fast-math compilation option matches Vulkan's math
results. In other cases, disabling it does. Broadly enabling or disabling fast-math
across all shaders results in some CTS test failures either way.

To fix this, selectively enable/disable fast-math optimizations in the MSL code,
using metal::fast and metal::precise function namespaces, where supported, and
the [[clang::optnone]] function attribute otherwise.

Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
2021-09-22 18:58:31 -04:00

50 lines
999 B
GLSL

#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_out
{
float FragColor [[color(0)]];
};
struct main0_in
{
float3 vRefract [[user(locn0)]];
};
template<typename T>
[[clang::optnone]] T spvReflect(T i, T n)
{
return i - T(2) * i * n * n;
}
template<typename T>
inline T spvRefract(T i, T n, T eta)
{
T NoI = n * i;
T NoI2 = NoI * NoI;
T k = T(1) - eta * eta * (T(1) - NoI2);
if (k < T(0))
{
return T(0);
}
else
{
return eta * i - (eta * NoI + sqrt(k)) * n;
}
}
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.FragColor = spvRefract(in.vRefract.x, in.vRefract.y, in.vRefract.z);
out.FragColor += spvReflect(in.vRefract.x, in.vRefract.y);
out.FragColor += refract(in.vRefract.xy, in.vRefract.yz, in.vRefract.z).y;
out.FragColor += reflect(in.vRefract.xy, in.vRefract.zy).y;
return out;
}