JFLib

gpu/vk_inst.rs#

Source: lib/gpu/vk_inst.rs

vk_inst -- Vulkan instance and adapters

  Instance::new() / with(&InstanceDesc) -> Result<Instance>
       jfgui_GPU=0 (or "off"): Err(Disabled); the loader from jfgui_GPU_DLL, vulkan-1.dll or
       libvulkan.so.1 (Err(NoLoader) without it); a loader below Vulkan 1.1: Err(Unsupported); no driver:
       Err(NoAdapter).  Instance extensions: VK_KHR_surface + VK_KHR_win32_surface
       (Android: VK_KHR_android_surface) when present, VK_EXT_debug_utils for jfgui_GPU_VALIDATE
       / jfgui_GPU_DEBUG.
  instance.adapters() -> Result<Vec<Adapter>>   every physical device: discrete, integrated,
       virtual, CPU, other (stable within a kind); AdapterInfo::missing says why one is
       unusable (Vulkan 1.1, a graphics + compute queue, timeline semaphores, dynamic
       rendering)
  instance.adapter() -> Result<Adapter>     jfgui_GPU_ADAPTER: an index into adapters() or a
       part of the name (case-insensitive); otherwise the first usable adapter
  instance.adapters_low_power(display) -> Result<Vec<Adapter>>   the adapters for showing
       windows (the UI's output): no CPU, virtual or unusable ones; the one that drives the
       display (vendor and device id, plat::win_display_adapter) first, integrated before
       discrete (low_power_rank); jfgui_GPU_ADAPTER as for adapter()
  adapter.can_present(&surface)            its queue can present to the surface
  adapter.info() / features() / limits() / level()   (level: the highest it supports)
  validation_messages() -> (errors, warnings)  counted by the debug messenger of every
       instance of the process (tests fail on errors)

Validation (jfgui_GPU_VALIDATE=1 or InstanceDesc::validate): VK_LAYER_KHRONOS_validation when
it is installed (the Vulkan SDK; never required), with synchronization validation, also of what
shaders access (VK_EXT_layer_settings "validate_sync" and "syncval_shader_accesses_heuristic", else
VK_EXT_validation_features, which knows only the first); warnings and errors
go to stderr as "gpu: validation error: ...".  Without the layer a note is printed once and
everything runs as without the variable.  jfgui_GPU_DEBUG=1: the messenger alone (driver
messages, info level and up).
  • fn validation_messages() -> (u32, u32) validation errors and warnings reported by the debug messenger so far (every instance of the process; 0, 0 without jfgui_GPU_VALIDATE / jfgui_GPU_DEBUG)

  • struct Instance the GPU API of the system (Vulkan); create adapters and surfaces from it

impl Instance

  • fn new() -> Result<Instance> the system's GPU API with the default settings

  • fn with(desc: &InstanceDesc) -> Result<Instance>

  • fn validating(&self) -> bool the validation layer is active on this instance

  • fn adapters(&self) -> Result<Vec<Adapter>> every GPU of the system, discrete ones first (AdapterInfo::missing: unusable ones)

  • fn prepare(&self) -> Result<bool> (the browser: adapter and device come asynchronously; here they are there)

  • fn adapter(&self) -> Result<Adapter> the adapter to use: jfgui_GPU_ADAPTER (index or name part), else the first usable one

  • fn adapters_low_power(&self, display: Option<(u32, u32)>) -> Result<Vec<Adapter>> the adapters for showing windows without waking more hardware than needed, the most frugal first: only integrated and discrete GPUs (a CPU or virtual adapter is no gain over the CPU path), the one that drives the display (vendor id, device id) before the others, integrated before discrete. jfgui_GPU_ADAPTER picks one as in adapter(). Programs that want a GPU for themselves keep adapter().

  • fn low_power_rank(kind: AdapterKind, drives_display: bool) -> Option<u32> the order of adapters for showing windows, lower first (None: not for this): the adapter that drives the display needs no copy across GPUs and is awake anyway; an integrated one before a discrete one that would have to wake up

  • struct Adapter a GPU of the system

impl Adapter

  • fn info(&self) -> &AdapterInfo
  • fn features(&self) -> &Features what a device of the highest level would have
  • fn limits(&self) -> &Limits
  • fn level(&self) -> Level the highest level a device of this adapter supports
  • fn can_present(&self, surface: &crate::Surface) -> bool a device of this adapter can show images on the surface
  • fn can_present(&self, surface: &crate::Surface) -> bool a device of this adapter can show images on the surface

Source: docs/API.md in the JFLib repository.