簡體   English   中英

無法在DirectX12下全屏顯示

[英]Can't go fullscreen under DirectX12

我有一個使用DirectX12的應用程序。 我想在我的應用中支持全屏模式。 但是,每次調用IDXGISwapChain :: SetFullscreenState()時,都會出現此錯誤:

DXGI錯誤:IDXGISwapChain :: GetContainingOutput:交換鏈的適配器不控制交換鏈窗口所在的輸出。

IDXGISwapChain :: SetFullscreenState()返回的錯誤代碼是

0x887a0004

我的電腦有兩個GPU:

英特爾(R)HD Graphics 630和

NVIDIA GeForce GTX 1060

后者是發生錯誤時用於創建d3d12設備的適配器。 如果適配器是前者,則不會出現錯誤。

用於創建IDXGISwapChain3的代碼流是

//variables used in the code example
ID3D12Device *pDevice;
IDXGIFactory4 *pDXGIFactory;
IDXGIAdapter *pAdapter;
ID3D12CommandQueue *pCommandQueue;
IDXGISwapChain1 *pTempSwapchain;
IDXGISwapChain3 *pSwapchain;

//the code flow
CreateDXGIFactory2();
pDXGIFactory->EnumAdapter();
D3D12CreateDevice(pAdapter, ...);
pD3DDevice->CreateCommandQueue();
pDXGIFactory->CreateSwapChainForHwnd(pCommandQueue, ..., &pTempSwapchain);
pTempSwapchain->QueryInterface(IID_PPV_ARGS(&pSwapChain));

IDXGISwapChain :: SetFullscreenState()應該會成功,但是失敗了。

請注意,問題是DXGI調試層的怪癖與“混合圖形”解決方案的實現方式的具體組合,具體取決於您當時使用的設備。

這里最好的選擇就是抑制錯誤:

#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()))))
        {
            dxgiInfoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, true);
            dxgiInfoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, true);

            DXGI_INFO_QUEUE_MESSAGE_ID hide[] =
            {
                80 /* IDXGISwapChain::GetContainingOutput: The swapchain's adapter does not control the output on which the swapchain's window resides. */,
            };
            DXGI_INFO_QUEUE_FILTER filter = {};
            filter.DenyList.NumIDs = _countof(hide);
            filter.DenyList.pIDList = hide;
            dxgiInfoQueue->AddStorageFilterEntries(DXGI_DEBUG_DXGI, &filter);
        }
    }
#endif

我在GitHub上的所有模板中使用它。

我找到了解決方案。 使用IDXGIFactory6 :: EnumAdapterByGpuPreference()方法代替IDXGIFactory :: EnumAdapter()方法然后錯誤將消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM