From 77a2d06e997bb77e869d89a94aedb138fb672de9 Mon Sep 17 00:00:00 2001 From: chasse20 Date: Sun, 22 Nov 2026 23:30:04 -0500 Subject: [PATCH] Contract packed product lanes in pixel interpolation --- crates/nodes/src/function/returned_product.rs | 68 +++++++++++++------ crates/nodes/src/function/tests.rs | 39 +++++++++++ docs/parity-fixes.md | 28 ++++++++ docs/sbs-root-nodes.md | 6 +- 4 files changed, 120 insertions(+), 21 deletions(-) diff --git a/crates/nodes/src/function/returned_product.rs b/crates/nodes/src/function/returned_product.rs index 0c72d97c..0dcc2807 100644 --- a/crates/nodes/src/function/returned_product.rs +++ b/crates/nodes/src/function/returned_product.rs @@ -68,15 +68,27 @@ pub(super) struct Term { pub(super) type Sum = [Option; 4]; pub(super) fn evaluate_sum(terms: &Sum, arguments: &[Value], subtract: bool, state: &EvaluationState) -> Result { - let [left, right] = arguments else { return Err("missing sum operands".into()) }; + let (left, right, subtract, weight) = match arguments { + [left, right] => (left, right, subtract, None), + // Interpolation first forms the difference between its second and first endpoints. + [first, second, Value::Float(weight)] => (second, first, true, Some(*weight)), + _ => return Err("invalid product sum operands".into()), + }; let width = value_type::dimensions(left); if width != value_type::dimensions(right) { return Err("float operands must have the same dimensions".into()); } - let left = value_type::floats(left)?.map(flush_subnormal); - let right = value_type::floats(right)?.map(flush_subnormal); + let left = value_type::floats(left)?; + let right = value_type::floats(right)?; let mut result = [0.0; 4]; for (((output, term), left), right) in result.iter_mut().zip(terms).zip(left).zip(right).take(width) { + if let Some(weight) = weight + && term.is_none() + { + *output = (left - right).mul_add(weight, right); + continue; + } + let (left, right) = (flush_subnormal(left), flush_subnormal(right)); let sum = if let Some(term) = term { let [a, b] = term.source.factors(state)?.map(flush_subnormal); let a = if subtract && term.on_right { -a } else { a }; @@ -96,7 +108,8 @@ pub(super) fn evaluate_sum(terms: &Sum, arguments: &[Value], subtract: bool, sta } else { left + right }; - *output = flush_subnormal(sum); + let sum = flush_subnormal(sum); + *output = weight.map_or(sum, |weight| flush_subnormal(sum.mul_add(weight, right))); } value_type::intermediate_float_value(result.get(..width).ok_or("invalid sum dimensions")?) } @@ -104,6 +117,12 @@ pub(super) fn evaluate_sum(terms: &Sum, arguments: &[Value], subtract: bool, sta pub(super) type Lanes = [Option; 4]; type Origins = [Option; 4]; +#[derive(Default)] +struct Reads { + total: usize, + sole_product_in_sum: usize, +} + pub(super) fn float_width(code: u32) -> usize { match code { 256 => 1, @@ -163,7 +182,7 @@ pub(super) fn identify(program: &mut Program, mut returned: BTreeMap = program.instructions.iter().enumerate().filter_map(|(i, op)| (op.definition.id == "while").then_some(i)).collect(); let mut origins: Vec = Vec::with_capacity(program.instructions.len()); - let mut products: Vec<(Source, usize)> = Vec::new(); + let mut products: Vec<(Source, Reads)> = Vec::new(); let mut sums = Vec::new(); for (index, op) in program.instructions.iter().enumerate() { if let Some(lanes) = forwarded(op, &program.instructions, &origins, None) { @@ -173,19 +192,29 @@ pub(super) fn identify(program: &mut Program, mut returned: BTreeMap 0 + let lanes_of = |i: usize| origins.get(i).copied().unwrap_or([None; 4]); + let sides = match (op.definition.id, op.inputs.as_slice()) { + ("add" | "sub", &[left, right]) => Some([lanes_of(left), lanes_of(right)]), + ("lerp", &[_, second, weight]) if program.instructions.get(weight).is_some_and(|w| w.type_code == 256) => Some([lanes_of(second), [None; 4]]), + _ => None, + }; + if width > 0 && op.pixel_product_sum.is_none() - && let &[left, right] = op.inputs.as_slice() + && let Some(sides) = sides + && sides.iter().flatten().any(Option::is_some) { - let sides = [left, right].map(|i| origins.get(i).copied().unwrap_or([None; 4])); - if sides.iter().flatten().any(Option::is_some) { - sums.push((index, sides)); + for (left, right) in sides[0].iter().zip(sides[1]) { + if let Some(id) = left.xor(right) + && let Some((_, reads)) = products.get_mut(id) + { + reads.sole_product_in_sum += 1; + } } + sums.push((index, sides)); } let mut lanes = [None; 4]; @@ -193,7 +222,7 @@ pub(super) fn identify(program: &mut Program, mut returned: BTreeMap> 25) modulo 3) for the biased F32 exponent, and bits 1 through 23 for the fraction. Use seed 379131 + 41j. Run F32 at all sizes, add U8, U16 and F16 at 64 × 32, then repeat its F32 setting. + +Use first endpoint (B,R,A,G), second endpoint (R×A,G×A,B×A,.625) and weight G. Test this graph, reversed endpoints, and identical packed endpoints. Also test returning the independently rounded blue product alongside the mixed RGB, adding the second endpoint to the mix, selecting lanes YWZX from the second endpoint, dividing RGB by A, using RGBA×A directly, and packing (R×A,G×A,R×B,B×G). At (11,0), the second-endpoint case gives RGB bits `bd551682 bef1e18c bec17c27`. Returning the blue product changes just the mixed blue to `bec17c28`. The separate product reads `3f1cb4a3`. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Nine original graphs, previous cook | 18,432/18,432 · 0 | 18,428/18,432 · 1 | 18,431/18,432 · 3.81469727e-06 | 64,959/92,160 · 9.53674316e-07 | +| Same nine graphs, corrected cook | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 92,160/92,160 · 0 | +| Five MaterialCraft saves, opened in both applications | 10,240/10,240 · 0 | 10,240/10,240 · 0 | 10,240/10,240 · 0 | 51,200/51,200 · 0 | + +The five saves cover the ordinary and reversed endpoints, the independently returned blue lane, the subsequent add and the quotient. Every saved reference buffer reproduced its original. Two additional probes deliberately connected a float4 to the weight port. The desktop reported that port as scalar and the incoming connection as float4. At 64 × 32 in F32 both reference outputs equaled the first endpoint, 4,096/4,096 pixels. MaterialCraft evaluated component weights at those connections. Across the 14 format and size comparisons those two graphs matched 214/32,768 pixels, with maxima of 255 U8 levels, 65,535 U16 levels, 10.1123047 F16 and 10.1180855 F32. These mismatched port types remain a separate difference. + +Repeat the [22 earlier plane-light settings](#nadir-patch-after-reopening-its-linked-shape-package). For four additional geometries use (output width, output height, input width, input height) = (32,16,32,16), (16,32,16,32), (64,32,32,16) and (32,64,64,32). For geometry j use seed 380233 + 47j. Number the three input identifiers m alphabetically and components c from zero. Store each channel as ((41x + 73y + 11xy + 157m + 61c + 3cx + seed) modulo 1021)/1024 in F32. Use channel zero for the pattern image. Keep the first geometry at defaults. For the others use position modes 2, 1, 0 and patterns 4, 1, 3 respectively. Set world position (−.875,.34375,1.125), UV position (.328125,.203125), scale .6875, size (.75,1.25), rotation (.046875,−.09375,.171875), color mode 2 and exposure 1.3125. Enable the background input. Enable ground clipping and the grid on geometry two only. Use F32 on all four geometries and all four formats on geometries zero and two. Reopen a normal MaterialCraft SBS save at these ten settings and the four earlier plane-space settings. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| 22 earlier whole-root settings | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 175,360/175,360 · 0 | +| 10 independent rectangular settings | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 5,120/5,120 · 0 | +| 14 whole-root reopens in both applications | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 33,792/33,792 · 0 | + +Panorama Plane Light matched **212,736/212,736** original pixels across 32 settings and **41,472/41,472** reopened pixels. Both applications reproduced their original buffers after reopening. The packed-lane regression failed on the previous build and passed with the fix. All 394 node release tests passed, as did formatting, strict workspace Clippy, dependency layers and WebAssembly. + +The 49 earlier graphs for returned vectors, shared product pairs and scalar quotients retained 1,288,192/1,288,192 exact pixels across 307 renders. [Returned-vector probes](#pixel-products-carried-through-vector-lanes-and-calls) · [Quotient and interpolation probes](#pixel-quotients-and-volume-mask-interpolation) + ### Reciprocal division through pixel function calls The two eighth specular passes divide a lighting term by the Z component of a normalized direction. Returning the environment lookup alone matched the 128-pixel scanline through (62,57) of the second pass. Returning the scalar lighting quotient exposed a rounding difference. Both operands matched at that pixel. In a separate original graph, the pixel expression `A / (1 / B)` reproduced A × B throughout the signed field. At (1,0) the inputs have F32 words `40763400` and `3f68c2ba`. A separate read of the inner reciprocal returns `3f8cc7a2`. The outer quotient returns `405fda66`. Supplying the one from a sampled channel returns `405fda65`. The latter control matched before the change. diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 61e3793c..6be025c8 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -35,7 +35,9 @@ A graph may accept input pins and still be a root under the dependency criterion Statuses: **Not checked**, **In progress**, **Parity** (exact pixels or typed values for the linked measured cases), or **Too hard** (reason recorded). Function calls do not count as regular graph dependencies. -The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **475 Parity**, **71 In progress** and **0 Too hard**. The November 17–22 comparisons include raw counts, output formats and remaining differences. [November 17 measurements](parity-fixes.md#2026-11-17-root-comparisons) · [November 18 measurements](parity-fixes.md#2026-11-18-root-comparisons) · [November 19 measurements](parity-fixes.md#2026-11-19-root-comparisons) · [November 20 measurements](parity-fixes.md#2026-11-20-root-comparisons) · [November 21 measurements](parity-fixes.md#2026-11-21-root-comparisons) · [November 22 measurements](parity-fixes.md#2026-11-22-root-comparisons) +The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **476 Parity**, **70 In progress** and **0 Too hard**. The November 17–22 comparisons include raw counts, output formats and remaining differences. [November 17 measurements](parity-fixes.md#2026-11-17-root-comparisons) · [November 18 measurements](parity-fixes.md#2026-11-18-root-comparisons) · [November 19 measurements](parity-fixes.md#2026-11-19-root-comparisons) · [November 20 measurements](parity-fixes.md#2026-11-20-root-comparisons) · [November 21 measurements](parity-fixes.md#2026-11-21-root-comparisons) · [November 22 measurements](parity-fixes.md#2026-11-22-root-comparisons) + +Panorama Plane Light matches 212,736/212,736 pixels across 32 original settings and 41,472/41,472 after reopening. [Interpolation probes and whole-root counts](parity-fixes.md#packed-products-in-the-second-endpoint-of-a-pixel-interpolation) In the two eighth specular passes, the corrected pixel arithmetic matched all 2,304 scanline pixels across zero through eight contributions. The changed 128² pass 396 scores 16,384/16,384 · 0 in F16 and the default 128² pass 408 scores 16,384/16,384 · 0. All 376,832 pixels in the direct and reusable function graphs match, as do all 131,072 reopened pixels. [Raw counts and procedural inputs](parity-fixes.md#reciprocal-division-through-pixel-function-calls) @@ -467,7 +469,7 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug | [panorama_position.sbs/panorama_3d_position](../assets/sbs/panorama_position.sbs) | 0 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | | [panorama_rotation.sbs/panorama_rotation](../assets/sbs/panorama_rotation.sbs) | 1 | No | [Parity · 206,336 exact pixels in 26 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | | [panorama_shape.sbs/panorama_line_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [Parity · 30 renders, all 241,152 pixels exact](parity-fixes.md#panoramic-line-light-and-horizon-across-the-seam) | -| [panorama_shape.sbs/panorama_plane_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [In progress · 199,155/199,936 pixels across 22 distinct settings](parity-fixes.md#nadir-patch-after-reopening-its-linked-shape-package) | +| [panorama_shape.sbs/panorama_plane_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [Parity · 212,736/212,736 pixels at 32 settings, 41,472/41,472 after reopening](parity-fixes.md#packed-products-in-the-second-endpoint-of-a-pixel-interpolation) · [Earlier measurements](parity-fixes.md#nadir-patch-after-reopening-its-linked-shape-package) | | [panorama_shape.sbs/panorama_shape](../assets/sbs/panorama_shape.sbs) | 1 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | | [panorama_shape.sbs/panorama_shape_2](../assets/sbs/panorama_shape.sbs) | 2 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | | [panorama_shape.sbs/panorama_sphere_light](../assets/sbs/panorama_shape.sbs) | 2 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) |