From f7fab5c1dbc144b24dbf52b5136e350f8bad5508 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 5 Nov 2023 01:21:22 -0400 Subject: [PATCH 01/24] add bind_group_layout_entries --- .../bind_group_layout_entries.rs | 293 ++++++++++++++++++ crates/bevy_render/src/render_resource/mod.rs | 2 + 2 files changed, 295 insertions(+) create mode 100644 crates/bevy_render/src/render_resource/bind_group_layout_entries.rs diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs new file mode 100644 index 0000000000000..ca71ab1dc5aea --- /dev/null +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -0,0 +1,293 @@ +use crate::render_resource::{ + BufferBindingType, SamplerBindingType, TextureSampleType, TextureViewDimension, +}; +use bevy_utils::all_tuples_with_size; +use std::num::{NonZeroU32, NonZeroU64}; +use wgpu::{BindingType, ShaderStages, StorageTextureAccess, TextureFormat}; + +pub struct BindGroupLayoutEntryBuilder { + pub ty: BindingType, + pub visibility: Option, + pub count: Option, +} + +impl BindGroupLayoutEntryBuilder { + pub fn visibility(mut self, visibility: ShaderStages) -> Self { + self.visibility = Some(visibility); + self + } + + pub fn count(mut self, count: NonZeroU32) -> Self { + self.count = Some(count); + self + } +} + +pub struct BindGroupLayoutEntries { + entries: [wgpu::BindGroupLayoutEntry; N], +} + +impl BindGroupLayoutEntries { + #[inline] + #[allow(unused)] + pub fn sequential( + default_visibility: ShaderStages, + entries_ext: impl IntoBindGroupLayoutEntryBuilderArray, + ) -> Self { + let mut i = 0; + Self { + entries: entries_ext.into_array().map(|entry| { + let binding = i; + i += 1; + wgpu::BindGroupLayoutEntry { + binding, + ty: entry.ty, + visibility: entry.visibility.unwrap_or(default_visibility), + count: entry.count, + } + }), + } + } + + #[inline] + #[allow(unused)] + pub fn with_indices( + default_visibility: ShaderStages, + indexed_entries: impl IntoIndexedBindGroupLayoutEntryBuilderArray, + ) -> Self { + Self { + entries: indexed_entries.into_array().map(|(binding, entry)| { + wgpu::BindGroupLayoutEntry { + binding, + ty: entry.ty, + visibility: entry.visibility.unwrap_or(default_visibility), + count: entry.count, + } + }), + } + } +} + +impl std::ops::Deref for BindGroupLayoutEntries { + type Target = [wgpu::BindGroupLayoutEntry]; + fn deref(&self) -> &[wgpu::BindGroupLayoutEntry] { + &self.entries + } +} + +pub trait IntoBindGroupLayoutEntryBuilder { + fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder; +} + +impl IntoBindGroupLayoutEntryBuilder for BindingType { + fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder { + BindGroupLayoutEntryBuilder { + ty: self, + visibility: None, + count: None, + } + } +} + +impl IntoBindGroupLayoutEntryBuilder for wgpu::BindGroupLayoutEntry { + fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder { + if self.binding != u32::MAX { + bevy_log::warn!("The BindGroupLayoutEntries api ignores the binding index when converting a raw wgpu::BindGroupLayoutEntry. You can ignore this warning by setting it to u32::MAX."); + } + BindGroupLayoutEntryBuilder { + ty: self.ty, + visibility: Some(self.visibility), + count: self.count, + } + } +} + +impl IntoBindGroupLayoutEntryBuilder for BindGroupLayoutEntryBuilder { + fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder { + self + } +} + +pub trait IntoBindGroupLayoutEntryBuilderArray { + fn into_array(self) -> [BindGroupLayoutEntryBuilder; N]; +} +macro_rules! impl_to_binding_type_slice { + ($N: expr, $(($T: ident, $I: ident)),*) => { + impl<$($T: IntoBindGroupLayoutEntryBuilder),*> IntoBindGroupLayoutEntryBuilderArray<$N> for ($($T,)*) { + #[inline] + fn into_array(self) -> [BindGroupLayoutEntryBuilder; $N] { + let ($($I,)*) = self; + [$($I.into_bind_group_layout_entry(), )*] + } + } + } +} +all_tuples_with_size!(impl_to_binding_type_slice, 1, 32, T, s); + +pub trait IntoIndexedBindGroupLayoutEntryBuilderArray { + fn into_array(self) -> [(u32, BindGroupLayoutEntryBuilder); N]; +} +macro_rules! impl_to_indexed_binding_type_slice { + ($N: expr, $(($T: ident, $S: ident, $I: ident)),*) => { + impl<$($T: IntoBindGroupLayoutEntryBuilder),*> IntoIndexedBindGroupLayoutEntryBuilderArray<$N> for ($((u32, $T),)*) { + #[inline] + fn into_array(self) -> [(u32, BindGroupLayoutEntryBuilder); $N] { + let ($(($S, $I),)*) = self; + [$(($S, $I.into_bind_group_layout_entry())), *] + } + } + } +} +all_tuples_with_size!(impl_to_indexed_binding_type_slice, 1, 32, T, n, s); + +#[allow(unused)] +pub fn storage_buffer( + has_dynamic_offset: bool, + min_binding_size: Option, +) -> BindGroupLayoutEntryBuilder { + BindingType::Buffer { + ty: BufferBindingType::Storage { read_only: false }, + has_dynamic_offset, + min_binding_size, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn storage_buffer_read_only( + has_dynamic_offset: bool, + min_binding_size: Option, +) -> BindGroupLayoutEntryBuilder { + BindingType::Buffer { + ty: BufferBindingType::Storage { read_only: true }, + has_dynamic_offset, + min_binding_size, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn uniform_buffer( + has_dynamic_offset: bool, + min_binding_size: Option, +) -> BindGroupLayoutEntryBuilder { + BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset, + min_binding_size, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2, + multisampled: false, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2, + multisampled: true, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2Array, + multisampled: false, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_array_multisampled( + sample_type: TextureSampleType, +) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2Array, + multisampled: true, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_multisampled_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Float { filterable }).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_i32() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_multisampled_i32() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_u32() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_2d_multisampled_u32() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_depth_2d() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Depth).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_depth_2d_multisampled() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Depth).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn sampler(sampler_binding_type: SamplerBindingType) -> BindGroupLayoutEntryBuilder { + BindingType::Sampler(sampler_binding_type).into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_storage_2d( + format: TextureFormat, + access: StorageTextureAccess, +) -> BindGroupLayoutEntryBuilder { + BindingType::StorageTexture { + access, + format, + view_dimension: TextureViewDimension::D2, + } + .into_bind_group_layout_entry() +} + +#[allow(unused)] +pub fn texture_storage_2d_array( + format: TextureFormat, + access: StorageTextureAccess, +) -> BindGroupLayoutEntryBuilder { + BindingType::StorageTexture { + access, + format, + view_dimension: TextureViewDimension::D2Array, + } + .into_bind_group_layout_entry() +} diff --git a/crates/bevy_render/src/render_resource/mod.rs b/crates/bevy_render/src/render_resource/mod.rs index 3ed787f257d65..12f2614d453fb 100644 --- a/crates/bevy_render/src/render_resource/mod.rs +++ b/crates/bevy_render/src/render_resource/mod.rs @@ -2,6 +2,7 @@ mod batched_uniform_buffer; mod bind_group; mod bind_group_entries; mod bind_group_layout; +mod bind_group_layout_entries; mod buffer; mod buffer_vec; mod gpu_array_buffer; @@ -17,6 +18,7 @@ mod uniform_buffer; pub use bind_group::*; pub use bind_group_entries::*; pub use bind_group_layout::*; +pub use bind_group_layout_entries::*; pub use buffer::*; pub use buffer_vec::*; pub use gpu_array_buffer::*; From 01564b6bea1d67afd43295d3e971f7159bbad97f Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 5 Nov 2023 01:21:36 -0500 Subject: [PATCH 02/24] update render_device --- crates/bevy_render/src/renderer/render_device.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/renderer/render_device.rs b/crates/bevy_render/src/renderer/render_device.rs index 6a126df8aa41e..55be54b496354 100644 --- a/crates/bevy_render/src/renderer/render_device.rs +++ b/crates/bevy_render/src/renderer/render_device.rs @@ -4,7 +4,8 @@ use crate::render_resource::{ }; use bevy_ecs::system::Resource; use wgpu::{ - util::DeviceExt, BindGroupDescriptor, BindGroupEntry, BufferAsyncError, BufferBindingType, + util::DeviceExt, BindGroupDescriptor, BindGroupEntry, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BufferAsyncError, BufferBindingType, }; use super::RenderQueue; @@ -100,11 +101,18 @@ impl RenderDevice { /// Creates a [`BindGroupLayout`](wgpu::BindGroupLayout). #[inline] - pub fn create_bind_group_layout( + pub fn create_bind_group_layout<'a>( &self, - desc: &wgpu::BindGroupLayoutDescriptor, + label: impl Into>, + entries: &'a [BindGroupLayoutEntry], ) -> BindGroupLayout { - BindGroupLayout::from(self.device.create_bind_group_layout(desc)) + BindGroupLayout::from( + self.device + .create_bind_group_layout(&BindGroupLayoutDescriptor { + label: label.into(), + entries, + }), + ) } /// Creates a [`PipelineLayout`](wgpu::PipelineLayout). From 8d645c276772bcb34c34ab21b7180c157a763678 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 5 Nov 2023 01:30:49 -0500 Subject: [PATCH 03/24] use new api --- crates/bevy_core_pipeline/src/blit/mod.rs | 41 ++- .../src/bloom/downsampling_pipeline.rs | 9 +- .../src/bloom/upsampling_pipeline.rs | 65 ++-- .../src/contrast_adaptive_sharpening/mod.rs | 61 ++-- .../src/deferred/copy_lighting_id.rs | 8 +- crates/bevy_core_pipeline/src/fxaa/mod.rs | 8 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 65 ++-- crates/bevy_core_pipeline/src/taa/mod.rs | 121 ++++---- .../bevy_core_pipeline/src/tonemapping/mod.rs | 5 +- crates/bevy_gizmos/src/lib.rs | 10 +- crates/bevy_pbr/src/deferred/mod.rs | 8 +- crates/bevy_pbr/src/prepass/mod.rs | 122 ++++---- crates/bevy_pbr/src/render/mesh_bindings.rs | 30 +- .../bevy_pbr/src/render/mesh_view_bindings.rs | 8 +- crates/bevy_pbr/src/ssao/mod.rs | 288 +++++++++--------- .../src/render_resource/bind_group.rs | 10 +- .../bevy_render/src/view/window/screenshot.rs | 8 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 16 +- crates/bevy_sprite/src/render/mod.rs | 16 +- crates/bevy_ui/src/render/pipeline.rs | 16 +- .../src/render/ui_material_pipeline.rs | 8 +- 21 files changed, 451 insertions(+), 472 deletions(-) diff --git a/crates/bevy_core_pipeline/src/blit/mod.rs b/crates/bevy_core_pipeline/src/blit/mod.rs index b6698838f4a54..cd58c49f73b25 100644 --- a/crates/bevy_core_pipeline/src/blit/mod.rs +++ b/crates/bevy_core_pipeline/src/blit/mod.rs @@ -36,28 +36,27 @@ impl FromWorld for BlitPipeline { fn from_world(render_world: &mut World) -> Self { let render_device = render_world.resource::(); - let texture_bind_group = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("blit_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + let texture_bind_group = render_device.create_bind_group_layout( + "blit_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: false }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, - }, - ], - }); + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Sampler(SamplerBindingType::NonFiltering), + count: None, + }, + ], + ); let sampler = render_device.create_sampler(&SamplerDescriptor::default()); diff --git a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs index 747f4ee4c87d4..22a702dd632f7 100644 --- a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs @@ -74,11 +74,10 @@ impl FromWorld for BloomDownsamplingPipeline { }; // Bind group layout - let bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("bloom_downsampling_bind_group_layout_with_settings"), - entries: &[texture, sampler, settings], - }); + let bind_group_layout = render_device.create_bind_group_layout( + Some("bloom_downsampling_bind_group_layout_with_settings"), + &[texture, sampler, settings], + ); // Sampler let sampler = render_device.create_sampler(&SamplerDescriptor { diff --git a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs index 996ccce08343a..89870700e36b6 100644 --- a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs @@ -31,41 +31,40 @@ impl FromWorld for BloomUpsamplingPipeline { fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); - let bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("bloom_upsampling_bind_group_layout"), - entries: &[ - // Input texture - BindGroupLayoutEntry { - binding: 0, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - visibility: ShaderStages::FRAGMENT, - count: None, - }, - // Sampler - BindGroupLayoutEntry { - binding: 1, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - visibility: ShaderStages::FRAGMENT, - count: None, + let bind_group_layout = render_device.create_bind_group_layout( + "bloom_upsampling_bind_group_layout", + &[ + // Input texture + BindGroupLayoutEntry { + binding: 0, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - // BloomUniforms - BindGroupLayoutEntry { - binding: 2, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(BloomUniforms::min_size()), - }, - visibility: ShaderStages::FRAGMENT, - count: None, + visibility: ShaderStages::FRAGMENT, + count: None, + }, + // Sampler + BindGroupLayoutEntry { + binding: 1, + ty: BindingType::Sampler(SamplerBindingType::Filtering), + visibility: ShaderStages::FRAGMENT, + count: None, + }, + // BloomUniforms + BindGroupLayoutEntry { + binding: 2, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(BloomUniforms::min_size()), }, - ], - }); + visibility: ShaderStages::FRAGMENT, + count: None, + }, + ], + ); BloomUpsamplingPipeline { bind_group_layout } } diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs index 89879938e8a8b..5f667b9e34964 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs @@ -169,39 +169,38 @@ pub struct CASPipeline { impl FromWorld for CASPipeline { fn from_world(render_world: &mut World) -> Self { let render_device = render_world.resource::(); - let texture_bind_group = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("sharpening_texture_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + let texture_bind_group = render_device.create_bind_group_layout( + "sharpening_texture_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - // CAS Settings - BindGroupLayoutEntry { - binding: 2, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(CASUniform::min_size()), - }, - visibility: ShaderStages::FRAGMENT, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Sampler(SamplerBindingType::Filtering), + count: None, + }, + // CAS Settings + BindGroupLayoutEntry { + binding: 2, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(CASUniform::min_size()), }, - ], - }); + visibility: ShaderStages::FRAGMENT, + count: None, + }, + ], + ); let sampler = render_device.create_sampler(&SamplerDescriptor::default()); diff --git a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs index c60306286900a..ec9aac0d4454f 100644 --- a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs +++ b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs @@ -128,9 +128,9 @@ impl FromWorld for CopyDeferredLightingIdPipeline { fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); - let layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("copy_deferred_lighting_id_bind_group_layout"), - entries: &[BindGroupLayoutEntry { + let layout = render_device.create_bind_group_layout( + "copy_deferred_lighting_id_bind_group_layout", + &[BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::FRAGMENT, ty: BindingType::Texture { @@ -140,7 +140,7 @@ impl FromWorld for CopyDeferredLightingIdPipeline { }, count: None, }], - }); + ); let pipeline_id = world diff --git a/crates/bevy_core_pipeline/src/fxaa/mod.rs b/crates/bevy_core_pipeline/src/fxaa/mod.rs index df37eaa1a8e76..7961af19fcc28 100644 --- a/crates/bevy_core_pipeline/src/fxaa/mod.rs +++ b/crates/bevy_core_pipeline/src/fxaa/mod.rs @@ -131,9 +131,9 @@ impl FromWorld for FxaaPipeline { fn from_world(render_world: &mut World) -> Self { let texture_bind_group = render_world .resource::() - .create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("fxaa_texture_bind_group_layout"), - entries: &[ + .create_bind_group_layout( + "fxaa_texture_bind_group_layout", + &[ BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::FRAGMENT, @@ -151,7 +151,7 @@ impl FromWorld for FxaaPipeline { count: None, }, ], - }); + ); FxaaPipeline { texture_bind_group } } diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 11caa03afd8aa..e1993ea68c9b3 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -10,7 +10,7 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, BufferBindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, RenderPipelineDescriptor, @@ -80,41 +80,38 @@ struct SkyboxPipeline { impl SkyboxPipeline { fn new(render_device: &RenderDevice) -> Self { - let bind_group_layout_descriptor = BindGroupLayoutDescriptor { - label: Some("skybox_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::Cube, - multisampled: false, + Self { + bind_group_layout: render_device.create_bind_group_layout( + "skybox_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::Cube, + multisampled: false, + }, + count: None, }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Sampler(SamplerBindingType::Filtering), + count: None, }, - count: None, - }, - ], - }; - - Self { - bind_group_layout: render_device - .create_bind_group_layout(&bind_group_layout_descriptor), + BindGroupLayoutEntry { + binding: 2, + visibility: ShaderStages::VERTEX_FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(ViewUniform::min_size()), + }, + count: None, + }, + ], + ), } } } diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index de4069c9abe7d..afb4d7bb4be50 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -21,7 +21,7 @@ use bevy_render::{ prelude::{Camera, Projection}, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ - BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, + BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, Extent3d, FilterMode, FragmentState, MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, Sampler, @@ -266,70 +266,69 @@ impl FromWorld for TaaPipeline { ..SamplerDescriptor::default() }); - let taa_bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("taa_bind_group_layout"), - entries: &[ - // View target (read) - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + let taa_bind_group_layout = render_device.create_bind_group_layout( + "taa_bind_group_layout", + &[ + // View target (read) + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - // TAA History (read) - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // Motion Vectors - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // Depth - BindGroupLayoutEntry { - binding: 3, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Depth, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + // TAA History (read) + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - // Nearest sampler - BindGroupLayoutEntry { - binding: 4, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, + count: None, + }, + // Motion Vectors + BindGroupLayoutEntry { + binding: 2, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: true }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - // Linear sampler - BindGroupLayoutEntry { - binding: 5, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, + count: None, + }, + // Depth + BindGroupLayoutEntry { + binding: 3, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Depth, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - ], - }); + count: None, + }, + // Nearest sampler + BindGroupLayoutEntry { + binding: 4, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Sampler(SamplerBindingType::NonFiltering), + count: None, + }, + // Linear sampler + BindGroupLayoutEntry { + binding: 5, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Sampler(SamplerBindingType::Filtering), + count: None, + }, + ], + ); TaaPipeline { taa_bind_group_layout, diff --git a/crates/bevy_core_pipeline/src/tonemapping/mod.rs b/crates/bevy_core_pipeline/src/tonemapping/mod.rs index bb4dec7f3bc49..d5c452ffe8c51 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/mod.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/mod.rs @@ -280,10 +280,7 @@ impl FromWorld for TonemappingPipeline { let tonemap_texture_bind_group = render_world .resource::() - .create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("tonemapping_hdr_texture_bind_group_layout"), - entries: &entries, - }); + .create_bind_group_layout("tonemapping_hdr_texture_bind_group_layout", &entries); TonemappingPipeline { texture_bind_group: tonemap_texture_bind_group, diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index d0df228449116..bff63e24418e1 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -54,7 +54,7 @@ use bevy_render::{ render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, Buffer, BufferBindingType, BufferInitDescriptor, BufferUsages, Shader, ShaderStages, ShaderType, VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode, @@ -120,8 +120,9 @@ impl Plugin for GizmoPlugin { }; let render_device = render_app.world.resource::(); - let layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[BindGroupLayoutEntry { + let layout = render_device.create_bind_group_layout( + "LineGizmoUniform layout", + &[BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::VERTEX, ty: BindingType::Buffer { @@ -131,8 +132,7 @@ impl Plugin for GizmoPlugin { }, count: None, }], - label: Some("LineGizmoUniform layout"), - }); + ); render_app.insert_resource(LineGizmoUniformBindgroupLayout { layout }); } diff --git a/crates/bevy_pbr/src/deferred/mod.rs b/crates/bevy_pbr/src/deferred/mod.rs index f679f638d42ac..77fb8acb5e4b1 100644 --- a/crates/bevy_pbr/src/deferred/mod.rs +++ b/crates/bevy_pbr/src/deferred/mod.rs @@ -376,9 +376,9 @@ impl SpecializedRenderPipeline for DeferredLightingLayout { impl FromWorld for DeferredLightingLayout { fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); - let layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("deferred_lighting_layout"), - entries: &[BindGroupLayoutEntry { + let layout = render_device.create_bind_group_layout( + "deferred_lighting_layout", + &[BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::VERTEX_FRAGMENT, ty: BindingType::Buffer { @@ -388,7 +388,7 @@ impl FromWorld for DeferredLightingLayout { }, count: None, }], - }); + ); Self { mesh_pipeline: world.resource::().clone(), bind_group_layout_1: layout, diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 6f2dfed69e12d..33f51c2d5ac1e 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -229,74 +229,72 @@ impl FromWorld for PrepassPipeline { let render_device = world.resource::(); let asset_server = world.resource::(); - let view_layout_motion_vectors = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ - // View - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, + let view_layout_motion_vectors = render_device.create_bind_group_layout( + "prepass_view_layout_motion_vectors", + &[ + // View + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(ViewUniform::min_size()), }, - // Globals - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, + count: None, + }, + // Globals + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::VERTEX_FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: Some(GlobalsUniform::min_size()), }, - // PreviousViewProjection - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(PreviousViewProjection::min_size()), - }, - count: None, + count: None, + }, + // PreviousViewProjection + BindGroupLayoutEntry { + binding: 2, + visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(PreviousViewProjection::min_size()), }, - ], - label: Some("prepass_view_layout_motion_vectors"), - }); + count: None, + }, + ], + ); - let view_layout_no_motion_vectors = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ - // View - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, + let view_layout_no_motion_vectors = render_device.create_bind_group_layout( + "prepass_view_layout_no_motion_vectors", + &[ + // View + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(ViewUniform::min_size()), }, - // Globals - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, + count: None, + }, + // Globals + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::VERTEX_FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: Some(GlobalsUniform::min_size()), }, - ], - label: Some("prepass_view_layout_no_motion_vectors"), - }); + count: None, + }, + ], + ); let mesh_pipeline = world.resource::(); diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index df935e1805c8a..d7b989911f2de 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -133,40 +133,38 @@ impl MeshLayouts { // ---------- create individual BindGroupLayouts ---------- fn model_only_layout(render_device: &RenderDevice) -> BindGroupLayout { - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[layout_entry::model(render_device, 0)], - label: Some("mesh_layout"), - }) + render_device + .create_bind_group_layout("mesh_layout", &[layout_entry::model(render_device, 0)]) } fn skinned_layout(render_device: &RenderDevice) -> BindGroupLayout { - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + render_device.create_bind_group_layout( + "skinned_mesh_layout", + &[ layout_entry::model(render_device, 0), layout_entry::skinning(1), ], - label: Some("skinned_mesh_layout"), - }) + ) } fn morphed_layout(render_device: &RenderDevice) -> BindGroupLayout { - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + render_device.create_bind_group_layout( + "morphed_mesh_layout", + &[ layout_entry::model(render_device, 0), layout_entry::weights(2), layout_entry::targets(3), ], - label: Some("morphed_mesh_layout"), - }) + ) } fn morphed_skinned_layout(render_device: &RenderDevice) -> BindGroupLayout { - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + render_device.create_bind_group_layout( + "morphed_skinned_mesh_layout", + &[ layout_entry::model(render_device, 0), layout_entry::skinning(1), layout_entry::weights(2), layout_entry::targets(3), ], - label: Some("morphed_skinned_mesh_layout"), - }) + ) } // ---------- BindGroup methods ---------- diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 853c253209a68..690bc12778787 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -16,7 +16,7 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, + BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindingType, BufferBindingType, DynamicBindGroupEntries, SamplerBindingType, ShaderStages, ShaderType, TextureFormat, TextureSampleType, TextureViewDimension, }, @@ -347,10 +347,8 @@ pub fn generate_view_layouts( .count(); MeshPipelineViewLayout { - bind_group_layout: render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some(key.label().as_str()), - entries: &entries, - }), + bind_group_layout: render_device + .create_bind_group_layout(key.label().as_str(), &entries), #[cfg(debug_assertions)] texture_count, } diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 62a7d4e5a4a6a..004d496c6eb56 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -345,28 +345,27 @@ impl FromWorld for SsaoPipelines { ..Default::default() }); - let common_bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("ssao_common_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, + let common_bind_group_layout = render_device.create_bind_group_layout( + "ssao_common_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Sampler(SamplerBindingType::NonFiltering), + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(ViewUniform::min_size()), }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - ], - }); + count: None, + }, + ], + ); let mip_texture_entry = BindGroupLayoutEntry { binding: 1, @@ -378,143 +377,140 @@ impl FromWorld for SsaoPipelines { }, count: None, }; - let preprocess_depth_bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("ssao_preprocess_depth_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Depth, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - mip_texture_entry, - BindGroupLayoutEntry { - binding: 2, - ..mip_texture_entry + let preprocess_depth_bind_group_layout = render_device.create_bind_group_layout( + "ssao_preprocess_depth_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Texture { + sample_type: TextureSampleType::Depth, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 3, - ..mip_texture_entry - }, - BindGroupLayoutEntry { - binding: 4, - ..mip_texture_entry - }, - BindGroupLayoutEntry { - binding: 5, - ..mip_texture_entry - }, - ], - }); + count: None, + }, + mip_texture_entry, + BindGroupLayoutEntry { + binding: 2, + ..mip_texture_entry + }, + BindGroupLayoutEntry { + binding: 3, + ..mip_texture_entry + }, + BindGroupLayoutEntry { + binding: 4, + ..mip_texture_entry + }, + BindGroupLayoutEntry { + binding: 5, + ..mip_texture_entry + }, + ], + ); - let gtao_bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("ssao_gtao_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + let gtao_bind_group_layout = render_device.create_bind_group_layout( + "ssao_gtao_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: false }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: false }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Uint, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 2, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Texture { + sample_type: TextureSampleType::Uint, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 3, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R16Float, - view_dimension: TextureViewDimension::D2, - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 3, + visibility: ShaderStages::COMPUTE, + ty: BindingType::StorageTexture { + access: StorageTextureAccess::WriteOnly, + format: TextureFormat::R16Float, + view_dimension: TextureViewDimension::D2, }, - BindGroupLayoutEntry { - binding: 4, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R32Uint, - view_dimension: TextureViewDimension::D2, - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 4, + visibility: ShaderStages::COMPUTE, + ty: BindingType::StorageTexture { + access: StorageTextureAccess::WriteOnly, + format: TextureFormat::R32Uint, + view_dimension: TextureViewDimension::D2, }, - BindGroupLayoutEntry { - binding: 5, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 5, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: Some(GlobalsUniform::min_size()), }, - ], - }); + count: None, + }, + ], + ); - let spatial_denoise_bind_group_layout = - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("ssao_spatial_denoise_bind_group_layout"), - entries: &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + let spatial_denoise_bind_group_layout = render_device.create_bind_group_layout( + "ssao_spatial_denoise_bind_group_layout", + &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: false }, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Uint, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Texture { + sample_type: TextureSampleType::Uint, + view_dimension: TextureViewDimension::D2, + multisampled: false, }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R16Float, - view_dimension: TextureViewDimension::D2, - }, - count: None, + count: None, + }, + BindGroupLayoutEntry { + binding: 2, + visibility: ShaderStages::COMPUTE, + ty: BindingType::StorageTexture { + access: StorageTextureAccess::WriteOnly, + format: TextureFormat::R16Float, + view_dimension: TextureViewDimension::D2, }, - ], - }); + count: None, + }, + ], + ); let preprocess_depth_pipeline = pipeline_cache.queue_compute_pipeline(ComputePipelineDescriptor { diff --git a/crates/bevy_render/src/render_resource/bind_group.rs b/crates/bevy_render/src/render_resource/bind_group.rs index b2907c64fd661..22ab55fd1292f 100644 --- a/crates/bevy_render/src/render_resource/bind_group.rs +++ b/crates/bevy_render/src/render_resource/bind_group.rs @@ -10,7 +10,7 @@ pub use bevy_render_macros::AsBindGroup; use bevy_utils::thiserror::Error; use encase::ShaderType; use std::ops::Deref; -use wgpu::{BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource}; +use wgpu::{BindGroupEntry, BindGroupLayoutEntry, BindingResource}; define_atomic_id!(BindGroupId); render_resource_wrapper!(ErasedBindGroup, wgpu::BindGroup); @@ -313,10 +313,10 @@ pub trait AsBindGroup { where Self: Sized, { - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Self::label(), - entries: &Self::bind_group_layout_entries(render_device), - }) + render_device.create_bind_group_layout( + Self::label(), + &Self::bind_group_layout_entries(render_device), + ) } /// Returns a vec of bind group layout entries diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index db3a034744be0..d8adeb802c634 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -201,9 +201,9 @@ impl FromWorld for ScreenshotToScreenPipeline { fn from_world(render_world: &mut World) -> Self { let device = render_world.resource::(); - let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - label: Some("screenshot-to-screen-bgl"), - entries: &[wgpu::BindGroupLayoutEntry { + let bind_group_layout = device.create_bind_group_layout( + "screenshot-to-screen-bgl", + &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { @@ -213,7 +213,7 @@ impl FromWorld for ScreenshotToScreenPipeline { }, count: None, }], - }); + ); Self { bind_group_layout } } diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 9a63de7d2eaaf..02536c31e6079 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -256,8 +256,9 @@ impl FromWorld for Mesh2dPipeline { )> = SystemState::new(world); let (render_device, render_queue, default_sampler) = system_state.get_mut(world); let render_device = render_device.into_inner(); - let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + let view_layout = render_device.create_bind_group_layout( + "mesh2d_view_layout", + &[ // View BindGroupLayoutEntry { binding: 0, @@ -280,17 +281,16 @@ impl FromWorld for Mesh2dPipeline { count: None, }, ], - label: Some("mesh2d_view_layout"), - }); + ); - let mesh_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[GpuArrayBuffer::::binding_layout( + let mesh_layout = render_device.create_bind_group_layout( + "mesh2d_layout", + &[GpuArrayBuffer::::binding_layout( 0, ShaderStages::VERTEX_FRAGMENT, render_device, )], - label: Some("mesh2d_layout"), - }); + ); // A 1x1x1 'all 1.0' texture to use as a dummy texture to use in place of optional StandardMaterial textures let dummy_white_gpu_image = { let image = Image::default(); diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 54048bfd448be..b57edd9ffa245 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -53,8 +53,9 @@ impl FromWorld for SpritePipeline { )> = SystemState::new(world); let (render_device, default_sampler, render_queue) = system_state.get_mut(world); - let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[BindGroupLayoutEntry { + let view_layout = render_device.create_bind_group_layout( + "sprite_view_layout", + &[BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, ty: BindingType::Buffer { @@ -64,11 +65,11 @@ impl FromWorld for SpritePipeline { }, count: None, }], - label: Some("sprite_view_layout"), - }); + ); - let material_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + let material_layout = render_device.create_bind_group_layout( + "sprite_material_layout", + &[ BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::FRAGMENT, @@ -86,8 +87,7 @@ impl FromWorld for SpritePipeline { count: None, }, ], - label: Some("sprite_material_layout"), - }); + ); let dummy_white_gpu_image = { let image = Image::default(); let texture = render_device.create_texture(&image.texture_descriptor); diff --git a/crates/bevy_ui/src/render/pipeline.rs b/crates/bevy_ui/src/render/pipeline.rs index eaef41dbf4e90..9212f758fef47 100644 --- a/crates/bevy_ui/src/render/pipeline.rs +++ b/crates/bevy_ui/src/render/pipeline.rs @@ -16,8 +16,9 @@ impl FromWorld for UiPipeline { fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); - let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[BindGroupLayoutEntry { + let view_layout = render_device.create_bind_group_layout( + "ui_view_layout", + &[BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, ty: BindingType::Buffer { @@ -27,11 +28,11 @@ impl FromWorld for UiPipeline { }, count: None, }], - label: Some("ui_view_layout"), - }); + ); - let image_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[ + let image_layout = render_device.create_bind_group_layout( + "ui_image_layout", + &[ BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::FRAGMENT, @@ -49,8 +50,7 @@ impl FromWorld for UiPipeline { count: None, }, ], - label: Some("ui_image_layout"), - }); + ); UiPipeline { view_layout, diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index 83ef5ef592c77..b521a9fdc1b90 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -223,8 +223,9 @@ impl FromWorld for UiMaterialPipeline { let render_device = world.resource::(); let ui_layout = M::bind_group_layout(render_device); - let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - entries: &[BindGroupLayoutEntry { + let view_layout = render_device.create_bind_group_layout( + "ui_view_layout", + &[BindGroupLayoutEntry { binding: 0, visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, ty: BindingType::Buffer { @@ -234,8 +235,7 @@ impl FromWorld for UiMaterialPipeline { }, count: None, }], - label: Some("ui_view_layout"), - }); + ); UiMaterialPipeline { ui_layout, view_layout, From 052be24d2b37a3d2377b092a8c27c1a624f2abbc Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 5 Nov 2023 01:35:43 -0500 Subject: [PATCH 04/24] use entries in a few places --- .../src/bloom/downsampling_pipeline.rs | 46 ++++----------- .../src/bloom/upsampling_pipeline.rs | 42 ++++---------- examples/shader/post_processing.rs | 58 +++++-------------- 3 files changed, 39 insertions(+), 107 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs index 22a702dd632f7..0a57f184fd8f3 100644 --- a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs @@ -41,42 +41,20 @@ impl FromWorld for BloomDownsamplingPipeline { fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); - // Input texture binding - let texture = BindGroupLayoutEntry { - binding: 0, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - visibility: ShaderStages::FRAGMENT, - count: None, - }; - - // Sampler binding - let sampler = BindGroupLayoutEntry { - binding: 1, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - visibility: ShaderStages::FRAGMENT, - count: None, - }; - - // Downsampling settings binding - let settings = BindGroupLayoutEntry { - binding: 2, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(BloomUniforms::min_size()), - }, - visibility: ShaderStages::FRAGMENT, - count: None, - }; - // Bind group layout let bind_group_layout = render_device.create_bind_group_layout( - Some("bloom_downsampling_bind_group_layout_with_settings"), - &[texture, sampler, settings], + "bloom_downsampling_bind_group_layout_with_settings", + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + // Input texture binding + texture_2d(TextureSampleType::Float { filterable: true }), + // Sampler binding + sampler(SamplerBindingType::Filtering), + // Downsampling settings binding + uniform_buffer(true, Some(BloomUniforms::min_size())), + ), + ), ); // Sampler diff --git a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs index 89870700e36b6..b01fa01dc3046 100644 --- a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs @@ -33,37 +33,17 @@ impl FromWorld for BloomUpsamplingPipeline { let bind_group_layout = render_device.create_bind_group_layout( "bloom_upsampling_bind_group_layout", - &[ - // Input texture - BindGroupLayoutEntry { - binding: 0, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - visibility: ShaderStages::FRAGMENT, - count: None, - }, - // Sampler - BindGroupLayoutEntry { - binding: 1, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - visibility: ShaderStages::FRAGMENT, - count: None, - }, - // BloomUniforms - BindGroupLayoutEntry { - binding: 2, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(BloomUniforms::min_size()), - }, - visibility: ShaderStages::FRAGMENT, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + // Input texture + texture_2d(TextureSampleType::Float { filterable: true }), + // Sampler + sampler(SamplerBindingType::Filtering), + // BloomUniforms + uniform_buffer(true, Some(BloomUniforms::min_size())), + ), + ), ); BloomUpsamplingPipeline { bind_group_layout } diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 39a6c46530b54..3f65ff628fde1 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -19,14 +19,7 @@ use bevy::{ render_graph::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, - render_resource::{ - BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, - BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, - MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, - RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, - SamplerDescriptor, ShaderStages, ShaderType, TextureFormat, TextureSampleType, - TextureViewDimension, - }, + render_resource::*, renderer::{RenderContext, RenderDevice}, texture::BevyDefault, view::ViewTarget, @@ -230,40 +223,21 @@ impl FromWorld for PostProcessPipeline { let render_device = world.resource::(); // We need to define the bind group layout used for our pipeline - let layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { - label: Some("post_process_bind_group_layout"), - entries: &[ - // The screen texture - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // The sampler that will be used to sample the screen texture - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - // The settings uniform that will control the effect - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: bevy::render::render_resource::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(PostProcessSettings::min_size()), - }, - count: None, - }, - ], - }); + let layout = render_device.create_bind_group_layout( + "post_process_bind_group_layout", + &BindGroupLayoutEntries::sequential( + // The layout entries will only be visible in the fragment stage + ShaderStages::FRAGMENT, + ( + // The screen texture + texture_2d(TextureSampleType::Float { filterable: true }), + // The sampler that will be used to sample the screen texture + sampler(SamplerBindingType::Filtering), + // The settings uniform that will control the effect + uniform_buffer(false, Some(PostProcessSettings::min_size())), + ), + ), + ); // We can create the sampler here since it won't change at runtime and doesn't depend on the view let sampler = render_device.create_sampler(&SamplerDescriptor::default()); From 8c9ba4f57022edb85a9134553c2de9523de9535a Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 5 Nov 2023 01:38:02 -0500 Subject: [PATCH 05/24] fmt --- crates/bevy_core_pipeline/src/skybox/mod.rs | 13 ++++++------- crates/bevy_core_pipeline/src/taa/mod.rs | 10 +++++----- crates/bevy_gizmos/src/lib.rs | 7 +++---- crates/bevy_pbr/src/render/mesh_view_bindings.rs | 6 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index e1993ea68c9b3..3acc0c4836547 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -10,13 +10,12 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, - BindGroupLayoutEntry, BindingType, BufferBindingType, CachedRenderPipelineId, - ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, - FragmentState, MultisampleState, PipelineCache, PrimitiveState, RenderPipelineDescriptor, - SamplerBindingType, Shader, ShaderStages, ShaderType, SpecializedRenderPipeline, - SpecializedRenderPipelines, StencilFaceState, StencilState, TextureFormat, - TextureSampleType, TextureViewDimension, VertexState, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, + BufferBindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, + DepthBiasState, DepthStencilState, FragmentState, MultisampleState, PipelineCache, + PrimitiveState, RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, + ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, + StencilState, TextureFormat, TextureSampleType, TextureViewDimension, VertexState, }, renderer::RenderDevice, texture::{BevyDefault, Image}, diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index afb4d7bb4be50..28757a1697c89 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -21,11 +21,11 @@ use bevy_render::{ prelude::{Camera, Projection}, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ - BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, - BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, Extent3d, FilterMode, - FragmentState, MultisampleState, Operations, PipelineCache, PrimitiveState, - RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, Sampler, - SamplerBindingType, SamplerDescriptor, Shader, ShaderStages, SpecializedRenderPipeline, + BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, + CachedRenderPipelineId, ColorTargetState, ColorWrites, Extent3d, FilterMode, FragmentState, + MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, + RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, + SamplerDescriptor, Shader, ShaderStages, SpecializedRenderPipeline, SpecializedRenderPipelines, TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, TextureViewDimension, }, diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index bff63e24418e1..b15c1a1438ecd 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -54,10 +54,9 @@ use bevy_render::{ render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, - BindGroupLayoutEntry, BindingType, Buffer, BufferBindingType, BufferInitDescriptor, - BufferUsages, Shader, ShaderStages, ShaderType, VertexAttribute, VertexBufferLayout, - VertexFormat, VertexStepMode, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, Buffer, + BufferBindingType, BufferInitDescriptor, BufferUsages, Shader, ShaderStages, ShaderType, + VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode, }, renderer::RenderDevice, view::RenderLayers, diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 690bc12778787..b13e8d43fd807 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -16,9 +16,9 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindingType, - BufferBindingType, DynamicBindGroupEntries, SamplerBindingType, ShaderStages, ShaderType, - TextureFormat, TextureSampleType, TextureViewDimension, + BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindingType, BufferBindingType, + DynamicBindGroupEntries, SamplerBindingType, ShaderStages, ShaderType, TextureFormat, + TextureSampleType, TextureViewDimension, }, renderer::RenderDevice, texture::{BevyDefault, FallbackImageCubemap, FallbackImageMsaa, FallbackImageZero, Image}, From 51d27212d01b64f06b14fdf387d623a51c616e1e Mon Sep 17 00:00:00 2001 From: IceSentry Date: Tue, 7 Nov 2023 23:27:49 -0500 Subject: [PATCH 06/24] binding_types in separate module --- .../src/bloom/downsampling_pipeline.rs | 8 +- .../src/bloom/upsampling_pipeline.rs | 9 +- .../bind_group_layout_entries.rs | 434 ++++++++++++------ 3 files changed, 300 insertions(+), 151 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs index 0a57f184fd8f3..e68af8784b73f 100644 --- a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs @@ -6,7 +6,13 @@ use bevy_ecs::{ world::{FromWorld, World}, }; use bevy_math::Vec4; -use bevy_render::{render_resource::*, renderer::RenderDevice}; +use bevy_render::{ + render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, + *, + }, + renderer::RenderDevice, +}; #[derive(Component)] pub struct BloomDownsamplingPipelineIds { diff --git a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs index b01fa01dc3046..6fb6fd1bb363c 100644 --- a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs @@ -8,7 +8,14 @@ use bevy_ecs::{ system::{Commands, Query, Res, ResMut, Resource}, world::{FromWorld, World}, }; -use bevy_render::{render_resource::*, renderer::RenderDevice, view::ViewTarget}; +use bevy_render::{ + render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, + *, + }, + renderer::RenderDevice, + view::ViewTarget, +}; #[derive(Component)] pub struct UpsamplingPipelineIds { diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index ca71ab1dc5aea..ed834db3b77fb 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -1,9 +1,130 @@ -use crate::render_resource::{ - BufferBindingType, SamplerBindingType, TextureSampleType, TextureViewDimension, -}; use bevy_utils::all_tuples_with_size; -use std::num::{NonZeroU32, NonZeroU64}; -use wgpu::{BindingType, ShaderStages, StorageTextureAccess, TextureFormat}; +use std::num::NonZeroU32; +use wgpu::{BindGroupLayoutEntry, BindingType, ShaderStages}; + +/// Helper for constructing bind group layouts. +/// +/// Allows constructing the layout's entries as: +/// ```ignore +/// let layout = render_device.create_bind_group_layout( +/// "my_bind_group_layout", +/// &BindGroupLayoutEntries::with_indices( +/// // The layout entries will only be visible in the fragment stage +/// ShaderStages::FRAGMENT, +/// ( +/// // Screen texture +/// (2, tepxture_2d(TextureSampleType::Float { filterable: true })), +/// // Sampler +/// (3, sampler(SamplerBindingType::Filtering)), +/// ), +/// ), +/// ); +/// ``` +/// +/// instead of +/// +/// ```ignore +/// let layout = render_device.create_bind_group_layout( +/// "my_bind_group_layout", +/// &[ +/// // Screen texture +/// BindGroupLayoutEntry { +/// binding: 2, +/// visibility: ShaderStages::FRAGMENT, +/// ty: BindingType::Texture { +/// sample_type: TextureSampleType::Float { filterable: true }, +/// view_dimension: TextureViewDimension::D2, +/// multisampled: false, +/// }, +/// count: None, +/// }, +/// // Sampler +/// BindGroupLayoutEntry { +/// binding: 3, +/// visibility: ShaderStages::FRAGMENT, +/// ty: BindingType::Sampler(SamplerBindingType::Filtering), +/// count: None, +/// }, +/// ], +/// ); +/// ``` +/// +/// or +/// +/// ```ignore +/// render_device.create_bind_group_layout( +/// "my_bind_group_layout", +/// &BindGroupLayoutEntries::sequential( +/// ShaderStages::FRAGMENT, +/// ( +/// // Screen texture +/// texture_2d(TextureSampleType::Float { filterable: true }), +/// // Sampler +/// sampler(SamplerBindingType::Filtering), +/// ), +/// ), +/// ); +/// ``` +/// +/// instead of +/// +/// ```ignore +/// let layout = render_device.create_bind_group_layout( +/// "my_bind_group_layout", +/// &[ +/// // Screen texture +/// BindGroupLayoutEntry { +/// binding: 0, +/// visibility: ShaderStages::FRAGMENT, +/// ty: BindingType::Texture { +/// sample_type: TextureSampleType::Float { filterable: true }, +/// view_dimension: TextureViewDimension::D2, +/// multisampled: false, +/// }, +/// count: None, +/// }, +/// // Sampler +/// BindGroupLayoutEntry { +/// binding: 1, +/// visibility: ShaderStages::FRAGMENT, +/// ty: BindingType::Sampler(SamplerBindingType::Filtering), +/// count: None, +/// }, +/// ], +/// ); +/// ``` +/// +/// or +/// +/// ```ignore +/// render_device.create_bind_group_layout( +/// "my_bind_group_layout", +/// &BindGroupLayoutEntries::single( +/// ShaderStages::FRAGMENT, +/// texture_2d(TextureSampleType::Float { filterable: true }), +/// ), +/// ); +/// ``` +/// +/// instead of +/// +/// ```ignore +/// let layout = render_device.create_bind_group_layout( +/// "my_bind_group_layout", +/// &[ +/// BindGroupLayoutEntry { +/// binding: 0, +/// visibility: ShaderStages::FRAGMENT, +/// ty: BindingType::Texture { +/// sample_type: TextureSampleType::Float { filterable: true }, +/// view_dimension: TextureViewDimension::D2, +/// multisampled: false, +/// }, +/// count: None, +/// }, +/// ], +/// ); +/// ``` pub struct BindGroupLayoutEntryBuilder { pub ty: BindingType, @@ -21,6 +142,19 @@ impl BindGroupLayoutEntryBuilder { self.count = Some(count); self } + + pub fn build( + &self, + binding: u32, + default_visibility: ShaderStages, + ) -> wgpu::BindGroupLayoutEntry { + wgpu::BindGroupLayoutEntry { + binding, + ty: self.ty, + visibility: self.visibility.unwrap_or(default_visibility), + count: self.count, + } + } } pub struct BindGroupLayoutEntries { @@ -39,12 +173,7 @@ impl BindGroupLayoutEntries { entries: entries_ext.into_array().map(|entry| { let binding = i; i += 1; - wgpu::BindGroupLayoutEntry { - binding, - ty: entry.ty, - visibility: entry.visibility.unwrap_or(default_visibility), - count: entry.count, - } + entry.build(binding, default_visibility) }), } } @@ -56,14 +185,10 @@ impl BindGroupLayoutEntries { indexed_entries: impl IntoIndexedBindGroupLayoutEntryBuilderArray, ) -> Self { Self { - entries: indexed_entries.into_array().map(|(binding, entry)| { - wgpu::BindGroupLayoutEntry { - binding, - ty: entry.ty, - visibility: entry.visibility.unwrap_or(default_visibility), - count: entry.count, - } - }), + entries: indexed_entries + .into_array() + .map(|(binding, entry)| entry.build(binding, default_visibility)), + } } } } @@ -76,11 +201,11 @@ impl std::ops::Deref for BindGroupLayoutEntries { } pub trait IntoBindGroupLayoutEntryBuilder { - fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder; + fn into_bind_group_layout_entry_builder(self) -> BindGroupLayoutEntryBuilder; } impl IntoBindGroupLayoutEntryBuilder for BindingType { - fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder { + fn into_bind_group_layout_entry_builder(self) -> BindGroupLayoutEntryBuilder { BindGroupLayoutEntryBuilder { ty: self, visibility: None, @@ -90,7 +215,7 @@ impl IntoBindGroupLayoutEntryBuilder for BindingType { } impl IntoBindGroupLayoutEntryBuilder for wgpu::BindGroupLayoutEntry { - fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder { + fn into_bind_group_layout_entry_builder(self) -> BindGroupLayoutEntryBuilder { if self.binding != u32::MAX { bevy_log::warn!("The BindGroupLayoutEntries api ignores the binding index when converting a raw wgpu::BindGroupLayoutEntry. You can ignore this warning by setting it to u32::MAX."); } @@ -103,7 +228,7 @@ impl IntoBindGroupLayoutEntryBuilder for wgpu::BindGroupLayoutEntry { } impl IntoBindGroupLayoutEntryBuilder for BindGroupLayoutEntryBuilder { - fn into_bind_group_layout_entry(self) -> BindGroupLayoutEntryBuilder { + fn into_bind_group_layout_entry_builder(self) -> BindGroupLayoutEntryBuilder { self } } @@ -117,7 +242,7 @@ macro_rules! impl_to_binding_type_slice { #[inline] fn into_array(self) -> [BindGroupLayoutEntryBuilder; $N] { let ($($I,)*) = self; - [$($I.into_bind_group_layout_entry(), )*] + [$($I.into_bind_group_layout_entry_builder(), )*] } } } @@ -133,161 +258,172 @@ macro_rules! impl_to_indexed_binding_type_slice { #[inline] fn into_array(self) -> [(u32, BindGroupLayoutEntryBuilder); $N] { let ($(($S, $I),)*) = self; - [$(($S, $I.into_bind_group_layout_entry())), *] + [$(($S, $I.into_bind_group_layout_entry_builder())), *] } } } } all_tuples_with_size!(impl_to_indexed_binding_type_slice, 1, 32, T, n, s); -#[allow(unused)] -pub fn storage_buffer( - has_dynamic_offset: bool, - min_binding_size: Option, -) -> BindGroupLayoutEntryBuilder { - BindingType::Buffer { - ty: BufferBindingType::Storage { read_only: false }, - has_dynamic_offset, - min_binding_size, +pub mod binding_types { + use crate::render_resource::{ + BufferBindingType, SamplerBindingType, TextureSampleType, TextureViewDimension, + }; + use std::num::NonZeroU64; + use wgpu::{BindingType, StorageTextureAccess, TextureFormat}; + + use super::*; + + #[allow(unused)] + pub fn storage_buffer( + has_dynamic_offset: bool, + min_binding_size: Option, + ) -> BindGroupLayoutEntryBuilder { + BindingType::Buffer { + ty: BufferBindingType::Storage { read_only: false }, + has_dynamic_offset, + min_binding_size, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn storage_buffer_read_only( - has_dynamic_offset: bool, - min_binding_size: Option, -) -> BindGroupLayoutEntryBuilder { - BindingType::Buffer { - ty: BufferBindingType::Storage { read_only: true }, - has_dynamic_offset, - min_binding_size, + #[allow(unused)] + pub fn storage_buffer_read_only( + has_dynamic_offset: bool, + min_binding_size: Option, + ) -> BindGroupLayoutEntryBuilder { + BindingType::Buffer { + ty: BufferBindingType::Storage { read_only: true }, + has_dynamic_offset, + min_binding_size, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn uniform_buffer( - has_dynamic_offset: bool, - min_binding_size: Option, -) -> BindGroupLayoutEntryBuilder { - BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset, - min_binding_size, + #[allow(unused)] + pub fn uniform_buffer( + has_dynamic_offset: bool, + min_binding_size: Option, + ) -> BindGroupLayoutEntryBuilder { + BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset, + min_binding_size, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn texture_2d(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { - BindingType::Texture { - sample_type, - view_dimension: TextureViewDimension::D2, - multisampled: false, + #[allow(unused)] + pub fn texture_2d(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2, + multisampled: false, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn texture_2d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { - BindingType::Texture { - sample_type, - view_dimension: TextureViewDimension::D2, - multisampled: true, + #[allow(unused)] + pub fn texture_2d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2, + multisampled: true, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn texture_2d_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { - BindingType::Texture { - sample_type, - view_dimension: TextureViewDimension::D2Array, - multisampled: false, + #[allow(unused)] + pub fn texture_2d_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2Array, + multisampled: false, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn texture_2d_array_multisampled( - sample_type: TextureSampleType, -) -> BindGroupLayoutEntryBuilder { - BindingType::Texture { - sample_type, - view_dimension: TextureViewDimension::D2Array, - multisampled: true, + #[allow(unused)] + pub fn texture_2d_array_multisampled( + sample_type: TextureSampleType, + ) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D2Array, + multisampled: true, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn texture_2d_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_2d_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_2d_multisampled_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Float { filterable }).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_2d_multisampled_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Float { filterable }) + .into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_2d_i32() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_2d_i32() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_2d_multisampled_i32() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_2d_multisampled_i32() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_2d_u32() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_2d_u32() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_2d_multisampled_u32() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_2d_multisampled_u32() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_depth_2d() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Depth).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_depth_2d() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Depth).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_depth_2d_multisampled() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Depth).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn texture_depth_2d_multisampled() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Depth).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn sampler(sampler_binding_type: SamplerBindingType) -> BindGroupLayoutEntryBuilder { - BindingType::Sampler(sampler_binding_type).into_bind_group_layout_entry() -} + #[allow(unused)] + pub fn sampler(sampler_binding_type: SamplerBindingType) -> BindGroupLayoutEntryBuilder { + BindingType::Sampler(sampler_binding_type).into_bind_group_layout_entry_builder() + } -#[allow(unused)] -pub fn texture_storage_2d( - format: TextureFormat, - access: StorageTextureAccess, -) -> BindGroupLayoutEntryBuilder { - BindingType::StorageTexture { - access, - format, - view_dimension: TextureViewDimension::D2, + #[allow(unused)] + pub fn texture_storage_2d( + format: TextureFormat, + access: StorageTextureAccess, + ) -> BindGroupLayoutEntryBuilder { + BindingType::StorageTexture { + access, + format, + view_dimension: TextureViewDimension::D2, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() -} -#[allow(unused)] -pub fn texture_storage_2d_array( - format: TextureFormat, - access: StorageTextureAccess, -) -> BindGroupLayoutEntryBuilder { - BindingType::StorageTexture { - access, - format, - view_dimension: TextureViewDimension::D2Array, + #[allow(unused)] + pub fn texture_storage_2d_array( + format: TextureFormat, + access: StorageTextureAccess, + ) -> BindGroupLayoutEntryBuilder { + BindingType::StorageTexture { + access, + format, + view_dimension: TextureViewDimension::D2Array, + } + .into_bind_group_layout_entry_builder() } - .into_bind_group_layout_entry() } From 62900376b95b786a31c15f87a4b346d95ef584ac Mon Sep 17 00:00:00 2001 From: IceSentry Date: Tue, 7 Nov 2023 23:27:56 -0500 Subject: [PATCH 07/24] single --- .../src/render_resource/bind_group_layout_entries.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index ed834db3b77fb..c14d147eaa2f4 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -189,7 +189,17 @@ impl BindGroupLayoutEntries { .into_array() .map(|(binding, entry)| entry.build(binding, default_visibility)), } - } + } +} + +impl BindGroupLayoutEntries<1> { + pub fn single( + visibility: ShaderStages, + resource: impl IntoBindGroupLayoutEntryBuilder, + ) -> [BindGroupLayoutEntry; 1] { + [resource + .into_bind_group_layout_entry_builder() + .build(0, visibility)] } } From cbe9e19f1d2ffbf04067d88843f37e60c22c8ece Mon Sep 17 00:00:00 2001 From: IceSentry Date: Tue, 7 Nov 2023 23:34:29 -0500 Subject: [PATCH 08/24] add dynamic variant --- .../bind_group_layout_entries.rs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index c14d147eaa2f4..2792e499adef8 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -275,6 +275,78 @@ macro_rules! impl_to_indexed_binding_type_slice { } all_tuples_with_size!(impl_to_indexed_binding_type_slice, 1, 32, T, n, s); +pub struct DynamicBindGroupLayoutEntries { + default_visibility: ShaderStages, + entries: Vec, +} + +impl DynamicBindGroupLayoutEntries { + pub fn sequential( + default_visibility: ShaderStages, + entries: impl IntoBindGroupLayoutEntryBuilderArray, + ) -> Self { + Self { + default_visibility, + entries: entries + .into_array() + .into_iter() + .enumerate() + .map(|(ix, resource)| resource.build(ix as u32, default_visibility)) + .collect(), + } + } + + pub fn extend_sequential( + mut self, + entries: impl IntoBindGroupLayoutEntryBuilderArray, + ) -> Self { + let start = self.entries.last().unwrap().binding + 1; + self.entries.extend( + entries + .into_array() + .into_iter() + .enumerate() + .map(|(ix, resource)| resource.build(start + ix as u32, self.default_visibility)), + ); + self + } + + pub fn new_with_indices( + default_visibility: ShaderStages, + entries: impl IntoIndexedBindGroupLayoutEntryBuilderArray, + ) -> Self { + Self { + default_visibility, + entries: entries + .into_array() + .into_iter() + .map(|(binding, resource)| resource.build(binding, default_visibility)) + .collect(), + } + } + + pub fn extend_with_indices( + mut self, + entries: impl IntoIndexedBindGroupLayoutEntryBuilderArray, + ) -> Self { + self.entries.extend( + entries + .into_array() + .into_iter() + .map(|(binding, resource)| resource.build(binding, self.default_visibility)), + ); + self + } +} + +impl std::ops::Deref for DynamicBindGroupLayoutEntries { + type Target = [BindGroupLayoutEntry]; + + fn deref(&self) -> &[BindGroupLayoutEntry] { + &self.entries + } +} + pub mod binding_types { use crate::render_resource::{ BufferBindingType, SamplerBindingType, TextureSampleType, TextureViewDimension, From 5fd4c54b9f0426d8cc53330bc4d257500fc27da2 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Nov 2023 00:12:14 -0500 Subject: [PATCH 09/24] add more texture type --- .../bind_group_layout_entries.rs | 70 ++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 2792e499adef8..447f98bde7d11 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -127,9 +127,9 @@ use wgpu::{BindGroupLayoutEntry, BindingType, ShaderStages}; /// ``` pub struct BindGroupLayoutEntryBuilder { - pub ty: BindingType, - pub visibility: Option, - pub count: Option, + ty: BindingType, + visibility: Option, + count: Option, } impl BindGroupLayoutEntryBuilder { @@ -478,6 +478,70 @@ pub mod binding_types { texture_2d_multisampled(TextureSampleType::Depth).into_bind_group_layout_entry_builder() } + #[allow(unused)] + pub fn texture_cube(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::Cube, + multisampled: false, + } + .into_bind_group_layout_entry_builder() + } + + #[allow(unused)] + pub fn texture_cube_mutlisampled( + sample_type: TextureSampleType, + ) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::Cube, + multisampled: true, + } + .into_bind_group_layout_entry_builder() + } + + #[allow(unused)] + pub fn texture_cube_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::CubeArray, + multisampled: false, + } + .into_bind_group_layout_entry_builder() + } + + #[allow(unused)] + pub fn texture_cube_array_mutlisampled( + sample_type: TextureSampleType, + ) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::CubeArray, + multisampled: true, + } + .into_bind_group_layout_entry_builder() + } + + #[allow(unused)] + pub fn texture_3d(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D3, + multisampled: false, + } + .into_bind_group_layout_entry_builder() + } + + #[allow(unused)] + pub fn texture_3d_mutlisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + BindingType::Texture { + sample_type, + view_dimension: TextureViewDimension::D3, + multisampled: true, + } + .into_bind_group_layout_entry_builder() + } + #[allow(unused)] pub fn sampler(sampler_binding_type: SamplerBindingType) -> BindGroupLayoutEntryBuilder { BindingType::Sampler(sampler_binding_type).into_bind_group_layout_entry_builder() From a51a46cd2a9e8b69afe2a857605f73fa82e7aae3 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Nov 2023 00:50:22 -0500 Subject: [PATCH 10/24] use where possible --- crates/bevy_core_pipeline/src/blit/mod.rs | 34 ++- .../src/contrast_adaptive_sharpening/mod.rs | 43 ++-- .../src/deferred/copy_lighting_id.rs | 13 +- crates/bevy_core_pipeline/src/fxaa/mod.rs | 30 +-- crates/bevy_core_pipeline/src/skybox/mod.rs | 50 ++--- crates/bevy_core_pipeline/src/taa/mod.rs | 91 +++----- crates/bevy_gizmos/src/lib.rs | 20 +- crates/bevy_pbr/src/deferred/mod.rs | 18 +- crates/bevy_pbr/src/environment_map/mod.rs | 36 +--- crates/bevy_pbr/src/prepass/mod.rs | 80 ++----- .../bevy_pbr/src/render/mesh_view_bindings.rs | 72 +------ crates/bevy_pbr/src/ssao/mod.rs | 196 ++++-------------- .../bind_group_layout_entries.rs | 1 + .../bevy_render/src/view/window/screenshot.rs | 20 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 33 +-- crates/bevy_sprite/src/render/mod.rs | 44 ++-- crates/bevy_ui/src/render/pipeline.rs | 44 ++-- .../src/render/ui_material_pipeline.rs | 14 +- .../shader/compute_shader_game_of_life.rs | 24 +-- 19 files changed, 238 insertions(+), 625 deletions(-) diff --git a/crates/bevy_core_pipeline/src/blit/mod.rs b/crates/bevy_core_pipeline/src/blit/mod.rs index cd58c49f73b25..9a9777a43f212 100644 --- a/crates/bevy_core_pipeline/src/blit/mod.rs +++ b/crates/bevy_core_pipeline/src/blit/mod.rs @@ -1,7 +1,14 @@ use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, Handle}; use bevy_ecs::prelude::*; -use bevy_render::{render_resource::*, renderer::RenderDevice, RenderApp}; +use bevy_render::{ + render_resource::{ + binding_types::{sampler, texture_2d}, + *, + }, + renderer::RenderDevice, + RenderApp, +}; use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state; @@ -38,24 +45,13 @@ impl FromWorld for BlitPipeline { let texture_bind_group = render_device.create_bind_group_layout( "blit_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + texture_2d(TextureSampleType::Float { filterable: false }), + sampler(SamplerBindingType::NonFiltering), + ), + ), ); let sampler = render_device.create_sampler(&SamplerDescriptor::default()); diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs index 5f667b9e34964..d35a0b0525743 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs @@ -11,7 +11,10 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin}, prelude::Camera, render_graph::RenderGraphApp, - render_resource::*, + render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, + *, + }, renderer::RenderDevice, texture::BevyDefault, view::{ExtractedView, ViewTarget}, @@ -171,35 +174,15 @@ impl FromWorld for CASPipeline { let render_device = render_world.resource::(); let texture_bind_group = render_device.create_bind_group_layout( "sharpening_texture_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - // CAS Settings - BindGroupLayoutEntry { - binding: 2, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(CASUniform::min_size()), - }, - visibility: ShaderStages::FRAGMENT, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + texture_2d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + // CAS Settings + uniform_buffer(true, Some(CASUniform::min_size())), + ), + ), ); let sampler = render_device.create_sampler(&SamplerDescriptor::default()); diff --git a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs index ec9aac0d4454f..7f32cb017bb1d 100644 --- a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs +++ b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs @@ -8,7 +8,7 @@ use bevy_ecs::prelude::*; use bevy_math::UVec2; use bevy_render::{ camera::ExtractedCamera, - render_resource::*, + render_resource::{binding_types::texture_2d_u32, *}, renderer::RenderDevice, texture::{CachedTexture, TextureCache}, view::ViewTarget, @@ -130,16 +130,7 @@ impl FromWorld for CopyDeferredLightingIdPipeline { let layout = render_device.create_bind_group_layout( "copy_deferred_lighting_id_bind_group_layout", - &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Uint, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }], + &BindGroupLayoutEntries::single(ShaderStages::FRAGMENT, texture_2d_u32()), ); let pipeline_id = diff --git a/crates/bevy_core_pipeline/src/fxaa/mod.rs b/crates/bevy_core_pipeline/src/fxaa/mod.rs index 7961af19fcc28..a0ccc00fbad1c 100644 --- a/crates/bevy_core_pipeline/src/fxaa/mod.rs +++ b/crates/bevy_core_pipeline/src/fxaa/mod.rs @@ -13,7 +13,10 @@ use bevy_render::{ prelude::Camera, render_graph::RenderGraphApp, render_graph::ViewNodeRunner, - render_resource::*, + render_resource::{ + binding_types::{sampler, texture_2d}, + *, + }, renderer::RenderDevice, texture::BevyDefault, view::{ExtractedView, ViewTarget}, @@ -133,24 +136,13 @@ impl FromWorld for FxaaPipeline { .resource::() .create_bind_group_layout( "fxaa_texture_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + texture_2d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + ), + ), ); FxaaPipeline { texture_bind_group } diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 3acc0c4836547..fc9b1d48b4dd5 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -10,12 +10,13 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, - BufferBindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, - DepthBiasState, DepthStencilState, FragmentState, MultisampleState, PipelineCache, - PrimitiveState, RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, - ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, - StencilState, TextureFormat, TextureSampleType, TextureViewDimension, VertexState, + binding_types::{sampler, texture_2d, uniform_buffer}, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, + CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, + DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, + RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType, + SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState, + TextureFormat, TextureSampleType, VertexState, }, renderer::RenderDevice, texture::{BevyDefault, Image}, @@ -82,34 +83,15 @@ impl SkyboxPipeline { Self { bind_group_layout: render_device.create_bind_group_layout( "skybox_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::Cube, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + texture_2d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + uniform_buffer(true, Some(ViewUniform::min_size())) + .visibility(ShaderStages::VERTEX_FRAGMENT), + ), + ), ), } } diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index 28757a1697c89..dd0ecfdbdd63b 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -21,13 +21,13 @@ use bevy_render::{ prelude::{Camera, Projection}, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ - BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, - CachedRenderPipelineId, ColorTargetState, ColorWrites, Extent3d, FilterMode, FragmentState, - MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, - RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, - SamplerDescriptor, Shader, ShaderStages, SpecializedRenderPipeline, - SpecializedRenderPipelines, TextureDescriptor, TextureDimension, TextureFormat, - TextureSampleType, TextureUsages, TextureViewDimension, + binding_types::{sampler, texture_2d, texture_depth_2d}, + BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, CachedRenderPipelineId, + ColorTargetState, ColorWrites, Extent3d, FilterMode, FragmentState, MultisampleState, + Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, + RenderPipelineDescriptor, Sampler, SamplerBindingType, SamplerDescriptor, Shader, + ShaderStages, SpecializedRenderPipeline, SpecializedRenderPipelines, TextureDescriptor, + TextureDimension, TextureFormat, TextureSampleType, TextureUsages, }, renderer::{RenderContext, RenderDevice}, texture::{BevyDefault, CachedTexture, TextureCache}, @@ -268,66 +268,23 @@ impl FromWorld for TaaPipeline { let taa_bind_group_layout = render_device.create_bind_group_layout( "taa_bind_group_layout", - &[ - // View target (read) - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // TAA History (read) - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // Motion Vectors - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // Depth - BindGroupLayoutEntry { - binding: 3, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Depth, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - // Nearest sampler - BindGroupLayoutEntry { - binding: 4, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, - }, - // Linear sampler - BindGroupLayoutEntry { - binding: 5, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + // View target (read) + texture_2d(TextureSampleType::Float { filterable: true }), + // TAA History (read) + texture_2d(TextureSampleType::Float { filterable: true }), + // Motion Vectors + texture_2d(TextureSampleType::Float { filterable: true }), + // Depth + texture_depth_2d(), + // Nearest sampler + sampler(SamplerBindingType::NonFiltering), + // Linear sampler + sampler(SamplerBindingType::Filtering), + ), + ), ); TaaPipeline { diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index b15c1a1438ecd..8e8a9c2d6c101 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -54,9 +54,9 @@ use bevy_render::{ render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType, Buffer, - BufferBindingType, BufferInitDescriptor, BufferUsages, Shader, ShaderStages, ShaderType, - VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode, + binding_types::uniform_buffer, BindGroup, BindGroupEntries, BindGroupLayout, + BindGroupLayoutEntries, Buffer, BufferInitDescriptor, BufferUsages, Shader, ShaderStages, + ShaderType, VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode, }, renderer::RenderDevice, view::RenderLayers, @@ -121,16 +121,10 @@ impl Plugin for GizmoPlugin { let render_device = render_app.world.resource::(); let layout = render_device.create_bind_group_layout( "LineGizmoUniform layout", - &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(LineGizmoUniform::min_size()), - }, - count: None, - }], + &BindGroupLayoutEntries::single( + ShaderStages::VERTEX, + uniform_buffer(true, Some(LineGizmoUniform::min_size())), + ), ); render_app.insert_resource(LineGizmoUniformBindgroupLayout { layout }); diff --git a/crates/bevy_pbr/src/deferred/mod.rs b/crates/bevy_pbr/src/deferred/mod.rs index 77fb8acb5e4b1..13e9d2523c0f2 100644 --- a/crates/bevy_pbr/src/deferred/mod.rs +++ b/crates/bevy_pbr/src/deferred/mod.rs @@ -18,7 +18,9 @@ use bevy_render::{ }, render_asset::RenderAssets, render_graph::{NodeRunError, RenderGraphContext, ViewNode, ViewNodeRunner}, - render_resource::{self, Operations, PipelineCache, RenderPassDescriptor}, + render_resource::{ + binding_types::uniform_buffer, Operations, PipelineCache, RenderPassDescriptor, + }, renderer::{RenderContext, RenderDevice}, texture::Image, view::{ViewTarget, ViewUniformOffset}, @@ -378,16 +380,10 @@ impl FromWorld for DeferredLightingLayout { let render_device = world.resource::(); let layout = render_device.create_bind_group_layout( "deferred_lighting_layout", - &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: render_resource::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(PbrDeferredLightingDepthId::min_size()), - }, - count: None, - }], + &BindGroupLayoutEntries::single( + ShaderStages::VERTEX_FRAGMENT, + uniform_buffer(false, Some(PbrDeferredLightingDepthId::min_size())), + ), ); Self { mesh_pipeline: world.resource::().clone(), diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index 9e8a1d517585f..bff3599345c12 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -6,7 +6,10 @@ use bevy_reflect::Reflect; use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, - render_resource::*, + render_resource::{ + binding_types::{sampler, texture_cube}, + *, + }, texture::{FallbackImageCubemap, Image}, }; @@ -81,31 +84,10 @@ pub fn get_bindings<'a>( pub fn get_bind_group_layout_entries(bindings: [u32; 3]) -> [BindGroupLayoutEntry; 3] { [ - BindGroupLayoutEntry { - binding: bindings[0], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::Cube, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: bindings[1], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::Cube, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: bindings[2], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, + texture_cube(TextureSampleType::Float { filterable: true }) + .build(bindings[0], ShaderStages::FRAGMENT), + texture_cube(TextureSampleType::Float { filterable: true }) + .build(bindings[1], ShaderStages::FRAGMENT), + sampler(SamplerBindingType::Filtering).build(bindings[2], ShaderStages::FRAGMENT), ] } diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 33f51c2d5ac1e..7cf1f91a616e6 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -1,5 +1,6 @@ mod prepass_bindings; +use bevy_render::render_resource::binding_types::uniform_buffer; pub use prepass_bindings::*; use bevy_app::{Plugin, PreUpdate}; @@ -231,69 +232,30 @@ impl FromWorld for PrepassPipeline { let view_layout_motion_vectors = render_device.create_bind_group_layout( "prepass_view_layout_motion_vectors", - &[ - // View - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - // Globals - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, - }, - // PreviousViewProjection - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(PreviousViewProjection::min_size()), - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::VERTEX_FRAGMENT, + ( + // View + uniform_buffer(true, Some(ViewUniform::min_size())), + // Globals + uniform_buffer(false, Some(GlobalsUniform::min_size())), + // PreviousViewProjection + uniform_buffer(true, Some(PreviousViewProjection::min_size())), + ), + ), ); let view_layout_no_motion_vectors = render_device.create_bind_group_layout( "prepass_view_layout_no_motion_vectors", - &[ - // View - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - // Globals - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::VERTEX_FRAGMENT, + ( + // View + uniform_buffer(true, Some(ViewUniform::min_size())), + // Globals + uniform_buffer(false, Some(GlobalsUniform::min_size())), + ), + ), ); let mesh_pipeline = world.resource::(); diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index b13e8d43fd807..76dfe1a69460c 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -16,6 +16,7 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, render_asset::RenderAssets, render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindingType, BufferBindingType, DynamicBindGroupEntries, SamplerBindingType, ShaderStages, ShaderType, TextureFormat, TextureSampleType, TextureViewDimension, @@ -151,27 +152,9 @@ fn layout_entries( ) -> Vec { let mut entries = vec![ // View - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, + uniform_buffer(true, Some(ViewUniform::min_size())).build(0, ShaderStages::VERTEX_FRAGMENT), // Lights - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(GpuLights::min_size()), - }, - count: None, - }, + uniform_buffer(true, Some(GpuLights::min_size())).build(1, ShaderStages::FRAGMENT), // Point Shadow Texture Cube Array BindGroupLayoutEntry { binding: 2, @@ -187,12 +170,7 @@ fn layout_entries( count: None, }, // Point Shadow Texture Array Sampler - BindGroupLayoutEntry { - binding: 3, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Comparison), - count: None, - }, + sampler(SamplerBindingType::Comparison).build(3, ShaderStages::FRAGMENT), // Directional Shadow Texture Array BindGroupLayoutEntry { binding: 4, @@ -208,12 +186,7 @@ fn layout_entries( count: None, }, // Directional Shadow Texture Array Sampler - BindGroupLayoutEntry { - binding: 5, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Comparison), - count: None, - }, + sampler(SamplerBindingType::Comparison).build(5, ShaderStages::FRAGMENT), // PointLights BindGroupLayoutEntry { binding: 6, @@ -254,38 +227,13 @@ fn layout_entries( count: None, }, // Globals - BindGroupLayoutEntry { - binding: 9, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, - }, + uniform_buffer(false, Some(GlobalsUniform::min_size())) + .build(9, ShaderStages::VERTEX_FRAGMENT), // Fog - BindGroupLayoutEntry { - binding: 10, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(GpuFog::min_size()), - }, - count: None, - }, + uniform_buffer(true, Some(GpuFog::min_size())).build(10, ShaderStages::FRAGMENT), // Screen space ambient occlusion texture - BindGroupLayoutEntry { - binding: 11, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled: false, - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, + texture_2d(TextureSampleType::Float { filterable: false }) + .build(11, ShaderStages::FRAGMENT), ]; // EnvironmentMapLight diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 004d496c6eb56..2618e0a87794e 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -20,7 +20,13 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, prelude::Camera, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, - render_resource::*, + render_resource::{ + binding_types::{ + sampler, texture_2d, texture_2d_u32, texture_depth_2d, texture_storage_2d, + uniform_buffer, + }, + *, + }, renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, texture::{CachedTexture, TextureCache}, view::{Msaa, ViewUniform, ViewUniformOffset, ViewUniforms}, @@ -347,169 +353,55 @@ impl FromWorld for SsaoPipelines { let common_bind_group_layout = render_device.create_bind_group_layout( "ssao_common_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + sampler(SamplerBindingType::NonFiltering), + uniform_buffer(true, Some(ViewUniform::min_size())), + ), + ), ); - let mip_texture_entry = BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R16Float, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }; let preprocess_depth_bind_group_layout = render_device.create_bind_group_layout( "ssao_preprocess_depth_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Depth, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - mip_texture_entry, - BindGroupLayoutEntry { - binding: 2, - ..mip_texture_entry - }, - BindGroupLayoutEntry { - binding: 3, - ..mip_texture_entry - }, - BindGroupLayoutEntry { - binding: 4, - ..mip_texture_entry - }, - BindGroupLayoutEntry { - binding: 5, - ..mip_texture_entry - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_depth_2d(), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + ), + ), ); let gtao_bind_group_layout = render_device.create_bind_group_layout( "ssao_gtao_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Uint, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 3, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R16Float, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 4, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R32Uint, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 5, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_2d(TextureSampleType::Float { filterable: false }), + texture_2d(TextureSampleType::Float { filterable: false }), + texture_2d_u32(), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::R32Uint, StorageTextureAccess::WriteOnly), + uniform_buffer(false, Some(GlobalsUniform::min_size())), + ), + ), ); let spatial_denoise_bind_group_layout = render_device.create_bind_group_layout( "ssao_spatial_denoise_bind_group_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::COMPUTE, - ty: BindingType::Texture { - sample_type: TextureSampleType::Uint, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::WriteOnly, - format: TextureFormat::R16Float, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_2d(TextureSampleType::Float { filterable: false }), + texture_2d_u32(), + texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), + ), + ), ); let preprocess_depth_pipeline = diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 447f98bde7d11..819da3b8d601a 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -126,6 +126,7 @@ use wgpu::{BindGroupLayoutEntry, BindingType, ShaderStages}; /// ); /// ``` +#[derive(Clone, Copy)] pub struct BindGroupLayoutEntryBuilder { ty: BindingType, visibility: Option, diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index d8adeb802c634..c219c3f243492 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -15,9 +15,9 @@ use wgpu::{ use crate::{ prelude::{Image, Shader}, render_resource::{ - BindGroup, BindGroupLayout, Buffer, CachedRenderPipelineId, FragmentState, PipelineCache, - RenderPipelineDescriptor, SpecializedRenderPipeline, SpecializedRenderPipelines, Texture, - VertexState, + binding_types::texture_2d, BindGroup, BindGroupLayout, BindGroupLayoutEntries, Buffer, + CachedRenderPipelineId, FragmentState, PipelineCache, RenderPipelineDescriptor, + SpecializedRenderPipeline, SpecializedRenderPipelines, Texture, VertexState, }, renderer::RenderDevice, texture::TextureFormatPixelInfo, @@ -203,16 +203,10 @@ impl FromWorld for ScreenshotToScreenPipeline { let bind_group_layout = device.create_bind_group_layout( "screenshot-to-screen-bgl", - &[wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { filterable: false }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }], + &BindGroupLayoutEntries::single( + wgpu::ShaderStages::FRAGMENT, + texture_2d(wgpu::TextureSampleType::Float { filterable: false }), + ), ); Self { bind_group_layout } diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 02536c31e6079..c308bf9d4688f 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -19,7 +19,7 @@ use bevy_render::{ mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout}, render_asset::RenderAssets, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, - render_resource::*, + render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, @@ -258,29 +258,14 @@ impl FromWorld for Mesh2dPipeline { let render_device = render_device.into_inner(); let view_layout = render_device.create_bind_group_layout( "mesh2d_view_layout", - &[ - // View - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::VERTEX_FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: Some(GlobalsUniform::min_size()), - }, - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::VERTEX_FRAGMENT, + ( + // View + uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer(false, Some(GlobalsUniform::min_size())), + ), + ), ); let mesh_layout = render_device.create_bind_group_layout( diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index b57edd9ffa245..84a5e6c39ab1b 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -21,7 +21,10 @@ use bevy_render::{ DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, }, - render_resource::{BindGroupEntries, *}, + render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, + BindGroupEntries, *, + }, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, @@ -55,38 +58,21 @@ impl FromWorld for SpritePipeline { let view_layout = render_device.create_bind_group_layout( "sprite_view_layout", - &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }], + &BindGroupLayoutEntries::single( + ShaderStages::VERTEX_FRAGMENT, + uniform_buffer(true, Some(ViewUniform::min_size())), + ), ); let material_layout = render_device.create_bind_group_layout( "sprite_material_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled: false, - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + texture_2d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + ), + ), ); let dummy_white_gpu_image = { let image = Image::default(); diff --git a/crates/bevy_ui/src/render/pipeline.rs b/crates/bevy_ui/src/render/pipeline.rs index 9212f758fef47..8953e99444157 100644 --- a/crates/bevy_ui/src/render/pipeline.rs +++ b/crates/bevy_ui/src/render/pipeline.rs @@ -1,6 +1,9 @@ use bevy_ecs::prelude::*; use bevy_render::{ - render_resource::*, + render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, + *, + }, renderer::RenderDevice, texture::BevyDefault, view::{ViewTarget, ViewUniform}, @@ -18,38 +21,21 @@ impl FromWorld for UiPipeline { let view_layout = render_device.create_bind_group_layout( "ui_view_layout", - &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }], + &BindGroupLayoutEntries::single( + ShaderStages::VERTEX_FRAGMENT, + uniform_buffer(true, Some(ViewUniform::min_size())), + ), ); let image_layout = render_device.create_bind_group_layout( "ui_image_layout", - &[ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled: false, - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - ], + &BindGroupLayoutEntries::sequential( + ShaderStages::FRAGMENT, + ( + texture_2d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + ), + ), ); UiPipeline { diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index b521a9fdc1b90..8bb6aa124d9fb 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -225,16 +225,10 @@ impl FromWorld for UiMaterialPipeline { let view_layout = render_device.create_bind_group_layout( "ui_view_layout", - &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }], + &BindGroupLayoutEntries::single( + ShaderStages::VERTEX_FRAGMENT, + uniform_buffer(true, Some(ViewUniform::min_size())), + ), ); UiMaterialPipeline { ui_layout, diff --git a/examples/shader/compute_shader_game_of_life.rs b/examples/shader/compute_shader_game_of_life.rs index 2f8a269e592b8..00e80c03abac8 100644 --- a/examples/shader/compute_shader_game_of_life.rs +++ b/examples/shader/compute_shader_game_of_life.rs @@ -15,6 +15,7 @@ use bevy::{ }, window::WindowPlugin, }; +use bevy_internal::render::render_resource::binding_types::texture_storage_2d; use std::borrow::Cow; const SIZE: (u32, u32) = (1280, 720); @@ -124,22 +125,13 @@ pub struct GameOfLifePipeline { impl FromWorld for GameOfLifePipeline { fn from_world(world: &mut World) -> Self { - let texture_bind_group_layout = - world - .resource::() - .create_bind_group_layout(&BindGroupLayoutDescriptor { - label: None, - entries: &[BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::COMPUTE, - ty: BindingType::StorageTexture { - access: StorageTextureAccess::ReadWrite, - format: TextureFormat::Rgba8Unorm, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }], - }); + let texture_bind_group_layout = world.resource::().create_bind_group_layout( + None, + &BindGroupLayoutEntries::single( + ShaderStages::COMPUTE, + texture_storage_2d(TextureFormat::Rgba8Unorm, StorageTextureAccess::ReadWrite), + ), + ); let shader = world .resource::() .load("shaders/game_of_life.wgsl"); From a407aac759fd1b22f0cf9e63906fa849fd79d37e Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Nov 2023 01:00:56 -0500 Subject: [PATCH 11/24] fix ci --- crates/bevy_ui/src/render/ui_material_pipeline.rs | 2 +- examples/shader/compute_shader_game_of_life.rs | 3 +-- examples/shader/post_processing.rs | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index 8bb6aa124d9fb..c8cd42e5b1dff 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -17,7 +17,7 @@ use bevy_render::{ extract_component::ExtractComponentPlugin, render_asset::RenderAssets, render_phase::*, - render_resource::*, + render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, texture::{BevyDefault, FallbackImage, Image}, view::*, diff --git a/examples/shader/compute_shader_game_of_life.rs b/examples/shader/compute_shader_game_of_life.rs index 00e80c03abac8..81afe9b662288 100644 --- a/examples/shader/compute_shader_game_of_life.rs +++ b/examples/shader/compute_shader_game_of_life.rs @@ -9,13 +9,12 @@ use bevy::{ extract_resource::{ExtractResource, ExtractResourcePlugin}, render_asset::RenderAssets, render_graph::{self, RenderGraph}, - render_resource::*, + render_resource::{binding_types::texture_storage_2d, *}, renderer::{RenderContext, RenderDevice}, Render, RenderApp, RenderSet, }, window::WindowPlugin, }; -use bevy_internal::render::render_resource::binding_types::texture_storage_2d; use std::borrow::Cow; const SIZE: (u32, u32) = (1280, 720); diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 3f65ff628fde1..144e3d9b65058 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -19,7 +19,10 @@ use bevy::{ render_graph::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, - render_resource::*, + render_resource::{ + binding_types::{sampler, texture_2d, uniform_buffer}, + *, + }, renderer::{RenderContext, RenderDevice}, texture::BevyDefault, view::ViewTarget, From 9e6cbeee1689baf642fb743f7907d3822603e704 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Nov 2023 02:19:05 -0500 Subject: [PATCH 12/24] mesh_view_bindings --- .../bevy_core_pipeline/src/tonemapping/mod.rs | 66 ++--- crates/bevy_pbr/src/environment_map/mod.rs | 10 +- .../bevy_pbr/src/prepass/prepass_bindings.rs | 63 ++--- .../bevy_pbr/src/render/mesh_view_bindings.rs | 230 +++++++++--------- .../bind_group_layout_entries.rs | 6 + 5 files changed, 170 insertions(+), 205 deletions(-) diff --git a/crates/bevy_core_pipeline/src/tonemapping/mod.rs b/crates/bevy_core_pipeline/src/tonemapping/mod.rs index d5c452ffe8c51..b9f30dfb0bd5f 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/mod.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/mod.rs @@ -7,6 +7,9 @@ use bevy_render::camera::Camera; use bevy_render::extract_component::{ExtractComponent, ExtractComponentPlugin}; use bevy_render::extract_resource::{ExtractResource, ExtractResourcePlugin}; use bevy_render::render_asset::RenderAssets; +use bevy_render::render_resource::binding_types::{ + sampler, texture_2d, texture_3d, uniform_buffer, +}; use bevy_render::renderer::RenderDevice; use bevy_render::texture::{CompressedImageFormats, Image, ImageSampler, ImageType}; use bevy_render::view::{ViewTarget, ViewUniform}; @@ -248,35 +251,20 @@ impl SpecializedRenderPipeline for TonemappingPipeline { impl FromWorld for TonemappingPipeline { fn from_world(render_world: &mut World) -> Self { - let mut entries = vec![ - BindGroupLayoutEntry { - binding: 0, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: Some(ViewUniform::min_size()), - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 1, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::NonFiltering), - count: None, - }, - ]; - entries.extend(get_lut_bind_group_layout_entries([3, 4])); + let mut entries = DynamicBindGroupLayoutEntries::new_with_indices( + ShaderStages::FRAGMENT, + ( + (0, uniform_buffer(true, Some(ViewUniform::min_size()))), + ( + 1, + texture_2d(TextureSampleType::Float { filterable: false }), + ), + (2, sampler(SamplerBindingType::NonFiltering)), + ), + ); + let lut_layout_entries = get_lut_bind_group_layout_entries(); + entries = + entries.extend_with_indices(((3, lut_layout_entries[0]), (4, lut_layout_entries[1]))); let tonemap_texture_bind_group = render_world .resource::() @@ -342,24 +330,10 @@ pub fn get_lut_bindings<'a>( (&lut_image.texture_view, &lut_image.sampler) } -pub fn get_lut_bind_group_layout_entries(bindings: [u32; 2]) -> [BindGroupLayoutEntry; 2] { +pub fn get_lut_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 2] { [ - BindGroupLayoutEntry { - binding: bindings[0], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - view_dimension: TextureViewDimension::D3, - multisampled: false, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: bindings[1], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, + texture_3d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), ] } diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index bff3599345c12..823f264a17923 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -82,12 +82,10 @@ pub fn get_bindings<'a>( (diffuse_map, specular_map, &fallback_image_cubemap.sampler) } -pub fn get_bind_group_layout_entries(bindings: [u32; 3]) -> [BindGroupLayoutEntry; 3] { +pub fn get_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 3] { [ - texture_cube(TextureSampleType::Float { filterable: true }) - .build(bindings[0], ShaderStages::FRAGMENT), - texture_cube(TextureSampleType::Float { filterable: true }) - .build(bindings[1], ShaderStages::FRAGMENT), - sampler(SamplerBindingType::Filtering).build(bindings[2], ShaderStages::FRAGMENT), + texture_cube(TextureSampleType::Float { filterable: true }), + texture_cube(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), ] } diff --git a/crates/bevy_pbr/src/prepass/prepass_bindings.rs b/crates/bevy_pbr/src/prepass/prepass_bindings.rs index b72ddd1e318cd..c01514879226c 100644 --- a/crates/bevy_pbr/src/prepass/prepass_bindings.rs +++ b/crates/bevy_pbr/src/prepass/prepass_bindings.rs @@ -1,7 +1,11 @@ use bevy_core_pipeline::prepass::ViewPrepassTextures; use bevy_render::render_resource::{ - BindGroupLayoutEntry, BindingType, ShaderStages, TextureAspect, TextureSampleType, TextureView, - TextureViewDescriptor, TextureViewDimension, + binding_types::{ + texture_2d, texture_2d_multisampled, texture_2d_u32, texture_depth_2d, + texture_depth_2d_multisampled, + }, + BindGroupLayoutEntryBuilder, TextureAspect, TextureSampleType, TextureView, + TextureViewDescriptor, }; use bevy_utils::default; use smallvec::SmallVec; @@ -9,25 +13,19 @@ use smallvec::SmallVec; use crate::MeshPipelineViewLayoutKey; pub fn get_bind_group_layout_entries( - bindings: [u32; 4], layout_key: MeshPipelineViewLayoutKey, -) -> SmallVec<[BindGroupLayoutEntry; 4]> { - let mut result = SmallVec::<[BindGroupLayoutEntry; 4]>::new(); +) -> SmallVec<[BindGroupLayoutEntryBuilder; 4]> { + let mut result = SmallVec::<[BindGroupLayoutEntryBuilder; 4]>::new(); let multisampled = layout_key.contains(MeshPipelineViewLayoutKey::MULTISAMPLED); if layout_key.contains(MeshPipelineViewLayoutKey::DEPTH_PREPASS) { result.push( // Depth texture - BindGroupLayoutEntry { - binding: bindings[0], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled, - sample_type: TextureSampleType::Depth, - view_dimension: TextureViewDimension::D2, - }, - count: None, + if multisampled { + texture_depth_2d_multisampled() + } else { + texture_depth_2d() }, ); } @@ -35,15 +33,10 @@ pub fn get_bind_group_layout_entries( if layout_key.contains(MeshPipelineViewLayoutKey::NORMAL_PREPASS) { result.push( // Normal texture - BindGroupLayoutEntry { - binding: bindings[1], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled, - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - }, - count: None, + if multisampled { + texture_2d_multisampled(TextureSampleType::Float { filterable: false }) + } else { + texture_2d(TextureSampleType::Float { filterable: false }) }, ); } @@ -51,15 +44,10 @@ pub fn get_bind_group_layout_entries( if layout_key.contains(MeshPipelineViewLayoutKey::MOTION_VECTOR_PREPASS) { result.push( // Motion Vectors texture - BindGroupLayoutEntry { - binding: bindings[2], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled, - sample_type: TextureSampleType::Float { filterable: false }, - view_dimension: TextureViewDimension::D2, - }, - count: None, + if multisampled { + texture_2d_multisampled(TextureSampleType::Float { filterable: false }) + } else { + texture_2d(TextureSampleType::Float { filterable: false }) }, ); } @@ -67,16 +55,7 @@ pub fn get_bind_group_layout_entries( if layout_key.contains(MeshPipelineViewLayoutKey::DEFERRED_PREPASS) { result.push( // Deferred texture - BindGroupLayoutEntry { - binding: bindings[3], - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled: false, - sample_type: TextureSampleType::Uint, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, + texture_2d_u32(), ); } diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 76dfe1a69460c..456695ec8a23a 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -1,4 +1,4 @@ -use std::array; +use std::{array, num::NonZeroU64}; use bevy_core_pipeline::{ core_3d::ViewTransmissionTexture, @@ -16,10 +16,13 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, render_asset::RenderAssets, render_resource::{ - binding_types::{sampler, texture_2d, uniform_buffer}, - BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindingType, BufferBindingType, - DynamicBindGroupEntries, SamplerBindingType, ShaderStages, ShaderType, TextureFormat, - TextureSampleType, TextureViewDimension, + binding_types::{ + sampler, storage_buffer, storage_buffer_read_only, texture_2d, texture_2d_array, + texture_cube_array, uniform_buffer, + }, + BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindGroupLayoutEntryBuilder, BindingType, + BufferBindingType, DynamicBindGroupEntries, DynamicBindGroupLayoutEntries, + SamplerBindingType, ShaderStages, ShaderType, TextureFormat, TextureSampleType, }, renderer::RenderDevice, texture::{BevyDefault, FallbackImageCubemap, FallbackImageMsaa, FallbackImageZero, Image}, @@ -145,137 +148,142 @@ impl From> for MeshPipelineViewLayoutKey { } } +fn buffer_layout( + buffer_binding_type: BufferBindingType, + has_dynamic_offset: bool, + min_binding_size: Option, +) -> BindGroupLayoutEntryBuilder { + match buffer_binding_type { + BufferBindingType::Uniform => uniform_buffer(has_dynamic_offset, min_binding_size), + BufferBindingType::Storage { read_only } => { + if read_only { + storage_buffer_read_only(has_dynamic_offset, min_binding_size) + } else { + storage_buffer(has_dynamic_offset, min_binding_size) + } + } + } +} + /// Returns the appropriate bind group layout vec based on the parameters fn layout_entries( clustered_forward_buffer_binding_type: BufferBindingType, layout_key: MeshPipelineViewLayoutKey, ) -> Vec { - let mut entries = vec![ - // View - uniform_buffer(true, Some(ViewUniform::min_size())).build(0, ShaderStages::VERTEX_FRAGMENT), - // Lights - uniform_buffer(true, Some(GpuLights::min_size())).build(1, ShaderStages::FRAGMENT), - // Point Shadow Texture Cube Array - BindGroupLayoutEntry { - binding: 2, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled: false, - sample_type: TextureSampleType::Depth, + let mut entries = DynamicBindGroupLayoutEntries::new_with_indices( + ShaderStages::FRAGMENT, + ( + // View + ( + 0, + uniform_buffer(true, Some(ViewUniform::min_size())) + .visibility(ShaderStages::VERTEX_FRAGMENT), + ), + // Lights + (1, uniform_buffer(true, Some(GpuLights::min_size()))), + // Point Shadow Texture Cube Array + ( + 2, #[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))] - view_dimension: TextureViewDimension::CubeArray, + texture_cube_array(TextureSampleType::Depth), #[cfg(all(feature = "webgl", target_arch = "wasm32"))] - view_dimension: TextureViewDimension::Cube, - }, - count: None, - }, - // Point Shadow Texture Array Sampler - sampler(SamplerBindingType::Comparison).build(3, ShaderStages::FRAGMENT), - // Directional Shadow Texture Array - BindGroupLayoutEntry { - binding: 4, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - multisampled: false, - sample_type: TextureSampleType::Depth, + texture_cube(TextureSampleType::Depth), + ), + // Point Shadow Texture Array Sampler + (3, sampler(SamplerBindingType::Comparison)), + // Directional Shadow Texture Array + ( + 4, #[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))] - view_dimension: TextureViewDimension::D2Array, + texture_2d_array(TextureSampleType::Depth), #[cfg(all(feature = "webgl", target_arch = "wasm32"))] - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - // Directional Shadow Texture Array Sampler - sampler(SamplerBindingType::Comparison).build(5, ShaderStages::FRAGMENT), - // PointLights - BindGroupLayoutEntry { - binding: 6, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: clustered_forward_buffer_binding_type, - has_dynamic_offset: false, - min_binding_size: Some(GpuPointLights::min_size( + texture_2d(TextureSampleType::Depth), + ), + // Directional Shadow Texture Array Sampler + (5, sampler(SamplerBindingType::Comparison)), + // PointLights + ( + 6, + buffer_layout( clustered_forward_buffer_binding_type, - )), - }, - count: None, - }, - // ClusteredLightIndexLists - BindGroupLayoutEntry { - binding: 7, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: clustered_forward_buffer_binding_type, - has_dynamic_offset: false, - min_binding_size: Some(ViewClusterBindings::min_size_cluster_light_index_lists( + false, + Some(GpuPointLights::min_size( + clustered_forward_buffer_binding_type, + )), + ), + ), + // ClusteredLightIndexLists + ( + 7, + buffer_layout( clustered_forward_buffer_binding_type, - )), - }, - count: None, - }, - // ClusterOffsetsAndCounts - BindGroupLayoutEntry { - binding: 8, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Buffer { - ty: clustered_forward_buffer_binding_type, - has_dynamic_offset: false, - min_binding_size: Some(ViewClusterBindings::min_size_cluster_offsets_and_counts( + false, + Some(ViewClusterBindings::min_size_cluster_light_index_lists( + clustered_forward_buffer_binding_type, + )), + ), + ), + // ClusterOffsetsAndCounts + ( + 8, + buffer_layout( clustered_forward_buffer_binding_type, - )), - }, - count: None, - }, - // Globals - uniform_buffer(false, Some(GlobalsUniform::min_size())) - .build(9, ShaderStages::VERTEX_FRAGMENT), - // Fog - uniform_buffer(true, Some(GpuFog::min_size())).build(10, ShaderStages::FRAGMENT), - // Screen space ambient occlusion texture - texture_2d(TextureSampleType::Float { filterable: false }) - .build(11, ShaderStages::FRAGMENT), - ]; + false, + Some(ViewClusterBindings::min_size_cluster_offsets_and_counts( + clustered_forward_buffer_binding_type, + )), + ), + ), + // Globals + (9, uniform_buffer(false, Some(GlobalsUniform::min_size()))), + // Fog + (10, uniform_buffer(true, Some(GpuFog::min_size()))), + // Screen space ambient occlusion texture + ( + 11, + texture_2d(TextureSampleType::Float { filterable: false }), + ), + ), + ); // EnvironmentMapLight - let environment_map_entries = environment_map::get_bind_group_layout_entries([12, 13, 14]); - entries.extend_from_slice(&environment_map_entries); + let environment_map_entries = environment_map::get_bind_group_layout_entries(); + entries = entries.extend_with_indices(( + (12, environment_map_entries[0]), + (13, environment_map_entries[1]), + (14, environment_map_entries[2]), + )); // Tonemapping - let tonemapping_lut_entries = get_lut_bind_group_layout_entries([15, 16]); - entries.extend_from_slice(&tonemapping_lut_entries); + let tonemapping_lut_entries = get_lut_bind_group_layout_entries(); + entries = entries.extend_with_indices(( + (15, tonemapping_lut_entries[0]), + (16, tonemapping_lut_entries[1]), + )); // Prepass if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || (cfg!(all(feature = "webgl", target_arch = "wasm32")) && !layout_key.contains(MeshPipelineViewLayoutKey::MULTISAMPLED)) { - entries.extend_from_slice(&prepass::get_bind_group_layout_entries( - [17, 18, 19, 20], - layout_key, - )); + for (entry, binding) in prepass::get_bind_group_layout_entries(layout_key) + .iter() + .zip([17, 18, 19, 20]) + { + entries = entries.extend_with_indices(((binding as u32, *entry),)); + } } // View Transmission Texture - entries.extend_from_slice(&[ - BindGroupLayoutEntry { - binding: 21, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Texture { - sample_type: TextureSampleType::Float { filterable: true }, - multisampled: false, - view_dimension: TextureViewDimension::D2, - }, - count: None, - }, - BindGroupLayoutEntry { - binding: 22, - visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler(SamplerBindingType::Filtering), - count: None, - }, - ]); - - entries + entries = entries.extend_with_indices(( + ( + 21, + texture_2d(TextureSampleType::Float { filterable: true }), + ), + (22, sampler(SamplerBindingType::Filtering)), + )); + + (&entries).to_vec() } /// Generates all possible view layouts for the mesh pipeline, based on all combinations of diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 819da3b8d601a..528234500ef4b 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -276,6 +276,12 @@ macro_rules! impl_to_indexed_binding_type_slice { } all_tuples_with_size!(impl_to_indexed_binding_type_slice, 1, 32, T, n, s); +impl IntoBindGroupLayoutEntryBuilderArray for [BindGroupLayoutEntry; N] { + fn into_array(self) -> [BindGroupLayoutEntryBuilder; N] { + self.map(|x| x.into_bind_group_layout_entry_builder()) + } +} + pub struct DynamicBindGroupLayoutEntries { default_visibility: ShaderStages, entries: Vec, From cf09ecd420d996172cb81abaa55b2d7c59c5f210 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 16:11:38 -0500 Subject: [PATCH 13/24] fix --- crates/bevy_pbr/src/render/mesh_view_bindings.rs | 2 +- .../src/render_resource/bind_group_layout_entries.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 456695ec8a23a..67ad9d9432d75 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -283,7 +283,7 @@ fn layout_entries( (22, sampler(SamplerBindingType::Filtering)), )); - (&entries).to_vec() + entries.to_vec() } /// Generates all possible view layouts for the mesh pipeline, based on all combinations of diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 528234500ef4b..03c97407659f6 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -496,7 +496,7 @@ pub mod binding_types { } #[allow(unused)] - pub fn texture_cube_mutlisampled( + pub fn texture_cube_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { BindingType::Texture { @@ -518,7 +518,7 @@ pub mod binding_types { } #[allow(unused)] - pub fn texture_cube_array_mutlisampled( + pub fn texture_cube_array_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { BindingType::Texture { @@ -540,7 +540,7 @@ pub mod binding_types { } #[allow(unused)] - pub fn texture_3d_mutlisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { + pub fn texture_3d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, view_dimension: TextureViewDimension::D3, From c11042083b6ff5e7e9801a28209a0723f6dfcecb Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 17:04:16 -0500 Subject: [PATCH 14/24] gpu array buffer --- crates/bevy_pbr/src/render/mesh_bindings.rs | 22 +++------- .../src/render_resource/gpu_array_buffer.rs | 41 +++++++------------ crates/bevy_sprite/src/mesh2d/mesh.rs | 7 ++-- 3 files changed, 23 insertions(+), 47 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index d7b989911f2de..f5e6cd900baa2 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -17,30 +17,18 @@ mod layout_entry { use crate::MeshUniform; use bevy_render::{ render_resource::{ - BindGroupLayoutEntry, BindingType, BufferBindingType, BufferSize, GpuArrayBuffer, - ShaderStages, TextureSampleType, TextureViewDimension, + binding_types::uniform_buffer, BindGroupLayoutEntry, BindingType, BufferSize, + GpuArrayBuffer, ShaderStages, TextureSampleType, TextureViewDimension, }, renderer::RenderDevice, }; fn buffer(binding: u32, size: u64, visibility: ShaderStages) -> BindGroupLayoutEntry { - BindGroupLayoutEntry { - binding, - visibility, - count: None, - ty: BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - min_binding_size: BufferSize::new(size), - }, - } + uniform_buffer(true, BufferSize::new(size)).build(binding, visibility) } pub(super) fn model(render_device: &RenderDevice, binding: u32) -> BindGroupLayoutEntry { - GpuArrayBuffer::::binding_layout( - binding, - ShaderStages::VERTEX_FRAGMENT, - render_device, - ) + GpuArrayBuffer::::binding_layout(render_device) + .build(binding, ShaderStages::VERTEX_FRAGMENT) } pub(super) fn skinning(binding: u32) -> BindGroupLayoutEntry { buffer(binding, JOINT_BUFFER_SIZE as u64, ShaderStages::VERTEX) diff --git a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs index a7147e367bec6..b159d68d60100 100644 --- a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs +++ b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs @@ -1,4 +1,7 @@ -use super::StorageBuffer; +use super::{ + binding_types::{storage_buffer, uniform_buffer}, + BindGroupLayoutEntryBuilder, StorageBuffer, +}; use crate::{ render_resource::batched_uniform_buffer::BatchedUniformBuffer, renderer::{RenderDevice, RenderQueue}, @@ -7,7 +10,7 @@ use bevy_ecs::{prelude::Component, system::Resource}; use bevy_utils::nonmax::NonMaxU32; use encase::{private::WriteInto, ShaderSize, ShaderType}; use std::{marker::PhantomData, mem}; -use wgpu::{BindGroupLayoutEntry, BindingResource, BindingType, BufferBindingType, ShaderStages}; +use wgpu::BindingResource; /// Trait for types able to go in a [`GpuArrayBuffer`]. pub trait GpuArrayBufferable: ShaderType + ShaderSize + WriteInto + Clone {} @@ -74,30 +77,16 @@ impl GpuArrayBuffer { } } - pub fn binding_layout( - binding: u32, - visibility: ShaderStages, - device: &RenderDevice, - ) -> BindGroupLayoutEntry { - BindGroupLayoutEntry { - binding, - visibility, - ty: if device.limits().max_storage_buffers_per_shader_stage == 0 { - BindingType::Buffer { - ty: BufferBindingType::Uniform, - has_dynamic_offset: true, - // BatchedUniformBuffer uses a MaxCapacityArray that is runtime-sized, so we use - // None here and let wgpu figure out the size. - min_binding_size: None, - } - } else { - BindingType::Buffer { - ty: BufferBindingType::Storage { read_only: true }, - has_dynamic_offset: false, - min_binding_size: Some(T::min_size()), - } - }, - count: None, + pub fn binding_layout(device: &RenderDevice) -> BindGroupLayoutEntryBuilder { + if device.limits().max_storage_buffers_per_shader_stage == 0 { + uniform_buffer( + true, + // BatchedUniformBuffer uses a MaxCapacityArray that is runtime-sized, so we use + // None here and let wgpu figure out the size. + None, + ) + } else { + storage_buffer(false, Some(T::min_size())) } } diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index c308bf9d4688f..36641cd174074 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -270,11 +270,10 @@ impl FromWorld for Mesh2dPipeline { let mesh_layout = render_device.create_bind_group_layout( "mesh2d_layout", - &[GpuArrayBuffer::::binding_layout( - 0, + &BindGroupLayoutEntries::single( ShaderStages::VERTEX_FRAGMENT, - render_device, - )], + GpuArrayBuffer::::binding_layout(render_device), + ), ); // A 1x1x1 'all 1.0' texture to use as a dummy texture to use in place of optional StandardMaterial textures let dummy_white_gpu_image = { From 8d4fd6623cb4106e81cfeb77183a052c1a14c238 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 21:21:09 -0500 Subject: [PATCH 15/24] fix skybox example --- crates/bevy_core_pipeline/src/skybox/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index fc9b1d48b4dd5..f8b6e4a2cb919 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -10,7 +10,7 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - binding_types::{sampler, texture_2d, uniform_buffer}, + binding_types::{sampler, texture_cube, uniform_buffer}, BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, @@ -86,7 +86,7 @@ impl SkyboxPipeline { &BindGroupLayoutEntries::sequential( ShaderStages::FRAGMENT, ( - texture_2d(TextureSampleType::Float { filterable: true }), + texture_cube(TextureSampleType::Float { filterable: true }), sampler(SamplerBindingType::Filtering), uniform_buffer(true, Some(ViewUniform::min_size())) .visibility(ShaderStages::VERTEX_FRAGMENT), From 6fcde2d94c6c6de62a498313d8943c1200101d3f Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 21:39:09 -0500 Subject: [PATCH 16/24] remove all the allow(unused) --- .../bind_group_layout_entries.rs | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 03c97407659f6..28e4a8e61f4aa 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -164,7 +164,6 @@ pub struct BindGroupLayoutEntries { impl BindGroupLayoutEntries { #[inline] - #[allow(unused)] pub fn sequential( default_visibility: ShaderStages, entries_ext: impl IntoBindGroupLayoutEntryBuilderArray, @@ -180,7 +179,6 @@ impl BindGroupLayoutEntries { } #[inline] - #[allow(unused)] pub fn with_indices( default_visibility: ShaderStages, indexed_entries: impl IntoIndexedBindGroupLayoutEntryBuilderArray, @@ -363,7 +361,6 @@ pub mod binding_types { use super::*; - #[allow(unused)] pub fn storage_buffer( has_dynamic_offset: bool, min_binding_size: Option, @@ -376,7 +373,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn storage_buffer_read_only( has_dynamic_offset: bool, min_binding_size: Option, @@ -389,7 +385,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn uniform_buffer( has_dynamic_offset: bool, min_binding_size: Option, @@ -402,7 +397,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -412,7 +406,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -422,7 +415,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -432,7 +424,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_array_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { @@ -444,48 +435,39 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_multisampled_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Float { filterable }) .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_i32() -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_multisampled_i32() -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_u32() -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_2d_multisampled_u32() -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_depth_2d() -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Depth).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_depth_2d_multisampled() -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Depth).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_cube(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -495,7 +477,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_cube_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { @@ -507,7 +488,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_cube_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -517,7 +497,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_cube_array_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { @@ -529,7 +508,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_3d(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -539,7 +517,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_3d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -549,12 +526,10 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn sampler(sampler_binding_type: SamplerBindingType) -> BindGroupLayoutEntryBuilder { BindingType::Sampler(sampler_binding_type).into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_storage_2d( format: TextureFormat, access: StorageTextureAccess, @@ -567,7 +542,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - #[allow(unused)] pub fn texture_storage_2d_array( format: TextureFormat, access: StorageTextureAccess, From ce550270b3d8471dec24fc8081cf69ed2fa070fa Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 22:04:37 -0500 Subject: [PATCH 17/24] fix wasm import --- crates/bevy_pbr/src/render/mesh_view_bindings.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 67ad9d9432d75..66d1faa987187 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -17,8 +17,8 @@ use bevy_render::{ render_asset::RenderAssets, render_resource::{ binding_types::{ - sampler, storage_buffer, storage_buffer_read_only, texture_2d, texture_2d_array, - texture_cube_array, uniform_buffer, + sampler, storage_buffer, storage_buffer_read_only, texture_2d, uniform_buffer, + uniform_buffer_sized, }, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindGroupLayoutEntryBuilder, BindingType, BufferBindingType, DynamicBindGroupEntries, DynamicBindGroupLayoutEntries, @@ -29,6 +29,11 @@ use bevy_render::{ view::{Msaa, ViewUniform, ViewUniforms}, }; +#[cfg(all(feature = "webgl", target_arch = "wasm32"))] +use bevy_render::render_resource::binding_types::texture_cube; +#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))] +use bevy_render::render_resource::binding_types::{texture_2d_array, texture_cube_array}; + use crate::{ environment_map, prepass, EnvironmentMapLight, FogMeta, GlobalLightMeta, GpuFog, GpuLights, GpuPointLights, LightMeta, MeshPipeline, MeshPipelineKey, ScreenSpaceAmbientOcclusionTextures, From 009cf1e32b6508771627a887fe3d8cb344ffdafb Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 21:52:29 -0500 Subject: [PATCH 18/24] automatic min_size --- .../src/bloom/downsampling_pipeline.rs | 2 +- .../src/bloom/upsampling_pipeline.rs | 2 +- .../src/contrast_adaptive_sharpening/mod.rs | 2 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 4 ++-- crates/bevy_core_pipeline/src/tonemapping/mod.rs | 2 +- crates/bevy_gizmos/src/lib.rs | 2 +- crates/bevy_pbr/src/deferred/mod.rs | 2 +- crates/bevy_pbr/src/prepass/mod.rs | 10 +++++----- crates/bevy_pbr/src/render/mesh_bindings.rs | 4 ++-- crates/bevy_pbr/src/render/mesh_view_bindings.rs | 13 ++++++------- crates/bevy_pbr/src/ssao/mod.rs | 4 ++-- .../render_resource/bind_group_layout_entries.rs | 7 ++++++- .../src/render_resource/gpu_array_buffer.rs | 4 ++-- crates/bevy_sprite/src/mesh2d/mesh.rs | 4 ++-- crates/bevy_sprite/src/render/mod.rs | 2 +- crates/bevy_ui/src/render/pipeline.rs | 2 +- crates/bevy_ui/src/render/ui_material_pipeline.rs | 2 +- examples/shader/post_processing.rs | 2 +- 18 files changed, 37 insertions(+), 33 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs index e68af8784b73f..736ebeaf24288 100644 --- a/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs @@ -58,7 +58,7 @@ impl FromWorld for BloomDownsamplingPipeline { // Sampler binding sampler(SamplerBindingType::Filtering), // Downsampling settings binding - uniform_buffer(true, Some(BloomUniforms::min_size())), + uniform_buffer::(true), ), ), ); diff --git a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs index 6fb6fd1bb363c..161c251e36d4d 100644 --- a/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs +++ b/crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs @@ -48,7 +48,7 @@ impl FromWorld for BloomUpsamplingPipeline { // Sampler sampler(SamplerBindingType::Filtering), // BloomUniforms - uniform_buffer(true, Some(BloomUniforms::min_size())), + uniform_buffer::(true), ), ), ); diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs index d35a0b0525743..7efa3f5028cc7 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs @@ -180,7 +180,7 @@ impl FromWorld for CASPipeline { texture_2d(TextureSampleType::Float { filterable: true }), sampler(SamplerBindingType::Filtering), // CAS Settings - uniform_buffer(true, Some(CASUniform::min_size())), + uniform_buffer::(true), ), ), ); diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index f8b6e4a2cb919..cfb7d788e0ced 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -14,7 +14,7 @@ use bevy_render::{ BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, - RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType, + RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState, TextureFormat, TextureSampleType, VertexState, }, @@ -88,7 +88,7 @@ impl SkyboxPipeline { ( texture_cube(TextureSampleType::Float { filterable: true }), sampler(SamplerBindingType::Filtering), - uniform_buffer(true, Some(ViewUniform::min_size())) + uniform_buffer::(true) .visibility(ShaderStages::VERTEX_FRAGMENT), ), ), diff --git a/crates/bevy_core_pipeline/src/tonemapping/mod.rs b/crates/bevy_core_pipeline/src/tonemapping/mod.rs index b9f30dfb0bd5f..87167fd8db585 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/mod.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/mod.rs @@ -254,7 +254,7 @@ impl FromWorld for TonemappingPipeline { let mut entries = DynamicBindGroupLayoutEntries::new_with_indices( ShaderStages::FRAGMENT, ( - (0, uniform_buffer(true, Some(ViewUniform::min_size()))), + (0, uniform_buffer::(true)), ( 1, texture_2d(TextureSampleType::Float { filterable: false }), diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 8e8a9c2d6c101..2b8a3df7d2e0a 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -123,7 +123,7 @@ impl Plugin for GizmoPlugin { "LineGizmoUniform layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX, - uniform_buffer(true, Some(LineGizmoUniform::min_size())), + uniform_buffer::(true), ), ); diff --git a/crates/bevy_pbr/src/deferred/mod.rs b/crates/bevy_pbr/src/deferred/mod.rs index 13e9d2523c0f2..5de8f327f8d72 100644 --- a/crates/bevy_pbr/src/deferred/mod.rs +++ b/crates/bevy_pbr/src/deferred/mod.rs @@ -382,7 +382,7 @@ impl FromWorld for DeferredLightingLayout { "deferred_lighting_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX_FRAGMENT, - uniform_buffer(false, Some(PbrDeferredLightingDepthId::min_size())), + uniform_buffer::(false), ), ); Self { diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 7cf1f91a616e6..67ed3b8362b13 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -236,11 +236,11 @@ impl FromWorld for PrepassPipeline { ShaderStages::VERTEX_FRAGMENT, ( // View - uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer::(true), // Globals - uniform_buffer(false, Some(GlobalsUniform::min_size())), + uniform_buffer::(false), // PreviousViewProjection - uniform_buffer(true, Some(PreviousViewProjection::min_size())), + uniform_buffer::(true), ), ), ); @@ -251,9 +251,9 @@ impl FromWorld for PrepassPipeline { ShaderStages::VERTEX_FRAGMENT, ( // View - uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer::(true), // Globals - uniform_buffer(false, Some(GlobalsUniform::min_size())), + uniform_buffer::(false), ), ), ); diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index f5e6cd900baa2..d55680a9f809e 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -17,14 +17,14 @@ mod layout_entry { use crate::MeshUniform; use bevy_render::{ render_resource::{ - binding_types::uniform_buffer, BindGroupLayoutEntry, BindingType, BufferSize, + binding_types::uniform_buffer_sized, BindGroupLayoutEntry, BindingType, BufferSize, GpuArrayBuffer, ShaderStages, TextureSampleType, TextureViewDimension, }, renderer::RenderDevice, }; fn buffer(binding: u32, size: u64, visibility: ShaderStages) -> BindGroupLayoutEntry { - uniform_buffer(true, BufferSize::new(size)).build(binding, visibility) + uniform_buffer_sized(true, BufferSize::new(size)).build(binding, visibility) } pub(super) fn model(render_device: &RenderDevice, binding: u32) -> BindGroupLayoutEntry { GpuArrayBuffer::::binding_layout(render_device) diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 66d1faa987187..b56c748b1d970 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -22,7 +22,7 @@ use bevy_render::{ }, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindGroupLayoutEntryBuilder, BindingType, BufferBindingType, DynamicBindGroupEntries, DynamicBindGroupLayoutEntries, - SamplerBindingType, ShaderStages, ShaderType, TextureFormat, TextureSampleType, + SamplerBindingType, ShaderStages, TextureFormat, TextureSampleType, }, renderer::RenderDevice, texture::{BevyDefault, FallbackImageCubemap, FallbackImageMsaa, FallbackImageZero, Image}, @@ -159,7 +159,7 @@ fn buffer_layout( min_binding_size: Option, ) -> BindGroupLayoutEntryBuilder { match buffer_binding_type { - BufferBindingType::Uniform => uniform_buffer(has_dynamic_offset, min_binding_size), + BufferBindingType::Uniform => uniform_buffer_sized(has_dynamic_offset, min_binding_size), BufferBindingType::Storage { read_only } => { if read_only { storage_buffer_read_only(has_dynamic_offset, min_binding_size) @@ -181,11 +181,10 @@ fn layout_entries( // View ( 0, - uniform_buffer(true, Some(ViewUniform::min_size())) - .visibility(ShaderStages::VERTEX_FRAGMENT), + uniform_buffer::(true).visibility(ShaderStages::VERTEX_FRAGMENT), ), // Lights - (1, uniform_buffer(true, Some(GpuLights::min_size()))), + (1, uniform_buffer::(true)), // Point Shadow Texture Cube Array ( 2, @@ -240,9 +239,9 @@ fn layout_entries( ), ), // Globals - (9, uniform_buffer(false, Some(GlobalsUniform::min_size()))), + (9, uniform_buffer::(false)), // Fog - (10, uniform_buffer(true, Some(GpuFog::min_size()))), + (10, uniform_buffer::(true)), // Screen space ambient occlusion texture ( 11, diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 2618e0a87794e..95ef562d30e1a 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -357,7 +357,7 @@ impl FromWorld for SsaoPipelines { ShaderStages::COMPUTE, ( sampler(SamplerBindingType::NonFiltering), - uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer::(true), ), ), ); @@ -387,7 +387,7 @@ impl FromWorld for SsaoPipelines { texture_2d_u32(), texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), texture_storage_2d(TextureFormat::R32Uint, StorageTextureAccess::WriteOnly), - uniform_buffer(false, Some(GlobalsUniform::min_size())), + uniform_buffer::(false), ), ), ); diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 28e4a8e61f4aa..337c3620335bd 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -356,6 +356,7 @@ pub mod binding_types { use crate::render_resource::{ BufferBindingType, SamplerBindingType, TextureSampleType, TextureViewDimension, }; + use encase::ShaderType; use std::num::NonZeroU64; use wgpu::{BindingType, StorageTextureAccess, TextureFormat}; @@ -385,7 +386,11 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn uniform_buffer( + pub fn uniform_buffer(has_dynamic_offset: bool) -> BindGroupLayoutEntryBuilder { + uniform_buffer_sized(has_dynamic_offset, Some(T::min_size())) + } + + pub fn uniform_buffer_sized( has_dynamic_offset: bool, min_binding_size: Option, ) -> BindGroupLayoutEntryBuilder { diff --git a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs index b159d68d60100..fc9187f2b3c67 100644 --- a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs +++ b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs @@ -1,5 +1,5 @@ use super::{ - binding_types::{storage_buffer, uniform_buffer}, + binding_types::{storage_buffer, uniform_buffer_sized}, BindGroupLayoutEntryBuilder, StorageBuffer, }; use crate::{ @@ -79,7 +79,7 @@ impl GpuArrayBuffer { pub fn binding_layout(device: &RenderDevice) -> BindGroupLayoutEntryBuilder { if device.limits().max_storage_buffers_per_shader_stage == 0 { - uniform_buffer( + uniform_buffer_sized( true, // BatchedUniformBuffer uses a MaxCapacityArray that is runtime-sized, so we use // None here and let wgpu figure out the size. diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 36641cd174074..1d7f8b11ba31a 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -262,8 +262,8 @@ impl FromWorld for Mesh2dPipeline { ShaderStages::VERTEX_FRAGMENT, ( // View - uniform_buffer(true, Some(ViewUniform::min_size())), - uniform_buffer(false, Some(GlobalsUniform::min_size())), + uniform_buffer::(true), + uniform_buffer::(false), ), ), ); diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 84a5e6c39ab1b..bc1b91a0e5ff4 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -60,7 +60,7 @@ impl FromWorld for SpritePipeline { "sprite_view_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX_FRAGMENT, - uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer::(true), ), ); diff --git a/crates/bevy_ui/src/render/pipeline.rs b/crates/bevy_ui/src/render/pipeline.rs index 8953e99444157..6dad2b104c3bb 100644 --- a/crates/bevy_ui/src/render/pipeline.rs +++ b/crates/bevy_ui/src/render/pipeline.rs @@ -23,7 +23,7 @@ impl FromWorld for UiPipeline { "ui_view_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX_FRAGMENT, - uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer::(true), ), ); diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index c8cd42e5b1dff..a535877485471 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -227,7 +227,7 @@ impl FromWorld for UiMaterialPipeline { "ui_view_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX_FRAGMENT, - uniform_buffer(true, Some(ViewUniform::min_size())), + uniform_buffer::(true), ), ); UiMaterialPipeline { diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 144e3d9b65058..9e10f04a81067 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -237,7 +237,7 @@ impl FromWorld for PostProcessPipeline { // The sampler that will be used to sample the screen texture sampler(SamplerBindingType::Filtering), // The settings uniform that will control the effect - uniform_buffer(false, Some(PostProcessSettings::min_size())), + uniform_buffer::(false), ), ), ); From bd540271897b4b35ee58f903eb223ff8976e6951 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 22:28:16 -0500 Subject: [PATCH 19/24] automatic min_size for storage buffers --- crates/bevy_pbr/src/render/mesh_view_bindings.rs | 8 ++++---- .../render_resource/bind_group_layout_entries.rs | 14 ++++++++++++-- .../src/render_resource/gpu_array_buffer.rs | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index b56c748b1d970..cbd0e982a460e 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -17,8 +17,8 @@ use bevy_render::{ render_asset::RenderAssets, render_resource::{ binding_types::{ - sampler, storage_buffer, storage_buffer_read_only, texture_2d, uniform_buffer, - uniform_buffer_sized, + sampler, storage_buffer_read_only_sized, storage_buffer_sized, texture_2d, + uniform_buffer, uniform_buffer_sized, }, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindGroupLayoutEntryBuilder, BindingType, BufferBindingType, DynamicBindGroupEntries, DynamicBindGroupLayoutEntries, @@ -162,9 +162,9 @@ fn buffer_layout( BufferBindingType::Uniform => uniform_buffer_sized(has_dynamic_offset, min_binding_size), BufferBindingType::Storage { read_only } => { if read_only { - storage_buffer_read_only(has_dynamic_offset, min_binding_size) + storage_buffer_read_only_sized(has_dynamic_offset, min_binding_size) } else { - storage_buffer(has_dynamic_offset, min_binding_size) + storage_buffer_sized(has_dynamic_offset, min_binding_size) } } } diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 337c3620335bd..c6e1d60ebfd19 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -362,7 +362,11 @@ pub mod binding_types { use super::*; - pub fn storage_buffer( + pub fn storage_buffer(has_dynamic_offset: bool) -> BindGroupLayoutEntryBuilder { + storage_buffer_sized(has_dynamic_offset, Some(T::min_size())) + } + + pub fn storage_buffer_sized( has_dynamic_offset: bool, min_binding_size: Option, ) -> BindGroupLayoutEntryBuilder { @@ -374,7 +378,13 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn storage_buffer_read_only( + pub fn storage_buffer_read_only( + has_dynamic_offset: bool, + ) -> BindGroupLayoutEntryBuilder { + storage_buffer_read_only_sized(has_dynamic_offset, Some(T::min_size())) + } + + pub fn storage_buffer_read_only_sized( has_dynamic_offset: bool, min_binding_size: Option, ) -> BindGroupLayoutEntryBuilder { diff --git a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs index fc9187f2b3c67..a7b1a7d77988d 100644 --- a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs +++ b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs @@ -86,7 +86,7 @@ impl GpuArrayBuffer { None, ) } else { - storage_buffer(false, Some(T::min_size())) + storage_buffer::(false) } } From 37ba67fec3dbeab77b07f3aea864c57667b18804 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 22 Nov 2023 22:47:11 -0500 Subject: [PATCH 20/24] use in mesh bindings --- crates/bevy_pbr/src/render/mesh_bindings.rs | 82 +++++++++++---------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index d55680a9f809e..f273da7bcb245 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -17,38 +17,28 @@ mod layout_entry { use crate::MeshUniform; use bevy_render::{ render_resource::{ - binding_types::uniform_buffer_sized, BindGroupLayoutEntry, BindingType, BufferSize, - GpuArrayBuffer, ShaderStages, TextureSampleType, TextureViewDimension, + binding_types::{texture_3d, uniform_buffer_sized}, + BindGroupLayoutEntryBuilder, BufferSize, GpuArrayBuffer, ShaderStages, + TextureSampleType, }, renderer::RenderDevice, }; - fn buffer(binding: u32, size: u64, visibility: ShaderStages) -> BindGroupLayoutEntry { - uniform_buffer_sized(true, BufferSize::new(size)).build(binding, visibility) - } - pub(super) fn model(render_device: &RenderDevice, binding: u32) -> BindGroupLayoutEntry { + pub(super) fn model(render_device: &RenderDevice) -> BindGroupLayoutEntryBuilder { GpuArrayBuffer::::binding_layout(render_device) - .build(binding, ShaderStages::VERTEX_FRAGMENT) + .visibility(ShaderStages::VERTEX_FRAGMENT) } - pub(super) fn skinning(binding: u32) -> BindGroupLayoutEntry { - buffer(binding, JOINT_BUFFER_SIZE as u64, ShaderStages::VERTEX) + pub(super) fn skinning() -> BindGroupLayoutEntryBuilder { + uniform_buffer_sized(true, BufferSize::new(JOINT_BUFFER_SIZE as u64)) } - pub(super) fn weights(binding: u32) -> BindGroupLayoutEntry { - buffer(binding, MORPH_BUFFER_SIZE as u64, ShaderStages::VERTEX) + pub(super) fn weights() -> BindGroupLayoutEntryBuilder { + uniform_buffer_sized(true, BufferSize::new(MORPH_BUFFER_SIZE as u64)) } - pub(super) fn targets(binding: u32) -> BindGroupLayoutEntry { - BindGroupLayoutEntry { - binding, - visibility: ShaderStages::VERTEX, - ty: BindingType::Texture { - view_dimension: TextureViewDimension::D3, - sample_type: TextureSampleType::Float { filterable: false }, - multisampled: false, - }, - count: None, - } + pub(super) fn targets() -> BindGroupLayoutEntryBuilder { + texture_3d(TextureSampleType::Float { filterable: false }) } } + /// Individual [`BindGroupEntry`] /// for bind groups. mod entry { @@ -121,37 +111,51 @@ impl MeshLayouts { // ---------- create individual BindGroupLayouts ---------- fn model_only_layout(render_device: &RenderDevice) -> BindGroupLayout { - render_device - .create_bind_group_layout("mesh_layout", &[layout_entry::model(render_device, 0)]) + render_device.create_bind_group_layout( + "mesh_layout", + &BindGroupLayoutEntries::single( + ShaderStages::empty(), + layout_entry::model(render_device), + ), + ) } fn skinned_layout(render_device: &RenderDevice) -> BindGroupLayout { render_device.create_bind_group_layout( "skinned_mesh_layout", - &[ - layout_entry::model(render_device, 0), - layout_entry::skinning(1), - ], + &BindGroupLayoutEntries::with_indices( + ShaderStages::VERTEX, + ( + (0, layout_entry::model(render_device)), + (1, layout_entry::skinning()), + ), + ), ) } fn morphed_layout(render_device: &RenderDevice) -> BindGroupLayout { render_device.create_bind_group_layout( "morphed_mesh_layout", - &[ - layout_entry::model(render_device, 0), - layout_entry::weights(2), - layout_entry::targets(3), - ], + &BindGroupLayoutEntries::with_indices( + ShaderStages::VERTEX, + ( + (0, layout_entry::model(render_device)), + (2, layout_entry::weights()), + (3, layout_entry::targets()), + ), + ), ) } fn morphed_skinned_layout(render_device: &RenderDevice) -> BindGroupLayout { render_device.create_bind_group_layout( "morphed_skinned_mesh_layout", - &[ - layout_entry::model(render_device, 0), - layout_entry::skinning(1), - layout_entry::weights(2), - layout_entry::targets(3), - ], + &BindGroupLayoutEntries::with_indices( + ShaderStages::VERTEX, + ( + (0, layout_entry::model(render_device)), + (1, layout_entry::skinning()), + (2, layout_entry::weights()), + (3, layout_entry::targets()), + ), + ), ) } From 00b59c2a383786fe643efedbadf7dbe7fd9a74b3 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 23 Nov 2023 01:39:24 -0500 Subject: [PATCH 21/24] fix gpu array buffer readonly --- crates/bevy_render/src/render_resource/gpu_array_buffer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs index a7b1a7d77988d..6c8103be04c30 100644 --- a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs +++ b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs @@ -1,5 +1,5 @@ use super::{ - binding_types::{storage_buffer, uniform_buffer_sized}, + binding_types::{storage_buffer_read_only, uniform_buffer_sized}, BindGroupLayoutEntryBuilder, StorageBuffer, }; use crate::{ @@ -86,7 +86,7 @@ impl GpuArrayBuffer { None, ) } else { - storage_buffer::(false) + storage_buffer_read_only::(false) } } From 5d3b9c7432cc1a6781cd79740018f61869464187 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 23 Nov 2023 13:11:03 -0500 Subject: [PATCH 22/24] rename to float/sint/uint --- .../src/deferred/copy_lighting_id.rs | 4 ++-- crates/bevy_pbr/src/prepass/prepass_bindings.rs | 4 ++-- crates/bevy_pbr/src/ssao/mod.rs | 6 +++--- .../src/render_resource/bind_group_layout_entries.rs | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs index 7f32cb017bb1d..ff34e8042dd5b 100644 --- a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs +++ b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs @@ -8,7 +8,7 @@ use bevy_ecs::prelude::*; use bevy_math::UVec2; use bevy_render::{ camera::ExtractedCamera, - render_resource::{binding_types::texture_2d_u32, *}, + render_resource::{binding_types::texture_2d_uint, *}, renderer::RenderDevice, texture::{CachedTexture, TextureCache}, view::ViewTarget, @@ -130,7 +130,7 @@ impl FromWorld for CopyDeferredLightingIdPipeline { let layout = render_device.create_bind_group_layout( "copy_deferred_lighting_id_bind_group_layout", - &BindGroupLayoutEntries::single(ShaderStages::FRAGMENT, texture_2d_u32()), + &BindGroupLayoutEntries::single(ShaderStages::FRAGMENT, texture_2d_uint()), ); let pipeline_id = diff --git a/crates/bevy_pbr/src/prepass/prepass_bindings.rs b/crates/bevy_pbr/src/prepass/prepass_bindings.rs index c01514879226c..3fda4eaa1c61d 100644 --- a/crates/bevy_pbr/src/prepass/prepass_bindings.rs +++ b/crates/bevy_pbr/src/prepass/prepass_bindings.rs @@ -1,7 +1,7 @@ use bevy_core_pipeline::prepass::ViewPrepassTextures; use bevy_render::render_resource::{ binding_types::{ - texture_2d, texture_2d_multisampled, texture_2d_u32, texture_depth_2d, + texture_2d, texture_2d_multisampled, texture_2d_uint, texture_depth_2d, texture_depth_2d_multisampled, }, BindGroupLayoutEntryBuilder, TextureAspect, TextureSampleType, TextureView, @@ -55,7 +55,7 @@ pub fn get_bind_group_layout_entries( if layout_key.contains(MeshPipelineViewLayoutKey::DEFERRED_PREPASS) { result.push( // Deferred texture - texture_2d_u32(), + texture_2d_uint(), ); } diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 95ef562d30e1a..610f1f6beb3ee 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -22,7 +22,7 @@ use bevy_render::{ render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ binding_types::{ - sampler, texture_2d, texture_2d_u32, texture_depth_2d, texture_storage_2d, + sampler, texture_2d, texture_2d_uint, texture_depth_2d, texture_storage_2d, uniform_buffer, }, *, @@ -384,7 +384,7 @@ impl FromWorld for SsaoPipelines { ( texture_2d(TextureSampleType::Float { filterable: false }), texture_2d(TextureSampleType::Float { filterable: false }), - texture_2d_u32(), + texture_2d_uint(), texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), texture_storage_2d(TextureFormat::R32Uint, StorageTextureAccess::WriteOnly), uniform_buffer::(false), @@ -398,7 +398,7 @@ impl FromWorld for SsaoPipelines { ShaderStages::COMPUTE, ( texture_2d(TextureSampleType::Float { filterable: false }), - texture_2d_u32(), + texture_2d_uint(), texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), ), ), diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index c6e1d60ebfd19..ab4d144c8fcc1 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -450,28 +450,28 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn texture_2d_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { + pub fn texture_2d_float(filterable: bool) -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry_builder() } - pub fn texture_2d_multisampled_f32(filterable: bool) -> BindGroupLayoutEntryBuilder { + pub fn texture_2d_multisampled_float(filterable: bool) -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Float { filterable }) .into_bind_group_layout_entry_builder() } - pub fn texture_2d_i32() -> BindGroupLayoutEntryBuilder { + pub fn texture_2d_sint() -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry_builder() } - pub fn texture_2d_multisampled_i32() -> BindGroupLayoutEntryBuilder { + pub fn texture_2d_multisampled_sint() -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry_builder() } - pub fn texture_2d_u32() -> BindGroupLayoutEntryBuilder { + pub fn texture_2d_uint() -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry_builder() } - pub fn texture_2d_multisampled_u32() -> BindGroupLayoutEntryBuilder { + pub fn texture_2d_multisampled_uint() -> BindGroupLayoutEntryBuilder { texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry_builder() } From 8248fbb35c15e6832f8707ddf250530a1a079d97 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 23 Nov 2023 13:31:00 -0500 Subject: [PATCH 23/24] more variants --- .../bind_group_layout_entries.rs | 62 +++++++++++++------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index ab4d144c8fcc1..93e98877d4511 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -421,6 +421,18 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } + pub fn texture_2d_float(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry_builder() + } + + pub fn texture_2d_sint() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry_builder() + } + + pub fn texture_2d_uint() -> BindGroupLayoutEntryBuilder { + texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry_builder() + } + pub fn texture_2d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -430,6 +442,19 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } + pub fn texture_2d_multisampled_float(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Float { filterable }) + .into_bind_group_layout_entry_builder() + } + + pub fn texture_2d_multisampled_sint() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry_builder() + } + + pub fn texture_2d_multisampled_uint() -> BindGroupLayoutEntryBuilder { + texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry_builder() + } + pub fn texture_2d_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -439,6 +464,18 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } + pub fn texture_2d_array_float(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d_array(TextureSampleType::Float { filterable }) + } + + pub fn texture_2d_array_sint() -> BindGroupLayoutEntryBuilder { + texture_2d_array(TextureSampleType::Sint) + } + + pub fn texture_2d_array_uint() -> BindGroupLayoutEntryBuilder { + texture_2d_array(TextureSampleType::Uint) + } + pub fn texture_2d_array_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { @@ -450,29 +487,16 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn texture_2d_float(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry_builder() + pub fn texture_2d_array_multisampled_float(filterable: bool) -> BindGroupLayoutEntryBuilder { + texture_2d_array_multisampled(TextureSampleType::Float { filterable }) } - pub fn texture_2d_multisampled_float(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Float { filterable }) - .into_bind_group_layout_entry_builder() + pub fn texture_2d_array_multisampled_sint() -> BindGroupLayoutEntryBuilder { + texture_2d_array_multisampled(TextureSampleType::Sint) } - pub fn texture_2d_sint() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_multisampled_sint() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_uint() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_multisampled_uint() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry_builder() + pub fn texture_2d_array_multisampled_uint() -> BindGroupLayoutEntryBuilder { + texture_2d_array_multisampled(TextureSampleType::Uint) } pub fn texture_depth_2d() -> BindGroupLayoutEntryBuilder { From c69f6f5657b5654e689afdaa1bd4e85e15d1cfa1 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 23 Nov 2023 13:33:31 -0500 Subject: [PATCH 24/24] yeet sized variants --- .../src/deferred/copy_lighting_id.rs | 7 ++- .../bevy_pbr/src/prepass/prepass_bindings.rs | 5 +- crates/bevy_pbr/src/ssao/mod.rs | 7 ++- .../bind_group_layout_entries.rs | 49 ------------------- 4 files changed, 10 insertions(+), 58 deletions(-) diff --git a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs index ff34e8042dd5b..988d529d09c44 100644 --- a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs +++ b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs @@ -8,7 +8,7 @@ use bevy_ecs::prelude::*; use bevy_math::UVec2; use bevy_render::{ camera::ExtractedCamera, - render_resource::{binding_types::texture_2d_uint, *}, + render_resource::{binding_types::texture_2d, *}, renderer::RenderDevice, texture::{CachedTexture, TextureCache}, view::ViewTarget, @@ -130,7 +130,10 @@ impl FromWorld for CopyDeferredLightingIdPipeline { let layout = render_device.create_bind_group_layout( "copy_deferred_lighting_id_bind_group_layout", - &BindGroupLayoutEntries::single(ShaderStages::FRAGMENT, texture_2d_uint()), + &BindGroupLayoutEntries::single( + ShaderStages::FRAGMENT, + texture_2d(TextureSampleType::Uint), + ), ); let pipeline_id = diff --git a/crates/bevy_pbr/src/prepass/prepass_bindings.rs b/crates/bevy_pbr/src/prepass/prepass_bindings.rs index 3fda4eaa1c61d..52ea02c1f5d20 100644 --- a/crates/bevy_pbr/src/prepass/prepass_bindings.rs +++ b/crates/bevy_pbr/src/prepass/prepass_bindings.rs @@ -1,8 +1,7 @@ use bevy_core_pipeline::prepass::ViewPrepassTextures; use bevy_render::render_resource::{ binding_types::{ - texture_2d, texture_2d_multisampled, texture_2d_uint, texture_depth_2d, - texture_depth_2d_multisampled, + texture_2d, texture_2d_multisampled, texture_depth_2d, texture_depth_2d_multisampled, }, BindGroupLayoutEntryBuilder, TextureAspect, TextureSampleType, TextureView, TextureViewDescriptor, @@ -55,7 +54,7 @@ pub fn get_bind_group_layout_entries( if layout_key.contains(MeshPipelineViewLayoutKey::DEFERRED_PREPASS) { result.push( // Deferred texture - texture_2d_uint(), + texture_2d(TextureSampleType::Uint), ); } diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 610f1f6beb3ee..14f1a05355385 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -22,8 +22,7 @@ use bevy_render::{ render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ binding_types::{ - sampler, texture_2d, texture_2d_uint, texture_depth_2d, texture_storage_2d, - uniform_buffer, + sampler, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer, }, *, }, @@ -384,7 +383,7 @@ impl FromWorld for SsaoPipelines { ( texture_2d(TextureSampleType::Float { filterable: false }), texture_2d(TextureSampleType::Float { filterable: false }), - texture_2d_uint(), + texture_2d(TextureSampleType::Uint), texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), texture_storage_2d(TextureFormat::R32Uint, StorageTextureAccess::WriteOnly), uniform_buffer::(false), @@ -398,7 +397,7 @@ impl FromWorld for SsaoPipelines { ShaderStages::COMPUTE, ( texture_2d(TextureSampleType::Float { filterable: false }), - texture_2d_uint(), + texture_2d(TextureSampleType::Uint), texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly), ), ), diff --git a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs index 93e98877d4511..ad251696571bf 100644 --- a/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_layout_entries.rs @@ -421,18 +421,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn texture_2d_float(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Float { filterable }).into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_sint() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Sint).into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_uint() -> BindGroupLayoutEntryBuilder { - texture_2d(TextureSampleType::Uint).into_bind_group_layout_entry_builder() - } - pub fn texture_2d_multisampled(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -442,19 +430,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn texture_2d_multisampled_float(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Float { filterable }) - .into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_multisampled_sint() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Sint).into_bind_group_layout_entry_builder() - } - - pub fn texture_2d_multisampled_uint() -> BindGroupLayoutEntryBuilder { - texture_2d_multisampled(TextureSampleType::Uint).into_bind_group_layout_entry_builder() - } - pub fn texture_2d_array(sample_type: TextureSampleType) -> BindGroupLayoutEntryBuilder { BindingType::Texture { sample_type, @@ -464,18 +439,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn texture_2d_array_float(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d_array(TextureSampleType::Float { filterable }) - } - - pub fn texture_2d_array_sint() -> BindGroupLayoutEntryBuilder { - texture_2d_array(TextureSampleType::Sint) - } - - pub fn texture_2d_array_uint() -> BindGroupLayoutEntryBuilder { - texture_2d_array(TextureSampleType::Uint) - } - pub fn texture_2d_array_multisampled( sample_type: TextureSampleType, ) -> BindGroupLayoutEntryBuilder { @@ -487,18 +450,6 @@ pub mod binding_types { .into_bind_group_layout_entry_builder() } - pub fn texture_2d_array_multisampled_float(filterable: bool) -> BindGroupLayoutEntryBuilder { - texture_2d_array_multisampled(TextureSampleType::Float { filterable }) - } - - pub fn texture_2d_array_multisampled_sint() -> BindGroupLayoutEntryBuilder { - texture_2d_array_multisampled(TextureSampleType::Sint) - } - - pub fn texture_2d_array_multisampled_uint() -> BindGroupLayoutEntryBuilder { - texture_2d_array_multisampled(TextureSampleType::Uint) - } - pub fn texture_depth_2d() -> BindGroupLayoutEntryBuilder { texture_2d(TextureSampleType::Depth).into_bind_group_layout_entry_builder() }