Skip to content

Optimize bevy_solari binding layouts and bevy_render SlabAllocator robustness#24298

Open
Os-Ir wants to merge 4 commits into
bevyengine:mainfrom
Os-Ir:fix/binding_optimize
Open

Optimize bevy_solari binding layouts and bevy_render SlabAllocator robustness#24298
Os-Ir wants to merge 4 commits into
bevyengine:mainfrom
Os-Ir:fix/binding_optimize

Conversation

@Os-Ir
Copy link
Copy Markdown

@Os-Ir Os-Ir commented May 14, 2026

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:

  • Prefering slab-contiguous buffer layouts when possible
  • Removing unnecessary descriptor splits for logically-coherent data
  • Packing frequently co-accessed data into unified GPU structures
  • Reducing reliance on binding_array where it is not strictly required
  • Introducing fallback behavior based on allocator layout constraints

This results in a more portable and predictable resource binding model for bevy_solari.

Objective

This PR addresses three main issues:

  • A potential correctness issue in SlabAllocator when handling slabs on SlabGrowthResult::CantGrow condition.
  • Excessive reliance on BUFFER_BINDING_ARRAY for ray tracing bindings.
  • Fragmented and descriptor-heavy world cache / reservoir binding layout in pipelines of bevy_solari.

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

  • Removed the hard dependency on BUFFER_BINDING_ARRAY
  • Introduced fallback path using SlabAllocator characteristics
  • Dynamically adapts binding strategy depending on whether buffers are unified in slabs

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

  • Replaced mat4x4 transforms to affine representation
  • Merged material_id into InstanceRenderInfo
  • Merged the data of InstanceGeometryIds into InstanceRenderInfo to replace

Result

  • Reduced binding fragmentation
  • Improved portability across Metal / Vulkan / DX12

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:

  • world_cache_checksums
  • world_cache_life
  • world_cache_radiance
  • world_cache_geometry_data
  • world_cache_luminance_deltas
  • world_cache_active_cells_new_radiance
  • world_cache_a

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

  • Significant reduction in binding count
  • Reduced descriptor pressure on Metal and other constrained platforms
  • Improved stability on Apple Silicon

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:

  • Run stably on Metal (previously unsupported under binding constraints)
  • Operate without requiring BUFFER_BINDING_ARRAY in all cases
  • Maintain compatibility with existing pipelines
  • Reduce overall binding pressure in both path tracing and ReSTIR pipelines

This is run on Metal backend. ( RenderDiagnosticsPlugin is not supported on my MacBook, so I disabled it. )
baseline_metal

And this is run on Windows backend.
baseline_vulkan

@github-actions
Copy link
Copy Markdown
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 ✨

@mnmaita mnmaita added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Shaders This code uses GPU shader languages C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. labels May 16, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. D-Complex Quite challenging from either a design or technical perspective. Ask for help! D-Shaders This code uses GPU shader languages S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants