Skip to content

Commit

Permalink
[dxvk] Improve handling of nested debug regions
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Feb 16, 2025
1 parent 5a5541f commit ec36b61
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
58 changes: 33 additions & 25 deletions src/dxvk/dxvk_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2854,27 +2854,19 @@ namespace dxvk {

label << ")";

beginInternalDebugRegion(vk::makeLabel(0xf0e6dc, label.str().c_str()));
pushDebugRegion(vk::makeLabel(0xf0e6dc, label.str().c_str()), util::DxvkDebugLabelType::Internal);
}


void DxvkContext::beginDebugLabel(const VkDebugUtilsLabelEXT& label) {
if (m_features.test(DxvkContextFeature::DebugUtils)) {
endInternalDebugRegion();

m_cmd->cmdBeginDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer, label);
m_debugLabelStack.emplace_back(label);
}
if (m_features.test(DxvkContextFeature::DebugUtils))
pushDebugRegion(label, util::DxvkDebugLabelType::External);
}


void DxvkContext::endDebugLabel() {
if (m_features.test(DxvkContextFeature::DebugUtils)) {
if (!m_debugLabelStack.empty()) {
m_cmd->cmdEndDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer);
m_debugLabelStack.pop_back();
}
}
if (m_features.test(DxvkContextFeature::DebugUtils))
popDebugRegion(util::DxvkDebugLabelType::External);
}


Expand Down Expand Up @@ -5182,7 +5174,8 @@ namespace dxvk {

flushBarriers();
flushResolves();
endInternalDebugRegion();

popDebugRegion(util::DxvkDebugLabelType::Internal);
} else if (!suspend) {
// We may end a previously suspended render pass
if (m_flags.test(DxvkContextFlag::GpRenderPassSuspended)) {
Expand Down Expand Up @@ -8138,22 +8131,37 @@ namespace dxvk {
}


void DxvkContext::beginInternalDebugRegion(const VkDebugUtilsLabelEXT& label) {
void DxvkContext::pushDebugRegion(const VkDebugUtilsLabelEXT& label, util::DxvkDebugLabelType type) {
if (m_features.test(DxvkContextFeature::DebugUtils)) {
// If the app provides us with debug regions, don't add any
// internal ones to avoid potential issues with scoping.
if (m_debugLabelStack.empty()) {
m_cmd->cmdBeginDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer, label);
m_debugLabelInternalActive = true;
}
m_cmd->cmdBeginDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer, label);
m_debugLabelStack.emplace_back(label, type);
}
}


void DxvkContext::endInternalDebugRegion() {
if (m_debugLabelInternalActive) {
m_debugLabelInternalActive = false;
m_cmd->cmdEndDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer);
void DxvkContext::popDebugRegion(util::DxvkDebugLabelType type) {
if (m_features.test(DxvkContextFeature::DebugUtils)) {
// Find last active region of the given type
size_t index = m_debugLabelStack.size();

while (index && m_debugLabelStack[index - 1u].type() != type)
index -= 1u;

if (!index)
return;

// End all debug regions inside the scope we want to end, as
// well as the debug region of the requested type itself
for (size_t i = index; i <= m_debugLabelStack.size(); i++)
m_cmd->cmdEndDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer);

// Re-emit nested debug regions and erase the region we ended
for (size_t i = index; i < m_debugLabelStack.size(); i++) {
m_cmd->cmdBeginDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer, m_debugLabelStack[i].get());
m_debugLabelStack[i - 1u] = m_debugLabelStack[i];
}

m_debugLabelStack.pop_back();
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/dxvk/dxvk_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,6 @@ namespace dxvk {
std::vector<VkImageMemoryBarrier2> m_imageLayoutTransitions;

std::vector<util::DxvkDebugLabel> m_debugLabelStack;
bool m_debugLabelInternalActive = false;

Rc<DxvkLatencyTracker> m_latencyTracker;
uint64_t m_latencyFrameId = 0u;
Expand Down Expand Up @@ -2061,10 +2060,12 @@ namespace dxvk {

void beginRenderPassDebugRegion();

void beginInternalDebugRegion(
const VkDebugUtilsLabelEXT& label);
void pushDebugRegion(
const VkDebugUtilsLabelEXT& label,
util::DxvkDebugLabelType type);

void endInternalDebugRegion();
void popDebugRegion(
util::DxvkDebugLabelType type);

void beginActiveDebugRegions();

Expand Down
17 changes: 15 additions & 2 deletions src/dxvk/dxvk_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

namespace dxvk::util {

/**
* \brief Debug utils label type
*/
enum class DxvkDebugLabelType : uint32_t {
Internal, ///< Internal scope, e.g. render pass
External, ///< App-provided scope
};

/**
* \brief Debug label wrapper
*
Expand All @@ -16,12 +24,16 @@ namespace dxvk::util {

DxvkDebugLabel() = default;

DxvkDebugLabel(const VkDebugUtilsLabelEXT& label)
: m_text(label.pLabelName ? label.pLabelName : "") {
DxvkDebugLabel(const VkDebugUtilsLabelEXT& label, DxvkDebugLabelType type)
: m_text(label.pLabelName ? label.pLabelName : ""), m_type(type) {
for (uint32_t i = 0; i < m_color.size(); i++)
m_color[i] = label.color[i];
}

DxvkDebugLabelType type() const {
return m_type;
}

VkDebugUtilsLabelEXT get() const {
VkDebugUtilsLabelEXT label = { VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT };
label.pLabelName = m_text.c_str();
Expand All @@ -34,6 +46,7 @@ namespace dxvk::util {

std::string m_text;
std::array<float, 4> m_color = { };
DxvkDebugLabelType m_type;

};

Expand Down

0 comments on commit ec36b61

Please sign in to comment.