Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a bindless mode to AsBindGroup. #16368

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pcwalton
Copy link
Contributor

@pcwalton pcwalton commented Nov 13, 2024

This adds the infrastructure necessary for Bevy to support bindless resources. Bindless resources significantly improve rendering performance by reducing wgpu and driver overhead considerably.

TODO: Write more here.

Copied and pasted from the new AsBindGroup documentation:

  • bindless(COUNT)
    • This switch enables bindless resources, which changes the way Bevy
      supplies resources (uniforms, textures, and samplers) to the shader.
      When bindless resources are enabled, and the current platform supports
      them, instead of presenting a single instance of a resource to your
      shader Bevy will instead present a binding array of COUNT elements.
      In your shader, the index of the element of each binding array
      corresponding to the mesh currently being drawn can be retrieved with
      mesh[in.instance_index].material_bind_group_slot.
    • The purpose of bindless mode is to improve performance by reducing
      state changes. By grouping resources together into binding arrays, Bevy
      doesn't have to modify GPU state as often, decreasing API and driver
      overhead.
    • If bindless mode is enabled, the BINDLESS definition will be
      available. Because not all platforms support bindless resources, you
      should check for the presence of this definition via #ifdef and fall
      back to standard bindings if it isn't present.
    • See the shaders/shader_material_bindless example for an example of
      how to use bindless mode.

This should be ready except for documentation. I'm submitting it now as a draft since this shouldn't land before 0.15 is released anyway.

Here's a Tracy profile of submit_graph_commands of this patch and an additional patch (not submitted yet) that makes StandardMaterial use bindless. Red is those patches; yellow is main. The scene was Bistro Exterior with a hack that forces all textures to opaque. You can see a 1.47x mean speedup.
Screenshot 2024-11-12 161713

Migration Guide

  • RenderAssets::prepare_asset now takes an AssetId parameter.
  • Bin keys now have Bevy-specific material bind group indices instead of wgpu material bind group IDs, as part of the bindless change. Use the new MaterialBindGroupAllocator to map from bind group index to bind group ID.

This adds the infrastructure necessary for Bevy to support *bindless
resources*. Bindless resources significantly improve rendering
performance by reducing `wgpu` and driver overhead considerably.
@pcwalton pcwalton added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged D-Shaders This code uses GPU shader languages labels Nov 13, 2024
Copy link
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

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 D-Shaders This code uses GPU shader languages S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant