From 3a9e975a7130960942cc3bd1eab4e0b3ff62897d Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 27 Oct 2022 19:36:56 +0200 Subject: [PATCH] [dxgi] Implement DxgiSurfaceFactory --- src/d3d11/meson.build | 1 + src/dxgi/dxgi_surface.cpp | 45 +++++++++++++++++++++++++++++++++++++++ src/dxgi/dxgi_surface.h | 43 +++++++++++++++++++++++++++++++++++++ src/dxgi/meson.build | 1 + 4 files changed, 90 insertions(+) create mode 100644 src/dxgi/dxgi_surface.cpp create mode 100644 src/dxgi/dxgi_surface.h diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index f231fcf49..6067f7697 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -3,6 +3,7 @@ d3d11_res = wrc_generator.process('version.rc') dxgi_common_src = [ '../dxgi/dxgi_format.cpp', '../dxgi/dxgi_monitor.cpp', + '../dxgi/dxgi_surface.cpp', '../dxgi/dxgi_swapchain.cpp', ] diff --git a/src/dxgi/dxgi_surface.cpp b/src/dxgi/dxgi_surface.cpp new file mode 100644 index 000000000..d18abd648 --- /dev/null +++ b/src/dxgi/dxgi_surface.cpp @@ -0,0 +1,45 @@ +#include "dxgi_surface.h" + +#include "../wsi/wsi_window.h" + +namespace dxvk { + + DxgiSurfaceFactory::DxgiSurfaceFactory(PFN_vkGetInstanceProcAddr vulkanLoaderProc, HWND hWnd) + : m_vkGetInstanceProcAddr(vulkanLoaderProc), m_window(hWnd) { + + } + + + DxgiSurfaceFactory::~DxgiSurfaceFactory() { + + } + + + HRESULT STDMETHODCALLTYPE DxgiSurfaceFactory::QueryInterface( + REFIID riid, + void** ppvObject) { + if (ppvObject == nullptr) + return E_POINTER; + + *ppvObject = nullptr; + + if (riid == __uuidof(IUnknown) + || riid == __uuidof(IDXGIVkSurfaceFactory)) { + *ppvObject = ref(this); + return S_OK; + } + + Logger::warn("DxgiSurfaceFactory::QueryInterface: Unknown interface query"); + Logger::warn(str::format(riid)); + return E_NOINTERFACE; + } + + + VkResult STDMETHODCALLTYPE DxgiSurfaceFactory::CreateSurface( + VkInstance Instance, + VkPhysicalDevice Adapter, + VkSurfaceKHR* pSurface) { + return wsi::createSurface(m_window, m_vkGetInstanceProcAddr, Instance, pSurface); + } + +} \ No newline at end of file diff --git a/src/dxgi/dxgi_surface.h b/src/dxgi/dxgi_surface.h new file mode 100644 index 000000000..25a845fdd --- /dev/null +++ b/src/dxgi/dxgi_surface.h @@ -0,0 +1,43 @@ +#pragma once + +#include "../util/com/com_object.h" + +#include "../vulkan/vulkan_loader.h" + +#include "dxgi_interfaces.h" + +namespace dxvk { + + /** + * \brief Surface factory + * + * Provides a way to transparently create a + * Vulkan surface for a given platform window. + */ + class DxgiSurfaceFactory : public ComObject { + + public: + + DxgiSurfaceFactory( + PFN_vkGetInstanceProcAddr vulkanLoaderProc, + HWND hWnd); + + ~DxgiSurfaceFactory(); + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void** ppvObject); + + VkResult STDMETHODCALLTYPE CreateSurface( + VkInstance Instance, + VkPhysicalDevice Adapter, + VkSurfaceKHR* pSurface); + + private: + + PFN_vkGetInstanceProcAddr m_vkGetInstanceProcAddr; + HWND m_window; + + }; + +} \ No newline at end of file diff --git a/src/dxgi/meson.build b/src/dxgi/meson.build index f0c1b2e9c..a6e83b54e 100644 --- a/src/dxgi/meson.build +++ b/src/dxgi/meson.build @@ -9,6 +9,7 @@ dxgi_src = [ 'dxgi_monitor.cpp', 'dxgi_options.cpp', 'dxgi_output.cpp', + 'dxgi_surface.cpp', 'dxgi_swapchain.cpp', ]