Skip to main content

Abstract Class: Device

Defined in: modules/core/src/adapter/device.ts:494

WebGPU Device/WebGL context abstraction

Constructors

Constructor

new Device(props): Device

Defined in: modules/core/src/adapter/device.ts:553

Parameters

props

DeviceProps

Returns

Device

Properties

_factories

_factories: DeviceFactories = {}

Defined in: modules/core/src/adapter/device.ts:524

Internal per-device factory storage


_reused

_reused: boolean = false

Defined in: modules/core/src/adapter/device.ts:529

True if this device has been reused during device creation (app has multiple references)


canvasContext

abstract canvasContext: CanvasContext | null

Defined in: modules/core/src/adapter/device.ts:722

Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext


commandEncoder

abstract commandEncoder: CommandEncoder

Defined in: modules/core/src/adapter/device.ts:515


features

abstract features: DeviceFeatures

Defined in: modules/core/src/adapter/device.ts:538

Optional capability discovery


handle

abstract readonly handle: unknown

Defined in: modules/core/src/adapter/device.ts:514


id

readonly id: string

Defined in: modules/core/src/adapter/device.ts:511

id of this device, primarily for debugging


info

abstract info: DeviceInfo

Defined in: modules/core/src/adapter/device.ts:536

Information about the device (vendor, versions etc)


lost

abstract readonly lost: Promise<{ message: string; reason: "destroyed"; }>

Defined in: modules/core/src/adapter/device.ts:655

Promise that resolves when device is lost


preferredColorFormat

abstract preferredColorFormat: "rgba8unorm" | "bgra8unorm" | "rgba16float"

Defined in: modules/core/src/adapter/device.ts:545

Optimal presentation format, including rgba16float for high-dynamic-range canvases.


preferredDepthFormat

abstract preferredDepthFormat: "depth24plus" | "depth32float" | "depth16"

Defined in: modules/core/src/adapter/device.ts:547

Default depth format used on this system


props

readonly props: Required<DeviceProps>

Defined in: modules/core/src/adapter/device.ts:518

A copy of the device props


statsManager

readonly statsManager: StatsManager = lumaStats

Defined in: modules/core/src/adapter/device.ts:522

stats


timestamp

timestamp: number = 0

Defined in: modules/core/src/adapter/device.ts:526

An abstract timestamp used for change tracking


type

abstract readonly type: "webgl" | "webgpu" | "null" | "unknown"

Defined in: modules/core/src/adapter/device.ts:513

type of this device


userData

userData: object = {}

Defined in: modules/core/src/adapter/device.ts:520

Available for the application to store data on the device

Index Signature

[key: string]: unknown


defaultProps

static defaultProps: Required<DeviceProps>

Defined in: modules/core/src/adapter/device.ts:495

Accessors

[toStringTag]

Get Signature

get [toStringTag](): string

Defined in: modules/core/src/adapter/device.ts:497

Returns

string


isLost

Get Signature

get abstract isLost(): boolean

Defined in: modules/core/src/adapter/device.ts:652

true if device is already lost

Returns

boolean


limits

Get Signature

get abstract limits(): DeviceLimits

Defined in: modules/core/src/adapter/device.ts:540

WebGPU style device limits

Returns

DeviceLimits

Methods

_createBindGroupLayoutWebGPU()

_createBindGroupLayoutWebGPU(_pipeline, _group): unknown

Defined in: modules/core/src/adapter/device.ts:829

Internal WebGPU-only helper for retrieving the native bind-group layout for a pipeline group.

Parameters

_pipeline

RenderPipeline | ComputePipeline

_group

number

Returns

unknown


_createBindGroupWebGPU()

_createBindGroupWebGPU(_bindGroupLayout, _shaderLayout, _bindings, _group, _label?): unknown

Defined in: modules/core/src/adapter/device.ts:837

Internal WebGPU-only helper for creating a native bind group.

Parameters

_bindGroupLayout

unknown

_shaderLayout

ShaderLayout | ComputeShaderLayout

_bindings

Bindings

_group

number

_label?

string

Returns

unknown


_createSharedRenderPipelineWebGL()

_createSharedRenderPipelineWebGL(_props): SharedRenderPipeline

Defined in: modules/core/src/adapter/device.ts:824

Internal helper for creating a shareable WebGL render-pipeline implementation.

Parameters

_props

RenderPipelineProps

Returns

SharedRenderPipeline


_disableDebugGPUTime()

_disableDebugGPUTime(): void

Defined in: modules/core/src/adapter/device.ts:890

Internal helper that disables device-managed GPU timing collection and restores the default command encoder to an unprofiled state.

Returns

void


_enableDebugGPUTime()

_enableDebugGPUTime(queryCount?): QuerySet | null

Defined in: modules/core/src/adapter/device.ts:864

Internal helper that enables device-managed GPU timing collection on the default command encoder. Reuses the existing query set if timing is already enabled.

Parameters

queryCount?

number = 256

Number of timestamp slots reserved for profiled passes.

Returns

QuerySet | null

The device-managed timestamp QuerySet, or null when timing is not supported or could not be enabled.


_isDebugGPUTimeEnabled()

_isDebugGPUTimeEnabled(): boolean

Defined in: modules/core/src/adapter/device.ts:906

Internal helper that returns true when device-managed GPU timing is currently active.

Returns

boolean


_supportsDebugGPUTime()

_supportsDebugGPUTime(): boolean

Defined in: modules/core/src/adapter/device.ts:851

Internal helper that returns true when timestamp-query GPU timing should be collected for this device.

Returns

boolean


beginComputePass()

beginComputePass(props?): ComputePass

Defined in: modules/core/src/adapter/device.ts:796

Create a ComputePass using the default CommandEncoder

Parameters

props?

ComputePassProps

Returns

ComputePass


beginRenderPass()

beginRenderPass(props?): RenderPass

Defined in: modules/core/src/adapter/device.ts:791

Create a RenderPass using the default CommandEncoder

Parameters

props?

RenderPassProps

Returns

RenderPass


clearWebGL()

clearWebGL(options?): void

Defined in: modules/core/src/adapter/device.ts:980

Parameters

options?
color?

any

depth?

any

framebuffer?

Framebuffer

stencil?

any

Returns

void

Deprecated

  • will be removed - should use clear arguments in RenderPass

createBuffer()

abstract createBuffer(props): Buffer

Defined in: modules/core/src/adapter/device.ts:744

Create a buffer

Parameters

props

ArrayBuffer | ArrayBufferView<ArrayBufferLike> | BufferProps

Returns

Buffer


createCanvasContext()

abstract createCanvasContext(props?): CanvasContext

Defined in: modules/core/src/adapter/device.ts:733

Creates a new CanvasContext (WebGPU only)

Parameters

props?

CanvasContextProps

Returns

CanvasContext


createCommandEncoder()

abstract createCommandEncoder(props?): CommandEncoder

Defined in: modules/core/src/adapter/device.ts:778

Parameters

props?

CommandEncoderProps

Returns

CommandEncoder


createComputePipeline()

abstract createComputePipeline(props): ComputePipeline

Defined in: modules/core/src/adapter/device.ts:765

Create a compute pipeline (aka program). WebGPU only.

Parameters

props

ComputePipelineProps

Returns

ComputePipeline


createExternalTexture()

abstract createExternalTexture(props): ExternalTexture

Defined in: modules/core/src/adapter/device.ts:750

Create a temporary external texture binding when available on this backend.

Parameters

props

ExternalTextureProps

Returns

ExternalTexture


createFence()

createFence(): Fence

Defined in: modules/core/src/adapter/device.ts:786

Create a fence sync object

Returns

Fence


createFramebuffer()

abstract createFramebuffer(props): Framebuffer

Defined in: modules/core/src/adapter/device.ts:756

Create a Framebuffer. Must have at least one attachment.

Parameters

props

FramebufferProps

Returns

Framebuffer


createPresentationContext()

abstract createPresentationContext(props?): PresentationContext

Defined in: modules/core/src/adapter/device.ts:736

Creates a presentation context for a destination canvas. WebGL requires the default canvas context to use an OffscreenCanvas.

Parameters

props?

CanvasContextProps

Returns

PresentationContext


createQuerySet()

abstract createQuerySet(props): QuerySet

Defined in: modules/core/src/adapter/device.ts:783

Parameters

props

QuerySetProps

Returns

QuerySet


createRenderBundleEncoder()

abstract createRenderBundleEncoder(props?): RenderBundleEncoder

Defined in: modules/core/src/adapter/device.ts:773

Creates an encoder for reusable WebGPU draw commands.

Parameters

props?

RenderBundleEncoderProps

Resource metadata and render-attachment compatibility requirements.

Returns

RenderBundleEncoder

A render bundle encoder that records without beginning a render pass.

Throws

On backends other than WebGPU.


createRenderPipeline()

abstract createRenderPipeline(props): RenderPipeline

Defined in: modules/core/src/adapter/device.ts:762

Create a render pipeline (aka program)

Parameters

props

RenderPipelineProps

Returns

RenderPipeline


createSampler()

abstract createSampler(props): Sampler

Defined in: modules/core/src/adapter/device.ts:753

Create a sampler

Parameters

props

SamplerProps

Returns

Sampler


createShader()

abstract createShader(props): Shader

Defined in: modules/core/src/adapter/device.ts:759

Create a shader

Parameters

props

ShaderProps

Returns

Shader


createTexture()

abstract createTexture(props): Texture

Defined in: modules/core/src/adapter/device.ts:747

Create a texture

Parameters

props

TextureProps

Returns

Texture


createTransformFeedback()

abstract createTransformFeedback(props): TransformFeedback

Defined in: modules/core/src/adapter/device.ts:781

Create a transform feedback (immutable set of output buffer bindings). WebGL only.

Parameters

props

TransformFeedbackProps

Returns

TransformFeedback


createVertexArray()

abstract createVertexArray(props): VertexArray

Defined in: modules/core/src/adapter/device.ts:776

Create a vertex array

Parameters

props

VertexArrayProps

Returns

VertexArray


debug()

debug(): void

Defined in: modules/core/src/adapter/device.ts:705

Break in the debugger - if device.props.debug is true

Returns

void


destroy()

abstract destroy(): void

Defined in: modules/core/src/adapter/device.ts:558

Returns

void


generateMipmapsWebGPU()

generateMipmapsWebGPU(_texture): void

Defined in: modules/core/src/adapter/device.ts:819

Generate mipmaps for a WebGPU texture. WebGPU textures must be created up front with the required mip count, usage flags, and a format that supports the chosen generation path. WebGL uses Texture.generateMipmapsWebGL() directly because the backend manages mip generation on the texture object itself.

Parameters

_texture

Texture

Returns

void


getCanvasContext()

getCanvasContext(): CanvasContext

Defined in: modules/core/src/adapter/device.ts:921

Returns

CanvasContext

Deprecated

Use getDefaultCanvasContext()


getDefaultCanvasContext()

getDefaultCanvasContext(): CanvasContext

Defined in: modules/core/src/adapter/device.ts:725

Returns the default / primary canvas context. Throws an error if no canvas context is available (a WebGPU compute device)

Returns

CanvasContext


getExternalImageSize()

getExternalImageSize(data): object

Defined in: modules/core/src/adapter/device.ts:598

Get the size of an external image

Parameters

data

ExternalImage

Returns

object

height

height: number

width

width: number


getMipLevelCount()

getMipLevelCount(width, height, depth3d?): number

Defined in: modules/core/src/adapter/device.ts:587

Calculates the number of mip levels for a texture of width, height and in case of 3d textures only, depth

Parameters

width

number

height

number

depth3d?

number = 1

Returns

number


getModuleData()

getModuleData<ModuleDataT>(moduleName): ModuleDataT

Defined in: modules/core/src/adapter/device.ts:991

Type Parameters

ModuleDataT

ModuleDataT extends Record<string, unknown>

Parameters

moduleName

string

Returns

ModuleDataT


getParametersWebGL()

getParametersWebGL(parameters): void

Defined in: modules/core/src/adapter/device.ts:970

Parameters

parameters

any

Returns

void

Deprecated

  • will be removed - should use WebGPU parameters (pipeline)

getSupportedCompressedTextureFormats()

getSupportedCompressedTextureFormats(): TextureFormatCompressed[]

Defined in: modules/core/src/adapter/device.ts:623

Returns the compressed texture formats that can be created and sampled on this device

Returns

TextureFormatCompressed[]


getTextureFormatCapabilities()

getTextureFormatCapabilities(format): DeviceTextureFormatCapabilities

Defined in: modules/core/src/adapter/device.ts:576

Determines what operations are supported on a texture format on this particular device (checks against supported device features)

Parameters

format

TextureFormat

Returns

DeviceTextureFormatCapabilities


getTextureFormatInfo()

getTextureFormatInfo(format): TextureFormatInfo

Defined in: modules/core/src/adapter/device.ts:571

Returns information about a texture format, such as data type, channels, bits per channel, compression etc

Parameters

format

TextureFormat

Returns

TextureFormatInfo


getVertexFormatInfo()

getVertexFormatInfo(format): VertexFormatInfo

Defined in: modules/core/src/adapter/device.ts:562

Parameters

format

VertexFormat

Returns

VertexFormatInfo


incrementTimestamp()

incrementTimestamp(): number

Defined in: modules/core/src/adapter/device.ts:667

A monotonic counter for tracking buffer and texture updates

Returns

number


insertDebugMarker()

insertDebugMarker(markerLabel): void

Defined in: modules/core/src/adapter/device.ts:645

Parameters

markerLabel

string

Returns

void


isExternalImage()

isExternalImage(data): data is ExternalImage

Defined in: modules/core/src/adapter/device.ts:593

Check if data is an external image

Parameters

data

unknown

Returns

data is ExternalImage


isTextureFormatCompressed()

isTextureFormatCompressed(format): boolean

Defined in: modules/core/src/adapter/device.ts:618

Check if a specific texture format is GPU compressed

Parameters

format

TextureFormat

Returns

boolean


isTextureFormatFilterable()

isTextureFormatFilterable(format): boolean

Defined in: modules/core/src/adapter/device.ts:608

Check if linear filtering (sampler interpolation) is supported for a specific texture format

Parameters

format

TextureFormat

Returns

boolean


isTextureFormatRenderable()

isTextureFormatRenderable(format): boolean

Defined in: modules/core/src/adapter/device.ts:613

Check if device supports rendering to a framebuffer color attachment of a specific texture format

Parameters

format

TextureFormat

Returns

boolean


isTextureFormatSupported()

isTextureFormatSupported(format): boolean

Defined in: modules/core/src/adapter/device.ts:603

Check if device supports a specific texture format (creation and nearest sampling)

Parameters

format

TextureFormat

Returns

boolean


isVertexFormatSupported()

isVertexFormatSupported(format): boolean

Defined in: modules/core/src/adapter/device.ts:566

Parameters

format

VertexFormat

Returns

boolean


loseDevice()

loseDevice(): boolean

Defined in: modules/core/src/adapter/device.ts:662

Trigger device loss.

Returns

boolean

true if context loss could actually be triggered.

Note

primarily intended for testing how application reacts to device loss


popDebugGroup()

popDebugGroup(): void

Defined in: modules/core/src/adapter/device.ts:641

Returns

void


pushDebugGroup()

pushDebugGroup(groupLabel): void

Defined in: modules/core/src/adapter/device.ts:637

Parameters

groupLabel

string

Returns

void


readPixelsToArrayWebGL()

readPixelsToArrayWebGL(source, options?): Uint16Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Float32Array<ArrayBufferLike>

Defined in: modules/core/src/adapter/device.ts:929

Parameters

source

Texture | Framebuffer

options?
sourceAttachment?

number

sourceFormat?

number

sourceHeight?

number

sourceType?

number

sourceWidth?

number

sourceX?

number

sourceY?

number

target?

Uint16Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Float32Array<ArrayBufferLike>

Returns

Uint16Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Float32Array<ArrayBufferLike>

Deprecated

  • will be removed - should use command encoder

readPixelsToBufferWebGL()

readPixelsToBufferWebGL(source, options?): Buffer

Defined in: modules/core/src/adapter/device.ts:947

Parameters

source

Texture | Framebuffer

options?
sourceFormat?

number

sourceHeight?

number

sourceType?

number

sourceWidth?

number

sourceX?

number

sourceY?

number

target?

Buffer

targetByteOffset?

number

Returns

Buffer

Deprecated

  • will be removed - should use command encoder

reportError()

reportError(error, context, ...args): () => unknown

Defined in: modules/core/src/adapter/device.ts:688

Reports Device errors in a way that optimizes for developer experience / debugging.

  • Logs so that the console error links directly to the source code that generated the error.
  • Includes the object that reported the error in the log message, even if the error is asynchronous.

Conventions when calling reportError():

  • Always call the returned function - to ensure error is logged, at the error site
  • Follow with a call to device.debug() - to ensure that the debugger breaks at the error site

Parameters

error

Error

the error to report. If needed, just create a new Error object with the appropriate message.

context

unknown

pass this as context, otherwise it may not be available in the debugger for async errors.

args

...unknown[]

Returns

the logger function returned by device.props.onError() so that it can be called from the error site.

() => unknown

Example

device.reportError(new Error(...), this)();
device.debug();

resetWebGL()

resetWebGL(): void

Defined in: modules/core/src/adapter/device.ts:985

Returns

void

Deprecated

  • will be removed - should use for debugging only

setParametersWebGL()

setParametersWebGL(parameters): void

Defined in: modules/core/src/adapter/device.ts:965

Parameters

parameters

any

Returns

void

Deprecated

  • will be removed - should use WebGPU parameters (pipeline)

submit()

abstract submit(commandBuffer?): void

Defined in: modules/core/src/adapter/device.ts:739

Call after rendering a frame (necessary e.g. on WebGL OffscreenCanvas)

Parameters

commandBuffer?

CommandBuffer

Returns

void


toJSON()

toJSON(): string

Defined in: modules/core/src/adapter/device.ts:506

Compact serialization for assertion diffs and structured debug logs.

Returns

string


toString()

toString(): string

Defined in: modules/core/src/adapter/device.ts:501

Returns

string


withParametersWebGL()

withParametersWebGL(parameters, func): any

Defined in: modules/core/src/adapter/device.ts:975

Parameters

parameters

any

func

any

Returns

any

Deprecated

  • will be removed - should use WebGPU parameters (pipeline)

writeBufferViaCommandEncoder()

writeBufferViaCommandEncoder(_commandEncoder, _destinationBuffer, _data, _byteOffset?): void

Defined in: modules/core/src/adapter/device.ts:805

Internal helper for encoding CPU-to-buffer uploads in submission order. Backends may record onto the supplied command encoder or fall back to an immediate write when no separate queue ordering is required.

Parameters

_commandEncoder

CommandEncoder

_destinationBuffer

Buffer

_data

ArrayBufferLike | ArrayBufferView<ArrayBufferLike>

_byteOffset?

number = 0

Returns

void


_getCanvasContextProps()

static _getCanvasContextProps(props): CanvasContextProps | undefined

Defined in: modules/core/src/adapter/device.ts:1001

Helper to get the canvas context props

Parameters

props

DeviceProps

Returns

CanvasContextProps | undefined