Upscaling and frame generation: the 30 fps gate, fallbacks, and the DLSS step-down

- Frame generation under 30 fps (VICTORY_FRAMEGEN_MIN_FPS): the switch on now needs 90 % of frames at a 29th of a second or less, one frame a second of slack. At the title's own 30 cap about half the frames come a little over a 30th, so the gate never turned it on. New tests: a 30 cap with up to 1 ms of jitter turns it on; a steady 28 never does.
- A failed DLSS or FSR upscaling now records the plain stretch of the scene over the output. The title's own upscaling does not run for that frame, so before this the output kept the frame before. VICTORY_UPSCALE_FALLBACK=0 restores 0.8.3's behaviour.
- DLSS out of the card's memory: the budget steps down after 30 "out of VRAM" answers within 120 upscalings (about four seconds at 30 fps), not only 30 in a row. Failures with successes between them never stepped it down. New tests cover alternating, consecutive and rare failures.
- FSR 4 frame generation: when FidelityFX refuses the FSR 4 swap chain, FSR 3's is made instead, and the generator follows it. Before, frame generation stayed off for the session.
- AMD's upscaler and frame generation alone no longer load Streamline. Streamline has no default folder any more: without VICTORY_STREAMLINE_DIR, DLSS and its frame generation stay off and say why. 0.8.3 tried a developer's folder on FSR-only runs and logged that the title's own upscaling ran. The DLSS setup doc says so.
- Removed the Series S flag that nothing read.

Tests: victory-gpu 639 passed. Clippy is clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
readmet3xt-lab
2026-12-03 02:09:20 +05:30
parent 465a1e95ec
commit 889d607b62
4 changed files with 173 additions and 41 deletions

View File

@ -17,7 +17,7 @@
//! the latency markers Frame Generation needs (Reflex on). Needs the line
//! of submissions (`VICTORY_THIN=1` or `VICTORY_ASYNC_SUBMIT=1`).
//! - `VICTORY_STREAMLINE_DIR`: the folder of `sl.interposer.dll`, its plugins
//! and NGX's DLLs (default [`DEFAULT_DIR`]).
//! and NGX's DLLs (none by default: DLSS and its frame generation then stay off).
//!
//! Anything missing (the folder, a signature, a feature on this GPU, the
//! device hand-over) leaves the title's own upscaling and our plain present
@ -46,8 +46,6 @@ use windows::core::Interface;
use crate::object::Object;
/// Where `sl.interposer.dll` is looked for without `VICTORY_STREAMLINE_DIR`.
pub const DEFAULT_DIR: &str = r"C:\dev\sdk\streamline-sdk-v2.14.16\bin\x64";
const INTERPOSER: &str = "sl.interposer.dll";
/// The project id NGX is given (engine "custom", no NVIDIA application id).
const PROJECT_ID: &CStr = c"6f0d7b2e-3a41-4c1e-9b57-2d8e4f1a9c30";
@ -86,10 +84,6 @@ pub struct Asked {
/// `VICTORY_FSR_UPSCALE`: AMD's PC upscaler in DLSS's place ([`fsr_upscale`]).
pub fsr_upscale: fsr_upscale::Asked,
pub fidelityfx_dir: PathBuf,
/// The Series S profile (`VICTORY_CONSOLE=series-s`, set by the runner). Without DLSS the
/// title's own FidelityFX upscales, made for the Series S sizes only: FSR 3 frame generation,
/// which needs that upscaling, runs on Series X with DLSS only.
pub series_s: bool,
}
impl Asked {
@ -118,7 +112,7 @@ impl Asked {
framegen,
mode,
preset,
dir: var("VICTORY_STREAMLINE_DIR").map_or_else(|| PathBuf::from(DEFAULT_DIR), PathBuf::from),
dir: var("VICTORY_STREAMLINE_DIR").map(PathBuf::from).unwrap_or_default(),
jitter: plan::pair(var("VICTORY_DLSS_JITTER").as_deref()),
mvec: plan::pair(var("VICTORY_DLSS_MV").as_deref()),
reactive: var("VICTORY_DLSS_REACTIVE").is_none_or(|v| v.trim() != "0"),
@ -128,13 +122,19 @@ impl Asked {
fsr_framegen,
fsr_upscale,
fidelityfx_dir: fsr::dir_from_env(),
series_s: crate::console::current() == crate::console::Console::SeriesS,
})
}
pub fn any(&self) -> bool {
self.dlss || self.framegen || self.fsr_upscale != fsr_upscale::Asked::Off
}
/// Whether anything asked for comes from Streamline (DLSS, its frame generation): AMD's
/// upscaler and frame generation alone load no Streamline (0.8.3 tried a folder of its
/// developers' and logged that the title's own upscaling ran).
pub fn streamline(&self) -> bool {
self.dlss || self.framegen
}
}
/// What [`init`] made available: the upscaling (the title's renderer may be
@ -488,11 +488,41 @@ pub(crate) fn title_presents(frame: u64) {
// left to the title; presents with frame generation on and off, frames it
// reported shown; and in all.
static EVALUATED: AtomicU64 = AtomicU64::new(0);
/// Upscalings in a row that DLSS answered "out of VRAM" (back to 0 with one that worked), and
/// how many of them take the budget a step down (`crate::host::dlss_out_of_memory`): a
/// second's worth at 30 fps.
static OUT_OF_VRAM_RUN: AtomicU64 = AtomicU64::new(0);
const OUT_OF_VRAM_RUN_STEP: u64 = 30;
/// DLSS's "out of VRAM" answers in the present window of upscalings: the upscalings counted (high
/// 32 bits) and the failures among them (low 32). [`OUT_OF_VRAM_STEP`] failures within
/// [`OUT_OF_VRAM_WINDOW`] upscalings (about four seconds at 30 fps) take the budget a step down
/// (`crate::host::dlss_out_of_memory`); a window without that many starts again. (0.8.3 needed
/// them all in a row, so failures with a success between them never stepped it down.)
static OUT_OF_VRAM: AtomicU64 = AtomicU64::new(0);
const OUT_OF_VRAM_STEP: u64 = 30;
const OUT_OF_VRAM_WINDOW: u64 = 120;
/// [`OUT_OF_VRAM`] after one more upscaling (`out_of_vram`: DLSS answered so), and whether the
/// budget comes a step down now.
fn out_of_vram_next(state: u64, out_of_vram: bool) -> (u64, bool) {
let (seen, failed) = ((state >> 32) + 1, (state & 0xffff_ffff) + u64::from(out_of_vram));
if failed >= OUT_OF_VRAM_STEP {
return (0, true);
}
if seen >= OUT_OF_VRAM_WINDOW {
return (0, false);
}
((seen << 32) | failed, false)
}
/// An upscaling's answer into [`OUT_OF_VRAM`]: the budget a step down when a window holds enough
/// "out of VRAM".
fn note_out_of_vram(out_of_vram: bool) {
let mut step = false;
let _ = OUT_OF_VRAM.fetch_update(Relaxed, Relaxed, |state| {
let (next, now) = out_of_vram_next(state, out_of_vram);
step = now;
Some(next)
});
if step {
crate::host::dlss_out_of_memory();
}
}
static FAILED: AtomicU64 = AtomicU64::new(0);
static FORWARDED: AtomicU64 = AtomicU64::new(0);
static FG_ON: AtomicU64 = AtomicU64::new(0);
@ -523,7 +553,7 @@ pub(crate) fn generated_frames() -> Option<u64> {
/// title's imports are bound. Fails soft: what is not there is logged and
/// left off.
pub fn init(asked: &Asked) -> Available {
let available = if !asked.any() {
let available = if !asked.streamline() {
Available::default()
} else {
match load_and_init(asked, true) {
@ -581,6 +611,9 @@ pub fn init(asked: &Asked) -> Available {
}
fn load_and_init(asked: &Asked, require_line: bool) -> Result<Available, String> {
if asked.dir.as_os_str().is_empty() {
return Err("no Streamline folder was given (VICTORY_STREAMLINE_DIR, the launcher's Streamline folder)".to_owned());
}
let path = std::path::absolute(asked.dir.join(INTERPOSER)).map_err(|e| e.to_string())?;
if !path.is_file() {
return Err(format!("no {INTERPOSER} in that folder (VICTORY_STREAMLINE_DIR)"));
@ -1113,13 +1146,16 @@ pub fn upscale(up: &Upscale) -> Taken {
if framegen {
note(host, &up, id);
}
// A failed upscaling falls back to the plain stretch of the scene over the output: the
// title's own upscaling does not run for this frame (`Taken::Dlss`), so without it the
// output kept the frame before (`VICTORY_UPSCALE_FALLBACK=0`: as in 0.8.3).
if fsr_up {
return fsr_evaluate(host, &up, id);
return fsr_evaluate(host, &up, id) || upscale_fallback() && stretch_evaluate(host, &up);
}
if stretch_up {
return stretch_evaluate(host, &up);
}
dlss && evaluate(host, &up, id)
dlss && (evaluate(host, &up, id) || upscale_fallback() && stretch_evaluate(host, &up))
}),
);
if !asked {
@ -1128,6 +1164,13 @@ pub fn upscale(up: &Upscale) -> Taken {
if dlss || fsr_up || stretch_up { Taken::Dlss } else { Taken::Noted }
}
/// Whether a failed DLSS or FSR upscaling falls back to the plain stretch (on;
/// `VICTORY_UPSCALE_FALLBACK=0`: the output keeps the frame before, as in 0.8.3).
fn upscale_fallback() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_UPSCALE_FALLBACK").is_none_or(|v| v != "0"))
}
/// The title's own upscaling ran for this reason.
pub fn forwarded() {
FORWARDED.fetch_add(1, Relaxed);
@ -1533,15 +1576,12 @@ fn record(list: *mut c_void, textures: &Textures, camera: &plan::Camera, pre_exp
inputs.extend(tags.iter_mut().map(|t| std::ptr::from_ref(&t.base)));
// SAFETY: an open command list; inputs that live through the call.
let code = unsafe { (sl.evaluate_feature)(abi::FEATURE_DLSS, token, inputs.as_ptr(), inputs.len() as u32, list) };
// Out of the card's memory often enough within a window of upscalings: the budget comes down
// a step (and again after as many more, up to the host's most).
note_out_of_vram(code == abi::RESULT_OUT_OF_VRAM);
if code != 0 {
// Out of the card's memory, a second's worth of upscalings in a row: the budget comes
// down a step (and again after as many more, up to the host's most).
if code == abi::RESULT_OUT_OF_VRAM && (OUT_OF_VRAM_RUN.fetch_add(1, Relaxed) + 1).is_multiple_of(OUT_OF_VRAM_RUN_STEP) {
crate::host::dlss_out_of_memory();
}
return Err(format!("slEvaluateFeature: {} ({code})", abi::result_name(code)));
}
OUT_OF_VRAM_RUN.store(0, Relaxed);
crate::host::dlss_memory_fine();
if let Some(began) = began {
spent(T_UPSCALE, began);
@ -2454,3 +2494,43 @@ pub(crate) fn line(frames: f64) {
}
}
}
#[cfg(test)]
mod out_of_vram_tests {
use super::{OUT_OF_VRAM_STEP, OUT_OF_VRAM_WINDOW, out_of_vram_next};
/// Feeds `answers` (true: out of VRAM) from an empty window; the upscalings after which the
/// budget stepped down.
fn steps(answers: impl IntoIterator<Item = bool>) -> Vec<usize> {
let mut state = 0;
let mut at = Vec::new();
for (k, oom) in answers.into_iter().enumerate() {
let (next, step) = out_of_vram_next(state, oom);
state = next;
if step {
at.push(k);
}
}
at
}
#[test]
fn failures_between_successes_step_the_budget_down() {
// Every other upscaling out of VRAM: never 30 in a row, 30 within the window; a step at
// each 30th failure, the window starting again after each.
let alternating = (0..OUT_OF_VRAM_WINDOW as usize).map(|k| k % 2 == 0);
let first = 2 * (OUT_OF_VRAM_STEP as usize - 1);
assert_eq!(steps(alternating), vec![first, first + 2 * OUT_OF_VRAM_STEP as usize]);
}
#[test]
fn thirty_in_a_row_still_step_it_down_once() {
assert_eq!(steps(std::iter::repeat_n(true, OUT_OF_VRAM_STEP as usize)), vec![OUT_OF_VRAM_STEP as usize - 1]);
}
#[test]
fn rare_failures_never_do() {
// One in five: 24 within a window of 120, then the window starts again.
assert!(steps((0..10 * OUT_OF_VRAM_WINDOW as usize).map(|k| k % 5 == 0)).is_empty());
}
}

View File

@ -467,6 +467,15 @@ fn ml(ffx: &Ffx, device: *mut c_void) -> Option<(u64, u64)> {
})
}
/// FidelityFX refused the FSR 4 swap chain the driver offered, and FSR 3 frame generation made one
/// ([`swap_chain`]): the generator is FSR 3's too ([`ml_in_use`]).
static ML_REFUSED: AtomicBool = AtomicBool::new(false);
/// [`ml`], unless FSR 4's swap chain was refused and FSR 3's runs.
fn ml_in_use(ffx: &Ffx, device: *mut c_void) -> Option<(u64, u64)> {
ml(ffx, device).filter(|_| !ML_REFUSED.load(Acquire))
}
/// Whether the title's upscalings are to be noted for us: the DLLs are in and
/// DLSS Frame Generation does not have the presents.
pub(crate) fn noting() -> bool {
@ -526,21 +535,38 @@ pub(crate) fn swap_chain(
device
};
let device = device.as_ref().map_or(std::ptr::null_mut(), |d| d.as_raw());
let ml = ml(ffx, device);
let mut proxy = OverrideVersion { header: Header::new(OVERRIDE_VERSION), id: ml.map_or(0, |(_, p)| p) };
for v in SWAPCHAIN_VERSIONS {
let mut version = Version { header: Header::new(CREATE_SWAPCHAIN_VERSION_DX12), version: v };
create.header.next = (&raw mut version).cast();
if ml.is_some() {
proxy.header.next = (&raw mut version).cast();
create.header.next = (&raw mut proxy).cast();
let ml = ml_in_use(ffx, device);
// FSR 4's swap chain where the driver offers it; refused, FSR 3's (a refusal left frame
// generation off for the session; `VICTORY_FSR_FRAMEGEN_VERSION=3` asks for FSR 3 from the
// start).
let tries: &[Option<u64>] = if let Some((_, p)) = ml { &[Some(p), None] } else { &[None] };
for &proxy_id in tries {
let mut proxy = OverrideVersion { header: Header::new(OVERRIDE_VERSION), id: proxy_id.unwrap_or(0) };
for v in SWAPCHAIN_VERSIONS {
let mut version = Version { header: Header::new(CREATE_SWAPCHAIN_VERSION_DX12), version: v };
create.header.next = (&raw mut version).cast();
if proxy_id.is_some() {
proxy.header.next = (&raw mut version).cast();
create.header.next = (&raw mut proxy).cast();
}
// SAFETY: filled descriptions that live through the call.
code = unsafe { (ffx.create)(&mut *context, (&raw mut create).cast(), std::ptr::null()) };
api = v;
if code != ERROR_PARAMETER {
break;
}
}
// SAFETY: filled descriptions that live through the call.
code = unsafe { (ffx.create)(&mut *context, (&raw mut create).cast(), std::ptr::null()) };
api = v;
if code != ERROR_PARAMETER {
if code == OK && !made.is_null() {
break;
}
if proxy_id.is_some() {
tracing::warn!(code, "FSR frame generation: FidelityFX refused the FSR 4 swap chain; trying FSR 3 frame generation");
ML_REFUSED.store(true, Release);
// SAFETY: the slot `create` points at, which FidelityFX writes; left empty for the
// next try.
unsafe { create.swap_chain.write(std::ptr::null_mut()) };
context = Box::new(std::ptr::null_mut());
}
}
if code != OK || made.is_null() {
tracing::warn!(code, "FSR 3 frame generation: FidelityFX did not make the swap chain; made as before, frame generation off");
@ -853,7 +879,7 @@ fn create_context(
version.header.next = first_after_version;
create.header.next = (&raw mut version).cast();
let mut generator = OverrideVersion { header: Header::new(OVERRIDE_VERSION), id: 0 };
if let Some((g, _)) = ml(ffx, device.as_raw()) {
if let Some((g, _)) = ml_in_use(ffx, device.as_raw()) {
generator.id = g;
generator.header.next = (&raw mut version).cast();
create.header.next = (&raw mut generator).cast();

View File

@ -5,8 +5,9 @@
//! generation by itself unless the player asked for this.
//!
//! Decided on the title's presents, before any frame is generated: on when 90 % of the frames of
//! the last 5 seconds took a 30th of a second or less; off when the median of the last 2 seconds is
//! slower than 28 a second; and after a switch, none for 2 seconds, so that it does not flap. Both
//! the last 5 seconds took a 29th of a second or less (one frame a second of slack: at the title's
//! own 30 cap about half the frames come a little over a 30th, so a 30th never turned it on); off
//! when the median of the last 2 seconds is slower than 28 a second; and after a switch, none for 2 seconds, so that it does not flap. Both
//! paths switch per present without making anything again (DLSS Frame Generation keeps its
//! resources while off, FSR's context and swap chain stay), so a switch costs one call.
@ -54,7 +55,9 @@ impl Gate {
if self.switched != 0 && now.saturating_sub(self.switched) < HOLD_US {
return Decision { on: self.on, switched: None };
}
let fast = 1_000_000 / u64::from(min_fps);
// (One frame a second of slack for the switch on: a steady cap at `min_fps` jitters around
// its interval, half its frames a little over it.)
let fast = 1_000_000 / u64::from(min_fps.saturating_sub(1).max(1));
let slow = 1_000_000 / u64::from(min_fps.saturating_sub(2).max(1));
let next = if self.on {
// Off when the median of the last 2 seconds is slower than `slow`.
@ -173,6 +176,27 @@ mod tests {
assert!(back.iter().all(|d| !d.on));
}
/// The title's own 30 cap: frames of 33.3 ms, each up to 1 ms early or late. On after the
/// window fills, and it stays on.
#[test]
fn a_steady_thirty_with_jitter_turns_it_on() {
let (mut gate, mut now) = (Gate::default(), 0);
let jitter = [0.0, 1.0, -1.0, 0.6, -0.4, 0.9, -0.8, 0.3];
let mut decisions = Vec::new();
for k in 0..300 {
decisions.extend(run(&mut gate, &mut now, 1, 33.333 + jitter[k % jitter.len()]));
}
assert_eq!(decisions.iter().filter(|d| d.switched.is_some()).count(), 1);
assert!(decisions.last().unwrap().on);
}
/// Under the slack: a steady 28 a second never turns it on.
#[test]
fn a_steady_twenty_eight_does_not() {
let (mut gate, mut now) = (Gate::default(), 0);
assert!(run(&mut gate, &mut now, 300, 1000.0 / 28.0).iter().all(|d| !d.on));
}
#[test]
fn zero_means_always() {
let (mut gate, mut now) = (Gate::default(), 0);

View File

@ -28,8 +28,10 @@ own upscaling and our plain present run as before.
Frame Generation).
A newer `nvngx_dlss.dll` (the DLSS SDK, <https://github.com/NVIDIA/DLSS>,
`lib\Windows_x86_64\rel`) can replace the one in that folder.
2. `VICTORY_STREAMLINE_DIR=<that bin\x64 folder>`; the default is
`C:\dev\sdk\streamline-sdk-v2.14.16\bin\x64`.
2. `VICTORY_STREAMLINE_DIR=<that bin\x64 folder>` (the launcher's Streamline
folder sets it). There is no default: without it DLSS and its frame
generation stay off, and AMD's upscaler and frame generation load no
Streamline at all.
3. Check the PC without the program (a few seconds):
- `victory upscaler-check`: Streamline loads, and what this GPU supports.
- `victory upscaler-check --device`: the host device is made and handed over