Crash fixes: upload room reserved at the start, D3D12 folder of any version, VICTORY_HOME

- upload.rs: 32 pieces of 64 MiB at the top of [4 GiB, 2^37) are reserved first
  thing in main, before the process's allocations can fill that window. On
  players' PCs it was full by the first ray-traced frame, the first upload
  failed and the title threw "D3D12 XDXR Error: Failed to allocate upload
  buffer". Past the pool: the window as before, a failed search not repeated
  for a second (with PR #88's per-frame limit in memory.rs), then the heap
  instead of null.
- main.rs: D3D12SDKVersion follows the version of D3D12\D3D12Core.dll beside
  the exe (a repack's 1.618 or 1.620 gave 0x887E0003 against our 614).
- VICTORY_HOME: one folder for settings, saves, caches, logs and downloads
  (a full C: drive, issue 135).
- README: both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
trustno1-coderandClaude Opus 5.5 committed 2026-11-27 12:07:42 -08:00
1 parent c5f7528bbf
commit e69e39c55b
7 files changed
+242 -62

No files matched your search

+67 -1
View File
@@ -26,11 +26,48 @@ use clap::{Parser, Subcommand, ValueEnum};
/// older: Windows 10's stops at shader model 6.5, and the translated shaders
/// are 6.6 (`victory play` fetches it there; 2026-11-27, an RTX 3060 on
/// Windows 10 22H2 had every pipeline refused). Without the folder, nothing changes.
///
/// A `D3D12Core.dll` there of another version (other forks' guides put 1.618
/// or 1.620 there) made Windows refuse Direct3D 12 altogether, "the D3D12 SDK
/// version configuration of the host exe is invalid" (0x887E0003; 2026-11-27,
/// an RTX 5080 and an RTX 3080 Ti on Windows 11): [`match_d3d12_core`] asks
/// for the version of the file that is there, before Direct3D 12 is loaded.
/// (An atomic: the same bytes as a `u32`, in memory that can be written.)
#[cfg(windows)]
#[unsafe(no_mangle)]
#[used]
#[allow(non_upper_case_globals)]
pub static D3D12SDKVersion: u32 = 614;
pub static D3D12SDKVersion: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(614);
/// The Agility SDK version of a `D3D12Core.dll` (its file version is
/// `1.<sdk>.<patch>.0`, e.g. 1.614.1.0): from the file's VS_FIXEDFILEINFO.
fn agility_version(dll: &[u8]) -> Option<u32> {
let signature = 0xFEEF_04BD_u32.to_le_bytes();
let at = dll.windows(4).position(|w| w == signature)?;
let most = u32::from_le_bytes(dll.get(at + 8..at + 12)?.try_into().ok()?);
let (major, minor) = (most >> 16, most & 0xffff);
(major == 1 && minor >= 600).then_some(minor)
}
/// Asks Windows for the Agility SDK version of the `D3D12\D3D12Core.dll`
/// beside this program, where there is one and it is not 614. First thing in
/// `main`: Windows reads `D3D12SDKVersion` when Direct3D 12 is first used.
#[cfg(windows)]
fn match_d3d12_core() {
let Some(core) = std::env::current_exe().ok().and_then(|p| p.parent().map(|d| d.join("D3D12").join("D3D12Core.dll")))
else {
return;
};
let Ok(bytes) = std::fs::read(&core) else { return };
match agility_version(&bytes) {
Some(v) if v != D3D12SDKVersion.load(std::sync::atomic::Ordering::Relaxed) => {
D3D12SDKVersion.store(v, std::sync::atomic::Ordering::Relaxed);
println!("{} is the D3D12 Agility SDK 1.{v}: asking Windows for that version.", core.display());
}
Some(_) => {}
None => println!("{} is not a D3D12 Agility SDK runtime Windows can use; move it away if Direct3D 12 fails.", core.display()),
}
}
/// `D3D12SDKPath`'s value: a pointer to a C string.
#[cfg(windows)]
@@ -258,6 +295,11 @@ enum Console {
}
fn main() -> Result<()> {
#[cfg(windows)]
match_d3d12_core();
// Before anything else can take the address space it needs.
#[cfg(windows)]
victory_hle::reserve_upload_space();
// The audio recorder `run` starts for `VICTORY_AUDIO_CAPTURE`.
#[cfg(all(windows, feature = "diagnostics"))]
if std::env::var_os("VICTORY_AUDIO_CAPTURE").is_some() {
@@ -424,6 +466,30 @@ fn show_config() -> Result<()> {
Ok(())
}
#[cfg(test)]
mod tests {
/// A D3D12Core.dll's VS_FIXEDFILEINFO: signature, structure version, then
/// the file version's high and low words (1.620.2.0 here).
fn core_bytes(major: u32, minor: u32) -> Vec<u8> {
let mut b = vec![0u8; 40];
for w in [0xFEEF_04BD_u32, 0x0001_0000, (major << 16) | minor, 2 << 16] {
b.extend_from_slice(&w.to_le_bytes());
}
b.extend_from_slice(&[0u8; 16]);
b
}
#[test]
fn agility_versions_are_read_from_the_file() {
assert_eq!(super::agility_version(&core_bytes(1, 620)), Some(620));
assert_eq!(super::agility_version(&core_bytes(1, 614)), Some(614));
// Windows' own D3D12Core.dll (10.0.x) and files without the structure are not one.
assert_eq!(super::agility_version(&core_bytes(10, 0)), None);
assert_eq!(super::agility_version(&[0u8; 64]), None);
assert_eq!(super::agility_version(&core_bytes(1, 620)[..48]), None);
}
}
/// Paths given on the command line, or the configured game + test titles.
pub(crate) fn default_paths(paths: Vec<PathBuf>) -> Result<Vec<PathBuf>> {
if !paths.is_empty() {
+4 -1
View File
@@ -195,8 +195,11 @@ pub(crate) fn preload(exe: &Path) {
}
}
/// `%LOCALAPPDATA%\victory`.
/// `%LOCALAPPDATA%\victory`, or the folder `VICTORY_HOME` names.
fn home() -> Result<PathBuf> {
if let Some(home) = victory_core::config::home_override() {
return Ok(home);
}
let base = std::env::var_os("LOCALAPPDATA").context("no %LOCALAPPDATA% to keep settings and logs in")?;
Ok(PathBuf::from(base).join("victory"))
}