3D engine that AI agents drive
Add Cook M1 6-scene Cycles parity and lobe furnace harness (#890)
Nguyen Xuan An8a9e33531abe
diff --git a/bench/cycles-parity/compare.py b/bench/cycles-parity/compare.pyindex 3ceae2c0..7de12451 100644--- a/bench/cycles-parity/compare.py+++ b/bench/cycles-parity/compare.py@@ -13,6 +13,34 @@ REL_MSE_EPSILON = 1e-2TILE_GRID_SIZE = 8TILE_ELIGIBLE_MEAN_THRESHOLD = 0.01TILE_RATIO_TOLERANCE = 0.05+CHANNEL_MEAN_TOLERANCE = 0.02+FLIP_NOISE_MARGIN = 0.02+DISPLAY_GAMMA = 2.2+++def tone_map_like_67js(linear_rgb):+ positive_color = numpy.maximum(linear_rgb, 0.0)+ numerator = positive_color * (2.51 * positive_color + 0.03)+ denominator = positive_color * (2.43 * positive_color + 0.59) + 0.14+ mapped = numpy.clip(numerator / denominator, 0.0, 1.0)+ return (mapped ** (1.0 / DISPLAY_GAMMA)).astype(numpy.float32)+++def compute_flip_scores(reference_rgb, candidate_rgb):+ try:+ import flip_evaluator+ except ImportError as error:+ raise RuntimeError("flip_evaluator is required for FLIP scoring. Run via 'uv run --no-project --with flip-evaluator ...' or pass --no-flip.") from error+ reference_ldr = tone_map_like_67js(reference_rgb)+ candidate_ldr = tone_map_like_67js(candidate_rgb)+ _, mean_ldr, _ = flip_evaluator.evaluate(reference_ldr, candidate_ldr, "LDR", inputsRGB=True)+ reference_hdr = numpy.maximum(reference_rgb, 0.0).astype(numpy.float32)+ candidate_hdr = numpy.maximum(candidate_rgb, 0.0).astype(numpy.float32)+ _, mean_hdr, _ = flip_evaluator.evaluate(reference_hdr, candidate_hdr, "HDR")+ return {+ "flipLdr": float(mean_ldr),+ "flipHdr": float(mean_hdr),+ }def load_linear_rgb_image(image_path):@@ -74,17 +102,21 @@ def compute_tile_grid_ratios(reference_rgb, candidate_rgb):"row": row_index,"column": column_index,"ratio": round(ratio, 4),+ "ratioExact": ratio,"absDeviation": abs(ratio - 1.0),"referenceMean": round(ref_mean, 5),"candidateMean": round(cand_mean, 5),"channelRatios": channel_ratios,})grid_ratios.append(row_values)- ratios_only = [entry["ratio"] for entry in eligible_entries]+ ratios_only = [entry["ratioExact"] for entry in eligible_entries]within_tolerance = [entry for entry in eligible_entries if entry["absDeviation"] <= TILE_RATIO_TOLERANCE]+ min_tile_index = min(range(len(eligible_entries)), key=lambda idx: eligible_entries[idx]["ratioExact"]) if eligible_entries else None+ max_tile_index = max(range(len(eligible_entries)), key=lambda idx: eligible_entries[idx]["ratioExact"]) if eligible_entries else Noneworst_tiles = sorted(eligible_entries, key=lambda entry: entry["absDeviation"], reverse=True)[:8]- for entry in worst_tiles:+ for entry in eligible_entries:entry.pop("absDeviation", None)+ entry.pop("ratioExact", None)return {"gridShape": [TILE_GRID_SIZE, TILE_GRID_SIZE],"eligibleMeanThreshold": TILE_ELIGIBLE_MEAN_THRESHOLD,@@ -94,6 +126,8 @@ def compute_tile_grid_ratios(reference_rgb, candidate_rgb):"minRatio": round(min(ratios_only), 4) if ratios_only else None,"medianRatio": round(float(statistics.median(ratios_only)), 4) if ratios_only else None,"maxRatio": round(max(ratios_only), 4) if ratios_only else None,+ "minTile": dict(eligible_entries[min_tile_index]) if min_tile_index is not None else None,+ "maxTile": dict(eligible_entries[max_tile_index]) if max_tile_index is not None else None,"gridRatios": grid_ratios,"worstTiles": worst_tiles,}@@ -130,13 +164,59 @@ def compute_part_breakdown(reference_rgb, candidate_rgb, parts_prefix):return breakdown-def compare_image_pair(reference_rgb, candidate_rgb, parts_prefix=None):+def build_parity_gates(raw_channel_ratios, tile_grid, candidate_flip, seed_ab_flip):+ channel_mean_pass = all(abs(ratio - 1.0) <= CHANNEL_MEAN_TOLERANCE for ratio in raw_channel_ratios)+ tile_grid_pass = tile_grid["outsideFivePercentCount"] == 0+ gates = {+ "channelMeanRatioExact": [round(float(ratio), 6) for ratio in raw_channel_ratios],+ "channelMeanTolerance": CHANNEL_MEAN_TOLERANCE,+ "channelMeanPass": bool(channel_mean_pass),+ "tileGridTolerance": TILE_RATIO_TOLERANCE,+ "tileGridEligibleCount": tile_grid["eligibleTileCount"],+ "tileGridWithinFivePercentCount": tile_grid["withinFivePercentCount"],+ "tileGridOutsideFivePercentCount": tile_grid["outsideFivePercentCount"],+ "tileGridMinRatio": tile_grid["minRatio"],+ "tileGridMaxRatio": tile_grid["maxRatio"],+ "tileGridPass": bool(tile_grid_pass),+ }+ if candidate_flip is not None:+ gates["flipLdrCandidateVsA"] = round(candidate_flip["flipLdr"], 6)+ gates["flipHdrCandidateVsA"] = round(candidate_flip["flipHdr"], 6)+ if candidate_flip is not None and seed_ab_flip is not None:+ ceiling = seed_ab_flip["flipLdr"] + FLIP_NOISE_MARGIN+ flip_pass = candidate_flip["flipLdr"] <= ceiling+ gates["flipLdrAVsB"] = round(seed_ab_flip["flipLdr"], 6)+ gates["flipHdrAVsB"] = round(seed_ab_flip["flipHdr"], 6)+ gates["flipLdrMargin"] = FLIP_NOISE_MARGIN+ gates["flipLdrCeiling"] = round(ceiling, 6)+ gates["flipPass"] = bool(flip_pass)+ gates["allGatesPass"] = bool(channel_mean_pass and tile_grid_pass and flip_pass)+ else:+ gates["flipLdrAVsB"] = None+ gates["flipHdrAVsB"] = None+ gates["flipLdrMargin"] = FLIP_NOISE_MARGIN+ gates["flipLdrCeiling"] = None+ gates["flipPass"] = None+ gates["allGatesPass"] = None+ return gates+++def compare_image_pair(reference_rgb, candidate_rgb, parts_prefix=None, include_flip=False, seed_ab_comparison=None):error_metrics = compute_relative_mse(reference_rgb, candidate_rgb)abs_diff = numpy.abs(candidate_rgb - reference_rgb)differing_mask = abs_diff.max(axis=-1) > 0.0ref_mean_channels = reference_rgb.reshape(-1, 3).mean(axis=0)cand_mean_channels = candidate_rgb.reshape(-1, 3).mean(axis=0)- channel_ratios = [round(float(cand_mean_channels[ch] / max(ref_mean_channels[ch], 1e-12)), 4) for ch in range(3)]+ raw_channel_ratios = [float(cand_mean_channels[ch] / max(ref_mean_channels[ch], 1e-12)) for ch in range(3)]+ channel_ratios = [round(ratio, 4) for ratio in raw_channel_ratios]+ tile_grid = compute_tile_grid_ratios(reference_rgb, candidate_rgb)+ candidate_flip = compute_flip_scores(reference_rgb, candidate_rgb) if include_flip else None+ seed_ab_flip = None+ if seed_ab_comparison is not None and seed_ab_comparison.get("flipLdr") is not None:+ seed_ab_flip = {+ "flipLdr": seed_ab_comparison["flipLdr"],+ "flipHdr": seed_ab_comparison["flipHdr"],+ }result = {**error_metrics,"differingPixelCount": int(differing_mask.sum()),@@ -147,8 +227,14 @@ def compare_image_pair(reference_rgb, candidate_rgb, parts_prefix=None):"candidateChannelMean": [round(float(val), 6) for val in cand_mean_channels],"channelMeanRatio": channel_ratios,"scalarMeanRatio": round(float(cand_mean_channels.mean() / max(ref_mean_channels.mean(), 1e-12)), 4),- "tileGrid8x8": compute_tile_grid_ratios(reference_rgb, candidate_rgb),+ "flipLdr": round(candidate_flip["flipLdr"], 6) if candidate_flip is not None else None,+ "flipLdrRounded4": round(candidate_flip["flipLdr"], 4) if candidate_flip is not None else None,+ "flipHdr": round(candidate_flip["flipHdr"], 6) if candidate_flip is not None else None,+ "parityGates": build_parity_gates(raw_channel_ratios, tile_grid, candidate_flip, seed_ab_flip),+ "tileGrid8x8": tile_grid,}+ if seed_ab_comparison is not None:+ result["seedAVsSeedB"] = seed_ab_comparisonif parts_prefix is not None:result["partBreakdown"] = compute_part_breakdown(reference_rgb, candidate_rgb, parts_prefix)return result@@ -202,27 +288,95 @@ def interpolate_equal_error_time(target_rel_mse, native_points, time_key):}+def format_parity_summary_line(comparison):+ gates = comparison["parityGates"]+ tile_grid = comparison["tileGrid8x8"]+ ratios = comparison["channelMeanRatio"]+ flip_text = f"FLIP_LDR={comparison['flipLdr']:.4f}" if comparison["flipLdr"] is not None else "FLIP_LDR=n/a"+ if gates["flipLdrCeiling"] is not None:+ flip_text += f" (ceil {gates['flipLdrCeiling']:.4f}, A/B {gates['flipLdrAVsB']:.4f}, pass={gates['flipPass']})"+ tile_text = (+ f"tiles={tile_grid['withinFivePercentCount']}/{tile_grid['eligibleTileCount']} "+ f"[{tile_grid['minRatio']}, {tile_grid['maxRatio']}] pass={gates['tileGridPass']}"+ )+ return (+ f"{os.path.basename(comparison['image'])}: "+ f"allGatesPass={gates['allGatesPass']} "+ f"RGB={ratios} (pass={gates['channelMeanPass']}) "+ f"{tile_text} {flip_text} relMSE={comparison['relMse']:.6f}"+ )++def run_pair_cli(argument_list):parts_prefix = None+ reference_b_path = None+ json_out_path = None+ skip_flip = False+ print_summary = Falsefiltered = []index = 0while index < len(argument_list):- if argument_list[index] == "--parts":+ token = argument_list[index]+ if token == "--parts":parts_prefix = argument_list[index + 1]index += 2continue- filtered.append(argument_list[index])+ if token == "--reference-b":+ reference_b_path = argument_list[index + 1]+ index += 2+ continue+ if token == "--json-out":+ json_out_path = argument_list[index + 1]+ index += 2+ continue+ if token == "--no-flip":+ skip_flip = True+ index += 1+ continue+ if token == "--summary":+ print_summary = True+ index += 1+ continue+ filtered.append(token)index += 1if len(filtered) < 2:- raise ValueError("Usage: compare.py [pair] [--parts <partsPrefix>] <referenceImage> <candidateImage> [<candidateImage>...]")+ raise ValueError(+ "Usage: compare.py [pair] [--reference-b <seed2Image>] [--parts <partsPrefix>] "+ "[--json-out <outputPath>] [--no-flip] [--summary] <referenceImage> <candidateImage> [<candidateImage>...]"+ )reference_rgb = load_linear_rgb_image(filtered[0])+ include_flip = not skip_flip+ seed_ab_comparison = None+ if reference_b_path is not None:+ reference_b_rgb = load_linear_rgb_image(reference_b_path)+ if reference_b_rgb.shape != reference_rgb.shape:+ raise ValueError(f"Resolution mismatch for --reference-b '{reference_b_path}': {reference_b_rgb.shape} vs {reference_rgb.shape}.")+ seed_ab_comparison = compare_image_pair(reference_rgb, reference_b_rgb, include_flip=include_flip)+ seed_ab_comparison["referenceAPath"] = filtered[0]+ seed_ab_comparison["referenceBPath"] = reference_b_path+ comparisons = []for candidate_path in filtered[1:]:candidate_rgb = load_linear_rgb_image(candidate_path)if candidate_rgb.shape != reference_rgb.shape:raise ValueError(f"Resolution mismatch for '{candidate_path}': {candidate_rgb.shape} vs {reference_rgb.shape}.")- comparison = compare_image_pair(reference_rgb, candidate_rgb, parts_prefix=parts_prefix)+ comparison = compare_image_pair(+ reference_rgb,+ candidate_rgb,+ parts_prefix=parts_prefix,+ include_flip=include_flip,+ seed_ab_comparison=seed_ab_comparison,+ )+ comparison["referenceImage"] = filtered[0]comparison["image"] = candidate_path+ comparisons.append(comparison)print(json.dumps(comparison))+ if print_summary:+ print(format_parity_summary_line(comparison), file=sys.stderr)+ if json_out_path is not None:+ os.makedirs(os.path.dirname(os.path.abspath(json_out_path)), exist_ok=True)+ payload = comparisons[0] if len(comparisons) == 1 else comparisons+ with open(json_out_path, "w", encoding="utf-8") as handle:+ json.dump(payload, handle, indent=2)def summarize_repeated_runs(records):diff --git a/bench/cycles-parity/render-cycles.py b/bench/cycles-parity/render-cycles.pyindex d1f4603f..1fc9877a 100644--- a/bench/cycles-parity/render-cycles.py+++ b/bench/cycles-parity/render-cycles.py@@ -164,6 +164,52 @@ def connect_vertex_colors(material, principled_node, material_entry):links.new(multiply_node.outputs["Color"], principled_node.inputs["Base Color"])+def connect_emissive_map(material, principled_node, material_entry, emission_color, image_entries, built_images):+ nodes = material.node_tree.nodes+ links = material.node_tree.links+ texture_node = nodes.new("ShaderNodeTexImage")+ texture_node.image = unpack_shared_image(f"{material.name}-emissive", material_entry["emissiveMap"], image_entries, built_images)+ multiply_node = nodes.new("ShaderNodeMixRGB")+ multiply_node.blend_type = "MULTIPLY"+ multiply_node.inputs[0].default_value = 1.0+ set_linear_rgba_socket(multiply_node.inputs[2], emission_color)+ links.new(texture_node.outputs["Color"], multiply_node.inputs[1])+ links.new(multiply_node.outputs["Color"], principled_node.inputs["Emission Color"])+++def configure_anisotropy(principled_node, material_entry):+ strength = material_entry.get("anisotropy", 0.0)+ if strength <= 0.0:+ return+ alpha = material_entry.get("roughness", 0.5) ** 2+ alpha_tangent = alpha + (1.0 - alpha) * (strength ** 2)+ principled_node.inputs["Anisotropic"].default_value = min((1.0 - alpha / alpha_tangent) / 0.9, 1.0)+ principled_node.inputs["Roughness"].default_value = (alpha * alpha_tangent) ** 0.25+ principled_node.inputs["Anisotropic Rotation"].default_value = material_entry.get("anisotropyRotation", 0.0) / (2.0 * math.pi)+ node_tree = principled_node.id_data+ tangent_node = node_tree.nodes.new("ShaderNodeTangent")+ tangent_node.direction_type = "UV_MAP"+ tangent_node.uv_map = "UVMap"+ node_tree.links.new(tangent_node.outputs["Tangent"], principled_node.inputs["Tangent"])+++def configure_thin_film(principled_node, material_entry):+ if material_entry.get("iridescence", 0.0) <= 0.0:+ return+ principled_node.inputs["Thin Film Thickness"].default_value = material_entry.get("iridescenceThickness", 400.0)+ principled_node.inputs["Thin Film IOR"].default_value = material_entry.get("iridescenceIor", 1.3)+++def configure_subsurface(principled_node, material_entry):+ subsurface_block = material_entry.get("subsurface")+ if not subsurface_block or subsurface_block.get("weight", 0.0) <= 0.0:+ return+ principled_node.subsurface_method = "RANDOM_WALK"+ principled_node.inputs["Subsurface Weight"].default_value = subsurface_block["weight"]+ principled_node.inputs["Subsurface Radius"].default_value = subsurface_block.get("radius", [1.0, 0.2, 0.1])+ principled_node.inputs["Subsurface Scale"].default_value = subsurface_block.get("scale", 0.05)++def configure_principled_layers(material, principled_node, material_entry):principled_node.inputs["Coat Weight"].default_value = material_entry.get("clearcoat", 0.0)principled_node.inputs["Coat Roughness"].default_value = material_entry.get("clearcoatRoughness", 0.0)@@ -171,8 +217,16 @@ def configure_principled_layers(material, principled_node, material_entry):principled_node.inputs["Transmission Weight"].default_value = material_entry.get("transmission", default_transmission)default_ior = principled_node.inputs["IOR"].default_valueprincipled_node.inputs["IOR"].default_value = material_entry.get("ior", default_ior)+ sheen_color = material_entry.get("sheenColor", [0.0, 0.0, 0.0])+ if any(sheen_color):+ principled_node.inputs["Sheen Weight"].default_value = 1.0+ set_linear_rgba_socket(principled_node.inputs["Sheen Tint"], sheen_color)+ principled_node.inputs["Sheen Roughness"].default_value = material_entry.get("sheenRoughness", 0.0)principled_node.inputs["Specular IOR Level"].default_value = 0.5 * material_entry.get("specular", 1.0)set_linear_rgba_socket(principled_node.inputs["Specular Tint"], material_entry.get("specularColor", [1.0, 1.0, 1.0]))+ configure_anisotropy(principled_node, material_entry)+ configure_thin_film(principled_node, material_entry)+ configure_subsurface(principled_node, material_entry)attenuation_distance = material_entry.get("attenuationDistance")if attenuation_distance:absorption_node = material.node_tree.nodes.new("ShaderNodeVolumeAbsorption")@@ -198,6 +252,8 @@ def build_blender_material(material_name, material_entry, has_vertex_colors, imaemission_color = material_entry.get("emissiveColor", material_entry["color"])set_linear_rgba_socket(principled_node.inputs["Emission Color"], emission_color)principled_node.inputs["Emission Strength"].default_value = material_entry["emission"]+ if "emissiveMap" in material_entry:+ connect_emissive_map(material, principled_node, material_entry, emission_color, image_entries, built_images)if "map" in material_entry:connect_base_color_texture(material, principled_node, material_entry, has_vertex_colors, image_entries, built_images)elif has_vertex_colors:@@ -491,12 +547,22 @@ def execute_timed_cycles_render(scene, exr_path):}+def lower_process_priority():+ if os.name != "nt":+ return+ import ctypes+ below_normal_priority_class = 0x00004000+ process_handle = ctypes.windll.kernel32.GetCurrentProcess()+ ctypes.windll.kernel32.SetPriorityClass(process_handle, below_normal_priority_class)++def main():+ lower_process_priority()options = parse_cli_arguments()os.makedirs(os.path.dirname(options["output_prefix"]), exist_ok=True)with open(options["scene_json_path"], encoding="utf-8") as handle:description = json.load(handle)- repository_root = os.getcwd()+ repository_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))build_started = time.perf_counter()bpy.ops.wm.read_factory_settings(use_empty=True)scene = bpy.context.scenediff --git a/bench/cycles-parity/run-m0-suite.py b/bench/cycles-parity/run-m0-suite.pyindex ff924ea7..3c3c376a 100644--- a/bench/cycles-parity/run-m0-suite.py+++ b/bench/cycles-parity/run-m0-suite.py@@ -56,7 +56,9 @@ def wrap_with_gpu_lock(inner_command):bash_binary = os.environ.get("GIT_BASH_BIN")gpu_lock_script = os.environ.get("GPU_LOCK_SCRIPT")if bash_binary and gpu_lock_script:- return [bash_binary, gpu_lock_script, *inner_command]+ normalized_script = gpu_lock_script.replace("\\", "/")+ normalized_inner = [token.replace("\\", "/") if os.path.sep in token else token for token in inner_command]+ return [bash_binary, normalized_script, *normalized_inner]return inner_commanddiff --git a/bench/cycles-parity/run-m1-parity.py b/bench/cycles-parity/run-m1-parity.pynew file mode 100644index 00000000..cdc09733--- /dev/null+++ b/bench/cycles-parity/run-m1-parity.py@@ -0,0 +1,249 @@+"""Run or score the 6-scene M1 Cycles 5.3 parity suite (noise floor, legacy kernel, or Cook cycles kernel)."""+import json+import os+import subprocess+import sys++from compare import compare_image_pair, load_linear_rgb_image++sys.stdout.reconfigure(encoding="utf-8", errors="replace")++M1_SCENES = [+ "spot-area",+ "light-linking",+ "metal",+ "glass",+ "outdoor-hdri",+ "lit-interior",+]+++def read_flag_value(argument_list, flag_name, fallback_value):+ if flag_name not in argument_list:+ return fallback_value+ flag_index = argument_list.index(flag_name)+ if flag_index + 1 >= len(argument_list):+ raise ValueError(f"Flag {flag_name} requires a value.")+ return argument_list[flag_index + 1]+++def parse_arguments():+ argument_list = sys.argv[1:]+ if not argument_list or argument_list[0].startswith("--"):+ raise ValueError(+ "Usage: run-m1-parity.py <workDirectory> [--kernel cycles|legacy] [--samples 1024] "+ "[--bounces 8] [--seed 1] [--reference-samples 4096] [--noise-floor-only] [--score-only] [--skip-existing]"+ )+ scenes_text = read_flag_value(argument_list, "--scenes", ",".join(M1_SCENES))+ scenes = [token.strip() for token in scenes_text.split(",") if token.strip()]+ return {+ "work_directory": os.path.abspath(argument_list[0]),+ "kernel": read_flag_value(argument_list, "--kernel", "cycles"),+ "samples": int(read_flag_value(argument_list, "--samples", "1024")),+ "bounces": int(read_flag_value(argument_list, "--bounces", "8")),+ "seed": int(read_flag_value(argument_list, "--seed", "1")),+ "reference_samples": int(read_flag_value(argument_list, "--reference-samples", "4096")),+ "node_binary": read_flag_value(argument_list, "--node-bin", "node"),+ "json_out": read_flag_value(argument_list, "--json-out", ""),+ "scenes": scenes,+ "noise_floor_only": "--noise-floor-only" in argument_list,+ "score_only": "--score-only" in argument_list,+ "skip_existing": "--skip-existing" in argument_list,+ }+++def wrap_with_gpu_lock(inner_command):+ bash_binary = os.environ.get("GIT_BASH_BIN")+ gpu_lock_script = os.environ.get("GPU_LOCK_SCRIPT")+ if bash_binary and gpu_lock_script:+ normalized_script = gpu_lock_script.replace("\\", "/")+ normalized_inner = [token.replace("\\", "/") if os.path.sep in token else token for token in inner_command]+ return [bash_binary, normalized_script, *normalized_inner]+ return inner_command+++def load_optional_json(file_path):+ if not os.path.exists(file_path):+ return None+ with open(file_path, encoding="utf-8-sig") as handle:+ return json.load(handle)+++def evaluate_noise_floor(work_dir, scene_id, ref_samples):+ ref_dir = os.path.join(work_dir, "references")+ prefix_a = os.path.join(ref_dir, f"{scene_id}-cycles-{ref_samples}-seed1")+ prefix_b = os.path.join(ref_dir, f"{scene_id}-cycles-{ref_samples}-seed2")+ rgb_a = load_linear_rgb_image(f"{prefix_a}.npy")+ rgb_b = load_linear_rgb_image(f"{prefix_b}.npy")+ pair = compare_image_pair(rgb_a, rgb_b, include_flip=True)+ meta_a = load_optional_json(f"{prefix_a}.json") or {}+ meta_b = load_optional_json(f"{prefix_b}.json") or {}+ metrics_a = load_optional_json(f"{prefix_a}.metrics.json") or {}+ metrics_b = load_optional_json(f"{prefix_b}.metrics.json") or {}+ tile_grid = pair["tileGrid8x8"]+ return {+ "sceneId": scene_id,+ "samples": ref_samples,+ "relMse": round(pair["relMse"], 6),+ "channelMeanSeed1": pair["referenceChannelMean"],+ "channelMeanSeed2": pair["candidateChannelMean"],+ "channelMeanRatio": pair["channelMeanRatio"],+ "channelMeanRatioExact": pair["parityGates"]["channelMeanRatioExact"],+ "eligibleTileCount": tile_grid["eligibleTileCount"],+ "tileMinRatio": tile_grid["minRatio"],+ "tileMedianRatio": tile_grid["medianRatio"],+ "tileMaxRatio": tile_grid["maxRatio"],+ "flipLdrSeed1VsSeed2": pair["flipLdr"],+ "flipLdrCeiling": round(pair["flipLdr"] + 0.02, 6),+ "flipHdrSeed1VsSeed2": pair["flipHdr"],+ "seed1SamplingSeconds": meta_a.get("samplingSeconds"),+ "seed2SamplingSeconds": meta_b.get("samplingSeconds"),+ "seed1SetupSeconds": meta_a.get("setupSeconds"),+ "seed1GpuExclusive": metrics_a.get("gpuExclusive"),+ "seed2GpuExclusive": metrics_b.get("gpuExclusive"),+ "fullComparison": pair,+ }+++def run_trace_if_needed(options, scene_id, candidate_prefix):+ if options["score_only"]:+ return+ npy_path = f"{candidate_prefix}.npy"+ json_path = f"{candidate_prefix}.json"+ metrics_path = f"{candidate_prefix}.metrics.json"+ if options["skip_existing"] and os.path.exists(npy_path) and os.path.exists(json_path):+ return+ scene_json = os.path.join(options["work_directory"], "scenes", f"{scene_id}.json")+ trace_cmd = [+ options["node_binary"],+ "bench/cycles-parity/trace-native.mjs",+ scene_json,+ candidate_prefix,+ "--kernel",+ options["kernel"],+ "--samples",+ str(options["samples"]),+ "--bounces",+ str(options["bounces"]),+ "--seed",+ str(options["seed"]),+ "--firefly-clamp",+ "1000000000",+ "--noise-threshold",+ "0",+ ]+ measure_cmd = [+ "uv",+ "run",+ "--no-project",+ "--with",+ "psutil",+ "python",+ "bench/cycles-parity/measure-gpu-run.py",+ metrics_path,+ "--",+ *trace_cmd,+ ]+ completed = subprocess.run(wrap_with_gpu_lock(measure_cmd), check=False)+ if completed.returncode != 0:+ raise RuntimeError(f"trace-native failed for '{scene_id}' with exit code {completed.returncode}.")+++def evaluate_candidate(options, scene_id, noise_entry):+ work_dir = options["work_directory"]+ ref_samples = options["reference_samples"]+ ref_a_npy = os.path.join(work_dir, "references", f"{scene_id}-cycles-{ref_samples}-seed1.npy")+ cand_dir = os.path.join(work_dir, "harness", f"{options['kernel']}-s{options['samples']}")+ os.makedirs(cand_dir, exist_ok=True)+ cand_prefix = os.path.join(cand_dir, f"{scene_id}-{options['kernel']}-{options['samples']}-seed{options['seed']}")+ run_trace_if_needed(options, scene_id, cand_prefix)++ rgb_a = load_linear_rgb_image(ref_a_npy)+ rgb_cand = load_linear_rgb_image(f"{cand_prefix}.npy")+ parts_prefix = os.path.join(work_dir, "scenes", scene_id)+ has_parts = os.path.exists(f"{parts_prefix}-parts.npy")+ comparison = compare_image_pair(+ rgb_a,+ rgb_cand,+ parts_prefix=parts_prefix if has_parts else None,+ include_flip=True,+ seed_ab_comparison=noise_entry["fullComparison"],+ )+ trace_meta = load_optional_json(f"{cand_prefix}.json") or {}+ metrics_meta = load_optional_json(f"{cand_prefix}.metrics.json") or {}+ gates = comparison["parityGates"]+ tiles = comparison["tileGrid8x8"]+ return {+ "sceneId": scene_id,+ "kernel": options["kernel"],+ "samples": options["samples"],+ "allGatesPass": gates["allGatesPass"],+ "channelMeanPass": gates["channelMeanPass"],+ "tileGridPass": gates["tileGridPass"],+ "flipPass": gates["flipPass"],+ "channelMeanRatio": comparison["channelMeanRatio"],+ "channelMeanRatioExact": gates["channelMeanRatioExact"],+ "eligibleTileCount": tiles["eligibleTileCount"],+ "withinFivePercentCount": tiles["withinFivePercentCount"],+ "tileMinRatio": tiles["minRatio"],+ "tileMaxRatio": tiles["maxRatio"],+ "flipLdr": comparison["flipLdr"],+ "flipLdrSeed1VsSeed2": gates["flipLdrAVsB"],+ "flipLdrCeiling": gates["flipLdrCeiling"],+ "flipHdr": comparison["flipHdr"],+ "relMse": round(comparison["relMse"], 6),+ "setupSeconds": trace_meta.get("setupSeconds"),+ "samplingSeconds": trace_meta.get("samplingSeconds"),+ "totalTraceSeconds": trace_meta.get("totalTraceSeconds"),+ "gpuExclusive": metrics_meta.get("gpuExclusive"),+ "comparison": comparison,+ }+++def strip_heavy_nested(noise_rows):+ cleaned = []+ for row in noise_rows:+ copied = dict(row)+ copied.pop("fullComparison", None)+ cleaned.append(copied)+ return cleaned+++def main():+ options = parse_arguments()+ noise_rows = [+ evaluate_noise_floor(options["work_directory"], scene_id, options["reference_samples"])+ for scene_id in options["scenes"]+ ]+ if options["noise_floor_only"]:+ payload = {+ "referenceSamples": options["reference_samples"],+ "sceneCount": len(noise_rows),+ "noiseFloor": strip_heavy_nested(noise_rows),+ }+ else:+ scene_results = [+ evaluate_candidate(options, scene_id, noise_row)+ for scene_id, noise_row in zip(options["scenes"], noise_rows)+ ]+ payload = {+ "kernel": options["kernel"],+ "samples": options["samples"],+ "bounces": options["bounces"],+ "referenceSamples": options["reference_samples"],+ "sceneCount": len(scene_results),+ "scenePassCount": sum(1 for item in scene_results if item["allGatesPass"]),+ "allScenesPass": all(item["allGatesPass"] for item in scene_results),+ "noiseFloor": strip_heavy_nested(noise_rows),+ "scenes": scene_results,+ }+ if options["json_out"]:+ out_path = os.path.abspath(options["json_out"])+ os.makedirs(os.path.dirname(out_path), exist_ok=True)+ with open(out_path, "w", encoding="utf-8") as handle:+ json.dump(payload, handle, indent=2)+ print(json.dumps(payload, indent=2))+++if __name__ == "__main__":+ main()diff --git a/bench/cycles-parity/scene-bridge.mjs b/bench/cycles-parity/scene-bridge.mjsindex 0ee76e6f..4aebeb59 100644--- a/bench/cycles-parity/scene-bridge.mjs+++ b/bench/cycles-parity/scene-bridge.mjs@@ -130,6 +130,59 @@ async function resolvePartGeometry(part, boxProjectedCache) {return byScale.get(cacheKey);}+function ensureNodeImageData() {+ if (typeof globalThis.ImageData === 'function') {+ return;+ }+ globalThis.ImageData = class ImageData {+ constructor(firstArgument, secondArgument, thirdArgument) {+ if (typeof firstArgument === 'number') {+ this.width = firstArgument;+ this.height = secondArgument;+ this.data = new Uint8ClampedArray(firstArgument * secondArgument * 4);+ return;+ }+ if (firstArgument instanceof Uint8ClampedArray) {+ this.data = firstArgument;+ } else {+ this.data = new Uint8ClampedArray(firstArgument.buffer, firstArgument.byteOffset, firstArgument.byteLength);+ }+ this.width = secondArgument;+ this.height = thirdArgument ?? (this.data.length / (4 * secondArgument));+ }+ };+}++async function readRepositoryAsset(rootRelativeUrl) {+ const cleanRelativePath = rootRelativeUrl.split(/[?#]/, 1)[0].slice(1);+ const publicCandidatePath = join(REPOSITORY_ROOT_PATH, 'public', cleanRelativePath);+ try {+ return await readFile(publicCandidatePath);+ } catch (error) {+ if (error?.code !== 'ENOENT') {+ throw error;+ }+ return readFile(join(REPOSITORY_ROOT_PATH, cleanRelativePath));+ }+}++async function runWithRepositoryAssetFetch(callback) {+ ensureNodeImageData();+ const previousFetch = globalThis.fetch;+ globalThis.fetch = async (input, init) => {+ if (typeof input === 'string' && input.startsWith('/')) {+ const assetBytes = await readRepositoryAsset(input);+ return new Response(assetBytes, { status: 200 });+ }+ return previousFetch(input, init);+ };+ try {+ return await callback();+ } finally {+ globalThis.fetch = previousFetch;+ }+}+export async function loadReferenceScene(sceneId) {const [{ REFERENCE_SCENES }, { applyLightLinks }] = await Promise.all([import('../../bench/reference/scenes.js'),@@ -140,7 +193,7 @@ export async function loadReferenceScene(sceneId) {const availableIds = Object.keys(REFERENCE_SCENES).join(', ');throw new RangeError(`Unknown reference scene "${sceneId}". Pass one of: ${availableIds}.`);}- const rawScene = await sceneFactory();+ const rawScene = await runWithRepositoryAssetFetch(() => sceneFactory());const linkedParts = applyLightLinks(rawScene.parts, rawScene.environment);return {rawScene,diff --git a/bench/cycles-parity/test-lobes.mjs b/bench/cycles-parity/test-lobes.mjsnew file mode 100644index 00000000..56e82bcc--- /dev/null+++ b/bench/cycles-parity/test-lobes.mjs@@ -0,0 +1,638 @@+// Runs Cycles lobe white-furnace and PDF grid probes plus end-to-end uniform-sky sphere furnace renders.+// node bench/cycles-parity/test-lobes.mjs <outputDirectory> [--samples-width 512] [--samples-height 512] [--grid-width 1024] [--grid-height 512]+import { mkdir, writeFile } from 'node:fs/promises';+import { constants, setPriority } from 'node:os';+import { join, resolve } from 'node:path';+import { pathToFileURL } from 'node:url';+import { sphere } from '../../src/geometry.js';+import { createEnvironmentMap } from '../../src/hdri.js';+import { createCamera } from '../../src/path-tracer.js';+import * as packModule from '../../src/path-tracer-gpu-pack.js';+import { buildTraceScene } from '../../src/path-tracer-scene.js';+import * as renderNative from '../../packages/render-native/index.mjs';+import { writeFloat32Npy } from './npy.mjs';++const MATERIAL_RECORD_BYTE_LENGTH = 256;+const MATERIAL_FLAG_MULTISCATTER_GGX = 1;+const MATERIAL_FLAG_F82_METALLIC = 32;+const INVALID_SVM_OFFSET = 0xFFFFFFFF;+const IDENTITY_MATRIX = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);++export const LOBE_PROBE_CASES = [+ {+ id: 'diffuse-lambert-normal',+ family: 'diffuse',+ wo: [0.0, 0.0, 1.0],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ specularIorLevel: 0.0,+ diffuseRoughness: 0.0,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'diffuse-principled-oblique',+ family: 'diffuse',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ specularIorLevel: 0.0,+ diffuseRoughness: 0.6,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'dielectric-glossy-sharp-oblique',+ family: 'glossy_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: false,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.05,+ ior: 1.5,+ specularIorLevel: 0.5,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'dielectric-glossy-rough-oblique',+ family: 'glossy_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.35,+ ior: 1.5,+ specularIorLevel: 0.5,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'dielectric-glossy-grazing',+ family: 'glossy_ggx',+ wo: [0.88, 0.0, 0.47497],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.6,+ ior: 1.5,+ specularIorLevel: 0.5,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'conductor-ggx-sharp',+ family: 'glossy_ggx',+ wo: [0.5, 0.0, 0.86603],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: false,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ f82Tint: [1.0, 1.0, 1.0],+ metallic: 1.0,+ roughness: 0.05,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+ {+ id: 'conductor-ggx-medium',+ family: 'glossy_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ f82Tint: [1.0, 1.0, 1.0],+ metallic: 1.0,+ roughness: 0.35,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+ {+ id: 'conductor-ggx-rough-grazing',+ family: 'glossy_ggx',+ wo: [0.9, 0.0, 0.43589],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ f82Tint: [1.0, 1.0, 1.0],+ metallic: 1.0,+ roughness: 0.75,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+ {+ id: 'conductor-f82-gold-oblique',+ family: 'glossy_ggx',+ wo: [0.75, 0.0, 0.66144],+ frontFace: true,+ expectWhiteFurnace: false,+ expectColorOrder: [0, 1, 2],+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 0.78, 0.34],+ f82Tint: [0.92, 0.86, 0.65],+ metallic: 1.0,+ roughness: 0.35,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+ {+ id: 'anisotropic-ggx-unrotated',+ family: 'anisotropic_ggx',+ wo: [0.5, 0.3, 0.8124],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ f82Tint: [1.0, 1.0, 1.0],+ metallic: 1.0,+ roughness: 0.35,+ anisotropy: 0.7,+ anisotropyRotation: 0.0,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+ {+ id: 'anisotropic-ggx-rotated',+ family: 'anisotropic_ggx',+ wo: [0.5, 0.3, 0.8124],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ f82Tint: [1.0, 1.0, 1.0],+ metallic: 1.0,+ roughness: 0.35,+ anisotropy: 0.7,+ anisotropyRotation: 0.2,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+ {+ id: 'glass-ggx-frontface-sharp',+ family: 'glass_ggx',+ wo: [0.5, 0.0, 0.86603],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: false,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.05,+ ior: 1.5,+ transmissionWeight: 1.0,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'glass-ggx-frontface-rough',+ family: 'glass_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.35,+ ior: 1.5,+ transmissionWeight: 1.0,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'glass-ggx-backface-subcritical',+ family: 'glass_ggx',+ wo: [0.3, 0.0, 0.95394],+ frontFace: false,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.35,+ ior: 1.5,+ transmissionWeight: 1.0,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'glass-ggx-backface-tir',+ family: 'glass_ggx',+ wo: [0.85, 0.0, 0.52678],+ frontFace: false,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.35,+ ior: 1.5,+ transmissionWeight: 1.0,+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'coat-ggx-over-diffuse-sharp',+ family: 'coat_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: false,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.5,+ ior: 1.5,+ specularIorLevel: 0.5,+ coatWeight: 1.0,+ coatRoughness: 0.05,+ coatIor: 1.5,+ coatTint: [1.0, 1.0, 1.0],+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'coat-ggx-over-diffuse-rough',+ family: 'coat_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ metallic: 0.0,+ roughness: 0.5,+ ior: 1.5,+ specularIorLevel: 0.5,+ coatWeight: 1.0,+ coatRoughness: 0.35,+ coatIor: 1.5,+ coatTint: [1.0, 1.0, 1.0],+ flags: MATERIAL_FLAG_MULTISCATTER_GGX,+ },+ },+ {+ id: 'coat-ggx-over-metal-rough',+ family: 'coat_ggx',+ wo: [0.6, 0.0, 0.8],+ frontFace: true,+ expectWhiteFurnace: true,+ expectChiSquare: true,+ material: {+ baseColor: [1.0, 1.0, 1.0],+ f82Tint: [1.0, 1.0, 1.0],+ metallic: 1.0,+ roughness: 0.4,+ coatWeight: 1.0,+ coatRoughness: 0.3,+ coatIor: 1.5,+ coatTint: [1.0, 1.0, 1.0],+ flags: MATERIAL_FLAG_MULTISCATTER_GGX | MATERIAL_FLAG_F82_METALLIC,+ },+ },+];++export const FURNACE_SCENE_CASES = [+ {+ id: 'furnace-scene-diffuse',+ material: { color: [1.0, 1.0, 1.0], metallic: 0.0, roughness: 0.5, specular: 0.0 },+ },+ {+ id: 'furnace-scene-dielectric-glossy',+ material: { color: [1.0, 1.0, 1.0], metallic: 0.0, roughness: 0.35, specular: 1.0, ior: 1.5 },+ },+ {+ id: 'furnace-scene-metal',+ material: { color: [1.0, 1.0, 1.0], metallic: 1.0, roughness: 0.35 },+ },+ {+ id: 'furnace-scene-glass',+ material: { color: [1.0, 1.0, 1.0], metallic: 0.0, roughness: 0.15, transmission: 1.0, ior: 1.5 },+ },+ {+ id: 'furnace-scene-coat',+ material: { color: [1.0, 1.0, 1.0], metallic: 0.0, roughness: 0.5, clearcoat: 1.0, clearcoatRoughness: 0.2 },+ },+];++function writeVec3(view, byteOffset, rgb) {+ view.setFloat32(byteOffset, rgb[0], true);+ view.setFloat32(byteOffset + 4, rgb[1], true);+ view.setFloat32(byteOffset + 8, rgb[2], true);+}++export function packMaterialRecord(spec) {+ const bytes = new Uint8Array(MATERIAL_RECORD_BYTE_LENGTH);+ const view = new DataView(bytes.buffer);+ writeVec3(view, 0, spec.baseColor ?? [1.0, 1.0, 1.0]);+ view.setFloat32(12, spec.metallic ?? 0.0, true);+ view.setFloat32(16, spec.roughness ?? 0.5, true);+ view.setFloat32(20, spec.ior ?? 1.5, true);+ view.setFloat32(24, spec.specularIorLevel ?? 0.5, true);+ view.setFloat32(28, spec.diffuseRoughness ?? 0.0, true);+ writeVec3(view, 32, spec.f82Tint ?? [1.0, 1.0, 1.0]);+ view.setFloat32(44, spec.anisotropy ?? 0.0, true);+ view.setFloat32(48, spec.anisotropyRotation ?? 0.0, true);+ view.setFloat32(52, spec.transmissionWeight ?? 0.0, true);+ view.setFloat32(56, spec.alpha ?? 1.0, true);+ view.setFloat32(60, spec.alphaCutoff ?? 0.0, true);+ writeVec3(view, 64, spec.coatTint ?? [1.0, 1.0, 1.0]);+ view.setFloat32(76, spec.coatWeight ?? 0.0, true);+ view.setFloat32(80, spec.coatRoughness ?? 0.0, true);+ view.setFloat32(84, spec.coatIor ?? 1.5, true);+ view.setFloat32(88, spec.thinFilmThickness ?? 0.0, true);+ view.setFloat32(92, spec.thinFilmIor ?? 1.33, true);+ writeVec3(view, 96, spec.sheenTint ?? [1.0, 1.0, 1.0]);+ view.setFloat32(108, spec.sheenWeight ?? 0.0, true);+ writeVec3(view, 112, spec.absorptionColor ?? [1.0, 1.0, 1.0]);+ view.setFloat32(124, spec.absorptionDistance ?? 0.0, true);+ writeVec3(view, 128, spec.emissionColor ?? [0.0, 0.0, 0.0]);+ view.setFloat32(140, spec.emissionStrength ?? 0.0, true);+ writeVec3(view, 144, spec.subsurfaceRadius ?? [1.0, 0.2, 0.1]);+ view.setFloat32(156, spec.subsurfaceWeight ?? 0.0, true);+ writeVec3(view, 160, spec.subsurfaceColor ?? [1.0, 1.0, 1.0]);+ view.setFloat32(172, spec.subsurfaceAnisotropy ?? 0.0, true);+ view.setFloat32(176, spec.sheenRoughness ?? 0.5, true);+ view.setFloat32(180, spec.subsurfaceIor ?? 1.4, true);+ view.setFloat32(184, spec.normalScale ?? 1.0, true);+ view.setFloat32(188, spec.coatNormalScale ?? 1.0, true);+ view.setUint32(192, spec.flags ?? MATERIAL_FLAG_MULTISCATTER_GGX, true);+ view.setUint32(196, spec.alphaMode ?? 0, true);+ view.setFloat32(200, spec.bumpDistance ?? 0.0, true);+ view.setUint32(204, INVALID_SVM_OFFSET, true);+ for (let byteOffset = 208; byteOffset < 256; byteOffset += 4) {+ view.setInt32(byteOffset, -1, true);+ }+ return bytes;+}++function readFlagValue(argumentList, flagName, fallbackValue) {+ const flagIndex = argumentList.indexOf(flagName);+ if (flagIndex === -1) {+ return fallbackValue;+ }+ const nextValue = argumentList[flagIndex + 1];+ if (nextValue === undefined || nextValue.startsWith('--')) {+ throw new RangeError(`Flag ${flagName} requires a value.`);+ }+ return nextValue;+}++function parseIntegerOption(argumentList, flagName, fallbackValue, minimumValue) {+ const parsed = Number(readFlagValue(argumentList, flagName, fallbackValue));+ if (!Number.isInteger(parsed) || parsed < minimumValue) {+ throw new RangeError(`Option ${flagName} must be an integer >= ${minimumValue}, got ${parsed}.`);+ }+ return parsed;+}++function parseCliArguments(argumentList) {+ if (argumentList.length < 1 || argumentList[0].startsWith('--')) {+ throw new RangeError('Usage: node bench/cycles-parity/test-lobes.mjs <outputDirectory> [--samples-width 512] [--samples-height 512] [--grid-width 1024] [--grid-height 512] [--scene-samples 512] [--seed 1] [--filter <substring>] [--skip-scenes] [--skip-probes]');+ }+ return {+ outputDirectory: resolve(argumentList[0]),+ samplesWidth: parseIntegerOption(argumentList, '--samples-width', 512, 16),+ samplesHeight: parseIntegerOption(argumentList, '--samples-height', 512, 16),+ gridWidth: parseIntegerOption(argumentList, '--grid-width', 1024, 32),+ gridHeight: parseIntegerOption(argumentList, '--grid-height', 512, 32),+ sceneWidth: parseIntegerOption(argumentList, '--scene-width', 128, 32),+ sceneHeight: parseIntegerOption(argumentList, '--scene-height', 128, 32),+ sceneSamples: parseIntegerOption(argumentList, '--scene-samples', 512, 16),+ seed: parseIntegerOption(argumentList, '--seed', 1, 0),+ filter: readFlagValue(argumentList, '--filter', ''),+ skipScenes: argumentList.includes('--skip-scenes'),+ skipProbes: argumentList.includes('--skip-probes'),+ };+}++function unpackModeZeroRows(rawPlanes, sampleCount) {+ const packedRows = new Float32Array(sampleCount * 12);+ const plane1Base = sampleCount * 4;+ const plane2Base = sampleCount * 8;+ for (let sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) {+ const planeOffset = sampleIndex * 4;+ const rowOffset = sampleIndex * 12;+ packedRows[rowOffset] = rawPlanes[planeOffset];+ packedRows[rowOffset + 1] = rawPlanes[planeOffset + 1];+ packedRows[rowOffset + 2] = rawPlanes[planeOffset + 2];+ packedRows[rowOffset + 3] = rawPlanes[planeOffset + 3];+ packedRows[rowOffset + 4] = rawPlanes[plane1Base + planeOffset];+ packedRows[rowOffset + 5] = rawPlanes[plane1Base + planeOffset + 1];+ packedRows[rowOffset + 6] = rawPlanes[plane1Base + planeOffset + 2];+ packedRows[rowOffset + 7] = rawPlanes[plane1Base + planeOffset + 3];+ packedRows[rowOffset + 8] = rawPlanes[plane2Base + planeOffset];+ packedRows[rowOffset + 9] = rawPlanes[plane2Base + planeOffset + 1];+ packedRows[rowOffset + 10] = rawPlanes[plane2Base + planeOffset + 2];+ packedRows[rowOffset + 11] = rawPlanes[plane2Base + planeOffset + 3];+ }+ return packedRows;+}++function unpackModeOnePdfGrid(rawPlanes, gridCount) {+ const pdfGrid = new Float32Array(gridCount);+ for (let cellIndex = 0; cellIndex < gridCount; cellIndex++) {+ pdfGrid[cellIndex] = rawPlanes[cellIndex * 4 + 3];+ }+ return pdfGrid;+}++function extractLinearRgb(rgbaPixels, pixelCount) {+ const linearRgb = new Float32Array(pixelCount * 3);+ for (let pixelIndex = 0; pixelIndex < pixelCount; pixelIndex++) {+ const sourceOffset = pixelIndex * 4;+ const targetOffset = pixelIndex * 3;+ linearRgb[targetOffset] = rgbaPixels[sourceOffset];+ linearRgb[targetOffset + 1] = rgbaPixels[sourceOffset + 1];+ linearRgb[targetOffset + 2] = rgbaPixels[sourceOffset + 2];+ }+ return linearRgb;+}++async function runLobeProbeCase(probeCase, options) {+ const materialBytes = packMaterialRecord(probeCase.material);+ const sampleCount = options.samplesWidth * options.samplesHeight;+ const rawModeZero = renderNative.probeCyclesLobe({+ width: options.samplesWidth,+ height: options.samplesHeight,+ wo: probeCase.wo,+ frontFace: probeCase.frontFace,+ mode: 0,+ seed: options.seed,+ materialBytes,+ });+ const modeZeroFloats = rawModeZero instanceof Float32Array ? rawModeZero : rawModeZero.data;+ if (!(modeZeroFloats instanceof Float32Array) || modeZeroFloats.length < sampleCount * 12) {+ throw new Error(`probeCyclesLobe Mode 0 returned unexpected buffer length for "${probeCase.id}".`);+ }+ const modeZeroPath = join(options.outputDirectory, `${probeCase.id}-mode0.npy`);+ const modeZeroRows = unpackModeZeroRows(modeZeroFloats, sampleCount);+ await writeFloat32Npy(modeZeroPath, modeZeroRows, [sampleCount, 12]);++ let modeOnePath = null;+ if (probeCase.expectChiSquare) {+ const gridCount = options.gridWidth * options.gridHeight;+ const rawModeOne = renderNative.probeCyclesLobe({+ width: options.gridWidth,+ height: options.gridHeight,+ wo: probeCase.wo,+ frontFace: probeCase.frontFace,+ mode: 1,+ seed: options.seed,+ materialBytes,+ });+ const modeOneFloats = rawModeOne instanceof Float32Array ? rawModeOne : rawModeOne.data;+ if (!(modeOneFloats instanceof Float32Array) || modeOneFloats.length < gridCount * 4) {+ throw new Error(`probeCyclesLobe Mode 1 returned unexpected buffer length for "${probeCase.id}".`);+ }+ modeOnePath = join(options.outputDirectory, `${probeCase.id}-mode1-pdf.npy`);+ const pdfGrid = unpackModeOnePdfGrid(modeOneFloats, gridCount);+ await writeFloat32Npy(modeOnePath, pdfGrid, [options.gridHeight, options.gridWidth]);+ }+ return {+ id: probeCase.id,+ family: probeCase.family,+ wo: probeCase.wo,+ frontFace: probeCase.frontFace,+ expectWhiteFurnace: probeCase.expectWhiteFurnace,+ expectColorOrder: probeCase.expectColorOrder ?? null,+ expectChiSquare: probeCase.expectChiSquare,+ sampleCount,+ gridShape: probeCase.expectChiSquare ? [options.gridHeight, options.gridWidth] : null,+ modeZeroPath,+ modeOnePath,+ };+}++async function runFurnaceSceneCase(sceneCase, sphereGeometry, whiteEnvironment, cameraDescriptor, options) {+ const parts = [{+ name: 'furnace-sphere',+ geometry: sphereGeometry,+ matrix: IDENTITY_MATRIX,+ material: sceneCase.material,+ }];+ const traceScene = buildTraceScene(parts, whiteEnvironment);+ const camera = createCamera(cameraDescriptor, options.sceneWidth, options.sceneHeight);+ const traceOptions = {+ width: options.sceneWidth,+ height: options.sceneHeight,+ samples: options.sceneSamples,+ bounces: 8,+ seed: options.seed,+ kernel: 'cycles',+ filterType: 'box',+ filterWidth: 1.0,+ clampDirect: 0.0,+ clampIndirect: 0.0,+ fireflyClamp: 1e9,+ noiseThreshold: 0.0,+ maxSeconds: 300,+ };+ const nativeInput = typeof renderNative.buildNativeInputV2 === 'function'+ ? renderNative.buildNativeInputV2(traceScene, camera, traceOptions, packModule)+ : renderNative.buildNativeInput(traceScene, camera, traceOptions, packModule);+ const traced = renderNative.traceNative(nativeInput, traceOptions);+ const pixelCount = options.sceneWidth * options.sceneHeight;+ const linearRgb = extractLinearRgb(traced.rgba, pixelCount);+ const imagePath = join(options.outputDirectory, `${sceneCase.id}.npy`);+ await writeFloat32Npy(imagePath, linearRgb, [options.sceneHeight, options.sceneWidth, 3]);+ return {+ id: sceneCase.id,+ width: options.sceneWidth,+ height: options.sceneHeight,+ samples: options.sceneSamples,+ bounces: 8,+ cameraEyeZ: 3.2,+ cameraFovDegrees: 40,+ sphereRadius: 1.0,+ imagePath,+ };+}++async function runCli() {+ setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);+ const options = parseCliArguments(process.argv.slice(2));+ if (!renderNative.findNativeAddon()) {+ throw new Error('The render-native addon is missing. Build packages/render-native before running test-lobes.mjs.');+ }+ await mkdir(options.outputDirectory, { recursive: true });+ const probeManifestEntries = [];+ if (!options.skipProbes) {+ if (typeof renderNative.probeCyclesLobe !== 'function') {+ throw new Error('packages/render-native/index.mjs does not export probeCyclesLobe yet. Merge the host and closures lanes before running lobe probes.');+ }+ const selectedProbes = LOBE_PROBE_CASES.filter((item) => !options.filter || item.id.includes(options.filter));+ for (const probeCase of selectedProbes) {+ const result = await runLobeProbeCase(probeCase, options);+ probeManifestEntries.push(result);+ }+ }+ const sceneManifestEntries = [];+ if (!options.skipScenes) {+ const selectedScenes = FURNACE_SCENE_CASES.filter((item) => !options.filter || item.id.includes(options.filter));+ if (selectedScenes.length > 0) {+ const sphereGeometry = sphere(64, 40);+ const constantWhite = new Float32Array(8 * 4 * 3).fill(1.0);+ const environmentMap = createEnvironmentMap({ width: 8, height: 4, data: constantWhite, showBackground: true });+ const whiteEnvironment = {+ map: environmentMap,+ keyColor: [0, 0, 0],+ lightDirection: [0, 1, 0],+ pointLights: [],+ spotLights: [],+ areaLights: [],+ };+ const cameraDescriptor = {+ eye: [0, 0, 3.2],+ target: [0, 0, 0],+ up: [0, 1, 0],+ fov: 40,+ near: 0.1,+ far: 20,+ };+ for (const sceneCase of selectedScenes) {+ const result = await runFurnaceSceneCase(sceneCase, sphereGeometry, whiteEnvironment, cameraDescriptor, options);+ sceneManifestEntries.push(result);+ }+ }+ }+ const manifest = {+ seed: options.seed,+ samplesWidth: options.samplesWidth,+ samplesHeight: options.samplesHeight,+ gridWidth: options.gridWidth,+ gridHeight: options.gridHeight,+ probes: probeManifestEntries,+ furnaceScenes: sceneManifestEntries,+ };+ const manifestPath = join(options.outputDirectory, 'lobes-manifest.json');+ await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);+ console.log(`LOBE_PROBES_WRITTEN ${JSON.stringify({ manifestPath, probeCount: probeManifestEntries.length, furnaceSceneCount: sceneManifestEntries.length })}`);+}++if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {+ await runCli();+}diff --git a/bench/cycles-parity/trace-native.mjs b/bench/cycles-parity/trace-native.mjsindex 4bf77ee4..251f6d46 100644--- a/bench/cycles-parity/trace-native.mjs+++ b/bench/cycles-parity/trace-native.mjs@@ -1,15 +1,18 @@// Traces an exported scene JSON on packages/render-native and writes linear RGB float32 (.npy) plus timing JSON.-// node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--samples 256] [--bounces 8] [--seed 1]+// node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--kernel legacy|cycles] [--samples 256] [--bounces 8] [--seed 1]import { mkdir, readFile, writeFile } from 'node:fs/promises';import { constants, setPriority } from 'node:os';import { dirname, resolve } from 'node:path';import { createCamera } from '../../src/path-tracer.js';import * as packModule from '../../src/path-tracer-gpu-pack.js';import { buildTraceScene } from '../../src/path-tracer-scene.js';-import { buildNativeInput, findNativeAddon, traceNative } from '../../packages/render-native/index.mjs';+import * as renderNative from '../../packages/render-native/index.mjs';import { writeFloat32Npy } from './npy.mjs';import { reconstructTraceSceneSource } from './scene-bridge.mjs';+const SUPPORTED_KERNELS = new Set(['legacy', 'cycles']);+const SUPPORTED_FILTERS = new Set(['box', 'blackman-harris']);+function readFlagValue(argumentList, flagName, fallbackValue) {const flagIndex = argumentList.indexOf(flagName);if (flagIndex === -1) {@@ -38,24 +41,52 @@ function parseNumberOption(argumentList, flagName, fallbackValue, minimumValue)return parsed;}+function parseKernelOption(argumentList) {+ const kernel = String(readFlagValue(argumentList, '--kernel', 'legacy'));+ if (!SUPPORTED_KERNELS.has(kernel)) {+ throw new RangeError(`Option --kernel must be "legacy" or "cycles", got "${kernel}".`);+ }+ return kernel;+}++function parseFilterTypeOption(argumentList) {+ const filterType = String(readFlagValue(argumentList, '--filter-type', 'box'));+ if (!SUPPORTED_FILTERS.has(filterType)) {+ throw new RangeError(`Option --filter-type must be "box" or "blackman-harris", got "${filterType}".`);+ }+ return filterType;+}+function parseTraceArguments(argumentList) {if (argumentList.length < 2 || argumentList[0].startsWith('--') || argumentList[1].startsWith('--')) {- throw new RangeError('Usage: node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--samples 256] [--bounces 8] [--seed 1] [--width 960] [--height 540] [--firefly-clamp 1e9] [--noise-threshold 0]');+ throw new RangeError('Usage: node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--kernel legacy|cycles] [--samples 256] [--bounces 8] [--seed 1] [--width 960] [--height 540] [--filter-type box|blackman-harris] [--filter-width 1.0] [--clamp-direct 0] [--clamp-indirect 0] [--firefly-clamp 1e9] [--noise-threshold 0]');}return {sceneJsonPath: resolve(argumentList[0]),outputPrefix: resolve(argumentList[1]),+ kernel: parseKernelOption(argumentList),width: parseIntegerOption(argumentList, '--width', 960, 16),height: parseIntegerOption(argumentList, '--height', 540, 16),samples: parseIntegerOption(argumentList, '--samples', 256, 1),bounces: parseIntegerOption(argumentList, '--bounces', 8, 0),seed: parseIntegerOption(argumentList, '--seed', 1, 0),+ filterType: parseFilterTypeOption(argumentList),+ filterWidth: parseNumberOption(argumentList, '--filter-width', 1.0, 0.01),+ clampDirect: parseNumberOption(argumentList, '--clamp-direct', 0, 0),+ clampIndirect: parseNumberOption(argumentList, '--clamp-indirect', 0, 0),fireflyClamp: parseNumberOption(argumentList, '--firefly-clamp', 1e9, 0),noiseThreshold: parseNumberOption(argumentList, '--noise-threshold', 0, 0),maxSeconds: parseNumberOption(argumentList, '--max-seconds', 1800, 1),};}+function packSceneForKernel(traceScene, camera, options) {+ if (options.kernel === 'cycles' && typeof renderNative.buildNativeInputV2 === 'function') {+ return renderNative.buildNativeInputV2(traceScene, camera, options, packModule);+ }+ return renderNative.buildNativeInput(traceScene, camera, options, packModule);+}+function extractLinearRgb(rgbaPixels, pixelCount) {const linearRgb = new Float32Array(pixelCount * 3);for (let pixelIndex = 0; pixelIndex < pixelCount; pixelIndex++) {@@ -71,7 +102,7 @@ function extractLinearRgb(rgbaPixels, pixelCount) {async function runCli() {setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);const options = parseTraceArguments(process.argv.slice(2));- if (!findNativeAddon()) {+ if (!renderNative.findNativeAddon()) {throw new Error('The render-native addon is missing. Build packages/render-native before running trace-native.mjs.');}const description = JSON.parse(await readFile(options.sceneJsonPath, 'utf8'));@@ -81,13 +112,20 @@ async function runCli() {const traceSource = await reconstructTraceSceneSource(description);const traceScene = buildTraceScene(traceSource.parts, traceSource.environment);const camera = createCamera(traceSource.camera, options.width, options.height);- const nativeInput = buildNativeInput(traceScene, camera, options, packModule);+ const nativeInput = packSceneForKernel(traceScene, camera, options);const sceneBuildSeconds = (performance.now() - buildStarted) / 1000;- const traced = traceNative(nativeInput, {+ const traced = renderNative.traceNative(nativeInput, {width: options.width,height: options.height,samples: options.samples,+ bounces: options.bounces,+ seed: options.seed,maxSeconds: options.maxSeconds,+ kernel: options.kernel,+ filterType: options.filterType,+ filterWidth: options.filterWidth,+ clampDirect: options.clampDirect,+ clampIndirect: options.clampIndirect,});const totalTraceSeconds = (performance.now() - totalStarted) / 1000;const postTraceRssMegabytes = process.memoryUsage().rss / (1024 * 1024);@@ -97,7 +135,9 @@ async function runCli() {await writeFloat32Npy(npyPath, linearRgb, [options.height, options.width, 3]);const setupSeconds = sceneBuildSeconds + traced.setupSeconds + traced.compileSeconds + traced.uploadSeconds + traced.accelerationBuildSeconds;const report = {- engine: '67js-render-native',+ engine: options.kernel === 'cycles' ? 'cook-render-native' : '67js-render-native',+ kernel: traced.kernel ?? options.kernel,+ inputSchemaVersion: nativeInput.schemaVersion ?? 1,sceneId: description.id,npyPath,width: options.width,@@ -106,6 +146,10 @@ async function runCli() {averageSamples: traced.averageSamples,bounces: options.bounces,seed: options.seed,+ filterType: options.filterType,+ filterWidth: options.filterWidth,+ clampDirect: options.clampDirect,+ clampIndirect: options.clampIndirect,fireflyClamp: options.fireflyClamp,noiseThreshold: options.noiseThreshold,triangleCount: nativeInput.triangleCount,diff --git a/bench/cycles-parity/verify-lobes.py b/bench/cycles-parity/verify-lobes.pynew file mode 100644index 00000000..7e1acd9b--- /dev/null+++ b/bench/cycles-parity/verify-lobes.py@@ -0,0 +1,440 @@+"""Verify lobe white-furnace directional albedo, eval/sample consistency, and 2D Pearson chi-square."""+import json+import math+import os+import sys+import tempfile++import numpy++sys.stdout.reconfigure(encoding="utf-8", errors="replace")++FURNACE_TOLERANCE = 0.01+FURNACE_LIMB_TOLERANCE = 0.015+CHI_SQUARE_MIN_P_VALUE = 0.001+CHI_SQUARE_MIN_EXPECTED = 5.0+HISTOGRAM_PHI_BINS = 32+HISTOGRAM_Z_BINS = 32+EVAL_CONSISTENCY_TOLERANCE = 2e-3+PDF_INTEGRAL_TOLERANCE = 0.015+++def regularized_gamma_upper(shape_a, value_x):+ if value_x <= 0.0:+ return 1.0+ if value_x < shape_a + 1.0:+ term = 1.0 / shape_a+ series_sum = term+ for step in range(1, 2000):+ term *= value_x / (shape_a + step)+ series_sum += term+ if abs(term) < abs(series_sum) * 1e-15:+ break+ log_prefix = -value_x + shape_a * math.log(value_x) - math.lgamma(shape_a)+ lower_ratio = series_sum * math.exp(log_prefix)+ return max(0.0, min(1.0, 1.0 - lower_ratio))+ tiny = 1e-300+ denominator = value_x + 1.0 - shape_a+ if abs(denominator) < tiny:+ denominator = tiny+ c_val = 1.0 / tiny+ d_val = 1.0 / denominator+ fraction = d_val+ for step in range(1, 2000):+ an_val = -step * (step - shape_a)+ b_val = value_x + 2.0 * step + 1.0 - shape_a+ d_val = an_val * d_val + b_val+ if abs(d_val) < tiny:+ d_val = tiny+ c_val = b_val + an_val / c_val+ if abs(c_val) < tiny:+ c_val = tiny+ d_val = 1.0 / d_val+ delta = d_val * c_val+ fraction *= delta+ if abs(delta - 1.0) < 1e-15:+ break+ log_prefix = -value_x + shape_a * math.log(value_x) - math.lgamma(shape_a)+ return max(0.0, min(1.0, fraction * math.exp(log_prefix)))+++def chi_square_survival_p_value(chi2_statistic, degrees_of_freedom):+ if not math.isfinite(chi2_statistic) or degrees_of_freedom <= 0:+ return 0.0+ return regularized_gamma_upper(0.5 * degrees_of_freedom, 0.5 * chi2_statistic)+++def pool_histogram_bins(observed_counts, expected_counts):+ leaked_zero_pdf = int(observed_counts[expected_counts <= 1e-12].sum())+ pooled_obs = []+ pooled_exp = []+ carry_obs = 0.0+ carry_exp = 0.0+ for obs_val, exp_val in zip(observed_counts.tolist(), expected_counts.tolist()):+ if exp_val <= 1e-12:+ continue+ carry_obs += obs_val+ carry_exp += exp_val+ if carry_exp >= CHI_SQUARE_MIN_EXPECTED:+ pooled_obs.append(carry_obs)+ pooled_exp.append(carry_exp)+ carry_obs = 0.0+ carry_exp = 0.0+ if carry_exp > 0.0:+ if pooled_exp:+ pooled_obs[-1] += carry_obs+ pooled_exp[-1] += carry_exp+ else:+ pooled_obs.append(carry_obs)+ pooled_exp.append(carry_exp)+ return numpy.array(pooled_obs, dtype=numpy.float64), numpy.array(pooled_exp, dtype=numpy.float64), leaked_zero_pdf+++def evaluate_spherical_chi_square(mode_zero_rows, pdf_grid):+ sample_count = mode_zero_rows.shape[0]+ grid_height, grid_width = pdf_grid.shape+ if grid_height % HISTOGRAM_Z_BINS != 0 or grid_width % HISTOGRAM_PHI_BINS != 0:+ raise ValueError(f"Mode 1 PDF grid {pdf_grid.shape} must be divisible by ({HISTOGRAM_Z_BINS}, {HISTOGRAM_PHI_BINS}).")+ d_omega = 4.0 * math.pi / float(grid_height * grid_width)+ sub_z = grid_height // HISTOGRAM_Z_BINS+ sub_phi = grid_width // HISTOGRAM_PHI_BINS+ reshaped_grid = pdf_grid.astype(numpy.float64).reshape(HISTOGRAM_Z_BINS, sub_z, HISTOGRAM_PHI_BINS, sub_phi)+ bin_probabilities = reshaped_grid.sum(axis=(1, 3)) * d_omega+ raw_pdf_integral = float(bin_probabilities.sum())++ sampled_pdf = mode_zero_rows[:, 3].astype(numpy.float64)+ valid_mask = sampled_pdf > 0.0+ invalid_count = int((~valid_mask).sum())+ wi = mode_zero_rows[valid_mask, 0:3].astype(numpy.float64)+ norms = numpy.maximum(numpy.linalg.norm(wi, axis=1, keepdims=True), 1e-15)+ wi_unit = wi / norms+ z_bin = numpy.clip(numpy.floor((1.0 - wi_unit[:, 2]) * 0.5 * HISTOGRAM_Z_BINS).astype(numpy.int64), 0, HISTOGRAM_Z_BINS - 1)+ phi_angles = numpy.mod(numpy.arctan2(wi_unit[:, 1], wi_unit[:, 0]), 2.0 * math.pi)+ phi_bin = numpy.clip(numpy.floor(phi_angles / (2.0 * math.pi) * HISTOGRAM_PHI_BINS).astype(numpy.int64), 0, HISTOGRAM_PHI_BINS - 1)+ flat_indices = z_bin * HISTOGRAM_PHI_BINS + phi_bin+ observed_bins = numpy.bincount(flat_indices, minlength=HISTOGRAM_Z_BINS * HISTOGRAM_PHI_BINS).astype(numpy.float64)++ expected_probs = bin_probabilities.ravel().copy()+ if raw_pdf_integral > 1.0:+ expected_probs = expected_probs / raw_pdf_integral+ invalid_prob = 0.0+ else:+ invalid_prob = max(0.0, 1.0 - raw_pdf_integral)+ all_observed = numpy.append(observed_bins, float(invalid_count))+ all_expected = numpy.append(expected_probs, invalid_prob) * float(sample_count)+ pooled_obs, pooled_exp, leaked_zero_pdf = pool_histogram_bins(all_observed, all_expected)+ degrees_of_freedom = max(1, int(len(pooled_exp) - 1))+ if leaked_zero_pdf > 0:+ chi2_stat = float("inf")+ p_value = 0.0+ else:+ chi2_stat = float(numpy.sum(((pooled_obs - pooled_exp) ** 2) / pooled_exp))+ p_value = chi_square_survival_p_value(chi2_stat, degrees_of_freedom)+ integral_valid = raw_pdf_integral <= 1.0 + PDF_INTEGRAL_TOLERANCE+ passed = bool(leaked_zero_pdf == 0 and integral_valid and p_value >= CHI_SQUARE_MIN_P_VALUE)+ return {+ "rawPdfIntegral": round(raw_pdf_integral, 6),+ "invalidSampleCount": invalid_count,+ "leakedZeroPdfSamples": leaked_zero_pdf,+ "pooledBinCount": int(len(pooled_exp)),+ "degreesOfFreedom": degrees_of_freedom,+ "chiSquare": round(chi2_stat, 4) if math.isfinite(chi2_stat) else None,+ "reducedChiSquare": round(chi2_stat / degrees_of_freedom, 4) if math.isfinite(chi2_stat) else None,+ "pValue": round(p_value, 6),+ "minPValue": CHI_SQUARE_MIN_P_VALUE,+ "pass": passed,+ }+++def evaluate_lobe_probe(probe_entry):+ rows = numpy.load(probe_entry["modeZeroPath"]).astype(numpy.float64)+ finite_all = bool(numpy.isfinite(rows).all())+ sample_count = rows.shape[0]+ samp_pdf = rows[:, 3]+ samp_eval = rows[:, 4:7]+ ev_value = rows[:, 8:11]+ ev_pdf = rows[:, 11]++ valid_mask = samp_pdf > 0.0+ weights = numpy.zeros((sample_count, 3), dtype=numpy.float64)+ weights[valid_mask] = samp_eval[valid_mask] / samp_pdf[valid_mask, None]+ furnace_mean = weights.mean(axis=0)+ furnace_stderr = weights.std(axis=0, ddof=1) / math.sqrt(sample_count)++ if valid_mask.any():+ eval_scale = numpy.maximum(numpy.maximum(numpy.abs(samp_eval[valid_mask]), numpy.abs(ev_value[valid_mask])), 1.0)+ rel_eval_diff = float(numpy.max(numpy.abs(samp_eval[valid_mask] - ev_value[valid_mask]) / eval_scale))+ pdf_scale = numpy.maximum(numpy.maximum(samp_pdf[valid_mask], ev_pdf[valid_mask]), 1.0)+ rel_pdf_diff = float(numpy.max(numpy.abs(samp_pdf[valid_mask] - ev_pdf[valid_mask]) / pdf_scale))+ else:+ rel_eval_diff = float("inf")+ rel_pdf_diff = float("inf")+ consistency_pass = bool(rel_eval_diff <= EVAL_CONSISTENCY_TOLERANCE and rel_pdf_diff <= EVAL_CONSISTENCY_TOLERANCE)++ if probe_entry["expectWhiteFurnace"]:+ furnace_pass = bool(all(abs(val - 1.0) <= FURNACE_TOLERANCE for val in furnace_mean))+ else:+ bounded = all(0.01 <= val <= 1.0 + FURNACE_TOLERANCE for val in furnace_mean)+ order = probe_entry.get("expectColorOrder")+ ordered = True if not order else all(furnace_mean[order[idx]] > furnace_mean[order[idx + 1]] for idx in range(len(order) - 1))+ furnace_pass = bool(bounded and ordered)++ chi_square_report = None+ chi_square_pass = True+ if probe_entry["expectChiSquare"]:+ pdf_grid = numpy.load(probe_entry["modeOnePath"])+ chi_square_report = evaluate_spherical_chi_square(rows, pdf_grid)+ chi_square_pass = chi_square_report["pass"]++ overall_pass = bool(finite_all and furnace_pass and consistency_pass and chi_square_pass)+ return {+ "id": probe_entry["id"],+ "family": probe_entry["family"],+ "frontFace": probe_entry["frontFace"],+ "wo": probe_entry["wo"],+ "sampleCount": int(sample_count),+ "validSampleCount": int(valid_mask.sum()),+ "finiteAll": finite_all,+ "expectWhiteFurnace": probe_entry["expectWhiteFurnace"],+ "furnaceMeanRgb": [round(float(val), 6) for val in furnace_mean],+ "furnaceStdErrRgb": [round(float(val), 6) for val in furnace_stderr],+ "furnaceTolerance": FURNACE_TOLERANCE,+ "furnacePass": furnace_pass,+ "maxRelativeEvalMismatch": round(rel_eval_diff, 7) if math.isfinite(rel_eval_diff) else None,+ "maxRelativePdfMismatch": round(rel_pdf_diff, 7) if math.isfinite(rel_pdf_diff) else None,+ "consistencyPass": consistency_pass,+ "chiSquare": chi_square_report,+ "pass": overall_pass,+ }+++def evaluate_furnace_scene(scene_entry):+ image = numpy.load(scene_entry["imagePath"]).astype(numpy.float64)+ finite_all = bool(numpy.isfinite(image).all())+ height, width, _ = image.shape+ ys, xs = numpy.ogrid[:height, :width]+ center_y = 0.5 * (height - 1.0)+ center_x = 0.5 * (width - 1.0)+ radius_px = numpy.sqrt((xs - center_x) ** 2 + (ys - center_y) ** 2)++ tan_half_fov = math.tan(math.radians(0.5 * scene_entry["cameraFovDegrees"]))+ sin_sil = scene_entry["sphereRadius"] / scene_entry["cameraEyeZ"]+ tan_sil = sin_sil / math.sqrt(max(1e-8, 1.0 - sin_sil * sin_sil))+ projected_radius = (tan_sil / tan_half_fov) * (0.5 * height)++ center_mask = radius_px <= 0.40 * projected_radius+ limb_mask = (radius_px >= 0.72 * projected_radius) & (radius_px <= 0.92 * projected_radius)+ full_mean = image.reshape(-1, 3).mean(axis=0)+ center_mean = image[center_mask].mean(axis=0)+ limb_mean = image[limb_mask].mean(axis=0)++ full_pass = all(abs(val - 1.0) <= FURNACE_TOLERANCE for val in full_mean)+ center_pass = all(abs(val - 1.0) <= FURNACE_TOLERANCE for val in center_mean)+ limb_pass = all(abs(val - 1.0) <= FURNACE_LIMB_TOLERANCE for val in limb_mean)+ passed = bool(finite_all and full_pass and center_pass and limb_pass)+ return {+ "id": scene_entry["id"],+ "shape": list(image.shape),+ "samples": scene_entry["samples"],+ "finiteAll": finite_all,+ "fullImageMeanRgb": [round(float(val), 6) for val in full_mean],+ "sphereCenterMeanRgb": [round(float(val), 6) for val in center_mean],+ "sphereLimbMeanRgb": [round(float(val), 6) for val in limb_mean],+ "fullPass": bool(full_pass),+ "centerPass": bool(center_pass),+ "limbPass": bool(limb_pass),+ "pass": passed,+ }+++def build_synthetic_pdf_grid(grid_height, grid_width, pdf_function):+ iy = (numpy.arange(grid_height, dtype=numpy.float64) + 0.5) / grid_height+ ix = (numpy.arange(grid_width, dtype=numpy.float64) + 0.5) / grid_width+ z_vals = 1.0 - 2.0 * iy[:, None]+ phi_vals = 2.0 * math.pi * ix[None, :]+ evaluated = pdf_function(z_vals, phi_vals)+ return numpy.broadcast_to(evaluated, (grid_height, grid_width)).copy().astype(numpy.float32)+++def run_self_test():+ rng = numpy.random.default_rng(894)+ sample_count = 65536+ grid_h, grid_w = 256, 512++ with tempfile.TemporaryDirectory() as temp_dir:+ u1 = rng.random(sample_count)+ u2 = rng.random(sample_count)+ z_cos = numpy.sqrt(u1)+ sin_t = numpy.sqrt(numpy.maximum(0.0, 1.0 - u1))+ phi = 2.0 * math.pi * u2+ pdf_lambert = z_cos / math.pi+ rows_lambert = numpy.zeros((sample_count, 12), dtype=numpy.float32)+ rows_lambert[:, 0] = sin_t * numpy.cos(phi)+ rows_lambert[:, 1] = sin_t * numpy.sin(phi)+ rows_lambert[:, 2] = z_cos+ rows_lambert[:, 3] = pdf_lambert+ rows_lambert[:, 4:7] = pdf_lambert[:, None]+ rows_lambert[:, 8:11] = pdf_lambert[:, None]+ rows_lambert[:, 11] = pdf_lambert+ lambert_m0 = os.path.join(temp_dir, "lambert-m0.npy")+ lambert_m1 = os.path.join(temp_dir, "lambert-m1.npy")+ numpy.save(lambert_m0, rows_lambert)+ numpy.save(lambert_m1, build_synthetic_pdf_grid(grid_h, grid_w, lambda z, _p: numpy.maximum(z, 0.0) / math.pi))+ lambert_res = evaluate_lobe_probe({+ "id": "self-lambert",+ "family": "diffuse",+ "frontFace": True,+ "wo": [0, 0, 1],+ "expectWhiteFurnace": True,+ "expectChiSquare": True,+ "modeZeroPath": lambert_m0,+ "modeOnePath": lambert_m1,+ })+ assert lambert_res["pass"], f"Lambert self-test failed: {lambert_res}"++ split_reflect = rng.random(sample_count) < 0.35+ rows_glass = rows_lambert.copy()+ rows_glass[~split_reflect, 2] = -z_cos[~split_reflect]+ rows_glass[split_reflect, 3] = 0.35 * pdf_lambert[split_reflect]+ rows_glass[~split_reflect, 3] = 0.65 * pdf_lambert[~split_reflect]+ rows_glass[:, 4:7] = rows_glass[:, 3:4]+ rows_glass[:, 8:11] = rows_glass[:, 3:4]+ rows_glass[:, 11] = rows_glass[:, 3]+ glass_m0 = os.path.join(temp_dir, "glass-m0.npy")+ glass_m1 = os.path.join(temp_dir, "glass-m1.npy")+ numpy.save(glass_m0, rows_glass)+ numpy.save(+ glass_m1,+ build_synthetic_pdf_grid(+ grid_h,+ grid_w,+ lambda z, _p: numpy.where(z >= 0.0, 0.35 * z / math.pi, 0.65 * (-z) / math.pi),+ ),+ )+ glass_res = evaluate_lobe_probe({+ "id": "self-glass-two-hemisphere",+ "family": "glass_ggx",+ "frontFace": True,+ "wo": [0, 0, 1],+ "expectWhiteFurnace": True,+ "expectChiSquare": True,+ "modeZeroPath": glass_m0,+ "modeOnePath": glass_m1,+ })+ assert glass_res["pass"], f"Two-hemisphere glass self-test failed: {glass_res}"++ bad_furnace_rows = rows_lambert.copy()+ bad_furnace_rows[:, 4:7] *= 0.94+ bad_furnace_rows[:, 8:11] *= 0.94+ bad_m0 = os.path.join(temp_dir, "bad-furnace.npy")+ numpy.save(bad_m0, bad_furnace_rows)+ bad_furnace_res = evaluate_lobe_probe({+ "id": "self-bad-furnace",+ "family": "diffuse",+ "frontFace": True,+ "wo": [0, 0, 1],+ "expectWhiteFurnace": True,+ "expectChiSquare": False,+ "modeZeroPath": bad_m0,+ "modeOnePath": None,+ })+ assert not bad_furnace_res["pass"] and not bad_furnace_res["furnacePass"], "6% energy loss was not rejected"++ skewed_grid = build_synthetic_pdf_grid(+ grid_h,+ grid_w,+ lambda z, p: numpy.maximum(z, 0.0) / math.pi * (1.0 + 0.5 * numpy.cos(p)),+ )+ skewed_m1 = os.path.join(temp_dir, "skewed-m1.npy")+ numpy.save(skewed_m1, skewed_grid)+ bad_chi_res = evaluate_lobe_probe({+ "id": "self-bad-chisquare",+ "family": "anisotropic_ggx",+ "frontFace": True,+ "wo": [0, 0, 1],+ "expectWhiteFurnace": True,+ "expectChiSquare": True,+ "modeZeroPath": lambert_m0,+ "modeOnePath": skewed_m1,+ })+ assert not bad_chi_res["pass"] and not bad_chi_res["chiSquare"]["pass"], "Skewed azimuthal PDF was not rejected"++ furnace_ok_path = os.path.join(temp_dir, "scene-ok.npy")+ furnace_img = (1.0 + rng.normal(0.0, 0.015, size=(128, 128, 3))).astype(numpy.float32)+ numpy.save(furnace_ok_path, furnace_img)+ scene_ok = evaluate_furnace_scene({+ "id": "self-scene-ok",+ "samples": 512,+ "cameraEyeZ": 3.2,+ "cameraFovDegrees": 40.0,+ "sphereRadius": 1.0,+ "imagePath": furnace_ok_path,+ })+ assert scene_ok["pass"], f"Valid sphere furnace scene failed: {scene_ok}"++ furnace_dark_rim_path = os.path.join(temp_dir, "scene-dark-rim.npy")+ ys, xs = numpy.ogrid[:128, :128]+ rad = numpy.sqrt((xs - 63.5) ** 2 + (ys - 63.5) ** 2)+ dark_rim = furnace_img.copy()+ dark_rim[(rad >= 40.0) & (rad <= 56.0)] *= 0.88+ numpy.save(furnace_dark_rim_path, dark_rim)+ scene_bad = evaluate_furnace_scene({+ "id": "self-scene-dark-rim",+ "samples": 512,+ "cameraEyeZ": 3.2,+ "cameraFovDegrees": 40.0,+ "sphereRadius": 1.0,+ "imagePath": furnace_dark_rim_path,+ })+ assert not scene_bad["pass"] and not scene_bad["limbPass"], "Dark-rim grazing energy loss was not rejected"++ print(json.dumps({+ "selfTest": "ok",+ "lambertPValue": lambert_res["chiSquare"]["pValue"],+ "glassPValue": glass_res["chiSquare"]["pValue"],+ }))+++def main():+ arguments = sys.argv[1:]+ if "--self-test" in arguments:+ run_self_test()+ return+ if not arguments or arguments[0].startswith("--"):+ raise ValueError("Usage: verify-lobes.py <lobesDirectoryOrManifestJson> [--json-out <outputPath>] | --self-test")+ target_path = os.path.abspath(arguments[0])+ manifest_path = os.path.join(target_path, "lobes-manifest.json") if os.path.isdir(target_path) else target_path+ json_out_path = None+ if "--json-out" in arguments:+ flag_idx = arguments.index("--json-out")+ json_out_path = os.path.abspath(arguments[flag_idx + 1])++ with open(manifest_path, encoding="utf-8") as handle:+ manifest = json.load(handle)+ probe_results = [evaluate_lobe_probe(entry) for entry in manifest.get("probes", [])]+ scene_results = [evaluate_furnace_scene(entry) for entry in manifest.get("furnaceScenes", [])]+ all_probes_pass = all(item["pass"] for item in probe_results)+ all_scenes_pass = all(item["pass"] for item in scene_results)+ summary = {+ "manifestPath": manifest_path,+ "probeCount": len(probe_results),+ "probePassCount": sum(1 for item in probe_results if item["pass"]),+ "furnaceSceneCount": len(scene_results),+ "furnaceScenePassCount": sum(1 for item in scene_results if item["pass"]),+ "allProbesPass": bool(all_probes_pass),+ "allFurnaceScenesPass": bool(all_scenes_pass),+ "allPass": bool(all_probes_pass and all_scenes_pass),+ "probes": probe_results,+ "furnaceScenes": scene_results,+ }+ if json_out_path is not None:+ os.makedirs(os.path.dirname(json_out_path), exist_ok=True)+ with open(json_out_path, "w", encoding="utf-8") as handle:+ json.dump(summary, handle, indent=2)+ print(json.dumps(summary, indent=2))+ if not summary["allPass"]:+ sys.exit(1)+++if __name__ == "__main__":+ main()diff --git a/docs/cycles-parity.md b/docs/cycles-parity.mdindex 34e9e088..9635d7ed 100644--- a/docs/cycles-parity.md+++ b/docs/cycles-parity.md@@ -1,4 +1,4 @@-# Cycles 5.3 Parity Baseline (M0)+# Cycles 5.3 Parity Baseline & M1 SuiteMilestone M0 measures today's native path tracer ([`packages/render-native`](../packages/render-native/README.md), legacy `kernel.wgsl` on `wgpu 30.0.1` Vulkan `EXPERIMENTAL_RAY_QUERY`) against **Blender 5.3.0 Cycles OptiX** under matched unbiased settings on a single reference scene before any Cycles-kernel port changes land.@@ -197,6 +197,51 @@ Least-squares fit of $\text{relMSE}(N) = B_{\text{bias}} + \frac{V}{N}$ across t---+## 5. Milestone M1 6-Scene Reference Noise Floor, Parity Gates, and Lobe Furnace Harness++Milestone M1 expands parity verification for **Cook** (`packages/render-native` `--kernel cycles`) from `lit-interior` to six reference scenes from [`bench/reference/scenes.js`](../bench/reference/scenes.js): `spot-area`, `light-linking`, `metal`, `glass`, `outdoor-hdri`, and `lit-interior`. Every scene exports losslessly (`roundTripVerified = true`) via [`bench/cycles-parity/export-scene.mjs`](../bench/cycles-parity/export-scene.mjs) with Node asset loading handled in [`bench/cycles-parity/scene-bridge.mjs`](../bench/cycles-parity/scene-bridge.mjs) `[measured]`.++### M1 Acceptance Gates++Evaluated in [`bench/cycles-parity/compare.py`](../bench/cycles-parity/compare.py) (`--reference-b <seed2.npy>`) and orchestrated across all six scenes by [`bench/cycles-parity/run-m1-parity.py`](../bench/cycles-parity/run-m1-parity.py):++1. **Global per-channel mean radiance**: `mean(Cook) / mean(Cycles_Seed1)` within **`1 ± 0.02`** (`[0.98, 1.02]`) on each of `(R, G, B)`.+2. **`8 × 8` tile grid radiance**: every tile with `mean(Cycles_Seed1) > 0.01` has `mean(Cook) / mean(Cycles_Seed1)` within **`1 ± 0.05`** (`[0.95, 1.05]`).+3. **Display-space FLIP (`LDR`)**: `FLIP_LDR(Cook, Cycles_Seed1) <= FLIP_LDR(Cycles_Seed1, Cycles_Seed2) + 0.02`, using the exact ACES-like tone map and `2.2` gamma curve from [`bench/reference/score.py`](../bench/reference/score.py) (`tone_map_like_67js`, float32 inputs to `flip_evaluator`). Scene-referred `FLIP_HDR` is recorded alongside `FLIP_LDR` as a diagnostic.+4. **Closure white-furnace & sampling distribution gates**: evaluated in [`bench/cycles-parity/test-lobes.mjs`](../bench/cycles-parity/test-lobes.mjs) and [`bench/cycles-parity/verify-lobes.py`](../bench/cycles-parity/verify-lobes.py) across `18` `probeCyclesLobe` cases (`diffuse`, dielectric & conductor multiscatter `glossy_ggx`, F82-tint conductor, `anisotropic_ggx`, frontface/backface/TIR `glass_ggx`, and `coat_ggx`) plus `5` end-to-end uniform-sky sphere furnace scenes (`traceNative({ kernel: 'cycles' })`):+ - Mode `0` Monte Carlo directional albedo `mean(samp.eval / samp.pdf)` within **`1 ± 0.01`** (`N = 262,144` samples per case) on white-albedo configurations, plus `closure_sample` vs `closure_eval` self-consistency (`<= 2 × 10⁻³`).+ - Mode `0` vs Mode `1` (`1024 × 512` spherical `(cos_theta, phi)` quadrature aggregated into `32 × 32` directional bins, pooling `E_k < 5`) **Pearson $\chi^2$ goodness-of-fit `p >= 0.001`**.++### Cycles 5.3 OptiX `4096`-spp Reference Noise Floor (`Seed 1` vs `Seed 2`)++All six scenes were rendered in Blender `5.3.0` Cycles OptiX at `960 × 540`, `4096` samples (`seed = 1` and `seed = 2`), `bounces = 8` across all bounce types (`diffuse`, `glossy`, `transmission`, `volume`, `transparent_max`), `caustics_reflective = True`, `caustics_refractive = True`, direct/indirect clamps `0.0`, `BOX` filter width `1.0`, undenoised, `Raw` linear float32 EXR + `.npy` `[measured]`:++| Scene | Triangles | `relMSE(A, B)` `[measured]` | `Seed 2 / Seed 1` Mean Ratio `(R, G, B)` | Eligible `8 × 8` Tiles (`mean > 0.01`) | Tile `[min, max]` | `FLIP_LDR(A, B)` | M1 `FLIP_LDR` Ceiling (`+0.02`) | `FLIP_HDR(A, B)` |+| --- | --- | --- | --- | --- | --- | --- | --- | --- |+| `spot-area` | `3,024` | `0.000009` | `[1.000005, 1.000009, 1.000011]` | `47 / 47` | `[0.9995, 1.0004]` | `0.003934` | **`0.023934`** | `0.008907` |+| `light-linking` | `5,988` | `0.000004` | `[1.000001, 1.000000, 0.999996]` | `64 / 64` | `[0.9998, 1.0001]` | `0.002808` | **`0.022808`** | `0.004260` |+| `metal` | `18,520` | `0.003399` | `[0.999676, 0.999708, 0.999790]` | `64 / 64` | `[0.9945, 1.0016]` | `0.003733` | **`0.023733`** | `0.004250` |+| `glass` | `12,156` | `0.000044` | `[0.999754, 0.999784, 0.999836]` | `64 / 64` | `[0.9838, 1.0004]` | `0.003390` | **`0.023390`** | `0.004339` |+| `outdoor-hdri` | `5,028` | `0.000007` | `[1.000001, 1.000002, 1.000002]` | `64 / 64` | `[1.0000, 1.0001]` | `0.001520` | **`0.021520`** | `0.001687` |+| `lit-interior` | `3,072` | `0.000285` | `[1.000022, 1.000047, 1.000045]` | `64 / 64` | `[0.9993, 1.0011]` | `0.016457` | **`0.036457`** | `0.018145` |++*Light-linking audit `[measured]`*: Direct-only (`bounces = 0`, `32` spp) Cycles 5.3 OptiX verification with `--part-ids` confirmed exact per-receiver isolation on `light-linking`: `sphere-left` (`Point-0` `[1.0, 0.35, 0.2]`) measured `meanRGB = [0.33204, 0.11935, 0.07027]`, symmetric `sphere-right` (`Point-1` `[0.2, 0.45, 1.0]`) measured `meanRGB = [0.08664, 0.15207, 0.33205]`, and `stage-floor` (`Point-2` neutral) measured `meanRGB = [0.07034, 0.07033, 0.07033]` (`maxRGB = [0.1329, 0.1329, 0.1329]`, zero red/blue leakage).++### Pre-M1 Legacy Kernel (`--kernel legacy`, `256` spp) Baseline Against M1 Gates++Scored against `Cycles 4096 Seed 1` with `--reference-b Cycles 4096 Seed 2` (`2 / 6` scenes pass, `4 / 6` fail before the Cook `cycles` kernel lands) `[measured]`:++| Scene | All Gates | Mean Ratio `(R, G, B)` (`±2%`) | `8 × 8` Tiles Within `±5%` | Tile `[min, max]` | `FLIP_LDR` | Ceiling | `relMSE` | Sampling (s) | Primary Pre-M1 Failure Cause `[source]` + `[measured]` |+| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |+| `spot-area` | **Pass** | `[1.0070, 1.0056, 1.0044]` | `47 / 47` | `[0.9812, 1.0231]` | `0.0231` | `0.0239` | `0.000863` | `1.007` | Within tolerance (analytic spot cone + rect area NEE) |+| `light-linking` | **Fail** | `[1.0115, 1.0107, 1.0115]` | `64 / 64` | `[0.9992, 1.0304]` | **`0.0243`** | `0.0228` | `0.000872` | `1.136` | Full-sphere `r = 0.1 m` point-light jitter + PCG grain |+| `metal` | **Fail** | `[0.9978, 0.9994, 0.9985]` | **`57 / 64`** | **`[0.9101, 1.1569]`** | **`0.0401`** | `0.0237` | `1.637659` | `1.369` | Missing F82 metallic tint, multiscatter GGX, and glossy sun/HDRI MIS |+| `glass` | **Fail** | `[1.0095, 1.0097, 1.0114]` | **`61 / 64`** | **`[0.8423, 1.2842]`** | **`0.0319`** | `0.0234` | `0.005463` | `1.317` | Missing full microfacet glass refraction Jacobian, multiscatter, and caustics |+| `outdoor-hdri` | **Pass** | `[1.0057, 1.0037, 1.0000]` | `64 / 64` | `[0.9981, 1.0208]` | `0.0173` | `0.0215` | `0.000287` | `0.491` | Open sky + `1°` sun NEE dominates smooth dielectric transport |+| `lit-interior` | **Fail** | `[1.0104, 1.0091, 1.0069]` | `64 / 64` | `[0.9832, 1.0282]` | **`0.0801`** | `0.0365` | `0.019762` | `1.173` | `6.3×` higher Monte Carlo variance without Light Tree + Tabulated Sobol |++---+## Reproducible CommandsRun from the repository root in PowerShell. Set `$env:BLENDER_BIN` if Blender 5.3 is installed outside `C:\Program Files\Blender Foundation\Blender 5.3\blender.exe`, and pass an untracked `<out-dir>` (such as `artifacts/cycles-parity`) so binary `.exr` and `.npy` files stay out of Git:@@ -212,23 +257,35 @@ $OutDir = "artifacts/cycles-parity"# 2. Build packages/render-native if build/render-native.node is not present yetnode packages/render-native/build.mjs-# 3. Export lit-interior scene JSON and verify byte-identical NativeTraceInput round-trip-node bench/cycles-parity/export-scene.mjs $OutDir --scene lit-interior+# 3. Export all 6 M1 reference scenes and verify byte-identical round-trip packing+foreach ($Scene in @("spot-area", "light-linking", "metal", "glass", "outdoor-hdri", "lit-interior")) {+ node bench/cycles-parity/export-scene.mjs $OutDir --scene $Scene+}-# 4. Run a single matched pair (Cycles 5.3 OptiX vs 67js render-native) through gpu-lock+# 4. Run a single matched pair (Cycles 5.3 OptiX vs Cook --kernel cycles) through gpu-lock& "C:\Program Files\Git\bin\bash.exe" $env:GPU_LOCK_SCRIPT `- uv run --no-project --with psutil python bench/cycles-parity/measure-gpu-run.py "$OutDir/single/cycles-256.metrics.json" -- `+ uv run --no-project --with psutil python bench/cycles-parity/measure-gpu-run.py "$OutDir/references/spot-area-cycles-4096-seed1.metrics.json" -- `$env:BLENDER_BIN -b --factory-startup --python bench/cycles-parity/render-cycles.py -- `- "$OutDir/scenes/lit-interior.json" "$OutDir/single/cycles-256" --samples 256 --bounces 8 --seed 1+ "$OutDir/scenes/spot-area.json" "$OutDir/references/spot-area-cycles-4096-seed1" --samples 4096 --bounces 8 --seed 1 --keep-exr& "C:\Program Files\Git\bin\bash.exe" $env:GPU_LOCK_SCRIPT `- uv run --no-project --with psutil python bench/cycles-parity/measure-gpu-run.py "$OutDir/single/native-256.metrics.json" -- `+ uv run --no-project --with psutil python bench/cycles-parity/measure-gpu-run.py "$OutDir/harness/spot-area-cycles-1024.metrics.json" -- `node bench/cycles-parity/trace-native.mjs `- "$OutDir/scenes/lit-interior.json" "$OutDir/single/native-256" --samples 256 --bounces 8 --seed 1 --firefly-clamp 1000000000 --noise-threshold 0+ "$OutDir/scenes/spot-area.json" "$OutDir/harness/spot-area-cycles-1024" --kernel cycles --samples 1024 --bounces 8 --seed 1++uv run --no-project --with numpy --with flip-evaluator python bench/cycles-parity/compare.py `+ --reference-b "$OutDir/references/spot-area-cycles-4096-seed2.npy" --summary `+ "$OutDir/references/spot-area-cycles-4096-seed1.npy" "$OutDir/harness/spot-area-cycles-1024.npy"++# 5. Run the 6-scene M1 parity suite and the Lobe White-Furnace + Pearson Chi-Square suite+uv run --no-project --with numpy --with flip-evaluator --with psutil python bench/cycles-parity/run-m1-parity.py `+ $OutDir --kernel cycles --samples 1024 --bounces 8 --seed 1 --json-out "$OutDir/harness/m1-parity-cycles-s1024.json"-uv run --no-project --with numpy python bench/cycles-parity/compare.py pair "$OutDir/single/cycles-256.npy" "$OutDir/single/native-256.npy"+& "C:\Program Files\Git\bin\bash.exe" $env:GPU_LOCK_SCRIPT node bench/cycles-parity/test-lobes.mjs "$OutDir/harness/lobes"+uv run --no-project --with numpy python bench/cycles-parity/verify-lobes.py "$OutDir/harness/lobes" --json-out "$OutDir/harness/lobes/verify-summary.json"+uv run --no-project --with numpy python bench/cycles-parity/verify-lobes.py --self-test-# 5. Run or re-score the full M0 reference + 3x back-to-back ladder suite (writes <out-dir>/lit-interior-summary.json)+# 6. Run or re-score the M0 reference + 3x back-to-back ladder suite (writes <out-dir>/lit-interior-summary.json)# Set GIT_BASH_BIN="C:\Program Files\Git\bin\bash.exe" and GPU_LOCK_SCRIPT="<path-to-gpu-lock.sh>" to wrap every GPU step automatically.uv run --no-project --with numpy --with psutil python bench/cycles-parity/run-m0-suite.py $OutDir --scene lit-interior --repeats 3 --bounces 8 --mode all```