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.
110 lines
4.3 KiB
Rust
110 lines
4.3 KiB
Rust
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})"
|
|
);
|
|
}
|
|
}
|
|
}
|