Skip to content

Conversation

Zeophlite
Copy link
Contributor

@Zeophlite Zeophlite commented Sep 25, 2025

Objective

  • Defer creating BindGroupLayout by using a BindGroupLayoutDescriptor and cache the results
  • Unblocks bevy_material (render-less material definitions)

Solution

  • Reviewers, look at first commit for mechanism, and following for usage

Testing

  • CI

render_device,
material_param,
false,
) {
Copy link
Contributor Author

@Zeophlite Zeophlite Sep 25, 2025

Choose a reason for hiding this comment

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

This is yuck, AsBindGroup::unprepared_bind_group needs a BindGroupLayout , so we fetch it from the cache - investigate if unprepared_bind_group can use BindGroupLayoutDescriptor instead

where
Self: Sized,
{
todo!();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can do similar to what the method right above this one does, something like

Suggested change
todo!();
BindGroupLayoutDescriptor::new(
Self::label(),
&Self::bind_group_layout_entries(render_device, false),
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, the entries method takes render_device. Hmm. im not sure why that is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems to be related to #[derive(AsBindGroup)] macro with bindless , it needs the render_device to see if its supported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See Zeophlite@1c9e74c - this disables the above check, but hopefully helps point in the right direction

Copy link
Contributor Author

@Zeophlite Zeophlite Sep 26, 2025

Choose a reason for hiding this comment

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

Okay I think the bindless_supported check can be deferred but too much for this PR, I've added back render_device for bindless cases, see 3bae3f4

Copy link
Contributor

Choose a reason for hiding this comment

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

@Zeophlite I think the way we should go about this is to remove the render device dependency in the other direction: we don't want to defer it but make it happen earlier, and inform as bind group by some other mechanism. For example, if we had a way of setting shader defs like BINDLESS and then checking them in as bind group, we can generate the right bind group layout etc for it. Because thats really what it is, shader-def-dependent bind group layouts.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the time being using a render device to implement it is fine though :)

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 26, 2025
@alice-i-cecile
Copy link
Member

Can you add more motivation to the PR description please? I'm having trouble following why this is a good idea.

@Zeophlite Zeophlite added this to the 0.18 milestone Sep 26, 2025
@Zeophlite Zeophlite removed the C-Bug An unexpected or incorrect behavior label Sep 26, 2025
@Zeophlite Zeophlite added S-Needs-Help The author needs help finishing this PR. and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 26, 2025
@Zeophlite Zeophlite marked this pull request as ready for review September 26, 2025 23:51
@Zeophlite Zeophlite added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Needs-Help The author needs help finishing this PR. labels Sep 26, 2025
pub label: Option<Cow<'static, str>>,
/// The layout of bind groups for this pipeline.
pub layout: Vec<BindGroupLayout>,
pub layout: Vec<BindGroupLayoutDescriptor>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Reviewers: this line (and the equivalent on ComputePipelineDescriptor) is the whole point of this change. It makes these two structs not depend on wgpu, which means they can be moved out of bevy_render into a bevy_material, and created without the need of a renderdevice. Specifically, this allows describing a shader's inputs without bevy_render, which when combined with bevy_shader allows for renderless material abstraction.

Everything else in this PR is just to make these two line diffs happen.

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 S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants