Staged textures at title addresses: whether all is there, from the runtime's views
The texture pass's question whether a staged texture's memory is all there is still put to Windows for textures made at an address the title mapped (the console's usual placed textures; a question per 256 pages). The runtime's views of physical pages answer it where they cover the memory, as they already answer `mapped_bytes` for placed views: one look, under a microsecond where Windows took 3 us (350 KB), 135 us (22 MB) and 647 us (22 MB, 1 MB there) (look_costs on this PC). Windows is asked only where no view lies. `VICTORY_MAPPED_BY_VIEWS=0` asks Windows, as for `mapped_bytes`; `VICTORY_STAGED_ASK_ALL=1` still asks Windows of every texture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c1d1b4ee76
commit
6b3960daf2
1 file changed
+56
-8
@@ -1750,18 +1750,41 @@ pub(crate) fn is_staged(resource: This) -> bool {
|
||||
/// milliseconds when the pages had left the working set, and each such page
|
||||
/// read back into it), for 66 found not all there in a whole run
|
||||
/// (coolfox-20261126-223059); the pass's unattributed time went with their
|
||||
/// count, 13 us each. `VICTORY_STAGED_ASK_ALL=1`: asked of every texture,
|
||||
/// as before.
|
||||
/// count, 13 us each. Of one at a title address, the runtime's views of
|
||||
/// physical pages answer where they cover the memory ([`all_there`]: one
|
||||
/// look, under a microsecond), as they do for placed textures
|
||||
/// ([`mapped_bytes`]). `VICTORY_STAGED_ASK_ALL=1`: Windows is asked of every
|
||||
/// texture, as before.
|
||||
pub(crate) fn staged(resource: This, ask: bool) -> Option<(u64, bool)> {
|
||||
static ALL: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
let s = {
|
||||
let map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
|
||||
map.as_ref()?.get(&(resource as usize))?.clone()
|
||||
};
|
||||
let ask = ask
|
||||
&& (*ALL.get_or_init(|| std::env::var_os("VICTORY_STAGED_ASK_ALL").is_some_and(|v| v == "1"))
|
||||
|| crate::resource::at_title_address(resource));
|
||||
Some((s.read as u64, !ask || committed(s.memory, s.read)))
|
||||
let whole = !ask
|
||||
|| if *ALL.get_or_init(|| std::env::var_os("VICTORY_STAGED_ASK_ALL").is_some_and(|v| v == "1")) {
|
||||
committed(s.memory, s.read)
|
||||
} else {
|
||||
!crate::resource::at_title_address(resource) || all_there(s.memory, s.read)
|
||||
};
|
||||
Some((s.read as u64, whole))
|
||||
}
|
||||
|
||||
/// Whether all of `[at, at + len)` is mapped: by the runtime's views of
|
||||
/// physical pages where any lies there (as [`mapped_bytes`] asks), else by
|
||||
/// asking Windows ([`committed`]).
|
||||
fn all_there(at: *const u8, len: usize) -> bool {
|
||||
match by_views().then(|| crate::inplace::shown_bytes(at as usize, len)).flatten() {
|
||||
Some(there) => there >= len as u64,
|
||||
None => committed(at, len),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether how much of title memory is mapped is asked of the runtime's
|
||||
/// views of physical pages first (`VICTORY_MAPPED_BY_VIEWS=0`: of Windows).
|
||||
fn by_views() -> bool {
|
||||
static BY_VIEWS: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*BY_VIEWS.get_or_init(|| std::env::var_os("VICTORY_MAPPED_BY_VIEWS").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// Whether `[at, at + len)` is committed memory (streamed textures may be
|
||||
@@ -1875,8 +1898,7 @@ pub(crate) fn mapped_bytes(at: *const u8, len: usize) -> u64 {
|
||||
// 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"))
|
||||
if by_views()
|
||||
&& let Some(there) = crate::inplace::shown_bytes(start, len)
|
||||
{
|
||||
return there;
|
||||
@@ -2045,6 +2067,32 @@ fn staging(resource: This, copy: &crate::resource::HostTexture, first: u32) -> O
|
||||
mod title_memory_tests {
|
||||
use super::with_title;
|
||||
|
||||
/// Whether memory is all there is answered by the runtime's views of
|
||||
/// physical pages where they lie, and by Windows where none does.
|
||||
#[test]
|
||||
fn all_there_asks_the_views_where_they_lie() {
|
||||
use windows_sys::Win32::System::Memory::{MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_READWRITE, VirtualAlloc, VirtualFree};
|
||||
const BLOCK: usize = 64 << 10;
|
||||
// SAFETY: a reservation of our own, its first two blocks committed.
|
||||
let at = unsafe {
|
||||
let at = VirtualAlloc(std::ptr::null(), 4 * BLOCK, MEM_RESERVE, PAGE_READWRITE);
|
||||
VirtualAlloc(at, 2 * BLOCK, MEM_COMMIT, PAGE_READWRITE);
|
||||
at as usize
|
||||
};
|
||||
let there = |len| super::all_there(at as *const u8, len);
|
||||
assert!(there(2 * BLOCK));
|
||||
assert!(!there(3 * BLOCK));
|
||||
// The runtime's views of the first two blocks answer for them.
|
||||
for block in 0..2 {
|
||||
crate::title_memory_view(at + block * BLOCK, BLOCK, 9, 0);
|
||||
}
|
||||
assert!(there(2 * BLOCK));
|
||||
assert!(!there(3 * BLOCK));
|
||||
crate::inplace::views_gone(at, 4 * BLOCK);
|
||||
// SAFETY: our reservation, released whole.
|
||||
unsafe { VirtualFree(at as *mut _, 0, MEM_RELEASE) };
|
||||
}
|
||||
|
||||
/// Title memory whose tail is reserved and not committed reads through
|
||||
/// the copy as its bytes and then zeros, without a fault; so does
|
||||
/// memory a page of which is taken away between two reads, and the
|
||||
|
||||
Reference in new issue
Block a user