From 7b9726fd937130b1da8c85e43926dd2116ed4d1e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 23 Oct 2018 15:10:01 +0200 Subject: [PATCH] [d3d11] D3D11Presenter -> D3D11PresentDevice --- src/d3d11/d3d11_device.cpp | 2 +- src/d3d11/d3d11_device.h | 10 ++--- src/d3d11/d3d11_main.cpp | 2 +- src/d3d11/d3d11_present.cpp | 83 +++---------------------------------- src/d3d11/d3d11_present.h | 37 ++--------------- src/dxgi/dxgi_interfaces.h | 38 ++--------------- src/dxgi/dxgi_swapchain.cpp | 8 ++-- src/dxgi/dxgi_swapchain.h | 1 - src/util/com/com_guid.cpp | 2 +- 9 files changed, 25 insertions(+), 158 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 214c3668f..74eec122a 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -67,7 +67,7 @@ namespace dxvk { return S_OK; } - if (riid == __uuidof(IDXGIVkPresenter)) { + if (riid == __uuidof(IDXGIVkPresentDevice)) { *ppvObject = ref(m_d3d11Presenter); return S_OK; } diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index eb1d28f38..0580b890a 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -31,7 +31,7 @@ namespace dxvk { class D3D11DeviceContext; class D3D11ImmediateContext; class D3D11Predicate; - class D3D11Presenter; + class D3D11PresentDevice; class D3D11Query; class D3D11Texture1D; class D3D11Texture2D; @@ -59,10 +59,10 @@ namespace dxvk { REFIID riid, void** ppParent); - IDXGIVkDevice* m_dxgiDevice = nullptr; - D3D11Device* m_d3d11Device = nullptr; - D3D11Presenter* m_d3d11Presenter = nullptr; - D3D11VkInterop* m_d3d11VkInterop = nullptr; + IDXGIVkDevice* m_dxgiDevice = nullptr; + D3D11Device* m_d3d11Device = nullptr; + D3D11PresentDevice* m_d3d11Presenter = nullptr; + D3D11VkInterop* m_d3d11VkInterop = nullptr; }; diff --git a/src/d3d11/d3d11_main.cpp b/src/d3d11/d3d11_main.cpp index 92db016c1..be94cb49c 100644 --- a/src/d3d11/d3d11_main.cpp +++ b/src/d3d11/d3d11_main.cpp @@ -79,7 +79,7 @@ extern "C" { container->m_d3d11Device = new D3D11Device( container.ptr(), container->m_dxgiDevice, fl, Flags); - container->m_d3d11Presenter = new D3D11Presenter( + container->m_d3d11Presenter = new D3D11PresentDevice( container.ptr(), container->m_d3d11Device); container->m_d3d11VkInterop = new D3D11VkInterop( container.ptr(), container->m_d3d11Device); diff --git a/src/d3d11/d3d11_present.cpp b/src/d3d11/d3d11_present.cpp index a8fe3d986..0f73eb38e 100644 --- a/src/d3d11/d3d11_present.cpp +++ b/src/d3d11/d3d11_present.cpp @@ -1,31 +1,9 @@ #include "d3d11_device.h" -#include "d3d11_context_imm.h" #include "d3d11_present.h" namespace dxvk { - D3D11VkBackBuffer::D3D11VkBackBuffer(D3D11Texture2D* pTexture) - : m_texture(pTexture) { - m_texture->AddRefPrivate(); - } - - - D3D11VkBackBuffer::~D3D11VkBackBuffer() { - m_texture->ReleasePrivate(); - } - - - HRESULT STDMETHODCALLTYPE D3D11VkBackBuffer::QueryInterface(REFIID riid, void** ppvObject) { - return m_texture->QueryInterface(riid, ppvObject); - } - - - Rc D3D11VkBackBuffer::GetDXVKImage() { - return m_texture->GetCommonTexture()->GetImage(); - } - - - D3D11Presenter:: D3D11Presenter( + D3D11PresentDevice::D3D11PresentDevice( IDXGIObject* pContainer, ID3D11Device* pDevice) : m_container(pContainer), m_device(pDevice) { @@ -33,76 +11,27 @@ namespace dxvk { } - D3D11Presenter::~D3D11Presenter() { + D3D11PresentDevice::~D3D11PresentDevice() { } - ULONG STDMETHODCALLTYPE D3D11Presenter::AddRef() { + ULONG STDMETHODCALLTYPE D3D11PresentDevice::AddRef() { return m_container->AddRef(); } - ULONG STDMETHODCALLTYPE D3D11Presenter::Release() { + ULONG STDMETHODCALLTYPE D3D11PresentDevice::Release() { return m_container->Release(); } - HRESULT STDMETHODCALLTYPE D3D11Presenter::QueryInterface(REFIID riid, void** ppvObject) { + HRESULT STDMETHODCALLTYPE D3D11PresentDevice::QueryInterface(REFIID riid, void** ppvObject) { return m_container->QueryInterface(riid, ppvObject); } - - - HRESULT STDMETHODCALLTYPE D3D11Presenter::CreateSwapChainBackBuffer( - const DXGI_SWAP_CHAIN_DESC1* pSwapChainDesc, - IDXGIVkBackBuffer** ppInterface) { - D3D11_COMMON_TEXTURE_DESC desc; - desc.Width = std::max(pSwapChainDesc->Width, 1u); - desc.Height = std::max(pSwapChainDesc->Height, 1u); - desc.Depth = 1; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = pSwapChainDesc->Format; - desc.SampleDesc = pSwapChainDesc->SampleDesc; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_RENDER_TARGET - | D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - - if (pSwapChainDesc->BufferUsage & DXGI_USAGE_UNORDERED_ACCESS) - desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS; - - try { - *ppInterface = ref(new D3D11VkBackBuffer( - new D3D11Texture2D(static_cast(m_device), &desc))); - return S_OK; - } catch (const DxvkError& e) { - Logger::err(e.message()); - return E_FAIL; - } - } - - - HRESULT STDMETHODCALLTYPE D3D11Presenter::FlushRenderingCommands() { - Com deviceContext = nullptr; - m_device->GetImmediateContext(&deviceContext); - - // The presentation code is run from the main rendering thread - // rather than the command stream thread, so we synchronize. - auto immediateContext = static_cast(deviceContext.ptr()); - immediateContext->Flush(); - immediateContext->SynchronizeCsThread(); - return S_OK; - } - - - HRESULT STDMETHODCALLTYPE D3D11Presenter::GetDevice(REFGUID riid, void** ppvDevice) { - return m_device->QueryInterface(riid, ppvDevice); - } - HRESULT STDMETHODCALLTYPE D3D11Presenter::CreateSwapChainForHwnd( + HRESULT STDMETHODCALLTYPE D3D11PresentDevice::CreateSwapChainForHwnd( HWND hWnd, const DXGI_SWAP_CHAIN_DESC1* pDesc, IDXGIVkSwapChain** ppSwapChain) { diff --git a/src/d3d11/d3d11_present.h b/src/d3d11/d3d11_present.h index 58d0dd7dc..d0b727ce2 100644 --- a/src/d3d11/d3d11_present.h +++ b/src/d3d11/d3d11_present.h @@ -5,46 +5,25 @@ #include "d3d11_include.h" #include "d3d11_swapchain.h" -#include "d3d11_texture.h" namespace dxvk { class D3D11Device; - class D3D11VkBackBuffer : public ComObject { - - public: - - D3D11VkBackBuffer(D3D11Texture2D* pTexture); - ~D3D11VkBackBuffer(); - - HRESULT STDMETHODCALLTYPE QueryInterface( - REFIID riid, - void** ppvObject) final; - - Rc GetDXVKImage() final; - - public: - - D3D11Texture2D* m_texture; - - }; - - /** * \brief Present device * * Wires up some swap chain related * functions to the D3D11 device. */ - class D3D11Presenter final : public IDXGIVkPresenter { + class D3D11PresentDevice final : public IDXGIVkPresentDevice { public: - D3D11Presenter( + D3D11PresentDevice( IDXGIObject* pContainer, ID3D11Device* pDevice); - ~D3D11Presenter(); + ~D3D11PresentDevice(); ULONG STDMETHODCALLTYPE AddRef(); @@ -54,16 +33,6 @@ namespace dxvk { REFIID riid, void** ppvObject); - HRESULT STDMETHODCALLTYPE CreateSwapChainBackBuffer( - const DXGI_SWAP_CHAIN_DESC1* pSwapChainDesc, - IDXGIVkBackBuffer** ppInterface); - - HRESULT STDMETHODCALLTYPE FlushRenderingCommands(); - - HRESULT STDMETHODCALLTYPE GetDevice( - REFGUID riid, - void** ppvDevice); - HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd( HWND hWnd, const DXGI_SWAP_CHAIN_DESC1* pDesc, diff --git a/src/dxgi/dxgi_interfaces.h b/src/dxgi/dxgi_interfaces.h index 96b676a62..7ae275813 100644 --- a/src/dxgi/dxgi_interfaces.h +++ b/src/dxgi/dxgi_interfaces.h @@ -150,41 +150,9 @@ IDXGIVkBackBuffer : public IUnknown { * back buffer interface. */ MIDL_INTERFACE("79352328-16f2-4f81-9746-9c2e2ccd43cf") -IDXGIVkPresenter : public IUnknown { +IDXGIVkPresentDevice : public IUnknown { static const GUID guid; - /** - * \brief Creates a swap chain back buffer - * - * \param [in] pSwapChainDesc Swap chain description - * \param [out] ppBackBuffer The swap chain back buffer - * \returns \c S_OK on success - */ - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainBackBuffer( - const DXGI_SWAP_CHAIN_DESC1* pSwapChainDesc, - IDXGIVkBackBuffer** ppBackBuffer) = 0; - - /** - * \brief Flushes the immediate context - * - * Used by the swap chain's \c Present method to - * ensure that all rendering commands get dispatched - * before presenting the swap chain's back buffer. - * \returns \c S_OK on success - */ - virtual HRESULT STDMETHODCALLTYPE FlushRenderingCommands() = 0; - - /** - * \brief Underlying DXVK device - * - * \param [in] riid Device type - * \param [in] ppDevice device - * \returns DXVK device handle - */ - virtual HRESULT STDMETHODCALLTYPE GetDevice( - REFGUID riid, - void** ppDevice) = 0; - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd( HWND hWnd, const DXGI_SWAP_CHAIN_DESC1* pDesc, @@ -337,7 +305,7 @@ IDXGIVkInteropDevice : public IUnknown { struct __declspec(uuid("907bf281-ea3c-43b4-a8e4-9f231107b4ff")) IDXGIVkAdapter; struct __declspec(uuid("7a622cf6-627a-46b2-b52f-360ef3da831c")) IDXGIVkDevice; struct __declspec(uuid("5679becd-8547-4d93-96a1-e61a1ce7ef37")) IDXGIVkBackBuffer; -struct __declspec(uuid("79352328-16f2-4f81-9746-9c2e2ccd43cf")) IDXGIVkPresenter; +struct __declspec(uuid("79352328-16f2-4f81-9746-9c2e2ccd43cf")) IDXGIVkPresentDevice; struct __declspec(uuid("e2ef5fa5-dc21-4af7-90c4-f67ef6a09323")) IDXGIVkInteropDevice; struct __declspec(uuid("5546cf8c-77e7-4341-b05d-8d4d5000e77d")) IDXGIVkInteropSurface; struct __declspec(uuid("104001a6-7f36-4957-b932-86ade9567d91")) IDXGIVkSwapChain; @@ -345,7 +313,7 @@ struct __declspec(uuid("104001a6-7f36-4957-b932-86ade9567d91")) IDXGIVkSwapChain DXVK_DEFINE_GUID(IDXGIVkAdapter); DXVK_DEFINE_GUID(IDXGIVkDevice); DXVK_DEFINE_GUID(IDXGIVkBackBuffer); -DXVK_DEFINE_GUID(IDXGIVkPresenter); +DXVK_DEFINE_GUID(IDXGIVkPresentDevice); DXVK_DEFINE_GUID(IDXGIVkInteropDevice); DXVK_DEFINE_GUID(IDXGIVkInteropSurface); DXVK_DEFINE_GUID(IDXGIVkSwapChain); diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index 70413e7d0..847a2256b 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -16,10 +16,12 @@ 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(IDXGIVkPresenter), - reinterpret_cast(&m_presentDevice)))) + if (FAILED(pDevice->QueryInterface(__uuidof(IDXGIVkPresentDevice), + reinterpret_cast(&presentDevice)))) throw DxvkError("DXGI: DxgiSwapChain: Invalid device"); // Retrieve the adapter, which is going @@ -54,7 +56,7 @@ namespace dxvk { if (!m_descFs.Windowed && FAILED(EnterFullscreenMode(nullptr))) throw DxvkError("DXGI: DxgiSwapChain: Failed to set initial fullscreen state"); - if (FAILED(m_presentDevice->CreateSwapChainForHwnd(m_window, &m_desc, &m_presenter))) + if (FAILED(presentDevice->CreateSwapChainForHwnd(m_window, &m_desc, &m_presenter))) throw DxvkError("DXGI: DxgiSwapChain: Failed to create presenter"); } diff --git a/src/dxgi/dxgi_swapchain.h b/src/dxgi/dxgi_swapchain.h index 88a4e477a..232d0602a 100644 --- a/src/dxgi/dxgi_swapchain.h +++ b/src/dxgi/dxgi_swapchain.h @@ -137,7 +137,6 @@ namespace dxvk { Com m_factory; Com m_adapter; Com m_device; - Com m_presentDevice; HWND m_window; DXGI_SWAP_CHAIN_DESC1 m_desc; diff --git a/src/util/com/com_guid.cpp b/src/util/com/com_guid.cpp index f1d429c68..9ccb03e7e 100644 --- a/src/util/com/com_guid.cpp +++ b/src/util/com/com_guid.cpp @@ -7,7 +7,7 @@ const GUID IDXGIVkAdapter::guid = {0x907bf281,0xea3c,0x43b4,{0xa8,0xe4,0x9f,0x23,0x11,0x07,0xb4,0xff}}; const GUID IDXGIVkDevice::guid = {0x7a622cf6,0x627a,0x46b2,{0xb5,0x2f,0x36,0x0e,0xf3,0xda,0x83,0x1c}}; const GUID IDXGIVkBackBuffer::guid = {0x5679becd,0x8547,0x4d93,{0x96,0xa1,0xe6,0x1a,0x1c,0xe7,0xef,0x37}}; -const GUID IDXGIVkPresenter::guid = {0x79352328,0x16f2,0x4f81,{0x97,0x46,0x9c,0x2e,0x2c,0xcd,0x43,0xcf}}; +const GUID IDXGIVkPresentDevice::guid = {0x79352328,0x16f2,0x4f81,{0x97,0x46,0x9c,0x2e,0x2c,0xcd,0x43,0xcf}}; const GUID IDXGIVkInteropDevice::guid = {0xe2ef5fa5,0xdc21,0x4af7,{0x90,0xc4,0xf6,0x7e,0xf6,0xa0,0x93,0x23}}; const GUID IDXGIVkInteropSurface::guid = {0x5546cf8c,0x77e7,0x4341,{0xb0,0x5d,0x8d,0x4d,0x50,0x00,0xe7,0x7d}}; const GUID IDXGIVkSwapChain::guid = {0x104001a6,0x7f36,0x4957,{0xb9,0x32,0x86,0xad,0xe9,0x56,0x7d,0x91}};