Report Vectorize progress from ollev's own estimate of the whole trace

This commit is contained in:
Dennis Kobert committed 2026-11-21 23:12:25 +01:00
1 parent 4e3dfcd7e0
commit a42db391e6
5 files changed
+16 -157

No files matched your search

Generated
+2 -2
View File
@@ -4842,9 +4842,9 @@ dependencies = [
[[package]]
name = "ollev"
version = "0.1.2"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d77164e6c8fb386ee064104ab480578451b0fd106ca4c0a6988eb7ca4ed9ec4b"
checksum = "9e858a872f7e5f74992f283fe52d9c184234e8505f316e6aa7822fa394b39d0a"
dependencies = [
"glam",
]
+1 -1
View File
@@ -271,7 +271,7 @@ tinyvec = { version = "1", features = ["std"] }
criterion = { version = "0.8", features = ["html_reports"] }
gungraun = { version = "0.20" }
ndarray = "0.17"
ollev = "0.1.2"
ollev = "0.2.0"
dirs = "7.0"
cef = "156"
cef-dll-sys = "156"
+8 -10
View File
@@ -1,5 +1,4 @@
mod convert;
mod progress;
mod slices;
pub use convert::{ATTR_OLLEV_REPEAT, RepeatStructure};
@@ -149,18 +148,17 @@ fn trace_slice(image: &Item<Raster<CPU>>, detail: f64, tolerance: f64, stages: o
width,
height,
};
let options = ollev::TraceOptions {
tolerance,
detail: ollev::Detail::Scaled(detail),
max_pixels,
host: CAPABILITIES,
stages,
..Default::default()
};
let mut options = ollev::TraceOptions::default();
options.tolerance = tolerance;
options.detail = ollev::Detail::Scaled(detail);
options.max_pixels = max_pixels;
options.host = CAPABILITIES;
options.stages = stages;
ollev::Tracing::new(&source, &options).map(|tracing| (tracing, pixels_to_document))
};
slot.poll(hasher.finish(), slice, stages.translucency, start, convert::model_to_graphic)
slot.poll(hasher.finish(), slice, start, convert::model_to_graphic)
}
#[cfg(test)]
-137
View File
@@ -1,137 +0,0 @@
/// The top-level stages of a trace in the order ollev runs them, each with its share of the trace's time.
/// Measured with ollev 0.1.2 on 1024 by 1024 pixel renders of the demo artwork with the node's default stages, averaged over the images.
/// The unnamed stage is the setup before the first checkpoint names one.
const STAGES: [(&str, f64); 8] = [
("", 0.03),
("analyze", 0.21),
("plan", 0.09),
("draw", 0.18),
("redraw", 0.09),
("shapes", 0.16),
("families", 0.),
("passes", 0.24),
];
const FAMILIES: usize = 6;
/// The share of the trace's time the translucent families take with translucency on, which ranged from 6 to 93% on the same images.
/// The other stages split the rest in proportion to their shares.
const FAMILIES_SHARE: f64 = 0.35;
/// How many nested traces of the families stage fill half of its share, since how many there will be isn't known up front.
const HALF_FILLING_NESTED_TRACES: f64 = 4.;
/// Folds the stages ollev reports into one fraction of the whole trace that never goes down.
#[derive(Clone, Debug)]
pub struct TraceProgress {
translucency: bool,
stage: usize,
/// The fraction of the current stage, or for the families stage how many traces beneath its layers have started.
within_stage: f64,
previous_stage: &'static str,
fraction: f64,
}
impl TraceProgress {
pub fn new(translucency: bool) -> Self {
Self {
translucency,
stage: 0,
within_stage: 0.,
previous_stage: "",
fraction: 0.,
}
}
/// Takes in a checkpoint of the trace, where it is in `stage` with `fraction` of the stage done.
pub fn observe(&mut self, stage: &'static str, fraction: f64) {
let entered = stage != self.previous_stage;
self.previous_stage = stage;
// The traces beneath translucent layers repeat the stages before the families stage, so they count as part of it
if self.stage == FAMILIES && stage != "passes" {
if entered && stage == "analyze" {
self.within_stage += 1.;
}
} else if let Some(index) = STAGES.iter().position(|(name, _)| *name == stage)
&& index >= self.stage
{
if index > self.stage {
self.stage = index;
self.within_stage = 0.;
}
if index != FAMILIES {
self.within_stage = fraction.clamp(0., 1.);
}
}
let within_share = match self.stage {
FAMILIES => self.within_stage / (self.within_stage + HALF_FILLING_NESTED_TRACES),
_ => self.within_stage,
};
let before: f64 = (0..self.stage).map(|index| self.share(index)).sum();
self.fraction = self.fraction.max(before + self.share(self.stage) * within_share);
}
/// How much of the trace is done, from 0 to 1.
pub fn fraction(&self) -> f64 {
self.fraction.min(1.)
}
fn share(&self, index: usize) -> f64 {
match (self.translucency, index) {
(false, _) => STAGES[index].1,
(true, FAMILIES) => FAMILIES_SHARE,
(true, _) => STAGES[index].1 * (1. - FAMILIES_SHARE),
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn the_stages_fill_the_whole_trace() {
for translucency in [false, true] {
let progress = TraceProgress::new(translucency);
let total: f64 = (0..STAGES.len()).map(|index| progress.share(index)).sum();
assert!((total - 1.).abs() < 1e-9, "the shares add up to {total}");
}
}
#[test]
fn progress_moves_through_the_stages_and_within_them() {
let mut progress = TraceProgress::new(false);
progress.observe("analyze", 0.);
assert!((progress.fraction() - 0.03).abs() < 1e-9);
progress.observe("draw", 0.5);
assert!((progress.fraction() - (0.03 + 0.21 + 0.09 + 0.09)).abs() < 1e-9);
progress.observe("passes", 0.);
assert!((progress.fraction() - 0.76).abs() < 1e-9);
}
#[test]
fn the_traces_beneath_translucent_layers_never_move_progress_back() {
let mut progress = TraceProgress::new(true);
progress.observe("shapes", 0.);
progress.observe("families", 0.);
let families_start = progress.fraction();
let mut previous = families_start;
for _ in 0..3 {
for stage in ["analyze", "plan", "draw", "redraw", "shapes"] {
progress.observe(stage, 0.5);
assert!(progress.fraction() >= previous, "{stage} moved progress back");
previous = progress.fraction();
}
}
assert!(previous > families_start, "the nested traces didn't move progress");
assert!(previous < families_start + FAMILIES_SHARE, "the nested traces filled the families stage");
progress.observe("passes", 0.);
assert!((progress.fraction() - (1. - 0.24 * (1. - FAMILIES_SHARE))).abs() < 1e-9);
}
}
+5 -7
View File
@@ -1,4 +1,3 @@
use crate::progress::TraceProgress;
use core_types::list::List;
use core_types::runtime::Instant;
use core_types::{NodeError, Poll};
@@ -31,18 +30,17 @@ struct Trace {
shown: List<Graphic>,
/// The revision of the scene in `shown`.
revision: Option<u64>,
progress: TraceProgress,
/// How much of the trace is done from 0 to 1, as ollev last reported it.
progress: f64,
}
impl TraceSlot {
/// Advances the trace of `inputs` by `slice`, replacing any trace of other inputs with one from `start`, which also gives where the traced pixels lie.
/// Traces translucent layers if `translucency`.
/// Returns the latest showable scene, partial until the trace is done.
pub fn poll(
&self,
inputs: u64,
slice: Duration,
translucency: bool,
start: impl FnOnce() -> Result<(ollev::Tracing, DAffine2), ollev::TraceError>,
convert: impl Fn(&Model, DAffine2) -> List<Graphic>,
) -> Poll<List<Graphic>> {
@@ -58,7 +56,7 @@ impl TraceSlot {
pixels_to_document,
shown: List::new(),
revision: None,
progress: TraceProgress::new(translucency),
progress: 0.,
},
Err(error) => return Poll::fallback(List::new(), error),
},
@@ -68,7 +66,7 @@ impl TraceSlot {
let deadline = Instant::now() + slice;
let progress = &mut trace.progress;
let step = tracing.step(|checkpoint| {
progress.observe(checkpoint.stage, checkpoint.fraction);
*progress = checkpoint.overall;
if Instant::now() >= deadline { ControlFlow::Break(()) } else { ControlFlow::Continue(()) }
});
match step {
@@ -105,7 +103,7 @@ impl TraceSlot {
/// How much of the slot's trace is done from 0 to 1, while it is not yet done.
pub fn progress(&self) -> Option<f64> {
let held = self.lock();
held.as_ref().filter(|trace| trace.tracing.is_some()).map(|trace| trace.progress.fraction())
held.as_ref().filter(|trace| trace.tracing.is_some()).map(|trace| trace.progress)
}
/// Stops the slot's trace, keeping the scene traced so far as the result for its inputs.