WIP: d3d12: the title's graphics heap as private memory with a write-only twin in the card's memory (LEONIDA_HEAP_TWIN, off by default) #3399
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "feat/heap-twin:feat/heap-twin" git switch "feat/heap-twin"
Draft
leonida/mandy
MoonEyes
wants to merge 1 commit from
feat/heap-twin into main
pull from: feat/heap-twin
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/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
3 participants
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!3399
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/heap-twin"
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?
This pull request has changes conflicting with the target branch.
Merge manually to resolve the conflicts.
Reviewers 0 approvals
Details
This pull request has changes conflicting with the target branch.
Merge manually to resolve the conflicts.
d3d12/docs/findings.mdView command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Branche :
feat/heap-twinsurleonidanow(https://git.leonida.now/leonida/mandy), commit4b9a9c1bdb, basemain312d88d1d4. Comparer : https://git.leonida.now/leonida/mandy/compare/main...feat/heap-twinWhat it does
LEONIDA_HEAP_TWIN=1(experimental, off by default; without the variable nothing changes) ports Darner's heap twin(GPL-3.0-or-later, as this repository;
crates/darner-gpu/src/heap_twin.rsand the private heap of itsxmem),adapted to this layer rather than copied.
Renderer port 1 (
LEONIDA_PORT_CONSTANTS) opened the title's 32-bit graphics heap in place for the card and cost290 ms a frame on an RTX 4060 Ti (
d3d12/docs/findings.md, "Frame-rate switches measured on a six-core PC"): theCPU's 31,000 fills a frame read memory opened for the card. The twin splits the two sides:
leonida-hlexmem: with the switch and the 1.0.2.1 heap (allocation type 0x42000, 0xb90_0000 bytes, 32-bit),the heap is plain private memory below 4 GiB, committed at once and write-watched. Its parts, splits
(
VirtualFreewithMEM_PRESERVE_PLACEHOLDER/MEM_COALESCE_PLACEHOLDERS) and page mappings(
XMemMapPhysicalPages,...Scatter) inside it do nothing.leonida-gpu/src/heap_twin.rs(new): the part after the heap's first 0xb0_0000 bytes (the 174 MB buffer at0x34e10000) gets a twin of the same size in a GPU upload heap (resizable BAR), made with the first buffer placed
in it. Title buffers and windows there are placed in the twin through
port::place_for, so the existing in-placeShadowpath applies (nothing refreshed, sent up or fetched back for them).host.rs, both paths that calldescriptor::make_waiting) the 4 KiB parts the CPUwrote since the last sync are copied up, from the existing write journal (
watch::writes,watch::parts_written),by 2 MiB chunks the card reads, never mixing two askings in one copy. A thread of ours does the same each time
the title submits (
queue.rs). Our CPU buffer copies into the heap are also written through to the twin. The CPUnever reads the card's memory.
Not ported: the 256-byte constant buffers (
DARNER_CBV_ALIGN, a patch of the title's code), the write sites, theper-list stamps (here a sync is left out only when a complete one began after the title's latest submission: more
syncs, never fewer), the parallel sync, the twin's place in the card budget.
Risks (a wrong assumption shows as a wrong picture, not a crash)
copies newer bytes.
shaders wrote and read later: overwritten by the CPU's (for example skinned faces pulled to a point).
Tests
cargo test -p leonida-gpu --locked(Windows 11, toolchain fromrust-toolchain.toml): 738 passed, 0 failed,59 ignored. One unrelated test,
pool::tests::a_texture_gives_its_piece_back_when_it_goes, failed once in onefull run and passed in three runs alone and in the next full run (flaky, not touched here).
heap_twin.rs: the heap's identity and twin bounds, off without the switch (no hot pathdoes anything), range and chunk arithmetic, pieces of one epoch, joined 4 KiB copies, when a sync may be left out,
and a sync over real write-watched memory that copies only the parts written since the last asking.
cargo check -p leonida-hle --locked --tests: clean.python -I tools/d3d12_switches.py --out d3d12/docs/switches.md(one line added), note ind3d12/docs/findings.md.python -I scripts/check_no_game_data.pyon every touched file: clean.In-game A/B required
Not measured here. Darner's own figures (not ours): 71 to 59 ms a frame on an RTX 5080 (Series X, 1440p); its whole
set (twin, 256-byte CBVs, write sites) 14.1 to 16.3 fps on an RTX 5070.
Proposed recipe: resizable BAR on (the log says "card memory the CPU maps" supported = true and "a twin in the
card's memory" once), same save and place, same profile and launcher settings, runs of 600 s each in the order
A B B A (A:
LEONIDA_HEAP_TWINunset; B:LEONIDA_HEAP_TWIN=1; the heap is made once at start, so one run per arm,not
LEONIDA_AB). Compare frame median and p90, the card's busy time and the submitting thread's work per frame,and the heap twin's per-frame line (syncs, MB copied, ms). Watch the recordings for the faults above (flicker,
objects a frame ahead, stretched skinned meshes). Merge only after a 300 s in-game run without device loss.
Credits and AI assistance
Mechanism from Darner (GPL-3.0-or-later), credited in the code comments and in the commit message.
AI-assisted: written with Claude Code (Claude Opus 5.5,
claude-opus-5-5); reviewed by a separate Claude Opus 5.5reviewer agent (first verdict REFUSE, its four points fixed or documented, then re-reviewed).
🤖 Generated with Claude Code
A/B on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300, Resizable BAR on), executable of this pull request's head
4b9a9c1bd(diag profile,diagnostics,dlss,mimalloc, msvc target), the same executable in every run. Series X output 2560x1440, DLSS quality, no frame generation, 600 s standing at the save, fresh data for each run. A = default; B =LEONIDA_HEAP_TWIN=1. Run order A1, B1, B2 (A2 dropped: A1 already matches themainreference runs of the same night, 33.0-33.6 frames/s).Verdict: default path fine (A1 is at the
mainlevel). With the switch on, a large regression on the RTX 3090; it should stay off by default, at least on this card. (It was taken out of the beta defaults on this measurement.)GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: runs and report by Claude Code (Claude Opus 5.5).
Independent RTX 3090 fallback/stability check for head
4b9a9c1bdbf7dea86a2e87bc8393f17a695618a2, applied to maine1a13ab251de832eb07fd78bad9e95a62149bf39.Host: NVIDIA RTX 3090 24 GiB, driver 610.88, Windows 11, Ryzen 9 5900X, 32 GiB RAM. Rust 1.98.1 MSVC;
diagnostics,dlss,mimalloc; Series X, DLSS quality, frame generation/precompile disabled. Both runs used the same candidate executable, separate processes, stock game gate and freeroam driver, matched initial pipeline seeds and the same memory stops. The disabled arm is the PR executable withLEONIDA_HEAP_TWIN=0, rather than a separate plain-main binary.The runtime reported no usable GPU upload heap. A separate device-only OPTIONS16 query after the game exited returned
S_OKandGPUUploadHeapSupported=0on the RTX 3090, using the same system D3D12Core path as the game (version 10.0.26100.9818). No twin was created and no active-twin placements or copy counters were exercised. The single “not placed” warning is the fallback diagnostic, not an active-twin refusal count; active-path statistics are unavailable. This is fallback stability coverage. It establishes neither twin correctness nor a performance/memory improvement. The differing placement/workload, one run per mode and shared driver shader cache also prevent effect attribution. Neither run proves 300 seconds at the destination. No logged ERROR, crash or device loss in either completed run; no forced termination.Before live execution: full eight-file diff/build-script audit, tracked/new-file clean-room scans and diff check passed. Local tests passed: heap-twin 9; default GPU 739 (59 ignored); diagnostics GPU 820 (59 ignored, device-backed depth-bounds included); diagnostics XMem 28 (1 ignored); diagnostics replay 1; optimized diagnostic build. The pure heap tests do not validate live alias/remap or GPU-write coherence assumptions.
One earlier preparation attempt was stopped cleanly before reaching world because its actions log inherited a system-drive temp path. It is excluded above; both completed arms used matched scratch-drive TEMP/TMP and verified actual actions-log placement.
AI-assisted: GPT-6.1 Sol xhigh for the testing worker and independent source/numerical verification. No approval or merge recommendation from this limited coverage.
d3d12: the title's graphics heap as private memory with a write-only twin in the card's memory (LEONIDA_HEAP_TWIN, off by default)to WIP: d3d12: the title's graphics heap as private memory with a write-only twin in the card's memory (LEONIDA_HEAP_TWIN, off by default)Moved to WIP. Measured on an RTX 3090 (Series X 1440p, DLSS quality, resizable BAR on, 600 s runs): with
LEONIDA_HEAP_TWIN=1the frame rate drops by about 40 % (20.4 and 20.6 fps against 34.2 without), about 20 ms more GPU work a frame; no image fault, no device loss. The default path (variable unset) matches main.Likely cause: the title's descriptor heap is then read by shaders from the upload heap (BAR), which is slow for the GPU. VIctory-SandBar keeps that part in RAM for the same reason. A next version would keep the descriptor heap in RAM and twin only the data the GPU reads rarely. Not to be merged switched on as is.
🤖 Generated with Claude Code