3D engine that AI agents drive
Merge main into the session jobs branch: sequences take instanced exports and a failed export starts a new sequence (#896)
Nguyen Xuan An196dc1eb9844
diff --cc scripts/agent-native-trace.mjsindex c92dc960,bbef0f1c..251908c8--- a/scripts/agent-native-trace.mjs+++ b/scripts/agent-native-trace.mjs@@@ -159,17 -189,13 +189,18 @@@ export async function denoiseFrameWithO/*** Traces one frame the page exported and returns the PNG (base64) with the job report. `denoise` is "none", "wavelet",* "atrous" (the tracer's GPU filter, which is also where a missing or failing OIDN lands) or "oidn"; `denoiser` is the- * loaded OIDN package for "oidn". Throws when the tracer cannot run, so the caller can fall back.+ * loaded OIDN package for "oidn". `sequence` (from createNativeSequence) renders a cycles kernel frame through the job's+ * persistent session and adds `report.nativeSession`, the route the frame took. Throws when the tracer cannot run, so the+ * caller can fall back.*/-export async function traceFrameNative({ tracer, exported, width, height, samples, bounces, seed, denoise, denoiser, maxSeconds, noiseThreshold = 0, kernel = chooseNativeKernel() }) {+export async function traceFrameNative({ tracer, exported, width, height, samples, bounces, seed, denoise, denoiser, maxSeconds, noiseThreshold = 0, kernel = chooseNativeKernel(), sequence }) {const started = performance.now();const filtersInTrace = denoise === 'atrous' && kernel === 'cycles';+ const tables = decodeTables(exported);- const traced = tracer.traceNative(tables, { width, height, samples, maxSeconds, kernel, noiseThreshold, ...(filtersInTrace ? { denoise: 'atrous' } : {}) });+ const traceOptions = { width, height, samples, maxSeconds, kernel, noiseThreshold, ...(filtersInTrace ? { denoise: 'atrous' } : {}) };+ const { traced, route } = sequence && kernel === 'cycles'- ? sequence.trace(decodeTables(exported), traceOptions)- : { traced: tracer.traceNative(decodeTables(exported), traceOptions) };++ ? sequence.trace(tables, traceOptions)++ : { traced: tracer.traceNative(tables, traceOptions) };const tracedSeconds = (performance.now() - started) / 1000;const pixelCount = width * height;const features = { color: withoutAlpha(traced.rgba, pixelCount), albedo: traced.albedo, normal: traced.normal,@@@ -178,8 -204,8 +209,9 @@@const report = { width, height, samples, bounces, seed, denoised: false, denoiser: 'none', threads: 1, backend: 'native',gpu: traced.adapter, nativeBackend: traced.backend, nativeFeatures: traced.features, setupSeconds: traced.setupSeconds, compileSeconds: traced.compileSeconds,uploadSeconds: traced.uploadSeconds, accelerationBuildSeconds: traced.accelerationBuildSeconds,- kernel, averageSamples: traced.averageSamples ?? samples, noiseThreshold, triangles: exported.triangles, tracedSeconds, ignored: exported.ignored,+ kernel, averageSamples: traced.averageSamples ?? samples, noiseThreshold, triangles: exported.triangles, inputBytes: tableBytes(tables), ...(exported.instances === undefined ? {} : { instances: exported.instances }),- ...(exported.instancing === undefined ? {} : { instancing: exported.instancing, instancingReason: exported.instancingReason }), tracedSeconds, ignored: exported.ignored };++ ...(exported.instancing === undefined ? {} : { instancing: exported.instancing, instancingReason: exported.instancingReason }), tracedSeconds, ignored: exported.ignored,+ ...(route ? { nativeSession: route } : {}) };let linear = features.color;const denoiseStarted = performance.now();if (denoise === 'oidn') {diff --cc scripts/agent-runtime.mjsindex 138b4975,010f69df..c5caa7d3--- a/scripts/agent-runtime.mjs+++ b/scripts/agent-runtime.mjs@@@ -15,8 -15,7 +15,8 @@@ import { MATERIAL_SNIPPET_CAPABILITIESimport { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS, MAXIMUM_JOB_SIDE, MAXIMUM_JOB_PIXELS, MAXIMUM_MEMORY_MIB, BAKE_WORKER_MAXIMUM_SECONDS } from '../src/agent-scene-capabilities.js';import { PATH_TRACER_CAPABILITIES } from '../src/path-tracer-capabilities.js';import { chooseDenoiser, finishWithOidn } from './agent-path-trace-denoise.mjs';+import { createNativeSequence } from './agent-native-sequence.mjs';- import { chooseTraceBackend, createNativeTracerLocator, isNativeTimeLimitError, traceFrameNative, traceTexelsNative } from './agent-native-trace.mjs';+ import { chooseNativeInstancing, chooseTraceBackend, createNativeTracerLocator, isNativeTimeLimitError, traceFrameNative, traceTexelsNative } from './agent-native-trace.mjs';import { createAgentAssetCatalog } from './agent-asset-catalog.mjs';import { geometryOnlyGlb } from './agent-query-asset.mjs';import { AGENT_ASSET_LIMITS, assertCombinedAssetBytes } from '../src/agent-asset-limits.js';@@@ -567,18 -564,19 +567,22 @@@ export function createAgentRuntime({ kelet traced;let backendNote = trace.note;if (trace.backend === 'native') {+ let exportedScene = false;try {- const exported = await jobPage.evaluate(input => window.__agentPreview.exportNativeScene(input), { ...frameInput, options: { width, height, bounces: tracerOptions.bounces, seed: tracerOptions.seed, fireflyClamp: 20, noiseThreshold: tracerOptions.noiseThreshold } });+ const exported = await jobPage.evaluate(input => window.__agentPreview.exportNativeScene(input), { ...frameInput, options: { width, height, bounces: tracerOptions.bounces, seed: tracerOptions.seed, fireflyClamp: 20, noiseThreshold: tracerOptions.noiseThreshold, instancing: chooseNativeInstancing() } });+ exportedScene = true;- traced = await traceFrameNative({ tracer: trace.tracer, exported, width, height, samples: tracerOptions.samples, bounces: tracerOptions.bounces,+ if (settings.frameCount > 1 && process.env.JS67_NATIVE_SESSIONS !== 'off') nativeSequence ??= createNativeSequence({ tracer: trace.tracer });+ traced = await traceFrameNative({ tracer: trace.tracer, sequence: nativeSequence, exported, width, height, samples: tracerOptions.samples, bounces: tracerOptions.bounces,seed: tracerOptions.seed, denoise: choice.denoise === true ? 'wavelet' : choice.denoise === false ? 'none' : choice.denoise, denoiser: choice.denoiser,maxSeconds: tracerOptions.maxSeconds, noiseThreshold: tracerOptions.noiseThreshold });} catch (error) {// Past maxSeconds the job fails as it does on every backend; falling back would only run it twice as long.if (isNativeTimeLimitError(error)) throw error;+ nativeSequence?.close();- nativeTracerLocator.markUnusable(error.message);- backendNote = (await nativeTracerLocator.find()).reason;++ nativeSequence = undefined;+ // Only a tracer or adapter failure makes the tracer unusable; a scene that failed to export says so for this job alone.+ if (exportedScene) nativeTracerLocator.markUnusable(error.message);+ backendNote = exportedScene ? (await nativeTracerLocator.find()).reason : `renderer.backend "native" could not export the scene (${error.message}).`;traceOptions.backend = backend === 'cpu' ? 'cpu' : 'gpu';choice = await chooseDenoiser(settings.renderer.denoise);traceOptions.denoise = choice.denoise;