VTK  9.7.20260910
vtkWebGPUHandle.h File Reference

Reference-counted ownership for WebGPU C API handles. More...

#include "vtkABINamespace.h"
#include "vtk_wgpu.h"
#include <cstddef>
#include <utility>
Include dependency graph for vtkWebGPUHandle.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  vtkWebGPU::Handle< T, AddRefFn, ReleaseFn >
 Reference-counted owner of a WebGPU C API handle. More...

Namespaces

namespace  vtkWebGPU

Macros

#define vtkWebGPUDeclareHandle(Name)

Functions

template<typename T, void(*)(T) A, void(*)(T) R>
bool vtkWebGPU::operator== (const Handle< T, A, R > &handle, std::nullptr_t)
template<typename T, void(*)(T) A, void(*)(T) R>
bool vtkWebGPU::operator!= (const Handle< T, A, R > &handle, std::nullptr_t)
template<typename T, void(*)(T) A, void(*)(T) R>
bool vtkWebGPU::operator== (std::nullptr_t, const Handle< T, A, R > &handle)
template<typename T, void(*)(T) A, void(*)(T) R>
bool vtkWebGPU::operator!= (std::nullptr_t, const Handle< T, A, R > &handle)
template<typename T, typename ReleaseFn>
void vtkWebGPU::ReleaseAndNull (T &raw, ReleaseFn release)
 Release raw if it is non-null and set it to null.
 vtkWebGPU::vtkWebGPUDeclareHandle (Adapter)
 vtkWebGPU::vtkWebGPUDeclareHandle (BindGroup)
 vtkWebGPU::vtkWebGPUDeclareHandle (BindGroupLayout)
 vtkWebGPU::vtkWebGPUDeclareHandle (Buffer)
 vtkWebGPU::vtkWebGPUDeclareHandle (CommandBuffer)
 vtkWebGPU::vtkWebGPUDeclareHandle (CommandEncoder)
 vtkWebGPU::vtkWebGPUDeclareHandle (ComputePassEncoder)
 vtkWebGPU::vtkWebGPUDeclareHandle (ComputePipeline)
 vtkWebGPU::vtkWebGPUDeclareHandle (Device)
 vtkWebGPU::vtkWebGPUDeclareHandle (Instance)
 vtkWebGPU::vtkWebGPUDeclareHandle (PipelineLayout)
 vtkWebGPU::vtkWebGPUDeclareHandle (QuerySet)
 vtkWebGPU::vtkWebGPUDeclareHandle (Queue)
 vtkWebGPU::vtkWebGPUDeclareHandle (RenderBundle)
 vtkWebGPU::vtkWebGPUDeclareHandle (RenderBundleEncoder)
 vtkWebGPU::vtkWebGPUDeclareHandle (RenderPassEncoder)
 vtkWebGPU::vtkWebGPUDeclareHandle (RenderPipeline)
 vtkWebGPU::vtkWebGPUDeclareHandle (Sampler)
 vtkWebGPU::vtkWebGPUDeclareHandle (ShaderModule)
 vtkWebGPU::vtkWebGPUDeclareHandle (Surface)
 vtkWebGPU::vtkWebGPUDeclareHandle (Texture)
 vtkWebGPU::vtkWebGPUDeclareHandle (TextureView)

Detailed Description

Reference-counted ownership for WebGPU C API handles.

WebGPU's C API hands out opaque, reference-counted handles (WGPUBuffer, WGPUTexture, ...). Every handle type has a matching wgpu<Type>AddRef / wgpu<Type>Release pair, but the raw handles carry no ownership semantics of their own, so tracking those calls by hand is error prone.

vtkWebGPU::Handle wraps a raw handle and issues the AddRef/Release calls on copy, move and destruction, giving the same convenience the wgpu:: C++ wrapper provided without requiring a generated C++ wrapper header (and therefore without requiring C++20). A named handle implicitly converts back to the raw handle, so a vtkWebGPU::Buffer can be passed directly to any C API entry point. The conversion is deleted for temporaries, so a handle cannot be dropped into a raw pointer field and released out from under it.

Ownership is explicit at construction:

  • Acquire(raw) adopts a handle the caller already owns a reference to (the usual case for the result of a wgpuDeviceCreate* call).
  • Reference(raw) takes a new reference to a handle owned by someone else.

Ownership in this module follows one rule, with one exception forced by VTK's header layout:

  • Anything that owns a WebGPU object holds it in a vtkWebGPU::Handle. That covers every implementation file and every private header.
  • A public header cannot include this one - it is not installed - so classes whose members are declared in a public header keep raw WGPU* members and release them through vtkWebGPU::ReleaseAndNull, never by calling wgpu<Type>Release directly. That keeps the "assigning nullptr leaks" footgun in one helper instead of at every call site.
  • Raw handles obtained from an accessor are borrowed. Do not release them, and do not store them past the lifetime of the owner.

wgpu<Type>Destroy is not a release: it frees the object's memory but leaves the reference count alone, so a Destroy still needs its matching release.

This is a private implementation header; it is not installed.

Definition in file vtkWebGPUHandle.h.

Macro Definition Documentation

◆ vtkWebGPUDeclareHandle

#define vtkWebGPUDeclareHandle ( Name)
Value:
using Name = Handle<WGPU##Name, &wgpu##Name##AddRef, &wgpu##Name##Release>

Definition at line 212 of file vtkWebGPUHandle.h.