Make the Vulkan GPU log profiler a runtime developer setting.

I keep forgetting to disable the define on commit, this is a better
solution.
This commit is contained in:
Henrik Rydgård 2021-12-19 22:49:42 +01:00
parent 748b8287a6
commit df2f0df155
10 changed files with 28 additions and 18 deletions

View File

@ -16,15 +16,8 @@
// other things as well. We also have a nice integrated render pass profiler in the queue // 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. // 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_BEGIN(vulkan, cmd, stage, ...) vulkan->GetProfiler()->Begin(cmd, stage, __VA_ARGS__);
#define VK_PROFILE_END(vulkan, cmd, stage) vulkan->GetProfiler()->End(cmd, stage); #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 { enum {
VULKAN_FLAG_VALIDATE = 1, VULKAN_FLAG_VALIDATE = 1,
@ -321,6 +314,12 @@ public:
return swapchainFormat_; 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. // 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. // 2 is an OK compromise, while 3 performs best but risks slightly higher latency.
enum { enum {

View File

@ -60,12 +60,14 @@ void VulkanProfiler::BeginFrame(VulkanContext *vulkan, VkCommandBuffer firstComm
numQueries_ = MAX_QUERY_COUNT; numQueries_ = MAX_QUERY_COUNT;
firstFrame_ = false; firstFrame_ = false;
} }
vkCmdResetQueryPool(firstCommandBuf, queryPool_, 0, numQueries_); if (numQueries_ > 0) {
vkCmdResetQueryPool(firstCommandBuf, queryPool_, 0, numQueries_);
}
numQueries_ = 0; numQueries_ = 0;
} }
void VulkanProfiler::Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stageFlags, const char *fmt, ...) { 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; return;
} }
@ -89,7 +91,7 @@ void VulkanProfiler::Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage
} }
void VulkanProfiler::End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stageFlags) { void VulkanProfiler::End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stageFlags) {
if (numQueries_ >= MAX_QUERY_COUNT - 1) { if ((enabledPtr_ && !*enabledPtr_) || numQueries_ >= MAX_QUERY_COUNT - 1) {
return; return;
} }

View File

@ -37,6 +37,9 @@ public:
; ;
void End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage); void End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage);
void SetEnabledPtr(bool *enabledPtr) {
enabledPtr_ = enabledPtr;
}
private: private:
VulkanContext *vulkan_; VulkanContext *vulkan_;
@ -44,6 +47,7 @@ private:
std::vector<ProfilerScope> scopes_; std::vector<ProfilerScope> scopes_;
int numQueries_ = 0; int numQueries_ = 0;
bool firstFrame_ = true; bool firstFrame_ = true;
bool *enabledPtr_ = nullptr;
std::vector<size_t> scopeStack_; std::vector<size_t> scopeStack_;

View File

@ -516,7 +516,7 @@ void VulkanRenderManager::ThreadFunc() {
VLOG("PULL: Quitting"); VLOG("PULL: Quitting");
} }
void VulkanRenderManager::BeginFrame(bool enableProfiling) { void VulkanRenderManager::BeginFrame(bool enableProfiling, bool enableLogProfiler) {
VLOG("BeginFrame"); VLOG("BeginFrame");
VkDevice device = vulkan_->GetDevice(); VkDevice device = vulkan_->GetDevice();
@ -584,11 +584,7 @@ void VulkanRenderManager::BeginFrame(bool enableProfiling) {
WARN_LOG(G3D, "BeginFrame while !run_!"); WARN_LOG(G3D, "BeginFrame while !run_!");
} }
#if defined(VULKAN_PROFILER_ENABLED) vulkan_->BeginFrame(enableLogProfiler ? GetInitCmd() : VK_NULL_HANDLE);
vulkan_->BeginFrame(GetInitCmd());
#else
vulkan_->BeginFrame(VK_NULL_HANDLE);
#endif
insideFrame_ = true; insideFrame_ = true;
renderStepOffset_ = 0; renderStepOffset_ = 0;

View File

@ -187,7 +187,7 @@ public:
void DrainCompileQueue(); void DrainCompileQueue();
// Makes sure that the GPU has caught up enough that we can start writing buffers of this frame again. // 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! // Can run on a different thread!
void Finish(); void Finish();
void Run(int frame); void Run(int frame);

View File

@ -906,7 +906,8 @@ VKContext::~VKContext() {
} }
void VKContext::BeginFrame() { 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()]; FrameData &frame = frame_[vulkan_->GetCurFrame()];
push_ = frame.pushBuffer; push_ = frame.pushBuffer;

View File

@ -916,6 +916,7 @@ static ConfigSetting graphicsSettings[] = {
ConfigSetting("RenderDuplicateFrames", &g_Config.bRenderDuplicateFrames, false, true, true), ConfigSetting("RenderDuplicateFrames", &g_Config.bRenderDuplicateFrames, false, true, true),
ConfigSetting("ShaderCache", &g_Config.bShaderCache, true, false, false), // Doesn't save. Ini-only. ConfigSetting("ShaderCache", &g_Config.bShaderCache, true, false, false), // Doesn't save. Ini-only.
ConfigSetting("GpuLogProfiler", &g_Config.bGpuLogProfiler, false, true, false),
ConfigSetting(false), ConfigSetting(false),
}; };

View File

@ -495,6 +495,7 @@ public:
// Volatile development settings // Volatile development settings
bool bShowFrameProfiler; bool bShowFrameProfiler;
bool bGpuLogProfiler; // Controls the Vulkan logging profiler (profiles textures uploads etc).
// Various directories. Autoconfigured, not read from ini. // Various directories. Autoconfigured, not read from ini.
Path currentDirectory; // The directory selected in the game browsing window. Path currentDirectory; // The directory selected in the game browsing window.

View File

@ -59,6 +59,9 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
CheckGPUFeatures(); CheckGPUFeatures();
VulkanContext *vulkan = (VulkanContext *)gfxCtx->GetAPIContext(); VulkanContext *vulkan = (VulkanContext *)gfxCtx->GetAPIContext();
vulkan->SetProfilerEnabledPtr(&g_Config.bGpuLogProfiler);
shaderManagerVulkan_ = new ShaderManagerVulkan(draw); shaderManagerVulkan_ = new ShaderManagerVulkan(draw);
pipelineManager_ = new PipelineManagerVulkan(vulkan); pipelineManager_ = new PipelineManagerVulkan(vulkan);
framebufferManagerVulkan_ = new FramebufferManagerVulkan(draw); framebufferManagerVulkan_ = new FramebufferManagerVulkan(draw);

View File

@ -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.bShowOnScreenMessages, dev->T("Show on-screen messages")));
list->Add(new CheckBox(&g_Config.bEnableLogging, dev->T("Enable Logging")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLoggingChanged); 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 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 Choice(dev->T("Logging Channels")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLogConfig);
list->Add(new ItemHeader(dev->T("Language"))); list->Add(new ItemHeader(dev->T("Language")));