From 8850b52d883f2d3a1972c7693fb32a289d29056e Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 9 Apr 2020 19:48:36 +0100 Subject: [PATCH] prevent missing polygons with AMD GPU --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 11 +++++++++++ src/core/hle/D3D8/Direct3D9/VertexShader.cpp | 11 ++++++----- src/core/hle/D3D8/Direct3D9/VertexShader.h | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 6dd4915de..5d765c728 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -1662,6 +1662,17 @@ VOID EmuD3DInit() std::cout << "Host D3DCaps : " << g_D3DCaps << "\n"; std::cout << "----------------------------------------\n"; } + + // AMD compatibility workaround since VS model 3.0 doesn't work as intended with Direct3D9. + { + D3DADAPTER_IDENTIFIER9 adapter_info; + HRESULT status = g_pDirect3D->GetAdapterIdentifier(g_EmuCDPD.Adapter, 0, &adapter_info); + // 1002 and 1022 are vendor ids of AMD gpus + if (status == D3D_OK && (adapter_info.VendorId == 0x1002 || adapter_info.VendorId == 0x1022)) { + g_vs_model = vs_model_2_a; + EmuLog(LOG_LEVEL::WARNING, "AMD GPU Detected, falling back to shader model 2.X to prevent missing polygons"); + } + } } // cleanup Direct3D diff --git a/src/core/hle/D3D8/Direct3D9/VertexShader.cpp b/src/core/hle/D3D8/Direct3D9/VertexShader.cpp index 2a58e0a10..acbc31b72 100644 --- a/src/core/hle/D3D8/Direct3D9/VertexShader.cpp +++ b/src/core/hle/D3D8/Direct3D9/VertexShader.cpp @@ -6,6 +6,8 @@ #include +extern const char* g_vs_model = vs_model_3_0; + // HLSL generation void OutputHlsl(std::stringstream& hlsl, VSH_IMD_OUTPUT& dest) { @@ -247,9 +249,8 @@ extern HRESULT EmuCompileShader EmuLog(LOG_LEVEL::DEBUG, DebugPrependLineNumbers(hlsl_str).c_str()); EmuLog(LOG_LEVEL::DEBUG, "-----------------------"); - // Level 0 for fastest runtime compilation - // TODO Can we recompile an optimized shader in the background? - UINT flags1 = D3DCOMPILE_OPTIMIZATION_LEVEL0; + + UINT flags1 = D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE_AVOID_FLOW_CONTROL; hRet = D3DCompile( hlsl_str.c_str(), @@ -258,7 +259,7 @@ extern HRESULT EmuCompileShader nullptr, // pDefines nullptr, // pInclude // TODO precompile x_* HLSL functions? "main", // shader entry poiint - "vs_3_0", // shader profile + g_vs_model, // shader profile flags1, // flags1 0, // flags2 ppHostShader, // out @@ -275,7 +276,7 @@ extern HRESULT EmuCompileShader nullptr, // pDefines nullptr, // pInclude // TODO precompile x_* HLSL functions? "main", // shader entry poiint - "vs_3_0", // shader profile + g_vs_model, // shader profile flags1, // flags1 0, // flags2 ppHostShader, // out diff --git a/src/core/hle/D3D8/Direct3D9/VertexShader.h b/src/core/hle/D3D8/Direct3D9/VertexShader.h index 153f7636d..3e02ff0b5 100644 --- a/src/core/hle/D3D8/Direct3D9/VertexShader.h +++ b/src/core/hle/D3D8/Direct3D9/VertexShader.h @@ -10,6 +10,10 @@ enum class ShaderType { Unsupported, }; +static const char* vs_model_2_a = "vs_2_a"; +static const char* vs_model_3_0 = "vs_3_0"; +extern const char* g_vs_model; + extern ShaderType EmuGetShaderInfo(IntermediateVertexShader* pIntermediateShader); extern HRESULT EmuCompileShader