From d5348ec1723e86a52589b328733acf5f213055e3 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Wed, 12 Jun 2024 21:30:09 -0400 Subject: [PATCH] render: a tiny bit of code cleanup --- lyra-game/src/render/graph/mod.rs | 32 ++++++++++++------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lyra-game/src/render/graph/mod.rs b/lyra-game/src/render/graph/mod.rs index 7fd0ec4..89111f3 100644 --- a/lyra-game/src/render/graph/mod.rs +++ b/lyra-game/src/render/graph/mod.rs @@ -119,16 +119,8 @@ pub struct RenderGraph { device: Rc, queue: Rc, slots: FxHashMap, - /// HashMap used to lookup the slot id using the label's hash - //slot_label_lookup: FxHashMap, - passes: FxHashMap, - // TODO: Use a SlotMap + nodes: FxHashMap, bind_groups: FxHashMap, - /// HashMap used to lookup the bind group id using the label's hash - //bind_group_names: FxHashMap, - // TODO: make pipelines a `type` parameter in RenderPasses, - // then the pipelines can be retrieved via TypeId to the pass. - //pipelines: FxHashMap, /// A directed graph describing the execution path of the RenderGraph execution_graph: petgraph::matrix_graph::DiMatrix, usize>, } @@ -139,7 +131,7 @@ impl RenderGraph { device, queue, slots: Default::default(), - passes: Default::default(), + nodes: Default::default(), bind_groups: Default::default(), execution_graph: Default::default(), } @@ -213,7 +205,7 @@ impl RenderGraph { let label: RenderGraphLabelValue = label.into(); let index = self.execution_graph.add_node(label.clone()); - self.passes.insert( + self.nodes.insert( label, PassEntry { inner: Arc::new(RefCell::new(pass)), @@ -231,7 +223,7 @@ impl RenderGraph { #[instrument(skip(self, device))] pub fn setup(&mut self, device: &wgpu::Device) { // For all passes, create their pipelines - for pass in self.passes.values_mut() { + for pass in self.nodes.values_mut() { let desc = (*pass.desc).borrow(); if let Some(pipeline_desc) = &desc.pipeline_desc { let pipeline = match desc.ty { @@ -270,9 +262,9 @@ impl RenderGraph { let mut buffer_writes = VecDeque::::new(); // reserve some buffer writes. not all nodes write so half the amount of them is probably // fine. - buffer_writes.reserve(self.passes.len() / 2); + buffer_writes.reserve(self.nodes.len() / 2); - for (label, pass) in &mut self.passes { + for (label, pass) in &mut self.nodes { let mut context = RenderGraphContext::new(&self.device, &self.queue, None, label.clone()); let mut inner = pass.inner.borrow_mut(); inner.prepare(world, &mut context); @@ -311,9 +303,9 @@ impl RenderGraph { .collect(); //debug!("Render graph execution order: {:?}", sorted); - let mut encoders = Vec::with_capacity(self.passes.len() / 2); + let mut encoders = Vec::with_capacity(self.nodes.len() / 2); while let Some(pass_label) = sorted.pop_front() { - let pass = self.passes.get(&pass_label).unwrap(); + let pass = self.nodes.get(&pass_label).unwrap(); let pass_inn = pass.inner.clone(); let pass_desc = pass.desc.clone(); @@ -373,12 +365,12 @@ impl RenderGraph { } pub fn node_desc>(&self, label: L) -> Option> { - self.passes.get(&label.into()).map(|s| (*s.desc).borrow()) + self.nodes.get(&label.into()).map(|s| (*s.desc).borrow()) } #[inline(always)] pub fn pipeline>(&self, label: L) -> Option> { - self.passes.get(&label.into()) + self.nodes.get(&label.into()) .and_then(|p| { let v = p.pipeline.borrow(); @@ -416,13 +408,13 @@ impl RenderGraph { let to = RenderGraphLabelValue::from(to); let from_idx = self - .passes + .nodes .iter() .find(|p| *p.0 == from) .map(|p| p.1.graph_index) .expect("Failed to find from pass"); let to_idx = self - .passes + .nodes .iter() .find(|p| *p.0 == to) .map(|p| p.1.graph_index)