Precise Float Fixes
Fixes artifacts in TOTK
This commit is contained in:
committed by
Isaac Marovitz
parent
3360740250
commit
8fa8f3a390
@@ -122,6 +122,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Msl/HelperFunctions/SwizzleAdd.metal");
|
||||
}
|
||||
|
||||
if ((info.HelperFunctionsMask & HelperFunctionsMask.Precise) != 0)
|
||||
{
|
||||
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Msl/HelperFunctions/Precise.metal");
|
||||
}
|
||||
|
||||
return sets;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
template<typename T>
|
||||
[[clang::optnone]] T PreciseFAdd(T l, T r) {
|
||||
return fma(T(1), l, r);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[clang::optnone]] T PreciseFSub(T l, T r) {
|
||||
return fma(T(-1), r, l);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[clang::optnone]] T PreciseFMul(T l, T r) {
|
||||
return fma(l, r, T(0));
|
||||
}
|
||||
@@ -118,6 +118,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
return op + expr[0];
|
||||
|
||||
case 2:
|
||||
if (operation.ForcePrecise)
|
||||
{
|
||||
var func = (inst & Instruction.Mask) switch
|
||||
{
|
||||
Instruction.Add => "PreciseFAdd",
|
||||
Instruction.Subtract => "PreciseFSub",
|
||||
Instruction.Multiply => "PreciseFMul",
|
||||
};
|
||||
|
||||
return $"{func}({expr[0]}, {expr[1]})";
|
||||
}
|
||||
|
||||
return $"{expr[0]} {op} {expr[1]}";
|
||||
|
||||
case 3:
|
||||
|
||||
@@ -49,9 +49,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
return false;
|
||||
}
|
||||
|
||||
formatted = value.ToString("F9", CultureInfo.InvariantCulture);
|
||||
formatted = value.ToString("G9", CultureInfo.InvariantCulture);
|
||||
|
||||
if (!formatted.Contains('.'))
|
||||
if (!(formatted.Contains('.') ||
|
||||
formatted.Contains('e') ||
|
||||
formatted.Contains('E')))
|
||||
{
|
||||
formatted += ".0f";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user