From cb6240e2718ed865492468f5c09755968efe092c Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 18 Mar 2020 17:14:20 +0000 Subject: [PATCH] On replay prefer loading the d3dcompiler we ship * On windows 7, d3dcompiler_47.dll is too old to support SM5.1 shaders. --- .../driver/shaders/dxbc/dxbc_compile.cpp | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp b/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp index 535ef6ae6..274e38f55 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp @@ -24,11 +24,19 @@ #include "dxbc_compile.h" #include "common/common.h" +#include "core/core.h" #include "os/os_specific.h" #include "strings/string_utils.h" -// gives us an address to identify this dll with -static int dllLocator = 0; +static HMODULE GetLocalD3DCompiler() +{ + rdcstr dllFile; + FileIO::GetLibraryFilename(dllFile); + + rdcstr dll = get_dirname(dllFile) + "/d3dcompiler_47.dll"; + + return LoadLibraryW(StringFormat::UTF82Wide(dll.c_str()).data()); +} HMODULE GetD3DCompiler() { @@ -36,7 +44,15 @@ HMODULE GetD3DCompiler() if(ret != NULL) return ret; - // dlls to try in priority order + // during replay, try to load our local one to get the newest possible. + if(RenderDoc::Inst().IsReplayApp()) + { + ret = GetLocalD3DCompiler(); + if(ret) + return ret; + } + + // now dlls to try in priority order const char *dlls[] = { "d3dcompiler_47.dll", "d3dcompiler_46.dll", "d3dcompiler_45.dll", "d3dcompiler_44.dll", "d3dcompiler_43.dll", @@ -46,6 +62,8 @@ HMODULE GetD3DCompiler() { for(int d = 0; d < ARRAY_COUNT(dlls); d++) { + // first time around, try to load one that already exists. Second time around try to load it + // in the default search path. if(i == 0) ret = GetModuleHandleA(dlls[d]); else @@ -56,15 +74,9 @@ HMODULE GetD3DCompiler() } } - // all else failed, couldn't find d3dcompiler loaded, - // and couldn't even loadlibrary any version! - // we'll have to loadlibrary the version that ships with - // RenderDoc. + // finally if we couldn't load a library anywhere from the system while capturing, load our local + // compiler. + ret = GetLocalD3DCompiler(); - rdcstr dllFile; - FileIO::GetLibraryFilename(dllFile); - - rdcstr dll = get_dirname(dllFile) + "/d3dcompiler_47.dll"; - - return LoadLibraryW(StringFormat::UTF82Wide(dll.c_str()).data()); + return ret; }