Optimize bevy_solari binding layouts and bevy_render SlabAllocator robustness#24298
Open
Os-Ir wants to merge 4 commits into
Open
Optimize bevy_solari binding layouts and bevy_render SlabAllocator robustness#24298Os-Ir wants to merge 4 commits into
Os-Ir wants to merge 4 commits into
Conversation
…:CantGrow, which can resulting in the unregistered growth. Optimized the binding groups of bevy_solari.
Contributor
|
Welcome, new contributor! Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the robustness of SlabAllocator of bevy_render.
Then significantly optimizes the binding layout strategy of bevy_solari, making it more portable across Metal and Windows platforms.
It also reduces descriptor pressure and improves compatibility on platforms with stricter binding or buffer constraints (notably Metal on Apple Silicon).
Solution
The core idea of this PR is to reduce binding fragmentation and improve cross-platform compatibility by:
This results in a more portable and predictable resource binding model for bevy_solari.
Objective
This PR addresses three main issues:
Additionally, this PR improves cross-platform compatibility and enables stable execution on Metal (Apple Silicon) without requiring BUFFER_BINDING_ARRAY features.
Changes Overview
Fix: SlabAllocator growth edge-case
Fixed a potential issue where:
When SlabGrowthResult::CantGrow is returned, the slab virtual size is still set to the upper bound, but no actual reallocation occurs.
This could lead to a mismatch between logical slab size and actual allocated memory, potentially causing undefined allocation behavior.
This PR ensures that slab size changes remain consistent with allocation state.
Ray tracing scene binding optimization ( raytracing_scene_bindings.wgsl and related modules )
Key changes
Behavior changes
If geometry buffers are unified in a single slab, then use traditional contiguous buffer access path.
If not unified, keep as usual in platforms with BUFFER_BINDING_ARRAY and emit runtime warning suggesting slab expansion in platforms without it.
Additional improvements
Result
Realtime pipeline optimization / ( realtime_bindings.wgsl and related modules )
Key changes
Unified all world cache buffers into a single WorldCache structure.
Merged multiple storage buffers into a single binding:
Merged world_cache_active_cells_count into the tail of world_cache_b.
Combined gi_reservoirs_a and gi_reservoirs_b into a unified structure.
Result
Testing
This PR has been tested on:
MacOS (Metal backend, Apple Silicon / M5 MacBook Air)
Windows (Vulkan backend, Intel Core i5-13600KF / NVIDIA GeForce RTX 4070 Ti)
Test coverage:
ReSTIR GI pipeline
Real-time rendering stability
Notes:
Metal backend previously failed under strict binding constraints, this PR resolves those issues.
No regression observed in Windows Vulkan tests.
Further stress testing under extreme scene fragmentation is recommended.
Showcase
This PR enables bevy_solari to:
This is run on Metal backend. ( RenderDiagnosticsPlugin is not supported on my MacBook, so I disabled it. )

And this is run on Windows backend.
