From 99bb9dadfec165b4e8017fb7008696db28a71b19 Mon Sep 17 00:00:00 2001 From: owenjbendon-creator <281052257+owenjbendon-creator@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:17:47 +0000 Subject: [PATCH] d3d12: Windows 10 runs the D3D12 runtime with the Agility SDK (D3D12-RUNTIME-WIN10-AGILITY) Windows 10's own Direct3D 12 stops at shader model 6.5 and refuses the heap-directly-indexed root signatures every translated pipeline uses, so on Windows 10 leonida.exe made no host pipeline at all. leonida.exe now exports D3D12SDKVersion and D3D12SDKPath (.\D3D12\), so Windows loads Microsoft's newer runtime from a D3D12 folder beside it. D3D12SDKVersion is set first thing in main to the version of the D3D12Core.dll that is there (a mismatch makes Windows refuse Direct3D 12, 0x887E0003), or to Windows' own runtime's without one, so nothing changes on Windows 11. d3d12.dll is delay-loaded so that Windows reads the version main set. Get-D3D12.cmd (scripts\get-d3d12.ps1) fetches Agility SDK 1.614.1 from nuget.org with pinned SHA-256s and a Microsoft signature check, and play-nvidia.ps1 stops with that hint on Windows 10 without the folder. Ported from trustno1-coder/VIctory-NVIDIA (GPL-3.0-or-later), commits 10862a6, e69e39c, f3534e6 and 0f0ada1 there. Tested on Windows 10 Pro 22H2 (19045), RTX 3090, driver 610.88, Ryzen 7 9800X3D: `leonida warm --used --again --limit 30` made 30 of 30 host pipelines with D3D12\D3D12Core.dll (1.620) beside the exe, and 30 of 30 had no host pipeline without it. New tests: agility::tests (version and export parsing, Windows' own runtime: it exports D3D12SDKVersion 2 on Windows 10 22H2) and tests/agility.rs (the exe exports both symbols; d3d12.dll is delay-loaded, not imported). Written with AI assistance (Claude). Co-Authored-By: Claude Opus 5.5 --- d3d12/Get-D3D12.cmd | 9 + d3d12/README.md | 10 + d3d12/apps/leonida/build.rs | 20 ++ d3d12/apps/leonida/src/agility.rs | 321 ++++++++++++++++++++++++++++ d3d12/apps/leonida/src/main.rs | 5 + d3d12/apps/leonida/tests/agility.rs | 59 +++++ d3d12/scripts/get-d3d12.ps1 | 64 ++++++ d3d12/scripts/play-nvidia.ps1 | 11 + 8 files changed, 499 insertions(+) create mode 100644 d3d12/Get-D3D12.cmd create mode 100644 d3d12/apps/leonida/build.rs create mode 100644 d3d12/apps/leonida/src/agility.rs create mode 100644 d3d12/apps/leonida/tests/agility.rs create mode 100644 d3d12/scripts/get-d3d12.ps1 diff --git a/d3d12/Get-D3D12.cmd b/d3d12/Get-D3D12.cmd new file mode 100644 index 000000000..c25ee8da8 --- /dev/null +++ b/d3d12/Get-D3D12.cmd @@ -0,0 +1,9 @@ +@echo off +rem Downloads Microsoft's newer Direct3D 12 runtime (the D3D12 Agility SDK, about 22 MB, from nuget.org) into +rem target\diag\D3D12 beside leonida.exe. Windows 10 needs it: its own Direct3D 12 stops at shader model 6.5 and +rem refuses every translated pipeline. Windows 11 does not (leonida.exe uses Windows' own runtime where it is newer). +rem Get-D3D12.cmd into target\diag\D3D12 +rem Get-D3D12.cmd -To FOLDER into another folder (the D3D12 folder beside your leonida.exe) +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-d3d12.ps1" %* +echo. +pause diff --git a/d3d12/README.md b/d3d12/README.md index b406ac074..d5deef007 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -361,6 +361,16 @@ scripts\play-nvidia.ps1 -Exe The first start builds the layer by itself (`scripts\build-nvidia.ps1`: the `diag` profile with `diagnostics`). +**On Windows 10, run `Get-D3D12.cmd` once.** Windows 10's own Direct3D 12 stops +at shader model 6.5 and refuses every translated pipeline. `Get-D3D12.cmd` +downloads Microsoft's newer runtime (the D3D12 Agility SDK 1.614.1, about 22 +MB, from nuget.org, checked against its SHA-256 and Microsoft's signature) into +`target\diag\D3D12\`, and `leonida.exe` asks Windows for it +(`apps\leonida\src\agility.rs`: it exports `D3D12SDKVersion`, set to the version +of the `D3D12Core.dll` there, and `D3D12SDKPath`). Windows 11 needs nothing: +where no such folder is there, the exe asks for Windows' own runtime. +`scripts\play-nvidia.ps1` stops with this hint on Windows 10 without the folder. + **For DLSS and DLSS frame generation, run `Get-NVIDIA-DLSS.cmd` once** (double click it, or `Get-NVIDIA-DLSS.cmd -NoStreamline` for DLSS alone). It downloads the few NVIDIA files they need, about 70 MB, from NVIDIA's own GitHub diff --git a/d3d12/apps/leonida/build.rs b/d3d12/apps/leonida/build.rs new file mode 100644 index 000000000..294f32f49 --- /dev/null +++ b/d3d12/apps/leonida/build.rs @@ -0,0 +1,20 @@ +//! `leonida.exe` exports `D3D12SDKVersion` and `D3D12SDKPath` (src/agility.rs): +//! Windows' Direct3D 12 reads them from the process's executable to load +//! Microsoft's newer runtime from `D3D12\` beside it (Windows 10's own stops +//! at shader model 6.5). An executable exports nothing by itself, so the +//! linker is told to. +//! +//! Direct3D 12 reads `D3D12SDKVersion` when `d3d12.dll` is loaded. Imported +//! the usual way, it is loaded before `main` runs, so the version `main` sets +//! from the `D3D12` folder (or Windows' own, without one) would come too late. +//! Loaded on its first use instead, it reads that version. +//! +//! From trustno1-coder/VIctory-NVIDIA (GPL-3.0-or-later), commit 0f0ada1 there. +fn main() { + if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") { + println!("cargo:rustc-link-arg-bins=/EXPORT:D3D12SDKVersion,DATA"); + println!("cargo:rustc-link-arg-bins=/EXPORT:D3D12SDKPath,DATA"); + println!("cargo:rustc-link-arg-bins=/DELAYLOAD:d3d12.dll"); + println!("cargo:rustc-link-arg-bins=delayimp.lib"); + } +} diff --git a/d3d12/apps/leonida/src/agility.rs b/d3d12/apps/leonida/src/agility.rs new file mode 100644 index 000000000..0fc0a5b9d --- /dev/null +++ b/d3d12/apps/leonida/src/agility.rs @@ -0,0 +1,321 @@ +//! Which Direct3D 12 runtime `leonida.exe` asks Windows for. +//! +//! Windows 10's own Direct3D 12 stops at shader model 6.5 and refuses root +//! signatures that index the descriptor heaps directly, which every +//! translated pipeline uses (shader model 6.6): there each pipeline is +//! refused and the title closes within seconds. Microsoft's D3D12 Agility SDK +//! fixes that: an executable that exports `D3D12SDKVersion` and +//! `D3D12SDKPath` gets the newer `D3D12Core.dll` from that folder, where its +//! version is newer than Windows' own (`scripts\get-d3d12.ps1` fetches it). +//! +//! The version asked for has to match the file: a `D3D12Core.dll` of another +//! version than the one asked for makes Windows refuse Direct3D 12 altogether +//! ("the D3D12 SDK version configuration of the host exe is invalid", +//! 0x887E0003), and asking for one where the folder is missing does the same +//! on a Windows whose own runtime is older. So [`match_d3d12_core`] reads +//! the version of the file beside the program, or Windows' own without one, +//! first thing in `main`. Windows reads `D3D12SDKVersion` when `d3d12.dll` is +//! loaded, so build.rs delay-loads it: imported the usual way it is loaded +//! before `main`, and the value set here would come too late. +//! +//! Ported from trustno1-coder/VIctory-NVIDIA (GPL-3.0-or-later: `main.rs`, +//! `build.rs` and `scripts/get-d3d12.ps1` of v2026.11.27.9, commits 10862a6, +//! e69e39c, f3534e6 and 0f0ada1 there), where it was measured on Windows 10 +//! 22H2 and on Windows 11 22H2 and 25H2. + +/// The Agility SDK version Windows reads, set by [`match_d3d12_core`] +/// before Direct3D 12 is first used (an atomic: the same bytes as a `u32`, +/// in memory that can be written). 614 until then. +#[cfg(windows)] +#[unsafe(no_mangle)] +#[used] +#[allow(non_upper_case_globals)] +pub static D3D12SDKVersion: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(614); + +/// `D3D12SDKPath`'s value: a pointer to a C string. +#[cfg(windows)] +#[repr(transparent)] +pub struct SdkPath(*const std::ffi::c_char); + +// SAFETY: it points at a string literal, never written. +#[cfg(windows)] +unsafe impl Sync for SdkPath {} + +/// Where `D3D12Core.dll` is, from `leonida.exe`'s folder. +#[cfg(windows)] +#[unsafe(no_mangle)] +#[used] +#[allow(non_upper_case_globals)] +pub static D3D12SDKPath: SdkPath = SdkPath(c".\\D3D12\\".as_ptr()); + +/// The highest version asked for where no `D3D12\D3D12Core.dll` is beside +/// the program: the one the fetch script gets. +#[cfg_attr(not(windows), allow(dead_code))] +const TESTED: u32 = 614; + +/// The Agility SDK version of a `D3D12Core.dll` (its file version is +/// `1...0`, e.g. 1.614.1.0), from the file's VS_FIXEDFILEINFO. +#[cfg_attr(not(windows), allow(dead_code))] +pub(crate) fn agility_version(dll: &[u8]) -> Option { + 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) +} + +/// The `D3D12SDKVersion` a `D3D12Core.dll` exports: Windows' own, in +/// System32, says which version it is (616 on Windows 11 25H2). +#[cfg_attr(not(windows), allow(dead_code))] +pub(crate) fn exported_sdk_version(dll: &[u8]) -> Option { + let u16_at = |at: usize| Some(u16::from_le_bytes(dll.get(at..at + 2)?.try_into().ok()?)); + let u32_at = |at: usize| Some(u32::from_le_bytes(dll.get(at..at + 4)?.try_into().ok()?)); + let pe = u32_at(0x3c)? as usize; + (dll.get(pe..pe + 4)? == b"PE\0\0").then_some(())?; + let sections = usize::from(u16_at(pe + 6)?); + let optional = pe + 24; + let table = optional + usize::from(u16_at(pe + 20)?); + // PE32+ only: the export directory is the first data directory, at 112. + (u16_at(optional)? == 0x20b).then_some(())?; + let offset = |rva: u32| -> Option { + (0..sections).find_map(|i| { + let s = table + i * 40; + let (size, va, raw_size, raw) = ( + u32_at(s + 8)?, + u32_at(s + 12)?, + u32_at(s + 16)?, + u32_at(s + 20)?, + ); + (va <= rva && rva < va + size.max(raw_size)).then(|| (rva - va + raw) as usize) + }) + }; + let exports = offset(u32_at(optional + 112)?)?; + // NumberOfNames, AddressOfFunctions, AddressOfNames, AddressOfNameOrdinals + let count = u32_at(exports + 24)? as usize; + let functions_at = offset(u32_at(exports + 28)?)?; + let names_at = offset(u32_at(exports + 32)?)?; + let ordinals_at = offset(u32_at(exports + 36)?)?; + (0..count).find_map(|i| { + let name = offset(u32_at(names_at + 4 * i)?)?; + if dll.get(name..name + 16)? != b"D3D12SDKVersion\0" { + return None; + } + let ordinal = usize::from(u16_at(ordinals_at + 2 * i)?); + u32_at(offset(u32_at(functions_at + 4 * ordinal)?)?) + }) +} + +/// The version asked for where no `D3D12\D3D12Core.dll` is beside this +/// program: Windows' own runtime's (System32's `D3D12Core.dll` exports it), +/// at most [`TESTED`], so Windows keeps its own. Where that file is missing +/// or unreadable (Windows older than 10 2004 reads no `D3D12SDKVersion`), 4, +/// the first Agility SDK's. +#[cfg(windows)] +fn os_runtime() -> u32 { + let system = std::env::var_os("SystemRoot") + .map(std::path::PathBuf::from) + .unwrap_or_else(|| r"C:\Windows".into()); + std::fs::read(system.join("System32").join("D3D12Core.dll")) + .ok() + .and_then(|dll| exported_sdk_version(&dll)) + .map_or(4, |v| v.min(TESTED)) +} + +/// Windows' build number (19045 is Windows 10 22H2; 22000 and up, Windows +/// 11), from `RtlGetVersion`, which no compatibility shim changes. +/// `LEONIDA_WINDOWS_BUILD` stands in for it (to try Windows 10's path). +#[cfg(windows)] +pub(crate) fn windows_build() -> Option { + if let Some(build) = std::env::var("LEONIDA_WINDOWS_BUILD") + .ok() + .and_then(|v| v.trim().parse().ok()) + { + return Some(build); + } + #[repr(C)] + struct OsVersionInfo { + size: u32, + major: u32, + minor: u32, + build: u32, + platform: u32, + service_pack: [u16; 128], + } + #[link(name = "ntdll")] + unsafe extern "system" { + fn RtlGetVersion(info: *mut OsVersionInfo) -> i32; + } + let mut info = OsVersionInfo { + size: size_of::() as u32, + major: 0, + minor: 0, + build: 0, + platform: 0, + service_pack: [0; 128], + }; + // SAFETY: `info` is an OSVERSIONINFOW with its size set, as RtlGetVersion takes. + (unsafe { RtlGetVersion(&mut info) } == 0).then_some(info.build) +} + +/// Sets [`D3D12SDKVersion`] to the version of the `D3D12\D3D12Core.dll` +/// beside this program, or to Windows' own runtime's where there is none. +/// First thing in `main`: Windows reads it when Direct3D 12 is first used. +#[cfg(windows)] +pub(crate) fn match_d3d12_core() { + use std::sync::atomic::Ordering::Relaxed; + 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 { + D3D12SDKVersion.store(os_runtime(), Relaxed); + if windows_build().is_some_and(|build| build < 22000) { + eprintln!( + "Windows 10: Direct3D 12 here stops at shader model 6.5, and the translated shaders need 6.6. \ + Without {} the game's pipelines are refused: d3d12\\Get-D3D12.cmd fetches Microsoft's runtime once.", + core.display() + ); + } + return; + }; + match agility_version(&bytes) { + Some(v) => { + if v != TESTED { + eprintln!( + "{} is the D3D12 Agility SDK 1.{v}: asking Windows for that version.", + core.display() + ); + } + D3D12SDKVersion.store(v, Relaxed); + } + None => { + D3D12SDKVersion.store(os_runtime(), Relaxed); + eprintln!( + "{} is not a D3D12 Agility SDK runtime Windows can use: Windows' own is used.", + core.display() + ); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// The bytes of a VS_FIXEDFILEINFO for file version `major.minor.patch.0`, + /// behind some padding, as a DLL's version resource holds it. + fn version_resource(major: u16, minor: u16, patch: u16) -> Vec { + let mut bytes = vec![0u8; 64]; + bytes.extend_from_slice(&0xFEEF_04BD_u32.to_le_bytes()); + bytes.extend_from_slice(&0x0001_0000_u32.to_le_bytes()); // structure version + bytes.extend_from_slice(&((u32::from(major) << 16) | u32::from(minor)).to_le_bytes()); + bytes.extend_from_slice(&(u32::from(patch) << 16).to_le_bytes()); + bytes.extend_from_slice(&[0u8; 40]); + bytes + } + + #[test] + fn agility_version_reads_the_minor_of_an_agility_runtime() { + assert_eq!(agility_version(&version_resource(1, 614, 1)), Some(614)); + assert_eq!(agility_version(&version_resource(1, 620, 2)), Some(620)); + } + + #[test] + fn agility_version_refuses_what_is_not_an_agility_runtime() { + // Windows' own D3D12Core.dll carries the OS version (10.0.x). + assert_eq!(agility_version(&version_resource(10, 0, 19041)), None); + assert_eq!(agility_version(&version_resource(1, 4, 0)), None); + assert_eq!(agility_version(b"no version resource"), None); + } + + /// A minimal PE32+ image whose export directory names `exports` (each + /// pointing at its `u32` value), in one section. + fn pe_with_exports(exports: &[(&str, u32)]) -> Vec { + const PE: usize = 0x40; + const OPTIONAL: usize = PE + 24; + const OPTIONAL_SIZE: usize = 240; + const TABLE: usize = OPTIONAL + OPTIONAL_SIZE; + const RAW: usize = 0x200; + const VA: u32 = 0x1000; + // The section: export directory (40), functions, names, ordinals, values, name strings. + let n = exports.len(); + let functions = 40; + let names = functions + 4 * n; + let ordinals = names + 4 * n; + let values = ordinals + 2 * n + (2 * n) % 4; + let mut strings = values + 4 * n; + let mut section = vec![0u8; strings]; + let put32 = + |s: &mut Vec, at: usize, v: u32| s[at..at + 4].copy_from_slice(&v.to_le_bytes()); + put32(&mut section, 24, n as u32); + put32(&mut section, 28, VA + functions as u32); + put32(&mut section, 32, VA + names as u32); + put32(&mut section, 36, VA + ordinals as u32); + for (i, (name, value)) in exports.iter().enumerate() { + put32( + &mut section, + functions + 4 * i, + VA + (values + 4 * i) as u32, + ); + put32(&mut section, names + 4 * i, VA + strings as u32); + section[ordinals + 2 * i..ordinals + 2 * i + 2] + .copy_from_slice(&(i as u16).to_le_bytes()); + put32(&mut section, values + 4 * i, *value); + section.extend_from_slice(name.as_bytes()); + section.push(0); + strings += name.len() + 1; + } + let mut image = vec![0u8; RAW]; + image[0x3c..0x40].copy_from_slice(&(PE as u32).to_le_bytes()); + image[PE..PE + 4].copy_from_slice(b"PE\0\0"); + image[PE + 6..PE + 8].copy_from_slice(&1u16.to_le_bytes()); + image[PE + 20..PE + 22].copy_from_slice(&(OPTIONAL_SIZE as u16).to_le_bytes()); + image[OPTIONAL..OPTIONAL + 2].copy_from_slice(&0x20bu16.to_le_bytes()); + image[OPTIONAL + 112..OPTIONAL + 116].copy_from_slice(&VA.to_le_bytes()); + let len = section.len() as u32; + image[TABLE + 8..TABLE + 12].copy_from_slice(&len.to_le_bytes()); + image[TABLE + 12..TABLE + 16].copy_from_slice(&VA.to_le_bytes()); + image[TABLE + 16..TABLE + 20].copy_from_slice(&len.to_le_bytes()); + image[TABLE + 20..TABLE + 24].copy_from_slice(&(RAW as u32).to_le_bytes()); + image.extend_from_slice(§ion); + image + } + + #[test] + fn exported_sdk_version_finds_the_export_among_others() { + let image = pe_with_exports(&[ + ("D3D12GetInterface", 7), + ("D3D12SDKVersion", 616), + ("D3D12SDKPath", 9), + ]); + assert_eq!(exported_sdk_version(&image), Some(616)); + } + + #[test] + fn exported_sdk_version_is_none_without_the_export_or_a_pe_image() { + assert_eq!( + exported_sdk_version(&pe_with_exports(&[("D3D12GetInterface", 7)])), + None + ); + assert_eq!(exported_sdk_version(b"MZ and nothing else"), None); + } + + /// Windows' own runtime, where there is one: it exports a version the + /// parser reads (on Windows 10 2004 and later): 2 on Windows 10 22H2 + /// (19045), 616 on Windows 11 25H2. + #[cfg(windows)] + #[test] + fn exported_sdk_version_reads_windows_own_runtime() { + let system = std::env::var_os("SystemRoot") + .map(std::path::PathBuf::from) + .unwrap_or_else(|| r"C:\Windows".into()); + let Ok(dll) = std::fs::read(system.join("System32").join("D3D12Core.dll")) else { + return; + }; + let version = + exported_sdk_version(&dll).expect("System32's D3D12Core.dll exports D3D12SDKVersion"); + assert!(version >= 1, "D3D12SDKVersion {version}"); + } +} diff --git a/d3d12/apps/leonida/src/main.rs b/d3d12/apps/leonida/src/main.rs index 08df7abe8..8d39fe529 100644 --- a/d3d12/apps/leonida/src/main.rs +++ b/d3d12/apps/leonida/src/main.rs @@ -3,6 +3,7 @@ //! Every command reads the user's own files and writes only to stdout or to //! the user's cache directory (outside the repository). +mod agility; mod census; mod inspect; mod leonida; @@ -177,6 +178,10 @@ enum Console { } fn main() -> Result<()> { + // Which Direct3D 12 runtime Windows loads (the Agility SDK beside the exe, or its own), + // before anything uses Direct3D 12: it reads the version then. + #[cfg(windows)] + agility::match_d3d12_core(); // Leonida's settings names (LEONIDA_X for LEONIDA_X), before any thread starts. leonida::apply_settings_names(); leonida_core::logging::init("info"); diff --git a/d3d12/apps/leonida/tests/agility.rs b/d3d12/apps/leonida/tests/agility.rs new file mode 100644 index 000000000..7073d883a --- /dev/null +++ b/d3d12/apps/leonida/tests/agility.rs @@ -0,0 +1,59 @@ +//! `leonida.exe` asks Windows for Microsoft's newer Direct3D 12 runtime +//! (the D3D12 Agility SDK) beside it: Windows reads `D3D12SDKVersion` and +//! `D3D12SDKPath` from the executable's exports, and reads them when +//! `d3d12.dll` is loaded, so that DLL is delay-loaded (src/agility.rs, +//! build.rs). Without the exports Windows 10 keeps its own runtime, which +//! stops at shader model 6.5 and refuses every translated pipeline. +#![cfg(all(windows, target_env = "msvc"))] + +use std::process::Command; + +/// `leonida inspect `'s output. +fn inspect_self(flag: &str) -> String { + let exe = env!("CARGO_BIN_EXE_leonida"); + let output = Command::new(exe) + .args(["inspect", exe, flag]) + .output() + .unwrap(); + assert!( + output.status.success(), + "inspect failed: {}", + String::from_utf8_lossy(&output.stderr) + ); + String::from_utf8_lossy(&output.stdout).into_owned() +} + +#[test] +fn the_exe_exports_the_agility_sdk_symbols() { + let stdout = inspect_self("--exports"); + for name in ["D3D12SDKVersion", "D3D12SDKPath"] { + assert!( + stdout + .lines() + .any(|line| line.split_whitespace().nth(1) == Some(name)), + "{name} is not exported:\n{stdout}" + ); + } +} + +#[test] +fn d3d12_dll_is_delay_loaded() { + let stdout = inspect_self("--imports"); + let (plain, delayed) = stdout + .split_once("delay-load imports") + .unwrap_or((&stdout, "")); + let names = |part: &str| -> Vec { + part.lines() + .filter_map(|line| line.split_whitespace().next()) + .map(str::to_ascii_lowercase) + .collect() + }; + assert!( + !names(plain).iter().any(|dll| dll == "d3d12.dll"), + "d3d12.dll is imported before main runs:\n{stdout}" + ); + assert!( + names(delayed).iter().any(|dll| dll == "d3d12.dll"), + "d3d12.dll is not delay-loaded:\n{stdout}" + ); +} diff --git a/d3d12/scripts/get-d3d12.ps1 b/d3d12/scripts/get-d3d12.ps1 new file mode 100644 index 000000000..b1cab8c71 --- /dev/null +++ b/d3d12/scripts/get-d3d12.ps1 @@ -0,0 +1,64 @@ +# From trustno1-coder/VIctory-NVIDIA (GPL-3.0-or-later), scripts/get-d3d12.ps1 of v2026.11.27.9. +# Fetches Microsoft's newer Direct3D 12 runtime (the D3D12 Agility SDK, D3D12Core.dll, from Microsoft's own +# NuGet package Microsoft.Direct3D.D3D12, about 22 MB) into a D3D12 folder: by default the one beside +# target\diag\leonida.exe, the build scripts\play-nvidia.ps1 runs; -To names another. Windows 10's own Direct3D 12 +# stops at shader model 6.5, and every shader the layer translates is 6.6: without this runtime each pipeline is +# refused and the game closes within seconds. leonida.exe asks Windows for this runtime (it exports +# D3D12SDKVersion, set to the version of the file there, and D3D12SDKPath = .\D3D12\); Windows uses it only where +# its own is older. It is Microsoft's, under Microsoft's +# licence (saved beside it: read it); this repository does not carry it. The package and the DLL are checked +# against the SHA-256 of the copies tested, and the DLL against Microsoft's signature. +param( + [string]$Version = '1.614.1', + [string]$To = '' +) +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' +[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 +$dir = if ($To) { $To } else { Join-Path (Resolve-Path (Join-Path $PSScriptRoot '..')).Path 'target\diag\D3D12' } +# The SHA-256 of the copies tested: D3D12Core.dll 1.614.1.0 first, since launchers take the first hash after +# that name as the DLL's (VILauncher's "Fix and verify" took the package's and then refused every package). +$core = '8A23D826B25B4329522FF451CB52B7F2B34D7F2913CFEB878371CE8BD765FE2D' +# The package it comes in, Microsoft.Direct3D.D3D12 1.614.1. +$package = '9880AA91602DD51DD6CF7911A2BCA7A2323513B15338573CDE014B3356EEAFF2' +$url = "https://api.nuget.org/v3-flatcontainer/microsoft.direct3d.d3d12/$Version/microsoft.direct3d.d3d12.$Version.nupkg" + +$target = Join-Path $dir 'D3D12Core.dll' +if ((Test-Path $target) -and (Get-FileHash $target -Algorithm SHA256).Hash -eq $core) { + Write-Host "Microsoft's Direct3D 12 runtime $Version is already in $dir" + exit 0 +} +Write-Host "Microsoft's Direct3D 12 runtime $Version (the Agility SDK), from nuget.org (about 22 MB):" +New-Item -ItemType Directory -Force $dir | Out-Null +$part = Join-Path $dir "microsoft.direct3d.d3d12.$Version.nupkg.part" +try { + if (Get-Command curl.exe -ErrorAction SilentlyContinue) { + & curl.exe --location --fail --silent --show-error --progress-bar --output $part $url + if ($LASTEXITCODE -ne 0) { throw "could not get $url" } + } else { + Invoke-WebRequest -Uri $url -OutFile $part -UseBasicParsing + } + $hash = (Get-FileHash $part -Algorithm SHA256).Hash + if ($hash -ne $package) { throw "the package is not the one this build was tested with (SHA-256 $hash); not kept" } + Add-Type -AssemblyName System.IO.Compression.FileSystem + $zip = [IO.Compression.ZipFile]::OpenRead($part) + try { + $entry = $zip.Entries | Where-Object FullName -eq 'build/native/bin/x64/D3D12Core.dll' + if (-not $entry) { throw 'the package has no build/native/bin/x64/D3D12Core.dll' } + $dll = "$target.part" + [IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $dll, $true) + $lic = $zip.Entries | Where-Object FullName -eq 'LICENSE.txt' + if ($lic) { [IO.Compression.ZipFileExtensions]::ExtractToFile($lic, (Join-Path $dir 'microsoft-d3d12-license.txt'), $true) } + } finally { $zip.Dispose() } + $hash = (Get-FileHash $dll -Algorithm SHA256).Hash + if ($hash -ne $core) { Remove-Item $dll -Force; throw "D3D12Core.dll is not the file this build was tested with (SHA-256 $hash); not kept" } + $sig = Get-AuthenticodeSignature $dll + if ($sig.Status -ne 'Valid' -or $sig.SignerCertificate.Subject -notlike 'CN=Microsoft Corporation,*') { + Remove-Item $dll -Force; throw "D3D12Core.dll is not validly signed by Microsoft ($($sig.Status)); not kept" + } + Move-Item $dll $target -Force +} finally { + Remove-Item $part -Force -ErrorAction SilentlyContinue +} +Write-Host (' D3D12Core.dll {0:N1} MB, signed by Microsoft' -f ((Get-Item $target).Length / 1MB)) +Write-Host " in $dir (licence: microsoft-d3d12-license.txt beside it)" diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 5f5888ae9..5ec47f3b7 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -99,6 +99,17 @@ if (-not $DryRun -and $Build -eq 'diag' -and (-not (Test-Path $leonida) -or ($ca $hasDlss = (Test-Path $built) -and ((Get-Content $built -Raw) -match 'dlss') } if (-not $DryRun -and -not (Test-Path $leonida)) { Write-Host "No $leonida. Build it first (scripts\build-nvidia.ps1)."; return } +# Windows 10's own Direct3D 12 stops at shader model 6.5 and refuses every translated pipeline (6.6): there the +# exe needs Microsoft's newer runtime beside it, which it asks Windows for (apps\leonida\src\agility.rs). +# Nothing is downloaded here: Get-D3D12.cmd fetches it once. +$windowsBuild = [int](Get-CimInstance Win32_OperatingSystem).BuildNumber +$agility = Join-Path (Split-Path $leonida) 'D3D12\D3D12Core.dll' +if ($windowsBuild -lt 22000 -and -not (Test-Path $agility)) { + Write-Host "Windows 10 (build $windowsBuild): its own Direct3D 12 refuses the game's shaders (shader model 6.6)." + Write-Host "Get-D3D12.cmd in the d3d12 folder fetches Microsoft's newer runtime (about 22 MB, from nuget.org) into" + Write-Host "$(Split-Path $agility); then start this again." + if (-not $DryRun) { return } +} # A build nobody noted the making of (cargo by hand) is taken at its word: with DLSS if the files are there. # $dlssCan: DLSS can run (its files and a build with it), whoever asks for it: this start, or the F1 menu later. $dlssCan = -not $NoDlss -and $DlssDir -and ($hasDlss -or -not (Test-Path $built))