From 4cf9624b585004bf98a3c14b692e182409e80fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Kry=C5=84ski?= Date: Thu, 22 Oct 2020 08:58:52 +0200 Subject: [PATCH] simplify DynamicBindings declaration --- crates/bevy_pbr/src/entity.rs | 14 ++---- crates/bevy_render/src/lib.rs | 7 ++- .../src/pipeline/pipeline_compiler.rs | 9 +--- .../src/renderer/render_resource_context.rs | 10 ++--- crates/bevy_sprite/src/entity.rs | 29 ++----------- crates/bevy_ui/src/entity.rs | 43 ++----------------- examples/shader/shader_custom_material.rs | 15 +------ examples/shader/shader_defs.rs | 28 ++---------- 8 files changed, 23 insertions(+), 132 deletions(-) diff --git a/crates/bevy_pbr/src/entity.rs b/crates/bevy_pbr/src/entity.rs index 9436025a0f5a39..6ef29f636e1338 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::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines}, + pipeline::{PipelineSpecialization, RenderPipeline, RenderPipelines}, render_graph::base::MainPass, }; use bevy_transform::prelude::{GlobalTransform, Transform}; @@ -28,16 +28,8 @@ impl Default for PbrComponents { FORWARD_PIPELINE_HANDLE, PipelineSpecialization { dynamic_bindings: vec![ - DynamicBinding { - bind_group: 2, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 3, - binding: 0, - name: "StandardMaterial_albedo".to_string(), - }, + "Transform".to_string(), + "StandardMaterial_albedo".to_string(), ], ..Default::default() }, diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index a1dc9ea65b284b..2ef2daba787460 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -37,8 +37,8 @@ use camera::{ ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities, }; use pipeline::{ - DynamicBinding, IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, - PrimitiveTopology, ShaderSpecialization, VertexBufferDescriptors, + IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, PrimitiveTopology, + ShaderSpecialization, VertexBufferDescriptors, }; use render_graph::{ base::{self, BaseRenderGraphBuilder, BaseRenderGraphConfig}, @@ -66,7 +66,7 @@ pub mod stage { /// Adds core render types and systems to an App pub struct RenderPlugin { - /// configures the "base render graph". If this is not `None`, the "base render graph" will be added + /// configures the "base render graph". If this is not `None`, the "base render graph" will be added pub base_render_graph_config: Option, } @@ -112,7 +112,6 @@ impl Plugin for RenderPlugin { .register_property::() .register_property::>() .register_property::() - .register_property::() .register_property::() .register_property::() .register_properties::() diff --git a/crates/bevy_render/src/pipeline/pipeline_compiler.rs b/crates/bevy_render/src/pipeline/pipeline_compiler.rs index 01ef82ee454127..c8294eb483557c 100644 --- a/crates/bevy_render/src/pipeline/pipeline_compiler.rs +++ b/crates/bevy_render/src/pipeline/pipeline_compiler.rs @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize}; pub struct PipelineSpecialization { pub shader_specialization: ShaderSpecialization, pub primitive_topology: PrimitiveTopology, - pub dynamic_bindings: Vec, + pub dynamic_bindings: Vec, pub index_format: IndexFormat, pub sample_count: u32, } @@ -56,13 +56,6 @@ struct SpecializedPipeline { specialization: PipelineSpecialization, } -#[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize, Property)] -pub struct DynamicBinding { - pub bind_group: u32, - pub binding: u32, - pub name: String, -} - #[derive(Debug, Default)] pub struct PipelineCompiler { specialized_shaders: HashMap, Vec>, diff --git a/crates/bevy_render/src/renderer/render_resource_context.rs b/crates/bevy_render/src/renderer/render_resource_context.rs index b19c4b4b05f314..7839ef473a4d17 100644 --- a/crates/bevy_render/src/renderer/render_resource_context.rs +++ b/crates/bevy_render/src/renderer/render_resource_context.rs @@ -1,6 +1,6 @@ use crate::{ pipeline::{ - BindGroupDescriptorId, BindType, DynamicBinding, PipelineDescriptor, PipelineLayout, + BindGroupDescriptorId, BindType, PipelineDescriptor, PipelineLayout, VertexBufferDescriptors, }, renderer::{BindGroup, BufferId, BufferInfo, RenderResourceId, SamplerId, TextureId}, @@ -78,7 +78,7 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static { shader_stages: &ShaderStages, enforce_bevy_conventions: bool, vertex_buffer_descriptors: Option<&VertexBufferDescriptors>, - dynamic_bindings: &[DynamicBinding], + dynamic_bindings: &[String], ) -> PipelineLayout { // TODO: maybe move this default implementation to PipelineLayout? let mut shader_layouts: Vec = shader_stages @@ -97,11 +97,7 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static { for bind_group in layout.bind_groups.iter_mut() { let mut binding_changed = false; for binding in bind_group.bindings.iter_mut() { - let current = (bind_group.index, binding.index); - if dynamic_bindings - .iter() - .any(|b| (b.bind_group, b.binding) == current) - { + if dynamic_bindings.iter().any(|b| b == &binding.name) { if let BindType::Uniform { ref mut dynamic, .. } = binding.bind_type diff --git a/crates/bevy_sprite/src/entity.rs b/crates/bevy_sprite/src/entity.rs index cf772ea870df41..4a456433d866c8 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::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines}, + pipeline::{PipelineSpecialization, RenderPipeline, RenderPipelines}, prelude::Draw, render_graph::base::MainPass, }; @@ -31,20 +31,7 @@ impl Default for SpriteComponents { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( SPRITE_PIPELINE_HANDLE, PipelineSpecialization { - dynamic_bindings: vec![ - // Transform - DynamicBinding { - bind_group: 2, - binding: 0, - name: "Transform".to_string(), - }, - // Sprite - DynamicBinding { - bind_group: 2, - binding: 1, - name: "Sprite_size".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "Sprite_size".to_string()], ..Default::default() }, )]), @@ -85,16 +72,8 @@ impl Default for SpriteSheetComponents { SPRITE_SHEET_PIPELINE_HANDLE, PipelineSpecialization { dynamic_bindings: vec![ - DynamicBinding { - bind_group: 2, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 2, - binding: 1, - name: "TextureAtlasSprite".to_string(), - }, + "Transform".to_string(), + "TextureAtlasSprite".to_string(), ], ..Default::default() }, diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index 7249bb952fce8c..8390c03ca43e2d 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::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines}, + pipeline::{PipelineSpecialization, RenderPipeline, RenderPipelines}, }; use bevy_sprite::{ColorMaterial, QUAD_HANDLE}; use bevy_transform::prelude::{GlobalTransform, Transform}; @@ -35,18 +35,7 @@ impl Default for NodeComponents { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( UI_PIPELINE_HANDLE, PipelineSpecialization { - dynamic_bindings: vec![ - DynamicBinding { - bind_group: 1, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 1, - binding: 1, - name: "Node_size".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "Node_size".to_string()], ..Default::default() }, )]), @@ -81,20 +70,7 @@ impl Default for ImageComponents { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( UI_PIPELINE_HANDLE, PipelineSpecialization { - dynamic_bindings: vec![ - // Transform - DynamicBinding { - bind_group: 1, - binding: 0, - name: "Transform".to_string(), - }, - // Node_size - DynamicBinding { - bind_group: 1, - binding: 1, - name: "Node_size".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "Node_size".to_string()], ..Default::default() }, )]), @@ -163,18 +139,7 @@ impl Default for ButtonComponents { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized( UI_PIPELINE_HANDLE, PipelineSpecialization { - dynamic_bindings: vec![ - DynamicBinding { - bind_group: 1, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 1, - binding: 1, - name: "Node_size".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "Node_size".to_string()], ..Default::default() }, )]), diff --git a/examples/shader/shader_custom_material.rs b/examples/shader/shader_custom_material.rs index d43a202a79f682..6bcfdb5f6d09d3 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::{DynamicBinding, PipelineDescriptor, PipelineSpecialization, RenderPipeline}, + pipeline::{PipelineDescriptor, PipelineSpecialization, RenderPipeline}, render_graph::{base, AssetRenderResourcesNode, RenderGraph}, renderer::RenderResources, shader::{ShaderStage, ShaderStages}, @@ -89,18 +89,7 @@ fn setup( pipeline_handle, // NOTE: in the future you wont need to manually declare dynamic bindings PipelineSpecialization { - dynamic_bindings: vec![ - DynamicBinding { - bind_group: 1, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 1, - binding: 1, - name: "MyMaterial_color".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "MyMaterial_color".to_string()], ..Default::default() }, )]), diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index 20896ccf2acfac..5892a91dfa99b9 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -2,7 +2,7 @@ use bevy::{ prelude::*, render::{ mesh::shape, - pipeline::{DynamicBinding, PipelineDescriptor, PipelineSpecialization, RenderPipeline}, + pipeline::{PipelineDescriptor, PipelineSpecialization, RenderPipeline}, render_graph::{base, AssetRenderResourcesNode, RenderGraph}, renderer::RenderResources, shader::{asset_shader_defs_system, ShaderDefs, ShaderStage, ShaderStages}, @@ -110,18 +110,7 @@ fn setup( pipeline_handle.clone(), // NOTE: in the future you wont need to manually declare dynamic bindings PipelineSpecialization { - dynamic_bindings: vec![ - DynamicBinding { - bind_group: 1, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 1, - binding: 1, - name: "MyMaterial_color".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "MyMaterial_color".to_string()], ..Default::default() }, )]), @@ -136,18 +125,7 @@ fn setup( pipeline_handle, // NOTE: in the future you wont need to manually declare dynamic bindings PipelineSpecialization { - dynamic_bindings: vec![ - DynamicBinding { - bind_group: 1, - binding: 0, - name: "Transform".to_string(), - }, - DynamicBinding { - bind_group: 1, - binding: 1, - name: "MyMaterial_color".to_string(), - }, - ], + dynamic_bindings: vec!["Transform".to_string(), "MyMaterial_color".to_string()], ..Default::default() }, )]),