git.s-ol.nu forks/DiligentCore / 4c73f2d
Updated swap chain creation functions to use NativeWindow struct assiduous 3 years ago
18 changed file(s) with 75 addition(s) and 82 deletion(s). Raw diff Collapse all Expand all
2929 /// \file
3030 /// Diligent API information
3131
32 #define DILIGENT_API_VERSION 240053
32 #define DILIGENT_API_VERSION 240054
3333
3434 #include "../../../Primitives/interface/BasicTypes.h"
3535
4646 const FullScreenModeDesc& FSDesc,
4747 class RenderDeviceD3D11Impl* pRenderDeviceD3D11,
4848 class DeviceContextD3D11Impl* pDeviceContextD3D11,
49 void* pNativeWndHandle);
49 const NativeWindow& Window);
5050 ~SwapChainD3D11Impl();
5151
5252 virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
7777 /// \param [in] pImmediateContext - Pointer to the immediate device context.
7878 /// \param [in] SCDesc - Swap chain description.
7979 /// \param [in] FSDesc - Fullscreen mode description.
80 /// \param [in] pNativeWndHandle - Platform-specific native handle of the window
81 /// the swap chain will be associated with:
82 /// * On Win32 platform, this should be the window handle (HWND)
83 /// * On Universal Windows Platform, this should be the reference
84 /// to the core window (Windows::UI::Core::CoreWindow)
80 /// \param [in] Window - Platform-specific native window description that
81 /// the swap chain will be associated with:
82 /// * On Win32 platform, this is the window handle (HWND)
83 /// * On Universal Windows Platform, this is the reference
84 /// to the core window (Windows::UI::Core::CoreWindow)
8585 ///
8686 /// \param [out] ppSwapChain - Address of the memory location where pointer to the new
8787 /// swap chain will be written.
9090 IDeviceContext* pImmediateContext,
9191 const SwapChainDesc REF SCDesc,
9292 const FullScreenModeDesc REF FSDesc,
93 void* pNativeWndHandle,
93 const NativeWindow REF Window,
9494 ISwapChain** ppSwapChain) PURE;
9595
9696
2828 SwapChainDesc SwapChainDesc;
2929 RefCntAutoPtr<ISwapChain> pSwapChain;
3030 pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &pRenderDevice, &pImmediateContext);
31 pFactoryD3D11->CreateSwapChainD3D11(pRenderDevice, pImmediateContext, SwapChainDesc, hWnd, &pSwapChain);
31 NativeWindow Window;
32 Window.hWnd = hWnd;
33 pFactoryD3D11->CreateSwapChainD3D11(pRenderDevice, pImmediateContext, SwapChainDesc, Window, &pSwapChain);
3234 ```
3335
3436 Alternatively, the engine can be initialized by attaching to existing D3D11 device and immediate context (see below).
6565 IDeviceContext* pImmediateContext,
6666 const SwapChainDesc& SCDesc,
6767 const FullScreenModeDesc& FSDesc,
68 void* pNativeWndHandle,
68 const NativeWindow& Window,
6969 ISwapChain** ppSwapChain) override final;
7070
7171 virtual void DILIGENT_CALL_TYPE AttachToD3D11Device(void* pd3d11NativeDevice,
283283 IDeviceContext* pImmediateContext,
284284 const SwapChainDesc& SCDesc,
285285 const FullScreenModeDesc& FSDesc,
286 void* pNativeWndHandle,
286 const NativeWindow& Window,
287287 ISwapChain** ppSwapChain)
288288 {
289289 VERIFY(ppSwapChain, "Null pointer provided");
298298 auto* pDeviceContextD3D11 = ValidatedCast<DeviceContextD3D11Impl>(pImmediateContext);
299299 auto& RawMemAllocator = GetRawAllocator();
300300
301 auto* pSwapChainD3D11 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D11Impl instance", SwapChainD3D11Impl)(SCDesc, FSDesc, pDeviceD3D11, pDeviceContextD3D11, pNativeWndHandle);
301 auto* pSwapChainD3D11 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D11Impl instance", SwapChainD3D11Impl)(SCDesc, FSDesc, pDeviceD3D11, pDeviceContextD3D11, Window);
302302 pSwapChainD3D11->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));
303303 }
304304 catch (const std::runtime_error&)
3838 const FullScreenModeDesc& FSDesc,
3939 RenderDeviceD3D11Impl* pRenderDeviceD3D11,
4040 DeviceContextD3D11Impl* pDeviceContextD3D11,
41 void* pNativeWndHandle) :
41 const NativeWindow& Window) :
4242 // clang-format off
4343 TSwapChainBase
4444 {
4747 pDeviceContextD3D11,
4848 SCDesc,
4949 FSDesc,
50 pNativeWndHandle
50 Window
5151 }
5252 // clang-format on
5353 {
4747 const FullScreenModeDesc& FSDesc,
4848 class RenderDeviceD3D12Impl* pRenderDeviceD3D12,
4949 class DeviceContextD3D12Impl* pDeviceContextD3D12,
50 void* pNativeWndHandle);
50 const NativeWindow& Window);
5151 ~SwapChainD3D12Impl();
5252
5353 virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
113113 /// \param [in] pImmediateContext - Pointer to the immediate device context.
114114 /// \param [in] SCDesc - Swap chain description.
115115 /// \param [in] FSDesc - Fullscreen mode description.
116 /// \param [in] pNativeWndHandle - Platform-specific native handle of the window
117 /// the swap chain will be associated with:
118 /// * On Win32 platform, this should be the window handle (HWND)
119 /// * On Universal Windows Platform, this should be the reference
120 /// to the core window (Windows::UI::Core::CoreWindow)
116 /// \param [in] Window - Platform-specific native window description that
117 /// the swap chain will be associated with:
118 /// * On Win32 platform, this is the window handle (HWND)
119 /// * On Universal Windows Platform, this is the reference
120 /// to the core window (Windows::UI::Core::CoreWindow)
121121 ///
122122 /// \param [out] ppSwapChain - Address of the memory location where pointer to the new
123123 /// swap chain will be written
126126 IDeviceContext* pImmediateContext,
127127 const SwapChainDesc REF SwapChainDesc,
128128 const FullScreenModeDesc REF FSDesc,
129 void* pNativeWndHandle,
129 const NativeWindow REF Window,
130130 ISwapChain** ppSwapChain) PURE;
131131
132132
2727 SwapChainDesc SwapChainDesc;
2828 RefCntAutoPtr<ISwapChain> pSwapChain;
2929 pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &pRenderDevice, &pImmediateContext);
30 pFactoryD3D12->CreateSwapChainD3D12(pRenderDevice, pImmediateContext, SwapChainDesc, hWnd, &pSwapChain);
30 NativeWindow Window;
31 Window.hWnd = hWnd;
32 pFactoryD3D12->CreateSwapChainD3D12(pRenderDevice, pImmediateContext, SwapChainDesc, Window, &pSwapChain);
3133 ```
3234
3335 Alternatively, the engine can be initialized by attaching to existing Direct3D12 device (see below).
8484 IDeviceContext* pImmediateContext,
8585 const SwapChainDesc& SwapChainDesc,
8686 const FullScreenModeDesc& FSDesc,
87 void* pNativeWndHandle,
87 const NativeWindow& Window,
8888 ISwapChain** ppSwapChain) override final;
8989
9090 virtual void DILIGENT_CALL_TYPE EnumerateAdapters(DIRECT3D_FEATURE_LEVEL MinFeatureLevel,
446446 IDeviceContext* pImmediateContext,
447447 const SwapChainDesc& SCDesc,
448448 const FullScreenModeDesc& FSDesc,
449 void* pNativeWndHandle,
449 const NativeWindow& Window,
450450 ISwapChain** ppSwapChain)
451451 {
452452 VERIFY(ppSwapChain, "Null pointer provided");
461461 auto* pDeviceContextD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pImmediateContext);
462462 auto& RawMemAllocator = GetRawAllocator();
463463
464 auto* pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, FSDesc, pDeviceD3D12, pDeviceContextD3D12, pNativeWndHandle);
464 auto* pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, FSDesc, pDeviceD3D12, pDeviceContextD3D12, Window);
465465 pSwapChainD3D12->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));
466466 }
467467 catch (const std::runtime_error&)
4040 const FullScreenModeDesc& FSDesc,
4141 RenderDeviceD3D12Impl* pRenderDeviceD3D12,
4242 DeviceContextD3D12Impl* pDeviceContextD3D12,
43 void* pNativeWndHandle) :
43 const NativeWindow& Window) :
4444 // clang-format off
4545 TSwapChainBase
4646 {
4949 pDeviceContextD3D12,
5050 SCDesc,
5151 FSDesc,
52 pNativeWndHandle
52 Window
5353 },
5454 m_pBackBufferRTV(STD_ALLOCATOR_RAW_MEM(RefCntAutoPtr<ITextureView>, GetRawAllocator(), "Allocator for vector<RefCntAutoPtr<ITextureView>>"))
5555 // clang-format on
4646 IDeviceContext* pDeviceContext,
4747 const SwapChainDesc& SCDesc,
4848 const FullScreenModeDesc& FSDesc,
49 void* pNativeWndHandle) :
49 const NativeWindow& Window) :
5050 // clang-format off
5151 TBase{pRefCounters, pDevice, pDeviceContext, SCDesc},
5252 m_FSDesc {FSDesc},
53 m_pNativeWndHandle {pNativeWndHandle}
53 m_Window {Window}
5454 // clang-format on
5555 {}
5656
7373 void CreateDXGISwapChain(IUnknown* pD3D11DeviceOrD3D12CmdQueue)
7474 {
7575 #if PLATFORM_WIN32
76 auto hWnd = reinterpret_cast<HWND>(m_pNativeWndHandle);
76 auto hWnd = reinterpret_cast<HWND>(m_Window.hWnd);
7777 if (m_SwapChainDesc.Width == 0 || m_SwapChainDesc.Height == 0)
7878 {
7979 RECT rc;
193193
194194 hr = factory->CreateSwapChainForCoreWindow(
195195 pD3D11DeviceOrD3D12CmdQueue,
196 reinterpret_cast<IUnknown*>(m_pNativeWndHandle),
196 reinterpret_cast<IUnknown*>(m_Window.pWindow),
197197 &swapChainDesc,
198198 nullptr,
199199 &pSwapChain1);
241241
242242 FullScreenModeDesc m_FSDesc;
243243 CComPtr<DXGISwapChainType> m_pSwapChain;
244 void* m_pNativeWndHandle;
244 NativeWindow m_Window;
245245 };
246246
247247 } // namespace Diligent
4848 const SwapChainDesc& SwapChainDesc,
4949 class RenderDeviceVkImpl* pRenderDeviceVk,
5050 class DeviceContextVkImpl* pDeviceContextVk,
51 void* pNativeWndHandle);
51 const NativeWindow& Window);
5252 ~SwapChainVkImpl();
5353
5454 virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
6565
6666 DILIGENT_BEGIN_INTERFACE(IEngineFactoryVk, IEngineFactory)
6767 {
68 /// Creates a render device and device contexts for Vulkan backend
69
70 /// \param [in] EngineCI - Engine creation attributes.
71 /// \param [out] ppDevice - Address of the memory location where pointer to
72 /// the created device will be written
73 /// \param [out] ppContexts - Address of the memory location where pointers to
74 /// the contexts will be written. Immediate context goes at
75 /// position 0. If EngineCI.NumDeferredContexts > 0,
76 /// pointers to the deferred contexts are written afterwards.
6877 VIRTUAL void METHOD(CreateDeviceAndContextsVk)(THIS_
6978 const EngineVkCreateInfo REF EngineCI,
7079 IRenderDevice** ppDevice,
7180 IDeviceContext** ppContexts) PURE;
7281
73 //virtual void AttachToVulkanDevice(void *pVkNativeDevice,
74 // class ICommandQueueVk *pCommandQueue,
75 // const EngineVkCreateInfo& EngineCI,
76 // IRenderDevice **ppDevice,
77 // IDeviceContext **ppContexts) = 0;
7882
83 /// Creates a swap chain for Vulkan-based engine implementation
84
85 /// \param [in] pDevice - Pointer to the render device
86 /// \param [in] pImmediateContext - Pointer to the immediate device context
87 /// \param [in] SCDesc - Swap chain description
88 /// \param [in] Window - Platform-specific native window description that
89 /// the swap chain will be associated with.
90 ///
91 /// \param [out] ppSwapChain - Address of the memory location where pointer to the new
92 /// swap chain will be written
7993 VIRTUAL void METHOD(CreateSwapChainVk)(THIS_
8094 IRenderDevice* pDevice,
8195 IDeviceContext* pImmediateContext,
8296 const SwapChainDesc REF SwapChainDesc,
83 void* pNativeWndHandle,
97 const NativeWindow REF Window,
8498 ISwapChain** ppSwapChain) PURE;
8599 };
86100 DILIGENT_END_INTERFACE
7373 virtual void DILIGENT_CALL_TYPE CreateSwapChainVk(IRenderDevice* pDevice,
7474 IDeviceContext* pImmediateContext,
7575 const SwapChainDesc& SwapChainDesc,
76 void* pNativeWndHandle,
76 const NativeWindow& Window,
7777 ISwapChain** ppSwapChain) override final;
7878
7979 private:
8080 std::function<void(RenderDeviceVkImpl*)> OnRenderDeviceCreated = nullptr;
8181 };
8282
83 /// Creates render device and device contexts for Vulkan backend
84
85 /// \param [in] EngineCI - Engine creation attributes.
86 /// \param [out] ppDevice - Address of the memory location where pointer to
87 /// the created device will be written
88 /// \param [out] ppContexts - Address of the memory location where pointers to
89 /// the contexts will be written. Immediate context goes at
90 /// position 0. If EngineCI.NumDeferredContexts > 0,
91 /// pointers to the deferred contexts are written afterwards.
83
9284 void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& _EngineCI,
9385 IRenderDevice** ppDevice,
9486 IDeviceContext** ppContexts)
316308 }
317309
318310
319 /// Creates a swap chain for Direct3D12-based engine implementation
320
321 /// \param [in] pDevice - Pointer to the render device
322 /// \param [in] pImmediateContext - Pointer to the immediate device context
323 /// \param [in] SCDesc - Swap chain description
324 /// \param [in] pNativeWndHandle - Platform-specific native handle of the window
325 /// the swap chain will be associated with:
326 /// * On Win32 platform, this should be window handle (HWND)
327 /// * On Universal Windows Platform, this should be reference to the
328 /// core window (Windows::UI::Core::CoreWindow)
329 ///
330 /// \param [out] ppSwapChain - Address of the memory location where pointer to the new
331 /// swap chain will be written
332311 void EngineFactoryVkImpl::CreateSwapChainVk(IRenderDevice* pDevice,
333312 IDeviceContext* pImmediateContext,
334313 const SwapChainDesc& SCDesc,
335 void* pNativeWndHandle,
314 const NativeWindow& Window,
336315 ISwapChain** ppSwapChain)
337316 {
338317 VERIFY(ppSwapChain, "Null pointer provided");
347326 auto* pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pImmediateContext);
348327 auto& RawMemAllocator = GetRawAllocator();
349328
350 auto* pSwapChainVk = NEW_RC_OBJ(RawMemAllocator, "SwapChainVkImpl instance", SwapChainVkImpl)(SCDesc, pDeviceVk, pDeviceContextVk, pNativeWndHandle);
329 auto* pSwapChainVk = NEW_RC_OBJ(RawMemAllocator, "SwapChainVkImpl instance", SwapChainVkImpl)(SCDesc, pDeviceVk, pDeviceContextVk, Window);
351330 pSwapChainVk->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));
352331 }
353332 catch (const std::runtime_error&)
3939 const SwapChainDesc& SCDesc,
4040 RenderDeviceVkImpl* pRenderDeviceVk,
4141 DeviceContextVkImpl* pDeviceContextVk,
42 void* pNativeWndHandle) :
42 const NativeWindow& Window) :
4343 // clang-format off
4444 TSwapChainBase {pRefCounters, pRenderDeviceVk, pDeviceContextVk, SCDesc},
4545 m_VulkanInstance {pRenderDeviceVk->GetVulkanInstance()},
5454
5555 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
5656 surfaceCreateInfo.hinstance = GetModuleHandle(NULL);
57 surfaceCreateInfo.hwnd = (HWND)pNativeWndHandle;
57 surfaceCreateInfo.hwnd = (HWND)Window.hWnd;
5858
5959 auto err = vkCreateWin32SurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface);
6060 #elif defined(VK_USE_PLATFORM_ANDROID_KHR)
6161 VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo = {};
6262
6363 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
64 surfaceCreateInfo.window = (ANativeWindow*)pNativeWndHandle;
64 surfaceCreateInfo.window = (ANativeWindow*)Window.pAWindow;
6565
6666 auto err = vkCreateAndroidSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface);
6767 #elif defined(VK_USE_PLATFORM_IOS_MVK)
6868 VkIOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
6969
7070 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
71 surfaceCreateInfo.pView = pNativeWndHandle;
71 surfaceCreateInfo.pView = Window.pNSWindow;
7272
7373 auto err = vkCreateIOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface);
7474 #elif defined(VK_USE_PLATFORM_MACOS_MVK)
7575 VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {};
7676
7777 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
78 surfaceCreateInfo.pView = pNativeWndHandle;
78 surfaceCreateInfo.pView = Window.pNSView;
7979
8080 auto err = vkCreateMacOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface);
8181 #elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
8282 VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo = {};
8383
8484 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
85 surfaceCreateInfo.display = display;
86 surfaceCreatem_VkSurface = window;
85 surfaceCreateInfo.display = Window.pDisplay;
86 surfaceCreatem_VkSurface = Window.pWindow;
8787
8888 err = vkCreateWaylandSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface);
8989 #elif defined(VK_USE_PLATFORM_XCB_KHR)
9090 VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {};
9191
92 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
93 struct XCBInfo
94 {
95 xcb_connection_t* connection = nullptr;
96 uint32_t window = 0;
97 };
98 XCBInfo& info = *reinterpret_cast<XCBInfo*>(pNativeWndHandle);
99 surfaceCreateInfo.connection = info.connection;
100 surfaceCreateInfo.window = info.window;
92 surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
93 surfaceCreateInfo.connection = Window.pXCBConnection;
94 surfaceCreateInfo.window = Window.pWindow;
10195
10296 auto err = vkCreateXcbSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface);
10397 #endif
3232
3333 struct LinuxNativeWindow
3434 {
35 void* pDisplay DEFAULT_INITIALIZER(nullptr);
36 void* pWindow DEFAULT_INITIALIZER(nullptr);
35 void* pDisplay DEFAULT_INITIALIZER(nullptr);
36 void* pWindow DEFAULT_INITIALIZER(nullptr);
37 void* pXCBConnection DEFAULT_INITIALIZER(nullptr);
3738 };
3839
3940 DILIGENT_END_NAMESPACE // namespace Diligent
00 ## Current Progress
11
2 * Updated swap chain creation functions to use `NativeWindow` (API Version 240054)
23 * Added `NativeWindow` wrapper and replaced `pNativeWndHandle` and `pDisplay` members with it in `EngineGLCreateInfo` (API Version 240053)
34 * Added C Interface (API Version 240052)
45