Repository: microsoft/terminal
File: src/renderer/atlas/AtlasEngine.cpp (C++)

Code before:
                // I didn't want to link with dxguid.lib just for getting DXGI_DEBUG_ALL. This GUID is publicly documented.
                static constexpr GUID dxgiDebugAll = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8 } };
                for (const auto severity : std::array{ DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_WARNING })
                {
                    infoQueue->SetBreakOnSeverity(dxgiDebugAll, severity, true);
                }
            }

            if (wil::com_ptr<IDXGIDebug1> debug; SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(debug.addressof()))))
            {
                debug->EnableLeakTrackingForThread();
            }
        }
    }
#endif // NDEBUG

    // D3D device setup (basically a D3D class factory)
    {
        wil::com_ptr<ID3D11DeviceContext> deviceContext;

        static constexpr std::array featureLevels{
            D3D_FEATURE_LEVEL_11_1,
            D3D_FEATURE_LEVEL_11_0,
            D3D_FEATURE_LEVEL_10_1,
        };

        auto hr = E_UNEXPECTED;

        if (!_api.useSoftwareRendering)
        {
            // Why D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS:
            // This flag prevents the driver from creating a large thread pool for things like shader computations
            // that would be advantageous for games. For us this has only a minimal performance benefit,
            // but comes with a large memory usage overhead. At the time of writing the Nvidia
            // driver launches $cpu_thread_count more worker threads without this flag.
            hr = D3D11CreateDevice(
                /* pAdapter */ nullptr,
                /* DriverType */ D3D_DRIVER_TYPE_HARDWARE,
                /* Software */ nullptr,
                /* Flags */ deviceFlags | D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
                /* pFeatureLevels */ featureLevels.data(),
                /* FeatureLevels */ gsl::narrow_cast<UINT>(featureLevels.size()),
                /* SDKVersion */ D3D11_SDK_VERSION,
                /* ppDevice */ _r.device.put(),
                /* pFeatureLevel */ nullptr,
                /* ppImmediateContext */ deviceContext.put());
        }
        if (FAILED(hr))
        {
            hr = D3D11CreateDevice(
                /* pAdapter */ nullptr,

Review comment (suggestion):
So you've made the fallback manual (explicit check instead of iterating over a list of device types)? Neat! Thanks!

Code after:
                static constexpr GUID dxgiDebugAll = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8 } };
                for (const auto severity : std::array{ DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_WARNING })
                {
                    infoQueue->SetBreakOnSeverity(dxgiDebugAll, severity, true);
                }
            }

            if (wil::com_ptr<IDXGIDebug1> debug; SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(debug.addressof()))))
            {
                debug->EnableLeakTrackingForThread();
            }
        }
    }
#endif // NDEBUG

    // D3D device setup (basically a D3D class factory)
    {
        wil::com_ptr<ID3D11DeviceContext> deviceContext;

        static constexpr std::array featureLevels{
            D3D_FEATURE_LEVEL_11_1,
            D3D_FEATURE_LEVEL_11_0,
            D3D_FEATURE_LEVEL_10_1,
            D3D_FEATURE_LEVEL_10_0,
        };

        auto hr = E_UNEXPECTED;

        if (!_api.useSoftwareRendering)
        {
            // Why D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS:
            // This flag prevents the driver from creating a large thread pool for things like shader computations
            // that would be advantageous for games. For us this has only a minimal performance benefit,
            // but comes with a large memory usage overhead. At the time of writing the Nvidia
            // driver launches $cpu_thread_count more worker threads without this flag.
            hr = D3D11CreateDevice(
                /* pAdapter */ nullptr,
                /* DriverType */ D3D_DRIVER_TYPE_HARDWARE,
                /* Software */ nullptr,
                /* Flags */ deviceFlags | D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
                /* pFeatureLevels */ featureLevels.data(),
                /* FeatureLevels */ gsl::narrow_cast<UINT>(featureLevels.size()),
                /* SDKVersion */ D3D11_SDK_VERSION,
                /* ppDevice */ _r.device.put(),
                /* pFeatureLevel */ nullptr,
                /* ppImmediateContext */ deviceContext.put());
        }
        if (FAILED(hr))
        {
            hr = D3D11CreateDevice(
                /* pAdapter */ nullptr,