gpt4 book ai didi

c++ - D3D12 不可避免的泄漏报告

转载 作者:搜寻专家 更新时间:2023-10-31 00:28:03 24 4
gpt4 key购买 nike

这个程序:

#include <d3d12.h>
#pragma comment(lib,"d3d12")

int main()
{
ID3D12Debug *pDebug = NULL;
D3D12GetDebugInterface(__uuidof(ID3D12Debug),(void**)&pDebug);
pDebug->EnableDebugLayer();
pDebug->Release();

ID3D12Device *pDev = NULL;
D3D12CreateDevice(NULL,D3D_FEATURE_LEVEL_12_1,__uuidof(ID3D12Device),(void**)&pDev);

ID3D12DebugDevice *pDebugDevice = NULL;
pDev->QueryInterface(&pDebugDevice);
pDev->Release();
pDebugDevice->ReportLiveDeviceObjects(D3D12_RLDO_DETAIL);
pDebugDevice->Release();
}

在调试输出中给出:

D3D12 WARNING: Live ID3D12Device at 0x000C6BA8, Refcount: 2 [ STATE_CREATION WARNING #274: LIVE_DEVICE]
D3D12 WARNING: Live ID3D12RootSignature at 0x000E62E8, Refcount: 0, IntRef: 2 [ STATE_CREATION WARNING #577: LIVE_ROOTSIGNATURE]
D3D12 WARNING: Live ID3D12PipelineState at 0x0011C3C8, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #572: LIVE_PIPELINESTATE]
D3D12 WARNING: Live ID3D12PipelineState at 0x001421D8, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #572: LIVE_PIPELINESTATE]
D3D12 WARNING: Live ID3D12Resource at 0x00138FF8, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #575: LIVE_RESOURCE]
D3D12 WARNING: Live ID3D12Heap at 0x00144DD8, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #579: LIVE_HEAP]

调试设备报告我创建的 D3D12 设备在我释放它后仍然存在。我知道这确实是真的,因为调试设备本身实际上是使 D3D12 设备保持事件状态的唯一剩余引荐来源网址,但从我的角度来看,这不是泄漏,因为我已经正确释放了我的 D3D12 设备.这只是对我的程序输出的污染,给出了我的代码中存在错误的错误指示。

我的问题是:我在这里确实做错了什么吗?还是报告在 D3D12 调试设备中的工作方式不好?关于如何解决它的任何想法?

谢谢!

最佳答案

您应该尝试使用 D3D12_RLDO_IGNORE_INTERNAL 标志来忽略那些 RefCount 为 0 但仍具有 IntRef 的项目。

对于“干净关机”场景,我更喜欢使用 DXGI 调试设备报告而不是 Direct3D。

在我的DeviceResources实现,我按如下方式创建 DXGI 设备:

    m_dxgiFactoryFlags = 0;

#if defined(_DEBUG)
// Enable the debug layer (requires the Graphics Tools "optional feature").
//
// NOTE: Enabling the debug layer after device creation will invalidate the active device.
{
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(debugController.GetAddressOf()))))
{
debugController->EnableDebugLayer();
}
else
{
OutputDebugStringA("WARNING: Direct3D Debug Device is not available\n");
}

ComPtr<IDXGIInfoQueue> dxgiInfoQueue;
if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(dxgiInfoQueue.GetAddressOf()))))
{
m_dxgiFactoryFlags = DXGI_CREATE_FACTORY_DEBUG;

dxgiInfoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, true);
dxgiInfoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, true);
}
}
#endif

ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(m_dxgiFactory.ReleaseAndGetAddressOf())));

然后当我关机并想检查“泄漏”时:

#ifdef _DEBUG
{
ComPtr<IDXGIDebug1> dxgiDebug;
if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug))))
{
dxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_SUMMARY | DXGI_DEBUG_RLO_IGNORE_INTERNAL));
}
}
#endif

For Win32 apps, there's a clear time to do 'clean exit' report leaks. For UWP apps, lifetime is controlled by PLM so you don't ever get a 'clean exit'--the process is just terminated after a suspend. For UWP, the best place to do leak checks is in the "device lost" handler caused by device removal errors.

关于c++ - D3D12 不可避免的泄漏报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46802508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com