Commit Graph

413 Commits

Author SHA1 Message Date
HP van Braam 52f27370ab Fix a deadlock in CanvasRenderRD
RenderingServerDefault::_draw wants to get all of the materials. The threaded
loader is still loading the materials:

1) The main thread locks canvas_singleton->shader.mutex via
   RendererRD::Utilities::update_dirty_resources
    -> RendererRD::MaterialStorage::_update_queued_materials
      -> RendererCanvasRenderRD::CanvasMaterialData::update_parameters()
2) RendererCanvasRenderRD::CanvasMaterialData::update_parameters() wants
   to get the current shader via ShaderRD::version_get_shader. This
   eventually wants to wait on the load of that shader via
   WorkerThreadPool::wait_for_group_task_completion in
   ShaderRD::_compile_version_end

At this point the main thread is waiting for the threaded load to finish
loading the shader. Meanwhile in a thread not too far away the load is
progressing:

1) The loader is loading the tres in ResourceLoaderText::load which
   eventually wants to ShaderMaterial::set_shader
2) We eventually end up in RendererCanvasRenderRD::CanvasShaderData::set_code
3) set_code wants to lock canvas_singleton->shader.mutex to protect
   against concurrent compilation

At this point the main thread is waiting on the load to complete, but
holds "canvas_singleton->shader.mutex" via update_parameters(), and the
loader is waiting on "canvas_singleton->shader.mutex" in set_code.

Tragedy ensues etc.

To fix the problem we don't acquire the lock until after we're sure
we're done compiling the shader.

The same pattern exists in scene_shader_forward_clustered.cpp which
was created in the same commit as the code in the canvas singleton.

With this change the deadlock can no longer occur as set_code() can now run
concurrently with RenderingServerDefault::_draw() as the path where the
main thread waits on the workerthreadpool with
canvas_singleton->shader.mutex held can no longer occur.

Data integrity wise: previously you'd think that
canvas_singleton->shader.mutex would have protected against metadata
changes to uniforms, ubo_offsets, and texture_uniforms but set_code() used
to write to some of these (uniforms, ubo_size) without taking the lock with
no ill effects because the material isn't updated until the shader has loaded.

A similar pattern was found in scene_shader_forward_mobile.cpp and was
fixed in the same way.
2026-06-08 00:22:02 +02:00
Skyth c6987624ef Disable ubershaders on problematic Adreno compiler versions. 2026-05-21 22:13:32 +03:00
Thaddeus Crews aaaf76403e Merge pull request #119223 from Calinou/render-timestamp-add-setup-shadows
Add Setup Shadows render timestamp for the visual profiler
2026-05-07 16:22:28 -05:00
Stuart Carnie 64a1a66a14 Rendering: Zero double InstanceData fields
Root cause was unitinitialised stack variable.

I was able to reproduce by enabling this build-flag:

```
-ftrivial-auto-var-init=pattern
```

which initialises stack allocated variables with hostile values.

Closes #118918
2026-05-07 19:06:42 +10:00
Hugo Locurcio 376bea65e0 Add Setup Shadows render timestamp for the visual profiler
- Rename shadow timestamp to clarify it's for directional and spot shadows.
- Fix Render OmniLight Shadows timestamp being visible even when no
  omnilight shadows are being rendered.
2026-05-04 19:30:14 +02:00
CookieBadger 7c532acc09 change LTC lookup table texture format to RGBAF and set p_8bit_dst to true in gaussian_blur 2026-04-27 21:35:46 +02:00
David Snopek 0c00e99d39 Fix Parameter "rt" is null when toggling ReflectionProbe visibility 2026-04-19 08:45:54 -05:00
CookieBadger 7b7bd1dcea Add AreaLight3D 2026-04-04 01:37:10 +02:00
David Snopek 4d218bdeb7 OpenXR: Allow using Vulkan subsampled images with foveated rendered 2026-03-05 11:00:37 -06:00
Rémi Verschelde e3b60a1530 Move RenderingMethod::RenderInfo to RenderingServerTypes
Also move RS::scaling_3d_mode_type to RenderingServerEnums.
2026-02-25 20:17:28 +01:00
Rémi Verschelde 0ce92073ae Move RS::ShaderNativeSourceCode to RenderingServerTypes to reduce dependencies on RS
On my machine, this reduces incremental compilation time after an edit of
`rendering_server.h` by 1s, and paves the way for more decoupling in
rendering code.
2026-02-25 20:17:27 +01:00
Rémi Verschelde a3cb56dd38 Decouple RenderingServer from XR/OpenXR headers
Move BlitToScreen to RenderingServerTypes.
2026-02-25 20:17:23 +01:00
Rémi Verschelde f5a290ac46 Move RenderingServer enums to a dedicated RenderingServerEnums (RSE) namespace
A number of headers in the codebase included `rendering_server.h` just for
some enum definitions. This means that any change to `rendering_server.h` or
one of its dependencies would trigger a massive incremental rebuild.

With this change, we decouple a number of classes from `rendering_server.h`,
greatly speeding up incremental rebuilds for that area.

On my machine, this reduces incremental compilation time after an edit of
`rendering_server.h` by 60s (from 2m57s).
2026-02-25 19:43:03 +01:00
Lukas Tenbrink 0ea5ece984 Move binary math functions to Math namespace in math_funcs_binary header. 2026-02-17 12:24:35 +01:00
jon1solution 979d3e58d0 Keeping the top N lights per mesh in the culling phase.
Previously, each mesh was paired up with the first N of each Omni- and Spot-lights.
Now each light is scored based on its distance to the mesh, energy, and range.
The new code uses a heap to track the best N lights (of each type) for predictability.
2026-02-02 08:59:30 -08:00
Bastiaan Olij aac883849e Apply fixed size properly for mono/stereo rendering. 2026-01-20 23:19:45 +11:00
clayjohn 87217e50ef Use luminance multiplier for sky background when using mobile renderer with HDR2D 2026-01-09 09:59:22 -08:00
Skyth c1d7c097b1 Pass consistent viewport and screen sizes to fix point size emulation. 2025-12-19 14:51:49 +03:00
Skyth f6298405f3 Fix radiance/reflection fallback texture types. 2025-12-03 16:15:56 +03:00
Dario c78c3ba894 Rewrite Radiance and Reflection probes to use Octahedral maps.
Co-authored-by: clayjohn <claynjohn@gmail.com>
2025-12-02 17:48:12 -08:00
Skyth ba556ebe03 Implement point size emulation in the forward shader for D3D12. 2025-12-02 17:36:31 +03:00
Bastiaan Olij 21ffbecfa9 Resolve depth buffer in pass if supported by driver 2025-11-17 17:29:38 +11:00
Stuart Carnie 90c0e6acca 2D: Switch to VBOs for instance data
- Add support for vertex bindings and UMA vertex buffers in D3D12.
- Simplify 2D instance params and move more into per-batch data to save
  bandwidth

Co-authored-by: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com>
Co-authored-by: Clay John <claynjohn@gmail.com>
Co-authored-by: A Thousand Ships <96648715+athousandships@users.noreply.github.com>
2025-11-15 06:25:49 +11:00
Stuart Carnie 230adb7511 Add Persistent Buffers
This work is a heavily refactored and rewritten from TheForge's initial
code.

TheForge's original code had too many race conditions and was
fundamentally flawed as it was too easy to incur into those data races
by accident.

However they identified the proper places that needed changes, and the
idea was sound. I used their work as a blueprint to design this work.

This PR implements:

 - Introduction of UMA buffers used by a few buffers
(most notably the ones filled by _fill_instance_data).

Ironically this change seems to positively affect PC more than it does
on Mobile.

Updates D3D12 Memory Allocator to get GPU_UPLOAD heap support.

Metal implementation by Stuart Carnie.

Co-authored-by: Stuart Carnie <stuart.carnie@gmail.com>
Co-authored-by: TheForge team
2025-10-24 08:16:19 +11:00
clayjohn f61ee7bdf6 Use half float precision buffer for 3D when HDR2D is enabled
This is necessary for Environment effects like Glow to work correctly.
2025-10-21 13:44:46 -07:00
Skyth c128886c63 Overhaul screen space reflections. 2025-10-21 19:23:38 +03:00
Dario b49aea89d0 Organize render surface sorting key for optimizing API performance. 2025-10-15 11:35:02 -03:00
Kaleb Reid 8a8bd02860 Use correct shadow material in some cases in Mobile 2025-10-14 13:44:09 -07:00
Thaddeus Crews 8150cb9200 Merge pull request #111403 from AeioMuch/fix_double_precision_wrong_indexes
Fix wrong indices used for transform & UBO matrix for double precision build
2025-10-10 10:25:59 -05:00
AeioMuch dae2122388 Fix wrong indexes for double precision 2025-10-09 22:01:41 +02:00
Allen Pestaluky bd9d1bf070 Add material debanding for use in Mobile rendering method.
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
2025-10-08 16:22:41 -04:00
clayjohn c7276273d8 Fix scene shader crash due to rename of view matrix and inverse view matrix 2025-10-07 13:36:23 -07:00
Thaddeus Crews f85dc0720d Merge pull request #111303 from Kaleb-Reid/fix-dof-msaa-mobile
Use resolved depth texture for DOF with MSAA in Mobile
2025-10-06 09:06:38 -05:00
Kaleb Reid ac8491ae72 Use resolved depth texture for DOF with MSAA in Mobile 2025-10-05 13:51:42 -07:00
BlueCube3310 24ed12d4a3 Fix LightmapGI not being correctly applied to objects 2025-10-01 19:18:09 +02:00
Thaddeus Crews 2b7f39ea28 Merge pull request #110505 from Calinou/tweak-draw-command-labels
Tweak draw command label names for consistency
2025-09-30 20:10:37 -05:00
Aaron Franke 9fbf5808a0 Rename server "free" functions to "free_rid" to match exposed API 2025-09-30 16:52:25 -07:00
Thaddeus Crews f9694033a5 Merge pull request #107923 from clayjohn/RD-mat3x4
Use Mat3x4 for model and view transforms to save bandwidth and ALUs
2025-09-30 18:34:59 -05:00
Thaddeus Crews 3997e77393 Merge pull request #111054 from Kaleb-Reid/fix-render-list
Sort render list correctly in RD renderers
2025-09-30 11:19:18 -05:00
Thaddeus Crews 21fd4faf1b Merge pull request #107469 from Ivorforce/vector-localvector-explicit-span-conversions
Remove implicit conversions between `LocalVector` and `Vector`
2025-09-30 11:19:17 -05:00
Kaleb Reid 5021b3e6e5 Sort render list correctly in RD renderers 2025-09-29 17:22:26 -07:00
clayjohn 14b60f2264 Optimize vertex shader using mat3x4 to reduce bandwidth, load/store operations and ALUs 2025-09-26 23:20:08 -07:00
Thaddeus Crews 8c7c96e2c4 Merge pull request #108636 from clayjohn/MSAA-depth-mobile
Add depth resolve to the mobile renderer
2025-09-17 11:34:13 -05:00
Lukas Tenbrink abe3b481ae Make conversions from LocalVector to Vector explicit. 2025-09-16 21:41:28 +02:00
Hugo Locurcio 204e310914 Tweak draw command label names for consistency
- Use Title Case for all labels, and add hyphens where relevant.
- Mention Roughness in SSR Filter's label name, as it's only enabled
  when the SSR roughness quality is not set to Disabled.
2025-09-14 01:23:47 +02:00
clayjohn a8efa55bed Add depth resolve to the mobile renderer 2025-07-16 20:37:39 -07:00
Apples 62a5cd90a7 Fix opaque stencil rendering 2025-07-02 21:49:19 -05:00
devloglogan 36128bfc29 Check render target validity before getting motion vector texture in mobile renderer 2025-06-13 18:52:02 -05:00
Rémi Verschelde da05a6b775 Merge pull request #106907 from SpockBauru/fix-mobile-lightmap-instances
Vulkan Mobile: Fix lightmap instances count
2025-06-12 11:56:32 +02:00
Rémi Verschelde 0497ae9947 Merge pull request #80710 from apples/7174-apples-stencil
Add stencil support to spatial materials
2025-06-12 01:15:35 +02:00