feat(stress): add a deterministic particle demo with sequenced music

Move Storm Eagle playback and source assets to Stress Console and keep Dummy Boy silent. Exercise VM math, seeded Random and persistent typed particles with a projected tunnel, bounded 512-sprite heavy workload, reproducible replays and measured costs.
This commit is contained in:
2026-11-20 22:15:47 +00:00
parent 8510c5b00d
commit c2bf8d055c
42 changed files with 20688 additions and 232 deletions
@@ -0,0 +1,81 @@
# Stress Console local measurement
Executed on 2026-11-20: Apple M2 Pro, macOS/Darwin 27.2.0, aarch64,
`rustc 1.98.1 (48a229cea 2026-09-01)`, Cargo release profile, VM
`resource-diagnostics` enabled. The host was not isolated and its power/thermal
state was not controlled. These are elapsed-time observations from one run.
Reproduce from the runtime root:
```sh
cargo run -p pbxgen-stress --release --example demo_measure -- 120 /tmp/stress-measure
```
Seed: `1347571533`. Particle position-travel multiplier: `1.5`. Each preset loads
independently, executes its first frame,
then measures 120 steady logical frames. All measured frames compose the native
640x360 image and process 800 stereo audio frames (48 kHz). Initialization is
excluded from steady distributions. Percentiles are nearest-rank over the 120
samples; they do not estimate a guaranteed upper bound.
| Preset | VM only mean ms | Headless mean ms | p95 ms | Max ms | Mean virtual cycles | Host ticks/logical frame |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| light | 1.982 | 2.683 | 2.853 | 2.996 | 84701.2 | 1 |
| normal | 4.154 | 4.907 | 5.056 | 5.184 | 178972.8 | 1 |
| heavy | 19.183 | 19.685 | 20.553 | 21.700 | 774621.4 | 4 |
VM-only uses the same PBX on the real VM and SpriteController; other native
calls are counted. Headless uses actual firmware, assets, composition and audio.
Virtual cycles are machine accounting, not CPU cycles or milliseconds. The
heavy preset spans four 250,000-cycle host slices per logical frame; light and
normal use one. `advance_frame` completes all required slices, so these timings
are not physical presentation cadence or a promise of 60 FPS in another host.
| Preset | Host boot ms | First frame ms | GuestBytes used | Live handles/objects | AuxiliaryBytes used | TemporaryBytes peak | Sprites accepted |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| light | 1.730 | 3.037 | 22640 | 66 | 8680 | 3840 | 192 |
| normal | 3.421 | 5.213 | 44656 | 130 | 16360 | 7680 | 256 |
| heavy | 3.278 | 20.683 | 132720 | 386 | 31720 | 15360 | 512 |
Each preset recorded zero sprite overflows and zero guest composer errors.
Music play was submitted once. The two-second observation reached eight active
voices; the separate 52.4-second audio regression reached ten, with no clipped
samples. Processing 800 audio frames averaged 0.123–0.128 ms in this run.
The guest retains exactly N Particle structs plus one array and one RNG object.
Rebirth reuses those objects. Quota accounting excludes process RSS, framebuffers,
resident banks, renderer caches and allocator overhead. The musical bank has
60,358 PCM bytes and canonical decoded size 112,224 bytes; those are independent
of the workload preset. Boot/first-frame times include their respective host
work and are not isolated codec-decoding measurements.
The current default is heavy: 384 particles, four real simulation passes and
128 tunnel markers. It deliberately selects the largest existing numerical
workload. Normal (128 particles/two passes) and light remain explicit options
for comparison. The current run includes the 1.5 position-travel multiplier and
the larger heavy population. Relative to the previous 256-particle heavy workload, sprite
admission rises from 384 to 512, mean virtual cycles from about 531,444 to
774,621 and host slices from three to four. Its observed mean headless cost
increased from 13.649 to 19.685 ms. These observations do not provide a handheld
frame-rate guarantee.
The example saves report.json, generated cartridges and PPM captures. Diagnostic
state hashes after the initial frame plus 120 measured frames were:
| Preset | Particle-state hash | Native frame hash |
| --- | --- | --- |
| light | `b53cd663d1741a24` | `87f646410e9c3ade` |
| normal | `16b062d046d8efc9` | `c33ceb1e514ff1a8` |
| heavy | `f934f3e61ae1be77` | `6c3302f4a16903bc` |
The tests additionally pin six-frame numeric and visual baselines and execute
them in debug and release. A separate probe checks actual guest displacement
against the updated velocity, establishing the 1.5 multiplier independently of
the replay hashes. The native desktop integration test exercises actual
cartridge music through AudioCallback without a physical output device.
No physical callback deadlines, underruns, GPU presentation, VSync, battery
consumption, thermal throttling or affordable handheld hardware were measured.
The headless harness drives audio explicitly; it cannot observe a device underrun.
Use dedicated subsystem tests for numeric edge cases, GC churn, storage/input,
crossfade, SFX and full 32-voice load.
@@ -0,0 +1,101 @@
//! Reproducible fixture measurement; times include diagnostics and do not qualify a handheld.
#[path = "../tests/support/mod.rs"]
mod support;
use pbxgen_stress::{Preset, DEFAULT_SEED};
use prometeu_host_headless::{AdvanceFrameOutcome, HeadlessHost};
use std::{
io::Write,
path::{Path, PathBuf},
time::Instant,
};
fn distribution(mut ms: Vec<f64>) -> serde_json::Value {
ms.sort_by(f64::total_cmp);
let n = ms.len();
serde_json::json!({"count":n,"mean_ms":ms.iter().sum::<f64>()/n as f64,"p50_ms":ms[(n*50).div_ceil(100)-1],"p95_ms":ms[(n*95).div_ceil(100)-1],"max_ms":ms[n-1]})
}
fn ppm(path: &Path, pixels: &[u32]) {
let mut f = std::io::BufWriter::new(std::fs::File::create(path).unwrap());
write!(f, "P6\n640 360\n255\n").unwrap();
for &p in pixels {
let (r, g, b, _) = prometeu_hal::color::Color::unpack_to_native(p);
f.write_all(&[r, g, b]).unwrap();
}
}
fn main() {
let frames: usize = std::env::args().nth(1).unwrap_or("120".into()).parse().expect("frames");
assert!((1..=10000).contains(&frames));
let output =
PathBuf::from(std::env::args().nth(2).unwrap_or("/tmp/prometeu-demo-measure".into()));
std::fs::create_dir_all(&output).unwrap();
let mut reports = vec![];
for preset in [Preset::Light, Preset::Normal, Preset::Heavy] {
let started = Instant::now();
let mut vm = support::vm(preset, DEFAULT_SEED);
let vm_load_ms = started.elapsed().as_secs_f64() * 1000.0;
let mut native = support::Workload::default();
let started = Instant::now();
let init_cycles = support::frame(&mut vm, &mut native);
let init_vm_ms = started.elapsed().as_secs_f64() * 1000.0;
let mut vm_times = Vec::new();
let mut cycles = 0;
for _ in 0..frames {
let started = Instant::now();
cycles += support::frame(&mut vm, &mut native);
vm_times.push(started.elapsed().as_secs_f64() * 1000.0);
}
let resources = vm.resource_snapshot();
let state_hash = support::hash(&support::particle_bits(&vm));
let cart = output.join(format!("{}-cartridge", preset.name()));
pbxgen_stress::generate_with(preset, DEFAULT_SEED, Some(cart.clone())).unwrap();
let mut host = HeadlessHost::new();
let started = Instant::now();
host.boot(cart.to_string_lossy()).unwrap();
let boot_ms = started.elapsed().as_secs_f64() * 1000.0;
let started = Instant::now();
assert!(matches!(
host.advance_frame().unwrap(),
AdvanceFrameOutcome::FrameCompleted { .. }
));
let host_first_frame_ms = started.elapsed().as_secs_f64() * 1000.0;
host.resume().unwrap();
let mut pcm = [0.0; 1600];
host.render_audio(&mut pcm);
let mut host_times = vec![];
let mut audio_times = vec![];
let mut previous_tick = host.get_state().tick_index;
let mut slices = vec![];
for _ in 0..frames {
let started = Instant::now();
assert!(matches!(
host.advance_frame().unwrap(),
AdvanceFrameOutcome::FrameCompleted { .. }
));
host.resume().unwrap();
let audio_started = Instant::now();
host.render_audio(&mut pcm);
audio_times.push(audio_started.elapsed().as_secs_f64() * 1000.0);
host_times.push(started.elapsed().as_secs_f64() * 1000.0);
let tick = host.get_state().tick_index;
slices.push(tick - previous_tick);
previous_tick = tick;
}
let capture = host.capture_frame().unwrap();
let file = output.join(format!("{}.ppm", preset.name()));
ppm(&file, &capture.frame.pixels);
let audio = host.audio_diagnostics();
reports.push(serde_json::json!({"preset":preset.name(),"particles":preset.particles(),"substeps":preset.substeps(),"steady_frames":frames,"seed":DEFAULT_SEED,
"vm_load_ms":vm_load_ms,"vm_first_frame_ms":init_vm_ms,"host_boot_ms":boot_ms,"host_first_frame_ms":host_first_frame_ms,
"vm_only_with_bounded_native":distribution(vm_times),"headless_graphics_and_800_audio_frames":distribution(host_times),"audio_800_frames_only":distribution(audio_times),
"mean_host_ticks_per_logical_frame":slices.iter().sum::<u64>() as f64 / frames as f64,"max_host_ticks_per_logical_frame":slices.iter().max(),
"first_virtual_cycles":init_cycles,"mean_steady_virtual_cycles":cycles as f64/frames as f64,
"sprites_submitted_per_frame":preset.particles()+128,"sprites_accepted_last_frame":native.sprites.sprite_count(),"sprite_overflow":native.sprites.dropped_sprites(),"guest_composer_errors":native.errors,
"live_guest_objects":resources.live_objects,"vm_budget_used":resources.budget.used,"vm_budget_peaks":resources.budget.peaks,"vm_budget_limits":resources.budget.limits,
"state_hash":format!("{state_hash:016x}"),"music_play_commands":native.plays,"observed_maximum_voices":audio.maximum_voices,"audio_frames":audio.frames,
"capture":file,"frame_hash":format!("{:016x}",support::hash(&capture.frame.pixels.iter().map(|&p|u64::from(p)).collect::<Vec<_>>()))}));
}
let report = serde_json::json!({"profile":if cfg!(debug_assertions){"debug"}else{"release"},"arch":std::env::consts::ARCH,"os":std::env::consts::OS,"resource_diagnostics":true,"particle_travel_scale":pbxgen_stress::PARTICLE_TRAVEL_SCALE,
"notes":["Native-only timing uses real VM and SpriteController, with other host calls counted.","Headless timing includes real software composition and 800 stereo audio frames per logical frame.","No physical callback, VSync, GPU presentation, power or handheld measurement.","VM quota arrays are ordered by RuntimeResource; they are not process RSS."],"presets":reports});
std::fs::write(output.join("report.json"), serde_json::to_vec_pretty(&report).unwrap())
.unwrap();
println!("{}", serde_json::to_string_pretty(&report).unwrap());
}