mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90f3a6d020 | ||
|
|
505103dacb | ||
|
|
8cbf438488 | ||
|
|
4447ff2425 |
No files matched your search
Generated
+1
@@ -15003,6 +15003,7 @@ dependencies = [
|
||||
"bytemuck",
|
||||
"dunce",
|
||||
"image",
|
||||
"raea-core-facts",
|
||||
"raea-core-program",
|
||||
"raea-core-shape",
|
||||
"raea-gpu-device",
|
||||
|
||||
+42
-2
@@ -108,7 +108,7 @@ pub fn microphone(tx: Sender<Vec<f32>>) -> anyhow::Result<cpal::Stream> {
|
||||
rs.push(&mono, &mut out);
|
||||
let _ = tx.send(out);
|
||||
};
|
||||
let bad = |e| eprintln!("raea voice: the microphone: {e}");
|
||||
let bad = said_once::<cpal::StreamError>("raea voice: the microphone");
|
||||
let stream = match cfg.sample_format() {
|
||||
cpal::SampleFormat::F32 => {
|
||||
dev.build_input_stream(&cfg.config(), move |d: &[f32], _: &cpal::InputCallbackInfo| take(mono(d, ch)), bad, None)
|
||||
@@ -242,7 +242,7 @@ impl Speaker {
|
||||
f.fill(ready.pop_front().unwrap_or(0.0));
|
||||
}
|
||||
};
|
||||
let stream = dev.build_output_stream(&cfg.config(), play, |e| eprintln!("raea voice: the speakers: {e}"), None).map_err(|e| anyhow!("the speakers didn't open: {e}"))?;
|
||||
let stream = dev.build_output_stream(&cfg.config(), play, said_once::<cpal::StreamError>("raea voice: the speakers"), None).map_err(|e| anyhow!("the speakers didn't open: {e}"))?;
|
||||
stream.play().map_err(|e| anyhow!("the speakers didn't start: {e}"))?;
|
||||
Ok(Speaker { line, rate, to, _stream: Some(stream) })
|
||||
}
|
||||
@@ -286,3 +286,43 @@ mod tests {
|
||||
assert!(x.iter().zip(&y).all(|(a, b)| (a - b).abs() < 1e-3));
|
||||
}
|
||||
}
|
||||
|
||||
/// A device's error said once, then only how often it came back (at its 10th, 100th, ... time, and never more than once
|
||||
/// a second): a failing ALSA device calls a stream's error callback without pause, and every call printed a line: #239's
|
||||
/// app.log reached 40 GB of one line in two days.
|
||||
fn said_once<E: std::fmt::Display>(what: &'static str) -> impl FnMut(E) + Send + 'static {
|
||||
let mut seen = Repeats::default();
|
||||
move |e| {
|
||||
let m = e.to_string();
|
||||
match seen.hit(&m, std::time::Instant::now()) {
|
||||
Some(1) => eprintln!("{what}: {m}"),
|
||||
Some(n) => eprintln!("{what}: {m} ({n} times now)"),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Which of an error's repeats get said: `hit` answers with the count to print, or nothing.
|
||||
#[derive(Default)]
|
||||
struct Repeats {
|
||||
last: String,
|
||||
n: u64,
|
||||
next: u64,
|
||||
at: Option<std::time::Instant>,
|
||||
}
|
||||
|
||||
impl Repeats {
|
||||
fn hit(&mut self, m: &str, now: std::time::Instant) -> Option<u64> {
|
||||
if m != self.last || self.n == 0 {
|
||||
(self.last, self.n, self.next) = (m.to_string(), 0, 1);
|
||||
}
|
||||
self.n += 1;
|
||||
let soon = self.at.is_some_and(|t| now.duration_since(t).as_secs() < 1);
|
||||
if self.n < self.next || (soon && self.n > 1) {
|
||||
return None;
|
||||
}
|
||||
self.next = self.n.saturating_mul(10);
|
||||
self.at = Some(now);
|
||||
Some(self.n)
|
||||
}
|
||||
}
|
||||
@@ -122,12 +122,22 @@ fn draw(dir: &Path, file: &str, composition: Option<&str>, how: &[&str], env: &[
|
||||
if !run.status.success() {
|
||||
return Err(format!("the held render failed: {}", err.lines().rev().take(4).collect::<Vec<_>>().into_iter().rev().collect::<Vec<_>>().join(" | ")));
|
||||
}
|
||||
Ok(())
|
||||
unshaded(out)
|
||||
}
|
||||
|
||||
/// A held run whose shaders didn't compile drew without them (a Solari pipeline that failed leaves the frame to
|
||||
/// whatever is left), and its light says nothing about the path it was held for: refused, with the shader's error.
|
||||
fn unshaded(out: &Path) -> R<()> {
|
||||
let log = std::fs::read_to_string(out.join("render.log")).unwrap_or_default();
|
||||
let Some(at) = log.find("failed to process shader") else { return Ok(()) };
|
||||
let why: Vec<&str> = log[at..].lines().skip(1).map(str::trim).filter(|l| !l.is_empty()).take(3).collect();
|
||||
Err(format!("a shader of this render didn't compile, so its frames aren't the light it was held for: {} ({}/render.log)", why.join(" "), out.display()))
|
||||
}
|
||||
|
||||
/// The held frames of `dir` measured: DIR/steady.png and steady.json written, and the report, its "steady" saying
|
||||
/// whether the light held (`max`: the blotch a run may show, percent; MAX when None).
|
||||
pub fn report(dir: &Path, max: Option<f64>) -> R<Value> {
|
||||
unshaded(dir)?;
|
||||
let max = max.unwrap_or(MAX);
|
||||
// the second half: the first is the light building from nothing, which a render's lead-in covers
|
||||
let files = held(dir)?;
|
||||
@@ -237,4 +247,17 @@ mod tests {
|
||||
assert!(blotch["blotch"].as_f64().unwrap() > 2.0, "{blotch}");
|
||||
assert!(blotch["spread"].as_f64().unwrap() > 0.6, "{blotch}");
|
||||
}
|
||||
|
||||
/// A run whose shaders failed isn't measured: its frames are another light's.
|
||||
#[test]
|
||||
fn a_run_that_drew_without_its_shaders_is_refused() {
|
||||
let dir = std::env::temp_dir().join(format!("raea-steady-unshaded-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::fs::write(dir.join("render.log"), "ERROR bevy_render::render_resource::pipeline_cache: failed to process shader error:\n use of a reserved word `target`\n").unwrap();
|
||||
let e = report(&dir, None).unwrap_err();
|
||||
assert!(e.contains("didn't compile") && e.contains("reserved word"), "{e}");
|
||||
std::fs::write(dir.join("render.log"), "APPLIED 96 frames\n").unwrap();
|
||||
assert!(unshaded(&dir).is_ok());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ raea-sys-gi = { path = "../../systems/gi" }
|
||||
bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "multi_threaded", "3d_bevy_render", "ui_bevy_render", "png", "tonemapping_luts", "ktx2", "zstd_rust"] }
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "hdr"] }
|
||||
# an edit as rows keyed per frame, and 3D shapes as values (docs/media.feature M2)
|
||||
raea-core-facts = { path = "../../core/facts" }
|
||||
raea-core-program = { path = "../../core/program" }
|
||||
# procedural surfaces on a mesh row (`proc`)
|
||||
raea-sys-procmat = { path = "../../systems/procmat" }
|
||||
|
||||
@@ -128,7 +128,7 @@ impl Engine {
|
||||
app.add_plugins((raea_plugins::RaeaPlugins, raea_plugins::RegisteredPlugins { fps: prog.fps }));
|
||||
app.sub_app_mut(bevy::render::RenderApp).add_systems(
|
||||
bevy::render::Render,
|
||||
wait_pipelines.in_set(bevy::render::RenderSystems::Render).before(bevy::render::renderer::render_system),
|
||||
(wait_pipelines, failed_pipelines).chain().in_set(bevy::render::RenderSystems::Render).before(bevy::render::renderer::render_system),
|
||||
);
|
||||
// overlapping fog volumes composited in one order whatever frames came before (raea-sys-fog's FogRank)
|
||||
app.sub_app_mut(bevy::render::RenderApp)
|
||||
@@ -292,3 +292,22 @@ fn solari_cut(mut cams: Query<(&raea_sys_post::cut::CameraCut, &mut bevy::solari
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A pipeline whose shader didn't compile draws nothing, and the frame comes out without its pass (Solari's light, a
|
||||
/// material): an error of the render, said once a pipeline, so `raea render` ends on it instead of "0 errors" over a
|
||||
/// picture that isn't the scene's (11-25: a reserved word in a shader, and three held runs measured as if lit). A
|
||||
/// shader still loading is Bevy's to retry, not a failure.
|
||||
fn failed_pipelines(cache: Res<bevy::render::render_resource::PipelineCache>, mut told: Local<std::collections::HashSet<usize>>) {
|
||||
use bevy::render::render_resource::CachedPipelineState;
|
||||
use bevy::shader::ShaderCacheError;
|
||||
for (i, p) in cache.pipelines().enumerate() {
|
||||
let CachedPipelineState::Err(e) = &p.state else { continue };
|
||||
if matches!(e, ShaderCacheError::ShaderNotLoaded(_) | ShaderCacheError::ShaderImportNotYetAvailable) || !told.insert(i) {
|
||||
continue;
|
||||
}
|
||||
let why = e.to_string();
|
||||
let found = raea_core_facts::Finding::new("shader", raea_core_facts::Level::Error, format!("a shader didn't compile, so its pass isn't in the picture: {}", why.lines().map(str::trim).filter(|l| !l.is_empty()).take(4).collect::<Vec<_>>().join(" ")), "raea render");
|
||||
eprintln!("raea: {}", found.line());
|
||||
raea_core_facts::finding::said(&[found]);
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,8 @@ raea_plugin! {
|
||||
ProcMatPlugin: raea_sys_procmat::install, "Procedural surfaces: wood, stone, brick, tiles and the rest, with dust and dirt (systems/procmat).";
|
||||
PaintPlugin: super::paint::install, "The paint and cartoon looks' surfaces (paint.rs).";
|
||||
PassesPlugin: super::passes::install, "Render passes per view (passes.rs).";
|
||||
TracedAoPlugin: raea_sys_rt::passes, "Traced passes: ambient occlusion, raea GI's world probes and the sun's far shadow map (raea-sys-rt).";
|
||||
GiScreenPlugin: raea_sys_gi::install, "raea GI's light on screen: each pixel's indirect diffuse from the world cache, read by the main pass (raea-sys-gi, RAEA_GI=1).";
|
||||
TracedAoPlugin: raea_sys_rt::passes, "Traced passes: ambient occlusion, raealism's world probes and the sun's far shadow map (raea-sys-rt).";
|
||||
GiScreenPlugin: raea_sys_gi::install, "raealism's light on screen: each pixel's indirect diffuse from the world cache, read by the main pass (raea-sys-gi, RAEA_GI=1).";
|
||||
VolumePlugin: super::volume::install, "Simulated smoke, clouds and contrails, raymarched (volume.rs).";
|
||||
GrassPlugin: raea_sys_grass::install, "Fields of grass, made in tiles as detailed as the camera's distance asks (systems/grass).";
|
||||
DetailPlugin: raea_sys_lod::install, "Where each part is drawn: levels by distance or size on screen, cross-faded, draw distance and shadows left to a coarser level (raea-sys-lod, docs/realism.feature LT21).";
|
||||
|
||||
+59
-1
@@ -451,11 +451,51 @@ fn start(cx: &mut FirewheelContext, block: u32) -> Result<(cpal::Stream, u32), S
|
||||
// the block size when the device's range takes it, else its own
|
||||
let fits = dev.supported_output_configs().map(|mut c| c.any(|r| r.channels() == channels && matches!(r.buffer_size(), cpal::SupportedBufferSize::Range { min, max } if *min <= block && block <= *max))).unwrap_or(false);
|
||||
let config = cpal::StreamConfig { channels, sample_rate: cpal::SampleRate(rate), buffer_size: if fits { cpal::BufferSize::Fixed(block) } else { cpal::BufferSize::Default } };
|
||||
let stream = dev.build_output_stream(&config, move |o: &mut [f32], i: &cpal::OutputCallbackInfo| callback(o, i), |e| eprintln!("raea mixer: {e}"), None).map_err(|e| format!("audio stream: {e}"))?;
|
||||
let stream = dev.build_output_stream(&config, move |o: &mut [f32], i: &cpal::OutputCallbackInfo| callback(o, i), said_once::<cpal::StreamError>("raea mixer"), None).map_err(|e| format!("audio stream: {e}"))?;
|
||||
stream.play().map_err(|e| format!("audio stream: {e}"))?;
|
||||
Ok((stream, rate))
|
||||
}
|
||||
|
||||
/// A device's error said once, then only how often it came back (at its 10th, 100th, ... time, and never more than once
|
||||
/// a second): a failing ALSA device calls a stream's error callback without pause, and every call printed a line: #239's
|
||||
/// app.log reached 40 GB of one line in two days.
|
||||
fn said_once<E: std::fmt::Display>(what: &'static str) -> impl FnMut(E) + Send + 'static {
|
||||
let mut seen = Repeats::default();
|
||||
move |e| {
|
||||
let m = e.to_string();
|
||||
match seen.hit(&m, std::time::Instant::now()) {
|
||||
Some(1) => eprintln!("{what}: {m}"),
|
||||
Some(n) => eprintln!("{what}: {m} ({n} times now)"),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Which of an error's repeats get said: `hit` answers with the count to print, or nothing.
|
||||
#[derive(Default)]
|
||||
struct Repeats {
|
||||
last: String,
|
||||
n: u64,
|
||||
next: u64,
|
||||
at: Option<std::time::Instant>,
|
||||
}
|
||||
|
||||
impl Repeats {
|
||||
fn hit(&mut self, m: &str, now: std::time::Instant) -> Option<u64> {
|
||||
if m != self.last || self.n == 0 {
|
||||
(self.last, self.n, self.next) = (m.to_string(), 0, 1);
|
||||
}
|
||||
self.n += 1;
|
||||
let soon = self.at.is_some_and(|t| now.duration_since(t).as_secs() < 1);
|
||||
if self.n < self.next || (soon && self.n > 1) {
|
||||
return None;
|
||||
}
|
||||
self.next = self.n.saturating_mul(10);
|
||||
self.at = Some(now);
|
||||
Some(self.n)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Live {
|
||||
fn drop(&mut self) {
|
||||
let Some((path, buf)) = self.tap.take() else { return };
|
||||
@@ -470,3 +510,21 @@ impl Drop for Live {
|
||||
let _ = std::fs::write(&side, format!("{{\"anchors\": [{}], \"report\": {}}}", anchors.join(", "), self.report()));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod repeats {
|
||||
use super::Repeats;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// #239: half a billion repeats of one ALSA error were half a billion lines. Two days of them are a handful.
|
||||
#[test]
|
||||
fn a_repeating_error_is_a_handful_of_lines() {
|
||||
let (mut r, t0) = (Repeats::default(), Instant::now());
|
||||
// 5,000 a second for a minute
|
||||
let said = (0..300_000u64).filter(|i| r.hit("alsa::poll() returned POLLERR", t0 + Duration::from_micros(i * 200)).is_some()).count();
|
||||
assert!(said <= 8, "{said} lines for 300,000 repeats");
|
||||
assert_eq!(Repeats::default().hit("x", t0), Some(1), "the first is always said");
|
||||
// another error is said at once, when a second has gone by
|
||||
assert_eq!(r.hit("the device went away", t0 + Duration::from_secs(120)), Some(1));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user