diff options
author | Bill Hollings <bill.hollings@brenwill.com> | 2021-09-23 01:58:31 +0300 |
---|---|---|
committer | Bill Hollings <bill.hollings@brenwill.com> | 2021-09-23 01:58:31 +0300 |
commit | 40141ffddfe6a00fba0cce7e1b5f3759b8d520b8 (patch) | |
tree | 9f97661170f9ccdb3de82110a0df7d3738505f61 /reference/shaders-ue4/asm/frag | |
parent | b81334a513e357cc15d6e93b9395b7733056f993 (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/shaders-ue4/asm/frag')
4 files changed, 11 insertions, 11 deletions
diff --git a/reference/shaders-ue4/asm/frag/depth-compare.asm.frag b/reference/shaders-ue4/asm/frag/depth-compare.asm.frag index bdeccc2f..9ee2d89b 100644 --- a/reference/shaders-ue4/asm/frag/depth-compare.asm.frag +++ b/reference/shaders-ue4/asm/frag/depth-compare.asm.frag @@ -246,7 +246,7 @@ fragment main0_out main0(constant type_View& View [[buffer(0)]], constant type_G float _218 = sqrt(mix(1.0, _213 * _213, _Globals.ShadowFadeFraction)); float4 _219 = _107; _219.z = _218; - float3 _236 = normalize((SceneTexturesStruct_GBufferATexture.sample(SceneTexturesStruct_GBufferATextureSampler, _114, level(0.0)).xyz * float3(2.0)) - float3(1.0)); + float3 _236 = fast::normalize((SceneTexturesStruct_GBufferATexture.sample(SceneTexturesStruct_GBufferATextureSampler, _114, level(0.0)).xyz * float3(2.0)) - float3(1.0)); uint _240 = uint(round(SceneTexturesStruct_GBufferBTexture.sample(SceneTexturesStruct_GBufferBTextureSampler, _114, level(0.0)).w * 255.0)); bool _248 = (_240 & 15u) == 5u; float _448; @@ -259,7 +259,7 @@ fragment main0_out main0(constant type_View& View [[buffer(0)]], constant type_G if (_160) { float3 _278 = _152 / float3(_158); - float3 _280 = normalize(cross(_278, float3(0.0, 0.0, 1.0))); + float3 _280 = fast::normalize(cross(_278, float3(0.0, 0.0, 1.0))); float3 _284 = float3(_Globals.InvShadowmapResolution); float3 _285 = _280 * _284; float3 _286 = cross(_280, _278) * _284; diff --git a/reference/shaders-ue4/asm/frag/global-constant-arrays.asm.frag b/reference/shaders-ue4/asm/frag/global-constant-arrays.asm.frag index 210d4f98..c3d26e65 100644 --- a/reference/shaders-ue4/asm/frag/global-constant-arrays.asm.frag +++ b/reference/shaders-ue4/asm/frag/global-constant-arrays.asm.frag @@ -176,7 +176,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa float _644 = ((0.317398726940155029296875 + (4.25 * _Globals.WhiteTemp)) + ((4.2048167614439080352894961833954e-08 * _Globals.WhiteTemp) * _Globals.WhiteTemp)) / ((1.0 - (2.8974181986995972692966461181641e-05 * _Globals.WhiteTemp)) + ((1.6145605741257895715534687042236e-07 * _Globals.WhiteTemp) * _Globals.WhiteTemp)); float _649 = ((2.0 * _633) - (8.0 * _644)) + 4.0; float2 _653 = float2((3.0 * _633) / _649, (2.0 * _644) / _649); - float2 _660 = normalize(float2(_633, _644)); + float2 _660 = fast::normalize(float2(_633, _644)); float _665 = _633 + (((-_660.y) * _Globals.WhiteTint) * 0.0500000007450580596923828125); float _669 = _644 + ((_660.x * _Globals.WhiteTint) * 0.0500000007450580596923828125); float _674 = ((2.0 * _665) - (8.0 * _669)) + 4.0; @@ -273,7 +273,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa } else { - _990 = 57.2957763671875 * atan2(sqrt(3.0) * (_974 - _976), ((2.0 * _973) - _974) - _976); + _990 = 57.2957763671875 * precise::atan2(sqrt(3.0) * (_974 - _976), ((2.0 * _973) - _974) - _976); } float _995; if (_990 < 0.0) @@ -436,7 +436,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa } else { - _2174 = 57.2957763671875 * atan2(sqrt(3.0) * (_2158 - _2160), ((2.0 * _2157) - _2158) - _2160); + _2174 = 57.2957763671875 * precise::atan2(sqrt(3.0) * (_2158 - _2160), ((2.0 * _2157) - _2158) - _2160); } float _2179; if (_2174 < 0.0) @@ -909,7 +909,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa } else { - _1337 = 57.2957763671875 * atan2(sqrt(3.0) * (_1321 - _1323), ((2.0 * _1320) - _1321) - _1323); + _1337 = 57.2957763671875 * precise::atan2(sqrt(3.0) * (_1321 - _1323), ((2.0 * _1320) - _1321) - _1323); } float _1342; if (_1337 < 0.0) diff --git a/reference/shaders-ue4/asm/frag/padded-float-array-member-defef.asm.frag b/reference/shaders-ue4/asm/frag/padded-float-array-member-defef.asm.frag index 67fa21aa..83857f22 100644 --- a/reference/shaders-ue4/asm/frag/padded-float-array-member-defef.asm.frag +++ b/reference/shaders-ue4/asm/frag/padded-float-array-member-defef.asm.frag @@ -178,7 +178,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa float _670 = ((0.317398726940155029296875 + (4.25 * _Globals.WhiteTemp)) + ((4.2048167614439080352894961833954e-08 * _Globals.WhiteTemp) * _Globals.WhiteTemp)) / ((1.0 - (2.8974181986995972692966461181641e-05 * _Globals.WhiteTemp)) + ((1.6145605741257895715534687042236e-07 * _Globals.WhiteTemp) * _Globals.WhiteTemp)); float _675 = ((2.0 * _659) - (8.0 * _670)) + 4.0; float2 _679 = float2((3.0 * _659) / _675, (2.0 * _670) / _675); - float2 _686 = normalize(float2(_659, _670)); + float2 _686 = fast::normalize(float2(_659, _670)); float _691 = _659 + (((-_686.y) * _Globals.WhiteTint) * 0.0500000007450580596923828125); float _695 = _670 + ((_686.x * _Globals.WhiteTint) * 0.0500000007450580596923828125); float _700 = ((2.0 * _691) - (8.0 * _695)) + 4.0; @@ -275,7 +275,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa } else { - _1016 = 57.2957763671875 * atan2(sqrt(3.0) * (_1000 - _1002), ((2.0 * _999) - _1000) - _1002); + _1016 = 57.2957763671875 * precise::atan2(sqrt(3.0) * (_1000 - _1002), ((2.0 * _999) - _1000) - _1002); } float _1021; if (_1016 < 0.0) @@ -485,7 +485,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa } else { - _2278 = 57.2957763671875 * atan2(sqrt(3.0) * (_2262 - _2264), ((2.0 * _2261) - _2262) - _2264); + _2278 = 57.2957763671875 * precise::atan2(sqrt(3.0) * (_2262 - _2264), ((2.0 * _2261) - _2262) - _2264); } float _2283; if (_2278 < 0.0) @@ -958,7 +958,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_Globals& _Globa } else { - _1443 = 57.2957763671875 * atan2(sqrt(3.0) * (_1427 - _1429), ((2.0 * _1426) - _1427) - _1429); + _1443 = 57.2957763671875 * precise::atan2(sqrt(3.0) * (_1427 - _1429), ((2.0 * _1426) - _1427) - _1429); } float _1448; if (_1443 < 0.0) diff --git a/reference/shaders-ue4/asm/frag/sample-mask-not-array.asm.frag b/reference/shaders-ue4/asm/frag/sample-mask-not-array.asm.frag index 9404aa66..834517a8 100644 --- a/reference/shaders-ue4/asm/frag/sample-mask-not-array.asm.frag +++ b/reference/shaders-ue4/asm/frag/sample-mask-not-array.asm.frag @@ -462,7 +462,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant type_View& View [[bu { _215 = in.in_var_TEXCOORD7; } - float3 _216 = fast::max(Material.Material_VectorExpressions[1].xyz * float3(((1.0 + dot(float3(-1.0, -1.5, 3.0) / float3(sqrt(12.25)), normalize(float3x3(in.in_var_TEXCOORD10_centroid.xyz, cross(in.in_var_TEXCOORD11_centroid.xyz, in.in_var_TEXCOORD10_centroid.xyz) * float3(in.in_var_TEXCOORD11_centroid.w), in.in_var_TEXCOORD11_centroid.xyz) * normalize((float3(0.0, 0.0, 1.0) * float3(View.View_NormalOverrideParameter.w)) + View.View_NormalOverrideParameter.xyz)))) * 0.5) + 0.20000000298023223876953125), float3(0.0)); + float3 _216 = fast::max(Material.Material_VectorExpressions[1].xyz * float3(((1.0 + dot(float3(-1.0, -1.5, 3.0) / float3(sqrt(12.25)), fast::normalize(float3x3(in.in_var_TEXCOORD10_centroid.xyz, cross(in.in_var_TEXCOORD11_centroid.xyz, in.in_var_TEXCOORD10_centroid.xyz) * float3(in.in_var_TEXCOORD11_centroid.w), in.in_var_TEXCOORD11_centroid.xyz) * fast::normalize((float3(0.0, 0.0, 1.0) * float3(View.View_NormalOverrideParameter.w)) + View.View_NormalOverrideParameter.xyz)))) * 0.5) + 0.20000000298023223876953125), float3(0.0)); float3 _246; if (View.View_OutOfBoundsMask > 0.0) { |