Implement a Render Graph #16
|
@ -384,6 +384,12 @@ version = "1.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
|
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bind_match"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "171f0236f66c7be99f32060539c2bade94033ded356ecf4c9dc9b1e6198326cd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit-set"
|
name = "bit-set"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
|
@ -1859,6 +1865,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"bind_match",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"gilrs-core",
|
"gilrs-core",
|
||||||
|
|
|
@ -37,6 +37,7 @@ thiserror = "1.0.56"
|
||||||
unique = "0.9.1"
|
unique = "0.9.1"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
petgraph = { version = "0.6.5", features = ["matrix_graph"] }
|
petgraph = { version = "0.6.5", features = ["matrix_graph"] }
|
||||||
|
bind_match = "0.1.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tracy = ["dep:tracing-tracy"]
|
tracy = ["dep:tracing-tracy"]
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
mod pass;
|
mod node;
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell, collections::{HashMap, VecDeque}, fmt::Debug, hash::Hash, rc::Rc, sync::Arc
|
cell::RefCell, collections::{HashMap, VecDeque}, fmt::Debug, hash::Hash, rc::Rc, sync::Arc
|
||||||
};
|
};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lyra_ecs::World;
|
use lyra_ecs::World;
|
||||||
pub use pass::*;
|
pub use node::*;
|
||||||
|
|
||||||
mod passes;
|
mod passes;
|
||||||
pub use passes::*;
|
pub use passes::*;
|
||||||
|
@ -76,8 +76,8 @@ impl PartialEq for RenderGraphLabelValue {
|
||||||
impl Eq for RenderGraphLabelValue {}
|
impl Eq for RenderGraphLabelValue {}
|
||||||
|
|
||||||
struct PassEntry {
|
struct PassEntry {
|
||||||
inner: Arc<RefCell<dyn RenderGraphPass>>,
|
inner: Arc<RefCell<dyn Node>>,
|
||||||
desc: Arc<RenderGraphPassDesc>,
|
desc: Arc<NodeDesc>,
|
||||||
/// The index of the pass in the execution graph
|
/// The index of the pass in the execution graph
|
||||||
graph_index: petgraph::matrix_graph::NodeIndex<usize>,
|
graph_index: petgraph::matrix_graph::NodeIndex<usize>,
|
||||||
}
|
}
|
||||||
|
@ -165,8 +165,18 @@ impl RenderGraph {
|
||||||
self.slot_label_lookup.get(&label.rc_clone().into()).cloned()
|
self.slot_label_lookup.get(&label.rc_clone().into()).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a [`Node`] to the RenderGraph.
|
||||||
|
///
|
||||||
|
/// When the node is added, its [`Node::desc`] method will be executed.
|
||||||
|
///
|
||||||
|
/// Additionally, all [`Slot`](node::NodeSlot)s of the node will be iterated,
|
||||||
|
/// 1. Ensuring that there are no two slots of the same name, with different value types
|
||||||
|
/// 2. Changing the id of insert slots to match the id of the output slot of the same name.
|
||||||
|
/// * This means that the id of insert slots **ARE NOT STABLE**. **DO NOT** rely on them to
|
||||||
|
/// not change. The IDs of output slots do stay the same.
|
||||||
|
/// 3. Ensuring that no two slots share the same ID when the names do not match.
|
||||||
#[instrument(skip(self, pass), level = "debug")]
|
#[instrument(skip(self, pass), level = "debug")]
|
||||||
pub fn add_pass<P: RenderGraphPass>(&mut self, mut pass: P) {
|
pub fn add_pass<P: Node>(&mut self, mut pass: P) {
|
||||||
let mut desc = pass.desc(self);
|
let mut desc = pass.desc(self);
|
||||||
|
|
||||||
// collect all the slots of the pass
|
// collect all the slots of the pass
|
||||||
|
@ -234,25 +244,28 @@ impl RenderGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates all buffers required for the passes, also creates an internal execution path.
|
/// Creates all buffers required for the passes, also creates an internal execution path.
|
||||||
|
///
|
||||||
|
/// This only needs to be ran when the [`Node`]s in the graph change, or they are removed or
|
||||||
|
/// added.
|
||||||
#[instrument(skip(self, device))]
|
#[instrument(skip(self, device))]
|
||||||
pub fn setup(&mut self, device: &wgpu::Device) {
|
pub fn setup(&mut self, device: &wgpu::Device) {
|
||||||
// For all passes, create their pipelines
|
// For all passes, create their pipelines
|
||||||
for pass in self.passes.values() {
|
for pass in self.passes.values() {
|
||||||
if let Some(pipeline_desc) = &pass.desc.pipeline_desc {
|
if let Some(pipeline_desc) = &pass.desc.pipeline_desc {
|
||||||
let pipeline = match pass.desc.pass_type {
|
let pipeline = match pass.desc.ty {
|
||||||
RenderPassType::Render => Pipeline::Render(RenderPipeline::create(
|
NodeType::Render => Pipeline::Render(RenderPipeline::create(
|
||||||
device,
|
device,
|
||||||
pipeline_desc
|
pipeline_desc
|
||||||
.as_render_pipeline_descriptor()
|
.as_render_pipeline_descriptor()
|
||||||
.expect("got compute pipeline descriptor in a render pass"),
|
.expect("got compute pipeline descriptor in a render pass"),
|
||||||
)),
|
)),
|
||||||
RenderPassType::Compute => Pipeline::Compute(ComputePipeline::create(
|
NodeType::Compute => Pipeline::Compute(ComputePipeline::create(
|
||||||
device,
|
device,
|
||||||
pipeline_desc
|
pipeline_desc
|
||||||
.as_compute_pipeline_descriptor()
|
.as_compute_pipeline_descriptor()
|
||||||
.expect("got render pipeline descriptor in a compute pass"),
|
.expect("got render pipeline descriptor in a compute pass"),
|
||||||
)),
|
)),
|
||||||
RenderPassType::Presenter | RenderPassType::Node => {
|
NodeType::Presenter | NodeType::Node => {
|
||||||
panic!("Present or Node RenderGraph passes should not have a pipeline descriptor!");
|
panic!("Present or Node RenderGraph passes should not have a pipeline descriptor!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -319,7 +332,7 @@ impl RenderGraph {
|
||||||
let label = format!("{:?} Encoder", pass_desc.label);
|
let label = format!("{:?} Encoder", pass_desc.label);
|
||||||
|
|
||||||
// encoders are not needed for presenter nodes.
|
// encoders are not needed for presenter nodes.
|
||||||
let encoder = if pass_desc.pass_type.should_have_pipeline() {
|
let encoder = if pass_desc.ty.should_have_pipeline() {
|
||||||
Some(
|
Some(
|
||||||
self.device
|
self.device
|
||||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||||
|
@ -336,7 +349,7 @@ impl RenderGraph {
|
||||||
let mut context = RenderGraphContext::new(&device, &queue, encoder);
|
let mut context = RenderGraphContext::new(&device, &queue, encoder);
|
||||||
|
|
||||||
// all encoders need to be submitted before a presenter node is executed.
|
// all encoders need to be submitted before a presenter node is executed.
|
||||||
if pass_desc.pass_type == RenderPassType::Presenter {
|
if pass_desc.ty == NodeType::Presenter {
|
||||||
trace!("Submitting {} encoderd before presenting", encoders.len());
|
trace!("Submitting {} encoderd before presenting", encoders.len());
|
||||||
self.queue.submit(encoders.drain(..));
|
self.queue.submit(encoders.drain(..));
|
||||||
}
|
}
|
||||||
|
@ -369,7 +382,7 @@ impl RenderGraph {
|
||||||
self.slots.get_mut(&id).map(|s| &mut s.value)
|
self.slots.get_mut(&id).map(|s| &mut s.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pass(&self, id: u64) -> Option<&RenderGraphPassDesc> {
|
pub fn pass(&self, id: u64) -> Option<&NodeDesc> {
|
||||||
self.passes.get(&id).map(|s| &*s.desc)
|
self.passes.get(&id).map(|s| &*s.desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,13 +451,13 @@ impl RenderGraph {
|
||||||
/// graph.set_bind_groups(
|
/// graph.set_bind_groups(
|
||||||
/// &mut pass,
|
/// &mut pass,
|
||||||
/// &[
|
/// &[
|
||||||
/// // retrieves the "depth_texture" bind group and sets the index 0 in the
|
/// // retrieves the `BasePassSlots::DepthTexture` bind group and sets the index 0 in the
|
||||||
/// // pass to it.
|
/// // pass to it.
|
||||||
/// ("depth_texture", 0),
|
/// (&BasePassSlots::DepthTexture, 0),
|
||||||
/// ("camera", 1),
|
/// (&BasePassSlots::Camera, 1),
|
||||||
/// ("light_buffers", 2),
|
/// (&LightBasePassSlots::Lights, 2),
|
||||||
/// ("light_indices_grid", 3),
|
/// (&LightCullComputePassSlots::LightIndicesGridGroup, 3),
|
||||||
/// ("screen_size", 4),
|
/// (&BasePassSlots::ScreenSize, 4),
|
||||||
/// ],
|
/// ],
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{cell::{Ref, RefCell, RefMut}, collections::HashMap, num::NonZeroU32, rc::Rc};
|
use std::{cell::{Ref, RefCell, RefMut}, collections::HashMap, num::NonZeroU32, rc::Rc};
|
||||||
|
|
||||||
|
use bind_match::bind_match;
|
||||||
use lyra_ecs::World;
|
use lyra_ecs::World;
|
||||||
|
|
||||||
use crate::render::resource::PipelineDescriptor;
|
use crate::render::resource::PipelineDescriptor;
|
||||||
|
@ -7,26 +8,31 @@ use crate::render::resource::PipelineDescriptor;
|
||||||
use super::{RenderGraph, RenderGraphContext, RenderGraphLabel, RenderGraphLabelValue, RenderTarget};
|
use super::{RenderGraph, RenderGraphContext, RenderGraphLabel, RenderGraphLabelValue, RenderTarget};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||||
pub enum RenderPassType {
|
pub enum NodeType {
|
||||||
/// A node doesn't render, compute, or present anything. This likely means it injects data into the graph.
|
/// A node doesn't render, compute, or present anything. This likely means it injects data into the graph.
|
||||||
Node,
|
|
||||||
Compute,
|
|
||||||
#[default]
|
#[default]
|
||||||
|
Node,
|
||||||
|
/// A Compute pass node type.
|
||||||
|
Compute,
|
||||||
|
/// A render pass node type.
|
||||||
Render,
|
Render,
|
||||||
|
/// A node that presents render results to a render target.
|
||||||
Presenter,
|
Presenter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderPassType {
|
impl NodeType {
|
||||||
|
/// Returns a boolean indicating if the node should have a [`Pipeline`](crate::render::resource::Pipeline).
|
||||||
pub fn should_have_pipeline(&self) -> bool {
|
pub fn should_have_pipeline(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
RenderPassType::Node => false,
|
NodeType::Node => false,
|
||||||
RenderPassType::Compute => true,
|
NodeType::Compute => true,
|
||||||
RenderPassType::Render => true,
|
NodeType::Render => true,
|
||||||
RenderPassType::Presenter => false,
|
NodeType::Presenter => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The type of data that is stored in a [`Node`] slot.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum SlotType {
|
pub enum SlotType {
|
||||||
TextureView,
|
TextureView,
|
||||||
|
@ -36,10 +42,13 @@ pub enum SlotType {
|
||||||
RenderTarget,
|
RenderTarget,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The value of a slot in a [`Node`].
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum SlotValue {
|
pub enum SlotValue {
|
||||||
|
/// This slot doesn't have any value
|
||||||
None,
|
None,
|
||||||
/// The value will be set during a later phase of the render graph.
|
/// The value will be set during a later phase of the render graph. To see the type of value
|
||||||
|
/// this will be set to, see the slots type.
|
||||||
Lazy,
|
Lazy,
|
||||||
TextureView(Rc<wgpu::TextureView>),
|
TextureView(Rc<wgpu::TextureView>),
|
||||||
Sampler(Rc<wgpu::Sampler>),
|
Sampler(Rc<wgpu::Sampler>),
|
||||||
|
@ -49,56 +58,51 @@ pub enum SlotValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SlotValue {
|
impl SlotValue {
|
||||||
/// Gets `self` as a texture, panics if self is not a instance of [`SlotValue::Texture`].
|
pub fn as_texture_view(&self) -> Option<&Rc<wgpu::TextureView>> {
|
||||||
pub fn as_texture(&self) -> &wgpu::Texture {
|
bind_match!(self, Self::TextureView(v) => v)
|
||||||
match self {
|
|
||||||
Self::Texture(v) => v,
|
|
||||||
_ => panic!("self is not an instance of SlotValue::Texture"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_texture_view(&self) -> &wgpu::TextureView {
|
pub fn as_sampler(&self) -> Option<&Rc<wgpu::Sampler>> {
|
||||||
match self {
|
bind_match!(self, Self::Sampler(v) => v)
|
||||||
Self::TextureView(v) => v,
|
|
||||||
_ => panic!("self is not an instance of SlotValue::TextureView"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_buffer(&self) -> Option<&wgpu::Buffer> {
|
pub fn as_texture(&self) -> Option<&Rc<wgpu::Texture>> {
|
||||||
match self {
|
bind_match!(self, Self::Texture(v) => v)
|
||||||
Self::Buffer(v) => Some(v),
|
|
||||||
_ => None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_buffer(&self) -> Option<&Rc<wgpu::Buffer>> {
|
||||||
|
bind_match!(self, Self::Buffer(v) => v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_render_target(&self) -> Option<Ref<RenderTarget>> {
|
pub fn as_render_target(&self) -> Option<Ref<RenderTarget>> {
|
||||||
match self {
|
bind_match!(self, Self::RenderTarget(v) => v.borrow())
|
||||||
Self::RenderTarget(v) => Some(v.borrow()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_render_target_mut(&mut self) -> Option<RefMut<RenderTarget>> {
|
pub fn as_render_target_mut(&mut self) -> Option<RefMut<RenderTarget>> {
|
||||||
match self {
|
bind_match!(self, Self::RenderTarget(v) => v.borrow_mut())
|
||||||
Self::RenderTarget(v) => Some(v.borrow_mut()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum SlotAttribute {
|
pub enum SlotAttribute {
|
||||||
|
/// This slot inputs a value into the node, expecting another node to `Output` it.
|
||||||
Input,
|
Input,
|
||||||
|
/// This slot outputs a value from the node, providing the value to other nodes that
|
||||||
|
/// `Input`it.
|
||||||
Output,
|
Output,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RenderPassSlot {
|
pub struct NodeSlot {
|
||||||
|
/// The type of the value that this slot inputs/outputs.
|
||||||
pub ty: SlotType,
|
pub ty: SlotType,
|
||||||
|
/// The way this slot uses the value. Defines if this slot is an output or input.
|
||||||
pub attribute: SlotAttribute,
|
pub attribute: SlotAttribute,
|
||||||
|
// What if these are just completely removed and labels are used everywhere instead?
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
|
/// The identifying label of this slot.
|
||||||
pub label: RenderGraphLabelValue,
|
pub label: RenderGraphLabelValue,
|
||||||
/// The descriptor of the slot value.
|
/// The value of the slot.
|
||||||
/// This will be `None` if this slot is an input.
|
/// This is `None` if the slot is a `SlotAttribute::Input` type.
|
||||||
pub value: Option<SlotValue>,
|
pub value: Option<SlotValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,13 +161,23 @@ impl RenderGraphPipelineInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RenderGraphPassDesc {
|
/// Descriptor of a Node in a [`RenderGraph`].
|
||||||
|
pub struct NodeDesc {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
|
/// The label of the Node, used to identify the Node.
|
||||||
pub label: RenderGraphLabelValue,
|
pub label: RenderGraphLabelValue,
|
||||||
pub pass_type: RenderPassType,
|
/// The [`NodeType`] of the node.
|
||||||
pub slots: Vec<RenderPassSlot>,
|
pub ty: NodeType,
|
||||||
|
/// The slots that the Node uses.
|
||||||
|
/// This defines the resources that the node uses and creates in the graph.
|
||||||
|
pub slots: Vec<NodeSlot>,
|
||||||
slot_label_lookup: HashMap<RenderGraphLabelValue, u64>,
|
slot_label_lookup: HashMap<RenderGraphLabelValue, u64>,
|
||||||
|
/// An optional pipeline descriptor for the Node.
|
||||||
|
/// This is `None` if the Node type is not a node that requires a pipeline
|
||||||
|
/// (see [`NodeType::should_have_pipeline`]).
|
||||||
pub pipeline_desc: Option<PipelineDescriptor>,
|
pub pipeline_desc: Option<PipelineDescriptor>,
|
||||||
|
/// The bind groups that this Node creates.
|
||||||
|
/// This makes the bind groups accessible to other Nodes.
|
||||||
pub bind_groups: Vec<(
|
pub bind_groups: Vec<(
|
||||||
RenderGraphLabelValue,
|
RenderGraphLabelValue,
|
||||||
Rc<wgpu::BindGroup>,
|
Rc<wgpu::BindGroup>,
|
||||||
|
@ -171,18 +185,19 @@ pub struct RenderGraphPassDesc {
|
||||||
)>,
|
)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphPassDesc {
|
impl NodeDesc {
|
||||||
|
/// Create a new node descriptor.
|
||||||
pub fn new<L: RenderGraphLabel>(
|
pub fn new<L: RenderGraphLabel>(
|
||||||
id: u64,
|
id: u64,
|
||||||
label: L,
|
label: L,
|
||||||
pass_type: RenderPassType,
|
pass_type: NodeType,
|
||||||
pipeline_desc: Option<PipelineDescriptor>,
|
pipeline_desc: Option<PipelineDescriptor>,
|
||||||
bind_groups: Vec<(&dyn RenderGraphLabel, Rc<wgpu::BindGroup>, Option<Rc<wgpu::BindGroupLayout>>)>,
|
bind_groups: Vec<(&dyn RenderGraphLabel, Rc<wgpu::BindGroup>, Option<Rc<wgpu::BindGroupLayout>>)>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
pass_type,
|
ty: pass_type,
|
||||||
slots: vec![],
|
slots: vec![],
|
||||||
slot_label_lookup: HashMap::default(),
|
slot_label_lookup: HashMap::default(),
|
||||||
pipeline_desc,
|
pipeline_desc,
|
||||||
|
@ -193,7 +208,11 @@ impl RenderGraphPassDesc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_slot(&mut self, slot: RenderPassSlot) {
|
/// Add a slot to the descriptor.
|
||||||
|
///
|
||||||
|
/// In debug builds, there is an assert that triggers if the slot is an input slot and has
|
||||||
|
/// a value set.
|
||||||
|
pub fn add_slot(&mut self, slot: NodeSlot) {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
!(slot.attribute == SlotAttribute::Input && slot.value.is_some()),
|
!(slot.attribute == SlotAttribute::Input && slot.value.is_some()),
|
||||||
"input slots should not have values"
|
"input slots should not have values"
|
||||||
|
@ -203,6 +222,11 @@ impl RenderGraphPassDesc {
|
||||||
self.slots.push(slot);
|
self.slots.push(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a buffer slot to the descriptor.
|
||||||
|
///
|
||||||
|
/// In debug builds, there is an assert that triggers if the slot is an input slot and has
|
||||||
|
/// a value set. There is also an assert that is triggered if this slot value is not `None`,
|
||||||
|
/// `SlotValue::Lazy` or a `Buffer`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_buffer_slot<L: RenderGraphLabel>(
|
pub fn add_buffer_slot<L: RenderGraphLabel>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -216,7 +240,7 @@ impl RenderGraphPassDesc {
|
||||||
"slot value is not a buffer"
|
"slot value is not a buffer"
|
||||||
);
|
);
|
||||||
|
|
||||||
let slot = RenderPassSlot {
|
let slot = NodeSlot {
|
||||||
id,
|
id,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
ty: SlotType::Buffer,
|
ty: SlotType::Buffer,
|
||||||
|
@ -226,6 +250,11 @@ impl RenderGraphPassDesc {
|
||||||
self.add_slot(slot);
|
self.add_slot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a slot that stores a [`wgpu::Texture`] to the descriptor.
|
||||||
|
///
|
||||||
|
/// In debug builds, there is an assert that triggers if the slot is an input slot and has
|
||||||
|
/// a value set. There is also an assert that is triggered if this slot value is not `None`,
|
||||||
|
/// `SlotValue::Lazy` or a `SlotValue::Texture`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_texture_slot<L: RenderGraphLabel>(
|
pub fn add_texture_slot<L: RenderGraphLabel>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -239,7 +268,7 @@ impl RenderGraphPassDesc {
|
||||||
"slot value is not a texture"
|
"slot value is not a texture"
|
||||||
);
|
);
|
||||||
|
|
||||||
let slot = RenderPassSlot {
|
let slot = NodeSlot {
|
||||||
id,
|
id,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
ty: SlotType::Texture,
|
ty: SlotType::Texture,
|
||||||
|
@ -249,6 +278,11 @@ impl RenderGraphPassDesc {
|
||||||
self.add_slot(slot);
|
self.add_slot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a slot that stores a [`wgpu::TextureView`] to the descriptor.
|
||||||
|
///
|
||||||
|
/// In debug builds, there is an assert that triggers if the slot is an input slot and has
|
||||||
|
/// a value set. There is also an assert that is triggered if this slot value is not `None`,
|
||||||
|
/// `SlotValue::Lazy` or a `SlotValue::TextureView`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_texture_view_slot<L: RenderGraphLabel>(
|
pub fn add_texture_view_slot<L: RenderGraphLabel>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -262,7 +296,7 @@ impl RenderGraphPassDesc {
|
||||||
"slot value is not a texture view"
|
"slot value is not a texture view"
|
||||||
);
|
);
|
||||||
|
|
||||||
let slot = RenderPassSlot {
|
let slot = NodeSlot {
|
||||||
id,
|
id,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
ty: SlotType::TextureView,
|
ty: SlotType::TextureView,
|
||||||
|
@ -272,6 +306,11 @@ impl RenderGraphPassDesc {
|
||||||
self.add_slot(slot);
|
self.add_slot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a slot that stores a [`wgpu::Sampler`] to the descriptor.
|
||||||
|
///
|
||||||
|
/// In debug builds, there is an assert that triggers if the slot is an input slot and has
|
||||||
|
/// a value set. There is also an assert that is triggered if this slot value is not `None`,
|
||||||
|
/// `SlotValue::Lazy` or a `SlotValue::Sampler`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_sampler_slot<L: RenderGraphLabel>(
|
pub fn add_sampler_slot<L: RenderGraphLabel>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -285,7 +324,7 @@ impl RenderGraphPassDesc {
|
||||||
"slot value is not a sampler"
|
"slot value is not a sampler"
|
||||||
);
|
);
|
||||||
|
|
||||||
let slot = RenderPassSlot {
|
let slot = NodeSlot {
|
||||||
id,
|
id,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
ty: SlotType::Sampler,
|
ty: SlotType::Sampler,
|
||||||
|
@ -295,14 +334,16 @@ impl RenderGraphPassDesc {
|
||||||
self.add_slot(slot);
|
self.add_slot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input_slots(&self) -> Vec<&RenderPassSlot> {
|
/// Returns all input slots that the descriptor defines.
|
||||||
|
pub fn input_slots(&self) -> Vec<&NodeSlot> {
|
||||||
self.slots
|
self.slots
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|s| s.attribute == SlotAttribute::Input)
|
.filter(|s| s.attribute == SlotAttribute::Input)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output_slots(&self) -> Vec<&RenderPassSlot> {
|
/// Returns all output slots that the descriptor defines.
|
||||||
|
pub fn output_slots(&self) -> Vec<&NodeSlot> {
|
||||||
self.slots
|
self.slots
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|s| s.attribute == SlotAttribute::Output)
|
.filter(|s| s.attribute == SlotAttribute::Output)
|
||||||
|
@ -310,17 +351,34 @@ impl RenderGraphPassDesc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RenderGraphPass: 'static {
|
/// A node that can be executed and scheduled in a [`RenderGraph`].
|
||||||
/// Create a render pass describer.
|
|
||||||
///
|
///
|
||||||
/// The `id` argument is passed as mutable so you can increment it as you use it for new slots.
|
/// A node can be used for rendering, computing data on the GPU, collecting data from the main
|
||||||
fn desc<'a, 'b>(&'a mut self, graph: &'b mut RenderGraph) -> RenderGraphPassDesc;
|
/// world and writing it to GPU buffers, or presenting renders to a surface.
|
||||||
|
///
|
||||||
|
/// The [`RenderGraph`] is ran in phases. The first phase is `prepare`, then `execute`. When a node
|
||||||
|
/// is first added to a RenderGraph, its [`Node::desc`] function will be ran. The descriptor
|
||||||
|
/// describes all resources the node requires for execution during the `execute` phase.
|
||||||
|
pub trait Node: 'static {
|
||||||
|
/// Retrieve a descriptor of the Node.
|
||||||
|
fn desc<'a, 'b>(&'a mut self, graph: &'b mut RenderGraph) -> NodeDesc;
|
||||||
|
|
||||||
|
/// Prepare the node for rendering.
|
||||||
|
///
|
||||||
|
/// This phase runs before `execute` and is meant to be used to collect data from the World
|
||||||
|
/// and write to GPU buffers.
|
||||||
fn prepare(&mut self, world: &mut World, context: &mut RenderGraphContext);
|
fn prepare(&mut self, world: &mut World, context: &mut RenderGraphContext);
|
||||||
|
|
||||||
|
/// Execute the node.
|
||||||
|
///
|
||||||
|
/// Parameters:
|
||||||
|
/// * `graph` - The RenderGraph that this node is a part of. Can be used to get bind groups and bind to them.
|
||||||
|
/// * `desc` - The descriptor of this node.
|
||||||
|
/// * `context` - The rendering graph context.
|
||||||
fn execute(
|
fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut RenderGraph,
|
graph: &mut RenderGraph,
|
||||||
desc: &RenderGraphPassDesc,
|
desc: &NodeDesc,
|
||||||
context: &mut RenderGraphContext,
|
context: &mut RenderGraphContext,
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -9,8 +9,8 @@ use crate::{
|
||||||
render::{
|
render::{
|
||||||
camera::{CameraUniform, RenderCamera},
|
camera::{CameraUniform, RenderCamera},
|
||||||
graph::{
|
graph::{
|
||||||
RenderGraphContext, RenderGraphPass, RenderGraphPassDesc, RenderPassSlot,
|
RenderGraphContext, Node, NodeDesc, NodeSlot,
|
||||||
RenderPassType, RenderTarget, SlotAttribute, SlotType, SlotValue,
|
NodeType, RenderTarget, SlotAttribute, SlotType, SlotValue,
|
||||||
},
|
},
|
||||||
render_buffer::BufferWrapper, texture::RenderTexture,
|
render_buffer::BufferWrapper, texture::RenderTexture,
|
||||||
},
|
},
|
||||||
|
@ -61,11 +61,11 @@ impl BasePass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphPass for BasePass {
|
impl Node for BasePass {
|
||||||
fn desc(
|
fn desc(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
) -> crate::render::graph::RenderGraphPassDesc {
|
) -> crate::render::graph::NodeDesc {
|
||||||
let render_target = self.temp_render_target.take().unwrap();
|
let render_target = self.temp_render_target.take().unwrap();
|
||||||
self.screen_size = UVec2::new(
|
self.screen_size = UVec2::new(
|
||||||
render_target.surface_config.width,
|
render_target.surface_config.width,
|
||||||
|
@ -101,10 +101,10 @@ impl RenderGraphPass for BasePass {
|
||||||
let depth_texture_bgl = dt_bg_pair.layout;
|
let depth_texture_bgl = dt_bg_pair.layout;
|
||||||
let depth_texture_view = Rc::new(depth_texture.view);
|
let depth_texture_view = Rc::new(depth_texture.view);
|
||||||
|
|
||||||
let mut desc = RenderGraphPassDesc::new(
|
let mut desc = NodeDesc::new(
|
||||||
graph.next_id(),
|
graph.next_id(),
|
||||||
BasePassLabel,
|
BasePassLabel,
|
||||||
RenderPassType::Node,
|
NodeType::Node,
|
||||||
None,
|
None,
|
||||||
vec![
|
vec![
|
||||||
// TODO: Make this a trait maybe?
|
// TODO: Make this a trait maybe?
|
||||||
|
@ -120,7 +120,7 @@ impl RenderGraphPass for BasePass {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.main_rt_id = graph.next_id();
|
self.main_rt_id = graph.next_id();
|
||||||
desc.add_slot(RenderPassSlot {
|
desc.add_slot(NodeSlot {
|
||||||
ty: SlotType::RenderTarget,
|
ty: SlotType::RenderTarget,
|
||||||
attribute: SlotAttribute::Output,
|
attribute: SlotAttribute::Output,
|
||||||
id: self.main_rt_id,
|
id: self.main_rt_id,
|
||||||
|
@ -173,7 +173,7 @@ impl RenderGraphPass for BasePass {
|
||||||
fn execute(
|
fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
_desc: &crate::render::graph::RenderGraphPassDesc,
|
_desc: &crate::render::graph::NodeDesc,
|
||||||
context: &mut crate::render::graph::RenderGraphContext,
|
context: &mut crate::render::graph::RenderGraphContext,
|
||||||
) {
|
) {
|
||||||
let tv_slot = graph
|
let tv_slot = graph
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
use glam::UVec2;
|
|
||||||
|
|
||||||
use crate::render::{
|
|
||||||
camera::CameraUniform,
|
|
||||||
graph::{
|
|
||||||
BufferInitDescriptor, RenderGraphPass, RenderGraphPassDesc, RenderPassType, SamplerDescriptor, SlotAttribute, SlotDescriptor, TextureDescriptor, TextureViewDescriptor
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Supplies some basic things other passes needs.
|
|
||||||
///
|
|
||||||
/// screen size buffer, camera buffer,
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct DepthPrePass;
|
|
||||||
|
|
||||||
impl DepthPrePass {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RenderGraphPass for DepthPrePass {
|
|
||||||
fn desc(
|
|
||||||
&self,
|
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
|
||||||
id: &mut u64,
|
|
||||||
) -> crate::render::graph::RenderGraphPassDesc {
|
|
||||||
let mut desc = RenderGraphPassDesc::new(*id, "DepthPrePass", RenderPassType::Compute);
|
|
||||||
*id += 1;
|
|
||||||
|
|
||||||
let size = wgpu::Extent3d {
|
|
||||||
width: graph.surface_config.width,
|
|
||||||
height: graph.surface_config.height,
|
|
||||||
depth_or_array_layers: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
desc.add_texture_slot(
|
|
||||||
*id,
|
|
||||||
"depth_texture",
|
|
||||||
SlotAttribute::Output,
|
|
||||||
Some(SlotDescriptor::Texture(TextureDescriptor {
|
|
||||||
size,
|
|
||||||
mip_level_count: 1,
|
|
||||||
sample_count: 1,
|
|
||||||
dimension: wgpu::TextureDimension::D2,
|
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
|
||||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
|
||||||
view_formats: vec![],
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
*id += 1;
|
|
||||||
|
|
||||||
desc.add_texture_view_slot(
|
|
||||||
*id,
|
|
||||||
"depth_texture_view",
|
|
||||||
SlotAttribute::Output,
|
|
||||||
Some(SlotDescriptor::TextureView(TextureViewDescriptor::default_view("depth_texture"))),
|
|
||||||
);
|
|
||||||
*id += 1;
|
|
||||||
|
|
||||||
desc.add_texture_view_slot(
|
|
||||||
*id,
|
|
||||||
"depth_texture_sampler",
|
|
||||||
SlotAttribute::Output,
|
|
||||||
Some(SlotDescriptor::Sampler(SamplerDescriptor {
|
|
||||||
mag_filter: wgpu::FilterMode::Linear,
|
|
||||||
min_filter: wgpu::FilterMode::Linear,
|
|
||||||
compare: Some(wgpu::CompareFunction::LessEqual),
|
|
||||||
lod_min_clamp: 0.0,
|
|
||||||
lod_max_clamp: 100.0,
|
|
||||||
..SamplerDescriptor::default_sampler("depth_texture")
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
*id += 1;
|
|
||||||
|
|
||||||
desc
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prepare(&mut self, world: &mut lyra_ecs::World) {
|
|
||||||
let _ = world;
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn execute(
|
|
||||||
&mut self,
|
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
|
||||||
desc: &crate::render::graph::RenderGraphPassDesc,
|
|
||||||
context: &mut crate::render::graph::RenderGraphContext,
|
|
||||||
) {
|
|
||||||
let _ = (graph, desc, context);
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@ use lyra_game_derive::RenderGraphLabel;
|
||||||
|
|
||||||
use crate::render::{
|
use crate::render::{
|
||||||
graph::{
|
graph::{
|
||||||
RenderGraphContext, RenderGraphPass, RenderGraphPassDesc, RenderPassType, SlotAttribute,
|
RenderGraphContext, Node, NodeDesc, NodeType, SlotAttribute,
|
||||||
SlotValue,
|
SlotValue,
|
||||||
},
|
},
|
||||||
light::LightUniformBuffers,
|
light::LightUniformBuffers,
|
||||||
|
@ -30,19 +30,19 @@ impl LightBasePass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphPass for LightBasePass {
|
impl Node for LightBasePass {
|
||||||
fn desc(
|
fn desc(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
) -> crate::render::graph::RenderGraphPassDesc {
|
) -> crate::render::graph::NodeDesc {
|
||||||
let device = &graph.device;
|
let device = &graph.device;
|
||||||
self.light_buffers = Some(LightUniformBuffers::new(device));
|
self.light_buffers = Some(LightUniformBuffers::new(device));
|
||||||
let light_buffers = self.light_buffers.as_ref().unwrap();
|
let light_buffers = self.light_buffers.as_ref().unwrap();
|
||||||
|
|
||||||
let mut desc = RenderGraphPassDesc::new(
|
let mut desc = NodeDesc::new(
|
||||||
graph.next_id(),
|
graph.next_id(),
|
||||||
LightBasePassLabel,
|
LightBasePassLabel,
|
||||||
RenderPassType::Node,
|
NodeType::Node,
|
||||||
None,
|
None,
|
||||||
vec![(
|
vec![(
|
||||||
&LightBasePassSlots::Lights,
|
&LightBasePassSlots::Lights,
|
||||||
|
@ -70,7 +70,7 @@ impl RenderGraphPass for LightBasePass {
|
||||||
fn execute(
|
fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
_graph: &mut crate::render::graph::RenderGraph,
|
_graph: &mut crate::render::graph::RenderGraph,
|
||||||
_desc: &crate::render::graph::RenderGraphPassDesc,
|
_desc: &crate::render::graph::NodeDesc,
|
||||||
_context: &mut crate::render::graph::RenderGraphContext,
|
_context: &mut crate::render::graph::RenderGraphContext,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
use crate::render::{
|
use crate::render::{
|
||||||
graph::{
|
graph::{
|
||||||
RenderGraphContext, RenderGraphPass, RenderGraphPassDesc, RenderPassType, SlotAttribute,
|
RenderGraphContext, Node, NodeDesc, NodeType, SlotAttribute,
|
||||||
SlotValue,
|
SlotValue,
|
||||||
},
|
},
|
||||||
resource::{ComputePipelineDescriptor, PipelineDescriptor, Shader},
|
resource::{ComputePipelineDescriptor, PipelineDescriptor, Shader},
|
||||||
|
@ -37,11 +37,11 @@ impl LightCullComputePass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphPass for LightCullComputePass {
|
impl Node for LightCullComputePass {
|
||||||
fn desc(
|
fn desc(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
) -> crate::render::graph::RenderGraphPassDesc {
|
) -> crate::render::graph::NodeDesc {
|
||||||
let shader = Rc::new(Shader {
|
let shader = Rc::new(Shader {
|
||||||
label: Some("light_cull_comp_shader".into()),
|
label: Some("light_cull_comp_shader".into()),
|
||||||
source: include_str!("../../shaders/light_cull.comp.wgsl").to_string(),
|
source: include_str!("../../shaders/light_cull.comp.wgsl").to_string(),
|
||||||
|
@ -176,10 +176,10 @@ impl RenderGraphPass for LightCullComputePass {
|
||||||
let lights_bgl = graph.bind_group_layout(graph.bind_group_id(&LightBasePassSlots::Lights).unwrap());
|
let lights_bgl = graph.bind_group_layout(graph.bind_group_id(&LightBasePassSlots::Lights).unwrap());
|
||||||
let screen_size_bgl = graph.bind_group_layout(graph.bind_group_id(&BasePassSlots::ScreenSize).unwrap());
|
let screen_size_bgl = graph.bind_group_layout(graph.bind_group_id(&BasePassSlots::ScreenSize).unwrap());
|
||||||
|
|
||||||
let mut desc = RenderGraphPassDesc::new(
|
let mut desc = NodeDesc::new(
|
||||||
pass_id,
|
pass_id,
|
||||||
LightCullComputePassLabel,
|
LightCullComputePassLabel,
|
||||||
RenderPassType::Compute,
|
NodeType::Compute,
|
||||||
Some(PipelineDescriptor::Compute(ComputePipelineDescriptor {
|
Some(PipelineDescriptor::Compute(ComputePipelineDescriptor {
|
||||||
label: Some("light_cull_pipeline".into()),
|
label: Some("light_cull_pipeline".into()),
|
||||||
push_constant_ranges: vec![],
|
push_constant_ranges: vec![],
|
||||||
|
@ -228,7 +228,7 @@ impl RenderGraphPass for LightCullComputePass {
|
||||||
fn execute(
|
fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
desc: &crate::render::graph::RenderGraphPassDesc,
|
desc: &crate::render::graph::NodeDesc,
|
||||||
context: &mut RenderGraphContext,
|
context: &mut RenderGraphContext,
|
||||||
) {
|
) {
|
||||||
let mut pass = context.begin_compute_pass(&wgpu::ComputePassDescriptor {
|
let mut pass = context.begin_compute_pass(&wgpu::ComputePassDescriptor {
|
||||||
|
|
|
@ -15,8 +15,8 @@ use wgpu::util::DeviceExt;
|
||||||
use crate::{
|
use crate::{
|
||||||
render::{
|
render::{
|
||||||
desc_buf_lay::DescVertexBufferLayout, graph::{
|
desc_buf_lay::DescVertexBufferLayout, graph::{
|
||||||
RenderGraphContext, RenderGraphPass, RenderGraphPassDesc,
|
RenderGraphContext, Node, NodeDesc,
|
||||||
RenderPassType,
|
NodeType,
|
||||||
}, material::{Material, MaterialUniform}, render_buffer::{BufferStorage, BufferWrapper}, render_job::RenderJob, resource::{FragmentState, PipelineDescriptor, RenderPipelineDescriptor, Shader, VertexState}, texture::RenderTexture, transform_buffer_storage::{TransformBuffers, TransformGroup}, vertex::Vertex
|
}, material::{Material, MaterialUniform}, render_buffer::{BufferStorage, BufferWrapper}, render_job::RenderJob, resource::{FragmentState, PipelineDescriptor, RenderPipelineDescriptor, Shader, VertexState}, texture::RenderTexture, transform_buffer_storage::{TransformBuffers, TransformGroup}, vertex::Vertex
|
||||||
},
|
},
|
||||||
DeltaTime,
|
DeltaTime,
|
||||||
|
@ -201,11 +201,11 @@ impl MeshPass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphPass for MeshPass {
|
impl Node for MeshPass {
|
||||||
fn desc(
|
fn desc(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
) -> crate::render::graph::RenderGraphPassDesc {
|
) -> crate::render::graph::NodeDesc {
|
||||||
|
|
||||||
let device = graph.device();
|
let device = graph.device();
|
||||||
|
|
||||||
|
@ -253,10 +253,10 @@ impl RenderGraphPass for MeshPass {
|
||||||
source: include_str!("../../shaders/base.wgsl").to_string(),
|
source: include_str!("../../shaders/base.wgsl").to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let desc = RenderGraphPassDesc::new(
|
let desc = NodeDesc::new(
|
||||||
pass_id,
|
pass_id,
|
||||||
MeshesPassLabel,
|
MeshesPassLabel,
|
||||||
RenderPassType::Render,
|
NodeType::Render,
|
||||||
Some(PipelineDescriptor::Render(RenderPipelineDescriptor {
|
Some(PipelineDescriptor::Render(RenderPipelineDescriptor {
|
||||||
label: Some("meshes".into()),
|
label: Some("meshes".into()),
|
||||||
layouts: vec![
|
layouts: vec![
|
||||||
|
@ -445,7 +445,7 @@ impl RenderGraphPass for MeshPass {
|
||||||
fn execute(
|
fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
graph: &mut crate::render::graph::RenderGraph,
|
graph: &mut crate::render::graph::RenderGraph,
|
||||||
desc: &crate::render::graph::RenderGraphPassDesc,
|
desc: &crate::render::graph::NodeDesc,
|
||||||
context: &mut crate::render::graph::RenderGraphContext,
|
context: &mut crate::render::graph::RenderGraphContext,
|
||||||
) {
|
) {
|
||||||
let encoder = context.encoder.as_mut().unwrap();
|
let encoder = context.encoder.as_mut().unwrap();
|
||||||
|
@ -453,12 +453,14 @@ impl RenderGraphPass for MeshPass {
|
||||||
let view = graph
|
let view = graph
|
||||||
.slot_value(graph.slot_id(&BasePassSlots::WindowTextureView).unwrap())
|
.slot_value(graph.slot_id(&BasePassSlots::WindowTextureView).unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_texture_view();
|
.as_texture_view()
|
||||||
|
.expect("BasePassSlots::WindowTextureView was not a TextureView slot");
|
||||||
|
|
||||||
let depth_view = graph
|
let depth_view = graph
|
||||||
.slot_value(graph.slot_id(&BasePassSlots::DepthTextureView).unwrap())
|
.slot_value(graph.slot_id(&BasePassSlots::DepthTextureView).unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_texture_view();
|
.as_texture_view()
|
||||||
|
.expect("BasePassSlots::DepthTextureView was not a TextureView slot");
|
||||||
|
|
||||||
let camera_bg = graph
|
let camera_bg = graph
|
||||||
.bind_group(graph.bind_group_id(&BasePassSlots::Camera)
|
.bind_group(graph.bind_group_id(&BasePassSlots::Camera)
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::hash::Hash;
|
||||||
|
|
||||||
use lyra_game_derive::RenderGraphLabel;
|
use lyra_game_derive::RenderGraphLabel;
|
||||||
|
|
||||||
use crate::render::graph::{RenderGraphContext, RenderGraphLabel, RenderGraphLabelValue, RenderGraphPass, RenderGraphPassDesc, RenderPassSlot, RenderPassType, SlotAttribute, SlotType};
|
use crate::render::graph::{RenderGraphContext, RenderGraphLabel, RenderGraphLabelValue, Node, NodeDesc, NodeSlot, NodeType, SlotAttribute, SlotType};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, RenderGraphLabel)]
|
#[derive(Debug, Clone, Hash, PartialEq, RenderGraphLabel)]
|
||||||
pub struct PresentPassLabel(RenderGraphLabelValue);
|
pub struct PresentPassLabel(RenderGraphLabelValue);
|
||||||
|
@ -31,18 +31,18 @@ impl PresentPass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderGraphPass for PresentPass {
|
impl Node for PresentPass {
|
||||||
fn desc(&mut self, graph: &mut crate::render::graph::RenderGraph) -> crate::render::graph::RenderGraphPassDesc {
|
fn desc(&mut self, graph: &mut crate::render::graph::RenderGraph) -> crate::render::graph::NodeDesc {
|
||||||
let mut desc = RenderGraphPassDesc::new(
|
let mut desc = NodeDesc::new(
|
||||||
graph.next_id(),
|
graph.next_id(),
|
||||||
self.label.clone(),
|
self.label.clone(),
|
||||||
RenderPassType::Presenter,
|
NodeType::Presenter,
|
||||||
None,
|
None,
|
||||||
vec![],
|
vec![],
|
||||||
);
|
);
|
||||||
|
|
||||||
desc.add_slot(
|
desc.add_slot(
|
||||||
RenderPassSlot {
|
NodeSlot {
|
||||||
ty: SlotType::RenderTarget,
|
ty: SlotType::RenderTarget,
|
||||||
attribute: SlotAttribute::Input,
|
attribute: SlotAttribute::Input,
|
||||||
id: graph.next_id(),
|
id: graph.next_id(),
|
||||||
|
@ -58,7 +58,7 @@ impl RenderGraphPass for PresentPass {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(&mut self, graph: &mut crate::render::graph::RenderGraph, _desc: &crate::render::graph::RenderGraphPassDesc, _context: &mut crate::render::graph::RenderGraphContext) {
|
fn execute(&mut self, graph: &mut crate::render::graph::RenderGraph, _desc: &crate::render::graph::NodeDesc, _context: &mut crate::render::graph::RenderGraphContext) {
|
||||||
let id = graph.slot_id_rc(&self.label.0)
|
let id = graph.slot_id_rc(&self.label.0)
|
||||||
.expect(&format!("render target slot '{:?}' for PresentPass is missing", self.label.0));
|
.expect(&format!("render target slot '{:?}' for PresentPass is missing", self.label.0));
|
||||||
let mut slot = graph.slot_value_mut(id).unwrap().as_render_target_mut().unwrap();
|
let mut slot = graph.slot_value_mut(id).unwrap().as_render_target_mut().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue