Skip to content

Commit fcc1a09

Browse files
authored
Use d3d12/vk debug layer when gfx debug layer is enabled. (shader-slang#2411)
* Use d3d12/vk debug layer when gfx debug layer is enabled. * Fix. Co-authored-by: Yong He <yhe@nvidia.com>
1 parent 4b58c50 commit fcc1a09

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

tools/gfx/d3d12/d3d12-device.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,15 @@ Result DeviceImpl::initialize(const Desc& desc)
471471
// TODO: we should probably provide a command-line option
472472
// to override UseDebug of default rather than leave it
473473
// up to each back-end to specify.
474-
#if ENABLE_DEBUG_LAYER
475-
combiner.add(
476-
DeviceCheckFlag::UseDebug, ChangeType::OnOff); ///< First try debug then non debug
477-
#else
478-
combiner.add(DeviceCheckFlag::UseDebug, ChangeType::Off); ///< Don't bother with debug
479-
#endif
474+
if (ENABLE_DEBUG_LAYER || isGfxDebugLayerEnabled())
475+
{
476+
combiner.add(
477+
DeviceCheckFlag::UseDebug, ChangeType::OnOff); ///< First try debug then non debug
478+
}
479+
else
480+
{
481+
combiner.add(DeviceCheckFlag::UseDebug, ChangeType::Off); ///< Don't bother with debug
482+
}
480483
combiner.add(
481484
DeviceCheckFlag::UseHardwareDevice,
482485
ChangeType::OnOff); ///< First try hardware, then reference

tools/gfx/debug-layer/debug-command-queue.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ void DebugCommandQueue::executeCommandBuffers(GfxCount count, ICommandBuffer* co
4747
}
4848
}
4949
baseObject->executeCommandBuffers(count, innerCommandBuffers.getBuffer(), getInnerObj(fence), valueToSignal);
50+
if (fence)
51+
{
52+
getDebugObj(fence)->maxValueToSignal = Math::Max(getDebugObj(fence)->maxValueToSignal, valueToSignal);
53+
}
5054
}
5155

5256
void DebugCommandQueue::waitOnHost()

tools/gfx/debug-layer/debug-fence.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Result DebugFence::getCurrentValue(uint64_t* outValue)
3131
Result DebugFence::setCurrentValue(uint64_t value)
3232
{
3333
SLANG_GFX_API_FUNC;
34+
if (value < maxValueToSignal)
35+
{
36+
GFX_DIAGNOSE_ERROR_FORMAT("Cannot set fence value (%d) to lower than pending signal value (%d) on the fence.", value, maxValueToSignal);
37+
}
3438
return baseObject->setCurrentValue(value);
3539
}
3640

tools/gfx/debug-layer/debug-fence.h

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class DebugFence : public DebugObject<IFence>
1818
virtual SLANG_NO_THROW Result SLANG_MCALL setCurrentValue(uint64_t value) override;
1919
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
2020
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outNativeHandle) override;
21+
public:
22+
uint64_t maxValueToSignal = 0;
2123
};
2224

2325
} // namespace debug

tools/gfx/render.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevi
1616
Result SLANG_MCALL createCPUDevice(const IDevice::Desc* desc, IDevice** outDevice);
1717

1818
static bool debugLayerEnabled = false;
19+
bool isGfxDebugLayerEnabled() { return debugLayerEnabled; }
1920

2021
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Global Renderer Functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
2122

tools/gfx/renderer-shared.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ struct GfxGUID
4545
static const Slang::Guid IID_ID3D12TransientResourceHeap;
4646
};
4747

48+
bool isGfxDebugLayerEnabled();
49+
4850
// We use a `BreakableReference` to avoid the cyclic reference situation in gfx implementation.
4951
// It is a common scenario where objects created from an `IDevice` implementation needs to hold
5052
// a strong reference to the device object that creates them. For example, a `Buffer` or a

tools/gfx/vulkan/vk-device.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
662662
continue;
663663
descriptorSetAllocator.m_api = &m_api;
664664
initDeviceResult = initVulkanInstanceAndDevice(
665-
desc.existingDeviceHandles.handles, ENABLE_VALIDATION_LAYER != 0);
665+
desc.existingDeviceHandles.handles, ENABLE_VALIDATION_LAYER != 0 || isGfxDebugLayerEnabled());
666666
if (initDeviceResult == SLANG_OK)
667667
break;
668668
}

0 commit comments

Comments
 (0)