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:
1 parent
9e7ab9d9a2
commit
63957271cd
55 files changed
+8030
-1313
No files matched your search
@@ -0,0 +1,201 @@
|
||||
//! Host-memory admission for speculative texture work and reusable upload storage.
|
||||
use std::sync::OnceLock;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use windows_sys::Win32::System::SystemInformation::{GlobalMemoryStatusEx, MEMORYSTATUSEX};
|
||||
|
||||
const MIB: u64 = 1 << 20;
|
||||
const GIB: u64 = 1 << 30;
|
||||
static PRESSURED: AtomicBool = AtomicBool::new(false);
|
||||
static HEADROOM: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
|
||||
fn memory_status() -> Option<MEMORYSTATUSEX> {
|
||||
// SAFETY: the API initializes the fields of a correctly sized structure.
|
||||
let mut status: MEMORYSTATUSEX = unsafe { std::mem::zeroed() };
|
||||
status.dwLength = std::mem::size_of::<MEMORYSTATUSEX>() as u32;
|
||||
(unsafe { GlobalMemoryStatusEx(&mut status) } != 0).then_some(status)
|
||||
}
|
||||
|
||||
// The texture sweep may run for seconds inside a single submitted frame.
|
||||
static NEXT_COMMIT_SAMPLE: AtomicU64 = AtomicU64::new(0);
|
||||
static AVAILABLE_COMMIT: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
static RETRY_UPLOAD_AT: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub(crate) fn allocation_error(error: &windows::core::Error) {
|
||||
if error.code() == windows::Win32::Foundation::E_OUTOFMEMORY {
|
||||
RETRY_UPLOAD_AT.fetch_max(crate::host::coarse_ms().saturating_add(500), Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static STAGING_DEFERRED: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
||||
}
|
||||
|
||||
pub(crate) fn note_staging_deferred() {
|
||||
STAGING_DEFERRED.set(true);
|
||||
}
|
||||
|
||||
pub(crate) fn take_staging_deferred() -> bool {
|
||||
STAGING_DEFERRED.replace(false)
|
||||
}
|
||||
|
||||
pub(crate) fn upload_refused() -> bool {
|
||||
crate::host::coarse_ms() < RETRY_UPLOAD_AT.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn sample_commit(now: u64) -> u64 {
|
||||
let next = NEXT_COMMIT_SAMPLE.load(Ordering::Relaxed);
|
||||
if now >= next
|
||||
&& NEXT_COMMIT_SAMPLE
|
||||
.compare_exchange(next, now.saturating_add(32), Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_ok()
|
||||
&& let Some(status) = memory_status()
|
||||
{
|
||||
AVAILABLE_COMMIT.store(status.ullAvailPageFile, Ordering::Relaxed);
|
||||
}
|
||||
AVAILABLE_COMMIT.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn has_upload_reserve(commit: u64, bake: bool) -> bool {
|
||||
// Keep a protective floor against Rust/game OOM aborts without starving
|
||||
// bindless world textures or one-shot ped decoration bakes when steady-state
|
||||
// commit headroom sits in the 1-4 GiB range on 32 GiB hosts.
|
||||
commit >= if bake { 256 * MIB } else { 512 * MIB }
|
||||
}
|
||||
|
||||
fn has_growth_reserve(commit: u64, bake: bool) -> bool {
|
||||
// Growing a fresh 64 MiB upload block for speculative bindless prefetch
|
||||
// requires more headroom than reusing slices already committed inside the
|
||||
// staging pool.
|
||||
commit >= if bake { 256 * MIB } else { 1024 * MIB }
|
||||
}
|
||||
|
||||
/// Leave commit for game allocations and submissions already in flight while
|
||||
/// still letting bindless textures and one-shot material bakes upload.
|
||||
pub(crate) fn admit_texture_pass(bake: bool) -> bool {
|
||||
let now = crate::host::coarse_ms();
|
||||
if now < RETRY_UPLOAD_AT.load(Ordering::Relaxed) {
|
||||
return false;
|
||||
}
|
||||
has_upload_reserve(sample_commit(now), bake)
|
||||
}
|
||||
|
||||
/// Whether the staging allocator may commit a brand-new OS upload buffer
|
||||
/// (reusing existing free ranges in already-committed pool blocks stays open
|
||||
/// whenever `admit_texture_pass` is true).
|
||||
pub(crate) fn allow_staging_growth(bake: bool) -> bool {
|
||||
let now = crate::host::coarse_ms();
|
||||
if now < RETRY_UPLOAD_AT.load(Ordering::Relaxed) {
|
||||
return false;
|
||||
}
|
||||
has_growth_reserve(sample_commit(now), bake)
|
||||
}
|
||||
|
||||
pub(crate) fn limited_host_ram() -> bool {
|
||||
static LIMITED: OnceLock<bool> = OnceLock::new();
|
||||
*LIMITED.get_or_init(|| memory_status().is_some_and(|s| s.ullTotalPhys <= 32 * GIB))
|
||||
}
|
||||
|
||||
fn next_pressure(was: bool, physical: u64, commit: u64) -> bool {
|
||||
if was {
|
||||
physical < 5 * GIB || commit < 6 * GIB
|
||||
} else {
|
||||
physical <= 3 * GIB || commit <= 4 * GIB
|
||||
}
|
||||
}
|
||||
|
||||
/// Called by the once-per-second submission sweep. A failed sample keeps the last good state.
|
||||
pub(crate) fn refresh() {
|
||||
let Some(status) = memory_status() else { return };
|
||||
let (physical, commit) = (status.ullAvailPhys, status.ullAvailPageFile);
|
||||
HEADROOM.store(physical.min(commit), Ordering::Relaxed);
|
||||
let was = pressured();
|
||||
let pressure = next_pressure(was, physical, commit);
|
||||
if pressure != was {
|
||||
PRESSURED.store(pressure, Ordering::Relaxed);
|
||||
if pressure {
|
||||
tracing::warn!(
|
||||
pid = std::process::id(),
|
||||
frame = crate::frame::current(),
|
||||
physical_free_mib = physical >> 20,
|
||||
available_commit_mib = commit >> 20,
|
||||
buffer_mirror_span_mib = crate::shadow::live_span_bytes() >> 20,
|
||||
texture_staging_mib = crate::texture::live_staging_bytes() >> 20,
|
||||
spare_scratch_mib = crate::host::ALIVE[4].load(Ordering::Relaxed) >> 20,
|
||||
game_filled_gpu_texture_mib = crate::resource::KINDS[1].load(Ordering::Relaxed) >> 20,
|
||||
"host memory pressure: limiting texture prefetch and idle upload storage"
|
||||
);
|
||||
} else {
|
||||
tracing::info!(physical_free_mib = physical >> 20, available_commit_mib = commit >> 20, "host memory pressure cleared");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn headroom() -> Option<u64> {
|
||||
let bytes = HEADROOM.load(Ordering::Relaxed);
|
||||
(bytes != u64::MAX).then_some(bytes)
|
||||
}
|
||||
|
||||
pub(crate) fn pressured() -> bool {
|
||||
PRESSURED.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// True when OS commit headroom is critically low (< 1.5 GiB) or an allocation
|
||||
/// just failed with `E_OUTOFMEMORY`, requiring emergency throttling.
|
||||
pub(crate) fn critical_commit() -> bool {
|
||||
let now = crate::host::coarse_ms();
|
||||
now < RETRY_UPLOAD_AT.load(Ordering::Relaxed) || sample_commit(now) < 1536 * MIB
|
||||
}
|
||||
|
||||
/// A soft per-frame admission limit. A single texture can cross it. The
|
||||
/// queue retains unserved slots so they can be retried on later frames.
|
||||
pub(crate) fn prefetch_limit(bytes: u64, pressure: bool, critical: bool, limited: bool, staging: u64) -> u64 {
|
||||
if critical {
|
||||
bytes.min(16 << 20)
|
||||
} else if pressure || (limited && staging >= GIB) {
|
||||
bytes.min(64 << 20)
|
||||
} else {
|
||||
bytes
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn bake_and_lookahead_leave_room_for_live_game_allocations() {
|
||||
for (commit, bake, lookahead, growth) in [
|
||||
(128 * MIB, false, false, false),
|
||||
(256 * MIB, true, false, false),
|
||||
(512 * MIB, true, true, false),
|
||||
(768 * MIB, true, true, false),
|
||||
(1024 * MIB, true, true, true),
|
||||
] {
|
||||
assert_eq!(has_upload_reserve(commit, true), bake);
|
||||
assert_eq!(has_upload_reserve(commit, false), lookahead);
|
||||
assert_eq!(has_growth_reserve(commit, false), growth);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn either_constraint_enters_pressure_and_both_must_recover() {
|
||||
assert!(next_pressure(false, 12 * GIB, 4 * GIB));
|
||||
assert!(next_pressure(false, 3 * GIB, 16 * GIB));
|
||||
assert!(next_pressure(true, 4 * GIB, 7 * GIB));
|
||||
assert!(next_pressure(true, 6 * GIB, 5 * GIB));
|
||||
assert!(!next_pressure(true, 5 * GIB, 6 * GIB));
|
||||
assert!(!next_pressure(false, 4 * GIB, 5 * GIB));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefetch_respects_existing_budgets_and_resumes_after_recovery() {
|
||||
assert_eq!(prefetch_limit(512 << 20, false, false, true, GIB), 64 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, false, false, true, GIB - 1), 512 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, false, false, false, 2 * GIB), 512 << 20);
|
||||
assert_eq!(prefetch_limit(0, true, true, false, 0), 0);
|
||||
assert_eq!(prefetch_limit(8 << 20, true, true, false, 0), 8 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, true, false, false, 0), 64 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, true, true, false, 0), 16 << 20);
|
||||
assert_eq!(prefetch_limit(192 << 20, false, false, false, 0), 192 << 20);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user