mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-30 01:53:54 +01:00
Qualify saved function calls with their owning package
This commit is contained in:
1 parent
fe78d92ed3
commit
c0f88de60d
6 files changed
+54
-16
No files matched your search
@@ -16,5 +16,5 @@ pub(super) const MAX_SBS_BYTES: u64 = 256 << 20;
|
||||
pub(super) const MAX_WIRES: usize = 1_000_000;
|
||||
pub(super) const SNIFF_BYTES: usize = 4096;
|
||||
pub(super) const SELF_DEPENDENCY: &str = "?himself";
|
||||
pub(super) const FIRST_UID: u64 = 1_000_000_000;
|
||||
pub(super) const SELF_DEPENDENCY_UID: u64 = 1_000_000_001;
|
||||
pub(super) const NODE_HALF_SIZE: [f32; 2] = [50.0, 40.0];
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
constant::SELF_DEPENDENCY,
|
||||
constant::{SELF_DEPENDENCY, SELF_DEPENDENCY_UID},
|
||||
sbs_writer::SbsWriter,
|
||||
xml::{child_element, child_value, children_named, xml_escape},
|
||||
};
|
||||
@@ -64,11 +64,9 @@ fn source_reference(element: XmlNode<'_, '_>, reference: &str) -> Result<(String
|
||||
}
|
||||
|
||||
pub(super) fn write(instance: &GraphInstance, writer: &mut SbsWriter) -> String {
|
||||
let reference = if instance.package.is_empty() {
|
||||
format!("pkg:///{}", instance.graph)
|
||||
} else {
|
||||
format!("pkg:///{}?dependency={}", instance.graph, writer.external_package_uid(&instance.package))
|
||||
};
|
||||
// Another open package can contain a function with the same path.
|
||||
let dependency = if instance.package.is_empty() { SELF_DEPENDENCY_UID } else { writer.external_package_uid(&instance.package) };
|
||||
let reference = format!("pkg:///{}?dependency={dependency}", instance.graph);
|
||||
let mut xml = format!(
|
||||
"<funcDatas><funcData><name v=\"instance\"/><constantValue><constantValueString v=\"{}\"/></constantValue></funcData></funcDatas>",
|
||||
xml_escape(&reference)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
constant::{FIRST_UID, SELF_DEPENDENCY, UPDATER_VERSION},
|
||||
constant::{SELF_DEPENDENCY, SELF_DEPENDENCY_UID, UPDATER_VERSION},
|
||||
sbs_writer::SbsWriter,
|
||||
xml::xml_escape,
|
||||
};
|
||||
@@ -19,11 +19,10 @@ pub fn output_format_version(imported: Option<&str>) -> &str {
|
||||
|
||||
pub fn write_sbs(pkg: &Package) -> Result<Vec<u8>> {
|
||||
let format_version = output_format_version(pkg.format_version.as_deref());
|
||||
let mut writer = SbsWriter { last_uid: FIRST_UID, external_packages: BTreeMap::new() };
|
||||
let self_uid = writer.next_uid();
|
||||
let mut writer = SbsWriter { last_uid: SELF_DEPENDENCY_UID, external_packages: BTreeMap::new() };
|
||||
|
||||
let mut content = String::from("<content>");
|
||||
super::group_layout::write(&mut content, pkg, &mut writer, self_uid)?;
|
||||
super::group_layout::write(&mut content, pkg, &mut writer, SELF_DEPENDENCY_UID)?;
|
||||
content.push_str("</content>");
|
||||
|
||||
let mut out = String::with_capacity(content.len() + 4096);
|
||||
@@ -41,7 +40,7 @@ pub fn write_sbs(pkg: &Package) -> Result<Vec<u8>> {
|
||||
);
|
||||
};
|
||||
|
||||
write_dependency(&mut out, SELF_DEPENDENCY, self_uid);
|
||||
write_dependency(&mut out, SELF_DEPENDENCY, SELF_DEPENDENCY_UID);
|
||||
for (file, uid) in &writer.external_packages {
|
||||
write_dependency(&mut out, file, *uid);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,31 @@ fn nested_function_paths_and_library_aliases_survive_save() {
|
||||
assert!(String::from_utf8(bytes).unwrap().contains(&format!("<updaterVersion v=\"{}\"", env!("CARGO_PKG_VERSION"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_function_calls_save_their_owning_package_dependency() {
|
||||
let local = LIBRARY.replace("sbs://functions.sbs", "?himself");
|
||||
for source in [local.replace("?dependency=9", ""), local] {
|
||||
let package = read_sbs(source.as_bytes(), "source.sbs", &|_| None).unwrap().pkg;
|
||||
let bytes = write_sbs(&package).unwrap();
|
||||
let xml = roxmltree::Document::parse(std::str::from_utf8(&bytes).unwrap()).unwrap();
|
||||
let owner = xml
|
||||
.descendants()
|
||||
.find(|node| {
|
||||
node.has_tag_name("dependency") && node.children().any(|child| child.has_tag_name("filename") && child.attribute("v") == Some("?himself"))
|
||||
})
|
||||
.unwrap();
|
||||
let uid = owner.children().find(|child| child.has_tag_name("uid")).unwrap().attribute("v").unwrap();
|
||||
let call = xml.descendants().find(|node| node.has_tag_name("constantValueString")).unwrap().attribute("v").unwrap();
|
||||
|
||||
assert_eq!(call, format!("pkg:///Functions/Math/Pi?dependency={uid}"));
|
||||
let saved = read_sbs(&bytes, "saved.sbs", &|_| None).unwrap().pkg;
|
||||
let caller = saved.graph_by_name("Caller").unwrap().1.function.as_ref().unwrap();
|
||||
let instance = caller.nodes[0].instance.as_ref().unwrap();
|
||||
assert!(instance.package.is_empty());
|
||||
assert_eq!(instance.graph, "Functions/Math/Pi");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_operations_keep_their_data_and_output() {
|
||||
let xml = LIBRARY.replace("const_float1", "future_operation");
|
||||
|
||||
@@ -123,6 +123,22 @@ The independent 312-case primitive series from the preceding comparison has the
|
||||
|
||||
Both release regressions failed before the fix and passed afterward. All 320 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed.
|
||||
|
||||
### Package ownership of saved function calls
|
||||
|
||||
A saved same-package function call now includes the UID of the package’s own `?himself` dependency. A bare function path could bind to another open package with the same folder and function name. Older files with either representation still open.
|
||||
|
||||
For an independent reproduction, make two files, each with a grayscale Pixel Processor that calls a local function named `Controls/SharedLevel`. Return .125 in the first file and .875 in the second. Open both files in that order. Compare U8 at 16²/seed 0, U16 at 32 × 16/71, F16 at 16 × 32/903 and F32 at 32²/1911. Both original files gave their own constant. With the earlier writer, the first save matched all 2,304 pixels. The second save reopened with the first file’s value in the reference app. It matched 0/256 U8, 0/512 U16, 0/512 F16 and 0/1,024 F32 pixels. Maximum errors were 191 and 49,151 integer levels and .75 in each floating format. The corrected saves matched **4,608/4,608** pixels across both applications, maximum zero.
|
||||
|
||||
The same test in the 3D Voronoi graph replaced the local distance function’s return value with .375. Use a 16² F32 output at seed 37 with defaults, random-color style and the same style with a constant black position field. The first two use position field 7 below. In the previously unqualified file none of the 768 pixels agreed, maximum .6220703125. Reopening the ordinary MaterialCraft save restored **768/768**, maximum zero. Replacing the entire Pixel Processor output with .625 also agreed on all 768 pixels.
|
||||
|
||||
For the four [Voronoi roots](#voronoi-distortion-and-shared-noise-inputs), supply the same original 1024 × 16 U16 table to each application. In one table, shuffle rows of the integers 0 through 1023 consecutively with the Python Mersenne Twister seeded 104729. In the other, use `((53+2y)x + 137y + 29) mod 1024`. Round each table entry times 65535/1023 to the nearest even integer. Save the linked 3D noise package and the parent through MaterialCraft, keep the resource and dependency paths valid, then save the parent a second time. On all four roots, for each table, the reference app reproduced **81,920/81,920** pixels in 36 settings after each save, maximum zero. The two saves also agreed bit for bit. Changing just the two version fields in the linked source did not restore its distorted output. An additional save with qualified function calls reproduced **28,672/28,672** reference pixels in 12 settings for each root and table, maximum zero. These within-application comparisons test the file handoff.
|
||||
|
||||
The 36 settings use sizes 16², 32 × 16, 16 × 32, 32², 64 × 16, 16 × 64, 64 × 32, 32 × 64, 64², 128 × 32, 32 × 128 and 128 × 64, indexed by `j` starting at zero. For 3D roots after index zero, the U16 position channels are `(⌊65535x/(w−1)⌋ + 1597j) mod 65536`, `(⌊65535y/(h−1)⌋ + 977j) mod 65536`, `(233x + 641y + 47xy + 3079(x mod 5) + 11j) mod 65536` and 65535. At 0 and 8 use defaults and seed zero. Use seed 42 at 1 and `457043 + 19j` elsewhere. Use U16 and F32 throughout, plus U8 and F16 at 0, 2, 4, 7, 8 and 10.
|
||||
|
||||
In index order set scale to (8,3,7,2,5,11,9,4,8,13,6,15) and `d` to (0,.15625,.6875,.96875,.4375,0,.28125,.8125,.5625,.171875,.9375,.3125) at changed settings. Use distance mode `j mod 4`, style `(j−1) mod 7`, edge thickness `.03125+.15625d`, Minkowski number `1.25+1.5d`, random-color seed mode `j mod 2` and seed `211j`. Invert when `j mod 3 = 1`. Set offset to `(.1875d,−.375d,.625d)`, size to `(.75+d,1.25−.25d,1.5−.375d)`, distance scale to `.75+.5d`, distortion multiplier to `1+.5d`, intensity to `.1875d` and rounded curve to `.25d`. The 3D variants use disorder `d` and tiling on odd indices. The 2D variants use `(d,.625d,1−.375d)` and non-square expansion on odd indices. Fractal variants use levels `j mod 2` through `2+j mod 3`, opacity `.5+.625d`, roughness `.25+.5d`, lacunarity `1.5+.75d` and blend mode `j mod 3`.
|
||||
|
||||
For the 3D Voronoi cross-application comparison, also repeat indices 1, 2, 3, 4 and 6 with F32 and zero distortion. Across both tables and 82 original settings, U8 matches **20,028/24,064** (maximum 162), U16 **53,820/57,856** (41,505), F16 **20,028/24,064** (.633056641) and F32 **64,060/68,096** (.633334696). In the shuffled-table random-color case at 32 × 64, 32/2,048 pixels agree in each format. The four roots remain in progress. The writer regression failed on the earlier exporter. All 125 format release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed.
|
||||
|
||||
## 2026-11-20 root comparisons
|
||||
|
||||
### Hue, saturation, lightness and Replace Color
|
||||
|
||||
@@ -403,10 +403,10 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug
|
||||
| [noise_upscale_1.sbs/noise_upscale_1](../assets/sbs/noise_upscale_1.sbs) | 1 | No | [Parity · 21 renders, 697,344 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) |
|
||||
| [noise_upscale_2.sbs/noise_upscale_2](../assets/sbs/noise_upscale_2.sbs) | 1 | No | [Parity · 21 renders, 697,344 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) |
|
||||
| [noise_upscale_3.sbs/noise_upscale_3](../assets/sbs/noise_upscale_3.sbs) | 2 | No | [Parity · 21 renders, 697,344 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) |
|
||||
| [noise_voronoi.sbs/3d_voronoi](../assets/sbs/noise_voronoi.sbs) | 1 | No | [In progress · 37 renders, 152,320/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) |
|
||||
| [noise_voronoi.sbs/3d_voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 1 | No | [In progress · 37 renders, 152,163/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) |
|
||||
| [noise_voronoi.sbs/voronoi](../assets/sbs/noise_voronoi.sbs) | 0 | No | [In progress · 37 renders, 152,320/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) |
|
||||
| [noise_voronoi.sbs/voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 0 | No | [In progress · 37 renders, 152,320/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) |
|
||||
| [noise_voronoi.sbs/3d_voronoi](../assets/sbs/noise_voronoi.sbs) | 1 | No | [In progress · 37 renders, 152,320/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) · [Saved function calls and linked noise packages](parity-fixes.md#package-ownership-of-saved-function-calls) |
|
||||
| [noise_voronoi.sbs/3d_voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 1 | No | [In progress · 37 renders, 152,163/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) · [Saved function calls and linked noise packages](parity-fixes.md#package-ownership-of-saved-function-calls) |
|
||||
| [noise_voronoi.sbs/voronoi](../assets/sbs/noise_voronoi.sbs) | 0 | No | [In progress · 37 renders, 152,320/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) · [Saved function calls and linked noise packages](parity-fixes.md#package-ownership-of-saved-function-calls) |
|
||||
| [noise_voronoi.sbs/voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 0 | No | [In progress · 37 renders, 152,320/155,392 exact pixels with stock and shared tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) · [Saved function calls and linked noise packages](parity-fixes.md#package-ownership-of-saved-function-calls) |
|
||||
| [non_square_transform.sbs/non_square_transform](../assets/sbs/non_square_transform.sbs) | 1 | No | [Parity · 204,032 exact pixels in 23 renders](parity-fixes.md#rotated-transforms-and-fractional-texture-coordinates) |
|
||||
| [non_square_transform.sbs/non_square_transform_greyscale](../assets/sbs/non_square_transform.sbs) | 1 | No | [Parity · 204,032 exact pixels in 23 renders](parity-fixes.md#rotated-transforms-and-fractional-texture-coordinates) |
|
||||
| [non_uniform_blur.sbs/non_uniform_blur_grayscale_sample](../assets/sbs/non_uniform_blur.sbs) | 2 | Yes | [Parity · 19 cases, 175,360 exact pixels](parity-fixes.md#directional-warp-orientation-and-input-precision) |
|
||||
|
||||
Reference in new issue
Block a user