Stream repeated pattern visits and measure Cells 1

This commit is contained in:
chasse20 committed 2026-11-20 22:24:33 -05:00
1 parent b8d9c04c09
commit 043c8ea32c
4 files changed
+62 -19

No files matched your search

+22 -18
View File
@@ -44,7 +44,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
context.inputs.iter().skip(1).take(crate::MAX_IMAGE_INPUTS).enumerate().filter_map(|(i, image)| image.as_ref().map(|_| i as i32)).collect();
let mut pending = Vec::new();
if let Some(root) = graph.root {
pending.push(PatternVisit { node: root, center: [0.5; 2], extent: 1.0, depth: 0, number: 0, seed: context.seed });
pending.push((PatternVisit { node: root, center: [0.5; 2], extent: 1.0, depth: 0, number: 0, seed: context.seed }, 0_u32));
}
let mut stamps = Vec::new();
@@ -61,7 +61,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
let mut children = Vec::new();
let mut empty_switches = BTreeSet::new();
let grayscale = !context.b("color_mode");
while let Some(mut visit) = pending.pop() {
while let Some((mut visit, repeats_left)) = pending.pop() {
// Returning below the previous stack size starts the next child of the root.
if pending.len() < root_children_pending {
root_children_pending = pending.len();
@@ -73,11 +73,17 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
continue;
}
remaining = remaining.checked_sub(1).ok_or("pattern graph exceeded its execution budget")?;
if repeats_left != 0 {
// Resume the previous draw's scope before scheduling its sibling. Descendants of
// this draw run first and inherit its own number and seed.
let next = PatternVisit { number: visit.number + 1, seed: crate::random::iteration_child(visit.seed), ..visit.clone() };
pending.push((next, repeats_left - 1));
}
let &(node, literal_geometry) = nodes.get(&visit.node).ok_or("missing pattern node")?;
if node.kind == PatternNodeKind::Dot {
if let Some(Some(child)) = node.children.first() {
visit.node = *child;
pending.push(visit);
pending.push((visit, 0));
}
continue;
}
@@ -150,6 +156,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
let integer = |name: &str| field(name).and_then(Value::as_i32).unwrap_or(0);
let vector = |name: &str| field(name).and_then(Value::as_vec4).map(|value| [value[0], value[1]]).unwrap_or([0.0; 2]);
children.clear();
let mut repeated = None;
match node.kind {
PatternNodeKind::Dot => {}
PatternNodeKind::Quadrant => {
@@ -233,10 +240,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
}
}
PatternNodeKind::Iterate => {
let count = usize::try_from(integer("numberadded")).map_err(|_| "iteration count cannot be negative")?;
if count > remaining || count > 10_000 {
return Err("pattern iteration count exceeds the execution budget".into());
}
let count = u32::try_from(integer("numberadded")).map_err(|_| "iteration count cannot be negative")?;
if let Some(Some(child)) = node.children.first() {
let mut first = visit.clone();
@@ -244,18 +248,17 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
first.number = 0;
children.push(first);
}
if let Some(Some(child)) = node.children.get(1)
if let Some(repeats_left) = count.checked_sub(1)
&& let Some(Some(child)) = node.children.get(1)
&& !empty_switches.contains(child)
{
let mut seed = visit.seed;
for number in 0..count {
let mut repeated = visit.clone();
repeated.node = *child;
repeated.number = number as u32;
seed = crate::random::iteration_child(seed);
repeated.seed = seed;
children.push(repeated);
// Each connected visit costs at least one unit, even if its stamp is discarded.
// A fixed switch can discover an empty branch on its first visit and skip the rest.
if count as usize > remaining + discard_allowance && !fixed_switches.contains(child) {
return Err("pattern iteration count exceeds the execution budget".into());
}
let first = PatternVisit { node: *child, number: 0, seed: crate::random::iteration_child(visit.seed), ..visit };
repeated = Some((first, repeats_left));
}
}
}
@@ -271,7 +274,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
}
});
}
if children.len().saturating_add(pending.len()) > remaining {
if children.len() + pending.len() + usize::from(repeated.is_some()) > remaining {
return Err("pattern graph exceeded its execution budget".into());
}
@@ -279,7 +282,8 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
if grayscale && node.kind == PatternNodeKind::Quadrant && Some(node.id) == graph.root {
root_children_pending = children.len();
}
pending.extend(children.drain(..).rev());
pending.extend(repeated);
pending.extend(children.drain(..).rev().map(|visit| (visit, 0)));
}
let mut groups = [&[][..]; 5];
+23
View File
@@ -1052,6 +1052,29 @@ fn iterate_sets_number_and_switch_selects_one_child() {
assert_eq!(cook(graph).unwrap()[0].mean()[0], 0.0);
}
#[test]
fn long_pattern_iterations_charge_only_connected_visits() {
let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate);
let square = graph.add(PatternNodeKind::Quadrant).unwrap();
graph.nodes[1].parameters = BTreeMap::from([
("patterntype".into(), Value::Int(2)),
("blendingmode".into(), Value::Int(0)),
("patternsize".into(), Value::Float2([1.0; 2])),
("opacity".into(), Value::Float(1.0 / 32_768.0)),
]);
for (initial, repeated, count, expected) in [
(None, Some(square), 12_003, 12_003.0 / 32_768.0),
(Some(square), None, 16_384, 1.0 / 32_768.0),
(None, None, 16_384, 0.0),
(Some(square), None, i32::MAX, 1.0 / 32_768.0),
] {
graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(count));
graph.nodes[0].children = vec![initial, repeated];
let image = cook_at_size(graph.clone(), &BTreeMap::new(), 452933, 4).unwrap().remove(0);
assert!(image.data().iter().all(|&v| v == expected));
}
}
#[test]
fn repeated_empty_size_switches_leave_the_visit_budget_for_drawing() {
let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate);
+16
View File
@@ -816,6 +816,22 @@ At 1024×512 the first difference in the color root is the last directional blur
All 310 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. Seven alternating single-worker release runs gave median cook times of 326 to 328 ms for color at 512×128, 1,828 to 1,897 ms for color at 512², 1,839 to 1,813 ms for grayscale at 512² and 26.2 to 25.1 ms for the rectangular Tile helper.
### Streaming repeated pattern visits
A repeating pattern now advances its number and random seed one draw at a time. The initial child runs once and a disconnected repeat child takes no visits. The evaluator accounts for visited nodes and keeps its existing bounds on retained stamps, discarded stamps and raster work. A repeat count alone previously caused an error above 10,000, even with the repeat child disconnected.
For an independent reproduction, connect a single unit white square to the repeated child of an Iterate node. Use additive blending on a black grayscale background, zero roughness and an opacity multiplier of 1/32768. Render counts 0, 1, 8192, 9999, 10000, 10001, 12003 and 16384 in F32 at 8×4 with seed 452933, and U16 at 4² with seed 452950. For counts 0, 10001 and 16384 also wire only the initial child or leave both children disconnected. The 28 original renders matched 672/672 pixels, maximum zero. In F32 every repeated square added exactly 1/32768. At 12,003 repeats the stored U16 value is 24,006. At 16,384 repeats F32 stores .5 and U16 stores 32,767. Another 42 renders with independent random colors and positions retained 258,048/258,048 identical RGBA pixels, maximum zero.
| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max |
|---|---:|---:|---:|---:|---:|
| Cells 1, second package (241) | 49 | 135,940/136,448 · 255 | 197,357/243,968 · 65441 | 86,784/87,296 · 0.998535156 | 220,333/269,824 · 0.99857223 |
Both applications reproduced their original Cells 1 outputs after reopening the saved graph across all 629,760 pixels of the new 30-setting series. All 30 now cook. The four 64×16 results formerly refused by MaterialCraft match 516/1,024 U8 pixels, 511/1,024 U16, 512/1,024 F16 and 511/1,024 F32. Their respective maxima are 255, 65,441, .998535156 and .99857223. The other settings include exact 16², 256² and 128×512 outputs. The root remains open. [Earlier field comparisons](#wire-presence-inside-a-called-function)
To reproduce the new series, use dimensions 16², 64×16, 16×64, 64², 128×64, 64×128, 128², 256², 128×512 and 512×128 in order. Use defaults at j=0 and 7. The other rows use d from (default,.03125,.875,.34375,.96875,.1875,.65625,default,.53125,.09375). Use zero seed at the default rows, 42 at j=1 and 411416+61j otherwise. Render U16 and F32 throughout, adding U8 and F16 at j=0,1,3,5,7. For changed settings select scale and pattern from (8,16,5,11,27,4,19,32,7,12) and (4,3,4,9,5,7,1,4,3,10) respectively. Set disorder, disorder speed, disorder anisotropy, luminance random and angle random to d. Set angle and anisotropy angle to d−.25 and pattern scale to .375+1.25d. Use pattern size (.4375+.75d,.8125+.6875(1−d)), tile offset (d−.34375,.40625−.875d) and enable non-square expansion at odd j. The primary table counts distinct settings once.
The new regression failed on the preceding evaluator. All 311 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. In seven alternating single-worker release runs, median times for 8,192 and 10,000 small repeats changed from 36.2 to 32.3 ms and 37.3 to 47.5 ms respectively. For Cells 1 the 64² changed case took 23.1 to 23.2 ms and the 256² default took 156.1 to 169.6 ms.
### Short directional blur tap order on rectangular inputs
Fluid matches **25,969,920/25,969,920 final pixels across 121 distinct settings** through 2048 pixels per side. Both applications reopened the MaterialCraft package and reproduced every pixel of their originals over 28, 38 and 36 settings (498,688, 8,654,848 and 17,588,224 pixels). The three instrumented renders at 512×1024, 1024×512 and 1024² match 9,961,472/9,961,472 intermediate and final samples. [First differing stage and earlier settings](#fibers-1-and-fluid-through-1024-pixels-per-side)
+1 -1
View File
@@ -340,7 +340,7 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug
| [noise_bnw_spots_3.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3.sbs) | 0 | Yes | [In progress · 32² now exact, 64² precision differences](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) |
| [noise_bnw_spots_3_v2.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3_v2.sbs) | 0 | No | [In progress · 106,559/107,776 pixels, 13 execution-limit cases](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) |
| [noise_cells_1.sbs/cells_1](../assets/sbs/noise_cells_1.sbs) | 0 | Yes | [In progress · 143,321/153,856 pixels in 19 renders](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) |
| [noise_cells_1_v2.sbs/cells_1](../assets/sbs/noise_cells_1_v2.sbs) | 0 | No | [In progress · 20 renders, 158,728/173,312 exact pixels](parity-fixes.md#wire-presence-inside-a-called-function) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) |
| [noise_cells_1_v2.sbs/cells_1](../assets/sbs/noise_cells_1_v2.sbs) | 0 | No | [In progress · 640,414/737,536 pixels across 49 distinct settings](parity-fixes.md#streaming-repeated-pattern-visits) |
| [noise_cells_4.sbs/cells_4](../assets/sbs/noise_cells_4.sbs) | 1 | Yes | [In progress · 215,500/215,552 pixels in 29 renders](parity-fixes.md#paths-caustics-and-cell-fields-after-pattern-sampling) |
| [noise_cells_4_v2.sbs/cells_4](../assets/sbs/noise_cells_4_v2.sbs) | 1 | No | [In progress · 215,516/215,552 pixels in 29 renders](parity-fixes.md#paths-caustics-and-cell-fields-after-pattern-sampling) |
| [noise_clouds_1.sbs/clouds_1](../assets/sbs/noise_clouds_1.sbs) | 0 | Yes | [In progress · 143,752/149,760 pixels, two execution-limit cases](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) |