From 52c82733f6ba606de5d877c25b95828b73e668bd Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 7 Sep 2021 17:27:18 -0700 Subject: Use custom isnan implementation to avoid HLSL optimizer issues This adjusts the NaN replacement logic introduced in #9928 to work around the HLSL compiler optimizing away calls to isnan, which caused that functionality to not work with ubershaders on D3D11 and D3D12 (it did work with specialized shaders, despite a warning being logged for both; that warning is also now gone). Note that the `D3DCOMPILE_IEEE_STRICTNESS` flag did not solve this issue, despite the warning suggesting that it might. Suggested by @kayru and @jamiehayes. --- Source/Core/VideoCommon/ShaderGenCommon.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Source/Core/VideoCommon/ShaderGenCommon.cpp') diff --git a/Source/Core/VideoCommon/ShaderGenCommon.cpp b/Source/Core/VideoCommon/ShaderGenCommon.cpp index 53cf3edf61..c5cd3ef30d 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.cpp +++ b/Source/Core/VideoCommon/ShaderGenCommon.cpp @@ -87,6 +87,24 @@ std::string GetDiskShaderCacheFileName(APIType api_type, const char* type, bool return filename; } +void WriteIsNanHeader(ShaderCode& out, APIType api_type) +{ + 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 (asint(f) & 0x7FFFFFFF) > 0x7F800000;\n" + "}}\n\n"); + // If isfinite is needed, (asint(f) & 0x7F800000) != 0x7F800000 can be used + } + else + { + out.Write("#define dolphin_isnan(f) isnan(f)\n"); + } +} + static void DefineOutputMember(ShaderCode& object, APIType api_type, std::string_view qualifier, std::string_view type, std::string_view name, int var_index, std::string_view semantic = {}, int semantic_index = -1) -- cgit v1.2.3