From 51bca0e283cf0782ad9a9d8f867640ae08fe1da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Kry=C5=84ski?= Date: Thu, 5 Nov 2020 10:12:53 +0100 Subject: [PATCH] use RenderPipeline::new, update dynamic_bindings --- crates/bevy_pbr/src/entity.rs | 5 ++--- crates/bevy_render/src/draw.rs | 2 +- .../bevy_render/src/pipeline/pipeline_compiler.rs | 6 ++++-- .../bevy_render/src/pipeline/render_pipelines.rs | 4 ++-- crates/bevy_sprite/src/entity.rs | 8 +++----- crates/bevy_text/src/draw.rs | 2 +- crates/bevy_ui/src/entity.rs | 11 ++++------- examples/shader/mesh_custom_attribute.rs | 15 ++------------- examples/shader/shader_custom_material.rs | 6 ++---- examples/shader/shader_defs.rs | 8 ++------ 10 files changed, 23 insertions(+), 44 deletions(-) diff --git a/crates/bevy_pbr/src/entity.rs b/crates/bevy_pbr/src/entity.rs index 45424734a31b3..eab323b091c9b 100644 --- a/crates/bevy_pbr/src/entity.rs +++ b/crates/bevy_pbr/src/entity.rs @@ -4,7 +4,7 @@ use bevy_ecs::Bundle; use bevy_render::{ draw::Draw, mesh::Mesh, - pipeline::{PipelineSpecialization, RenderPipeline, RenderPipelines}, + pipeline::{RenderPipeline, RenderPipelines}, render_graph::base::MainPass, }; use bevy_transform::prelude::{GlobalTransform, Transform}; @@ -24,9 +24,8 @@ pub struct PbrComponents { impl Default for PbrComponents { fn default() -> Self { Self { - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( FORWARD_PIPELINE_HANDLE, - PipelineSpecialization::default(), )]), mesh: Default::default(), material: Default::default(), diff --git a/crates/bevy_render/src/draw.rs b/crates/bevy_render/src/draw.rs index 062dfe500ea8d..7748747bbc174 100644 --- a/crates/bevy_render/src/draw.rs +++ b/crates/bevy_render/src/draw.rs @@ -241,7 +241,7 @@ impl<'a> DrawContext<'a> { &mut self, draw: &mut Draw, pipeline_handle: &Handle, - specialization: &PipelineSpecialization, + specialization: &mut PipelineSpecialization, render_resource_bindings: &mut [&mut RenderResourceBindings], ) -> Result<(), DrawError> { let specialized_pipeline = if let Some(specialized_pipeline) = self diff --git a/crates/bevy_render/src/pipeline/pipeline_compiler.rs b/crates/bevy_render/src/pipeline/pipeline_compiler.rs index 7baf1ca4c3104..2c04d4538bea1 100644 --- a/crates/bevy_render/src/pipeline/pipeline_compiler.rs +++ b/crates/bevy_render/src/pipeline/pipeline_compiler.rs @@ -18,6 +18,7 @@ use std::borrow::Cow; pub struct PipelineSpecialization { pub shader_specialization: ShaderSpecialization, pub primitive_topology: PrimitiveTopology, + pub dynamic_bindings: Vec, pub index_format: IndexFormat, pub vertex_buffer_descriptor: VertexBufferDescriptor, pub sample_count: u32, @@ -30,6 +31,7 @@ impl Default for PipelineSpecialization { index_format: IndexFormat::Uint32, shader_specialization: Default::default(), primitive_topology: Default::default(), + dynamic_bindings: Default::default(), vertex_buffer_descriptor: Default::default(), } } @@ -134,7 +136,7 @@ impl PipelineCompiler { pipelines: &mut Assets, shaders: &mut Assets, source_pipeline: &Handle, - pipeline_specialization: &PipelineSpecialization, + pipeline_specialization: &mut PipelineSpecialization, render_resource_bindings: &mut [&mut RenderResourceBindings], ) -> Handle { let source_descriptor = pipelines.get(source_pipeline).unwrap(); @@ -185,7 +187,7 @@ impl PipelineCompiler { } } } - + pipeline_specialization.dynamic_bindings = dynamic_bindings; specialized_descriptor.layout = Some(layout); // create a vertex layout that provides all attributes from either the specialized vertex buffers or a zero buffer diff --git a/crates/bevy_render/src/pipeline/render_pipelines.rs b/crates/bevy_render/src/pipeline/render_pipelines.rs index 6bc150ec51e01..acf71d6370a29 100644 --- a/crates/bevy_render/src/pipeline/render_pipelines.rs +++ b/crates/bevy_render/src/pipeline/render_pipelines.rs @@ -103,7 +103,7 @@ pub fn draw_render_pipelines_system( // TODO: move these to mesh.rs? } - for render_pipeline in render_pipelines.pipelines.iter() { + for render_pipeline in render_pipelines.pipelines.iter_mut() { let render_resource_bindings = &mut [ &mut render_pipelines.bindings, &mut render_resource_bindings, @@ -112,7 +112,7 @@ pub fn draw_render_pipelines_system( .set_pipeline( &mut draw, &render_pipeline.pipeline, - &render_pipeline.specialization, + &mut render_pipeline.specialization, render_resource_bindings, ) .unwrap(); diff --git a/crates/bevy_sprite/src/entity.rs b/crates/bevy_sprite/src/entity.rs index 0a07ebcd74ae0..2296796a23450 100644 --- a/crates/bevy_sprite/src/entity.rs +++ b/crates/bevy_sprite/src/entity.rs @@ -6,7 +6,7 @@ use bevy_asset::Handle; use bevy_ecs::Bundle; use bevy_render::{ mesh::Mesh, - pipeline::{PipelineSpecialization, RenderPipeline, RenderPipelines}, + pipeline::{RenderPipeline, RenderPipelines}, prelude::Draw, render_graph::base::MainPass, }; @@ -28,9 +28,8 @@ impl Default for SpriteComponents { fn default() -> Self { Self { mesh: QUAD_HANDLE, - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( SPRITE_PIPELINE_HANDLE, - PipelineSpecialization::default(), )]), draw: Draw { is_transparent: true, @@ -65,9 +64,8 @@ pub struct SpriteSheetComponents { impl Default for SpriteSheetComponents { fn default() -> Self { Self { - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( SPRITE_SHEET_PIPELINE_HANDLE, - PipelineSpecialization::default(), )]), draw: Draw { is_transparent: true, diff --git a/crates/bevy_text/src/draw.rs b/crates/bevy_text/src/draw.rs index 74219f3c5e381..cf9d13e9176ee 100644 --- a/crates/bevy_text/src/draw.rs +++ b/crates/bevy_text/src/draw.rs @@ -49,7 +49,7 @@ impl<'a> Drawable for DrawableText<'a> { context.set_pipeline( draw, &bevy_sprite::SPRITE_SHEET_PIPELINE_HANDLE, - &PipelineSpecialization { + &mut PipelineSpecialization { sample_count: self.msaa.samples, vertex_buffer_descriptor: self.font_quad_vertex_descriptor.clone(), ..Default::default() diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index d1335abce0b35..a0c050e7aafc8 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -11,7 +11,7 @@ use bevy_render::{ camera::{Camera, OrthographicProjection, VisibleEntities, WindowOrigin}, draw::Draw, mesh::Mesh, - pipeline::{PipelineSpecialization, RenderPipeline, RenderPipelines}, + pipeline::{RenderPipeline, RenderPipelines}, }; use bevy_sprite::{ColorMaterial, QUAD_HANDLE}; use bevy_transform::prelude::{GlobalTransform, Transform}; @@ -32,9 +32,8 @@ impl Default for NodeComponents { fn default() -> Self { NodeComponents { mesh: QUAD_HANDLE, - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( UI_PIPELINE_HANDLE, - PipelineSpecialization::default(), )]), node: Default::default(), style: Default::default(), @@ -64,9 +63,8 @@ impl Default for ImageComponents { fn default() -> Self { ImageComponents { mesh: QUAD_HANDLE, - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( UI_PIPELINE_HANDLE, - PipelineSpecialization::default(), )]), node: Default::default(), image: Default::default(), @@ -130,9 +128,8 @@ impl Default for ButtonComponents { ButtonComponents { button: Button, mesh: QUAD_HANDLE, - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( UI_PIPELINE_HANDLE, - PipelineSpecialization::default(), )]), interaction: Default::default(), focus_policy: Default::default(), diff --git a/examples/shader/mesh_custom_attribute.rs b/examples/shader/mesh_custom_attribute.rs index c6d3aed93056c..35357d49faa82 100644 --- a/examples/shader/mesh_custom_attribute.rs +++ b/examples/shader/mesh_custom_attribute.rs @@ -2,7 +2,7 @@ use bevy::{ prelude::*, render::{ mesh::{shape, VertexAttributeValues}, - pipeline::{DynamicBinding, PipelineDescriptor, PipelineSpecialization, RenderPipeline}, + pipeline::{PipelineDescriptor, PipelineSpecialization, RenderPipeline}, render_graph::{base, AssetRenderResourcesNode, RenderGraph}, renderer::RenderResources, shader::{ShaderStage, ShaderStages}, @@ -129,19 +129,8 @@ fn setup( // cube .spawn(MeshComponents { mesh: meshes.add(cube_with_vertex_colors), // use our cube with vertex colors - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, - // NOTE: in the future you wont need to manually declare dynamic bindings - PipelineSpecialization { - dynamic_bindings: vec![ - // Transform - DynamicBinding { - bind_group: 1, - binding: 0, - }, - ], - ..Default::default() - }, )]), transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)), ..Default::default() diff --git a/examples/shader/shader_custom_material.rs b/examples/shader/shader_custom_material.rs index 541cf0c3a3821..94bb5b1e4cec6 100644 --- a/examples/shader/shader_custom_material.rs +++ b/examples/shader/shader_custom_material.rs @@ -2,7 +2,7 @@ use bevy::{ prelude::*, render::{ mesh::shape, - pipeline::{PipelineDescriptor, PipelineSpecialization, RenderPipeline}, + pipeline::{PipelineDescriptor, RenderPipeline}, render_graph::{base, AssetRenderResourcesNode, RenderGraph}, renderer::RenderResources, shader::{ShaderStage, ShaderStages}, @@ -85,10 +85,8 @@ fn setup( // cube .spawn(MeshComponents { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, - // NOTE: in the future you wont need to manually declare dynamic bindings - PipelineSpecialization::default(), )]), transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)), ..Default::default() diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index 4bfbcfe4d6ad7..e4ca2a916fb8f 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -106,10 +106,8 @@ fn setup( // cube .spawn(MeshComponents { mesh: cube_handle.clone(), - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle.clone(), - // NOTE: in the future you wont need to manually declare dynamic bindings - PipelineSpecialization::default(), )]), transform: Transform::from_translation(Vec3::new(-2.0, 0.0, 0.0)), ..Default::default() @@ -118,10 +116,8 @@ fn setup( // cube .spawn(MeshComponents { mesh: cube_handle, - render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( + render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, - // NOTE: in the future you wont need to manually declare dynamic bindings - PipelineSpecialization::default(), )]), transform: Transform::from_translation(Vec3::new(2.0, 0.0, 0.0)), ..Default::default()