diff --git a/crates/nodes/src/pattern/tests/underfilled_quadrants.rs b/crates/nodes/src/pattern/tests/underfilled_quadrants.rs index 59c9d0be..4a57b1c7 100644 --- a/crates/nodes/src/pattern/tests/underfilled_quadrants.rs +++ b/crates/nodes/src/pattern/tests/underfilled_quadrants.rs @@ -69,8 +69,7 @@ fn wide_first_level_stamps_keep_the_order_of_deeper_draws() { assert_eq!(overlapping_subtree_pixel(1, -1.0, true).to_bits(), 2.0_f32.powi(-25).to_bits()); } -#[test] -fn filled_quadrant_batches_submit_the_middle_pair_before_the_upper_pair() { +fn filled_quadrant_pixel(negative: usize, positive: usize) -> f32 { let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); let iterate = graph.root.unwrap(); let root = graph.add(PatternNodeKind::Quadrant).unwrap(); @@ -92,10 +91,13 @@ fn filled_quadrant_batches_submit_the_middle_pair_before_the_upper_pair() { let second = graph.add(PatternNodeKind::Quadrant).unwrap(); graph.nodes[(first - 1) as usize].children[slot] = Some(second); let cell = [2 * (quadrant % 2) + slot % 2, 2 * (quadrant / 2) + slot / 2]; - let gain = match 4 * quadrant + slot { - 10 => -1.0, - 2 => small, - _ => faint, + let ordinal = 4 * quadrant + slot; + let gain = if ordinal == negative { + -1.0 + } else if ordinal == positive { + small + } else { + faint }; let shift = if gain == faint { [0.0; 2] } else { cell.map(|i| 0.265625 - (i as f32 + 0.5) * 0.25) }; let node = &mut graph.nodes[(second - 1) as usize]; @@ -104,5 +106,15 @@ fn filled_quadrant_batches_submit_the_middle_pair_before_the_upper_pair() { } } let image = cook_in_regions(graph, &BTreeMap::new(), 41381, [32; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); - assert_eq!(image.get_gray(8, 8, false).to_bits(), small.to_bits()); + image.get_gray(8, 8, false) +} + +#[test] +fn filled_quadrant_batches_submit_the_middle_pair_before_the_upper_pair() { + assert_eq!(filled_quadrant_pixel(10, 2).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_full_batch_collects_separate_ranges_of_the_last_quadrant() { + assert_eq!(filled_quadrant_pixel(15, 4).to_bits(), 2.0_f32.powi(-25).to_bits()); } diff --git a/crates/nodes/src/pattern/underfilled_quadrants.rs b/crates/nodes/src/pattern/underfilled_quadrants.rs index 3f5c76d6..5e3001df 100644 --- a/crates/nodes/src/pattern/underfilled_quadrants.rs +++ b/crates/nodes/src/pattern/underfilled_quadrants.rs @@ -2,7 +2,7 @@ use materialcraft_core::{PatternNode, PatternNodeKind}; use super::{ footprint::SampleGrid, - pattern_stamp::{DrawPosition, DrawRun, PatternStamp}, + pattern_stamp::{CopyPositions, DrawPosition, DrawRun, PatternStamp}, raster::MIN_STAMP_SIZE, tile_runs::{COPIES_PER_BATCH, LEADING_SUBTREES}, }; @@ -20,6 +20,9 @@ const GROUPS: [&[(usize, usize)]; 8] = [ &[(30, 40), (66, 68)], &[(10, 20)], ]; +// After the leading pairs fill their batches, the last root child collects a +// batch from these three ranges in submission order. They are separate in traversal. +const LAST_CHILD_GROUP: usize = 4; const RANGES_PER_CHILD: usize = 1 + 4 * 5; const RANGES_PER_TREE: usize = 4 * RANGES_PER_CHILD; @@ -56,6 +59,8 @@ pub(super) struct UnderfilledQuadrants { first_shape: Option, first_copies: u64, pairs: Vec, + last_child_spans: [CopyPositions; GROUPS[LAST_CHILD_GROUP].len()], + last_child_span: Option, active_deep_draws: usize, } @@ -91,8 +96,13 @@ impl UnderfilledQuadrants { if !parent { self.occupied.push(false); } - let Some(group) = GROUPS.iter().position(|spans| spans.iter().any(|&(lo, hi)| (lo..hi).contains(&segment))) else { return false }; + let Some((group, span)) = + GROUPS.iter().enumerate().find_map(|(group, spans)| spans.iter().position(|&(lo, hi)| (lo..hi).contains(&segment)).map(|span| (group, span))) + else { + return false; + }; self.group = group; + self.last_child_span = (group == LAST_CHILD_GROUP && self.visits[0] == 1).then_some(span); true } @@ -127,6 +137,11 @@ impl UnderfilledQuadrants { } let Some(pair) = self.pairs.last_mut() else { return false }; pair.record(count, index, retained); + if let Some(span) = self.last_child_span + && self.last_child_spans[span].record(count, retained).is_none() + { + return false; + } self.active_deep_draws += 1; self.copies[self.group] = self.copies[self.group].saturating_add(count); true @@ -142,23 +157,41 @@ impl UnderfilledQuadrants { return None; } let position = |stamp| DrawPosition { stamp, copy: 0 }; - let mut runs = Vec::new(); + let mut leading = Vec::new(); for group in LEADING_SUBTREES { let pair = self.pairs.get(group / 8)?; - runs.push(DrawRun::between(stamps, position(pair.start), pair.cut?)?); + leading.push((position(pair.start), pair.cut?)); } + let copies: u64 = self.last_child_spans.iter().map(|span| u64::from(span.total)).sum(); + if copies / u64::from(COPIES_PER_BATCH) == 1 { + let mut remaining = COPIES_PER_BATCH; + for (&(first, _), span) in GROUPS[LAST_CHILD_GROUP].iter().zip(&self.last_child_spans) { + let start = *self.starts.get(first + 1 + first / 20)?; + let count = remaining.min(span.total); + let end = span.at(count); + leading.push((position(start), DrawPosition { stamp: start.checked_add(end.stamp)?, copy: end.copy })); + remaining -= count; + if remaining == 0 { + break; + } + } + } + leading.retain(|(start, end)| start < end); + let mut runs: Vec<_> = leading.iter().map(|&(start, end)| DrawRun::between(stamps, start, end)).collect::>()?; + // Remove the submitted pieces in traversal order. A wrapped stamp may contribute to both sides of a cut. + leading.sort_unstable(); + let mut submitted = leading.into_iter().peekable(); for tree in 0..trees { for child in 0..4 { let base = tree * RANGES_PER_TREE + child * RANGES_PER_CHILD; let mut start = position(*self.starts.get(base + 1)?); - if tree == 0 - && let Some(group) = LEADING_SUBTREES.iter().find(|&&group| group / 16 == child) - { - let pair = self.pairs.get(group / 8)?; - runs.push(DrawRun::between(stamps, start, position(pair.start))?); - start = pair.cut?; + let end = position(*self.starts.get(base + RANGES_PER_CHILD)?); + while submitted.peek().is_some_and(|(first, _)| *first < end) { + let (first, next) = submitted.next()?; + runs.push(DrawRun::between(stamps, start, first)?); + start = next; } - runs.push(DrawRun::between(stamps, start, position(*self.starts.get(base + RANGES_PER_CHILD)?))?); + runs.push(DrawRun::between(stamps, start, end)?); } } Some(runs) diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index 13cc5b18..5d4df25a 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -59,6 +59,30 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas ## 2026-11-23 root comparisons +### A full copy batch in the last root quadrant + +In a complete eight-level additive tree with two full batches per neighboring pair of depth-two quadrants, the next 5,460 physical copies come from three parts of the first tree. In zero-based child-slot traversal order, take the depth-two draw at 15, then the depth-three subtrees 62 and 63, then 48 and 49. Stop after 5,460 copies when these parts together contain one full batch and a smaller remainder. A cut within one wrapped stamp can submit some of its copies now and the others later. The shared evaluator uses the observed batch counts and the ordered spans. [Evaluator and shape conditions](../crates/nodes/src/pattern/underfilled_quadrants.rs) · [Two-square regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Use the earlier signed-square procedure with depth-two (negative, positive) pairs (15,4), (12,15), (15,0) and (14,15). Use a plain quadrant for the first and fourth trees and one outer iteration for the second and third. Add faint first-level Gaussians to the second and fourth. The 32² default with pair (15,4) reads 2⁻²⁵ at (.265625,.265625), previously zero. Repeat at 16 × 32, 32 × 16 and 64 × 32 with the same changed gains, seed series and four output formats as the preceding batch experiment. [Gains, seeds and ordinary-save procedure](#leading-copy-batches-in-complete-quadrant-trees) + +| Output | Previous exact / 16,384 · max | Current original exact / 16,384 · max | Current ordinary save exact / 16,384 · max | +|---|---:|---:|---:| +| U8 | 16,384 · 0 | 16,384 · 0 | 16,384 · 0 | +| U16 | 16,384 · 0 | 16,384 · 0 | 16,384 · 0 | +| F16 | 16,300 · 2⁻²⁴ | 16,384 · 0 | 16,384 · 0 | +| F32 | 15,712 · 2⁻²⁴ | 16,286 · 5.29395623e−23 | 16,286 · 5.29395623e−23 | + +Together the four graphs match 65,438/65,536 original and 65,438/65,536 reopened pixels. Three retain a residual in F32. In five independently authored fields with one, two and four trees, all 1,250 signed order comparisons agree. Doubling the physical copies everywhere except depth-two pairs starting at 2, 6 and 10 in the first tree produces a second full batch in the last root quadrant. In this control 65/269 predicted orders differ. For a separate boundary check, double the footprints in subtrees 62 and 63 to place the cut there, or leave them at unit size to place it in 48 and 49. Place the boundary stamp across the horizontal seam for two copies, or across both seams for four. Test each copy against a depth-two square at 4 with both gain directions. All 56 comparisons agree, including cuts one, two and three copies into a four-copy stamp. All 245 earlier procedural settings still give 1,138,688/1,138,688 exact pixels. + +| Noise BNW Spots 1 | One processor · exact / total · max | Eight processors · exact / total · max | Ordinary saves · exact / total · max | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,342/328,448 · 1 | 328,259/328,448 · 1 | 93,683/93,696 · 1 | +| F16 | 108,799/108,800 · .0001220703125 | 108,799/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 253,651/295,680 · 2.38418579e−7 | 234,924/295,680 · 3.57627869e−7 | 5,920/6,144 · 2.38418579e−7 | + +The 86 one-processor settings gain 4,246 exact pixels, reaching 799,592/841,728. The eight-processor comparisons lose 1,247, reaching 780,781/841,728. The 19 ordinary saves gain 13, reaching 196,115/196,352. At 16 × 32 with scale and roughness one, disorder zero and seed zero, the whole F32 image improves from 393 to 403 of 512, maximum 1.19209290e−7, in four original and four reopened captures. The early levels match 512/512 in each. Under the 256² exposed defaults and seed zero, F32 improves from 51,179 to 53,802 of 65,536 on one processor and changes from 43,327 to 42,389 on the eight-processor capture. The one-processor 256² F16 original is now exact. One 2,048-pixel F32 setting loses two exact pixels on one processor. One U16 setting becomes exact on one processor and loses whole-frame agreement on eight. At 32 × 64, seed 456747, scale two, roughness one and disorder .84375, interleave four fresh renders with changed seeds. The new F32 result loses exactly two matches against each of the five one-processor frames, including two of the 1,709 invariant pixels. At 64 × 32, seed 162172, scale one, disorder .5625 and roughness .6015625, all five one-processor U16 frames match 2,048/2,048. The eight-processor captures give three distinct frames. All 2,045 invariant pixels agree, and each of the three varying pixels agrees with at least one capture. Subsequent submissions and processor-dependent differences remain open. [Earlier measurements and repeated captures](#leading-copy-batches-in-complete-quadrant-trees) + ### Leading copy batches in complete quadrant trees In a complete eight-level grayscale quadrant tree, each pair of neighboring depth-two quadrants contains eight depth-three subtrees. Number the subtrees 0–63 in child-slot traversal order. When every pair emits two full batches of 5,460 physical copies plus a remainder smaller than a batch, the first tree submits 10,920 copies from each of the spans starting at subtrees 24, 40 and 8, in that order. This was measured with additive draws at every level from two through eight and a separate optional shape at level one. Copies outside the sampled pixels still count. A cut within a wrapped stamp separates individual copies. The renderer applies the measured prefix and keeps its existing traversal for the remaining deeper draws. [Shared evaluator](../crates/nodes/src/pattern/underfilled_quadrants.rs) · [Two-square regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 13e4f103..cf8aabd3 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -405,7 +405,7 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug | [multiangle_to_normal.sbs/angle_weight](../assets/sbs/multiangle_to_normal.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [noise_anisotropic_noise.sbs/anisotropic_noise](../assets/sbs/noise_anisotropic_noise.sbs) | 0 | Yes | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#quarter-turn-directional-blur) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | | [noise_anisotropic_noise_v2.sbs/anisotropic_noise_v2](../assets/sbs/noise_anisotropic_noise_v2.sbs) | 0 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#high-pass-anisotropic-noise-and-triangle-grid-controls) | -| [noise_bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1.sbs) | 0 | Yes | [In progress · 795,346/841,728 on one processor, 782,028/841,728 on eight across 86 settings, and 196,102/196,352 on 19 saves](parity-fixes.md#leading-copy-batches-in-complete-quadrant-trees) · [393/512 in eight identical original and reopened F32 captures at 16 × 32](parity-fixes.md#leading-copy-batches-in-complete-quadrant-trees) · [Measured physical copy boundary](parity-fixes.md#physical-copy-boundaries-in-dense-quadrant-subtrees) · [Inactive descendants affect draw order, 21/21 independently replayed F32 values](parity-fixes.md#connected-inactive-descendants-and-dense-quadrant-draw-order) · [Eight additional 64 × 32 F32 isolates cook](parity-fixes.md#bounded-work-for-empty-terminal-quadrants) · [Five levels combined, original and reopened, each 8,192/8,192 F32](parity-fixes.md#wide-first-level-shapes-in-additive-quadrant-trees) · [Depths 3–6 match 32,768/32,768 isolated F32 pixels](parity-fixes.md#submission-order-in-underfilled-eight-level-quadrant-trees) · [Earlier 60-setting comparison](parity-fixes.md#connected-quadrant-depth-and-amplified-spot-patterns) · [Zero roughness exact in U16 and F32](parity-fixes.md#grayscale-pattern-output-at-zero-roughness) · [Draw order, 18 changed-format comparisons](parity-fixes.md#draw-order-for-overlapping-procedural-grayscale-stamps) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) | +| [noise_bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1.sbs) | 0 | Yes | [In progress · 799,592/841,728 on one processor, 780,781/841,728 on eight across 86 settings, and 196,115/196,352 on 19 saves](parity-fixes.md#a-full-copy-batch-in-the-last-root-quadrant) · [403/512 in eight identical original and reopened F32 captures at 16 × 32](parity-fixes.md#a-full-copy-batch-in-the-last-root-quadrant) · [Earlier six batches](parity-fixes.md#leading-copy-batches-in-complete-quadrant-trees) · [Measured physical copy boundary](parity-fixes.md#physical-copy-boundaries-in-dense-quadrant-subtrees) · [Inactive descendants affect draw order, 21/21 independently replayed F32 values](parity-fixes.md#connected-inactive-descendants-and-dense-quadrant-draw-order) · [Eight additional 64 × 32 F32 isolates cook](parity-fixes.md#bounded-work-for-empty-terminal-quadrants) · [Five levels combined, original and reopened, each 8,192/8,192 F32](parity-fixes.md#wide-first-level-shapes-in-additive-quadrant-trees) · [Depths 3–6 match 32,768/32,768 isolated F32 pixels](parity-fixes.md#submission-order-in-underfilled-eight-level-quadrant-trees) · [Earlier 60-setting comparison](parity-fixes.md#connected-quadrant-depth-and-amplified-spot-patterns) · [Zero roughness exact in U16 and F32](parity-fixes.md#grayscale-pattern-output-at-zero-roughness) · [Draw order, 18 changed-format comparisons](parity-fixes.md#draw-order-for-overlapping-procedural-grayscale-stamps) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) | | [noise_bnw_spots_1_v2.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1_v2.sbs) | 0 | No | [In progress · 831,506/842,752 pixels on one processor, 831,311/842,752 on eight · 87 settings](parity-fixes.md#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [All 87 original settings and 19 saves rechecked](parity-fixes.md#dense-settings-recovered-in-the-third-spots-graph) · [Depth-local variable writes fixed, 28,082/28,160 on twelve whole guards](parity-fixes.md#inherited-and-writable-variables-across-quadrant-depths) · [Two additional 64 × 32 isolates, each 2,048/2,048 F32](parity-fixes.md#bounded-work-for-empty-terminal-quadrants) · [Levels 7–8, 8,047/8,192 F32 on original, 8,048/8,192 reopened](parity-fixes.md#wide-first-level-shapes-in-additive-quadrant-trees) · [Earlier spot comparison](parity-fixes.md#connected-quadrant-depth-and-amplified-spot-patterns) · [Zero roughness exact in U16 and F32](parity-fixes.md#grayscale-pattern-output-at-zero-roughness) · [Draw order, 18 changed-format comparisons](parity-fixes.md#draw-order-for-overlapping-procedural-grayscale-stamps) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) | | [noise_bnw_spots_3.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3.sbs) | 0 | Yes | [In progress · six more settings render, 49,131/49,152 on one processor, 49,132/49,152 on eight](parity-fixes.md#dense-settings-recovered-in-the-third-spots-graph) · [Earlier 48 settings, 671,452/671,744 pixels on one processor, 671,526/671,744 on eight](parity-fixes.md#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [Earlier spot comparison](parity-fixes.md#deep-pattern-samples-in-custom-render-and-tiling-regions) · [Earlier matrix](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) · [64² precision and remaining traversal limits](parity-fixes.md#precision-of-two-dense-noise-generators-in-custom-regions) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit worker counts](parity-fixes.md#branch-offsets-center-culling-and-two-dense-spot-graphs) · [Four-format square and reopened comparisons](parity-fixes.md#two-dense-spots-packages-across-storage-formats) | | [noise_bnw_spots_3_v2.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3_v2.sbs) | 0 | No | [In progress · 16 of 32 blocked settings now render, 185,202/193,536 on one processor and 184,698/193,536 on eight](parity-fixes.md#recovered-settings-in-the-second-version-of-the-third-spots-graph) · [Three recovered saves, 5,999/6,144](parity-fixes.md#recovered-settings-in-the-second-version-of-the-third-spots-graph) · [Dense 32² comparison](parity-fixes.md#bounded-work-for-terminal-quadrant-siblings) · [Earlier comparison · 339,986/347,136 pixels on one processor, 341,093/347,136 on eight · 30 of 62 settings rendered](parity-fixes.md#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [Earlier spot comparison](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [bounded stage counts at scale two](parity-fixes.md#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Explicit worker counts](parity-fixes.md#branch-offsets-center-culling-and-two-dense-spot-graphs) · [Dense F32 traversal and worker repeats](parity-fixes.md#dense-quadrant-traversal-and-reference-worker-counts) · [Four-format square and reopened comparisons](parity-fixes.md#two-dense-spots-packages-across-storage-formats) |