diff --git a/crates/bevy_pbr/src/extended_material.rs b/crates/bevy_pbr/src/extended_material.rs index a443b953d5cfc..1b2d48e4c69f9 100644 --- a/crates/bevy_pbr/src/extended_material.rs +++ b/crates/bevy_pbr/src/extended_material.rs @@ -150,6 +150,15 @@ impl AsBindGroup for ExtendedMaterial { type Data = (::Data, ::Data); type Param = (::Param, ::Param); + fn bindless_slot_count() -> Option { + match (B::bindless_slot_count(), E::bindless_slot_count()) { + (Some(base_bindless_slot_count), Some(extension_bindless_slot_count)) => { + Some(base_bindless_slot_count.min(extension_bindless_slot_count)) + } + _ => None, + } + } + fn unprepared_bind_group( &self, layout: &BindGroupLayout, @@ -159,9 +168,7 @@ impl AsBindGroup for ExtendedMaterial { ) -> Result, AsBindGroupError> { // Only allow bindless mode if both the base material and the extension // support it. - force_no_bindless = force_no_bindless - || B::BINDLESS_SLOT_COUNT.is_none() - || E::BINDLESS_SLOT_COUNT.is_none(); + force_no_bindless = force_no_bindless || Self::bindless_slot_count().is_none(); // add together the bindings of the base material and the user material let UnpreparedBindGroup { @@ -199,9 +206,7 @@ impl AsBindGroup for ExtendedMaterial { { // Only allow bindless mode if both the base material and the extension // support it. - force_no_bindless = force_no_bindless - || B::BINDLESS_SLOT_COUNT.is_none() - || E::BINDLESS_SLOT_COUNT.is_none(); + force_no_bindless = force_no_bindless || Self::bindless_slot_count().is_none(); // add together the bindings of the standard material and the user material let mut entries = B::bind_group_layout_entries(render_device, force_no_bindless); diff --git a/crates/bevy_pbr/src/material_bind_groups.rs b/crates/bevy_pbr/src/material_bind_groups.rs index ab3f4b464f81e..a9bf1e8274f66 100644 --- a/crates/bevy_pbr/src/material_bind_groups.rs +++ b/crates/bevy_pbr/src/material_bind_groups.rs @@ -440,7 +440,7 @@ where { /// Returns a new bind group. fn new() -> MaterialBindlessBindGroup { - let count = M::BINDLESS_SLOT_COUNT.unwrap_or(1); + let count = M::bindless_slot_count().unwrap_or(1); MaterialBindlessBindGroup { bind_group: None, @@ -789,7 +789,7 @@ pub fn material_uses_bindless_resources(render_device: &RenderDevice) -> bool where M: Material, { - M::BINDLESS_SLOT_COUNT.is_some() + M::bindless_slot_count().is_some() && render_device .features() .contains(WgpuFeatures::BUFFER_BINDING_ARRAY | WgpuFeatures::TEXTURE_BINDING_ARRAY) diff --git a/crates/bevy_render/macros/src/as_bind_group.rs b/crates/bevy_render/macros/src/as_bind_group.rs index a31db478fba8f..80e707c938d49 100644 --- a/crates/bevy_render/macros/src/as_bind_group.rs +++ b/crates/bevy_render/macros/src/as_bind_group.rs @@ -567,7 +567,11 @@ pub fn derive_as_bind_group(ast: syn::DeriveInput) -> Result { // limitations into account. let (bindless_slot_count, actual_bindless_slot_count_declaration) = match attr_bindless_count { Some(bindless_count) => ( - quote! { const BINDLESS_SLOT_COUNT: Option = Some(#bindless_count); }, + quote! { + fn bindless_slot_count() -> Option { + Some(#bindless_count) + } + }, quote! { let #actual_bindless_slot_count = if render_device.features().contains( #render_path::settings::WgpuFeatures::BUFFER_BINDING_ARRAY | diff --git a/crates/bevy_render/src/render_resource/bind_group.rs b/crates/bevy_render/src/render_resource/bind_group.rs index 1a42eb00415b9..d7033d660b85a 100644 --- a/crates/bevy_render/src/render_resource/bind_group.rs +++ b/crates/bevy_render/src/render_resource/bind_group.rs @@ -337,7 +337,9 @@ pub trait AsBindGroup { /// Note that the *actual* slot count may be different from this value, due /// to platform limitations. For example, if bindless resources aren't /// supported on this platform, the actual slot count will be 1. - const BINDLESS_SLOT_COUNT: Option = None; + fn bindless_slot_count() -> Option { + None + } /// label fn label() -> Option<&'static str> {