diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index 0b5a9caf96..0ae7d29466 100644 --- a/d3d12/crates/leonida-gpu/src/draw.rs +++ b/d3d12/crates/leonida-gpu/src/draw.rs @@ -786,10 +786,12 @@ fn in_place_order() -> bool { /// of it (tables with such a view are gone through at every bind, root views are declared at /// every bind), so the ranges kept since a pass are those of the shaders recorded behind it: /// a record outside them is as the pass read it. A shader that can store to buffers by other -/// ways than a view bound to it (by address, through a view it picks from the heap by a number -/// it computes or per lane, at an offset in a table it computes, past the first view of a range, -/// code that is not all known or not followed, the structure builder) ends the batch, as with 1 -/// ([`stores_declared`]). Copies the title places in the list end it in every setting. +/// ways than a view bound to it (by address, through a view it loads from the heap by a number +/// it computes or picks per lane, at an offset in a table it computes, past the first view of a +/// range, code that is not all known or not followed, the structure builder) ends the batch, as +/// with 1 ([`stores_declared`]). A stage that loads views from the heap only to read through them +/// ends none, unless `LEONIDA_BATCH_HEAP_READS=0` ([`batch_heap_reads`]), where every stage that +/// loads views from the heap ends it. Copies the title places in the list end it in every setting. /// (Switched with `LEONIDA_AB` between 2 and 4 the first batches of 4 after a phase of 2 may /// have missed a store by address made during it: measure 4 against 1 for the picture.) fn batches() -> u8 { @@ -854,48 +856,266 @@ fn batch_stale(mode: u8, wrote: bool, in_list: impl FnOnce() -> bool, since: imp /// Whether all that the shaders of `p` can store to buffers goes through views bound to it, /// which a list is told of at every bind (`crate::shadow::Shadow::gpu_writes`): no stage that /// stores does so otherwise than through a buffer view -/// (`crate::pipeline::Translated::stores_past_views`) or picks its views from the heap by a -/// number it computes (what it writes through one of those is declared nowhere: -/// [`State::heap_buffers`]), and every store of every stage goes through a table entry or root -/// view that the bind declares (`crate::pipeline::stores_bound`: not a view picked per lane, at -/// an offset the program computes or past the first of a range; no until a thread of its own -/// has looked). `builder`: it is the structure builder's, whose stores are not declared while it -/// is quarantined. -fn stores_declared(p: &HostPipeline, builder: bool) -> bool { - !builder - && p.stages.iter().all(|stage| { +/// (`crate::pipeline::Translated::stores_past_views`), and every store of every stage goes +/// through a table entry or root view that the bind declares (`crate::pipeline::stores_bound`: +/// not a view loaded from the heap or picked per lane, at an offset the program computes or past +/// the first of a range; no until a thread of its own has looked). A stage that loads buffer +/// views from the heap only to read through them passes; with `LEONIDA_BATCH_HEAP_READS=0` +/// ([`batch_heap_reads`]) no such stage does. `builder`: it is the structure builder's, whose +/// stores are not declared while it is quarantined. The answer says which setting of the switch +/// it was made under, for the diagnostic of the same decision ([`Declared`]). +fn stores_declared(p: &HostPipeline, builder: bool) -> Declared { + stages_declared( + builder, + p.stages.iter().map(|stage| { let t = stage.translated(); - !t.stores - || (!(t.stores_past_views || t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES)) - && crate::pipeline::stores_bound(&stage.shader, t)) - }) + (StageFacts::of(t), move || crate::pipeline::stores_bound(&stage.shader, t)) + }), + ) } -/// Diagnostics: why [`stores_declared`] says no of `p`, for the first stage that stores. -#[cfg(feature = "diagnostics")] -fn undeclared_why(p: &HostPipeline, builder: bool) -> &'static str { +/// What [`stores_declared`] answers: whether all that the pipeline stores is declared (`all`), +/// and under which setting of [`batch_heap_reads`], read once for the decision (`heap_reads`): +/// [`undeclared_why`] says why not under the same, whatever `LEONIDA_AB` did since. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +struct Declared { + all: bool, + heap_reads: bool, +} + +/// [`stores_declared`] of a pipeline's stages, each given as its facts and +/// [`crate::pipeline::stores_bound`] (asked last, the stages in order): the switch is read here, +/// once ([`batch_heap_reads`]). +fn stages_declared bool>(builder: bool, stages: impl IntoIterator) -> Declared { + let heap_reads = batch_heap_reads(); + Declared { all: !builder && stages.into_iter().all(|(s, bound)| stage_declared(s, heap_reads, bound)), heap_reads } +} + +/// What [`stage_declared`] takes of one stage of a pipeline. +#[derive(Clone, Copy, Debug, Default)] +struct StageFacts { + /// Its code can store to buffer memory (`crate::pipeline::Translated::stores`). + stores: bool, + /// It can store otherwise than through a buffer view + /// (`crate::pipeline::Translated::stores_past_views`). + past_views: bool, + /// It has the root SRV [`leonida_shader::emit::SLOT_STRIDES`]: it loads buffer views from the + /// heap (a `ResourceHeap` root parameter) at a slot it computes, to read through them or to + /// store. + heap: bool, +} + +impl StageFacts { + fn of(t: &crate::pipeline::Translated) -> StageFacts { + StageFacts { + stores: t.stores, + past_views: t.stores_past_views, + heap: t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES), + } + } +} + +/// Whether what one stage (`s`) stores to buffers is all declared at its bind +/// ([`stores_declared`]): it stores nothing; or it stores through buffer views alone, loads no +/// view from the heap unless `heap_reads` ([`batch_heap_reads`]), and all it stores goes through +/// views bound to it (`bound`, asked last: [`crate::pipeline::stores_bound`] starts a thread the +/// first time). +fn stage_declared(s: StageFacts, heap_reads: bool, bound: impl FnOnce() -> bool) -> bool { + !s.stores || (!s.past_views && (heap_reads || !s.heap) && bound()) +} + +#[cfg(test)] +thread_local! { + /// [`batch_heap_reads`] for this thread's tests (`None`: as the variable says). + static HEAP_READS_IN_TEST: std::cell::Cell> = const { std::cell::Cell::new(None) }; +} + +/// `LEONIDA_BATCH_HEAP_READS` (on unless `0`; `LEONIDA_AB` can turn it on and off while the title +/// runs): with `LEONIDA_INDIRECT_BATCH=4`, a stage that loads buffer views from the heap (a +/// `ResourceHeap` root parameter: the root SRV [`leonida_shader::emit::SLOT_STRIDES`]) does not +/// end the open batch for that alone ([`stage_declared`]): whether all it stores goes through +/// views bound to it decides, as for any other stage (`crate::pipeline::stores_bound`). With `0` +/// such a stage ends the batch whatever it does with those views, as before. +/// +/// The translator gives a program that root SRV for any buffer access through a view it loads +/// from the heap, reads included (`leonida-shader` `emit/lower.rs`, `slot_word`), and +/// `stores_bound` already says no of a program that stores through such a view or through a +/// table at an offset it computes: the batch still ends for those, whose writes are declared +/// nowhere. +/// +/// Measured on an RTX 3090 (NVIDIA 621.40) in the world with `LEONIDA_INDIRECT_BATCH=4` (what +/// `scripts/play-nvidia.ps1` sets). Before (main 640b0d0df): some 600 clamp passes a frame, about +/// 2.3 ms of the card's time, the costliest entry of a GPU timing run; about 509 batches a frame +/// ended by a program whose stores are not all declared. With the switch against without it +/// (`LEONIDA_AB`, 33 pairs of phases, on main 0d41b0a0c): 122 batches a frame instead of 601, the +/// ends for undeclared stores 9 instead of 507 (498 of those were stages that only read through +/// views of the heap, their stores bound), the clamp passes 0.8 ms of the card's time instead of +/// 2.3, the frame's median 2.2 ms shorter (+-0.17), the card busy 1.9 ms less, the lists' steps on +/// the CPU 0.5 ms longer; captures alike. +fn batch_heap_reads() -> bool { + #[cfg(test)] + if let Some(on) = HEAP_READS_IN_TEST.get() { + return on; + } + crate::toggled!("LEONIDA_BATCH_HEAP_READS") +} + +/// Why [`stores_declared`] says no of a pipeline, as the frame-rate line counts the batches it +/// ends ([`undeclared_kind`], [`batch_why_line`]). +#[cfg(any(test, feature = "diagnostics"))] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Undeclared { + /// The structure builder's, whose stores are not declared while it is quarantined. + Builder, + /// A stage stores by address. + ByAddress, + /// A stage stores otherwise than through a buffer view (scalar stores, code not known). + PastViews, + /// A stage stores through a view it loads from the heap, or from a table at an offset it + /// computes (`crate::picked::picks`). + HeapStores, + /// A stage loads buffer views from the heap (a `ResourceHeap` root parameter) and stores + /// through none of them, and all it stores goes through views bound to it + /// (`crate::pipeline::stores_bound`); or not; or that is not known yet. + HeapReadsBound, + HeapReadsUnbound, + HeapReadsNotYet, + /// A stage loads buffer views from the heap, and neither of those is known yet. + HeapNotYet, + /// A stage stores through a view its bind does not declare. + NotBound, + /// A stage's stores are not looked at yet. + NotYet, + /// None: every stage that stores is declared. + Other, +} + +#[cfg(any(test, feature = "diagnostics"))] +impl Undeclared { + #[cfg(test)] + const ALL: [Undeclared; 11] = [ + Undeclared::Builder, + Undeclared::ByAddress, + Undeclared::PastViews, + Undeclared::HeapStores, + Undeclared::HeapReadsBound, + Undeclared::HeapReadsUnbound, + Undeclared::HeapReadsNotYet, + Undeclared::HeapNotYet, + Undeclared::NotBound, + Undeclared::NotYet, + Undeclared::Other, + ]; + + /// As the frame-rate line names it (no `", "` in it: the line lists them so). + fn label(self) -> &'static str { + match self { + Undeclared::Builder => "the structure builder", + Undeclared::ByAddress => "stores by address", + Undeclared::PastViews => "scalar stores or code not known", + Undeclared::HeapStores => "stores through a view picked from the heap", + Undeclared::HeapReadsBound => "reads only from the heap (stores bound yes)", + Undeclared::HeapReadsUnbound => "reads only from the heap (stores bound no)", + Undeclared::HeapReadsNotYet => "reads only from the heap (stores bound not yet)", + Undeclared::HeapNotYet => "views picked from the heap (not looked at yet)", + Undeclared::NotBound => "a view not declared at its bind", + Undeclared::NotYet => "stores not looked at yet", + Undeclared::Other => "?", + } + } +} + +/// What [`undeclared_kind`] knows of a stage that stores to buffers. +#[cfg(any(test, feature = "diagnostics"))] +#[derive(Clone, Copy, Debug, Default)] +struct StoringStage { + /// `crate::pipeline::Translated::stores_by_address`. + by_address: bool, + /// `crate::pipeline::Translated::stores_past_views`. + past_views: bool, + /// It loads buffer views from the heap (a `ResourceHeap` root parameter): it has the root SRV + /// [`leonida_shader::emit::SLOT_STRIDES`]. + heap: bool, + /// Whether all it stores goes through views bound to it (`crate::pipeline::stores_bound`): + /// `None` until a thread of its own has looked. + bound: Option, + /// Whether it stores through a view it loads from the heap, or from a table at an offset it + /// computes (`crate::picked::picks`): `None` + /// until a thread of its own has looked. + picks: Option, +} + +/// Why the stores of a pipeline (`builder`: the structure builder's) are not all declared +/// ([`stores_declared`]), from its stages that store, in order: the first stage that is not +/// declared decides; [`Undeclared::Other`] if each is. +#[cfg(any(test, feature = "diagnostics"))] +fn undeclared_kind(builder: bool, heap_reads: bool, stages: &[StoringStage]) -> Undeclared { if builder { - return "the structure builder"; + return Undeclared::Builder; } - for stage in &p.stages { - let t = stage.translated(); - if !t.stores { + for s in stages { + if stage_declared(StageFacts { stores: true, past_views: s.past_views, heap: s.heap }, heap_reads, || s.bound == Some(true)) { continue; } - if t.stores_by_address { - return "stores by address"; - } - if t.stores_past_views { - return "scalar stores or code not known"; - } - if t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES) { - return "views picked from the heap"; - } - if !crate::pipeline::stores_bound(&stage.shader, t) { - return "a view not declared at its bind, or not looked at yet"; - } + return if s.by_address { + Undeclared::ByAddress + } else if s.past_views { + Undeclared::PastViews + } else if s.heap { + // (A stage whose stores are all bound stores through no view of the heap.) + match (s.picks, s.bound) { + (Some(true), _) => Undeclared::HeapStores, + (_, Some(true)) => Undeclared::HeapReadsBound, + (Some(false), Some(false)) => Undeclared::HeapReadsUnbound, + (Some(false), None) => Undeclared::HeapReadsNotYet, + (None, _) => Undeclared::HeapNotYet, + } + } else if s.bound == Some(false) { + Undeclared::NotBound + } else { + Undeclared::NotYet + }; + } + Undeclared::Other +} + +/// The batch ends counted for each reason, a frame (`frames`): every reason counted, the most +/// first, as ` ` items separated by `", "` (the frame-rate line). +#[cfg(any(test, feature = "diagnostics"))] +fn by_reason(mut counts: Vec<(&'static str, u64)>, frames: f64) -> String { + counts.retain(|c| c.1 > 0); + counts.sort_by(|a, b| b.1.cmp(&a.1).then(a.0.cmp(b.0))); + counts.iter().map(|(why, n)| format!("{why} {:.1}", *n as f64 / frames)).collect::>().join(", ") +} + +/// Diagnostics: why [`stores_declared`] says no of `p`, for the first stage that stores +/// ([`undeclared_kind`]), under the setting of the switch that answer was made under +/// (`heap_reads`: [`Declared`]). What [`crate::pipeline::stores_bound`] says of each stage that +/// stores only through views, and what [`crate::picked::picks`] says of each that loads views from +/// the heap, is asked for here if nobody has yet. +#[cfg(feature = "diagnostics")] +fn undeclared_why(p: &HostPipeline, builder: bool, heap_reads: bool) -> &'static str { + if builder { + return Undeclared::Builder.label(); } - "?" + let stages: Vec = p + .stages + .iter() + .filter(|stage| stage.translated().stores) + .map(|stage| { + let t = stage.translated(); + let facts = StageFacts::of(t); + // (Each asked only where `undeclared_kind` reads it.) + StoringStage { + by_address: t.stores_by_address, + past_views: facts.past_views, + heap: facts.heap, + bound: if facts.past_views { None } else { crate::pipeline::bound_answer(&stage.shader, t) }, + picks: if facts.heap { crate::picked::answer(&stage.shader, &t.picks) } else { None }, + } + }) + .collect(); + undeclared_kind(false, heap_reads, &stages).label() } /// Diagnostics: `LEONIDA_BATCH_WHY=1` counts what ends indirect batches and by which @@ -909,9 +1129,10 @@ pub(crate) fn batch_why() -> bool { /// Since the last frame-rate line ([`batch_why`]): batches opened; batches ended by a shader /// that stores (1, 0, and with 2 at the title's next wait or draw), by a shader whose stores /// are not all declared (4), by a copy, for a record declared written (3, 4), for a full -/// table or another source; executions that read from a batch. +/// table; executions that read from a batch; batches ended for a record in another source +/// (or at an offset the pass does not take: [`crate::indirect::batch::Table::full_for`]). #[cfg(feature = "diagnostics")] -static BATCH_WHY: [AtomicU64; 7] = [const { AtomicU64::new(0) }; 7]; +static BATCH_WHY: [AtomicU64; 8] = [const { AtomicU64::new(0) }; 8]; /// By writer and reader program ([`batch_why`]): how often a record the reader executes lay /// in a range declared for the writer since the batch's pass, and the smallest and largest @@ -925,6 +1146,12 @@ static BATCH_PAIRS: std::sync::Mutex> = std::sync::Mutex::new #[cfg(feature = "diagnostics")] static BATCH_UNDECLARED: std::sync::Mutex>> = std::sync::Mutex::new(None); +/// By reason ([`batch_why`], [`undeclared_why`]): batches ended because not all a program +/// stores is declared (4), all of them (the programs' list has the first eight). +#[cfg(feature = "diagnostics")] +static BATCH_UNDECLARED_WHY: std::sync::Mutex>> = + std::sync::Mutex::new(None); + /// For the frame-rate line: what ended indirect batches ([`BATCH_WHY`]) and the pairs of /// programs behind the records declared written ([`BATCH_PAIRS`]). #[cfg(feature = "diagnostics")] @@ -932,13 +1159,19 @@ pub(crate) fn batch_why_line(frames: f64) { if !batch_why() { return; } - let [opened, stored, undeclared, copied, written, full, read] = - [0, 1, 2, 3, 4, 5, 6].map(|i: usize| BATCH_WHY[i].swap(0, Ordering::Relaxed) as f64 / frames); + let [opened, stored, undeclared, copied, written, full, read, other] = + [0, 1, 2, 3, 4, 5, 6, 7].map(|i: usize| BATCH_WHY[i].swap(0, Ordering::Relaxed) as f64 / frames); tracing::info!( "indirect batches per frame (LEONIDA_INDIRECT_BATCH={}): {opened:.0} opened; ended by a storing shader {stored:.0}, by one whose \ stores are not all declared {undeclared:.0}, by a copy {copied:.0}, for a record declared written since the pass {written:.0}, \ - for a full table or another source {full:.0}; {read:.0} executions read from an open batch", - batches() + for a full table or another source {:.0}; {read:.0} executions read from an open batch", + batches(), + full + other + ); + let reasons = BATCH_UNDECLARED_WHY.lock().unwrap_or_else(|e| e.into_inner()).take().unwrap_or_default(); + tracing::info!( + " batches ended per frame for stores not all declared, by reason: {}; for a full table {full:.1}, for another source {other:.1}", + by_reason(reasons.into_iter().collect(), frames) ); let said = crate::pipeline::BOUND_SAID.each_ref().map(|n| n.swap(0, Ordering::Relaxed)); let undeclared = BATCH_UNDECLARED.lock().unwrap_or_else(|e| e.into_inner()).take().unwrap_or_default(); @@ -6231,7 +6464,10 @@ impl State { if batches() != 4 { return false; } - if !self.views_untold && stores_declared(p, crate::pipeline::is_builder(self.pipeline as This)) { + let builder = crate::pipeline::is_builder(self.pipeline as This); + // (One reading of the switch for the decision and its diagnostic: `Declared::heap_reads`.) + let declared = (!self.views_untold).then(|| stores_declared(p, builder)); + if declared.is_some_and(|d| d.all) { if let Some(batch) = &mut self.batch { batch.wrote = true; } @@ -6239,13 +6475,15 @@ impl State { #[cfg(feature = "diagnostics")] if self.batch.is_some() && batch_why() { BATCH_WHY[2].fetch_add(1, Ordering::Relaxed); - let why = if self.views_untold { - "a table its bind did not go through" - } else { - undeclared_why(p, crate::pipeline::is_builder(self.pipeline as This)) + let why = match declared { + Some(d) => undeclared_why(p, builder, d.heap_reads), + None => "a table its bind did not go through", }; let mut by = BATCH_UNDECLARED.lock().unwrap_or_else(|e| e.into_inner()); *by.get_or_insert_with(Default::default).entry(format!("{} ({why})", p.name)).or_default() += 1; + drop(by); + let mut reasons = BATCH_UNDECLARED_WHY.lock().unwrap_or_else(|e| e.into_inner()); + *reasons.get_or_insert_with(Default::default).entry(why).or_default() += 1; } self.batch = None; } @@ -6393,7 +6631,7 @@ impl State { } #[cfg(feature = "diagnostics")] if batch_why() { - BATCH_WHY[5].fetch_add(1, Ordering::Relaxed); + BATCH_WHY[if table.full_for(id) { 5 } else { 7 }].fetch_add(1, Ordering::Relaxed); } } } @@ -6958,9 +7196,71 @@ fn compute_word(p: &HostPipeline, kind: u32) -> Option<(u32, u32)> { #[cfg(test)] mod batch_tests { - use super::batch_stale; + use super::{Declared, HEAP_READS_IN_TEST, StageFacts, batch_heap_reads, batch_stale, stage_declared, stages_declared}; use crate::host::Spans; + /// A stage that stores through buffer views alone and loads none from the heap; one that also + /// stores otherwise; one that loads views from the heap; one that stores nothing. + const VIEWS: StageFacts = StageFacts { stores: true, past_views: false, heap: false }; + const PAST: StageFacts = StageFacts { past_views: true, ..VIEWS }; + const HEAP: StageFacts = StageFacts { heap: true, ..VIEWS }; + const NOTHING: StageFacts = StageFacts { stores: false, past_views: true, heap: true }; + + /// What a stage that stores needs for a batch to stay open past it + /// (`LEONIDA_INDIRECT_BATCH=4`, `LEONIDA_BATCH_HEAP_READS=0`): it stores through buffer views + /// alone, loads no view from the heap, and all it stores goes through views bound to it, which + /// is asked last. + #[test] + fn a_stage_is_declared_when_it_stores_through_its_bound_views_alone() { + let not_asked = || -> bool { panic!("stores_bound asked") }; + assert!(stage_declared(NOTHING, false, not_asked), "it stores nothing"); + assert!(!stage_declared(PAST, false, not_asked), "it stores past views"); + assert!(!stage_declared(HEAP, false, not_asked), "it loads views from the heap"); + assert!(!stage_declared(StageFacts { heap: true, ..PAST }, false, not_asked)); + assert!(stage_declared(VIEWS, false, || true)); + assert!(!stage_declared(VIEWS, false, || false), "a store through a view its bind does not declare"); + } + + /// `LEONIDA_BATCH_HEAP_READS`: a stage that loads views from the heap is declared when all it + /// stores goes through views bound to it (`crate::pipeline::stores_bound` says so of no stage + /// that stores through a view of the heap); the rest as without it. + #[test] + fn with_heap_reads_a_stage_reading_from_the_heap_is_declared_when_its_stores_are_bound() { + let not_asked = || -> bool { panic!("stores_bound asked") }; + assert!(stage_declared(HEAP, true, || true)); + assert!(!stage_declared(HEAP, true, || false)); + assert!(!stage_declared(StageFacts { heap: true, ..PAST }, true, not_asked), "it stores past views"); + assert!(stage_declared(NOTHING, true, not_asked), "it stores nothing"); + assert!(stage_declared(VIEWS, true, || true)); + assert!(!stage_declared(HEAP, false, not_asked), "off: as before"); + } + + /// The switch reaches the decision itself: [`stages_declared`] reads it, once, and says which it + /// read. Off, a stage that loads views from the heap ends the batch; on, not when its stores + /// are bound; the structure builder's never. + #[test] + fn the_switch_reaches_the_decision_and_is_said_with_it() { + let reader = || [(HEAP, || true)]; + let under = |on: bool| { + HEAP_READS_IN_TEST.set(Some(on)); + let said = (stages_declared(false, reader()), stages_declared(true, reader())); + HEAP_READS_IN_TEST.set(None); + said + }; + assert_eq!(under(false), (Declared { all: false, heap_reads: false }, Declared { all: false, heap_reads: false })); + assert_eq!(under(true), (Declared { all: true, heap_reads: true }, Declared { all: false, heap_reads: true })); + } + + /// `LEONIDA_BATCH_HEAP_READS` is on unless set to `0` (when neither it nor `LEONIDA_AB` is set + /// where the tests run). + #[test] + fn heap_reads_are_on_by_default() { + if std::env::var_os("LEONIDA_BATCH_HEAP_READS").is_some() || std::env::var_os("LEONIDA_AB").is_some() { + return; + } + assert!(batch_heap_reads()); + } + /// With 3 an execution leaves the open batch only when shaders recorded since its pass may /// have written the execution's own record; 2 never asks (its batches end at the title's /// waits and draws), and with 1 no batch is open past such shaders. @@ -7060,6 +7360,106 @@ mod batch_tests { } } +#[cfg(test)] +mod undeclared_tests { + use super::{StoringStage, Undeclared, by_reason, undeclared_kind}; + + fn heap(bound: Option, picks: Option) -> StoringStage { + StoringStage { heap: true, bound, picks, ..StoringStage::default() } + } + + fn plain(bound: Option) -> StoringStage { + StoringStage { bound, ..StoringStage::default() } + } + + /// `LEONIDA_BATCH_WHY` counts the batches ended for stores not all declared by what the stage + /// that is not declared does: one that loads views from the heap only to read through them is + /// told from one that stores through one, and by what is known of its stores. + #[test] + fn batch_ends_for_undeclared_stores_are_told_apart() { + use Undeclared::*; + let kind = |stages: &[StoringStage]| undeclared_kind(false, false, stages); + assert_eq!(undeclared_kind(true, false, &[plain(Some(true))]), Builder); + assert_eq!(kind(&[StoringStage { by_address: true, past_views: true, ..heap(Some(false), Some(false)) }]), ByAddress); + assert_eq!(kind(&[StoringStage { past_views: true, ..heap(Some(false), Some(false)) }]), PastViews); + // A view loaded from the heap and stored through... + assert_eq!(kind(&[heap(Some(false), Some(true))]), HeapStores); + assert_eq!(kind(&[heap(None, Some(true))]), HeapStores); + // ...or only read through: what the stage stores is bound to it, is not, or is not known yet. + assert_eq!(kind(&[heap(Some(true), Some(false))]), HeapReadsBound); + assert_eq!(kind(&[heap(Some(true), None)]), HeapReadsBound, "stores all bound go through no view of the heap"); + assert_eq!(kind(&[heap(Some(false), Some(false))]), HeapReadsUnbound); + assert_eq!(kind(&[heap(None, Some(false))]), HeapReadsNotYet); + // Neither known yet. + assert_eq!(kind(&[heap(None, None)]), HeapNotYet); + assert_eq!(kind(&[heap(Some(false), None)]), HeapNotYet); + // No view from the heap. + assert_eq!(kind(&[plain(Some(false))]), NotBound); + assert_eq!(kind(&[plain(None)]), NotYet); + // The first stage that is not declared decides; each declared: none. + assert_eq!(kind(&[plain(Some(true)), heap(Some(true), Some(false))]), HeapReadsBound); + assert_eq!(kind(&[heap(None, None), plain(Some(false))]), HeapNotYet); + assert_eq!(kind(&[plain(Some(true))]), Other); + assert_eq!(kind(&[]), Other); + } + + /// With `LEONIDA_BATCH_HEAP_READS` a stage that reads from the heap, its stores bound, is + /// declared: the next stage decides; the other reasons are as without it. + #[test] + fn with_heap_reads_a_stage_reading_from_the_heap_with_its_stores_bound_ends_no_batch() { + use Undeclared::*; + let kind = |stages: &[StoringStage]| undeclared_kind(false, true, stages); + assert_eq!(kind(&[heap(Some(true), Some(false))]), Other); + assert_eq!(kind(&[heap(Some(true), None)]), Other); + assert_eq!(kind(&[heap(Some(true), Some(false)), plain(None)]), NotYet); + assert_eq!(kind(&[heap(Some(false), Some(false))]), HeapReadsUnbound); + assert_eq!(kind(&[heap(None, Some(false))]), HeapReadsNotYet); + assert_eq!(kind(&[heap(Some(false), Some(true))]), HeapStores); + assert_eq!(kind(&[heap(None, None)]), HeapNotYet); + assert_eq!(kind(&[StoringStage { past_views: true, ..heap(Some(true), Some(false)) }]), PastViews); + assert_eq!(undeclared_kind(true, true, &[heap(Some(true), Some(false))]), Builder); + } + + #[test] + fn each_reason_has_a_label_of_its_own() { + // Every reason is in `ALL`, once and in order (a new one does not build here until it is). + let at = |k: Undeclared| match k { + Undeclared::Builder => 0, + Undeclared::ByAddress => 1, + Undeclared::PastViews => 2, + Undeclared::HeapStores => 3, + Undeclared::HeapReadsBound => 4, + Undeclared::HeapReadsUnbound => 5, + Undeclared::HeapReadsNotYet => 6, + Undeclared::HeapNotYet => 7, + Undeclared::NotBound => 8, + Undeclared::NotYet => 9, + Undeclared::Other => 10, + }; + assert!(Undeclared::ALL.iter().enumerate().all(|(i, &k)| at(k) == i)); + let labels: std::collections::BTreeSet<_> = Undeclared::ALL.iter().map(|k| k.label()).collect(); + assert_eq!(labels.len(), Undeclared::ALL.len()); + assert!(labels.iter().all(|l| !l.contains(", ")), "the line separates them by \", \""); + } + + /// Every reason a batch ended for is on the line, the most first: not only the first eight + /// (as the programs are). + #[test] + fn every_reason_counted_is_on_the_line() { + let counts: Vec<(&'static str, u64)> = + Undeclared::ALL.iter().enumerate().map(|(i, k)| (k.label(), 10 * (i as u64 + 1))).collect(); + let line = by_reason(counts, 10.0); + let items: Vec<&str> = line.split(", ").collect(); + assert_eq!(items.len(), Undeclared::ALL.len(), "{line}"); + assert_eq!(items[0], "? 11.0"); + assert_eq!(items[1], "stores not looked at yet 10.0"); + assert_eq!(items[10], "the structure builder 1.0"); + // Nothing counted: not listed. + assert_eq!(by_reason(vec![("a", 0), ("b", 5)], 2.0), "b 2.5"); + assert_eq!(by_reason(Vec::new(), 1.0), ""); + } +} + #[cfg(test)] mod depth_companion_tests { use super::*; diff --git a/d3d12/crates/leonida-gpu/src/indirect/batch.rs b/d3d12/crates/leonida-gpu/src/indirect/batch.rs index 54e7240f18..ecdc47df8f 100644 --- a/d3d12/crates/leonida-gpu/src/indirect/batch.rs +++ b/d3d12/crates/leonida-gpu/src/indirect/batch.rs @@ -325,6 +325,15 @@ impl Table { } Some(place(i)) } + + /// Diagnostics (`LEONIDA_BATCH_WHY`, `crate::draw`): whether [`Table::place_packed`] has no + /// place for a record of the host copy `id` because every job is taken: the pass reads that + /// copy and has [`JOBS`] jobs. (Else the record is in another source, or at an offset the + /// pass does not take.) + #[cfg(any(test, feature = "diagnostics"))] + pub(crate) fn full_for(&self, id: u64) -> bool { + self.sources.contains(&id) && self.times.len() as u32 >= JOBS + } } /// What the pass waits for before it reads the records ([`record`]). @@ -393,3 +402,28 @@ pub(super) fn record( l.ResourceBarrier(&[after]); } } + +#[cfg(test)] +mod tests { + use super::{JOBS, TABLE, Table}; + + /// A batch with no place for an execution's record either does not read the copy the record + /// is in or has every job taken: `LEONIDA_BATCH_WHY` counts the two apart. + #[test] + fn a_table_is_full_for_a_copy_it_reads_once_every_job_is_taken() { + const DISPATCH: u32 = 2; + let mut memory = vec![0u32; (TABLE / 4) as usize]; + // SAFETY: TABLE bytes on 4, alive past the table, read by no list. + let mut table = unsafe { Table::new(memory.as_mut_ptr().cast(), 0, [7, 9, 0, 0]) }; + for i in 0..JOBS { + assert!(!table.full_for(7), "{i} jobs"); + assert!(table.place(7, u64::from(i) * 32, DISPATCH).is_some()); + } + assert!(table.place(7, u64::from(JOBS) * 32, DISPATCH).is_none()); + assert!(table.full_for(7)); + assert!(table.full_for(9), "another copy the pass reads"); + assert!(!table.full_for(8), "a copy the pass does not read: another source"); + // A record it has already is still placed. + assert!(table.place(7, 0, DISPATCH).is_some()); + } +} diff --git a/d3d12/crates/leonida-gpu/src/picked.rs b/d3d12/crates/leonida-gpu/src/picked.rs index cbb54549db..ac8e08fc3a 100644 --- a/d3d12/crates/leonida-gpu/src/picked.rs +++ b/d3d12/crates/leonida-gpu/src/picked.rs @@ -130,6 +130,18 @@ pub(crate) fn picks(shader: &Arc, known: &AtomicU8) -> } } +/// Diagnostics (`LEONIDA_BATCH_WHY`, `crate::draw`): what [`picks`] says of `shader`, asked +/// for if nobody has yet: `None` until its thread has looked. +#[cfg(feature = "diagnostics")] +pub(crate) fn answer(shader: &Arc, known: &AtomicU8) -> Option { + picks(shader, known); + match known.load(Relaxed) { + YES => Some(true), + NO => Some(false), + _ => None, + } +} + fn ask(shader: Arc) { use std::sync::mpsc::{Sender, channel}; static ASKS: OnceLock>>> = OnceLock::new(); diff --git a/d3d12/crates/leonida-gpu/src/pipeline.rs b/d3d12/crates/leonida-gpu/src/pipeline.rs index 3729514873..1594726100 100644 --- a/d3d12/crates/leonida-gpu/src/pipeline.rs +++ b/d3d12/crates/leonida-gpu/src/pipeline.rs @@ -677,6 +677,18 @@ pub(crate) fn stores_bound(shader: &Arc, t: &Translated) -> bool { } } +/// Diagnostics (`LEONIDA_BATCH_WHY`, `crate::draw`): what [`stores_bound`] says of `shader` +/// (translated as `t`), asked for if nobody has yet: `None` until its thread has looked. +#[cfg(all(windows, feature = "diagnostics"))] +pub(crate) fn bound_answer(shader: &Arc, t: &Translated) -> Option { + stores_bound(shader, t); + match t.bound.load(std::sync::atomic::Ordering::Relaxed) { + BOUND_YES => Some(true), + BOUND_NO => Some(false), + _ => None, + } +} + #[cfg(windows)] fn ask_bound(shader: Arc) { use std::sync::atomic::Ordering::Relaxed; @@ -1269,7 +1281,9 @@ pub fn save_pipeline_cache() { /// Which stores [`stores_in_bound_views`] takes as declared at a bind (`LEONIDA_INDIRECT_BATCH=4`). #[cfg(all(test, windows))] mod bound_tests { + use leonida_shader::gfx10::Fields; use leonida_shader::native::{ComputeIo, HwStage, NativeProgram, ResourceType, RootParam, RootType, StageIo, UsedResource}; + use leonida_shader::resource::{Role, Source}; fn used(kind: ResourceType, root: RootType, at: u32) -> UsedResource { UsedResource { kind, root, table_offset_dwords: at, lower_bound: 0, stride: 4, dwords: 4, user_data: 4, slot: 1 } @@ -1343,6 +1357,191 @@ mod bound_tests { ps.stage = HwStage::Ps; assert!(!super::bound_programs(&[bound.clone(), ps]), "a second storing program the host does not bind by"); } + + /// A program that also has the view heap among its parameters (in s6, after the table in s4): + /// it loads a buffer view from the heap at a slot it computes, reads through it, and stores + /// what it read through the descriptor in s[`at`..`at` + 4]: 12, the table's descriptor 1 (an + /// entry of unordered access), or 16, the one it loaded from the heap. + fn heap_reader(at: u32) -> NativeProgram { + let code = [ + 0xBE85_0380, // s_mov_b32 s5, 0 + 0xBE87_0380, // s_mov_b32 s7, 0 + 0x8F08_8500, // s_lshl_b32 s8, s0, 5 (a slot of the heap, 32 bytes each) + 0xF408_0403, + 0x08 << 25, // s_load_dwordx4 s[16:19], s[6:7], s8 + 0xF408_0302, + 0x7D << 25 | 0x20, // s_load_dwordx4 s[12:15], s[4:5], 0x20 + 0x342A_0084, // v_lshlrev_b32 v21, 4, v0 + 0xE038_1000, + 0x8004_0D15, // buffer_load_dwordx4 v[13:16], v21, s[16:19], 0 offen + 0xE078_1000, + 0x8000_0D15 | (at / 4) << 16, // buffer_store_dwordx4 v[13:16], v21, s[at:at+3], 0 offen + ]; + with_heap(program(RootType::Table, vec![used(ResourceType::Uav, RootType::Table, 8)], &code), 6) + } + + /// `p` with the view heap among its parameters too (a `ResourceHeap` root parameter in one + /// register, at `user_data`), its user registers reaching to it. + fn with_heap(mut p: NativeProgram, user_data: u8) -> NativeProgram { + p.layout.push(RootParam { root: RootType::ResourceHeap, table_offset_dwords: 0, sgprs: 1, base_register: 0, user_data, slot: 2 }); + p.io = StageIo::Cs(ComputeIo { rsrc2: (u32::from(user_data) + 1) << 1, threads: [32, 1, 1] }); + p + } + + /// What resource tracking finds for the descriptor of `p`'s buffer store, and for each source + /// it picks from, the root parameter of a descriptor loaded from one and whether at an offset + /// the program computes (`None` for any other source). + fn store_traced(p: &NativeProgram) -> (Source, Vec>) { + let built = leonida_shader::spill::build(p).expect("builds"); + let res = leonida_shader::resource::track(&built, &p.layout, p.stage, None).expect("tracked"); + let d = res + .descriptors + .iter() + .find(|d| { + let inst = &built.blocks[d.site.0].insts[d.site.1]; + d.role == Role::Resource && matches!(inst.fields, Fields::Buffer { .. }) && inst.name().contains("store") + }) + .expect("the store's descriptor"); + let leaves = d + .source + .leaves() + .into_iter() + .map(|leaf| match leaf { + Source::Loaded { load, .. } => { + res.scalar.iter().find(|(site, _)| site == load).map(|(_, a)| (a.param, a.dynamic.is_some())) + } + _ => None, + }) + .collect(); + (d.source.clone(), leaves) + } + + /// A store through a descriptor made of numbers in the code (neither a table entry nor a root + /// view): declared nowhere. + #[test] + fn a_store_through_a_descriptor_made_in_the_code_is_not_declared() { + let code = [ + 0xBE8C_03FF, + 0x0000_1000, // s_mov_b32 s12, 0x1000 + 0xBE8D_0380, // s_mov_b32 s13, 0 + 0xBE8E_03C1, // s_mov_b32 s14, -1 + 0xBE8F_03FF, + 0x0002_7FAC, // s_mov_b32 s15, 0x27fac + 0x342A_0084, // v_lshlrev_b32 v21, 4, v0 + 0xE078_1000, + 0x8003_0D15, // buffer_store_dwordx4 v[13:16], v21, s[12:15], 0 offen + ]; + let p = program(RootType::Table, vec![used(ResourceType::Uav, RootType::Table, 8)], &code); + assert!(super::stores(&p)); + let (source, _) = store_traced(&p); + assert!(!matches!(source, Source::Loaded { .. } | Source::Built { .. }), "{source:?}"); + assert!(!super::stores_in_bound_views(&p)); + } + + /// A store through the table's descriptor 1 loaded at an offset the program computes (s8, from + /// s0): any of the table's, whether or not the program also has the view heap. + #[test] + fn a_store_at_a_table_offset_the_program_computes_is_not_declared() { + let alone = [ + 0xBE85_0380, // s_mov_b32 s5, 0 + 0x8F08_8500, // s_lshl_b32 s8, s0, 5 + 0xF408_0302, + 0x08 << 25 | 0x20, // s_load_dwordx4 s[12:15], s[4:5], s8 + 0x20 + 0x342A_0084, // v_lshlrev_b32 v21, 4, v0 + 0xE078_1000, + 0x8003_0D15, // buffer_store_dwordx4 v[13:16], v21, s[12:15], 0 offen + ]; + // The same beside a read through a view loaded from the heap in s6. + let beside_heap = [ + 0xBE85_0380, // s_mov_b32 s5, 0 + 0xBE87_0380, // s_mov_b32 s7, 0 + 0x8F08_8500, // s_lshl_b32 s8, s0, 5 + 0xF408_0403, + 0x08 << 25, // s_load_dwordx4 s[16:19], s[6:7], s8 + 0xF408_0302, + 0x08 << 25 | 0x20, // s_load_dwordx4 s[12:15], s[4:5], s8 + 0x20 + 0x342A_0084, // v_lshlrev_b32 v21, 4, v0 + 0xE038_1000, + 0x8004_0D15, // buffer_load_dwordx4 v[13:16], v21, s[16:19], 0 offen + 0xE078_1000, + 0x8003_0D15, // buffer_store_dwordx4 v[13:16], v21, s[12:15], 0 offen + ]; + let table = || vec![used(ResourceType::Uav, RootType::Table, 8)]; + for p in [program(RootType::Table, table(), &alone), with_heap(program(RootType::Table, table(), &beside_heap), 6)] { + assert!(super::stores(&p)); + assert_eq!(store_traced(&p).1, [Some((1, true))], "the table's, at a computed offset"); + assert!(!super::stores_in_bound_views(&p)); + } + } + + /// A store through a descriptor chosen (`s_cselect_b64`) between the table's entry of + /// unordered access and one loaded from the heap: not declared, though one of the two is. + #[test] + fn a_store_through_a_descriptor_chosen_between_the_table_and_the_heap_is_not_declared() { + let code = [ + 0xBE85_0380, // s_mov_b32 s5, 0 + 0xBE87_0380, // s_mov_b32 s7, 0 + 0x8F08_8500, // s_lshl_b32 s8, s0, 5 + 0xF408_0403, + 0x08 << 25, // s_load_dwordx4 s[16:19], s[6:7], s8 + 0xF408_0302, + 0x7D << 25 | 0x20, // s_load_dwordx4 s[12:15], s[4:5], 0x20 + 0xBF06_8001, // s_cmp_eq_u32 s1, 0 + 0x8594_100C, // s_cselect_b64 s[20:21], s[12:13], s[16:17] + 0x8596_120E, // s_cselect_b64 s[22:23], s[14:15], s[18:19] + 0x342A_0084, // v_lshlrev_b32 v21, 4, v0 + 0xE078_1000, + 0x8005_0D15, // buffer_store_dwordx4 v[13:16], v21, s[20:23], 0 offen + ]; + let p = with_heap(program(RootType::Table, vec![used(ResourceType::Uav, RootType::Table, 8)], &code), 6); + assert!(super::stores(&p)); + let (source, leaves) = store_traced(&p); + assert!(matches!(source, Source::Select { .. }), "{source:?}"); + assert_eq!(leaves, [Some((1, false)), Some((2, true))], "the table's entry, then the heap's"); + assert!(!super::stores_in_bound_views(&p)); + } + + /// A program that reads through a view it loads from the heap (s8) and stores through a + /// descriptor built around its root view of unordered access (s[4:5]): declared. + #[test] + fn reads_from_the_heap_leave_a_store_through_a_root_view_declared() { + let code = [ + 0xBE89_0380, // s_mov_b32 s9, 0 + 0x8F0A_8500, // s_lshl_b32 s10, s0, 5 + 0xF408_0404, + 0x0A << 25, // s_load_dwordx4 s[16:19], s[8:9], s10 + 0x342A_0084, // v_lshlrev_b32 v21, 4, v0 + 0xE038_1000, + 0x8004_0D15, // buffer_load_dwordx4 v[13:16], v21, s[16:19], 0 offen + 0xBE86_03C1, // s_mov_b32 s6, -1 + 0xBE87_03FF, + 0x0002_7FAC, // s_mov_b32 s7, 0x27fac + 0xE078_1000, + 0x8001_0D15, // buffer_store_dwordx4 v[13:16], v21, s[4:7], 0 offen + ]; + let p = with_heap(program(RootType::Descriptor, vec![used(ResourceType::Uav, RootType::Descriptor, 0)], &code), 8); + assert!(super::stores(&p)); + assert!(matches!(store_traced(&p).0, Source::Built { .. })); + assert!(super::stores_in_bound_views(&p)); + // The same root view named as read only: the bind declares nothing for it. + let read_only = with_heap(program(RootType::Descriptor, vec![used(ResourceType::Srv, RootType::Descriptor, 0)], &code), 8); + assert!(!super::stores_in_bound_views(&read_only)); + } + + /// What a program reads through views it loads from the heap is no store: its stores through + /// the table entry its bind declares are declared all the same (`crate::draw::stores_declared`, + /// `LEONIDA_BATCH_HEAP_READS`); a store through the view it loaded is not. + #[test] + fn reads_through_views_loaded_from_the_heap_leave_bound_stores_declared() { + let reads = heap_reader(12); + assert!(super::stores(&reads), "the program stores"); + assert!(super::stores_in_bound_views(&reads)); + assert!(super::bound_programs(std::slice::from_ref(&reads))); + let stores = heap_reader(16); + assert!(super::stores(&stores)); + assert!(!super::stores_in_bound_views(&stores)); + assert!(!super::bound_programs(std::slice::from_ref(&stores))); + } } #[cfg(test)] diff --git a/d3d12/docs/switches.md b/d3d12/docs/switches.md index 25dd7882ba..57e7fd6546 100644 --- a/d3d12/docs/switches.md +++ b/d3d12/docs/switches.md @@ -6,7 +6,7 @@ It says which names exist and what the code's own comments say of them. It is ** settings and says nothing of what a switch gains: for that read [findings.md](findings.md) first, and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. -664 names; 624 have a sentence of a comment below, the others no comment or only a bare list. +668 names; 627 have a sentence of a comment below, the others no comment or only a bare list. - **Kind**: how the code reads it, where that can be told. "see the code" is a number, a path, a list or a switch read some other way; its default is not given here. @@ -148,10 +148,11 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_BARRIER_TEST` | see the code | | | | `leonida-gpu/copystat.rs` +2 | Whether an experiment on barriers is on (`LEONIDA_BARRIER_TEST`): bit 0 for `groups` (the title's barrier groups record no wait for earlier shader writes), bit 1 for `indirect` (the pass that bounds an indirect command r... | | `LEONIDA_BARRIER_WAITS` | on, `0` turns it off | yes | | yes | `leonida-gpu/copystat.rs` | `LEONIDA_AB=<s>,LEONIDA_BARRIER_WAITS` (off: both kinds of waits left out, as `both`). | | `LEONIDA_BATCH_DESCRIPTORS` | see the code | yes | | yes | `leonida-gpu/descriptor/host.rs` +2 | ... table instead of one `CopyDescriptorsSimple` call a slot (`LEONIDA_BATCH_DESCRIPTORS=1`, or by turns with `LEONIDA_AB`; off by default).... | +| `LEONIDA_BATCH_HEAP_READS` | on, `0` turns it off | yes | | | `leonida-gpu/draw.rs` +1 | A stage that loads views from the heap only to read through them ends none, unless `LEONIDA_BATCH_HEAP_READS=0` ([`batch_heap_reads`]), where every stage that loads views from the heap ends it. | | `LEONIDA_BATCH_KEPT` | on, `0` turns it off | yes | | yes | `leonida-gpu/host.rs` | (`LEONIDA_BATCH_KEPT`: read once, so that the whole submission goes one way while `LEONIDA_AB` flips it.) | | `LEONIDA_BATCH_SCRATCH_POOL` | on, `0` turns it off | yes | | yes | `leonida-gpu/host.rs` | Whether the scratch buffers of the batched clamps ([`HostList::batch_place`]) are shared by the lists (`LEONIDA_BATCH_SCRATCH_POOL=0`: a list keeps every one it ever took for as long as it lives, as before; `LEONIDA_AB`... | | `LEONIDA_BATCH_TEXTURE_DISPATCHES` | on, `0` turns it off | yes | | | `leonida-gpu/draw.rs` | `LEONIDA_BATCH_TEXTURE_DISPATCHES=0`: every dispatch ends the batch, as before (an A/B switch, `LEONIDA_AB`). | -| `LEONIDA_BATCH_WHY` | off unless set and not `0` | | | yes | `leonida-gpu/draw.rs` +2 | `LEONIDA_BATCH_WHY=1` counts what ends indirect batches and by which programs' declared ranges ([`batch_why_line`]). | +| `LEONIDA_BATCH_WHY` | off unless set and not `0` | | | yes | `leonida-gpu/draw.rs` +5 | `LEONIDA_BATCH_WHY=1` counts what ends indirect batches and by which programs' declared ranges ([`batch_why_line`]). | | `LEONIDA_BIND_CACHE` | see the code | | | | `leonida-gpu/draw.rs` | `LEONIDA_BIND_CACHE=0` sets them every time. | | `LEONIDA_BOOK` | see the code | | | | `leonida-gpu/book.rs` | The book is kept with device-removed data on (`LEONIDA_D3D12_DRED`) or the check; `LEONIDA_BOOK=0` keeps none. | | `LEONIDA_BURY_LAG` | see the code | | | | `leonida-gpu/host.rs` | Objects let go while nothing runs wait as well: lists recorded and not yet sent may name them. `LEONIDA_BURY_LAG=0`: not. | @@ -191,7 +192,9 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_COMMIT_FLOOR` | see the code | yes | | yes | `leonida-gpu/resource.rs` | `LEONIDA_COMMIT_FLOOR=1` (off by default; `LEONIDA_AB` can name it), and less left than `LEONIDA_COMMIT_FLOOR_MB` megabytes (4096 where it is unset: where `crate::residency` begins to speak of pressure by commit). | | `LEONIDA_COMMIT_FLOOR_MB` | see the code | | | yes | `leonida-gpu/resource.rs` | `LEONIDA_COMMIT_FLOOR=1` (off by default; `LEONIDA_AB` can name it), and less left than `LEONIDA_COMMIT_FLOOR_MB` megabytes (4096 where it is unset: where `crate::residency` begins to speak of pressure by commit). | | `LEONIDA_COMPOSE_NAN` | see the code | | | | `leonida-gpu/compose.rs` | A clamp to [0,1] that is safe for NaN and infinity (CLEAN, set when the pass is made from LEONIDA_COMPOSE_NAN): saturate() makes a NaN 0, which showed as black specks and a black sun where the upscaler or frame generatio... | +| `LEONIDA_CONSTANTS_ONCE` | on, `0` turns it off | yes | | | `leonida-gpu/host.rs` +1 | ... whose slots any other table showing the same bytes joins (`LEONIDA_CONSTANTS_ONCE`).... | | `LEONIDA_CONSTANT_MARKS` | see the code | | | | `leonida-gpu/shader_cache.rs` +1 | `LEONIDA_CONSTANT_MARKS=1` turns it on. | +| `LEONIDA_CONSTANT_SLOT_INLINE` | off unless set and not `0` | yes | | | `leonida-gpu/host.rs` | | | `LEONIDA_CONTENT_TABLES` | off unless set and not `0` | yes | | yes | `leonida-gpu/draw.rs` | Off unless `LEONIDA_CONTENT_TABLES=1`; by turns under A/B. | | `LEONIDA_COPIES_IN_PLACE` | see the code | | | | `leonida-gpu/host/place.rs` | The title's buffer copies, done on the card at their place in the list (`LEONIDA_COPIES_IN_PLACE`, on by default; `0`: all at submission, on the CPU, as before). | | `LEONIDA_COPYBACK_ELIDE` | see the code | yes | | yes | `leonida-gpu/shadow.rs` +1 | Copy-back elision (`LEONIDA_COPYBACK_ELIDE`): a big host copy in the card's memory that only the card ever changes is not copied back into title memory. | @@ -515,6 +518,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_STRUCTURED_BYTES` | see the code | | | | `leonida-gpu/descriptor/host.rs` | Off unless `LEONIDA_STRUCTURED_BYTES=1`: it leaves such a view structured on its buffer's copy, as before. | | `LEONIDA_SUBMIT_DEPTH` | see the code | | | | `leonida-gpu/queue/behind.rs` | How many submissions may be in the line when a submit call returns (`LEONIDA_SUBMIT_DEPTH`; 64: about two frames of the title's). | | `LEONIDA_SUBMIT_FRAMES` | see the code | yes | | yes | `leonida-gpu/queue/behind.rs` | How many presents may be in the line when a present call returns (`LEONIDA_SUBMIT_FRAMES`; 1: the frame before is sent, this one may not be; 0: both are). | +| `LEONIDA_SUBMIT_SENDER` | off unless set and not `0` | yes | | | `leonida-gpu/host.rs` | Whether anything was ever published ([`publish`]); until then [`wait_sent`] has nothing to wait for and does not take [`SENDS`], so a run without `LEONIDA_SUBMIT_SENDER` never touches it. | | `LEONIDA_SWEEP` | see the code | | | | `leonida-gpu/host.rs` | `LEONIDA_SWEEP=0` keeps everything, as before. | | `LEONIDA_SWEEP_SPANS` | on, `0` turns it off | yes | | | `leonida-gpu/draw.rs` | ...n the part cover, and joins those for the spans of a pass (`LEONIDA_SWEEP_SPANS=0`: the spans are made from every slot's range at every pass, as before, and a written slot that is also of the pass's part is looked at twi... | | `LEONIDA_SWEEP_WRAP` | on, `0` turns it off | yes | | | `leonida-gpu/resource.rs` | ...s released) starts again at the first address when `wrap` (`LEONIDA_SWEEP_WRAP=0`: it stayed past the end, as before, and the sweep looked at nothing).... | @@ -698,7 +702,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_LDS_EXACT` | see the code | | | yes | `leonida-shader/emit/lds_exact.rs` | `LEONIDA_LDS_EXACT=0` turns this off. | | `LEONIDA_LDS_INIT_HOIST` | see the code | | | yes | `leonida-shader/emit/lds_init.rs` | `LEONIDA_LDS_INIT_HOIST=0` turns it off. | | `LEONIDA_LEGACY_PLAIN` | see the code | | | yes | `leonida-shader/emit/lower.rs` +1 | ...ain product where the zero rule cannot apply, on any host (`LEONIDA_LEGACY_PLAIN=1`; off by default): of a value with itself, of two factors known to be finite, and with a finite constant that is not 0; and only the fini... | -| `LEONIDA_LOOPS_WAVE` | see the code | | | yes | `leonida-shader/emit/lower.rs` +4 | `LEONIDA_LOOPS_WAVE`: - unset or `1`: console wave64 compute programs on a host of 32-lane waves; - `0`: none; - `2`: every compute program. | +| `LEONIDA_LOOPS_WAVE` | see the code | | | yes | `leonida-shader/emit/lower.rs` +5 | `LEONIDA_LOOPS_WAVE`: - unset or `1`: console wave64 compute programs on a host of 32-lane waves; - `0`: none; - `2`: every compute program. | | `LEONIDA_LSHL_ADD_SCC` | see the code | | | | `leonida-shader/emit/lower.rs` | `LEONIDA_LSHL_ADD_SCC=0` restores the old lowering. | | `LEONIDA_MED3_CLAMP` | see the code | | | yes | `leonida-shader/emit/lower.rs` | Whether the median of a value and two constants that are normal numbers or infinities is a clamp (`Lower::med3_clamp`; `LEONIDA_MED3_CLAMP=0`: the general form, as before): the same bits, with fewer instructions (bounds... | | `LEONIDA_MESH_COUNTS` | see the code | | | yes | `leonida-shader/emit/lower.rs` +2 | A mesh program's own output counts (`LEONIDA_MESH_COUNTS=1`; off by default). | @@ -721,10 +725,10 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | Name | Kind | A/B | L | F | Named in | In the code's words | |---|---|---|---|---|---|---| -| `LEONIDA_HAIR_SHADOW_MASKS` | see the code | | | | `scripts/play-nvidia.ps1` | | +| `LEONIDA_HAIR_SHADOW_MASKS` | see the code | | yes | | `scripts/play-nvidia.ps1` | | | `LEONIDA_SKIP_RT_RESOLVE` | see the code | | | | `scripts/play-nvidia.ps1` | | | `LEONIDA_TITLE_GRAPHICS` | see the code | | | yes | `scripts/play-nvidia.ps1` | | -| `LEONIDA_WATER_TRANSMISSION` | see the code | | | yes | `scripts/play-nvidia.ps1` | | +| `LEONIDA_WATER_TRANSMISSION` | see the code | | yes | yes | `scripts/play-nvidia.ps1` | | ## Only in tests diff --git a/docs/README.md b/docs/README.md index 289ff89791..dccea162da 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ method, scope and caveats. No game data is included. | [boot_leads.md](boot_leads.md) | Open leads that may move the retail boot further (TLS at module index 0, feature level at device creation, command-list replay, descriptor words, shader corpus count, frame pacing), each with where it lands, how to implement it and how to test it, and a status table: BL-2, BL-5 and BL-6 are done, BL-3 and BL-4 have open pull requests, BL-1 waits for a retail confirmation. | | [rpf.md](rpf.md) | RPF9 archive layout, the carve tools and the unreadable encrypted TOC. | | [linux.md](linux.md) | Linux in one page: what runs natively and what runs under Wine or Proton, the Ubuntu packages, `Build.sh`, the runtime cross-build, and why there is no native Linux `gta6rt`. | -| [running.md](running.md) | Running the game per platform and GPU (Linux/Wine with AMD, Linux/Proton and Windows with NVIDIA, Windows with AMD, Intel, macOS): build, shaders, pipeline pre-compile, driver settings, environment, what to expect; each value measured by us, reported by others (linked) or TBD. | +| [running.md](running.md) | Running the game per platform and GPU (Linux/Wine with AMD and NVIDIA, Linux/Proton and Windows with NVIDIA, Windows with AMD, Intel, macOS): build, shaders, pipeline pre-compile, driver settings, environment, what to expect; each value measured by us, reported by others (linked) or TBD. | | [testing.md](testing.md) | Running the GPU tests on your own GPU: setup per OS, wave64 emulation, running without a GPU on Mesa llvmpipe, and known problems. | | [gpu_test_results.md](gpu_test_results.md) | Published GPU test results by hardware, driver and commit, with pass, skip and failure counts. | | [progress_dashboard.md](progress_dashboard.md) | A local page of what works, what changed since it last passed and what blocks next: unit and runtime tests, the translator contract by confirmation method, measured imports, corpus counts and, with `--github`, CI and the D3D- items (`tools/progress_dashboard.py`). | diff --git a/docs/linux_proton.md b/docs/linux_proton.md index 8117a01f53..fd73f6cb34 100644 --- a/docs/linux_proton.md +++ b/docs/linux_proton.md @@ -106,7 +106,10 @@ What it does: the run folder's `session/cache`, so it is cold; with a kept cache the caller's variables stay. - **Traces:** `gta6rt --run` with `--trace` and `--trace-d3d12`, a fresh `--overlay` and save folder in the run folder. Every other `LEONIDA_*` variable reaches the runtime unchanged, so `LEONIDA_INPUT_SCRIPT=a@210,a@240` - presses A as above. Arguments after `--` go to `gta6rt`. + presses A as above. Arguments after `--` go to `gta6rt`. The + [Linux, Wine, NVIDIA section of running.md](running.md#linux-wine-nvidia-geforce-rtx-3060-12-gb) reports runs + with a local change that leaves this trace off (`LEONIDA_NO_TRACE_D3D12=1`); `main`'s script always passes + `--trace-d3d12`. - **Summary:** `tools/game_run_summary.py` prints the run time, how it ended, exceptions by code, D3D12 calls by outcome, presents, the most frequent failing calls and the `[rt]` lines by category with numbers masked. It never prints a log line. `--screenshot-every S` captures the game window into the run folder (ImageMagick's `import` and diff --git a/docs/running.md b/docs/running.md index a6c003ba2f..b155f4d76a 100644 --- a/docs/running.md +++ b/docs/running.md @@ -171,6 +171,46 @@ Reported by others: [#1608, comment 7184700506](https://github.com/ubiquitariani The black stretch before it is graphics pipelines of 1-2.6 MB SPIR-V compiling one at a time, 5-10 s each. - **Known problems:** nothing ray-traced is in the picture. +## Linux, Wine, NVIDIA (GeForce RTX 3060 12 GB) + +Reported by others: [#2464, comment 7299367912](https://github.com/ProjectLeonida/mandy/issues/2464#issuecomment-7299367912) +and [comment 7300173397](https://github.com/ProjectLeonida/mandy/issues/2464#issuecomment-7300173397) (desktop, 31 GB +of RAM, no swap, 12 threads; NVIDIA 620.70.10; Debian 13, kernel 6.12.118; Wine 11.22 staging). Not run by us. + +- **Build:** clang-cl + xwin cross-build of `main` `d8ca18240`, RelWithDebInfo. +- **Shaders:** `make_game.py --stages check,shaders,runtime --wave64-emulate on`: 26,503 main, 2,684 library, + 2,713 FSPX, 52 BVH and 12 executable sets, `spirv-val` clean. +- **Pipeline pre-compile:** none. The runs reused a 1.7 GB journal that three earlier runs had filled; the opening + sequence's night scene alone built 763 graphics and 619 compute pipelines (2,296 modules, 732 MiB of SPIR-V, + 45 minutes in `vkCreate*Pipeline` across the run), and the builds ended within two minutes of the last present. +- **Driver and OS:** no GPU timeout change. The runs sat in a systemd cgroup with `MemoryMax=24G` and no swap. With + the defaults one run was killed at 22.3 GB, 21 minutes in, before a world frame; another had drawn the city night + street when it was killed at 22.2 GB. The 1024/2048 arenas hold the earlier world runs at 19-20 GB, but the later + shots still reached 23.6 GB. +- **Environment:** `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_COMPUTE_WARMUP=0`, + `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_FRAME_PACING=1`, `LEONIDA_PRESENT_NO_TEAR=1`, `LEONIDA_SUBMIT_ASYNC=4`, + `LEONIDA_KEYBOARD_PAD=always`, `LEONIDA_ARENA_MB=1024`, `LEONIDA_GEOMETRY_MB=2048`, + `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_SKIP_COMPUTE=,...` with the names of this pack's 723 + library compute programs of 2 MiB or more (the page's 724 is the maintainers' count; 676 of theirs are + ray-tracing resolve), and the title's watchdog off with its KICK values set. `LEONIDA_STRAY_RO_HEAL=1` is needed + on this build and driver: without it a run ended at 47 s (exit 5) writing to a title page the runtime had marked + read-only. That last detail is from an earlier run on the same machine, not in the two linked comments. +- **Command:** `scripts/run_game_wine.sh --build --exe + --game-dir --shaders --out --seconds 3600 --visible`, with + the arguments described in [linux_proton.md](linux_proton.md#running-the-game-under-wine-with-one-command). These + runs used a local change to the script: `LEONIDA_NO_TRACE_D3D12=1` makes it pass no `--trace-d3d12`, while `main` + always passes it; the trace costs a mutex, an fprintf and an fflush per D3D12 call, so a run with `main`'s script + writes it too. +- **What to expect:** the first-run UI at 30 frames/s, the account picker, then the story load; with a warm journal + the first world frame is 20-34 minutes in. The opening sequence draws at 1-3 frames per 10-16 s, 0.06-0.30 + frames/s, with cgroup memory at 19-20 GB and up to 23.6 GB later in the sequence. 12 GB of VRAM does not hold the + scene; the earlier runs spilled VRAM to host memory once the 12 GB card was full. +- **Known problems:** the night scene ends a run in one of two ways. With the list values on, one console value + wait stayed unmet for 101 minutes with no presents and no queue calls, and no gate was released unmet, including + in the stalled case; with `LEONIDA_LIST_VALUES=0` the scene draws further and then the device is lost (five + compute queues in flight, and `VK_EXT_device_fault` gave no address on this driver). What the picture lacks there + is not measured. + ## Windows, NVIDIA Reported by others: [#2019](https://github.com/ubiquitarianism/leonida/issues/2019) (RTX 5090 32 GB, driver 616.92,