Skip to content

Commit

Permalink
Fix running blazium on blocked GPUs.
Browse files Browse the repository at this point in the history
Patch from godot 4.4
  • Loading branch information
WhalesState committed Dec 3, 2024
1 parent d5c0df7 commit 52165be
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 162 deletions.
11 changes: 8 additions & 3 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void OS::ensure_user_data_dir() {

Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error err = da->make_dir_recursive(dd);
ERR_FAIL_COND_MSG(err != OK, "Error attempting to create data dir: " + dd + ".");
ERR_FAIL_COND_MSG(err != OK, vformat("Error attempting to create data dir: %s.", dd));
}

String OS::get_model_name() const {
Expand Down Expand Up @@ -526,9 +526,14 @@ bool OS::has_feature(const String &p_feature) {
return true;
}

if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
return true;
if (has_server_feature_callback) {
return has_server_feature_callback(p_feature);
}
#ifdef DEBUG_ENABLED
else if (is_stdout_verbose()) {
WARN_PRINT_ONCE("Server features cannot be checked before RenderingServer has been created. If you are checking a server feature, consider moving your OS::has_feature call after INITIALIZATION_LEVEL_SERVERS.");
}
#endif

if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) {
return true;
Expand Down
14 changes: 7 additions & 7 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ class OS {
virtual void initialize() = 0;
virtual void initialize_joypads() = 0;

void set_current_rendering_driver_name(const String &p_driver_name) { _current_rendering_driver_name = p_driver_name; }
void set_current_rendering_method(const String &p_name) { _current_rendering_method = p_name; }

void set_display_driver_id(int p_display_driver_id) { _display_driver_id = p_display_driver_id; }

virtual void set_main_loop(MainLoop *p_main_loop) = 0;
Expand All @@ -131,6 +128,9 @@ class OS {

static OS *get_singleton();

void set_current_rendering_driver_name(const String &p_driver_name) { _current_rendering_driver_name = p_driver_name; }
void set_current_rendering_method(const String &p_name) { _current_rendering_method = p_name; }

String get_current_rendering_driver_name() const { return _current_rendering_driver_name; }
String get_current_rendering_method() const { return _current_rendering_method; }

Expand Down Expand Up @@ -173,14 +173,14 @@ class OS {
void set_delta_smoothing(bool p_enabled);
bool is_delta_smoothing_enabled() const;

virtual Vector<String> get_system_fonts() const { return Vector<String>(); };
virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const { return String(); };
virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const { return Vector<String>(); };
virtual Vector<String> get_system_fonts() const { return Vector<String>(); }
virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const { return String(); }
virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const { return Vector<String>(); }
virtual String get_executable_path() const;
virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) = 0;
virtual Dictionary execute_with_pipe(const String &p_path, const List<String> &p_arguments) { return Dictionary(); }
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) = 0;
virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) { return create_process(get_executable_path(), p_arguments, r_child_id); };
virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) { return create_process(get_executable_path(), p_arguments, r_child_id); }
virtual Error kill(const ProcessID &p_pid) = 0;
virtual int get_process_id() const;
virtual bool is_process_running(const ProcessID &p_pid) const = 0;
Expand Down
4 changes: 4 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,10 @@
If [code]true[/code], the forward renderer will fall back to Direct3D 12 if Vulkan is not supported.
[b]Note:[/b] This setting is implemented only on Windows.
</member>
<member name="rendering/rendering_device/fallback_to_opengl3" type="bool" setter="" getter="" default="true">
If [code]true[/code], the forward renderer will fall back to OpenGL 3 if both Direct3D 12, Metal and Vulkan are not supported.
[b]Note:[/b] This setting is implemented only on Windows, Android, macOS, iOS, and Linux/X11.
</member>
<member name="rendering/rendering_device/fallback_to_vulkan" type="bool" setter="" getter="" default="true">
If [code]true[/code], the forward renderer will fall back to Vulkan if Direct3D 12 is not supported.
[b]Note:[/b] This setting is implemented only on Windows.
Expand Down
13 changes: 8 additions & 5 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph

GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true);
GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_d3d12", true);
GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_opengl3", true);
}

{
Expand Down Expand Up @@ -3975,6 +3976,7 @@ int Main::start() {
ProjectManager *pmanager = memnew(ProjectManager);
ProgressDialog *progress_dialog = memnew(ProgressDialog);
pmanager->add_child(progress_dialog);

sml->get_root()->add_child(pmanager);
OS::get_singleton()->benchmark_end_measure("Startup", "Project Manager");
}
Expand Down Expand Up @@ -4095,16 +4097,16 @@ bool Main::iteration() {

uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();

#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->sync();
PhysicsServer3D::get_singleton()->flush_queries();
#endif // _3D_DISABLED

// Prepare the fixed timestep interpolated nodes BEFORE they are updated
// by the physics server, otherwise the current and previous transforms
// may be the same, and no interpolation takes place.
OS::get_singleton()->get_main_loop()->iteration_prepare();

#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->sync();
PhysicsServer3D::get_singleton()->flush_queries();
#endif // _3D_DISABLED

PhysicsServer2D::get_singleton()->sync();
PhysicsServer2D::get_singleton()->flush_queries();

Expand All @@ -4114,6 +4116,7 @@ bool Main::iteration() {
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->end_sync();

Engine::get_singleton()->_in_physics = false;
exit = true;
break;
}
Expand Down
31 changes: 22 additions & 9 deletions platform/android/display_server_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,6 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis

native_menu = memnew(NativeMenu);

#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
RasterizerGLES3::make_current(false);
}
#endif

#if defined(RD_ENABLED)
rendering_context = nullptr;
rendering_device = nullptr;
Expand All @@ -607,13 +601,26 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis

if (rendering_context) {
if (rendering_context->initialize() != OK) {
ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver));
memdelete(rendering_context);
rendering_context = nullptr;
r_error = ERR_UNAVAILABLE;
return;
#if defined(GLES3_ENABLED)
bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3");
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your device seem not to support Vulkan, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif
{
ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver));
r_error = ERR_UNAVAILABLE;
return;
}
}
}

if (rendering_context) {
union {
#ifdef VULKAN_ENABLED
RenderingContextDriverVulkanAndroid::WindowPlatformData vulkan;
Expand Down Expand Up @@ -653,6 +660,12 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
}
#endif

#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
RasterizerGLES3::make_current(false);
}
#endif

Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events);

r_error = OK;
Expand Down
19 changes: 16 additions & 3 deletions platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,26 @@

if (rendering_context) {
if (rendering_context->initialize() != OK) {
ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver));
memdelete(rendering_context);
rendering_context = nullptr;
r_error = ERR_UNAVAILABLE;
return;
#if defined(GLES3_ENABLED)
bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3");
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your device seem not to support MoltenVK or Metal, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif
{
ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver));
r_error = ERR_UNAVAILABLE;
return;
}
}
}

if (rendering_context) {
if (rendering_context->window_create(MAIN_WINDOW_ID, &wpd) != OK) {
ERR_PRINT(vformat("Failed to create %s window.", rendering_driver));
memdelete(rendering_context);
Expand Down
73 changes: 64 additions & 9 deletions platform/linuxbsd/wayland/display_server_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,23 +1349,50 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win

rendering_driver = p_rendering_driver;

bool driver_found = false;
String executable_name = OS::get_singleton()->get_executable_path().get_file();

#ifdef RD_ENABLED
#ifdef VULKAN_ENABLED
if (rendering_driver == "vulkan") {
rendering_context = memnew(RenderingContextDriverVulkanWayland);
}
#endif
#endif // VULKAN_ENABLED

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;
#if defined(GLES3_ENABLED)
bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3");
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your video card drivers seem not to support the required Vulkan version, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif // GLES3_ENABLED
{
r_error = ERR_CANT_CREATE;

if (p_rendering_driver == "vulkan") {
OS::get_singleton()->alert(
vformat("Your video card drivers seem not to support the required Vulkan version.\n\n"
"If possible, consider updating your video card drivers or using the OpenGL 3 driver.\n\n"
"You can enable the OpenGL 3 driver by starting the engine from the\n"
"command line with the command:\n\n \"%s\" --rendering-driver opengl3\n\n"
"If you recently updated your video card drivers, try rebooting.",
executable_name),
"Unable to initialize Vulkan video driver");
}

ERR_FAIL_MSG(vformat("Could not initialize %s", rendering_driver));
}
}

driver_found = true;
}
#endif
#endif // RD_ENABLED

#ifdef GLES3_ENABLED
if (rendering_driver == "opengl3" || rendering_driver == "opengl3_es") {
Expand Down Expand Up @@ -1429,30 +1456,58 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
if (fallback) {
WARN_PRINT("Your video card drivers seem not to support the required OpenGL version, switching to OpenGLES.");
rendering_driver = "opengl3_es";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else {
r_error = ERR_UNAVAILABLE;

OS::get_singleton()->alert(
vformat("Your video card drivers seem not to support the required OpenGL 3.3 version.\n\n"
"If possible, consider updating your video card drivers or using the Vulkan driver.\n\n"
"You can enable the Vulkan driver by starting the engine from the\n"
"command line with the command:\n\n \"%s\" --rendering-driver vulkan\n\n"
"If you recently updated your video card drivers, try rebooting.",
executable_name),
"Unable to initialize OpenGL video driver");

ERR_FAIL_MSG("Could not initialize OpenGL.");
}
} else {
RasterizerGLES3::make_current(true);
driver_found = true;
}
}

if (rendering_driver == "opengl3_es") {
egl_manager = memnew(EGLManagerWaylandGLES);

if (egl_manager->initialize(wayland_thread.get_wl_display()) != OK) {
if (egl_manager->initialize(wayland_thread.get_wl_display()) != OK || egl_manager->open_display(wayland_thread.get_wl_display()) != OK) {
memdelete(egl_manager);
egl_manager = nullptr;
r_error = ERR_CANT_CREATE;
ERR_FAIL_MSG("Could not initialize GLES3.");

OS::get_singleton()->alert(
vformat("Your video card drivers seem not to support the required OpenGL ES 3.0 version.\n\n"
"If possible, consider updating your video card drivers or using the Vulkan driver.\n\n"
"You can enable the Vulkan driver by starting the engine from the\n"
"command line with the command:\n\n \"%s\" --rendering-driver vulkan\n\n"
"If you recently updated your video card drivers, try rebooting.",
executable_name),
"Unable to initialize OpenGL ES video driver");

ERR_FAIL_MSG("Could not initialize OpenGL ES.");
}

RasterizerGLES3::make_current(false);
driver_found = true;
}
}
#endif // GLES3_ENABLED

if (!driver_found) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Video driver not found.");
}

cursor_set_shape(CURSOR_BUSY);

WindowData &wd = main_window;
Expand Down Expand Up @@ -1481,12 +1536,12 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win

RendererCompositorRD::make_current();
}
#endif
#endif // RD_ENABLED

#ifdef DBUS_ENABLED
portal_desktop = memnew(FreeDesktopPortalDesktop);
screensaver = memnew(FreeDesktopScreenSaver);
#endif
#endif // DBUS_ENABLED

screen_set_keep_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));

Expand Down
Loading

0 comments on commit 52165be

Please sign in to comment.