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:
1 parent
20d9d1ebfe
commit
77582c3af4
5 files changed
+54
-9
No files matched your search
@@ -267,6 +267,8 @@ A release build has no debugging aids. Build them in with
|
|||||||
cargo build --profile diag -p victory --features diagnostics # target\diag\victory.exe
|
cargo build --profile diag -p victory --features diagnostics # target\diag\victory.exe
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The on/off switches below (`...=1`) are off when unset or set to `0`.
|
||||||
|
|
||||||
| Variable | Effect |
|
| Variable | Effect |
|
||||||
|----------|--------|
|
|----------|--------|
|
||||||
| `VICTORY_LOG=<target>=debug,...` | debug and trace output |
|
| `VICTORY_LOG=<target>=debug,...` | debug and trace output |
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ static TARGETS: std::sync::Mutex<Vec<(usize, std::sync::Arc<crate::resource::Hos
|
|||||||
|
|
||||||
fn dump_on() -> bool {
|
fn dump_on() -> bool {
|
||||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||||
*ON.get_or_init(|| folder().is_some() && std::env::var_os("VICTORY_DUMP_TARGETS").is_some())
|
*ON.get_or_init(|| folder().is_some() && crate::switch::on("VICTORY_DUMP_TARGETS"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Notes a title texture the frame being built renders to or writes.
|
/// Notes a title texture the frame being built renders to or writes.
|
||||||
|
|||||||
@@ -553,8 +553,7 @@ fn create() -> windows::core::Result<Host> {
|
|||||||
// SAFETY: plain D3D12 object creation with valid descriptions.
|
// SAFETY: plain D3D12 object creation with valid descriptions.
|
||||||
unsafe {
|
unsafe {
|
||||||
// The debug layer only in builds with diagnostics.
|
// The debug layer only in builds with diagnostics.
|
||||||
let debug =
|
let debug = cfg!(feature = "diagnostics") && crate::switch::on("VICTORY_D3D12_DEBUG");
|
||||||
cfg!(feature = "diagnostics") && std::env::var_os("VICTORY_D3D12_DEBUG").is_some();
|
|
||||||
if debug {
|
if debug {
|
||||||
let mut layer: Option<ID3D12Debug> = None;
|
let mut layer: Option<ID3D12Debug> = None;
|
||||||
match D3D12GetDebugInterface(&mut layer) {
|
match D3D12GetDebugInterface(&mut layer) {
|
||||||
@@ -565,7 +564,7 @@ fn create() -> windows::core::Result<Host> {
|
|||||||
// descriptor heap indices and the like become messages naming
|
// descriptor heap indices and the like become messages naming
|
||||||
// the command instead of page faults. Without state tracking
|
// the command instead of page faults. Without state tracking
|
||||||
// (directly indexed textures are not transitioned).
|
// (directly indexed textures are not transitioned).
|
||||||
if std::env::var_os("VICTORY_D3D12_GBV").is_some()
|
if crate::switch::on("VICTORY_D3D12_GBV")
|
||||||
&& let Some(l) = &layer
|
&& let Some(l) = &layer
|
||||||
{
|
{
|
||||||
if let Ok(d1) = l.cast::<ID3D12Debug1>() {
|
if let Ok(d1) = l.cast::<ID3D12Debug1>() {
|
||||||
@@ -594,7 +593,7 @@ fn create() -> windows::core::Result<Host> {
|
|||||||
// Diagnostics: the software adapter, on which a shader's wild access
|
// Diagnostics: the software adapter, on which a shader's wild access
|
||||||
// is an access violation in this process (a crash report with the
|
// is an access violation in this process (a crash report with the
|
||||||
// address and instruction) instead of a GPU fault and driver reset.
|
// address and instruction) instead of a GPU fault and driver reset.
|
||||||
if cfg!(feature = "diagnostics") && std::env::var_os("VICTORY_D3D12_WARP").is_some() {
|
if cfg!(feature = "diagnostics") && crate::switch::on("VICTORY_D3D12_WARP") {
|
||||||
let adapter = warp_adapter()?;
|
let adapter = warp_adapter()?;
|
||||||
D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?;
|
D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?;
|
||||||
tracing::info!("host device on the software adapter (WARP)");
|
tracing::info!("host device on the software adapter (WARP)");
|
||||||
@@ -1326,9 +1325,7 @@ fn record_twin_copy(
|
|||||||
/// builds).
|
/// builds).
|
||||||
pub(crate) fn dred_on() -> bool {
|
pub(crate) fn dred_on() -> bool {
|
||||||
static ON: OnceLock<bool> = OnceLock::new();
|
static ON: OnceLock<bool> = OnceLock::new();
|
||||||
*ON.get_or_init(|| {
|
*ON.get_or_init(|| cfg!(feature = "diagnostics") && crate::switch::on("VICTORY_D3D12_DRED"))
|
||||||
cfg!(feature = "diagnostics") && std::env::var_os("VICTORY_D3D12_DRED").is_some()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indirect mesh dispatches since the last frame line: the largest group
|
/// Indirect mesh dispatches since the last frame line: the largest group
|
||||||
@@ -1352,7 +1349,7 @@ fn card_budget() -> bool {
|
|||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
fn timing() -> bool {
|
fn timing() -> bool {
|
||||||
static ON: OnceLock<bool> = OnceLock::new();
|
static ON: OnceLock<bool> = OnceLock::new();
|
||||||
*ON.get_or_init(|| std::env::var_os("VICTORY_GPU_TIMING").is_some())
|
*ON.get_or_init(|| crate::switch::on("VICTORY_GPU_TIMING"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Names a host object for the device-removed report, which names the
|
/// Names a host object for the device-removed report, which names the
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ mod shadow;
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod tiles;
|
mod tiles;
|
||||||
pub mod signature;
|
pub mod signature;
|
||||||
|
mod switch;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod texture;
|
mod texture;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|||||||
@@ -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:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user