Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions d3d12/apps/leonida/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ fn main() -> Result<()> {
console,
title_args,
} => {
// Before the host GPU and Streamline: a proxy DLL hooks what loads after it.
#[cfg(windows)]
leonida_loader::preload_dlls();
leonida_hle::runtime::set_title_args(title_args);
run::run(&exe, unimplemented, strict, execute, console)
}
Expand Down
59 changes: 52 additions & 7 deletions d3d12/crates/leonida-gpu/src/inplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ fn views_mut() -> std::sync::RwLockWriteGuard<'static, Views> {
VIEWS.write().unwrap_or_else(|e| e.into_inner())
}

/// The bytes of the section with handle `section`, if the runtime told of it
/// ([`title_memory_section`]).
pub(crate) fn section_bytes(section: usize) -> Option<u64> {
views().sections.iter().find(|s| s.0 == section).map(|s| s.1)
}

/// The runtime made a section of `bytes` for physical pages; `committed`
/// if with `SEC_COMMIT` (only such a section can be opened as a heap).
pub fn title_memory_section(section: usize, bytes: u64, committed: bool) {
Expand Down Expand Up @@ -535,6 +541,34 @@ pub(crate) fn cover(at: usize, len: usize) -> Cover {
cover_in(&views().views, at, len)
}

/// The section and offset of every 64 KiB page of title memory `[at, at +
/// len)`, in order, if every page is in a view of a section: the page-pool
/// windows are not one run of a section, but each page can be mapped into
/// one run of ours ([`crate::port`] level 2).
pub(crate) fn page_sections(at: usize, len: usize) -> Option<Vec<(usize, u64)>> {
if len == 0 {
return None;
}
let start = at & !(K64 - 1);
let end = at.checked_add(len)?.checked_add(K64 - 1)? & !(K64 - 1);
if end <= start {
return None;
}
let v = views();
let mut pages = Vec::with_capacity((end - start) / K64);
let mut page = start;
while page < end {
let (&base, &(bytes, section, offset)) = v.views.range(..=page).next_back()?;
let within = page.checked_sub(base)?;
if within >= bytes || !within.is_multiple_of(K64) {
return None;
}
pages.push((section, offset + within as u64));
page += K64;
}
Some(pages)
}

/// The whole stretch of views around `[at, at + len)` that follow one
/// another in memory and in one section alike, if the range is one run of a
/// section ([`Cover::Run`]): its first address, its bytes, the section and
Expand Down Expand Up @@ -1258,10 +1292,24 @@ fn real_part(spans: &[(u64, u64, bool)]) -> Vec<String> {
lines
}

/// When the census is taken, in seconds after the probe
/// (`LEONIDA_INPLACE_CENSUS_S`, `30,150`): later ones see the world, which
/// the first minutes of a run (menus, the load) do not.
fn census_times() -> &'static [u64] {
static TIMES: std::sync::OnceLock<Vec<u64>> = std::sync::OnceLock::new();
TIMES.get_or_init(|| {
let times: Vec<u64> = std::env::var("LEONIDA_INPLACE_CENSUS_S")
.ok()
.map(|v| v.split(',').filter_map(|s| s.trim().parse().ok()).collect())
.unwrap_or_default();
if times.is_empty() { vec![30, 150] } else { times }
})
}

/// Called once a second by the thread that submits, before a submission
/// (`host::sweep`): with [`probe_level`], the probe at the first call, the
/// census (on a thread of its own: it asks Windows about every copy) 30
/// and 150 seconds later.
/// census (on a thread of its own: it asks Windows about every copy) at
/// [`census_times`].
pub(crate) fn tick() {
if level() > 0 {
say();
Expand All @@ -1288,11 +1336,8 @@ pub(crate) fn tick() {
}
Err(started) => started,
};
let due = match DONE.load(Ordering::Relaxed) {
0 => now >= started + 30_000,
1 => now >= started + 150_000,
_ => false,
};
let done = DONE.load(Ordering::Relaxed) as usize;
let due = census_times().get(done).is_some_and(|&s| now >= started + s * 1000);
if due {
let which = DONE.fetch_add(1, Ordering::Relaxed);
std::thread::spawn(move || {
Expand Down
Loading