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
// 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 {

View File

@ -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;
}

View File

@ -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<ProfilerScope> scopes_;
int numQueries_ = 0;
bool firstFrame_ = true;
bool *enabledPtr_ = nullptr;
std::vector<size_t> scopeStack_;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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),
};

View File

@ -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.

View File

@ -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);

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.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")));