Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Hollings <bill.hollings@brenwill.com>2021-09-23 01:58:31 +0300
committerBill Hollings <bill.hollings@brenwill.com>2021-09-23 01:58:31 +0300
commit40141ffddfe6a00fba0cce7e1b5f3759b8d520b8 (patch)
tree9f97661170f9ccdb3de82110a0df7d3738505f61 /reference/opt/shaders-msl
parentb81334a513e357cc15d6e93b9395b7733056f993 (diff)
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.
Diffstat (limited to 'reference/opt/shaders-msl')
-rw-r--r--reference/opt/shaders-msl/flatten/struct.flatten.vert2
-rw-r--r--reference/opt/shaders-msl/frag/in_mat.frag2
-rw-r--r--reference/opt/shaders-msl/frag/scalar-refract-reflect.frag2
-rw-r--r--reference/opt/shaders-msl/vert/copy.flatten.vert2
-rw-r--r--reference/opt/shaders-msl/vert/dynamic.flatten.vert2
-rw-r--r--reference/opt/shaders-msl/vert/packed_matrix.vert2
6 files changed, 6 insertions, 6 deletions
diff --git a/reference/opt/shaders-msl/flatten/struct.flatten.vert b/reference/opt/shaders-msl/flatten/struct.flatten.vert
index d97a34a8..dc96ceae 100644
--- a/reference/opt/shaders-msl/flatten/struct.flatten.vert
+++ b/reference/opt/shaders-msl/flatten/struct.flatten.vert
@@ -34,7 +34,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant UBO& _18 [[buffer(0)]]
out.gl_Position = _18.uMVP * in.aVertex;
out.vColor = float4(0.0);
float3 _39 = in.aVertex.xyz - float3(_18.light.Position);
- out.vColor += ((_18.light.Color * fast::clamp(1.0 - (length(_39) / _18.light.Radius), 0.0, 1.0)) * dot(in.aNormal, normalize(_39)));
+ out.vColor += ((_18.light.Color * fast::clamp(1.0 - (length(_39) / _18.light.Radius), 0.0, 1.0)) * dot(in.aNormal, fast::normalize(_39)));
return out;
}
diff --git a/reference/opt/shaders-msl/frag/in_mat.frag b/reference/opt/shaders-msl/frag/in_mat.frag
index 83ed9b5e..1defc6c3 100644
--- a/reference/opt/shaders-msl/frag/in_mat.frag
+++ b/reference/opt/shaders-msl/frag/in_mat.frag
@@ -27,7 +27,7 @@ fragment main0_out main0(main0_in in [[stage_in]], texturecube<float> samplerCol
inInvModelView[1] = in.inInvModelView_1;
inInvModelView[2] = in.inInvModelView_2;
inInvModelView[3] = in.inInvModelView_3;
- float4 _31 = inInvModelView * float4(reflect(normalize(in.inPos), normalize(in.inNormal)), 0.0);
+ float4 _31 = inInvModelView * float4(reflect(fast::normalize(in.inPos), fast::normalize(in.inNormal)), 0.0);
float _33 = _31.x;
float3 _59 = float3(_33, _31.yz);
_59.x = _33 * (-1.0);
diff --git a/reference/opt/shaders-msl/frag/scalar-refract-reflect.frag b/reference/opt/shaders-msl/frag/scalar-refract-reflect.frag
index 592d4458..e4adc4ab 100644
--- a/reference/opt/shaders-msl/frag/scalar-refract-reflect.frag
+++ b/reference/opt/shaders-msl/frag/scalar-refract-reflect.frag
@@ -16,7 +16,7 @@ struct main0_in
};
template<typename T>
-inline T spvReflect(T i, T n)
+[[clang::optnone]] T spvReflect(T i, T n)
{
return i - T(2) * i * n * n;
}
diff --git a/reference/opt/shaders-msl/vert/copy.flatten.vert b/reference/opt/shaders-msl/vert/copy.flatten.vert
index d73ee328..32fde3a4 100644
--- a/reference/opt/shaders-msl/vert/copy.flatten.vert
+++ b/reference/opt/shaders-msl/vert/copy.flatten.vert
@@ -36,7 +36,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant UBO& _21 [[buffer(0)]]
for (int _96 = 0; _96 < 4; )
{
float3 _68 = in.aVertex.xyz - float3(_21.lights[_96].Position);
- out.vColor += ((_21.lights[_96].Color * fast::clamp(1.0 - (length(_68) / _21.lights[_96].Radius), 0.0, 1.0)) * dot(in.aNormal, normalize(_68)));
+ out.vColor += ((_21.lights[_96].Color * fast::clamp(1.0 - (length(_68) / _21.lights[_96].Radius), 0.0, 1.0)) * dot(in.aNormal, fast::normalize(_68)));
_96++;
continue;
}
diff --git a/reference/opt/shaders-msl/vert/dynamic.flatten.vert b/reference/opt/shaders-msl/vert/dynamic.flatten.vert
index 92911a4e..26264ddf 100644
--- a/reference/opt/shaders-msl/vert/dynamic.flatten.vert
+++ b/reference/opt/shaders-msl/vert/dynamic.flatten.vert
@@ -36,7 +36,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant UBO& _21 [[buffer(0)]]
for (int _82 = 0; _82 < 4; )
{
float3 _54 = in.aVertex.xyz - float3(_21.lights[_82].Position);
- out.vColor += ((_21.lights[_82].Color * fast::clamp(1.0 - (length(_54) / _21.lights[_82].Radius), 0.0, 1.0)) * dot(in.aNormal, normalize(_54)));
+ out.vColor += ((_21.lights[_82].Color * fast::clamp(1.0 - (length(_54) / _21.lights[_82].Radius), 0.0, 1.0)) * dot(in.aNormal, fast::normalize(_54)));
_82++;
continue;
}
diff --git a/reference/opt/shaders-msl/vert/packed_matrix.vert b/reference/opt/shaders-msl/vert/packed_matrix.vert
index 74b2c5fc..b8cac0ac 100644
--- a/reference/opt/shaders-msl/vert/packed_matrix.vert
+++ b/reference/opt/shaders-msl/vert/packed_matrix.vert
@@ -39,7 +39,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant _RESERVED_IDENTIFIER_F
{
main0_out out = {};
float4 _70 = _RESERVED_IDENTIFIER_FIXUP_22044._RESERVED_IDENTIFIER_FIXUP_m0 * float4(float3(_RESERVED_IDENTIFIER_FIXUP_22044._RESERVED_IDENTIFIER_FIXUP_m10) + (in._RESERVED_IDENTIFIER_FIXUP_5275.xyz * (_RESERVED_IDENTIFIER_FIXUP_22044._RESERVED_IDENTIFIER_FIXUP_m17 + _RESERVED_IDENTIFIER_FIXUP_22044._RESERVED_IDENTIFIER_FIXUP_m18)), 1.0);
- out._RESERVED_IDENTIFIER_FIXUP_3976 = normalize(float4(in._RESERVED_IDENTIFIER_FIXUP_5275.xyz, 0.0) * _RESERVED_IDENTIFIER_FIXUP_18812._RESERVED_IDENTIFIER_FIXUP_m1);
+ out._RESERVED_IDENTIFIER_FIXUP_3976 = fast::normalize(float4(in._RESERVED_IDENTIFIER_FIXUP_5275.xyz, 0.0) * _RESERVED_IDENTIFIER_FIXUP_18812._RESERVED_IDENTIFIER_FIXUP_m1);
float4 _94 = _70;
_94.y = -_70.y;
out.gl_Position = _94;