Publish the pareto-residency Windows build and portable launcher
This commit is contained in:
1 parent
efeef1d65b
commit
545f89019e
20 files changed
+1671
-217
No files matched your search
@@ -3,6 +3,7 @@ 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);
|
||||
@@ -25,30 +26,68 @@ pub(crate) fn allocation_error(error: &windows::core::Error) {
|
||||
}
|
||||
}
|
||||
|
||||
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 has_upload_reserve(commit: u64, bake: bool) -> bool {
|
||||
commit >= if bake { 2 * GIB } else { 4 * GIB }
|
||||
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)
|
||||
}
|
||||
|
||||
/// Leave commit for game allocations and submissions already in flight. Direct
|
||||
/// texture consumers bypass this gate. Bake prefetch gets priority over lookahead.
|
||||
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;
|
||||
}
|
||||
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() {
|
||||
if let Some(status) = memory_status() {
|
||||
AVAILABLE_COMMIT.store(status.ullAvailPageFile, Ordering::Relaxed);
|
||||
}
|
||||
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_upload_reserve(AVAILABLE_COMMIT.load(Ordering::Relaxed), bake)
|
||||
has_growth_reserve(sample_commit(now), bake)
|
||||
}
|
||||
|
||||
pub(crate) fn limited_host_ram() -> bool {
|
||||
@@ -58,9 +97,9 @@ pub(crate) fn limited_host_ram() -> bool {
|
||||
|
||||
fn next_pressure(was: bool, physical: u64, commit: u64) -> bool {
|
||||
if was {
|
||||
physical < 6 * GIB || commit < 8 * GIB
|
||||
physical < 5 * GIB || commit < 6 * GIB
|
||||
} else {
|
||||
physical <= 4 * GIB || commit <= 6 * GIB
|
||||
physical <= 3 * GIB || commit <= 4 * GIB
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,13 +139,20 @@ 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, limited: bool, staging: u64) -> u64 {
|
||||
if pressure {
|
||||
pub(crate) fn prefetch_limit(bytes: u64, pressure: bool, critical: bool, limited: bool, staging: u64) -> u64 {
|
||||
if critical {
|
||||
bytes.min(16 << 20)
|
||||
} else if limited && staging >= GIB {
|
||||
bytes.min(32 << 20)
|
||||
} else if pressure || (limited && staging >= GIB) {
|
||||
bytes.min(64 << 20)
|
||||
} else {
|
||||
bytes
|
||||
}
|
||||
@@ -118,32 +164,38 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bake_and_lookahead_leave_room_for_live_game_allocations() {
|
||||
for (commit, bake, lookahead) in [
|
||||
(277 << 20, false, false), (2 * GIB, true, false), (4 * GIB, true, true),
|
||||
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, 6 * GIB));
|
||||
assert!(next_pressure(false, 4 * GIB, 16 * GIB));
|
||||
assert!(next_pressure(true, 5 * GIB, 9 * GIB));
|
||||
assert!(next_pressure(true, 7 * GIB, 7 * GIB));
|
||||
assert!(!next_pressure(true, 6 * GIB, 8 * GIB));
|
||||
assert!(!next_pressure(false, 5 * GIB, 7 * GIB));
|
||||
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, true, GIB), 32 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, false, true, GIB - 1), 512 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, false, false, 2 * GIB), 512 << 20);
|
||||
assert_eq!(prefetch_limit(0, true, false, 0), 0);
|
||||
assert_eq!(prefetch_limit(8 << 20, true, false, 0), 8 << 20);
|
||||
assert_eq!(prefetch_limit(512 << 20, true, false, 0), 16 << 20);
|
||||
assert_eq!(prefetch_limit(192 << 20, false, false, 0), 192 << 20);
|
||||
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