3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into 895-cook-sampler-light-tree
Nguyen Xuan Anc46960b844fb
diff --cc bench/cycles-parity/trace-native.mjsindex c9963971,2cb055bd..265c0095--- a/bench/cycles-parity/trace-native.mjs+++ b/bench/cycles-parity/trace-native.mjs@@@ -197,11 -168,12 +197,12 @@@ async function runCli()samples: options.samples,averageSamples: traced.averageSamples,samplesPerDispatch: traced.samplesPerDispatch ?? null,+ longestDispatchSeconds: traced.longestDispatchSeconds ?? null,bounces: options.bounces,seed: options.seed,- sampler: options.sampler,- lightTree: options.lightTree,filterType: options.filterType,+ sampler: options.sampler,+ lightSampling: options.lightSampling,filterWidth: options.filterWidth,clampDirect: options.clampDirect,clampIndirect: options.clampIndirect,diff --cc packages/render-native/README.mdindex c4f684f6,47c1914c..6cb1144a--- a/packages/render-native/README.md+++ b/packages/render-native/README.md@@@ -32,4 -32,8 +32,8 @@@ const { radiance, escaped } = traceNati`radiance` is the mean light that reaches each texel (three floats per texel) and `escaped` the share of first rays that left the scene. The agent runtime uses it for recipe bakes (`bake.backend: "native"`).-Cook's sampler is an Owen-scrambled Sobol sequence (Burley 2020); `sampler: 'pcg'` selects the earlier white-noise hash. Lights are picked through a light tree (Conty and Kulla 2018) when a kind, analytic lights or emissive triangles, holds more than 8 emitters, no sun is among the lights and no instance restricts its light group; `useLightTree: true` forces it and `false` turns it off. Both change only the noise pattern of the image, not its mean. The pixel filter stays `box` unless `filterType: 'blackman-harris'` is passed ([FORMAT-v2.md](./FORMAT-v2.md)).+Cook's `cycles` kernel samples with Cycles' Sobol-Burley blue-noise pattern (`sampler: 'sobol-burley'`, default; `'white'` keeps the earlier hash sampler, and `'pcg'` and `'sobol'` are other names for `'white'` and `'sobol-burley'`). It picks lights through the Cycles light tree over the analytic lights, a sun and the emissive triangles (`lightSampling: 'auto'`, default: tree from more than one emitter; `'tree'`; `'uniform'` for the flat pick, and `useLightTree: true|false` is another name for `'tree'|'uniform'`). Naming an option twice with different values is an error. The pixel filter is `box` unless `filterType` says otherwise. Details and measurements: [docs/cycles-parity.md](../../docs/cycles-parity.md), layout: [FORMAT-v2.md](./FORMAT-v2.md).++ ## Dispatches++ The Cook kernel splits a render into dispatches that each aim for about 0.5 s, sized from the time of the previous one, so a heavy scene does not run past the driver timeout and lose the device. `samplesPerDispatch` fixes the batch instead. A lost device raises an error that names the dispatch and how to lower the work per dispatch. The split is tested in `tests/dispatch.rs` (`cargo test --test dispatch`).diff --cc packages/render-native/src/host/session.rsindex e4ed2467,9d877509..aab00315--- a/packages/render-native/src/host/session.rs+++ b/packages/render-native/src/host/session.rs@@@ -115,12 -118,24 +118,26 @@@ fn get_cached_device() -> Result<(wgpu:let (device, queue, adapter_info) = open_device()?;let device_lost = Arc::new(AtomicBool::new(false));let lost_flag = Arc::clone(&device_lost);- device.set_device_lost_callback(move |_reason, _message| {+ let device_error = Arc::new(Mutex::new(String::new()));+ let lost_message = Arc::clone(&device_error);+ device.set_device_lost_callback(move |reason, message| {+ if let Ok(mut stored) = lost_message.lock() {+ *stored = format!("{reason:?}: {message}");+ }lost_flag.store(true, Ordering::SeqCst);});+ // The default handler panics on a lost device; record the report so the render can raise a readable error.+ let error_flag = Arc::clone(&device_lost);+ let error_message = Arc::clone(&device_error);+ device.on_uncaptured_error(Arc::new(move |error: wgpu::Error| {+ if let Ok(mut stored) = error_message.lock() {+ stored.push_str(&error.to_string());+ }+ error_flag.store(true, Ordering::SeqCst);+ }));- let lut_bytes: &[u8] = bytemuck::cast_slice(&CYCLES_LUT_WORDS[..]);+ let mut lut_words: Vec<u32> = CYCLES_LUT_WORDS.to_vec();+ lut_words.extend(unit_filter_table_words());+ let lut_bytes: &[u8] = bytemuck::cast_slice(&lut_words);let lut_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {label: Some("cycles LUT binding 12"),contents: lut_bytes,