1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00
Commit Graph

336 Commits

Author SHA1 Message Date
Thaddeus Crews
0fb0804546 Merge pull request #103641 from darksylinc/matias-mobile-shadows-update
Fix inefficient upload in Mobile Shadows
2025-03-11 09:35:05 -05:00
Thaddeus Crews
dfdb5359ea Merge pull request #103547 from clayjohn/forward-plus_instance_data_optimize
Optimize `_fill_instance_data` function in Forward+ renderer.
2025-03-09 09:05:19 -05:00
clayjohn
5efcd64b23 Reduce per-frame memory allocations from the heap in the Mobile renderer. 2025-03-07 22:01:24 -08:00
clayjohn
574f5126a2 Optimize _fill_instance_data function in Forward+ and Mobile renderers.
This batches together a couple of micro-optimizations that were discovered in profiling and analyzing disassembly.

Importantly, this reduces the amount of instructions in a heavy loop. This has the biggest impact when there are lots of objects and lights in the scene as the function is called once per objects + once per light that touches the object
2025-03-07 15:44:53 -08:00
Thaddeus Crews
324512e11c Style: Replace header guards with #pragma once 2025-03-07 17:33:47 -06:00
Thaddeus Crews
b6ece17de1 Merge pull request #103529 from clayjohn/RD-trivial-instance-data
Validate triviality of InstanceData struct in Mobile and Forward+ renderers
2025-03-06 16:36:14 -06:00
Matias N. Goldberg
e605ad93c7 Fix inefficient upload in Mobile Shadows
Clustered performs the following shadow rendering steps

1. Process objects [0; 10) for cascade 0.
2. Process objects [10; 30) for cascade 1.
3. Process objects [30; 100) for cascade 2.
4. Upload objects [0; 100) to GPU.
5. Draw all cascades.

Mobile was supposed to be doing the same, but instead was doing:

1. Process objects [0; 10) for cascade 0.
2. Upload objects [0; 10) to GPU.
3. Process objects [10; 30) for cascade 1.
4. Upload objects [0; 30) to GPU.
5. Process objects [30; 100) for cascade 2.
6. Upload objects [0; 100) to GPU.
7. Draw all cascades.

That is, always reuploaded everything from scratch.
Therefore it pointlessly (and with geometric growth) wasted BW.
2025-03-05 15:21:25 -03:00
Thaddeus Crews
729c4e9e88 Merge pull request #102905 from kleonc/render_info_fix_primitive_count_per_triangle_strip
Fix render info primitive count per `TRIANGLE_STRIP`
2025-03-05 12:07:47 -06:00
Matias N. Goldberg
62c1a4782d Fix inefficient upload in Mobile Shadows
Clustered performs the following shadow rendering steps

1. Process objects [0; 10) for cascade 0.
2. Process objects [10; 30) for cascade 1.
3. Process objects [30; 100) for cascade 2.
4. Upload objects [0; 100) to GPU.
5. Draw all cascades.

Mobile was supposed to be doing the same, but instead was doing:

1. Process objects [0; 10) for cascade 0.
2. Upload objects [0; 10) to GPU.
3. Process objects [10; 30) for cascade 1.
4. Upload objects [0; 30) to GPU.
5. Process objects [30; 100) for cascade 2.
6. Upload objects [0; 100) to GPU.
7. Draw all cascades.

That is, always reuploaded everything from scratch.
Therefore it pointlessly (and with geometric growth) wasted BW.
2025-03-03 19:57:27 -03:00
clayjohn
1bdb3bc88a Validate triviality of the InstanceData and RenderElementInfo structs in Mobile and Forward+ renderers.
This is needed to avoid overhead that results from calling the constructor during calls to LocalVector.resize()
2025-03-03 14:38:37 -08:00
kleonc
b691a997a3 Fix render info primitive count per TRIANGLE_STRIP 2025-02-15 23:50:07 +01:00
clayjohn
7444839299 Reduce mobile pipeline compilations by tracking more feature usage globally and only compile what is needed 2025-02-05 18:27:23 -08:00
Dario
d0c29faa15 Mark pipeline compilation of ubershaders as high priority. 2025-01-28 11:40:05 -03:00
Matias N. Goldberg
7b2f1e1d09 Fix union order to simplify empty initializers
This is a followup to PR #101344 (commit
0e06eb80bc).

Some of them were not an issue because Godot was initializing all
members, but they were "fixed" just in case since it could become a
problem in the future.

Valgrind was specifically complaining about HashMapData &
GlobalPipelineData.
2025-01-14 19:05:01 -03:00
David House
e6daec9cf8 Added indirect drawing functionality to MultiMesh
Update doc/classes/RenderingServer.xml

Co-Authored-By: Micky <66727710+Mickeon@users.noreply.github.com>
2025-01-13 14:51:51 -06:00
Rémi Verschelde
3014eec40d Merge pull request #99407 from devloglogan/rec-resolution
Allow using custom `Rect2i` for rendering with OpenXR
2025-01-10 23:05:46 +01:00
devloglogan
e7f6b7ea0b Allow using custom Rect2i for rendering with OpenXR 2025-01-09 09:46:15 -06:00
Dario
0e06eb80bc Fix union order to simplify empty initializers. 2025-01-09 10:39:13 -03:00
Rémi Verschelde
084da581be Merge pull request #100241 from lander-vr/reflection-probe-priority
Add priority-based blending to reflection probes.
2025-01-07 10:14:38 +01:00
landervr
1637736c20 ReflectionProbe priority 2024-12-23 21:58:11 +01:00
Yufeng Ying
e88e30c273 Remove unused headers in servers.
Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
2024-12-20 18:51:01 +08:00
Thaddeus Crews
2fcd8223e8 Merge pull request #99538 from Geometror/lightmap-gi-transparent-surface
Add transparency support for LightmapGI
2024-12-19 19:59:52 -06:00
Alex Threlfo
5f617663aa fix: separate sky luminance and user brightness calculations around fog 2024-12-20 11:25:11 +11:00
Hendrik Brucker
a3525bc015 Add transparency support for LightmapGI
Co-authored-by: Guerro323 <kaltobattle@gmail.com>
2024-12-18 19:36:16 +01:00
Thaddeus Crews
dc5f1b7a28 Merge pull request #100319 from Flarkk/fix_light_shadow_range
Fix shadows of long range `OmniLight3D` and `SpotLight3D`
2024-12-13 16:19:39 -06:00
Thaddeus Crews
9ecdeb3723 Merge pull request #98747 from tetrapod00/standardize-renderer-strings
Standardize terms for renderers in error strings
2024-12-13 16:19:37 -06:00
Thaddeus Crews
6594a6364e Merge pull request #100213 from DarioSamo/pipeline-hash-map-thread-safety
Improve thread-safety of pipeline hash map.
2024-12-13 16:19:34 -06:00
Florent Guiocheau
5125adf40b Fix large range point lights shadows 2024-12-12 15:37:38 +01:00
BlueCube3310
189c8eb671 Implement shadowmasks for LightmapGI
Co-authored-by: dearthdev <nathandearthdev@gmail.com>
2024-12-12 11:00:28 +01:00
Thaddeus Crews
66dea152b5 Merge pull request #99257 from darksylinc/matias-TheForge-pr04-excluded-ubo+render_opt
Improvements from TheForge
2024-12-10 14:15:55 -06:00
clayjohn
fce34f22a2 Avoid error spam when shaders fail to compile by freeing shader_data version when compilation fails 2024-12-09 10:51:57 -08:00
Dario
be1dce1071 Improve thread-safety of pipeline hash map. 2024-12-09 15:12:40 -03:00
Matias N. Goldberg
c77cbf096b Improvements from TheForge (see description)
The work was performed by collaboration of TheForge and Google. I am
merely splitting it up into smaller PRs and cleaning it up.

This is the most "risky" PR so far because the previous ones have been
miscellaneous stuff aimed at either [improve
debugging](https://github.com/godotengine/godot/pull/90993) (e.g. device
lost), [improve Android
experience](https://github.com/godotengine/godot/pull/96439) (add Swappy
for better Frame Pacing + Pre-Transformed Swapchains for slightly better
performance), or harmless [ASTC
improvements](https://github.com/godotengine/godot/pull/96045) (better
performance by simply toggling a feature when available).

However this PR contains larger modifications aimed at improving
performance or reducing memory fragmentation. With greater
modifications, come greater risks of bugs or breakage.

Changes introduced by this PR:

TBDR GPUs (e.g. most of Android + iOS + M1 Apple) support rendering to
Render Targets that are not backed by actual GPU memory (everything
stays in cache). This works as long as load action isn't `LOAD`, and
store action must be `DONT_CARE`. This saves VRAM (it also makes
painfully obvious when a mistake introduces a performance regression).
Of particular usefulness is when doing MSAA and keeping the raw MSAA
content is not necessary.

Some GPUs get faster when the sampler settings are hard-coded into the
GLSL shaders (instead of being dynamically bound at runtime). This
required changes to the GLSL shaders, PSO creation routines, Descriptor
creation routines, and Descriptor binding routines.

 - `bool immutable_samplers_enabled = true`

Setting it to false enforces the old behavior. Useful for debugging bugs
and regressions.

Immutable samplers requires that the samplers stay... immutable, hence
this boolean is useful if the promise gets broken. We might want to turn
this into a `GLOBAL_DEF` setting.

Instead of creating dozen/hundreds/thousands of `VkDescriptorSet` every
frame that need to be freed individually when they are no longer needed,
they all get freed at once by resetting the whole pool. Once the whole
pool is no longer in use by the GPU, it gets reset and its memory
recycled. Descriptor sets that are created to be kept around for longer
or forever (i.e. not created and freed within the same frame) **must
not** use linear pools. There may be more than one pool per frame. How
many pools per frame Godot ends up with depends on its capacity, and
that is controlled by
`rendering/rendering_device/vulkan/max_descriptors_per_pool`.

- **Possible improvement for later:** It should be possible for Godot
to adapt to how many descriptors per pool are needed on a per-key basis
(i.e. grow their capacity like `std::vector` does) after rendering a few
frames; which would be better than the current solution of having a
single global value for all pools (`max_descriptors_per_pool`) that the
user needs to tweak.

 - `bool linear_descriptor_pools_enabled = true`

Setting it to false enforces the old behavior. Useful for debugging bugs
and regressions.
Setting it to false is required when workarounding driver bugs (e.g.
Adreno 730).

A ridiculous optimization. Ridiculous because the original code
should've done this in the first place. Previously Godot was doing the
following:

  1. Create a command buffer **pool**. One per frame.
  2. Create multiple command buffers from the pool in point 1.
3. Call `vkBeginCommandBuffer` on the cmd buffer in point 2. This
resets the cmd buffer because Godot requests the
`VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT` flag.
  4. Add commands to the cmd buffers from point 2.
  5. Submit those commands.
6. On frame N + 2, recycle the buffer pool and cmd buffers from pt 1 &
2, and repeat from step 3.

The problem here is that step 3 resets each command buffer individually.
Initially Godot used to have 1 cmd buffer per pool, thus the impact is
very low.

But not anymore (specially with Adreno workarounds to force splitting
compute dispatches into a new cmd buffer, more on this later). However
Godot keeps around a very low amount of command buffers per frame.

The recommended method is to reset the whole pool, to reset all cmd
buffers at once. Hence the new steps would be:

  1. Create a command buffer **pool**. One per frame.
  2. Create multiple command buffers from the pool in point 1.
3. Call `vkBeginCommandBuffer` on the cmd buffer in point 2, which is
already reset/empty (see step 6).
  4. Add commands to the cmd buffers from point 2.
  5. Submit those commands.
6. On frame N + 2, recycle the buffer pool and cmd buffers from pt 1 &
2, call `vkResetCommandPool` and repeat from step 3.

**Possible issues:** @dariosamo added `transfer_worker` which creates a
command buffer pool:

```cpp
transfer_worker->command_pool =
driver->command_pool_create(transfer_queue_family,
RDD::COMMAND_BUFFER_TYPE_PRIMARY);
```

As expected, validation was complaining that command buffers were being
reused without being reset (that's good, we now know Validation Layers
will warn us of wrong use).
I fixed it by adding:

```cpp
void RenderingDevice::_wait_for_transfer_worker(TransferWorker
*p_transfer_worker) {
	driver->fence_wait(p_transfer_worker->command_fence);
	driver->command_pool_reset(p_transfer_worker->command_pool); //
! New line !
```

**Secondary cmd buffers are subject to the same issue but I didn't alter
them. I talked this with Dario and he is aware of this.**
Secondary cmd buffers are currently disabled due to other issues (it's
disabled on master).

 - `bool RenderingDeviceCommons::command_pool_reset_enabled`

Setting it to false enforces the old behavior. Useful for debugging bugs
and regressions.

There's no other reason for this boolean. Possibly once it becomes well
tested, the boolean could be removed entirely.

Adds `command_bind_render_uniform_sets` and
`add_draw_list_bind_uniform_sets` (+ compute variants).

It performs the same as `add_draw_list_bind_uniform_set` (notice
singular vs plural), but on multiple consecutive uniform sets, thus
reducing graph and draw call overhead.

 - `bool descriptor_set_batching = true;`

Setting it to false enforces the old behavior. Useful for debugging bugs
and regressions.

There's no other reason for this boolean. Possibly once it becomes well
tested, the boolean could be removed entirely.

Godot currently does the following:

 1. Fill the entire cmd buffer with commands.
 2. `submit()`
    - Wait with a semaphore for the swapchain.
- Trigger a semaphore to indicate when we're done (so the swapchain
can submit).
 3. `present()`

The optimization opportunity here is that 95% of Godot's rendering is
done offscreen.
Then a fullscreen pass copies everything to the swapchain. Godot doesn't
practically render directly to the swapchain.

The problem with this is that the GPU has to wait for the swapchain to
be released **to start anything**, when we could start *much earlier*.
Only the final blit pass must wait for the swapchain.

TheForge changed it to the following (more complicated, I'm simplifying
the idea):

 1. Fill the entire cmd buffer with commands.
 2. In `screen_prepare_for_drawing` do `submit()`
    - There are no semaphore waits for the swapchain.
    - Trigger a semaphore to indicate when we're done.
3. Fill a new cmd buffer that only does the final blit to the
swapchain.
 4. `submit()`
    - Wait with a semaphore for the submit() from step 2.
- Wait with a semaphore for the swapchain (so the swapchain can
submit).
- Trigger a semaphore to indicate when we're done (so the swapchain
can submit).
 5. `present()`

Dario discovered this problem independently while working on a different
platform.

**However TheForge's solution had to be rewritten from scratch:** The
complexity to achieve the solution was high and quite difficult to
maintain with the way Godot works now (after Übershaders PR).
But on the other hand, re-implementing the solution became much simpler
because Dario already had to do something similar: To fix an Adreno 730
driver bug, he had to implement splitting command buffers. **This is
exactly what we need!**. Thus it was re-written using this existing
functionality for a new purpose.

To achieve this, I added a new argument, `bool p_split_cmd_buffer`, to
`RenderingDeviceGraph::add_draw_list_begin`, which is only set to true
by `RenderingDevice::draw_list_begin_for_screen`.

The graph will split the draw list into its own command buffer.

 - `bool split_swapchain_into_its_own_cmd_buffer = true;`

Setting it to false enforces the old behavior. This might be necessary
for consoles which follow an alternate solution to the same problem.
If not, then we should consider removing it.

PR #90993 added `shader_destroy_modules()` but it was not actually in
use.

This PR adds several places where `shader_destroy_modules()` is called
after initialization to free up memory of SPIR-V structures that are no
longer needed.
2024-12-09 11:49:28 -03:00
Dario
fa7615be9e Add specialization for directional light split blend and fog. 2024-12-03 15:12:46 -03:00
CrazyRoka
d9ef826c54 Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00
Dario
6d5ac8f7ef Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
clayjohn
02efdb28dc Unify y-flip behavior for sky in RD backends 2024-11-19 16:59:04 -08:00
Thaddeus Crews
fd4c29a189 Merge pull request #98683 from clayjohn/wireframe
Ensure shadow material and mesh are not used with wireframe mode
2024-11-18 09:23:54 -06:00
BlueCube3310
bb3d0045b0 Fix updating lightmap captures on Mobile 2024-11-17 19:29:21 +01:00
clayjohn
90b4b48b5a Ensure shadow material and mesh are not used with wireframe mode
And in the Compatibility renderer actually use the wireframe render mode
2024-11-16 22:25:00 -08:00
tetrapod00
899f5151c3 Standardize terms for renderers in error strings
Use "Forward+", "Mobile", "Compatibility", and "renderer" or "rendering method".
2024-11-10 13:30:44 -08:00
Thaddeus Crews
88d9903f6d Merge pull request #86138 from EnlightenedOne/master
Fix Frustum Sky projection translation logic shearing
2024-11-04 21:52:07 -06:00
Dario
53099c56f0 Add multiple specialization constants to Forward+ and Mobile. 2024-11-04 14:35:40 -03:00
EnlightenedOne
1d141ab32a Fix Frustum Sky projection translation logic, all pipelines, fixes 63863 2024-11-02 21:34:55 +00:00
Dario
427ba09efc Fix soft shadows by increasing the bit count for specialization constants. 2024-10-28 10:26:50 -03:00
Chaosus
463e81413e Make OUTPUT_IS_SRGB/CLIP_SPACE_FAR shader built-ins global 2024-10-24 12:32:05 +03:00
Dario
e2c6daf7ef Implement asynchronous transfer queues, thread guards on RenderingDevice. Add ubershaders and rework pipeline caches for Forward+ and Mobile.
- Implements asynchronous transfer queues from PR #87590.
- Adds ubershaders that can run with specialization constants specified as push constants.
- Pipelines with specialization constants can compile in the background.
- Added monitoring for pipeline compilations.
- Materials and shaders can now be created asynchronously on background threads.
- Meshes that are loaded on background threads can also compile pipelines as part of the loading process.
2024-10-02 15:11:58 -03:00
ywmaa
0a9ad8f9de Implement vertex shading
This adds support in all backends, but the Compatibility renderer works the best.
Mobile and Forward+ can only support one directional light shader (the first in the tree)
While the Compatibility renderer supports any number of shadows.

Co-authored-by: Clay John <claynjohn@gmail.com>
2024-09-29 00:36:09 +02:00
Thaddeus Crews
9f9ee0c813 SCons: Add unobtrusive type hints in SCons files 2024-09-25 09:34:35 -05:00
Thaddeus Crews
b37fc1014a Style: Apply new clang-format changes 2024-09-20 08:09:48 -05:00