Skip to content

Configuration

Introduction

vtkWebGPUConfiguration owns the WebGPU adapter and the device, independently of a canvas or a render window.

Feature and limit negotiation occurs in one place, as in the C++ class of the same name. An application that wants more than one render window on one device creates a configuration, then gives it to each render window with setWebGPUConfiguration(). Those render windows share one device, and thus one set of VTK.js resource caches.

A render window that receives no configuration creates one for itself. An application that shows only one view can thus ignore this class.

Usage

js
import vtkWebGPUConfiguration from '@kitware/vtk.js/Rendering/WebGPU/Configuration';

const configuration = vtkWebGPUConfiguration.newInstance();
if (!(await configuration.initialize())) {
  throw new Error('No WebGPU device is available.');
}
firstView.setWebGPUConfiguration(configuration);
secondView.setWebGPUConfiguration(configuration);

Methods

extend

Method used to decorate a given object (publicAPI+model) with vtkWebGPUConfiguration characteristics.

ArgumentTypeRequiredDescription
publicAPIYesobject on which methods will be bounds (public)
modelYesobject on which data structure will be bounds (protected)
initialValuesYes(default: {})

finalize

Destroy and release the adapter and device that this configuration holds.

The subsequent call to initialize() requests a new adapter and a new device. This does not release the GPU resources of the render windows that use this configuration. Call releaseGraphicsResources() on each of those render windows before you call this.

getAdapter

Get the WebGPU adapter, or null before initialization.

The type is the native GPUAdapter. The adapter is released together with the device if the device is lost, because an adapter that lost its device cannot make a new one.

getDevice

Get the native WebGPU device, or null before initialization.

The type is the native GPUDevice. Give this object to a library that must record commands on the same device. Do not replace or destroy it while render windows use this configuration.

getDeviceReady

Tell if a device is available. This gives the same result as isInitialized().

getFeature

Alias for hasFeature(), for code that queries a configuration feature.

getOptionalFeatures

Get the optional features requested when supported by the adapter.

getPowerPreference

Get the power preference used for the adapter request.

getRequiredLimits

Get the limits that the adapter and the device must supply, or undefined if the adapter limits are used.

hasFeature

Return whether the initialized device exposes a feature.

initialize

Request an adapter and a device.

The call does nothing and gives true if a device is already available. Calls that occur while a request is in progress wait for that same request. The request fails if the adapter or the device cannot supply the required limits. An error message then tells which limit failed.

A render window calls this during its own initialization. An application calls it directly only to make sure that the device is available before it builds its views.

Returns

TypeDescription
true if a device is available

isInitialized

Tell if a device is available.

This becomes false again if the device is lost.

newInstance

Method used to create a new instance of vtkWebGPUConfiguration.

ArgumentTypeRequiredDescription
initialValuesYesfor pre-setting some of its content

setOptionalFeatures

Set the features requested when supported by the adapter. Set this before initialization.

setPowerPreference

Set the power preference for the adapter request.

Set this before initialization, because the adapter is requested only one time.

ArgumentTypeRequiredDescription
powerPreferenceYesthe preference to send to the browser

Returns

TypeDescription
true if the value changed

setRequiredLimits

Set the limits that the adapter and the device must supply.

Set this before initialization. Initialization fails, with a message for each limit that is too small, if the adapter or the device cannot supply these limits. Set undefined to ask for the largest buffer sizes that the adapter offers.

ArgumentTypeRequiredDescription
requiredLimitsYesthe limits, or undefined to use the adapter limits

Returns

TypeDescription
true if the value changed