Skip to main content

DeviceResource

DeviceResource is the abstract base class for GPU objects created by a Device. It standardizes common fields such as identifiers and backend handles that are shared across buffers, textures, passes, and similar GPU resources.

Types​

DeviceResourceProps​

DeviceResourceProps define the shared configuration for all resources. These fields are inherited by every resource-specific props type.

PropertyTypeDefaultDescription
id?stringautogeneratedOptional human-readable identifier. When omitted, a unique identifier is generated.
handle?unknownundefinedExisting backend handle to wrap instead of creating a new one.
userData?Record<string, unknown>undefinedApplication data stored on the resource instance.

Members​

  • id: string – Debug-friendly identifier assigned at creation.
  • device: Device – Device that owns the resource.
  • handle: unknown – Backend object handle (WebGL object or WebGPU handle).
  • props: DeviceResourceProps – Initialization properties, normalized with defaults.
  • userData: Record<string, unknown> – Application-defined metadata for the resource.

Methods​

  • destroy() – Releases GPU memory and attached resources.
  • delete() – Deprecated alias for destroy().
  • attachResource(resource) / detachResource(resource) – Manage owned child resources that are auto-destroyed with the parent.
  • destroyAttachedResource(resource) / destroyAttachedResources() – Destroy owned resources.

DeviceResource extends Resource. Backend subclasses override protected destroyHandle() instead of destroy() or onDestroy(). Ownership cleanup runs before native cleanup; memory and resource statistics are finalized even if native cleanup throws.

Native handle ownership (ownsHandle / isHandleBorrowed) is separate from wrapper ownership (owner). See the ownership guide.