Skip to content

Allow to disable RenderingDevice and/or its renderers while compiling#103100

Open
YeldhamDev wants to merge 1 commit into
godotengine:masterfrom
YeldhamDev:build_disable_rd
Open

Allow to disable RenderingDevice and/or its renderers while compiling#103100
YeldhamDev wants to merge 1 commit into
godotengine:masterfrom
YeldhamDev:build_disable_rd

Conversation

@YeldhamDev

@YeldhamDev YeldhamDev commented Feb 20, 2025

Copy link
Copy Markdown
Member

This PR makes so that the engine can be compiled without RenderingDevice, and/or the renderers that make use of it (Forward+ and Mobile). This allows for builds that only make use of the compatibility render to cut extra fat from their binaries.

I mainly tested this on GNU/Linux, testers from other OSes are appreciated.

Here's a comparison of binary sizes (GNU/Linux, Template Release):

Default No Vulkan No RD
133.1 MB 127.1 MB 116.9 MB

Sponsored By: 🐺 Lone Wolf Technology / 🍀 W4 Games.

@clayjohn

Copy link
Copy Markdown
Member

How much of a size decrease did you measure?

@YeldhamDev

Copy link
Copy Markdown
Member Author

@clayjohn I've updated the OP with the info.

Comment thread SConstruct Outdated
Comment thread SConstruct Outdated

@Calinou Calinou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested locally, it works as expected.

Linux x86_64 release export template stripped binary size (production=yes lto=full):

  • Default: 72,126,160 bytes
  • vulkan=no: 69,537,616 bytes
  • vulkan=no opengl3=no: 67,690,552 bytes
  • rendering_device=no: 62,368,304 bytes
  • rendering_device=no opengl3=no: 60,611,224 bytes
    • The resulting binary doesn't include any rendering drivers but will still try to spawn a window (and fail with an error; see below). I suppose it should automatically run in headless mode instead to mimic 3.x's headless binaries, but that can be done in a future PR.

When you disable all RenderingDevice drivers for the target platform, rendering_device=no should be implied so you get the smallest possible binary size (unless there is a reason to keep it I'm not aware of).

On Linux and Android, this is the case when using vulkan=no. On Windows, this is the case with vulkan=no d3d12=no, and on macOS/iOS, this is the case with vulkan=no metal=no. The web platform should always imply rendering_device=no.

Error when running a binary with no rendering drivers:

❯ bin/godot.linuxbsd.template_release.x86_64 --path /tmp/test_empty_project                                               
ERROR: No renderers available.
   at: setup (main/main.cpp:2249)
Godot Engine v4.4.beta.custom_build.b8c37952b (2025-02-21 00:13:28 UTC) - https://godotengine.org
ERROR: Video driver not found.
   at: DisplayServerX11 (platform/linuxbsd/x11/display_server_x11.cpp:6883)
WARNING: Display driver x11 failed, falling back to wayland.
     at: setup2 (main/main.cpp:3017)
ERROR: Can't connect to a Wayland display.
   at: init (platform/linuxbsd/wayland/wayland_thread.cpp:3909)
ERROR: Could not initialize the Wayland thread.
   at: DisplayServerWayland (platform/linuxbsd/wayland/display_server_wayland.cpp:1421)
ERROR: Can't create the Wayland display server.
   at: create_func (platform/linuxbsd/wayland/display_server_wayland.cpp:1395)
ERROR: Unable to create DisplayServer, all display drivers failed.
Use "--headless" command line argument to run the engine in headless mode if this is desired (e.g. for continuous integration).
   at: setup2 (main/main.cpp:3027)
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:2378)

When running the same binary with --headless, an error is printed but the program keeps on running correctly:

❯ bin/godot.linuxbsd.template_release.x86_64 --path /tmp/test_empty_project --headless
ERROR: No renderers available.
   at: setup (main/main.cpp:2249)
Godot Engine v4.4.beta.custom_build.b8c37952b (2025-02-21 00:13:28 UTC) - https://godotengine.org

@YeldhamDev

Copy link
Copy Markdown
Member Author

When you disable all RenderingDevice drivers for the target platform, rendering_device=no should be implied so you get the smallest possible binary size (unless there is a reason to keep it I'm not aware of).

If I'm not mistaken, I think it's possible to create custom renderers that use RenderingDevice, no?

@YeldhamDev YeldhamDev force-pushed the build_disable_rd branch 3 times, most recently from b17bb08 to e22f208 Compare February 26, 2025 00:10
@YeldhamDev

Copy link
Copy Markdown
Member Author

I've updated the PR to silence the error about no renders being available if the binary is running in headless mode.

@akien-mga akien-mga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good overall! I don't love the added boilerplate and hacks but the size gains are worth it, and the hacks are still reasonable.

Comment on lines +225 to +227
#ifdef RD_ENABLED
virtual RenderingDevice::DeviceType get_video_adapter_type() const override { return RenderingDevice::DeviceType::DEVICE_TYPE_OTHER; }
#endif // RD_ENABLED

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a bug that we should fix, GLES3 shouldn't depend on RenderingDevice.

I think it's just a mistake here and the DeviceType enum should likely be define somewhere else. I understand that it makes sense exposed in a class named RenderingDevice but if it's used elsewhere it should be in a more generic class (RenderingServer maybe?).

And well actually it's not even supported here, it's just something that shouldn't be part of the abstract API in this form.

CC @clayjohn

Comment thread editor/editor_settings.cpp
Comment thread editor/project_manager/project_dialog.cpp
Comment thread modules/betsy/image_compress_betsy.cpp Outdated
Comment thread modules/lightmapper_rd/config.py Outdated
Comment thread servers/rendering/renderer_viewport.cpp Outdated
Comment on lines +373 to +376
#ifdef RD_ENABLED
// This is needed because the main RD is created on the main thread.
RenderingDevice::get_singleton()->make_current();
#endif // RD_ENABLED

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's also a hack we should solve somehow, this breaks encapsulation.

CC @godotengine/rendering

Comment on lines +1845 to +1848
#ifdef RD_ENABLED
RenderingDevice *get_rendering_device() const;
RenderingDevice *create_local_rendering_device() const;
#endif // RD_ENABLED

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These also break encapsulation, but I guess solving that will be trickier / not possible.

Comment on lines 320 to 321
// In due time this will need to be enhance to return the correct INTERNAL RID for the chosen rendering engine.
// So once a GLES driver is implemented we'll return that and the implemented plugin needs to handle this correctly too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FYI @BastiaanOlij @dsnopek - the OpenGL driver is implemented ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we have this. Is this a utility function meant to be used by child classes of XRInterfaceExtension? If so, I don't think they need it, there's RenderingServer::texture_get_rd_texture() exposed. Maybe this is something that can be deprecated?

Given that we have OpenXR in Godot itself now, it's possible XRInterfaceExtension was never fully baked...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or, hm, this takes the render target, not the RID of the RenderingServer texture. So, maybe we do need this as a utility function? Would be nice for it to be on RenderingServer, though, and not here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is something I wrote waaaaaaaaaaay at the beginning and probably came from translating the implementation in Godot 3 to Godot 4. I'm not even sure if there are implementations that use this. Maybe the TiltFive GDExtension? Though that works with OpenGL so more reason to think this is a defunct method...

Comment thread servers/xr/xr_vrs.cpp Outdated
@YeldhamDev YeldhamDev force-pushed the build_disable_rd branch 2 times, most recently from 6b135ac to efa82f3 Compare March 21, 2025 19:13
@YeldhamDev YeldhamDev force-pushed the build_disable_rd branch 2 times, most recently from fdd5075 to 64806e6 Compare November 29, 2025 19:01
@YeldhamDev YeldhamDev requested review from a team as code owners November 29, 2025 19:01
Comment thread SConstruct Outdated
@KoBeWi

KoBeWi commented Dec 1, 2025

Copy link
Copy Markdown
Member

I tried compiling on Windows with

scons dev_build=yes scu_build=yes fast_unsafe=yes rendering_device=no

and I'm getting lots of compilation errors about undefined RD.

@YeldhamDev YeldhamDev requested a review from a team as a code owner December 2, 2025 14:51
@YeldhamDev YeldhamDev force-pushed the build_disable_rd branch 2 times, most recently from b254e00 to 2b7ad5e Compare December 2, 2025 15:09
@KoBeWi

KoBeWi commented Dec 2, 2025

Copy link
Copy Markdown
Member

Still does not compile:

C:\godot_source\modules\openxr\extensions/openxr_fb_foveation_extension.h(110): error C3646: "meta_vulkan_swapchain_create_info": nieznany specyfikator przes�oni�cia
C:\godot_source\modules\openxr\extensions/openxr_fb_foveation_extension.h(110): error C4430: brak specyfikatora typu - za�o�ono, �e int. Uwaga: C++ nie obs�uguje domy�lnie typu int
scons: *** [bin\obj\modules\openxr\.scu\scu_modules_openxr.gen.windows.editor.dev.x86_64.obj] Error 2
C:\godot_source\modules\openxr\extensions\openxr_fb_foveation_extension.h(110): error C3646: "meta_vulkan_swapchain_create_info": nieznany specyfikator przes�oni�cia
C:\godot_source\modules\openxr\extensions\openxr_fb_foveation_extension.h(110): error C4430: brak specyfikatora typu - za�o�ono, �e int. Uwaga: C++ nie obs�uguje domy�lnie typu int
modules\openxr\extensions\openxr_fb_foveation_extension.cpp(66): error C2065: "meta_vulkan_swapchain_create_info": niezadeklarowany identyfikator 
modules\openxr\extensions\openxr_fb_foveation_extension.cpp(67): error C2065: "meta_vulkan_swapchain_create_info": niezadeklarowany identyfikator 
modules\openxr\extensions\openxr_fb_foveation_extension.cpp(68): error C2065: "meta_vulkan_swapchain_create_info": niezadeklarowany identyfikator 
modules\openxr\extensions\openxr_fb_foveation_extension.cpp(68): error C2065: "VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_QCOM": niezadeklarowany identyfikator
modules\openxr\extensions\openxr_fb_foveation_extension.cpp(69): error C2065: "meta_vulkan_swapchain_create_info": niezadeklarowany identyfikator 
modules\openxr\extensions\openxr_fb_foveation_extension.cpp(148): error C2065: "meta_vulkan_swapchain_create_info": niezadeklarowany identyfikatormodules\openxr\extensions\openxr_fb_foveation_extension.cpp(149): error C2065: "meta_vulkan_swapchain_create_info": niezadeklarowany identyfikatorscons: *** [bin\obj\modules\openxr\extensions\openxr_fb_foveation_extension.windows.editor.dev.x86_64.obj] Error 2
scons: building terminated because of errors.

(sorry for non-English errors, you can look up their error code)

@YeldhamDev

YeldhamDev commented Dec 2, 2025

Copy link
Copy Markdown
Member Author

@KoBeWi Unrelated to this PR: #113460
Use disable_xr=true for now. Rebased, should work just fine now.

@KoBeWi

KoBeWi commented Dec 4, 2025

Copy link
Copy Markdown
Member

It compiles on Windows now and the editor seems to work correctly. The rendering_device/ project settings are still available, not sure if intended.

Comment thread editor/project_manager/project_dialog.cpp Outdated
@YeldhamDev

Copy link
Copy Markdown
Member Author

I've added a #ifdef for the project settings as well.

@YeldhamDev YeldhamDev force-pushed the build_disable_rd branch 2 times, most recently from 137b494 to eab2f1a Compare February 12, 2026 17:43
@YeldhamDev YeldhamDev requested a review from a team as a code owner February 12, 2026 17:43
@YeldhamDev

Copy link
Copy Markdown
Member Author

Rebased, again...

rendering_device=false wont compile if module_openxr_enabled=false isn't also present, otherwise this occurs (on GNU/Linux at least):

In file included from ./thirdparty/glad/glad/glx.h:38,
                 from modules/openxr/extensions/../openxr_platform_inc.h:69,
                 from modules/openxr/extensions/openxr_fb_foveation_extension.h:43,
                 from modules/openxr/extensions/openxr_fb_foveation_extension.cpp:31:
thirdparty/linuxbsd_headers/X11/X.h:632:33: error: expected identifier before numeric constant
  632 | #define CursorShape             0       /* largest size that can be displayed */
      |                                 ^

No clue why. CC @godotengine/xr

@Nintorch Nintorch requested a review from a team March 5, 2026 16:52
@Nintorch Nintorch removed the request for review from a team March 5, 2026 17:38
@YeldhamDev YeldhamDev requested a review from a team as a code owner April 7, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants