From 3d3aec17554224674765e4db1dfe22288be94f7a Mon Sep 17 00:00:00 2001 From: chasse20 Date: Thu, 26 Nov 2026 09:18:21 -0500 Subject: [PATCH] Count reused off-sample draws across terminal sibling groups --- crates/nodes/src/pattern/evaluation.rs | 16 ++++++----- crates/nodes/src/pattern/tests.rs | 36 +++++++++++++++++++++++++ docs/parity-fixes.md | 37 ++++++++++++++++++++++++++ docs/sbs-root-nodes.md | 6 +++-- 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/crates/nodes/src/pattern/evaluation.rs b/crates/nodes/src/pattern/evaluation.rs index bb8ec2b4..19e8b815 100644 --- a/crates/nodes/src/pattern/evaluation.rs +++ b/crates/nodes/src/pattern/evaluation.rs @@ -44,7 +44,6 @@ fn reusable_leaf(node: &PatternNode, programs: &PropertyPrograms, assigned: &BTr struct TerminalSiblings { stack: usize, discarded: bool, - reused: bool, } fn quadrant_mode(kind: PatternNodeKind, name: &str) -> bool { @@ -278,6 +277,7 @@ fn evaluate(context: &CookContext, base_level_only: &[bool], visit_limit: usize, let mut max_depth = 0; let mut state = EvaluationState::default(); let mut terminal_siblings: Option = None; + let mut reused_terminal_misses = 0_usize; let mut remaining = visit_limit; let mut discard_allowance = visit_limit; let mut full_evaluations = visit_limit.saturating_mul(5); @@ -518,7 +518,7 @@ fn evaluate(context: &CookContext, base_level_only: &[bool], visit_limit: usize, // properties and failed the sample-grid test in the original draw order. if let Some(siblings) = &mut terminal_siblings { siblings.discarded = true; - siblings.reused |= reused; + reused_terminal_misses = reused_terminal_misses.saturating_add(usize::from(reused)); remaining += 1; } else { discarded_draw = true; @@ -529,7 +529,7 @@ fn evaluate(context: &CookContext, base_level_only: &[bool], visit_limit: usize, } if quadrant_children == QuadrantChildren::AllTerminal { - terminal_siblings = Some(TerminalSiblings { stack: pending.len(), discarded: false, reused: false }); + terminal_siblings = Some(TerminalSiblings { stack: pending.len(), discarded: false }); } if quadrant_children != QuadrantChildren::None { let mut child_random = visit.seed; @@ -612,11 +612,13 @@ fn evaluate(context: &CookContext, base_level_only: &[bool], visit_limit: usize, && terminal_siblings.as_ref().is_some_and(|siblings| pending.len() == siblings.stack) && let Some(siblings) = terminal_siblings.take() && siblings.discarded - && !siblings.reused { - // A parent covers its terminal misses when a repeated property evaluation - // was avoided. Otherwise charge the first discard once all siblings finish. - if discard_allowance > 0 { + // Each skipped property evaluation pays for one group's first discarded draw. + // Sibling groups can reuse different numbers of stamps. Parents and visible + // stamps still pay for their own visits, and full evaluations stay bounded. + if reused_terminal_misses > 0 { + reused_terminal_misses -= 1; + } else if discard_allowance > 0 { discard_allowance -= 1; } else { remaining = remaining.checked_sub(1).ok_or("pattern graph exceeded its execution budget")?; diff --git a/crates/nodes/src/pattern/tests.rs b/crates/nodes/src/pattern/tests.rs index 350031fc..36c2fa48 100644 --- a/crates/nodes/src/pattern/tests.rs +++ b/crates/nodes/src/pattern/tests.rs @@ -1890,6 +1890,42 @@ fn terminal_quadrants_charge_the_first_discard_of_each_sibling_group() { assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); } +#[test] +fn repeated_terminal_misses_cover_uncached_misses_in_the_next_branch() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + let pair = graph.add(PatternNodeKind::Quadrant).unwrap(); + let first = graph.add(PatternNodeKind::Quadrant).unwrap(); + let second = graph.add(PatternNodeKind::Quadrant).unwrap(); + let cached = graph.add(PatternNodeKind::Quadrant).unwrap(); + let uncached = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(marker), Some(pair)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(34)); + square(&mut graph, 1); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.375)); + graph.nodes[2].children = vec![Some(first), Some(second), None, None]; + graph.nodes[3].children.fill(Some(cached)); + graph.nodes[4].children.fill(Some(uncached)); + for node in &mut graph.nodes[3..] { + node.parameters.insert("patterntype".into(), Value::Int(2)); + node.parameters.insert("patternsize".into(), Value::Float2([0.015625; 2])); + } + // Both sets of leaves fall between sample centers. Only the first set can reuse its properties. + for node in &mut graph.nodes[5..] { + node.parameters.insert("frameoffset".into(), Value::Float2([0.0625; 2])); + } + let mut tint = FunctionGraph::default(); + let gain = tint.add_constant(Value::Float(0.5)); + tint.output = Some(tint.add("rand", &[gain], None)); + graph.nodes[5].parameters.insert("randominherited".into(), Value::Bool(false)); + graph.nodes[5].parameters.insert("opacity".into(), Value::Function(Box::new(tint))); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), &[0.375; 16]); + + // The cached leaf still pays for every retained draw when moved onto the samples. + graph.nodes[5].parameters.insert("frameoffset".into(), Value::Float2([0.0; 2])); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + #[test] fn repeated_terminal_properties_leave_room_for_their_visible_siblings() { let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index fa2eeb53..f335662f 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -59,6 +59,43 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas ## 2026-11-26 root comparisons +### Reused properties across adjacent groups of terminal quadrants + +Directional Noise 3 has produced images for 15 of its first 19 whole settings, up from seven. The eight additional settings below include two default seeds, two changed square sizes and one changed rectangle. The preceding release still exhausted the execution limit at 32², seed 113. On the current release the 256² default and the changed 128² graph at seed zero still exceed it. The 64 × 32 scale-two and 32² scale-three settings retain their earlier failures. The corresponding 32², seed 113 setting in Directional Noise 3 v2 was also checked on the current release and still exceeds the limit. [Initial nineteen settings](#discarding-pattern-stamps-that-miss-every-output-sample) + +For the 128² renders, leave all parameters at their defaults. For the 32² and 64² changed renders, set scale 2, disorder .37, angle .125 and angle random .2. For the 64 × 32 F16 case use scale 1, non-square expansion on, disorder zero and both angles zero. Leave every other control at its default. Read the grayscale output at the indicated precision. In the last column save normally in MaterialCraft and reopen in each application. + +| Size and seed | Format | Original, one processor · max | Original, eight processors · max | Ordinary save, one processor · max | +|---|---|---:|---:|---:| +| 128², 0 | U16 | 16,342/16,384 · 2 | 16,339/16,384 · 2 | 16,342/16,384 · 2 | +| 128², 42 | U16 | 16,346/16,384 · 2 | 16,342/16,384 · 2 | — | +| 32², 113 | F32 | 1,014/1,024 · 2.50339508e−05 | 1,023/1,024 · 2.53617764e−05 | 1,014/1,024 · 2.53617764e−05 | +| 64², 42 | U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64², 42 | U16 | 4,071/4,096 · 2 | 4,087/4,096 · 2 | — | +| 64², 42 | F16 | 4,095/4,096 · 0.000244140625 | 4,096/4,096 · 0 | — | +| 64², 42 | F32 | 4,073/4,096 · 2.7358532e−05 | 4,088/4,096 · 2.62260437e−05 | — | +| 64 × 32, 103861 | F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | — | + +The eight recovered originals match 52,085/52,224 pixels on one processor and 52,119/52,224 on eight. The three ordinary saves match 21,452/21,504 on one. Each saved MaterialCraft buffer is bit-identical to its original. At 32², the original and reopened reference captures themselves agree on 1,022/1,024, with maximum error 2.53617764e−05. + +The deepest pattern at 32² traverses four depth-ten trees, totaling 5,592,404 quadrant visits. Each depth-nine parent has four terminal draws. A replay of the four incoming seeds under the property cache found 807,299 hits, concentrated in 342,193 of 1,048,576 terminal sibling groups. The previous accounting credited only the first reused miss in each group. Even if every draw missed, it required at least 2,104,483 charges against 2,097,152 available. The evaluator now counts each cached terminal draw that misses every sample once. It can spend that saving on the first discard of a later sibling group. Parents and visible draws still pay separately. The evaluator allows at most 5,242,880 full property evaluations and 1,048,576 retained stamps. Raster work is capped at 256,000,000 candidate pixels. [Quadrant evaluator](../crates/nodes/src/pattern/evaluation.rs) + +For an independent regression, connect the initial branch of an Iterate to a .375 square. Repeat a second branch 34 times. Give it two children, each with four references to a 1/64-size square. On the first set of leaves, disable seed inheritance and use a random tint scaled by .5. On the second set use a constant .25 tint. The 4² Rust test previously exhausted its 64 visits. All 16 output values now equal .375. Moving the cached leaves onto samples still reaches the limit. [Regression and visible-draw control](../crates/nodes/src/pattern/tests.rs) + +For desktop readback, use a .125 background, roughness zero, opacity one and additive squares. Set both parents and both leaves to 1/64 size. Render with leaf offsets (1/16, 1/16), then (1/32, 1/32). Use 16², seed 19 and 32 × 16, seed 113, and repeat at U8, U16, F16 and F32. All 6,144 original and 6,144 ordinary-save pixels matched the one-processor reference, maximum zero, and reproduced the previous MaterialCraft buffers exactly. Moving the squares produced three distinct F32 levels at 16². All 559 node and evaluator release tests, formatting, strict workspace Clippy, layer checks and WebAssembly checks passed. + +### Complete render coverage in the second version of Directional Noise 1 + +Directional Noise 1 v2 now renders all 60 established originals and all 12 ordinary saves. Four 64 × 32 originals and their U8 save previously reached the execution budget. These buffers were measured on revision `ac8706a`. Set seed 194938, scale 3, disorder, disorder speed, disorder anisotropy and angle random .34375, disorder anisotropy angle and angle .09375, tile offset (0, .10546875) and non-square expansion on. The U8 and F16 originals each match 2,048/2,048 pixels on both processor counts, maximum zero. U16 matches 2,045/2,048 on one processor and 2,044 on eight, maximum one level. F32 matches 1,222/2,048 and 1,229/2,048, maximum errors 2.38418579e−7 and 1.78813934e−7 respectively. The U8 ordinary save matches 2,048/2,048, maximum zero. [Established settings and save procedure](#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) + +| Comparison | Exact frames | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Original, one processor | 20/60 | 137,469/137,472 · 1 | 251,336/251,648 · 1 | 90,360/90,368 · 0.00048828125 | 147,168/254,976 · 4.17232513e−07 | +| Original, eight processors | 24/60 | 137,472/137,472 · 0 | 251,387/251,648 · 1 | 90,357/90,368 · 0.00048828125 | 153,836/254,976 · 4.17232513e−07 | +| Ordinary save, one processor | 4/12 | 30,719/30,720 · 1 | 6,389/6,400 · 1 | 1,024/1,024 · 0 | 45,629/84,992 · 4.17232513e−07 | + +Across all settings, 626,333/734,464 original pixels match on one processor, 633,052/734,464 on eight and 83,761/123,136 after reopening on one. The F32 differences keep this root open. + ### Sample coverage of narrow and circular quadrant stamps Noise BNW Spots 3 v2 now renders the 128 × 512 original in U16 and F32 and the ordinary F32 save. On the preceding release and on a trial that reused writable terminal properties, these settings exceeded the execution budget. Set scale 2, disorder, disorder speed and anisotropy .53125, anisotropy angle .28125, tile offset (.1875, −.05859375), non-square expansion off and seed 411890. Leave other controls at their defaults. Compare the grayscale output at its stored precision. Save the graph in MaterialCraft and reopen it in each application for the last column. [Previous dense settings and saved cases](#recovered-settings-in-the-second-version-of-the-third-spots-graph) diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index d5b36e53..5bd769c9 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -41,6 +41,8 @@ Writable quadrant tints now match 16,896/16,896 pixels in 44 settings across fou Six upstream filters now match 27,648/27,648 original and 27,648/27,648 reopened pixels across four output formats, up from 24,192 on each side. Both directions of an image connection through a graph instance also match 4,608/4,608 F32 pixels on each side. [Published filter properties, fixed controls and raw errors](parity-fixes.md#published-filter-properties-upstream-of-a-quadrant-draw) +Directional Noise 3 now renders 15 of the first 19 whole settings. Directional Noise 1 v2 renders all 60 originals and all 12 ordinary saves. Both still have pixel differences. [Recovered Directional Noise 3 settings](parity-fixes.md#reused-properties-across-adjacent-groups-of-terminal-quadrants) · [Complete Directional Noise 1 v2 comparison](parity-fixes.md#complete-render-coverage-in-the-second-version-of-directional-noise-1) + Noise BNW Spots 3 v2 renders two more originals and one more ordinary save at 128 × 512. Noise Clouds 1 now renders all 60 originals and 15 saves, with 43, 37 and 9 complete images exact on the one-processor, eight-processor and reopened comparisons respectively. [Tall Spots 3 v2 render](parity-fixes.md#sample-coverage-of-narrow-and-circular-quadrant-stamps) · [Complete Clouds 1 comparison](parity-fixes.md#complete-rectangular-render-coverage-in-the-first-clouds-graph) Noise BNW Spots 3 now renders all 62 established settings and all 14 ordinary saves. Complete images match in 34/62 one-processor originals, 32/62 eight-processor originals and 8/14 saves. The eight previously blocked rectangular settings all render. Across four formats at 64 × 16 and 64 × 32 it matches 12,288/12,288 pixels on one processor and 12,287/12,288 on eight. One U16 pixel differs by one level. Its two previously blocked ordinary saves match 3,072/3,072 pixels. [Parameters, shared evaluator and ordinary saves](parity-fixes.md#reusing-terminal-quadrant-properties-in-dense-rectangular-renders) @@ -437,10 +439,10 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug | [noise_crystal_1.sbs/crystal_1](../assets/sbs/noise_crystal_1.sbs) | 0 | No | [Parity · 809,216/809,216 pixels across 64 distinct settings on one and eight processors](parity-fixes.md#creased-and-crystal-noise-sources-on-one-and-eight-processors) · [Archived settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) | | [noise_crystal_2.sbs/crystal_2](../assets/sbs/noise_crystal_2.sbs) | 0 | No | [Parity · 809,216/809,216 pixels across 64 distinct settings on one and eight processors](parity-fixes.md#creased-and-crystal-noise-sources-on-one-and-eight-processors) · [Archived settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | | [noise_directional_noise_1.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1.sbs) | 0 | Yes | [In progress · 734,118/734,464 whole pixels across 60 settings on one processor, 734,140 on eight](parity-fixes.md#final-three-quadrant-levels-in-directional-noise-1) · [Seven interior routes and their ordinary saves](parity-fixes.md#interior-routes-between-terminal-quadrants) · [Outer routes and five ordinary reopens](parity-fixes.md#outer-routes-into-the-final-three-active-quadrant-levels) · [Partly wrapped copies and seven reopens](parity-fixes.md#partly-wrapped-copies-in-directional-noise-1) · [Copy counts across sampling windows](parity-fixes.md#terminal-quadrant-order-across-sampling-windows) · [Earlier directional measurements](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | -| [noise_directional_noise_1_v2.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1_v2.sbs) | 0 | No | [In progress · 56/60 whole settings rendered, 618,970/726,272 pixels on one processor, 625,683 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Earlier comparison · 133,251/142,592 pixels in 18 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | +| [noise_directional_noise_1_v2.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1_v2.sbs) | 0 | No | [In progress · 60/60 originals and 12/12 saves render, 626,333/734,464 original pixels on one processor and 633,052 on eight](parity-fixes.md#complete-render-coverage-in-the-second-version-of-directional-noise-1) · [Earlier comparison · 56/60 whole settings rendered, 618,970/726,272 pixels on one processor, 625,683 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Earlier comparison · 133,251/142,592 pixels in 18 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | | [noise_directional_noise_2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2.sbs) | 0 | Yes | [In progress · 103,497/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | | [noise_directional_noise_2_v2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2_v2.sbs) | 0 | No | [In progress · 105,116/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | -| [noise_directional_noise_3.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3.sbs) | 0 | Yes | [In progress · 7/19 whole renders completed, 7,168/7,424 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | +| [noise_directional_noise_3.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3.sbs) | 0 | Yes | [In progress · 15/19 original settings have rendered, eight additional settings and three ordinary saves compared](parity-fixes.md#reused-properties-across-adjacent-groups-of-terminal-quadrants) · [Earlier comparison · 7/19 whole renders completed, 7,168/7,424 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | | [noise_directional_noise_3_v2.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3_v2.sbs) | 0 | No | [In progress · 2/19 whole renders completed, 1,280/1,280 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | | [noise_directional_noise_4.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4.sbs) | 0 | Yes | [In progress · 134,015/144,640 pixels in 19 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) | | [noise_directional_noise_4_v2.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4_v2.sbs) | 0 | No | [In progress · 134,664/144,640 pixels in 19 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) |