From 76422f71cd56437f91898b4754f837fa0c966ead Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 9 Apr 2025 13:39:42 -0700 Subject: [PATCH] Make the `StandardMaterial` bindless index table have a fixed size regardless of the features that are enabled. (#18771) Due to the preprocessor usage in the shader, different combinations of features could cause the fields of `StandardMaterialBindings` to shift around. In certain cases, this could cause them to not line up with the bindings specified in `StandardMaterial`. This resulted in #18104. This commit fixes the issue by making `StandardMaterialBindings` have a fixed size. On the CPU side, it uses the `#[bindless(index_table(range(M..N)))]` feature I added to `AsBindGroup` in #18025 to do so. Thus this patch has a dependency on #18025. Closes #18104. --------- Co-authored-by: Robert Swain --- crates/bevy_pbr/src/pbr_material.rs | 2 +- crates/bevy_pbr/src/render/pbr_bindings.wgsl | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index 224bd3ed5c..fd1babd8ec 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -32,7 +32,7 @@ pub enum UvChannel { #[derive(Asset, AsBindGroup, Reflect, Debug, Clone)] #[bind_group_data(StandardMaterialKey)] #[data(0, StandardMaterialUniform, binding_array(10))] -#[bindless] +#[bindless(index_table(range(0..31)))] #[reflect(Default, Debug, Clone)] pub struct StandardMaterial { /// The color of the surface of the material before lighting. diff --git a/crates/bevy_pbr/src/render/pbr_bindings.wgsl b/crates/bevy_pbr/src/render/pbr_bindings.wgsl index d5cd3b03c1..fac7b97265 100644 --- a/crates/bevy_pbr/src/render/pbr_bindings.wgsl +++ b/crates/bevy_pbr/src/render/pbr_bindings.wgsl @@ -17,32 +17,24 @@ struct StandardMaterialBindings { normal_map_sampler: u32, // 10 depth_map_texture: u32, // 11 depth_map_sampler: u32, // 12 -#ifdef PBR_ANISOTROPY_TEXTURE_SUPPORTED anisotropy_texture: u32, // 13 anisotropy_sampler: u32, // 14 -#endif // PBR_ANISOTROPY_TEXTURE_SUPPORTED -#ifdef PBR_TRANSMISSION_TEXTURES_SUPPORTED specular_transmission_texture: u32, // 15 specular_transmission_sampler: u32, // 16 thickness_texture: u32, // 17 thickness_sampler: u32, // 18 diffuse_transmission_texture: u32, // 19 diffuse_transmission_sampler: u32, // 20 -#endif // PBR_TRANSMISSION_TEXTURES_SUPPORTED -#ifdef PBR_MULTI_LAYER_MATERIAL_TEXTURES_SUPPORTED clearcoat_texture: u32, // 21 clearcoat_sampler: u32, // 22 clearcoat_roughness_texture: u32, // 23 clearcoat_roughness_sampler: u32, // 24 clearcoat_normal_texture: u32, // 25 clearcoat_normal_sampler: u32, // 26 -#endif // PBR_MULTI_LAYER_MATERIAL_TEXTURES_SUPPORTED -#ifdef PBR_SPECULAR_TEXTURES_SUPPORTED specular_texture: u32, // 27 specular_sampler: u32, // 28 specular_tint_texture: u32, // 29 specular_tint_sampler: u32, // 30 -#endif // PBR_SPECULAR_TEXTURES_SUPPORTED } @group(2) @binding(0) var material_indices: array;