From ff63eb86fc7bbe7ee862b71a6f301555132355cf Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sun, 3 Sep 2023 18:06:45 +0100 Subject: [PATCH 01/29] BindGroupEntries --- crates/bevy_core_pipeline/src/bloom/mod.rs | 63 ++---- .../src/contrast_adaptive_sharpening/node.rs | 25 +-- crates/bevy_core_pipeline/src/fxaa/node.rs | 18 +- .../bevy_core_pipeline/src/msaa_writeback.rs | 16 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 25 +-- crates/bevy_core_pipeline/src/taa/mod.rs | 46 +--- .../bevy_core_pipeline/src/tonemapping/mod.rs | 14 +- .../src/tonemapping/node.rs | 51 ++--- .../bevy_core_pipeline/src/upscaling/node.rs | 18 +- crates/bevy_pbr/src/environment_map/mod.rs | 22 +- crates/bevy_pbr/src/prepass/mod.rs | 59 ++--- crates/bevy_pbr/src/render/mesh.rs | 101 +++------ crates/bevy_pbr/src/ssao/mod.rs | 190 ++++------------ .../src/render_resource/bind_group_entries.rs | 211 ++++++++++++++++++ crates/bevy_render/src/render_resource/mod.rs | 2 + .../src/render_resource/uniform_buffer.rs | 9 + crates/bevy_sprite/src/mesh2d/mesh.rs | 16 +- crates/bevy_sprite/src/render/mod.rs | 20 +- crates/bevy_ui/src/render/mod.rs | 20 +- crates/bevy_utils/macros/src/lib.rs | 35 +++ examples/shader/post_processing.rs | 27 +-- examples/shader/texture_binding_array.rs | 15 +- 22 files changed, 460 insertions(+), 543 deletions(-) create mode 100644 crates/bevy_render/src/render_resource/bind_group_entries.rs diff --git a/crates/bevy_core_pipeline/src/bloom/mod.rs b/crates/bevy_core_pipeline/src/bloom/mod.rs index 7ee2091031558..a7014ae8cb8be 100644 --- a/crates/bevy_core_pipeline/src/bloom/mod.rs +++ b/crates/bevy_core_pipeline/src/bloom/mod.rs @@ -20,7 +20,7 @@ use bevy_render::{ }, prelude::Color, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, - render_resource::*, + render_resource::{*, BindGroupEntries}, renderer::{RenderContext, RenderDevice}, texture::{CachedTexture, TextureCache}, view::ViewTarget, @@ -178,23 +178,12 @@ impl ViewNode for BloomNode { .create_bind_group(&BindGroupDescriptor { label: Some("bloom_downsampling_first_bind_group"), layout: &downsampling_pipeline_res.bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - // Read from main texture directly - resource: BindingResource::TextureView( - view_target.main_texture_view(), - ), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&bind_groups.sampler), - }, - BindGroupEntry { - binding: 2, - resource: uniforms.clone(), - }, - ], + entries: &BindGroupEntries::sequential(( + // Read from main texture directly + view_target.main_texture_view(), + &bind_groups.sampler, + uniforms.clone(), + )) }); let view = &bloom_texture.view(0); @@ -421,20 +410,11 @@ fn prepare_bloom_bind_groups( downsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor { label: Some("bloom_downsampling_bind_group"), layout: &downsampling_pipeline.bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(&bloom_texture.view(mip - 1)), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(sampler), - }, - BindGroupEntry { - binding: 2, - resource: uniforms.binding().unwrap(), - }, - ], + entries: &BindGroupEntries::sequential(( + &bloom_texture.view(mip - 1), + sampler, + uniforms.binding().unwrap(), + )) })); } @@ -443,20 +423,11 @@ fn prepare_bloom_bind_groups( upsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor { label: Some("bloom_upsampling_bind_group"), layout: &upsampling_pipeline.bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(&bloom_texture.view(mip)), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(sampler), - }, - BindGroupEntry { - binding: 2, - resource: uniforms.binding().unwrap(), - }, - ], + entries: &BindGroupEntries::sequential(( + &bloom_texture.view(mip), + sampler, + uniforms.binding().unwrap(), + )) })); } diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs index 0dd3f086ee27c..98b2220be6860 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs @@ -7,8 +7,8 @@ use bevy_render::{ extract_component::{ComponentUniforms, DynamicUniformIndex}, render_graph::{Node, NodeRunError, RenderGraphContext}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, BufferId, Operations, - PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId, + BindGroup, BindGroupDescriptor, BufferId, Operations, + PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId, BindGroupEntries, }, renderer::RenderContext, view::{ExtractedView, ViewTarget}, @@ -83,22 +83,11 @@ impl Node for CASNode { .create_bind_group(&BindGroupDescriptor { label: Some("cas_bind_group"), layout: &sharpening_pipeline.texture_bind_group, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(view_target.source), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler( - &sharpening_pipeline.sampler, - ), - }, - BindGroupEntry { - binding: 2, - resource: uniforms, - }, - ], + entries: &BindGroupEntries::sequential(( + view_target.source, + &sharpening_pipeline.sampler, + uniforms, + )), }); let (_, _, bind_group) = diff --git a/crates/bevy_core_pipeline/src/fxaa/node.rs b/crates/bevy_core_pipeline/src/fxaa/node.rs index 2daaf0584d981..adce9dd8770d2 100644 --- a/crates/bevy_core_pipeline/src/fxaa/node.rs +++ b/crates/bevy_core_pipeline/src/fxaa/node.rs @@ -6,9 +6,9 @@ use bevy_ecs::query::QueryItem; use bevy_render::{ render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, FilterMode, Operations, + BindGroup, BindGroupDescriptor, FilterMode, Operations, PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, - TextureViewId, + TextureViewId, BindGroupEntries, }, renderer::RenderContext, view::ViewTarget, @@ -67,16 +67,10 @@ impl ViewNode for FxaaNode { .create_bind_group(&BindGroupDescriptor { label: None, layout: &fxaa_pipeline.texture_bind_group, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(source), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&sampler), - }, - ], + entries: &BindGroupEntries::sequential(( + source, + &sampler, + )) }); let (_, bind_group) = cached_bind_group.insert((source.id(), bind_group)); diff --git a/crates/bevy_core_pipeline/src/msaa_writeback.rs b/crates/bevy_core_pipeline/src/msaa_writeback.rs index 0646d4ce67ffb..1b00e91d94a77 100644 --- a/crates/bevy_core_pipeline/src/msaa_writeback.rs +++ b/crates/bevy_core_pipeline/src/msaa_writeback.rs @@ -10,7 +10,7 @@ use bevy_render::{ render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext}, renderer::RenderContext, view::{Msaa, ViewTarget}, - Render, RenderSet, + Render, RenderSet, render_resource::BindGroupEntries, }; use bevy_render::{render_resource::*, RenderApp}; @@ -96,16 +96,10 @@ impl Node for MsaaWritebackNode { .create_bind_group(&BindGroupDescriptor { label: None, layout: &blit_pipeline.texture_bind_group, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(post_process.source), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&blit_pipeline.sampler), - }, - ], + entries: &BindGroupEntries::sequential(( + post_process.source, + &blit_pipeline.sampler, + )) }); let mut render_pass = render_context diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 86fa28aa8a530..3c5583e51b94f 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -11,13 +11,13 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingResource, BindingType, BlendState, BufferBindingType, + BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BindingType, BlendState, BufferBindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState, - TextureFormat, TextureSampleType, TextureViewDimension, VertexState, + TextureFormat, TextureSampleType, TextureViewDimension, VertexState, BindGroupEntries, }, renderer::RenderDevice, texture::{BevyDefault, Image}, @@ -224,20 +224,11 @@ fn prepare_skybox_bind_groups( let bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: Some("skybox_bind_group"), layout: &pipeline.bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(&skybox.texture_view), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&skybox.sampler), - }, - BindGroupEntry { - binding: 2, - resource: view_uniforms, - }, - ], + entries: &BindGroupEntries::sequential(( + &skybox.texture_view, + &skybox.sampler, + view_uniforms, + )) }); commands.entity(entity).insert(SkyboxBindGroup(bind_group)); diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index a674ab825bcde..3f2f955145a95 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::{ - BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingResource, BindingType, CachedRenderPipelineId, + BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, + 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, + TextureDimension, TextureFormat, TextureSampleType, TextureUsages, TextureViewDimension, BindGroupEntries, }, renderer::{RenderContext, RenderDevice}, texture::{BevyDefault, CachedTexture, TextureCache}, @@ -204,38 +204,14 @@ impl ViewNode for TAANode { .create_bind_group(&BindGroupDescriptor { label: Some("taa_bind_group"), layout: &pipelines.taa_bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(view_target.source), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::TextureView( - &taa_history_textures.read.default_view, - ), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView( - &prepass_motion_vectors_texture.default_view, - ), - }, - BindGroupEntry { - binding: 3, - resource: BindingResource::TextureView( - &prepass_depth_texture.default_view, - ), - }, - BindGroupEntry { - binding: 4, - resource: BindingResource::Sampler(&pipelines.nearest_sampler), - }, - BindGroupEntry { - binding: 5, - resource: BindingResource::Sampler(&pipelines.linear_sampler), - }, - ], + entries: &BindGroupEntries::sequential(( + view_target.source, + &taa_history_textures.read.default_view, + &prepass_motion_vectors_texture.default_view, + &prepass_depth_texture.default_view, + &pipelines.nearest_sampler, + &pipelines.linear_sampler + )), }); { diff --git a/crates/bevy_core_pipeline/src/tonemapping/mod.rs b/crates/bevy_core_pipeline/src/tonemapping/mod.rs index 5ff93f1fdc25d..ba411cd97add8 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/mod.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/mod.rs @@ -307,8 +307,7 @@ pub fn get_lut_bindings<'a>( images: &'a RenderAssets, tonemapping_luts: &'a TonemappingLuts, tonemapping: &Tonemapping, - bindings: [u32; 2], -) -> [BindGroupEntry<'a>; 2] { +) -> (&'a TextureView, &'a Sampler) { let image = match tonemapping { // AgX lut texture used when tonemapping doesn't need a texture since it's very small (32x32x32) Tonemapping::None @@ -321,16 +320,7 @@ pub fn get_lut_bindings<'a>( Tonemapping::BlenderFilmic => &tonemapping_luts.blender_filmic, }; let lut_image = images.get(image).unwrap(); - [ - BindGroupEntry { - binding: bindings[0], - resource: BindingResource::TextureView(&lut_image.texture_view), - }, - BindGroupEntry { - binding: bindings[1], - resource: BindingResource::Sampler(&lut_image.sampler), - }, - ] + (&lut_image.texture_view, &lut_image.sampler) } pub fn get_lut_bind_group_layout_entries(bindings: [u32; 2]) -> [BindGroupLayoutEntry; 2] { diff --git a/crates/bevy_core_pipeline/src/tonemapping/node.rs b/crates/bevy_core_pipeline/src/tonemapping/node.rs index e3da4aa03e417..cabe0ebd0de2a 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/node.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/node.rs @@ -7,16 +7,16 @@ use bevy_render::{ render_asset::RenderAssets, render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, BufferId, LoadOp, + BindGroup, BindGroupDescriptor, BufferId, LoadOp, Operations, PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, - SamplerDescriptor, TextureViewId, + SamplerDescriptor, TextureViewId, BindGroupEntries, }, renderer::RenderContext, texture::Image, view::{ViewTarget, ViewUniformOffset, ViewUniforms}, }; -use super::{get_lut_bindings, Tonemapping}; +use super::{Tonemapping, get_lut_bindings}; #[derive(Default)] pub struct TonemappingNode { @@ -88,36 +88,25 @@ impl ViewNode for TonemappingNode { let tonemapping_luts = world.resource::(); - let mut entries = vec![ - BindGroupEntry { - binding: 0, - resource: view_uniforms.binding().unwrap(), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::TextureView(source), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::Sampler(&sampler), - }, - ]; - - entries.extend(get_lut_bindings( + let lut_bindings = get_lut_bindings( gpu_images, tonemapping_luts, - tonemapping, - [3, 4], - )); - - let bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: None, - layout: &tonemapping_pipeline.texture_bind_group, - entries: &entries, - }); + tonemapping + ); + + let bind_group = render_context + .render_device() + .create_bind_group(&BindGroupDescriptor { + label: None, + layout: &tonemapping_pipeline.texture_bind_group, + entries: &BindGroupEntries::sequential(( + view_uniforms, + source, + &sampler, + lut_bindings.0, + lut_bindings.1, + )), + }); let (_, _, bind_group) = cached_bind_group.insert((view_uniforms_id, source.id(), bind_group)); diff --git a/crates/bevy_core_pipeline/src/upscaling/node.rs b/crates/bevy_core_pipeline/src/upscaling/node.rs index 76ff1d195c998..6068962d60a17 100644 --- a/crates/bevy_core_pipeline/src/upscaling/node.rs +++ b/crates/bevy_core_pipeline/src/upscaling/node.rs @@ -4,9 +4,9 @@ use bevy_render::{ camera::{CameraOutputMode, ExtractedCamera}, render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, LoadOp, Operations, + BindGroup, BindGroupDescriptor, LoadOp, Operations, PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, - TextureViewId, + TextureViewId, BindGroupEntries, }, renderer::RenderContext, view::ViewTarget, @@ -63,16 +63,10 @@ impl ViewNode for UpscalingNode { .create_bind_group(&BindGroupDescriptor { label: None, layout: &blit_pipeline.texture_bind_group, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(upscaled_texture), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&sampler), - }, - ], + entries: &BindGroupEntries::sequential(( + upscaled_texture, + &sampler + )), }); let (_, bind_group) = cached_bind_group.insert((upscaled_texture.id(), bind_group)); diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index 7e6e8732028eb..a2f8d8d8f72a6 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -7,8 +7,8 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroupEntry, BindGroupLayoutEntry, BindingResource, BindingType, SamplerBindingType, - Shader, ShaderStages, TextureSampleType, TextureViewDimension, + BindGroupLayoutEntry, BindingType, SamplerBindingType, + Shader, ShaderStages, TextureSampleType, TextureViewDimension, TextureView, Sampler, }, texture::{FallbackImageCubemap, Image}, }; @@ -74,8 +74,7 @@ pub fn get_bindings<'a>( environment_map_light: Option<&EnvironmentMapLight>, images: &'a RenderAssets, fallback_image_cubemap: &'a FallbackImageCubemap, - bindings: [u32; 3], -) -> [BindGroupEntry<'a>; 3] { +) -> (&'a TextureView, &'a TextureView, &'a Sampler) { let (diffuse_map, specular_map) = match ( environment_map_light.and_then(|env_map| images.get(&env_map.diffuse_map)), environment_map_light.and_then(|env_map| images.get(&env_map.specular_map)), @@ -89,20 +88,7 @@ pub fn get_bindings<'a>( ), }; - [ - BindGroupEntry { - binding: bindings[0], - resource: BindingResource::TextureView(diffuse_map), - }, - BindGroupEntry { - binding: bindings[1], - resource: BindingResource::TextureView(specular_map), - }, - BindGroupEntry { - binding: bindings[2], - resource: BindingResource::Sampler(&fallback_image_cubemap.sampler), - }, - ] + (diffuse_map, specular_map, &fallback_image_cubemap.sampler) } pub fn get_bind_group_layout_entries(bindings: [u32; 3]) -> [BindGroupLayoutEntry; 3] { diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 21ea58e57f8f6..5a18037295a99 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -27,14 +27,14 @@ use bevy_render::{ RenderPhase, SetItemPipeline, TrackedRenderPass, }, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, BlendState, BufferBindingType, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, RenderPipelineDescriptor, Shader, ShaderRef, ShaderStages, ShaderType, SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines, StencilFaceState, StencilState, TextureSampleType, - TextureViewDimension, VertexState, + TextureViewDimension, VertexState, BindGroupEntries, }, renderer::{RenderDevice, RenderQueue}, texture::{FallbackImagesDepth, FallbackImagesMsaa}, @@ -587,8 +587,7 @@ pub fn get_bindings<'a>( fallback_images: &'a mut FallbackImagesMsaa, fallback_depths: &'a mut FallbackImagesDepth, msaa: &'a Msaa, - bindings: [u32; 3], -) -> [BindGroupEntry<'a>; 3] { +) -> (BindingResource<'a>, BindingResource<'a>, BindingResource<'a>) { let depth_view = match prepass_textures.and_then(|x| x.depth.as_ref()) { Some(texture) => &texture.default_view, None => { @@ -612,20 +611,11 @@ pub fn get_bindings<'a>( None => normal_motion_vectors_fallback, }; - [ - BindGroupEntry { - binding: bindings[0], - resource: BindingResource::TextureView(depth_view), - }, - BindGroupEntry { - binding: bindings[1], - resource: BindingResource::TextureView(normal_view), - }, - BindGroupEntry { - binding: bindings[2], - resource: BindingResource::TextureView(motion_vectors_view), - }, - ] + ( + BindingResource::TextureView(depth_view), + BindingResource::TextureView(normal_view), + BindingResource::TextureView(motion_vectors_view), + ) } // Extract the render phases for the prepass @@ -705,16 +695,10 @@ pub fn prepare_prepass_view_bind_group( ) { prepass_view_bind_group.no_motion_vectors = Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ - BindGroupEntry { - binding: 0, - resource: view_binding.clone(), - }, - BindGroupEntry { - binding: 1, - resource: globals_binding.clone(), - }, - ], + entries: &BindGroupEntries::sequential(( + view_binding.clone(), + globals_binding.clone(), + )), label: Some("prepass_view_no_motion_vectors_bind_group"), layout: &prepass_pipeline.view_layout_no_motion_vectors, })); @@ -722,20 +706,11 @@ pub fn prepare_prepass_view_bind_group( if let Some(previous_view_proj_binding) = previous_view_proj_uniforms.uniforms.binding() { prepass_view_bind_group.motion_vectors = Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ - BindGroupEntry { - binding: 0, - resource: view_binding, - }, - BindGroupEntry { - binding: 1, - resource: globals_binding, - }, - BindGroupEntry { - binding: 2, - resource: previous_view_proj_binding, - }, - ], + entries: &BindGroupEntries::sequential(( + view_binding, + globals_binding, + previous_view_proj_binding, + )), label: Some("prepass_view_motion_vectors_bind_group"), layout: &prepass_pipeline.view_layout_motion_vectors, })); diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index a52c54557ed82..fa8e1df1ca059 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -11,7 +11,7 @@ use bevy_core_pipeline::{ core_3d::{AlphaMask3d, Opaque3d, Transparent3d}, prepass::ViewPrepassTextures, tonemapping::{ - get_lut_bind_group_layout_entries, get_lut_bindings, Tonemapping, TonemappingLuts, + get_lut_bind_group_layout_entries, Tonemapping, TonemappingLuts, get_lut_bindings, }, }; use bevy_ecs::{ @@ -1236,89 +1236,46 @@ pub fn prepare_mesh_view_bind_groups( &mesh_pipeline.view_layout }; - let mut entries = vec![ - BindGroupEntry { - binding: 0, - resource: view_binding.clone(), - }, - BindGroupEntry { - binding: 1, - resource: light_binding.clone(), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView( - &view_shadow_bindings.point_light_depth_texture_view, - ), - }, - BindGroupEntry { - binding: 3, - resource: BindingResource::Sampler(&shadow_samplers.point_light_sampler), - }, - BindGroupEntry { - binding: 4, - resource: BindingResource::TextureView( - &view_shadow_bindings.directional_light_depth_texture_view, - ), - }, - BindGroupEntry { - binding: 5, - resource: BindingResource::Sampler(&shadow_samplers.directional_light_sampler), - }, - BindGroupEntry { - binding: 6, - resource: point_light_binding.clone(), - }, - BindGroupEntry { - binding: 7, - resource: view_cluster_bindings.light_index_lists_binding().unwrap(), - }, - BindGroupEntry { - binding: 8, - resource: view_cluster_bindings.offsets_and_counts_binding().unwrap(), - }, - BindGroupEntry { - binding: 9, - resource: globals.clone(), - }, - BindGroupEntry { - binding: 10, - resource: fog_binding.clone(), - }, - BindGroupEntry { - binding: 11, - resource: BindingResource::TextureView( - ssao_textures - .map(|t| &t.screen_space_ambient_occlusion_texture.default_view) - .unwrap_or(&fallback_ssao), - ), - }, - ]; + let mut entries = DynamicBindGroupEntries::sequential(( + // 0 + view_binding.clone(), + light_binding.clone(), + &view_shadow_bindings.point_light_depth_texture_view, + &shadow_samplers.point_light_sampler, + &view_shadow_bindings.directional_light_depth_texture_view, + // 5 + &shadow_samplers.directional_light_sampler, + point_light_binding.clone(), + view_cluster_bindings.light_index_lists_binding().unwrap(), + view_cluster_bindings.offsets_and_counts_binding().unwrap(), + globals.clone(), + // 10 + fog_binding.clone(), + ssao_textures + .map(|t| &t.screen_space_ambient_occlusion_texture.default_view) + .unwrap_or(&fallback_ssao), + )); - let env_map = environment_map::get_bindings( + // 12 - 14 + entries = entries.extend_sequential(environment_map::get_bindings( environment_map, &images, &fallback_cubemap, - [12, 13, 14], - ); - entries.extend_from_slice(&env_map); + )); - let tonemapping_luts = - get_lut_bindings(&images, &tonemapping_luts, tonemapping, [15, 16]); - entries.extend_from_slice(&tonemapping_luts); + // 15 - 16 + entries = entries.extend_sequential(get_lut_bindings(&images, &tonemapping_luts, tonemapping)); // When using WebGL, we can't have a depth texture with multisampling - if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) - || (cfg!(all(feature = "webgl", target_arch = "wasm32")) && msaa.samples() == 1) - { - entries.extend_from_slice(&prepass::get_bindings( + if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || msaa.samples() == 1 { + // 17 - 19 + entries = entries.extend_sequential(prepass::get_bindings( prepass_textures, &mut fallback_images, &mut fallback_depths, &msaa, - [17, 18, 19], )); - } + } let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { entries: &entries, diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 30d8c07141dbd..1f4277b030dab 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -21,14 +21,14 @@ use bevy_render::{ prelude::Camera, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ - AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, + AddressMode, BindGroup, BindGroupDescriptor, BindGroupLayout, + BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BufferBindingType, CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, Extent3d, FilterMode, PipelineCache, Sampler, SamplerBindingType, SamplerDescriptor, Shader, ShaderDefVal, ShaderStages, ShaderType, SpecializedComputePipeline, SpecializedComputePipelines, StorageTextureAccess, TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, - TextureView, TextureViewDescriptor, TextureViewDimension, + TextureView, TextureViewDescriptor, TextureViewDimension, BindGroupEntries, }, renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, texture::{CachedTexture, TextureCache}, @@ -783,166 +783,62 @@ fn prepare_ssao_bind_groups( let common_bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: Some("ssao_common_bind_group"), layout: &pipelines.common_bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::Sampler(&pipelines.point_clamp_sampler), - }, - BindGroupEntry { - binding: 1, - resource: view_uniforms.clone(), - }, - ], + entries: &BindGroupEntries::sequential(( + &pipelines.point_clamp_sampler, + view_uniforms.clone(), + )), }); - let preprocess_depth_mip_view_descriptor = TextureViewDescriptor { - format: Some(TextureFormat::R16Float), - dimension: Some(TextureViewDimension::D2), - mip_level_count: Some(1), - ..default() + let create_depth_view = |mip_level| { + ssao_textures + .preprocessed_depth_texture + .texture + .create_view(&TextureViewDescriptor { + label: Some("ssao_preprocessed_depth_texture_mip_view"), + base_mip_level: mip_level, + format: Some(TextureFormat::R16Float), + dimension: Some(TextureViewDimension::D2), + mip_level_count: Some(1), + ..default() + }) }; + let preprocess_depth_bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: Some("ssao_preprocess_depth_bind_group"), layout: &pipelines.preprocess_depth_bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &prepass_textures.depth.as_ref().unwrap().default_view, - ), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::TextureView( - &ssao_textures - .preprocessed_depth_texture - .texture - .create_view(&TextureViewDescriptor { - label: Some("ssao_preprocessed_depth_texture_mip_view_0"), - base_mip_level: 0, - ..preprocess_depth_mip_view_descriptor - }), - ), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView( - &ssao_textures - .preprocessed_depth_texture - .texture - .create_view(&TextureViewDescriptor { - label: Some("ssao_preprocessed_depth_texture_mip_view_1"), - base_mip_level: 1, - ..preprocess_depth_mip_view_descriptor - }), - ), - }, - BindGroupEntry { - binding: 3, - resource: BindingResource::TextureView( - &ssao_textures - .preprocessed_depth_texture - .texture - .create_view(&TextureViewDescriptor { - label: Some("ssao_preprocessed_depth_texture_mip_view_2"), - base_mip_level: 2, - ..preprocess_depth_mip_view_descriptor - }), - ), - }, - BindGroupEntry { - binding: 4, - resource: BindingResource::TextureView( - &ssao_textures - .preprocessed_depth_texture - .texture - .create_view(&TextureViewDescriptor { - label: Some("ssao_preprocessed_depth_texture_mip_view_3"), - base_mip_level: 3, - ..preprocess_depth_mip_view_descriptor - }), - ), - }, - BindGroupEntry { - binding: 5, - resource: BindingResource::TextureView( - &ssao_textures - .preprocessed_depth_texture - .texture - .create_view(&TextureViewDescriptor { - label: Some("ssao_preprocessed_depth_texture_mip_view_4"), - base_mip_level: 4, - ..preprocess_depth_mip_view_descriptor - }), - ), - }, - ], + entries: &BindGroupEntries::sequential(( + &prepass_textures.depth.as_ref().unwrap().default_view, + &create_depth_view(0), + &create_depth_view(1), + &create_depth_view(2), + &create_depth_view(3), + &create_depth_view(4), + )), }); let gtao_bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: Some("ssao_gtao_bind_group"), layout: &pipelines.gtao_bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &ssao_textures.preprocessed_depth_texture.default_view, - ), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::TextureView( - &prepass_textures.normal.as_ref().unwrap().default_view, - ), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView(&pipelines.hilbert_index_lut), - }, - BindGroupEntry { - binding: 3, - resource: BindingResource::TextureView( - &ssao_textures.ssao_noisy_texture.default_view, - ), - }, - BindGroupEntry { - binding: 4, - resource: BindingResource::TextureView( - &ssao_textures.depth_differences_texture.default_view, - ), - }, - BindGroupEntry { - binding: 5, - resource: globals_uniforms.clone(), - }, - ], + entries: &BindGroupEntries::sequential(( + &ssao_textures.preprocessed_depth_texture.default_view, + &prepass_textures.normal.as_ref().unwrap().default_view, + &pipelines.hilbert_index_lut, + &ssao_textures.ssao_noisy_texture.default_view, + &ssao_textures.depth_differences_texture.default_view, + globals_uniforms.clone(), + )), }); let spatial_denoise_bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: Some("ssao_spatial_denoise_bind_group"), layout: &pipelines.spatial_denoise_bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &ssao_textures.ssao_noisy_texture.default_view, - ), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::TextureView( - &ssao_textures.depth_differences_texture.default_view, - ), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView( - &ssao_textures - .screen_space_ambient_occlusion_texture - .default_view, - ), - }, - ], + entries: &BindGroupEntries::sequential(( + &ssao_textures.ssao_noisy_texture.default_view, + &ssao_textures.depth_differences_texture.default_view, + &ssao_textures + .screen_space_ambient_occlusion_texture + .default_view, + )) }); commands.entity(entity).insert(SsaoBindGroups { diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs new file mode 100644 index 0000000000000..de05b62c50cc8 --- /dev/null +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -0,0 +1,211 @@ +use bevy_utils::all_tuples_with_size; +use wgpu::{BindGroupEntry, BindingResource}; + +use super::{TextureView, Sampler}; + +/// Helper for constructing bindgroups. +/// +/// Allows constructing the descriptor's entries as: +/// ``` +/// render_device.create_bind_group(&BindGroupDescriptor { +/// label: Some("my_bind_group"), +/// layout: &my_layout, +/// entries: BindGroupEntries::with_indexes(( +/// (2, &my_sampler), +/// (3, my_uniform), +/// )).as_slice(), +/// }); +/// ``` +/// +/// instead of +/// +/// ``` +/// render_device.create_bind_group(&BindGroupDescriptor { +/// label: Some("my_bind_group"), +/// layout: &my_layout, +/// entries: &[ +/// BindGroupEntry { +/// binding: 2, +/// resource: BindingResource::Sampler(&my_sampler), +/// }, +/// BindGroupEntry { +/// binding: 3, +/// resource: my_uniform, +/// }, +/// ], +/// }); +/// ``` +/// +/// or +/// +/// ``` +/// render_device.create_bind_group(&BindGroupDescriptor { +/// label: Some("my_bind_group"), +/// layout: &my_layout, +/// entries: BindGroupEntries::sequential(( +/// &my_sampler, +/// my_uniform, +/// )).as_slice(), +/// }); +/// ``` +/// +/// instead of +/// +/// ``` +/// render_device.create_bind_group(&BindGroupDescriptor { +/// label: Some("my_bind_group"), +/// layout: &my_layout, +/// entries: &[ +/// BindGroupEntry { +/// binding: 0, +/// resource: BindingResource::Sampler(&my_sampler), +/// }, +/// BindGroupEntry { +/// binding: 1, +/// resource: my_uniform, +/// }, +/// ], +/// }); +/// ``` + +pub struct BindGroupEntries<'b, const N: usize> { + entries: [BindGroupEntry<'b>; N] +} + +impl<'b, const N: usize> BindGroupEntries<'b, N> { + #[inline] + pub fn sequential(resources: impl AsBindingArray<'b, N>) -> Self { + let mut i = 0; + Self { + entries: resources.as_array().map(|resource| { + let binding = i; + i += 1; + BindGroupEntry{ binding, resource } + }) + } + } + + #[inline] + pub fn with_indexes(indexed_resources: impl AsIndexedBindingArray<'b, N>) -> Self { + Self { + entries: indexed_resources.as_array().map(|(binding, resource)| { + BindGroupEntry{ binding, resource } + }) + } + } +} + +impl<'b, const N: usize> std::ops::Deref for BindGroupEntries<'b, N> { + type Target = [BindGroupEntry<'b>]; + + fn deref(&self) -> &[BindGroupEntry<'b>] { + &self.entries + } +} + +pub trait AsBinding<'a> { + fn as_binding(self) -> BindingResource<'a>; +} + +impl<'a> AsBinding<'a> for &'a TextureView { + #[inline] + fn as_binding(self) -> BindingResource<'a> { + BindingResource::TextureView(self) + } +} + +impl<'a> AsBinding<'a> for &'a[&'a wgpu::TextureView] { + #[inline] + fn as_binding(self) -> BindingResource<'a> { + BindingResource::TextureViewArray(self) + } +} + +impl<'a> AsBinding<'a> for &'a Sampler { + #[inline] + fn as_binding(self) -> BindingResource<'a> { + BindingResource::Sampler(self) + } +} + +impl<'a> AsBinding<'a> for BindingResource<'a> { + #[inline] + fn as_binding(self) -> BindingResource<'a> { + self + } +} + +pub trait AsBindingArray<'b, const N: usize> { + fn as_array(self) -> [BindingResource<'b>; N]; +} + + + +macro_rules! impl_to_binding_slice { + ($N: expr, $(($T: ident, $I: ident)),*) => { + impl<'b, $($T: AsBinding<'b>),*> AsBindingArray<'b, $N> for ($($T,)*) { + #[inline] + fn as_array(self) -> [BindingResource<'b>; $N] { + let ($($I,)*) = self; + [$($I.as_binding(), )*] + } + } + } +} + +all_tuples_with_size!(impl_to_binding_slice, 1, 32, T, s); + +pub trait AsIndexedBindingArray<'b, const N: usize> { + fn as_array(self) -> [(u32, BindingResource<'b>); N]; +} + +macro_rules! impl_to_indexed_binding_slice { + ($N: expr, $(($T: ident, $S: ident, $I: ident)),*) => { + impl<'b, $($T: AsBinding<'b>),*> AsIndexedBindingArray<'b, $N> for ($((u32, $T),)*) { + #[inline] + fn as_array(self) -> [(u32, BindingResource<'b>); $N] { + let ($(($S, $I),)*) = self; + [$(($S, $I.as_binding())), *] + } + } + } +} + +all_tuples_with_size!(impl_to_indexed_binding_slice, 1, 32, T, n, s); + +pub struct DynamicBindGroupEntries<'b> { + entries: Vec>, +} + +impl<'b> DynamicBindGroupEntries<'b> { + pub fn sequential(entries: impl AsBindingArray<'b, N>) -> Self { + Self { + entries: entries.as_array().into_iter().enumerate().map(|(ix, resource)| BindGroupEntry { binding: ix as u32, resource }).collect() + } + } + + pub fn extend_sequential(mut self, entries: impl AsBindingArray<'b, N>) -> Self { + let start = self.entries.last().unwrap().binding + 1; + self.entries.extend(entries.as_array().into_iter().enumerate().map(|(ix, resource)| BindGroupEntry { binding: start + ix as u32, resource })); + self + } + + pub fn new_with_indexes(entries: impl AsIndexedBindingArray<'b, N>) -> Self { + Self { + entries: entries.as_array().into_iter().map(|(binding, resource)| BindGroupEntry { binding, resource }).collect() + } + } + + pub fn extend_with_indexes(mut self, entries: impl AsIndexedBindingArray<'b, N>) -> Self { + self.entries.extend(entries.as_array().into_iter().map(|(binding, resource)| BindGroupEntry { binding, resource })); + self + } +} + +impl<'b> std::ops::Deref for DynamicBindGroupEntries<'b> { + type Target = [BindGroupEntry<'b>]; + + fn deref(&self) -> &[BindGroupEntry<'b>] { + &self.entries + } +} \ No newline at end of file diff --git a/crates/bevy_render/src/render_resource/mod.rs b/crates/bevy_render/src/render_resource/mod.rs index f16f5f1269929..6de15671ee6c7 100644 --- a/crates/bevy_render/src/render_resource/mod.rs +++ b/crates/bevy_render/src/render_resource/mod.rs @@ -12,6 +12,7 @@ mod shader; mod storage_buffer; mod texture; mod uniform_buffer; +mod bind_group_entries; pub use bind_group::*; pub use bind_group_layout::*; @@ -25,6 +26,7 @@ pub use shader::*; pub use storage_buffer::*; pub use texture::*; pub use uniform_buffer::*; +pub use bind_group_entries::*; // TODO: decide where re-exports should go pub use wgpu::{ diff --git a/crates/bevy_render/src/render_resource/uniform_buffer.rs b/crates/bevy_render/src/render_resource/uniform_buffer.rs index 4c1ad61b2aeb8..c45d409ec4b59 100644 --- a/crates/bevy_render/src/render_resource/uniform_buffer.rs +++ b/crates/bevy_render/src/render_resource/uniform_buffer.rs @@ -10,6 +10,8 @@ use encase::{ }; use wgpu::{util::BufferInitDescriptor, BindingResource, BufferBinding, BufferUsages}; +use super::AsBinding; + /// Stores data to be transferred to the GPU and made accessible to shaders as a uniform buffer. /// /// Uniform buffers are available to shaders on a read-only basis. Uniform buffers are commonly used to make available to shaders @@ -268,3 +270,10 @@ impl DynamicUniformBuffer { self.scratch.set_offset(0); } } + +impl<'a, T: ShaderType + WriteInto> AsBinding<'a> for &'a DynamicUniformBuffer { + #[inline] + fn as_binding(self) -> BindingResource<'a> { + self.binding().unwrap() + } +} \ No newline at end of file diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index e614c58e8495e..5a0dacfb6cae7 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -14,7 +14,7 @@ use bevy_render::{ mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout}, render_asset::RenderAssets, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, - render_resource::*, + render_resource::{*, BindGroupEntries}, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, @@ -519,16 +519,10 @@ pub fn prepare_mesh2d_view_bind_groups( ) { for entity in &views { let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ - BindGroupEntry { - binding: 0, - resource: view_binding.clone(), - }, - BindGroupEntry { - binding: 1, - resource: globals.clone(), - }, - ], + entries: &BindGroupEntries::sequential(( + view_binding.clone(), + globals.clone(), + )), label: Some("mesh2d_view_bind_group"), layout: &mesh2d_pipeline.view_layout, }); diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index f00f63f1a69a9..bb57ed38a8542 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -22,7 +22,7 @@ use bevy_render::{ DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, }, - render_resource::*, + render_resource::{*, BindGroupEntries}, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, @@ -670,20 +670,10 @@ pub fn prepare_sprites( .entry(Handle::weak(batch_image_handle)) .or_insert_with(|| { render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &gpu_image.texture_view, - ), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler( - &gpu_image.sampler, - ), - }, - ], + entries: &BindGroupEntries::sequential(( + &gpu_image.texture_view, + &gpu_image.sampler, + )), label: Some("sprite_material_bind_group"), layout: &sprite_pipeline.material_layout, }) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 1305093c05047..c2af8f98ee0b4 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -4,7 +4,7 @@ mod render_pass; use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}; use bevy_ecs::storage::SparseSet; use bevy_hierarchy::Parent; -use bevy_render::{ExtractSchedule, Render}; +use bevy_render::{ExtractSchedule, Render, render_resource::BindGroupEntries}; use bevy_window::{PrimaryWindow, Window}; pub use pipeline::*; pub use render_pass::*; @@ -755,20 +755,10 @@ pub fn prepare_uinodes( .entry(Handle::weak(batch_image_handle)) .or_insert_with(|| { render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &gpu_image.texture_view, - ), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler( - &gpu_image.sampler, - ), - }, - ], + entries: &BindGroupEntries::sequential(( + &gpu_image.texture_view, + &gpu_image.sampler, + )), label: Some("ui_material_bind_group"), layout: &ui_pipeline.image_layout, }) diff --git a/crates/bevy_utils/macros/src/lib.rs b/crates/bevy_utils/macros/src/lib.rs index f46c869beb6a2..e76f84134a599 100644 --- a/crates/bevy_utils/macros/src/lib.rs +++ b/crates/bevy_utils/macros/src/lib.rs @@ -136,3 +136,38 @@ pub fn all_tuples(input: TokenStream) -> TokenStream { )* }) } + +#[proc_macro] +pub fn all_tuples_with_size(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as AllTuples); + let len = 1 + input.end - input.start; + let mut ident_tuples = Vec::with_capacity(len); + for i in 0..=len { + let idents = input + .idents + .iter() + .map(|ident| format_ident!("{}{}", ident, i)); + if input.idents.len() < 2 { + ident_tuples.push(quote! { + #(#idents)* + }); + } else { + ident_tuples.push(quote! { + (#(#idents),*) + }); + } + } + + let macro_ident = &input.macro_ident; + let invocations = (input.start..=input.end).map(|i| { + let ident_tuples = &ident_tuples[..i]; + quote! { + #macro_ident!(#i, #(#ident_tuples),*); + } + }); + TokenStream::from(quote! { + #( + #invocations + )* + }) +} diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 7aed8e8f85d8c..261faa16bfe48 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -21,8 +21,8 @@ use bevy::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, render_resource::{ - BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingResource, BindingType, CachedRenderPipelineId, + BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, SamplerDescriptor, ShaderStages, @@ -35,6 +35,7 @@ use bevy::{ }, utils::Duration, }; +use bevy_internal::render::render_resource::BindGroupEntries; fn main() { App::new() @@ -191,23 +192,11 @@ impl ViewNode for PostProcessNode { label: Some("post_process_bind_group"), layout: &post_process_pipeline.layout, // It's important for this to match the BindGroupLayout defined in the PostProcessPipeline - entries: &[ - BindGroupEntry { - binding: 0, - // Make sure to use the source view - resource: BindingResource::TextureView(post_process.source), - }, - BindGroupEntry { - binding: 1, - // Use the sampler created for the pipeline - resource: BindingResource::Sampler(&post_process_pipeline.sampler), - }, - BindGroupEntry { - binding: 2, - // Set the settings binding - resource: settings_binding.clone(), - }, - ], + entries: &BindGroupEntries::sequential(( + post_process.source, + &post_process_pipeline.sampler, + settings_binding.clone(), + )), }); // Begin the render pass diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 90bf00afc705b..7f7b6cfc2c42a 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -12,6 +12,7 @@ use bevy::{ RenderApp, }, }; +use bevy_internal::render::render_resource::BindGroupEntries; use std::{num::NonZeroU32, process::exit}; fn main() { @@ -126,16 +127,10 @@ impl AsBindGroup for BindlessMaterial { let bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: "bindless_material_bind_group".into(), layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: BindingResource::TextureViewArray(&textures[..]), - }, - BindGroupEntry { - binding: 1, - resource: BindingResource::Sampler(&fallback_image.sampler), - }, - ], + entries: &BindGroupEntries::sequential(( + &textures[..], + &fallback_image.sampler, + )), }); Ok(PreparedBindGroup { From da60a7706e6022dc62082489f48d87d1580106c0 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sun, 3 Sep 2023 18:08:29 +0100 Subject: [PATCH 02/29] fmt --- crates/bevy_core_pipeline/src/bloom/mod.rs | 8 +- .../src/contrast_adaptive_sharpening/node.rs | 4 +- crates/bevy_core_pipeline/src/fxaa/node.rs | 10 +-- .../bevy_core_pipeline/src/msaa_writeback.rs | 5 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 16 ++-- crates/bevy_core_pipeline/src/taa/mod.rs | 16 ++-- .../src/tonemapping/node.rs | 43 +++++---- .../bevy_core_pipeline/src/upscaling/node.rs | 10 +-- crates/bevy_pbr/src/environment_map/mod.rs | 4 +- crates/bevy_pbr/src/prepass/mod.rs | 22 +++-- crates/bevy_pbr/src/render/mesh.rs | 13 ++- crates/bevy_pbr/src/ssao/mod.rs | 18 ++-- .../src/render_resource/bind_group_entries.rs | 88 +++++++++++++------ crates/bevy_render/src/render_resource/mod.rs | 4 +- .../src/render_resource/uniform_buffer.rs | 2 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 7 +- crates/bevy_sprite/src/render/mod.rs | 2 +- crates/bevy_ui/src/render/mod.rs | 2 +- examples/shader/post_processing.rs | 12 +-- examples/shader/texture_binding_array.rs | 5 +- 20 files changed, 157 insertions(+), 134 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/mod.rs b/crates/bevy_core_pipeline/src/bloom/mod.rs index a7014ae8cb8be..02f7cb12a3c90 100644 --- a/crates/bevy_core_pipeline/src/bloom/mod.rs +++ b/crates/bevy_core_pipeline/src/bloom/mod.rs @@ -20,7 +20,7 @@ use bevy_render::{ }, prelude::Color, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, - render_resource::{*, BindGroupEntries}, + render_resource::{BindGroupEntries, *}, renderer::{RenderContext, RenderDevice}, texture::{CachedTexture, TextureCache}, view::ViewTarget, @@ -183,7 +183,7 @@ impl ViewNode for BloomNode { view_target.main_texture_view(), &bind_groups.sampler, uniforms.clone(), - )) + )), }); let view = &bloom_texture.view(0); @@ -414,7 +414,7 @@ fn prepare_bloom_bind_groups( &bloom_texture.view(mip - 1), sampler, uniforms.binding().unwrap(), - )) + )), })); } @@ -427,7 +427,7 @@ fn prepare_bloom_bind_groups( &bloom_texture.view(mip), sampler, uniforms.binding().unwrap(), - )) + )), })); } diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs index 98b2220be6860..0a932f5871e92 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs @@ -7,8 +7,8 @@ use bevy_render::{ extract_component::{ComponentUniforms, DynamicUniformIndex}, render_graph::{Node, NodeRunError, RenderGraphContext}, render_resource::{ - BindGroup, BindGroupDescriptor, BufferId, Operations, - PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId, BindGroupEntries, + BindGroup, BindGroupDescriptor, BindGroupEntries, BufferId, Operations, PipelineCache, + RenderPassColorAttachment, RenderPassDescriptor, TextureViewId, }, renderer::RenderContext, view::{ExtractedView, ViewTarget}, diff --git a/crates/bevy_core_pipeline/src/fxaa/node.rs b/crates/bevy_core_pipeline/src/fxaa/node.rs index adce9dd8770d2..709e0bbaa67d2 100644 --- a/crates/bevy_core_pipeline/src/fxaa/node.rs +++ b/crates/bevy_core_pipeline/src/fxaa/node.rs @@ -6,9 +6,8 @@ use bevy_ecs::query::QueryItem; use bevy_render::{ render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, FilterMode, Operations, - PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, - TextureViewId, BindGroupEntries, + BindGroup, BindGroupDescriptor, BindGroupEntries, FilterMode, Operations, PipelineCache, + RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, TextureViewId, }, renderer::RenderContext, view::ViewTarget, @@ -67,10 +66,7 @@ impl ViewNode for FxaaNode { .create_bind_group(&BindGroupDescriptor { label: None, layout: &fxaa_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential(( - source, - &sampler, - )) + entries: &BindGroupEntries::sequential((source, &sampler)), }); let (_, bind_group) = cached_bind_group.insert((source.id(), bind_group)); diff --git a/crates/bevy_core_pipeline/src/msaa_writeback.rs b/crates/bevy_core_pipeline/src/msaa_writeback.rs index 1b00e91d94a77..72174e1d126b3 100644 --- a/crates/bevy_core_pipeline/src/msaa_writeback.rs +++ b/crates/bevy_core_pipeline/src/msaa_writeback.rs @@ -8,9 +8,10 @@ use bevy_ecs::prelude::*; use bevy_render::{ camera::ExtractedCamera, render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext}, + render_resource::BindGroupEntries, renderer::RenderContext, view::{Msaa, ViewTarget}, - Render, RenderSet, render_resource::BindGroupEntries, + Render, RenderSet, }; use bevy_render::{render_resource::*, RenderApp}; @@ -99,7 +100,7 @@ impl Node for MsaaWritebackNode { entries: &BindGroupEntries::sequential(( post_process.source, &blit_pipeline.sampler, - )) + )), }); let mut render_pass = render_context diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 3c5583e51b94f..a3b32802a7e7d 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -11,13 +11,13 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingType, BlendState, BufferBindingType, - CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, - DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, - RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType, - SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState, - TextureFormat, TextureSampleType, TextureViewDimension, VertexState, BindGroupEntries, + BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, + BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState, + 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}, @@ -228,7 +228,7 @@ fn prepare_skybox_bind_groups( &skybox.texture_view, &skybox.sampler, view_uniforms, - )) + )), }); commands.entity(entity).insert(SkyboxBindGroup(bind_group)); diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index 3f2f955145a95..15eee3cbdd7f1 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::{ - BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, - 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, BindGroupEntries, + BindGroupDescriptor, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, + 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, }, renderer::{RenderContext, RenderDevice}, texture::{BevyDefault, CachedTexture, TextureCache}, @@ -210,7 +210,7 @@ impl ViewNode for TAANode { &prepass_motion_vectors_texture.default_view, &prepass_depth_texture.default_view, &pipelines.nearest_sampler, - &pipelines.linear_sampler + &pipelines.linear_sampler, )), }); diff --git a/crates/bevy_core_pipeline/src/tonemapping/node.rs b/crates/bevy_core_pipeline/src/tonemapping/node.rs index cabe0ebd0de2a..b26e33165c4fc 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/node.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/node.rs @@ -7,16 +7,16 @@ use bevy_render::{ render_asset::RenderAssets, render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BufferId, LoadOp, - Operations, PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, - SamplerDescriptor, TextureViewId, BindGroupEntries, + BindGroup, BindGroupDescriptor, BindGroupEntries, BufferId, LoadOp, Operations, + PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, + TextureViewId, }, renderer::RenderContext, texture::Image, view::{ViewTarget, ViewUniformOffset, ViewUniforms}, }; -use super::{Tonemapping, get_lut_bindings}; +use super::{get_lut_bindings, Tonemapping}; #[derive(Default)] pub struct TonemappingNode { @@ -88,25 +88,22 @@ impl ViewNode for TonemappingNode { let tonemapping_luts = world.resource::(); - let lut_bindings = get_lut_bindings( - gpu_images, - tonemapping_luts, - tonemapping - ); - - let bind_group = render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: None, - layout: &tonemapping_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential(( - view_uniforms, - source, - &sampler, - lut_bindings.0, - lut_bindings.1, - )), - }); + let lut_bindings = get_lut_bindings(gpu_images, tonemapping_luts, tonemapping); + + let bind_group = + render_context + .render_device() + .create_bind_group(&BindGroupDescriptor { + label: None, + layout: &tonemapping_pipeline.texture_bind_group, + entries: &BindGroupEntries::sequential(( + view_uniforms, + source, + &sampler, + lut_bindings.0, + lut_bindings.1, + )), + }); let (_, _, bind_group) = cached_bind_group.insert((view_uniforms_id, source.id(), bind_group)); diff --git a/crates/bevy_core_pipeline/src/upscaling/node.rs b/crates/bevy_core_pipeline/src/upscaling/node.rs index 6068962d60a17..009205ee5041f 100644 --- a/crates/bevy_core_pipeline/src/upscaling/node.rs +++ b/crates/bevy_core_pipeline/src/upscaling/node.rs @@ -4,9 +4,8 @@ use bevy_render::{ camera::{CameraOutputMode, ExtractedCamera}, render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, LoadOp, Operations, - PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, - TextureViewId, BindGroupEntries, + BindGroup, BindGroupDescriptor, BindGroupEntries, LoadOp, Operations, PipelineCache, + RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, TextureViewId, }, renderer::RenderContext, view::ViewTarget, @@ -63,10 +62,7 @@ impl ViewNode for UpscalingNode { .create_bind_group(&BindGroupDescriptor { label: None, layout: &blit_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential(( - upscaled_texture, - &sampler - )), + entries: &BindGroupEntries::sequential((upscaled_texture, &sampler)), }); let (_, bind_group) = cached_bind_group.insert((upscaled_texture.id(), bind_group)); diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index a2f8d8d8f72a6..ea9b792c64323 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -7,8 +7,8 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroupLayoutEntry, BindingType, SamplerBindingType, - Shader, ShaderStages, TextureSampleType, TextureViewDimension, TextureView, Sampler, + BindGroupLayoutEntry, BindingType, Sampler, SamplerBindingType, Shader, ShaderStages, + TextureSampleType, TextureView, TextureViewDimension, }, texture::{FallbackImageCubemap, Image}, }; diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 5a18037295a99..ca9d79de73b54 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -27,14 +27,14 @@ use bevy_render::{ RenderPhase, SetItemPipeline, TrackedRenderPass, }, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingResource, BindingType, BlendState, BufferBindingType, - ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, - DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, PipelineCache, - PolygonMode, PrimitiveState, PushConstantRange, RenderPipelineDescriptor, Shader, - ShaderRef, ShaderStages, ShaderType, SpecializedMeshPipeline, SpecializedMeshPipelineError, - SpecializedMeshPipelines, StencilFaceState, StencilState, TextureSampleType, - TextureViewDimension, VertexState, BindGroupEntries, + BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, + BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, BlendState, + BufferBindingType, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, + DepthStencilState, DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, + PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, RenderPipelineDescriptor, + Shader, ShaderRef, ShaderStages, ShaderType, SpecializedMeshPipeline, + SpecializedMeshPipelineError, SpecializedMeshPipelines, StencilFaceState, StencilState, + TextureSampleType, TextureViewDimension, VertexState, }, renderer::{RenderDevice, RenderQueue}, texture::{FallbackImagesDepth, FallbackImagesMsaa}, @@ -587,7 +587,11 @@ pub fn get_bindings<'a>( fallback_images: &'a mut FallbackImagesMsaa, fallback_depths: &'a mut FallbackImagesDepth, msaa: &'a Msaa, -) -> (BindingResource<'a>, BindingResource<'a>, BindingResource<'a>) { +) -> ( + BindingResource<'a>, + BindingResource<'a>, + BindingResource<'a>, +) { let depth_view = match prepass_textures.and_then(|x| x.depth.as_ref()) { Some(texture) => &texture.default_view, None => { diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index fa8e1df1ca059..33168a982d58f 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -11,7 +11,7 @@ use bevy_core_pipeline::{ core_3d::{AlphaMask3d, Opaque3d, Transparent3d}, prepass::ViewPrepassTextures, tonemapping::{ - get_lut_bind_group_layout_entries, Tonemapping, TonemappingLuts, get_lut_bindings, + get_lut_bind_group_layout_entries, get_lut_bindings, Tonemapping, TonemappingLuts, }, }; use bevy_ecs::{ @@ -1264,10 +1264,15 @@ pub fn prepare_mesh_view_bind_groups( )); // 15 - 16 - entries = entries.extend_sequential(get_lut_bindings(&images, &tonemapping_luts, tonemapping)); + entries = entries.extend_sequential(get_lut_bindings( + &images, + &tonemapping_luts, + tonemapping, + )); // When using WebGL, we can't have a depth texture with multisampling - if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || msaa.samples() == 1 { + if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || msaa.samples() == 1 + { // 17 - 19 entries = entries.extend_sequential(prepass::get_bindings( prepass_textures, @@ -1275,7 +1280,7 @@ pub fn prepare_mesh_view_bind_groups( &mut fallback_depths, &msaa, )); - } + } let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { entries: &entries, diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 1f4277b030dab..f4d36dea7b048 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -21,14 +21,14 @@ use bevy_render::{ prelude::Camera, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ - AddressMode, BindGroup, BindGroupDescriptor, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, - BufferBindingType, CachedComputePipelineId, ComputePassDescriptor, - ComputePipelineDescriptor, Extent3d, FilterMode, PipelineCache, Sampler, - SamplerBindingType, SamplerDescriptor, Shader, ShaderDefVal, ShaderStages, ShaderType, - SpecializedComputePipeline, SpecializedComputePipelines, StorageTextureAccess, - TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, - TextureView, TextureViewDescriptor, TextureViewDimension, BindGroupEntries, + AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, + BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BufferBindingType, + CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, Extent3d, + FilterMode, PipelineCache, Sampler, SamplerBindingType, SamplerDescriptor, Shader, + ShaderDefVal, ShaderStages, ShaderType, SpecializedComputePipeline, + SpecializedComputePipelines, StorageTextureAccess, TextureDescriptor, TextureDimension, + TextureFormat, TextureSampleType, TextureUsages, TextureView, TextureViewDescriptor, + TextureViewDimension, }, renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, texture::{CachedTexture, TextureCache}, @@ -838,7 +838,7 @@ fn prepare_ssao_bind_groups( &ssao_textures .screen_space_ambient_occlusion_texture .default_view, - )) + )), }); commands.entity(entity).insert(SsaoBindGroups { diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index de05b62c50cc8..0e78321b7bcd8 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -1,10 +1,10 @@ use bevy_utils::all_tuples_with_size; use wgpu::{BindGroupEntry, BindingResource}; -use super::{TextureView, Sampler}; +use super::{Sampler, TextureView}; /// Helper for constructing bindgroups. -/// +/// /// Allows constructing the descriptor's entries as: /// ``` /// render_device.create_bind_group(&BindGroupDescriptor { @@ -16,9 +16,9 @@ use super::{TextureView, Sampler}; /// )).as_slice(), /// }); /// ``` -/// +/// /// instead of -/// +/// /// ``` /// render_device.create_bind_group(&BindGroupDescriptor { /// label: Some("my_bind_group"), @@ -35,9 +35,9 @@ use super::{TextureView, Sampler}; /// ], /// }); /// ``` -/// +/// /// or -/// +/// /// ``` /// render_device.create_bind_group(&BindGroupDescriptor { /// label: Some("my_bind_group"), @@ -48,9 +48,9 @@ use super::{TextureView, Sampler}; /// )).as_slice(), /// }); /// ``` -/// -/// instead of -/// +/// +/// instead of +/// /// ``` /// render_device.create_bind_group(&BindGroupDescriptor { /// label: Some("my_bind_group"), @@ -69,28 +69,28 @@ use super::{TextureView, Sampler}; /// ``` pub struct BindGroupEntries<'b, const N: usize> { - entries: [BindGroupEntry<'b>; N] + entries: [BindGroupEntry<'b>; N], } impl<'b, const N: usize> BindGroupEntries<'b, N> { #[inline] pub fn sequential(resources: impl AsBindingArray<'b, N>) -> Self { let mut i = 0; - Self { + Self { entries: resources.as_array().map(|resource| { let binding = i; i += 1; - BindGroupEntry{ binding, resource } - }) + BindGroupEntry { binding, resource } + }), } } #[inline] pub fn with_indexes(indexed_resources: impl AsIndexedBindingArray<'b, N>) -> Self { - Self { - entries: indexed_resources.as_array().map(|(binding, resource)| { - BindGroupEntry{ binding, resource } - }) + Self { + entries: indexed_resources + .as_array() + .map(|(binding, resource)| BindGroupEntry { binding, resource }), } } } @@ -98,7 +98,7 @@ impl<'b, const N: usize> BindGroupEntries<'b, N> { impl<'b, const N: usize> std::ops::Deref for BindGroupEntries<'b, N> { type Target = [BindGroupEntry<'b>]; - fn deref(&self) -> &[BindGroupEntry<'b>] { + fn deref(&self) -> &[BindGroupEntry<'b>] { &self.entries } } @@ -114,7 +114,7 @@ impl<'a> AsBinding<'a> for &'a TextureView { } } -impl<'a> AsBinding<'a> for &'a[&'a wgpu::TextureView] { +impl<'a> AsBinding<'a> for &'a [&'a wgpu::TextureView] { #[inline] fn as_binding(self) -> BindingResource<'a> { BindingResource::TextureViewArray(self) @@ -139,8 +139,6 @@ pub trait AsBindingArray<'b, const N: usize> { fn as_array(self) -> [BindingResource<'b>; N]; } - - macro_rules! impl_to_binding_slice { ($N: expr, $(($T: ident, $I: ident)),*) => { impl<'b, $($T: AsBinding<'b>),*> AsBindingArray<'b, $N> for ($($T,)*) { @@ -180,24 +178,56 @@ pub struct DynamicBindGroupEntries<'b> { impl<'b> DynamicBindGroupEntries<'b> { pub fn sequential(entries: impl AsBindingArray<'b, N>) -> Self { Self { - entries: entries.as_array().into_iter().enumerate().map(|(ix, resource)| BindGroupEntry { binding: ix as u32, resource }).collect() + entries: entries + .as_array() + .into_iter() + .enumerate() + .map(|(ix, resource)| BindGroupEntry { + binding: ix as u32, + resource, + }) + .collect(), } } - pub fn extend_sequential(mut self, entries: impl AsBindingArray<'b, N>) -> Self { + pub fn extend_sequential( + mut self, + entries: impl AsBindingArray<'b, N>, + ) -> Self { let start = self.entries.last().unwrap().binding + 1; - self.entries.extend(entries.as_array().into_iter().enumerate().map(|(ix, resource)| BindGroupEntry { binding: start + ix as u32, resource })); + self.entries.extend( + entries + .as_array() + .into_iter() + .enumerate() + .map(|(ix, resource)| BindGroupEntry { + binding: start + ix as u32, + resource, + }), + ); self } pub fn new_with_indexes(entries: impl AsIndexedBindingArray<'b, N>) -> Self { Self { - entries: entries.as_array().into_iter().map(|(binding, resource)| BindGroupEntry { binding, resource }).collect() + entries: entries + .as_array() + .into_iter() + .map(|(binding, resource)| BindGroupEntry { binding, resource }) + .collect(), } } - pub fn extend_with_indexes(mut self, entries: impl AsIndexedBindingArray<'b, N>) -> Self { - self.entries.extend(entries.as_array().into_iter().map(|(binding, resource)| BindGroupEntry { binding, resource })); + pub fn extend_with_indexes( + mut self, + entries: impl AsIndexedBindingArray<'b, N>, + ) -> Self { + self.entries.extend( + entries + .as_array() + .into_iter() + .map(|(binding, resource)| BindGroupEntry { binding, resource }), + ); self } } @@ -205,7 +235,7 @@ impl<'b> DynamicBindGroupEntries<'b> { impl<'b> std::ops::Deref for DynamicBindGroupEntries<'b> { type Target = [BindGroupEntry<'b>]; - fn deref(&self) -> &[BindGroupEntry<'b>] { + fn deref(&self) -> &[BindGroupEntry<'b>] { &self.entries } -} \ No newline at end of file +} diff --git a/crates/bevy_render/src/render_resource/mod.rs b/crates/bevy_render/src/render_resource/mod.rs index 6de15671ee6c7..b7d245b0bdbc9 100644 --- a/crates/bevy_render/src/render_resource/mod.rs +++ b/crates/bevy_render/src/render_resource/mod.rs @@ -1,5 +1,6 @@ mod batched_uniform_buffer; mod bind_group; +mod bind_group_entries; mod bind_group_layout; mod buffer; mod buffer_vec; @@ -12,9 +13,9 @@ mod shader; mod storage_buffer; mod texture; mod uniform_buffer; -mod bind_group_entries; pub use bind_group::*; +pub use bind_group_entries::*; pub use bind_group_layout::*; pub use buffer::*; pub use buffer_vec::*; @@ -26,7 +27,6 @@ pub use shader::*; pub use storage_buffer::*; pub use texture::*; pub use uniform_buffer::*; -pub use bind_group_entries::*; // TODO: decide where re-exports should go pub use wgpu::{ diff --git a/crates/bevy_render/src/render_resource/uniform_buffer.rs b/crates/bevy_render/src/render_resource/uniform_buffer.rs index c45d409ec4b59..c9d1c76f43911 100644 --- a/crates/bevy_render/src/render_resource/uniform_buffer.rs +++ b/crates/bevy_render/src/render_resource/uniform_buffer.rs @@ -276,4 +276,4 @@ impl<'a, T: ShaderType + WriteInto> AsBinding<'a> for &'a DynamicUniformBuffer BindingResource<'a> { self.binding().unwrap() } -} \ No newline at end of file +} diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 5a0dacfb6cae7..61c3224c64e63 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -14,7 +14,7 @@ use bevy_render::{ mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout}, render_asset::RenderAssets, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, - render_resource::{*, BindGroupEntries}, + render_resource::{BindGroupEntries, *}, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, @@ -519,10 +519,7 @@ pub fn prepare_mesh2d_view_bind_groups( ) { for entity in &views { let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - entries: &BindGroupEntries::sequential(( - view_binding.clone(), - globals.clone(), - )), + entries: &BindGroupEntries::sequential((view_binding.clone(), globals.clone())), label: Some("mesh2d_view_bind_group"), layout: &mesh2d_pipeline.view_layout, }); diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index bb57ed38a8542..b9906941cc2a5 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -22,7 +22,7 @@ use bevy_render::{ DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, }, - render_resource::{*, BindGroupEntries}, + render_resource::{BindGroupEntries, *}, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index c2af8f98ee0b4..17b178ef3e046 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -4,7 +4,7 @@ mod render_pass; use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}; use bevy_ecs::storage::SparseSet; use bevy_hierarchy::Parent; -use bevy_render::{ExtractSchedule, Render, render_resource::BindGroupEntries}; +use bevy_render::{render_resource::BindGroupEntries, ExtractSchedule, Render}; use bevy_window::{PrimaryWindow, Window}; pub use pipeline::*; pub use render_pass::*; diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 261faa16bfe48..9ddf70c1bcb7a 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -21,12 +21,12 @@ use bevy::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, render_resource::{ - BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingType, CachedRenderPipelineId, - ColorTargetState, ColorWrites, FragmentState, MultisampleState, Operations, - PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, - RenderPipelineDescriptor, Sampler, SamplerBindingType, SamplerDescriptor, ShaderStages, - ShaderType, TextureFormat, TextureSampleType, TextureViewDimension, + BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, + BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, + MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, + RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, + SamplerDescriptor, ShaderStages, ShaderType, TextureFormat, TextureSampleType, + TextureViewDimension, }, renderer::{RenderContext, RenderDevice}, texture::BevyDefault, diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 7f7b6cfc2c42a..b2f0d8d5c82c4 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -127,10 +127,7 @@ impl AsBindGroup for BindlessMaterial { let bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: "bindless_material_bind_group".into(), layout, - entries: &BindGroupEntries::sequential(( - &textures[..], - &fallback_image.sampler, - )), + entries: &BindGroupEntries::sequential((&textures[..], &fallback_image.sampler)), }); Ok(PreparedBindGroup { From a9fb7791a32e3f620ce5e0887cdc581b599b62c5 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sun, 3 Sep 2023 18:11:50 +0100 Subject: [PATCH 03/29] ci --- .../src/render_resource/bind_group_entries.rs | 64 +++++++++---------- .../src/render_resource/uniform_buffer.rs | 6 +- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 0e78321b7bcd8..35579b4579b71 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -74,10 +74,10 @@ pub struct BindGroupEntries<'b, const N: usize> { impl<'b, const N: usize> BindGroupEntries<'b, N> { #[inline] - pub fn sequential(resources: impl AsBindingArray<'b, N>) -> Self { + pub fn sequential(resources: impl IntoBindingArray<'b, N>) -> Self { let mut i = 0; Self { - entries: resources.as_array().map(|resource| { + entries: resources.into_array().map(|resource| { let binding = i; i += 1; BindGroupEntry { binding, resource } @@ -86,10 +86,10 @@ impl<'b, const N: usize> BindGroupEntries<'b, N> { } #[inline] - pub fn with_indexes(indexed_resources: impl AsIndexedBindingArray<'b, N>) -> Self { + pub fn with_indexes(indexed_resources: impl IntoIndexedBindingArray<'b, N>) -> Self { Self { entries: indexed_resources - .as_array() + .into_array() .map(|(binding, resource)| BindGroupEntry { binding, resource }), } } @@ -103,49 +103,49 @@ impl<'b, const N: usize> std::ops::Deref for BindGroupEntries<'b, N> { } } -pub trait AsBinding<'a> { - fn as_binding(self) -> BindingResource<'a>; +pub trait IntoBinding<'a> { + fn into_binding(self) -> BindingResource<'a>; } -impl<'a> AsBinding<'a> for &'a TextureView { +impl<'a> IntoBinding<'a> for &'a TextureView { #[inline] - fn as_binding(self) -> BindingResource<'a> { + fn into_binding(self) -> BindingResource<'a> { BindingResource::TextureView(self) } } -impl<'a> AsBinding<'a> for &'a [&'a wgpu::TextureView] { +impl<'a> IntoBinding<'a> for &'a [&'a wgpu::TextureView] { #[inline] - fn as_binding(self) -> BindingResource<'a> { + fn into_binding(self) -> BindingResource<'a> { BindingResource::TextureViewArray(self) } } -impl<'a> AsBinding<'a> for &'a Sampler { +impl<'a> IntoBinding<'a> for &'a Sampler { #[inline] - fn as_binding(self) -> BindingResource<'a> { + fn into_binding(self) -> BindingResource<'a> { BindingResource::Sampler(self) } } -impl<'a> AsBinding<'a> for BindingResource<'a> { +impl<'a> IntoBinding<'a> for BindingResource<'a> { #[inline] - fn as_binding(self) -> BindingResource<'a> { + fn into_binding(self) -> BindingResource<'a> { self } } -pub trait AsBindingArray<'b, const N: usize> { - fn as_array(self) -> [BindingResource<'b>; N]; +pub trait IntoBindingArray<'b, const N: usize> { + fn into_array(self) -> [BindingResource<'b>; N]; } macro_rules! impl_to_binding_slice { ($N: expr, $(($T: ident, $I: ident)),*) => { - impl<'b, $($T: AsBinding<'b>),*> AsBindingArray<'b, $N> for ($($T,)*) { + impl<'b, $($T: IntoBinding<'b>),*> IntoBindingArray<'b, $N> for ($($T,)*) { #[inline] - fn as_array(self) -> [BindingResource<'b>; $N] { + fn into_array(self) -> [BindingResource<'b>; $N] { let ($($I,)*) = self; - [$($I.as_binding(), )*] + [$($I.into_binding(), )*] } } } @@ -153,17 +153,17 @@ macro_rules! impl_to_binding_slice { all_tuples_with_size!(impl_to_binding_slice, 1, 32, T, s); -pub trait AsIndexedBindingArray<'b, const N: usize> { - fn as_array(self) -> [(u32, BindingResource<'b>); N]; +pub trait IntoIndexedBindingArray<'b, const N: usize> { + fn into_array(self) -> [(u32, BindingResource<'b>); N]; } macro_rules! impl_to_indexed_binding_slice { ($N: expr, $(($T: ident, $S: ident, $I: ident)),*) => { - impl<'b, $($T: AsBinding<'b>),*> AsIndexedBindingArray<'b, $N> for ($((u32, $T),)*) { + impl<'b, $($T: IntoBinding<'b>),*> IntoIndexedBindingArray<'b, $N> for ($((u32, $T),)*) { #[inline] - fn as_array(self) -> [(u32, BindingResource<'b>); $N] { + fn into_array(self) -> [(u32, BindingResource<'b>); $N] { let ($(($S, $I),)*) = self; - [$(($S, $I.as_binding())), *] + [$(($S, $I.into_binding())), *] } } } @@ -176,10 +176,10 @@ pub struct DynamicBindGroupEntries<'b> { } impl<'b> DynamicBindGroupEntries<'b> { - pub fn sequential(entries: impl AsBindingArray<'b, N>) -> Self { + pub fn sequential(entries: impl IntoBindingArray<'b, N>) -> Self { Self { entries: entries - .as_array() + .into_array() .into_iter() .enumerate() .map(|(ix, resource)| BindGroupEntry { @@ -192,12 +192,12 @@ impl<'b> DynamicBindGroupEntries<'b> { pub fn extend_sequential( mut self, - entries: impl AsBindingArray<'b, N>, + entries: impl IntoBindingArray<'b, N>, ) -> Self { let start = self.entries.last().unwrap().binding + 1; self.entries.extend( entries - .as_array() + .into_array() .into_iter() .enumerate() .map(|(ix, resource)| BindGroupEntry { @@ -208,10 +208,10 @@ impl<'b> DynamicBindGroupEntries<'b> { self } - pub fn new_with_indexes(entries: impl AsIndexedBindingArray<'b, N>) -> Self { + pub fn new_with_indexes(entries: impl IntoIndexedBindingArray<'b, N>) -> Self { Self { entries: entries - .as_array() + .into_array() .into_iter() .map(|(binding, resource)| BindGroupEntry { binding, resource }) .collect(), @@ -220,11 +220,11 @@ impl<'b> DynamicBindGroupEntries<'b> { pub fn extend_with_indexes( mut self, - entries: impl AsIndexedBindingArray<'b, N>, + entries: impl IntoIndexedBindingArray<'b, N>, ) -> Self { self.entries.extend( entries - .as_array() + .into_array() .into_iter() .map(|(binding, resource)| BindGroupEntry { binding, resource }), ); diff --git a/crates/bevy_render/src/render_resource/uniform_buffer.rs b/crates/bevy_render/src/render_resource/uniform_buffer.rs index c9d1c76f43911..ef2f7e8c0c3eb 100644 --- a/crates/bevy_render/src/render_resource/uniform_buffer.rs +++ b/crates/bevy_render/src/render_resource/uniform_buffer.rs @@ -10,7 +10,7 @@ use encase::{ }; use wgpu::{util::BufferInitDescriptor, BindingResource, BufferBinding, BufferUsages}; -use super::AsBinding; +use super::IntoBinding; /// Stores data to be transferred to the GPU and made accessible to shaders as a uniform buffer. /// @@ -271,9 +271,9 @@ impl DynamicUniformBuffer { } } -impl<'a, T: ShaderType + WriteInto> AsBinding<'a> for &'a DynamicUniformBuffer { +impl<'a, T: ShaderType + WriteInto> IntoBinding<'a> for &'a DynamicUniformBuffer { #[inline] - fn as_binding(self) -> BindingResource<'a> { + fn into_binding(self) -> BindingResource<'a> { self.binding().unwrap() } } From 6800f244527113538fa623eebc207457fddc7880 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sun, 3 Sep 2023 23:58:23 +0100 Subject: [PATCH 04/29] tweak prepass get_bindings --- crates/bevy_pbr/src/prepass/mod.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index ca9d79de73b54..06440bde53734 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -28,13 +28,13 @@ use bevy_render::{ }, render_resource::{ BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, BlendState, + BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState, BufferBindingType, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, RenderPipelineDescriptor, Shader, ShaderRef, ShaderStages, ShaderType, SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines, StencilFaceState, StencilState, - TextureSampleType, TextureViewDimension, VertexState, + TextureSampleType, TextureView, TextureViewDimension, VertexState, }, renderer::{RenderDevice, RenderQueue}, texture::{FallbackImagesDepth, FallbackImagesMsaa}, @@ -587,11 +587,7 @@ pub fn get_bindings<'a>( fallback_images: &'a mut FallbackImagesMsaa, fallback_depths: &'a mut FallbackImagesDepth, msaa: &'a Msaa, -) -> ( - BindingResource<'a>, - BindingResource<'a>, - BindingResource<'a>, -) { +) -> (&'a TextureView, &'a TextureView, &'a TextureView) { let depth_view = match prepass_textures.and_then(|x| x.depth.as_ref()) { Some(texture) => &texture.default_view, None => { @@ -615,11 +611,7 @@ pub fn get_bindings<'a>( None => normal_motion_vectors_fallback, }; - ( - BindingResource::TextureView(depth_view), - BindingResource::TextureView(normal_view), - BindingResource::TextureView(motion_vectors_view), - ) + (depth_view, normal_view, motion_vectors_view) } // Extract the render phases for the prepass From b35c6540345451ef3982787007c1e09d9965116c Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:32:54 +0100 Subject: [PATCH 05/29] destructure BindGroupDescriptor --- crates/bevy_core_pipeline/src/bloom/mod.rs | 43 +++++++------- .../src/contrast_adaptive_sharpening/node.rs | 23 ++++---- crates/bevy_core_pipeline/src/fxaa/node.rs | 15 ++--- .../bevy_core_pipeline/src/msaa_writeback.rs | 16 ++--- crates/bevy_core_pipeline/src/skybox/mod.rs | 24 ++++---- crates/bevy_core_pipeline/src/taa/mod.rs | 41 ++++++------- .../src/tonemapping/node.rs | 30 +++++----- .../bevy_core_pipeline/src/upscaling/node.rs | 17 +++--- crates/bevy_gizmos/src/lib.rs | 12 ++-- crates/bevy_pbr/src/prepass/mod.rs | 49 +++++++--------- crates/bevy_pbr/src/render/mesh.rs | 7 +-- crates/bevy_pbr/src/render/mesh_bindings.rs | 43 +++++++------- crates/bevy_pbr/src/ssao/mod.rs | 58 +++++++++---------- .../bevy_render/macros/src/as_bind_group.rs | 13 ++--- .../src/render_resource/bind_group_entries.rs | 38 ++++++------ .../bevy_render/src/renderer/render_device.rs | 18 +++++- crates/bevy_render/src/view/window/mod.rs | 10 ++-- crates/bevy_sprite/src/mesh2d/mesh.rs | 20 +++---- crates/bevy_sprite/src/render/mod.rs | 20 +++---- crates/bevy_ui/src/render/mod.rs | 20 +++---- .../shader/compute_shader_game_of_life.rs | 10 ++-- examples/shader/post_processing.rs | 24 ++++---- examples/shader/texture_binding_array.rs | 8 +-- 23 files changed, 264 insertions(+), 295 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/mod.rs b/crates/bevy_core_pipeline/src/bloom/mod.rs index 02f7cb12a3c90..f263133f4b799 100644 --- a/crates/bevy_core_pipeline/src/bloom/mod.rs +++ b/crates/bevy_core_pipeline/src/bloom/mod.rs @@ -172,19 +172,16 @@ impl ViewNode for BloomNode { // First downsample pass { - let downsampling_first_bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: Some("bloom_downsampling_first_bind_group"), - layout: &downsampling_pipeline_res.bind_group_layout, - entries: &BindGroupEntries::sequential(( - // Read from main texture directly - view_target.main_texture_view(), - &bind_groups.sampler, - uniforms.clone(), - )), - }); + let downsampling_first_bind_group = render_context.render_device().create_bind_group( + Some("bloom_downsampling_first_bind_group"), + &downsampling_pipeline_res.bind_group_layout, + &BindGroupEntries::sequential(( + // Read from main texture directly + view_target.main_texture_view(), + &bind_groups.sampler, + uniforms.clone(), + )), + ); let view = &bloom_texture.view(0); let mut downsampling_first_pass = @@ -407,28 +404,28 @@ fn prepare_bloom_bind_groups( let mut downsampling_bind_groups = Vec::with_capacity(bind_group_count); for mip in 1..bloom_texture.mip_count { - downsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor { - label: Some("bloom_downsampling_bind_group"), - layout: &downsampling_pipeline.bind_group_layout, - entries: &BindGroupEntries::sequential(( + downsampling_bind_groups.push(render_device.create_bind_group( + Some("bloom_downsampling_bind_group"), + &downsampling_pipeline.bind_group_layout, + &BindGroupEntries::sequential(( &bloom_texture.view(mip - 1), sampler, uniforms.binding().unwrap(), )), - })); + )); } let mut upsampling_bind_groups = Vec::with_capacity(bind_group_count); for mip in (0..bloom_texture.mip_count).rev() { - upsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor { - label: Some("bloom_upsampling_bind_group"), - layout: &upsampling_pipeline.bind_group_layout, - entries: &BindGroupEntries::sequential(( + upsampling_bind_groups.push(render_device.create_bind_group( + Some("bloom_upsampling_bind_group"), + &upsampling_pipeline.bind_group_layout, + &BindGroupEntries::sequential(( &bloom_texture.view(mip), sampler, uniforms.binding().unwrap(), )), - })); + )); } commands.entity(entity).insert(BloomBindGroups { diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs index 0a932f5871e92..acbeb3c5b1981 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs @@ -7,7 +7,7 @@ use bevy_render::{ extract_component::{ComponentUniforms, DynamicUniformIndex}, render_graph::{Node, NodeRunError, RenderGraphContext}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntries, BufferId, Operations, PipelineCache, + BindGroup, BindGroupEntries, BufferId, Operations, PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId, }, renderer::RenderContext, @@ -77,18 +77,15 @@ impl Node for CASNode { bind_group } cached_bind_group => { - let bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: Some("cas_bind_group"), - layout: &sharpening_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential(( - view_target.source, - &sharpening_pipeline.sampler, - uniforms, - )), - }); + let bind_group = render_context.render_device().create_bind_group( + Some("cas_bind_group"), + &sharpening_pipeline.texture_bind_group, + &BindGroupEntries::sequential(( + view_target.source, + &sharpening_pipeline.sampler, + uniforms, + )), + ); let (_, _, bind_group) = cached_bind_group.insert((uniforms_id, source.id(), bind_group)); diff --git a/crates/bevy_core_pipeline/src/fxaa/node.rs b/crates/bevy_core_pipeline/src/fxaa/node.rs index 709e0bbaa67d2..7eaf4dce268ad 100644 --- a/crates/bevy_core_pipeline/src/fxaa/node.rs +++ b/crates/bevy_core_pipeline/src/fxaa/node.rs @@ -6,7 +6,7 @@ use bevy_ecs::query::QueryItem; use bevy_render::{ render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntries, FilterMode, Operations, PipelineCache, + BindGroup, BindGroupEntries, FilterMode, Operations, PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, TextureViewId, }, renderer::RenderContext, @@ -60,14 +60,11 @@ impl ViewNode for FxaaNode { ..default() }); - let bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: None, - layout: &fxaa_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential((source, &sampler)), - }); + let bind_group = render_context.render_device().create_bind_group( + None, + &fxaa_pipeline.texture_bind_group, + &BindGroupEntries::sequential((source, &sampler)), + ); let (_, bind_group) = cached_bind_group.insert((source.id(), bind_group)); bind_group diff --git a/crates/bevy_core_pipeline/src/msaa_writeback.rs b/crates/bevy_core_pipeline/src/msaa_writeback.rs index 72174e1d126b3..d80bc0fce7bc9 100644 --- a/crates/bevy_core_pipeline/src/msaa_writeback.rs +++ b/crates/bevy_core_pipeline/src/msaa_writeback.rs @@ -91,17 +91,11 @@ impl Node for MsaaWritebackNode { depth_stencil_attachment: None, }; - let bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: None, - layout: &blit_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential(( - post_process.source, - &blit_pipeline.sampler, - )), - }); + let bind_group = render_context.render_device().create_bind_group( + None, + &blit_pipeline.texture_bind_group, + &BindGroupEntries::sequential((post_process.source, &blit_pipeline.sampler)), + ); let mut render_pass = render_context .command_encoder() diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index a3b32802a7e7d..cf5c027346395 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -11,13 +11,13 @@ use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState, - 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, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BindingType, BlendState, 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}, @@ -221,15 +221,15 @@ fn prepare_skybox_bind_groups( if let (Some(skybox), Some(view_uniforms)) = (images.get(&skybox.0), view_uniforms.uniforms.binding()) { - let bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Some("skybox_bind_group"), - layout: &pipeline.bind_group_layout, - entries: &BindGroupEntries::sequential(( + let bind_group = render_device.create_bind_group( + Some("skybox_bind_group"), + &pipeline.bind_group_layout, + &BindGroupEntries::sequential(( &skybox.texture_view, &skybox.sampler, view_uniforms, )), - }); + ); commands.entity(entity).insert(SkyboxBindGroup(bind_group)); } diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index 15eee3cbdd7f1..96bf23a2362e8 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::{ - BindGroupDescriptor, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, - 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, + BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, 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, }, renderer::{RenderContext, RenderDevice}, texture::{BevyDefault, CachedTexture, TextureCache}, @@ -198,21 +198,18 @@ impl ViewNode for TAANode { }; let view_target = view_target.post_process_write(); - let taa_bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: Some("taa_bind_group"), - layout: &pipelines.taa_bind_group_layout, - entries: &BindGroupEntries::sequential(( - view_target.source, - &taa_history_textures.read.default_view, - &prepass_motion_vectors_texture.default_view, - &prepass_depth_texture.default_view, - &pipelines.nearest_sampler, - &pipelines.linear_sampler, - )), - }); + let taa_bind_group = render_context.render_device().create_bind_group( + Some("taa_bind_group"), + &pipelines.taa_bind_group_layout, + &BindGroupEntries::sequential(( + view_target.source, + &taa_history_textures.read.default_view, + &prepass_motion_vectors_texture.default_view, + &prepass_depth_texture.default_view, + &pipelines.nearest_sampler, + &pipelines.linear_sampler, + )), + ); { let mut taa_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor { diff --git a/crates/bevy_core_pipeline/src/tonemapping/node.rs b/crates/bevy_core_pipeline/src/tonemapping/node.rs index b26e33165c4fc..1d1c95d970850 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/node.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/node.rs @@ -7,9 +7,8 @@ use bevy_render::{ render_asset::RenderAssets, render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntries, BufferId, LoadOp, Operations, - PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, - TextureViewId, + BindGroup, BindGroupEntries, BufferId, LoadOp, Operations, PipelineCache, + RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, TextureViewId, }, renderer::RenderContext, texture::Image, @@ -90,20 +89,17 @@ impl ViewNode for TonemappingNode { let lut_bindings = get_lut_bindings(gpu_images, tonemapping_luts, tonemapping); - let bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: None, - layout: &tonemapping_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential(( - view_uniforms, - source, - &sampler, - lut_bindings.0, - lut_bindings.1, - )), - }); + let bind_group = render_context.render_device().create_bind_group( + None, + &tonemapping_pipeline.texture_bind_group, + &BindGroupEntries::sequential(( + view_uniforms, + source, + &sampler, + lut_bindings.0, + lut_bindings.1, + )), + ); let (_, _, bind_group) = cached_bind_group.insert((view_uniforms_id, source.id(), bind_group)); diff --git a/crates/bevy_core_pipeline/src/upscaling/node.rs b/crates/bevy_core_pipeline/src/upscaling/node.rs index 009205ee5041f..536b2b9437515 100644 --- a/crates/bevy_core_pipeline/src/upscaling/node.rs +++ b/crates/bevy_core_pipeline/src/upscaling/node.rs @@ -4,8 +4,8 @@ use bevy_render::{ camera::{CameraOutputMode, ExtractedCamera}, render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntries, LoadOp, Operations, PipelineCache, - RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, TextureViewId, + BindGroup, BindGroupEntries, LoadOp, Operations, PipelineCache, RenderPassColorAttachment, + RenderPassDescriptor, SamplerDescriptor, TextureViewId, }, renderer::RenderContext, view::ViewTarget, @@ -56,14 +56,11 @@ impl ViewNode for UpscalingNode { .render_device() .create_sampler(&SamplerDescriptor::default()); - let bind_group = - render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: None, - layout: &blit_pipeline.texture_bind_group, - entries: &BindGroupEntries::sequential((upscaled_texture, &sampler)), - }); + let bind_group = render_context.render_device().create_bind_group( + None, + &blit_pipeline.texture_bind_group, + &BindGroupEntries::sequential((upscaled_texture, &sampler)), + ); let (_, bind_group) = cached_bind_group.insert((upscaled_texture.id(), bind_group)); bind_group diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 631cb058fa4ac..1d6a49a025e23 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -41,7 +41,7 @@ use bevy_render::{ render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroup, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, Buffer, BufferBindingType, BufferInitDescriptor, BufferUsages, Shader, ShaderStages, ShaderType, VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode, @@ -424,14 +424,14 @@ fn prepare_line_gizmo_bind_group( ) { if let Some(binding) = line_gizmo_uniforms.uniforms().binding() { commands.insert_resource(LineGizmoUniformBindgroup { - bindgroup: render_device.create_bind_group(&BindGroupDescriptor { - entries: &[BindGroupEntry { + bindgroup: render_device.create_bind_group( + Some("LineGizmoUniform bindgroup"), + &line_gizmo_uniform_layout.layout, + &[BindGroupEntry { binding: 0, resource: binding, }], - label: Some("LineGizmoUniform bindgroup"), - layout: &line_gizmo_uniform_layout.layout, - }), + ), }); } } diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 06440bde53734..bee7a7e500f84 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -27,14 +27,14 @@ use bevy_render::{ RenderPhase, SetItemPipeline, TrackedRenderPass, }, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState, - BufferBindingType, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, - DepthStencilState, DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, - PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, RenderPipelineDescriptor, - Shader, ShaderRef, ShaderStages, ShaderType, SpecializedMeshPipeline, - SpecializedMeshPipelineError, SpecializedMeshPipelines, StencilFaceState, StencilState, - TextureSampleType, TextureView, TextureViewDimension, VertexState, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BindingType, BlendState, BufferBindingType, ColorTargetState, + ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, DynamicUniformBuffer, + FragmentState, FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, + PushConstantRange, RenderPipelineDescriptor, Shader, ShaderRef, ShaderStages, ShaderType, + SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines, + StencilFaceState, StencilState, TextureSampleType, TextureView, TextureViewDimension, + VertexState, }, renderer::{RenderDevice, RenderQueue}, texture::{FallbackImagesDepth, FallbackImagesMsaa}, @@ -689,27 +689,22 @@ pub fn prepare_prepass_view_bind_group( view_uniforms.uniforms.binding(), globals_buffer.buffer.binding(), ) { - prepass_view_bind_group.no_motion_vectors = - Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &BindGroupEntries::sequential(( - view_binding.clone(), - globals_binding.clone(), - )), - label: Some("prepass_view_no_motion_vectors_bind_group"), - layout: &prepass_pipeline.view_layout_no_motion_vectors, - })); + prepass_view_bind_group.no_motion_vectors = Some(render_device.create_bind_group( + Some("prepass_view_no_motion_vectors_bind_group"), + &prepass_pipeline.view_layout_no_motion_vectors, + &BindGroupEntries::sequential((view_binding.clone(), globals_binding.clone())), + )); if let Some(previous_view_proj_binding) = previous_view_proj_uniforms.uniforms.binding() { - prepass_view_bind_group.motion_vectors = - Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &BindGroupEntries::sequential(( - view_binding, - globals_binding, - previous_view_proj_binding, - )), - label: Some("prepass_view_motion_vectors_bind_group"), - layout: &prepass_pipeline.view_layout_motion_vectors, - })); + prepass_view_bind_group.motion_vectors = Some(render_device.create_bind_group( + Some("prepass_view_motion_vectors_bind_group"), + &prepass_pipeline.view_layout_motion_vectors, + &BindGroupEntries::sequential(( + view_binding, + globals_binding, + previous_view_proj_binding, + )), + )); } } } diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 33168a982d58f..54da95c3aa127 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -1282,11 +1282,8 @@ pub fn prepare_mesh_view_bind_groups( )); } - let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - entries: &entries, - label: Some("mesh_view_bind_group"), - layout, - }); + let view_bind_group = + render_device.create_bind_group(Some("mesh_view_bind_group"), layout, &entries); commands.entity(entity).insert(MeshViewBindGroup { value: view_bind_group, diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index e46af242fdf85..f7b55b73ce747 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -3,8 +3,7 @@ use bevy_render::{ mesh::morph::MAX_MORPH_WEIGHTS, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, - BindingResource, Buffer, TextureView, + BindGroup, BindGroupLayout, BindGroupLayoutDescriptor, BindingResource, Buffer, TextureView, }, renderer::RenderDevice, }; @@ -175,11 +174,11 @@ impl MeshLayouts { // ---------- BindGroup methods ---------- pub fn model_only(&self, render_device: &RenderDevice, model: &BindingResource) -> BindGroup { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &[entry::model(0, model.clone())], - layout: &self.model_only, - label: Some("model_only_mesh_bind_group"), - }) + render_device.create_bind_group( + Some("model_only_mesh_bind_group"), + &self.model_only, + &[entry::model(0, model.clone())], + ) } pub fn skinned( &self, @@ -187,11 +186,11 @@ impl MeshLayouts { model: &BindingResource, skin: &Buffer, ) -> BindGroup { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &[entry::model(0, model.clone()), entry::skinning(1, skin)], - layout: &self.skinned, - label: Some("skinned_mesh_bind_group"), - }) + render_device.create_bind_group( + Some("skinned_mesh_bind_group"), + &self.skinned, + &[entry::model(0, model.clone()), entry::skinning(1, skin)], + ) } pub fn morphed( &self, @@ -200,15 +199,15 @@ impl MeshLayouts { weights: &Buffer, targets: &TextureView, ) -> BindGroup { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ + render_device.create_bind_group( + Some("morphed_mesh_bind_group"), + &self.morphed, + &[ entry::model(0, model.clone()), entry::weights(2, weights), entry::targets(3, targets), ], - layout: &self.morphed, - label: Some("morphed_mesh_bind_group"), - }) + ) } pub fn morphed_skinned( &self, @@ -218,15 +217,15 @@ impl MeshLayouts { weights: &Buffer, targets: &TextureView, ) -> BindGroup { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &[ + render_device.create_bind_group( + Some("morphed_skinned_mesh_bind_group"), + &self.morphed_skinned, + &[ entry::model(0, model.clone()), entry::skinning(1, skin), entry::weights(2, weights), entry::targets(3, targets), ], - layout: &self.morphed_skinned, - label: Some("morphed_skinned_mesh_bind_group"), - }) + ) } } diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index f4d36dea7b048..9048156f8790b 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -21,14 +21,13 @@ use bevy_render::{ prelude::Camera, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, render_resource::{ - AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntries, BindGroupLayout, - BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BufferBindingType, - CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, Extent3d, - FilterMode, PipelineCache, Sampler, SamplerBindingType, SamplerDescriptor, Shader, - ShaderDefVal, ShaderStages, ShaderType, SpecializedComputePipeline, - SpecializedComputePipelines, StorageTextureAccess, TextureDescriptor, TextureDimension, - TextureFormat, TextureSampleType, TextureUsages, TextureView, TextureViewDescriptor, - TextureViewDimension, + AddressMode, BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroupLayoutEntry, BindingType, BufferBindingType, CachedComputePipelineId, + ComputePassDescriptor, ComputePipelineDescriptor, Extent3d, FilterMode, PipelineCache, + Sampler, SamplerBindingType, SamplerDescriptor, Shader, ShaderDefVal, ShaderStages, + ShaderType, SpecializedComputePipeline, SpecializedComputePipelines, StorageTextureAccess, + TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, + TextureView, TextureViewDescriptor, TextureViewDimension, }, renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, texture::{CachedTexture, TextureCache}, @@ -780,14 +779,11 @@ fn prepare_ssao_bind_groups( }; for (entity, ssao_textures, prepass_textures) in &views { - let common_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Some("ssao_common_bind_group"), - layout: &pipelines.common_bind_group_layout, - entries: &BindGroupEntries::sequential(( - &pipelines.point_clamp_sampler, - view_uniforms.clone(), - )), - }); + let common_bind_group = render_device.create_bind_group( + Some("ssao_common_bind_group"), + &pipelines.common_bind_group_layout, + &BindGroupEntries::sequential((&pipelines.point_clamp_sampler, view_uniforms.clone())), + ); let create_depth_view = |mip_level| { ssao_textures @@ -803,10 +799,10 @@ fn prepare_ssao_bind_groups( }) }; - let preprocess_depth_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Some("ssao_preprocess_depth_bind_group"), - layout: &pipelines.preprocess_depth_bind_group_layout, - entries: &BindGroupEntries::sequential(( + let preprocess_depth_bind_group = render_device.create_bind_group( + Some("ssao_preprocess_depth_bind_group"), + &pipelines.preprocess_depth_bind_group_layout, + &BindGroupEntries::sequential(( &prepass_textures.depth.as_ref().unwrap().default_view, &create_depth_view(0), &create_depth_view(1), @@ -814,12 +810,12 @@ fn prepare_ssao_bind_groups( &create_depth_view(3), &create_depth_view(4), )), - }); + ); - let gtao_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Some("ssao_gtao_bind_group"), - layout: &pipelines.gtao_bind_group_layout, - entries: &BindGroupEntries::sequential(( + let gtao_bind_group = render_device.create_bind_group( + Some("ssao_gtao_bind_group"), + &pipelines.gtao_bind_group_layout, + &BindGroupEntries::sequential(( &ssao_textures.preprocessed_depth_texture.default_view, &prepass_textures.normal.as_ref().unwrap().default_view, &pipelines.hilbert_index_lut, @@ -827,19 +823,19 @@ fn prepare_ssao_bind_groups( &ssao_textures.depth_differences_texture.default_view, globals_uniforms.clone(), )), - }); + ); - let spatial_denoise_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Some("ssao_spatial_denoise_bind_group"), - layout: &pipelines.spatial_denoise_bind_group_layout, - entries: &BindGroupEntries::sequential(( + let spatial_denoise_bind_group = render_device.create_bind_group( + Some("ssao_spatial_denoise_bind_group"), + &pipelines.spatial_denoise_bind_group_layout, + &BindGroupEntries::sequential(( &ssao_textures.ssao_noisy_texture.default_view, &ssao_textures.depth_differences_texture.default_view, &ssao_textures .screen_space_ambient_occlusion_texture .default_view, )), - }); + ); commands.entity(entity).insert(SsaoBindGroups { common_bind_group, diff --git a/crates/bevy_render/macros/src/as_bind_group.rs b/crates/bevy_render/macros/src/as_bind_group.rs index df137e95d8b55..060bbacbc1947 100644 --- a/crates/bevy_render/macros/src/as_bind_group.rs +++ b/crates/bevy_render/macros/src/as_bind_group.rs @@ -452,14 +452,11 @@ pub fn derive_as_bind_group(ast: syn::DeriveInput) -> Result { ) -> Result<#render_path::render_resource::PreparedBindGroup, #render_path::render_resource::AsBindGroupError> { let bindings = vec![#(#binding_impls,)*]; - let bind_group = { - let descriptor = #render_path::render_resource::BindGroupDescriptor { - entries: &[#(#bind_group_entries,)*], - label: None, - layout: &layout, - }; - render_device.create_bind_group(&descriptor) - }; + let bind_group = render_device.create_bind_group( + None, + &layout, + &[#(#bind_group_entries,)*], + ); Ok(#render_path::render_resource::PreparedBindGroup { bindings, diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 35579b4579b71..7b06bcc86a85a 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -7,23 +7,23 @@ use super::{Sampler, TextureView}; /// /// Allows constructing the descriptor's entries as: /// ``` -/// render_device.create_bind_group(&BindGroupDescriptor { -/// label: Some("my_bind_group"), -/// layout: &my_layout, -/// entries: BindGroupEntries::with_indexes(( +/// render_device.create_bind_group( +/// Some("my_bind_group"), +/// &my_layout, +/// BindGroupEntries::with_indexes(( /// (2, &my_sampler), /// (3, my_uniform), /// )).as_slice(), -/// }); +/// ); /// ``` /// /// instead of /// /// ``` -/// render_device.create_bind_group(&BindGroupDescriptor { -/// label: Some("my_bind_group"), -/// layout: &my_layout, -/// entries: &[ +/// render_device.create_bind_group( +/// Some("my_bind_group"), +/// &my_layout, +/// &[ /// BindGroupEntry { /// binding: 2, /// resource: BindingResource::Sampler(&my_sampler), @@ -33,29 +33,29 @@ use super::{Sampler, TextureView}; /// resource: my_uniform, /// }, /// ], -/// }); +/// ); /// ``` /// /// or /// /// ``` -/// render_device.create_bind_group(&BindGroupDescriptor { -/// label: Some("my_bind_group"), -/// layout: &my_layout, -/// entries: BindGroupEntries::sequential(( +/// render_device.create_bind_group( +/// Some("my_bind_group"), +/// &my_layout, +/// BindGroupEntries::sequential(( /// &my_sampler, /// my_uniform, /// )).as_slice(), -/// }); +/// ); /// ``` /// /// instead of /// /// ``` /// render_device.create_bind_group(&BindGroupDescriptor { -/// label: Some("my_bind_group"), -/// layout: &my_layout, -/// entries: &[ +/// Some("my_bind_group"), +/// &my_layout, +/// &[ /// BindGroupEntry { /// binding: 0, /// resource: BindingResource::Sampler(&my_sampler), @@ -65,7 +65,7 @@ use super::{Sampler, TextureView}; /// resource: my_uniform, /// }, /// ], -/// }); +/// ); /// ``` pub struct BindGroupEntries<'b, const N: usize> { diff --git a/crates/bevy_render/src/renderer/render_device.rs b/crates/bevy_render/src/renderer/render_device.rs index 8a177e94774cb..d627c33045637 100644 --- a/crates/bevy_render/src/renderer/render_device.rs +++ b/crates/bevy_render/src/renderer/render_device.rs @@ -3,7 +3,10 @@ use crate::render_resource::{ RenderPipeline, Sampler, Texture, }; use bevy_ecs::system::Resource; -use wgpu::{util::DeviceExt, BufferAsyncError, BufferBindingType}; +use wgpu::{ + util::DeviceExt, BindGroupDescriptor, BindGroupEntry, BufferAsyncError, BufferBindingType, + Label, +}; use super::RenderQueue; @@ -82,8 +85,17 @@ impl RenderDevice { /// Creates a new [`BindGroup`](wgpu::BindGroup). #[inline] - pub fn create_bind_group(&self, desc: &wgpu::BindGroupDescriptor) -> BindGroup { - let wgpu_bind_group = self.device.create_bind_group(desc); + pub fn create_bind_group<'a>( + &self, + label: Label<'a>, + layout: &'a BindGroupLayout, + entries: &'a [BindGroupEntry<'a>], + ) -> BindGroup { + let wgpu_bind_group = self.device.create_bind_group(&BindGroupDescriptor { + label, + layout, + entries, + }); BindGroup::from(wgpu_bind_group) } diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index 911214ecbaf01..dafdc899a76d3 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -389,14 +389,14 @@ pub fn prepare_windows( usage: BufferUsages::MAP_READ | BufferUsages::COPY_DST, mapped_at_creation: false, }); - let bind_group = render_device.create_bind_group(&wgpu::BindGroupDescriptor { - label: Some("screenshot-to-screen-bind-group"), - layout: &screenshot_pipeline.bind_group_layout, - entries: &[wgpu::BindGroupEntry { + let bind_group = render_device.create_bind_group( + Some("screenshot-to-screen-bind-group"), + &screenshot_pipeline.bind_group_layout, + &[wgpu::BindGroupEntry { binding: 0, resource: wgpu::BindingResource::TextureView(&texture_view), }], - }); + ); let pipeline_id = pipelines.specialize( &pipeline_cache, &screenshot_pipeline, diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 61c3224c64e63..0327e9acba97c 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -488,14 +488,14 @@ pub fn prepare_mesh2d_bind_group( ) { if let Some(binding) = mesh2d_uniforms.uniforms().binding() { commands.insert_resource(Mesh2dBindGroup { - value: render_device.create_bind_group(&BindGroupDescriptor { - entries: &[BindGroupEntry { + value: render_device.create_bind_group( + Some("mesh2d_bind_group"), + &mesh2d_pipeline.mesh_layout, + &[BindGroupEntry { binding: 0, resource: binding, }], - label: Some("mesh2d_bind_group"), - layout: &mesh2d_pipeline.mesh_layout, - }), + ), }); } } @@ -518,11 +518,11 @@ pub fn prepare_mesh2d_view_bind_groups( globals_buffer.buffer.binding(), ) { for entity in &views { - let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { - entries: &BindGroupEntries::sequential((view_binding.clone(), globals.clone())), - label: Some("mesh2d_view_bind_group"), - layout: &mesh2d_pipeline.view_layout, - }); + let view_bind_group = render_device.create_bind_group( + Some("mesh2d_view_bind_group"), + &mesh2d_pipeline.view_layout, + &BindGroupEntries::sequential((view_binding.clone(), globals.clone())), + ); commands.entity(entity).insert(Mesh2dViewBindGroup { value: view_bind_group, diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index b9906941cc2a5..7f2ca0fb68c83 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -611,14 +611,14 @@ pub fn prepare_sprites( sprite_meta.vertices.clear(); sprite_meta.colored_vertices.clear(); - sprite_meta.view_bind_group = Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &[BindGroupEntry { + sprite_meta.view_bind_group = Some(render_device.create_bind_group( + Some("sprite_view_bind_group"), + &sprite_pipeline.view_layout, + &[BindGroupEntry { binding: 0, resource: view_binding, }], - label: Some("sprite_view_bind_group"), - layout: &sprite_pipeline.view_layout, - })); + )); // Vertex buffer indices let mut index = 0; @@ -669,14 +669,14 @@ pub fn prepare_sprites( .values .entry(Handle::weak(batch_image_handle)) .or_insert_with(|| { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &BindGroupEntries::sequential(( + render_device.create_bind_group( + Some("sprite_material_bind_group"), + &sprite_pipeline.material_layout, + &BindGroupEntries::sequential(( &gpu_image.texture_view, &gpu_image.sampler, )), - label: Some("sprite_material_bind_group"), - layout: &sprite_pipeline.material_layout, - }) + ) }); existing_batch = batches.last_mut(); } else { diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 17b178ef3e046..c1f6c15578fcb 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -715,14 +715,14 @@ pub fn prepare_uinodes( let mut batches: Vec<(Entity, UiBatch)> = Vec::with_capacity(*previous_len); ui_meta.vertices.clear(); - ui_meta.view_bind_group = Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &[BindGroupEntry { + ui_meta.view_bind_group = Some(render_device.create_bind_group( + Some("ui_view_bind_group"), + &ui_pipeline.view_layout, + &[BindGroupEntry { binding: 0, resource: view_binding, }], - label: Some("ui_view_bind_group"), - layout: &ui_pipeline.view_layout, - })); + )); // Vertex buffer index let mut index = 0; @@ -754,14 +754,14 @@ pub fn prepare_uinodes( .values .entry(Handle::weak(batch_image_handle)) .or_insert_with(|| { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &BindGroupEntries::sequential(( + render_device.create_bind_group( + Some("ui_material_bind_group"), + &ui_pipeline.image_layout, + &BindGroupEntries::sequential(( &gpu_image.texture_view, &gpu_image.sampler, )), - label: Some("ui_material_bind_group"), - layout: &ui_pipeline.image_layout, - }) + ) }); existing_batch = batches.last_mut(); diff --git a/examples/shader/compute_shader_game_of_life.rs b/examples/shader/compute_shader_game_of_life.rs index 6d8383ee0c532..152e06970ec9f 100644 --- a/examples/shader/compute_shader_game_of_life.rs +++ b/examples/shader/compute_shader_game_of_life.rs @@ -107,14 +107,14 @@ fn prepare_bind_group( render_device: Res, ) { let view = &gpu_images[&game_of_life_image.0]; - let bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: None, - layout: &pipeline.texture_bind_group_layout, - entries: &[BindGroupEntry { + let bind_group = render_device.create_bind_group( + None, + &pipeline.texture_bind_group_layout, + &[BindGroupEntry { binding: 0, resource: BindingResource::TextureView(&view.texture_view), }], - }); + ); commands.insert_resource(GameOfLifeImageBindGroup(bind_group)); } diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 9ddf70c1bcb7a..17018aaf49c5b 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -21,7 +21,7 @@ use bevy::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, render_resource::{ - BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, + BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, @@ -186,18 +186,16 @@ impl ViewNode for PostProcessNode { // The reason it doesn't work is because each post_process_write will alternate the source/destination. // The only way to have the correct source/destination for the bind_group // is to make sure you get it during the node execution. - let bind_group = render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: Some("post_process_bind_group"), - layout: &post_process_pipeline.layout, - // It's important for this to match the BindGroupLayout defined in the PostProcessPipeline - entries: &BindGroupEntries::sequential(( - post_process.source, - &post_process_pipeline.sampler, - settings_binding.clone(), - )), - }); + let bind_group = render_context.render_device().create_bind_group( + Some("post_process_bind_group"), + &post_process_pipeline.layout, + // It's important for this to match the BindGroupLayout defined in the PostProcessPipeline + &BindGroupEntries::sequential(( + post_process.source, + &post_process_pipeline.sampler, + settings_binding.clone(), + )), + ); // Begin the render pass let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor { diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index b2f0d8d5c82c4..d527b2d019a66 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -124,11 +124,11 @@ impl AsBindGroup for BindlessMaterial { textures[id] = &*image.texture_view; } - let bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: "bindless_material_bind_group".into(), + let bind_group = render_device.create_bind_group( + "bindless_material_bind_group".into(), layout, - entries: &BindGroupEntries::sequential((&textures[..], &fallback_image.sampler)), - }); + &BindGroupEntries::sequential((&textures[..], &fallback_image.sampler)), + ); Ok(PreparedBindGroup { bindings: vec![], From 862ae47e577387918a9b35fa5963943aae64d7f3 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:36:52 +0100 Subject: [PATCH 06/29] fmt --- examples/shader/post_processing.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 17018aaf49c5b..7821aa960c881 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -21,9 +21,9 @@ use bevy::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, render_resource::{ - BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, - BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, - MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, + BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, + CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, MultisampleState, + Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, SamplerDescriptor, ShaderStages, ShaderType, TextureFormat, TextureSampleType, TextureViewDimension, From a57ff80b476c74d22a8985ddf2a3a0ba6cfe0145 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:38:53 +0100 Subject: [PATCH 07/29] fix comment --- crates/bevy_render/src/render_resource/bind_group_entries.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 7b06bcc86a85a..6bcbefa178183 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -10,7 +10,7 @@ use super::{Sampler, TextureView}; /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, -/// BindGroupEntries::with_indexes(( +/// &BindGroupEntries::with_indexes(( /// (2, &my_sampler), /// (3, my_uniform), /// )).as_slice(), @@ -42,7 +42,7 @@ use super::{Sampler, TextureView}; /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, -/// BindGroupEntries::sequential(( +/// &BindGroupEntries::sequential(( /// &my_sampler, /// my_uniform, /// )).as_slice(), From 49e186ab6786ac304a257a188b23a299bbad3e46 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:41:16 +0100 Subject: [PATCH 08/29] no bevy_internals --- examples/shader/post_processing.rs | 7 +++---- examples/shader/texture_binding_array.rs | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 7821aa960c881..638e8d29d9735 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -21,9 +21,9 @@ use bevy::{ NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner, }, render_resource::{ - BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, - CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, MultisampleState, - Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, + BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, + BindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites, FragmentState, + MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType, SamplerDescriptor, ShaderStages, ShaderType, TextureFormat, TextureSampleType, TextureViewDimension, @@ -35,7 +35,6 @@ use bevy::{ }, utils::Duration, }; -use bevy_internal::render::render_resource::BindGroupEntries; fn main() { App::new() diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index d527b2d019a66..8ebdd6de9b746 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -6,13 +6,12 @@ use bevy::{ reflect::{TypePath, TypeUuid}, render::{ render_asset::RenderAssets, - render_resource::{AsBindGroupError, PreparedBindGroup, *}, + render_resource::{AsBindGroupError, BindGroupEntries, PreparedBindGroup, *}, renderer::RenderDevice, texture::FallbackImage, RenderApp, }, }; -use bevy_internal::render::render_resource::BindGroupEntries; use std::{num::NonZeroU32, process::exit}; fn main() { From 90d5caae5ac68cbd9653a198abe54703389ee8c3 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:49:54 +0100 Subject: [PATCH 09/29] no_run --- .../bevy_render/src/render_resource/bind_group_entries.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 6bcbefa178183..df0f5bfab9d13 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -6,7 +6,7 @@ use super::{Sampler, TextureView}; /// Helper for constructing bindgroups. /// /// Allows constructing the descriptor's entries as: -/// ``` +/// ```no_run /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, @@ -19,7 +19,7 @@ use super::{Sampler, TextureView}; /// /// instead of /// -/// ``` +/// ```no_run /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, @@ -38,7 +38,7 @@ use super::{Sampler, TextureView}; /// /// or /// -/// ``` +/// ```no_run /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, @@ -51,7 +51,7 @@ use super::{Sampler, TextureView}; /// /// instead of /// -/// ``` +/// ```no_run /// render_device.create_bind_group(&BindGroupDescriptor { /// Some("my_bind_group"), /// &my_layout, From b59a64de1fb4ca265538494077547982f610284e Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:58:57 +0100 Subject: [PATCH 10/29] ignore? --- .../bevy_render/src/render_resource/bind_group_entries.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index df0f5bfab9d13..8398e08ce2e59 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -6,7 +6,7 @@ use super::{Sampler, TextureView}; /// Helper for constructing bindgroups. /// /// Allows constructing the descriptor's entries as: -/// ```no_run +/// ```ignore /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, @@ -19,7 +19,7 @@ use super::{Sampler, TextureView}; /// /// instead of /// -/// ```no_run +/// ```ignore /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, @@ -38,7 +38,7 @@ use super::{Sampler, TextureView}; /// /// or /// -/// ```no_run +/// ```ignore /// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, @@ -51,7 +51,7 @@ use super::{Sampler, TextureView}; /// /// instead of /// -/// ```no_run +/// ```ignore /// render_device.create_bind_group(&BindGroupDescriptor { /// Some("my_bind_group"), /// &my_layout, From 7b881363bcc4a7642d5282768ab7e0db99f3810c Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:13:37 +0100 Subject: [PATCH 11/29] doc tests are hard --- crates/bevy_render/src/render_resource/bind_group_entries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 8398e08ce2e59..843f8fe2f0761 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -52,7 +52,7 @@ use super::{Sampler, TextureView}; /// instead of /// /// ```ignore -/// render_device.create_bind_group(&BindGroupDescriptor { +/// render_device.create_bind_group( /// Some("my_bind_group"), /// &my_layout, /// &[ From c43e753bf0faf903f7c4656f1b4309bf33fe1d75 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:34:52 +0100 Subject: [PATCH 12/29] IntoLabel --- crates/bevy_core_pipeline/src/bloom/mod.rs | 6 ++--- .../src/contrast_adaptive_sharpening/node.rs | 2 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 2 +- crates/bevy_core_pipeline/src/taa/mod.rs | 2 +- crates/bevy_gizmos/src/lib.rs | 2 +- crates/bevy_pbr/src/prepass/mod.rs | 4 ++-- crates/bevy_pbr/src/render/mesh.rs | 2 +- crates/bevy_pbr/src/render/mesh_bindings.rs | 8 +++---- crates/bevy_pbr/src/ssao/mod.rs | 8 +++---- .../src/render_resource/bind_group_entries.rs | 8 +++---- .../bevy_render/src/renderer/render_device.rs | 22 ++++++++++++++++--- crates/bevy_render/src/view/window/mod.rs | 2 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 4 ++-- crates/bevy_sprite/src/render/mod.rs | 4 ++-- crates/bevy_ui/src/render/mod.rs | 4 ++-- examples/shader/post_processing.rs | 2 +- examples/shader/texture_binding_array.rs | 2 +- 17 files changed, 50 insertions(+), 34 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/mod.rs b/crates/bevy_core_pipeline/src/bloom/mod.rs index f263133f4b799..6efa5fc7b971e 100644 --- a/crates/bevy_core_pipeline/src/bloom/mod.rs +++ b/crates/bevy_core_pipeline/src/bloom/mod.rs @@ -173,7 +173,7 @@ impl ViewNode for BloomNode { // First downsample pass { let downsampling_first_bind_group = render_context.render_device().create_bind_group( - Some("bloom_downsampling_first_bind_group"), + "bloom_downsampling_first_bind_group", &downsampling_pipeline_res.bind_group_layout, &BindGroupEntries::sequential(( // Read from main texture directly @@ -405,7 +405,7 @@ fn prepare_bloom_bind_groups( let mut downsampling_bind_groups = Vec::with_capacity(bind_group_count); for mip in 1..bloom_texture.mip_count { downsampling_bind_groups.push(render_device.create_bind_group( - Some("bloom_downsampling_bind_group"), + "bloom_downsampling_bind_group", &downsampling_pipeline.bind_group_layout, &BindGroupEntries::sequential(( &bloom_texture.view(mip - 1), @@ -418,7 +418,7 @@ fn prepare_bloom_bind_groups( let mut upsampling_bind_groups = Vec::with_capacity(bind_group_count); for mip in (0..bloom_texture.mip_count).rev() { upsampling_bind_groups.push(render_device.create_bind_group( - Some("bloom_upsampling_bind_group"), + "bloom_upsampling_bind_group", &upsampling_pipeline.bind_group_layout, &BindGroupEntries::sequential(( &bloom_texture.view(mip), diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs index acbeb3c5b1981..5bb8b87ebc58b 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs @@ -78,7 +78,7 @@ impl Node for CASNode { } cached_bind_group => { let bind_group = render_context.render_device().create_bind_group( - Some("cas_bind_group"), + "cas_bind_group", &sharpening_pipeline.texture_bind_group, &BindGroupEntries::sequential(( view_target.source, diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index cf5c027346395..1255b328dc5cd 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -222,7 +222,7 @@ fn prepare_skybox_bind_groups( (images.get(&skybox.0), view_uniforms.uniforms.binding()) { let bind_group = render_device.create_bind_group( - Some("skybox_bind_group"), + "skybox_bind_group", &pipeline.bind_group_layout, &BindGroupEntries::sequential(( &skybox.texture_view, diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index 96bf23a2362e8..acb7d6863accd 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -199,7 +199,7 @@ impl ViewNode for TAANode { let view_target = view_target.post_process_write(); let taa_bind_group = render_context.render_device().create_bind_group( - Some("taa_bind_group"), + "taa_bind_group", &pipelines.taa_bind_group_layout, &BindGroupEntries::sequential(( view_target.source, diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 1d6a49a025e23..4f320134636f7 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -425,7 +425,7 @@ fn prepare_line_gizmo_bind_group( if let Some(binding) = line_gizmo_uniforms.uniforms().binding() { commands.insert_resource(LineGizmoUniformBindgroup { bindgroup: render_device.create_bind_group( - Some("LineGizmoUniform bindgroup"), + "LineGizmoUniform bindgroup", &line_gizmo_uniform_layout.layout, &[BindGroupEntry { binding: 0, diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index bee7a7e500f84..95888eb6b2a88 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -690,14 +690,14 @@ pub fn prepare_prepass_view_bind_group( globals_buffer.buffer.binding(), ) { prepass_view_bind_group.no_motion_vectors = Some(render_device.create_bind_group( - Some("prepass_view_no_motion_vectors_bind_group"), + "prepass_view_no_motion_vectors_bind_group", &prepass_pipeline.view_layout_no_motion_vectors, &BindGroupEntries::sequential((view_binding.clone(), globals_binding.clone())), )); if let Some(previous_view_proj_binding) = previous_view_proj_uniforms.uniforms.binding() { prepass_view_bind_group.motion_vectors = Some(render_device.create_bind_group( - Some("prepass_view_motion_vectors_bind_group"), + "prepass_view_motion_vectors_bind_group", &prepass_pipeline.view_layout_motion_vectors, &BindGroupEntries::sequential(( view_binding, diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index d269f5d525659..4a6ce648adf55 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -1283,7 +1283,7 @@ pub fn prepare_mesh_view_bind_groups( } let view_bind_group = - render_device.create_bind_group(Some("mesh_view_bind_group"), layout, &entries); + render_device.create_bind_group("mesh_view_bind_group", layout, &entries); commands.entity(entity).insert(MeshViewBindGroup { value: view_bind_group, diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index f7b55b73ce747..c61ccc4dbd79b 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -175,7 +175,7 @@ impl MeshLayouts { pub fn model_only(&self, render_device: &RenderDevice, model: &BindingResource) -> BindGroup { render_device.create_bind_group( - Some("model_only_mesh_bind_group"), + "model_only_mesh_bind_group", &self.model_only, &[entry::model(0, model.clone())], ) @@ -187,7 +187,7 @@ impl MeshLayouts { skin: &Buffer, ) -> BindGroup { render_device.create_bind_group( - Some("skinned_mesh_bind_group"), + "skinned_mesh_bind_group", &self.skinned, &[entry::model(0, model.clone()), entry::skinning(1, skin)], ) @@ -200,7 +200,7 @@ impl MeshLayouts { targets: &TextureView, ) -> BindGroup { render_device.create_bind_group( - Some("morphed_mesh_bind_group"), + "morphed_mesh_bind_group", &self.morphed, &[ entry::model(0, model.clone()), @@ -218,7 +218,7 @@ impl MeshLayouts { targets: &TextureView, ) -> BindGroup { render_device.create_bind_group( - Some("morphed_skinned_mesh_bind_group"), + "morphed_skinned_mesh_bind_group", &self.morphed_skinned, &[ entry::model(0, model.clone()), diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 9048156f8790b..3af03da1008df 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -780,7 +780,7 @@ fn prepare_ssao_bind_groups( for (entity, ssao_textures, prepass_textures) in &views { let common_bind_group = render_device.create_bind_group( - Some("ssao_common_bind_group"), + "ssao_common_bind_group", &pipelines.common_bind_group_layout, &BindGroupEntries::sequential((&pipelines.point_clamp_sampler, view_uniforms.clone())), ); @@ -800,7 +800,7 @@ fn prepare_ssao_bind_groups( }; let preprocess_depth_bind_group = render_device.create_bind_group( - Some("ssao_preprocess_depth_bind_group"), + "ssao_preprocess_depth_bind_group", &pipelines.preprocess_depth_bind_group_layout, &BindGroupEntries::sequential(( &prepass_textures.depth.as_ref().unwrap().default_view, @@ -813,7 +813,7 @@ fn prepare_ssao_bind_groups( ); let gtao_bind_group = render_device.create_bind_group( - Some("ssao_gtao_bind_group"), + "ssao_gtao_bind_group", &pipelines.gtao_bind_group_layout, &BindGroupEntries::sequential(( &ssao_textures.preprocessed_depth_texture.default_view, @@ -826,7 +826,7 @@ fn prepare_ssao_bind_groups( ); let spatial_denoise_bind_group = render_device.create_bind_group( - Some("ssao_spatial_denoise_bind_group"), + "ssao_spatial_denoise_bind_group", &pipelines.spatial_denoise_bind_group_layout, &BindGroupEntries::sequential(( &ssao_textures.ssao_noisy_texture.default_view, diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 843f8fe2f0761..d1046ce2b7a4d 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -8,7 +8,7 @@ use super::{Sampler, TextureView}; /// Allows constructing the descriptor's entries as: /// ```ignore /// render_device.create_bind_group( -/// Some("my_bind_group"), +/// "my_bind_group", /// &my_layout, /// &BindGroupEntries::with_indexes(( /// (2, &my_sampler), @@ -21,7 +21,7 @@ use super::{Sampler, TextureView}; /// /// ```ignore /// render_device.create_bind_group( -/// Some("my_bind_group"), +/// "my_bind_group", /// &my_layout, /// &[ /// BindGroupEntry { @@ -40,7 +40,7 @@ use super::{Sampler, TextureView}; /// /// ```ignore /// render_device.create_bind_group( -/// Some("my_bind_group"), +/// "my_bind_group", /// &my_layout, /// &BindGroupEntries::sequential(( /// &my_sampler, @@ -53,7 +53,7 @@ use super::{Sampler, TextureView}; /// /// ```ignore /// render_device.create_bind_group( -/// Some("my_bind_group"), +/// "my_bind_group", /// &my_layout, /// &[ /// BindGroupEntry { diff --git a/crates/bevy_render/src/renderer/render_device.rs b/crates/bevy_render/src/renderer/render_device.rs index d627c33045637..c149011484068 100644 --- a/crates/bevy_render/src/renderer/render_device.rs +++ b/crates/bevy_render/src/renderer/render_device.rs @@ -5,7 +5,6 @@ use crate::render_resource::{ use bevy_ecs::system::Resource; use wgpu::{ util::DeviceExt, BindGroupDescriptor, BindGroupEntry, BufferAsyncError, BufferBindingType, - Label, }; use super::RenderQueue; @@ -87,12 +86,12 @@ impl RenderDevice { #[inline] pub fn create_bind_group<'a>( &self, - label: Label<'a>, + label: impl IntoLabel<'a>, layout: &'a BindGroupLayout, entries: &'a [BindGroupEntry<'a>], ) -> BindGroup { let wgpu_bind_group = self.device.create_bind_group(&BindGroupDescriptor { - label, + label: label.label(), layout, entries, }); @@ -219,3 +218,20 @@ impl RenderDevice { } } } + +// helper trait to create Option> from &'a str +pub trait IntoLabel<'a> { + fn label(self) -> wgpu::Label<'a>; +} + +impl<'a> IntoLabel<'a> for &'a str { + fn label(self) -> wgpu::Label<'a> { + Some(self.into()) + } +} + +impl<'a> IntoLabel<'a> for wgpu::Label<'a> { + fn label(self) -> wgpu::Label<'a> { + self + } +} diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index bde5ef16028ac..d60f73b7347f3 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -390,7 +390,7 @@ pub fn prepare_windows( mapped_at_creation: false, }); let bind_group = render_device.create_bind_group( - Some("screenshot-to-screen-bind-group"), + "screenshot-to-screen-bind-group", &screenshot_pipeline.bind_group_layout, &[wgpu::BindGroupEntry { binding: 0, diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 1eedfd487044f..e937fb6af5286 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -489,7 +489,7 @@ pub fn prepare_mesh2d_bind_group( if let Some(binding) = mesh2d_uniforms.uniforms().binding() { commands.insert_resource(Mesh2dBindGroup { value: render_device.create_bind_group( - Some("mesh2d_bind_group"), + "mesh2d_bind_group", &mesh2d_pipeline.mesh_layout, &[BindGroupEntry { binding: 0, @@ -519,7 +519,7 @@ pub fn prepare_mesh2d_view_bind_groups( ) { for entity in &views { let view_bind_group = render_device.create_bind_group( - Some("mesh2d_view_bind_group"), + "mesh2d_view_bind_group", &mesh2d_pipeline.view_layout, &BindGroupEntries::sequential((view_binding.clone(), globals.clone())), ); diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 0f7192399b8ba..8865e79160ad7 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -625,7 +625,7 @@ pub fn prepare_sprites( sprite_meta.sprite_instance_buffer.clear(); sprite_meta.view_bind_group = Some(render_device.create_bind_group( - Some("sprite_view_bind_group"), + "sprite_view_bind_group", &sprite_pipeline.view_layout, &[BindGroupEntry { binding: 0, @@ -671,7 +671,7 @@ pub fn prepare_sprites( .entry(Handle::weak(batch_image_handle)) .or_insert_with(|| { render_device.create_bind_group( - Some("sprite_material_bind_group"), + "sprite_material_bind_group", &sprite_pipeline.material_layout, &BindGroupEntries::sequential(( &gpu_image.texture_view, diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 63f62eb73584f..5ca8ee4260011 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -717,7 +717,7 @@ pub fn prepare_uinodes( ui_meta.vertices.clear(); ui_meta.view_bind_group = Some(render_device.create_bind_group( - Some("ui_view_bind_group"), + "ui_view_bind_group", &ui_pipeline.view_layout, &[BindGroupEntry { binding: 0, @@ -756,7 +756,7 @@ pub fn prepare_uinodes( .entry(Handle::weak(batch_image_handle)) .or_insert_with(|| { render_device.create_bind_group( - Some("ui_material_bind_group"), + "ui_material_bind_group", &ui_pipeline.image_layout, &BindGroupEntries::sequential(( &gpu_image.texture_view, diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 638e8d29d9735..92b8f25e97c50 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -186,7 +186,7 @@ impl ViewNode for PostProcessNode { // The only way to have the correct source/destination for the bind_group // is to make sure you get it during the node execution. let bind_group = render_context.render_device().create_bind_group( - Some("post_process_bind_group"), + "post_process_bind_group", &post_process_pipeline.layout, // It's important for this to match the BindGroupLayout defined in the PostProcessPipeline &BindGroupEntries::sequential(( diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 8ebdd6de9b746..11e3c25b974d8 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -124,7 +124,7 @@ impl AsBindGroup for BindlessMaterial { } let bind_group = render_device.create_bind_group( - "bindless_material_bind_group".into(), + "bindless_material_bind_group", layout, &BindGroupEntries::sequential((&textures[..], &fallback_image.sampler)), ); From 56e4297284ff20fdde22b2dd988240d6462d47ae Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:40:37 +0100 Subject: [PATCH 13/29] simpler --- .../bevy_render/src/renderer/render_device.rs | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/crates/bevy_render/src/renderer/render_device.rs b/crates/bevy_render/src/renderer/render_device.rs index c149011484068..6a126df8aa41e 100644 --- a/crates/bevy_render/src/renderer/render_device.rs +++ b/crates/bevy_render/src/renderer/render_device.rs @@ -86,12 +86,12 @@ impl RenderDevice { #[inline] pub fn create_bind_group<'a>( &self, - label: impl IntoLabel<'a>, + label: impl Into>, layout: &'a BindGroupLayout, entries: &'a [BindGroupEntry<'a>], ) -> BindGroup { let wgpu_bind_group = self.device.create_bind_group(&BindGroupDescriptor { - label: label.label(), + label: label.into(), layout, entries, }); @@ -218,20 +218,3 @@ impl RenderDevice { } } } - -// helper trait to create Option> from &'a str -pub trait IntoLabel<'a> { - fn label(self) -> wgpu::Label<'a>; -} - -impl<'a> IntoLabel<'a> for &'a str { - fn label(self) -> wgpu::Label<'a> { - Some(self.into()) - } -} - -impl<'a> IntoLabel<'a> for wgpu::Label<'a> { - fn label(self) -> wgpu::Label<'a> { - self - } -} From b8dbd66ed1a584761d4b58a03b622a710cef0391 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:42:57 +0100 Subject: [PATCH 14/29] re-add example comments --- examples/shader/post_processing.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 92b8f25e97c50..02a620e15e729 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -190,8 +190,11 @@ impl ViewNode for PostProcessNode { &post_process_pipeline.layout, // It's important for this to match the BindGroupLayout defined in the PostProcessPipeline &BindGroupEntries::sequential(( + // Make sure to use the source view post_process.source, + // Use the sampler created for the pipeline &post_process_pipeline.sampler, + // Set the settings binding settings_binding.clone(), )), ); From 3e3c9f60e5b6353bdf13d212bf24da4a8e3c4b9a Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:43:41 +0100 Subject: [PATCH 15/29] remove as_slice --- crates/bevy_render/src/render_resource/bind_group_entries.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index d1046ce2b7a4d..5bec21a0935cb 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -13,7 +13,7 @@ use super::{Sampler, TextureView}; /// &BindGroupEntries::with_indexes(( /// (2, &my_sampler), /// (3, my_uniform), -/// )).as_slice(), +/// )), /// ); /// ``` /// @@ -45,7 +45,7 @@ use super::{Sampler, TextureView}; /// &BindGroupEntries::sequential(( /// &my_sampler, /// my_uniform, -/// )).as_slice(), +/// )), /// ); /// ``` /// From 22c1e675306214b3a98619b74e5d66bcfd508756 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 5 Sep 2023 08:48:32 +0100 Subject: [PATCH 16/29] indexes -> indices --- .../bevy_render/src/render_resource/bind_group_entries.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 5bec21a0935cb..b6c17df979e16 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -10,7 +10,7 @@ use super::{Sampler, TextureView}; /// render_device.create_bind_group( /// "my_bind_group", /// &my_layout, -/// &BindGroupEntries::with_indexes(( +/// &BindGroupEntries::with_indices(( /// (2, &my_sampler), /// (3, my_uniform), /// )), @@ -86,7 +86,7 @@ impl<'b, const N: usize> BindGroupEntries<'b, N> { } #[inline] - pub fn with_indexes(indexed_resources: impl IntoIndexedBindingArray<'b, N>) -> Self { + pub fn with_indices(indexed_resources: impl IntoIndexedBindingArray<'b, N>) -> Self { Self { entries: indexed_resources .into_array() @@ -208,7 +208,7 @@ impl<'b> DynamicBindGroupEntries<'b> { self } - pub fn new_with_indexes(entries: impl IntoIndexedBindingArray<'b, N>) -> Self { + pub fn new_with_indices(entries: impl IntoIndexedBindingArray<'b, N>) -> Self { Self { entries: entries .into_array() @@ -218,7 +218,7 @@ impl<'b> DynamicBindGroupEntries<'b> { } } - pub fn extend_with_indexes( + pub fn extend_with_indices( mut self, entries: impl IntoIndexedBindingArray<'b, N>, ) -> Self { From 793eeebcb44878c58fa9113a1350e8e5d09ed61e Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 6 Sep 2023 00:31:35 +0100 Subject: [PATCH 17/29] importing * is plenty --- crates/bevy_core_pipeline/src/bloom/mod.rs | 2 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 2 +- examples/shader/texture_binding_array.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/mod.rs b/crates/bevy_core_pipeline/src/bloom/mod.rs index 6efa5fc7b971e..66aee17680cd4 100644 --- a/crates/bevy_core_pipeline/src/bloom/mod.rs +++ b/crates/bevy_core_pipeline/src/bloom/mod.rs @@ -20,7 +20,7 @@ use bevy_render::{ }, prelude::Color, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, - render_resource::{BindGroupEntries, *}, + render_resource::*, renderer::{RenderContext, RenderDevice}, texture::{CachedTexture, TextureCache}, view::ViewTarget, diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index e937fb6af5286..b45e38fe0cedc 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -14,7 +14,7 @@ use bevy_render::{ mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout}, render_asset::RenderAssets, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, - render_resource::{BindGroupEntries, *}, + render_resource::*, renderer::{RenderDevice, RenderQueue}, texture::{ BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 11e3c25b974d8..3904d98ef5c15 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -6,7 +6,7 @@ use bevy::{ reflect::{TypePath, TypeUuid}, render::{ render_asset::RenderAssets, - render_resource::{AsBindGroupError, BindGroupEntries, PreparedBindGroup, *}, + render_resource::*, renderer::RenderDevice, texture::FallbackImage, RenderApp, From 117637223272a631a7981f0d7f4f00f51a663d09 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 6 Sep 2023 00:45:11 +0100 Subject: [PATCH 18/29] fmt --- examples/shader/texture_binding_array.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 3904d98ef5c15..eb37c9d3249e4 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -5,11 +5,8 @@ use bevy::{ prelude::*, reflect::{TypePath, TypeUuid}, render::{ - render_asset::RenderAssets, - render_resource::*, - renderer::RenderDevice, - texture::FallbackImage, - RenderApp, + render_asset::RenderAssets, render_resource::*, renderer::RenderDevice, + texture::FallbackImage, RenderApp, }, }; use std::{num::NonZeroU32, process::exit}; From 3afbb440d3b32bce1c3dc78ba8e9f7e087875cc8 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 20 Sep 2023 09:48:25 +0100 Subject: [PATCH 19/29] use indices for mesh view bind group --- crates/bevy_pbr/src/render/mesh.rs | 65 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index d4abc19a5ab6d..ad632201d47fa 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -1212,8 +1212,8 @@ pub fn prepare_mesh_view_bind_groups( ) { for ( entity, - view_shadow_bindings, - view_cluster_bindings, + shadow_bindings, + cluster_bindings, ssao_textures, prepass_textures, environment_map, @@ -1224,6 +1224,9 @@ pub fn prepare_mesh_view_bind_groups( .image_for_samplecount(1) .texture_view .clone(); + let ssao_view = ssao_textures + .map(|t| &t.screen_space_ambient_occlusion_texture.default_view) + .unwrap_or(&fallback_ssao); let layout = if msaa.samples() > 1 { &mesh_pipeline.view_layout_multisampled @@ -1231,49 +1234,45 @@ pub fn prepare_mesh_view_bind_groups( &mesh_pipeline.view_layout }; - let mut entries = DynamicBindGroupEntries::sequential(( - // 0 - view_binding.clone(), - light_binding.clone(), - &view_shadow_bindings.point_light_depth_texture_view, - &shadow_samplers.point_light_sampler, - &view_shadow_bindings.directional_light_depth_texture_view, - // 5 - &shadow_samplers.directional_light_sampler, - point_light_binding.clone(), - view_cluster_bindings.light_index_lists_binding().unwrap(), - view_cluster_bindings.offsets_and_counts_binding().unwrap(), - globals.clone(), - // 10 - fog_binding.clone(), - ssao_textures - .map(|t| &t.screen_space_ambient_occlusion_texture.default_view) - .unwrap_or(&fallback_ssao), + let mut entries = DynamicBindGroupEntries::new_with_indices(( + (0, view_binding.clone()), + (1, light_binding.clone()), + (2, &shadow_bindings.point_light_depth_texture_view), + (3, &shadow_samplers.point_light_sampler), + (4, &shadow_bindings.directional_light_depth_texture_view), + (5, &shadow_samplers.directional_light_sampler), + (6, point_light_binding.clone()), + (7, cluster_bindings.light_index_lists_binding().unwrap()), + (8, cluster_bindings.offsets_and_counts_binding().unwrap()), + (9, globals.clone()), + (10, fog_binding.clone()), + (11, ssao_view), )); - // 12 - 14 - entries = entries.extend_sequential(environment_map::get_bindings( - environment_map, - &images, - &fallback_cubemap, + let env_map_bindings = + environment_map::get_bindings(environment_map, &images, &fallback_cubemap); + entries = entries.extend_with_indices(( + (12, env_map_bindings.0), + (13, env_map_bindings.1), + (14, env_map_bindings.2), )); - // 15 - 16 - entries = entries.extend_sequential(get_lut_bindings( - &images, - &tonemapping_luts, - tonemapping, - )); + let lut_bindings = get_lut_bindings(&images, &tonemapping_luts, tonemapping); + entries = entries.extend_with_indices(((15, lut_bindings.0), (16, lut_bindings.1))); // When using WebGL, we can't have a depth texture with multisampling if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || msaa.samples() == 1 { - // 17 - 19 - entries = entries.extend_sequential(prepass::get_bindings( + let prepass_bindings = prepass::get_bindings( prepass_textures, &mut fallback_images, &mut fallback_depths, &msaa, + ); + entries = entries.extend_with_indices(( + (17, prepass_bindings.0), + (18, prepass_bindings.1), + (19, prepass_bindings.2), )); } From 6f98c9aad617d27d76b14bee08db63694d095f2f Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:38:14 +0100 Subject: [PATCH 20/29] merge merge --- .../src/deferred/copy_lighting_id.rs | 25 ++++++++---------- crates/bevy_pbr/src/deferred/mod.rs | 18 ++++++------- crates/bevy_pbr/src/prepass/mod.rs | 26 +++++++++++-------- crates/bevy_pbr/src/render/mesh.rs | 16 +++++------- 4 files changed, 41 insertions(+), 44 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 5609896045ec8..9c4689d51dde2 100644 --- a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs +++ b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs @@ -19,8 +19,7 @@ use bevy_ecs::query::QueryItem; use bevy_render::{ render_graph::{NodeRunError, RenderGraphContext, ViewNode}, render_resource::{ - BindGroupDescriptor, BindGroupEntry, BindingResource, Operations, PipelineCache, - RenderPassDescriptor, + BindGroupEntry, BindingResource, Operations, PipelineCache, RenderPassDescriptor, }, renderer::RenderContext, }; @@ -94,18 +93,16 @@ impl ViewNode for CopyDeferredLightingIdNode { return Ok(()); }; - let bind_group = render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: Some("copy_deferred_lighting_id_bind_group"), - layout: ©_deferred_lighting_id_pipeline.layout, - entries: &[BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &deferred_lighting_pass_id_texture.default_view, - ), - }], - }); + let bind_group = render_context.render_device().create_bind_group( + "copy_deferred_lighting_id_bind_group", + ©_deferred_lighting_id_pipeline.layout, + &[BindGroupEntry { + binding: 0, + resource: BindingResource::TextureView( + &deferred_lighting_pass_id_texture.default_view, + ), + }], + ); let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor { label: Some("copy_deferred_lighting_id_pass"), diff --git a/crates/bevy_pbr/src/deferred/mod.rs b/crates/bevy_pbr/src/deferred/mod.rs index 568be134be18a..244c4c9b24f46 100644 --- a/crates/bevy_pbr/src/deferred/mod.rs +++ b/crates/bevy_pbr/src/deferred/mod.rs @@ -191,16 +191,14 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode { return Ok(()); }; - let bind_group_1 = render_context - .render_device() - .create_bind_group(&BindGroupDescriptor { - label: Some("deferred_lighting_layout_group_1"), - layout: &deferred_lighting_layout.bind_group_layout_1, - entries: &[BindGroupEntry { - binding: 0, - resource: deferred_lighting_pass_id_binding.clone(), - }], - }); + let bind_group_1 = render_context.render_device().create_bind_group( + "deferred_lighting_layout_group_1", + &deferred_lighting_layout.bind_group_layout_1, + &[BindGroupEntry { + binding: 0, + resource: deferred_lighting_pass_id_binding.clone(), + }], + ); let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor { label: Some("deferred_lighting_pass"), diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 0167f5ed65926..0314aa7ae3cae 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -32,12 +32,12 @@ use bevy_render::{ }, render_resource::{ BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingResource, BindingType, BlendState, BufferBindingType, - ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, - DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, PipelineCache, - PolygonMode, PrimitiveState, PushConstantRange, RenderPipelineDescriptor, Shader, - ShaderRef, ShaderStages, ShaderType, SpecializedMeshPipeline, SpecializedMeshPipelineError, - SpecializedMeshPipelines, StencilFaceState, StencilState, TextureAspect, TextureFormat, TextureSampleType, + BindGroupLayoutEntry, BindingType, BufferBindingType, ColorTargetState, ColorWrites, + CompareFunction, DepthBiasState, DepthStencilState, DynamicUniformBuffer, FragmentState, + FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, + RenderPipelineDescriptor, Shader, ShaderRef, ShaderStages, ShaderType, + SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines, + StencilFaceState, StencilState, TextureAspect, TextureFormat, TextureSampleType, TextureView, TextureViewDescriptor, TextureViewDimension, VertexState, }, renderer::{RenderDevice, RenderQueue}, @@ -688,9 +688,9 @@ pub fn get_bind_group_layout_entries( pub fn get_bindings<'a>( prepass_textures: Option<&'a ViewPrepassTextures>, - fallback_images: &'a mut FallbackImagesMsaa, + fallback_images: &'a mut FallbackImageMsaa, msaa: &'a Msaa, -) -> (&'a TextureView, &'a TextureView, &'a TextureView, &'a TextureView) { +) -> [TextureView; 4] { let depth_desc = TextureViewDescriptor { label: Some("prepass_depth"), aspect: TextureAspect::DepthOnly, @@ -701,6 +701,7 @@ pub fn get_bindings<'a>( Some(texture) => texture.texture.create_view(&depth_desc), None => fallback_images .image_for_samplecount(msaa.samples(), CORE_3D_DEPTH_FORMAT) + .clone() .texture .create_view(&depth_desc), }; @@ -712,12 +713,14 @@ pub fn get_bindings<'a>( let normal_view = match prepass_textures.and_then(|x| x.normal.as_ref()) { Some(texture) => &texture.default_view, None => normal_motion_vectors_fallback, - }; + } + .clone(); let motion_vectors_view = match prepass_textures.and_then(|x| x.motion_vectors.as_ref()) { Some(texture) => &texture.default_view, None => normal_motion_vectors_fallback, - }; + } + .clone(); let deferred_fallback = &fallback_images .image_for_samplecount(1, TextureFormat::Rgba32Uint) @@ -727,8 +730,9 @@ pub fn get_bindings<'a>( Some(texture) => &texture.default_view, None => deferred_fallback, } + .clone(); - (depth_view, normal_view, motion_vectors_view, deferred_view) + [depth_view, normal_view, motion_vectors_view, deferred_view] } // Extract the render phases for the prepass diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index c33e9c3ff0e90..de62078774b5c 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -1184,19 +1184,17 @@ pub fn prepare_mesh_view_bind_groups( let lut_bindings = get_lut_bindings(&images, &tonemapping_luts, tonemapping); entries = entries.extend_with_indices(((15, lut_bindings.0), (16, lut_bindings.1))); + let prepass_bindings; // When using WebGL, we can't have a depth texture with multisampling if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || msaa.samples() == 1 { - let prepass_bindings = prepass::get_bindings( - prepass_textures, - &mut fallback_images, - &msaa, - ); + prepass_bindings = + prepass::get_bindings(prepass_textures, &mut fallback_images, &msaa); entries = entries.extend_with_indices(( - (17, prepass_bindings.0), - (18, prepass_bindings.1), - (19, prepass_bindings.2), - (20, prepass_bindings.3), + (17, &prepass_bindings[0]), + (18, &prepass_bindings[1]), + (19, &prepass_bindings[2]), + (20, &prepass_bindings[3]), )); } From b070027d93f99efbc3ba9f6c543661c3e6e1b9de Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:45:09 +0100 Subject: [PATCH 21/29] merge that merged merge till its really merged --- crates/bevy_render/src/render_resource/bind_group.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/bevy_render/src/render_resource/bind_group.rs b/crates/bevy_render/src/render_resource/bind_group.rs index c4de9cb1b6089..8ee876b9c5208 100644 --- a/crates/bevy_render/src/render_resource/bind_group.rs +++ b/crates/bevy_render/src/render_resource/bind_group.rs @@ -9,10 +9,7 @@ use crate::{ pub use bevy_render_macros::AsBindGroup; use encase::ShaderType; use std::ops::Deref; -use wgpu::{ - BindGroupDescriptor, BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, - BindingResource, -}; +use wgpu::{BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource}; define_atomic_id!(BindGroupId); render_resource_wrapper!(ErasedBindGroup, wgpu::BindGroup); @@ -289,11 +286,7 @@ pub trait AsBindGroup { }) .collect::>(); - let bind_group = render_device.create_bind_group(&BindGroupDescriptor { - label: Self::label(), - layout, - entries: &entries, - }); + let bind_group = render_device.create_bind_group(Self::label(), layout, &entries); Ok(PreparedBindGroup { bindings, From 3c17ffc397495a79e975463dcc31436270103b15 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:50:41 +0100 Subject: [PATCH 22/29] add more IntoBinding impls Co-authored-by: IceSentry --- .../src/render_resource/bind_group_entries.rs | 7 +++++++ .../bevy_render/src/render_resource/uniform_buffer.rs | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index b6c17df979e16..f1c7176dc5f18 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -135,6 +135,13 @@ impl<'a> IntoBinding<'a> for BindingResource<'a> { } } +impl<'a> IntoBinding<'a> for wgpu::BufferBinding<'a> { + #[inline] + fn into_binding(self) -> BindingResource<'a> { + BindingResource::Buffer(self) + } +} + pub trait IntoBindingArray<'b, const N: usize> { fn into_array(self) -> [BindingResource<'b>; N]; } diff --git a/crates/bevy_render/src/render_resource/uniform_buffer.rs b/crates/bevy_render/src/render_resource/uniform_buffer.rs index 94c54f9b09ccf..692895c331e26 100644 --- a/crates/bevy_render/src/render_resource/uniform_buffer.rs +++ b/crates/bevy_render/src/render_resource/uniform_buffer.rs @@ -141,6 +141,17 @@ impl UniformBuffer { } } +impl<'a, T: ShaderType + WriteInto> IntoBinding<'a> for &'a UniformBuffer { + #[inline] + fn into_binding(self) -> BindingResource<'a> { + BindingResource::Buffer( + self.buffer() + .expect("Failed to get buffer") + .as_entire_buffer_binding(), + ) + } +} + /// Stores data to be transferred to the GPU and made accessible to shaders as a dynamic uniform buffer. /// /// Dynamic uniform buffers are available to shaders on a read-only basis. Dynamic uniform buffers are commonly used to make From 3875480e78598936a025789e47b14a81d864f1d1 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:03:40 +0100 Subject: [PATCH 23/29] Update crates/bevy_render/src/render_resource/uniform_buffer.rs Co-authored-by: IceSentry --- crates/bevy_render/src/render_resource/uniform_buffer.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/bevy_render/src/render_resource/uniform_buffer.rs b/crates/bevy_render/src/render_resource/uniform_buffer.rs index 692895c331e26..accf89c8f895d 100644 --- a/crates/bevy_render/src/render_resource/uniform_buffer.rs +++ b/crates/bevy_render/src/render_resource/uniform_buffer.rs @@ -144,11 +144,10 @@ impl UniformBuffer { impl<'a, T: ShaderType + WriteInto> IntoBinding<'a> for &'a UniformBuffer { #[inline] fn into_binding(self) -> BindingResource<'a> { - BindingResource::Buffer( - self.buffer() - .expect("Failed to get buffer") - .as_entire_buffer_binding(), - ) + self.buffer() + .expect("Failed to get buffer") + .as_entire_buffer_binding() + .into_binding(), } } From 3f0e1214805488ea01d36b90e4ae8471e4472307 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:08:04 +0100 Subject: [PATCH 24/29] bad comma --- crates/bevy_render/src/render_resource/uniform_buffer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/render_resource/uniform_buffer.rs b/crates/bevy_render/src/render_resource/uniform_buffer.rs index accf89c8f895d..95196568ff20a 100644 --- a/crates/bevy_render/src/render_resource/uniform_buffer.rs +++ b/crates/bevy_render/src/render_resource/uniform_buffer.rs @@ -147,7 +147,7 @@ impl<'a, T: ShaderType + WriteInto> IntoBinding<'a> for &'a UniformBuffer { self.buffer() .expect("Failed to get buffer") .as_entire_buffer_binding() - .into_binding(), + .into_binding() } } From 31bd9fcba1fd5642c53cd1d375a2f3282ed0241d Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:31:49 +0100 Subject: [PATCH 25/29] add/use BindGroupEntries::single --- .../src/deferred/copy_lighting_id.rs | 11 ++---- crates/bevy_gizmos/src/lib.rs | 7 ++-- crates/bevy_pbr/src/deferred/mod.rs | 5 +-- .../src/render_resource/bind_group_entries.rs | 35 ++++++++++++++++++- crates/bevy_render/src/view/window/mod.rs | 9 +++-- crates/bevy_sprite/src/mesh2d/mesh.rs | 5 +-- crates/bevy_sprite/src/render/mod.rs | 5 +-- crates/bevy_ui/src/render/mod.rs | 5 +-- .../shader/compute_shader_game_of_life.rs | 5 +-- 9 files changed, 47 insertions(+), 40 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 9c4689d51dde2..c60306286900a 100644 --- a/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs +++ b/crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs @@ -18,9 +18,7 @@ use bevy_render::{ use bevy_ecs::query::QueryItem; use bevy_render::{ render_graph::{NodeRunError, RenderGraphContext, ViewNode}, - render_resource::{ - BindGroupEntry, BindingResource, Operations, PipelineCache, RenderPassDescriptor, - }, + render_resource::{Operations, PipelineCache, RenderPassDescriptor}, renderer::RenderContext, }; @@ -96,12 +94,7 @@ impl ViewNode for CopyDeferredLightingIdNode { let bind_group = render_context.render_device().create_bind_group( "copy_deferred_lighting_id_bind_group", ©_deferred_lighting_id_pipeline.layout, - &[BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView( - &deferred_lighting_pass_id_texture.default_view, - ), - }], + &BindGroupEntries::single(&deferred_lighting_pass_id_texture.default_view), ); let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor { diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 7b4be075f2897..446605b43e4f8 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -52,7 +52,7 @@ use bevy_render::{ render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::{ - BindGroup, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, Buffer, BufferBindingType, BufferInitDescriptor, BufferUsages, Shader, ShaderStages, ShaderType, VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode, @@ -425,10 +425,7 @@ fn prepare_line_gizmo_bind_group( bindgroup: render_device.create_bind_group( "LineGizmoUniform bindgroup", &line_gizmo_uniform_layout.layout, - &[BindGroupEntry { - binding: 0, - resource: binding, - }], + &BindGroupEntries::single(binding), ), }); } diff --git a/crates/bevy_pbr/src/deferred/mod.rs b/crates/bevy_pbr/src/deferred/mod.rs index 244c4c9b24f46..7aea5ab78554d 100644 --- a/crates/bevy_pbr/src/deferred/mod.rs +++ b/crates/bevy_pbr/src/deferred/mod.rs @@ -194,10 +194,7 @@ impl ViewNode for DeferredOpaquePass3dPbrLightingNode { let bind_group_1 = render_context.render_device().create_bind_group( "deferred_lighting_layout_group_1", &deferred_lighting_layout.bind_group_layout_1, - &[BindGroupEntry { - binding: 0, - resource: deferred_lighting_pass_id_binding.clone(), - }], + &BindGroupEntries::single(deferred_lighting_pass_id_binding), ); let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor { diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index f1c7176dc5f18..83fb9be53a444 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -66,9 +66,33 @@ use super::{Sampler, TextureView}; /// }, /// ], /// ); +/// +/// or +/// +/// ```ignore +/// render_device.create_bind_group( +/// "my_bind_group", +/// &my_layout, +/// &BindGroupEntries::single(my_uniform), +/// ); +/// ``` +/// +/// instead of +/// +/// ```ignore +/// render_device.create_bind_group( +/// "my_bind_group", +/// &my_layout, +/// &[ +/// BindGroupEntry { +/// binding: 0, +/// resource: my_uniform, +/// }, +/// ], +/// ); /// ``` -pub struct BindGroupEntries<'b, const N: usize> { +pub struct BindGroupEntries<'b, const N: usize = 1> { entries: [BindGroupEntry<'b>; N], } @@ -95,6 +119,15 @@ impl<'b, const N: usize> BindGroupEntries<'b, N> { } } +impl<'b> BindGroupEntries<'b, 1> { + pub fn single(resource: impl IntoBinding<'b>) -> [BindGroupEntry<'b>; 1] { + [BindGroupEntry { + binding: 0, + resource: resource.into_binding(), + }] + } +} + impl<'b, const N: usize> std::ops::Deref for BindGroupEntries<'b, N> { type Target = [BindGroupEntry<'b>]; diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index 9412cdc59eac3..31ac4fca2cee3 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -1,5 +1,7 @@ use crate::{ - render_resource::{PipelineCache, SpecializedRenderPipelines, SurfaceTexture, TextureView}, + render_resource::{ + BindGroupEntries, PipelineCache, SpecializedRenderPipelines, SurfaceTexture, TextureView, + }, renderer::{RenderAdapter, RenderDevice, RenderInstance}, texture::TextureFormatPixelInfo, Extract, ExtractSchedule, Render, RenderApp, RenderSet, @@ -416,10 +418,7 @@ pub fn prepare_windows( let bind_group = render_device.create_bind_group( "screenshot-to-screen-bind-group", &screenshot_pipeline.bind_group_layout, - &[wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView(&texture_view), - }], + &BindGroupEntries::single(&texture_view), ); let pipeline_id = pipelines.specialize( &pipeline_cache, diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 059b34109e5bd..df5e4f0594011 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -599,10 +599,7 @@ pub fn prepare_mesh2d_bind_group( value: render_device.create_bind_group( "mesh2d_bind_group", &mesh2d_pipeline.mesh_layout, - &[BindGroupEntry { - binding: 0, - resource: binding, - }], + &BindGroupEntries::single(binding), ), }); } diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 2d25232a9ccae..bebdbad231393 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -626,10 +626,7 @@ pub fn prepare_sprites( sprite_meta.view_bind_group = Some(render_device.create_bind_group( "sprite_view_bind_group", &sprite_pipeline.view_layout, - &[BindGroupEntry { - binding: 0, - resource: view_binding, - }], + &BindGroupEntries::single(view_binding), )); // Index buffer indices diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 4dfe21256aa02..a7a52c628319e 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -815,10 +815,7 @@ pub fn prepare_uinodes( ui_meta.view_bind_group = Some(render_device.create_bind_group( "ui_view_bind_group", &ui_pipeline.view_layout, - &[BindGroupEntry { - binding: 0, - resource: view_binding, - }], + &BindGroupEntries::single(view_binding), )); // Vertex buffer index diff --git a/examples/shader/compute_shader_game_of_life.rs b/examples/shader/compute_shader_game_of_life.rs index 4b00b38a202f2..2f8a269e592b8 100644 --- a/examples/shader/compute_shader_game_of_life.rs +++ b/examples/shader/compute_shader_game_of_life.rs @@ -110,10 +110,7 @@ fn prepare_bind_group( let bind_group = render_device.create_bind_group( None, &pipeline.texture_bind_group_layout, - &[BindGroupEntry { - binding: 0, - resource: BindingResource::TextureView(&view.texture_view), - }], + &BindGroupEntries::single(&view.texture_view), ); commands.insert_resource(GameOfLifeImageBindGroup(bind_group)); } From 9985276f797007507d06fdca1d30d227afd081ff Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:34:18 +0100 Subject: [PATCH 26/29] remove errant clone --- crates/bevy_pbr/src/prepass/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 0314aa7ae3cae..939c9c80c9cb4 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -701,7 +701,6 @@ pub fn get_bindings<'a>( Some(texture) => texture.texture.create_view(&depth_desc), None => fallback_images .image_for_samplecount(msaa.samples(), CORE_3D_DEPTH_FORMAT) - .clone() .texture .create_view(&depth_desc), }; From e958c26c0bc89389c7f32ef03e39a4fbb19dfbba Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:41:36 +0100 Subject: [PATCH 27/29] ci --- crates/bevy_render/src/render_resource/bind_group_entries.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 83fb9be53a444..64ce317d5cb1a 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -66,7 +66,8 @@ use super::{Sampler, TextureView}; /// }, /// ], /// ); -/// +/// ``` +/// /// or /// /// ```ignore From 6a6a5a876d1e9a61df1ff9a04eb9c81c04d1dd75 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:48:22 +0100 Subject: [PATCH 28/29] ci ci --- crates/bevy_render/src/render_resource/bind_group_entries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/render_resource/bind_group_entries.rs b/crates/bevy_render/src/render_resource/bind_group_entries.rs index 64ce317d5cb1a..09336eeb0a093 100644 --- a/crates/bevy_render/src/render_resource/bind_group_entries.rs +++ b/crates/bevy_render/src/render_resource/bind_group_entries.rs @@ -67,7 +67,7 @@ use super::{Sampler, TextureView}; /// ], /// ); /// ``` -/// +/// /// or /// /// ```ignore From d0727297da2ce8f77c79c6ebfa7168d6c19dcb37 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sat, 21 Oct 2023 15:52:21 +0100 Subject: [PATCH 29/29] fix merge --- crates/bevy_pbr/src/prepass/mod.rs | 2 +- .../bevy_pbr/src/prepass/prepass_bindings.rs | 57 +------ .../bevy_pbr/src/render/mesh_view_bindings.rs | 140 ++++++------------ 3 files changed, 50 insertions(+), 149 deletions(-) diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index f487e9d8fa39b..54155ce385a0e 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -35,7 +35,7 @@ use bevy_render::{ RenderPhase, SetItemPipeline, TrackedRenderPass, }, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, + BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BufferBindingType, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState, DynamicUniformBuffer, FragmentState, FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, diff --git a/crates/bevy_pbr/src/prepass/prepass_bindings.rs b/crates/bevy_pbr/src/prepass/prepass_bindings.rs index acbf80ceabde1..b72ddd1e318cd 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::{ - BindGroupEntry, BindGroupLayoutEntry, BindingResource, BindingType, ShaderStages, - TextureAspect, TextureSampleType, TextureView, TextureViewDescriptor, TextureViewDimension, + BindGroupLayoutEntry, BindingType, ShaderStages, TextureAspect, TextureSampleType, TextureView, + TextureViewDescriptor, TextureViewDimension, }; use bevy_utils::default; use smallvec::SmallVec; @@ -83,51 +83,7 @@ pub fn get_bind_group_layout_entries( result } -// Needed so the texture views can live long enough. -pub struct PrepassBindingsSet { - depth_view: Option, - normal_view: Option, - motion_vectors_view: Option, - deferred_view: Option, -} - -impl PrepassBindingsSet { - pub fn get_entries(&self, bindings: [u32; 4]) -> SmallVec<[BindGroupEntry; 4]> { - let mut result = SmallVec::<[BindGroupEntry; 4]>::new(); - - if let Some(ref depth_view) = self.depth_view { - result.push(BindGroupEntry { - binding: bindings[0], - resource: BindingResource::TextureView(depth_view), - }); - } - - if let Some(ref normal_view) = self.normal_view { - result.push(BindGroupEntry { - binding: bindings[1], - resource: BindingResource::TextureView(normal_view), - }); - } - - if let Some(ref motion_vectors_view) = self.motion_vectors_view { - result.push(BindGroupEntry { - binding: bindings[2], - resource: BindingResource::TextureView(motion_vectors_view), - }); - } - - if let Some(ref deferred_view) = self.deferred_view { - result.push(BindGroupEntry { - binding: bindings[3], - resource: BindingResource::TextureView(deferred_view), - }); - } - - result - } -} - -pub fn get_bindings(prepass_textures: Option<&ViewPrepassTextures>) -> PrepassBindingsSet { +pub fn get_bindings(prepass_textures: Option<&ViewPrepassTextures>) -> [Option; 4] { let depth_desc = TextureViewDescriptor { label: Some("prepass_depth"), aspect: TextureAspect::DepthOnly, @@ -149,10 +105,5 @@ pub fn get_bindings(prepass_textures: Option<&ViewPrepassTextures>) -> PrepassBi .and_then(|x| x.deferred.as_ref()) .map(|texture| texture.default_view.clone()); - PrepassBindingsSet { - depth_view, - normal_view, - motion_vectors_view, - deferred_view, - } + [depth_view, normal_view, motion_vectors_view, deferred_view] } diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index 8ed474769525f..ba66561c6d785 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -15,9 +15,9 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, render_asset::RenderAssets, render_resource::{ - BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingResource, BindingType, BufferBindingType, SamplerBindingType, - ShaderStages, ShaderType, TextureFormat, TextureSampleType, TextureViewDimension, + BindGroup, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, + BufferBindingType, DynamicBindGroupEntries, SamplerBindingType, ShaderStages, ShaderType, + TextureFormat, TextureSampleType, TextureViewDimension, }, renderer::RenderDevice, texture::{BevyDefault, FallbackImageCubemap, FallbackImageMsaa, Image}, @@ -383,8 +383,8 @@ pub fn prepare_mesh_view_bind_groups( ) { for ( entity, - view_shadow_bindings, - view_cluster_bindings, + shadow_bindings, + cluster_bindings, ssao_textures, prepass_textures, environment_map, @@ -395,108 +395,58 @@ pub fn prepare_mesh_view_bind_groups( .image_for_samplecount(1, TextureFormat::bevy_default()) .texture_view .clone(); + let ssao_view = ssao_textures + .map(|t| &t.screen_space_ambient_occlusion_texture.default_view) + .unwrap_or(&fallback_ssao); let layout = &mesh_pipeline.get_view_layout( MeshPipelineViewLayoutKey::from(*msaa) | MeshPipelineViewLayoutKey::from(prepass_textures), ); - let mut entries = vec![ - BindGroupEntry { - binding: 0, - resource: view_binding.clone(), - }, - BindGroupEntry { - binding: 1, - resource: light_binding.clone(), - }, - BindGroupEntry { - binding: 2, - resource: BindingResource::TextureView( - &view_shadow_bindings.point_light_depth_texture_view, - ), - }, - BindGroupEntry { - binding: 3, - resource: BindingResource::Sampler(&shadow_samplers.point_light_sampler), - }, - BindGroupEntry { - binding: 4, - resource: BindingResource::TextureView( - &view_shadow_bindings.directional_light_depth_texture_view, - ), - }, - BindGroupEntry { - binding: 5, - resource: BindingResource::Sampler(&shadow_samplers.directional_light_sampler), - }, - BindGroupEntry { - binding: 6, - resource: point_light_binding.clone(), - }, - BindGroupEntry { - binding: 7, - resource: view_cluster_bindings.light_index_lists_binding().unwrap(), - }, - BindGroupEntry { - binding: 8, - resource: view_cluster_bindings.offsets_and_counts_binding().unwrap(), - }, - BindGroupEntry { - binding: 9, - resource: globals.clone(), - }, - BindGroupEntry { - binding: 10, - resource: fog_binding.clone(), - }, - BindGroupEntry { - binding: 11, - resource: BindingResource::TextureView( - ssao_textures - .map(|t| &t.screen_space_ambient_occlusion_texture.default_view) - .unwrap_or(&fallback_ssao), - ), - }, - ]; - - let env_map = environment_map::get_bindings( - environment_map, - &images, - &fallback_cubemap, - [12, 13, 14], - ); - entries.extend_from_slice(&env_map); - - let tonemapping_luts = - get_lut_bindings(&images, &tonemapping_luts, tonemapping, [15, 16]); - entries.extend_from_slice(&tonemapping_luts); - - let label = Some("mesh_view_bind_group"); + let mut entries = DynamicBindGroupEntries::new_with_indices(( + (0, view_binding.clone()), + (1, light_binding.clone()), + (2, &shadow_bindings.point_light_depth_texture_view), + (3, &shadow_samplers.point_light_sampler), + (4, &shadow_bindings.directional_light_depth_texture_view), + (5, &shadow_samplers.directional_light_sampler), + (6, point_light_binding.clone()), + (7, cluster_bindings.light_index_lists_binding().unwrap()), + (8, cluster_bindings.offsets_and_counts_binding().unwrap()), + (9, globals.clone()), + (10, fog_binding.clone()), + (11, ssao_view), + )); + + let env_map_bindings = + environment_map::get_bindings(environment_map, &images, &fallback_cubemap); + entries = entries.extend_with_indices(( + (12, env_map_bindings.0), + (13, env_map_bindings.1), + (14, env_map_bindings.2), + )); + + let lut_bindings = get_lut_bindings(&images, &tonemapping_luts, tonemapping); + entries = entries.extend_with_indices(((15, lut_bindings.0), (16, lut_bindings.1))); // When using WebGL, we can't have a depth texture with multisampling - let prepass_bindings = if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) - || (cfg!(all(feature = "webgl", target_arch = "wasm32")) && msaa.samples() == 1) + let prepass_bindings; + if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32"))) || msaa.samples() == 1 { - Some(prepass::get_bindings(prepass_textures)) - } else { - None - }; - - // This if statement is here to make the borrow checker happy. - // Ideally we could just have `entries.extend_from_slice(&prepass_bindings.get_entries([17, 18, 19, 20]));` - // in the existing if statement above, but that either doesn't allow `prepass_bindings` to live long enough, - // as its used when creating the bind group at the end of the function, or causes a `cannot move out of` error. - if let Some(prepass_bindings) = &prepass_bindings { - entries.extend_from_slice(&prepass_bindings.get_entries([17, 18, 19, 20])); + prepass_bindings = prepass::get_bindings(prepass_textures); + for (binding, index) in prepass_bindings + .iter() + .map(Option::as_ref) + .zip([17, 18, 19, 20]) + .flat_map(|(b, i)| b.map(|b| (b, i))) + { + entries = entries.extend_with_indices(((index, binding),)); + } } commands.entity(entity).insert(MeshViewBindGroup { - value: render_device.create_bind_group(&BindGroupDescriptor { - entries: &entries, - label, - layout, - }), + value: render_device.create_bind_group("mesh_view_bind_group", layout, &entries), }); } }