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] 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![],