Skip to main content

Module backend

Module backend 

Source
Expand description

Which wgpu backends an app lets wgpu use, for its compute device and for its window, and the crash sentinel around device creation (issue #136). Adapted from Ember crates/gpu.

wgpu loads the system driver of every backend in the instance’s set while it enumerates adapters, even when it then picks another one: with Vulkan in the set, a broken Vulkan driver can crash the process (an access violation inside the driver DLL, which nothing can catch) although DX12 would have been used. So Windows defaults to DX12 alone. macOS uses Metal, Linux Vulkan (plus GL for a window when the build has it).

Overrides, read from the environment each call: the app’s own variable (its name is passed as app_var, for example EMBER_GPU_BACKEND) = dx12 | vulkan | metal | gl (comma lists allowed), auto (the platform default), or off (no GPU compute; the window still needs one backend and keeps the platform default); else WGPU_BACKEND (wgpu’s own variable, same names) for both the window and compute.

Backends this build doesn’t contain (for example gl) are ignored with a warning and the platform default is used.

Structs§

Backends
Represents the backends that wgpu will use.

Enums§

BackendChoice
What the environment asks for.

Functions§

backend_options
wgpu’s backend options for every instance an app creates — the window’s and the compute devices’: wgpu’s environment variables, with the DX12 compiler from dx12_compiler.
begin_startup_marker
Begin guarding native window startup and its first frame with the same marker used by GPU device creation. A process terminated by a driver while this is active leaves the marker for the next launch to recover from. Returns whether a marker path is configured.
choose
The choice from the app’s variable app_var (value app) or else WGPU_BACKEND (wgpu): the first one that parses wins; an unknown value is skipped (with a warning).
compute_backends
The backends of the compute device (None: the app’s variable is off).
default_compute_backends
The backends compute devices use when nothing is asked for on os (std::env::consts::OS).
default_window_backends
The backends the window uses when nothing is asked for on os.
dx12_compiler
The DX12 shader compiler: FXC (d3dcompiler_47.dll, part of Windows) unless WGPU_DX12_COMPILER (wgpu, wgpu’s own variable: fxc, dxc, auto…) names another.
env_off
Whether the app’s variable app_var is off.
instance_flags
wgpu’s instance flags for every instance an app creates, from flags (wgpu’s defaults with its environment variables applied) without VALIDATION_INDIRECT_CALL, unless WGPU_VALIDATION_INDIRECT_CALL asks for it (any value but 0). That validation builds an internal compute pipeline when each device is created; Intel Macs’ Metal compiler fails on it (“Compiler encountered an internal error”), the device is lost and the window never opens (#250). It only guards indirect draws and dispatches, which the apps do not issue.
instance_flags_from_env
instance_flags with WGPU_VALIDATION_INDIRECT_CALL read from the environment.
parse_backends
Parse a backend list ("dx12", "vulkan,gl", "auto", "off"…). None: nothing usable in it (empty or unknown names).
read_init_marker
What the init marker path recorded, if it is present — without removing it. For sessions that must leave the disk as they found it (a memory-only session): GPU rendering still starts off, and the marker stays for the next ordinary launch to report and clear.
resolve
Resolve choice against the backends this build contains (compiled): None = GPU off. Asked-for backends that aren’t compiled in fall back to default.
set_init_marker
Configure the marker used around compute device creation and native startup. None (the default) writes nothing.
startup_failed
Finish a startup guard after a recoverable window creation error.
startup_succeeded
Finish a successful startup guard without clearing concurrent driver-work scopes.
take_init_marker
If the init marker path is present — the last process died while creating the GPU device — remove it and return what it recorded.
window_backends
The backends for a desktop window’s renderer. The window always needs one: off keeps the platform default.
with_init_marker
Run device creation (and the kernel build that follows it) f under the init marker.
with_marker
Run driver work f (what: “device creation”, “kernel compilation”…) between writing and removing the init marker (if one is set).