/** * One-call WebGPU renderer construction for VLAM! scenes. * * Every host needs the same four things right - adapter, device, raised limits * and the platform-dependent `powerPreference` - and getting any of them wrong * fails *late*: past ~8.4 M unified splats, or with MSAA silently dropped. * {@link createWebGPURenderer} is that block, once. * * The primitives it composes ({@link recommendedWebGpuRequiredLimits}, * {@link webGpuPowerPreferenceOptions}) stay exported for hosts that own device * creation themselves - an XR session sharing a device, say. */ import { WebGPURenderer, type WebGPURendererParameters } from 'three/webgpu'; import { type WebGpuPowerPreference } from './webgpu-limits'; /** The device handle `createWebGPURenderer` hands to `WebGPURenderer`. */ export interface WebGPURendererGpuDevice { readonly features: ReadonlySet; } /** The adapter surface `createWebGPURenderer` reads limits and features from. */ export interface WebGPURendererGpuAdapter { readonly features: ReadonlySet; /** Chrome 130+ reports a software adapter here. */ readonly info?: { readonly isFallbackAdapter?: boolean; }; /** Older Chromium builds report a software adapter on the adapter itself. */ readonly isFallbackAdapter?: boolean; readonly limits: { readonly maxStorageBufferBindingSize: number; readonly maxBufferSize: number; readonly maxTextureDimension2D?: number; }; requestDevice(descriptor?: { requiredFeatures?: readonly string[]; requiredLimits?: Record; }): Promise; } /** The `navigator.gpu` surface `createWebGPURenderer` probes. */ export interface WebGPURendererGpu { requestAdapter(options?: { powerPreference?: WebGpuPowerPreference; xrCompatible?: boolean; }): Promise; } /** * Options for {@link createWebGPURenderer}. * * Everything `THREE.WebGPURenderer` accepts passes straight through - * `antialias`, `forceWebGL`, `trackTimestamp`, `canvas`, `alpha`, `samples`, * `getFallback`, … - except the three members the helper owns (`device`, * `requiredLimits`, and `powerPreference`, which is widened here to allow * `null`). */ export interface CreateWebGPURendererOptions extends Omit { /** * Adapter/renderer power hint. Omitted automatically on Windows, where Chrome * ignores it and warns ([crbug.com/369219127](https://crbug.com/369219127)). * Pass `null` to never send it. * * @defaultValue `'high-performance'` */ powerPreference?: WebGpuPowerPreference | null; /** * Request an adapter whose device can be used by an immersive WebXR session. * This must be selected before `requestDevice`; an existing device cannot be * made XR-compatible later. * * @defaultValue `false` */ xrCompatible?: boolean; /** * Throw instead of degrading to three's WebGL2 backend. Adapter and device * failures rethrow their original error, unwrapped. * * @defaultValue `false` */ requireWebGpu?: boolean; /** * Treat a software (fallback) adapter, such as SwiftShader, as no adapter * and use three's WebGL2 backend instead. Chromium offers only a software * adapter on GPUs outside its WebGPU allowlist (common on Linux); splats on * it hang or render black, while WebGL2 on the same machine still reaches * the real GPU. With {@link requireWebGpu} set, a fallback adapter throws. * * @defaultValue `false` */ rejectFallbackAdapter?: boolean; /** * The WebGPU entry point to probe. Defaults to `navigator.gpu`; pass `null` * to skip the probe entirely (tests, non-DOM hosts). */ gpu?: WebGPURendererGpu | null; } /** * Optional convenience for creating a standard `THREE.WebGPURenderer` with * raised WebGPU limits. `SplatMesh` also works with a renderer constructed * directly by the application; this function does not return a VLAM-specific * renderer. * * ### What the helper adds * * | Call | Added parameters | * | --- | --- | * | `navigator.gpu.requestAdapter` | `powerPreference: 'high-performance'`, except on Windows where Chrome ignores it and warns; `xrCompatible: true` when requested | * | `adapter.requestDevice` | Every advertised adapter feature as `requiredFeatures`, plus `maxStorageBufferBindingSize`, `maxBufferSize`, and `maxTextureDimension2D` at the adapter's advertised maxima as `requiredLimits` | * | `new THREE.WebGPURenderer` | `antialias: true`, the supported `powerPreference`, and the requested `device` (or just the raised `requiredLimits` when device creation failed and Three.js must retry); caller options can override `antialias` | * * These settings matter late rather than loudly. Without the limits, large * unified or streamed scenes throw past ~8.4 M splats. Without * `core-features-and-limits` among the requested features, three treats the * backend as compatibility-mode and **silently drops MSAA** - which is why the * device is requested here rather than left to `WebGPUBackend.init`. Owning the * request also keeps the real failure: three's `getFallback` hook logs a flat * "WebGPU is not available" and drops the cause. * * Degrades to three's WebGL2 backend exactly as an unconfigured * `new THREE.WebGPURenderer()` would, warning through * {@link setVlamLogHandler} when the cause was a fixable failure rather than a * browser without WebGPU. Pass `requireWebGpu: true` to throw instead. * * Does **not** call `setSize`, `renderer.init()`, or append the canvas - those * stay in host code - and does not touch `outputColorSpace`, whose three.js * default (sRGB) is already what the splat shader expects. * * ### Manual equivalent * * Applications that own renderer or device creation can apply the same * successful WebGPU setup themselves. The two exported helpers keep the exact * limit selection and Windows `powerPreference` behavior reusable: * * ```ts * import * as THREE from 'three/webgpu'; * import { * recommendedWebGpuRequiredLimits, * webGpuPowerPreferenceOptions, * } from '@voluma/vlam'; * * const powerOptions = webGpuPowerPreferenceOptions('high-performance'); * const adapter = await navigator.gpu?.requestAdapter(powerOptions); * if (!adapter) throw new Error('WebGPU is unavailable.'); * * const requiredLimits = recommendedWebGpuRequiredLimits(adapter); * const device = await adapter.requestDevice({ * requiredFeatures: [...adapter.features], * requiredLimits, * }); * * const renderer = new THREE.WebGPURenderer({ * antialias: true, * ...powerOptions, * device, * }); * // Keep `adapter` on an ordinary JS object for as long as `device` is * // (the renderer, not only the GPUDevice host object). Chromium can reject * // three's pipeline-validation `popErrorScope` with "Instance dropped" if the * // adapter is collected first. * ``` * * That version deliberately leaves failure policy to the application. This * helper instead falls back to Three.js device creation or WebGL2 unless * `requireWebGpu` is set, and routes recoverable warnings through * {@link setVlamLogHandler}. * * @example * const renderer = await createWebGPURenderer(); * renderer.setSize(innerWidth, innerHeight); * document.body.appendChild(renderer.domElement); * * @throws {TypeError} if `requireWebGpu` and `forceWebGL` are both set. */ export declare function createWebGPURenderer(options?: CreateWebGPURendererOptions): Promise; /** * Whether a renderer runs on three's WebGPU backend, as opposed to its WebGL2 * fallback. Valid after `renderer.init()`; before that the backend is not * chosen yet and this returns `false`. */ export declare function isWebGpuBackend(renderer: Pick): boolean;