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

Add a page documenting Godot's internal rendering architecture #6133

Merged
merged 1 commit into from
May 18, 2023

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Sep 2, 2022

This is intended for new and returning engine contributors.

There are some clarifications I'd like to add – see my review comments and the question below. Also, I may have forgotten talking about certain features of the renderer entirely, so please comment if that's the case.

@BastiaanOlij Could you write up a paragraph or two about subpass usage in the Forward Mobile backend, and how it differs from approach in the Clustered Forward backend (and why subpasses are used)? This would be useful to list on this page 🙂
Edit: Added

@Calinou Calinou added enhancement content:new page Issues and PRs related to creation of new documentation pages for new or undocumented features labels Sep 2, 2022
@paddy-exe
Copy link
Contributor

paddy-exe commented Sep 2, 2022

Absolutely amazing work on this! Thank you for creating this

  1. Not sure if this should get its own category but it would be great to have the Visual Shader system and its place in the rendering code as well here.
  2. I am not sure if I understand the Rendering Device part correctly but if I want to add a new feature (e.g. like ray tracing or something else) which is technically supported by a Vulkan extension, would I first take a look at the Rendering Device API and see if I can implement this with its API and if not add the necessary stuff to the underlying code?

@Calinou Calinou force-pushed the add-rendering-architecture branch 3 times, most recently from 9103d69 to 195780a Compare September 4, 2022 20:59
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

We should also include the image from godotengine/godot#44094 somewhere in the document and explain its meaning in more detail. IMO the structure of the RenderingServer is something a lot of new contributors have trouble with

development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
ask in the ``#rendering`` channel of the
`Godot Contributors Chat <https://chat.godotengine.org/channel/rendering>`__.

Rendering drivers
Copy link
Member

Choose a reason for hiding this comment

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

Before we release 4.0 we are going to reorganize the renderer selection and place more emphasis on selecting the rendering method and less emphasis on the driver (see here. I think the organization of the document should emphasis that organization. I.e. it should start with the renderer, clustered forward then explain that there are two options for using that Vulkan or DirectX (in the future hopefully will support WebGPU and Metal), When using MacOS, you have to use Vulkan, but it is translated to metal through MoltenVK and in the future we may have a metal backend. If using the compatibility renderer, you have to use OpenGL3 now, but we will support choosing between opengl and Angle

development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
development/cpp/internal_rendering_architecture.rst Outdated Show resolved Hide resolved
@Calinou Calinou force-pushed the add-rendering-architecture branch 3 times, most recently from 8021cfc to 3790fb1 Compare September 5, 2022 16:48
@BastiaanOlij
Copy link
Contributor

@Calinou first draft of what could be a replacement Forward Mobile section. Let me know if its usable:

Forward Mobile
^^^^^^^^^^^^^^

This is a forward renderer that uses a traditional single-pass approach to lighting.

Intended for mobile platforms, but can also run on desktop platforms. This
backend is optimized to perform well on mobile GPUs. Mobile GPUs have a very
different architecture compared to desktop GPUs due to their unique constraints
around battery usage, heat and overal bandwidth limitations of reading and writing
data. Compute shaders also have very limited support or aren't supported at all, the
mobile renderer as a result purely uses raster based shaders.

Instead of rendering the whole image as a single unit, the image is divided in
smaller tiles that fit within the faster internal memory of the mobile GPU. Each
tile is rendered and then written out to the destination texture. This all happens
automatically on the graphics driver.

The problem this introduces is that our traditional approach for desktop rendering,
where we render all opaque geometry, then handle the background, then transparent
geometry, then post processing, introduces bottlenecks as each pass will need to
read the current result into tile memory, perform its operations and then write it 
out again. We then wait for all tiles to be completed before moving on to the next
pass.

The first important change in the mobile renderer is that the mobile renderer does
not use the RGBA16F texture formats that the desktop renderer does. Instead it is
using a R10B10G10A2 texture format. This halves the bandwidth required and has
further improvements as mobile hardware often further optimises 32bit formats.
The tradeoff is that the mobile renderer has limited HDR capabilities due to the 
reduced precision in the color data.

The second important change is the use of sub-passes whenever possible. Sub-passes
allows us to perform the rendering steps end-to-end per tile saving on the overhead
introduced by reading from and writing to the tiles inbetween each rendering pass.
The ability to use sub-passes is limited by the inability to read neighboring pixels
as we're constraint to working within a single tile.
This results in not being able to implement features such as glow and dof.
Similarly if there is a requirement to read from the screen texture or depth texture
we must fully write out the rendering result limiting our ability to use sub-passes.
When such features are enabled a mix of sub-passes and normal passes are used, and
these features thus have a notable performance penalty.

On desktop platforms the use of sub-passes won't have any impact on performance 
however this backend can still perform better than Clustered Forward in 
simple scenes thanks to its lower complexity and lower bandwidth usage.
This is especially noticeable on low-end GPUs, integrated graphics or in VR applications.

Given its low-end focus, this backend does not provide high-end rendering
features such as SDFGI and Volumetric fog. Most post-processing effects are also not
available.

@Calinou
Copy link
Member Author

Calinou commented Oct 18, 2022

@Calinou first draft of what could be a replacement Forward Mobile section. Let me know if its usable:

Thanks, I incorporated it 🙂

@skyace65 skyace65 added the area:contributing Issues and PRs related to the Contributing/Development section of the documentation label Jan 13, 2023
@Calinou Calinou force-pushed the add-rendering-architecture branch 4 times, most recently from 34be107 to 3a980e7 Compare February 10, 2023 16:52
@Calinou Calinou marked this pull request as ready for review February 27, 2023 00:23
@Calinou Calinou force-pushed the add-rendering-architecture branch 2 times, most recently from d11cda8 to 52f2c6c Compare February 27, 2023 19:21
@mhilbrunner mhilbrunner marked this pull request as draft March 23, 2023 04:07
@Calinou Calinou changed the title [WIP] Add a page documenting Godot's internal rendering architecture [ci skip] Add a page documenting Godot's internal rendering architecture Apr 22, 2023
@Calinou Calinou marked this pull request as ready for review April 22, 2023 18:34
@Calinou Calinou force-pushed the add-rendering-architecture branch 2 times, most recently from 63a9b71 to 6f838cc Compare April 22, 2023 18:35
@Calinou
Copy link
Member Author

Calinou commented Apr 22, 2023

I've added a small section on recommended OpenGL/Vulkan learning resources, as it may help with understanding concepts on this page (see https://twitter.com/reduzio/status/1649707259281260550).

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Excellent work! This is a fantastic start to a deep documentation of the rendering architecture. I have left a few comments, and I have tried to make suggestions wherever I had a comment. Please let me know if you have any questions about my suggestions

Copy link
Member

@mhilbrunner mhilbrunner left a comment

Choose a reason for hiding this comment

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

Fantastic addition to these contributor-facing docs. I have nothing to add besides Clay's feedback.

@Calinou Calinou force-pushed the add-rendering-architecture branch 2 times, most recently from 5409d3d to 11ec946 Compare May 17, 2023 16:36
This is intended for new and returning engine contributors.
@Calinou Calinou force-pushed the add-rendering-architecture branch from 11ec946 to 00381a5 Compare May 18, 2023 07:56
@mhilbrunner mhilbrunner merged commit c0c7197 into godotengine:master May 18, 2023
@mhilbrunner
Copy link
Member

Thanks for this contribution (and for addressing all the feedback :))! Merged. 🎉 Really good addition.

@Calinou Calinou deleted the add-rendering-architecture branch May 24, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:contributing Issues and PRs related to the Contributing/Development section of the documentation cherrypick:4.0 content:new page Issues and PRs related to creation of new documentation pages for new or undocumented features enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants