Skip to content
Closed
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
53 changes: 45 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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 |
Expand Down
6 changes: 6 additions & 0 deletions d3d12/Get-AMD-FSR.cmd
Original file line number Diff line number Diff line change
@@ -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
48 changes: 39 additions & 9 deletions d3d12/crates/leonida-gpu/src/fg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,18 @@ static GBUFFER_PENDING: Mutex<Option<(u64, u64, u64, [u32; 2])>> = 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
Expand All @@ -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 {
Expand All @@ -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);
Expand Down
116 changes: 64 additions & 52 deletions d3d12/crates/leonida-gpu/src/fsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)),
Expand All @@ -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(),
Expand All @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions d3d12/crates/leonida-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16> = caption.iter().copied().chain(text.encode_utf16()).collect();
text.push(0);
Expand Down
Loading