diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2023-12-12 21:58:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 21:58:57 +0100 |
commit | 41365c6c8ba357a490ed924a128958240f3ccf04 (patch) | |
tree | 4db73a1ff0e696ce7f8a16e73e72dd37c2212cbf /platform/windows/display_server_windows.cpp | |
parent | 84692c6252438393999c427bf7f5d35b9c43926c (diff) | |
parent | 2f47c573857f0e6f81281c62d51f006ab7f24828 (diff) | |
download | redot-engine-41365c6c8ba357a490ed924a128958240f3ccf04.tar.gz |
Merge pull request #70315 from RandomShaper/d3d12_mesa
Direct3D 12 Rendering Driver (Mesa NIR approach)
Diffstat (limited to 'platform/windows/display_server_windows.cpp')
-rw-r--r-- | platform/windows/display_server_windows.cpp | 91 |
1 files changed, 85 insertions, 6 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 50d6abc008..77dfff2e5d 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1107,6 +1107,11 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) { context_vulkan->window_destroy(p_window); } #endif +#ifdef D3D12_ENABLED + if (context_d3d12) { + context_d3d12->window_destroy(p_window); + } +#endif #ifdef GLES3_ENABLED if (gl_manager_angle) { gl_manager_angle->window_destroy(p_window); @@ -1539,6 +1544,11 @@ void DisplayServerWindows::window_set_size(const Size2i p_size, WindowID p_windo context_vulkan->window_resize(p_window, w, h); } #endif +#if defined(D3D12_ENABLED) + if (context_d3d12) { + context_d3d12->window_resize(p_window, w, h); + } +#endif #if defined(GLES3_ENABLED) if (gl_manager_native) { gl_manager_native->window_resize(p_window, w, h); @@ -2590,6 +2600,12 @@ void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsyn } #endif +#if defined(D3D12_ENABLED) + if (context_d3d12) { + context_d3d12->set_vsync_mode(p_window, p_vsync_mode); + } +#endif + #if defined(GLES3_ENABLED) if (gl_manager_native) { gl_manager_native->set_use_vsync(p_window, p_vsync_mode != DisplayServer::VSYNC_DISABLED); @@ -2608,6 +2624,12 @@ DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_ } #endif +#if defined(D3D12_ENABLED) + if (context_d3d12) { + return context_d3d12->get_vsync_mode(p_window); + } +#endif + #if defined(GLES3_ENABLED) if (gl_manager_native) { return gl_manager_native->is_using_vsync(p_window) ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED; @@ -2616,7 +2638,6 @@ DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_ return gl_manager_angle->is_using_vsync() ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED; } #endif - return DisplayServer::VSYNC_ENABLED; } @@ -3767,12 +3788,19 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA rect_changed = true; } + // Note: Trigger resize event to update swapchains when window is minimized/restored, even if size is not changed. + if (window_created && window.context_created) { #if defined(VULKAN_ENABLED) - if (context_vulkan && window.context_created) { - // Note: Trigger resize event to update swapchains when window is minimized/restored, even if size is not changed. - context_vulkan->window_resize(window_id, window.width, window.height); - } + if (context_vulkan) { + context_vulkan->window_resize(window_id, window.width, window.height); + } +#endif +#if defined(D3D12_ENABLED) + if (context_d3d12) { + context_d3d12->window_resize(window_id, window.width, window.height); + } #endif + } } if (!window.minimized && (!(window_pos_params->flags & SWP_NOMOVE) || window_pos_params->flags & SWP_FRAMECHANGED)) { @@ -4336,6 +4364,18 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, } #endif +#ifdef D3D12_ENABLED + if (context_d3d12) { + if (context_d3d12->window_create(id, p_vsync_mode, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) != OK) { + memdelete(context_d3d12); + context_d3d12 = nullptr; + windows.erase(id); + ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create D3D12 Window."); + } + wd.context_created = true; + } +#endif + #ifdef GLES3_ENABLED if (gl_manager_native) { if (gl_manager_native->window_create(id, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) != OK) { @@ -4644,6 +4684,17 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } } #endif +#if defined(D3D12_ENABLED) + if (rendering_driver == "d3d12") { + context_d3d12 = memnew(D3D12Context); + if (context_d3d12->initialize() != OK) { + memdelete(context_d3d12); + context_d3d12 = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } + } +#endif // Init context and rendering device #if defined(GLES3_ENABLED) @@ -4727,7 +4778,6 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win show_window(MAIN_WINDOW_ID); #if defined(VULKAN_ENABLED) - if (rendering_driver == "vulkan") { rendering_device_vulkan = memnew(RenderingDeviceVulkan); rendering_device_vulkan->initialize(context_vulkan); @@ -4735,6 +4785,14 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win RendererCompositorRD::make_current(); } #endif +#if defined(D3D12_ENABLED) + if (rendering_driver == "d3d12") { + rendering_device_d3d12 = memnew(RenderingDeviceD3D12); + rendering_device_d3d12->initialize(context_d3d12); + + RendererCompositorRD::make_current(); + } +#endif if (!Engine::get_singleton()->is_editor_hint() && !OS::get_singleton()->is_in_low_processor_usage_mode()) { // Increase priority for projects that are not in low-processor mode (typically games) @@ -4769,6 +4827,9 @@ Vector<String> DisplayServerWindows::get_rendering_drivers_func() { #ifdef VULKAN_ENABLED drivers.push_back("vulkan"); #endif +#ifdef D3D12_ENABLED + drivers.push_back("d3d12"); +#endif #ifdef GLES3_ENABLED drivers.push_back("opengl3"); drivers.push_back("opengl3_angle"); @@ -4833,6 +4894,11 @@ DisplayServerWindows::~DisplayServerWindows() { context_vulkan->window_destroy(MAIN_WINDOW_ID); } #endif +#ifdef D3D12_ENABLED + if (context_d3d12) { + context_d3d12->window_destroy(MAIN_WINDOW_ID); + } +#endif if (wintab_available && windows[MAIN_WINDOW_ID].wtctx) { wintab_WTClose(windows[MAIN_WINDOW_ID].wtctx); windows[MAIN_WINDOW_ID].wtctx = 0; @@ -4853,6 +4919,19 @@ DisplayServerWindows::~DisplayServerWindows() { } #endif +#if defined(D3D12_ENABLED) + if (rendering_device_d3d12) { + rendering_device_d3d12->finalize(); + memdelete(rendering_device_d3d12); + rendering_device_d3d12 = nullptr; + } + + if (context_d3d12) { + memdelete(context_d3d12); + context_d3d12 = nullptr; + } +#endif + if (restore_mouse_trails > 1) { SystemParametersInfoA(SPI_SETMOUSETRAILS, restore_mouse_trails, 0, 0); } |