mirror of
https://github.com/DoubleGhosty/cool_fox.git
synced 2026-12-06 09:08:36 +00:00
Whether a texture's memory is there is answered by the views that show it whole (VICTORY_COMMITTED_BY_VIEWS)
texture::committed asked the host about every texture due, and with VICTORY_COMMITTED_QUERY=1 (what the Proton launcher sets: QueryWorkingSetEx is the costly one under Wine) that is one VirtualQuery for each view the texture lies across. Each takes Wine's one lock for all of memory, which the protection changes of the guards and the title's page mappings hold a third of the time: 7,000 questions a second in the prologue, each holding the lock 0.5 us and waiting 7 to 40 us for it (an ntdll that counts the lock's takings by caller, RTX 5060 under Proton). What views of physical pages show whole, of sections made committed, is there by the runtime's own record (inplace::shown_committed): then the host is not asked. Anything else is asked as before: a part no view shows, or a section whose pages are committed one by one. Same scene: 1,000 questions a second from there, 388 questions a frame of all kinds where there were 735. VICTORY_COMMITTED_BY_VIEWS=0 asks every time, as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@ -499,6 +499,35 @@ pub(crate) fn shown_runs(at: usize, len: usize) -> Vec<(usize, usize)> {
|
||||
runs
|
||||
}
|
||||
|
||||
/// Whether all of `[at, at + len)` is shown by views of sections made
|
||||
/// committed: memory that is there, by the runtime's own record, with no
|
||||
/// question to the host. False says nothing (a part is not a view, or is of
|
||||
/// a section whose pages are committed one by one): the host is to be asked.
|
||||
pub(crate) fn shown_committed(at: usize, len: usize) -> bool {
|
||||
let v = views();
|
||||
let end = at.saturating_add(len.max(1));
|
||||
let committed = |section: usize| v.sections.iter().any(|s| s.0 == section && s.2);
|
||||
let Some((&base, &(bytes, section, _))) = v.views.range(..=at).next_back().filter(|(base, view)| *base + view.0 > at)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
if !committed(section) {
|
||||
return false;
|
||||
}
|
||||
let (mut reached, mut last) = (base + bytes, section);
|
||||
while reached < end {
|
||||
let Some(&(bytes, section, _)) = v.views.get(&reached) else {
|
||||
return false;
|
||||
};
|
||||
if section != last && !committed(section) {
|
||||
return false;
|
||||
}
|
||||
last = section;
|
||||
reached += bytes;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// How the views cover `[at, at + len)`.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub(crate) enum Cover {
|
||||
@ -1344,6 +1373,35 @@ pub(crate) mod tests {
|
||||
assert_eq!(shown(0, 8 * K64), None);
|
||||
}
|
||||
|
||||
/// What views of committed sections show whole is there without asking
|
||||
/// the host; anything else is not said to be.
|
||||
#[test]
|
||||
fn views_of_committed_sections_say_what_is_there() {
|
||||
const K64: usize = 64 << 10;
|
||||
// Addresses nothing has: only the record is asked.
|
||||
let at = 0x7ff2_0000_0000_usize;
|
||||
super::title_memory_section(0x51, 16 * K64 as u64, true);
|
||||
super::title_memory_section(0x52, 16 * K64 as u64, false);
|
||||
for (block, blocks, section, offset) in [(0, 2, 0x51, 0), (2, 1, 0x51, 9), (3, 1, 0x52, 0), (5, 1, 0x51, 12)] {
|
||||
super::title_memory_view(at + block * K64, blocks * K64, section, (offset * K64) as u64);
|
||||
}
|
||||
let there = |from: usize, len: usize| super::shown_committed(at + from, len);
|
||||
assert!(there(0, 3 * K64), "views that touch, from two places of the section");
|
||||
assert!(there(100, 10));
|
||||
assert!(there(2 * K64 - 1, 2), "across two views");
|
||||
assert!(there(0, 0));
|
||||
assert!(!there(0, 4 * K64), "the last of it in a section committed page by page");
|
||||
assert!(!there(3 * K64, 1));
|
||||
assert!(!there(4 * K64, K64), "no view");
|
||||
assert!(!there(2 * K64, 4 * K64), "a hole in it");
|
||||
assert!(there(5 * K64, K64));
|
||||
assert!(!there(5 * K64, K64 + 1), "past the last view");
|
||||
super::views_gone(at, 8 * K64);
|
||||
assert!(!there(0, K64));
|
||||
super::title_memory_section_gone(0x51);
|
||||
super::title_memory_section_gone(0x52);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn views_say_what_one_placed_buffer_could_show() {
|
||||
let mut views = BTreeMap::new();
|
||||
|
||||
@ -1769,6 +1769,17 @@ pub(crate) fn staged(resource: This, ask: bool) -> Option<(u64, bool)> {
|
||||
/// Whether `[at, at + len)` is committed memory (streamed textures may be
|
||||
/// unmapped until their pages arrive).
|
||||
pub(crate) fn committed(at: *const u8, len: usize) -> bool {
|
||||
// What views of physical pages show whole is there, by the runtime's own
|
||||
// record: no question to the host. Under Wine each question takes its one
|
||||
// memory lock, and a texture across n views is n questions: 7,000 a
|
||||
// second in the prologue, each waiting 7 to 40 us for the lock (run vm2).
|
||||
// `VICTORY_COMMITTED_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_COMMITTED_BY_VIEWS").is_none_or(|v| v != "0"))
|
||||
&& crate::inplace::shown_committed(at as usize, len)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if by_query() {
|
||||
return committed_by_query(at, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user