euv_core/layout/partition/
impl.rs1use super::*;
2
3impl Default for SubtreePartitionConfig {
5 fn default() -> Self {
11 Self {
12 min_gpu_nodes: DEFAULT_MIN_GPU_SUBTREE_NODES,
13 max_text_wrap_ratio: DEFAULT_MAX_GPU_TEXT_WRAP_RATIO,
14 max_gpu_depth: DEFAULT_MAX_GPU_SUBTREE_DEPTH,
15 hardware_compute_ready: false,
16 thermal_throttled: false,
17 }
18 }
19}
20
21impl Default for SubtreePartitionPlanner {
23 fn default() -> Self {
29 Self {
30 config: SubtreePartitionConfig::default(),
31 boundaries: HashMap::new(),
32 }
33 }
34}
35
36impl SubtreePartitionEntry {
38 #[must_use]
44 pub fn reject_reason_value(&self) -> Option<GpuSubtreeRejectReason> {
45 let Self { reject_reason, .. } = *self;
46 reject_reason
47 }
48}
49
50impl SubtreePartitionPlanner {
52 #[must_use]
62 pub fn with_config(config: SubtreePartitionConfig) -> Self {
63 Self {
64 config,
65 boundaries: HashMap::new(),
66 }
67 }
68
69 pub fn register_boundary(&mut self, boundary: LayoutBoundary) {
75 let _: Option<LayoutBoundary> = self
76 .get_mut_boundaries()
77 .insert(boundary.get_root_node(), boundary);
78 }
79
80 pub fn clear_boundaries(&mut self) {
82 self.get_mut_boundaries().clear();
83 }
84
85 #[must_use]
95 pub fn plan_tree(&self, tree: &SceneTree) -> SubtreePartitionPlan {
96 let root_id: NodeId = tree.get_root();
97 let config: SubtreePartitionConfig = self.get_config();
98 let mut candidate_roots: Vec<NodeId> = Vec::new();
99 for child_id in tree.children_iter(root_id) {
100 candidate_roots.push(child_id);
101 }
102 if candidate_roots.is_empty() {
103 candidate_roots.push(root_id);
104 }
105 let mut entries: Vec<SubtreePartitionEntry> = Vec::with_capacity(candidate_roots.len());
106 let mut cpu_node_count: usize = 1;
107 let mut gpu_node_count: usize = 0;
108 let mut cpu_subtree_count: usize = 0;
109 let mut gpu_subtree_count: usize = 0;
110 for candidate_id in candidate_roots {
111 let metrics: SubtreePartitionMetrics = measure_subtree_metrics(tree, candidate_id);
112 let boundary: Option<LayoutBoundary> =
113 self.get_boundaries().get(&candidate_id).copied();
114 let (lane, reject_reason): (SubtreeLane, Option<GpuSubtreeRejectReason>) =
115 match evaluate_subtree_gpu_eligibility(metrics, boundary, config) {
116 Ok(assigned_lane) => (assigned_lane, None),
117 Err(reason) => (SubtreeLane::CpuSubtree, Some(reason)),
118 };
119 match lane {
120 SubtreeLane::GpuSubtree => {
121 gpu_subtree_count = gpu_subtree_count.saturating_add(1);
122 gpu_node_count = gpu_node_count.saturating_add(metrics.get_total_nodes());
123 }
124 SubtreeLane::CpuSubtree => {
125 cpu_subtree_count = cpu_subtree_count.saturating_add(1);
126 cpu_node_count = cpu_node_count.saturating_add(metrics.get_total_nodes());
127 }
128 }
129 entries.push(SubtreePartitionEntry {
130 root_node: candidate_id,
131 lane,
132 metrics,
133 reject_reason,
134 });
135 }
136 let requires_mixed_coexec: bool = gpu_subtree_count > 0 && cpu_subtree_count > 0;
137 SubtreePartitionPlan {
138 entries,
139 cpu_node_count,
140 gpu_node_count,
141 cpu_subtree_count,
142 gpu_subtree_count,
143 requires_mixed_coexec,
144 }
145 }
146}