Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Bound the image side of an in-process OIDN call and fix the comparison usage line (#1025)

Nguyen Xuan Andc8e95ae3438
diff --git a/bench/cycles-parity/trace-native.mjs b/bench/cycles-parity/trace-native.mjs
index 4cea383e..c3b15929 100644
--- a/bench/cycles-parity/trace-native.mjs
+++ b/bench/cycles-parity/trace-native.mjs
@@ -114,7 +114,7 @@ function parseLightSamplingOption(argumentList) {
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> [--kernel legacy|cycles] [--samples 256] [--bounces 8] [--transparent-bounces 8] [--seed 1] [--width 960] [--height 540] [--sampler white|sobol-burley] [--light-sampling auto|tree|uniform] [--path-regeneration] [--env-compensation 0..1] [--filter-type box|gaussian|blackman-harris] [--filter-width 1.0] [--clamp-direct 0] [--clamp-indirect 0] [--firefly-clamp 1e9] [--noise-threshold 0] [--denoise none|wavelet|atrous] [--oidn-devices cpu,cuda] [--grey-diffuse] [--write-depth]');
+ throw new RangeError('Usage: node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--kernel legacy|cycles] [--samples 256] [--bounces 8] [--transparent-bounces 8] [--seed 1] [--width 960] [--height 540] [--sampler white|sobol-burley] [--light-sampling auto|tree|uniform] [--path-regeneration] [--env-compensation 0..1] [--filter-type box|gaussian|blackman-harris] [--filter-width 1.0] [--clamp-direct 0] [--clamp-indirect 0] [--firefly-clamp 1e9] [--noise-threshold 0] [--denoise none|wavelet|atrous] [--oidn-devices cpu,cuda,cpu-cli,cuda-cli] [--grey-diffuse] [--write-depth]');
}
return {
sceneJsonPath: resolve(argumentList[0]),
diff --git a/docs/cycles-parity.md b/docs/cycles-parity.md
index ecc9fe9c..dd2f36bb 100644
--- a/docs/cycles-parity.md
+++ b/docs/cycles-parity.md
@@ -834,7 +834,7 @@ The tool call also spends 0.010 / 0.007 s encoding and writing PFM files and 0.0
Output: the in-process image equals the tool's image byte for byte (maximum absolute difference 0) on all four rows, the first call equals a warm call, and so does the call after a size change and back. Resizing recommits the filter; warm calls never do.
-Equal total time on `lit-interior` and `many-lights-500` (same container, 3 rounds, seed 3, medians): the in-process CUDA denoise costs 0.008 s against 0.34 to 0.38 s for the tool, so the total of Cook + OIDN falls from 0.56 to 0.23 s at 16 spp on `lit-interior`, with the same relMSE (3.09e-4) as the tool path. The in-process CPU device costs 0.047 s against 0.22 s. The table is in the pull request.
+Equal total time on `lit-interior` and `many-lights-500` (same container, 3 rounds, seed 3, medians): the in-process CUDA denoise costs 0.008 s against 0.34 to 0.38 s for the tool, so the total of Cook + OIDN falls from 0.56 to 0.23 s at 16 spp on `lit-interior`, with the same relMSE (3.09e-4) as the tool path. The in-process CPU device costs 0.047 s against 0.22 s.
## Depth and grey-diffuse comparison (#896, slice C1a)
diff --git a/packages/render-native/src/host/oidn.rs b/packages/render-native/src/host/oidn.rs
index c3ee6fcc..3567910c 100644
--- a/packages/render-native/src/host/oidn.rs
+++ b/packages/render-native/src/host/oidn.rs
@@ -19,6 +19,8 @@ type Handle = *mut c_void;
const FORMAT_FLOAT3: c_int = 3;
const BYTES_PER_PIXEL: usize = 12;
+// Keeps width * height * 12 far below the range of usize, so the length checks cannot wrap.
+const MAXIMUM_IMAGE_SIDE: usize = 65_536;
const ERROR_NONE: c_int = 0;
const DEVICE_NAMES: [(&str, c_int); 6] = [("default", 0), ("cpu", 1), ("sycl", 2), ("cuda", 3), ("hip", 4), ("metal", 5)];
@@ -265,10 +267,13 @@ impl OidnDenoiser {
}
let width = call.width as usize;
let height = call.height as usize;
- let floats = width * height * 3;
if width == 0 || height == 0 {
return Err(failure("OIDN denoise needs a width and height of at least 1."));
}
+ if width > MAXIMUM_IMAGE_SIDE || height > MAXIMUM_IMAGE_SIDE {
+ return Err(failure(format!("OIDN denoise takes a width and height of at most {MAXIMUM_IMAGE_SIDE}; got {width} by {height}.")));
+ }
+ let floats = width * height * 3;
if call.normal.is_some() && call.albedo.is_none() {
return Err(failure("OIDN takes a normal guide only together with an albedo guide: pass albedo too, or drop normal."));
}