Commit Graph

4146 Commits

Author SHA1 Message Date
Thaddeus Crews
f2c8f17906
Merge pull request #100325 from hpvb/fix-rendering-alignment
Fix several ubsan reported misaligned accesses
2024-12-13 16:19:20 -06:00
HP van Braam
e674379764 Fix several ubsan reported misaligned accesses
These misaligned accesses are shown in all of our CI hooks. It turned
out to not be difficult to fix.

It is likely that this will improve performance for aarch64.
2024-12-13 15:32:35 +01:00
clayjohn
356fa37f89 Small fixups for the new reflection probe blending 2024-12-12 17:29:21 -08:00
Thaddeus Crews
bfc66f0608
Merge pull request #100282 from devloglogan/motion-vectors-openxr
Add renderer motion vectors API for use with OpenXR
2024-12-12 16:13:36 -06:00
Thaddeus Crews
7c015a768f
Merge pull request #99958 from lander-vr/reflection-probe-blend-property
Add Blend Distance property to ReflectionProbe
2024-12-12 16:13:32 -06:00
Thaddeus Crews
b7501d219c
Merge pull request #100322 from darksylinc/matias-tf-comment-fix
Fix grammar / spelling in comments
2024-12-12 16:13:25 -06:00
Matias N. Goldberg
a1b44ec7a7 Fix grammar / spelling in comments
Minor fixes for changes introduced in #99257 that could not be fixed in
time as the PR needed to be expedited.
2024-12-12 12:47:08 -03:00
Rémi Verschelde
562dd1ad85
Merge pull request #100305 from clayjohn/directional-light-2d-mask
Remove positional light mask from directional lights in Canvas Item shaders.
2024-12-12 14:10:24 +01:00
Rémi Verschelde
0e5c337453
Merge pull request #85653 from BlueCube3310/lightmap-gi-shadowmask
Implement LightmapGI shadowmasks
2024-12-12 14:09:30 +01:00
BlueCube3310
189c8eb671 Implement shadowmasks for LightmapGI
Co-authored-by: dearthdev <nathandearthdev@gmail.com>
2024-12-12 11:00:28 +01:00
clayjohn
f8827271d7 Remove positional light mask from directional lights in Canvas Item shaders. 2024-12-12 00:20:07 -08:00
Thaddeus Crews
ef3086bcdb
Merge pull request #94947 from ChrisBase/issue_94946
Change some image error messages to output the file path
2024-12-11 17:35:58 -06:00
devloglogan
3deb5884d7 Renderer agnostic motion vector rendering/OpenXR changes 2024-12-10 15:59:17 -06:00
Thaddeus Crews
f962fdce0e
Merge pull request #100185 from Repiteo/scons/fix-thirdparty-warnings
SCons: Fix MSVC bypassing disabled warnings
2024-12-10 14:16:02 -06: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
Thaddeus Crews
a167afd70a
Merge pull request #96771 from clayjohn/RD-static-lighting
Avoid calculating dynamic lights when lights are already baked using the static bake mode in the Forward+ renderer
2024-12-10 14:15:41 -06:00
Thaddeus Crews
a3656083ca
Merge pull request #100065 from clayjohn/mesh-aabb-clear
Clear AABB when Mesh is cleared
2024-12-09 14:33:32 -06:00
Thaddeus Crews
070aeb5688
SCons: Fix MSVC bypassing disabled warnings 2024-12-09 11:49:42 -06: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
Lukas Tenbrink
b5c31ebb41 Add contains_char() for single-character 'contains' calls. 2024-12-06 20:23:35 +01:00
clayjohn
9320865796 Avoid calculating dynamic lights when lights are baked into LightmapGI using the static bake mode 2024-12-06 10:17:44 -08:00
landervr
05010180ce ReflectionProbe add Blend Distance 2024-12-05 23:29:47 +01:00
Thaddeus Crews
8e01601123
Merge pull request #100064 from clayjohn/atlas-realloc-time
Correctly check time since shadow was allocated in atlas to avoid unnecessary re-allocations
2024-12-05 14:12:19 -06:00
Thaddeus Crews
85862ea718
Merge pull request #100058 from DarioSamo/d3d12-texture-limits
Add texture limits for D3D12 Driver.
2024-12-05 14:12:16 -06:00
clayjohn
deac37c464 Clear AABB when Mesh is cleared 2024-12-05 11:40:44 -08:00
clayjohn
1b5a15d5d1 Correctly check time since shadow was allocated in atlas to avoid unnecessary re-allocations
Co-authored-by: jitspoe <jitspoe@yahoo.com>
2024-12-05 11:13:37 -08:00
Dario
d7d6251c30 Add texture limits for D3D12 Driver. 2024-12-05 13:55:57 -03:00
Thaddeus Crews
156bc92282
Merge pull request #98397 from adamscott/add-tmp-support
Add temp utilities (alias `OS::get_temp_dir()`, `FileAccess::create_temp()`, and `DirAccess::create_temp()`)
2024-12-03 14:40:59 -06:00
Thaddeus Crews
608cccc64e
Merge pull request #99919 from bruvzg/ferror
[FileAccess] Set `last_error` on file read/write errors.
2024-12-03 14:40:57 -06:00
Thaddeus Crews
70dae45dd0
Merge pull request #99905 from stuartcarnie/fix_external_texture
Metal: Ensure `texture_create_from_extension` returns correct pixel format
2024-12-03 14:40:55 -06:00
Thaddeus Crews
6478f296bc
Merge pull request #99720 from mrsaturnsan/mac_vsync_fix
Fix vsync on macOS getting disabled when using `afterMinimumDuration`
2024-12-03 14:40:44 -06:00
Stuart Carnie
7caa039183
Metal: Ensure texture_create_from_extension returns correct pixel format 2024-12-03 05:45:50 +11:00
Adam Scott
1b3e483899
Add file and dir temporary utilities
Co-authored by @Alex2782 for the Android bindings.
Many thanks to the reviewers also.

Co-authored-by: Alex <alex.hart.278@gmail.com>
2024-12-02 12:08:14 -05:00
Rémi Verschelde
101b7414d2
Merge pull request #99036 from bruvzg/propkey_rename
[Windows] Rename `PKEY_Device_FriendlyName` to avoid duplicate symbols with newer MinGW SDKs.
2024-12-02 15:51:02 +01:00
bruvzg
d97313cd7d [FileAccess] Set last_error on file read/write errors. 2024-12-02 15:05:50 +02:00
Rémi Verschelde
c2f19e98bc
Merge pull request #98921 from RandomShaper/win_many_files
Raise the number of file handles on Windows
2024-11-29 22:46:54 +01:00
bruvzg
a4b17e7852 [FileAccess] Return error codes from store_* methods. 2024-11-29 23:22:31 +02:00
Thaddeus Crews
6e533b5ee4
Merge pull request #99606 from jamie-pate/fix_99592
Fix gl_compatibility lightmap uniforms not being set
2024-11-27 10:46:58 -06:00
mrsaturnsan
627d10e4c4 Fix vsync on macOS getting disabled when using afterMinimumDuration 2024-11-26 15:38:32 -06:00
Thaddeus Crews
127738c08b
Merge pull request #99387 from 0x0ACB/direct_composition
Use direct composition for d3d12 backend
2024-11-26 13:04:53 -06:00
0x0ACB
a8cd0e9677
Use direct composition for d3d12 backend 2024-11-26 10:28:40 +01:00
Jamie Pate
45a7bcc477 Fix gl_compatibility lightmap uniforms not being set
Fixes #99592

The following variables were set too early, and later code never ran..
prev_shader, prev_variant, prev_spec_constants variables

These variables were shared in two different branch conditions but were
updated inside the first one, so the second could never be true..

The condition to update lighting also should check prev_spec_constants
since it updates that uniform.
2024-11-23 16:43:07 -08:00
Pāvels Nadtočajevs
e9b57fce82 Convert line breaks to \n and strip line break from the end of string returned by OS::read_string_from_stdin/OS::get_stdin_string. 2024-11-23 15:11:50 +02:00
Thaddeus Crews
dcb59f0e7e Merge pull request #99548 from Repiteo/style/clang-format-19-options
Style: Add 19.1.0 LLVM options to `.clang-format`
2024-11-22 14:54:29 -06:00
Thaddeus Crews
e8a4b45ce4
Style: Add 19.1.0 LLVM options to .clang-format 2024-11-22 09:24:32 -06:00
clayjohn
2b68c63a88 Mask out shadows on CanvasItems that don't have a matching item_shadow_mask
This restores the behavior from 3.x
2024-11-21 22:15:54 -08:00
Thaddeus Crews
030cc69771
Merge pull request #96399 from andyprice/fileperms
Unix: Don't create world-writable files when safe save is enabled
2024-11-21 17:56:53 -06:00
Thaddeus Crews
8eee5066eb
Merge pull request #94981 from Chaosus/shader_fix_screen_uv_in_spatial_light
Allow `SCREEN_UV` to be used in light function of spatial shader
2024-11-21 17:56:45 -06:00
Chaosus
a64b3fd3f8 Allow SCREEN_UV to be used in light function of spatial shader 2024-11-19 11:39:49 +03:00
Alexander Hartmann
8e170248b3 Fix: Error output is not require, VK_QUEUE_TRANSFER_BIT is optional. 2024-11-19 03:01:07 +01:00