From 73eff10c76c201a083193c044de1836217b4d72b Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 19 Dec 2023 14:57:56 -0300 Subject: Finish splitting functionality of the Vulkan and D3D12 backends into RenderingDeviceDriver. --- platform/linuxbsd/wayland/SCsub | 2 +- .../linuxbsd/wayland/display_server_wayland.cpp | 61 ++++++++++-------- platform/linuxbsd/wayland/display_server_wayland.h | 4 +- .../rendering_context_driver_vulkan_wayland.cpp | 70 +++++++++++++++++++++ .../rendering_context_driver_vulkan_wayland.h | 57 +++++++++++++++++ .../linuxbsd/wayland/vulkan_context_wayland.cpp | 59 ----------------- platform/linuxbsd/wayland/vulkan_context_wayland.h | 52 --------------- platform/linuxbsd/x11/SCsub | 2 +- platform/linuxbsd/x11/display_server_x11.cpp | 73 +++++++++++++--------- platform/linuxbsd/x11/display_server_x11.h | 4 +- .../x11/rendering_context_driver_vulkan_x11.cpp | 70 +++++++++++++++++++++ .../x11/rendering_context_driver_vulkan_x11.h | 59 +++++++++++++++++ platform/linuxbsd/x11/vulkan_context_x11.cpp | 65 ------------------- platform/linuxbsd/x11/vulkan_context_x11.h | 56 ----------------- 14 files changed, 340 insertions(+), 294 deletions(-) create mode 100644 platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.cpp create mode 100644 platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.h delete mode 100644 platform/linuxbsd/wayland/vulkan_context_wayland.cpp delete mode 100644 platform/linuxbsd/wayland/vulkan_context_wayland.h create mode 100644 platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.cpp create mode 100644 platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.h delete mode 100644 platform/linuxbsd/x11/vulkan_context_x11.cpp delete mode 100644 platform/linuxbsd/x11/vulkan_context_x11.h (limited to 'platform/linuxbsd') diff --git a/platform/linuxbsd/wayland/SCsub b/platform/linuxbsd/wayland/SCsub index 910ac29b5e..cab45b7672 100644 --- a/platform/linuxbsd/wayland/SCsub +++ b/platform/linuxbsd/wayland/SCsub @@ -195,7 +195,7 @@ if env["use_sowrap"]: if env["vulkan"]: - source_files.append("vulkan_context_wayland.cpp") + source_files.append("rendering_context_driver_vulkan_wayland.cpp") if env["opengl3"]: source_files.append("egl_manager_wayland.cpp") diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp index 02b715056a..b8a10ea6b9 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.cpp +++ b/platform/linuxbsd/wayland/display_server_wayland.cpp @@ -100,8 +100,8 @@ void DisplayServerWayland::_resize_window(const Size2i &p_size) { wd.rect.size = p_size; #ifdef RD_ENABLED - if (wd.visible && context_rd) { - context_rd->window_resize(MAIN_WINDOW_ID, wd.rect.size.width, wd.rect.size.height); + if (wd.visible && rendering_context) { + rendering_context->window_set_size(MAIN_WINDOW_ID, wd.rect.size.width, wd.rect.size.height); } #endif @@ -140,10 +140,10 @@ void DisplayServerWayland::_show_window() { // the only acceptable way of implementing window showing is to move the // graphics context window creation logic here. #ifdef RD_ENABLED - if (context_rd) { + if (rendering_context) { union { #ifdef VULKAN_ENABLED - VulkanContextWayland::WindowPlatformData vulkan; + RenderingContextDriverVulkanWayland::WindowPlatformData vulkan; #endif } wpd; #ifdef VULKAN_ENABLED @@ -152,14 +152,17 @@ void DisplayServerWayland::_show_window() { wpd.vulkan.display = wayland_thread.get_wl_display(); } #endif - Error err = context_rd->window_create(wd.id, wd.vsync_mode, wd.rect.size.width, wd.rect.size.height, &wpd); - ERR_FAIL_COND_MSG(err != OK, vformat("Can't create a %s window", context_rd->get_api_name())); + Error err = rendering_context->window_create(wd.id, &wpd); + ERR_FAIL_COND_MSG(err != OK, vformat("Can't create a %s window", rendering_driver)); - emulate_vsync = (context_rd->get_vsync_mode(wd.id) == DisplayServer::VSYNC_ENABLED); + rendering_context->window_set_size(wd.id, wd.rect.size.width, wd.rect.size.height); + rendering_context->window_set_vsync_mode(wd.id, wd.vsync_mode); + + emulate_vsync = (rendering_context->window_get_vsync_mode(wd.id) == DisplayServer::VSYNC_ENABLED); if (emulate_vsync) { print_verbose("VSYNC: manually throttling frames using MAILBOX."); - context_rd->set_vsync_mode(wd.id, DisplayServer::VSYNC_MAILBOX); + rendering_context->window_set_vsync_mode(wd.id, DisplayServer::VSYNC_MAILBOX); } } #endif @@ -885,14 +888,14 @@ void DisplayServerWayland::window_set_vsync_mode(DisplayServer::VSyncMode p_vsyn MutexLock mutex_lock(wayland_thread.mutex); #ifdef RD_ENABLED - if (context_rd) { - context_rd->set_vsync_mode(p_window_id, p_vsync_mode); + if (rendering_context) { + rendering_context->window_set_vsync_mode(p_window_id, p_vsync_mode); - emulate_vsync = (context_rd->get_vsync_mode(p_window_id) == DisplayServer::VSYNC_ENABLED); + emulate_vsync = (rendering_context->window_get_vsync_mode(p_window_id) == DisplayServer::VSYNC_ENABLED); if (emulate_vsync) { print_verbose("VSYNC: manually throttling frames using MAILBOX."); - context_rd->set_vsync_mode(p_window_id, DisplayServer::VSYNC_MAILBOX); + rendering_context->window_set_vsync_mode(p_window_id, DisplayServer::VSYNC_MAILBOX); } } #endif // VULKAN_ENABLED @@ -917,8 +920,8 @@ DisplayServer::VSyncMode DisplayServerWayland::window_get_vsync_mode(DisplayServ } #ifdef VULKAN_ENABLED - if (context_rd) { - return context_rd->get_vsync_mode(p_window_id); + if (rendering_context) { + return rendering_context->window_get_vsync_mode(p_window_id); } #endif // VULKAN_ENABLED @@ -1236,15 +1239,15 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win #ifdef RD_ENABLED #ifdef VULKAN_ENABLED if (p_rendering_driver == "vulkan") { - context_rd = memnew(VulkanContextWayland); + rendering_context = memnew(RenderingContextDriverVulkanWayland); } #endif - if (context_rd) { - if (context_rd->initialize() != OK) { - ERR_PRINT(vformat("Could not initialize %s", context_rd->get_api_name())); - memdelete(context_rd); - context_rd = nullptr; + if (rendering_context) { + if (rendering_context->initialize() != OK) { + ERR_PRINT(vformat("Could not initialize %s", p_rendering_driver)); + memdelete(rendering_context); + rendering_context = nullptr; r_error = ERR_CANT_CREATE; return; } @@ -1329,9 +1332,10 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win _show_window(); #ifdef RD_ENABLED - if (context_rd) { + if (rendering_context) { rendering_device = memnew(RenderingDevice); - rendering_device->initialize(context_rd); + rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); } @@ -1351,8 +1355,12 @@ DisplayServerWayland::~DisplayServerWayland() { // TODO: Multiwindow support. if (main_window.visible) { #ifdef VULKAN_ENABLED - if (context_rd) { - context_rd->window_destroy(MAIN_WINDOW_ID); + if (rendering_device) { + rendering_device->screen_free(MAIN_WINDOW_ID); + } + + if (rendering_context) { + rendering_context->window_destroy(MAIN_WINDOW_ID); } #endif @@ -1374,12 +1382,11 @@ DisplayServerWayland::~DisplayServerWayland() { // Destroy all drivers. #ifdef RD_ENABLED if (rendering_device) { - rendering_device->finalize(); memdelete(rendering_device); } - if (context_rd) { - memdelete(context_rd); + if (rendering_context) { + memdelete(rendering_context); } #endif diff --git a/platform/linuxbsd/wayland/display_server_wayland.h b/platform/linuxbsd/wayland/display_server_wayland.h index 3e7f3c4cb4..58c5dab586 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.h +++ b/platform/linuxbsd/wayland/display_server_wayland.h @@ -39,7 +39,7 @@ #include "servers/rendering/rendering_device.h" #ifdef VULKAN_ENABLED -#include "wayland/vulkan_context_wayland.h" +#include "wayland/rendering_context_driver_vulkan_wayland.h" #endif #endif //RD_ENABLED @@ -123,7 +123,7 @@ class DisplayServerWayland : public DisplayServer { String rendering_driver; #ifdef RD_ENABLED - ApiContextRD *context_rd = nullptr; + RenderingContextDriver *rendering_context = nullptr; RenderingDevice *rendering_device = nullptr; #endif diff --git a/platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.cpp b/platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.cpp new file mode 100644 index 0000000000..c874c45a8a --- /dev/null +++ b/platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.cpp @@ -0,0 +1,70 @@ +/**************************************************************************/ +/* rendering_context_driver_vulkan_wayland.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifdef VULKAN_ENABLED + +#include "rendering_context_driver_vulkan_wayland.h" + +#ifdef USE_VOLK +#include +#else +#include +#endif + +const char *RenderingContextDriverVulkanWayland::_get_platform_surface_extension() const { + return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME; +} + +RenderingContextDriver::SurfaceID RenderingContextDriverVulkanWayland::surface_create(const void *p_platform_data) { + const WindowPlatformData *wpd = (const WindowPlatformData *)(p_platform_data); + + VkWaylandSurfaceCreateInfoKHR create_info = {}; + create_info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; + create_info.display = wpd->display; + create_info.surface = wpd->surface; + + VkSurfaceKHR vk_surface = VK_NULL_HANDLE; + VkResult err = vkCreateWaylandSurfaceKHR(instance_get(), &create_info, nullptr, &vk_surface); + ERR_FAIL_COND_V(err != VK_SUCCESS, SurfaceID()); + + Surface *surface = memnew(Surface); + surface->vk_surface = vk_surface; + return SurfaceID(surface); +} + +RenderingContextDriverVulkanWayland::RenderingContextDriverVulkanWayland() { + // Does nothing. +} + +RenderingContextDriverVulkanWayland::~RenderingContextDriverVulkanWayland() { + // Does nothing. +} + +#endif // VULKAN_ENABLED diff --git a/platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.h b/platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.h new file mode 100644 index 0000000000..dfebca1890 --- /dev/null +++ b/platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.h @@ -0,0 +1,57 @@ +/**************************************************************************/ +/* rendering_context_driver_vulkan_wayland.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef RENDERING_CONTEXT_DRIVER_VULKAN_WAYLAND_H +#define RENDERING_CONTEXT_DRIVER_VULKAN_WAYLAND_H + +#ifdef VULKAN_ENABLED + +#include "drivers/vulkan/rendering_context_driver_vulkan.h" + +class RenderingContextDriverVulkanWayland : public RenderingContextDriverVulkan { +private: + virtual const char *_get_platform_surface_extension() const override final; + +protected: + SurfaceID surface_create(const void *p_platform_data) override final; + +public: + struct WindowPlatformData { + struct wl_display *display; + struct wl_surface *surface; + }; + + RenderingContextDriverVulkanWayland(); + ~RenderingContextDriverVulkanWayland(); +}; + +#endif // VULKAN_ENABLED + +#endif // RENDERING_CONTEXT_DRIVER_VULKAN_WAYLAND_H diff --git a/platform/linuxbsd/wayland/vulkan_context_wayland.cpp b/platform/linuxbsd/wayland/vulkan_context_wayland.cpp deleted file mode 100644 index b3f28a1678..0000000000 --- a/platform/linuxbsd/wayland/vulkan_context_wayland.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************/ -/* vulkan_context_wayland.cpp */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#include "vulkan_context_wayland.h" - -#ifdef VULKAN_ENABLED - -#ifdef USE_VOLK -#include -#else -#include -#endif - -const char *VulkanContextWayland::_get_platform_surface_extension() const { - return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME; -} - -Error VulkanContextWayland::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height, const void *p_platform_data) { - const WindowPlatformData *wpd = (const WindowPlatformData *)p_platform_data; - - VkWaylandSurfaceCreateInfoKHR createInfo = {}; - createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; - createInfo.display = wpd->display; - createInfo.surface = wpd->surface; - - VkSurfaceKHR surface = VK_NULL_HANDLE; - VkResult err = vkCreateWaylandSurfaceKHR(get_instance(), &createInfo, nullptr, &surface); - ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); -} - -#endif // VULKAN_ENABLED diff --git a/platform/linuxbsd/wayland/vulkan_context_wayland.h b/platform/linuxbsd/wayland/vulkan_context_wayland.h deleted file mode 100644 index b0a7d1ff87..0000000000 --- a/platform/linuxbsd/wayland/vulkan_context_wayland.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************/ -/* vulkan_context_wayland.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifndef VULKAN_CONTEXT_WAYLAND_H -#define VULKAN_CONTEXT_WAYLAND_H - -#ifdef VULKAN_ENABLED - -#include "drivers/vulkan/vulkan_context.h" - -class VulkanContextWayland : public VulkanContext { - const char *_get_platform_surface_extension() const override final; - -public: - struct WindowPlatformData { - struct wl_display *display; - struct wl_surface *surface; - }; - - Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height, const void *p_platform_data) override final; -}; - -#endif // VULKAN_ENABLED - -#endif // VULKAN_CONTEXT_WAYLAND_H diff --git a/platform/linuxbsd/x11/SCsub b/platform/linuxbsd/x11/SCsub index bbfaaf10d1..75fe584ad5 100644 --- a/platform/linuxbsd/x11/SCsub +++ b/platform/linuxbsd/x11/SCsub @@ -21,7 +21,7 @@ if env["use_sowrap"]: ) if env["vulkan"]: - source_files.append("vulkan_context_x11.cpp") + source_files.append("rendering_context_driver_vulkan_x11.cpp") if env["opengl3"]: env.Append(CPPDEFINES=["GLAD_GLX_NO_X11"]) diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index c0937b6d4f..b838e4b870 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -1670,7 +1670,11 @@ DisplayServer::WindowID DisplayServerX11::create_sub_window(WindowMode p_mode, V window_set_flag(WindowFlags(i), true, id); } } - +#ifdef RD_ENABLED + if (rendering_device) { + rendering_device->screen_create(id); + } +#endif return id; } @@ -1719,8 +1723,12 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) { } #if defined(RD_ENABLED) - if (context_rd) { - context_rd->window_destroy(p_id); + if (rendering_device) { + rendering_device->screen_free(p_id); + } + + if (rendering_context) { + rendering_context->window_destroy(p_id); } #endif #ifdef GLES3_ENABLED @@ -2245,8 +2253,8 @@ void DisplayServerX11::window_set_size(const Size2i p_size, WindowID p_window) { // Keep rendering context window size in sync #if defined(RD_ENABLED) - if (context_rd) { - context_rd->window_resize(p_window, xwa.width, xwa.height); + if (rendering_context) { + rendering_context->window_set_size(p_window, xwa.width, xwa.height); } #endif #if defined(GLES3_ENABLED) @@ -3970,8 +3978,8 @@ void DisplayServerX11::_window_changed(XEvent *event) { wd.size = new_rect.size; #if defined(RD_ENABLED) - if (context_rd) { - context_rd->window_resize(window_id, wd.size.width, wd.size.height); + if (rendering_context) { + rendering_context->window_set_size(window_id, wd.size.width, wd.size.height); } #endif #if defined(GLES3_ENABLED) @@ -5300,8 +5308,8 @@ void DisplayServerX11::set_icon(const Ref &p_icon) { void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { _THREAD_SAFE_METHOD_ #if defined(RD_ENABLED) - if (context_rd) { - context_rd->set_vsync_mode(p_window, p_vsync_mode); + if (rendering_context) { + rendering_context->window_set_vsync_mode(p_window, p_vsync_mode); } #endif @@ -5318,8 +5326,8 @@ void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mo DisplayServer::VSyncMode DisplayServerX11::window_get_vsync_mode(WindowID p_window) const { _THREAD_SAFE_METHOD_ #if defined(RD_ENABLED) - if (context_rd) { - return context_rd->get_vsync_mode(p_window); + if (rendering_context) { + return rendering_context->window_get_vsync_mode(p_window); } #endif #if defined(GLES3_ENABLED) @@ -5662,10 +5670,10 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V _update_size_hints(id); #if defined(RD_ENABLED) - if (context_rd) { + if (rendering_context) { union { #ifdef VULKAN_ENABLED - VulkanContextX11::WindowPlatformData vulkan; + RenderingContextDriverVulkanX11::WindowPlatformData vulkan; #endif } wpd; #ifdef VULKAN_ENABLED @@ -5674,8 +5682,11 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V wpd.vulkan.display = x11_display; } #endif - Error err = context_rd->window_create(id, p_vsync_mode, win_rect.size.width, win_rect.size.height, &wpd); - ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, vformat("Can't create a %s window", context_rd->get_api_name())); + Error err = rendering_context->window_create(id, &wpd); + ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, vformat("Can't create a %s window", rendering_driver)); + + rendering_context->window_set_size(id, win_rect.size.width, win_rect.size.height); + rendering_context->window_set_vsync_mode(id, p_vsync_mode); } #endif #ifdef GLES3_ENABLED @@ -6077,15 +6088,15 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode #if defined(RD_ENABLED) #if defined(VULKAN_ENABLED) if (rendering_driver == "vulkan") { - context_rd = memnew(VulkanContextX11); + rendering_context = memnew(RenderingContextDriverVulkanX11); } #endif - if (context_rd) { - if (context_rd->initialize() != OK) { - ERR_PRINT(vformat("Could not initialize %s", context_rd->get_api_name())); - memdelete(context_rd); - context_rd = nullptr; + if (rendering_context) { + if (rendering_context->initialize() != OK) { + ERR_PRINT(vformat("Could not initialize %s", rendering_driver)); + memdelete(rendering_context); + rendering_context = nullptr; r_error = ERR_CANT_CREATE; return; } @@ -6197,9 +6208,10 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode show_window(main_window); #if defined(RD_ENABLED) - if (context_rd) { + if (rendering_context) { rendering_device = memnew(RenderingDevice); - rendering_device->initialize(context_rd); + rendering_device->initialize(rendering_context, MAIN_WINDOW_ID); + rendering_device->screen_create(MAIN_WINDOW_ID); RendererCompositorRD::make_current(); } @@ -6374,8 +6386,12 @@ DisplayServerX11::~DisplayServerX11() { //destroy all windows for (KeyValue &E : windows) { #if defined(RD_ENABLED) - if (context_rd) { - context_rd->window_destroy(E.key); + if (rendering_device) { + rendering_device->screen_free(E.key); + } + + if (rendering_context) { + rendering_context->window_destroy(E.key); } #endif #ifdef GLES3_ENABLED @@ -6419,14 +6435,13 @@ DisplayServerX11::~DisplayServerX11() { //destroy drivers #if defined(RD_ENABLED) if (rendering_device) { - rendering_device->finalize(); memdelete(rendering_device); rendering_device = nullptr; } - if (context_rd) { - memdelete(context_rd); - context_rd = nullptr; + if (rendering_context) { + memdelete(rendering_context); + rendering_context = nullptr; } #endif diff --git a/platform/linuxbsd/x11/display_server_x11.h b/platform/linuxbsd/x11/display_server_x11.h index da4085772a..7c094d6a41 100644 --- a/platform/linuxbsd/x11/display_server_x11.h +++ b/platform/linuxbsd/x11/display_server_x11.h @@ -61,7 +61,7 @@ #include "servers/rendering/rendering_device.h" #if defined(VULKAN_ENABLED) -#include "x11/vulkan_context_x11.h" +#include "x11/rendering_context_driver_vulkan_x11.h" #endif #endif @@ -144,7 +144,7 @@ class DisplayServerX11 : public DisplayServer { GLManagerEGL_X11 *gl_manager_egl = nullptr; #endif #if defined(RD_ENABLED) - ApiContextRD *context_rd = nullptr; + RenderingContextDriver *rendering_context = nullptr; RenderingDevice *rendering_device = nullptr; #endif diff --git a/platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.cpp b/platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.cpp new file mode 100644 index 0000000000..bf44062266 --- /dev/null +++ b/platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.cpp @@ -0,0 +1,70 @@ +/**************************************************************************/ +/* rendering_context_driver_vulkan_x11.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifdef VULKAN_ENABLED + +#include "rendering_context_driver_vulkan_x11.h" + +#ifdef USE_VOLK +#include +#else +#include +#endif + +const char *RenderingContextDriverVulkanX11::_get_platform_surface_extension() const { + return VK_KHR_XLIB_SURFACE_EXTENSION_NAME; +} + +RenderingContextDriver::SurfaceID RenderingContextDriverVulkanX11::surface_create(const void *p_platform_data) { + const WindowPlatformData *wpd = (const WindowPlatformData *)(p_platform_data); + + VkXlibSurfaceCreateInfoKHR create_info = {}; + create_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; + create_info.dpy = wpd->display; + create_info.window = wpd->window; + + VkSurfaceKHR vk_surface = VK_NULL_HANDLE; + VkResult err = vkCreateXlibSurfaceKHR(instance_get(), &create_info, nullptr, &vk_surface); + ERR_FAIL_COND_V(err != VK_SUCCESS, SurfaceID()); + + Surface *surface = memnew(Surface); + surface->vk_surface = vk_surface; + return SurfaceID(surface); +} + +RenderingContextDriverVulkanX11::RenderingContextDriverVulkanX11() { + // Does nothing. +} + +RenderingContextDriverVulkanX11::~RenderingContextDriverVulkanX11() { + // Does nothing. +} + +#endif // VULKAN_ENABLED diff --git a/platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.h b/platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.h new file mode 100644 index 0000000000..d525b69ec7 --- /dev/null +++ b/platform/linuxbsd/x11/rendering_context_driver_vulkan_x11.h @@ -0,0 +1,59 @@ +/**************************************************************************/ +/* rendering_context_driver_vulkan_x11.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef RENDERING_CONTEXT_DRIVER_VULKAN_X11_H +#define RENDERING_CONTEXT_DRIVER_VULKAN_X11_H + +#ifdef VULKAN_ENABLED + +#include "drivers/vulkan/rendering_context_driver_vulkan.h" + +#include + +class RenderingContextDriverVulkanX11 : public RenderingContextDriverVulkan { +private: + virtual const char *_get_platform_surface_extension() const override final; + +protected: + SurfaceID surface_create(const void *p_platform_data) override final; + +public: + struct WindowPlatformData { + ::Window window; + Display *display; + }; + + RenderingContextDriverVulkanX11(); + ~RenderingContextDriverVulkanX11(); +}; + +#endif // VULKAN_ENABLED + +#endif // RENDERING_CONTEXT_DRIVER_VULKAN_X11_H diff --git a/platform/linuxbsd/x11/vulkan_context_x11.cpp b/platform/linuxbsd/x11/vulkan_context_x11.cpp deleted file mode 100644 index 3eee1706b0..0000000000 --- a/platform/linuxbsd/x11/vulkan_context_x11.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************/ -/* vulkan_context_x11.cpp */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifdef VULKAN_ENABLED - -#include "vulkan_context_x11.h" - -#ifdef USE_VOLK -#include -#else -#include -#endif - -const char *VulkanContextX11::_get_platform_surface_extension() const { - return VK_KHR_XLIB_SURFACE_EXTENSION_NAME; -} - -Error VulkanContextX11::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height, const void *p_platform_data) { - const WindowPlatformData *wpd = (const WindowPlatformData *)p_platform_data; - - VkXlibSurfaceCreateInfoKHR createInfo = {}; - createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; - createInfo.dpy = wpd->display; - createInfo.window = wpd->window; - - VkSurfaceKHR surface = VK_NULL_HANDLE; - VkResult err = vkCreateXlibSurfaceKHR(get_instance(), &createInfo, nullptr, &surface); - ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); -} - -VulkanContextX11::VulkanContextX11() { -} - -VulkanContextX11::~VulkanContextX11() { -} - -#endif // VULKAN_ENABLED diff --git a/platform/linuxbsd/x11/vulkan_context_x11.h b/platform/linuxbsd/x11/vulkan_context_x11.h deleted file mode 100644 index 2390326b44..0000000000 --- a/platform/linuxbsd/x11/vulkan_context_x11.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************/ -/* vulkan_context_x11.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifndef VULKAN_CONTEXT_X11_H -#define VULKAN_CONTEXT_X11_H - -#ifdef VULKAN_ENABLED - -#include "drivers/vulkan/vulkan_context.h" - -#include - -class VulkanContextX11 : public VulkanContext { - virtual const char *_get_platform_surface_extension() const override final; - -public: - struct WindowPlatformData { - ::Window window; - Display *display; - }; - virtual Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height, const void *p_platform_data) override final; - - VulkanContextX11(); - ~VulkanContextX11(); -}; - -#endif // VULKAN_ENABLED - -#endif // VULKAN_CONTEXT_X11_H -- cgit v1.2.3