Skip to content

Commit

Permalink
use RenderPipeline::new, update dynamic_bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Nov 5, 2020
1 parent 083f7f1 commit 51bca0e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 44 deletions.
5 changes: 2 additions & 3 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::{PipelineSpecialization, RenderPipeline, RenderPipelines},
pipeline::{RenderPipeline, RenderPipelines},
render_graph::base::MainPass,
};
use bevy_transform::prelude::{GlobalTransform, Transform};
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<'a> DrawContext<'a> {
&mut self,
draw: &mut Draw,
pipeline_handle: &Handle<PipelineDescriptor>,
specialization: &PipelineSpecialization,
specialization: &mut PipelineSpecialization,
render_resource_bindings: &mut [&mut RenderResourceBindings],
) -> Result<(), DrawError> {
let specialized_pipeline = if let Some(specialized_pipeline) = self
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_render/src/pipeline/pipeline_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::borrow::Cow;
pub struct PipelineSpecialization {
pub shader_specialization: ShaderSpecialization,
pub primitive_topology: PrimitiveTopology,
pub dynamic_bindings: Vec<String>,
pub index_format: IndexFormat,
pub vertex_buffer_descriptor: VertexBufferDescriptor,
pub sample_count: u32,
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -134,7 +136,7 @@ impl PipelineCompiler {
pipelines: &mut Assets<PipelineDescriptor>,
shaders: &mut Assets<Shader>,
source_pipeline: &Handle<PipelineDescriptor>,
pipeline_specialization: &PipelineSpecialization,
pipeline_specialization: &mut PipelineSpecialization,
render_resource_bindings: &mut [&mut RenderResourceBindings],
) -> Handle<PipelineDescriptor> {
let source_descriptor = pipelines.get(source_pipeline).unwrap();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/pipeline/render_pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
8 changes: 3 additions & 5 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::{PipelineSpecialization, RenderPipeline, RenderPipelines},
pipeline::{RenderPipeline, RenderPipelines},
prelude::Draw,
render_graph::base::MainPass,
};
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 4 additions & 7 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::{PipelineSpecialization, RenderPipeline, RenderPipelines},
pipeline::{RenderPipeline, RenderPipelines},
};
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
use bevy_transform::prelude::{GlobalTransform, Transform};
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
15 changes: 2 additions & 13 deletions examples/shader/mesh_custom_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 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::{PipelineDescriptor, PipelineSpecialization, RenderPipeline},
pipeline::{PipelineDescriptor, RenderPipeline},
render_graph::{base, AssetRenderResourcesNode, RenderGraph},
renderer::RenderResources,
shader::{ShaderStage, ShaderStages},
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions examples/shader/shader_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 51bca0e

Please sign in to comment.