Utils¶
The wgpu library provides a few utilities. Note that most functions below need to be explictly imported.
Logger¶
Errors, warnings, and info messages (including messages generated by
wgpu-native) are logged using Python’s default logging mechanics. The
wgpu logger instance is in wgpu.logger
, but can also be obtained
via:
import logging
logger = logging.getLogger("wgpu")
Diagnostics¶
To print a full diagnostic report:
wgpu.diagnostics.print_report()
To inspect (for example) the total buffer usage:
>>> counts = wgpu.diagnostics.object_counts.get_dict()
>>> print(counts["Buffer"])
{'count': 3, 'resource_mem': 784}
- class wgpu._diagnostics.DiagnosticsRoot¶
Root object to access wgpu diagnostics (i.e.
wgpu.diagnostics
).Per-topic diagnostics can be accessed as attributes on this object. These include
system
,wgpu_native_info
,versions
,object_counts
,wgpu_natrive_counts
.- get_dict()¶
Get a dict that represents the full diagnostics info.
The keys are the diagnostic topics, and the values are dicts of dicts. See e.g.
wgpu.diagnostics.counts.get_dict()
for a topic-specific dict.
- get_report()¶
Get the full textual diagnostic report (as a str).
- print_report()¶
Convenience method to print the full diagnostics report.
- class wgpu.DiagnosticsBase(name)¶
Object that represents diagnostics on a specific topic.
This is a base class that must be subclassed to provide diagnostics on a certain topic. Typically only
get_dict()
needs to be implemented. Instantiating the class registers it with the root diagnostics object.- get_dict()¶
Get the diagnostics for this topic, in the form of a Python dict.
Subclasses must implement this method. The dict can be a simple map of keys to values (str, int, float):
foo: 1 bar: 2
If the values are dicts, the data has a table-like layout, with the keys representing the table header:
count mem Adapter: 1 264 Buffer: 4 704
Subdicts are also supported, which results in multi-row entries. In the report, the keys of the subdicts have colons behind them:
count mem backend o v e el_size Adapter: 1 264 vulkan: 1 0 0 264 d3d12: 1 0 0 220 Buffer: 4 704 vulkan: 4 0 0 176 d3d12: 0 0 0 154
- get_report()¶
Get the textual diagnostics report for this topic.
- get_subscript()¶
Get informative text that helps interpret the report.
Subclasses can implement this method. The text will show below the table in the report.
- print_report()¶
Print the diagnostics report for this topic.
Get default device¶
- wgpu.utils.get_default_device()¶
Get a wgpu device object. If this succeeds, it’s likely that the WGPU lib is usable on this system. If not, this call will probably exit (Rust panic). When called multiple times, returns the same global device object (useful for e.g. unit tests).
Compute with buffers¶
from wgpu.utils.compute import compute_with_buffers
- wgpu.utils.compute_with_buffers(*args, **kwargs)¶