summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/ShaderGenCommon.cpp
diff options
context:
space:
mode:
authorOatmealDome <OatmealDome@users.noreply.github.com>2023-02-26 02:00:25 -0500
committerGitHub <noreply@github.com>2023-02-26 02:00:25 -0500
commitc0d0a04b8f8a3812cbfdaa90be3b9866dc739b2c (patch)
treedab87dd274c36d0d832ebc87ae6dfa892658dee9 /Source/Core/VideoCommon/ShaderGenCommon.cpp
parent19e8569634aa1423ec97425f1e16682b49b40ef8 (diff)
parentad6e95afb45c090a037135451a98ee5b66d5a8c2 (diff)
Merge pull request #11603 from Dentomologist/fix_d3d_nan_regression
D3D: Restore workaround for erroneous NaN optimization
Diffstat (limited to 'Source/Core/VideoCommon/ShaderGenCommon.cpp')
-rw-r--r--Source/Core/VideoCommon/ShaderGenCommon.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Source/Core/VideoCommon/ShaderGenCommon.cpp b/Source/Core/VideoCommon/ShaderGenCommon.cpp
index 44037d01dc..234703d7d5 100644
--- a/Source/Core/VideoCommon/ShaderGenCommon.cpp
+++ b/Source/Core/VideoCommon/ShaderGenCommon.cpp
@@ -100,7 +100,20 @@ std::string GetDiskShaderCacheFileName(APIType api_type, const char* type, bool
void WriteIsNanHeader(ShaderCode& out, APIType api_type)
{
- out.Write("#define dolphin_isnan(f) isnan(f)\n");
+ if (api_type == APIType::D3D)
+ {
+ out.Write("bool dolphin_isnan(float f) {{\n"
+ " // Workaround for the HLSL compiler deciding that isnan can never be true and\n"
+ " // optimising away the call, even though the value can actually be NaN\n"
+ " // Just look for the bit pattern that indicates NaN instead\n"
+ " return (floatBitsToInt(f) & 0x7FFFFFFF) > 0x7F800000;\n"
+ "}}\n\n");
+ // If isfinite is needed, (floatBitsToInt(f) & 0x7F800000) != 0x7F800000 can be used
+ }
+ else
+ {
+ out.Write("#define dolphin_isnan(f) isnan(f)\n");
+ }
}
void WriteBitfieldExtractHeader(ShaderCode& out, APIType api_type,