Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ Fork: MagiccConch/VIctory, upstream: Marvisak/VIctory. CI: windows-latest only (
- Ported as fork PR #11 (branch new-cap, commit b8388e9d, CI 45545098162 green, mergeable CLEAN). Merge conflict was only the heap-size chain in descriptor/host.rs: kept BOTH upstream's `.max(views)` rungs first (small title heaps must span the full capped range) AND the fork's 6ac8fbe plain rungs (`count + DYNAMIC`, `count + MIN_DYNAMIC`), then the cap path. Guard arithmetic: when `cap == Some(count + DYNAMIC)` (or `+MIN_DYNAMIC`), the matching `.max(views)` rung always succeeds first, so the plain rungs can never hide a needed guard trim.
- Mingw test-run limitation confirmed — WSL interop intercepts the .exe (`UtilGetPpid` error); local signal stays check+clippy+test --no-run on x86_64-pc-windows-gnu.
- After merging to main: rebuild, re-run pre-build (pipeline library rebuilds — emitted shaders change with the new clamp constant), then run the title. Expect the `host view heaps capped` info line, no slot-past-heap flood, and no null-write crash at world entry. Old cache dirs are keyed out automatically (cap in the key).

## Hardware run 2 with the cap (2026-11-25): no crash; log-file feature added

- Pre-build on the 5080 at bb56f8a3: `host view heaps capped ... cap=1000000` confirmed; fresh shader cache dir (cap in key, 0 cached); 28,164 pack pipelines: 23,019 made + 3,622 found in the library (safe: library entries are named by a hash of code+root+state, so byte-identical DXIL reuses, changed DXIL remakes; 23,019+3,622 = 28,164 − 1,523 skipped) + 1,523 skipped. Skips: 994 unnamed states (852 rasteriser, 139 depth-stencil, 3 blend), 101 untranslated (61 compute + 40 pixel), 403 E_INVALIDARG (394 compute, 8 graphics, 1 mesh — new small bucket to investigate someday, possibly oversized root signatures), 23 shader-not-found, 2 exotic stages. The 15,863 root-signature refusals stayed gone.
- Title run: `title slot past the host heap index=1113775+ count=934464` warnings REAPPEARED but are now EXPECTED and benign — that is `descriptor::sync_heaps` mirroring title-written heap slots the host heap cannot hold (≥ 934,464); the clamp keeps every shader read below 1,000,000 (guard slot), so those slots can't be read and can't fault. The Breakpad `http_upload` + blocked `submit.backtrace.io` line is the title's own reporter, benign.
- **No crash log ≠ lost log**: `crashes.log` is per-title at `%LOCALAPPDATA%\victory\data\<8-hex title id>\temp\crashes.log` (apps/victory/src/run.rs `log_crashes_to(temp.with_file_name(...))`), NOT in the repo/exe folder. Find it: `Get-ChildItem "$env:LOCALAPPDATA\victory\data" -Recurse -Filter crashes.log`. Absent file = no unhandled exception/panic/GPU failure that run.
- Added `VICTORY_LOG_FILE=<path>` (victory-core/src/logging.rs): a second fmt layer appends every record to a file alongside stderr, so a run's console survives the window closing. Env-less core `init_with(default, filter, file)` for tests (Rust 2024 `set_var` is unsafe; no env mutation in tests). FileLog = shared Arc<Mutex<File>> handle opened append+create, flushed per write; bad path → warn after the subscriber is live, run continues. README documents it.

1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ victory run <exe> [--execute] [--unimplemented trap|zero] [--strict]
victory config
```

Logging: `VICTORY_LOG=victory_loader=trace,info` (a release build logs
info and above).
| `VICTORY_LOG=victory_loader=trace,info` | a release build logs
info and above; with the `diagnostics` feature, debug and trace too |
| `VICTORY_LOG_FILE=<file>` | also appends every log record to a file (opened for appending; an unusable path is warned about and ignored) |

### Windows shader-test validator

Expand Down
1 change: 1 addition & 0 deletions crates/victory-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ anyhow.workspace = true
thiserror.workspace = true
serde.workspace = true
toml.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

[dev-dependencies]
Expand Down
84 changes: 83 additions & 1 deletion crates/victory-core/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
//! `VICTORY_LOG=victory_loader=trace,info`. Debug and trace output exist
//! only in builds with the `diagnostics` feature; a plain release build
//! logs info and above whatever the filter asks for.
//!
//! Set `VICTORY_LOG_FILE=<path>` to also append every record to a file, so
//! a run's console output survives the window closing.

use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use tracing_subscriber::EnvFilter;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::layer::SubscriberExt;
Expand All @@ -17,12 +22,48 @@ const CAP: LevelFilter = if cfg!(feature = "diagnostics") {
LevelFilter::INFO
};

/// Appends to the log file. Shared handle behind a lock: a record's bytes
/// are written whole (and flushed), from whichever thread logs them.
struct FileLog(Arc<Mutex<std::fs::File>>);

impl std::io::Write for FileLog {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut file = self.0.lock().unwrap_or_else(|e| e.into_inner());
file.write_all(buf)?;
file.flush()?;
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}

pub fn init(default_level: &str) {
let filter = std::env::var("VICTORY_LOG")
.or_else(|_| std::env::var("RUST_LOG"))
.ok()
.ok();
let file = std::env::var_os("VICTORY_LOG_FILE").map(PathBuf::from);
init_with(default_level, filter, file);
}

/// The env-less core of [`init`]: the filter from `VICTORY_LOG` (else the
/// default), and the log file path, if any.
fn init_with(default_level: &str, filter: Option<String>, file: Option<PathBuf>) {
let filter = filter
.and_then(|v| EnvFilter::try_new(v).ok())
.unwrap_or_else(|| EnvFilter::new(default_level));
let (log, file_error) = match file {
Some(path) => match std::fs::OpenOptions::new().create(true).append(true).open(&path) {
Ok(f) => (Some(Arc::new(Mutex::new(f))), None),
Err(e) => (None, Some((path, e))),
},
None => (None, None),
};
let file = log.map(|log| {
tracing_subscriber::fmt::layer()
.with_target(true)
.with_writer(move || FileLog(Arc::clone(&log)))
});
let _ = tracing_subscriber::registry()
.with(CAP)
.with(filter)
Expand All @@ -31,5 +72,46 @@ pub fn init(default_level: &str) {
.with_target(true)
.with_writer(std::io::stderr),
)
.with(file)
.try_init();
if let Some((path, e)) = file_error {
// The subscriber is live: this is seen on the console.
tracing::warn!(error = %e, path = %path.display(), "no log file; logging to the console only");
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::io::Write as _;

/// The file writer appends every write and keeps what earlier runs
/// wrote (the file is opened for appending, never truncated).
#[test]
fn file_log_appends() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("run.log");
std::fs::write(&path, b"kept\n").unwrap();
let log = Arc::new(Mutex::new(
std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&path)
.unwrap(),
));
FileLog(Arc::clone(&log)).write_all(b"first\n").unwrap();
// A later writer (another run, another thread) appends, not replaces.
FileLog(log).write_all(b"second\n").unwrap();
assert_eq!(std::fs::read_to_string(&path).unwrap(), "kept\nfirst\nsecond\n");
}

/// An unusable log file path is no error: `init_with` goes on with the
/// console alone. The parent directories are missing, so the open fails
/// without creating anything.
#[test]
fn file_log_unusable() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("no/such/dir/run.log");
init_with("info", None, Some(path));
}
}