How much of a texture is mapped is read from the runtime's own record of its views

The pass that uploads textures picked by index asked the host for every
64 KiB of every texture it looked at, and twice for each block that was not
there (12,000 slots wait for their memory during a load, each looked at
again and again): 146 us for a texture of 22 MB, 721 us with 1 MB of it
there. The views of physical pages are known: 1.4 and 0.1 us. Memory that
is in no view is asked of the host as before. VICTORY_MAPPED_BY_VIEWS=0:
always. Measurement: cargo test --release -p victory-gpu --lib look_costs
-- --ignored --nocapture

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 23:46:35 -06:00
1 parent fbc1830858
commit c27a8ec844
2 files changed
+85

No files matched your search

+44
View File
@@ -1119,6 +1119,16 @@ pub(crate) fn mapped_bytes(at: *const u8, len: usize) -> u64 {
}
let start = at as usize;
let end = start.saturating_add(len);
// Streamed textures lie in views of physical pages, of which the runtime
// knows which are there: one look, where the host was asked for every
// 64 KiB of the texture (and once more for each that is not there).
// `VICTORY_MAPPED_BY_VIEWS=0`: the host is asked, as before.
static BY_VIEWS: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if *BY_VIEWS.get_or_init(|| std::env::var_os("VICTORY_MAPPED_BY_VIEWS").is_none_or(|v| v != "0"))
&& let Some(there) = crate::inplace::shown_bytes(start, len)
{
return there;
}
if !committed(at, 1) && !committed((end - 1) as *const u8, 1) {
return 0;
}
@@ -1417,6 +1427,40 @@ mod allocation_costs {
drop(all);
}
/// What a look at how much of a texture is there costs: by questions to
/// the host, and by the runtime's record of its views.
#[test]
#[ignore = "a measurement, not a check"]
fn look_costs() {
use windows_sys::Win32::System::Memory::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE, VirtualAlloc};
const BLOCK: usize = 64 << 10;
for (name, blocks, there) in [("350 KB, all there", 6, 6), ("22 MB, all there", 350, 350), ("22 MB, 1 MB there", 350, 16)] {
let make = || {
// SAFETY: a reservation of our own, of which the first part
// is committed and touched.
unsafe {
let at = VirtualAlloc(std::ptr::null(), blocks * BLOCK, MEM_RESERVE, PAGE_READWRITE);
VirtualAlloc(at, there * BLOCK, MEM_COMMIT, PAGE_READWRITE);
std::ptr::write_bytes(at.cast::<u8>(), 1, there * BLOCK);
at as usize
}
};
let (asked, noted) = (make(), make());
for block in 0..there {
crate::title_memory_view(noted + block * BLOCK, BLOCK, 9, 0);
}
for (how, at) in [("asking the host", asked), ("by the views", noted)] {
const N: u32 = 200;
let began = std::time::Instant::now();
for _ in 0..N {
assert_eq!(super::mapped_bytes(at as *const u8, blocks * BLOCK), (there * BLOCK) as u64);
}
println!("{name}, {how}: {:.1} us a look", began.elapsed().as_secs_f64() * 1e6 / f64::from(N));
}
crate::inplace::views_gone(noted, blocks * BLOCK);
}
}
#[test]
#[ignore = "a measurement, not a check"]
fn allocation_costs() {