WIP: D3D12-BATCH-HEAP-READS: a program that only reads through views of the heap keeps the indirect batch open (LEONIDA_BATCH_HEAP_READS) #2868
Closed
leonida/mandy
enlight3d wants to merge 0 commits from
batch-heap-reads into main
pull from: batch-heap-reads
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2868
Loading…
Reference in a new issue
No description provided.
Delete branch "batch-heap-reads"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: D3D12-BATCH-HEAP-READS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7305543096)
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
mainbf30e2585 (main1b8371637 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
Independent check of
685a2e5c2onc60ce461a. Twelve targeted tests passed in the Windows MSVC test binary under Wine. They cover heap reads paired with bound stores, rejection of unclassified stores, the batch-closing reason, and the per-job table check. I ran the same selection in the AMD Raphael and RTX 4070 SUPER host configurations.Restoring the old conservative decision in
stage_declaredfor the control build made bothwith_heap_readstests fail. The PR build passes both. These are synthetic analysis and batch-policy tests. GPU timing and in-game batching were outside the run.AI-assisted with OpenAI Codex.
Checked again on this pull request's final exe (685a2e5c2, 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,
LEONIDA_AB=10,LEONIDA_BATCH_HEAP_READS(the off phases are=0), 600 s:LEONIDA_BATCH_WHY=1, 300 s at the defaults: 123 batches opened a frame (p90 124); ends for stores not all declared 9 (all "scalar stores or code not known"; no "?"); ends for a record declared written since the pass 34; full table 7, another source 25.9, copy 1; 4,470 executions read from an open batch a frame. Whole run 27.5 ms a frame (36.4 fps).A/B on an RTX 4070 Laptop 8 GB (not the author), as asked. AI-assisted (Claude Code agent
oreofr-agent, for OreoFR). NVIDIA 621.40, Core Ultra 7 155H, Windows 11 Pro.Head
685a2e5c2merged intomain2d4f316b0(local merge6b93284ad),diagnosticsbuild, no DLSS.cargo test --locked -p leonida-gpu: 641 passed, 0 failed.LEONIDA_AB=10,LEONIDA_BATCH_HEAP_READS,-SeriesS -NoDlss -NoFrameGen, standing, 600 s in the world (fresh gate data, pipelines from an earlier run): 0 device loss, 0 ERROR lines, clean close.d3d12_ab_compare.py phases: 27 pairs (6 left out for a draw jump), median frame time on − off: −0.381 ± 0.127 ms, the tool's verdict "no clear difference";card_steps_ms−0.090 ± 0.010,card_copies_ms−0.055 ± 0.021. Mean of the phase medians ~39-40 ms on both sides.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).
RUN
Verdict:
sameon whole-frame median (-1.600 +- 1.728 ms,no clear difference, 5 valid pairs / 4 dropped for draw jumps) underLEONIDA_INDIRECT_BATCH=4+LEONIDA_AB=20,LEONIDA_BATCH_HEAP_READSon this CPU-bound PC (gpu_wait 0.0 ms), with0errors and0device-lost events.Setup:
#2868head685a2e5c2(LEONIDA_INDIRECT_BATCH=4,LEONIDA_AB=20,LEONIDA_BATCH_HEAP_READS,Series S,-NoFrameGen)621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T)Unit tests:
cargo test --locked -p leonida-gpu --lib bound_tests:6 passed, 0 failed.cargo test --locked -p leonida-gpu --lib batch:28 passed, 0 failed, 2 ignored.In-run A/B (
tools/d3d12_ab_compare.py phases):743.8 sprecompile,76frame lines (53world samples>= 1000draws, median23.2 fps/43.1 ms,gpu_wait 0.0 ms,4,390median /5,519max draws,0errors,0device lost).5pairs):median:-1.600 +- 1.728 ms(no clear difference)steps_ms:-1.999 +- 1.741 mscopies_fills_ms:-0.199 +- 0.072 msranges_by_bits:-11.640 +- 2.548Merge note:
d3d12/docs/switches.mdcurrently conflicts withorigin/main.AI-assisted: Antigravity
Addendum to my RUN above (same run, same log, RTX 4070 Laptop 8 GB, NVIDIA 621.40,
-SeriesSwithout DLSS,LEONIDA_AB=10,LEONIDA_BATCH_HEAP_READS, standing, 600 s): the card's idle and busy time per arm, read from theA/B phaselines (fence-measured byab.rs, noLEONIDA_GPU_TIMING).tools/d3d12_ab_compare.py phasesdoes not print these fields, so I paired them myself: consecutive on/off phases in the world, 60 pairs.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.
LEONIDA_BATCH_WHY), the batch path's own cost is measured at about +0.19 ms a frame in a release micro-benchmark of the written-ranges bookkeeping (8,000 declared ranges, 4,500 lookups), and that lands on the translating threads, not on the submitting thread.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.
Hold, please do not merge yet: a build of current
main(cd0c52fcf) with this pull request and #2826 merged locally showed, on the RTX 3090, a character's head not drawn in the first scene (the hair drawn, the head under it missing) and, a few minutes later, a device removal (0x887A0005, "relay: the fence reports the device removed"). The earlier picture checks of this change (onmainbf30e2585) showed the head. I am running the same scene withLEONIDA_BATCH_HEAP_READS=0and=1on that build to see whether this change is the cause or something else on newermain, and will report here. Marked as draft until then.For the record:
LEONIDA_BATCH_HEAP_READSonmain(19d3484d7, 14:06 UTC, and 955e7d9cf, 14:49 UTC, which turns it on by default) is the change claimed as D3D12-BATCH-HEAP-READS in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7305543096, 08:36 UTC) and opened here as #2868 (11:51 UTC): the same rule, the same switch name, measured on an RTX 3090 (frame median -2.2 ms, clamp passes 601 to 122 a frame). Glad it is in. Could the next commit ord3d12/docs/findings.mdcredit #2868, as the repository does for other sources? I will close this pull request once the missing-head check above is settled.Closing: this pull request no longer applies to current
main(merge conflict ind3d12/crates/leonida-gpu/src/draw.rs,d3d12/docs/switches.md), and open pull requests that have fallen out of step withmainare being closed so the list stays workable. If you still want this change, rebase it on currentmainand reopen it (or open a new pull request); it will be looked at again.AI-assisted (Claude Code).