The title's FidelityFX calls through ours, its FidelityFX path on Series X (from DexNom's fork)

With VICTORY_DLSS=1 or VICTORY_FRAMEGEN=1 and Streamline available, the
executable's imports of amd_fidelityfx_loader_xbox.dll (ffxCreateContext,
ffxDestroyContext, ffxQuery, ffxDispatch) are bound to ours, which call
the title's own DLL for everything and give an upscale dispatch to
victory_gpu::streamline: DLSS takes it (the title's is not called), or,
with frame generation alone, its inputs are noted and the title's runs.
The title's upscaler context stays its own, so its upscaling runs again
on any frame DLSS does not take; each reason is logged once.

Series X never uses that path by itself: no Series X run (stock or
1440p) loaded amd_fidelityfx_upscaler_xbox.dll, every Series S run did.
The renderer selection (title+0x7e9421) takes the FidelityFX path,
renderer 7, only on a Series S (title+0x75140 tests the device type for
6); Series X takes renderer 6, the title's own temporal pass. The title
sizes the FidelityFX path's scene itself (title+0x28ef69a: its scale
times the output size), not through ffxQuery. So with DLSS or frame
generation available, native_1440p::prepare_upscaler patches renderer 7
in and the scaled branch to VICTORY_DLSS_MODE's scale (dlaa 1, quality
2/3, balanced 0.58, performance 1/2, ultraperformance 1/3; noted as the
FidelityFX quality mode), and the temporal scene scale to the same, with
the 1440p output kept (images/native-1440p-upscaler-<mode>-sdr) or on
its own (images/upscaler-<mode>). Each instruction is checked against
the stock bytes first; the test does so with the retail executable.
Without Streamline the image is patched as before.

`victory upscaler-check [--device] [--present]` checks Streamline, DLSS
and frame generation on this PC without the title.

The FidelityFX description layouts and the image patch of the FidelityFX
path are ported from DexNom/VIctory (crates/victory-hle/src/modules/
fidelityfx.rs, apps/victory/src/native_1440p.rs prepare_fsr_4k,
GPL-3.0-or-later); here the title's DLL keeps serving the API and the
1440p output stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 20:22:58 +05:30
1 parent fc8b9caeb3
commit d11233aa22
6 files changed
+619 -4

No files matched your search

+29
View File
@@ -153,6 +153,24 @@ enum Command {
Replay(replay::Replay),
/// Show the resolved configuration and check it.
Config,
/// Check NVIDIA Streamline, DLSS and DLSS Frame Generation on this PC
/// without the title (`VICTORY_STREAMLINE_DIR`, `VICTORY_DLSS_MODE`,
/// `VICTORY_DLSS_PRESET`): what loads and what this GPU supports; with
/// --device, the host device handed over and DLSS run three times on
/// stand-in textures; with --present too, three seconds of presents with
/// frame generation in a window of ours.
#[cfg(windows)]
UpscalerCheck {
/// The output size, `<width>x<height>`.
#[arg(long, default_value = "2560x1440")]
output: String,
/// Make the host device and run DLSS on it.
#[arg(long)]
device: bool,
/// Present for three seconds with frame generation (with --device).
#[arg(long)]
present: bool,
},
}
#[derive(Clone, Copy, ValueEnum)]
@@ -230,6 +248,17 @@ fn main() -> Result<()> {
#[cfg(all(windows, feature = "diagnostics"))]
Command::Replay(options) => replay::run(options),
Command::Config => show_config(),
#[cfg(windows)]
Command::UpscalerCheck { output, device, present } => {
let size = output
.split_once(['x', 'X'])
.and_then(|(w, h)| Some([w.trim().parse().ok()?, h.trim().parse().ok()?]))
.ok_or_else(|| anyhow::anyhow!("--output {output}: not <width>x<height>"))?;
for line in victory_hle::streamline::check(size, device || present, present) {
println!("{line}");
}
Ok(())
}
}
}
+99
View File
@@ -13,6 +13,7 @@
use anyhow::{Context, Result, ensure};
use victory_formats::texture::{Dimension, Swizzle, Texture, TextureDesc};
use victory_hle::streamline::Mode;
use victory_loader::PreparedImage;
const RETAIL_BUILD: &str = "b99f876b74d4a77f03af5f878223b27bd647b5c35a79d5decd9f716504239e93";
@@ -74,6 +75,69 @@ pub(super) fn prepare(image: &mut PreparedImage, render_1080p: bool) -> Result<(
Ok((render_width, render_height))
}
/// The title's renderer selection: `mov eax, 6; cmovne eax, ecx` (the
/// title's own temporal pass, or on Series S with the upscaler there the
/// FidelityFX path, 7).
const RENDERER_SELECTION: u32 = 0x007e_9421;
const STOCK_RENDERER_SELECTION: [u8; 8] = [0xb8, 6, 0, 0, 0, 0x0f, 0x45, 0xc1];
/// The FidelityFX path's render size: the console check's result (Series S)
/// is noted as the FidelityFX quality mode and picks the scaled branch
/// (`movzx eax, al; mov [r14+0x90], eax; test al, al; jne`), whose scale
/// multiplies the output size.
const UPSCALER_SIZING: u32 = 0x028e_f69a;
const STOCK_UPSCALER_SIZING: [u8; 14] = [0x0f, 0xb6, 0xc0, 0x41, 0x89, 0x86, 0x90, 0, 0, 0, 0x84, 0xc0, 0x75, 0x0a];
/// The native branch's load of 1.0, and the scaled branch's of the scale.
const NATIVE_LOAD: u32 = 0x028e_f6a8;
const STOCK_NATIVE_LOAD: [u8; 10] = [0xc5, 0xfa, 0x10, 0x05, 0x28, 0x78, 0x6d, 0x03, 0xeb, 0x08];
const SCALED_LOAD: u32 = 0x028e_f6b2;
const STOCK_SCALED_LOAD: [u8; 8] = [0xc5, 0xfa, 0x10, 0x05, 0xa2, 0xe2, 0x86, 0x03];
/// The scale the scaled branch loads (shared with other code: not written).
const UPSCALER_SCALE: u32 = 0x0615_d95c;
/// Makes the title render through its FidelityFX upscaler path (renderer 7,
/// as Series S does) with the scene at `mode`'s scale of the output, so that
/// DLSS can take its upscale dispatches over (`victory_hle::modules::fidelityfx`).
/// On Series X the stock title uses its own temporal pass instead and never
/// loads its upscaler. The FidelityFX quality mode the title notes is
/// `mode`'s; the temporal scene scale (the title's own pass, and
/// `prepare`'s 1440p patch) is set to the same scale, as the stock Series X
/// image pairs them (2/3 each). Every patched instruction is checked against
/// the stock bytes first; nothing is written if one differs.
///
/// From DexNom's fork (DexNom/VIctory, `apps/victory/src/native_1440p.rs`,
/// `prepare_fsr_4k`, GPL-3.0-or-later), there for a 4K output; kept here
/// with the 1440p one.
pub(super) fn prepare_upscaler(image: &mut PreparedImage, mode: Mode) -> Result<()> {
ensure!(
image.original_hash.to_hex().as_str() == RETAIL_BUILD,
"the upscaler path is only known for the retail build {RETAIL_BUILD}"
);
ensure!(*field::<8>(image, RENDERER_SELECTION)? == STOCK_RENDERER_SELECTION, "unexpected renderer selection");
ensure!(*field::<14>(image, UPSCALER_SIZING)? == STOCK_UPSCALER_SIZING, "unexpected upscaler render size selection");
ensure!(*field::<10>(image, NATIVE_LOAD)? == STOCK_NATIVE_LOAD, "unexpected upscaler native scale load");
ensure!(*field::<8>(image, SCALED_LOAD)? == STOCK_SCALED_LOAD, "unexpected upscaler scaled load");
ensure!(*field::<4>(image, UPSCALER_SCALE)? == (2.0f32 / 3.0).to_le_bytes(), "unexpected upscaler scale");
let temporal = f32::from_le_bytes(*field::<4>(image, TEMPORAL_SCALE)?);
ensure!(
temporal == 2.0 / 3.0 || temporal == 1.0,
"unexpected temporal scene scale {temporal} (stock 2/3, or 1 with the 1440p output)"
);
// Renderer 7 every time it is asked (the console check has run).
*field::<8>(image, RENDERER_SELECTION)? = [0xb8, 7, 0, 0, 0, 0x90, 0x90, 0x90];
// `mov eax, mode; mov [r14+0x90], eax; jmp scaled`.
*field::<14>(image, UPSCALER_SIZING)? = [0xb8, mode.ffx_mode(), 0, 0, 0, 0x41, 0x89, 0x86, 0x90, 0, 0, 0, 0xeb, 0x0a];
if mode != Mode::Quality {
// The jump leaves the native branch unreached: its load's operand
// becomes a literal of ours, which the scaled branch loads.
let literal = NATIVE_LOAD + 4;
*field::<4>(image, literal)? = mode.scale().to_le_bytes();
let displacement = literal as i32 - (SCALED_LOAD as i32 + 8);
*field::<4>(image, SCALED_LOAD + 4)? = displacement.to_le_bytes();
}
*field::<4>(image, TEMPORAL_SCALE)? = mode.scale().to_le_bytes();
Ok(())
}
fn field<const N: usize>(image: &mut PreparedImage, rva: u32) -> Result<&mut [u8; N]> {
let offset = image.info.rva_to_file_offset(rva).context("display profile field missing")? as usize;
image
@@ -112,4 +176,39 @@ mod tests {
assert!(prepare(&mut image, render_1080p).is_err());
}
}
/// With the retail executable (as above): the upscaler path at each
/// scale, alone (4K output) and after the 1440p patch; the scaled
/// branch then loads the mode's scale and the noted mode is its
/// FidelityFX mode.
#[test]
fn patches_the_upscaler_path() {
let Some(path) = std::env::var_os("VICTORY_DISPLAY_PROFILE_TEST_IMAGE") else {
return;
};
let bytes = std::fs::read(path).unwrap();
for native in [false, true] {
for mode in [Mode::Dlaa, Mode::Quality, Mode::Balanced, Mode::Performance, Mode::UltraPerformance] {
let mut image = victory_loader::prepare(&bytes).unwrap();
if native {
prepare(&mut image, false).unwrap();
}
prepare_upscaler(&mut image, mode).unwrap();
assert_eq!(*field::<8>(&mut image, RENDERER_SELECTION).unwrap(), [0xb8, 7, 0, 0, 0, 0x90, 0x90, 0x90]);
let sizing = *field::<14>(&mut image, UPSCALER_SIZING).unwrap();
assert_eq!(sizing[1], mode.ffx_mode());
assert_eq!(sizing[12..], [0xeb, 0x0a]);
// The jump lands on the scaled load.
assert_eq!(UPSCALER_SIZING + 14 + 0x0a, SCALED_LOAD);
let disp = i32::from_le_bytes(*field::<4>(&mut image, SCALED_LOAD + 4).unwrap());
let loaded = (SCALED_LOAD + 8).wrapping_add_signed(disp);
assert_eq!(f32::from_le_bytes(*field::<4>(&mut image, loaded).unwrap()), mode.scale());
assert_eq!(f32::from_le_bytes(*field::<4>(&mut image, TEMPORAL_SCALE).unwrap()), mode.scale());
// The shared constant stays as it was.
assert_eq!(*field::<4>(&mut image, UPSCALER_SCALE).unwrap(), (2.0f32 / 3.0).to_le_bytes());
// Patched once, refused.
assert!(prepare_upscaler(&mut image, mode).is_err());
}
}
}
}
+53 -4
View File
@@ -56,6 +56,21 @@ pub fn run(
// A title that relaunched itself: the old process must be gone first.
victory_hle::modules::lifecycle::wait_for_previous();
let cfg = victory_core::Config::load()?;
// DLSS and frame generation (`VICTORY_DLSS`, `VICTORY_FRAMEGEN`): Streamline
// is loaded before anything of the title or the host GPU, and fails soft;
// only if it offers one of them does the title render through its
// FidelityFX path, which DLSS takes over (`native_1440p::prepare_upscaler`).
let asked = victory_hle::streamline::Asked::from_env().map_err(anyhow::Error::msg)?;
let available = victory_hle::streamline::init(&asked);
let upscaler = (available.dlss || available.framegen).then_some(asked.mode);
if asked.any() {
println!(
"upscaling DLSS {}, frame generation {}{}",
if available.dlss { "on" } else if asked.dlss { "asked, not available" } else { "off" },
if available.framegen { "on" } else if asked.framegen { "asked, not available" } else { "off" },
upscaler.map(|m| format!(", scene at the {} scale ({})", m.name(), m.scale())).unwrap_or_default()
);
}
let original = std::fs::read(exe).with_context(|| format!("reading {}", exe.display()))?;
let mut prepared = victory_loader::prepare(&original)?;
let hash = prepared.original_hash.to_hex();
@@ -70,15 +85,46 @@ pub fn run(
let native_1440p = render_1080p || std::env::var("VICTORY_NATIVE_1440P").as_deref() == Ok("1");
let images = if native_1440p {
anyhow::ensure!(matches!(console, Console::SeriesX), "1440p output needs the Series X profile");
let (w, h) = native_1440p::prepare(&mut prepared, render_1080p)?;
if upscaler.is_some() && render_1080p {
println!("display VICTORY_RENDER_1080P is left out: VICTORY_DLSS_MODE sets the scene's size");
}
let (w, h) = native_1440p::prepare(&mut prepared, render_1080p && upscaler.is_none())?;
// SAFETY: nothing else runs yet; the title and the display mode list
// read these later.
unsafe {
std::env::set_var("VICTORY_DISPLAY_MODE", format!("{}x{}", native_1440p::WIDTH, native_1440p::HEIGHT));
std::env::set_var("VICTORY_NATIVE_1440P", "1");
}
println!("display {}x{} SDR, scene {w}x{h}", native_1440p::WIDTH, native_1440p::HEIGHT);
cfg.cache_subdir(if render_1080p { "images/1080p-to-1440p-sdr" } else { "images/native-1440p-sdr" })?
match upscaler.map(|mode| (mode, native_1440p::prepare_upscaler(&mut prepared, mode))) {
Some((mode, Ok(()))) => {
let [rw, rh] = mode.render_size([native_1440p::WIDTH, native_1440p::HEIGHT]);
println!(
"display {}x{} SDR, scene {rw}x{rh} through the title's FidelityFX path ({})",
native_1440p::WIDTH,
native_1440p::HEIGHT,
mode.name()
);
cfg.cache_subdir(&format!("images/native-1440p-upscaler-{}-sdr", mode.name()))?
}
other => {
if let Some((_, Err(e))) = other {
println!("upscaling the title's FidelityFX path was not patched in: {e:#}");
}
println!("display {}x{} SDR, scene {w}x{h}", native_1440p::WIDTH, native_1440p::HEIGHT);
cfg.cache_subdir(if render_1080p { "images/1080p-to-1440p-sdr" } else { "images/native-1440p-sdr" })?
}
}
} else if let Some(mode) = upscaler {
match native_1440p::prepare_upscaler(&mut prepared, mode) {
Ok(()) => {
println!("display the title's output, scene at {} of it through its FidelityFX path ({})", mode.scale(), mode.name());
cfg.cache_subdir(&format!("images/upscaler-{}", mode.name()))?
}
Err(e) => {
println!("upscaling the title's FidelityFX path was not patched in: {e:#}");
cfg.cache_subdir("images")?
}
}
} else {
cfg.cache_subdir("images")?
};
@@ -182,7 +228,10 @@ pub fn run(
show(name, dll.bind_imports(&with_dlls, policy)?);
}
let exe_name = exe.file_name().unwrap_or_default().to_string_lossy();
show(&exe_name, image.bind_imports(&with_dlls, policy)?);
// The title's FidelityFX calls go through ours when DLSS or frame
// generation is on (bound as before otherwise).
let interposed = victory_hle::modules::fidelityfx::Interpose { inner: &with_dlls };
show(&exe_name, image.bind_imports(&interposed, policy)?);
if execute {
let size = image.info().size_of_image as usize;
// SAFETY: the image stays mapped, and nothing of it has run yet.