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§
- Backend
Choice - 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(valueapp) or elseWGPU_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 isoff). - 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) unlessWGPU_DX12_COMPILER(wgpu, wgpu’s own variable:fxc,dxc,auto…) names another. - env_off
- Whether the app’s variable
app_varisoff. - instance_
flags - wgpu’s instance flags for every instance an app creates, from
flags(wgpu’s defaults with its environment variables applied) withoutVALIDATION_INDIRECT_CALL, unlessWGPU_VALIDATION_INDIRECT_CALLasks for it (any value but0). 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_flagswithWGPU_VALIDATION_INDIRECT_CALLread 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
pathrecorded, 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
choiceagainst the backends this build contains (compiled):None= GPU off. Asked-for backends that aren’t compiled in fall back todefault. - 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
pathis 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:
offkeeps the platform default. - with_
init_ marker - Run device creation (and the kernel build that follows it)
funder 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).