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

+86 -7
View File
@@ -42,7 +42,25 @@ static SPARES: AtomicUsize = AtomicUsize::new(SPARE);
/// [`SPARE_KEPT`] below 85 % ([`crate::host::keep_freed`]), else [`SPARE`].
/// Asked once a second.
pub(crate) fn room(memory: Option<[u64; 4]>) {
SPARES.store(spares(memory, crate::host::keep_freed()), Ordering::Relaxed);
let pressure = crate::residency::pressured();
let limit = spares(memory, crate::host::keep_freed() && !pressure);
SPARES.store(limit, Ordering::Relaxed);
let tick = now();
// A full pool can become idle while another subsystem needs the VRAM.
// A busy allocator observes the new limit on its next allocation or tick.
if let Ok(mut pool) = TEXTURES.try_lock() {
pool.reclaim(tick, limit, true);
}
if let Ok(mut pool) = STAGING.try_lock() {
let staging_limit = if crate::residency::critical_commit() {
0
} else if pressure {
1
} else {
limit
};
pool.reclaim(tick, staging_limit, true);
}
}
fn spares(memory: Option<[u64; 4]>, keep: bool) -> usize {
@@ -180,11 +198,12 @@ struct Pool<B> {
/// The empty blocks it was last told to keep, and the most it keeps.
spare: usize,
most: usize,
retry_growth_at: u64,
}
impl<B: Clone> Pool<B> {
const fn new(most: usize) -> Pool<B> {
Pool { blocks: Vec::new(), resting: VecDeque::new(), spare: 0, most }
Pool { blocks: Vec::new(), resting: VecDeque::new(), spare: 0, most, retry_growth_at: 0 }
}
/// A piece of `len` bytes and the memory it lies in, and whether that
@@ -226,10 +245,13 @@ impl<B: Clone> Pool<B> {
unripe.sort_unstable();
found = unripe.into_iter().find_map(|(_, i)| Some((i, self.blocks[i].as_mut()?.free.take(len, align)?)));
}
// A failed 64 MiB block must not trigger another driver call for each
// small texture. Existing free ranges remain usable during backoff.
let (i, start) = match found {
Some(found) => found,
None => {
let i = self.add(make()?, ripe.started);
let memory = self.grow(now, &mut make)?;
let i = self.add(memory, ripe.started);
(i, self.blocks[i].as_mut()?.free.take(len, align)?)
}
};
@@ -242,7 +264,7 @@ impl<B: Clone> Pool<B> {
}
let empty = self.blocks.iter().flatten().filter(|b| b.free.whole(BLOCK)).count();
if empty < ripe.ahead
&& let Some(memory) = make()
&& let Some(memory) = self.grow(now, &mut make)
{
self.add(memory, ripe.started);
}
@@ -253,6 +275,17 @@ impl<B: Clone> Pool<B> {
Some((Piece { block: i, start, len }, block.memory.clone(), again))
}
fn grow(&mut self, now: u64, make: &mut impl FnMut() -> Option<B>) -> Option<B> {
if now < self.retry_growth_at {
return None;
}
let block = make();
if block.is_none() {
self.retry_growth_at = now.saturating_add(500);
}
block
}
fn add(&mut self, memory: B, made: u64) -> usize {
let i = match self.blocks.iter().position(Option::is_none) {
Some(i) => i,
@@ -272,6 +305,10 @@ impl<B: Clone> Pool<B> {
/// Makes the pieces that rested long enough free, and lets go of empty
/// blocks past [`SPARE`].
fn rested(&mut self, now: u64) {
self.reclaim(now, SPARES.load(Ordering::Relaxed), false);
}
fn reclaim(&mut self, now: u64, limit: usize, sweep: bool) {
let mut any = false;
while let Some(&(ready, piece)) = self.resting.front()
&& ready <= now
@@ -283,9 +320,9 @@ impl<B: Clone> Pool<B> {
}
}
// (Without a piece given back too, once there is less room.)
let most = SPARES.load(Ordering::Relaxed).min(self.most);
if any || most < self.spare {
self.spare = most;
let most = limit.min(self.most);
let previous = std::mem::replace(&mut self.spare, most);
if sweep || any || most < previous {
let mut spare = 0;
for block in &mut self.blocks {
if block.as_ref().is_some_and(|b| b.free.whole(BLOCK)) {
@@ -349,6 +386,13 @@ pub(crate) fn staging(host: &crate::host::Host, bytes: u64) -> Option<(StagingPi
// Copies from a buffer begin at multiples of 512.
let bytes = bytes.next_multiple_of(512);
let (piece, memory, again) = lock(&STAGING).take(bytes, 512, now(), || {
// Only gate speculative bindless prefetch on staging-pool growth
// headroom; table-bound textures and decoration bakes are sampled
// immediately and would otherwise read uninitialized/reused VRAM.
let speculative = crate::texture::PICKING.get().is_some() && !crate::texture::BAKING.get();
if speculative && !crate::residency::allow_staging_growth(false) {
return None;
}
let (buffer, data) = host.upload_buffer(BLOCK)?;
crate::host::name(&buffer, || "staging of textures (a block)".into());
Some(Upload(buffer, data))
@@ -488,6 +532,7 @@ pub(crate) unsafe fn texture(
let mut heap: Option<ID3D12Heap> = None;
// SAFETY: plain creation.
if let Err(e) = unsafe { device.CreateHeap(&desc, &mut heap) } {
crate::residency::allocation_error(&e);
tracing::warn!(error = %e, "no block of texture memory");
}
if let Some(h) = &heap
@@ -560,6 +605,40 @@ mod tests {
assert_eq!(spares(None, true), SPARE);
}
#[test]
fn a_failed_block_is_not_retried_for_each_small_upload() {
let mut pool: Pool<u32> = Pool::new(2);
let calls = std::cell::Cell::new(0);
let refuse = || { calls.set(calls.get() + 1); None };
for size in [704008, 179720, 179720, 24080, 48648, 524288, 89616, 351760] {
assert!(pool.take(size, 512, 12, refuse).is_none());
}
assert_eq!(calls.get(), 1);
assert!(pool.take(24080, 512, 1012, || Some(1)).is_some());
}
#[test]
fn budget_tick_reclaims_idle_blocks_without_reusing_live_or_resting_pieces() {
let mut pool = Pool::new(STAGING_KEPT);
let (held, _, _) = pool.take(BLOCK / 2, 1, 0, || Some(1)).unwrap();
let (resting, _, _) = pool.take(BLOCK / 2, 1, 0, || Some(2)).unwrap();
pool.give(resting, 0);
for i in 0..12 {
pool.add(i, 0);
}
pool.reclaim(0, SPARE_KEPT, true);
assert_eq!(pool.blocks(), STAGING_KEPT + 1);
pool.reclaim(REST - 1, SPARE, true);
assert_eq!(pool.blocks(), SPARE + 1);
assert_eq!(pool.resting.len(), 1);
pool.reclaim(REST, 0, true);
assert_eq!(pool.blocks(), 1);
assert!(pool.resting.is_empty());
pool.give(held, REST);
pool.reclaim(2 * REST, 0, true);
assert_eq!(pool.blocks(), 0);
}
#[test]
fn pieces_never_overlap_and_rest_before_they_are_used_again() {
let mut pool: Pool<u32> = Pool::new(SPARE);