Skip to content

Fix the texture_binding_array, specialized_mesh_pipeline, and custom_shader_instancing examples after the bindless change. #16641

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

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

pcwalton
Copy link
Contributor

@pcwalton pcwalton commented Dec 4, 2024

The bindless PR (#16368) broke some examples:

  • specialized_mesh_pipeline and custom_shader_instancing failed because they expect to be able to render a mesh with no material, by overriding enough of the render pipeline to be able to do so. This PR fixes the issue by restoring the old behavior in which we extract meshes even if they have no material.

  • texture_binding_array broke because it doesn't implement AsBindGroup::unprepared_bind_group. This was tricky to fix because there's a very good reason why texture_binding_array doesn't implement that method: there's no sensible way to do so with wgpu's current bindless API, due to its multiple levels of borrowed references. To fix the example, I split MaterialBindGroup into MaterialBindlessBindGroup and MaterialNonBindlessBindGroup, and allow direct custom implementations of AsBindGroup::as_bind_group for the latter type of bind groups. To opt in to the new behavior, return the AsBindGroupError::CreateBindGroupDirectly error from your AsBindGroup::unprepared_bind_group implementation, and Bevy will call your custom AsBindGroup::as_bind_group method as before.

Migration Guide

  • Bevy will now unconditionally call AsBindGroup::unprepared_bind_group for your materials, so you must no longer panic in that function. Instead, return the new AsBindGroupError::CreateBindGroupDirectly error, and Bevy will fall back to calling AsBindGroup::as_bind_group as before.

`custom_shader_instancing` examples after the bindless change.

The bindless PR (bevyengine#16368) broke some examples:

* `specialized_mesh_pipeline` and `custom_shader_instancing` failed
  because they expect to be able to render a mesh with no material, by
  overriding enough of the render pipeline to be able to do so. This PR
  fixes the issue by restoring the old behavior in which we extract
  meshes even if they have no material.

* `texture_binding_array` broke because it doesn't implement
  `AsBindGroup::unprepared_bind_group`. This was tricky to fix because
  there's a very good reason why `texture_binding_array` doesn't
  implement that method: there's no sensible way to do so with `wgpu`'s
  current bindless API, due to its multiple levels of borrowed
  references. To fix the example, I split `MaterialBindGroup` into
  `MaterialBindlessBindGroup` and `MaterialNonBindlessBindGroup`, and
  allow direct custom implementations of `AsBindGroup::as_bind_group`
  for the latter type of bind groups. To opt in to the new behavior,
  return the `AsBindGroupError::CreateBindGroupDirectly` error from your
  `AsBindGroup::unprepared_bind_group` implementation, and Bevy will
  call your custom `AsBindGroup::as_bind_group` method as before.
@pcwalton pcwalton added A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward P-Regression Functionality that used to work but no longer does. Add a test for this! C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples labels Dec 4, 2024
@pcwalton pcwalton requested review from JMS55 and Elabajaba December 4, 2024 17:29
fn init_custom(&mut self, bind_group: BindGroup, extra_data: M::Data) {
match *self {
MaterialBindGroup::Bindless(_) => {
error!("Custom bind groups aren't supported in bindless mode");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question (not asking for any changes), does limiting custom bind groups to non-bindless mean eg. custom materials (thinking about either an extended material, or maybe something like a full StandardMaterial toon shader replacement?) won't benefit from bindless currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bindless works for any material as long as you write #[bindless] on it; there's nothing specific to StandardMaterial. (Actually, StandardMaterial doesn't benefit from bindless yet; that's #16644.)

The restriction you quoted only applies in very unusual circumstances, basically only in the custom_shader_instancing example.

Copy link
Contributor

@Elabajaba Elabajaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples are working on my system (windows amd 6800xt, tested dx12 and vulkan), code looks good, comments are great as always.

@pcwalton pcwalton added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 5, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 5, 2024
Merged via the queue into bevyengine:main with commit d3241c4 Dec 5, 2024
29 checks passed
@pcwalton pcwalton deleted the bindless-fix branch December 5, 2024 22:50
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
…stom_shader_instancing` examples after the bindless change. (bevyengine#16641)

The bindless PR (bevyengine#16368) broke some examples:

* `specialized_mesh_pipeline` and `custom_shader_instancing` failed
because they expect to be able to render a mesh with no material, by
overriding enough of the render pipeline to be able to do so. This PR
fixes the issue by restoring the old behavior in which we extract meshes
even if they have no material.

* `texture_binding_array` broke because it doesn't implement
`AsBindGroup::unprepared_bind_group`. This was tricky to fix because
there's a very good reason why `texture_binding_array` doesn't implement
that method: there's no sensible way to do so with `wgpu`'s current
bindless API, due to its multiple levels of borrowed references. To fix
the example, I split `MaterialBindGroup` into
`MaterialBindlessBindGroup` and `MaterialNonBindlessBindGroup`, and
allow direct custom implementations of `AsBindGroup::as_bind_group` for
the latter type of bind groups. To opt in to the new behavior, return
the `AsBindGroupError::CreateBindGroupDirectly` error from your
`AsBindGroup::unprepared_bind_group` implementation, and Bevy will call
your custom `AsBindGroup::as_bind_group` method as before.

## Migration Guide

* Bevy will now unconditionally call
`AsBindGroup::unprepared_bind_group` for your materials, so you must no
longer panic in that function. Instead, return the new
`AsBindGroupError::CreateBindGroupDirectly` error, and Bevy will fall
back to calling `AsBindGroup::as_bind_group` as before.
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-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants