microsoft / microsoft/DirectX-Graphics-Samples

Rapid memory leak when ID3D12Debug::EnableDebugLayer used with Address Sanitizer (ASAN)

Open
#899 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
6.8k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

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:

Image

This does not affect all samples though, such as D3D12HelloFrameBuffering, which levels off near 600MB:

Image

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:

  1. Open the D3D12HelloWorld solution.
  2. Right click on the D3D12HelloTriangle project, select Properties.
  3. Make sure the current Configuration is Debug (top left dropdown).
  4. Under C/C++ -> General set Enable Address Sanitizer to Yes.

Image

  1. 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
/* ... */
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in the D3D12HelloTriangle sample with Debug configuration and Address Sanitizer enabled. Inspect the LoadPipeline debug-layer setup and compare its behavior with D3D12HelloFrameBuffering. Done means the debug layer can remain enabled while memory growth stays bounded in the affected samples.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.