Commit Graph

69961 Commits

Author SHA1 Message Date
Robin Ward
1e749f628e Fix user selection on top of bgcolor areas in a RichTextLabel 2024-12-09 11:37:37 -05:00
kobewi
3aebcaf4d3 Clarify limit_length() for infinite vectors 2024-12-09 15:53:11 +01: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
Chaosus
a7bb85d2b7 Fix shader crash when using varyings with non-flat integer type 2024-12-09 12:52:01 +03:00
Lukas Tenbrink
8df2dbe2f6 Optimize StringBuilder append for static strings, and as_string(). 2024-12-08 16:39:25 +01:00
David Snopek
3866a7f818 Add missing GDVIRTUAL_BIND() for AudioStream::_has_loop() and ::_get_bar_beats() 2024-12-08 06:38:47 -06:00
Lukas Tenbrink
875b48366c Optimize String.similarity by avoiding allocation for bigrams. 2024-12-08 13:28:40 +01:00
ArchercatNEO
00a791f04e Use temp dirs instead of cache dirs for export
Fixes #95897
During CI scenarios $HOME may be set to an invalid value (such as
`/var/empty`).
Using temp dirs fits better with godot's usage of these paths and is
independent from the user's $HOME.
2024-12-08 12:07:17 +00:00
Andrew
7558bed893 fixed crash when file too short 2024-12-08 01:57:49 -05:00
Juan Pablo Arce
8ab27a7ccf Fix generic arrays and dictionaries not calling set_typed 2024-12-08 01:01:19 -03:00
YoSoyFreeman
72650f9787 Allow apply_floor_snap to preserve the horizontal position after the snapping independently of stop_on_slopes 2024-12-07 23:00:46 +01:00
Serhii Snitsaruk
803fa8f2e8
Export EditorInspector::instantiate_property_editor for use by plugins
And export useful properties and methods in the `EditorProperty` class.
2024-12-07 14:07:04 +01:00
Jakub Marcowski
2481632b3c
thorvg: Regenerate and apply patches 2024-12-07 13:11:37 +01:00
Lukas Tenbrink
e1c42392c2 Improve string copy_from and copy_from_unchecked implementations, by making use of caller contracts and language spec (NULL termination and casts). 2024-12-07 01:41:25 +01:00
Allen Pestaluky
5601e4c18c Forced fixed undo history to make editor shortcuts use global history.
Fixes #76851.
2024-12-06 15:47:00 -05:00
Lukas Tenbrink
b5c31ebb41 Add contains_char() for single-character 'contains' calls. 2024-12-06 20:23:35 +01:00
Yelloween
98a23136d5 Fix missing event metadata in _input() with Input.parse_input_event()
Use merge_meta_from() for metadata copying.

Fixed include order

Removed unnecessary line
2024-12-06 22:08:16 +03: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
Zhiyi Hu
1e62c7f53e Add unit tests to Sky 2024-12-06 10:31:17 -05:00
smix8
4de615d1ae Fix avoidance dirty flag regression
The dirty flag can also still be set by some legacy functions triggered by the agents and obstacles.
2024-12-06 16:20:59 +01:00
Rémi Verschelde
aa8d9b83f6
Merge pull request #99960 from pafuent/fixing_tcp_server_flappy_disconnect_test
Fix `TCPServer` "Should disconnect client" test
2024-12-06 16:16:17 +01:00
Hei
b4c6f9b3d9 Mend gaps in meshes caused by trigonometric funcs. 2024-12-06 17:10:12 +02:00
Nông Văn Tình
e6a49ab6ac Save color palette as resources to reuse later
Co-authored-by: Micky <66727710+Mickeon@users.noreply.github.com>
2024-12-06 20:16:06 +07:00
kobewi
d3c9bee653 Move singleton StringName definitions to header 2024-12-06 13:43:31 +01:00
Danil Alexeev
7d65d0a908
GDScript: Add @warning_ignore_start and @warning_ignore_restore annotations 2024-12-06 15:37:02 +03:00
Timo Schwarzer
1daa9a180b
Fix Control offset_* property types 2024-12-06 09:06:55 +01:00
demolke
964e2b3a9e Fix handling of leading .. in simplify_path
Prior to this `..\..\texture.png` was incorrectly simplified to `texture.png`
2024-12-06 07:53:55 +01:00
clayjohn
f92018288f Ensure schlick is available when using clearcoat with GGX 2024-12-05 19:11:03 -08:00
landervr
05010180ce ReflectionProbe add Blend Distance 2024-12-05 23:29:47 +01:00
David
174e659a48
Add 3D translation sensitivity to Editor Settings 2024-12-05 22:50:52 +01:00
Thaddeus Crews
eb5103093c
Merge pull request #99327 from colinator27/sync-bar-beats
Implement `AudioStreamSynchronized::get_bar_beats()`, fix division by zero
2024-12-05 14:12:26 -06:00
Thaddeus Crews
4b91e98656
Merge pull request #99959 from fire/vsk-csg-error-and-ctd
Print better manifold errors and avoid crash on non manifold csg input.
2024-12-05 14:12:25 -06:00
Thaddeus Crews
7bff6c827f
Merge pull request #99186 from PhairZ/wheels-of-the-bus-go-round-and-round
Fix `fade_beats` defined as `int` in `audio_stream_interactive.h`
2024-12-05 14:12:24 -06:00
Thaddeus Crews
637239e979
Merge pull request #94193 from BastiaanOlij/buildin_includes
Add ability to include built-in include files
2024-12-05 14:12:23 -06:00
Thaddeus Crews
c153f963ce
Merge pull request #99947 from Meorge/ignore-macosx-in-zip
Ignore `__MACOSX` directory for export template and project ZIPs
2024-12-05 14:12:22 -06:00
Thaddeus Crews
45734bd451
Merge pull request #99817 from Ivorforce/strlen-char32_t
Use `strlen()` 3 times instead of custom length check implementations in ustring
2024-12-05 14:12:21 -06: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
6588505aca
Merge pull request #96735 from bruvzg/rtl_frame_indent
[RTL] Fix indent in tables and tables in indent.
2024-12-05 14:12:18 -06:00
Thaddeus Crews
4d0ce3ce76
Merge pull request #100060 from Rudolph-B/Issue-100032
Fixed occlusion culling buffer getting overwritten in larger scenes
2024-12-05 14:12:17 -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
Thaddeus Crews
b34a643404
Merge pull request #96346 from DeeJayLSP/qoa-opt
Use `qoa.c` and custom compress procedure
2024-12-05 14:12:15 -06:00
Thaddeus Crews
30b32396de
Merge pull request #100053 from bruvzg/font_change
Change default Arabic font to Vazirmatn.
2024-12-05 14:12:14 -06:00
Thaddeus Crews
370e5f3b0e
Merge pull request #99920 from lander-vr/reflection-probe-ui-improvements
Clean up UI of ReflectionProbe
2024-12-05 14:12:12 -06:00
Thaddeus Crews
49e033f8e2
Merge pull request #100047 from MBCX/fix-freebsd-compilation
Make Godot compile on `FreeBSD`
2024-12-05 14:12:11 -06:00
Thaddeus Crews
63af934d74
Merge pull request #98506 from 0xafbf/build-linux-with-spaces-in-path
Fix linux builds with separate debug symbols file when there is a space in the path.
2024-12-05 14:12:10 -06:00
Thaddeus Crews
09cbe05485
Merge pull request #76231 from Calinou/inspector-text-show-tooltip
Show String properties' text in a tooltip in the inspector
2024-12-05 14:12:09 -06:00
Thaddeus Crews
f5d82af1fd
Merge pull request #99136 from DarioSamo/light-compute-attenuation-skip
Improve performance of shader lighting code in Forward renderers.
2024-12-05 14:12:08 -06:00
Thaddeus Crews
ef22b6fe82
Merge pull request #100030 from passivestar/mainmenu-valign
Fix vertical alignment of the main menu bar
2024-12-05 14:12:06 -06:00
Thaddeus Crews
a4c2e16c19
Merge pull request #100028 from clayjohn/rd-lights-array
Use a vector instead of an array in canvas shader instance buffer
2024-12-05 14:12:05 -06:00
Thaddeus Crews
68cd7f2e97
Merge pull request #100027 from timothyqiu/efd-improve
Fix UI inconsistencies in `EditorFileDialog`'s toolbar
2024-12-05 14:12:04 -06:00