diff --git a/crates/eval/src/node_execution.rs b/crates/eval/src/node_execution.rs index 32de90e4..f90698da 100644 --- a/crates/eval/src/node_execution.rs +++ b/crates/eval/src/node_execution.rs @@ -380,7 +380,7 @@ pub(crate) fn cook_node( { *image = filtered; } - if base.format == OutputFormat::F16 && matches!(node.def.as_str(), "blend" | "fx_map" | "levels") { + if base.format == OutputFormat::F16 && matches!(node.def.as_str(), "blend" | "fx_map" | "levels" | "sharpen") { // When exactly one size is parameter-controlled, normalized inputs to these operations are stored at half precision first. // Images stamped by a pattern keep their sampling precision. for ((image, format), port) in inputs.iter_mut().zip(&input_formats).zip(input_ports) { diff --git a/crates/eval/src/tests.rs b/crates/eval/src/tests.rs index ebce1975..5339c6c5 100644 --- a/crates/eval/src/tests.rs +++ b/crates/eval/src/tests.rs @@ -1089,10 +1089,10 @@ fn unchanged_size_after_read(getter: &str, variable: &str) -> materialcraft_core } #[test] -fn half_levels_convert_the_input_before_the_curve_when_only_one_size_depends_on_a_parameter() { +fn half_levels_and_sharpen_convert_integer_inputs_when_one_size_is_parameter_controlled() { use materialcraft_core::{BaseParameter, OutputFormat, SizeMode}; - let mut graph = Graph::new("Levels sizing"); + let mut graph = Graph::new("Filter sizing"); graph.size = [4, 4]; graph.format = OutputFormat::U8; let input = graph.add_node("input_grayscale", [0.0; 2]); @@ -1106,17 +1106,35 @@ fn half_levels_convert_the_input_before_the_curve_when_only_one_size_depends_on_ curve.params.insert("in_low".into(), Value::Float4([0.21875; 4])); curve.params.insert("in_high".into(), Value::Float4([0.46875; 4])); graph.connect(input, "output", levels, "input").unwrap(); + let sharpen = graph.add_node("sharpen", [64.0, 64.0]); + let detail = graph.node_mut(sharpen).unwrap(); + detail.base.size_mode = SizeMode::RelativeToParent; + detail.base.format = OutputFormat::F16; + graph.connect(input, "output", sharpen, "input").unwrap(); let mut package = Package::new("Input precision"); package.graphs.push(graph); let mut options = Options::new(&no_res); - options.inputs.insert("source".into(), Image::filled(16, 16, Kind::Gray, [58.0 / 255.0; 4])); + let field = Image::generate(16, 16, Kind::Gray, |x, y| { + let byte: u8 = match (x, y) { + (7, 8) => 5, + (9, 8) => 78, + (8, 7) => 31, + (8, 9) => 42, + _ => 58, + }; + [f32::from(byte) / 255.0; 4] + }); + options.inputs.insert("source".into(), field); options.overrides.insert("gain".into(), Value::Float(0.375)); let cache = Mutex::new(Cache::default()); let runtime = unchanged_size_after_read("get_float1", "gain"); - for (source_dynamic, output_dynamic, expected) in - [(false, false, 0x3d0e8000), (true, false, 0x3d0e0000), (false, true, 0x3d0e0000), (true, true, 0x3d0e8000)] - { - for (id, dynamic) in [(input, source_dynamic), (levels, output_dynamic)] { + for (source_dynamic, output_dynamic, expected_levels, expected_sharpen) in [ + (false, false, 0x3d0e8000, 0x3f1e8000), + (true, false, 0x3d0e0000, 0x3f1e6000), + (false, true, 0x3d0e0000, 0x3f1e6000), + (true, true, 0x3d0e8000, 0x3f1e8000), + ] { + for (id, dynamic) in [(input, source_dynamic), (levels, output_dynamic), (sharpen, output_dynamic)] { let functions = &mut package.graphs[0].node_mut(id).unwrap().base.functions; if dynamic { functions.insert(BaseParameter::OutputSize, runtime.clone()); @@ -1126,7 +1144,9 @@ fn half_levels_convert_the_input_before_the_curve_when_only_one_size_depends_on_ } let cooked = cook(&package, 0, &options, &cache); assert_eq!(cooked.nodes[&levels].error, None); - assert_eq!(cooked.image(levels, 0).unwrap().get_gray(0, 0, false).to_bits(), expected); + assert_eq!(cooked.image(levels, 0).unwrap().get_gray(0, 0, false).to_bits(), expected_levels); + assert_eq!(cooked.nodes[&sharpen].error, None); + assert_eq!(cooked.image(sharpen, 0).unwrap().get_gray(9, 8, false).to_bits(), expected_sharpen); } } diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index 4ab64cd8..4de1af30 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -59,6 +59,34 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas ## 2026-11-27 root comparisons +### Half-precision inputs to Sharpen + +Sharpen reads equal-sized normalized integer inputs at half precision when it writes F16 and exactly one of the two sizes depends on a graph parameter. The shared evaluator now applies that conversion before the four-neighbor filter. The 55 grayscale and RGBA probes improved from **23,181/30,976** to **30,976/30,976** pixels on both reference processor counts. The maximum component error fell from .001953125 to zero. + +For a minimal case, fill a 16² U8 input with 58. Store 5 at (7,8), 78 at (9,8), 31 at (8,7) and 42 at (8,9). Use intensity 1 and an F16 destination. Have the source, the filter, both or neither read an exposed .375 and return (0,0) as the relative size offset. At (9,8) the two single-reader cases give .61865234375. The other two give .619140625. The four images now match all 1,024 pixels. For the larger series use the same procedural fields, sizes and seeds as the Levels comparison, intensity 1 for gray and .4375 for color. Include U8, U16, F16 and F32 sources, and check the F32 output control. Six configured ordinary saves reproduce all 3,584 pixels. The 130 repeated Levels controls retain 56,320/56,320. [Procedural inputs and size functions](#half-precision-inputs-to-levels) + +In Dirt 4 and Dirt 4 v2, edit the final Sharpen size property so it has the same extent as its FX-Map input. Set it first to half the parent on both axes, then to the input size with zero offset. Use a 16² parent, seed 0 and defaults. Repeat at 32 × 16, seed 93, scale 1, disorder .3125 and non-square expansion disabled. Store U8, U16, F16 and F32 on each route. Both processor counts agree at the FX-Map, Sharpen and output. The first root feeds U16 into the filter and the second feeds U8. + +| Root and size mode | F16 before · maximum | F16 after · maximum | All four formats after | +|---|---:|---:|---:| +| Dirt 4, half the parent | 79/192 · .001953125 | 192/192 · 0 | 768/768 · 0 | +| Dirt 4, relative to input | 192/192 · 0 | 192/192 · 0 | 768/768 · 0 | +| Dirt 4 v2, half the parent | 68/192 · .001953125 | 192/192 · 0 | 768/768 · 0 | +| Dirt 4 v2, relative to input | 192/192 · 0 | 192/192 · 0 | 768/768 · 0 | + +Across these 32 whole-graph settings, exact pixels rose from 2,835/3,072 to **3,072/3,072**. Opening eight configured F16 files without further edits gives another 768/768, maximum zero. + +With the original Sharpen size property, Dirt 4 enlarges the FX-Map. Use scale 1, disorder 0 and non-square expansion enabled at 64 × 32, seed 299618. For the 32 × 64 settings use seed 299697, scale 2, disorder 0.8125 and non-square expansion enabled. Each cell gives exact output pixels and maximum absolute error. + +| Original size · storage | Earlier capture, either processor count | Fresh one-processor capture | Fresh eight-processor capture | Ordinary save, either processor count | +|---|---:|---:|---:|---:| +| 64 × 32 · F16 | 2,045/2,048 · 0.0001220703125 | 2,045/2,048 · 0.0001220703125 | 2,048/2,048 · 0 | 2,044/2,048 · 0.00048828125 | +| 64 × 32 · F32 | 2,035/2,048 · 5.340576172e-05 | 2,007/2,048 · 6.103515625e-05 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · F16 | 2,040/2,048 · 0.001953125 | 2,040/2,048 · 0.001953125 | 2,040/2,048 · 0.001953125 | 2,048/2,048 · 0 | +| 32 × 64 · F32 | 2,026/2,048 · 4.583597183e-05 | 2,026/2,048 · 4.583597183e-05 | 2,048/2,048 · 0 | 2,037/2,048 · 6.103515625e-05 | + +The two fresh reference reads of the U16 FX-Map differ by one level at three of 512 input texels on the wide case and one of 512 on the tall case. MaterialCraft matches all 512 on the eight-processor read of each. In the tall F16 case the eight-processor Sharpen result matches MaterialCraft on all 2,048 pixels while the separately read reference output differs at eight. In Dirt 4 v2, both original-size 16 × 32 controls at seed 0 agree in F16 and F32 across both reference counts and their ordinary saves, 1,024/1,024 on each file route. Larger pattern executions and reference variation remain open. [Dense Dirt comparisons and work limits](#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) + ### Half-precision inputs to Levels Levels now converts a normalized integer image to half precision before applying the curve when the input and output have equal pixel dimensions and only one size is parameter-controlled. The curve runs in F32 and the output uses its declared storage precision. The untiled 16 × 32 Directional Noise 3 v2 graph at seed 731257 now matches **512/512 F16 pixels**, up from 99/512. The ordinary F16 save also improves from 99/512 to 512/512. Maximum error falls from .0009765625 to zero on one and eight reference processors. All four storage formats match **2,048/2,048** on the original and another **2,048/2,048** after opening the four normally saved files. [Graph parameters and intermediate sizes](#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 77a7572c..a695da43 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -501,8 +501,8 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug | [noise_dirt_2.sbs/dirt_2](../assets/sbs/noise_dirt_2.sbs) | 0 | Yes | [In progress · all 20 selected originals and four archived save buffers reproduce the earlier measurements](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) · [Earlier comparison · 53/60 whole tiled originals exact on one processor, 51/60 on eight](parity-fixes.md#tiled-copies-across-two-complete-quadrant-trees) · [Earlier comparison · 53/60 whole tiled settings exact on one processor, 51/60 on eight](parity-fixes.md#fixed-image-draws-in-tiled-dirt-graphs) · [All 60 originals and 12 archived ordinary saves rendered](parity-fixes.md#complete-render-coverage-for-the-two-fixed-image-dirt-graphs) · [58/60 originals and 11/12 archived ordinary saves rendered](parity-fixes.md#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2) · [Additional 32 × 16 U16 and F32 originals and saves exact](parity-fixes.md#streaming-deep-quadrants-that-draw-the-same-connected-image) · [Earlier comparison · 34/60 whole settings rendered, 512,247/512,256 pixels on one processor, 512,251 on eight](parity-fixes.md#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3) · [Earlier comparison · 11/19 whole outputs, 107,184/107,776 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) | | [noise_dirt_3.sbs/dirt_3](../assets/sbs/noise_dirt_3.sbs) | 0 | Yes | [In progress · 60/60 originals have now rendered across the recorded passes](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Earlier comparison · 775,891/777,472 exact whole pixels on one processor, 775,939 on eight, 58/60 settings rendered](parity-fixes.md#compositing-a-single-seven-level-tree-through-pattern-controls) · [Earlier comparison · 58/60 whole settings rendered, 775,891/777,472 pixels on one processor, 775,939 on eight](parity-fixes.md#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3) · [Earlier comparison · 19/19 whole outputs, 135,236/142,592 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [6/6 tiled settings render, 4 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) | | [noise_dirt_3_v2.sbs/dirt_3](../assets/sbs/noise_dirt_3_v2.sbs) | 0 | No | [In progress · 771,398/777,472 whole pixels on one processor, 771,548 on eight, 58/60 settings rendered](parity-fixes.md#whole-and-saved-outputs-for-noise-dirt-3-v2) · [Earlier comparison · 17/19 whole outputs, 136,738/141,568 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [6/6 tiled settings render, 4 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) | -| [noise_dirt_4.sbs/dirt_4](../assets/sbs/noise_dirt_4.sbs) | 0 | Yes | [In progress · 6/8 complete additional settings on one processor, 8/8 on eight and 7/8 ordinary saves](parity-fixes.md#recovered-dirt-4-and-moisture-renders-at-seed-113) · [Earlier comparison · 10/19 whole renders completed, 89,052/105,728 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Recovered 16 × 32 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Original stage comparisons](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [32 × 16, U8 and F32 exact on both processor counts](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) | -| [noise_dirt_4_v2.sbs/dirt_4](../assets/sbs/noise_dirt_4_v2.sbs) | 0 | No | [In progress · 5/19 whole renders completed, 99,535/99,584 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Recovered 16 × 32 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Original stage comparisons](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [32 × 16 at seed 105532 still reaches the property limit](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) | +| [noise_dirt_4.sbs/dirt_4](../assets/sbs/noise_dirt_4.sbs) | 0 | Yes | [In progress · 1,536/1,536 with both equal-size Sharpen modes and 384/384 on F16 reopens](parity-fixes.md#half-precision-inputs-to-sharpen) · [Earlier comparison · 6/8 complete additional settings on one processor, 8/8 on eight and 7/8 ordinary saves](parity-fixes.md#recovered-dirt-4-and-moisture-renders-at-seed-113) · [Earlier comparison · 10/19 whole renders completed, 89,052/105,728 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Recovered 16 × 32 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Original stage comparisons](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [32 × 16, U8 and F32 exact on both processor counts](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) | +| [noise_dirt_4_v2.sbs/dirt_4](../assets/sbs/noise_dirt_4_v2.sbs) | 0 | No | [In progress · 1,536/1,536 with both equal-size Sharpen modes and 384/384 on F16 reopens](parity-fixes.md#half-precision-inputs-to-sharpen) · [Earlier comparison · 5/19 whole renders completed, 99,535/99,584 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Recovered 16 × 32 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Original stage comparisons](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [32 × 16 at seed 105532 still reaches the property limit](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) | | [noise_dirt_5.sbs/dirt_5](../assets/sbs/noise_dirt_5.sbs) | 0 | Yes | [In progress · all 60 originals and 12 archived saves render, 31/60 exact on one processor and 30/60 on eight](parity-fixes.md#shared-branch-expressions-and-all-sixty-noise-dirt-5-renders) · [Single-tree F32 comparison, 5,120/5,120 on one processor and after reopening](parity-fixes.md#a-complete-quadrant-tree-with-one-physical-copy-per-draw) · [Earlier comparison · 58/60 tiled whole settings render, all ten recovered settings also measured after ordinary saves](parity-fixes.md#ten-recovered-whole-noise-dirt-5-settings) · [Earlier comparison · eight additional tiled settings and ordinary saves match 40,960/40,960 pixels on one processor, 4/8 settings on eight](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) · [Earlier comparison · 8/8 additional untiled originals on one, 5/8 on eight, 8/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · six of eight additional wide settings exact on one processor, both 128 × 64 formats match all 8,187 invariant locations](parity-fixes.md#the-receiving-half-of-a-quadrant-in-two-tiled-trees) · [Earlier comparison · 48/60 whole settings rendered, 701,551/701,696 pixels on one processor, 701,572 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Recovered 32 × 16 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Earlier comparison · 32² now exact](parity-fixes.md#deep-pattern-samples-in-custom-render-and-tiling-regions) · [Earlier matrix](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [64² precision and remaining traversal limits](parity-fixes.md#precision-of-two-dense-noise-generators-in-custom-regions) | | [noise_dirt_5_v2.sbs/dirt_5](../assets/sbs/noise_dirt_5_v2.sbs) | 0 | No | [In progress · 6/8 additional untiled originals on one, 6/8 on eight, 6/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · 11/19 whole outputs, 107,341/107,776 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Recovered 32 × 16 F32 setting, 457/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) | | [noise_dirt_gradient.sbs/dirt_gradient](../assets/sbs/noise_dirt_gradient.sbs) | 0 | Yes | [In progress · 8/8 additional untiled originals on one, 7/8 on eight, 8/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · 60/60 originals have now rendered across the recorded passes](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Earlier comparison · 58/60 whole settings rendered, 653,612/654,592 pixels on one processor, 653,621 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Earlier comparison · 19/19 whole outputs, 141,554/142,592 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) |