Can't enable debug layer

Gavin Williams 761 Reputation points
2020-12-21T05:44:50.09+00:00

I'm using TerraFX DirectX wrapper in a Desktop.WinUI project / .Net 5.

I've enabled the debug layer with the following code.

cs
            ID3D11Device* CreateD3DDevice(out ID3D11DeviceContext* pImmediateContext)
            {
                ID3D11Device* d3dDevice;
                ID3D11DeviceContext* immediateContext;

                D3D11_CREATE_DEVICE_FLAG flags = 0;
                // direct2d compat
                flags |= D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if (DEBUG)
                // debug layer
                flags |= D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_DEBUG;
#endif

                var featureLevel = D3D_FEATURE_LEVEL_11_1;
                ThrowIfFailed(nameof(D3D11CreateDevice), D3D11CreateDevice(
                    (IDXGIAdapter*)DxgiAdapter, 
                    D3D_DRIVER_TYPE_HARDWARE, 
                    Software: IntPtr.Zero, 
                    Flags: (uint)flags, 
                    &featureLevel, 
                    FeatureLevels: 1, 
                    D3D11_SDK_VERSION, 
                    &d3dDevice, 
                    pFeatureLevel: null, 
                    &immediateContext));

                pImmediateContext = immediateContext;
                return d3dDevice;
            }

This works for one project - samples that are available for TerraFX, but it doesn't work in my own project built from the Desktop.WinUI project template in VS.

PS. No DirectX Tags available for these forums? You need to look through your tags, they need some work.

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,006 questions
0 comments No comments
{count} votes

Accepted answer
  1. Gavin Williams 761 Reputation points
    2020-12-21T06:24:31.717+00:00

    I needed to also set

    cs
    uint dxgiFactoryFlags = (uint)DXGI_CREATE_FACTORY_DEBUG;
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.