rafx_framework/render_features/jobs/prepare/
submit_packet.rs1use crate::render_features::render_features_prelude::*;
2
3pub trait SubmitPacketData {
13 type PerFrameSubmitData: Sync + Send;
16
17 type RenderObjectInstanceSubmitData: Sync + Send;
20
21 type PerViewSubmitData: Sync + Send;
25
26 type RenderObjectInstancePerViewSubmitData: Sync + Send;
29
30 type SubmitNodeData: Sync + Send;
33
34 type RenderFeature: RenderFeature;
38
39 }
42
43pub struct SubmitPacket<SubmitPacketDataT: SubmitPacketData> {
45 feature_index: RenderFeatureIndex,
46
47 pub(crate) per_frame_submit_data: AtomicOnceCell<SubmitPacketDataT::PerFrameSubmitData>,
48 pub(crate) render_object_instances_submit_data:
49 AtomicOnceCellArray<SubmitPacketDataT::RenderObjectInstanceSubmitData>,
50
51 view_submit_packets: Vec<ViewSubmitPacket<SubmitPacketDataT>>,
52}
53
54impl<SubmitPacketDataT: SubmitPacketData + Send + Sync + 'static> SubmitPacket<SubmitPacketDataT> {
55 pub fn new(
56 feature_index: RenderFeatureIndex,
57 num_render_object_instances: usize,
58 view_submit_packets: Vec<ViewSubmitPacket<SubmitPacketDataT>>,
59 ) -> Self {
60 #[cfg(debug_assertions)]
61 for (i, vp) in view_submit_packets.iter().enumerate() {
62 assert_eq!(i, vp.view_frame_index() as usize);
63 }
64
65 Self {
66 feature_index,
67 per_frame_submit_data: AtomicOnceCell::new(),
68 render_object_instances_submit_data: AtomicOnceCellArray::with_capacity(
69 num_render_object_instances,
70 ),
71 view_submit_packets,
72 }
73 }
74
75 pub fn view_submit_packets(&self) -> &Vec<ViewSubmitPacket<SubmitPacketDataT>> {
76 &self.view_submit_packets
77 }
78
79 pub fn view_submit_packet(
80 &self,
81 view_frame_index: ViewFrameIndex,
82 ) -> &ViewSubmitPacket<SubmitPacketDataT> {
83 self.view_submit_packets
84 .get(view_frame_index as usize)
85 .unwrap_or_else(|| {
86 panic!(
87 "ViewSubmitPacket with ViewFrameIndex {} was not found in {}.",
88 view_frame_index,
89 std::any::type_name::<SubmitPacketDataT>()
90 )
91 })
92 }
93
94 pub fn render_object_instances_submit_data(
95 &self
96 ) -> &AtomicOnceCellArray<SubmitPacketDataT::RenderObjectInstanceSubmitData> {
97 &self.render_object_instances_submit_data
98 }
99
100 pub fn per_frame_submit_data(&self) -> &AtomicOnceCell<SubmitPacketDataT::PerFrameSubmitData> {
101 &self.per_frame_submit_data
102 }
103}
104
105impl<SubmitPacketDataT: 'static + Send + Sync + SubmitPacketData> RenderFeatureSubmitPacket
106 for SubmitPacket<SubmitPacketDataT>
107{
108 fn render_feature_view_submit_packet(
109 &self,
110 view_index: ViewFrameIndex,
111 ) -> &dyn RenderFeatureViewSubmitPacket {
112 self.view_submit_packet(view_index)
113 }
114
115 fn feature_index(&self) -> u32 {
116 self.feature_index
117 }
118}