From 9cf53473b24d908500e011c3b5fe93af130b46eb Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 24 Aug 2017 14:58:51 +0100 Subject: [PATCH] Extract plugin locating logic out of AMD ISA and reuse for counters --- renderdoc/CMakeLists.txt | 2 + renderdoc/core/plugins.cpp | 87 ++++++++++++++++++++++ renderdoc/core/plugins.h | 25 +++++++ renderdoc/driver/ihv/amd/amd_counters.cpp | 9 ++- renderdoc/driver/ihv/amd/amd_isa.cpp | 70 ++--------------- renderdoc/driver/ihv/amd/amd_isa_win32.cpp | 5 +- renderdoc/renderdoc.vcxproj | 2 + renderdoc/renderdoc.vcxproj.filters | 6 ++ 8 files changed, 137 insertions(+), 69 deletions(-) create mode 100644 renderdoc/core/plugins.cpp create mode 100644 renderdoc/core/plugins.h diff --git a/renderdoc/CMakeLists.txt b/renderdoc/CMakeLists.txt index 637ccd66f..fbc00efde 100644 --- a/renderdoc/CMakeLists.txt +++ b/renderdoc/CMakeLists.txt @@ -85,6 +85,8 @@ set(sources core/replay_proxy.h core/android.cpp core/android.h + core/plugins.cpp + core/plugins.h core/resource_manager.cpp core/resource_manager.h core/socket_helpers.h diff --git a/renderdoc/core/plugins.cpp b/renderdoc/core/plugins.cpp new file mode 100644 index 000000000..65cf7d642 --- /dev/null +++ b/renderdoc/core/plugins.cpp @@ -0,0 +1,87 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2017 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "core/plugins.h" +#include "serialise/string_utils.h" + +std::string LocatePluginFile(const std::string &path, const std::string &fileName) +{ + std::string ret; + + std::string exepath; + FileIO::GetExecutableFilename(exepath); + exepath = dirname(exepath); + + std::vector paths; + +#if defined(RENDERDOC_PLUGINS_PATH) + string customPath(RENDERDOC_PLUGINS_PATH); + + if(FileIO::IsRelativePath(customPath)) + customPath = exepath + "/" + customPath; + + paths.push_back(customPath); +#endif + + // windows installation + paths.push_back(exepath + "/plugins"); + // linux installation + paths.push_back(exepath + "/../share/renderdoc/plugins"); +// also search the appropriate OS-specific location in the root +#if ENABLED(RDOC_WIN32) && ENABLED(RDOC_X64) + paths.push_back(exepath + "/../../plugins-win64"); +#endif + +#if ENABLED(RDOC_WIN32) && DISABLED(RDOC_X64) + paths.push_back(exepath + "/../../plugins-win32"); +#endif + +#if ENABLED(RDOC_LINUX) + paths.push_back(exepath + "/../../plugins-linux64"); +#endif + + // there is no standard path for local builds as we don't provide these plugins in the repository + // directly. As a courtesy we search the root of the build, from the executable. The user can + // always put the plugins folder relative to the exe where it would be in an installation too. + paths.push_back(exepath + "/../../plugins"); + + // in future maybe we want to search a user-specific plugins folder? Like ~/.renderdoc/ on linux + // or %APPDATA%/renderdoc on windows? + + for(uint32_t i = 0; i < paths.size(); i++) + { + std::string check = paths[i] + "/" + path + "/" + fileName; + if(FileIO::exists(check.c_str())) + { + ret = check; + break; + } + } + + // if we didn't find it anywhere, just try running it directly in case it's in the PATH + if(ret.empty()) + ret = fileName; + + return ret; +} \ No newline at end of file diff --git a/renderdoc/core/plugins.h b/renderdoc/core/plugins.h new file mode 100644 index 000000000..25e1b0e91 --- /dev/null +++ b/renderdoc/core/plugins.h @@ -0,0 +1,25 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2017 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +std::string LocatePluginFile(const std::string &path, const std::string &fileName); \ No newline at end of file diff --git a/renderdoc/driver/ihv/amd/amd_counters.cpp b/renderdoc/driver/ihv/amd/amd_counters.cpp index 3c0a2ecbe..2b437ddac 100644 --- a/renderdoc/driver/ihv/amd/amd_counters.cpp +++ b/renderdoc/driver/ihv/amd/amd_counters.cpp @@ -25,6 +25,7 @@ #include "amd_counters.h" #include #include "common/common.h" +#include "core/plugins.h" #include "official/GPUPerfAPI/Include/GPUPerfAPI.h" #include "official/GPUPerfAPI/Include/GPUPerfAPIFunctionTypes.h" @@ -107,13 +108,15 @@ AMDCounters::AMDCounters() : m_pGPUPerfAPI(NULL) bool AMDCounters::Init(void *pContext) { - // first try in the location it will be in distributed builds - HMODULE module = LoadLibraryA("plugins/amd/counters/GPUPerfAPIDX11-x64.dll"); + const char *dllName = "GPUPerfAPIDX11-x64.dll"; + + // first try in the plugin location it will be in distributed builds + HMODULE module = LoadLibraryA(LocatePluginFile("amd/counters", dllName).c_str()); // if that failed then try checking for it just in the default search path if(module == NULL) { - module = LoadLibraryA("GPUPerfAPIDX11-x64.dll"); + module = LoadLibraryA(dllName); } if(module == NULL) diff --git a/renderdoc/driver/ihv/amd/amd_isa.cpp b/renderdoc/driver/ihv/amd/amd_isa.cpp index 1c490dff1..17fc33a4e 100644 --- a/renderdoc/driver/ihv/amd/amd_isa.cpp +++ b/renderdoc/driver/ihv/amd/amd_isa.cpp @@ -24,6 +24,7 @@ #include "amd_isa.h" #include "common/common.h" +#include "core/plugins.h" #include "driver/shaders/spirv/spirv_common.h" #include "serialise/string_utils.h" #include "amd_isa_devices.h" @@ -38,72 +39,13 @@ static const std::string amdspv_name = "amdspv.sh"; static const std::string virtualcontext_name = "VirtualContext"; #endif -std::string LocatePlugin(const std::string &fileName) -{ - std::string ret; - - std::string exepath; - FileIO::GetExecutableFilename(exepath); - exepath = dirname(exepath); - - std::vector paths; - -#if defined(RENDERDOC_PLUGINS_PATH) - string customPath(RENDERDOC_PLUGINS_PATH); - - if(FileIO::IsRelativePath(customPath)) - customPath = exepath + "/" + customPath; - - paths.push_back(customPath); -#endif - - // windows installation - paths.push_back(exepath + "/plugins"); - // linux installation - paths.push_back(exepath + "/../share/renderdoc/plugins"); -// also search the appropriate OS-specific location in the root -#if ENABLED(RDOC_WIN32) && ENABLED(RDOC_X64) - paths.push_back(exepath + "/../../plugins-win64"); -#endif - -#if ENABLED(RDOC_WIN32) && DISABLED(RDOC_X64) - paths.push_back(exepath + "/../../plugins-win32"); -#endif - -#if ENABLED(RDOC_LINUX) - paths.push_back(exepath + "/../../plugins-linux64"); -#endif - - // there is no standard path for local builds as we don't provide these plugins in the repository - // directly. As a courtesy we search the root of the build, from the executable. The user can - // always put the plugins folder relative to the exe where it would be in an installation too. - paths.push_back(exepath + "/../../plugins"); - - // in future maybe we want to search a user-specific plugins folder? Like ~/.renderdoc/ on linux - // or %APPDATA%/renderdoc on windows? - - for(uint32_t i = 0; i < paths.size(); i++) - { - std::string check = paths[i] + "/amd/isa/" + fileName; - if(FileIO::exists(check.c_str())) - { - ret = check; - break; - } - } - - // if we didn't find it anywhere, just try running it directly in case it's in the PATH - if(ret.empty()) - ret = fileName; - - return ret; -} +std::string pluginPath = "amd/isa"; static bool IsSupported(GraphicsAPI api) { if(api == GraphicsAPI::OpenGL) { - std::string vc = LocatePlugin(virtualcontext_name); + std::string vc = LocatePluginFile(pluginPath, virtualcontext_name); Process::ProcessResult result = {}; Process::LaunchProcess(vc.c_str(), dirname(vc).c_str(), "", &result); @@ -118,7 +60,7 @@ static bool IsSupported(GraphicsAPI api) if(api == GraphicsAPI::Vulkan) { // TODO need to check if an AMD context is running - std::string amdspv = LocatePlugin(amdspv_name); + std::string amdspv = LocatePluginFile(pluginPath, amdspv_name); Process::ProcessResult result = {}; Process::LaunchProcess(amdspv.c_str(), dirname(amdspv).c_str(), "", &result); @@ -232,7 +174,7 @@ std::string Disassemble(const SPVModule *spv, const std::string &entry, const st FileIO::dump(inPath.c_str(), spv->spirv.data(), spv->spirv.size() * sizeof(uint32_t)); // try to locate the amdspv relative to our running program - std::string amdspv = LocatePlugin(amdspv_name); + std::string amdspv = LocatePluginFile(pluginPath, amdspv_name); Process::ProcessResult result = {}; Process::LaunchProcess(amdspv.c_str(), dirname(amdspv).c_str(), cmdLine.c_str(), &result); @@ -395,7 +337,7 @@ std::string Disassemble(ShaderStage stage, const std::vector &glsl, FileIO::dump(inPath.c_str(), source.data(), source.size()); // try to locate the amdspv relative to our running program - std::string vc = LocatePlugin(virtualcontext_name); + std::string vc = LocatePluginFile(pluginPath, virtualcontext_name); Process::ProcessResult result = {}; Process::LaunchProcess(vc.c_str(), dirname(vc).c_str(), cmdLine.c_str(), &result); diff --git a/renderdoc/driver/ihv/amd/amd_isa_win32.cpp b/renderdoc/driver/ihv/amd/amd_isa_win32.cpp index 4acf72ded..e10a1b2e2 100644 --- a/renderdoc/driver/ihv/amd/amd_isa_win32.cpp +++ b/renderdoc/driver/ihv/amd/amd_isa_win32.cpp @@ -23,6 +23,7 @@ ******************************************************************************/ #include "amd_isa.h" +#include "core/plugins.h" #include "driver/shaders/dxbc/dxbc_inspect.h" #include "official/RGA/Common/AmdDxGsaCompile.h" #include "official/RGA/elf/elf32.h" @@ -44,13 +45,13 @@ https://github.com/baldurk/renderdoc/wiki/GCN-ISA)"; namespace GCNISA { -std::string LocatePlugin(const std::string &fileName); +extern std::string pluginPath; }; static HMODULE GetAMDModule() { // first try in the plugin locations - HMODULE module = LoadLibraryA(GCNISA::LocatePlugin(DLL_NAME).c_str()); + HMODULE module = LoadLibraryA(LocatePluginFile(GCNISA::pluginPath, DLL_NAME).c_str()); // if that failed then try checking for it just in the default search path if(module == NULL) diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index fa492e684..538b1f5e8 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -138,6 +138,7 @@ + @@ -212,6 +213,7 @@ + Create diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index a45650a47..3453758c8 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -282,6 +282,9 @@ Core + + Core + @@ -471,6 +474,9 @@ PCH + + Core +