diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 314744735..77b25cbf7 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -751,6 +751,13 @@ void RenderDoc::Initialise() if(IsReplayApp()) RDCLOGOUTPUT(); + if(IsReplayApp()) + { + for(auto it = m_EnvSetups.begin(); it != m_EnvSetups.end(); ++it) + (*it)(); + m_EnvSetups.clear(); + } + ProcessConfig(); } diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index e51ba7996..57b44a429 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -401,6 +401,7 @@ typedef bool (*VulkanLayerCheck)(VulkanLayerFlags &flags, rdcarray &myJS typedef void (*VulkanLayerInstall)(bool systemLevel); typedef void (*ShutdownFunction)(); +typedef void (*EnvSetupFunction)(); // this class mediates everything and owns any 'global' resources such as the crash handler. // @@ -536,6 +537,8 @@ public: rdcarray GetCaptureFileFormats(); rdcarray GetAvailableGPUs(); + void AddEnvSetup(EnvSetupFunction envSetup) { m_EnvSetups.push_back(envSetup); } + void SetVulkanLayerCheck(VulkanLayerCheck callback) { m_VulkanCheck = callback; } void SetVulkanLayerInstall(VulkanLayerInstall callback) { m_VulkanInstall = callback; } bool NeedVulkanLayerRegistration(VulkanLayerFlags &flags, rdcarray &myJSONs, @@ -736,6 +739,7 @@ private: VulkanLayerInstall m_VulkanInstall; rdcarray m_ShutdownFunctions; + rdcarray m_EnvSetups; struct FrameCap { diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index 66290e818..986c52cdc 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -5640,10 +5640,8 @@ void VulkanReplay::SetProxyBufferData(ResourceId bufid, byte *data, size_t dataS VULKANNOTIMP("SetProxyTextureData"); } -RDResult Vulkan_CreateReplayDevice(RDCFile *rdc, const ReplayOptions &opts, IReplayDriver **driver) +void VulkanEnvSetup() { - RDCDEBUG("Creating a VulkanReplay replay device"); - // disable the layer env var, just in case the user left it set from a previous capture run Process::RegisterEnvironmentModification( EnvironmentModification(EnvMod::Set, EnvSep::NoSep, RENDERDOC_VULKAN_LAYER_VAR, "0")); @@ -5706,6 +5704,11 @@ RDResult Vulkan_CreateReplayDevice(RDCFile *rdc, const ReplayOptions &opts, IRep EnvironmentModification(EnvMod::Set, EnvSep::NoSep, "DISABLE_LAYER", "1")); Process::ApplyEnvironmentModification(); +} + +RDResult Vulkan_CreateReplayDevice(RDCFile *rdc, const ReplayOptions &opts, IReplayDriver **driver) +{ + RDCDEBUG("Creating a VulkanReplay replay device"); void *module = LoadVulkanLibrary(); @@ -5803,6 +5806,7 @@ struct VulkanDriverRegistration VulkanDriverRegistration() { RenderDoc::Inst().RegisterReplayProvider(RDCDriver::Vulkan, &Vulkan_CreateReplayDevice); + RenderDoc::Inst().AddEnvSetup(&VulkanEnvSetup); RenderDoc::Inst().SetVulkanLayerCheck(&VulkanReplay::CheckVulkanLayer); RenderDoc::Inst().SetVulkanLayerInstall(&VulkanReplay::InstallVulkanLayer); } diff --git a/renderdoc/os/posix/posix_process.cpp b/renderdoc/os/posix/posix_process.cpp index 1438a0bef..d82610c6a 100644 --- a/renderdoc/os/posix/posix_process.cpp +++ b/renderdoc/os/posix/posix_process.cpp @@ -409,9 +409,26 @@ void ApplySingleEnvMod(EnvironmentModification &m, rdcstr &value) void ApplyEnvironmentModifications(rdcarray &modifications) { - // turn environment string to a UTF-8 map - char **currentEnvironment = GetCurrentEnvironment(); - std::map currentEnv = EnvStringToEnvMap(currentEnvironment); + bool needOldEnv = false; + + for(const EnvironmentModification &env : modifications) + { + if(env.mod != EnvMod::Set) + { + needOldEnv = true; + break; + } + } + + std::map currentEnv; + + // turn environment string to a UTF-8 map, but only if we actually need to. Environment variables + // are garbage 70s tier tech and so are not thread safe, minimise interaction with them as much as possible + if(needOldEnv) + { + char **currentEnvironment = GetCurrentEnvironment(); + currentEnv = EnvStringToEnvMap(currentEnvironment); + } for(size_t i = 0; i < modifications.size(); i++) {