diff --git a/Common/GPU/Vulkan/VulkanContext.h b/Common/GPU/Vulkan/VulkanContext.h index d0edb2419a..5740dedfae 100644 --- a/Common/GPU/Vulkan/VulkanContext.h +++ b/Common/GPU/Vulkan/VulkanContext.h @@ -16,15 +16,8 @@ // other things as well. We also have a nice integrated render pass profiler in the queue // runner, but this one is more convenient for transient events. -// #define VULKAN_PROFILER_ENABLED - -#if defined(VULKAN_PROFILER_ENABLED) #define VK_PROFILE_BEGIN(vulkan, cmd, stage, ...) vulkan->GetProfiler()->Begin(cmd, stage, __VA_ARGS__); #define VK_PROFILE_END(vulkan, cmd, stage) vulkan->GetProfiler()->End(cmd, stage); -#else -#define VK_PROFILE_BEGIN(vulkan, cmd, stage, ...) -#define VK_PROFILE_END(vulkan, cmd, stage) -#endif enum { VULKAN_FLAG_VALIDATE = 1, @@ -321,6 +314,12 @@ public: return swapchainFormat_; } + void SetProfilerEnabledPtr(bool *enabled) { + for (auto &frame : frame_) { + frame.profiler.SetEnabledPtr(enabled); + } + } + // 1 for no frame overlap and thus minimal latency but worst performance. // 2 is an OK compromise, while 3 performs best but risks slightly higher latency. enum { diff --git a/Common/GPU/Vulkan/VulkanProfiler.cpp b/Common/GPU/Vulkan/VulkanProfiler.cpp index 47d78b1907..39914a1928 100644 --- a/Common/GPU/Vulkan/VulkanProfiler.cpp +++ b/Common/GPU/Vulkan/VulkanProfiler.cpp @@ -60,12 +60,14 @@ void VulkanProfiler::BeginFrame(VulkanContext *vulkan, VkCommandBuffer firstComm numQueries_ = MAX_QUERY_COUNT; firstFrame_ = false; } - vkCmdResetQueryPool(firstCommandBuf, queryPool_, 0, numQueries_); + if (numQueries_ > 0) { + vkCmdResetQueryPool(firstCommandBuf, queryPool_, 0, numQueries_); + } numQueries_ = 0; } void VulkanProfiler::Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stageFlags, const char *fmt, ...) { - if (numQueries_ >= MAX_QUERY_COUNT - 1) { + if ((enabledPtr_ && !*enabledPtr_) || numQueries_ >= MAX_QUERY_COUNT - 1) { return; } @@ -89,7 +91,7 @@ void VulkanProfiler::Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage } void VulkanProfiler::End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stageFlags) { - if (numQueries_ >= MAX_QUERY_COUNT - 1) { + if ((enabledPtr_ && !*enabledPtr_) || numQueries_ >= MAX_QUERY_COUNT - 1) { return; } diff --git a/Common/GPU/Vulkan/VulkanProfiler.h b/Common/GPU/Vulkan/VulkanProfiler.h index bf0f41167e..bf653a47b3 100644 --- a/Common/GPU/Vulkan/VulkanProfiler.h +++ b/Common/GPU/Vulkan/VulkanProfiler.h @@ -37,6 +37,9 @@ public: ; void End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage); + void SetEnabledPtr(bool *enabledPtr) { + enabledPtr_ = enabledPtr; + } private: VulkanContext *vulkan_; @@ -44,6 +47,7 @@ private: std::vector scopes_; int numQueries_ = 0; bool firstFrame_ = true; + bool *enabledPtr_ = nullptr; std::vector scopeStack_; diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index d950a306d2..4fa5301ad2 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -516,7 +516,7 @@ void VulkanRenderManager::ThreadFunc() { VLOG("PULL: Quitting"); } -void VulkanRenderManager::BeginFrame(bool enableProfiling) { +void VulkanRenderManager::BeginFrame(bool enableProfiling, bool enableLogProfiler) { VLOG("BeginFrame"); VkDevice device = vulkan_->GetDevice(); @@ -584,11 +584,7 @@ void VulkanRenderManager::BeginFrame(bool enableProfiling) { WARN_LOG(G3D, "BeginFrame while !run_!"); } -#if defined(VULKAN_PROFILER_ENABLED) - vulkan_->BeginFrame(GetInitCmd()); -#else - vulkan_->BeginFrame(VK_NULL_HANDLE); -#endif + vulkan_->BeginFrame(enableLogProfiler ? GetInitCmd() : VK_NULL_HANDLE); insideFrame_ = true; renderStepOffset_ = 0; diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 924398f81f..2103b29ab1 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -187,7 +187,7 @@ public: void DrainCompileQueue(); // Makes sure that the GPU has caught up enough that we can start writing buffers of this frame again. - void BeginFrame(bool enableProfiling); + void BeginFrame(bool enableProfiling, bool enableLogProfiler); // Can run on a different thread! void Finish(); void Run(int frame); diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index 70cfde5a26..62669ec27d 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -906,7 +906,8 @@ VKContext::~VKContext() { } void VKContext::BeginFrame() { - renderManager_.BeginFrame(g_Config.bShowGpuProfile); + // TODO: Bad dependency on g_Config here! + renderManager_.BeginFrame(g_Config.bShowGpuProfile, g_Config.bGpuLogProfiler); FrameData &frame = frame_[vulkan_->GetCurFrame()]; push_ = frame.pushBuffer; diff --git a/Core/Config.cpp b/Core/Config.cpp index b8f7b7432e..cae5f22b5d 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -916,6 +916,7 @@ static ConfigSetting graphicsSettings[] = { ConfigSetting("RenderDuplicateFrames", &g_Config.bRenderDuplicateFrames, false, true, true), ConfigSetting("ShaderCache", &g_Config.bShaderCache, true, false, false), // Doesn't save. Ini-only. + ConfigSetting("GpuLogProfiler", &g_Config.bGpuLogProfiler, false, true, false), ConfigSetting(false), }; diff --git a/Core/Config.h b/Core/Config.h index f7e8c0170d..bed269cd63 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -495,6 +495,7 @@ public: // Volatile development settings bool bShowFrameProfiler; + bool bGpuLogProfiler; // Controls the Vulkan logging profiler (profiles textures uploads etc). // Various directories. Autoconfigured, not read from ini. Path currentDirectory; // The directory selected in the game browsing window. diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 55e78bada2..294cd9cb26 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -59,6 +59,9 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) CheckGPUFeatures(); VulkanContext *vulkan = (VulkanContext *)gfxCtx->GetAPIContext(); + + vulkan->SetProfilerEnabledPtr(&g_Config.bGpuLogProfiler); + shaderManagerVulkan_ = new ShaderManagerVulkan(draw); pipelineManager_ = new PipelineManagerVulkan(vulkan); framebufferManagerVulkan_ = new FramebufferManagerVulkan(draw); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 2ec06b3a1e..770e01b42b 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1774,6 +1774,9 @@ void DeveloperToolsScreen::CreateViews() { list->Add(new CheckBox(&g_Config.bShowOnScreenMessages, dev->T("Show on-screen messages"))); list->Add(new CheckBox(&g_Config.bEnableLogging, dev->T("Enable Logging")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLoggingChanged); + if (GetGPUBackend() == GPUBackend::VULKAN) { + list->Add(new CheckBox(&g_Config.bGpuLogProfiler, gr->T("GPU log profiler"))); + } list->Add(new CheckBox(&g_Config.bLogFrameDrops, dev->T("Log Dropped Frame Statistics"))); list->Add(new Choice(dev->T("Logging Channels")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLogConfig); list->Add(new ItemHeader(dev->T("Language")));