# graph_runner_stage.rs - source
Source of the Rust file `maplibre/src/render/stages/graph_runner_stage.rs`.
Keywords: rust, rustlang, rust-lang

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72

    //! Executes the [`RenderGraph`] current render graph.

    use crate::context::MapContext;
    use crate::render::graph::{EmptyNode, RenderGraph};
    use crate::render::graph_runner::RenderGraphRunner;
    use crate::render::main_pass::{MainPassDriverNode, MainPassNode};
    use crate::render::util::Eventually::Initialized;
    use crate::schedule::Stage;
    use crate::Renderer;
    use log::error;

    /// Updates the [`RenderGraph`] with all of its nodes and then runs it to render the entire frame.
    pub struct GraphRunnerStage {
        graph: RenderGraph,
    }

    impl GraphRunnerStage {
        pub fn new(graph: RenderGraph) -> Self {
            Self { graph }
        }
    }

    impl Stage for GraphRunnerStage {
        fn run(
            &mut self,
            MapContext {
                renderer:
                    Renderer {
                        device,
                        queue,
                        state,
                        ..
                    },
                ..
            }: &mut MapContext,
        ) {
            self.graph.update(state);

            if let Err(e) = RenderGraphRunner::run(&self.graph, device, queue, state) {
                error!("Error running render graph:");
                {
                    let mut src: &dyn std::error::Error = &e;
                    loop {
                        error!("> {}", src);
                        match src.source() {
                            Some(s) => src = s,
                            None => break,
                        }
                    }
                }

                panic!("Error running render graph: {:?}", e);
            }

            {
                let _span = tracing::info_span!("present_frames").entered();

                if let Initialized(render_target) = state.render_target.take() {
                    if let Some(surface_texture) = render_target.take_surface_texture() {
                        surface_texture.present();
                    }

                    #[cfg(feature = "tracing-tracy")]
                    tracing::event!(
                        tracing::Level::INFO,
                        message = "finished frame",
                        tracy.frame_mark = true
                    );
                }
            }
        }
    }