rafx_renderer/renderer_thread_pool.rs
1use crate::RenderFeaturePlugin;
2use rafx_framework::render_features::render_features_prelude::*;
3use std::sync::Arc;
4
5/// An application may implement `RendererThreadPool` to control the degree and method
6/// of parallelization used for each entry point defined by `RendererThreadPool`.
7///
8/// # Extract
9///
10/// The `extract` step contains the `run_view_visibility_jobs`, `count_render_features_render_objects`,
11/// `create_extract_jobs`, and `run_extract_jobs` entry points.
12///
13/// # Prepare
14///
15/// The `prepare` step contains the `run_prepare_jobs` and `create_submit_node_blocks` entry points.
16///
17/// # Write
18///
19/// The `write` step is not able to be parallelized in this release.
20pub trait RendererThreadPool: Sync + Send {
21 /// Each `RenderView` has an associated `ViewVisibilityJob` for calculating visible render objects
22 /// from that `RenderView`.
23 fn run_view_visibility_jobs<'extract>(
24 &mut self,
25 view_visibility_jobs: &[Arc<ViewVisibilityJob>],
26 extract_context: &RenderJobExtractContext<'extract>,
27 visibility_resource: &VisibilityResource,
28 ) -> Vec<RenderViewVisibilityQuery>;
29
30 /// All of the visibility results from `run_view_visibility_jobs` for all of the `RenderView`s
31 /// must be processed to size the `FramePacket` for each `RenderFeature`.
32 fn count_render_features_render_objects<'extract>(
33 &mut self,
34 features: &Vec<Arc<dyn RenderFeaturePlugin>>,
35 extract_context: &RenderJobExtractContext<'extract>,
36 visibility_results: &Vec<RenderViewVisibilityQuery>,
37 );
38
39 /// Each `RenderFeature` must populate its `FramePacket` and `ViewPacket`s with the mapping of
40 /// `RenderObjectInstance` and `RenderObjectInstancePerView` for the current frame using the
41 /// visibility results.
42 fn create_extract_jobs<'extract>(
43 &mut self,
44 features: &Vec<Arc<dyn RenderFeaturePlugin>>,
45 extract_context: &RenderJobExtractContext<'extract>,
46 visibility_results: Vec<RenderViewVisibilityQuery>,
47 ) -> Vec<Arc<dyn RenderFeatureExtractJob<'extract> + 'extract>>;
48
49 /// Each `RenderFeature` uses the `RenderFeatureExtractJob` to copy data from the game world and
50 /// other resources into the `RenderFeature`s `FramePacket`.
51 fn run_extract_jobs<'extract>(
52 &mut self,
53 extract_jobs: &Vec<Arc<dyn RenderFeatureExtractJob<'extract> + 'extract>>,
54 visibility_resource: &VisibilityResource,
55 );
56
57 /// Each `RenderFeature` uses the `RenderFeaturePrepareJob` to process data from the `FramePacket`
58 /// into the `RenderFeature`s `SubmitPacket`.
59 fn run_prepare_jobs<'prepare>(
60 &mut self,
61 prepare_jobs: &Vec<Arc<dyn RenderFeaturePrepareJob<'prepare> + 'prepare>>,
62 );
63
64 /// The output of each `RenderFeature`'s `prepare` step is one or more `SubmitNodeBlock`s containing
65 /// `SubmitNode`s for a particular `View` and `RenderPhase`. This entry point is responsible for
66 /// combining all `SubmitBlock`s across **all** `RenderFeature`s matching a specific `View` and
67 /// `RenderPhase` into a single contiguous `ViewPhaseSubmitNodeBlock` and then sorting all of the
68 /// `SubmitNode`s in that block according to the `RenderPhase`s sort function.
69 fn create_submit_node_blocks<'prepare>(
70 &mut self,
71 render_registry: &RenderRegistry,
72 render_view_submit_nodes: &RenderViewSubmitNodeCount,
73 finished_prepare_jobs: &Vec<Arc<dyn RenderFeaturePrepareJob<'prepare> + 'prepare>>,
74 ) -> SubmitNodeBlocks;
75
76 fn clone_to_box(&mut self) -> Box<dyn RendererThreadPool>;
77}