Merge fork main a803c87

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 18:57:47 -06:00
commit 1f951910e4
22 files changed
+895 -117

No files matched your search

+4 -5
View File
@@ -184,11 +184,10 @@ fn save_as(name: &str, width: u32, height: u32, pitch: usize, bgra: bool, rows:
header.extend(h.to_be_bytes());
header.extend([8, 2, 0, 0, 0]); // 8-bit RGB
chunk(&mut png, b"IHDR", &header);
chunk(
&mut png,
b"IDAT",
&miniz_oxide::deflate::compress_to_vec_zlib(&raw, 3),
);
let mut compressed = vec![0u8; zlib_rs::compress_bound(raw.len())];
let (idat, rc) = zlib_rs::compress_slice(&mut compressed, &raw, zlib_rs::DeflateConfig::new(3));
debug_assert_eq!(rc, zlib_rs::ReturnCode::Ok);
chunk(&mut png, b"IDAT", idat);
chunk(&mut png, b"IEND", &[]);
let path = folder.join(format!("{name}.png"));
match std::fs::write(&path, png) {
+122 -39
View File
@@ -289,6 +289,11 @@ struct Waiting {
/// Bytes of its memory that were mapped when it was last uploaded
/// without all of it there; 0: not uploaded yet.
mapped: u64,
/// For a slot uploaded whole and looked at again
/// ([`TextureQueue::recheck`]): where its memory is (address, bytes),
/// the fingerprint it had at the upload, how many looks found it
/// unchanged, and the frame of the upload. A fingerprint of 0: none.
checked: (u64, u64, u64, u8, u64),
}
/// The queue of title slots whose texture view waits to be brought up to
@@ -311,7 +316,7 @@ impl TextureQueue {
}
self.writes += 1;
let write = self.writes;
self.slots.insert(index, Waiting { due, written: frame, write, looks: 0, mapped: 0 });
self.slots.insert(index, Waiting { due, written: frame, write, looks: 0, mapped: 0, checked: (0, 0, 0, 0, 0) });
}
fn remove(&mut self, index: u32) {
@@ -382,6 +387,24 @@ impl TextureQueue {
}
}
/// Slot `index` was uploaded whole from memory `at` (address, bytes)
/// with fingerprint `print`: looked at again from frame `due`, for a
/// title that fills a texture's memory after it wrote the view (the
/// `looks`-th such look; `uploaded` is the upload's frame).
#[allow(clippy::too_many_arguments)]
fn recheck(&mut self, index: u32, write: u64, due: u64, at: (u64, u64), print: u64, looks: u8, uploaded: u64) {
if let Some(w) = self.same(index, write) {
(w.due, w.looks, w.mapped) = (due, 1, 0);
w.checked = (at.0, at.1, print, looks, uploaded);
}
}
/// What [`TextureQueue::recheck`] noted of slot `index`, if it is
/// waiting for such a look.
fn checked(&self, index: u32) -> Option<(u64, u64, u64, u8, u64)> {
self.slots.get(&index).map(|w| w.checked).filter(|c| c.2 != 0)
}
/// The memory slot `index`'s texture lies in was mapped, unmapped or
/// written in `frame`: the slot is looked at from frame `due` as one
/// written now, whatever was known of it (a pass at work on it does
@@ -390,7 +413,7 @@ impl TextureQueue {
self.writes += 1;
let write = self.writes;
let due = self.slots.get(&index).map_or(due, |w| w.due.min(due));
self.slots.insert(index, Waiting { due, written: frame, write, looks: 0, mapped: 0 });
self.slots.insert(index, Waiting { due, written: frame, write, looks: 0, mapped: 0, checked: (0, 0, 0, 0, 0) });
}
/// Bytes of slot `index`'s memory that were mapped at its last upload
@@ -509,34 +532,52 @@ pub(crate) fn near_heaps(va: u64) -> String {
/// tiers 1 and 2; tier 3 hardware may take more.
const PORTABLE_VIEWS: u32 = 1_000_000;
/// Asks the host, once, whether it caps view heaps at [`PORTABLE_VIEWS`],
/// and if so tells the translator now (`set_view_heap_limit`) instead of
/// when the title's heap is made: a shader keeps the limit it was
/// translated with, and the title makes 25 pipelines (their
/// shaders translated at once) before it makes its view heap. Those would
/// read a view index past the heap unclamped, the read that hangs NVIDIA.
/// Called before a shader is translated.
/// shortcut: the limit is the capped heap's last slot whatever size the
/// title's heap turns out to have; a heap that fits is not capped and
/// keeps no null slot there (an index past it is as undefined as before).
/// The size of every host view heap on a host that takes more than
/// [`PORTABLE_VIEWS`] (AMD): the title's heap (a little over 1,000,000
/// views in the retail game) plus [`DYNAMIC`] fits with room to spare, and
/// the last slot is the null slot every view index at or past it reads.
const UNCAPPED_VIEWS: u32 = 1 << 21;
/// Picks, once, the null slot at the end of every host view heap and tells
/// the translator now (`set_view_heap_limit`) instead of when the title's
/// heap is made: a shader keeps the limit it was translated with, and the
/// title makes 25 pipelines (their shaders translated at once) before it
/// makes its view heap. Called before a shader is translated and before a
/// view heap is made.
///
/// Every host clamps. A host that caps view heaps at [`PORTABLE_VIEWS`]
/// (NVIDIA) hung on a view index past the heap; one that does not (AMD
/// RDNA3, RX 7900 XT) took a page fault and removed the device on entering
/// the world: a compute program read view slot 16,777,088 (0xffff80) of a
/// heap of 1,507,328, past its end. Unclamped, that index is undefined on
/// any host.
pub(crate) fn probe_view_limit() {
static ONCE: std::sync::Once = std::sync::Once::new();
ONCE.call_once(|| {
let Some(host) = host() else { return };
// SAFETY: plain heap creation; the heap is released at once.
let made: windows::core::Result<ID3D12DescriptorHeap> = unsafe {
host.device
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
NumDescriptors: PORTABLE_VIEWS + 1,
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
NodeMask: 0,
})
let fits = |count: u32| {
// SAFETY: plain heap creation; the heap is released at once.
let made: windows::core::Result<ID3D12DescriptorHeap> = unsafe {
host.device
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
NumDescriptors: count,
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
NodeMask: 0,
})
};
made.is_ok()
};
if made.is_err() {
tracing::info!("the host caps view heaps at {PORTABLE_VIEWS}: view indices are clamped from the first shader on");
victory_shader::emit::set_view_heap_limit(PORTABLE_VIEWS - 1);
}
let views = if fits(UNCAPPED_VIEWS) {
UNCAPPED_VIEWS
} else {
PORTABLE_VIEWS
};
tracing::info!(
views,
"host view heaps hold {views} views; view indices are clamped to the null slot at the end from the first shader on"
);
victory_shader::emit::set_view_heap_limit(views - 1);
});
}
@@ -574,20 +615,41 @@ impl HostHeap {
}
};
let extra = if sampler { 0 } else { DYNAMIC };
let (heap, count, size) = match make(count + extra) {
Ok(heap) => (heap, count, count + extra),
Err(e) if !sampler && count + extra > PORTABLE_VIEWS => {
// shortcut: descriptors past the host's limit are left out; a title that reaches
// them needs remapping. The heap's last slot stays null, and shaders read it for
// any view index from there on (`set_view_heap_limit`): a read past the heap's
// end hung NVIDIA's GPU (the title's heap is a little over 1 000 000 views).
tracing::warn!(error = %e, count, "host view heap capped at {PORTABLE_VIEWS}; views past it read a null slot");
victory_shader::emit::set_view_heap_limit(PORTABLE_VIEWS - 1);
(make(PORTABLE_VIEWS).ok()?, PORTABLE_VIEWS - extra - 1, PORTABLE_VIEWS)
// A view heap ends at the null slot shaders clamp view indices to
// (`probe_view_limit`), whatever the title's own count: the title's
// slots, then the dynamic ones, then null up to and with that slot.
if !sampler {
probe_view_limit();
}
let null = if sampler {
0
} else {
victory_shader::emit::view_heap_limit()
};
let (heap, count, size) = if null == 0 {
match make(count + extra) {
Ok(heap) => (heap, count, count + extra),
Err(e) => {
tracing::warn!(error = %e, count, sampler, "no host descriptor heap");
return None;
}
}
Err(e) => {
tracing::warn!(error = %e, count, sampler, "no host descriptor heap");
return None;
} else {
let size = null + 1;
let fitted = if count + extra <= null {
count
} else {
// shortcut: descriptors past the host's limit are left out; a title that reaches
// them needs remapping. They read the null slot instead.
tracing::warn!(count, "host view heap capped at {size}; views past it read a null slot");
null - extra
};
match make(size) {
Ok(heap) => (heap, fitted, size),
Err(e) => {
tracing::warn!(error = %e, count, size, "no host view heap");
return None;
}
}
};
// SAFETY: a live heap.
@@ -602,7 +664,7 @@ impl HostHeap {
let gpu = unsafe { heap.GetGPUDescriptorHandleForHeapStart().ptr };
GPU_RANGES.lock().unwrap_or_else(|e| e.into_inner()).push((
gpu,
u64::from(count + extra) * u64::from(step),
u64::from(size) * u64::from(step),
u64::from(step),
sampler,
));
@@ -806,6 +868,27 @@ impl HostHeap {
}
}
/// Title slot `index` was uploaded whole: see [`TextureQueue::recheck`].
#[allow(clippy::too_many_arguments)]
pub(crate) fn texture_slot_recheck(
&self,
index: u32,
write: u64,
due: u64,
at: (u64, u64),
print: u64,
looks: u8,
uploaded: u64,
) {
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
textures.recheck(index, write, due, at, print, looks, uploaded);
}
/// See [`TextureQueue::checked`].
pub(crate) fn texture_slot_checked(&self, index: u32) -> Option<(u64, u64, u64, u8, u64)> {
self.textures.lock().unwrap_or_else(|e| e.into_inner()).checked(index)
}
/// Nothing to upload at title slot `index` now (its memory is not
/// mapped, or no more of it than before): looked at again after 1, 2,
/// 4, ... frames, at most `most`.
+81 -4
View File
@@ -333,6 +333,21 @@ pub(crate) static HEAP_TEXTURES_WAITING: AtomicU64 = AtomicU64::new(0);
/// Passes that made no texture because the card had no room
/// (`crate::resource::room`), for the memory line.
pub(crate) static HEAP_TEXTURES_FULL: AtomicU64 = AtomicU64::new(0);
/// Frames after a whole upload of a texture picked by index at which its
/// memory is looked at again, each counted from the look before.
const RECHECK_FRAMES: [u64; 5] = [4, 12, 40, 120, 400];
/// Looks at uploaded textures picked by index that found the memory as it
/// was, and that found it changed (uploaded again), since the start.
pub(crate) static HEAP_TEXTURES_RECHECKED: [AtomicU64; 2] = [AtomicU64::new(0), AtomicU64::new(0)];
/// Whether textures picked by index are looked at again after their upload
/// (`VICTORY_HEAP_RECHECK=0`: no).
fn heap_recheck() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_HEAP_RECHECK").is_none_or(|v| v != "0"))
}
/// Times a placed texture's slot was passed over because its memory is not
/// mapped.
pub(crate) static HEAP_TEXTURES_AWAY: AtomicU64 = AtomicU64::new(0);
@@ -1446,7 +1461,16 @@ impl State {
return;
}
let memory = crate::host::host().and_then(|h| h.video_memory());
let per_frame = staging_budget_per_frame(memory.map(|[budget, ..]| budget));
// `VICTORY_TEXTURE_STAGE_MB` sets it: a backlog of tens of thousands of
// textures (a scene's first minutes) then drains in fewer frames.
static PER_FRAME_MB: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
let asked = *PER_FRAME_MB.get_or_init(|| {
std::env::var("VICTORY_TEXTURE_STAGE_MB").ok().and_then(|v| v.trim().parse::<u64>().ok())
});
let per_frame = match asked {
Some(mb) => mb << 20,
None => staging_budget_per_frame(memory.map(|[budget, ..]| budget)),
};
static FRAME: AtomicU64 = AtomicU64::new(u64::MAX);
static SPENT: AtomicU64 = AtomicU64::new(0);
let frame = crate::frame::current();
@@ -1499,10 +1523,19 @@ impl State {
// records the frame, and making and staging 192 MB of textures took
// 1.6-2.2 s of each of the world's first twenty frames (run 20).
// The rest waits for the next frames, as it does past the bytes.
const SPAN: std::time::Duration = std::time::Duration::from_millis(250);
static SPAN_MS: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
let span = std::time::Duration::from_millis(*SPAN_MS.get_or_init(|| {
std::env::var("VICTORY_TEXTURE_STAGE_MS").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(250)
}));
// A backlog (a scene's first minutes: 22,000 slots due, 2-3 minutes of black
// surfaces at 192 MB a frame) gets three times the bytes and the time until it
// drains; `VICTORY_TEXTURE_CATCHUP=0` keeps the plain budget.
static CATCHUP: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
let catchup = *CATCHUP.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_CATCHUP").is_none_or(|v| v != "0"));
let (per_frame, span) = if catchup && due.len() >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) };
let began = std::time::Instant::now();
for (index, write) in due {
if SPENT.load(Ordering::Relaxed) >= per_frame || began.elapsed() > SPAN {
if SPENT.load(Ordering::Relaxed) >= per_frame || began.elapsed() > span {
break;
}
// A placed texture whose memory is not mapped (not streamed in
@@ -1516,6 +1549,38 @@ impl State {
// every 120 frames, changed or not; and asked by its first
// page alone, one whose first page is the one missing counted
// as not there.)
// A slot uploaded whole is looked at again a few times
// (`RECHECK_FRAMES`): the title writes a texture's view, and
// may fill the texture's memory itself only afterwards, with
// no descriptor write and nothing from the runtime to tell of
// it. The host copy then kept what the memory held at the
// first look for the rest of the run. The look reads 48 KiB;
// only a changed texture is uploaded again.
// `VICTORY_HEAP_RECHECK=0`: uploaded once, as before.
if let Some((at, len, print, looks, uploaded)) = host.texture_slot_checked(index) {
if crate::texture::fingerprint(at, len) == print {
HEAP_TEXTURES_RECHECKED[0].fetch_add(1, Ordering::Relaxed);
match RECHECK_FRAMES.get(usize::from(looks) + 1) {
Some(wait) => {
host.texture_slot_recheck(index, write, frame + wait, (at, len), print, looks + 1, uploaded)
}
None => host.texture_slot_done(index, write, None),
}
continue;
}
let n = HEAP_TEXTURES_RECHECKED[1].fetch_add(1, Ordering::Relaxed);
if n < 200 || n.is_multiple_of(1000) {
tracing::warn!(
slot = index,
address = format_args!("{at:#x}"),
bytes = len,
frames_after_upload = frame.saturating_sub(uploaded),
looks,
changed = n + 1,
"a texture picked by index changed after its upload with nothing to tell of it: uploaded again"
);
}
}
let mut partly = None;
if let Some(View::Placed(false, resource, desc)) = heap.handle(index).and_then(crate::descriptor::view) {
let address = u64::from(desc[10]) | u64::from(desc[11]) << 32;
@@ -1619,11 +1684,23 @@ impl State {
// yet, makes it anew. (Kept for those until now: every partly
// streamed texture of the heap held a staging buffer of its full
// size for good.)
let memory = if again.is_none() && heap_recheck() {
crate::texture::staged_memory(resource)
} else {
None
};
crate::texture::unstage(resource);
SPENT.fetch_add(bytes, Ordering::Relaxed);
HEAP_TEXTURE_BYTES.fetch_add(bytes, Ordering::Relaxed);
HEAP_TEXTURES.fetch_add(1, Ordering::Relaxed);
host.texture_slot_done(index, write, again);
match memory {
// Whole and uploaded: looked at again (see above).
Some((at, len)) => {
let print = crate::texture::fingerprint(at, len);
host.texture_slot_recheck(index, write, frame + RECHECK_FRAMES[0], (at, len), print, 0, frame);
}
None => host.texture_slot_done(index, write, again),
}
}
}
+90
View File
@@ -106,6 +106,60 @@ pub(crate) fn long_ago(moment: u64, ms: u64, frames: u64) -> bool {
(now >> 32).saturating_sub(moment >> 32) >= frames && tenths * 100 >= ms
}
/// Available physical RAM on the host in bytes, from `GlobalMemoryStatusEx`.
pub(crate) fn available_physical_ram() -> Option<u64> {
use windows_sys::Win32::System::SystemInformation::{GlobalMemoryStatusEx, MEMORYSTATUSEX};
// SAFETY: plain data the call fills in.
let mut m: MEMORYSTATUSEX = unsafe { std::mem::zeroed() };
m.dwLength = std::mem::size_of::<MEMORYSTATUSEX>() as u32;
// SAFETY: a sized structure.
let ok = unsafe { GlobalMemoryStatusEx(&mut m) } != 0;
ok.then_some(m.ullAvailPhys)
}
/// Effective idle timeout (in milliseconds) for VRAM-backed host textures,
/// scaled down under VRAM pressure. Never returns less than 1,000 ms so
/// handles not yet recorded into a list or slot remain protected.
pub(crate) fn vram_idle_ms(video_memory: Option<[u64; 4]>) -> u64 {
const NORMAL_MS: u64 = 5_000;
const MODERATE_MS: u64 = 2_500;
const HIGH_MS: u64 = 1_000;
let Some([budget, used, ..]) = video_memory else {
return NORMAL_MS;
};
if budget == 0 {
return NORMAL_MS;
}
let used_pct = (u128::from(used) * 100) / u128::from(budget);
if used_pct >= 85 {
HIGH_MS
} else if used_pct >= 75 {
MODERATE_MS
} else {
NORMAL_MS
}
}
/// Effective idle timeout (in milliseconds) for system-RAM caches (staging
/// buffers, loose shadows, and the mapped pipeline library), scaled down
/// when free physical RAM is low. Never returns less than 2,000 ms.
pub(crate) fn ram_idle_ms(avail_phys: Option<u64>) -> u64 {
const GIB: u64 = 1024 * 1024 * 1024;
const NORMAL_MS: u64 = 10_000;
const MODERATE_MS: u64 = 5_000;
const HIGH_MS: u64 = 2_000;
let Some(avail) = avail_phys else {
return NORMAL_MS;
};
if avail < 2 * GIB {
HIGH_MS
} else if avail < 4 * GIB {
MODERATE_MS
} else {
NORMAL_MS
}
}
/// How many references are held on a host object (its COM count): ours
/// all, since the host's views and commands hold none. A buffer or texture
/// with one is held by its owner alone: no descriptor slot keeps it
@@ -6656,5 +6710,41 @@ mod batch { // Batch::texture_due lives here; `mod tests` is already taken at
before.as_secs_f64() / after.as_secs_f64()
);
}
#[test]
fn vram_idle_ms_scales_with_pressure() {
use super::vram_idle_ms;
let gib = 1024 * 1024 * 1024;
// Normal (< 75%)
assert_eq!(vram_idle_ms(Some([10 * gib, 0, 0, 0])), 5_000);
assert_eq!(vram_idle_ms(Some([10 * gib, 7 * gib, 0, 0])), 5_000);
assert_eq!(vram_idle_ms(Some([100, 74, 0, 0])), 5_000);
// Moderate (75%..85%)
assert_eq!(vram_idle_ms(Some([100, 75, 0, 0])), 2_500);
assert_eq!(vram_idle_ms(Some([100, 84, 0, 0])), 2_500);
// High (>= 85%, including over-budget)
assert_eq!(vram_idle_ms(Some([100, 85, 0, 0])), 1_000);
assert_eq!(vram_idle_ms(Some([10 * gib, 12 * gib, 0, 0])), 1_000);
// Missing or zero budget falls back to normal
assert_eq!(vram_idle_ms(None), 5_000);
assert_eq!(vram_idle_ms(Some([0, 100, 0, 0])), 5_000);
}
#[test]
fn ram_idle_ms_scales_with_pressure() {
use super::ram_idle_ms;
let gib = 1024 * 1024 * 1024;
// Normal (>= 4 GiB)
assert_eq!(ram_idle_ms(Some(8 * gib)), 10_000);
assert_eq!(ram_idle_ms(Some(4 * gib)), 10_000);
// Moderate (2 GiB..4 GiB)
assert_eq!(ram_idle_ms(Some(4 * gib - 1)), 5_000);
assert_eq!(ram_idle_ms(Some(2 * gib)), 5_000);
// High (< 2 GiB)
assert_eq!(ram_idle_ms(Some(2 * gib - 1)), 2_000);
assert_eq!(ram_idle_ms(Some(0)), 2_000);
// Missing falls back to normal
assert_eq!(ram_idle_ms(None), 10_000);
}
}
+5 -2
View File
@@ -363,13 +363,16 @@ pub(crate) fn removal_note() -> String {
/// (hundreds of thousands of pages), once after each burst of loads.
/// `VICTORY_LIBRARY_TRIM=0`: the pages stay until Windows takes them.
pub(crate) fn trim() {
const QUIET_MS: u64 = 10_000;
static ON: OnceLock<bool> = OnceLock::new();
let (at, len) = (VIEW[0].load(Ordering::Relaxed), VIEW[1].load(Ordering::Relaxed));
if at == 0
|| TRIMMED.load(Ordering::Relaxed)
|| crate::host::now_ms() < LOADED_AT.load(Ordering::Relaxed) + QUIET_MS
|| !*ON.get_or_init(|| std::env::var_os("VICTORY_LIBRARY_TRIM").is_none_or(|v| v != "0"))
{
return;
}
let quiet_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
if crate::host::now_ms() < LOADED_AT.load(Ordering::Relaxed) + quiet_ms
|| TRIMMED.swap(true, Ordering::Relaxed)
{
return;
+2 -2
View File
@@ -1422,12 +1422,12 @@ pub(crate) fn room(memory: Option<[u64; 4]>) -> bool {
#[cfg(windows)]
pub(crate) fn let_go_idle() {
use std::sync::atomic::Ordering::Relaxed;
const IDLE_MS: u64 = 5_000;
const IDLE_FRAMES: u64 = 4;
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if !*ON.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_SWEEP").is_none_or(|v| v != "0")) {
return;
}
let idle_ms = crate::host::vram_idle_ms(crate::host::host().and_then(|h| h.video_memory()));
// For the trail (`crate::host::trail`): how many went, their bytes,
// and the first one.
let (mut went, mut bytes, mut first) = (0u64, 0u64, None);
@@ -1442,7 +1442,7 @@ pub(crate) fn let_go_idle() {
let gone = {
let mut made = r.host.made.lock().unwrap_or_else(|e| e.into_inner());
let idle = made.as_ref().is_some_and(|(host, _)| {
crate::host::long_ago(r.host.used.load(Relaxed), IDLE_MS, IDLE_FRAMES)
crate::host::long_ago(r.host.used.load(Relaxed), idle_ms, IDLE_FRAMES)
&& std::sync::Arc::strong_count(host) == 1
&& crate::host::references(&host.texture) == 1
});
+5
View File
@@ -42,6 +42,9 @@ pub(crate) fn counts() -> (u64, u64) {
/// what it was told of the host. Not our executable: a rebuild of anything
/// else used to translate every shader again.
fn build() -> [u8; 32] {
// The view heap's null slot differs by host GPU: a translation cached
// without the clamp must not be served (`host_settings` below).
crate::descriptor::host::probe_view_limit();
static FIXED: OnceLock<Vec<u8>> = OnceLock::new();
let fixed = FIXED.get_or_init(|| {
let limit = victory_shader::emit::loop_limit();
@@ -66,6 +69,8 @@ fn build() -> [u8; 32] {
"VICTORY_WAVE_LOCAL",
"VICTORY_F16_NEAREST",
"VICTORY_HELPER_OWN",
"VICTORY_FIRSTLANE_OWN",
"VICTORY_FIRST_HALF",
"VICTORY_STRICT_JOINS",
"VICTORY_MESH_OUTPUT_STRICT",
] {
+5 -2
View File
@@ -1617,17 +1617,20 @@ pub(crate) fn window_use() -> [u64; 8] {
/// The next read of that memory makes a new copy and copies the window
/// again. Called before a submission starts, by the thread that submits.
pub(crate) fn let_go_idle() {
const IDLE_MS: u64 = 10_000;
const IDLE_FRAMES: u64 = 4;
let gone: Vec<Arc<Shadow>> = {
// Held from the look to the removal: `loose` hands a copy out
// under the same lock, so none is handed out in between.
let mut map = LOOSE.lock().unwrap_or_else(|e| e.into_inner());
if map.is_empty() {
return;
}
let idle_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
let idle: Vec<(u64, u64)> = map
.iter()
.filter(|(_, s)| {
Arc::strong_count(s) == 1
&& crate::host::long_ago(s.used.load(Ordering::Relaxed), IDLE_MS, IDLE_FRAMES)
&& crate::host::long_ago(s.used.load(Ordering::Relaxed), idle_ms, IDLE_FRAMES)
&& crate::host::references(&s.buffer) == 1
})
.map(|(key, _)| *key)
+45 -2
View File
@@ -452,19 +452,22 @@ pub(crate) fn let_go() -> [u64; 2] {
/// Called before a submission starts, by the thread that submits.
pub(crate) fn let_go_idle() {
use std::sync::atomic::Ordering::Relaxed;
const IDLE_MS: u64 = 10_000;
const IDLE_FRAMES: u64 = 4;
let mut map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
let Some(map) = map.as_mut() else {
return;
};
if map.is_empty() {
return;
}
let idle_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
// A list that recorded an upload or a check holds the staging until it
// is reset: one only the table holds is named by no list, recorded or
// running.
let (mut went, mut bytes) = (0u64, 0u64);
map.retain(|_, s| {
let keep = Arc::strong_count(s) > 1
|| !crate::host::long_ago(s.used.load(Relaxed), IDLE_MS, IDLE_FRAMES);
|| !crate::host::long_ago(s.used.load(Relaxed), idle_ms, IDLE_FRAMES);
if !keep {
LET_GO[0].fetch_add(1, Relaxed);
LET_GO[1].fetch_add(s.bytes, Relaxed);
@@ -885,6 +888,46 @@ pub(crate) fn unstage(resource: This) {
}
}
/// Where a staged title texture's memory is: address and bytes.
pub(crate) fn staged_memory(resource: This) -> Option<(u64, u64)> {
let map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
let (at, len) = map.as_ref()?.get(&(resource as usize))?.memory();
Some((at as u64, len as u64))
}
/// A fingerprint of the title memory `[at, at + len)`, never 0: of all of
/// it up to 48 KiB, else of 16 KiB at its start, its middle and its end
/// (a texture streams in whole mips; the small ones lie first). Read
/// through the kernel, so pages not there count as zeros.
pub(crate) fn fingerprint(at: u64, len: u64) -> u64 {
const WINDOW: usize = 16 << 10;
thread_local! {
static READ: std::cell::RefCell<Vec<u8>> = const { std::cell::RefCell::new(Vec::new()) };
}
let len = len as usize;
let mut hasher = blake3::Hasher::new();
READ.with(|read| {
let mut read = read.borrow_mut();
read.resize(3 * WINDOW, 0);
let mut take = |from: usize, bytes: usize| {
read[..bytes].fill(0);
crate::host::copy_mapped(read.as_mut_ptr(), (at as usize + from) as *const u8, bytes, false);
hasher.update(&read[..bytes]);
};
if len <= 3 * WINDOW {
take(0, len);
} else {
take(0, WINDOW);
take((len / 2) & !0xfff, WINDOW);
take(len - WINDOW, WINDOW);
}
});
let hash = hasher.finalize();
let mut first = [0u8; 8];
first.copy_from_slice(&hash.as_bytes()[..8]);
u64::from_le_bytes(first) | 1
}
/// Whether a title texture has a staging buffer: a list recorded its
/// upload, and the lists that sample it check it at submission.
pub(crate) fn is_staged(resource: This) -> bool {