Skip to content

Commit

Permalink
Merge pull request #18588 from hrydgard/vk-count-commands
Browse files Browse the repository at this point in the history
Vulkan render queue runner: Count commands in debug builds, like the GL backend.
  • Loading branch information
hrydgard committed Dec 20, 2023
2 parents a9553f4 + 28189dc commit f47b87a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Common/GPU/Vulkan/VulkanFrameData.h
Expand Up @@ -29,6 +29,9 @@ struct QueueProfileContext {
double cpuEndTime;
double descWriteTime;
int descriptorsWritten;
#ifdef _DEBUG
int commandCounts[11];
#endif
};

class VKRFramebuffer;
Expand Down
33 changes: 30 additions & 3 deletions Common/GPU/Vulkan/VulkanQueueRunner.cpp
Expand Up @@ -350,7 +350,6 @@ void VulkanQueueRunner::RunSteps(std::vector<VKRStep *> &steps, int curFrame, Fr

for (size_t i = 0; i < steps.size(); i++) {
const VKRStep &step = *steps[i];

if (emitLabels) {
VkDebugUtilsLabelEXT labelInfo{ VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT };
char temp[128];
Expand Down Expand Up @@ -394,7 +393,7 @@ void VulkanQueueRunner::RunSteps(std::vector<VKRStep *> &steps, int curFrame, Fr
vkCmdBeginDebugUtilsLabelEXT(cmd, &labelInfo);
}
}
PerformRenderPass(step, cmd, curFrame);
PerformRenderPass(step, cmd, curFrame, frameData.profile);
break;
case VKRStepType::COPY:
PerformCopy(step, cmd);
Expand Down Expand Up @@ -1101,7 +1100,7 @@ void TransitionFromOptimal(VkCommandBuffer cmd, VkImage colorImage, VkImageLayou
}
}

void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer cmd, int curFrame) {
void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer cmd, int curFrame, QueueProfileContext &profile) {
for (size_t i = 0; i < step.preTransitions.size(); i++) {
const TransitionRequest &iter = step.preTransitions[i];
if (iter.aspect == VK_IMAGE_ASPECT_COLOR_BIT && iter.fb->color.layout != iter.targetLayout) {
Expand Down Expand Up @@ -1210,6 +1209,13 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c

for (size_t i = 0; i < commands.size(); i++) {
const VkRenderData &c = commands[i];
#ifdef _DEBUG
if (profile.enabled) {
if ((size_t)step.stepType < ARRAY_SIZE(profile.commandCounts)) {
profile.commandCounts[(size_t)c.cmd]++;
}
}
#endif
switch (c.cmd) {
case VKRRenderCommand::REMOVED:
break;
Expand Down Expand Up @@ -2088,3 +2094,24 @@ bool VulkanQueueRunner::CopyReadbackBuffer(FrameData &frameData, VKRFramebuffer
vmaUnmapMemory(vulkan_->Allocator(), readback->allocation);
return true;
}

const char *VKRRenderCommandToString(VKRRenderCommand cmd) {
const char * const str[] = {
"REMOVED",
"BIND_GRAPHICS_PIPELINE", // async
"STENCIL",
"BLEND",
"VIEWPORT",
"SCISSOR",
"CLEAR",
"DRAW",
"DRAW_INDEXED",
"PUSH_CONSTANTS",
"DEBUG_ANNOTATION",
};
if ((int)cmd < ARRAY_SIZE(str)) {
return str[(int)cmd];
} else {
return "N/A";
}
}
4 changes: 3 additions & 1 deletion Common/GPU/Vulkan/VulkanQueueRunner.h
Expand Up @@ -280,7 +280,7 @@ class VulkanQueueRunner {
bool InitDepthStencilBuffer(VkCommandBuffer cmd); // Used for non-buffered rendering.

VKRRenderPass *PerformBindFramebufferAsRenderTarget(const VKRStep &pass, VkCommandBuffer cmd);
void PerformRenderPass(const VKRStep &pass, VkCommandBuffer cmd, int curFrame);
void PerformRenderPass(const VKRStep &pass, VkCommandBuffer cmd, int curFrame, QueueProfileContext &profile);
void PerformCopy(const VKRStep &pass, VkCommandBuffer cmd);
void PerformBlit(const VKRStep &pass, VkCommandBuffer cmd);
void PerformReadback(const VKRStep &pass, VkCommandBuffer cmd, FrameData &frameData);
Expand Down Expand Up @@ -346,3 +346,5 @@ class VulkanQueueRunner {
};
DepthBufferInfo depth_;
};

const char *VKRRenderCommandToString(VKRRenderCommand cmd);
11 changes: 11 additions & 0 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Expand Up @@ -723,6 +723,17 @@ void VulkanRenderManager::BeginFrame(bool enableProfiling, bool enableLogProfile
str << line;
frameData.profile.profileSummary = str.str();
}

#ifdef _DEBUG
std::string cmdString;
for (int i = 0; i < ARRAY_SIZE(frameData.profile.commandCounts); i++) {
if (frameData.profile.commandCounts[i] > 0) {
cmdString += StringFromFormat("%s: %d\n", VKRRenderCommandToString((VKRRenderCommand)i), frameData.profile.commandCounts[i]);
}
}
memset(frameData.profile.commandCounts, 0, sizeof(frameData.profile.commandCounts));
frameData.profile.profileSummary += cmdString;
#endif
}

frameData.profile.descriptorsWritten = 0;
Expand Down

0 comments on commit f47b87a

Please sign in to comment.