diff --git a/src/d3d11/d3d11_swapchain.cpp b/src/d3d11/d3d11_swapchain.cpp index 09fa68835..6dae5c48d 100644 --- a/src/d3d11/d3d11_swapchain.cpp +++ b/src/d3d11/d3d11_swapchain.cpp @@ -73,6 +73,21 @@ namespace dxvk { } + HRESULT STDMETHODCALLTYPE D3D11SwapChain::GetAdapter( + REFIID riid, + void** ppvObject) { + Com dxgiDevice; + + HRESULT hr = GetDevice(__uuidof(IDXGIDevice), + reinterpret_cast(&dxgiDevice)); + + if (FAILED(hr)) + return hr; + + return dxgiDevice->GetParent(riid, ppvObject); + } + + HRESULT STDMETHODCALLTYPE D3D11SwapChain::GetDevice( REFIID riid, void** ppDevice) { diff --git a/src/d3d11/d3d11_swapchain.h b/src/d3d11/d3d11_swapchain.h index da9a98aef..f1ab2325c 100644 --- a/src/d3d11/d3d11_swapchain.h +++ b/src/d3d11/d3d11_swapchain.h @@ -40,6 +40,10 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE GetDesc( DXGI_SWAP_CHAIN_DESC1* pDesc); + HRESULT STDMETHODCALLTYPE GetAdapter( + REFIID riid, + void** ppvObject); + HRESULT STDMETHODCALLTYPE GetDevice( REFIID riid, void** ppDevice); diff --git a/src/dxgi/dxgi_interfaces.h b/src/dxgi/dxgi_interfaces.h index 7d58957b2..63bf7c7dd 100644 --- a/src/dxgi/dxgi_interfaces.h +++ b/src/dxgi/dxgi_interfaces.h @@ -30,6 +30,10 @@ IDXGIVkSwapChain : public IUnknown { virtual HRESULT STDMETHODCALLTYPE GetDesc( DXGI_SWAP_CHAIN_DESC1* pDesc) = 0; + virtual HRESULT STDMETHODCALLTYPE GetAdapter( + REFIID riid, + void** ppvObject) = 0; + virtual HRESULT STDMETHODCALLTYPE GetDevice( REFIID riid, void** ppDevice) = 0; diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index b4ce223f2..7182c7b0e 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -16,27 +16,6 @@ namespace dxvk { m_desc (*pDesc), m_descFs (*pFullscreenDesc), m_monitor (nullptr) { - Com presentDevice; - - // Retrieve a device pointer that allows us to - // communicate with the underlying D3D device - if (FAILED(pDevice->QueryInterface(__uuidof(IDXGIVkPresentDevice), - reinterpret_cast(&presentDevice)))) - throw DxvkError("DXGI: DxgiSwapChain: Invalid device"); - - // Retrieve the adapter, which is going - // to be used to enumerate displays. - Com device; - Com adapter; - - if (FAILED(pDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast(&device)))) - throw DxvkError("DXGI: DxgiSwapChain: Invalid device"); - - if (FAILED(device->GetAdapter(&adapter))) - throw DxvkError("DXGI: DxgiSwapChain: Failed to retrieve adapter"); - - m_adapter = static_cast(adapter.ptr()); - // Initialize frame statistics m_stats.PresentCount = 0; m_stats.PresentRefreshCount = 0; @@ -44,6 +23,13 @@ namespace dxvk { m_stats.SyncQPCTime.QuadPart = 0; m_stats.SyncGPUTime.QuadPart = 0; + // Create presenter, which also serves as an interface to the device + if (FAILED(CreatePresenter(pDevice, &m_presenter))) + throw DxvkError("DXGI: Failed to create presenter"); + + if (FAILED(m_presenter->GetAdapter(__uuidof(IDXGIAdapter), reinterpret_cast(&m_adapter)))) + throw DxvkError("DXGI: Failed to get adapter for present device"); + // Adjust initial back buffer size. If zero, these // shall be set to the current window size. const VkExtent2D windowSize = GetWindowSize(); @@ -53,10 +39,7 @@ namespace dxvk { // Set initial window mode and fullscreen state if (!m_descFs.Windowed && FAILED(EnterFullscreenMode(nullptr))) - throw DxvkError("DXGI: DxgiSwapChain: Failed to set initial fullscreen state"); - - if (FAILED(presentDevice->CreateSwapChainForHwnd(m_window, &m_desc, &m_presenter))) - throw DxvkError("DXGI: DxgiSwapChain: Failed to create presenter"); + throw DxvkError("DXGI: Failed to set initial fullscreen state"); } @@ -584,5 +567,20 @@ namespace dxvk { return E_INVALIDARG; } + + + HRESULT DxgiSwapChain::CreatePresenter( + IUnknown* pDevice, + IDXGIVkSwapChain** ppSwapChain) { + Com presentDevice; + + // Retrieve a device pointer that allows us to + // communicate with the underlying D3D device + if (SUCCEEDED(pDevice->QueryInterface(__uuidof(IDXGIVkPresentDevice), + reinterpret_cast(&presentDevice)))) + return presentDevice->CreateSwapChainForHwnd(m_window, &m_desc, ppSwapChain); + + return E_INVALIDARG; + } } diff --git a/src/dxgi/dxgi_swapchain.h b/src/dxgi/dxgi_swapchain.h index 0bbd19ea3..8f8cf59f9 100644 --- a/src/dxgi/dxgi_swapchain.h +++ b/src/dxgi/dxgi_swapchain.h @@ -165,6 +165,10 @@ namespace dxvk { UINT Count, VkSampleCountFlagBits* pCount) const; + HRESULT CreatePresenter( + IUnknown* pDevice, + IDXGIVkSwapChain** ppSwapChain); + }; }