CGBJ's renderer, DLSS, an F1 settings menu, frame generation, ray tracing switch

The default of scripts\play-nvidia.ps1 changes: the game renders its own
720p and DLSS takes it to 1080p (Series S), in place of the half render
scale and the title's upscaler. -Resolution still reaches the older path.

- Renderer: codec-d/cool_fox f4b48ad (GPL-3.0) with this fork's NVIDIA
  fixes on top (residency.rs, stretch.rs, the ffx upscale dispatch).
- DLSS for the title's upscale, from avatarmanz/VIctory-7900XTX pull
  request 203 (feature `dlss`, VICTORY_UPSCALE=dlss), with
  VICTORY_DLSS_PRESET and a live sharpness setting.
- F1 settings menu in the game (host/menu.rs): saved to
  victory-settings.txt, applied by the launcher at the next start,
  "save and restart" from the menu. F3: the panel, now with the
  generated frame rate beside the real one.
- DLSS frame generation through NVIDIA Streamline (streamline.rs, fg.rs),
  2x to 6x, the amount changed while playing. Constants and the depth and
  motion vector tags are handed over at each present.
- VICTORY_FPS_CAP: the title's own 30 frames a second can be lifted
  (60, 120, none), live from the menu.
- Real ray tracing as an option (-RayTracing, VICTORY_BVH_BUILDER=1): on
  this renderer the structure builder runs on NVIDIA. Frame generation is
  left off with it: the two together run at about 0.1 fps, cause not found.
- VICTORY_HEAP_RECHECK_EVERY: textures picked by index looked at again
  for the whole run (a test against the posterized look).
- Get-NVIDIA-DLSS.cmd / scripts\get-nvidia-sdks.ps1: fetch the few NVIDIA
  files DLSS and frame generation need (about 70 MB) from NVIDIA's GitHub
  into nvidia-sdk\ (git-ignored). They are NVIDIA's, under NVIDIA's
  licences, and are not part of this repository. Without them the picture
  is stretched and there is no frame generation.
- scripts\build-nvidia.ps1; the launcher builds the layer when it is not
  built, and again with DLSS once those files are there.

Measured on an RTX 5070 (Series S, DLSS, opening rooms): about 15-17 fps
without ray tracing, 13-15 with it, before generated frames. What is known
to be wrong is in the README's new section.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
trustno1-coderandClaude Fable 5.2 committed 2026-11-26 17:56:14 -08:00
1 parent 9e7ab9d9a2
commit 63957271cd
55 files changed
+8030 -1313

No files matched your search

+21 -3
View File
@@ -517,7 +517,16 @@ fn pump(context: Context, voice: &mut Voice) {
return;
}
while context.field(1, 31, 1) == 1 {
if voice.pcm.len() < SAMPLES_PER_BLOCK && !decode(context, voice) {
// A skipped frame or an input boundary can advance the decoder without
// producing samples. Publish only complete blocks, except the final
// padded tail. Limit empty steps so a broken looping voice cannot hold
// its lock or stall other voices for the whole decoding pass.
for _ in 0..8 {
if voice.pcm.len() >= SAMPLES_PER_BLOCK || !decode(context, voice) {
break;
}
}
if voice.pcm.is_empty() || (voice.pcm.len() < SAMPLES_PER_BLOCK && !voice.ended) {
return;
}
// The write block is the title's too: taken modulo the ring before
@@ -549,12 +558,21 @@ fn pump(context: Context, voice: &mut Voice) {
/// Decodes the next frame of the current input into `voice.pcm`; false
/// when there is nothing left to decode.
fn decode(context: Context, voice: &mut Voice) -> bool {
let valid = context.field(0, 20, 2);
if voice.ended {
return false;
// The title can refill either input while the context stays enabled.
// Flush the previous tail once and leave the ring idle until a valid
// buffer is published. The decoder resets its overlap when flushed.
if valid == 0 {
return false;
}
voice.ended = false;
if context.field(2, 26, 5) == INPUT_INVALID {
context.set_field(2, 26, 6, 0);
}
}
let channels = context.channels();
let mut current = context.field(4, 31, 1);
let valid = context.field(0, 20, 2);
if valid & (1 << current) == 0 {
if valid & (1 << (1 - current)) == 0 {
// Out of input: the overlap tail, then nothing.
+12 -3
View File
@@ -227,11 +227,20 @@ extern "system" fn create_queue(
)
}
/// The title asks for 32 MiB and stops if this fails.
/// The title asks for 32 MiB and stops if this fails. Give PC worker threads
/// enough staging headroom (default 256 MiB) so multi-MB RPF chunks don't
/// starve the remaining cores.
extern "system" fn set_staging_buffer_size(_: Factory, size: u32) -> HRESULT {
tracing::info!(size, "dstorage: staging buffer size");
static FLOOR_MB: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
let floor = *FLOOR_MB.get_or_init(|| {
std::env::var("VICTORY_DSTORAGE_STAGING_MB")
.ok()
.and_then(|v| v.trim().parse::<u64>().ok())
.unwrap_or(256)
}) << 20;
tracing::info!(size, floor, "dstorage: staging buffer size");
if let Some(scheduler) = scheduler() {
scheduler.lock().staging = u64::from(size);
scheduler.lock().staging = u64::from(size).max(floor);
}
S_OK
}
+250
View File
@@ -0,0 +1,250 @@
//! `amd_fidelityfx_loader_xbox.dll`: the upscale dispatch.
//!
//! The title's Series S mode renders below its output size and calls the
//! console's FidelityFX upscaler to make the output. The loader and the
//! upscaler are the title's own DLLs and run as they are, but the
//! upscaler's passes are compute pipelines in a container we do not
//! translate: its output stayed black. `ffxDispatch` alone is taken here:
//! an upscale dispatch becomes a plain stretch of the colour input
//! (`victory_gpu::list::upscale_stretch`); anything else, and an upscale we
//! could not stretch, goes to the title's DLL.
//!
//! The structures are the public FidelityFX API's (`ffx_api.h`,
//! `ffx_upscale.h`): a header of a type and a next pointer, and resources of
//! a pointer, a 32-byte description and a state.
use std::ffi::c_void;
use std::sync::atomic::{AtomicU32, AtomicUsize, Ordering};
/// The DLL whose `ffxDispatch` is taken.
pub const LOADER: &str = "amd_fidelityfx_loader_xbox.dll";
static REAL: AtomicUsize = AtomicUsize::new(0);
/// The title's own `ffxDispatch`, for what is not stretched here.
pub fn set_real_dispatch(address: usize) {
REAL.store(address, Ordering::Relaxed);
}
#[repr(C)]
struct Header {
kind: u64,
next: *const Header,
}
#[repr(C)]
struct Resource {
resource: *const c_void,
description: [u32; 8],
state: u32,
}
#[repr(C)]
struct Upscale {
header: Header,
list: *const c_void,
colour: Resource,
depth: Resource,
motion: Resource,
exposure: Resource,
reactive: Resource,
composition: Resource,
output: Resource,
jitter: [f32; 2],
motion_scale: [f32; 2],
render: [u32; 2],
upscale: [u32; 2],
// The rest of `ffxDispatchDescUpscale` (`ffx_upscale.h`), read by the
// probe only.
enable_sharpening: u8,
sharpness: f32,
frame_time_delta: f32,
pre_exposure: f32,
reset: u8,
camera_near: f32,
camera_far: f32,
camera_fov: f32,
view_to_meters: f32,
flags: u32,
}
/// `VICTORY_UPSCALE_PROBE=1`: logs what the title gives each upscale (the
/// inputs a temporal upscaler such as DLSS or FSR 2 needs), now and then.
fn probe() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_UPSCALE_PROBE").is_some_and(|v| v == "1"))
}
const _: () = assert!(size_of::<Resource>() == 48);
const _: () = assert!(std::mem::offset_of!(Upscale, output) == 0x138);
/// `FFX_API_RETURN_ERROR`: what a dispatch nothing could answer returns.
const ERROR: u32 = 1;
/// `FFX_API_DISPATCH_DESC_TYPE_UPSCALE`.
const UPSCALE: u64 = 0x0001_0001;
type Dispatch = extern "system" fn(*mut *mut c_void, *const Header) -> u32;
extern "system" fn dispatch(context: *mut *mut c_void, desc: *const Header) -> u32 {
// SAFETY: the title passes a dispatch description, whose header says
// what follows it.
if let Some(header) = unsafe { desc.as_ref() } {
static SEEN: AtomicU32 = AtomicU32::new(0);
let first = SEEN.fetch_add(1, Ordering::Relaxed) < 4;
if header.kind == UPSCALE {
// SAFETY: an upscale description, by its type.
let d = unsafe { &*desc.cast::<Upscale>() };
if first {
tracing::info!(
list = ?d.list,
colour = ?d.colour.resource,
colour_size = ?(d.colour.description[2], d.colour.description[3]),
output = ?d.output.resource,
output_size = ?(d.output.description[2], d.output.description[3]),
render = ?d.render,
upscale = ?d.upscale,
"upscale dispatch"
);
}
#[cfg(windows)]
if probe() {
static N: AtomicU32 = AtomicU32::new(0);
let n = N.fetch_add(1, Ordering::Relaxed);
// the first 12 upscales, then one in 300
if n < 12 || n.is_multiple_of(300) {
let inputs = victory_gpu::list::upscale_inputs(&[
d.colour.resource,
d.depth.resource,
d.motion.resource,
d.exposure.resource,
d.reactive.resource,
d.composition.resource,
d.output.resource,
]);
tracing::info!(
n,
colour = %inputs[0],
depth = %inputs[1],
motion = %inputs[2],
exposure = %inputs[3],
reactive = %inputs[4],
composition = %inputs[5],
output = %inputs[6],
jitter = ?d.jitter,
motion_scale = ?d.motion_scale,
render = ?d.render,
upscale = ?d.upscale,
sharpening = d.enable_sharpening,
sharpness = d.sharpness,
frame_time_delta = d.frame_time_delta,
pre_exposure = d.pre_exposure,
reset = d.reset,
near = d.camera_near,
far = d.camera_far,
fov = d.camera_fov,
meters = d.view_to_meters,
flags = format_args!("{:#x}", d.flags),
"upscale probe"
);
}
}
#[cfg(windows)]
{
let up = victory_gpu::list::Upscale {
colour: d.colour.resource as u64,
depth: d.depth.resource as u64,
motion: d.motion.resource as u64,
exposure: d.exposure.resource as u64,
output: d.output.resource as u64,
render: d.render,
jitter: d.jitter,
motion_scale: d.motion_scale,
reset: d.reset != 0,
pre_exposure: d.pre_exposure,
near: d.camera_near,
far: d.camera_far,
frame_ms: d.frame_time_delta,
dlss: std::env::var_os("VICTORY_UPSCALE").is_some_and(|v| v == "dlss"),
};
if victory_gpu::list::upscale(d.list, &up) {
return 0;
}
}
if first {
tracing::warn!("upscale dispatch not stretched: left to the title's upscaler");
}
} else if first {
tracing::info!(
kind = format_args!("{:#x}", header.kind),
"another FidelityFX dispatch"
);
}
}
match REAL.load(Ordering::Relaxed) {
// Neither stretched nor passed on: the output was not written, and
// the title is told so instead of presenting it as it is.
0 => {
static TOLD: std::sync::Once = std::sync::Once::new();
TOLD.call_once(|| {
tracing::error!(
"a FidelityFX dispatch was not answered: no stretch was recorded and the title's own ffxDispatch was not found"
);
});
ERROR
}
// SAFETY: the title's own `ffxDispatch`, with its own arguments.
real => unsafe { std::mem::transmute::<usize, Dispatch>(real)(context, desc) },
}
}
/// What the title's import of `ffxDispatch` is bound to. The DLL is not an
/// HLE module: the title's own must load, for its other entry points and
/// for the dispatches passed on.
pub fn dispatch_address() -> usize {
dispatch as *const () as usize
}
#[cfg(test)]
mod tests {
use super::*;
use std::mem::offset_of;
/// The upscale description as the public API lays it out: what the
/// stretch reads sits where the title wrote it.
#[test]
fn the_upscale_description_is_laid_out_as_the_public_api() {
assert_eq!(size_of::<Header>(), 16);
assert_eq!(offset_of!(Upscale, list), 0x10);
assert_eq!(offset_of!(Upscale, colour), 0x18);
assert_eq!(offset_of!(Upscale, depth), 0x48);
assert_eq!(offset_of!(Upscale, motion), 0x78);
assert_eq!(offset_of!(Upscale, output), 0x138);
assert_eq!(offset_of!(Upscale, jitter), 0x168);
assert_eq!(offset_of!(Upscale, motion_scale), 0x170);
assert_eq!(offset_of!(Upscale, render), 0x178);
assert_eq!(offset_of!(Upscale, upscale), 0x180);
assert_eq!(offset_of!(Upscale, enable_sharpening), 0x188);
assert_eq!(offset_of!(Upscale, sharpness), 0x18c);
assert_eq!(offset_of!(Upscale, reset), 0x198);
assert_eq!(offset_of!(Upscale, camera_near), 0x19c);
assert_eq!(offset_of!(Upscale, flags), 0x1ac);
assert_eq!(offset_of!(Resource, description), 8);
assert_eq!(offset_of!(Resource, state), 40);
}
/// A dispatch that is not an upscale, with no DLL of the title's to
/// pass it to, is an error and not a silent success.
#[test]
fn a_dispatch_nothing_answers_is_an_error() {
let before = REAL.swap(0, Ordering::Relaxed);
let other = Header {
kind: 0x0002_0001,
next: std::ptr::null(),
};
assert_eq!(dispatch(std::ptr::null_mut(), &other), ERROR);
assert_eq!(dispatch(std::ptr::null_mut(), std::ptr::null()), ERROR);
REAL.store(before, Ordering::Relaxed);
}
}
+4 -5
View File
@@ -1259,7 +1259,6 @@ mod host {
// pad's buttons, by the stand-in pad's table: with a real pad
// connected the stand-in is not there, and a title that listens
// to the pad (the title's start screen) saw nothing.
#[cfg(feature = "diagnostics")]
if slot == 0 {
for vk in scripted() {
if let Some(&(_, button)) = super::FALLBACK_BUTTONS.iter().find(|(key, _)| *key == vk) {
@@ -1271,10 +1270,11 @@ mod host {
}
fn keys(&mut self) -> Vec<KeyState> {
#[cfg(feature = "diagnostics")]
let mut down = scripted();
#[cfg(not(feature = "diagnostics"))]
let mut down = Vec::new();
// LOCAL (11/26): the F1 settings menu takes the keyboard while shown.
if victory_gpu::SETTINGS_MENU_OPEN.load(std::sync::atomic::Ordering::Relaxed) {
return Vec::new();
}
if focused_window().is_some() {
// Left/right modifier keys only, as devices report them; no
// mouse buttons (below 0x08).
@@ -1348,7 +1348,6 @@ mod host {
/// time), with or without focus. A key is a
/// letter, a digit, or `Enter`, `Esc`, `Tab`, `Back`, `Up`, `Down`,
/// `Left`, `Right` (the stand-in pad's table maps them to buttons).
#[cfg(feature = "diagnostics")]
fn scripted() -> Vec<u8> {
static SCRIPT: LazyLock<(Instant, Vec<(Duration, Duration, u8)>)> = LazyLock::new(|| {
let list = std::env::var("VICTORY_KEYS").unwrap_or_default();
+1
View File
@@ -17,6 +17,7 @@ pub mod dsp;
#[cfg(windows)]
pub mod dstorage;
#[cfg(windows)]
pub mod ffx;
pub mod files;
pub mod gameinput;
pub mod kernel;