diff --git a/README.md b/README.md index 51b2ec5c92..c19781c077 100644 --- a/README.md +++ b/README.md @@ -73,27 +73,63 @@ On 2026-11-27 the same spot measured 12 to 13 frames a second, and `main` of tha - **Your own copy** of the Xbox Series package, version 1.0.2.1, with its files readable on disk (the folder that holds `game_scarlett_master.exe`). - **Windows 10 or 11, x64**, with a CPU that has AVX2. -- **A Direct3D 12 graphics card with shader model 6.6 and mesh shaders**, NVIDIA or AMD. DLSS and frame generation - need an NVIDIA RTX card (frame generation an RTX 40 or 50). +- **A Direct3D 12 graphics card with shader model 6.6 and mesh shaders**, NVIDIA or AMD. DLSS needs an NVIDIA RTX + card. NVIDIA DLSS frame generation needs an RTX 40 or 50; this fork's experimental AMD FSR 3 frame generation + option is for older RTX cards, including the RTX 20 and 30 series. - **[Rust](https://rustup.rs/)** (rustup installs the pinned toolchain, 1.98.1, by itself) and **Visual Studio 2022 Build Tools** with *Desktop development with C++*: the runtime is built on your PC the first time. - **[Python 3.12+](https://www.python.org/downloads/)** for the launcher window (optional). ### Starting it -1. Download this repository: `git clone https://github.com/ProjectLeonida/mandy` (or the ZIP). -2. **NVIDIA cards:** double-click `d3d12\Get-NVIDIA-DLSS.cmd` once. It fetches the few NVIDIA files DLSS and frame - generation need (about 70 MB, from NVIDIA's own GitHub) into `d3d12\nvidia-sdk\`. Without them the game runs - all the same, without DLSS and frame generation. -3. **Windows 10 only:** double-click `d3d12\Get-D3D12.cmd` once. Windows 10's own Direct3D 12 stops at shader model +1. Download the `rtx3050-personal` branch of this fork (or choose that branch before downloading the ZIP): + + ```powershell + git clone --branch rtx3050-personal --single-branch ` + https://github.com/PSNBenchmark/mandy-rtx3050.git + ``` +2. **For DLSS or NVIDIA frame generation:** double-click `d3d12\Get-NVIDIA-DLSS.cmd` once. It fetches the few + NVIDIA files needed (about 70 MB, from NVIDIA's own GitHub) into `d3d12\nvidia-sdk\`. Without them the game runs + all the same, without DLSS or NVIDIA frame generation. RTX 20/30 users following the FSR steps below can skip it. +3. **RTX 20/30 series using FSR 3 frame generation:** double-click `d3d12\Get-AMD-FSR.cmd` once. It downloads and + verifies AMD's FidelityFX DLLs into the ignored `d3d12\amd-sdk\` folder. This is optional and is not needed for + the standard launcher or NVIDIA DLSS frame generation. +4. **Windows 10 only:** double-click `d3d12\Get-D3D12.cmd` once. Windows 10's own Direct3D 12 stops at shader model 6.5; this fetches Microsoft's newer runtime (the D3D12 Agility SDK) for the game to use. -4. Double-click **`Launcher.bat`** and press PLAY (settings, mods, saves and tools are on its other pages: +5. Double-click **`Launcher.bat`** and press PLAY (settings, mods, saves and tools are on its other pages: [docs/launcher.md](docs/launcher.md)). Or from PowerShell: ```powershell powershell -ExecutionPolicy Bypass -File scripts\play-d3d12.ps1 -Game "D:\path\to\your\package" ``` +#### RTX 20/30-series frame generation (experimental) + +On RTX 20/30 cards, use this fork's AMD FSR 3 frame generation instead of NVIDIA DLSS frame generation. It generates +additional displayed frames; it does not raise the game's rendered frame rate or guarantee a steady 30 FPS. The +540p profile is a starting point for a 6 GB RTX 3050. If it runs out of video memory, try 480p for a softer picture. + +In PowerShell, replace the repository path with where you cloned the fork and the game folder with the folder +containing your own `game_scarlett_master.exe`. These example paths keep the cache, saves and logs outside the +repository, so updating or replacing the checkout does not remove them: + +```powershell +Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass +Set-Location "D:\path\to\mandy-rtx3050\d3d12" +$env:LEONIDA_GAME_DIR = 'D:\path\to\your\package' +$env:LEONIDA_CACHE_DIR = 'D:\Leonida\cache-nvidia-2' +$env:LEONIDA_DATA_DIR = 'D:\Leonida\data' +$env:LEONIDA_LOG_DIR = 'D:\Leonida\logs' + +.\scripts\play-nvidia.ps1 ` + -Exe (Join-Path $env:LEONIDA_GAME_DIR 'game_scarlett_master.exe') ` + -Resolution 540 -NoDlss -FsrFrameGen -Adapter 3050 ` + -LowGraphics -NoSmoothMotion -WindowsBarMB 0 -Log +``` + +If 540p exceeds the card's available memory, change only `-Resolution 540` to `-Resolution 480`. FSR frame generation +still uses video memory, and the 480p profile may reduce image quality; neither profile guarantees a stable 30 FPS. + The first start builds the runtime (a few minutes) and translates every shader of the game into a cache before the game starts (longer the first time, seconds after). The caches and your saves are kept under `%LOCALAPPDATA%\Leonida\d3d12` (`-Data` picks another folder). @@ -107,6 +143,7 @@ Useful switches of `scripts\play-d3d12.ps1` (the launcher's Settings page has th | `-NoFrameGen` | no frame generation: only the frames the game renders | | `-MotionBlur` | the game's own motion blur (off by default: at this frame rate it smears in blocks on camera turns) | | `-FrameGen 2`…`6` with `-Dlss quality\|balanced\|performance\|ultra` | DLSS makes the output and frame generation shows 2 to 6 times the frames | +| `-FsrFrameGen` on `d3d12/scripts/play-nvidia.ps1` | experimental AMD FSR 3 frame generation at 2x; use instead of NVIDIA frame generation | | `-SeriesS` | the lighter Series S profile (720p rendered, DLSS to 1080p) | | `-RayTracing` | the game's real ray tracing: slower, shaders build for minutes the first time, not with frame generation | | `-NoPrecompile` | start at once, without translating the shaders first | diff --git a/d3d12/Get-AMD-FSR.cmd b/d3d12/Get-AMD-FSR.cmd new file mode 100644 index 0000000000..bcc87bcca8 --- /dev/null +++ b/d3d12/Get-AMD-FSR.cmd @@ -0,0 +1,6 @@ +@echo off +rem Downloads the AMD FidelityFX SDK DLLs used by the local FSR 3 frame-generation hook. +rem Files are checksum-verified and kept under amd-sdk\ (git-ignored); the game data is untouched. +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-amd-fsr.ps1" %* +echo. +pause diff --git a/d3d12/crates/leonida-gpu/src/fg.rs b/d3d12/crates/leonida-gpu/src/fg.rs index 9ebc7e3bfe..ee02ce63fc 100644 --- a/d3d12/crates/leonida-gpu/src/fg.rs +++ b/d3d12/crates/leonida-gpu/src/fg.rs @@ -794,6 +794,18 @@ static GBUFFER_PENDING: Mutex> = Mutex::new(No /// Passes submitted that a larger one of their frame stood before. static GBUFFER_PASSED_OVER: AtomicU64 = AtomicU64::new(0); +/// Whether two render targets have the same aspect ratio, within five percent. +/// The title also binds square depth/velocity targets for off-screen work; those +/// must not replace the frame-sized G-buffer used for frame generation. +fn same_aspect(a: [u32; 2], b: [u32; 2]) -> bool { + if a.contains(&0) || b.contains(&0) { + return false; + } + let aw_bh = u64::from(a[0]) * u64::from(b[1]); + let bw_ah = u64::from(b[0]) * u64::from(a[1]); + aw_bh.abs_diff(bw_ah) * 20 <= aw_bh.max(bw_ah) +} + /// A host list that bound a G-buffer pass ([`gbuffer`]) is submitted (submissions and presents are /// served in the title's order, on one thread). Of the passes submitted before a present, /// the largest is the one it tags: the title also fills smaller targets of the same kind (a pass of four @@ -804,6 +816,16 @@ pub(crate) fn gbuffer_submitted(depth: u64, motion: u64, size: [u32; 2]) { if !collecting() || !gbuffer_on() || UPSCALE_TAGS.load(Ordering::Relaxed) { return; } + let expected = LATEST.lock().unwrap_or_else(|e| e.into_inner()).as_ref().map(|l| l.render); + if let Some(expected) = expected + && !same_aspect(size, expected) + { + let n = GBUFFER_PASSED_OVER.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 4 || n.is_power_of_two() { + tracing::info!(n, ?size, ?expected, "frame generation: a G-buffer pass with another aspect ratio was passed over"); + } + return; + } let area = u64::from(size[0]) * u64::from(size[1]); let mut pending = lock(&GBUFFER_PENDING); match *pending { @@ -830,16 +852,24 @@ pub(crate) fn gbuffer_submitted(depth: u64, motion: u64, size: [u32; 2]) { /// ([`gbuffer_submitted`]) is the one it tags; none submitted, the last one stays. fn gbuffer_at_present() { let Some((area, depth, motion, size)) = lock(&GBUFFER_PENDING).take() else { return }; - // A frame whose only such pass is far smaller than the last one tagged (under half its area: the - // title's own dynamic resolution moves less, 1080 to 1440 lines being 0.56) keeps the last one. - if let Some(l) = LATEST.lock().unwrap_or_else(|e| e.into_inner()).as_ref() - && area * 2 < u64::from(l.render[0]) * u64::from(l.render[1]) - { - let n = GBUFFER_PASSED_OVER.fetch_add(1, Ordering::Relaxed) + 1; - if n <= 4 || n.is_power_of_two() { - tracing::info!(n, ?size, kept = ?l.render, "frame generation: a frame's only G-buffer pass is far smaller than the last one; that one stays"); + // Keep the last frame-sized target when another aspect ratio (often a + // square off-screen pass) wins the area comparison, or when dynamic + // resolution moves by less than half the previous frame's area. + let expected = LATEST.lock().unwrap_or_else(|e| e.into_inner()).as_ref().map(|l| l.render); + if let Some(expected) = expected { + let mismatched_aspect = !same_aspect(size, expected); + let much_smaller = area * 2 < u64::from(expected[0]) * u64::from(expected[1]); + if mismatched_aspect || much_smaller { + let n = GBUFFER_PASSED_OVER.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 4 || n.is_power_of_two() { + if mismatched_aspect { + tracing::info!(n, ?size, kept = ?expected, "frame generation: a G-buffer pass with another aspect ratio was passed over"); + } else { + tracing::info!(n, ?size, kept = ?expected, "frame generation: a frame's only G-buffer pass is far smaller than the last one; that one stays"); + } + } + return; } - return; } { let mut last = lock(&GBUFFER_LAST); diff --git a/d3d12/crates/leonida-gpu/src/fsr.rs b/d3d12/crates/leonida-gpu/src/fsr.rs index 5e50611340..e729f24029 100644 --- a/d3d12/crates/leonida-gpu/src/fsr.rs +++ b/d3d12/crates/leonida-gpu/src/fsr.rs @@ -616,11 +616,16 @@ pub(crate) fn before_present( let Some(live) = guard.as_mut() else { return }; if let Some(inputs) = &fresh { let render = inputs.render; + // Render sizes move by a few pixels with dynamic resolution. Give the context a small + // aligned margin so a 540 -> 544 line adjustment does not tear it down and recreate it. + // Keep the capacity within the output size and still pass the exact size to prepare. + let capacity = |n: u32, limit: u32| (n.saturating_add(15) / 16 * 16).min(limit); + let max_render = [capacity(render[0], size[0]), capacity(render[1], size[1])]; let flags = create_flags(inputs.near > inputs.far, format); // A context made for other sizes or formats goes first (a frame without its colour without the // interface keeps the context as it is). let stale = live.framegen.as_ref().is_some_and(|(_, (s, r, f, fl, h))| { - *s != size || r[0] < render[0] || r[1] < render[1] || *f != format || *fl != flags || (hudless_format != DXGI_FORMAT_UNKNOWN && *h != hudless_format) + *s != size || r[0] < max_render[0] || r[1] < max_render[1] || *f != format || *fl != flags || (hudless_format != DXGI_FORMAT_UNKNOWN && *h != hudless_format) }); if stale { // Everything sent so far is waited for: what was recorded with the old context has run. @@ -629,17 +634,17 @@ pub(crate) fn before_present( tracing::info!(display = ?size, max_render = ?render, "FSR 3 frame generation: its context is made again for other sizes"); } if live.framegen.is_none() && live.refused != Some((size, render)) { - match create_context(ffx, device, size, render, format, flags, hudless_format) { + match create_context(ffx, device, size, max_render, format, flags, hudless_format) { Some(context) => { tracing::info!( display = ?size, - max_render = ?render, + max_render = ?max_render, format = format.0, hudless_format = hudless_format.0, flags = format_args!("{flags:#x}"), "FSR 3 frame generation: its context was made" ); - live.framegen = Some((context, (size, render, format, flags, hudless_format))); + live.framegen = Some((context, (size, max_render, format, flags, hudless_format))); live.refused = None; } None => live.refused = Some((size, render)), @@ -653,61 +658,20 @@ pub(crate) fn before_present( live.frame_id += 1; let frame_id = live.frame_id; let debug = debug_flags(); - let mut prepared = false; + let on = fresh.is_some() && wanted; + let frame_ms = fresh.as_ref().map(|_| { + live.last_fresh.map_or(16.7, |t| (Instant::now() - t).as_secs_f32() * 1000.0).clamp(1.0, 1000.0) + }); if let Some(inputs) = &fresh { - let now = Instant::now(); - let frame_ms = live.last_fresh.map_or(16.7, |t| (now - t).as_secs_f32() * 1000.0).clamp(1.0, 1000.0); - live.last_fresh = Some(now); keep(&inputs.depth.0); keep(&inputs.motion.0); - let mut prepare = PrepareV2 { - header: Header::new(DISPATCH_PREPARE_V2), - frame_id, - flags: debug, - command_list: list.as_raw(), - render_size: inputs.render.into(), - jitter_offset: Floats { x: inputs.jitter[0], y: inputs.jitter[1] }, - motion_vector_scale: Floats { x: inputs.mv_pixels[0], y: inputs.mv_pixels[1] }, - frame_time_delta: frame_ms, - reset: inputs.reset, - // As the title gives them to its upscaler (FidelityFX's terms: near and far swapped with inverted depth). - camera_near: inputs.near, - camera_far: inputs.far, - camera_fov_angle_vertical: FOV_Y_DEGREES.to_radians(), - view_space_to_meters_factor: 1.0, - depth: Resource::texture(&inputs.depth.0, inputs.depth.1), - motion_vectors: Resource::texture(&inputs.motion.0, inputs.motion.1), - camera_position: [0.0; 3], - camera_up: [0.0, 1.0, 0.0], - camera_right: [1.0, 0.0, 0.0], - camera_forward: [0.0, 0.0, 1.0], - }; - // SAFETY: our context and a filled description of live textures in the states they are in when `list` runs. - let code = unsafe { (ffx.dispatch)(&mut **context, (&raw mut prepare).cast()) }; - if code == OK { - prepared = true; - once!( - info, - render = ?inputs.render, - back_buffer = ?size, - depth_state = format_args!("{:#x}", inputs.depth.1), - motion_state = format_args!("{:#x}", inputs.motion.1), - near = inputs.near, - far = inputs.far, - jitter = ?inputs.jitter, - mv_scale = ?inputs.mv_pixels, - frame_ms, - "FSR 3 frame generation: first frame prepared from depth and motion vectors" - ); - } else { - FAILED.fetch_add(1, Relaxed); - once!(warn, code, "FSR 3 frame generation: the prepare dispatch failed"); - } + live.last_fresh = Some(Instant::now()); } - let on = prepared && wanted; if let Some((texture, _)) = hudless.filter(|_| on) { keep(texture); } + // AMD's API requires configuration once per frame before the preparation dispatch, with + // matching frame IDs. Configure first, then record preparation on this present's command list. let mut configure = ConfigureFrameGeneration { header: Header::new(CONFIGURE_FRAMEGENERATION), swap_chain: swap_chain.as_raw(), @@ -732,6 +696,54 @@ pub(crate) fn before_present( once!(warn, code, "FSR 3 frame generation: the configuration failed"); } let on = on && code == OK; + if let Some(inputs) = &fresh { + if code == OK { + let mut prepare = PrepareV2 { + header: Header::new(DISPATCH_PREPARE_V2), + frame_id, + flags: debug, + command_list: list.as_raw(), + render_size: inputs.render.into(), + jitter_offset: Floats { x: inputs.jitter[0], y: inputs.jitter[1] }, + motion_vector_scale: Floats { x: inputs.mv_pixels[0], y: inputs.mv_pixels[1] }, + frame_time_delta: frame_ms.unwrap_or(16.7), + reset: inputs.reset, + // As the title gives them to its upscaler (FidelityFX's terms: near and far swapped with inverted depth). + camera_near: inputs.near, + camera_far: inputs.far, + camera_fov_angle_vertical: FOV_Y_DEGREES.to_radians(), + view_space_to_meters_factor: 1.0, + depth: Resource::texture(&inputs.depth.0, inputs.depth.1), + motion_vectors: Resource::texture(&inputs.motion.0, inputs.motion.1), + camera_position: [0.0; 3], + camera_up: [0.0, 1.0, 0.0], + camera_right: [1.0, 0.0, 0.0], + camera_forward: [0.0, 0.0, 1.0], + }; + // SAFETY: our context and a filled description of live textures in the states they are in when `list` runs. + let prepare_code = unsafe { (ffx.dispatch)(&mut **context, (&raw mut prepare).cast()) }; + if prepare_code == OK { + once!( + info, + render = ?inputs.render, + back_buffer = ?size, + depth_state = format_args!("{:#x}", inputs.depth.1), + motion_state = format_args!("{:#x}", inputs.motion.1), + near = inputs.near, + far = inputs.far, + jitter = ?inputs.jitter, + mv_scale = ?inputs.mv_pixels, + frame_ms = frame_ms.unwrap_or(16.7), + "FSR 3 frame generation: first frame prepared from depth and motion vectors" + ); + } else { + FAILED.fetch_add(1, Relaxed); + once!(warn, code = prepare_code, "FSR 3 frame generation: the prepare dispatch failed"); + } + } else { + FAILED.fetch_add(1, Relaxed); + } + } if ON.swap(on, Relaxed) != on { tracing::info!(on, frame_id, "FSR 3 frame generation switched"); } diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index 8476453d7e..4495cc9e75 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -12716,9 +12716,9 @@ impl Meter { // LOCAL (11/26): with frame generation, the frames shown too. let shown = crate::fg::shown_per_frame(); let text = if shown > 1 { - format!(" | Leonida {fps:.0} fps (frame gen {:.0} fps) {ms:.1} ms/frame {draws:.0} draws/frame", fps * f64::from(shown)) + format!(" | RTX 3050 {fps:.0} fps (frame gen {:.0} fps) {ms:.1} ms/frame {draws:.0} draws/frame", fps * f64::from(shown)) } else { - format!(" | Leonida {fps:.0} fps {ms:.1} ms/frame {draws:.0} draws/frame") + format!(" | RTX 3050 {fps:.0} fps {ms:.1} ms/frame {draws:.0} draws/frame") }; let mut text: Vec = caption.iter().copied().chain(text.encode_utf16()).collect(); text.push(0); diff --git a/d3d12/crates/leonida-gpu/src/queue.rs b/d3d12/crates/leonida-gpu/src/queue.rs index 6c095d2544..b65ed9f576 100644 --- a/d3d12/crates/leonida-gpu/src/queue.rs +++ b/d3d12/crates/leonida-gpu/src/queue.rs @@ -1026,6 +1026,28 @@ extern "system" fn timestamp_frequency(_: This, out: *mut u64) -> HRESULT { unsafe { out.write(TIMESTAMP_FREQUENCY) }; S_OK } + +/// `SuspendX(flags)`: the work already submitted by this queue is drained +/// before the title suspends it. A PC queue keeps accepting work, so the +/// operation only needs to preserve the layer's submission ordering. +extern "system" fn suspend_x(_: This, flags: u32) -> HRESULT { + tracing::info!(flags, "the title suspends a queue"); + #[cfg(windows)] + { + before_sync(); + if crate::host::late() { + crate::host::settle_for_fence(); + } + release_held(false); + } + S_OK +} + +/// `ResumeX()`: the host queue did not stop accepting submissions. +extern "system" fn resume_x(_: This) -> HRESULT { + tracing::info!("the title resumes a queue"); + S_OK +} const TIMESTAMP_FREQUENCY: u64 = 100_000_000; /// What a list's bottom-of-pipe write stores when the list has run. @@ -1498,7 +1520,7 @@ extern "system" fn desc(this: This, out: *mut QueueDesc) { /// The queue methods by their slot in older titles' queues (the 2020-era /// layout): IUnknown 3, object 4, device child 1, queue 26 (12 as on PC, /// then console ones). -const METHODS: [(usize, *const ()); 15] = [ +const METHODS: [(usize, *const ()); 17] = [ (0, query as *const ()), (2, release as *const ()), (7, object::parent_device as *const ()), // 0x38 @@ -1509,6 +1531,8 @@ const METHODS: [(usize, *const ()); 15] = [ (14, signal as *const ()), // 0x70 (15, wait as *const ()), // 0x78 (16, timestamp_frequency as *const ()), // 0x80 + (21, suspend_x as *const ()), // 0xa8 (newer 0xb8) + (22, resume_x as *const ()), // 0xb0 (newer 0xc0) (26, desc as *const ()), // 0xd0 (29, copy_page_mappings as *const ()), // 0xe8 page mapping batch (30, present as *const ()), // 0xf0 diff --git a/d3d12/scripts/get-amd-fsr.ps1 b/d3d12/scripts/get-amd-fsr.ps1 new file mode 100644 index 0000000000..e0ba5bfec5 --- /dev/null +++ b/d3d12/scripts/get-amd-fsr.ps1 @@ -0,0 +1,41 @@ +# Fetch the AMD FidelityFX SDK 2.4.0 DLLs used by this tree's FSR 3 frame-generation hook. +# The two binaries are taken from AMD's own GitHub and verified against the hashes measured by VIctory-NVIDIA. +# AMD's license text is saved beside them; the files are ignored by git and are not part of this repository. +param([string]$To = '') +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' +[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 +$bin = if ($To) { $To } else { Join-Path (Resolve-Path (Join-Path $PSScriptRoot '..')).Path 'amd-sdk\FidelityFX\bin' } +$base = 'https://raw.githubusercontent.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/v2.4.0/Kits/FidelityFX' +$files = [ordered]@{ + 'amd_fidelityfx_loader_dx12.dll' = 'E2191D3C0828BE45EB8AFFD4E3EC0378F2293ADC345B772A7170EDCF3B021ECB' + 'amd_fidelityfx_framegeneration_dx12.dll' = 'E6843252F58B0341A0D80F6A20BC0D840643EE95BC48C22CAC08745344577BB6' +} +Write-Host 'AMD FidelityFX SDK v2.4.0 (FSR frame generation), from AMD GPUOpen GitHub:' +New-Item -ItemType Directory -Force $bin | Out-Null +foreach ($name in $files.Keys) { + $toPath = Join-Path $bin $name + if ((Test-Path $toPath) -and (Get-FileHash $toPath -Algorithm SHA256).Hash -eq $files[$name]) { + Write-Host " $name is already present and verified" + continue + } + $part = "$toPath.part" + if (Get-Command curl.exe -ErrorAction SilentlyContinue) { + & curl.exe --location --fail --silent --show-error --output $part "$base/signedbin/$name" + if ($LASTEXITCODE -ne 0) { Remove-Item $part -ErrorAction SilentlyContinue; throw "Could not download $name from AMD GPUOpen." } + } else { + Invoke-WebRequest -Uri "$base/signedbin/$name" -OutFile $part -UseBasicParsing + } + $hash = (Get-FileHash $part -Algorithm SHA256).Hash + if ($hash -ne $files[$name]) { + Remove-Item $part -Force + throw "$name did not match the expected AMD SDK v2.4.0 SHA-256; it was not installed." + } + Move-Item $part $toPath -Force + Write-Host (" {0} {1:N1} MB SHA-256 verified" -f $name, ((Get-Item $toPath).Length / 1MB)) +} +$license = Join-Path $bin 'amd-fidelityfx-license.md' +if (-not (Test-Path $license)) { + try { Invoke-WebRequest -Uri "$base/docs/license.md" -OutFile $license -UseBasicParsing } catch { Write-Host " AMD license text download failed: $($_.Exception.Message)" } +} +Write-Host " AMD license: $license" diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 4f40e20599..f08467829f 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -14,7 +14,8 @@ # makes its 3840x2160 output, as before. # -Dlss DLSS makes the output, from a render height by mode: quality (2/3 of the output's lines: 1440 on # Series X, the game's own 720 on Series S), balanced (0.6: 1296), performance (1/2: 1080) or ultra -# (1/3: 720). On Series X the title is made to upscale through FidelityFX as on Series S +# (1/3: 720). On Series S, 480p pins the input to 480 lines and selects DLSS Performance. On +# Series X the title is made to upscale through FidelityFX as on Series S # (LEONIDA_FSR_UPSCALER), which is where DLSS takes over. # -FrameGen DLSS frame generation: 2 (twice the frames shown), up to 6 where the card does more (RTX 40: 2). # It takes depth and motion vectors from the DLSS upscale, so on Series X it turns -Dlss quality on @@ -31,6 +32,7 @@ # -Aspect the window's shape: 21:9, 32:9, 16:9, W:H or auto (the screen's). The game still draws 16:9. # -PresentScale fit (the 16:9 picture centred, black bars beside it: the default with -Aspect) or stretch # -Quality fewer stretched/jumping bodies, slower (relay stage 1, no card steps) +# -LowGraphics set the game's local settings file to its lighter performance profile # -RayTracing the title's real ray tracing (the structure builder runs). Shaders build for minutes the # first time, and DLSS frame generation is left off with it (the two together do not work yet). # -Resolution the older path: the game renders at this height (2160, 1440, 1080, 720, 540 or 480) and the @@ -43,14 +45,15 @@ # -Adapter on a PC with more than one card, the one to use: part of its name (-Adapter 5060) or its index # (-Adapter '#1'). Default: Windows' default card. # -Build target\diag (the default, the build all measurements are of) or target\release +# -LayerExe use a local layer executable outside target\ (for example, while that exe is in use) # -DlssDir the folder with nvngx_dlss.dll, if not nvidia-sdk\DLSS\lib\Windows_x86_64\rel # -StreamlineDir the folder with sl.interposer.dll (frame generation), if not nvidia-sdk\Streamline\bin\x64 # -NoPrecompile start at once. By default every shader of the title is translated into the cache and the # pipelines earlier runs drew with are made before the title starts (minutes the first time # and after a change of the layer, seconds otherwise), so that the world does not come up # half drawn or stall while they are made. -# -Log the layer's log goes to a file in %LOCALAPPDATA%\Leonida\logs instead of this window -# -Capture F9 in the game saves that frame and the pictures it drew, in %LOCALAPPDATA%\Leonida\captures +# -Log the layer's log goes to LEONIDA_LOG_DIR (default: %LOCALAPPDATA%\Leonida\logs) +# -Capture F9 saves a frame under LEONIDA_CAPTURE_DIR (default: %LOCALAPPDATA%\Leonida\captures) # -WindowsBarMB maximum MiB of title memory windows in CPU-mapped VRAM (by default 3072 on PCs with under # 24 GB of RAM, else 0; -WindowsBarMB 0 turns it off). # -More other settings: -More @{LEONIDA_PANEL='1'} @@ -65,10 +68,11 @@ param( [switch]$NoDlss, [switch]$SeriesX, [switch]$Quality, + [switch]$LowGraphics, [switch]$RayTracing, [ValidateSet('2160', '1440', '1080', '720', '540', '480')][string]$Resolution, [ValidateSet('1440', '1080', '720', '540', '480')][string]$Lowest, - [ValidateSet('quality', 'balanced', 'performance', 'ultra')][string]$Dlss, + [ValidateSet('quality', 'balanced', 'performance', 'ultra', '480p')][string]$Dlss, [ValidateRange(2, 6)][int]$FrameGen, [switch]$NoFrameGen, [switch]$MotionBlur, @@ -78,6 +82,7 @@ param( [ValidateSet('fit', 'stretch')][string]$PresentScale, [string]$Adapter, [ValidateSet('diag', 'release')][string]$Build = 'diag', + [string]$LayerExe, [string]$DlssDir, [string]$StreamlineDir, [switch]$NoPrecompile, @@ -93,6 +98,7 @@ if (-not (Test-Path $Exe)) { Write-Host "No $Exe."; return } if ($Dlss -and ($Resolution -or $Lowest)) { Write-Host '-Dlss sets the render height by its mode: leave -Resolution and -Lowest out with it.'; return } if ($Resolution -and $Lowest) { Write-Host '-Resolution holds one height, -Lowest lets the title pick from a lowest one: one or the other.'; return } if ($Dlss -and $NoDlss) { Write-Host '-Dlss and -NoDlss: one or the other.'; return } +if ($Dlss -eq '480p' -and $SeriesX) { Write-Host '-Dlss 480p is the Series S 480-to-1080 profile; leave -SeriesX out.'; return } $Exe = (Resolve-Path $Exe).Path # NVIDIA's own files: where they are (Get-NVIDIA-DLSS.cmd puts them in nvidia-sdk\). Nothing is downloaded here. @@ -112,10 +118,14 @@ if ($wantDlss -and -not $DlssDir) { # The build: made here if there is none, and made again with DLSS once its SDK is there (the diag build only). $leonida = Join-Path $root "target\$Build\leonida.exe" -$built = Join-Path $root "target\$Build\built-with.txt" +if ($LayerExe) { + if (-not (Test-Path -LiteralPath $LayerExe -PathType Leaf)) { Write-Host "No layer executable at '$LayerExe'."; return } + $leonida = (Resolve-Path -LiteralPath $LayerExe).Path +} +$built = Join-Path (Split-Path $leonida) 'built-with.txt' $hasDlss = (Test-Path $built) -and ((Get-Content $built -Raw) -match 'dlss') $canDlss = $wantDlss -and (Test-Path $sdkDlssLib) -if (-not $DryRun -and $Build -eq 'diag' -and (-not (Test-Path $leonida) -or ($canDlss -and -not $hasDlss -and (Test-Path $built)))) { +if (-not $LayerExe -and -not $DryRun -and $Build -eq 'diag' -and (-not (Test-Path $leonida) -or ($canDlss -and -not $hasDlss))) { if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { Write-Host 'No build and no cargo: install Rust (README.md), then start this again.'; return } Write-Host 'Building the layer (a few minutes the first time) ...' & (Join-Path $PSScriptRoot 'build-nvidia.ps1') @@ -125,9 +135,15 @@ if (-not $DryRun -and -not (Test-Path $leonida)) { Write-Host "No $leonida. Buil # 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 +$windowsBuild = $null +try { $windowsBuild = [int](Get-CimInstance Win32_OperatingSystem -ErrorAction Stop).BuildNumber } catch { } +if (-not $windowsBuild) { + # Some Windows sandboxes deny CIM even though the local OS version is readable from the registry. + $registryBuild = try { (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name CurrentBuildNumber -ErrorAction Stop).CurrentBuildNumber } catch { $null } + if ($registryBuild -match '^\d+$') { $windowsBuild = [int]$registryBuild } +} $agility = Join-Path (Split-Path $leonida) 'D3D12\D3D12Core.dll' -if ($windowsBuild -lt 22000 -and -not (Test-Path $agility)) { +if ($windowsBuild -and $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." @@ -135,8 +151,19 @@ if ($windowsBuild -lt 22000 -and -not (Test-Path $agility)) { } # 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)) +$dlssRuntime = $DlssDir -and (Test-Path (Join-Path $DlssDir 'nvngx_dlss.dll')) +$dlssCan = -not $NoDlss -and $dlssRuntime -and ($hasDlss -or -not (Test-Path $built)) $dlssOn = $wantDlss -and $dlssCan +if ($Dlss -and -not $dlssOn) { + if (-not $dlssRuntime) { + Write-Host "Cannot start -Dlss ${Dlss}: nvngx_dlss.dll was not found in '$DlssDir'." + Write-Host 'Run d3d12\Get-NVIDIA-DLSS.cmd, then start this command again.' + } else { + Write-Host "Cannot start -Dlss ${Dlss}: target\$Build\leonida.exe was built without the DLSS feature." + Write-Host 'Run d3d12\scripts\build-nvidia.ps1 after Get-NVIDIA-DLSS.cmd, then start this command again.' + } + return +} $settings = @{ # The play set. Textures are waited for: one loaded once at the start could stay empty for the run otherwise. @@ -362,7 +389,8 @@ if ($smallCard) { } $console = if ($SeriesX) { 'series-x' } else { 'series-s' } # The render scale of each DLSS mode (rendered lines over output lines; the layer picks DLSS's own mode by it). -$dlssScale = @{ quality = '0.6667'; balanced = '0.6'; performance = '0.5'; ultra = '0.3333' } +$dlssScale = @{ quality = '0.6667'; balanced = '0.6'; performance = '0.5'; ultra = '0.3333'; '480p' = '0.444444' } +$dlssQuality = @{ quality = '2'; balanced = '1'; performance = '0'; ultra = '3'; '480p' = '0' } if ($DlssDir) { $settings.LEONIDA_DLSS_DIR = $DlssDir } if ($Resolution -or $Lowest) { # The older path: a render scale and the title's own upscaler (rendered height over output height). -Lowest sets @@ -507,6 +535,18 @@ if (Test-Path $menuFile) { # Leonida: the runs write down the pipelines the title creates (pipeline/known.rs), for the precompile below. if (-not $NoPrecompile) { $settings.LEONIDA_PIPELINE_BOOK = '1' } foreach ($k in $More.Keys) { $settings[$k] = $More[$k] } +# An explicit FSR frame-generation switch also wins over an F1-saved disabled value. +if ($FsrFrameGen) { $settings.LEONIDA_FSR_FRAMEGEN = '1' } +# An explicit launcher DLSS mode wins over the F1 menu's saved own-upscaler or render-scale values. Without this, +# OWN UPSCALER=ON silently bypasses the requested DLSS path; pin the requested mode and remove those overrides. +if ($Dlss -and $dlssOn) { + $settings.LEONIDA_UPSCALE = 'dlss' + $settings.LEONIDA_RENDER_SCALE = $dlssScale[$Dlss] + $settings.LEONIDA_DLSS_QUALITY = $dlssQuality[$Dlss] + $settings.Remove('LEONIDA_OWN_UPSCALER') + $settings.Remove('LEONIDA_RENDER_SCALE_MIN') +} +if ($LowGraphics) { $settings.LEONIDA_TITLE_GRAPHICS = 'performance' } # DLSS only where it can be: a menu choice of it without the files or the build falls back to the stretch # (Series X: to the title's own upscaler, which is sharper than a stretch to 3840x2160). if ($settings.LEONIDA_UPSCALE -eq 'dlss' -and -not $dlssCan) { @@ -518,7 +558,7 @@ if ($settings.LEONIDA_BVH_BUILDER -eq '1' -and $settings.LEONIDA_FRAME_GEN -and Write-Host 'Ray tracing is on: DLSS frame generation is left off (the two together do not work yet).' $settings.Remove('LEONIDA_FRAME_GEN') } -if ($settings.LEONIDA_FRAME_GEN -and -not $StreamlineDir) { +if ($settings.LEONIDA_FRAME_GEN -and -not $StreamlineDir -and $settings.LEONIDA_FSR_FRAMEGEN -ne '1') { Write-Host 'Frame generation needs the Streamline files (Get-NVIDIA-DLSS.cmd): left off.' $settings.Remove('LEONIDA_FRAME_GEN') } @@ -531,6 +571,7 @@ if ($settings.LEONIDA_FSR_FRAMEGEN -eq '1') { if ($fsrFiles | Where-Object { -not (Test-Path $_) }) { Write-Host "FSR 3 frame generation needs AMD's amd_fidelityfx_loader_dx12.dll and amd_fidelityfx_framegeneration_dx12.dll" Write-Host "in $FidelityFxDir (the FidelityFX SDK's bin folder, from AMD's GitHub): left off." + if ($FsrFrameGen) { return } $settings.Remove('LEONIDA_FSR_FRAMEGEN') } elseif ($settings.LEONIDA_BVH_BUILDER -eq '1' -and $settings.LEONIDA_FG_WITH_RT -ne '1') { Write-Host 'Ray tracing is on: FSR 3 frame generation is left off (as DLSS frame generation is).' @@ -576,7 +617,8 @@ $settings.LEONIDA_MENU_CONSOLE = $console $settings.LEONIDA_MENU_FILE = $menuFile $settings.LEONIDA_MENU_PLAY = $MyInvocation.MyCommand.Path $again = @("-Exe '$($Exe -replace "'", "''")'", "-Build $Build") -foreach ($s in 'NoSmoothMotion', 'NoDlss', 'SeriesX', 'Quality', 'RayTracing', 'FsrFrameGen', 'NoPrecompile', 'Log', 'Capture') { +if ($LayerExe) { $again += "-LayerExe '$($leonida -replace "'", "''")'" } +foreach ($s in 'NoSmoothMotion', 'NoDlss', 'SeriesX', 'Quality', 'LowGraphics', 'RayTracing', 'FsrFrameGen', 'NoPrecompile', 'Log', 'Capture') { if ($PSBoundParameters[$s]) { $again += "-$s" } } foreach ($s in 'Resolution', 'Lowest', 'Dlss', 'FrameGen', 'Aspect', 'PresentScale', 'Adapter', 'DlssDir', 'StreamlineDir', 'FidelityFxDir') { @@ -622,7 +664,7 @@ if ($smooth) { Get-ChildItem (Join-Path (Split-Path $leonida) '*.old-*') -ErrorAction SilentlyContinue | Remove-Item -ErrorAction SilentlyContinue # (Other settings left over in this window go; where your files are stays.) -$paths = 'LEONIDA_CONFIG', 'LEONIDA_GAME_DIR', 'LEONIDA_CACHE_DIR', 'LEONIDA_DATA_DIR' +$paths = 'LEONIDA_CONFIG', 'LEONIDA_GAME_DIR', 'LEONIDA_CACHE_DIR', 'LEONIDA_DATA_DIR', 'LEONIDA_LOG_DIR', 'LEONIDA_CAPTURE_DIR' Get-ChildItem Env:LEONIDA_* | Where-Object { $_.Name -notin $paths } | ForEach-Object { Remove-Item "Env:$($_.Name)" } foreach ($k in $settings.Keys) { Set-Item "Env:$k" $settings[$k] } # Leonida: the keyboard-and-mouse and PlayStation button prompts. The title has only Xbox glyphs; the layer serves @@ -778,7 +820,8 @@ if (-not $NoPrecompile) { } $stamp = Get-Date -Format 'MMdd-HHmmss' if ($Capture) { - $env:LEONIDA_CAPTURE = Join-Path $env:LOCALAPPDATA "Leonida\captures\$stamp" + $captureRoot = if ($env:LEONIDA_CAPTURE_DIR) { $env:LEONIDA_CAPTURE_DIR } else { Join-Path $env:LOCALAPPDATA 'Leonida\captures' } + $env:LEONIDA_CAPTURE = Join-Path $captureRoot $stamp $env:LEONIDA_DUMP_TARGETS = '1' New-Item -ItemType Directory -Force $env:LEONIDA_CAPTURE | Out-Null Write-Host "F9 saves a frame to $env:LEONIDA_CAPTURE" @@ -787,7 +830,7 @@ $runArgs = @('run', "`"$Exe`"", '--execute', '--console', $console) Push-Location $root # leonida.toml is looked for here try { if ($Log) { - $logs = Join-Path $env:LOCALAPPDATA 'Leonida\logs' + $logs = if ($env:LEONIDA_LOG_DIR) { $env:LEONIDA_LOG_DIR } else { Join-Path $env:LOCALAPPDATA 'Leonida\logs' } New-Item -ItemType Directory -Force $logs | Out-Null Get-ChildItem $logs -Filter 'play-*.log' | Sort-Object LastWriteTime -Descending | Select-Object -Skip 4 | Remove-Item -ErrorAction SilentlyContinue Write-Host "log: $logs\play-$stamp.log"