Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable creating RD projects in project manager if RD is not supported #91172

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions editor/project_manager/project_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,30 +428,41 @@ void ProjectDialog::_renderer_selected() {

String renderer_type = renderer_button_group->get_pressed_button()->get_meta(SNAME("rendering_method"));

bool rd_error = false;

if (renderer_type == "forward_plus") {
renderer_info->set_text(
String::utf8("• ") + TTR("Supports desktop platforms only.") +
String::utf8("\n• ") + TTR("Advanced 3D graphics available.") +
String::utf8("\n• ") + TTR("Can scale to large complex scenes.") +
String::utf8("\n• ") + TTR("Uses RenderingDevice backend.") +
String::utf8("\n• ") + TTR("Slower rendering of simple scenes."));
rd_error = !rendering_device_supported;
} else if (renderer_type == "mobile") {
renderer_info->set_text(
String::utf8("• ") + TTR("Supports desktop + mobile platforms.") +
String::utf8("\n• ") + TTR("Less advanced 3D graphics.") +
String::utf8("\n• ") + TTR("Less scalable for complex scenes.") +
String::utf8("\n• ") + TTR("Uses RenderingDevice backend.") +
String::utf8("\n• ") + TTR("Fast rendering of simple scenes."));
rd_error = !rendering_device_supported;
} else if (renderer_type == "gl_compatibility") {
renderer_info->set_text(
String::utf8("• ") + TTR("Supports desktop, mobile + web platforms.") +
String::utf8("\n• ") + TTR("Least advanced 3D graphics (currently work-in-progress).") +
String::utf8("\n• ") + TTR("Least advanced 3D graphics.") +
String::utf8("\n• ") + TTR("Intended for low-end/older devices.") +
String::utf8("\n• ") + TTR("Uses OpenGL 3 backend (OpenGL 3.3/ES 3.0/WebGL2).") +
String::utf8("\n• ") + TTR("Fastest rendering of simple scenes."));
} else {
WARN_PRINT("Unknown renderer type. Please report this as a bug on GitHub.");
}

rd_not_supported->set_visible(rd_error);
get_ok_button()->set_disabled(rd_error);
if (rd_error) {
// Needs to be set here since theme colors aren't available at startup.
rd_not_supported->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
}
}

void ProjectDialog::_nonempty_confirmation_ok_pressed() {
Expand Down Expand Up @@ -903,10 +914,16 @@ ProjectDialog::ProjectDialog() {
default_renderer_type = EditorSettings::get_singleton()->get_setting("project_manager/default_renderer");
}

rendering_device_supported = DisplayServer::can_create_rendering_device();

if (!rendering_device_supported) {
default_renderer_type = "gl_compatibility";
}

Button *rs_button = memnew(CheckBox);
rs_button->set_button_group(renderer_button_group);
rs_button->set_text(TTR("Forward+"));
#if defined(WEB_ENABLED)
#ifndef RD_ENABLED
rs_button->set_disabled(true);
#endif
rs_button->set_meta(SNAME("rendering_method"), "forward_plus");
Expand All @@ -918,7 +935,7 @@ ProjectDialog::ProjectDialog() {
rs_button = memnew(CheckBox);
rs_button->set_button_group(renderer_button_group);
rs_button->set_text(TTR("Mobile"));
#if defined(WEB_ENABLED)
#ifndef RD_ENABLED
rs_button->set_disabled(true);
#endif
rs_button->set_meta(SNAME("rendering_method"), "mobile");
Expand Down Expand Up @@ -950,6 +967,15 @@ ProjectDialog::ProjectDialog() {
renderer_info = memnew(Label);
renderer_info->set_modulate(Color(1, 1, 1, 0.7));
rvb->add_child(renderer_info);

rd_not_supported = memnew(Label);
rd_not_supported->set_text(TTR("Rendering Device backend not available. Please use the Compatibility renderer."));
rd_not_supported->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
rd_not_supported->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
rd_not_supported->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
rd_not_supported->set_visible(false);
renderer_container->add_child(rd_not_supported);

_renderer_selected();

l = memnew(Label);
Expand Down
2 changes: 2 additions & 0 deletions editor/project_manager/project_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ProjectDialog : public ConfirmationDialog {
Label *renderer_info = nullptr;
HBoxContainer *default_files_container = nullptr;
Ref<ButtonGroup> renderer_button_group;
bool rendering_device_supported = false;
Label *rd_not_supported = nullptr;

Label *msg = nullptr;
LineEdit *project_name = nullptr;
Expand Down
42 changes: 42 additions & 0 deletions servers/display_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#include "scene/resources/texture.h"
#include "servers/display_server_headless.h"

#if defined(VULKAN_ENABLED)
#include "drivers/vulkan/rendering_context_driver_vulkan.h"
#undef CursorShape
Riteo marked this conversation as resolved.
Show resolved Hide resolved
#endif
#if defined(D3D12_ENABLED)
#include "drivers/d3d12/rendering_context_driver_d3d12.h"
#endif

DisplayServer *DisplayServer::singleton = nullptr;

bool DisplayServer::hidpi_allowed = false;
Expand Down Expand Up @@ -1211,6 +1219,40 @@ void DisplayServer::_input_set_custom_mouse_cursor_func(const Ref<Resource> &p_i
singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot);
}

bool DisplayServer::can_create_rendering_device() {
#if defined(RD_ENABLED)
Error err;
RenderingContextDriver *rcd = nullptr;

#if defined(VULKAN_ENABLED)
rcd = memnew(RenderingContextDriverVulkan);
#endif
#ifdef D3D12_ENABLED
if (rcd == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking as I'm not super-experienced with this kind of context driver swapping: could this cause issues with devices where Vulkan fails to initialize but D3D12 succeeds, if a device like that even exists?

Copy link
Member

@Calinou Calinou Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with devices where Vulkan fails to initialize but D3D12 succeeds, if a device like that even exists?

Yes, such devices exist if they have broken Vulkan layers that prevent Vulkan from initializing altogether. There's also Windows ARM devices without the Vulkan/OpenGL support pack installed.

rcd = memnew(RenderingContextDriverD3D12);
}
#endif

if (rcd != nullptr) {
err = rcd->initialize();
if (err == OK) {
RenderingDevice *rd = memnew(RenderingDevice);
err = rd->initialize(rcd);
memdelete(rd);
rd = nullptr;
if (err == OK) {
return true;
}
}

memdelete(rcd);
rcd = nullptr;
}

#endif // RD_ENABLED
return false;
}

DisplayServer::DisplayServer() {
singleton = this;
Input::set_mouse_mode_func = _input_set_mouse_mode;
Expand Down
2 changes: 2 additions & 0 deletions servers/display_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ class DisplayServer : public Object {
static Vector<String> get_create_function_rendering_drivers(int p_index);
static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);

static bool can_create_rendering_device();

DisplayServer();
~DisplayServer();
};
Expand Down
Loading