GPU: VICTORY_* switches set to 0 are off

Six diagnostic switches (VICTORY_D3D12_DEBUG, _GBV, _DRED, _WARP,
VICTORY_GPU_TIMING and VICTORY_DUMP_TARGETS) were on whenever their
variable existed, so VICTORY_D3D12_WARP=0 still selected the software
adapter. They now go through one helper that reads a value other than 0
as on and an unset variable or 0 as off; every other value keeps the
meaning it had. The README says so above its switch table.

(cherry picked from commit a4974e4c21c16e2305942e37a868647d42eefe37)
This commit is contained in:
KoLolX3 authored and local committed 2026-11-25 01:02:59 -06:00
1 parent 394cc9a5c3
commit 3c250125c5
5 files changed
+54 -9

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
//! The `VICTORY_*` on/off switches (`VICTORY_D3D12_DEBUG=1` and its siblings).
use std::ffi::OsStr;
/// Whether a switch's value turns it on: it is set, and is not `0`.
///
/// A switch used to be on whenever its variable existed, so `VICTORY_D3D12_WARP=0` (typed to switch it off, or left
/// over from comparing two runs) still selected the software adapter. Any other value keeps the old meaning.
fn value_is_on(value: Option<&OsStr>) -> bool {
value.is_some_and(|v| v != "0")
}
/// Whether the environment variable `name` switches something on.
pub(crate) fn on(name: &str) -> bool {
value_is_on(std::env::var_os(name).as_deref())
}
#[cfg(test)]
mod tests {
use super::value_is_on;
use std::ffi::OsStr;
#[test]
fn unset_is_off() {
assert!(!value_is_on(None));
}
#[test]
fn zero_is_off() {
assert!(!value_is_on(Some(OsStr::new("0"))));
}
#[test]
fn one_is_on() {
assert!(value_is_on(Some(OsStr::new("1"))));
}
#[test]
fn other_values_keep_their_old_meaning() {
// Documented as `=1`; anything else that was on before stays on: only `0` is new.
for value in ["", "true", "yes", "2", "00", " 0", "0 "] {
assert!(value_is_on(Some(OsStr::new(value))), "{value:?}");
}
}
}