Skip to content

Commit aa14ada

Browse files
authored
Fix extended_material_bindless example wgpu validation error on MacOS/Metal (#21729)
# Objective - Fixes #21719 ## Solution - Implementing `bindless_supported` of the `AsBindGroup` trait for `ExtendedMaterial`: ```rust fn bindless_supported(render_device: &RenderDevice) -> bool { B::bindless_supported(render_device) && E::bindless_supported(render_device) } ``` Before it just returned the default (true), leading to the mismatch. I made small, mostly stylistic, improvements to `fn bind_group_layout_entries` and a few other locations like a comment in `extended_material` during debugging but I could move that out into a separate PR as well. Since the changes are rather limited and related to the issue I decided to leave it in for now. ## Testing - Tested on Windows/NixOS and MacOS, tested multiple examples but most testing happened on the `extended_material_bindless` and `extended_material` examples.
1 parent 8978b47 commit aa14ada

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

crates/bevy_pbr/src/extended_material.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ impl<B: Material, E: MaterialExtension> AsBindGroup for ExtendedMaterial<B, E> {
196196
}
197197
}
198198

199+
fn bindless_supported(render_device: &RenderDevice) -> bool {
200+
B::bindless_supported(render_device) && E::bindless_supported(render_device)
201+
}
202+
199203
fn label() -> &'static str {
200204
E::label()
201205
}
@@ -216,23 +220,25 @@ impl<B: Material, E: MaterialExtension> AsBindGroup for ExtendedMaterial<B, E> {
216220
) -> Result<UnpreparedBindGroup, AsBindGroupError> {
217221
force_non_bindless = force_non_bindless || Self::bindless_slot_count().is_none();
218222

219-
// add together the bindings of the base material and the user material
223+
// add together the bindings of the base material and the extension
220224
let UnpreparedBindGroup { mut bindings } = B::unprepared_bind_group(
221225
&self.base,
222226
layout,
223227
render_device,
224228
base_param,
225229
force_non_bindless,
226230
)?;
227-
let extended_bindgroup = E::unprepared_bind_group(
231+
let UnpreparedBindGroup {
232+
bindings: extension_bindings,
233+
} = E::unprepared_bind_group(
228234
&self.extension,
229235
layout,
230236
render_device,
231237
extended_param,
232238
force_non_bindless,
233239
)?;
234240

235-
bindings.extend(extended_bindgroup.bindings.0);
241+
bindings.extend(extension_bindings.0);
236242

237243
Ok(UnpreparedBindGroup { bindings })
238244
}
@@ -251,17 +257,16 @@ impl<B: Material, E: MaterialExtension> AsBindGroup for ExtendedMaterial<B, E> {
251257
// when bindless mode is on, because of the common bindless resource
252258
// arrays, and we need to eliminate the duplicates or `wgpu` will
253259
// complain.
254-
let mut entries = vec![];
255-
let mut seen_bindings = HashSet::<_>::with_hasher(FixedHasher);
256-
for entry in B::bind_group_layout_entries(render_device, force_non_bindless)
260+
let base_entries = B::bind_group_layout_entries(render_device, force_non_bindless);
261+
let extension_entries = E::bind_group_layout_entries(render_device, force_non_bindless);
262+
263+
let mut seen_bindings = HashSet::<u32>::with_hasher(FixedHasher);
264+
265+
base_entries
257266
.into_iter()
258-
.chain(E::bind_group_layout_entries(render_device, force_non_bindless).into_iter())
259-
{
260-
if seen_bindings.insert(entry.binding) {
261-
entries.push(entry);
262-
}
263-
}
264-
entries
267+
.chain(extension_entries)
268+
.filter(|entry| seen_bindings.insert(entry.binding))
269+
.collect()
265270
}
266271

267272
fn bindless_descriptor() -> Option<BindlessDescriptor> {

0 commit comments

Comments
 (0)