diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index 2cb0e228af..cb2a698f24 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -293,12 +293,14 @@ void VulkanContext::BeginFrame(VkCommandBuffer firstCommandBuffer) { FrameData *frame = &frame_[curFrame_]; // Process pending deletes. frame->deleteList.PerformDeletes(device_, allocator_); - frame->profiler.BeginFrame(this, firstCommandBuffer); + // VK_NULL_HANDLE when profiler is disabled. + if (firstCommandBuffer) { + frame->profiler.BeginFrame(this, firstCommandBuffer); + } } void VulkanContext::EndFrame() { frame_[curFrame_].deleteList.Take(globalDeleteList_); - frame_[curFrame_].profiler.EndFrame(); curFrame_++; if (curFrame_ >= inflightFrames_) { curFrame_ = 0; @@ -678,7 +680,7 @@ VkResult VulkanContext::CreateDevice() { allocatorInfo.instance = instance_; vmaCreateAllocator(&allocatorInfo, &allocator_); - for (int i = 0; i < GetInflightFrames(); i++) { + for (int i = 0; i < ARRAY_SIZE(frame_); i++) { frame_[i].profiler.Init(this); } @@ -1129,7 +1131,7 @@ void VulkanContext::DestroyDevice() { INFO_LOG(G3D, "VulkanContext::DestroyDevice (performing deletes)"); PerformPendingDeletes(); - for (int i = 0; i < GetInflightFrames(); i++) { + for (int i = 0; i < ARRAY_SIZE(frame_); i++) { frame_[i].profiler.Shutdown(); } diff --git a/Common/GPU/Vulkan/VulkanContext.h b/Common/GPU/Vulkan/VulkanContext.h index 7528cb6734..0ff86c2301 100644 --- a/Common/GPU/Vulkan/VulkanContext.h +++ b/Common/GPU/Vulkan/VulkanContext.h @@ -11,14 +11,18 @@ #include "Common/GPU/Vulkan/VulkanAlloc.h" #include "Common/GPU/Vulkan/VulkanProfiler.h" -#define VULKAN_PROFILE_ENABLED +// Enable or disable a simple logging profiler for Vulkan. +// Mostly useful for profiling texture uploads currently, but could be useful for +// 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_PROFILE_ENABLED) +#if defined(VULKAN_PROFILER_ENABLED) #define VK_PROFILE_BEGIN(vulkan, cmd, stage, message) vulkan->GetProfiler()->Begin(cmd, stage, message); #define VK_PROFILE_END(vulkan, cmd, stage) vulkan->GetProfiler()->End(cmd, stage); #else -#define VK_PROFILE_BEGIN(..) -#define VK_PROFILE_END(..) +#define VK_PROFILE_BEGIN(vulkan, cmd, stage, message) +#define VK_PROFILE_END(vulkan, cmd, stage) #endif enum { diff --git a/Common/GPU/Vulkan/VulkanProfiler.cpp b/Common/GPU/Vulkan/VulkanProfiler.cpp index 69f1ee8ee4..9bd16edab4 100644 --- a/Common/GPU/Vulkan/VulkanProfiler.cpp +++ b/Common/GPU/Vulkan/VulkanProfiler.cpp @@ -6,18 +6,14 @@ using namespace PPSSPP_VK; void VulkanProfiler::Init(VulkanContext *vulkan) { vulkan_ = vulkan; - for (int i = 0; i < vulkan->GetInflightFrames(); i++) { - VkQueryPoolCreateInfo ci{ VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO }; - ci.queryCount = MAX_QUERY_COUNT; - ci.queryType = VK_QUERY_TYPE_TIMESTAMP; - vkCreateQueryPool(vulkan->GetDevice(), &ci, nullptr, &queryPool_); - } + VkQueryPoolCreateInfo ci{ VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO }; + ci.queryCount = MAX_QUERY_COUNT; + ci.queryType = VK_QUERY_TYPE_TIMESTAMP; + vkCreateQueryPool(vulkan->GetDevice(), &ci, nullptr, &queryPool_); } void VulkanProfiler::Shutdown() { - for (int i = 0; i < vulkan_->GetInflightFrames(); i++) { - vkDestroyQueryPool(vulkan_->GetDevice(), queryPool_, nullptr); - } + vkDestroyQueryPool(vulkan_->GetDevice(), queryPool_, nullptr); } void VulkanProfiler::BeginFrame(VulkanContext *vulkan, VkCommandBuffer firstCommandBuf) { @@ -61,10 +57,6 @@ void VulkanProfiler::BeginFrame(VulkanContext *vulkan, VkCommandBuffer firstComm numQueries_ = 0; } -void VulkanProfiler::EndFrame() { - // Not much to do here really except check that all scopes are closed. -} - void VulkanProfiler::Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stageFlags, std::string scopeName) { if (numQueries_ >= MAX_QUERY_COUNT - 1) { return; diff --git a/Common/GPU/Vulkan/VulkanProfiler.h b/Common/GPU/Vulkan/VulkanProfiler.h index d38fb79931..e5189da53c 100644 --- a/Common/GPU/Vulkan/VulkanProfiler.h +++ b/Common/GPU/Vulkan/VulkanProfiler.h @@ -30,8 +30,6 @@ public: void BeginFrame(VulkanContext *vulkan, VkCommandBuffer firstCommandBuffer); - void EndFrame(); - void Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage, std::string scopeName); void End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage); diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index b7890d2638..d278f258f7 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -584,7 +584,7 @@ void VulkanRenderManager::BeginFrame(bool enableProfiling) { WARN_LOG(G3D, "BeginFrame while !run_!"); } -#if defined(VULKAN_PROFILE_ENABLED) +#if defined(VULKAN_PROFILER_ENABLED) vulkan_->BeginFrame(GetInitCmd()); #else vulkan_->BeginFrame(VK_NULL_HANDLE); diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index f0f72b4446..186df3c5ac 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -786,7 +786,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { } if (entry->vkTex) { - vulkan->GetProfiler()->Begin(cmdInit, VkPipelineStageFlagBits(VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT), + VK_PROFILE_BEGIN(vulkan, cmdInit, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, StringFromFormat("Texture Upload")); // NOTE: Since the level is not part of the cache key, we assume it never changes. @@ -872,7 +872,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { // Generate any additional mipmap levels. // This will transition the whole stack to GENERAL if it wasn't already. if (maxLevel != maxLevelToGenerate) { - VK_PROFILE_BEGIN(vulkan, cmdInit, VK_PIPELINE_STAGE_TRANSFER_BIT, StringFromFormat("Mipgen %d", maxLevel + 1)); + VK_PROFILE_BEGIN(vulkan, cmdInit, VK_PIPELINE_STAGE_TRANSFER_BIT, StringFromFormat("Mipgen up to level %d", maxLevelToGenerate)); entry->vkTex->GenerateMips(cmdInit, maxLevel + 1, computeUpload); layout = VK_IMAGE_LAYOUT_GENERAL; prevStage = VK_PIPELINE_STAGE_TRANSFER_BIT; @@ -888,7 +888,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { entry->SetAlphaStatus(TexCacheEntry::TexStatus(replaced.AlphaStatus())); } entry->vkTex->EndCreate(cmdInit, false, prevStage, layout); - VK_PROFILE_END(vulkan, cmdInit, VkPipelineStageFlagBits(VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT)); + VK_PROFILE_END(vulkan, cmdInit, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT); } }