Commit graph

87 commits

Author SHA1 Message Date
Lukas Rahmann
f7fd65923a Add descriptor heap pooling to D3D12. 2025-09-04 09:17:40 -03:00
Talkashie
3ff4e29657 Typo fix round 2 2025-08-20 04:24:06 -05:00
Talkashie
bc7e68dfd1 Typos 2025-08-19 18:32:59 -05:00
Thaddeus Crews
65b8210b9b
SCons: Revert Mesa includes to CPPPATH 2025-08-18 13:37:46 -05:00
Thaddeus Crews
87bb5ab681
Merge pull request #108919 from KeyboardDanni/d3d12_init_shader_model_check
D3D12: Fix shader model check, initialization error handling
2025-08-01 11:45:19 -05:00
Danni
bf6629a005 D3D12: Fix shader model check, initialization error handling 2025-07-28 20:35:45 -04:00
Dario
b962b38e74 Check for Vulkan Memory Model support and make it a variant. 2025-07-25 09:24:58 -03:00
Stuart Carnie
5230f6c60c Apple: Use image atomic operations on supported Apple hardware
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
2025-07-05 05:59:00 +10:00
Dario
46277836a6 Optimize Mobile renderer by using FP16 explicitly. 2025-06-09 14:39:35 -03:00
Aaron Franke
f6f1df7d73
Add 64-bit versions of core power of 2 functions 2025-06-01 23:11:12 -07:00
Dario
5a30a7e7cd Add shader baker to project exporter.
Metal Support contributed by Migeran (https://migeran.com) and Stuart Carnie.

Co-authored-by: Stuart Carnie <stuart.carnie@gmail.com>
Co-authored-by: Gergely Kis <gergely.kis@migeran.com>
2025-05-27 12:45:27 -03:00
Pedro J. Estébanez
7759296594 Direct3D 12: Let platforms report support for direct composition 2025-05-14 17:48:19 +02:00
Sander
6ae50cad17 RenderingDevice: introduce parameter 'mipmaps' for texture_create_from_extension() 2025-05-07 15:15:55 +03:00
Dario
ddd3ced72d Fix error spam to due wrong use of reserve() in D3D12 driver. 2025-04-29 10:42:55 -03:00
Matthieu Bucchianeri
e3c215fc13 Add support for Direct3D 12 OpenXR backend.
This change adds support for running XR projects built with the `d3d12`
rendering backend. The XR backend hooks into the setup for the D3D12
render context in order to use the desired device and command queue for
submission to OpenXR. The XR backend takes care of importing the D3D12
swapchain images into the render context.

As part of this process, three issues are addressed:
- Ensuring that resource state transitions are only done on textures
  that require them.
- Enabling view instancing in the PSOs for multiview render passes.
- Addressing a bug in the D3D12 runtime where PSO creation may fail
  when front face detection is used.

Please refer to #86283 for additional discussions on the implementation
details.
2025-04-19 20:39:33 -07:00
Thaddeus Crews
0d267e7b1e
Core: Add dedicated BitField template 2025-04-11 11:53:26 -05:00
Thaddeus Crews
207a2b6472
Core: Integrate warning suppression macro helpers 2025-04-03 10:13:46 -05:00
Thaddeus Crews
f25fc34439
SCons: Add CPPEXTPATH for external includes 2025-04-02 07:29:08 -05:00
Thaddeus Crews
780cf03051
Merge pull request #104556 from Ivorforce/string-extend-instead-of-parse
Use `append_` instead of `parse_` for `String` methods.
2025-03-29 10:16:33 -05:00
Rémi Verschelde
408d07109b
Merge pull request #99551 from DarioSamo/fragment-density-map
Implement Fragment density map support.
2025-03-28 14:31:19 +01:00
Lukas Tenbrink
ffa6ef220b Use append_ instead of parse_ for String methods. 2025-03-27 17:51:02 +01:00
Dario
76d709be74 Implement support for fragment density maps.
Co-Authored-By: Bastiaan Olij <mux213@gmail.com>
2025-03-24 11:50:04 -05:00
Lukas Tenbrink
a23f630781 Remove String clipping constructors.
Callers should instead call constructors with explicit encoding names, with known length `Span`.
2025-03-15 12:34:44 +01:00
Thaddeus Crews
4bafafaeb3
Merge pull request #102777 from darksylinc/matias-astc-hdr
Add ASTC HDR format variants
2025-03-06 16:36:06 -06:00
clayjohn
338c12fc9a Implement LIMIT_MAX_COMPUTE_SHARED_MEMORY_SIZE to limit_get in all Rendering backends.
Also add a more helpful warning that is only displayed in dev builds to
match the D3D12 backend
2025-03-03 21:43:12 -08:00
clayjohn
35100396e4 Validate varying count when compiling shaders
This avoids crashing on devices when a number of varyings greater than the device limit is used.

For now this accurately prints an error when compiling the shader, but the error text only pops up in the editor if the number of user varyings is above the limit.
2025-02-13 15:07:15 -08:00
Matias N. Goldberg
fcd785ace2 Add ASTC HDR format variants 2025-02-13 11:45:42 -03:00
thimenesup
3d92f406b2 Implement Buffer Device Address for Rendering Device Vulkan and DirectX12 2025-01-13 22:43:29 -08:00
Aarni Koskela
f134769506 Fix various typos
* Add TODO notes for typos that should be fixed for 5.0

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
2025-01-08 14:47:42 +02:00
alessand10
9ea97c017b Fix a command buffer leak that occurs in dx12 2024-12-17 14:55:39 -05: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
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
d7d6251c30 Add texture limits for D3D12 Driver. 2024-12-05 13:55:57 -03:00
0x0ACB
a8cd0e9677
Use direct composition for d3d12 backend 2024-11-26 10:28:40 +01:00
Thaddeus Crews
150590a7e8
Merge pull request #98975 from clayjohn/D3D12-event-timing
Move D3D12 fence `SetEventOnCompletion` call to `fence_wait` to avoid stalling on some platforms
2024-11-13 08:33:55 -06:00
clayjohn
05576a2324 Move D3D12 fence SetEventOnCompletion call to fence_wait to avoid stalling on some platforms 2024-11-08 13:20:05 -08:00
Dario
5216ef5f9c Add dependency detection improvements to the render graph.
- Buffers changing their usage are no longer treated as write usage unless the API requires it.
- Draw lists are not treated as being dependent on each other if their regions do not intersect despite both being write commands.
- Particles were tweaked to use different unused buffers to reduce dependencies.
2024-11-01 09:46:52 -03:00
Thaddeus Crews
b7a0971ad2
Merge pull request #97934 from adamscott/give-AThousandShips-a-break
[Codestyle] Set clang-format `RemoveSemicolon` rule to `true`
2024-10-29 19:25:36 -05:00
Clay John
683d11a69f
Merge pull request #98279 from Calinou/vulkan-d3d12-silence-using-present-mode
Remove "Using present mode" verbose prints in Vulkan and Direct3D 12
2024-10-27 19:24:35 -07:00
Adam Scott
0d350e7108
Set clang-format RemoveSemicolon rule to true
- Set clang-format `Standard` rule to `c++20`
2024-10-25 13:49:43 -04:00
Dario
8c3e46b13b Move transitions of textures initialized by transfer workers to the main graphics queue.
Also adds a new possible texture layout and API trait to support a particular behavior in D3D12 where only the COMMON layout is supported in copy queues. Fixes #98158.
2024-10-18 09:15:25 -03:00
Hugo Locurcio
5ed10e3604 Remove "Using present mode" verbose prints in Vulkan and Direct3D 12
These messages were printed every time the swapchain was recreated
(e.g. on viewport size change), which could easily end up spamming
the output.

The chosen present mode is already displayed when using the Print FPS
project setting or command line argument.
2024-10-17 23:18:28 +02:00
Thaddeus Crews
a44f691fc7
CI: Add MinGW/GCC build to Windows GHA 2024-10-10 10:10:55 -05: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
Rémi Verschelde
c92a6c7e27
CI: Update clang-format pre-commit hook to 19.1.0 2024-09-26 11:46:12 +02:00
Matias N. Goldberg
364f916f3f
Add debug utilities for Vulkan
Features:
- Debug-only tracking of objects by type. See
get_driver_allocs_by_object_type et al.
 - Debug-only Breadcrumb info for debugging GPU crashes and device lost
 - Performance report per frame from get_perf_report
- Some VMA calls had to be modified in order to insert the necessary
memory callbacks

Functionality marked as "debug-only" is only available in debug or dev
builds.

Misc fixes:
 - Early break optimization in RenderingDevice::uniform_set_create

============================

The work was performed by collaboration of TheForge and Google. I am
merely splitting it up into smaller PRs and cleaning it up.
2024-08-21 23:48:08 +02:00
Rémi Verschelde
1fea6ed01c
Merge pull request #94733 from RandomShaper/d3d12_tex_barr_fast
D3D12: Be explicit about all-resources texture barriers
2024-08-16 10:34:49 +02:00
Rémi Verschelde
cddf321d30
Merge pull request #94731 from RandomShaper/d3d12_no_null_barr_grps
D3D12: Avoid validation warnings about zero-sized barrier groups
2024-08-16 10:34:42 +02:00
Pedro J. Estébanez
8cf2903c7f D3D12: Avoid cases of redundant render target clears 2024-08-02 14:26:17 +02:00
Pedro J. Estébanez
3260437afc D3D12: Be explicit about all-resources texture barriers 2024-07-25 15:06:42 +02:00