Use BindGroupLayoutEntryBuilder in texture_binding_array example (#13169)
# Objective - I've been using the `texture_binding_array` example as a base to use multiple textures in meshes in my program - I only realised once I was deep in render code that these helpers existed to create layouts - I wish I knew the existed earlier because the alternative (filling in every struct field) is so much more verbose ## Solution - Use `BindGroupLayoutEntries::with_indices` to teach users that the helper exists - Also fix typo which should be `texture_2d`. ## Alternatives considered - Just leave it as is to teach users about every single struct field - However, leaving as is leaves users writing roughly 29 lines versus roughly 2 lines for 2 entries and I'd prefer the 2 line approach ## Testing Ran the example locally and compared before and after. Before: <img width="1280" alt="image" src="https://github.com/bevyengine/bevy/assets/135186256/f5897210-2560-4110-b92b-85497be9023c"> After: <img width="1279" alt="image" src="https://github.com/bevyengine/bevy/assets/135186256/8d13a939-b1ce-4a49-a9da-0b1779c8cb6a"> Co-authored-by: mgi388 <>
This commit is contained in:
parent
1c15ac647a
commit
78bf48b874
@ -13,7 +13,7 @@ use wgpu::{BindGroupLayoutEntry, BindingType, ShaderStages};
|
|||||||
/// ShaderStages::FRAGMENT,
|
/// ShaderStages::FRAGMENT,
|
||||||
/// (
|
/// (
|
||||||
/// // Screen texture
|
/// // Screen texture
|
||||||
/// (2, tepxture_2d(TextureSampleType::Float { filterable: true })),
|
/// (2, texture_2d(TextureSampleType::Float { filterable: true })),
|
||||||
/// // Sampler
|
/// // Sampler
|
||||||
/// (3, sampler(SamplerBindingType::Filtering)),
|
/// (3, sampler(SamplerBindingType::Filtering)),
|
||||||
/// ),
|
/// ),
|
||||||
|
@ -6,7 +6,10 @@ use bevy::{
|
|||||||
reflect::TypePath,
|
reflect::TypePath,
|
||||||
render::{
|
render::{
|
||||||
render_asset::RenderAssets,
|
render_asset::RenderAssets,
|
||||||
render_resource::*,
|
render_resource::{
|
||||||
|
binding_types::{sampler, texture_2d},
|
||||||
|
*,
|
||||||
|
},
|
||||||
renderer::RenderDevice,
|
renderer::RenderDevice,
|
||||||
texture::{FallbackImage, GpuImage},
|
texture::{FallbackImage, GpuImage},
|
||||||
RenderApp,
|
RenderApp,
|
||||||
@ -148,29 +151,36 @@ impl AsBindGroup for BindlessMaterial {
|
|||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
vec![
|
BindGroupLayoutEntries::with_indices(
|
||||||
// @group(2) @binding(0) var textures: binding_array<texture_2d<f32>>;
|
// The layout entries will only be visible in the fragment stage
|
||||||
BindGroupLayoutEntry {
|
ShaderStages::FRAGMENT,
|
||||||
binding: 0,
|
(
|
||||||
visibility: ShaderStages::FRAGMENT,
|
// Screen texture
|
||||||
ty: BindingType::Texture {
|
//
|
||||||
sample_type: TextureSampleType::Float { filterable: true },
|
// @group(2) @binding(0) var textures: binding_array<texture_2d<f32>>;
|
||||||
view_dimension: TextureViewDimension::D2,
|
(
|
||||||
multisampled: false,
|
0,
|
||||||
},
|
texture_2d(TextureSampleType::Float { filterable: true })
|
||||||
count: NonZeroU32::new(MAX_TEXTURE_COUNT as u32),
|
.count(NonZeroU32::new(MAX_TEXTURE_COUNT as u32).unwrap()),
|
||||||
},
|
),
|
||||||
// @group(2) @binding(1) var nearest_sampler: sampler;
|
// Sampler
|
||||||
BindGroupLayoutEntry {
|
//
|
||||||
binding: 1,
|
// @group(2) @binding(1) var nearest_sampler: sampler;
|
||||||
visibility: ShaderStages::FRAGMENT,
|
//
|
||||||
ty: BindingType::Sampler(SamplerBindingType::Filtering),
|
// Note: as with textures, multiple samplers can also be bound
|
||||||
count: None,
|
// onto one binding slot:
|
||||||
// Note: as textures, multiple samplers can also be bound onto one binding slot.
|
//
|
||||||
// One may need to pay attention to the limit of sampler binding amount on some platforms.
|
// ```
|
||||||
// count: NonZeroU32::new(MAX_TEXTURE_COUNT as u32),
|
// sampler(SamplerBindingType::Filtering)
|
||||||
},
|
// .count(NonZeroU32::new(MAX_TEXTURE_COUNT as u32).unwrap()),
|
||||||
]
|
// ```
|
||||||
|
//
|
||||||
|
// One may need to pay attention to the limit of sampler binding
|
||||||
|
// amount on some platforms.
|
||||||
|
(1, sampler(SamplerBindingType::Filtering)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.to_vec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user