From 3889ecb552cff2793b20a61f15f689059008ce0f Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 4 Dec 2018 18:40:07 +0000 Subject: [PATCH] Use WNetGetUniversalName to convert paths to UNC in vulkan registration * If we use a mounted network drive as the JSON path but then elevate to register, the elevated run will not get the mounted drive but the full UNC path. This will cause renderdoc to constantly think it needs to re-register. * Converting to UNC first gives us a baseline comparison. --- renderdoc/driver/vulkan/vk_win32.cpp | 43 ++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_win32.cpp b/renderdoc/driver/vulkan/vk_win32.cpp index 4a5a16076..712290fdb 100644 --- a/renderdoc/driver/vulkan/vk_win32.cpp +++ b/renderdoc/driver/vulkan/vk_win32.cpp @@ -26,6 +26,8 @@ #include "vk_core.h" #include "vk_replay.h" +#include + static int dllLocator = 0; void VulkanReplay::OutputWindow::SetWindowHandle(WindowingData window) @@ -168,12 +170,47 @@ std::wstring GetJSONPath(bool wow6432) FileIO::GetLibraryFilename(libPath); std::string jsonPath = dirname(FileIO::GetFullPathname(libPath)); + std::wstring jsonWide = StringFormat::UTF82Wide(jsonPath); + + if(jsonWide[1] == L':' && PathIsNetworkPathW(jsonWide.c_str())) + { + using PFN_WNetGetUniversalNameW = decltype(&WNetGetUniversalNameW); + + HMODULE mpr = LoadLibraryA("mpr.dll"); + if(mpr) + { + PFN_WNetGetUniversalNameW getUniversal = + (PFN_WNetGetUniversalNameW)GetProcAddress(mpr, "WNetGetUniversalNameW"); + + DWORD bufSize = 2048; + byte *buf = new byte[bufSize]; + memset(buf, 0, bufSize); + DWORD result = getUniversal(jsonWide.c_str(), UNIVERSAL_NAME_INFO_LEVEL, buf, &bufSize); + if(result == NO_ERROR) + { + UNIVERSAL_NAME_INFOW *nameInfo = (UNIVERSAL_NAME_INFOW *)buf; + RDCLOG("Converted %ls network path to %ls", jsonWide.c_str(), nameInfo->lpUniversalName); + jsonWide = nameInfo->lpUniversalName; + } + else + { + RDCERR("Error calling WNetGetUniversalNameW: %d", result); + } + + delete[] buf; + } + else + { + RDCERR("Can't load mpr.dll for WNetGetUniversalNameW"); + } + } + if(wow6432) - jsonPath += "\\x86"; + jsonWide += L"\\x86"; - jsonPath += "\\renderdoc.json"; + jsonWide += L"\\renderdoc.json"; - return StringFormat::UTF82Wide(jsonPath); + return jsonWide; } static HKEY GetImplicitLayersKey(bool writeable, bool wow6432)