Static ReadonlyDEFAULT_ReadonlydeviceReadonlyqueueReadonlycontextReadonlyformatReadonlydepthReadonlycanvasReadonlyhdrReadonlyenableReadonlyshaderReadonlyxrReadonlymaxReadonlyreversedSee RenderContextOptions.reversedZ. Read by passes/Camera to flip depth.
The camera that subsequent render passes will sample matrices from via
pass.updateCamera(ctx). Set this each frame (per camera, if multi-camera
later) after camera.updateRender(ctx). Null until first set.
Optional per-pass GPU timing. When set (and enabled), RenderGraph
brackets every render/compute pass with timestamp queries and accumulates
EMA-smoothed per-pass durations. Null by default — the caller creates one
via GpuProfiler.create(ctx.device) and assigns it. Costs nothing while
gpuProfiler.enabled === false.
Seconds since the first call to update. Updated every frame.
Seconds since the last call to update. Updated every frame.
Total frames rendered since creation. Incremented every frame by update.
Smoothed frames-per-second (EMA with alpha 0.1). Updated every frame by update.
Frames-per-second clamped to an integer. Updated every frame by update.
Whether the GPU device backing this context has been lost or destroyed.
Current dynamic-resolution scale (see setRenderScale).
Render width: the XR override when set, else the canvas width scaled by
renderScale. All scene/lighting/post passes size their targets to
this, so lowering renderScale renders the whole scene sub-native.
Render height — see width.
Display (presentation) width: the canvas backing-store size, unaffected by renderScale (the XR override stands in for the canvas under XR). The temporal upscaler resolves to this; the final blit / tonemap targets it.
Display (presentation) height — see displayWidth.
Depth value the main camera's depth buffer clears to: the FAR plane. 0 under
reversed-Z (far→0), 1 under standard-Z. Use this for depth attachment
clearValue/depthClearValue so a pass works in either mode.
Returns the swap chain texture for the current frame.
Returns the swap chain texture view for the current frame.
Returns the depth texture for the current frame, or null if depth is not enabled.
Returns the depth texture view for the current frame, or null if depth is not enabled.
Override the reported render size (see _renderSizeOverride); pass
null to revert to the canvas backing-store size. Used by the engine's
WebXR driver per eye.
Maps a standard-Z depth-compare function to the equivalent under the active mode.
Under reversed-Z, "nearer" is a GREATER depth, so 'less'→'greater' and
'less-equal'→'greater-equal'; other functions pass through. Pass the
standard-Z function you'd normally use; the result is what the pipeline should use.
Sign to multiply a "toward the camera" polygon depth-bias by, so the same
positive value nudges a fragment nearer the viewer under either Z mode.
Standard-Z: nearer = smaller depth → -1. Reversed-Z: nearer = larger depth
→ +1. Multiply both depthBias and depthBiasSlopeScale by this when
building a pipeline (e.g. draped overlays that must win the depth test against
coincident terrain behind them). See Material.depthBias.
Call each frame to detect canvas resizes and update the backbuffer depth texture accordingly.
Also updates deltaTime, elapsedTime, frameCount, framesPerSecond and fps.
true if a resize was detected and handled, false otherwise.
StaticcreateRequests a WebGPU adapter and device, configures the canvas swap chain and returns a ready-to-use context.
Attempts an HDR (rgba16float + display-p3 + extended tonemapping) swap
chain and falls back to the preferred SDR format if unsupported.
canvas to bind the swap chain to
optional context configuration
initialized render context
StaticcreateBuild a second RenderContext for another canvas that SHARES the GPU device of an existing context, rather than requesting a fresh adapter/device.
WebGPU allows one device to drive multiple canvas contexts, and GPU
resources (buffers, textures) are only usable on the device that created
them — so a picture-in-picture / preview canvas that renders an
already-loaded scene MUST share the primary context's device. Use this for
any secondary view of a scene whose GPU resources live on base.
Reuses base's surface format and HDR flag so the two contexts are
pipeline-compatible (render pipelines are keyed on the surface format).
Creates a GPU shader module from the provided WGSL code.
WGSL shader code
Optionallabel: stringoptional debug label
Optionaldefines: Record<string, string>optional preprocessor defines for shader block imports
GPUShaderModule instance
Creates a render pipeline via the async WebGPU API. Prefer this for
one-time (boot/setup) pipeline creation: async compiles run on the
driver's background threads and overlap each other, while the sync
createRenderPipeline serializes on the device's command stream — with a
large feature roster boot then pays the sum of every compile instead of
roughly the slowest one.
Errors: a validation failure rejects the async call (it does not reach device error scopes). To preserve the sync path's log-and-continue semantics this logs the failure and falls back to the sync variant, whose invalid pipeline surfaces the same error through the device's regular error handling at first use.
Compute-pipeline counterpart of createRenderPipelineAsync; same rationale and error semantics.
Registers a shader block for later use in shader modules.
unique identifier for the shader block
WGSL code of the shader block
Removes a previously registered shader block by name.
name of the shader block to remove
Retrieves the WGSL code for a registered shader block by name.
name of the shader block
Optionaldefines: Record<string, string>WGSL code of the shader block, or a placeholder comment if not found
Convenience wrapper around device.createBuffer.
buffer size in bytes
usage flags
Optionallabel: stringoptional debug label
Uploads CPU data into a GPU buffer, handling both ArrayBuffer and typed-array sources.
destination GPU buffer
source bytes to copy
destination byte offset
Pushes a validation error scope used during one-time resource initialization. No-op when error handling is disabled.
Pops the matching init error scope and logs any validation failure.
identifier included in the log message
Pushes a per-frame validation error scope. No-op when error handling is disabled or the device has been lost.
Pops the matching per-frame error scope and logs any validation failure.
Pushes nested validation, out-of-memory and internal error scopes around a single render pass. No-op when error handling is disabled or the device has been lost.
pass identifier (currently unused; reserved for diagnostics)
Pops the three pass-level error scopes pushed by pushPassErrorScope and logs any captured errors.
pass identifier included in log messages
Convenience method to create a 1x1 cubemap texture with a neutral gray color, used as a fallback when IBL textures fail to load.
Convenience method to create a 1x1 BRDF LUT texture with a neutral value, used as a fallback when IBL textures fail to load.
Owns the WebGPU device, queue and canvas configuration for the renderer.
Acts as the single shared handle to GPU resources, and exposes helpers for buffer creation, swap-chain access and scoped validation error capture.