1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[dxgi] Refactor presenter creation

This change is needed to support non-D3D11 presenters in our DXGI code.
This commit is contained in:
Philip Rebohle 2018-11-12 11:20:27 +01:00
parent 8d2f8fca64
commit 1724d51079
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
5 changed files with 50 additions and 25 deletions

View File

@ -73,6 +73,21 @@ namespace dxvk {
}
HRESULT STDMETHODCALLTYPE D3D11SwapChain::GetAdapter(
REFIID riid,
void** ppvObject) {
Com<IDXGIDevice> dxgiDevice;
HRESULT hr = GetDevice(__uuidof(IDXGIDevice),
reinterpret_cast<void**>(&dxgiDevice));
if (FAILED(hr))
return hr;
return dxgiDevice->GetParent(riid, ppvObject);
}
HRESULT STDMETHODCALLTYPE D3D11SwapChain::GetDevice(
REFIID riid,
void** ppDevice) {

View File

@ -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);

View File

@ -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;

View File

@ -16,27 +16,6 @@ namespace dxvk {
m_desc (*pDesc),
m_descFs (*pFullscreenDesc),
m_monitor (nullptr) {
Com<IDXGIVkPresentDevice> presentDevice;
// Retrieve a device pointer that allows us to
// communicate with the underlying D3D device
if (FAILED(pDevice->QueryInterface(__uuidof(IDXGIVkPresentDevice),
reinterpret_cast<void**>(&presentDevice))))
throw DxvkError("DXGI: DxgiSwapChain: Invalid device");
// Retrieve the adapter, which is going
// to be used to enumerate displays.
Com<IDXGIDevice> device;
Com<IDXGIAdapter> adapter;
if (FAILED(pDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&device))))
throw DxvkError("DXGI: DxgiSwapChain: Invalid device");
if (FAILED(device->GetAdapter(&adapter)))
throw DxvkError("DXGI: DxgiSwapChain: Failed to retrieve adapter");
m_adapter = static_cast<DxgiAdapter*>(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<void**>(&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<IDXGIVkPresentDevice> presentDevice;
// Retrieve a device pointer that allows us to
// communicate with the underlying D3D device
if (SUCCEEDED(pDevice->QueryInterface(__uuidof(IDXGIVkPresentDevice),
reinterpret_cast<void**>(&presentDevice))))
return presentDevice->CreateSwapChainForHwnd(m_window, &m_desc, ppSwapChain);
return E_INVALIDARG;
}
}

View File

@ -165,6 +165,10 @@ namespace dxvk {
UINT Count,
VkSampleCountFlagBits* pCount) const;
HRESULT CreatePresenter(
IUnknown* pDevice,
IDXGIVkSwapChain** ppSwapChain);
};
}