From 8b89520b13cfeeb802f7bba28199c1ea70ee2322 Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 06:47:56 +0100 Subject: [PATCH 1/7] docs/running.md: a Linux + Wine + NVIDIA profile that draws world frames (DOCS-RUNNING-LINUX-WINE-NVIDIA) The page has Linux RADV, a Proton NVIDIA report and Windows sections, but no Linux + Wine + NVIDIA profile. This one is a desktop RTX 3060 12 GB with Wine 11.22: it draws the first-run UI at 30 frames/s, loads the story and draws the opening sequence's prison yard, city street and carnival scenes at 1-3 frames per 10-16 s, with host memory at 19-20 GB and up to 23.6 GB. The section carries the build, shader pack, environment (including LEONIDA_STRAY_RO_HEAL=1, without which a run ends at 47 s here) and what to expect, and names the two ends of the carnival scene as known problems: a console value wait held for 101 minutes with the list values on, and a device loss with LEONIDA_LIST_VALUES=0. Every value comes from the RUN blocks posted on #2464, which the section links; no game data is added. AI-assisted. --- docs/running.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/running.md b/docs/running.md index a6c003ba2f..d72248cdd1 100644 --- a/docs/running.md +++ b/docs/running.md @@ -171,6 +171,37 @@ 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 filled a 1.7 GB journal themselves; the opening sequence's carnival 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 scene's picture came up as those builds finished. +- **Driver and OS:** no GPU timeout change. The runs sat in a systemd cgroup with `MemoryMax=24G` and no swap; with + the defaults the kernel killed two of them at 22.2-22.3 GB before a world frame. +- **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=`, 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. +- **Command:** `scripts/run_game_wine.sh` with the environment above (`--visible` for a window). +- **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's scenes (the prison yard by day, the city street + at night with its credits, the night carnival scene) draw at 1-3 frames per 10-16 s, 0.06-0.30 frames/s, one to + three submissions a frame, with host memory at 19-20 GB and up to 23.6 GB later in the sequence: 12 GB of VRAM + does not hold the scene, so the runtime spills to host memory (logged once). +- **Known problems:** the carnival scene ends a run in one of two ways. With the list values on, one console value + wait stayed held for 101 minutes with no presents and no queue calls, and the stalled release did not fire; 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, From 6b6f75abbb885fe759c3f323eaefc7a685466084 Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 07:11:10 +0100 Subject: [PATCH 2/7] docs/running.md: source the Linux + Wine + NVIDIA details and index the profile - separate the 22.2 GB run that drew the city night street from the 22.3 GB default-arena run, as the reports do; - say the 1.7 GB journal was warm from three earlier runs, not filled by these runs; - replace the unsourced scene names and the submissions-per-frame count with the reports' words, and give the 47 s STRAY_RO_HEAL observation its provenance; - say that 724 is the maintainers' count and 723 is this pack's, that the skip list takes name fragments and is the ray-tracing programs; - give the full run_game_wine.sh invocation and name the local trace-off change; - index the profile in docs/README.md and point linux_proton.md at it. AI-assisted. --- docs/README.md | 2 +- docs/linux_proton.md | 5 ++++- docs/running.md | 43 ++++++++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1bc9ffcbbc..2e9482e626 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. | | [modding.md](modding.md) | The mod format: `mods//mod.json`, checked and loaded in name order by `gta6rt`; a swap takes effect once the game's archetype lookup is hooked (needs the executable, RT-5). A mod names game models and holds no game data. | diff --git a/docs/linux_proton.md b/docs/linux_proton.md index 61627b69a9..ace01d88e2 100644 --- a/docs/linux_proton.md +++ b/docs/linux_proton.md @@ -99,7 +99,10 @@ What it does: signal. - **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 d72248cdd1..e9716da2a7 100644 --- a/docs/running.md +++ b/docs/running.md @@ -180,27 +180,36 @@ of RAM, no swap, 12 threads; NVIDIA 620.70.10; Debian 13, kernel 6.12.118; Wine - **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 filled a 1.7 GB journal themselves; the opening sequence's carnival 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 scene's picture came up as those builds finished. -- **Driver and OS:** no GPU timeout change. The runs sat in a systemd cgroup with `MemoryMax=24G` and no swap; with - the defaults the kernel killed two of them at 22.2-22.3 GB before a world frame. +- **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=`, 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. -- **Command:** `scripts/run_game_wine.sh` with the environment above (`--visible` for a window). + `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's scenes (the prison yard by day, the city street - at night with its credits, the night carnival scene) draw at 1-3 frames per 10-16 s, 0.06-0.30 frames/s, one to - three submissions a frame, with host memory at 19-20 GB and up to 23.6 GB later in the sequence: 12 GB of VRAM - does not hold the scene, so the runtime spills to host memory (logged once). -- **Known problems:** the carnival scene ends a run in one of two ways. With the list values on, one console value - wait stayed held for 101 minutes with no presents and no queue calls, and the stalled release did not fire; 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. + 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 host 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 From 5ef76aa9aa0d5d633892fbfeb5e2f4a739fd1e4a Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 07:35:25 +0100 Subject: [PATCH 3/7] docs/running.md: say cgroup memory for the measured 19-20 GB The runs report the cgroup's peak, as the RUN blocks do; the VRAM spilled to host memory is a different figure. AI-assisted. --- docs/running.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/running.md b/docs/running.md index e9716da2a7..b155f4d76a 100644 --- a/docs/running.md +++ b/docs/running.md @@ -203,7 +203,7 @@ of RAM, no swap, 12 threads; NVIDIA 620.70.10; Debian 13, kernel 6.12.118; Wine 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 host memory at 19-20 GB and up to 23.6 GB later in the sequence. 12 GB of VRAM does not hold the + 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 From 1f9b893901076cb3500c9a8e2126e04acba9b962 Mon Sep 17 00:00:00 2001 From: enlight3d <19186686+enlight3d@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:01:58 +0100 Subject: [PATCH 4/7] LEONIDA_BATCH_WHY counts the batches ended for undeclared stores by reason, all of them With `LEONIDA_INDIRECT_BATCH=4` the frame-rate line listed the batches ended by a program whose stores are not all declared only by program, the first eight, which left most of those ends unattributed. A second line, right after the first, now gives the total for each reason (the line of the shaders looked at and the programs comes third). It tells a stage that loads buffer views from the heap (a `ResourceHeap` root parameter) only to read through them (its stores bound to it, not, or not looked at yet) from one that stores through such a view (`crate::picked::picks`). What `stores_bound` and `picks` say of a stage is asked for there if nobody has yet. The batches ended for a full table and for another source are counted apart (`Table::full_for`); the first line keeps their sum, so it reads as before. A test in `bound_tests` pins what the next change relies on: `stores_in_bound_views` takes a program that reads through a view it loads from the heap and stores through a table entry of unordered access as declared, and the same program storing through the view it loaded as not. AI-assisted (Claude). Tested on RTX 3090 24 GB: the new tests failed by assertion before the code (the bound_tests one passed on main, as it should), and pass with it, default and diagnostics. Co-Authored-By: Claude Opus 5.5 --- d3d12/crates/leonida-gpu/src/draw.rs | 261 ++++++++++++++++-- .../crates/leonida-gpu/src/indirect/batch.rs | 33 +++ d3d12/crates/leonida-gpu/src/picked.rs | 12 + d3d12/crates/leonida-gpu/src/pipeline.rs | 52 ++++ 4 files changed, 330 insertions(+), 28 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index 812766e082..d62a664b25 100644 --- a/d3d12/crates/leonida-gpu/src/draw.rs +++ b/d3d12/crates/leonida-gpu/src/draw.rs @@ -871,31 +871,152 @@ fn stores_declared(p: &HostPipeline, builder: bool) -> bool { }) } -/// 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 { +/// Why [`stores_declared`] says no of a pipeline, as the frame-rate line counts the batches that +/// 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 picks from the heap (`crate::picked::picks`). + HeapStores, + /// A stage picks views from the heap 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 picks 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 picks views from the heap: 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 picks from the heap (`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, stages: &[StoringStage]) -> Undeclared { if builder { - return "the structure builder"; - } - for stage in &p.stages { - let t = stage.translated(); - if !t.stores { - 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"; + return Undeclared::Builder; + } + for s in stages { + if s.by_address { + return Undeclared::ByAddress; + } + if s.past_views { + return Undeclared::PastViews; + } + if s.heap { + // (A stage whose stores are all bound stores through no view of the heap.) + return 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, + }; } - if !crate::pipeline::stores_bound(&stage.shader, t) { - return "a view not declared at its bind, or not looked at yet"; + match s.bound { + Some(true) => {} + Some(false) => return Undeclared::NotBound, + None => return 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`]). What [`crate::pipeline::stores_bound`] and [`crate::picked::picks`] +/// say of each stage that stores is asked for here if nobody has yet. +#[cfg(feature = "diagnostics")] +fn undeclared_why(p: &HostPipeline, builder: bool) -> &'static str { + let stages: Vec = p + .stages + .iter() + .filter(|stage| stage.translated().stores) + .map(|stage| { + let t = stage.translated(); + StoringStage { + by_address: t.stores_by_address, + past_views: t.stores_past_views, + heap: t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES), + bound: crate::pipeline::bound_answer(&stage.shader, t), + picks: crate::picked::answer(&stage.shader, &t.picks), + } + }) + .collect(); + undeclared_kind(builder, &stages).label() } /// Diagnostics: `LEONIDA_BATCH_WHY=1` counts what ends indirect batches and by which @@ -909,9 +1030,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 +1047,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 +1060,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(); @@ -6246,6 +6380,9 @@ impl State { }; 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 +6530,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); } } } @@ -7060,6 +7197,74 @@ 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 picks 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, stages); + assert_eq!(undeclared_kind(true, &[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 picked 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); + } + + #[test] + fn each_reason_has_a_label_of_its_own() { + 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..3a7fdbc039 100644 --- a/d3d12/crates/leonida-gpu/src/indirect/batch.rs +++ b/d3d12/crates/leonida-gpu/src/indirect/batch.rs @@ -325,6 +325,14 @@ 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 +401,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 f8a7652f65..17583c6744 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; @@ -1344,6 +1356,46 @@ 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 picks a buffer 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 picked 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 + ]; + let mut p = program(RootType::Table, vec![used(ResourceType::Uav, RootType::Table, 8)], &code); + p.layout.push(RootParam { root: RootType::ResourceHeap, table_offset_dwords: 0, sgprs: 1, base_register: 0, user_data: 6, slot: 2 }); + p.io = StageIo::Cs(ComputeIo { rsrc2: 7 << 1, threads: [32, 1, 1] }); + p + } + + /// What a program reads through views it picks 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 picked is not. + #[test] + fn reads_through_views_picked_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)] From 43a6ea46b4d38b2dc4fbca0e046e60d9026fcacf Mon Sep 17 00:00:00 2001 From: enlight3d <19186686+enlight3d@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:01:58 +0100 Subject: [PATCH 5/7] The test of one stage's stores in stores_declared is a function of its own `stores_declared` keeps its signature (others call it); what it asks of each stage is now `stage_declared`, which takes the stage's facts and `stores_bound` as a closure asked last, as before. The reasons `LEONIDA_BATCH_WHY` counts go through the same test, so they cannot drift from what ends a batch. A test pins what it says today. No change of behaviour. AI-assisted (Claude). Tested on RTX 3090 24 GB: the draw, bound and batch tests pass. Co-Authored-By: Claude Opus 5.5 --- d3d12/crates/leonida-gpu/src/draw.rs | 62 ++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index d62a664b25..c6e8756ca2 100644 --- a/d3d12/crates/leonida-gpu/src/draw.rs +++ b/d3d12/crates/leonida-gpu/src/draw.rs @@ -865,12 +865,24 @@ fn stores_declared(p: &HostPipeline, builder: bool) -> bool { !builder && p.stages.iter().all(|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)) + stage_declared( + t.stores, + t.stores_past_views, + t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES), + || crate::pipeline::stores_bound(&stage.shader, t), + ) }) } +/// Whether what one stage stores to buffers is all declared at its bind ([`stores_declared`]): +/// it stores nothing (`stores`: it can); or it stores through buffer views alone (`past_views`: +/// not), picks no view from the heap (`heap`: it has the root SRV +/// [`leonida_shader::emit::SLOT_STRIDES`]), 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(stores: bool, past_views: bool, heap: bool, bound: impl FnOnce() -> bool) -> bool { + !stores || (!(past_views || heap) && bound()) +} + /// Why [`stores_declared`] says no of a pipeline, as the frame-rate line counts the batches that /// ends ([`undeclared_kind`], [`batch_why_line`]). #[cfg(any(test, feature = "diagnostics"))] @@ -962,27 +974,27 @@ fn undeclared_kind(builder: bool, stages: &[StoringStage]) -> Undeclared { return Undeclared::Builder; } for s in stages { - if s.by_address { - return Undeclared::ByAddress; - } - if s.past_views { - return Undeclared::PastViews; + if stage_declared(true, s.past_views, s.heap, || s.bound == Some(true)) { + continue; } - if s.heap { + 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.) - return match (s.picks, s.bound) { + 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, - }; - } - match s.bound { - Some(true) => {} - Some(false) => return Undeclared::NotBound, - None => return Undeclared::NotYet, - } + } + } else if s.bound == Some(false) { + Undeclared::NotBound + } else { + Undeclared::NotYet + }; } Undeclared::Other } @@ -7095,7 +7107,21 @@ fn compute_word(p: &HostPipeline, kind: u32) -> Option<(u32, u32)> { #[cfg(test)] mod batch_tests { - use super::batch_stale; + use super::{batch_stale, stage_declared}; + + /// What a stage that stores needs for a batch to stay open past it + /// (`LEONIDA_INDIRECT_BATCH=4`): it stores through buffer views alone, picks 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(false, true, true, not_asked), "it stores nothing"); + assert!(!stage_declared(true, true, false, not_asked), "it stores past views"); + assert!(!stage_declared(true, false, true, not_asked), "it picks views from the heap"); + assert!(!stage_declared(true, true, true, not_asked)); + assert!(stage_declared(true, false, false, || true)); + assert!(!stage_declared(true, false, false, || false), "a store through a view its bind does not declare"); + } use crate::host::Spans; /// With 3 an execution leaves the open batch only when shaders recorded since its pass may From 51a2ef1f542b28a75646e91cf36592bbafbbf410 Mon Sep 17 00:00:00 2001 From: enlight3d <19186686+enlight3d@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:01:58 +0100 Subject: [PATCH 6/7] LEONIDA_BATCH_HEAP_READS: a program that only reads through views of the heap keeps the batch open (D3D12-BATCH-HEAP-READS) With `LEONIDA_INDIRECT_BATCH=4` (what `scripts/play-nvidia.ps1` sets) an open batch of clamped indirect records stays open past a dispatch or draw whose stores all go through views its bind declares. A stage with the root SRV `SLOT_STRIDES` ended it before `stores_bound` was asked: that root SRV marks a program that picks views from the heap, but the translator gives it to every buffer access through such a view, reads included. `stores_bound` already says no of a store through a view picked from the heap or from a table at an offset the program computes, so the batch still ends for those. `LEONIDA_BATCH_HEAP_READS=1` lets `stores_bound` decide for such a stage, as for any other; off by default until an A/B measures it (`LEONIDA_AB` can turn it on and off). `LEONIDA_BATCH_WHY` follows the same test, so with the switch on its "reads only from the heap (stores bound yes)" count goes to nothing. d3d12/docs/switches.md regenerated. Measured on an RTX 3090 (NVIDIA 621.40) in the world with mode 4, before this change: some 600 clamp passes a frame, about 2.3 ms of the card's time; about 509 batches a frame (85 % of the ends) ended by a program whose stores are not all declared, and the 13 programs the per-program list named all picked views from the heap, none of them among those found storing through such views. AI-assisted (Claude). Tested on RTX 3090 24 GB: the two new tests failed by assertion with the switch taken but not used, and pass with it, default and diagnostics; the batch and indirect tests pass. Co-Authored-By: Claude Opus 5.5 --- d3d12/crates/leonida-gpu/src/draw.rs | 96 +++++++++++++++---- .../crates/leonida-gpu/src/indirect/batch.rs | 1 + d3d12/docs/switches.md | 3 +- 3 files changed, 79 insertions(+), 21 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index c6e8756ca2..5baaa21d40 100644 --- a/d3d12/crates/leonida-gpu/src/draw.rs +++ b/d3d12/crates/leonida-gpu/src/draw.rs @@ -856,12 +856,15 @@ fn batch_stale(mode: u8, wrote: bool, in_list: impl FnOnce() -> bool, since: imp /// 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. +/// [`State::heap_buffers`]; with [`batch_heap_reads`] a stage that only reads through them is +/// let through, as `stores_bound` says no of one that stores through them), 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 from the heap or 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 { + let heap_reads = batch_heap_reads(); !builder && p.stages.iter().all(|stage| { let t = stage.translated(); @@ -869,6 +872,7 @@ fn stores_declared(p: &HostPipeline, builder: bool) -> bool { t.stores, t.stores_past_views, t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES), + heap_reads, || crate::pipeline::stores_bound(&stage.shader, t), ) }) @@ -879,11 +883,32 @@ fn stores_declared(p: &HostPipeline, builder: bool) -> bool { /// not), picks no view from the heap (`heap`: it has the root SRV /// [`leonida_shader::emit::SLOT_STRIDES`]), 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(stores: bool, past_views: bool, heap: bool, bound: impl FnOnce() -> bool) -> bool { - !stores || (!(past_views || heap) && bound()) +fn stage_declared(stores: bool, past_views: bool, heap: bool, heap_reads: bool, bound: impl FnOnce() -> bool) -> bool { + !stores || (!past_views && (heap_reads || !heap) && bound()) } -/// Why [`stores_declared`] says no of a pipeline, as the frame-rate line counts the batches that +/// `LEONIDA_BATCH_HEAP_READS=1` (`LEONIDA_AB` can turn it on and off while the title runs): with +/// `LEONIDA_INDIRECT_BATCH=4`, a stage that picks views from the heap no longer ends 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`). +/// +/// The translator gives a program the root SRV [`leonida_shader::emit::SLOT_STRIDES`] for any +/// buffer access through a view it picks from the heap, reads included, 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. A program that +/// only reads through views of the heap writes nothing through them. +/// +/// Measured on an RTX 3090 (NVIDIA 621.40) in the world with `LEONIDA_INDIRECT_BATCH=4`, the +/// setting of `scripts/play-nvidia.ps1`: 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 (85 % of the ends) ended by a +/// program whose stores are not all declared. The 13 programs the per-program list named (80 of +/// those ends) all picked views from the heap, and none of them was among the shaders +/// `crate::picked` found storing through such views. Off by default until an A/B measures it. +fn batch_heap_reads() -> bool { + crate::asked!("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)] @@ -969,12 +994,12 @@ struct StoringStage { /// ([`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, stages: &[StoringStage]) -> Undeclared { +fn undeclared_kind(builder: bool, heap_reads: bool, stages: &[StoringStage]) -> Undeclared { if builder { return Undeclared::Builder; } for s in stages { - if stage_declared(true, s.past_views, s.heap, || s.bound == Some(true)) { + if stage_declared(true, s.past_views, s.heap, heap_reads, || s.bound == Some(true)) { continue; } return if s.by_address { @@ -1028,7 +1053,7 @@ fn undeclared_why(p: &HostPipeline, builder: bool) -> &'static str { } }) .collect(); - undeclared_kind(builder, &stages).label() + undeclared_kind(builder, batch_heap_reads(), &stages).label() } /// Diagnostics: `LEONIDA_BATCH_WHY=1` counts what ends indirect batches and by which @@ -7108,6 +7133,7 @@ fn compute_word(p: &HostPipeline, kind: u32) -> Option<(u32, u32)> { #[cfg(test)] mod batch_tests { use super::{batch_stale, stage_declared}; + use crate::host::Spans; /// What a stage that stores needs for a batch to stay open past it /// (`LEONIDA_INDIRECT_BATCH=4`): it stores through buffer views alone, picks no view from the @@ -7115,14 +7141,27 @@ mod batch_tests { #[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(false, true, true, not_asked), "it stores nothing"); - assert!(!stage_declared(true, true, false, not_asked), "it stores past views"); - assert!(!stage_declared(true, false, true, not_asked), "it picks views from the heap"); - assert!(!stage_declared(true, true, true, not_asked)); - assert!(stage_declared(true, false, false, || true)); - assert!(!stage_declared(true, false, false, || false), "a store through a view its bind does not declare"); + assert!(stage_declared(false, true, true, false, not_asked), "it stores nothing"); + assert!(!stage_declared(true, true, false, false, not_asked), "it stores past views"); + assert!(!stage_declared(true, false, true, false, not_asked), "it picks views from the heap"); + assert!(!stage_declared(true, true, true, false, not_asked)); + assert!(stage_declared(true, false, false, false, || true)); + assert!(!stage_declared(true, false, false, false, || false), "a store through a view its bind does not declare"); + } + + /// `LEONIDA_BATCH_HEAP_READS`: a stage that picks 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(true, false, true, true, || true)); + assert!(!stage_declared(true, false, true, true, || false)); + assert!(!stage_declared(true, true, true, true, not_asked), "it stores past views"); + assert!(stage_declared(false, true, true, true, not_asked), "it stores nothing"); + assert!(stage_declared(true, false, false, true, || true)); + assert!(!stage_declared(true, false, true, false, not_asked), "off: as before"); } - use crate::host::Spans; /// 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 @@ -7241,8 +7280,8 @@ mod undeclared_tests { #[test] fn batch_ends_for_undeclared_stores_are_told_apart() { use Undeclared::*; - let kind = |stages: &[StoringStage]| undeclared_kind(false, stages); - assert_eq!(undeclared_kind(true, &[plain(Some(true))]), Builder); + 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 picked from the heap and stored through... @@ -7266,6 +7305,23 @@ mod undeclared_tests { 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() { let labels: std::collections::BTreeSet<_> = Undeclared::ALL.iter().map(|k| k.label()).collect(); diff --git a/d3d12/crates/leonida-gpu/src/indirect/batch.rs b/d3d12/crates/leonida-gpu/src/indirect/batch.rs index 3a7fdbc039..ecdc47df8f 100644 --- a/d3d12/crates/leonida-gpu/src/indirect/batch.rs +++ b/d3d12/crates/leonida-gpu/src/indirect/batch.rs @@ -325,6 +325,7 @@ 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 diff --git a/d3d12/docs/switches.md b/d3d12/docs/switches.md index f8ac0a9aea..36e50ff3f3 100644 --- a/d3d12/docs/switches.md +++ b/d3d12/docs/switches.md @@ -147,10 +147,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` | off unless set and not `0` | yes | | | `leonida-gpu/draw.rs` +1 | `LEONIDA_BATCH_HEAP_READS=1` (`LEONIDA_AB` can turn it on and off while the title runs): with `LEONIDA_INDIRECT_BATCH=4`, a stage that picks views from the heap no longer ends the open batch for that alone ([`stage_decla... | | `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. | From 685a2e5c200aa5ce95f1d6f41665602cd7bf42c6 Mon Sep 17 00:00:00 2001 From: enlight3d <19186686+enlight3d@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:27:43 +0100 Subject: [PATCH 7/7] LEONIDA_BATCH_HEAP_READS on by default, read once per decision; more tests of what stores_bound refuses The A/B on an RTX 3090 (NVIDIA 621.40, LEONIDA_AB=10,LEONIDA_BATCH_HEAP_READS, 900 s, 33 pairs of phases, standing in the world with what scripts/play-nvidia.ps1 sets) measured the switch: the frame's median 2.2 ms shorter (+-0.17), the card busy 1.9 ms less, 122 batches opened a frame instead of 601, the ends for undeclared stores 9 instead of 507 (the 498 of "reads only from the heap (stores bound yes)" with it off), the ends for a record declared written 34 instead of 20, the clamp passes 0.8 ms of the card's time instead of 2.3; the lists' steps on the CPU 0.5 ms longer; four captures in each of two runs alike. So it is on unless `LEONIDA_BATCH_HEAP_READS=0` (`crate::toggled!`, still switched by `LEONIDA_AB`), and `0` gives the old behaviour. `stores_told` reads the switch once: `stores_declared` answers with the setting it decided under (`Declared`), and `undeclared_why` takes it, so a phase change of `LEONIDA_AB` between the two cannot label an end by the other setting. The read is in `stages_declared`, where a test reaches it through a thread-local switch for tests (as titlewrite's `ON_IN_TEST`). A stage's facts are a struct with named fields (`StageFacts`). `undeclared_why` answers for the structure builder before it looks at stages, and asks `picks` only of stages that load views from the heap and `stores_bound` only of those that store through views alone. New tests of `stores_in_bound_views`: a store through a descriptor made of numbers in the code, through the table's entry at an offset the program computes (with and without the view heap among its parameters), and through a descriptor chosen with `s_cselect` between the table's entry and one loaded from the heap are not declared; a program that reads through a view it loads from the heap and stores through its root view of unordered access is. The label test checks with an exhaustive match that every reason is listed. The docs say "loads buffer views from the heap" (the root SRV `SLOT_STRIDES` is given for a descriptor loaded from a `ResourceHeap` parameter), `batches()` says what the switch changes, and the measurements name their commits. d3d12/docs/switches.md: the switch's row. `stores_declared` now returns `Declared` and `undeclared_why` takes the switch's value: a caller elsewhere passes `stores_declared(p, builder).all` and `undeclared_why(p, builder, heap_reads)`. AI-assisted (Claude). Tested on RTX 3090 24 GB: the test of the switch's reading and the test of the default failed by assertion before the code and pass with it; the new tests of `stores_in_bound_views` pass and each fails under the mutation it is for; default and diagnostics. Co-Authored-By: Claude Opus 5.5 --- d3d12/crates/leonida-gpu/src/draw.rs | 287 ++++++++++++++++------- d3d12/crates/leonida-gpu/src/pipeline.rs | 165 ++++++++++++- d3d12/docs/switches.md | 4 +- 3 files changed, 358 insertions(+), 98 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/draw.rs b/d3d12/crates/leonida-gpu/src/draw.rs index 5baaa21d40..659395c571 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,58 +856,108 @@ 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`]; with [`batch_heap_reads`] a stage that only reads through them is -/// let through, as `stores_bound` says no of one that stores through them), 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 from the heap or 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 { - let heap_reads = batch_heap_reads(); - !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(); - stage_declared( - t.stores, - t.stores_past_views, - t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES), - heap_reads, - || crate::pipeline::stores_bound(&stage.shader, t), - ) - }) + (StageFacts::of(t), move || crate::pipeline::stores_bound(&stage.shader, t)) + }), + ) +} + +/// 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()) } -/// Whether what one stage stores to buffers is all declared at its bind ([`stores_declared`]): -/// it stores nothing (`stores`: it can); or it stores through buffer views alone (`past_views`: -/// not), picks no view from the heap (`heap`: it has the root SRV -/// [`leonida_shader::emit::SLOT_STRIDES`]), 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(stores: bool, past_views: bool, heap: bool, heap_reads: bool, bound: impl FnOnce() -> bool) -> bool { - !stores || (!past_views && (heap_reads || !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=1` (`LEONIDA_AB` can turn it on and off while the title runs): with -/// `LEONIDA_INDIRECT_BATCH=4`, a stage that picks views from the heap no longer ends 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`). +/// `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 the root SRV [`leonida_shader::emit::SLOT_STRIDES`] for any -/// buffer access through a view it picks from the heap, reads included, 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. A program that -/// only reads through views of the heap writes nothing through them. +/// 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`, the -/// setting of `scripts/play-nvidia.ps1`: 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 (85 % of the ends) ended by a -/// program whose stores are not all declared. The 13 programs the per-program list named (80 of -/// those ends) all picked views from the heap, and none of them was among the shaders -/// `crate::picked` found storing through such views. Off by default until an A/B measures it. +/// 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 { - crate::asked!("LEONIDA_BATCH_HEAP_READS") + #[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 @@ -919,15 +971,16 @@ enum Undeclared { ByAddress, /// A stage stores otherwise than through a buffer view (scalar stores, code not known). PastViews, - /// A stage stores through a view it picks from the heap (`crate::picked::picks`). + /// 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 picks views from the heap 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. + /// 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 picks views from the heap, and neither of those is known yet. + /// 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, @@ -980,12 +1033,14 @@ struct StoringStage { by_address: bool, /// `crate::pipeline::Translated::stores_past_views`. past_views: bool, - /// It picks views from the heap: it has the root SRV [`leonida_shader::emit::SLOT_STRIDES`]. + /// 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 picks from the heap (`crate::picked::picks`): `None` + /// 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, } @@ -999,7 +1054,7 @@ fn undeclared_kind(builder: bool, heap_reads: bool, stages: &[StoringStage]) -> return Undeclared::Builder; } for s in stages { - if stage_declared(true, s.past_views, s.heap, heap_reads, || s.bound == Some(true)) { + if stage_declared(StageFacts { stores: true, past_views: s.past_views, heap: s.heap }, heap_reads, || s.bound == Some(true)) { continue; } return if s.by_address { @@ -1034,26 +1089,33 @@ fn by_reason(mut counts: Vec<(&'static str, u64)>, frames: f64) -> String { } /// Diagnostics: why [`stores_declared`] says no of `p`, for the first stage that stores -/// ([`undeclared_kind`]). What [`crate::pipeline::stores_bound`] and [`crate::picked::picks`] -/// say of each stage that stores is asked for here if nobody has yet. +/// ([`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) -> &'static str { +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: t.stores_past_views, - heap: t.host.root_srvs.contains(&leonida_shader::emit::SLOT_STRIDES), - bound: crate::pipeline::bound_answer(&stage.shader, t), - picks: crate::picked::answer(&stage.shader, &t.picks), + 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(builder, batch_heap_reads(), &stages).label() + undeclared_kind(false, heap_reads, &stages).label() } /// Diagnostics: `LEONIDA_BATCH_WHY=1` counts what ends indirect batches and by which @@ -6402,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; } @@ -6410,10 +6475,9 @@ 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; @@ -7132,35 +7196,69 @@ fn compute_word(p: &HostPipeline, kind: u32) -> Option<(u32, u32)> { #[cfg(test)] mod batch_tests { - use super::{batch_stale, stage_declared}; + 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`): it stores through buffer views alone, picks no view from the - /// heap, and all it stores goes through views bound to it, which is asked last. + /// (`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(false, true, true, false, not_asked), "it stores nothing"); - assert!(!stage_declared(true, true, false, false, not_asked), "it stores past views"); - assert!(!stage_declared(true, false, true, false, not_asked), "it picks views from the heap"); - assert!(!stage_declared(true, true, true, false, not_asked)); - assert!(stage_declared(true, false, false, false, || true)); - assert!(!stage_declared(true, false, false, false, || false), "a store through a view its bind does not declare"); + 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 picks views from the heap is declared when all it + /// `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(true, false, true, true, || true)); - assert!(!stage_declared(true, false, true, true, || false)); - assert!(!stage_declared(true, true, true, true, not_asked), "it stores past views"); - assert!(stage_declared(false, true, true, true, not_asked), "it stores nothing"); - assert!(stage_declared(true, false, false, true, || true)); - assert!(!stage_declared(true, false, true, false, not_asked), "off: as before"); + 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 @@ -7275,7 +7373,7 @@ mod undeclared_tests { } /// `LEONIDA_BATCH_WHY` counts the batches ended for stores not all declared by what the stage - /// that is not declared does: one that picks views from the heap only to read through them is + /// 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() { @@ -7284,7 +7382,7 @@ mod undeclared_tests { 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 picked from the heap and stored through... + // 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. @@ -7324,6 +7422,21 @@ mod undeclared_tests { #[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 \", \""); diff --git a/d3d12/crates/leonida-gpu/src/pipeline.rs b/d3d12/crates/leonida-gpu/src/pipeline.rs index 17583c6744..b29c6c5eb3 100644 --- a/d3d12/crates/leonida-gpu/src/pipeline.rs +++ b/d3d12/crates/leonida-gpu/src/pipeline.rs @@ -1282,7 +1282,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 } @@ -1358,9 +1360,9 @@ mod bound_tests { } /// A program that also has the view heap among its parameters (in s6, after the table in s4): - /// it picks a buffer 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 picked from the heap. + /// 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 @@ -1376,17 +1378,162 @@ mod bound_tests { 0xE078_1000, 0x8000_0D15 | (at / 4) << 16, // buffer_store_dwordx4 v[13:16], v21, s[at:at+3], 0 offen ]; - let mut p = program(RootType::Table, vec![used(ResourceType::Uav, RootType::Table, 8)], &code); - p.layout.push(RootParam { root: RootType::ResourceHeap, table_offset_dwords: 0, sgprs: 1, base_register: 0, user_data: 6, slot: 2 }); - p.io = StageIo::Cs(ComputeIo { rsrc2: 7 << 1, threads: [32, 1, 1] }); + 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 a program reads through views it picks from the heap is no store: its stores through + /// 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 picked is not. + /// `LEONIDA_BATCH_HEAP_READS`); a store through the view it loaded is not. #[test] - fn reads_through_views_picked_from_the_heap_leave_bound_stores_declared() { + 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)); diff --git a/d3d12/docs/switches.md b/d3d12/docs/switches.md index 36e50ff3f3..c07ff6d897 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. -662 names; 622 have a sentence of a comment below, the others no comment or only a bare list. +663 names; 623 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. @@ -147,7 +147,7 @@ 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` | off unless set and not `0` | yes | | | `leonida-gpu/draw.rs` +1 | `LEONIDA_BATCH_HEAP_READS=1` (`LEONIDA_AB` can turn it on and off while the title runs): with `LEONIDA_INDIRECT_BATCH=4`, a stage that picks views from the heap no longer ends the open batch for that alone ([`stage_decla... | +| `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`). |