Skip to main content

resolve_execution_backend

Function resolve_execution_backend 

pub fn resolve_execution_backend(
    preferred: TargetBackend,
    native_available: impl Fn(TargetBackend) -> bool,
) -> (TargetBackend, Option<String>)
Expand description

Resolve which backend the execution/validation pipeline should actually use, given a preferred target and a predicate reporting whether a given backend’s native toolchain is available on this host.

Policy (plan §2):

  • If preferred is available, use it unchanged: returns (preferred, None).
  • Otherwise walk fallback_chain to the first available tier and return (chosen, Some(note)), where note explains the downgrade.
  • Wgsl is always considered available — it is the universal fallback and needs no native toolchain (naga compiles it in-process), so this function never fails to resolve a backend. The predicate is therefore not consulted for Wgsl; whatever it returns for Wgsl is ignored.

The function is pure and deterministic: identical inputs (including predicate behaviour) yield identical output, with no I/O or global state. This is what makes it unit-testable against a mock predicate.