diff --git a/crates/nodes/src/pattern/tests/paired_batches.rs b/crates/nodes/src/pattern/tests/paired_batches.rs index bf857784..a9e19e64 100644 --- a/crates/nodes/src/pattern/tests/paired_batches.rs +++ b/crates/nodes/src/pattern/tests/paired_batches.rs @@ -294,3 +294,60 @@ fn deferred_copies_can_fill_the_receiving_quadrant() { ]; check_batch_markers(&group_counts, 225301, 1, &markers); } + +#[test] +fn full_middle_pairs_continue_their_separate_subtrees() { + for (pairs, seed, markers) in [ + ( + [[32, 32], [101, 90], [32, 32]], + 226537, + [(279551, 102866, true), (280895, 256149, true), (283583, 288357, false), (284961, 255831, true), (288993, 302446, false), (290337, 222622, true)], + ), + ( + [[32, 32], [32, 32], [78, 101]], + 226568, + [(301055, 181298, true), (302399, 342071, false), (305087, 328846, false), (306465, 341076, false), (310497, 332538, false), (311841, 54464, true)], + ), + ( + [[88, 90], [101, 90], [78, 101]], + 226599, + [(279551, 97145, true), (280895, 256381, true), (283583, 332807, false), (284961, 258500, true), (288993, 310660, false), (290337, 222196, true)], + ), + ] { + let mut group_counts = [32; 64]; + for (first, pair) in [48, 52, 56].into_iter().zip(pairs) { + group_counts[first..first + 2].copy_from_slice(&pair); + } + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn penultimate_pair_splits_when_the_partial_subtrees_fill_a_batch() { + for (pair, seed, markers) in [ + ( + [79, 91], + 227173, + [(322559, 6703, true), (323903, 86579, true), (326591, 276861, true), (327969, 267935, true), (332001, 288482, true), (333345, 270405, true)], + ), + ( + [85, 97], + 227204, + [(322559, 16047, true), (323903, 277749, true), (326591, 94356, true), (327969, 258216, true), (332001, 267414, true), (333345, 272173, true)], + ), + ( + [101, 128], + 227235, + [(322559, 14801, true), (323903, 98883, true), (326591, 279431, true), (327969, 167744, true), (332001, 214799, true), (333345, 129478, true)], + ), + ( + [79, 150], + 227266, + [(322559, 22151, true), (323903, 91701, true), (326591, 91253, true), (331967, 283167, true), (333345, 129341, true), (87397, 309051, false)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[60..62].copy_from_slice(&pair); + check_batch_markers(&group_counts, seed, 1, &markers); + } +} diff --git a/crates/nodes/src/pattern/tile_runs.rs b/crates/nodes/src/pattern/tile_runs.rs index 6100bb6a..b857d543 100644 --- a/crates/nodes/src/pattern/tile_runs.rs +++ b/crates/nodes/src/pattern/tile_runs.rs @@ -98,12 +98,14 @@ impl TileCopies { ranges.into_iter().map(|r| DrawRun::between(stamps, self.draw_position(r.start), self.draw_position(r.end))).collect() } + fn subtree_copies(&self, subtrees: Range) -> Option { + let start = self.subtree_ends.get(subtrees.start.checked_sub(1)?)?; + self.subtree_ends.get(subtrees.end.checked_sub(1)?)?.checked_sub(*start) + } + fn group_copies(&self, groups: Range) -> Option { - let boundary = |group: usize| { - let subtrees = group * (DEPTH_THREE_PARENTS / self.parents_per_subtree); - self.subtree_ends.get(subtrees.checked_sub(1)?).copied() - }; - boundary(groups.end)?.checked_sub(boundary(groups.start)?) + let subtrees = DEPTH_THREE_PARENTS / self.parents_per_subtree; + self.subtree_copies(groups.start * subtrees..groups.end * subtrees) } fn horizontal_layout(&self, ordinary: &'static [(usize, usize)], pair: Option<(usize, usize)>) -> Option> { @@ -129,6 +131,13 @@ impl TileCopies { return fallback(); } + Some(Self::shift_horizontal_boundaries(ordinary, pair, full_prefix)) + } + + fn shift_horizontal_boundaries(ordinary: &'static [(usize, usize)], pair: Option<(usize, usize)>, full_prefix: bool) -> Cow<'static, [(usize, usize)]> { + if pair.is_none() && !full_prefix { + return Cow::Borrowed(ordinary); + } let mut layout = ordinary.to_vec(); for (end, _) in &mut layout { if let Some((group, head)) = pair { @@ -145,7 +154,25 @@ impl TileCopies { *end = (*end - DEPTH_FOUR_PARENTS).max(last); } } - Some(Cow::Owned(layout)) + Cow::Owned(layout) + } + + fn penultimate_layout(&self, ordinary: &'static [(usize, usize)]) -> Option> { + let prefix = self.group_copies(60..61)?; + let full_prefix = prefix >= COPIES_PER_BATCH; + let subtrees = DEPTH_THREE_PARENTS / DEPTH_FOUR_PARENTS; + let receiver = 16 * subtrees; + let following = 61 * subtrees; + let first = if full_prefix { following + 2 } else { following }; + // After the first batch, the first remaining part of group 61 and its + // final subtree join the two middle subtrees of group 16. Only a full + // batch at that point separates the later runs. + let mut copies = prefix; + for range in [first..first + 1, following + 3..following + 4, receiver + 1..receiver + 3] { + copies = copies.checked_add(self.subtree_copies(range)?)?; + } + let layout = if copies >= 2 * COPIES_PER_BATCH { PairedBatches::Penultimate.layout() } else { ordinary }; + Some(Self::shift_horizontal_boundaries(layout, None, full_prefix)) } pub(super) fn layout(&self, ordinary: &'static [(usize, usize)]) -> Option> { @@ -156,7 +183,10 @@ impl TileCopies { let later = self.full_pairs & !1; if self.parents_per_subtree == DEPTH_FOUR_PARENTS && self.axes == [true, false] { match later { - 0 => return self.horizontal_layout(ordinary, None), + // Groups 52–53 and 56–57 submit their subtrees separately, + // including when both pairs contain two full batches. + 0 | 0b100 | 0b10000 | 0b10100 => return self.horizontal_layout(ordinary, None), + 0b1000000 => return self.penultimate_layout(ordinary), 0b10 => return self.horizontal_layout(ordinary, Some((50, 16))), 0b1000 => return self.horizontal_layout(ordinary, Some((54, 32))), _ => {} diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index c355f75b..12636d1a 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -464,6 +464,27 @@ The one-processor whole-root difference falls from 328 pixels to 45. The eight-p Remaining single-processor differences occur at six seed-and-size combinations. Further full-pair continuations and the late splits around groups 50, 54, 58, 60 and 62 remain under measurement. Both regression tests failed before the change. All 438 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly checks. +### Middle and penultimate horizontal subtree pairs in Dirt Gradient + +Dirt Gradient matches 102 of 111 whole settings on one processor, up from 96. Six additional U16, F16 and F32 renders are exact at 128², seed 191593, and 128 × 64, seed 142328. The other 105 settings retain their previous counts. Against eight processors 44 settings match in full. On the 28 saved-file controls each application reproduces every one of its own 430,336 pixels. Integers in the table use stored codes and floating-point maxima are absolute channel errors. [Whole-root inputs, settings and preceding measurements](#full-receiving-quadrants-and-seven-batch-prefixes-in-dirt-gradient) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,577/846,592 · 1 | 600,319/600,320 · 6.10351562e−5 | 816,113/816,128 · 1.75833702e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,265/846,592 · 2 | 600,295/600,320 · 0.00048828125 | 815,784/816,128 · 2.03251839e−5 | +| Reference one versus eight | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,777/816,128 · 2.03251839e−5 | +| Saved files on one processor | 36,864/36,864 · 0 | 80,887/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,808/279,808 · 0 | + +Use a complete quadrant tree with active levels 7, 8 and 9, horizontal tiling and groups numbered from zero in traversal order. Groups 52–53 and 56–57 submit their subtrees separately even when either pair contains two 5,460-copy batches. This covers the two pairs together and a full first pair in groups 48–49. For the penultimate pair, start with the copies in group 60. Add the two middle depth-four subtrees of group 16 and the last subtree of group 61. When group 60 is short of one batch, add the first subtree of group 61. When group 60 fills a batch, add the third subtree instead. Reaching 10,920 copies separates the later runs. A full group 60 also advances the three affected boundaries by one depth-four subtree. + +For the middle pairs, start at 32 extra copies per group and set groups 52–53 to 101 and 90, or 56–57 to 78 and 101, or both with groups 48–49 set to 88 and 90. Use seeds 226537, 226568 and 226599. For the last four controls set groups 60–61 to (79,91), (85,97), (101,128) and (79,150), starting at seed 227173 and adding 31 each time. Reversing the two marker opacities agrees on all 208 draw-order comparisons. The compiled renderer matches 229,376/229,376 F32 pixels across the 14 signed controls. [Procedural square and copy construction](#horizontal-pattern-batches-ending-in-the-preceding-subtree) + +Fifty-four earlier weighted fields and 70 independent threshold settings give 1,015,808/1,015,808 F32 pixels in the draw-order replay. For the latter, vary group 60's extra copies over 40, 65, 79, 83, 84, 85 and 96. Across two different fields for each value, move the four selected subtree counts to give combined totals of 10,918, 10,919, 10,920, 10,921 and 10,923. The compiled renderer matches all 573,440/573,440 pixels, maximum zero. The two affected direct F32 generator settings improve from 6,661/16,384 and 3,257/8,192 to 24,576/24,576 combined, maximum zero. An additional 84 weighted settings cover mixed group occupancies and four copy-count fields from whole renders. The compiled result is 677,519/688,128 · 3.4570694e−6. + +Seven weighted settings, the forward marker input from one fixture and the reversed input from another give nine additional saves. Each MaterialCraft reopen reproduces its original. All nine source renders match across applications. In the first reference reopen series the saved files differ from the reference originals on 6,771 pixels, giving 83,341/90,112 · 3.33786011e−6 across applications. Two fresh comparisons of each source and each saved file in a new reference session reproduce the originals on 360,448/360,448 pixels with zero error. + +The one-processor whole-root comparison now differs on 31 pixels and the eight-processor comparison on 696. The reference modes differ on 707 pixels for the same 111 settings. Three extra one-processor captures of each of the earlier 20 nonexact settings repeat all 2,927,616 stored pixels. Of the remaining 31 differences, 21 match the eight-processor capture and 10 fall outside all retained reference values. Four seed-and-size combinations remain open, including a final horizontal pair with three deferred copies. Both added regressions failed before the change. All 440 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. Across four interleaved release runs per implementation, the three horizontal generator settings used a median 20.281 seconds of process CPU time before the change and 20.312 seconds after it, including loading and readback. + ## 2026-11-21 root comparisons ### Connected quadrant depth and amplified spot patterns diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index e1baed51..5567f169 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -255,7 +255,7 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug | [dirt_3.sbs/dirt_3](../assets/sbs/dirt_3.sbs) | 0 | Yes | [In progress · 68 single-processor settings exact, 2,316,526/2,316,544 pixels on eight processors](parity-fixes.md#three-terminal-children-in-seven-level-quadrant-trees) · [Earlier distinct settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier isolation](parity-fixes.md#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,316,511/2,316,544 pixels across 68 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) | | [dirt_5.sbs/dirt_5](../assets/sbs/dirt_5.sbs) | 0 | Yes | [In progress · 2,662,656/2,662,656 pixels on one processor, 2,661,672/2,662,656 on eight across 95 settings](parity-fixes.md#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) · [2,005,576/2,006,016 pixels across 40 new renders](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier measurements](parity-fixes.md#stored-opacity-across-pattern-depths) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,299,232/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) | | [dirt_6.sbs/dirt_6](../assets/sbs/dirt_6.sbs) | 0 | Yes | [In progress · 2,593,024/2,593,024 pixels across 84 single-processor settings, 2,591,547/2,593,024 on eight](parity-fixes.md#individual-tile-copies-across-a-pattern-draw-boundary) · [Previous four-child generator results](parity-fixes.md#wrapped-draw-order-for-four-children-below-depth-seven) · [Earlier measurements](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier isolation](parity-fixes.md#drawing-axis-aligned-stamps-smaller-than-one-pixel) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,298,882/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [untiled generator measurements and four-format reopens](parity-fixes.md#untiled-draw-order-for-two-and-four-children-below-depth-seven) | -| [dirt_gradient.sbs/dirt_gradient](../assets/sbs/dirt_gradient.sbs) | 0 | Yes | [In progress · 96/111 settings and 2,863,315/2,863,360 pixels on one processor, 2,862,674/2,863,360 on eight](parity-fixes.md#full-receiving-quadrants-and-seven-batch-prefixes-in-dirt-gradient) · [Earlier deferred-copy comparison](parity-fixes.md#deferred-copies-in-horizontal-dirt-gradient-batches) · [Earlier preceding-subtree comparison](parity-fixes.md#horizontal-pattern-batches-ending-in-the-preceding-subtree) · [Earlier both-axis comparison](parity-fixes.md#eight-full-subtree-pairs-in-dirt-gradient) · [Nine horizontal generator settings](parity-fixes.md#a-late-copy-in-the-penultimate-horizontal-subtree-pair) · [Earlier horizontal comparison](parity-fixes.md#individual-tile-copies-after-two-full-horizontal-batches) · [Previous 111-setting comparison](parity-fixes.md#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient) · [Five of nine horizontal generator settings exact](parity-fixes.md#the-first-subtree-pair-in-the-final-dirt-gradient-quadrant) · [2,662,010/2,662,656 pixels on one processor, 2,662,090/2,662,656 on eight across 95 settings](parity-fixes.md#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) · [2,005,640/2,006,016 pixels across 40 new renders](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier measurements](parity-fixes.md#draw-order-at-six-quadrant-subdivisions) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,299,615/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) | +| [dirt_gradient.sbs/dirt_gradient](../assets/sbs/dirt_gradient.sbs) | 0 | Yes | [In progress · 102/111 settings and 2,863,329/2,863,360 pixels on one processor, 2,862,664/2,863,360 on eight](parity-fixes.md#middle-and-penultimate-horizontal-subtree-pairs-in-dirt-gradient) · [Earlier receiving-quadrant comparison](parity-fixes.md#full-receiving-quadrants-and-seven-batch-prefixes-in-dirt-gradient) · [Earlier deferred-copy comparison](parity-fixes.md#deferred-copies-in-horizontal-dirt-gradient-batches) · [Earlier preceding-subtree comparison](parity-fixes.md#horizontal-pattern-batches-ending-in-the-preceding-subtree) · [Earlier both-axis comparison](parity-fixes.md#eight-full-subtree-pairs-in-dirt-gradient) · [Nine horizontal generator settings](parity-fixes.md#a-late-copy-in-the-penultimate-horizontal-subtree-pair) · [Earlier horizontal comparison](parity-fixes.md#individual-tile-copies-after-two-full-horizontal-batches) · [Previous 111-setting comparison](parity-fixes.md#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient) · [Five of nine horizontal generator settings exact](parity-fixes.md#the-first-subtree-pair-in-the-final-dirt-gradient-quadrant) · [2,662,010/2,662,656 pixels on one processor, 2,662,090/2,662,656 on eight across 95 settings](parity-fixes.md#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) · [2,005,640/2,006,016 pixels across 40 new renders](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier measurements](parity-fixes.md#draw-order-at-six-quadrant-subdivisions) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,299,615/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) | | [exposure.sbs/exposure](../assets/sbs/exposure.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [extend_shape.sbs/extend_shape_color](../assets/sbs/extend_shape.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [extend_shape.sbs/extend_shape_grayscale](../assets/sbs/extend_shape.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) |