-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
When ID3D12Debug::EnableDebugLayer
is used with Address Sanitizer (ASAN) a rapid memory leak (over 3GB/minute on my machine) can be observed in many, but not all, D3D12 samples. Affected samples include even the most basic ones:
D3D12HelloTriangle
D3D12HelloTexture
D3D12HelloTriangle hits 10.3GB of Process Memory after running for 3 minutes and usage just keeps growing:
This does not affect all samples though, such as D3D12HelloFrameBuffering, which levels off near 600MB:
I have never observed this problem during years of using D3D11. When ASAN is used in general it is normal to observe an initial process memory growth for perhaps a minute or so but this eventually levels off. ASAN tries to keep around some freed memory for awhile in order to detect use-after-free bugs, but it is not supposed to keep growing unbounded.
To reproduce the issue:
- Open the D3D12HelloWorld solution.
- Right click on the D3D12HelloTriangle project, select Properties.
- Make sure the current Configuration is Debug (top left dropdown).
- Under C/C++ -> General set Enable Address Sanitizer to Yes.
- Run the project.
Expected behavior: relatively small amount of memory growth that eventually stops.
Observed behavior: rapid unbounded memory growth, multiple gigabytes in minutes.
Disabling this code that enables the D3D12 debug layer allows ASAN to function normally:
// Load the rendering pipeline dependencies.
void D3D12HelloTriangle::LoadPipeline()
{
UINT 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))))
{
debugController->EnableDebugLayer();
// Enable additional debug layers.
dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;
}
}
#endif
/* ... */
}