Skip to content

UWAL / Device

Type Aliases

ConfigurationOptions

ts
type ConfigurationOptions = Pick<Partial<CanvasConfiguration>, "format"> & Omit<CanvasConfiguration, "format">;

Type Parameters

Type Parameter

RequestAdapterOptions

ts
type RequestAdapterOptions = GPURequestAdapterOptions & Record<"forceCompatibility", boolean | void>;

Type Parameters

Type Parameter

CanvasConfiguration

ts
type CanvasConfiguration = Omit<GPUCanvasConfiguration, "device">;

Type Parameters

Type Parameter

Classes

Device

Static class for requesting and managing the GPUAdapter and the GPUDevice instances with specified features and limits when provided. It can clean up GPUBuffer, GPUTexture, and GPUQuerySet resources when no longer required and destroy the current GPUDevice.

Properties

OnLost
ts
static OnLost: ((detail) => unknown) | undefined;

Callback with a GPUDeviceLostInfo argument to call when a GPUDevice is lost. When present, prevents an ERROR.DEVICE_LOST from being thrown.

Methods

CreateQuerySet()
ts
static CreateQuerySet(
   type, 
   count, 
label?): Promise<GPUQuerySet | undefined>;

Create and cache a new GPUQuerySet.

Parameters
ParameterTypeDescription
typeGPUQueryTypeThe type of queries managed by the GPUQuerySet.
countnumberThe number of queries managed by the GPUQuerySet.
label?stringGPUQuerySet label. Defaults to DescriptorLabel when not provided.
Returns

Promise<GPUQuerySet | undefined>

See

GPUTiming which uses a "timestamp" query set.

Destroy()
ts
static Destroy(
   buffers?, 
   textures?, 
   querySets?): void;

Remove initialized GPUAdapter and GPUDevice instances, reset internal state, and destroy GPUBuffer, GPUTexture, and GPUQuerySet resources if passed as arguments.

Parameters
ParameterTypeDescription
buffers?GPUBuffer | GPUBuffer[]Optional buffers to destroy.
textures?GPUTexture | GPUTexture[]Optional textures to destroy.
querySets?GPUQuerySet | GPUQuerySet[]Optional query sets to destroy.
Returns

void

SetRequiredFeatures()
ts
static SetRequiredFeatures(features): Promise<Set<GPUFeatureName>>;

Set optional features when requesting a GPUDevice. The request will fail if the GPUAdapter cannot provide them. Must be called before initializing the Renderer, Computation, or TextureUtils or the CreateQuerySet method call.

Parameters
ParameterTypeDescription
featuresGPUFeatureName | GPUFeatureName[]List of fearures to request from the adapter.
Returns

Promise<Set<GPUFeatureName>>

Accessors

AdapterOptions
Set Signature
ts
set static AdapterOptions(options): void;

Set optional RequestAdapterOptions when requesting a GPUAdapter. Must be called before requesting a GPUDevice.

See

https://www.w3.org/TR/webgpu/#adapter-selection

Parameters
ParameterTypeDescription
optionsRequestAdapterOptionsStandard GPURequestAdapterOptions with an optional forceCompatibility flag to enable compatibility mode even when the target device supports core.
Returns

void

RequiredLimits
Set Signature
ts
set static RequiredLimits(requiredLimits): void;

Set optional device limits when requesting a GPUDevice. The request will fail if the GPUAdapter cannot provide them. Must be called before initializing the Renderer, Computation, or TextureUtils or the CreateQuerySet method call.

Parameters
ParameterTypeDescription
requiredLimitsRecord<string, number> | undefinedList of limits to request from the adapter.
Returns

void

DefaultQueue
Set Signature
ts
set static DefaultQueue(descriptor): void;

Set the descriptor for the default GPUQueue.

Parameters
ParameterTypeDescription
descriptorGPUQueueDescriptor | undefinedDefault queue descriptor object.
Returns

void

DescriptorLabel
Set Signature
ts
set static DescriptorLabel(label): void;

Set the descriptor label for the GPUDevice.

Parameters
ParameterTypeDescription
labelstring | undefinedDevice descriptor label.
Returns

void

PreferredCanvasFormat
Get Signature
ts
get static PreferredCanvasFormat(): GPUTextureFormat;

Get the optimal GPUTextureFormat for the current system.

See

https://www.w3.org/TR/webgpu/#dom-gpu-getpreferredcanvasformat

Returns

GPUTextureFormat

The only possible values are "rgba8unorm" and "bgra8unorm".

VERSION
Get Signature
ts
get static VERSION(): string;
Returns

string

The current version of the library.

Released under the MIT License.