implements PLN-0079 gfx2d primitive buffering

This commit is contained in:
2026-05-25 14:10:52 +01:00
parent 57439846c5
commit 5e00f6bb0d
7 changed files with 43 additions and 7 deletions
@@ -7,12 +7,13 @@ use prometeu_hal::asset::{AssetId, AssetOpStatus, BankType, SlotRef};
use prometeu_hal::color::Color;
use prometeu_hal::glyph::Glyph;
use prometeu_hal::log::{LogLevel, LogSource};
use prometeu_hal::primitives::Rect;
use prometeu_hal::sprite::Sprite;
use prometeu_hal::syscalls::Syscall;
use prometeu_hal::vm_fault::VmFault;
use prometeu_hal::{
AudioOpStatus, ComposerOpStatus, HostContext, HostReturn, NativeInterface, SyscallId,
expect_bool, expect_int,
AudioOpStatus, ComposerOpStatus, Gfx2dCommand, HostContext, HostReturn, NativeInterface,
SyscallId, expect_bool, expect_int,
};
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
@@ -185,6 +186,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
Syscall::SystemRunCart => unreachable!(),
Syscall::GfxClear => {
let color = self.get_color(expect_int(args, 0)?)?;
self.gfx2d_commands.push(Gfx2dCommand::Clear { color });
hw.gfx_mut().clear(color);
Ok(())
}
@@ -205,6 +207,8 @@ impl NativeInterface for VmRuntimeHost<'_> {
let w = expect_int(args, 2)? as i32;
let h = expect_int(args, 3)? as i32;
let color = self.get_color(expect_int(args, 4)?)?;
self.gfx2d_commands
.push(Gfx2dCommand::FillRect { rect: Rect { x, y, w, h }, color });
hw.gfx_mut().fill_rect(x, y, w, h, color);
Ok(())
}
@@ -229,6 +233,13 @@ impl NativeInterface for VmRuntimeHost<'_> {
let x2 = expect_int(args, 2)? as i32;
let y2 = expect_int(args, 3)? as i32;
let color = self.get_color(expect_int(args, 4)?)?;
self.gfx2d_commands.push(Gfx2dCommand::DrawLine {
x0: x1,
y0: y1,
x1: x2,
y1: y2,
color,
});
hw.gfx_mut().draw_line(x1, y1, x2, y2, color);
Ok(())
}
@@ -252,6 +263,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
let y = expect_int(args, 1)? as i32;
let r = expect_int(args, 2)? as i32;
let color = self.get_color(expect_int(args, 3)?)?;
self.gfx2d_commands.push(Gfx2dCommand::DrawCircle { x, y, radius: r, color });
hw.gfx_mut().draw_circle(x, y, r, color);
Ok(())
}
@@ -275,6 +287,13 @@ impl NativeInterface for VmRuntimeHost<'_> {
let r = expect_int(args, 2)? as i32;
let border_color = self.get_color(expect_int(args, 3)?)?;
let fill_color = self.get_color(expect_int(args, 4)?)?;
self.gfx2d_commands.push(Gfx2dCommand::DrawDisc {
x,
y,
radius: r,
border_color,
fill_color,
});
hw.gfx_mut().draw_disc(x, y, r, border_color, fill_color);
Ok(())
}
@@ -300,6 +319,11 @@ impl NativeInterface for VmRuntimeHost<'_> {
let h = expect_int(args, 3)? as i32;
let border_color = self.get_color(expect_int(args, 4)?)?;
let fill_color = self.get_color(expect_int(args, 5)?)?;
self.gfx2d_commands.push(Gfx2dCommand::DrawSquare {
rect: Rect { x, y, w, h },
border_color,
fill_color,
});
hw.gfx_mut().draw_square(x, y, w, h, border_color, fill_color);
Ok(())
}
@@ -324,6 +348,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
let y = expect_int(args, 1)? as i32;
let msg = expect_string(args, 2, "message")?;
let color = self.get_color(expect_int(args, 3)?)?;
self.gfx2d_commands.push(Gfx2dCommand::DrawText { x, y, text: msg.clone(), color });
hw.gfx_mut().draw_text(x, y, &msg, color);
Ok(())
}
@@ -23,6 +23,7 @@ impl VirtualMachineRuntime {
current_cartridge_app_version: String::new(),
current_cartridge_app_mode: AppMode::Game,
render_manager: RenderManager::new(AppMode::Game),
gfx2d_commands: Vec::new(),
logs_written_this_frame: HashMap::new(),
atomic_telemetry,
last_crash_report: None,
@@ -118,6 +119,7 @@ impl VirtualMachineRuntime {
self.current_cartridge_app_version.clear();
self.current_cartridge_app_mode = AppMode::Game;
self.render_manager = RenderManager::new(AppMode::Game);
self.gfx2d_commands.clear();
self.logs_written_this_frame.clear();
self.last_crash_report = None;
@@ -7,6 +7,7 @@ mod tick;
use crate::CrashReport;
use prometeu_bytecode::string_materialization_count;
use prometeu_hal::Gfx2dCommand;
use prometeu_hal::app_mode::AppMode;
use prometeu_hal::log::LogService;
use prometeu_hal::telemetry::{AtomicTelemetry, CertificationConfig, Certifier};
@@ -28,6 +29,7 @@ pub struct VirtualMachineRuntime {
pub current_cartridge_app_version: String,
pub current_cartridge_app_mode: AppMode,
pub render_manager: RenderManager,
pub gfx2d_commands: Vec<Gfx2dCommand>,
pub logs_written_this_frame: HashMap<u32, u32>,
pub atomic_telemetry: Arc<AtomicTelemetry>,
pub last_crash_report: Option<CrashReport>,
@@ -730,6 +730,13 @@ fn tick_draw_text_survives_no_scene_frame_path() {
);
assert!(report.is_none(), "no-scene overlay text must not crash");
let submission =
runtime.render_manager.latest_complete_submission().expect("closed submission");
let prometeu_hal::RenderSubmissionPacket::Game2D(packet) = &submission.packet else {
panic!("expected Game2D submission");
};
assert_eq!(packet.gfx2d.len(), 1);
assert!(matches!(packet.gfx2d[0], prometeu_hal::Gfx2dCommand::DrawText { .. }));
hardware.gfx.present();
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x11223344).raw());
}
@@ -222,10 +222,10 @@ impl VirtualMachineRuntime {
{
self.render_manager.set_active_app_mode(self.current_cartridge_app_mode);
if self.current_cartridge_app_mode == AppMode::Game {
let mut packet = hw.close_game2d_packet();
packet.gfx2d = std::mem::take(&mut self.gfx2d_commands);
self.render_manager
.close_frame_with_packet(RenderSubmissionPacket::Game2D(
hw.close_game2d_packet(),
))
.close_frame_with_packet(RenderSubmissionPacket::Game2D(packet))
.expect("game packet must match Game app mode");
} else {
self.render_manager.close_compat_frame();