feat(graphics): migrate native target to 640x360
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Centralize the fixed 640x360 RGBA8888/60 Hz contract in the existing HAL. Preserve 8/16/32 tiles and composition, cover partial edges and mixed-size camera movement, and adapt firmware, fixtures, hosts and native tests. Share nearest-neighbor presentation geometry with pointer input. Measure actual framebuffer publications and successful host presentations separately from VM ticks, with bounded opt-in diagnostics and release harnesses. Validated with the complete tooling verify gate, native rendering tests, GPU readback, headless/process integration, formatting and strict clippy. The existing synchronous session path is documented; no worker/session architecture replacement or format compatibility layer is introduced. Work: WRK-0016 / DEC-0001 / PLN-0001 Commit and push explicitly authorized by the user after completion.
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
//! Controlled graphics measurement. This is not a cartridge stress-suite replacement.
|
||||
use prometeu_drivers::{Gfx, GlyphBankPoolInstaller, MemoryBanks, hardware::Hardware};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::glyph::Glyph;
|
||||
use prometeu_hal::glyph_bank::{GlyphBank, TileSize};
|
||||
use prometeu_hal::scene_bank::SceneBank;
|
||||
use prometeu_hal::scene_layer::{ParallaxFactor, SceneLayer};
|
||||
use prometeu_hal::scene_viewport_cache::SceneViewportCache;
|
||||
use prometeu_hal::scene_viewport_resolver::SceneViewportResolver;
|
||||
use prometeu_hal::sprite::Sprite;
|
||||
use prometeu_hal::tile::Tile;
|
||||
use prometeu_hal::tilemap::TileMap;
|
||||
use prometeu_hal::{FrameId, OwnedRgba8888Frame, RenderOwnership, app_mode::AppMode};
|
||||
use std::alloc::{GlobalAlloc, Layout, System};
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
use std::time::Instant;
|
||||
|
||||
struct CountingAllocator;
|
||||
static LIVE: AtomicUsize = AtomicUsize::new(0);
|
||||
static PEAK: AtomicUsize = AtomicUsize::new(0);
|
||||
static ALLOCATIONS: AtomicUsize = AtomicUsize::new(0);
|
||||
// Only the measurement executable pays the atomic allocation instrumentation cost.
|
||||
unsafe impl GlobalAlloc for CountingAllocator {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
let ptr = unsafe { System.alloc(layout) };
|
||||
if !ptr.is_null() {
|
||||
let live = LIVE.fetch_add(layout.size(), Ordering::Relaxed) + layout.size();
|
||||
PEAK.fetch_max(live, Ordering::Relaxed);
|
||||
ALLOCATIONS.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
ptr
|
||||
}
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
LIVE.fetch_sub(layout.size(), Ordering::Relaxed);
|
||||
unsafe { System.dealloc(ptr, layout) };
|
||||
}
|
||||
}
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: CountingAllocator = CountingAllocator;
|
||||
|
||||
fn summary(samples: &mut [u64]) -> serde_json::Value {
|
||||
samples.sort_unstable();
|
||||
let n = samples.len();
|
||||
serde_json::json!({"mean_us": samples.iter().sum::<u64>() as f64 / n as f64 / 1000.0,
|
||||
"p95_us": samples[(n * 95).div_ceil(100) - 1] as f64 / 1000.0,
|
||||
"p99_us": samples[(n * 99).div_ceil(100) - 1] as f64 / 1000.0,
|
||||
"max_us": samples[n-1] as f64 / 1000.0,
|
||||
"over_60hz_budget": samples.iter().filter(|&&v| v > 1_000_000_000 / 60).count()})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let count: usize =
|
||||
std::env::args().nth(1).map(|v| v.parse().expect("frame count")).unwrap_or(600);
|
||||
assert!(count > 0);
|
||||
let (w, h) = (Hardware::W, Hardware::H);
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let mixed = std::env::args().nth(2).as_deref() == Some("mixed");
|
||||
let sizes = if mixed {
|
||||
[TileSize::Size8, TileSize::Size16, TileSize::Size32, TileSize::Size8]
|
||||
} else {
|
||||
[TileSize::Size16; 4]
|
||||
};
|
||||
for (i, size) in sizes.iter().enumerate() {
|
||||
let edge = *size as usize;
|
||||
let mut bank = GlyphBank::new(*size, edge, edge);
|
||||
bank.palettes[0][1] = Color::rgba((i * 47 + 30) as u8, 120, 210, 255);
|
||||
// Transparent holes make all four layers participate in the visible output.
|
||||
for (p, pixel) in bank.pixel_indices.iter_mut().enumerate() {
|
||||
*pixel = u8::from(i == 0 || (p + i) % 3 != 0);
|
||||
}
|
||||
banks.install_glyph_bank(i, Arc::new(bank));
|
||||
}
|
||||
let scene = SceneBank {
|
||||
layers: std::array::from_fn(|i| SceneLayer {
|
||||
active: true,
|
||||
glyph_asset_id: i as i32,
|
||||
tile_size: sizes[i],
|
||||
parallax_factor: ParallaxFactor { x: 1.0, y: 1.0 },
|
||||
tilemap: TileMap {
|
||||
width: 160,
|
||||
height: 100,
|
||||
tiles: vec![
|
||||
Tile {
|
||||
active: true,
|
||||
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||
flip_x: false,
|
||||
flip_y: false,
|
||||
};
|
||||
160 * 100
|
||||
],
|
||||
},
|
||||
}),
|
||||
};
|
||||
let min_tile = if mixed { 8 } else { 16 };
|
||||
let (cw, ch) = (w.div_ceil(min_tile) + 5, h.div_ceil(min_tile) + 4);
|
||||
let mut cache = SceneViewportCache::new(&scene, cw, ch);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
w as i32,
|
||||
h as i32,
|
||||
cw,
|
||||
ch,
|
||||
min_tile as i32 - 4,
|
||||
min_tile as i32 + 4,
|
||||
);
|
||||
let mut gfx = Gfx::new(w, h, banks);
|
||||
let sprites: Vec<_> = (0..512)
|
||||
.map(|i| Sprite {
|
||||
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||
x: ((i * 37) % w) as i32,
|
||||
y: ((i * 53) % h) as i32,
|
||||
layer: (i % 4) as u8,
|
||||
bank_id: (i % 4) as u8,
|
||||
active: true,
|
||||
flip_x: i % 2 == 0,
|
||||
flip_y: i % 3 == 0,
|
||||
priority: (i % 4) as u8,
|
||||
})
|
||||
.collect();
|
||||
gfx.load_frame_sprites(&sprites);
|
||||
let mut compose = Vec::with_capacity(count);
|
||||
let mut publish = Vec::with_capacity(count);
|
||||
let mut upload = Vec::with_capacity(count);
|
||||
let mut total = Vec::with_capacity(count);
|
||||
let mut rgba = vec![0u8; w * h * 4];
|
||||
let ownership = RenderOwnership::new(1, AppMode::Game, 1);
|
||||
let mut checksum = 0u32;
|
||||
for frame_id in 0..(count + 120) {
|
||||
// Resolve/materialize cache outside the raster timing; total includes it.
|
||||
let start = Instant::now();
|
||||
let update = resolver.update(&scene, (frame_id % 71) as i32, (frame_id % 43) as i32);
|
||||
for request in &update.copy_requests {
|
||||
cache.move_layer_window_to(
|
||||
request.layer_index,
|
||||
request.cache_origin_tile_x,
|
||||
request.cache_origin_tile_y,
|
||||
);
|
||||
}
|
||||
cache.materialize_all_layers(&scene);
|
||||
let t = Instant::now();
|
||||
gfx.render_scene_from_cache(&cache, &update, &[0, 1, 2, 3]);
|
||||
gfx.fill_rect(0, h as i32 - 8, w as i32, 8, Color::WHITE);
|
||||
let raster = t.elapsed().as_nanos() as u64;
|
||||
let t = Instant::now();
|
||||
gfx.present();
|
||||
let frame = OwnedRgba8888Frame::packed(
|
||||
FrameId::new(frame_id as u64),
|
||||
ownership,
|
||||
w,
|
||||
h,
|
||||
gfx.front_buffer().to_vec(),
|
||||
)
|
||||
.unwrap();
|
||||
let publication = t.elapsed().as_nanos() as u64;
|
||||
let t = Instant::now();
|
||||
for (pixel, bytes) in frame.pixels.iter().zip(rgba.as_chunks_mut::<4>().0.iter_mut()) {
|
||||
bytes.copy_from_slice(&pixel.to_be_bytes());
|
||||
}
|
||||
std::hint::black_box(&rgba);
|
||||
let staging = t.elapsed().as_nanos() as u64;
|
||||
checksum ^= frame.pixels[(frame_id * 173) % (w * h)];
|
||||
if frame_id >= 120 {
|
||||
compose.push(raster);
|
||||
publish.push(publication);
|
||||
upload.push(staging);
|
||||
total.push(start.elapsed().as_nanos() as u64);
|
||||
}
|
||||
}
|
||||
let live = LIVE.load(Ordering::Relaxed);
|
||||
let peak = PEAK.load(Ordering::Relaxed);
|
||||
let allocations = ALLOCATIONS.load(Ordering::Relaxed);
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::json!({"schema":1,"width":w,"height":h,"frames":count,
|
||||
"warmup_frames":120,"tiles":sizes.map(|s|s as u32),"sprites_accepted":512,"layers":4,
|
||||
"framebuffer_bytes":w*h*4,"front_back_bytes":w*h*8,"host_staging_bytes":rgba.len(),
|
||||
"compose":summary(&mut compose),"publish_owned":summary(&mut publish),
|
||||
"rgba_staging":summary(&mut upload),"total":summary(&mut total),
|
||||
"allocated_live_bytes":live,"allocated_peak_bytes":peak,"allocation_count":allocations,
|
||||
"checksum":checksum,"vm_hz":null,"physical_display_hz":null,
|
||||
"limitations":"unpaced controlled raster/cache/owned publication/staging; no VM, IPC or GPU present; allocator instrumented; RSS is measured by the process wrapper"})
|
||||
);
|
||||
}
|
||||
@@ -664,7 +664,7 @@ mod tests {
|
||||
assert!(frame_composer.bind_scene(0));
|
||||
|
||||
let cache = frame_composer.cache().expect("cache should exist for bound scene");
|
||||
assert_eq!((cache.width(), cache.height()), (65, 38));
|
||||
assert_eq!((cache.width(), cache.height()), (85, 49));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -43,6 +43,8 @@ pub struct Gfx {
|
||||
front: Vec<u32>,
|
||||
/// Back buffer: the working buffer where canonical game frames are composed
|
||||
back: Vec<u32>,
|
||||
/// Complete local framebuffer publications, including native Hub/Shell output.
|
||||
publication_count: u64,
|
||||
|
||||
/// Shared access to graphical memory banks (tiles and palettes).
|
||||
pub glyph_banks: Arc<dyn GlyphBankPoolAccess>,
|
||||
@@ -321,6 +323,7 @@ impl Gfx {
|
||||
h,
|
||||
front: vec![0; len],
|
||||
back: vec![0; len],
|
||||
publication_count: 0,
|
||||
glyph_banks,
|
||||
sprites: [EMPTY_SPRITE; 512],
|
||||
sprite_count: 0,
|
||||
@@ -570,6 +573,11 @@ impl Gfx {
|
||||
/// Typically called by the Host when it's time to display the finished frame.
|
||||
pub fn present(&mut self) {
|
||||
std::mem::swap(&mut self.front, &mut self.back);
|
||||
self.publication_count = self.publication_count.wrapping_add(1);
|
||||
}
|
||||
|
||||
pub fn publication_count(&self) -> u64 {
|
||||
self.publication_count
|
||||
}
|
||||
|
||||
pub fn load_frame_sprites(&mut self, sprites: &[Sprite]) {
|
||||
|
||||
@@ -28,7 +28,7 @@ use std::sync::Arc;
|
||||
/// for easier testing and different host implementations (Desktop, Web, etc.).
|
||||
///
|
||||
/// ### Console Specifications:
|
||||
/// - **Resolution**: 480x270 (16:9 Aspect Ratio).
|
||||
/// - **Resolution**: 640x360 (16:9 Aspect Ratio).
|
||||
/// - **Color Format**: RGBA8888.
|
||||
/// - **Audio**: Stereo, Command-based mixing.
|
||||
/// - **Input**: 12-button Digital Gamepad + Absolute Touch/Mouse.
|
||||
@@ -201,9 +201,9 @@ impl RuntimePlatform for Hardware {
|
||||
|
||||
impl Hardware {
|
||||
/// Internal hardware width in pixels.
|
||||
pub const W: usize = 480;
|
||||
pub const W: usize = prometeu_hal::graphics_contract::WIDTH;
|
||||
/// Internal hardware height in pixels.
|
||||
pub const H: usize = 270;
|
||||
pub const H: usize = prometeu_hal::graphics_contract::HEIGHT;
|
||||
|
||||
/// Creates a fresh hardware instance with default settings.
|
||||
pub fn new(wall_clock: Arc<dyn WallClock>) -> Self {
|
||||
|
||||
@@ -5,6 +5,8 @@ mod gfx;
|
||||
pub mod hardware;
|
||||
mod local_render_backend;
|
||||
mod memory_banks;
|
||||
#[cfg(test)]
|
||||
mod native_graphics_tests;
|
||||
mod pad;
|
||||
mod test_platform;
|
||||
mod touch;
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
use crate::{Gfx, GlyphBankPoolInstaller, MemoryBanks};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::glyph::Glyph;
|
||||
use prometeu_hal::glyph_bank::{GlyphBank, TileSize};
|
||||
use prometeu_hal::graphics_contract::{FRAME_BYTES, HEIGHT, PIXELS, WIDTH};
|
||||
use prometeu_hal::scene_bank::SceneBank;
|
||||
use prometeu_hal::scene_layer::{ParallaxFactor, SceneLayer};
|
||||
use prometeu_hal::scene_viewport_cache::SceneViewportCache;
|
||||
use prometeu_hal::scene_viewport_resolver::SceneViewportResolver;
|
||||
use prometeu_hal::tile::Tile;
|
||||
use prometeu_hal::tilemap::TileMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test]
|
||||
fn native_allocation_stride_corners_and_external_coordinates() {
|
||||
let mut gfx = Gfx::new(WIDTH, HEIGHT, Arc::new(MemoryBanks::new()));
|
||||
assert_eq!(gfx.publication_count(), 0);
|
||||
gfx.clear(Color::BLACK);
|
||||
for (x, y) in [(0, 0), (639, 0), (0, 359), (639, 359)] {
|
||||
gfx.draw_pixel(x, y, Color::RED);
|
||||
}
|
||||
for (x, y) in [(-1, 0), (640, 359), (639, 360), (0, -1)] {
|
||||
gfx.draw_pixel(x, y, Color::GREEN);
|
||||
}
|
||||
assert_eq!(gfx.publication_count(), 0, "drawing is not a complete publication");
|
||||
gfx.present();
|
||||
assert_eq!(gfx.publication_count(), 1);
|
||||
let front = gfx.front_buffer();
|
||||
assert_eq!(gfx.size(), (640, 360));
|
||||
assert_eq!(front.len(), PIXELS);
|
||||
assert_eq!(std::mem::size_of_val(front), FRAME_BYTES);
|
||||
for index in [0, 639, 359 * WIDTH, PIXELS - 1] {
|
||||
assert_eq!(front[index], Color::RED.raw());
|
||||
}
|
||||
assert_eq!(front.iter().filter(|&&p| p == Color::RED.raw()).count(), 4);
|
||||
gfx.present();
|
||||
assert_eq!(gfx.publication_count(), 2, "each complete swap is a publication");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_tile_edges_and_mixed_camera_layers_cover_every_corner() {
|
||||
for sizes in [
|
||||
[TileSize::Size8; 4],
|
||||
[TileSize::Size16; 4],
|
||||
[TileSize::Size32; 4],
|
||||
[TileSize::Size8, TileSize::Size16, TileSize::Size32, TileSize::Size8],
|
||||
] {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let colors = [Color::RED, Color::GREEN, Color::BLUE, Color::WHITE];
|
||||
for i in 0..4 {
|
||||
let n = sizes[i] as usize;
|
||||
let mut bank = GlyphBank::new(sizes[i], n, n);
|
||||
bank.palettes[0][1] = colors[i];
|
||||
bank.pixel_indices.fill(1);
|
||||
banks.install_glyph_bank(i, Arc::new(bank));
|
||||
}
|
||||
let scene = SceneBank {
|
||||
layers: std::array::from_fn(|i| SceneLayer {
|
||||
active: true,
|
||||
glyph_asset_id: i as i32,
|
||||
tile_size: sizes[i],
|
||||
parallax_factor: ParallaxFactor { x: 1.0, y: 1.0 },
|
||||
tilemap: TileMap {
|
||||
width: 160,
|
||||
height: 120,
|
||||
tiles: vec![
|
||||
Tile {
|
||||
active: true,
|
||||
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||
flip_x: true,
|
||||
flip_y: true,
|
||||
};
|
||||
160 * 120
|
||||
],
|
||||
},
|
||||
}),
|
||||
};
|
||||
let min = sizes.iter().map(|s| *s as usize).min().unwrap();
|
||||
let (cw, ch) = (WIDTH.div_ceil(min) + 5, HEIGHT.div_ceil(min) + 4);
|
||||
let mut cache = SceneViewportCache::new(&scene, cw, ch);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
WIDTH as i32,
|
||||
HEIGHT as i32,
|
||||
cw,
|
||||
ch,
|
||||
min as i32 - 4,
|
||||
min as i32 + 4,
|
||||
);
|
||||
let mut gfx = Gfx::new(WIDTH, HEIGHT, banks);
|
||||
for (x, y) in [(0, 0), (1, 1), (7, 7), (15, 15), (31, 31), (400, 300), (2, 3)] {
|
||||
let update = resolver.update(&scene, x, y);
|
||||
for request in &update.copy_requests {
|
||||
cache.move_layer_window_to(
|
||||
request.layer_index,
|
||||
request.cache_origin_tile_x,
|
||||
request.cache_origin_tile_y,
|
||||
);
|
||||
}
|
||||
cache.materialize_all_layers(&scene);
|
||||
gfx.render_scene_from_cache(&cache, &update, &[0, 1, 2, 3]);
|
||||
gfx.present();
|
||||
// Every pixel, including rows 352..359, must be supplied by the last layer.
|
||||
assert!(
|
||||
gfx.front_buffer().iter().all(|&p| p == Color::WHITE.raw()),
|
||||
"sizes={sizes:?}, camera=({x},{y})"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -609,7 +609,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn front_buffer_pixel(platform: &TestPlatform, x: i32, y: i32) -> u32 {
|
||||
const FRAMEBUFFER_WIDTH: usize = 480;
|
||||
const FRAMEBUFFER_WIDTH: usize = prometeu_hal::graphics_contract::WIDTH;
|
||||
let index = x as usize + y as usize * FRAMEBUFFER_WIDTH;
|
||||
platform.local_hardware().gfx.front_buffer()[index]
|
||||
}
|
||||
@@ -1094,7 +1094,9 @@ mod tests {
|
||||
assert_eq!(dummy_ownership.app_id, 2);
|
||||
|
||||
let front = platform.local_hardware().gfx.front_buffer();
|
||||
let center = 240 + 135 * 480;
|
||||
let center = prometeu_hal::graphics_contract::WIDTH / 2
|
||||
+ (prometeu_hal::graphics_contract::HEIGHT / 2)
|
||||
* prometeu_hal::graphics_contract::WIDTH;
|
||||
assert_eq!(front[center], Color::GREEN.raw());
|
||||
|
||||
firmware.request_home_from_host();
|
||||
@@ -1512,8 +1514,12 @@ mod tests {
|
||||
#[test]
|
||||
fn shell_running_close_click_uses_lifecycle_and_returns_hub_home() {
|
||||
let (mut firmware, mut platform, _signals, task_id) = load_shell_running_firmware();
|
||||
let close_signals =
|
||||
InputSignals { f_signal: true, x_pos: 420, y_pos: 24, ..Default::default() };
|
||||
let close_signals = InputSignals {
|
||||
f_signal: true,
|
||||
x_pos: prometeu_hal::graphics_contract::WIDTH as i32 - 60,
|
||||
y_pos: 24,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
firmware.tick(&close_signals, &mut platform);
|
||||
|
||||
|
||||
@@ -47,7 +47,12 @@ impl HubHomeStep {
|
||||
let id = ctx.os.windows().add_window(
|
||||
app.title().to_string(),
|
||||
WindowOwner::Task(task_id),
|
||||
Rect { x: 40, y: 20, w: 400, h: 220 },
|
||||
Rect {
|
||||
x: 40,
|
||||
y: 20,
|
||||
w: prometeu_hal::graphics_contract::WIDTH as i32 - 80,
|
||||
h: prometeu_hal::graphics_contract::HEIGHT as i32 - 50,
|
||||
},
|
||||
app.color(),
|
||||
);
|
||||
ctx.os.windows().set_focus(id);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//! Fixed machine graphics contract. Host surfaces never change these dimensions.
|
||||
pub const WIDTH: usize = 640;
|
||||
pub const HEIGHT: usize = 360;
|
||||
pub const REFRESH_HZ: u32 = 60;
|
||||
/// Canonical RGBA8888, with tightly packed native rows.
|
||||
pub const BYTES_PER_PIXEL: usize = 4;
|
||||
pub const PIXELS: usize = WIDTH * HEIGHT;
|
||||
pub const STRIDE_PIXELS: usize = WIDTH;
|
||||
pub const STRIDE_BYTES: usize = STRIDE_PIXELS * BYTES_PER_PIXEL;
|
||||
pub const FRAME_BYTES: usize = STRIDE_BYTES * HEIGHT;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn native_graphics_contract_is_fixed() {
|
||||
assert_eq!((WIDTH, HEIGHT, REFRESH_HZ), (640, 360, 60));
|
||||
assert_eq!((PIXELS, STRIDE_BYTES, FRAME_BYTES), (230_400, 2_560, 921_600));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ pub mod debugger_protocol;
|
||||
pub mod gfx_bridge;
|
||||
pub mod glyph;
|
||||
pub mod glyph_bank;
|
||||
pub mod graphics_contract;
|
||||
pub mod host_context;
|
||||
pub mod host_return;
|
||||
pub mod input_signals;
|
||||
|
||||
@@ -64,7 +64,7 @@ pub trait RuntimePlatform {
|
||||
fn wall_clock(&self) -> &dyn WallClock;
|
||||
|
||||
fn display_size(&self) -> (usize, usize) {
|
||||
(480, 270)
|
||||
(crate::graphics_contract::WIDTH, crate::graphics_contract::HEIGHT)
|
||||
}
|
||||
|
||||
fn render_submission_sink(&mut self) -> &mut dyn RenderSubmissionSink;
|
||||
|
||||
@@ -224,6 +224,8 @@ impl SceneViewportResolver {
|
||||
scene_height_tiles: usize,
|
||||
) -> TileAnchor {
|
||||
let mut next = current;
|
||||
// Mixed layers must not step past the center and immediately step back.
|
||||
let trigger = self.hysteresis_trigger_px.max(tile_size_px / 2);
|
||||
|
||||
loop {
|
||||
let center_x_px = next.x * tile_size_px + tile_size_px / 2;
|
||||
@@ -231,11 +233,11 @@ impl SceneViewportResolver {
|
||||
if drift_x.abs() <= self.hysteresis_safe_px {
|
||||
break;
|
||||
}
|
||||
if drift_x > self.hysteresis_trigger_px {
|
||||
if drift_x > trigger {
|
||||
next.x += 1;
|
||||
continue;
|
||||
}
|
||||
if drift_x < -self.hysteresis_trigger_px {
|
||||
if drift_x < -trigger {
|
||||
next.x -= 1;
|
||||
continue;
|
||||
}
|
||||
@@ -248,11 +250,11 @@ impl SceneViewportResolver {
|
||||
if drift_y.abs() <= self.hysteresis_safe_px {
|
||||
break;
|
||||
}
|
||||
if drift_y > self.hysteresis_trigger_px {
|
||||
if drift_y > trigger {
|
||||
next.y += 1;
|
||||
continue;
|
||||
}
|
||||
if drift_y < -self.hysteresis_trigger_px {
|
||||
if drift_y < -trigger {
|
||||
next.y -= 1;
|
||||
continue;
|
||||
}
|
||||
@@ -433,20 +435,34 @@ mod tests {
|
||||
#[test]
|
||||
fn first_update_initializes_master_and_layer_anchors() {
|
||||
let scene = make_scene();
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let update = resolver.update(&scene, 0, 0);
|
||||
|
||||
assert_eq!(update.master_anchor, TileAnchor { x: 17, y: 10 });
|
||||
assert_eq!(update.layer_anchors[0], TileAnchor { x: 17, y: 10 });
|
||||
assert_eq!(update.layer_anchors[1], TileAnchor { x: 17, y: 10 });
|
||||
assert_eq!(update.master_anchor, TileAnchor { x: 22, y: 13 });
|
||||
assert_eq!(update.layer_anchors[0], TileAnchor { x: 22, y: 13 });
|
||||
assert_eq!(update.layer_anchors[1], TileAnchor { x: 22, y: 13 });
|
||||
assert_eq!(update.refresh_requests.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn per_layer_copy_requests_follow_parallax_factor() {
|
||||
let scene = make_scene();
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let update = resolver.update(&scene, 32, 48);
|
||||
|
||||
@@ -461,24 +477,38 @@ mod tests {
|
||||
#[test]
|
||||
fn hysteresis_prevents_small_back_and_forth_refresh_churn() {
|
||||
let scene = make_scene();
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let _ = resolver.update(&scene, 0, 0);
|
||||
let update = resolver.update(&scene, 8, 0);
|
||||
|
||||
assert!(update.refresh_requests.is_empty());
|
||||
assert_eq!(update.master_anchor, TileAnchor { x: 17, y: 10 });
|
||||
assert_eq!(update.master_anchor, TileAnchor { x: 22, y: 13 });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_high_speed_movement_advances_in_tile_steps() {
|
||||
let scene = make_scene();
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let _ = resolver.update(&scene, 0, 0);
|
||||
let update = resolver.update(&scene, 64, 0);
|
||||
|
||||
assert!(update.master_anchor.x > 17);
|
||||
assert!(update.master_anchor.x > 22);
|
||||
assert!(update.refresh_requests.iter().any(|request| matches!(
|
||||
request,
|
||||
CacheRefreshRequest::RefreshColumn { layer_index: 0, .. }
|
||||
@@ -489,18 +519,32 @@ mod tests {
|
||||
#[test]
|
||||
fn anchors_clamp_near_scene_edges() {
|
||||
let scene = make_scene();
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let update = resolver.update(&scene, 10_000, 10_000);
|
||||
|
||||
assert_eq!(update.master_anchor, TileAnchor { x: 46, y: 53 });
|
||||
assert_eq!(update.layer_anchors[0], TileAnchor { x: 46, y: 53 });
|
||||
assert_eq!(update.master_anchor, TileAnchor { x: 41, y: 50 });
|
||||
assert_eq!(update.layer_anchors[0], TileAnchor { x: 41, y: 50 });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn corner_trigger_converts_to_non_overlapping_region_requests() {
|
||||
let scene = make_scene();
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let _ = resolver.update(&scene, 0, 0);
|
||||
let update = resolver.update(&scene, 64, 80);
|
||||
@@ -515,15 +559,22 @@ mod tests {
|
||||
.collect();
|
||||
|
||||
assert_eq!(regions.len(), 2);
|
||||
assert_eq!(regions[0].x + regions[0].width, 35);
|
||||
assert_eq!(regions[0].height, 21);
|
||||
assert_eq!(regions[1].width, 34);
|
||||
assert_eq!(regions[0].x + regions[0].width, 45);
|
||||
assert_eq!(regions[0].height, 27);
|
||||
assert_eq!(regions[1].width, 44);
|
||||
assert_eq!(regions[1].height, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_scene_requests_full_invalidation_for_all_layers() {
|
||||
let mut resolver = SceneViewportResolver::new(480, 270, 35, 21, 12, 20);
|
||||
let mut resolver = SceneViewportResolver::new(
|
||||
crate::graphics_contract::WIDTH as i32,
|
||||
crate::graphics_contract::HEIGHT as i32,
|
||||
45,
|
||||
27,
|
||||
12,
|
||||
20,
|
||||
);
|
||||
|
||||
let requests = resolver.reset_scene();
|
||||
|
||||
|
||||
@@ -385,6 +385,14 @@ impl<'a> VmFacade<'a> {
|
||||
self.os.vm_runtime.record_repeated_render_worker_frame(frame_id);
|
||||
}
|
||||
|
||||
pub fn record_presented_render_worker_frame(
|
||||
&self,
|
||||
ownership: RenderOwnership,
|
||||
frame_id: FrameId,
|
||||
) {
|
||||
self.os.vm_runtime.record_presented_render_worker_frame(ownership, frame_id);
|
||||
}
|
||||
|
||||
pub fn active_render_ownership(&self) -> RenderOwnership {
|
||||
if let Some(task_id) = self.foreground_session_task_id()
|
||||
&& let Some(session) = self.os.vm_sessions.for_task(task_id)
|
||||
|
||||
@@ -10,19 +10,41 @@ use prometeu_hal::{
|
||||
|
||||
const SHELL_A_BUTTON: Rect = Rect { x: 112, y: 172, w: 112, h: 32 };
|
||||
const SHELL_B_BUTTON: Rect = Rect { x: 256, y: 172, w: 112, h: 32 };
|
||||
const CLOSE_BUTTON: Rect = Rect { x: 420, y: 24, w: 16, h: 16 };
|
||||
const VIEWPORT: Rect = Rect { x: 0, y: 0, w: 480, h: 270 };
|
||||
const HOME_PANEL: Rect = Rect { x: 48, y: 58, w: 384, h: 154 };
|
||||
const TITLE_PANEL: Rect = Rect { x: 72, y: 34, w: 336, h: 28 };
|
||||
const CLOSE_BUTTON: Rect =
|
||||
Rect { x: prometeu_hal::graphics_contract::WIDTH as i32 - 60, y: 24, w: 16, h: 16 };
|
||||
const VIEWPORT: Rect = Rect {
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: prometeu_hal::graphics_contract::WIDTH as i32,
|
||||
h: prometeu_hal::graphics_contract::HEIGHT as i32,
|
||||
};
|
||||
const HOME_PANEL: Rect = Rect {
|
||||
x: 48,
|
||||
y: 58,
|
||||
w: prometeu_hal::graphics_contract::WIDTH as i32 - 96,
|
||||
h: prometeu_hal::graphics_contract::HEIGHT as i32 - 116,
|
||||
};
|
||||
const TITLE_PANEL: Rect =
|
||||
Rect { x: 72, y: 34, w: prometeu_hal::graphics_contract::WIDTH as i32 - 144, h: 28 };
|
||||
const GAME_ROW_X: i32 = 72;
|
||||
const GAME_ROW_Y: i32 = 90;
|
||||
const GAME_ROW_W: i32 = 336;
|
||||
const GAME_ROW_W: i32 = prometeu_hal::graphics_contract::WIDTH as i32 - 144;
|
||||
const GAME_ROW_H: i32 = 22;
|
||||
const GAME_ROW_GAP: i32 = 6;
|
||||
const MAX_HOME_GAME_ROWS: usize = 3;
|
||||
pub const HUB_SUSPENDED_GAME_KILL_CONTROL: Rect = Rect { x: 288, y: 230, w: 168, h: 24 };
|
||||
pub const HUB_SUSPENDED_GAME_KILL_CONTROL: Rect = Rect {
|
||||
x: prometeu_hal::graphics_contract::WIDTH as i32 - 192,
|
||||
y: prometeu_hal::graphics_contract::HEIGHT as i32 - 40,
|
||||
w: 168,
|
||||
h: 24,
|
||||
};
|
||||
#[cfg(test)]
|
||||
const SHELL_FRAME: Rect = Rect { x: 40, y: 20, w: 400, h: 220 };
|
||||
const SHELL_FRAME: Rect = Rect {
|
||||
x: 40,
|
||||
y: 20,
|
||||
w: prometeu_hal::graphics_contract::WIDTH as i32 - 80,
|
||||
h: prometeu_hal::graphics_contract::HEIGHT as i32 - 50,
|
||||
};
|
||||
|
||||
const COLOR_BG: Color = Color::rgb(12, 14, 22);
|
||||
const COLOR_PANEL: Color = Color::rgb(25, 31, 48);
|
||||
|
||||
@@ -187,6 +187,16 @@ impl VirtualMachineRuntime {
|
||||
self.render_worker_ownership.set(self.render_manager.active_ownership());
|
||||
}
|
||||
|
||||
pub fn record_presented_render_worker_frame(
|
||||
&self,
|
||||
ownership: prometeu_hal::RenderOwnership,
|
||||
frame_id: FrameId,
|
||||
) {
|
||||
if let Some(controller) = self.render_worker_controller.as_ref() {
|
||||
controller.record_presented_frame(ownership, frame_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn record_repeated_render_worker_frame(&self, frame_id: FrameId) {
|
||||
if let Some(controller) = self.render_worker_controller.as_ref() {
|
||||
controller.record_repeated_frame(frame_id);
|
||||
|
||||
@@ -25,6 +25,7 @@ impl Default for RenderWorkerConfig {
|
||||
struct RenderWorkerState {
|
||||
telemetry: RenderWorkerTelemetry,
|
||||
last_error: Option<RenderWorkerError>,
|
||||
last_presented: Option<(RenderOwnership, FrameId)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@@ -157,6 +158,7 @@ impl RenderWorkerController {
|
||||
let mut telemetry = self.handoff.telemetry();
|
||||
let state = self.state.lock().unwrap();
|
||||
telemetry.published_frames = state.telemetry.published_frames;
|
||||
telemetry.presented_frames = state.telemetry.presented_frames;
|
||||
telemetry.render_failures = state.telemetry.render_failures;
|
||||
telemetry.publish_failures = state.telemetry.publish_failures;
|
||||
telemetry.present_failures = state.telemetry.present_failures;
|
||||
@@ -179,6 +181,17 @@ impl RenderWorkerController {
|
||||
self.ownership.snapshot()
|
||||
}
|
||||
|
||||
/// Record only after a successful host presentation, never on publication.
|
||||
pub fn record_presented_frame(&self, ownership: RenderOwnership, frame_id: FrameId) {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
if state.last_presented == Some((ownership, frame_id)) {
|
||||
state.telemetry.record_repeated_frame(frame_id.get());
|
||||
} else {
|
||||
state.telemetry.record_presented(frame_id.get());
|
||||
}
|
||||
state.last_presented = Some((ownership, frame_id));
|
||||
}
|
||||
|
||||
pub fn record_repeated_frame(&self, frame_id: FrameId) {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.telemetry.record_repeated_frame(frame_id.get());
|
||||
@@ -203,13 +216,13 @@ fn run_worker_loop<B, S>(
|
||||
B: RenderWorkerBackend,
|
||||
S: RenderWorkerFrameSink,
|
||||
{
|
||||
loop {
|
||||
let submission = match handoff.wait_take() {
|
||||
RenderWorkerHandoffWait::Submission(submission) => submission,
|
||||
RenderWorkerHandoffWait::Shutdown => return,
|
||||
};
|
||||
let report_path = std::env::var_os("PROMETEU_GRAPHICS_METRICS").map(std::path::PathBuf::from);
|
||||
let mut measurements = Vec::new();
|
||||
let mut measured_frames = 0usize;
|
||||
while let RenderWorkerHandoffWait::Submission(submission) = handoff.wait_take() {
|
||||
let frame_id = submission.frame_id;
|
||||
|
||||
let render_begin = report_path.as_ref().map(|_| std::time::Instant::now());
|
||||
let render_result = catch_unwind(AssertUnwindSafe(|| backend.render(&submission)))
|
||||
.map_err(|_| RenderWorkerError::WorkerPanic);
|
||||
let frame = match render_result {
|
||||
@@ -225,13 +238,45 @@ fn run_worker_loop<B, S>(
|
||||
continue;
|
||||
}
|
||||
|
||||
let render_us = render_begin.map(|start| start.elapsed().as_micros() as u64);
|
||||
let publish_begin = report_path.as_ref().map(|_| std::time::Instant::now());
|
||||
let publish_result = catch_unwind(AssertUnwindSafe(|| sink.publish(frame)))
|
||||
.map_err(|_| RenderWorkerError::WorkerPanic);
|
||||
if let (Some(render_us), Some(begin)) = (render_us, publish_begin) {
|
||||
let sample = (frame_id.get(), render_us, begin.elapsed().as_micros() as u64);
|
||||
if measurements.len() < 16384 {
|
||||
measurements.push(sample);
|
||||
} else {
|
||||
measurements[measured_frames % 16384] = sample;
|
||||
}
|
||||
measured_frames += 1;
|
||||
}
|
||||
match publish_result {
|
||||
Ok(Ok(())) => record_published(&state, frame_id),
|
||||
Ok(Err(error)) | Err(error) => record_error(&state, error, frame_id),
|
||||
}
|
||||
}
|
||||
if let Some(path) = report_path {
|
||||
use std::io::Write;
|
||||
let worker = state.lock().unwrap();
|
||||
let handoff = handoff.telemetry();
|
||||
let report = serde_json::json!({"schema":1,"source":"async_render_worker",
|
||||
"produced_submissions":handoff.produced_submissions,"consumed_submissions":handoff.consumed_submissions,
|
||||
"replaced_before_consume":handoff.replaced_before_consume,
|
||||
"published_frames":worker.telemetry.published_frames,"first_presentations":worker.telemetry.presented_frames,
|
||||
"repeated_presentations":worker.telemetry.repeated_frames,
|
||||
"render_failures":worker.telemetry.render_failures,"publish_failures":worker.telemetry.publish_failures,
|
||||
"measured_frames":measured_frames,"samples_frame_render_publish_us":measurements,
|
||||
"physical_display_hz":null,
|
||||
"limitations":"last 16384 successful-render samples; render includes owned-frame copy; sink publication is not scanout; opt-in clock and storage overhead"});
|
||||
if let Ok(mut file) = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(path.with_extension("renderer.jsonl"))
|
||||
{
|
||||
let _ = writeln!(file, "{report}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn record_published(state: &Arc<Mutex<RenderWorkerState>>, frame_id: FrameId) {
|
||||
@@ -346,6 +391,14 @@ mod tests {
|
||||
SharedFakeBackend(backend),
|
||||
);
|
||||
|
||||
let first_session = RenderOwnership::new(1, AppMode::Game, 7);
|
||||
controller.record_presented_frame(first_session, FrameId::ZERO);
|
||||
controller.record_presented_frame(first_session, FrameId::ZERO);
|
||||
// Frame zero in a new epoch is a new image, not a repeat of the old session.
|
||||
controller.record_presented_frame(RenderOwnership::new(2, AppMode::Game, 7), FrameId::ZERO);
|
||||
assert_eq!(controller.telemetry().presented_frames, 2);
|
||||
assert_eq!(controller.telemetry().repeated_frames, 1);
|
||||
|
||||
assert_eq!(controller.stop(), Ok(()));
|
||||
assert_eq!(controller.last_error(), None);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user