Skip to content

Commit

Permalink
simplify DynamicBindings declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Oct 22, 2020
1 parent be84628 commit 4cf9624
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 132 deletions.
14 changes: 3 additions & 11 deletions crates/bevy_pbr/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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()
},
Expand Down
7 changes: 3 additions & 4 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<BaseRenderGraphConfig>,
}

Expand Down Expand Up @@ -112,7 +112,6 @@ impl Plugin for RenderPlugin {
.register_property::<Color>()
.register_property::<Range<f32>>()
.register_property::<ShaderSpecialization>()
.register_property::<DynamicBinding>()
.register_property::<PrimitiveTopology>()
.register_property::<IndexFormat>()
.register_properties::<PipelineSpecialization>()
Expand Down
9 changes: 1 addition & 8 deletions crates/bevy_render/src/pipeline/pipeline_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
pub struct PipelineSpecialization {
pub shader_specialization: ShaderSpecialization,
pub primitive_topology: PrimitiveTopology,
pub dynamic_bindings: Vec<DynamicBinding>,
pub dynamic_bindings: Vec<String>,
pub index_format: IndexFormat,
pub sample_count: u32,
}
Expand Down Expand Up @@ -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<Handle<Shader>, Vec<SpecializedShader>>,
Expand Down
10 changes: 3 additions & 7 deletions crates/bevy_render/src/renderer/render_resource_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
pipeline::{
BindGroupDescriptorId, BindType, DynamicBinding, PipelineDescriptor, PipelineLayout,
BindGroupDescriptorId, BindType, PipelineDescriptor, PipelineLayout,
VertexBufferDescriptors,
},
renderer::{BindGroup, BufferId, BufferInfo, RenderResourceId, SamplerId, TextureId},
Expand Down Expand Up @@ -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<ShaderLayout> = shader_stages
Expand All @@ -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
Expand Down
29 changes: 4 additions & 25 deletions crates/bevy_sprite/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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()
},
)]),
Expand Down Expand Up @@ -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()
},
Expand Down
43 changes: 4 additions & 39 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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()
},
)]),
Expand Down Expand Up @@ -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()
},
)]),
Expand Down Expand Up @@ -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()
},
)]),
Expand Down
15 changes: 2 additions & 13 deletions examples/shader/shader_custom_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()
},
)]),
Expand Down
28 changes: 3 additions & 25 deletions examples/shader/shader_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()
},
)]),
Expand All @@ -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()
},
)]),
Expand Down

0 comments on commit 4cf9624

Please sign in to comment.