1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Driver capability detection — f64 workarounds, NVK/RADV detection
use super::WgpuDevice;
impl WgpuDevice {
/// Check if this device uses the NVK (nouveau) Vulkan driver
///
/// NVK is the open-source Vulkan driver for NVIDIA GPUs built on Mesa.
/// Some f64 builtins (particularly `exp()`) crash the NAK compiler on NVK.
#[must_use]
pub fn is_nvk(&self) -> bool {
let driver = self.adapter_info.driver.to_lowercase();
let driver_info = self.adapter_info.driver_info.to_lowercase();
driver.contains("nvk")
|| driver.contains("nouveau")
|| driver.contains("mesa")
|| driver_info.contains("nvk")
|| driver_info.contains("nouveau")
}
/// Check if this device uses AMD's RADV Vulkan driver
///
/// RADV is the open-source Vulkan driver for AMD GPUs built on Mesa.
#[must_use]
pub fn is_radv(&self) -> bool {
let driver = self.adapter_info.driver.to_lowercase();
let driver_info = self.adapter_info.driver_info.to_lowercase();
driver.contains("radv") || driver_info.contains("radv")
}
/// Whether this device needs software workarounds for f64 exp/log builtins.
///
/// Known broken drivers:
/// - NVK/NAK: crashes on native exp(f64), log(f64)
/// - RADV/ACO (AMD open-source): `fexp2` unimplemented for f64
/// - NVIDIA proprietary (NVVM/PTXAS): fails to compile native f64
/// transcendentals (exp, log, pow, sin, cos, abs on f64). Observed on
/// Ada Lovelace (SM89) and Ampere (SM86). NVVM's PTXAS does not
/// implement double-precision transcendentals — it relies on libdevice
/// which SPIR-V cannot link. The fix: use our Cody-Waite + minimax
/// polynomial implementations from `math_f64.wgsl`.
#[must_use]
pub fn needs_f64_exp_log_workaround(&self) -> bool {
self.is_nvk() || self.is_radv() || self.is_nvidia_proprietary()
}
/// Check if this device is NVIDIA Ada Lovelace (RTX 40xx) on the proprietary driver.
///
/// This combination has broken f64 transcendentals in NVVM PTXAS.
#[must_use]
pub fn is_nvidia_ada_lovelace(&self) -> bool {
let name = self.adapter_info.name.to_lowercase();
let is_ada = name.contains("rtx 40") || name.contains("rtx40") || name.contains("l40");
is_ada && self.is_nvidia_proprietary()
}
/// Probe and cache whether this device supports native f64 exp/log.
///
/// This is the deep-debt evolution of `needs_f64_exp_log_workaround()`:
/// instead of name-matching, it dispatches a tiny shader and verifies
/// the result empirically. First call is async; subsequent calls use cache.
pub async fn probe_f64_exp_capable(&self) -> bool {
crate::device::probe::probe_f64_exp_capable(self).await
}
/// Check if this device uses a proprietary NVIDIA driver
#[must_use]
pub fn is_nvidia_proprietary(&self) -> bool {
let name = self.adapter_info.name.to_lowercase();
let driver = self.adapter_info.driver.to_lowercase();
(name.contains("nvidia")
|| name.contains("geforce")
|| name.contains("rtx")
|| name.contains("gtx"))
&& !self.is_nvk()
&& !driver.contains("mesa")
}
}