From 0e7c233af487c6ed499734313ea910f25cbf330e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 16 Feb 2025 18:45:52 +0100 Subject: [PATCH] [dxvk] Add debug region for barrier control --- src/dxvk/dxvk_context.cpp | 55 +++++++++++++++++++++++++++++++++++++-- src/dxvk/dxvk_context.h | 6 +++++ src/dxvk/dxvk_util.h | 1 + 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index a71fe3d57060..2078aeab1686 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -2626,10 +2626,13 @@ namespace dxvk { // If any control flags change, play it safe and force a barrier the next // time we encounter a write-after-write hazard, even if the same set of // flags is restored. - if (m_barrierControl != control) + if (m_barrierControl != control) { m_flags.set(DxvkContextFlag::ForceWriteAfterWriteSync); + m_barrierControl = control; - m_barrierControl = control; + if (unlikely(m_features.test(DxvkContextFeature::DebugUtils))) + popDebugRegion(util::DxvkDebugLabelType::InternalBarrierControl); + } } @@ -2866,6 +2869,30 @@ namespace dxvk { } + template + void DxvkContext::beginBarrierControlDebugRegion() { + if (hasDebugRegion(util::DxvkDebugLabelType::InternalBarrierControl)) + return; + + const char* label = nullptr; + + if (BindPoint == VK_PIPELINE_BIND_POINT_COMPUTE) { + if (m_barrierControl.test(DxvkBarrierControl::ComputeAllowReadWriteOverlap)) + label = "Relaxed sync"; + else if (m_barrierControl.test(DxvkBarrierControl::ComputeAllowWriteOnlyOverlap)) + label = "Relaxed sync (write-only)"; + } else { + if (m_barrierControl.test(DxvkBarrierControl::GraphicsAllowReadWriteOverlap)) + label = "Relaxed sync"; + } + + if (label) { + pushDebugRegion(vk::makeLabel(0x9bded9, label), + util::DxvkDebugLabelType::InternalBarrierControl); + } + } + + void DxvkContext::beginDebugLabel(const VkDebugUtilsLabelEXT& label) { if (m_features.test(DxvkContextFeature::DebugUtils)) pushDebugRegion(label, util::DxvkDebugLabelType::External); @@ -5124,6 +5151,9 @@ namespace dxvk { void DxvkContext::startRenderPass() { if (!m_flags.test(DxvkContextFlag::GpRenderPassBound)) { + if (unlikely(m_features.test(DxvkContextFeature::DebugUtils))) + popDebugRegion(util::DxvkDebugLabelType::InternalBarrierControl); + this->applyRenderTargetLoadLayouts(); this->flushClears(true); @@ -5184,6 +5214,9 @@ namespace dxvk { m_queryManager.endQueries(m_cmd, VK_QUERY_TYPE_OCCLUSION); m_queryManager.endQueries(m_cmd, VK_QUERY_TYPE_PIPELINE_STATISTICS); + if (unlikely(m_features.test(DxvkContextFeature::DebugUtils))) + popDebugRegion(util::DxvkDebugLabelType::InternalBarrierControl); + this->renderPassUnbindFramebuffer(); if (suspend) @@ -6643,6 +6676,9 @@ namespace dxvk { m_descriptorState.dirtyStages(VK_SHADER_STAGE_COMPUTE_BIT); } + if (unlikely(m_features.test(DxvkContextFeature::DebugUtils))) + this->beginBarrierControlDebugRegion(); + if (m_descriptorState.hasDirtyComputeSets()) this->updateComputeShaderResources(); @@ -6690,6 +6726,13 @@ namespace dxvk { if (!m_flags.test(DxvkContextFlag::GpRenderPassBound)) this->startRenderPass(); + if (m_flags.test(DxvkContextFlag::GpRenderPassSideEffects)) { + // Make sure that the debug label for barrier control + // always starts within an active render pass + if (unlikely(m_features.test(DxvkContextFeature::DebugUtils))) + this->beginBarrierControlDebugRegion(); + } + if (m_flags.test(DxvkContextFlag::GpDirtyIndexBuffer) && Indexed) { if (unlikely(!this->updateIndexBufferBinding())) return false; @@ -8188,6 +8231,14 @@ namespace dxvk { } + bool DxvkContext::hasDebugRegion( + util::DxvkDebugLabelType type) { + auto e = std::find_if(m_debugLabelStack.crbegin(), m_debugLabelStack.crend(), + [type] (const util::DxvkDebugLabel& label) { return label.type() == type; }); + return e != m_debugLabelStack.crend(); + } + + void DxvkContext::beginActiveDebugRegions() { for (const auto& region : m_debugLabelStack) m_cmd->cmdBeginDebugUtilsLabel(DxvkCmdBuffer::ExecBuffer, region.get()); diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 85ad7574c982..725c9cc1a1c1 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -2071,6 +2071,9 @@ namespace dxvk { void beginRenderPassDebugRegion(); + template + void beginBarrierControlDebugRegion(); + void pushDebugRegion( const VkDebugUtilsLabelEXT& label, util::DxvkDebugLabelType type); @@ -2078,6 +2081,9 @@ namespace dxvk { void popDebugRegion( util::DxvkDebugLabelType type); + bool hasDebugRegion( + util::DxvkDebugLabelType type); + void beginActiveDebugRegions(); void endActiveDebugRegions(); diff --git a/src/dxvk/dxvk_util.h b/src/dxvk/dxvk_util.h index ab166e3f0419..49a63da1c5d6 100644 --- a/src/dxvk/dxvk_util.h +++ b/src/dxvk/dxvk_util.h @@ -10,6 +10,7 @@ namespace dxvk::util { enum class DxvkDebugLabelType : uint32_t { External, ///< App-provided scope InternalRenderPass, ///< Internal render pass markers + InternalBarrierControl, ///< Barrier control markers }; /**