The wgpu backends
What do backends do?
The heavy lifting (i.e communication with the hardware) in wgpu is performed by one of its backends.
Backends can be selected explicitly by importing them:
import wgpu.backends.wgpu_natve
There is also an auto backend to help keep code portable:
import wgpu.backends.auto
In most cases, however, you don’t need any of the above imports, because
a backend is automatically selected in the first call to wgpu.GPU.request_adapter()
.
Each backend can also provide additional (backend-specific) functionality. To keep the main API clean and portable, this extra functionality is provided as a functional API that has to be imported from the specific backend.
The wgpu_native backend
import wgpu.backends.wgpu_natve
This backend wraps wgpu-native, which is a C-api for wgpu, a Rust library that wraps Vulkan, Metal, DirectX12 and more. This is the main backend for wgpu-core. The only working backend, right now, to be precise. It also works out of the box, because the wgpu-native DLL is shipped with wgpu-py.
The wgpu_native backend provides a few extra functionalities:
- wgpu.backends.wgpu_native.request_device_tracing(adapter, trace_path, *, label='', required_features, required_limits, default_queue)
An alternative to
wgpu.GPUAdapter.request_adapter()
, that streams a trace of all low level calls to disk, so the visualization can be replayed (also on other systems), investigated, and debugged.- Parameters:
adapter – The adapter to create a device for.
trace_path – The path to an (empty) directory. Is created if it does not exist.
label – A human readable label. Optional.
required_features – The features (extensions) that you need. Default [].
required_limits – the various limits that you need. Default {}.
default_queue – Descriptor for the default queue. Optional.
- Returns:
Device
- Return type:
The js_webgpu backend
import wgpu.backends.js_webgpu
This backend calls into the JavaScript WebGPU API. For this, the Python code would need access to JavaScript - this backend is intended for use-cases like PScript PyScript, and RustPyhon.
This backend is still a stub, see issue #407 for details.