Repository navigation
D3D12-BATCH-HEAP-READS: a program that only reads through views of the heap keeps the indirect batch open (LEONIDA_BATCH_HEAP_READS) - #2868
Conversation
…mes (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 ProjectLeonida#2464, which the section links; no game data is added. AI-assisted.
…he 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.
The runs report the cgroup's peak, as the RUN blocks do; the VRAM spilled to host memory is a different figure. AI-assisted.
…eason, 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 <noreply@anthropic.com>
…s 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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
|
Independent check of Restoring the old conservative decision in AI-assisted with OpenAI Codex. |
|
Checked again on this pull request's final exe (685a2e5, the switch on by default), RTX 3090 24 GB, NVIDIA 621.40, launcher defaults, Series S settings, the same save, standing still; warm-up and a throwaway run first, nothing else running; no device loss, private memory at most 29.5 GB. In-run A/B,
|
KelboLive
left a comment
There was a problem hiding this comment.
The rule reads well and fails closed on every write shape the new tests cover. stage_declared (draw.rs:923) requires !s.stores || (!s.past_views && (heap_reads || !s.heap) && bound()), and bound() is the per-store analysis (pipeline.rs:577-633) that only accepts a table descriptor loaded at a fixed offset with a UAV entry, or a non-spilled root UAV. A store through a heap-loaded descriptor becomes Source::Loaded with a ResourceHeap root param and is rejected (pipeline.rs:607); dynamic offsets, code-made descriptors, cselects and unknown tracking all fail closed, and the new heap_reader(16) case pins it. stores_told (draw.rs:6463-6490) really is the only thing kept — the open batch, not a descriptor table or slot — marking batch.wrote = true so later executions check the writer's ranges. The switch is read once and threaded as Declared.heap_reads, so an A/B phase change can't leave the diagnostic lying.
Mutation confirms the guard is load-bearing: relaxing it to "every non-past-view heap stage declared" fails draw::batch_tests::with_heap_reads_a_stage_reading_from_the_heap_is_declared_when_its_stores_are_bound (draw.rs:7231) and draw::undeclared_tests::…ends_no_batch (:7414). 641 lib tests pass, and merge-tree against origin/main is clean.
One wording issue, and it matters because these names end up in the diagnostics a tester reads: HeapReadsBound's "reads only from the heap" actually means "stores nothing through a heap view" — the stage still stores through its bound table/root views. "Heap views read only" would say that, and the batch_heap_reads doc should not read as if the stage were read-only. Also worth one sentence where heap is computed: SLOT_STRIDES is emitted for a heap-loaded constant buffer too (root type, not view kind), so some batches deliberately stay open a moment longer — conservative, not a hole.
Table::full_for is diagnostics-only and gated, and the regenerated switches.md counts (663/623) match the added row.
|
A/B on an RTX 4070 Laptop 8 GB (not the author), as asked. AI-assisted (Claude Code agent Head
So on this card the change goes the same way as on the 3090 but is much smaller (about −1 % of the frame, not −7 %). No regression seen. I did not repeat the mutation red here (the description lists 15 killed mutants). |
…nux-wine-nvidia docs: a Linux + Wine + NVIDIA profile that draws world frames (DOCS-RUNNING-LINUX-WINE-NVIDIA)
|
RUN Verdict: Setup:
Unit tests:
In-run A/B (
Merge note: AI-assisted: Antigravity |
|
Addendum to my RUN above (same run, same log, RTX 4070 Laptop 8 GB, NVIDIA 621.40,
Reading: the card saves about the same time as on the 3090 (−1.9 to −2.0 ms there). On this card the submitting thread does not pay for the switch, but almost all of the saved card time turns into card idle, so the frame barely moves. Something other than the card's work and the submitting thread holds the frame at ~38 ms here; that part is a hypothesis. |
|
Follow-up on the 0.86 ms of extra work on the submitting thread that the final A/B showed: it does not come from code this switch runs.
So the sentence in my previous comment that this extra work "would eat into the gain" on a machine held by the submitting thread overstated it: it is work the late wait does in place of waiting, and it did not show on the 4070. |
d3d12/docs/switches.md regenerated with tools/d3d12_switches.py (the conflict was its count line and rows); the page now also lists the names main's sources added since its last regeneration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hold, please do not merge yet: a build of current |
|
For the record: |
Claimed in the coordination issue as: D3D12-BATCH-HEAP-READS (#2570 (comment))
Depends on: none. Conflicts: #2834 in
d3d12/docs/switches.md(regenerate the page). #2569 merges without a textual conflict, but its oneLEONIDA_UNDECLARED_TRACEcall needsstores_declared(p, builder).allandundeclared_why(p, builder, heap_reads)(see below).What and why
With
LEONIDA_INDIRECT_BATCH=4(whatd3d12/scripts/play-nvidia.ps1sets), an open batch of clamped indirect records stays open past a dispatch or draw whose stores all go through views its bind declares (stores_declared). A stage with the root SRVSLOT_STRIDESended the batch beforestores_boundwas asked. The translator gives that root SRV for every buffer access through a descriptor loaded from aResourceHeaproot parameter, reads included (leonida-shaderemit/lower.rs,slot_word), so programs that only read through views of the heap ended the batch as if they stored through them.stores_bound(stores_in_bound_views) already says no of a store through a view loaded from the heap, or through a table at an offset the program computes, so it can decide for those stages too.LEONIDA_BATCH_HEAP_READS(on unless0,crate::toggled!, switched byLEONIDA_AB): a stage that loads views from the heap is declared whenstores_boundsays all its stores go through views its bind declares.0gives the old behaviour. No store through a view loaded from the heap is let through, as before. Batches whose records really are written still end, for "a record declared written since the pass".stores_toldreads the switch once per decision:stores_declaredanswers with the setting it used (Declared), and the diagnostic takes that same setting.LEONIDA_BATCH_WHY(diagnostics only) gets a second line with the total for every reason a batch ended for undeclared stores, not only the first eight programs. It tells "reads only from the heap (stores bound yes / no / not yet)" from "stores through a view picked from the heap", and counts the ends for a full table and for another source apart. The first line reads as before.Measurements
RTX 3090 24 GB, NVIDIA 621.40, Windows 11, launcher defaults (mode 4), Series S settings, standing in the world.
LEONIDA_AB=10,LEONIDA_BATCH_HEAP_READS, 900 s, 33 pairs of phases (on this branch before the default changed): frame median -2.2 +- 0.17 ms with the switch on, the card busy 1.9 ms less a frame, the lists' steps on the submitting thread 0.5 ms longer.LEONIDA_BATCH_WHY=1, 300 s with the switch off and 300 s on: 601 batches opened a frame against 122; ends for stores not all declared 507 against 9 (the 498 of "reads only from the heap (stores bound yes)" with it off); ends for a record declared written since the pass 20 against 34.0and1): nothing missing or different apart from a character's idle pose.Limits: at these settings the 3090 is held by the card, so the gain may differ on a card-light or CPU-bound machine; the picture check is four captures per run on two runs, not a frame-by-frame scan; the switch adds about 0.5 ms a frame to the lists' steps on the CPU; the timing run with the switch on had no run with it off in the same session (it is compared with an earlier timing run on another commit).
Tested
On this branch at
mainbf30e25 (main1b83716 since then changes nothing underd3d12/, and the branch merges onto it cleanly), againstmainat the same commit:cargo test -p leonida-gpu: default 641 passed, 58 ignored (main 627, 58).--features diagnostics: 720 passed, 58 ignored, replay 1 passed (main 706, 58, replay 1). In both diagnostics runstimeline::record::tests::global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacksfailed once, on main as here, and it passes run alone on both. The 14 new tests make the difference.cargo test --workspace --exclude xtask --no-fail-fast(the CI step): 1,619 passed, 2 failed.leonida-loaderload_probefails the same way on main in this environment (its probe DLL is not found with a target folder of its own).watch::tests::a_write_opens_the_view_it_goes_throughpasses run alone and in theleonida-gpuruns above.texture::allocation_costs::no_two_changes_cancel_in_the_aes_digestnow and then stops the diagnostics test process with aptr::copyalignment check (1 run in 12 of that module on main, 2 in 12 here). No code it runs is touched here.left: Other, right: Builder), the totals line (1 item instead of 11), the full-table counter (table.full_for(7)), the switch in the stage test and in the reasons (left: HeapReadsBound, right: Other), the switch reaching the decision (Declared { all: false, heap_reads: false }instead of{ all: true, heap_reads: true }), the default (batch_heap_reads()false).stores_in_bound_views(pass on main, as they should): reads from the heap with a store through a table entry or through a root view of unordered access are declared; a store through the view loaded from the heap, through a descriptor made in the code, through the table at a computed offset, or through a descriptor chosen bys_cselectbetween the table's entry and the heap's is not.stages_declared; theSLOT_STRIDESshort-cut put back;stores_bound's answer taken as yes;stores_in_bound_viewsalways yes; heap and table roots swapped; the computed-offset test dropped; other descriptor sources taken as declared; one declared leaf of a choice taken as enough; root views refused; a reason misclassified; the full-table counter off by one and blind to the source; the default back to off.cargo clippy -p leonida-gpu --all-targets, default and--features diagnostics: the same warnings as main, none new.python -I tools/d3d12_switches.py --check d3d12/docs/switches.mdpasses (the page is the tool's output);python -I scripts/check_no_game_data.pyon every file touched and on this text.GPUs tested: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (unit tests and the in-game A/B).
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code