mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-28 17:19:17 +01:00
Defer overflowing horizontal tile copies to their measured subtree positions
This commit is contained in:
1 parent
6f1042ad9c
commit
d91a28e84e
5 files changed
+146
-10
No files matched your search
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use materialcraft_core::{PatternNode, PatternNodeKind};
|
||||
|
||||
use super::{
|
||||
@@ -209,15 +211,16 @@ impl MixedDepthRuns {
|
||||
return None;
|
||||
}
|
||||
self.starts.push(DrawPosition { stamp: stamps.len(), copy: 0 });
|
||||
let mut layout = Cow::Borrowed(self.layout);
|
||||
if let Some(copies) = self.copies {
|
||||
if self.children_per_parent == 2 {
|
||||
return copies.two_child_runs(stamps);
|
||||
}
|
||||
self.layout = copies.layout(self.layout)?;
|
||||
self.starts = copies.boundaries(self.layout, self.draws_per_parent)?;
|
||||
layout = copies.layout(self.layout)?;
|
||||
self.starts = copies.boundaries(&layout, self.draws_per_parent)?;
|
||||
}
|
||||
let mut groups = vec![DrawRun::whole(&[]); self.layout.len()];
|
||||
for ((_, rank), bounds) in self.layout.iter().zip(self.starts.windows(2)) {
|
||||
let mut groups = vec![DrawRun::whole(&[]); layout.len()];
|
||||
for ((_, rank), bounds) in layout.iter().zip(self.starts.windows(2)) {
|
||||
*groups.get_mut(*rank)? = DrawRun::between(stamps, bounds[0], bounds[1])?;
|
||||
}
|
||||
Some(groups)
|
||||
|
||||
@@ -163,12 +163,70 @@ fn full_pairs_defer_individual_copies_after_two_batches() {
|
||||
for (group, count) in [(50, 91), (54, 96), (58, 93), (62, 95)] {
|
||||
crossing[group] = count;
|
||||
}
|
||||
let second_pair_markers = [
|
||||
(279537, 138231, true),
|
||||
(279583, 94160, true),
|
||||
(87397, 15706, true),
|
||||
(90047, 978, true),
|
||||
(92773, 303597, false),
|
||||
(95423, 213678, false),
|
||||
(95461, 94418, true),
|
||||
];
|
||||
let mut second_pair = [32; 64];
|
||||
second_pair[50] = 75;
|
||||
second_pair[51] = 107;
|
||||
let penultimate_prefix_markers = [
|
||||
(327930, 327964, false),
|
||||
(327931, 328139, false),
|
||||
(327934, 327958, false),
|
||||
(327935, 328054, false),
|
||||
(327967, 263018, true),
|
||||
(327973, 280124, true),
|
||||
(329279, 332822, false),
|
||||
(329317, 331280, false),
|
||||
(330623, 331042, false),
|
||||
(330661, 311138, true),
|
||||
];
|
||||
let mut penultimate_prefix = [32; 64];
|
||||
penultimate_prefix[60] = 90;
|
||||
let combined_prefixes_markers = [
|
||||
(279537, 144436, true),
|
||||
(279583, 328198, false),
|
||||
(327930, 92890, true),
|
||||
(327931, 93598, true),
|
||||
(327934, 92755, true),
|
||||
(327935, 93864, true),
|
||||
(327967, 262553, true),
|
||||
(87397, 7121, true),
|
||||
(90047, 33270, true),
|
||||
(92773, 173881, false),
|
||||
];
|
||||
let mut combined_prefixes = [32; 64];
|
||||
combined_prefixes[50] = 75;
|
||||
combined_prefixes[51] = 107;
|
||||
combined_prefixes[60] = 90;
|
||||
let fourth_pair_markers = [
|
||||
(301041, 217929, true),
|
||||
(301087, 180528, true),
|
||||
(173413, 18515, true),
|
||||
(176063, 11958, true),
|
||||
(178789, 262684, false),
|
||||
(181439, 265280, false),
|
||||
(181477, 179464, true),
|
||||
];
|
||||
let mut fourth_pair = [32; 64];
|
||||
fourth_pair[54] = 75;
|
||||
fourth_pair[55] = 107;
|
||||
for (group_counts, seed, axes, markers) in [
|
||||
(pair_copy_counts(58), 653180, 1, pair58.as_slice()),
|
||||
(pair_copy_counts(60), 1763066, 1, pair60.as_slice()),
|
||||
(pair_copy_counts(62), 653180, 1, pair62.as_slice()),
|
||||
([96; 64], 206407, 3, all_pairs.as_slice()),
|
||||
(crossing, 214261, 1, preceding_subtrees.as_slice()),
|
||||
(fourth_pair, 222453, 1, fourth_pair_markers.as_slice()),
|
||||
(second_pair, 220419, 1, second_pair_markers.as_slice()),
|
||||
(penultimate_prefix, 220472, 1, penultimate_prefix_markers.as_slice()),
|
||||
(combined_prefixes, 220525, 1, combined_prefixes_markers.as_slice()),
|
||||
] {
|
||||
let variables = BTreeMap::from([("$tiling".into(), Value::Int(axes))]);
|
||||
let inputs = [None, Some(stamp_field(&group_counts, markers))];
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{
|
||||
region::Region,
|
||||
};
|
||||
use crate::CookContext;
|
||||
use std::ops::Range;
|
||||
use std::{borrow::Cow, ops::Range};
|
||||
|
||||
mod paired_batches;
|
||||
mod sparse_quadrants;
|
||||
@@ -98,20 +98,75 @@ impl TileCopies {
|
||||
ranges.into_iter().map(|r| DrawRun::between(stamps, self.draw_position(r.start), self.draw_position(r.end))).collect()
|
||||
}
|
||||
|
||||
pub(super) fn layout(&self, ordinary: &'static [(usize, usize)]) -> Option<&'static [(usize, usize)]> {
|
||||
fn group_copies(&self, groups: Range<usize>) -> Option<u32> {
|
||||
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)?)
|
||||
}
|
||||
|
||||
fn horizontal_layout(&self, ordinary: &'static [(usize, usize)], pair: Option<(usize, usize)>) -> Option<Cow<'static, [(usize, usize)]>> {
|
||||
let prefix = self.group_copies(60..61)?;
|
||||
let full_prefix = prefix >= COPIES_PER_BATCH;
|
||||
let fallback = || pair.is_none().then_some(Cow::Borrowed(ordinary));
|
||||
if !full_prefix && pair.is_none() {
|
||||
return fallback();
|
||||
}
|
||||
if let Some((group, head)) = pair {
|
||||
// The paired prefix defers everything after its second batch. Filling another
|
||||
// batch in the receiving subtree changes the order of the remaining draws.
|
||||
let deferred = self.group_copies(group..group + 2)?.checked_sub(2 * COPIES_PER_BATCH)?;
|
||||
if self.group_copies(head..head + 1)?.checked_add(deferred)? >= COPIES_PER_BATCH {
|
||||
return fallback();
|
||||
}
|
||||
}
|
||||
if full_prefix && self.group_copies(16..17)?.checked_add(prefix - COPIES_PER_BATCH)? >= COPIES_PER_BATCH {
|
||||
// The later copy from group 60 can then move across another partially filled batch.
|
||||
return fallback();
|
||||
}
|
||||
|
||||
let mut layout = ordinary.to_vec();
|
||||
for (end, _) in &mut layout {
|
||||
if let Some((group, head)) = pair {
|
||||
let start = head * DEPTH_THREE_PARENTS;
|
||||
if *end == start + DEPTH_FOUR_PARENTS || *end == start + 3 * DEPTH_FOUR_PARENTS {
|
||||
*end += DEPTH_THREE_PARENTS;
|
||||
} else if ((group + 1) * DEPTH_THREE_PARENTS..(group + 2) * DEPTH_THREE_PARENTS).contains(end) {
|
||||
// Repeated endpoints split the final subtree at the physical copy count.
|
||||
*end = (group + 2) * DEPTH_THREE_PARENTS;
|
||||
}
|
||||
}
|
||||
let last = 61 * DEPTH_THREE_PARENTS;
|
||||
if full_prefix && last < *end && *end <= last + 3 * DEPTH_FOUR_PARENTS {
|
||||
*end = (*end - DEPTH_FOUR_PARENTS).max(last);
|
||||
}
|
||||
}
|
||||
Some(Cow::Owned(layout))
|
||||
}
|
||||
|
||||
pub(super) fn layout(&self, ordinary: &'static [(usize, usize)]) -> Option<Cow<'static, [(usize, usize)]>> {
|
||||
if self.full_pairs == u8::MAX && self.axes[0] {
|
||||
return Some(paired_batches::ALL_FULL_PAIRS);
|
||||
return Some(Cow::Borrowed(paired_batches::ALL_FULL_PAIRS));
|
||||
}
|
||||
// The first pair also submits its parts separately in the ordinary layout.
|
||||
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),
|
||||
0b10 => return self.horizontal_layout(ordinary, Some((50, 16))),
|
||||
0b1000 => return self.horizontal_layout(ordinary, Some((54, 32))),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if later == 0 {
|
||||
return Some(ordinary);
|
||||
return Some(Cow::Borrowed(ordinary));
|
||||
}
|
||||
if self.axes != [true, false] || !later.is_power_of_two() {
|
||||
return None;
|
||||
}
|
||||
let end = FIRST_PAIR_END + later.trailing_zeros() as usize * PAIRED_SUBTREE_PARENTS;
|
||||
Some(PairedBatches::ending_at(end)?.layout())
|
||||
Some(Cow::Borrowed(PairedBatches::ending_at(end)?.layout()))
|
||||
}
|
||||
|
||||
fn split_fits_subtree(&self, parents: usize, cut: u32) -> bool {
|
||||
|
||||
@@ -425,6 +425,26 @@ Repeat the [111 whole-root settings and 28 saved selections](#individual-tile-co
|
||||
|
||||
Dirt 5 retains 2,662,656/2,662,656 exact pixels on one processor, 2,661,672/2,662,656 on eight and 354,560/354,560 across the 22 reopened settings. The median process CPU time for the 128 × 32 seed-398611, 64² seed-41 and 128 × 512 seed-398816 F32 generator renders was 9.594 seconds before and 9.633 seconds after the fix, using four interleaved runs per version on one processor. All 436 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly.
|
||||
|
||||
### Deferred copies in horizontal Dirt Gradient batches
|
||||
|
||||
Across 111 distinct whole-root settings, 91 match every pixel on one reference processor, up from 81. Ten changed outputs account for all 83 newly matching pixels. On eight processors 43 settings match every pixel, down from 45, and seven fewer pixels match. All 28 MaterialCraft saves reopened in both applications. Each application reproduced its original 430,336 pixels. The cross-application difference fell from 49 pixels to 16. Maximum errors are in storage codes for integers and in absolute units for floats.
|
||||
|
||||
| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max |
|
||||
|---|---:|---:|---:|---:|
|
||||
| Whole root, one processor | 600,320/600,320 · 0 | 846,442/846,592 · 2 | 600,302/600,320 · 0.00048828125 | 815,968/816,128 · 1.96099281e−5 |
|
||||
| Whole root, eight processors | 600,320/600,320 · 0 | 846,290/846,592 · 2 | 600,298/600,320 · 0.00048828125 | 815,805/816,128 · 2.03251839e−5 |
|
||||
| Reopened, one processor | 36,864/36,864 · 0 | 80,887/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,802/279,808 · 1.80006027e−5 |
|
||||
|
||||
Repeat the original and changed whole-graph settings with U8, U16, F16 and F32 output. For the ordering probe, use the third generator’s complete depth-nine quadrant tree with original additive square stamps at depths seven through nine and horizontal tiling. Each of its 64 depth-three groups contains 5,376 logical draws before tiling. One physical batch holds 5,460 copies. At 64² and seed 42, group 60 fills one batch and its six remaining copies draw later. At 128 × 256 and seed 398693, groups 50–51 fill two batches and defer 14 copies. The original signed probes verify all 32,766 adjacent depth-seven parent comparisons in each setting. Overlaps in both polarities place the first and last deferred copies and verify the order within each tail. Replaying the observed order matches all 36,864 raw F32 pixels. Groups 54–55 produce the corresponding displacement into group 32 at 128 × 256, seed 142631, and 256 × 128, seed 188843. These two generator images match 65,536/65,536. [Whole-graph settings](#horizontal-pattern-batches-ending-in-the-preceding-subtree)
|
||||
|
||||
To reproduce the four regressions, start with 32 additional horizontal seam copies per group. Set groups 50–51 to 75 and 107, set group 60 to 90, combine both changes, or set groups 54–55 to 75 and 107. Use seeds 220419, 220472, 220525 and 222453 respectively. The pairs of logical draw indices and quota distribution are in the regression. Give one square weight −1 and the other 2⁻²⁵ over a background of one, swap the weights and read the same pixels in F32. Both directions agree on all 76 signed comparisons. The compiled renderer matches 131,072/131,072 · 0 over the eight complete images. [Regression fixture](../crates/nodes/src/pattern/tests/paired_batches.rs)
|
||||
|
||||
For the receiving-subtree boundary, use 128 × 64 weighted square fields. Put 78 extra seam copies in group 50 or 54 and 90 + E in its neighbor, with E in 0, 1, 14, 31 and 63. In the receiving group, 16 or 32 respectively, set the extra count to 84 − E plus an offset of −3, −1, 0, 1 or 4. Split each quota between four depth-four subtrees as in the regression. Keep all other group counts at 32. Name the case with the group, E and offset + 3 as in `p50e14d2`. Seed PCG64 with 193887 plus the sum of the one-based character positions times their ASCII values. Draw a uniform number per logical stamp in depth-first order, divide by 4, 1.8 or 1 at depth seven, eight or nine, and wrap the lowest scores within each subtree. Use the four-weight input construction with paint seed 222419 + 19j. Number j from zero in the order above, starting the group-54 sweep at 35. Below capacity the predicted two-batch order matches all 163,840 F32 pixels. At capacity it matches 73,526/81,920 · 2.38418579e−6. Above capacity it matches 146,845/163,840 · 1.90734863e−6. The renderer uses this continuation only while the receiving group has room. A subsequent full batch can split later subtrees again. [Weighted field construction](#the-first-subtree-pair-in-the-final-dirt-gradient-quadrant)
|
||||
|
||||
The compiled renderer matches all 151,552 pixels in the eight horizontal F32 isolates, up from 126,056. Untiled and both-axis controls each match 45,056/45,056. Across the 86 earlier weighted component settings the compiled result changed from 1,033,611/1,056,768 · 3.4570694e−6 to 1,045,203/1,056,768 · 2.86102295e−6. All twelve previously exact settings from the six boundary distributions match 147,456/147,456. Nine additional saved signed and weighted controls reproduced their original output in both applications and match 104,581/106,496 · 2.38418579e−6 across applications. For the twelve release cooks of the six boundary distributions, the median elapsed time was 9.566 seconds before and 11.242 after. The measurements include contention from concurrent comparisons.
|
||||
|
||||
Thirteen remaining seed-and-size combinations from the preceding build and two independent seeds isolate the discrepancy to the third generator. The first two generators match 261,120/261,120 · 0 in stored U16. The third matches 504,154/504,320 · 1 in stored U16 and 260,217/504,320 · 1.1920929e−7 in direct F32. At 512² and seed 398898, the whole U16, F16 and F32 outputs still differ at 124, 14 and 132 pixels, respectively. Three fresh one-processor captures of eight direct F32 settings, with size and seed 512 × 512 at 398898, 128 × 256 at 142631, 128 × 256 at 398693, 256 × 128 at 188843, 128 × 128 at 42, 64 × 128 at 142326, 64 × 64 at 42 and 32 × 16 at 188233, reproduce 1,166,691/1,168,896 · 2.98023224e−8 relative to their first captures. The middle repeat differs at 2,013 pixels for seed 142631 and 192 at 64² and seed 42. Dirt 5 retains its previous 95-setting result, 2,662,656/2,662,656 on one processor and 2,661,672/2,662,656 on eight. All 436 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed.
|
||||
|
||||
## 2026-11-21 root comparisons
|
||||
|
||||
### Connected quadrant depth and amplified spot patterns
|
||||
|
||||
@@ -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 · 2,862,949/2,863,360 pixels on one processor and 2,862,720/2,863,360 on eight across 111 settings](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 · 2,863,032/2,863,360 pixels on one processor and 2,862,713/2,863,360 on eight across 111 settings](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) |
|
||||
|
||||
Reference in new issue
Block a user