GPU

class wgpu.GPU

Bases: object

The entrypoint to the wgpu API.

The starting point of your wgpu-adventure is always to obtain an adapter. This is the equivalent to browser’s navigator.gpu. When a backend is loaded, the wgpu.gpu object is replaced with a backend-specific implementation.

enumerate_adapters()

Get a list of adapter objects available on the current system.

An adapter can then be selected (e.g. using it’s summary), and a device then created from it.

The order of the devices is such that Vulkan adapters go first, then Metal, then D3D12, then OpenGL. Within each category, the order as provided by the particular backend is maintained. Note that the same device may be present via multiple backends (e.g. vulkan/opengl).

We cannot make guarantees about whether the order of the adapters matches the order as reported by e.g. nvidia-smi. We have found that on a Linux multi-gpu cluster, the order does match, but we cannot promise that this is always the case. If you want to make sure, do some testing by allocating big buffers and checking memory usage using nvidia-smi.

See https://github.com/pygfx/wgpu-py/issues/482 for more details.

async enumerate_adapters_async()

Async version of enumerate_adapters.

get_preferred_canvas_format()

Not implemented in wgpu-py; use GPUCanvasContext.get_preferred_format() instead. The WebGPU spec defines this function, but in wgpu there are different kinds of canvases which may each prefer/support a different format.

request_adapter(**parameters)

Create a GPUAdapter, the object that represents an abstract wgpu implementation, from which one can request a GPUDevice.

Parameters:
  • power_preference (PowerPreference) – “high-performance” or “low-power”.

  • force_fallback_adapter (bool) – whether to use a (probably CPU-based) fallback adapter.

  • canvas (WgpuCanvasInterface) – The canvas that the adapter should be able to render to. This can typically be left to None.

async request_adapter_async(**parameters)

Async version of request_adapter().

property wgsl_language_features

A set of strings representing the WGSL language extensions supported by all adapters. Returns an empty set for now.