Skip to content

DeviceContext

Under Construction

This documentation is auto-generated, and is a work in progress. Please see the source code at https://github.com/phetsims/alpenglow/blob/main/js/webgpu/compute/DeviceContext.ts for the most up-to-date information.

Overview

Handle resources and settings connected to a GPUDevice

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class DeviceContext

import { DeviceContext } from 'scenerystack/alpenglow';

Constructor

new DeviceContext( device : GPUDevice )

Instance Methods

createBuffer( size : number, flags ) : GPUBuffer

in bytes

createDataBuffer( data : ArrayBufferView ) : GPUBuffer

createU32Buffer( data : number[] ) : GPUBuffer

createI32Buffer( data : number[] ) : GPUBuffer

createF32Buffer( data : number[] ) : GPUBuffer

createByteEncoderBuffer( encoder : ByteEncoder ) : GPUBuffer

createMapReadableBuffer( size : number ) : GPUBuffer

in bytes

createQueryBuffer( size : number ) : GPUBuffer

in bytes (takes 8 bytes per count)

createQuerySet( capacity : number ) : GPUQuerySet

(will take 8*capacity bytes)

getCanvasContext( canvas : HTMLCanvasElement, colorSpace : 'srgb' | 'display-p3' ) : GPUCanvasContext

dispose()

Instance Properties

preferredCanvasFormat : PreferredCanvasFormat

(readonly)

preferredStorageFormat : 'bgra8unorm' | 'rgba8unorm'

(readonly)

lostEmitter : TinyEmitter

(readonly)

Static Methods

getDevice( providedOptions? : DeviceContextDeviceOptions ) : Promise<GPUDevice | null>

getMappedFloatArray( buffer : GPUBuffer ) : Promise<Float32Array>

TODO: reduce code duplication around here

getMappedUintArray( buffer : GPUBuffer ) : Promise<Uint32Array>

getMappedIntArray( buffer : GPUBuffer ) : Promise<Int32Array>

getMappedByteArray( buffer : GPUBuffer ) : Promise<Uint8Array>

getMappedArrayBuffer( buffer : GPUBuffer ) : Promise<ArrayBuffer>

Type DeviceContextDeviceOptions

import type { DeviceContextDeviceOptions } from 'scenerystack/alpenglow';
  • maxLimits?: boolean
  • timestampQuery?: boolean
  • highPerformance?: boolean

Source Code

See the source for DeviceContext.ts in the alpenglow repository.