Merge day/submit: the panel, parts of submissions prepared as one (VICTORY_JOIN_PARTS, off), fills cut free of copies
A submission whose lists are still being translated is unfolded where the one before it may take it along. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
7c607d63f4
10 files changed
+1300
-112
No files matched your search
@@ -30,7 +30,7 @@ diagnostics = []
|
||||
workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Security", "Win32_System_Diagnostics_Debug", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Kernel", "Win32_System_LibraryLoader", "Win32_System_Memory", "Win32_System_Performance", "Win32_System_ProcessStatus", "Win32_System_Registry", "Win32_System_SystemInformation", "Win32_System_Threading"] }
|
||||
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Security", "Win32_System_Diagnostics_Debug", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Kernel", "Win32_System_LibraryLoader", "Win32_System_Memory", "Win32_System_Performance", "Win32_System_ProcessStatus", "Win32_System_Registry", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] }
|
||||
windows = { workspace = true, features = [
|
||||
"Win32_Graphics_Direct3D",
|
||||
"Win32_Graphics_Direct3D_Fxc",
|
||||
|
||||
@@ -161,6 +161,13 @@ pub(crate) fn add(c: C, n: u64) {
|
||||
COUNT[bank()].0[c as usize].fetch_add(n, Relaxed);
|
||||
}
|
||||
|
||||
/// The counter, all sets together, as it is now (it goes back to 0 with
|
||||
/// [`log`]).
|
||||
pub(crate) fn peek(c: C) -> u64 {
|
||||
let i = c as usize;
|
||||
COUNT.iter().map(|b| b.0[i].load(Relaxed)).sum()
|
||||
}
|
||||
|
||||
/// Counter `i`, all sets together, from now on 0.
|
||||
fn taken(i: usize) -> u64 {
|
||||
COUNT.iter().map(|b| b.0[i].swap(0, Relaxed)).sum()
|
||||
@@ -491,7 +498,7 @@ mod own_tests {
|
||||
|
||||
/// The process's memory in bytes: in physical memory, and committed
|
||||
/// (private bytes).
|
||||
fn process_memory() -> (u64, u64) {
|
||||
pub(crate) fn process_memory() -> (u64, u64) {
|
||||
use windows_sys::Win32::System::ProcessStatus::{
|
||||
K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS,
|
||||
};
|
||||
|
||||
@@ -452,6 +452,12 @@ pub(crate) fn take_frame() -> Vec<String> {
|
||||
std::mem::take(&mut *FRAME.lock().unwrap_or_else(|e| e.into_inner()))
|
||||
}
|
||||
|
||||
/// The draws dropped since [`take_dropped`].
|
||||
#[cfg_attr(not(feature = "diagnostics"), allow(dead_code))]
|
||||
pub(crate) fn dropped_now() -> u64 {
|
||||
DROPPED.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Draws, mesh dispatches and dispatches recorded but not run on the host
|
||||
/// (no host pipeline) since the last call.
|
||||
pub(crate) fn take_dropped() -> u64 {
|
||||
|
||||
+381
-37
@@ -2944,6 +2944,87 @@ fn stale_under_flights(runs: &[&HostList]) -> Vec<(std::sync::Arc<crate::shadow:
|
||||
spans
|
||||
}
|
||||
|
||||
/// How many parts of submissions, and lists, the line's thread gives to the
|
||||
/// host as one (`VICTORY_JOIN_PARTS=<n>`; off by default, 1; `VICTORY_JOIN_LISTS`,
|
||||
/// 48).
|
||||
///
|
||||
/// The idea is fxceless/victory-fork's, commit 39731795 (GPL-3.0-or-later, as
|
||||
/// this): the title's lists wait for memory values, which cuts a frame into
|
||||
/// some 29 parts, each prepared on its own: the write watch asked, the heaps'
|
||||
/// records, the title's bytes under the flights' writes, a list that sends
|
||||
/// what changed and one that compares. (Run submit-1, the dorm, 12 of 28 parts
|
||||
/// joined, eight at most: the thread works 51.4 ms a frame instead of 54.8, the
|
||||
/// frame is 0.6 to 3 ms shorter.) What differs here: the parts are taken
|
||||
/// off one queue's entries of the line (`crate::queue`), still go to the queue
|
||||
/// in calls of their own, and everything they refresh is brought up to date in
|
||||
/// front of the first ([`refresh_front`], without which a later part's title
|
||||
/// bytes under an earlier part's declared writes would go missing).
|
||||
pub(crate) fn joins() -> (usize, usize) {
|
||||
if ahead_of_writes() { joins_asked() } else { (1, 1) }
|
||||
}
|
||||
|
||||
fn joins_asked() -> (usize, usize) {
|
||||
static MOST: OnceLock<(usize, usize)> = OnceLock::new();
|
||||
let of = |name: &str| std::env::var(name).ok().and_then(|v| v.trim().parse::<usize>().ok());
|
||||
let (parts, lists) = *MOST.get_or_init(|| (of("VICTORY_JOIN_PARTS").unwrap_or(1).max(1), of("VICTORY_JOIN_LISTS").unwrap_or(48).max(1)));
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if let Some(on) = crate::ab::pick("VICTORY_JOIN_PARTS") {
|
||||
return (if on { 8 } else { 1 }, lists);
|
||||
}
|
||||
(parts, lists)
|
||||
}
|
||||
|
||||
/// Whether the part `next` can be prepared together with `ahead`, which goes
|
||||
/// before it and has not been sent: nothing done on the CPU for it reads what
|
||||
/// those give their shaders, write back or write when they are done, and it
|
||||
/// changes no title memory that they read ([`Step::Copy`], [`Step::Run`]).
|
||||
pub(crate) fn joinable<'a>(ahead: impl Iterator<Item = &'a HostList>, next: &[&HostList]) -> bool {
|
||||
if next.iter().any(|l| l.deferred().copies.iter().any(|s| matches!(s, Step::Copy(..) | Step::Run(_)))) {
|
||||
return false;
|
||||
}
|
||||
let ahead: Vec<&HostList> = ahead.collect();
|
||||
let mut written: Vec<(usize, usize)> = declared_writes(&ahead).into_iter().flat_map(|(_, ranges)| ranges).collect();
|
||||
for list in &ahead {
|
||||
let deferred = list.deferred();
|
||||
written.extend(deferred.writes.iter().map(|&(at, _, bytes)| (at, at + bytes)));
|
||||
written.extend(deferred.backs.iter().map(|&(_, at, [row, rows, pitch])| (at, at + rows.saturating_sub(1) * pitch + row)));
|
||||
}
|
||||
let mut joined = Vec::new();
|
||||
join_ranges(&mut joined, written);
|
||||
blocked_by(&joined, next, false).is_none()
|
||||
}
|
||||
|
||||
/// Whether a bottom-of-pipe write of `list` meets `wait`.
|
||||
pub(crate) fn will_meet(list: &HostList, wait: &crate::list::ValueWait) -> bool {
|
||||
let (address, bytes) = wait.place();
|
||||
// The last write there says.
|
||||
let deferred = list.deferred();
|
||||
let last = deferred.writes.iter().rev().find(|(at, _, n)| *at < address + bytes && address < *at + *n);
|
||||
matches!(last, Some((at, crate::queue::Written::Value(v), n)) if *at == address && *n >= bytes && wait.holds_for(*v))
|
||||
}
|
||||
|
||||
/// Lists and the order they run in.
|
||||
type Run<T> = (Vec<T>, Vec<usize>);
|
||||
|
||||
/// `order`'s first `cut` places and the rest, each with the lists they name;
|
||||
/// as it was if a list is named on both sides.
|
||||
fn split<T>(lists: Vec<T>, order: Vec<usize>, cut: usize) -> Result<[Run<T>; 2], Run<T>> {
|
||||
let (first, second) = order.split_at(cut);
|
||||
if first.is_empty() || second.is_empty() || first.iter().any(|i| second.contains(i)) {
|
||||
return Err((lists, order));
|
||||
}
|
||||
let behind: Vec<bool> = (0..lists.len()).map(|i| second.contains(&i)).collect();
|
||||
let place = |i: usize| behind[..i].iter().filter(|&&b| b == behind[i]).count();
|
||||
let orders = [first, second].map(|half| half.iter().map(|&i| place(i)).collect::<Vec<_>>());
|
||||
let mut halves: [Vec<T>; 2] = [Vec::new(), Vec::new()];
|
||||
for (list, behind) in lists.into_iter().zip(&behind) {
|
||||
halves[usize::from(*behind)].push(list);
|
||||
}
|
||||
let [a, b] = halves;
|
||||
let [x, y] = orders;
|
||||
Ok([(a, x), (b, y)])
|
||||
}
|
||||
|
||||
/// A fence signal on a queue ([`late`]): goes behind the flights in the
|
||||
/// air, if there are any, and is set when they are settled. Whether it
|
||||
/// did; if not the caller sets the fence now.
|
||||
@@ -2973,11 +3054,20 @@ pub(crate) fn late_signal(fence: usize, value: u64) -> bool {
|
||||
/// the value in a way not known here (shaders, a timestamp, another
|
||||
/// width), they are settled and memory is asked again.
|
||||
pub(crate) fn late_met(wait: &crate::list::ValueWait) -> bool {
|
||||
if let Some(met) = late_met_known(wait) {
|
||||
return met;
|
||||
}
|
||||
settle_now(WHY_VALUE);
|
||||
wait.met()
|
||||
}
|
||||
|
||||
/// [`late_met`] without a wait for the card; `None`: it has to be waited for.
|
||||
pub(crate) fn late_met_known(wait: &crate::list::ValueWait) -> Option<bool> {
|
||||
let (address, bytes) = wait.place();
|
||||
{
|
||||
let line = line();
|
||||
if line.line.is_empty() && line.in_hand.is_empty() {
|
||||
return false;
|
||||
return Some(false);
|
||||
}
|
||||
let mut unsure = touches(&line.written, address, address + bytes);
|
||||
// (With the relay: first the writes of flights being landed.)
|
||||
@@ -2993,18 +3083,17 @@ pub(crate) fn late_met(wait: &crate::list::ValueWait) -> bool {
|
||||
crate::queue::Written::Value(v) if *at == address && *n >= bytes => {
|
||||
if wait.holds_for(*v) {
|
||||
LATE_STATS[13].fetch_add(1, Ordering::Relaxed);
|
||||
return true;
|
||||
return Some(true);
|
||||
}
|
||||
}
|
||||
_ => unsure = true,
|
||||
}
|
||||
}
|
||||
if !unsure {
|
||||
return false;
|
||||
return Some(false);
|
||||
}
|
||||
}
|
||||
settle_now(WHY_VALUE);
|
||||
wait.met()
|
||||
None
|
||||
}
|
||||
|
||||
/// Settles the flights in the air, if any ([`Host::settle`]), for reason
|
||||
@@ -3467,12 +3556,16 @@ pub(crate) mod aside;
|
||||
pub(crate) mod awake;
|
||||
mod card_steps;
|
||||
pub(crate) mod indirects;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
mod panel;
|
||||
mod place;
|
||||
mod send;
|
||||
pub(crate) use send::{goes_as_words, words_under};
|
||||
#[cfg(feature = "diagnostics")]
|
||||
pub(crate) mod spans;
|
||||
mod torn;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
mod traffic;
|
||||
pub(crate) mod upcheck;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
mod stamps;
|
||||
@@ -4014,30 +4107,13 @@ impl Host {
|
||||
/// `relay`).
|
||||
/// `picked`: ranges that may be written too, and ranges to look at
|
||||
/// (`crate::picked`).
|
||||
fn card_before(&self, runs: &[&HostList], picked: &crate::picked::Ranges, flown: bool) -> Option<CardPlan> {
|
||||
fn card_before(&self, declared: &[Declared], picked: &crate::picked::Ranges, flown: bool) -> Option<CardPlan> {
|
||||
use std::sync::Arc;
|
||||
if !crate::shadow::cards() {
|
||||
return None;
|
||||
}
|
||||
// The ranges this submission's shaders may write, per copy.
|
||||
let mut declared: Vec<(Arc<crate::shadow::Shadow>, Vec<(usize, usize)>)> = Vec::new();
|
||||
for list in runs {
|
||||
for step in &list.deferred().copies {
|
||||
if let Step::GpuWrite(shadow, address, len) = step
|
||||
&& shadow.carded()
|
||||
{
|
||||
let range = (*address, *address + *len);
|
||||
match declared.iter_mut().find(|(s, _)| Arc::ptr_eq(s, shadow)) {
|
||||
Some((_, ranges)) => {
|
||||
if !ranges.contains(&range) {
|
||||
ranges.push(range);
|
||||
}
|
||||
}
|
||||
None => declared.push((shadow.clone(), vec![range])),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let declared: Vec<Declared> = declared.iter().filter(|(shadow, _)| shadow.carded()).cloned().collect();
|
||||
let declared = if crate::picked::lands() { crate::picked::with(declared, &picked.written) } else { declared };
|
||||
// (Of a copy with a declared range here, that says it.)
|
||||
let looked: Vec<&crate::picked::Range> =
|
||||
@@ -4110,6 +4186,8 @@ impl Host {
|
||||
crate::shadow::CARD_STATS[0].fetch_add((b - a) as u64, Ordering::Relaxed);
|
||||
}
|
||||
crate::shadow::CARD_STATS[1].fetch_add(ranges.len() as u64, Ordering::Relaxed);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
traffic::moved(traffic::UP, shadow.span(), ranges.iter().copied());
|
||||
if own.is_none() && before.is_some() && !ranges.is_empty() {
|
||||
sent.push(transition(
|
||||
&shadow.buffer,
|
||||
@@ -4453,6 +4531,10 @@ impl Host {
|
||||
if let Some(check) = &check {
|
||||
total = check.total;
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
for (shadow, lo, hi, _) in &pieces {
|
||||
traffic::moved(traffic::FETCHED, shadow.span(), std::iter::once((*lo, *hi)));
|
||||
}
|
||||
// The sends these flights ran behind, all a fetch on the copy queue
|
||||
// is known to have run behind.
|
||||
let behind = plans.iter().map(|p| p.0.sent_as).max().unwrap_or(0);
|
||||
@@ -4881,7 +4963,7 @@ impl Host {
|
||||
pub(crate) fn execute(&self, runs: &[&HostList]) {
|
||||
// Behind what the title's queues were given before it.
|
||||
crate::queue::before_sync();
|
||||
let _ = self.submit(runs, false);
|
||||
let _ = self.submit(runs, &[], false);
|
||||
}
|
||||
|
||||
/// A queue's submission with [`late`]: the host lists `lists`, taken
|
||||
@@ -4891,14 +4973,39 @@ impl Host {
|
||||
/// ([`late`] lists those points); their host lists are reset and kept
|
||||
/// for reuse then, as a queue does for the lists it ran.
|
||||
pub(crate) fn execute_late(&self, lists: Vec<crate::list::Detached>, order: Vec<usize>) {
|
||||
self.execute_parts(lists, order, &[]);
|
||||
}
|
||||
|
||||
/// [`Host::execute_late`] of parts of submissions in one: another begins
|
||||
/// at each place of `order` in `parts` ([`joins`]).
|
||||
pub(crate) fn execute_parts(&self, lists: Vec<crate::list::Detached>, order: Vec<usize>, parts: &[usize]) {
|
||||
if order.is_empty() {
|
||||
crate::list::recycle(lists, &order);
|
||||
return;
|
||||
}
|
||||
late_threads();
|
||||
if let Some(cut) = {
|
||||
let runs: Vec<&HostList> = order.iter().map(|&i| lists[i].host()).collect();
|
||||
card_steps::cut_for(&runs)
|
||||
} {
|
||||
match split(lists, order, cut) {
|
||||
Ok([(lists, order), (more, behind)]) => {
|
||||
let first: Vec<usize> = parts.iter().copied().filter(|&p| p < cut).collect();
|
||||
let second: Vec<usize> = parts.iter().filter(|&&p| p > cut).map(|p| p - cut).collect();
|
||||
self.execute_parts(lists, order, &first);
|
||||
self.execute_parts(more, behind, &second);
|
||||
}
|
||||
Err((lists, order)) => self.send_late(lists, order, parts),
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.send_late(lists, order, parts);
|
||||
}
|
||||
|
||||
fn send_late(&self, lists: Vec<crate::list::Detached>, order: Vec<usize>, parts: &[usize]) {
|
||||
let sent = {
|
||||
let runs: Vec<&HostList> = order.iter().map(|&i| lists[i].host()).collect();
|
||||
self.submit(&runs, true)
|
||||
self.submit(&runs, parts, true)
|
||||
};
|
||||
let Some((mut submitted, sent)) = sent else {
|
||||
// (Not reached: a submission sent ahead always comes back.)
|
||||
@@ -4948,7 +5055,7 @@ impl Host {
|
||||
/// it ran and was waited for after all.
|
||||
fn execute_own(&self, list: &HostList) -> u64 {
|
||||
late_threads();
|
||||
let Some((submitted, sent)) = self.submit(&[list], true) else {
|
||||
let Some((submitted, sent)) = self.submit(&[list], &[], true) else {
|
||||
return 0;
|
||||
};
|
||||
let number = sent.number;
|
||||
@@ -5170,7 +5277,11 @@ impl Host {
|
||||
/// [`Host::execute_late`]: the lists are prepared and sent, and what is
|
||||
/// to be done once they have run comes back with the submission lock
|
||||
/// still held.
|
||||
fn submit<'a>(&'a self, runs: &[&HostList], late: bool) -> Option<(std::sync::MutexGuard<'a, u64>, Sent)> {
|
||||
///
|
||||
/// `parts`: the lists of `runs` at which another part begins
|
||||
/// ([`joins`]): those go to the queue in calls of their own, one after the
|
||||
/// other, as they would have.
|
||||
fn submit<'a>(&'a self, runs: &[&HostList], parts: &[usize], late: bool) -> Option<(std::sync::MutexGuard<'a, u64>, Sent)> {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let called = std::time::Instant::now();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
@@ -5223,6 +5334,7 @@ impl Host {
|
||||
}
|
||||
None => runs,
|
||||
};
|
||||
let parts: Vec<usize> = parts.iter().map(|&n| n + usize::from(own.is_some())).collect();
|
||||
stage.next("submit: the sweep");
|
||||
let behind = late && flying();
|
||||
// Before this submission counts as started: what the sweep lets go
|
||||
@@ -5318,7 +5430,9 @@ impl Host {
|
||||
// What flights in the air may write.
|
||||
let air = line().written.clone();
|
||||
stage.next("submit: refreshes ahead of writes");
|
||||
if ahead_of_writes() {
|
||||
if refresh_front() {
|
||||
batch.refresh_front(runs, &parts);
|
||||
} else if ahead_of_writes() {
|
||||
batch.refresh_ahead(runs, |list, i| own.as_ref().is_some_and(|own| own.takes(list, i)));
|
||||
}
|
||||
stage.next("submit: the lists' steps");
|
||||
@@ -5365,7 +5479,8 @@ impl Host {
|
||||
for (shadow, at, len) in &picked.written {
|
||||
shadow.writing(*at, *len);
|
||||
}
|
||||
let card = self.card_before(runs, &picked, flown);
|
||||
let declared = declared_writes(runs);
|
||||
let card = self.card_before(&declared, &picked, flown);
|
||||
// The sends are taken: from here on the references hold what the
|
||||
// copies in the lists put.
|
||||
for (shadow, at, bytes) in batch.placed.drain(..) {
|
||||
@@ -5402,10 +5517,16 @@ impl Host {
|
||||
if let Some([front, behind]) = self.span_lists() {
|
||||
lists.insert(0, Some(front));
|
||||
lists.push(Some(behind));
|
||||
firsts.iter_mut().for_each(|first| *first += 1);
|
||||
}
|
||||
let cuts: Vec<usize> = parts.iter().filter_map(|&n| firsts.get(n).copied()).collect();
|
||||
// SAFETY: closed lists; the fence is ours.
|
||||
let signalled = unsafe {
|
||||
self.queue.ExecuteCommandLists(&lists);
|
||||
let mut from = 0;
|
||||
for to in cuts.into_iter().chain([lists.len()]) {
|
||||
self.queue.ExecuteCommandLists(&lists[from..to]);
|
||||
from = to;
|
||||
}
|
||||
self.queue.Signal(&self.fence, *submitted)
|
||||
};
|
||||
awake::sent(&self.device);
|
||||
@@ -5418,7 +5539,7 @@ impl Host {
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
split.part(5);
|
||||
let back = crate::picked::with(declared_writes(runs), &picked.written);
|
||||
let back = crate::picked::with(declared, &picked.written);
|
||||
let writes = runs.iter().flat_map(|l| l.deferred().writes.clone()).collect();
|
||||
SUBMISSION_US[0].fetch_add((prepared - started).saturating_sub(settled).as_micros() as u64, Ordering::Relaxed);
|
||||
submitting(0, 0);
|
||||
@@ -5543,7 +5664,7 @@ impl Host {
|
||||
if let Some(card) = &card {
|
||||
self.card_back(card, &mut submitted, &mut std::collections::HashSet::new());
|
||||
}
|
||||
let back = crate::picked::with(declared_writes(runs), &picked.written);
|
||||
let back = crate::picked::with(declared, &picked.written);
|
||||
hand_back(&back);
|
||||
if let Some(card) = card {
|
||||
self.card_done(card);
|
||||
@@ -7180,6 +7301,9 @@ struct Batch {
|
||||
/// Copies (by address) brought up to date ahead of the steps, and the
|
||||
/// range (from, to) ([`Batch::refresh_ahead`]).
|
||||
ahead: ByCopy<(usize, usize)>,
|
||||
/// `ahead` holds everything the submission refreshes
|
||||
/// ([`Batch::refresh_front`]).
|
||||
front: bool,
|
||||
}
|
||||
|
||||
/// Whether the copies that a submission's shaders write are brought up to
|
||||
@@ -7193,6 +7317,73 @@ fn ahead_of_writes() -> bool {
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_REFRESH_AHEAD").is_none_or(|v| v != "0") && wide_refresh() && crate::watch::light())
|
||||
}
|
||||
|
||||
/// Whether everything a submission refreshes is brought up to date in one go,
|
||||
/// on several threads, ahead of its steps (`VICTORY_REFRESH_FRONT=1`, and with
|
||||
/// `VICTORY_JOIN_PARTS`, which needs it; else in groups where the steps ask
|
||||
/// for it). Measured on its own at nothing (run submit-1: refreshes 17.1 ms a
|
||||
/// frame without, 18.3 with).
|
||||
///
|
||||
/// A submission's refreshes were done in up to five groups one after the other
|
||||
/// (the copies its shaders write, those between its steps, what is left),
|
||||
/// each ending with the threads waiting for the last copy; and the submitting
|
||||
/// thread went over all the steps once for each question it has (what to ask
|
||||
/// about, what flights may write too, what shaders write). A refresh may come
|
||||
/// earlier than its step: the title's bytes are the same until a step writes
|
||||
/// title memory, and behind such a step everything is asked for again, as it
|
||||
/// was.
|
||||
fn refresh_front() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
ahead_of_writes() && (joins_asked().0 > 1 || *ON.get_or_init(|| crate::switch::on("VICTORY_REFRESH_FRONT")))
|
||||
}
|
||||
|
||||
/// Per copy what is refreshed in front of a submission's steps, as
|
||||
/// [`written_spans`]'s but of all copies, up to the copy's first write by
|
||||
/// shaders in each part of the submission (`Touch::Part`: another begins).
|
||||
/// What a part refreshes of a copy it has given to its shaders stays where it
|
||||
/// stands: around what they write. What a later part refreshes is the
|
||||
/// title's bytes of before either.
|
||||
fn front_spans(steps: impl Iterator<Item = Touch>) -> Vec<(usize, usize, usize)> {
|
||||
let mut at: ByCopy<usize> = ByCopy::default();
|
||||
// (Copy, from, to), in the order they come, and the part that gave it to
|
||||
// shaders last.
|
||||
let mut spans: Vec<(usize, usize, usize)> = Vec::new();
|
||||
let mut given: Vec<u32> = Vec::new();
|
||||
let (mut part, mut last) = (1, usize::MAX);
|
||||
for step in steps {
|
||||
match step {
|
||||
Touch::Refresh(copy, from, to) => {
|
||||
// (Most come several times on end.)
|
||||
let i = if spans.get(last).is_some_and(|s| s.0 == copy) {
|
||||
last
|
||||
} else {
|
||||
*at.entry(copy).or_insert_with(|| {
|
||||
spans.push((copy, usize::MAX, 0));
|
||||
given.push(0);
|
||||
spans.len() - 1
|
||||
})
|
||||
};
|
||||
last = i;
|
||||
if given[i] != part {
|
||||
let span = &mut spans[i];
|
||||
(span.1, span.2) = (span.1.min(from), span.2.max(to));
|
||||
}
|
||||
}
|
||||
Touch::Write(copy) => {
|
||||
let i = *at.entry(copy).or_insert_with(|| {
|
||||
spans.push((copy, usize::MAX, 0));
|
||||
given.push(0);
|
||||
spans.len() - 1
|
||||
});
|
||||
given[i] = part;
|
||||
}
|
||||
Touch::Part => part += 1,
|
||||
Touch::Title | Touch::Nothing => {}
|
||||
}
|
||||
}
|
||||
spans.retain(|s| s.1 < s.2);
|
||||
spans
|
||||
}
|
||||
|
||||
/// What a step is to the copies' refreshes, for [`written_spans`].
|
||||
enum Touch {
|
||||
/// A refresh of a copy (by address), from, to.
|
||||
@@ -7202,6 +7393,8 @@ enum Touch {
|
||||
/// Title memory is written.
|
||||
Title,
|
||||
Nothing,
|
||||
/// Another part of the submission begins.
|
||||
Part,
|
||||
}
|
||||
|
||||
/// Of `steps`, up to the first that writes title memory: the copies given to
|
||||
@@ -7224,7 +7417,7 @@ fn written_spans(steps: impl Iterator<Item = Touch>) -> Vec<(usize, usize, usize
|
||||
}
|
||||
}
|
||||
Touch::Title => break,
|
||||
Touch::Nothing => {}
|
||||
Touch::Nothing | Touch::Part => {}
|
||||
}
|
||||
}
|
||||
spans.into_iter().filter(|(_, s)| s.2).map(|(copy, (from, to, _))| (copy, from, to)).collect()
|
||||
@@ -7232,7 +7425,47 @@ fn written_spans(steps: impl Iterator<Item = Touch>) -> Vec<(usize, usize, usize
|
||||
|
||||
#[cfg(test)]
|
||||
mod written_spans_tests {
|
||||
use super::{Touch, written_spans};
|
||||
use super::{Touch, front_spans, split, written_spans};
|
||||
|
||||
#[test]
|
||||
fn everything_is_refreshed_in_front_but_what_a_part_gave_its_shaders() {
|
||||
use Touch::{Nothing, Part, Refresh, Title, Write};
|
||||
let found = front_spans(
|
||||
[
|
||||
Refresh(1, 10, 20),
|
||||
Refresh(1, 12, 25),
|
||||
Refresh(2, 0, 5),
|
||||
Nothing,
|
||||
Write(1),
|
||||
// (Around what the part's own shaders write.)
|
||||
Refresh(1, 0, 100),
|
||||
Write(3),
|
||||
Refresh(3, 1, 2),
|
||||
Title,
|
||||
Refresh(4, 7, 9),
|
||||
Part,
|
||||
// The next part's bytes under the first one's writes.
|
||||
Refresh(1, 30, 40),
|
||||
Write(4),
|
||||
Refresh(4, 0, 9),
|
||||
]
|
||||
.into_iter(),
|
||||
);
|
||||
assert_eq!(found, [(1, 10, 40), (2, 0, 5), (4, 7, 9)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_submission_is_cut_between_its_lists() {
|
||||
// Lists c and e are in neither half's order: they go with the first.
|
||||
let Ok([first, second]) = split(vec!['a', 'b', 'c', 'd', 'e'], vec![1, 3, 0], 1) else {
|
||||
panic!("no list is named twice");
|
||||
};
|
||||
let run = |(lists, order): &(Vec<char>, Vec<usize>)| order.iter().map(|&i| lists[i]).collect::<String>();
|
||||
assert_eq!((run(&first), run(&second)), ("b".into(), "da".into()));
|
||||
assert_eq!(first.0.len() + second.0.len(), 5);
|
||||
assert!(split(vec!['a', 'b'], vec![0, 1, 0], 2).is_err());
|
||||
assert!(split(vec!['a', 'b'], vec![0, 1], 0).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_is_written_is_refreshed_ahead_up_to_its_write_and_to_title_writes() {
|
||||
@@ -7313,8 +7546,11 @@ impl Batch {
|
||||
/// Before shaders are given a range of `shadow`'s copy: its pending
|
||||
/// refresh is done, the others stay pending.
|
||||
fn flush_one(&mut self, shadow: &std::sync::Arc<crate::shadow::Shadow>) {
|
||||
// From here on it is refreshed around what the shaders write.
|
||||
self.ahead.remove(&(std::sync::Arc::as_ptr(shadow) as usize));
|
||||
// From here on it is refreshed around what the shaders write. (What
|
||||
// is in front of all the steps was, up to here.)
|
||||
if !self.front {
|
||||
self.ahead.remove(&(std::sync::Arc::as_ptr(shadow) as usize));
|
||||
}
|
||||
let Some(at) = self.index.remove(&(std::sync::Arc::as_ptr(shadow) as usize)) else {
|
||||
return;
|
||||
};
|
||||
@@ -7363,6 +7599,99 @@ impl Batch {
|
||||
self.textures.clear();
|
||||
}
|
||||
|
||||
/// Before the steps of `runs` ([`refresh_front`]), a new part of the
|
||||
/// submission beginning at each of `parts`.
|
||||
fn refresh_front(&mut self, runs: &[&HostList], parts: &[usize]) {
|
||||
let mut copies: ByCopy<std::sync::Arc<crate::shadow::Shadow>> = ByCopy::default();
|
||||
let mut due = Vec::new();
|
||||
let mut touches = Vec::new();
|
||||
for (n, list) in runs.iter().enumerate() {
|
||||
if parts.contains(&n) {
|
||||
touches.push(Touch::Part);
|
||||
}
|
||||
let mut last = 0;
|
||||
for step in &list.deferred().copies {
|
||||
match step {
|
||||
Step::Refresh(shadow, at, len) => {
|
||||
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||
if key != last {
|
||||
copies.entry(key).or_insert_with(|| shadow.clone());
|
||||
last = key;
|
||||
}
|
||||
touches.push(Touch::Refresh(key, *at, *at + *len));
|
||||
}
|
||||
Step::GpuWrite(shadow, ..) => touches.push(Touch::Write(std::sync::Arc::as_ptr(shadow) as usize)),
|
||||
Step::Texture(staging) if wide_textures() => {
|
||||
if self.texture_due(staging) {
|
||||
due.push(staging.clone());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
let spans: Vec<_> = front_spans(touches.into_iter())
|
||||
.into_iter()
|
||||
.filter_map(|(key, from, to)| Some((copies.remove(&key)?, from, to)))
|
||||
.collect();
|
||||
self.front = true;
|
||||
for (shadow, from, to) in &spans {
|
||||
self.ahead.insert(std::sync::Arc::as_ptr(shadow) as usize, (*from, *to));
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
{
|
||||
FLUSHES[0].fetch_add(1, Ordering::Relaxed);
|
||||
FLUSHES[1].fetch_add(spans.len() as u64, Ordering::Relaxed);
|
||||
}
|
||||
let _flush = crate::timeline::span("refreshes of copies");
|
||||
let started = std::time::Instant::now();
|
||||
let before = [0, 2].map(|i| PREPARING[i].load(Ordering::Relaxed));
|
||||
// Those known to copy nothing are said so here, unless they are very
|
||||
// many: then beside the others.
|
||||
const FEW: usize = 256;
|
||||
let mut spans = spans;
|
||||
let many = spans.len() > FEW;
|
||||
if !many {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let all = spans.len();
|
||||
spans.retain(|(shadow, from, to)| !shadow.nothing_new(*from, *to - *from));
|
||||
#[cfg(feature = "diagnostics")]
|
||||
FLUSHES[2].fetch_add((all - spans.len()) as u64, Ordering::Relaxed);
|
||||
}
|
||||
let ahead = spans.len() > 1;
|
||||
if ahead {
|
||||
let ranges: Vec<(usize, usize)> = spans.iter().filter(|r| r.0.asked_ahead()).map(|r| (r.1, r.2)).collect();
|
||||
crate::watch::ask_ahead(&ranges);
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
FLUSHES[3].fetch_add(spans.len() as u64, Ordering::Relaxed);
|
||||
crate::shadow::wide_each(spans.len() + due.len(), move |i| {
|
||||
// The textures first: they are the longer pieces.
|
||||
let Some(i) = i.checked_sub(due.len()) else {
|
||||
due[i].refresh();
|
||||
return;
|
||||
};
|
||||
let (shadow, from, to) = &spans[i];
|
||||
if many && shadow.nothing_new(*from, *to - *from) {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
FLUSHES[2].fetch_add(1, Ordering::Relaxed);
|
||||
return;
|
||||
}
|
||||
Self::update(shadow, *from, *to);
|
||||
});
|
||||
if ahead {
|
||||
crate::watch::ask_ahead_done();
|
||||
}
|
||||
// The time counted is the time it took, not the threads' sum.
|
||||
let took = started.elapsed().as_micros() as u64;
|
||||
let summed = [0, 2].map(|i| PREPARING[i].load(Ordering::Relaxed)).iter().zip(before).map(|(now, was)| now.saturating_sub(was)).collect::<Vec<_>>();
|
||||
PREPARING[2].fetch_sub(summed[1], Ordering::Relaxed);
|
||||
PREPARING[0].fetch_sub(summed[0], Ordering::Relaxed);
|
||||
PREPARING[0].fetch_add(took, Ordering::Relaxed);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
SPLIT[6].fetch_add(started.elapsed().as_nanos() as u64, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Before the steps of `runs` ([`ahead_of_writes`]); copies and fills
|
||||
/// that `taken` names are not done on the CPU.
|
||||
fn refresh_ahead(&mut self, runs: &[&HostList], taken: impl Fn(&HostList, usize) -> bool) {
|
||||
@@ -7960,6 +8289,8 @@ struct Presenter {
|
||||
ahead: Vec<(HostList, u64)>,
|
||||
hwnd: HWND,
|
||||
meter: Meter,
|
||||
#[cfg(feature = "diagnostics")]
|
||||
panel: panel::Panel,
|
||||
}
|
||||
|
||||
/// The frame rate, shown in the window's caption every second and logged
|
||||
@@ -7989,6 +8320,12 @@ impl Meter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the next frame counted makes the frame-rate line.
|
||||
#[cfg(feature = "diagnostics")]
|
||||
fn line_due(&self) -> bool {
|
||||
self.since.elapsed() >= std::time::Duration::from_secs(1)
|
||||
}
|
||||
|
||||
/// Counts a presented frame.
|
||||
fn frame(&mut self, hwnd: HWND) {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
@@ -8222,6 +8559,7 @@ impl Meter {
|
||||
put[2] / 1e6,
|
||||
put[3]
|
||||
);
|
||||
traffic::line(self.copy_stats_frames as f64);
|
||||
crate::copystat::log(std::mem::take(&mut self.copy_stats_frames) as f64);
|
||||
for (why, n) in drops.iter().take(40) {
|
||||
tracing::info!(
|
||||
@@ -8363,6 +8701,8 @@ impl Host {
|
||||
.flatten();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let probe = if slot.is_some() { None } else { crate::capture::probe(&self.device, list, texture) };
|
||||
#[cfg(feature = "diagnostics")]
|
||||
p.panel.draw(self, copy, &back, (width, height), format);
|
||||
#[cfg(not(feature = "diagnostics"))]
|
||||
let _ = frame;
|
||||
list.ResourceBarrier(&[
|
||||
@@ -8390,6 +8730,8 @@ impl Host {
|
||||
let mut showing = crate::timeline::span("the host's Present");
|
||||
let _ = p.swap_chain.Present(0, DXGI_PRESENT(0));
|
||||
showing.next("the frame meter");
|
||||
#[cfg(feature = "diagnostics")]
|
||||
p.panel.frame(p.meter.line_due());
|
||||
p.meter.frame(p.hwnd);
|
||||
showing.end();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
@@ -8442,6 +8784,8 @@ impl Host {
|
||||
ahead: Vec::new(),
|
||||
hwnd,
|
||||
meter: Meter::new(),
|
||||
#[cfg(feature = "diagnostics")]
|
||||
panel: panel::Panel::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,22 @@ pub(super) fn stage() -> u32 {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a copy at its place in a list ([`place`]) is only in the way of
|
||||
/// what is done on the card in front of the lists if that stands behind it in
|
||||
/// them (`VICTORY_PLACED_ORDER=0`: wherever it stands, as before), and a
|
||||
/// submission where it does is cut behind the copy's list ([`cut_for`]).
|
||||
///
|
||||
/// The fills of constant buffers read the title's ring (7,500 a frame in the
|
||||
/// opening), and one copy of a few hundred bytes a frame writes into it at its
|
||||
/// place in a list. The whole submission was refused for it, and stood 40 to
|
||||
/// 60 ms until the flights had landed (run n19).
|
||||
fn placed_order() -> bool {
|
||||
crate::toggled!("VICTORY_PLACED_ORDER")
|
||||
}
|
||||
|
||||
/// Why [`plan`] refuses for [`place`].
|
||||
const BEHIND_PLACED: &str = "a copy at its place in a list writes what it reads, or reads or writes what it writes";
|
||||
|
||||
/// The bytes of our buffer between reading and writing: what one submission
|
||||
/// may do this way (each place read once, however many fills take it).
|
||||
const BETWEEN: u64 = 4 << 20;
|
||||
@@ -226,10 +242,13 @@ fn touched(ranges: &[(usize, usize)], r: (usize, usize)) -> bool {
|
||||
/// only what a taken copy has not been told to write yet: bytes a step
|
||||
/// ahead of it reads, in title memory as it is.
|
||||
///
|
||||
/// `behind`: for [`BEHIND_PLACED`], the copy at its place and the first step
|
||||
/// behind it that is in its way.
|
||||
///
|
||||
/// Steps of a level are done together, every read before every write; a
|
||||
/// step that writes what an earlier one reads or writes, or reads what it
|
||||
/// writes, is of a higher level. Our list does them level by level.
|
||||
fn plan(does: &[Does], stage: u32) -> Result<Vec<(usize, u32)>, &'static str> {
|
||||
fn plan(does: &[Does], stage: u32, by_order: bool, behind: &mut Option<(usize, usize)>) -> Result<Vec<(usize, u32)>, &'static str> {
|
||||
let takes = |d: &Does| match *d {
|
||||
Does::Copy { .. } if stage < 2 => Err("a buffer copy (VICTORY_CARD_STEPS=2 does it on the card)"),
|
||||
Does::Fill { to: false, .. } => Err("a fill of memory the card cannot be given the bytes of"),
|
||||
@@ -281,12 +300,21 @@ fn plan(does: &[Does], stage: u32) -> Result<Vec<(usize, u32)>, &'static str> {
|
||||
}
|
||||
}
|
||||
// A copy at its place in a list comes after what is done in front of all
|
||||
// of them.
|
||||
for d in does {
|
||||
// of them: as it should after the steps ahead of it, but not after those
|
||||
// behind it that read or write its bytes.
|
||||
for (p, d) in does.iter().enumerate() {
|
||||
if let Does::Placed { dst, src, len } = *d
|
||||
&& (touched(&read, (dst, dst + len)) || touched(&written, (dst, dst + len)) || touched(&written, (src, src + len)))
|
||||
{
|
||||
return Err("a copy at its place in a list writes what it reads, or reads or writes what it writes");
|
||||
let (to, from) = ((dst, dst + len), (src, src + len));
|
||||
let in_the_way = |i: usize| {
|
||||
reads_writes(&does[i]).is_some_and(|(r, w)| meet(r, to) || w.0 < w.1 && (meet(w, to) || meet(w, from)))
|
||||
};
|
||||
let found = (p + 1..does.len()).find(|&i| taken[i] && in_the_way(i));
|
||||
*behind = found.map(|i| (p, i));
|
||||
if !by_order || found.is_some() {
|
||||
return Err(BEHIND_PLACED);
|
||||
}
|
||||
}
|
||||
}
|
||||
let order: Vec<usize> = (0..does.len()).filter(|&i| taken[i]).collect();
|
||||
@@ -375,6 +403,78 @@ fn holder(writers: &[Writer], from: usize, to: usize) -> Result<Arc<Shadow>, &'s
|
||||
Ok(shadow)
|
||||
}
|
||||
|
||||
/// What the steps of `runs` do, and which step each is (its list by address,
|
||||
/// its place in it). `written`: what flights may write.
|
||||
fn does_of(written: &[(usize, usize)], runs: &[&HostList]) -> (Vec<Does>, Vec<(usize, usize)>) {
|
||||
let mut does = Vec::new();
|
||||
// Which step each is. One list's lock at a time: a submission may
|
||||
// name a list twice.
|
||||
let mut steps = Vec::new();
|
||||
for list in runs {
|
||||
for (i, step) in list.deferred().copies.iter().enumerate() {
|
||||
does.push(match step {
|
||||
&Step::Copy(dst, src, len) => Does::Copy {
|
||||
dst,
|
||||
src,
|
||||
len,
|
||||
asked: copy_blocked(written, dst, src, len).is_some(),
|
||||
},
|
||||
Step::Fill(_, src, len, to) => Does::Fill {
|
||||
src: *src,
|
||||
len: *len,
|
||||
asked: read_blocked(written, *src, *len),
|
||||
to: to.is_some(),
|
||||
},
|
||||
Step::Texture(staging) => {
|
||||
let (at, len) = staging.memory();
|
||||
Does::Read {
|
||||
from: at,
|
||||
to: at + len,
|
||||
asked: touches(written, at, at + len),
|
||||
}
|
||||
}
|
||||
&Step::Host(_, (from, to)) if from < to => Does::Read { from, to, asked: false },
|
||||
Step::Refresh(shadow, at, len) => Does::Refresh {
|
||||
shadow: Arc::as_ptr(shadow) as usize,
|
||||
from: *at,
|
||||
to: *at + *len,
|
||||
},
|
||||
Step::Run(_) => Does::Run,
|
||||
Step::Placed(p) => Does::Placed { dst: p.dst, src: p.src, len: p.len },
|
||||
Step::GpuWrite(..) | Step::Host(..) => continue,
|
||||
});
|
||||
steps.push((std::ptr::from_ref::<HostList>(list) as usize, i));
|
||||
}
|
||||
}
|
||||
(does, steps)
|
||||
}
|
||||
|
||||
/// With flights in the air: before which of `runs` the submission is cut so
|
||||
/// that what reads or writes the bytes of a copy at its place in an earlier
|
||||
/// list ([`BEHIND_PLACED`]) is done on the card in front of a submission of
|
||||
/// its own, behind that copy.
|
||||
pub(super) fn cut_for(runs: &[&HostList]) -> Option<usize> {
|
||||
if stage() == 0 || !relay_exact() || !placed_order() || runs.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
// (Most submissions have none.)
|
||||
let first = runs.iter().position(|l| l.deferred().copies.iter().any(|s| matches!(s, Step::Placed(_))))?;
|
||||
if first + 1 == runs.len() {
|
||||
return None;
|
||||
}
|
||||
let written = line().written.clone();
|
||||
blocked_by(&written, runs, false)?;
|
||||
let (does, steps) = does_of(&written, runs);
|
||||
let mut behind = None;
|
||||
if plan(&does, stage(), true, &mut behind) != Err(BEHIND_PLACED) {
|
||||
return None;
|
||||
}
|
||||
let (placed, reader) = behind?;
|
||||
let place = |i: usize| runs.iter().position(|l| std::ptr::from_ref::<HostList>(l) as usize == steps[i].0);
|
||||
let cut = place(placed)? + 1;
|
||||
(place(reader)? >= cut).then_some(cut)
|
||||
}
|
||||
|
||||
/// Whether every page of `[from, to)` can be read (through the kernel:
|
||||
/// asking Windows walks the page tables, milliseconds in the title's heap).
|
||||
/// `room`: for what is read.
|
||||
@@ -567,47 +667,8 @@ impl Host {
|
||||
}
|
||||
|
||||
fn take_steps(&self, written: &[(usize, usize)], runs: &[&HostList]) -> Result<Option<Taken>, &'static str> {
|
||||
let mut does = Vec::new();
|
||||
// Which step each is. One list's lock at a time: a submission may
|
||||
// name a list twice.
|
||||
let mut steps = Vec::new();
|
||||
for list in runs {
|
||||
for (i, step) in list.deferred().copies.iter().enumerate() {
|
||||
does.push(match step {
|
||||
&Step::Copy(dst, src, len) => Does::Copy {
|
||||
dst,
|
||||
src,
|
||||
len,
|
||||
asked: copy_blocked(written, dst, src, len).is_some(),
|
||||
},
|
||||
Step::Fill(_, src, len, to) => Does::Fill {
|
||||
src: *src,
|
||||
len: *len,
|
||||
asked: read_blocked(written, *src, *len),
|
||||
to: to.is_some(),
|
||||
},
|
||||
Step::Texture(staging) => {
|
||||
let (at, len) = staging.memory();
|
||||
Does::Read {
|
||||
from: at,
|
||||
to: at + len,
|
||||
asked: touches(written, at, at + len),
|
||||
}
|
||||
}
|
||||
&Step::Host(_, (from, to)) if from < to => Does::Read { from, to, asked: false },
|
||||
Step::Refresh(shadow, at, len) => Does::Refresh {
|
||||
shadow: Arc::as_ptr(shadow) as usize,
|
||||
from: *at,
|
||||
to: *at + *len,
|
||||
},
|
||||
Step::Run(_) => Does::Run,
|
||||
Step::Placed(p) => Does::Placed { dst: p.dst, src: p.src, len: p.len },
|
||||
Step::GpuWrite(..) | Step::Host(..) => continue,
|
||||
});
|
||||
steps.push((std::ptr::from_ref::<HostList>(list) as usize, i));
|
||||
}
|
||||
}
|
||||
let chosen = plan(&does, stage())?;
|
||||
let (does, steps) = does_of(written, runs);
|
||||
let chosen = plan(&does, stage(), placed_order(), &mut None)?;
|
||||
if chosen.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -863,7 +924,7 @@ mod tests {
|
||||
|
||||
/// What is done on the card, as (place, level), in stage 2.
|
||||
fn planned(does: &[Does]) -> Vec<(usize, u32)> {
|
||||
plan(does, 2).unwrap()
|
||||
plan(does, 2, true, &mut None).unwrap()
|
||||
}
|
||||
|
||||
/// Only what is asked for is taken, all of it, and a step that stands
|
||||
@@ -881,8 +942,8 @@ mod tests {
|
||||
];
|
||||
assert_eq!(planned(&does), [(1, 0), (3, 0)]);
|
||||
// Two fills of the same bytes.
|
||||
assert_eq!(plan(&[fill(0, 64, true), fill(32, 64, true)], 1), Ok(vec![(0, 0), (1, 0)]));
|
||||
assert_eq!(plan(&[fill(0, 64, false)], 1), Ok(vec![]));
|
||||
assert_eq!(plan(&[fill(0, 64, true), fill(32, 64, true)], 1, true, &mut None), Ok(vec![(0, 0), (1, 0)]));
|
||||
assert_eq!(plan(&[fill(0, 64, false)], 1, true, &mut None), Ok(vec![]));
|
||||
// Ends that touch are apart.
|
||||
let does = [
|
||||
copy(1000, 5000, 100, true),
|
||||
@@ -927,6 +988,29 @@ mod tests {
|
||||
assert_eq!(planned(&[copy(7000, 5000, 10, false), taken]), [(1, 0)]);
|
||||
}
|
||||
|
||||
/// A copy at its place in a list is in the way of what reads or writes its
|
||||
/// bytes behind it, not of what did ahead of it.
|
||||
#[test]
|
||||
fn copies_at_their_place_stand_in_the_way_of_what_is_behind_them() {
|
||||
let placed = Does::Placed { dst: 2000, src: 3000, len: 64 };
|
||||
let behind = |does: &[Does]| {
|
||||
let mut found = None;
|
||||
let refused = plan(does, 2, true, &mut found);
|
||||
assert!(refused.is_ok() || found.is_some() && refused == Err(BEHIND_PLACED));
|
||||
assert_eq!(plan(does, 2, false, &mut None).is_err(), does.len() > 1 && !matches!(does, [_, Does::Fill { src: 5000, .. }]));
|
||||
found
|
||||
};
|
||||
assert_eq!(behind(&[fill(2032, 64, true), placed]), None);
|
||||
assert_eq!(behind(&[placed, fill(2032, 64, true)]), Some((0, 1)));
|
||||
assert_eq!(behind(&[placed, fill(5000, 64, true)]), None);
|
||||
assert_eq!(behind(&[fill(2000, 8, true), placed, fill(2000, 8, true)]), Some((1, 2)));
|
||||
// One that writes what it copies from, and one that writes over it.
|
||||
assert_eq!(behind(&[copy(3000, 5000, 8, true), placed]), None);
|
||||
assert_eq!(behind(&[placed, copy(3000, 5000, 8, true)]), Some((0, 1)));
|
||||
assert_eq!(behind(&[copy(2060, 5000, 8, true), placed]), None);
|
||||
assert_eq!(behind(&[placed, copy(2060, 5000, 8, true)]), Some((0, 1)));
|
||||
}
|
||||
|
||||
/// Whatever the steps, done level by level (in a level every read
|
||||
/// before every write) they read and leave what they read and leave one
|
||||
/// after the other, the CPU's steps ahead of all of them.
|
||||
@@ -951,7 +1035,7 @@ mod tests {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let Ok(chosen) = plan(&does, 2) else {
|
||||
let Ok(chosen) = plan(&does, 2, true, &mut None) else {
|
||||
refused += 1;
|
||||
continue;
|
||||
};
|
||||
@@ -1005,22 +1089,22 @@ mod tests {
|
||||
#[test]
|
||||
fn steps_in_the_way_are_refused() {
|
||||
let taken = copy(1000, 5000, 100, true);
|
||||
assert!(plan(&[taken, Does::Run], 2).is_err());
|
||||
assert!(plan(&[taken, Does::Run], 2, true, &mut None).is_err());
|
||||
// A texture that itself waits for flights; a fill that cannot be
|
||||
// taken but waits.
|
||||
assert!(plan(&[taken, Does::Read { from: 1, to: 2, asked: true }], 2).is_err());
|
||||
assert!(plan(&[Does::Fill { src: 1, len: 1, asked: true, to: false }], 2).is_err());
|
||||
assert!(plan(&[taken, Does::Read { from: 1, to: 2, asked: true }], 2, true, &mut None).is_err());
|
||||
assert!(plan(&[Does::Fill { src: 1, len: 1, asked: true, to: false }], 2, true, &mut None).is_err());
|
||||
// Reads on the CPU of what it writes: behind it, not ahead of it.
|
||||
for read in [Does::Read { from: 900, to: 1001, asked: false }, stuck(1050, 3)] {
|
||||
assert!(plan(&[taken, read], 2).is_err(), "{read:?} behind");
|
||||
assert!(plan(&[taken, read], 2, true, &mut None).is_err(), "{read:?} behind");
|
||||
assert_eq!(planned(&[read, taken]), [(1, 0)], "{read:?} ahead");
|
||||
}
|
||||
// Also of what is taken along.
|
||||
assert!(plan(&[taken, copy(3000, 1000, 10, false), stuck(3005, 1)], 2).is_err());
|
||||
assert!(plan(&[taken, copy(3000, 1000, 10, false), stuck(3005, 1)], 2, true, &mut None).is_err());
|
||||
// Into itself, and copies without stage 2.
|
||||
assert!(plan(&[copy(1000, 1050, 100, true)], 2).is_err());
|
||||
assert!(plan(&[taken], 1).is_err());
|
||||
assert!(plan(&[fill(1000, 4, true), copy(1000, 5000, 100, false)], 1).is_err());
|
||||
assert!(plan(&[copy(1000, 1050, 100, true)], 2, true, &mut None).is_err());
|
||||
assert!(plan(&[taken], 1, true, &mut None).is_err());
|
||||
assert!(plan(&[fill(1000, 4, true), copy(1000, 5000, 100, false)], 1, true, &mut None).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
//! Diagnostics: the run's numbers on the picture (`VICTORY_PANEL=1`; off by
|
||||
//! default; F3 shows and hides it while our window has the focus): white
|
||||
//! text on a black box in the upper left corner of what is shown, so that a
|
||||
//! screenshot carries them, with what it costs itself on the submitting
|
||||
//! thread. Made again twice a second from the counters of
|
||||
//! the frame-rate line, memory and textures; a frame itself only copies the
|
||||
//! box out of a buffer in the card's memory. Copied onto the swap chain's
|
||||
//! buffer, behind the title's picture: saved frames and the frame recorder
|
||||
//! see the title's own.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use windows::Win32::Graphics::Direct3D12::*;
|
||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_F3};
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId};
|
||||
|
||||
use super::{Host, HostList, transition};
|
||||
|
||||
/// How often the numbers change.
|
||||
const EVERY: Duration = Duration::from_millis(500);
|
||||
|
||||
/// A character's dots, and with the space beside and below it.
|
||||
const GLYPH: (u32, u32) = (5, 7);
|
||||
const CELL: (u32, u32) = (6, 9);
|
||||
/// Characters in a line, lines, and the box's rim in dots.
|
||||
const COLUMNS: u32 = 40;
|
||||
const LINES: u32 = 9;
|
||||
const RIM: u32 = 3;
|
||||
|
||||
/// The texts are put into one of these in turn: the card reads the others,
|
||||
/// at most half a second old.
|
||||
const UPLOADS: usize = 4;
|
||||
|
||||
fn asked() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| crate::switch::on("VICTORY_PANEL"))
|
||||
}
|
||||
|
||||
/// Whether it is shown now.
|
||||
fn shown() -> &'static AtomicBool {
|
||||
static SHOWN: OnceLock<AtomicBool> = OnceLock::new();
|
||||
SHOWN.get_or_init(|| AtomicBool::new(asked()))
|
||||
}
|
||||
|
||||
/// F3 was pressed since the last call, with one of our windows in front.
|
||||
fn pressed() -> bool {
|
||||
static DOWN: AtomicBool = AtomicBool::new(false);
|
||||
// SAFETY: a plain query.
|
||||
let down = unsafe { GetAsyncKeyState(i32::from(VK_F3)) } < 0;
|
||||
if DOWN.swap(down, Ordering::Relaxed) || !down {
|
||||
return false;
|
||||
}
|
||||
let mut process = 0;
|
||||
// SAFETY: plain queries; room for the answer.
|
||||
unsafe { GetWindowThreadProcessId(GetForegroundWindow(), &mut process) };
|
||||
process == std::process::id()
|
||||
}
|
||||
|
||||
/// Seven rows of five dots, the leftmost the highest bit.
|
||||
#[rustfmt::skip]
|
||||
const fn glyph(c: u8) -> [u8; 7] {
|
||||
match c {
|
||||
b'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110],
|
||||
b'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||
b'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111],
|
||||
b'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110],
|
||||
b'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010],
|
||||
b'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110],
|
||||
b'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110],
|
||||
b'7' => [0b11111, 0b00001, 0b00010, 0b00010, 0b00100, 0b00100, 0b00100],
|
||||
b'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110],
|
||||
b'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100],
|
||||
b'A' => [0b00100, 0b01010, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001],
|
||||
b'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110],
|
||||
b'C' => [0b01111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b01111],
|
||||
b'D' => [0b11110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11110],
|
||||
b'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111],
|
||||
b'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000],
|
||||
b'G' => [0b01111, 0b10000, 0b10000, 0b10011, 0b10001, 0b10001, 0b01111],
|
||||
b'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
||||
b'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||
b'J' => [0b00111, 0b00010, 0b00010, 0b00010, 0b00010, 0b10010, 0b01100],
|
||||
b'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
|
||||
b'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
|
||||
b'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
|
||||
b'N' => [0b10001, 0b11001, 0b11001, 0b10101, 0b10011, 0b10011, 0b10001],
|
||||
b'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||
b'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000],
|
||||
b'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101],
|
||||
b'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001],
|
||||
b'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110],
|
||||
b'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||
b'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||
b'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
|
||||
b'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
|
||||
b'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001],
|
||||
b'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||
b'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111],
|
||||
b'.' => [0, 0, 0, 0, 0, 0b01100, 0b01100],
|
||||
b'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
|
||||
b'-' => [0, 0, 0, 0b11111, 0, 0, 0],
|
||||
b' ' => [0; 7],
|
||||
_ => [0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111],
|
||||
}
|
||||
}
|
||||
|
||||
/// The box's size in pixels, a dot being `scale` of them each way.
|
||||
const fn size(scale: u32) -> (u32, u32) {
|
||||
((COLUMNS * CELL.0 + 2 * RIM) * scale, (LINES * CELL.1 + 2 * RIM) * scale)
|
||||
}
|
||||
|
||||
/// Pixels to a dot for a picture that high: a 720-line screenshot of it
|
||||
/// shows one and a third.
|
||||
fn scale(height: u32) -> u32 {
|
||||
(height / 540).max(1)
|
||||
}
|
||||
|
||||
/// Whether a dot of the picture of `lines` is white.
|
||||
fn lit(lines: &[String], x: u32, y: u32) -> bool {
|
||||
let (Some(x), Some(y)) = (x.checked_sub(RIM), y.checked_sub(RIM)) else {
|
||||
return false;
|
||||
};
|
||||
if x % CELL.0 >= GLYPH.0 || y % CELL.1 >= GLYPH.1 || x / CELL.0 >= COLUMNS {
|
||||
return false;
|
||||
}
|
||||
let Some(&c) = lines.get((y / CELL.1) as usize).and_then(|l| l.as_bytes().get((x / CELL.0) as usize)) else {
|
||||
return false;
|
||||
};
|
||||
(glyph(c.to_ascii_uppercase())[(y % CELL.1) as usize] >> (GLYPH.0 - 1 - x % CELL.0)) & 1 != 0
|
||||
}
|
||||
|
||||
/// The bytes of a black and a white pixel of a swap chain's format.
|
||||
fn colours(format: DXGI_FORMAT) -> Option<[&'static [u8]; 2]> {
|
||||
Some(match format {
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM => [&[0, 0, 0, 0xFF], &[0xFF; 4]],
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM => [&[0, 0, 0, 0xC0], &[0xFF; 4]],
|
||||
// Halves of 0 and 1.
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT => [
|
||||
&[0, 0, 0, 0, 0, 0, 0, 0x3C],
|
||||
&[0, 0x3C, 0, 0x3C, 0, 0x3C, 0, 0x3C],
|
||||
],
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The box as rows of `pitch` bytes.
|
||||
fn painted(lines: &[String], scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec<u8> {
|
||||
let (width, height) = size(scale);
|
||||
let bytes = colours[0].len();
|
||||
let mut out = vec![0; pitch * height as usize];
|
||||
for y in 0..height / scale {
|
||||
let top = pitch * (y * scale) as usize;
|
||||
for x in 0..width / scale {
|
||||
let colour = colours[usize::from(lit(lines, x, y))];
|
||||
for i in 0..scale {
|
||||
let at = top + (x * scale + i) as usize * bytes;
|
||||
out[at..at + bytes].copy_from_slice(colour);
|
||||
}
|
||||
}
|
||||
for i in 1..scale as usize {
|
||||
out.copy_within(top..top + pitch, top + i * pitch);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The counters read for it. They grow, and go back to 0 with the frame-rate
|
||||
/// line (right behind a look of ours).
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct Counters([u64; COUNTERS]);
|
||||
|
||||
const COUNTERS: usize = 11;
|
||||
|
||||
impl Counters {
|
||||
fn now() -> Counters {
|
||||
use super::{CARD_CLOCK_US, COPY_BACK, PREPARING};
|
||||
use crate::copystat::{C, peek};
|
||||
let get = |a: &std::sync::atomic::AtomicU64| a.load(Ordering::Relaxed);
|
||||
Counters([
|
||||
super::worked(),
|
||||
get(&CARD_CLOCK_US[0]),
|
||||
get(&CARD_CLOCK_US[1]),
|
||||
get(&CARD_CLOCK_US[2]),
|
||||
get(&PREPARING[3]),
|
||||
get(©_BACK[0]),
|
||||
get(©_BACK[1]),
|
||||
get(&crate::shadow::CARD_STATS[0]),
|
||||
crate::draw::dropped_now(),
|
||||
peek(C::RecordNs),
|
||||
crate::draw::drawn(),
|
||||
])
|
||||
}
|
||||
|
||||
/// What came since `before`, per frame.
|
||||
fn since(self, before: Counters, frames: f64) -> [f64; COUNTERS] {
|
||||
let mut out = [0.0; COUNTERS];
|
||||
for (i, out) in out.iter_mut().enumerate() {
|
||||
let (was, is) = (before.0[i], self.0[i]);
|
||||
*out = if is >= was { is - was } else { is } as f64 / frames;
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// The text. `c`: [`Counters`] per frame, `ms` a frame's time, `worst` the
|
||||
/// longest frame's, `cost` what this takes of a frame, in microseconds.
|
||||
fn text(c: &[f64; COUNTERS], ms: f64, worst: f64, cost: f64, host: &Host) -> Vec<String> {
|
||||
let gb = |bytes: u64| bytes as f64 / (1u64 << 30) as f64;
|
||||
let (working, private) = crate::copystat::process_memory();
|
||||
let [budget, used, _, shared] = host.video_memory().unwrap_or_default();
|
||||
let idle = (c[1] / 1e3).min(ms);
|
||||
vec![
|
||||
format!("FPS {:.1} FRAME {ms:.1} MS LONGEST {worst:.0}", 1e3 / ms.max(0.001)),
|
||||
format!("DRAWS {:.0} DROPPED {:.0}", c[10], c[8]),
|
||||
format!("SUBMIT BUSY {:.1} WAITS FOR GPU {:.1}", c[0] / 1e3, c[3] / 1e3),
|
||||
format!("GPU BUSY {:.1} IDLE BEHIND US {:.1}", ms - idle, c[2] / 1e3),
|
||||
format!("RECORDING {:.0} MS COPY BACK {:.1}", c[9] / 1e6, c[5] / 1e3),
|
||||
format!("MB UP {:.0} TEXTURES {:.0} BACK {:.0}", c[7] / 1e6, c[4] / 1e6, c[6] / 1e6),
|
||||
format!("RAM {:.1} GB IN MEMORY {:.1}", gb(private), gb(working)),
|
||||
format!("VRAM {:.1}/{:.1} GB SHARED {:.1}", gb(used), gb(budget), gb(shared)),
|
||||
format!("THIS PANEL {:.0} US A FRAME", cost),
|
||||
]
|
||||
}
|
||||
|
||||
/// The buffers of a box that size and format.
|
||||
struct Buffers {
|
||||
format: DXGI_FORMAT,
|
||||
scale: u32,
|
||||
pitch: u32,
|
||||
uploads: Vec<(ID3D12Resource, *mut u8)>,
|
||||
card: ID3D12Resource,
|
||||
/// The upload written last.
|
||||
turn: usize,
|
||||
/// It is not in the card's buffer yet.
|
||||
fresh: bool,
|
||||
}
|
||||
|
||||
// SAFETY: free-threaded resources, and memory only written under the presenter's lock.
|
||||
unsafe impl Send for Buffers {}
|
||||
|
||||
impl Buffers {
|
||||
fn new(host: &Host, format: DXGI_FORMAT, scale: u32) -> Option<Buffers> {
|
||||
let (width, height) = size(scale);
|
||||
let pitch = (width * colours(format)?[0].len() as u32).next_multiple_of(256);
|
||||
let bytes = u64::from(pitch) * u64::from(height);
|
||||
let uploads = (0..UPLOADS).map(|_| host.upload_buffer(bytes)).collect::<Option<Vec<_>>>()?;
|
||||
let heap = D3D12_HEAP_PROPERTIES {
|
||||
Type: D3D12_HEAP_TYPE_DEFAULT,
|
||||
..Default::default()
|
||||
};
|
||||
let desc = D3D12_RESOURCE_DESC {
|
||||
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
|
||||
Width: bytes,
|
||||
Height: 1,
|
||||
DepthOrArraySize: 1,
|
||||
MipLevels: 1,
|
||||
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
|
||||
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
|
||||
..Default::default()
|
||||
};
|
||||
let mut card: Option<ID3D12Resource> = None;
|
||||
// SAFETY: plain creation of a buffer.
|
||||
unsafe {
|
||||
host.device
|
||||
.CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, None, &mut card)
|
||||
.ok()?;
|
||||
}
|
||||
Some(Buffers { format, scale, pitch, uploads, card: card?, turn: 0, fresh: false })
|
||||
}
|
||||
|
||||
fn write(&mut self, lines: &[String]) {
|
||||
let Some(colours) = colours(self.format) else { return };
|
||||
let picture = painted(lines, self.scale, colours, self.pitch as usize);
|
||||
self.turn = (self.turn + 1) % UPLOADS;
|
||||
// SAFETY: a mapped upload buffer of the picture's size, which the card read a second or more ago.
|
||||
unsafe { std::ptr::copy_nonoverlapping(picture.as_ptr(), self.uploads[self.turn].1, picture.len()) };
|
||||
self.fresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// The panel of a presenter.
|
||||
pub(super) struct Panel {
|
||||
since: Instant,
|
||||
frames: u32,
|
||||
last: Instant,
|
||||
worst: f64,
|
||||
/// What this took since the last text.
|
||||
cost: Duration,
|
||||
before: Counters,
|
||||
lines: Vec<String>,
|
||||
changed: bool,
|
||||
buffers: Option<Buffers>,
|
||||
failed: bool,
|
||||
}
|
||||
|
||||
impl Panel {
|
||||
pub(super) fn new() -> Panel {
|
||||
let now = Instant::now();
|
||||
Panel {
|
||||
since: now,
|
||||
frames: 0,
|
||||
last: now,
|
||||
worst: 0.0,
|
||||
cost: Duration::ZERO,
|
||||
before: Counters::default(),
|
||||
lines: Vec::new(),
|
||||
changed: false,
|
||||
buffers: None,
|
||||
failed: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// A frame was presented; `line`: the counters go back to 0 right behind
|
||||
/// this call. (Not shown it asks for the key's state and no more.)
|
||||
pub(super) fn frame(&mut self, line: bool) {
|
||||
if pressed() {
|
||||
shown().fetch_xor(true, Ordering::Relaxed);
|
||||
}
|
||||
if !shown().load(Ordering::Relaxed) {
|
||||
self.frames = 0;
|
||||
return;
|
||||
}
|
||||
let now = Instant::now();
|
||||
if self.frames == 0 && now - self.last > 2 * EVERY {
|
||||
// (Shown from here on.)
|
||||
(self.since, self.last, self.worst, self.before) = (now, now, 0.0, Counters::now());
|
||||
self.frames = 0;
|
||||
}
|
||||
self.frames += 1;
|
||||
self.worst = self.worst.max((now - self.last).as_secs_f64() * 1e3);
|
||||
self.last = now;
|
||||
let elapsed = now - self.since;
|
||||
if elapsed < EVERY && !(line && elapsed * 2 >= EVERY) {
|
||||
return;
|
||||
}
|
||||
let Some(host) = super::host() else { return };
|
||||
let frames = f64::from(self.frames);
|
||||
let counters = Counters::now();
|
||||
let c = counters.since(self.before, frames);
|
||||
self.before = counters;
|
||||
let cost = self.cost.as_secs_f64() * 1e6 / frames;
|
||||
self.lines = text(&c, elapsed.as_secs_f64() * 1e3 / frames, self.worst, cost, host);
|
||||
self.changed = true;
|
||||
(self.since, self.frames, self.worst) = (now, 0, 0.0);
|
||||
self.cost = now.elapsed();
|
||||
}
|
||||
|
||||
/// Records the copy of the box onto `back`, a buffer of the swap chain of
|
||||
/// that size and format in the state to be copied into.
|
||||
pub(super) fn draw(
|
||||
&mut self,
|
||||
host: &Host,
|
||||
list: &HostList,
|
||||
back: &ID3D12Resource,
|
||||
(width, height): (u32, u32),
|
||||
format: DXGI_FORMAT,
|
||||
) {
|
||||
if !shown().load(Ordering::Relaxed) || self.lines.is_empty() || self.failed {
|
||||
return;
|
||||
}
|
||||
let began = Instant::now();
|
||||
// Not the title's: the frame recorder leaves it out.
|
||||
let _ours = crate::replay::record::unrecorded();
|
||||
let scale = scale(height);
|
||||
if self.buffers.as_ref().is_none_or(|b| (b.format, b.scale) != (format, scale)) {
|
||||
// (What the card may still read stays: a picture's size changes once or twice in a run.)
|
||||
std::mem::forget(self.buffers.take());
|
||||
self.buffers = Buffers::new(host, format, scale);
|
||||
self.failed = self.buffers.is_none();
|
||||
self.changed = true;
|
||||
}
|
||||
let Some(buffers) = &mut self.buffers else { return };
|
||||
if std::mem::take(&mut self.changed) {
|
||||
buffers.write(&self.lines);
|
||||
}
|
||||
let (w, h) = size(scale);
|
||||
let list = &list.list;
|
||||
// SAFETY: an open list and live resources; the box lies within both.
|
||||
unsafe {
|
||||
if std::mem::take(&mut buffers.fresh) {
|
||||
list.CopyResource(&buffers.card, &buffers.uploads[buffers.turn].0);
|
||||
list.ResourceBarrier(&[transition(
|
||||
&buffers.card,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
D3D12_RESOURCE_STATE_COPY_SOURCE,
|
||||
)]);
|
||||
}
|
||||
let from = D3D12_TEXTURE_COPY_LOCATION {
|
||||
pResource: std::mem::transmute_copy(&buffers.card),
|
||||
Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
||||
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 {
|
||||
PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
|
||||
Offset: 0,
|
||||
Footprint: D3D12_SUBRESOURCE_FOOTPRINT {
|
||||
Format: format,
|
||||
Width: w,
|
||||
Height: h,
|
||||
Depth: 1,
|
||||
RowPitch: buffers.pitch,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
let to = D3D12_TEXTURE_COPY_LOCATION {
|
||||
pResource: std::mem::transmute_copy(back),
|
||||
Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
||||
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: 0 },
|
||||
};
|
||||
let part = D3D12_BOX {
|
||||
left: 0,
|
||||
top: 0,
|
||||
front: 0,
|
||||
right: w.min(width),
|
||||
bottom: h.min(height),
|
||||
back: 1,
|
||||
};
|
||||
list.CopyTextureRegion(&to, 0, 0, 0, &from, Some(&part));
|
||||
}
|
||||
self.cost += began.elapsed();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Every character the lines use has its own picture, and no two look
|
||||
/// alike.
|
||||
#[test]
|
||||
fn characters_differ() {
|
||||
let used: Vec<u8> = (b'0'..=b'9').chain(b'A'..=b'Z').chain(*b"./- ").collect();
|
||||
for (i, a) in used.iter().enumerate() {
|
||||
assert_ne!(glyph(*a), glyph(b'#'), "{} has a picture", *a as char);
|
||||
assert!(glyph(*a).iter().all(|row| row >> GLYPH.0 == 0));
|
||||
for b in &used[i + 1..] {
|
||||
assert_ne!(glyph(*a), glyph(*b), "{} {}", *a as char, *b as char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_box_is_painted() {
|
||||
let lines = vec!["I".to_owned(), " i".to_owned()];
|
||||
for scale in [1, 2, 4] {
|
||||
let (width, height) = size(scale);
|
||||
let pitch = (width * 4).next_multiple_of(256) as usize;
|
||||
let colours = colours(DXGI_FORMAT_R10G10B10A2_UNORM).unwrap();
|
||||
let picture = painted(&lines, scale, colours, pitch);
|
||||
assert_eq!(picture.len(), pitch * height as usize);
|
||||
let at = |x: u32, y: u32| &picture[y as usize * pitch + x as usize * 4..][..4];
|
||||
// The rim is black, the first letter's top row lit in its middle.
|
||||
assert_eq!(at(0, 0), colours[0]);
|
||||
assert_eq!(at((RIM + 2) * scale, RIM * scale), colours[1]);
|
||||
assert_eq!(at((RIM + 2) * scale + scale - 1, RIM * scale + scale - 1), colours[1]);
|
||||
assert_eq!(at(RIM * scale, RIM * scale), colours[0]);
|
||||
// Small letters are shown as capitals, a line and a cell on.
|
||||
assert_eq!(at((RIM + CELL.0 + 2) * scale, (RIM + CELL.1) * scale), colours[1]);
|
||||
// Nothing past a line's end.
|
||||
assert_eq!(at((RIM + CELL.0 * 2 + 2) * scale, (RIM + CELL.1) * scale), colours[0]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn counters_that_went_back_to_nothing_count_from_there() {
|
||||
let (mut a, mut b) = (Counters::default(), Counters::default());
|
||||
(a.0[0], b.0[0]) = (10, 30);
|
||||
(a.0[1], b.0[1]) = (50, 20);
|
||||
let c = b.since(a, 10.0);
|
||||
assert_eq!((c[0], c[1]), (2.0, 2.0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//! Diagnostics: which host copies' bytes cross the bus, and which way: per
|
||||
//! copy (title address, bytes) what was sent up and what shaders wrote that
|
||||
//! was fetched, a frame; and how many different 64 KiB pieces of it. Every
|
||||
//! five seconds, the eight that move most. For placing resources: a copy whose
|
||||
//! pieces are fetched every frame and never sent up is written by shaders
|
||||
//! alone, and nobody but shaders may read it.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// Of a copy, each way (up, fetched): bytes, and the pieces (64 KiB).
|
||||
#[derive(Default)]
|
||||
struct Moved {
|
||||
bytes: [u64; 2],
|
||||
pieces: [HashSet<u32>; 2],
|
||||
}
|
||||
|
||||
pub(super) const UP: usize = 0;
|
||||
pub(super) const FETCHED: usize = 1;
|
||||
|
||||
static MOVED: Mutex<Option<HashMap<(u64, u64), Moved>>> = Mutex::new(None);
|
||||
|
||||
/// Offsets `ranges` of the copy of `span` (title address, bytes) went `way`.
|
||||
pub(super) fn moved(way: usize, span: (u64, u64), ranges: impl Iterator<Item = (usize, usize)>) {
|
||||
let mut all = MOVED.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let m = all.get_or_insert_with(Default::default).entry(span).or_default();
|
||||
for (from, to) in ranges.filter(|r| r.0 < r.1) {
|
||||
m.bytes[way] += (to - from) as u64;
|
||||
m.pieces[way].extend((from >> 16) as u32..=((to - 1) >> 16) as u32);
|
||||
}
|
||||
}
|
||||
|
||||
/// For the log, over `frames` frames.
|
||||
pub(super) fn line(frames: f64) {
|
||||
let all = MOVED.lock().unwrap_or_else(|e| e.into_inner()).take().unwrap_or_default();
|
||||
let mut all: Vec<_> = all.into_iter().collect();
|
||||
all.sort_by_key(|(_, m)| std::cmp::Reverse(m.bytes[0] + m.bytes[1]));
|
||||
let mb = |b: u64| b as f64 / 1e6 / frames.max(1.0);
|
||||
let sum = |way: usize| all.iter().map(|(_, m)| m.bytes[way]).sum::<u64>();
|
||||
// Copies that only move one way.
|
||||
let only = |way: usize| all.iter().filter(|(_, m)| m.bytes[1 - way] == 0).map(|(_, m)| m.bytes[way]).sum::<u64>();
|
||||
tracing::info!(
|
||||
"bytes of host copies over the bus per frame: {:.1} MB up ({:.1} of copies nothing was fetched from), {:.1} MB fetched \
|
||||
({:.1} of copies nothing was sent up to), {} copies; the most:",
|
||||
mb(sum(UP)),
|
||||
mb(only(UP)),
|
||||
mb(sum(FETCHED)),
|
||||
mb(only(FETCHED)),
|
||||
all.len()
|
||||
);
|
||||
for ((start, len), m) in all.into_iter().take(8) {
|
||||
let both = m.pieces[0].intersection(&m.pieces[1]).count();
|
||||
tracing::info!(
|
||||
" {start:#x}+{len:#x}: {:.2} MB up in {} different pieces, {:.2} MB fetched in {}, {both} of them both ways",
|
||||
mb(m.bytes[0]),
|
||||
m.pieces[0].len(),
|
||||
mb(m.bytes[1]),
|
||||
m.pieces[1].len()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,14 @@ pub(super) trait Work: Send {
|
||||
}
|
||||
/// Waits until a folded one is free to go.
|
||||
fn settle(_: &Self::Ask) {}
|
||||
/// Takes `next`, what its queue was given behind it, along to be done with
|
||||
/// it; or gives it back. Whether it is a submission that was taken.
|
||||
fn take_along(&mut self, next: Self) -> Result<bool, Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Err(next)
|
||||
}
|
||||
/// Does it. `forced`: its wait was not met.
|
||||
fn go(self, forced: bool);
|
||||
}
|
||||
@@ -245,6 +253,17 @@ impl<W: Work> Lane<W> {
|
||||
while self.step(limit) {}
|
||||
}
|
||||
|
||||
/// The parts of `entry`, which stands for them, in place `at`.
|
||||
fn unfold(state: &mut State<W>, at: usize, entry: Entry<W>) {
|
||||
let (number, queue, runs) = (entry.number, entry.queue, usize::from(entry.what.runs()));
|
||||
let parts = entry.what.unfold();
|
||||
state.runs -= runs;
|
||||
state.runs += parts.iter().filter(|p| p.runs()).count();
|
||||
for (i, what) in parts.into_iter().enumerate() {
|
||||
state.items.insert(at + i, Entry { number, queue, what });
|
||||
}
|
||||
}
|
||||
|
||||
/// Does one entry: the oldest that is the first of its queue and free to
|
||||
/// run. Whether there was one. Only one thread calls this.
|
||||
fn step(&self, limit: u64) -> bool {
|
||||
@@ -286,7 +305,7 @@ impl<W: Work> Lane<W> {
|
||||
(first, true)
|
||||
}
|
||||
};
|
||||
let entry = {
|
||||
let mut entry = {
|
||||
let mut state = self.lock();
|
||||
let Some(at) = state.items.iter().position(|e| e.number == number) else {
|
||||
return false;
|
||||
@@ -297,31 +316,56 @@ impl<W: Work> Lane<W> {
|
||||
state.running = Some(entry.queue);
|
||||
entry
|
||||
};
|
||||
let (shows, runs) = (entry.what.shows(), entry.what.runs());
|
||||
let (shows, mut runs) = (entry.what.shows(), usize::from(entry.what.runs()));
|
||||
if entry.what.folded() {
|
||||
// Its parts take its place: behind everything before it, before
|
||||
// everything after it (they share its number; the first of them
|
||||
// is found first).
|
||||
let (number, queue) = (entry.number, entry.queue);
|
||||
let parts = entry.what.unfold();
|
||||
let mut state = self.lock();
|
||||
state.running = None;
|
||||
state.runs -= usize::from(runs);
|
||||
state.runs += parts.iter().filter(|p| p.runs()).count();
|
||||
let place = state.items.iter().position(|e| e.number > number).unwrap_or(state.items.len());
|
||||
for (i, what) in parts.into_iter().enumerate() {
|
||||
state.items.insert(place + i, Entry { number, queue, what });
|
||||
}
|
||||
let at = state.items.iter().position(|e| e.number > entry.number).unwrap_or(state.items.len());
|
||||
Self::unfold(&mut state, at, entry);
|
||||
drop(state);
|
||||
self.moved.notify_all();
|
||||
return true;
|
||||
}
|
||||
// What follows it in its queue, if that can go with it. (Nobody else
|
||||
// takes anything out, and what comes in goes to the end.)
|
||||
while runs > 0 && !forced {
|
||||
let next = {
|
||||
let mut state = self.lock();
|
||||
let at = state.items.iter().position(|e| e.queue == entry.queue && e.number < limit);
|
||||
at.and_then(|at| Some((at, state.items.remove(at)?)))
|
||||
};
|
||||
let Some((at, next)) = next else {
|
||||
break;
|
||||
};
|
||||
// (Back where it was: parts of one submission share a number.)
|
||||
if next.what.folded() {
|
||||
let free = next.what.ask().is_none_or(|ask| W::met(&ask));
|
||||
let mut state = self.lock();
|
||||
if free {
|
||||
Self::unfold(&mut state, at, next);
|
||||
continue;
|
||||
}
|
||||
state.items.insert(at, next);
|
||||
break;
|
||||
}
|
||||
let Entry { number, queue, what } = next;
|
||||
match entry.what.take_along(what) {
|
||||
Ok(run) => runs += usize::from(run),
|
||||
Err(what) => {
|
||||
self.lock().items.insert(at, Entry { number, queue, what });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
entry.what.go(forced);
|
||||
{
|
||||
let mut state = self.lock();
|
||||
state.running = None;
|
||||
state.presents -= usize::from(shows);
|
||||
state.runs -= usize::from(runs);
|
||||
state.runs -= runs;
|
||||
}
|
||||
self.moved.notify_all();
|
||||
true
|
||||
@@ -342,6 +386,9 @@ enum Job {
|
||||
/// A submission whose lists are being translated ([`crate::list::thin`]):
|
||||
/// the parts of it are known when they are.
|
||||
Lists(usize, Recordings),
|
||||
/// Parts taken along with a submission ([`crate::host::joins`]): where they
|
||||
/// begin in the order, and the signals given behind them.
|
||||
Joined(usize, Vec<crate::list::Detached>, Vec<usize>, Vec<usize>, Vec<(usize, u64)>),
|
||||
/// A signal of the queue's.
|
||||
Signal(usize, u64),
|
||||
/// A frame is shown: the texture and the state its lists leave it in.
|
||||
@@ -408,13 +455,73 @@ impl Work for Job {
|
||||
}
|
||||
|
||||
fn runs(&self) -> bool {
|
||||
matches!(self, Job::Run(..) | Job::Lists(..))
|
||||
matches!(self, Job::Run(..) | Job::Joined(..) | Job::Lists(..))
|
||||
}
|
||||
|
||||
fn take_along(&mut self, next: Job) -> Result<bool, Job> {
|
||||
let (most, most_lists) = crate::host::joins();
|
||||
if most < 2 {
|
||||
return Err(next);
|
||||
}
|
||||
// Nothing but waits and signals that a submission may follow.
|
||||
let (count, lists, signals) = match self {
|
||||
Job::Run(_, lists, order) => (1, (&*lists, &*order), &[][..]),
|
||||
Job::Joined(_, lists, order, parts, signals) => (1 + parts.len(), (&*lists, &*order), &signals[..]),
|
||||
_ => return Err(next),
|
||||
};
|
||||
let hosts = || lists.1.iter().map(|&i| lists.0[i].host());
|
||||
match &next {
|
||||
Job::Value(wait) => {
|
||||
let met = wait.met()
|
||||
|| crate::host::late_met_known(wait) == Some(true)
|
||||
|| hosts().any(|list| crate::host::will_meet(list, wait));
|
||||
if !met {
|
||||
return Err(next);
|
||||
}
|
||||
}
|
||||
&Job::Wait(fence, value) => {
|
||||
if crate::fence::completed(fence as This) < value && !signals.iter().any(|&(f, v)| f == fence && v >= value) {
|
||||
return Err(next);
|
||||
}
|
||||
}
|
||||
Job::Signal(..) => {}
|
||||
Job::Run(_, more, order) => {
|
||||
let runs: Vec<&crate::host::HostList> = order.iter().map(|&i| more[i].host()).collect();
|
||||
if count >= most || lists.1.len() + runs.len() > most_lists || !crate::host::joinable(hosts(), &runs) {
|
||||
return Err(next);
|
||||
}
|
||||
}
|
||||
Job::Joined(..) | Job::Present(..) | Job::Lists(..) => return Err(next),
|
||||
}
|
||||
let taken = std::mem::replace(self, Job::Wait(0, 0));
|
||||
let (queue, mut lists, mut order, mut parts, mut signals) = match taken {
|
||||
Job::Run(queue, lists, order) => (queue, lists, order, Vec::new(), Vec::new()),
|
||||
Job::Joined(queue, lists, order, parts, signals) => (queue, lists, order, parts, signals),
|
||||
other => {
|
||||
*self = other;
|
||||
return Err(next);
|
||||
}
|
||||
};
|
||||
let run = matches!(next, Job::Run(..));
|
||||
match next {
|
||||
Job::Run(_, more, then) => {
|
||||
parts.push(order.len());
|
||||
order.extend(then.into_iter().map(|i| i + lists.len()));
|
||||
lists.extend(more);
|
||||
STATS[JOINED].fetch_add(1, Relaxed);
|
||||
}
|
||||
Job::Signal(fence, value) => signals.push((fence, value)),
|
||||
_ => {}
|
||||
}
|
||||
*self = Job::Joined(queue, lists, order, parts, signals);
|
||||
Ok(run)
|
||||
}
|
||||
|
||||
fn go(self, forced: bool) {
|
||||
let began = Instant::now();
|
||||
let _doing = crate::timeline::span(match self {
|
||||
Job::Run(..) => "the line: a submission",
|
||||
Job::Joined(..) => "the line: submissions joined",
|
||||
Job::Present(..) => "the line: a present",
|
||||
Job::Signal(..) => "the line: a signal",
|
||||
_ => "the line: a wait that is met",
|
||||
@@ -439,6 +546,24 @@ impl Work for Job {
|
||||
}
|
||||
QUEUED.fetch_sub(1, Relaxed);
|
||||
}
|
||||
Job::Joined(queue, lists, order, parts, signals) => {
|
||||
let _ = queue;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
crate::capture::op(queue, || {
|
||||
format!("RUN {} parts of submissions in one, {} lists (its thread's)", 1 + parts.len(), order.len())
|
||||
});
|
||||
match crate::host::host() {
|
||||
Some(host) => host.execute_parts(lists, order, &parts),
|
||||
None => drop(lists),
|
||||
}
|
||||
// (A part that had no list is one all the same.)
|
||||
QUEUED.fetch_sub(1 + parts.len() as u64, Relaxed);
|
||||
for (fence, value) in signals {
|
||||
if !crate::host::late_signal(fence, value) {
|
||||
crate::fence::set(fence as This, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Job::Signal(fence, value) => {
|
||||
if !crate::host::late_signal(fence, value) {
|
||||
crate::fence::set(fence as This, value);
|
||||
@@ -469,7 +594,7 @@ static QUEUED: AtomicU64 = AtomicU64::new(0);
|
||||
/// threads of the title waited, in microseconds, for room in the line, at a
|
||||
/// present, and for a drain, and the drains; what our thread worked; waits
|
||||
/// not met at a present.
|
||||
static STATS: [AtomicU64; 10] = [const { AtomicU64::new(0) }; 10];
|
||||
static STATS: [AtomicU64; 11] = [const { AtomicU64::new(0) }; 11];
|
||||
const RUNS: usize = 0;
|
||||
const PRESENTS: usize = 1;
|
||||
const DEPTH: usize = 2;
|
||||
@@ -480,6 +605,8 @@ const DRAINING: usize = 6;
|
||||
const DRAINS: usize = 7;
|
||||
const BUSY: usize = 8;
|
||||
const FORCED: usize = 9;
|
||||
/// Parts prepared together with the one before them.
|
||||
const JOINED: usize = 10;
|
||||
|
||||
/// How many submissions may be in the line when a submit call returns
|
||||
/// (`VICTORY_SUBMIT_DEPTH`; 64: about two frames of the title's).
|
||||
@@ -701,7 +828,8 @@ pub(super) fn line(frames: f64) {
|
||||
tracing::info!(
|
||||
"submissions prepared by a thread of ours, per frame (VICTORY_ASYNC_SUBMIT): {:.1} in {:.1} presents, {:.1} in the line \
|
||||
when one was added (at most {:.0}); that thread worked {:.1} ms; threads of the title waited {:.1} ms for room in the \
|
||||
line, {:.1} ms at presents, {:.1} ms in {:.1} drains; waits not met at a present {:.2}",
|
||||
line, {:.1} ms at presents, {:.1} ms in {:.1} drains; waits not met at a present {:.2}; {:.1} of the \
|
||||
submissions were prepared together with the one before them (VICTORY_JOIN_PARTS)",
|
||||
s[RUNS] / frames,
|
||||
s[PRESENTS] / frames,
|
||||
s[DEPTH] / s[RUNS].max(1.0),
|
||||
@@ -711,7 +839,8 @@ pub(super) fn line(frames: f64) {
|
||||
ms(AT_PRESENT),
|
||||
ms(DRAINING),
|
||||
s[DRAINS] / frames,
|
||||
s[FORCED] / frames
|
||||
s[FORCED] / frames,
|
||||
s[JOINED] / frames
|
||||
);
|
||||
}
|
||||
|
||||
@@ -731,6 +860,8 @@ mod tests {
|
||||
Slow(&'static str, Log, Arc<(Mutex<bool>, Condvar)>),
|
||||
Signal(usize, u64, Log),
|
||||
Present(&'static str, Log),
|
||||
/// Takes others of its kind, waits that are met, and signals along.
|
||||
Group(Vec<&'static str>, Log, Vec<(usize, u64)>),
|
||||
}
|
||||
|
||||
impl Work for T {
|
||||
@@ -748,7 +879,24 @@ mod tests {
|
||||
matches!(self, T::Present(..))
|
||||
}
|
||||
fn runs(&self) -> bool {
|
||||
matches!(self, T::Run(..) | T::Slow(..))
|
||||
matches!(self, T::Run(..) | T::Slow(..) | T::Group(..))
|
||||
}
|
||||
fn take_along(&mut self, next: T) -> Result<bool, T> {
|
||||
let T::Group(names, _, signals) = self else {
|
||||
return Err(next);
|
||||
};
|
||||
match next {
|
||||
T::Group(more, ..) if names.len() < 3 => {
|
||||
names.extend(more);
|
||||
Ok(true)
|
||||
}
|
||||
T::Wait(f, v) if crate::fence::completed(f as This) >= v || signals.contains(&(f, v)) => Ok(false),
|
||||
T::Signal(f, v, _) => {
|
||||
signals.push((f, v));
|
||||
Ok(false)
|
||||
}
|
||||
other => Err(other),
|
||||
}
|
||||
}
|
||||
fn go(self, forced: bool) {
|
||||
match self {
|
||||
@@ -769,6 +917,12 @@ mod tests {
|
||||
log.lock().unwrap().push(format!("signal {value}"));
|
||||
crate::fence::set(fence as This, value);
|
||||
}
|
||||
T::Group(names, log, signals) => {
|
||||
log.lock().unwrap().push(names.join("+"));
|
||||
for (fence, value) in signals {
|
||||
crate::fence::set(fence as This, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -814,6 +968,34 @@ mod tests {
|
||||
assert!(done);
|
||||
}
|
||||
|
||||
/// A submission takes what follows it in its queue along, up to what it
|
||||
/// cannot take, which stays at its place; the counts come out even.
|
||||
#[test]
|
||||
fn submissions_take_those_behind_them_along() {
|
||||
let lane = Lane::new();
|
||||
let log: Log = Default::default();
|
||||
let f = fence();
|
||||
let part = |name| T::Group(vec![name], log.clone(), Vec::new());
|
||||
lane.push(1, [part("a"), T::Wait(f, 0), part("b")]);
|
||||
lane.push(2, [part("other queue"), T::Wait(f, 1), part("behind a's signal")]);
|
||||
lane.push(1, [T::Signal(f, 1, log.clone()), T::Wait(f, 1), part("c"), part("d")]);
|
||||
lane.push(1, [T::Wait(f, 9), part("held"), T::Present("present", log.clone()), part("next frame")]);
|
||||
// What came after the look was asked for is not touched.
|
||||
let limit = lane.lock().next;
|
||||
lane.push(1, [part("later")]);
|
||||
lane.look(limit);
|
||||
assert_eq!(
|
||||
*log.lock().unwrap(),
|
||||
["a+b+c", "other queue+behind a's signal", "d", "held", "present", "next frame"],
|
||||
"{:?}",
|
||||
lane.lock().items.len()
|
||||
);
|
||||
look(&lane);
|
||||
assert_eq!(log.lock().unwrap().last().unwrap(), "later");
|
||||
let state = lane.lock();
|
||||
assert_eq!((state.presents, state.runs, state.items.len()), (0, 0, 0));
|
||||
}
|
||||
|
||||
/// A wait that nothing meets holds its queue until a present, which
|
||||
/// comes behind everything given before it and before what comes after.
|
||||
#[test]
|
||||
|
||||
@@ -393,6 +393,12 @@ impl Drop for Ours {
|
||||
}
|
||||
}
|
||||
|
||||
/// While what this returns lives, this thread's D3D12 calls are not
|
||||
/// recorded.
|
||||
pub(crate) fn unrecorded() -> impl Drop {
|
||||
Ours::new()
|
||||
}
|
||||
|
||||
fn ours() -> bool {
|
||||
OURS.with(|o| o.get() > 0)
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ pub extern "system" fn XMemVirtualAlloc(
|
||||
0
|
||||
},
|
||||
};
|
||||
let asked = protect;
|
||||
let mut protect = match protect & HOST_PROTECTION {
|
||||
0 => PAGE_NOACCESS,
|
||||
p => p,
|
||||
@@ -179,9 +180,32 @@ pub extern "system" fn XMemVirtualAlloc(
|
||||
if !at.is_null() && !placeholder {
|
||||
victory_gpu::title_memory_allocated(at as usize, size);
|
||||
}
|
||||
note_protection(asked, kind, flags, at as usize, size);
|
||||
at
|
||||
}
|
||||
|
||||
/// What the title asks its memory to be (the console's protection, with the
|
||||
/// bits that say how each processor reaches it: 0x200 uncached, 0x400
|
||||
/// write-combined, 0x800 and on the GPU's): said for the 1st, 2nd, 4th.. time of
|
||||
/// each, with how much so far. (For placing it: memory the CPU reaches
|
||||
/// uncached or write-combined is memory it does not read.)
|
||||
fn note_protection(protect: u32, kind: u32, flags: u64, at: usize, size: usize) {
|
||||
type Seen = std::collections::HashMap<(u32, u32, u64), (u64, usize)>;
|
||||
static SEEN: std::sync::Mutex<Option<Seen>> = std::sync::Mutex::new(None);
|
||||
let (n, bytes) = {
|
||||
let mut seen = SEEN.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let e = seen.get_or_insert_with(Default::default).entry((protect, kind, flags)).or_default();
|
||||
*e = (e.0 + 1, e.1 + size);
|
||||
*e
|
||||
};
|
||||
if n.is_power_of_two() {
|
||||
tracing::info!(
|
||||
"title memory asked for as protection {protect:#x}, kind {kind:#x}, flags {flags:#x}: {n} times, {} MB, last {at:#x}+{size:#x}",
|
||||
bytes >> 20
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// `MEMORY_BASIC_INFORMATION` (the console's first 0x30 bytes are the
|
||||
/// same), then the XMem flags and tag.
|
||||
#[repr(C)]
|
||||
|
||||
Reference in new issue
Block a user