[PERF] Host Debug Overlay Isolation

This commit is contained in:
2026-04-10 14:10:20 +01:00
parent b8d33c9e02
commit 58a5f9a3a6
18 changed files with 1315 additions and 123 deletions
@@ -3,6 +3,7 @@ use crate::debugger::HostDebugger;
use crate::fs_backend::HostDirBackend;
use crate::input::HostInputHandler;
use crate::log_sink::HostConsoleSink;
use crate::overlay::{capture_snapshot, draw_overlay};
use crate::stats::HostStats;
use crate::utilities::draw_rgb565_to_rgba8;
use pixels::wgpu::PresentMode;
@@ -10,7 +11,6 @@ use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
use prometeu_drivers::AudioCommand;
use prometeu_drivers::hardware::Hardware;
use prometeu_firmware::{BootTarget, Firmware};
use prometeu_hal::color::Color;
use prometeu_hal::telemetry::CertificationConfig;
use std::time::{Duration, Instant};
use winit::application::ApplicationHandler;
@@ -123,110 +123,6 @@ impl HostRunner {
}
}
fn display_dbg_overlay(&mut self) {
let tel = self.firmware.os.atomic_telemetry.snapshot();
let color_text = Color::WHITE;
let color_bg = Color::INDIGO; // Dark blue to stand out
let color_warn = Color::RED;
self.hardware.gfx.fill_rect(5, 5, 175, 130, color_bg);
self.hardware.gfx.draw_text(
10,
10,
&format!("FPS: {:.1}", self.stats.current_fps),
color_text,
);
self.hardware.gfx.draw_text(
10,
18,
&format!("HOST: {:.2}MS", tel.host_cpu_time_us as f64 / 1000.0),
color_text,
);
self.hardware.gfx.draw_text(10, 26, &format!("STEPS: {}", tel.vm_steps), color_text);
self.hardware.gfx.draw_text(10, 34, &format!("SYSC: {}", tel.syscalls), color_text);
let cycles_pct = if tel.cycles_budget > 0 {
(tel.cycles_used as f64 / tel.cycles_budget as f64) * 100.0
} else {
0.0
};
self.hardware.gfx.draw_text(
10,
42,
&format!("CYC: {}/{} ({:.1}%)", tel.cycles_used, tel.cycles_budget, cycles_pct),
color_text,
);
self.hardware.gfx.draw_text(
10,
50,
&format!("GFX: {}K/16M ({}S)", tel.gfx_used_bytes / 1024, tel.gfx_slots_occupied),
color_text,
);
if tel.gfx_inflight_bytes > 0 {
self.hardware.gfx.draw_text(
10,
58,
&format!("LOAD GFX: {}KB", tel.gfx_inflight_bytes / 1024),
color_warn,
);
}
self.hardware.gfx.draw_text(
10,
66,
&format!("AUD: {}K/32M ({}S)", tel.audio_used_bytes / 1024, tel.audio_slots_occupied),
color_text,
);
if tel.audio_inflight_bytes > 0 {
self.hardware.gfx.draw_text(
10,
74,
&format!("LOAD AUD: {}KB", tel.audio_inflight_bytes / 1024),
color_warn,
);
}
self.hardware.gfx.draw_text(
10,
82,
&format!("RAM: {}KB", tel.heap_used_bytes / 1024),
color_text,
);
self.hardware.gfx.draw_text(10, 90, &format!("LOGS: {}", tel.logs_count), color_text);
// Snapshot does not include violations, as they are part of certification (logical end of frame)
// But for visual debug, we can check if there are recent CA tags in logs
let recent_logs = self.firmware.os.log_service.get_recent(10);
let violations_count =
recent_logs.iter().filter(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07).count();
let cert_color = if violations_count > 0 { color_warn } else { color_text };
self.hardware.gfx.draw_text(
10,
98,
&format!("CERT RECENT: {}", violations_count),
cert_color,
);
if violations_count > 0
&& let Some(event) =
recent_logs.into_iter().rev().find(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07)
{
let mut msg = event.msg.clone();
if msg.len() > 30 {
msg.truncate(30);
}
self.hardware.gfx.draw_text(10, 106, &msg, color_warn);
}
if let Some(report) = self.firmware.os.last_crash_report.as_ref() {
let mut msg = report.summary();
if msg.len() > 30 {
msg.truncate(30);
}
self.hardware.gfx.draw_text(10, 114, &msg, color_warn);
}
}
}
impl ApplicationHandler for HostRunner {
@@ -280,6 +176,9 @@ impl ApplicationHandler for HostRunner {
}
WindowEvent::RedrawRequested => {
let overlay_snapshot =
self.overlay_enabled.then(|| capture_snapshot(&self.stats, &self.firmware));
// Get Pixels directly from the field (not via helper that gets the entire &mut self)
let pixels = self.pixels.as_mut().expect("pixels not initialized");
@@ -291,6 +190,10 @@ impl ApplicationHandler for HostRunner {
let src = self.hardware.gfx.front_buffer();
draw_rgb565_to_rgba8(src, frame);
if let Some(snapshot) = overlay_snapshot.as_ref() {
draw_overlay(frame, Hardware::W, Hardware::H, snapshot);
}
} // <- frame borrow ends here
if pixels.render().is_err() {
@@ -358,6 +261,7 @@ impl ApplicationHandler for HostRunner {
// Unless the debugger is waiting for a 'start' command, advance the system.
if !self.debugger.waiting_for_start {
self.firmware.tick(&self.input.signals, &mut self.hardware);
self.stats.record_host_cpu_time(self.firmware.os.last_frame_cpu_time_us);
}
// Sync pause state with audio.
@@ -393,15 +297,8 @@ impl ApplicationHandler for HostRunner {
};
self.log_sink.process_events(new_events);
// 5. Rendering the Telemetry Overlay (if enabled).
if self.overlay_enabled {
// We temporarily swap buffers to draw over the current image.
self.hardware.gfx.present();
self.display_dbg_overlay();
self.hardware.gfx.present();
}
// Finally, request a window redraw to present the new pixels.
// 5. Request redraw so the host surface can present the latest machine frame
// and, when enabled, compose the overlay in the host-only RGBA surface.
self.request_redraw();
}
}