From 3128f4ea8e90a2053d420c0c78235c8befb718f5 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 22 Jan 2023 20:04:39 +0100 Subject: [PATCH] [dxgi] Implement IDXGIVkInteropFactory for DXGI factory --- src/dxgi/dxgi_factory.cpp | 44 +++++++++++++++++++++++++++++++++++++++ src/dxgi/dxgi_factory.h | 30 +++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/dxgi/dxgi_factory.cpp b/src/dxgi/dxgi_factory.cpp index d1568663..63522186 100644 --- a/src/dxgi/dxgi_factory.cpp +++ b/src/dxgi/dxgi_factory.cpp @@ -5,8 +5,47 @@ namespace dxvk { + DxgiVkFactory::DxgiVkFactory(DxgiFactory* pFactory) + : m_factory(pFactory) { + + } + + + ULONG STDMETHODCALLTYPE DxgiVkFactory::AddRef() { + return m_factory->AddRef(); + } + + + ULONG STDMETHODCALLTYPE DxgiVkFactory::Release() { + return m_factory->Release(); + } + + + HRESULT STDMETHODCALLTYPE DxgiVkFactory::QueryInterface( + REFIID riid, + void** ppvObject) { + return m_factory->QueryInterface(riid, ppvObject); + } + + + void STDMETHODCALLTYPE DxgiVkFactory::GetVulkanInstance( + VkInstance* pInstance, + PFN_vkGetInstanceProcAddr* ppfnVkGetInstanceProcAddr) { + auto instance = m_factory->GetDXVKInstance(); + + if (pInstance) + *pInstance = instance->handle(); + + if (ppfnVkGetInstanceProcAddr) + *ppfnVkGetInstanceProcAddr = instance->vki()->getLoaderProc(); + } + + + + DxgiFactory::DxgiFactory(UINT Flags) : m_instance (new DxvkInstance()), + m_interop (this), m_options (m_instance->config()), m_monitorInfo (this, m_options), m_flags (Flags) { @@ -40,6 +79,11 @@ namespace dxvk { return S_OK; } + if (riid == __uuidof(IDXGIVkInteropFactory)) { + *ppvObject = ref(&m_interop); + return S_OK; + } + if (riid == __uuidof(IDXGIVkMonitorInfo)) { *ppvObject = ref(&m_monitorInfo); return S_OK; diff --git a/src/dxgi/dxgi_factory.h b/src/dxgi/dxgi_factory.h index 4d75c277..72af2f3c 100644 --- a/src/dxgi/dxgi_factory.h +++ b/src/dxgi/dxgi_factory.h @@ -9,7 +9,34 @@ #include "../dxvk/dxvk_instance.h" namespace dxvk { - + + class DxgiFactory; + + class DxgiVkFactory : public IDXGIVkInteropFactory { + + public: + + DxgiVkFactory(DxgiFactory* pFactory); + + ULONG STDMETHODCALLTYPE AddRef(); + + ULONG STDMETHODCALLTYPE Release(); + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void** ppvObject); + + void STDMETHODCALLTYPE GetVulkanInstance( + VkInstance* pInstance, + PFN_vkGetInstanceProcAddr* ppfnVkGetInstanceProcAddr); + + private: + + DxgiFactory* m_factory; + + }; + + class DxgiFactory : public DxgiObject { public: @@ -146,6 +173,7 @@ namespace dxvk { private: Rc m_instance; + DxgiVkFactory m_interop; DxgiOptions m_options; DxgiMonitorInfo m_monitorInfo; UINT m_flags;