Skip to content

Commit

Permalink
[dxvk] Add debug region for barrier control
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Feb 19, 2025
1 parent 636669e commit 19361c9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
58 changes: 55 additions & 3 deletions src/dxvk/dxvk_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2634,13 +2634,17 @@ namespace dxvk {
: DxvkBarrierControlFlags(DxvkBarrierControl::ComputeAllowReadWriteOverlap,
DxvkBarrierControl::ComputeAllowWriteOnlyOverlap);

if (!((m_barrierControl ^ control) & mask).isClear())
if (!((m_barrierControl ^ control) & mask).isClear()) {
m_flags.set(DxvkContextFlag::ForceWriteAfterWriteSync);

if (unlikely(m_features.test(DxvkContextFeature::DebugUtils)))
popDebugRegion(util::DxvkDebugLabelType::InternalBarrierControl);
}

m_barrierControl = control;
}


void DxvkContext::updatePageTable(
const DxvkSparseBindInfo& bindInfo,
DxvkSparseBindFlags flags) {
Expand Down Expand Up @@ -2874,6 +2878,30 @@ namespace dxvk {
}


template<VkPipelineBindPoint BindPoint>
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);
Expand Down Expand Up @@ -5132,6 +5160,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);

Expand Down Expand Up @@ -5192,6 +5223,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)
Expand Down Expand Up @@ -6651,6 +6685,9 @@ namespace dxvk {
m_descriptorState.dirtyStages(VK_SHADER_STAGE_COMPUTE_BIT);
}

if (unlikely(m_features.test(DxvkContextFeature::DebugUtils)))
this->beginBarrierControlDebugRegion<VK_PIPELINE_BIND_POINT_COMPUTE>();

if (m_descriptorState.hasDirtyComputeSets())
this->updateComputeShaderResources();

Expand Down Expand Up @@ -6698,6 +6735,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<VK_PIPELINE_BIND_POINT_GRAPHICS>();
}

if (m_flags.test(DxvkContextFlag::GpDirtyIndexBuffer) && Indexed) {
if (unlikely(!this->updateIndexBufferBinding()))
return false;
Expand Down Expand Up @@ -8196,6 +8240,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());
Expand Down
6 changes: 6 additions & 0 deletions src/dxvk/dxvk_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -2071,13 +2071,19 @@ namespace dxvk {

void beginRenderPassDebugRegion();

template<VkPipelineBindPoint BindPoint>
void beginBarrierControlDebugRegion();

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

void popDebugRegion(
util::DxvkDebugLabelType type);

bool hasDebugRegion(
util::DxvkDebugLabelType type);

void beginActiveDebugRegions();

void endActiveDebugRegions();
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/dxvk_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down

0 comments on commit 19361c9

Please sign in to comment.