From 1a410efd246e0f2f41766d47e300f474c8379b2e Mon Sep 17 00:00:00 2001 From: andriyDev Date: Tue, 1 Jul 2025 12:27:42 -0700 Subject: [PATCH] Flatten `PrepassPipelineInternal` into `PrepassPipeline`. (#19909) # Objective - PrepassPipelineInternal used to exist to optimize compile time and binary size when PrepassPipeline was generic over the material. - After #19667, PrepassPipeline is no longer generic! ## Solution - Flatten all the fields of `PrepassPipelineInternal` into `PrepassPipeline`. --- .../src/meshlet/material_pipeline_prepare.rs | 9 ++---- crates/bevy_pbr/src/prepass/mod.rs | 31 ++++++------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs b/crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs index 536451a673..cda93189be 100644 --- a/crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs +++ b/crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs @@ -351,12 +351,9 @@ pub fn prepare_material_meshlet_meshes_prepass( shader_defs.push("MESHLET_MESH_MATERIAL_PASS".into()); let view_layout = if view_key.contains(MeshPipelineKey::MOTION_VECTOR_PREPASS) { - prepass_pipeline.internal.view_layout_motion_vectors.clone() + prepass_pipeline.view_layout_motion_vectors.clone() } else { - prepass_pipeline - .internal - .view_layout_no_motion_vectors - .clone() + prepass_pipeline.view_layout_no_motion_vectors.clone() }; let fragment_shader = if view_key.contains(MeshPipelineKey::DEFERRED_PREPASS) { @@ -381,7 +378,7 @@ pub fn prepare_material_meshlet_meshes_prepass( label: material_pipeline_descriptor.label, layout: vec![ view_layout, - prepass_pipeline.internal.empty_layout.clone(), + prepass_pipeline.empty_layout.clone(), resource_manager.material_shade_bind_group_layout.clone(), material .properties diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index b007242c76..c1def00b18 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -254,14 +254,6 @@ pub fn update_mesh_previous_global_transforms( #[derive(Resource, Clone)] pub struct PrepassPipeline { - pub internal: PrepassPipelineInternal, - pub material_pipeline: MaterialPipeline, -} - -/// Internal fields of the `PrepassPipeline` that don't need the generic bound -/// This is done as an optimization to not recompile the same code multiple time -#[derive(Clone)] -pub struct PrepassPipelineInternal { pub view_layout_motion_vectors: BindGroupLayout, pub view_layout_no_motion_vectors: BindGroupLayout, pub mesh_layouts: MeshLayouts, @@ -277,6 +269,7 @@ pub struct PrepassPipelineInternal { /// Whether binding arrays (a.k.a. bindless textures) are usable on the /// current render device. pub binding_arrays_are_usable: bool, + pub material_pipeline: MaterialPipeline, } impl FromWorld for PrepassPipeline { @@ -339,7 +332,7 @@ impl FromWorld for PrepassPipeline { let depth_clip_control_supported = render_device .features() .contains(WgpuFeatures::DEPTH_CLIP_CONTROL); - let internal = PrepassPipelineInternal { + PrepassPipeline { view_layout_motion_vectors, view_layout_no_motion_vectors, mesh_layouts: mesh_pipeline.mesh_layouts.clone(), @@ -348,9 +341,6 @@ impl FromWorld for PrepassPipeline { depth_clip_control_supported, binding_arrays_are_usable: binding_arrays_are_usable(render_device, render_adapter), empty_layout: render_device.create_bind_group_layout("prepass_empty_layout", &[]), - }; - PrepassPipeline { - internal, material_pipeline: world.resource::().clone(), } } @@ -373,12 +363,9 @@ impl SpecializedMeshPipeline for PrepassPipelineSpecializer { if self.properties.bindless { shader_defs.push("BINDLESS".into()); } - let mut descriptor = self.pipeline.internal.specialize( - key.mesh_key, - shader_defs, - layout, - &self.properties, - )?; + let mut descriptor = + self.pipeline + .specialize(key.mesh_key, shader_defs, layout, &self.properties)?; // This is a bit risky because it's possible to change something that would // break the prepass but be fine in the main pass. @@ -396,7 +383,7 @@ impl SpecializedMeshPipeline for PrepassPipelineSpecializer { } } -impl PrepassPipelineInternal { +impl PrepassPipeline { fn specialize( &self, mesh_key: MeshPipelineKey, @@ -726,7 +713,7 @@ impl FromWorld for PrepassViewBindGroup { let render_device = world.resource::(); let empty_bind_group = render_device.create_bind_group( "prepass_view_empty_bind_group", - &pipeline.internal.empty_layout, + &pipeline.empty_layout, &[], ); PrepassViewBindGroup { @@ -753,7 +740,7 @@ pub fn prepare_prepass_view_bind_group( ) { prepass_view_bind_group.no_motion_vectors = Some(render_device.create_bind_group( "prepass_view_no_motion_vectors_bind_group", - &prepass_pipeline.internal.view_layout_no_motion_vectors, + &prepass_pipeline.view_layout_no_motion_vectors, &BindGroupEntries::with_indices(( (0, view_binding.clone()), (1, globals_binding.clone()), @@ -764,7 +751,7 @@ pub fn prepare_prepass_view_bind_group( if let Some(previous_view_uniforms_binding) = previous_view_uniforms.uniforms.binding() { prepass_view_bind_group.motion_vectors = Some(render_device.create_bind_group( "prepass_view_motion_vectors_bind_group", - &prepass_pipeline.internal.view_layout_motion_vectors, + &prepass_pipeline.view_layout_motion_vectors, &BindGroupEntries::with_indices(( (0, view_binding), (1, globals_binding),