Skip to main content

katra_core/
deadline.rs

1//! Deadline classes (Katra3D ยง15).
2//!
3//! Work is classified by urgency. The scheduler and prefetcher must never
4//! starve required work in favor of speculative work.
5
6use serde::{Deserialize, Serialize};
7
8/// Urgency classification for graph nodes and I/O operations.
9#[derive(
10    Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
11)]
12#[serde(rename_all = "snake_case")]
13pub enum DeadlineClass {
14    /// Needed for the frame currently being produced.
15    #[default]
16    ThisFrame,
17    /// Needed for the next frame.
18    NextFrame,
19    /// Blocks a scene transition.
20    SceneTransition,
21    /// Blocks a loading screen.
22    LoadingScreen,
23    /// Background streaming; should not block frames.
24    BackgroundStreaming,
25    /// Speculative prefetch; may be dropped under pressure.
26    SpeculativePrefetch,
27}
28
29impl DeadlineClass {
30    /// All classes in priority order (highest first).
31    pub const ALL: [DeadlineClass; 6] = [
32        DeadlineClass::ThisFrame,
33        DeadlineClass::NextFrame,
34        DeadlineClass::SceneTransition,
35        DeadlineClass::LoadingScreen,
36        DeadlineClass::BackgroundStreaming,
37        DeadlineClass::SpeculativePrefetch,
38    ];
39
40    /// Numeric priority; lower runs first. 0 = most urgent.
41    pub const fn priority(self) -> u8 {
42        match self {
43            DeadlineClass::ThisFrame => 0,
44            DeadlineClass::NextFrame => 1,
45            DeadlineClass::SceneTransition => 2,
46            DeadlineClass::LoadingScreen => 3,
47            DeadlineClass::BackgroundStreaming => 4,
48            DeadlineClass::SpeculativePrefetch => 5,
49        }
50    }
51
52    /// Stable string name.
53    pub const fn as_str(self) -> &'static str {
54        match self {
55            DeadlineClass::ThisFrame => "this_frame",
56            DeadlineClass::NextFrame => "next_frame",
57            DeadlineClass::SceneTransition => "scene_transition",
58            DeadlineClass::LoadingScreen => "loading_screen",
59            DeadlineClass::BackgroundStreaming => "background_streaming",
60            DeadlineClass::SpeculativePrefetch => "speculative_prefetch",
61        }
62    }
63}
64
65impl std::fmt::Display for DeadlineClass {
66    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67        f.write_str(self.as_str())
68    }
69}