implements PLN-0091

This commit is contained in:
2026-06-05 09:41:09 +01:00
parent 84daa5fd70
commit dcfc258aeb
5 changed files with 93 additions and 5 deletions
@@ -14,6 +14,46 @@ pub enum RenderSubmissionError {
PacketAppModeMismatch { active: AppMode },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RenderPacingPolicy {
FrameScheduled,
LifecycleDriven,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RenderExecutionPolicy {
LocalSynchronous,
WorkerCapableWithLocalFallback,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RenderPolicy {
pub app_mode: AppMode,
pub pacing: RenderPacingPolicy,
pub execution: RenderExecutionPolicy,
}
impl RenderPolicy {
pub const fn for_app_mode(app_mode: AppMode) -> Self {
match app_mode {
AppMode::Game => Self {
app_mode,
pacing: RenderPacingPolicy::FrameScheduled,
execution: RenderExecutionPolicy::WorkerCapableWithLocalFallback,
},
AppMode::Shell => Self {
app_mode,
pacing: RenderPacingPolicy::LifecycleDriven,
execution: RenderExecutionPolicy::LocalSynchronous,
},
}
}
pub const fn uses_frame_scheduler(self) -> bool {
matches!(self.pacing, RenderPacingPolicy::FrameScheduled)
}
}
pub trait RenderSurface {
fn consume_submission(&mut self, submission: &RenderSubmission);
}
@@ -69,6 +109,7 @@ impl RenderHandoff {
#[derive(Debug, Clone)]
pub struct RenderManager {
active_app_mode: AppMode,
active_policy: RenderPolicy,
next_frame_id: FrameId,
handoff: RenderHandoff,
transition_state: RenderTransitionState,
@@ -78,6 +119,7 @@ impl RenderManager {
pub fn new(active_app_mode: AppMode) -> Self {
Self {
active_app_mode,
active_policy: RenderPolicy::for_app_mode(active_app_mode),
next_frame_id: FrameId::ZERO,
handoff: RenderHandoff::default(),
transition_state: RenderTransitionState::Idle,
@@ -88,6 +130,14 @@ impl RenderManager {
self.active_app_mode
}
pub fn active_render_policy(&self) -> RenderPolicy {
self.active_policy
}
pub fn policy_for_app_mode(app_mode: AppMode) -> RenderPolicy {
RenderPolicy::for_app_mode(app_mode)
}
pub fn transition_state(&self) -> RenderTransitionState {
self.transition_state
}
@@ -119,6 +169,7 @@ impl RenderManager {
let previous = self.active_app_mode;
self.active_app_mode = app_mode;
self.active_policy = RenderPolicy::for_app_mode(app_mode);
self.transition_state = RenderTransitionState::Pending { from: previous, to: app_mode };
}
@@ -239,6 +290,35 @@ mod tests {
assert_eq!(manager.transition_state(), RenderTransitionState::Idle);
}
#[test]
fn render_policy_maps_game_to_frame_scheduled_worker_capable() {
let policy = RenderPolicy::for_app_mode(AppMode::Game);
assert_eq!(policy.pacing, RenderPacingPolicy::FrameScheduled);
assert_eq!(policy.execution, RenderExecutionPolicy::WorkerCapableWithLocalFallback);
assert!(policy.uses_frame_scheduler());
}
#[test]
fn render_policy_maps_shell_to_lifecycle_driven_local_sync() {
let policy = RenderPolicy::for_app_mode(AppMode::Shell);
assert_eq!(policy.pacing, RenderPacingPolicy::LifecycleDriven);
assert_eq!(policy.execution, RenderExecutionPolicy::LocalSynchronous);
assert!(!policy.uses_frame_scheduler());
}
#[test]
fn active_render_policy_follows_app_mode_transition() {
let mut manager = RenderManager::new(AppMode::Game);
assert_eq!(manager.active_render_policy(), RenderPolicy::for_app_mode(AppMode::Game));
manager.set_active_app_mode(AppMode::Shell);
assert_eq!(manager.active_render_policy(), RenderPolicy::for_app_mode(AppMode::Shell));
}
#[test]
fn publish_latest_hands_submission_to_surface() {
let mut manager = RenderManager::new(AppMode::Game);
@@ -484,6 +484,8 @@ fn tick_shell_profile_closes_gfxui_commands_into_shell_packet() {
assert_eq!(packet.commands.len(), 1);
assert!(matches!(packet.commands[0], prometeu_hal::GfxUiCommand::Clear { .. }));
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x11223344).raw());
assert_eq!(runtime.frame_scheduler.completed_game_frames(), 0);
assert_eq!(runtime.frame_scheduler.active_game_frame_id(), None);
}
#[test]
@@ -833,6 +835,7 @@ fn tick_game_submissions_are_immutable_and_latest_complete_wins() {
prometeu_hal::Gfx2dCommand::Clear { color } if color == Color::from_raw(0x11223344)
));
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x11223344).raw());
assert_eq!(runtime.frame_scheduler.completed_game_frames(), 1);
let second_packet = prometeu_hal::Game2DFramePacket::new(
Default::default(),
@@ -141,7 +141,9 @@ impl VirtualMachineRuntime {
self.update_fs(log_service, fs, fs_state);
if !self.logical_frame_active {
if self.current_cartridge_app_mode == AppMode::Game {
if RenderManager::policy_for_app_mode(self.current_cartridge_app_mode)
.uses_frame_scheduler()
{
self.frame_scheduler
.authorize_game_frame()
.expect("logical frame cannot start while another Game frame is active");
@@ -322,7 +324,9 @@ impl VirtualMachineRuntime {
self.logical_frame_index += 1;
self.logical_frame_active = false;
self.logical_frame_remaining_cycles = 0;
if self.current_cartridge_app_mode == AppMode::Game {
if RenderManager::policy_for_app_mode(self.current_cartridge_app_mode)
.uses_frame_scheduler()
{
self.frame_scheduler.complete_game_frame();
}
@@ -335,7 +339,8 @@ impl VirtualMachineRuntime {
self.debug_step_request = false;
}
} else if run.reason == LogicalFrameEndingReason::BudgetExhausted
&& self.current_cartridge_app_mode == AppMode::Game
&& RenderManager::policy_for_app_mode(self.current_cartridge_app_mode)
.uses_frame_scheduler()
{
self.frame_scheduler.record_logical_frame_overrun();
}