mirror of
https://github.com/bevyengine/bevy
synced 2024-11-24 21:53:07 +00:00
make pipelines cloneable and draw_target a part of render_graph
This commit is contained in:
parent
4de039eb71
commit
26588d0c41
11 changed files with 44 additions and 23 deletions
|
@ -16,7 +16,7 @@ use crate::{
|
|||
};
|
||||
|
||||
use bevy_transform::{prelude::LocalToWorld, transform_system_bundle};
|
||||
use render_graph_2::{CompiledShaderMap, PipelineDescriptor};
|
||||
use render_graph_2::{CompiledShaderMap, PipelineDescriptor, resource_name, draw_targets::{ui_draw_target, mesh_draw_target}};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct AppBuilder {
|
||||
|
@ -195,6 +195,8 @@ impl AppBuilder {
|
|||
.unwrap();
|
||||
self.render_graph_builder = self
|
||||
.render_graph_builder
|
||||
.add_draw_target(resource_name::draw_target::MESHES, mesh_draw_target)
|
||||
.add_draw_target(resource_name::draw_target::UI, ui_draw_target)
|
||||
.add_resource_provider(Box::new(CameraResourceProvider))
|
||||
.add_resource_provider(Box::new(Camera2dResourceProvider))
|
||||
.add_resource_provider(Box::new(LightResourceProvider::new(10)))
|
||||
|
|
|
@ -9,6 +9,7 @@ pub use texture::*;
|
|||
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Handle<T> {
|
||||
pub id: usize,
|
||||
marker: PhantomData<T>,
|
||||
|
|
|
@ -3,6 +3,7 @@ use crate::{asset::{AssetStorage, Handle}, render::{
|
|||
shader::{Shader, ShaderStages},
|
||||
}};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VertexBufferDescriptor {
|
||||
pub stride: wgpu::BufferAddress,
|
||||
pub step_mode: wgpu::InputStepMode,
|
||||
|
@ -19,8 +20,9 @@ impl<'a> Into<wgpu::VertexBufferDescriptor<'a>> for &'a VertexBufferDescriptor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PipelineDescriptor {
|
||||
pub draw_targets: Vec<DrawTarget>,
|
||||
pub draw_targets: Vec<String>,
|
||||
pub pipeline_layout: PipelineLayout,
|
||||
pub shader_stages: ShaderStages,
|
||||
pub rasterization_state: Option<wgpu::RasterizationStateDescriptor>,
|
||||
|
@ -145,8 +147,8 @@ impl<'a> PipelineBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_draw_target(mut self, draw_target: DrawTarget) -> Self {
|
||||
self.pipeline.draw_targets.push(draw_target);
|
||||
pub fn add_draw_target(mut self, name: &str) -> Self {
|
||||
self.pipeline.draw_targets.push(name.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ use std::{
|
|||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PipelineLayout {
|
||||
pub bind_groups: Vec<BindGroup>,
|
||||
}
|
||||
|
@ -14,7 +16,7 @@ impl PipelineLayout {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct BindGroup {
|
||||
pub bindings: Vec<Binding>,
|
||||
hash: Option<u64>,
|
||||
|
@ -39,14 +41,14 @@ impl BindGroup {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct Binding {
|
||||
pub name: String,
|
||||
pub bind_type: BindType,
|
||||
// TODO: ADD SHADER STAGE VISIBILITY
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub enum BindType {
|
||||
Uniform {
|
||||
dynamic: bool,
|
||||
|
@ -79,13 +81,13 @@ impl BindType {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct UniformProperty {
|
||||
pub name: String,
|
||||
pub property_type: UniformPropertyType,
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub enum UniformPropertyType {
|
||||
// TODO: Add all types here
|
||||
Int,
|
||||
|
@ -116,7 +118,7 @@ impl UniformPropertyType {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Hash)]
|
||||
#[derive(Copy, Clone, Debug, Hash)]
|
||||
pub enum TextureViewDimension {
|
||||
D1,
|
||||
D2,
|
||||
|
@ -139,7 +141,7 @@ impl From<TextureViewDimension> for wgpu::TextureViewDimension {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Hash)]
|
||||
#[derive(Copy, Clone, Debug, Hash)]
|
||||
pub enum TextureDimension {
|
||||
D1,
|
||||
D2,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{asset::AssetStorage, render::{
|
||||
render_graph_2::{
|
||||
draw_targets::mesh_draw_target, pipeline_layout::*, PipelineDescriptor, RenderGraphBuilder,
|
||||
pipeline_layout::*, PipelineDescriptor, RenderGraphBuilder, resource_name,
|
||||
},
|
||||
shader::{Shader, ShaderStage},
|
||||
Vertex,
|
||||
|
@ -101,7 +101,7 @@ impl ForwardPipelineBuilder for RenderGraphBuilder {
|
|||
write_mask: wgpu::ColorWrite::ALL,
|
||||
})
|
||||
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
||||
.add_draw_target(mesh_draw_target)
|
||||
.add_draw_target(resource_name::draw_target::MESHES)
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
asset::AssetStorage,
|
||||
render::{
|
||||
render_graph_2::{
|
||||
draw_targets::mesh_draw_target, pipeline_layout::*, PipelineDescriptor,
|
||||
resource_name, pipeline_layout::*, PipelineDescriptor,
|
||||
RenderGraphBuilder,
|
||||
},
|
||||
shader::{Shader, ShaderStage},
|
||||
|
@ -89,7 +89,7 @@ impl ForwardFlatPipelineBuilder for RenderGraphBuilder {
|
|||
write_mask: wgpu::ColorWrite::ALL,
|
||||
})
|
||||
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
||||
.add_draw_target(mesh_draw_target)
|
||||
.add_draw_target(resource_name::draw_target::MESHES)
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::{
|
|||
asset::AssetStorage,
|
||||
render::{
|
||||
render_graph_2::{
|
||||
draw_targets::ui_draw_target, pipeline_layout::*, resource_providers::RectData,
|
||||
PipelineDescriptor, RenderGraphBuilder, VertexBufferDescriptor,
|
||||
pipeline_layout::*, resource_providers::RectData,
|
||||
PipelineDescriptor, RenderGraphBuilder, VertexBufferDescriptor, resource_name,
|
||||
},
|
||||
shader::{Shader, ShaderStage},
|
||||
Vertex,
|
||||
|
@ -100,7 +100,7 @@ impl UiPipelineBuilder for RenderGraphBuilder {
|
|||
},
|
||||
],
|
||||
})
|
||||
.add_draw_target(ui_draw_target)
|
||||
.add_draw_target(resource_name::draw_target::UI)
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
render::{
|
||||
render_graph_2::{PassDescriptor, PipelineDescriptor, ResourceProvider, TextureDescriptor},
|
||||
render_graph_2::{PassDescriptor, PipelineDescriptor, ResourceProvider, TextureDescriptor, DrawTarget},
|
||||
},
|
||||
};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
@ -13,6 +13,7 @@ pub struct RenderGraph {
|
|||
pub pass_pipelines: HashMap<String, Vec<Handle<PipelineDescriptor>>>,
|
||||
pub resource_providers: Vec<Box<dyn ResourceProvider>>,
|
||||
pub queued_textures: Vec<(String, TextureDescriptor)>,
|
||||
pub draw_targets: HashMap<String, DrawTarget>,
|
||||
}
|
||||
|
||||
impl Default for RenderGraph {
|
||||
|
@ -23,6 +24,7 @@ impl Default for RenderGraph {
|
|||
pass_pipelines: HashMap::new(),
|
||||
resource_providers: Vec::new(),
|
||||
queued_textures: Vec::new(),
|
||||
draw_targets: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +85,11 @@ impl RenderGraphBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_draw_target(mut self, name: &str, draw_target: DrawTarget) -> Self {
|
||||
self.render_graph.draw_targets.insert(name.to_string(), draw_target);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> RenderGraph {
|
||||
self.render_graph
|
||||
}
|
||||
|
|
|
@ -446,7 +446,8 @@ impl Renderer for WgpuRenderer {
|
|||
pipeline_descriptor,
|
||||
};
|
||||
|
||||
for draw_target in pipeline_descriptor.draw_targets.iter() {
|
||||
for draw_target_name in pipeline_descriptor.draw_targets.iter() {
|
||||
let draw_target = render_graph.draw_targets.get(draw_target_name).unwrap();
|
||||
draw_target(world, &mut render_pass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,3 +14,8 @@ pub mod buffer {
|
|||
pub const TEMP_MESH_VERTEX_BUFFER_NAME: &str = "TempMeshVertexBuffer";
|
||||
pub const TEMP_MESH_INDEX_BUFFER_NAME: &str = "TempMeshIndexBuffer";
|
||||
}
|
||||
|
||||
pub mod draw_target {
|
||||
pub const MESHES: &str = "Meshes";
|
||||
pub const UI: &str = "Ui";
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use crate::asset::Handle;
|
||||
use std::marker::Copy;
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone)]
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum ShaderStage {
|
||||
Vertex,
|
||||
Fragment,
|
||||
|
@ -44,13 +44,13 @@ pub fn glsl_to_spirv(
|
|||
binary_result.as_binary().into()
|
||||
}
|
||||
|
||||
#[derive(Hash, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum ShaderSource {
|
||||
Spirv(Vec<u32>),
|
||||
Glsl(String),
|
||||
}
|
||||
|
||||
#[derive(Hash, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct Shader {
|
||||
pub source: ShaderSource,
|
||||
pub stage: ShaderStage,
|
||||
|
@ -83,6 +83,7 @@ impl Shader {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ShaderStages {
|
||||
pub vertex: Handle<Shader>,
|
||||
pub fragment: Option<Handle<Shader>>,
|
||||
|
|
Loading…
Reference in a new issue