From 4c73f2d3fd5305b82d3413ebeab74cc566b57f33 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 2 Feb 2020 15:07:25 -0800 Subject: Updated swap chain creation functions to use NativeWindow struct --- .../include/SwapChainVkImpl.hpp | 2 +- .../interface/EngineFactoryVk.h | 26 ++++++++++++++++----- .../GraphicsEngineVulkan/src/EngineFactoryVk.cpp | 27 +++------------------- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 26 ++++++++------------- 4 files changed, 34 insertions(+), 47 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp index 996817ca..e58c5f71 100644 --- a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp @@ -49,7 +49,7 @@ public: const SwapChainDesc& SwapChainDesc, class RenderDeviceVkImpl* pRenderDeviceVk, class DeviceContextVkImpl* pDeviceContextVk, - void* pNativeWndHandle); + const NativeWindow& Window); ~SwapChainVkImpl(); virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; diff --git a/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h b/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h index eb9c1f58..be79c99f 100644 --- a/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h @@ -66,22 +66,36 @@ static const INTERFACE_ID IID_EngineFactoryVk = DILIGENT_BEGIN_INTERFACE(IEngineFactoryVk, IEngineFactory) { + /// Creates a render device and device contexts for Vulkan backend + + /// \param [in] EngineCI - Engine creation attributes. + /// \param [out] ppDevice - Address of the memory location where pointer to + /// the created device will be written + /// \param [out] ppContexts - Address of the memory location where pointers to + /// the contexts will be written. Immediate context goes at + /// position 0. If EngineCI.NumDeferredContexts > 0, + /// pointers to the deferred contexts are written afterwards. VIRTUAL void METHOD(CreateDeviceAndContextsVk)(THIS_ const EngineVkCreateInfo REF EngineCI, IRenderDevice** ppDevice, IDeviceContext** ppContexts) PURE; - //virtual void AttachToVulkanDevice(void *pVkNativeDevice, - // class ICommandQueueVk *pCommandQueue, - // const EngineVkCreateInfo& EngineCI, - // IRenderDevice **ppDevice, - // IDeviceContext **ppContexts) = 0; + /// Creates a swap chain for Vulkan-based engine implementation + + /// \param [in] pDevice - Pointer to the render device + /// \param [in] pImmediateContext - Pointer to the immediate device context + /// \param [in] SCDesc - Swap chain description + /// \param [in] Window - Platform-specific native window description that + /// the swap chain will be associated with. + /// + /// \param [out] ppSwapChain - Address of the memory location where pointer to the new + /// swap chain will be written VIRTUAL void METHOD(CreateSwapChainVk)(THIS_ IRenderDevice* pDevice, IDeviceContext* pImmediateContext, const SwapChainDesc REF SwapChainDesc, - void* pNativeWndHandle, + const NativeWindow REF Window, ISwapChain** ppSwapChain) PURE; }; DILIGENT_END_INTERFACE diff --git a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp index 77a6f49b..f695b372 100644 --- a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp @@ -74,22 +74,14 @@ public: virtual void DILIGENT_CALL_TYPE CreateSwapChainVk(IRenderDevice* pDevice, IDeviceContext* pImmediateContext, const SwapChainDesc& SwapChainDesc, - void* pNativeWndHandle, + const NativeWindow& Window, ISwapChain** ppSwapChain) override final; private: std::function OnRenderDeviceCreated = nullptr; }; -/// Creates render device and device contexts for Vulkan backend -/// \param [in] EngineCI - Engine creation attributes. -/// \param [out] ppDevice - Address of the memory location where pointer to -/// the created device will be written -/// \param [out] ppContexts - Address of the memory location where pointers to -/// the contexts will be written. Immediate context goes at -/// position 0. If EngineCI.NumDeferredContexts > 0, -/// pointers to the deferred contexts are written afterwards. void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& _EngineCI, IRenderDevice** ppDevice, IDeviceContext** ppContexts) @@ -317,23 +309,10 @@ void EngineFactoryVkImpl::AttachToVulkanDevice(std::shared_ptr(pImmediateContext); auto& RawMemAllocator = GetRawAllocator(); - auto* pSwapChainVk = NEW_RC_OBJ(RawMemAllocator, "SwapChainVkImpl instance", SwapChainVkImpl)(SCDesc, pDeviceVk, pDeviceContextVk, pNativeWndHandle); + auto* pSwapChainVk = NEW_RC_OBJ(RawMemAllocator, "SwapChainVkImpl instance", SwapChainVkImpl)(SCDesc, pDeviceVk, pDeviceContextVk, Window); pSwapChainVk->QueryInterface(IID_SwapChain, reinterpret_cast(ppSwapChain)); } catch (const std::runtime_error&) diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 2a906a2b..d4282068 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -40,7 +40,7 @@ SwapChainVkImpl::SwapChainVkImpl(IReferenceCounters* pRefCounters, const SwapChainDesc& SCDesc, RenderDeviceVkImpl* pRenderDeviceVk, DeviceContextVkImpl* pDeviceContextVk, - void* pNativeWndHandle) : + const NativeWindow& Window) : // clang-format off TSwapChainBase {pRefCounters, pRenderDeviceVk, pDeviceContextVk, SCDesc}, m_VulkanInstance {pRenderDeviceVk->GetVulkanInstance()}, @@ -55,50 +55,44 @@ SwapChainVkImpl::SwapChainVkImpl(IReferenceCounters* pRefCounters, surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; surfaceCreateInfo.hinstance = GetModuleHandle(NULL); - surfaceCreateInfo.hwnd = (HWND)pNativeWndHandle; + surfaceCreateInfo.hwnd = (HWND)Window.hWnd; auto err = vkCreateWin32SurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface); #elif defined(VK_USE_PLATFORM_ANDROID_KHR) VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; - surfaceCreateInfo.window = (ANativeWindow*)pNativeWndHandle; + surfaceCreateInfo.window = (ANativeWindow*)Window.pAWindow; auto err = vkCreateAndroidSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface); #elif defined(VK_USE_PLATFORM_IOS_MVK) VkIOSSurfaceCreateInfoMVK surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK; - surfaceCreateInfo.pView = pNativeWndHandle; + surfaceCreateInfo.pView = Window.pNSWindow; auto err = vkCreateIOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface); #elif defined(VK_USE_PLATFORM_MACOS_MVK) VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; - surfaceCreateInfo.pView = pNativeWndHandle; + surfaceCreateInfo.pView = Window.pNSView; auto err = vkCreateMacOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; - surfaceCreateInfo.display = display; - surfaceCreatem_VkSurface = window; + surfaceCreateInfo.display = Window.pDisplay; + surfaceCreatem_VkSurface = Window.pWindow; err = vkCreateWaylandSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface); #elif defined(VK_USE_PLATFORM_XCB_KHR) VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {}; - surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; - struct XCBInfo - { - xcb_connection_t* connection = nullptr; - uint32_t window = 0; - }; - XCBInfo& info = *reinterpret_cast(pNativeWndHandle); - surfaceCreateInfo.connection = info.connection; - surfaceCreateInfo.window = info.window; + surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + surfaceCreateInfo.connection = Window.pXCBConnection; + surfaceCreateInfo.window = Window.pWindow; auto err = vkCreateXcbSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface); #endif -- cgit v1.2.3