Skip to main content

Fence

A GPU->CPU synchronization primitive that signals / resolves when any GPU commands submitted prior to the Fence have completed.

Remarks:

  • Fences can e.g. be useful in WebGL to avoid starting a synchronous GPU->CPU data readback until all GPU commands affecting the buffer in question have completed.
  • In contrast to WebGL 2, WebGPU does not provide an actual "GPUFence" primitive. Instead a function GPUDevice.onSubmittedWorkDone() is used. This means that the "fence" is inserted after the last submitted (completed) command buffer (render pass, compute pass etc), rather than into the stream of commands in a command buffer.

Props

FenceProps

FenceProps extends ResourceProps and accepts the following fields.

PropertyTypeDefaultDescription
id?stringautogeneratedOptional human readable identifier inherited from Resource.
handle?unknownundefinedOptional handle to the underlying platform resource.
userData?Record<string, any>undefinedApplication reserved data stored on the fence instance.

Members

  • signaled: Promise<void> - resolves when the fence is signaled.

Methods

isSignaled(): boolean

Checks if the fence has already been signaled.

destroy(): void

Destroys the fence and releases any associated resources.