Skip to main content

Module gpu_api

Module gpu_api 

Source
Expand description

Graphics and compute API versions: Vulkan, OpenGL and OpenCL.

The last user-visible gap against fastfetch (NOTES.md §6). Each API is reached by dlopening its loader at runtime rather than linking it, for three reasons:

  1. Linking would make the libraries hard requirements. A machine without Vulkan must still run retch; a #[link] on libvulkan would refuse to start.
  2. They are genuinely optional. Absence is a normal answer (“no Vulkan here”), not an error, so the field is simply omitted.
  3. It keeps the crate free of new dependencies, matching the hand-written FFI house style used for the Windows and macOS probes.

§These probes never modify the process environment

Mesa’s rusticl OpenCL driver is opt-in via RUSTICL_ENABLE: without it the ICD still registers a platform advertising OpenCL 3.0 while exposing zero devices. It is tempting to set that variable in-process before loading the ICD so the field looks better. This module deliberately does not, for two reasons:

  • It would be a data race. Fields are collected inside a std::thread::scope, and mutating the environment while sibling threads read it is unsound. std::env::set_var became unsafe in Rust 2024 precisely for this; this crate is on edition 2021, where it still compiles silently — a trap rather than a compile error.
  • It would report something false. A device visible only because retch enabled it for itself is not a device the user’s own programs can use.

So the OpenCL field reports the device count it actually observes, and says when that count is zero. fastfetch prints a bare OpenCL: 3.0 in both states — i.e. it reports a working stack when nothing can run on it. Under-reporting beats asserting something false, the same call as the Users: 0 suppression (v0.6.1) and the v0.7.0 input classification.

Structs§

GpuApis
Versions reported by each graphics/compute API present on the system.

Functions§

cstr_field
Trim a NUL-terminated fixed-size C string field into a String.
detect_gpu_apis
Detect Vulkan, OpenGL and OpenCL versions.
device_type_rank
Rank a Vulkan VkPhysicalDeviceType so the most capable real device wins.
format_opencl
Render the OpenCL field, distinguishing “usable” from “present but inert”.
format_vulkan
Render the Vulkan field from its parts.
format_vulkan_version
Decode a packed Vulkan version into major.minor.patch.
shorten_device_name
Shorten a driver-reported device name to the part a human recognises.