d3d12/vulkan: batch indirect clamp windows and lift default overflow cap (RT-INDIRECT-CLAMP-WINDOWS) #3331
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/3331:github-pr/3331" git switch "github-pr/3331"
Open
leonida/mandy
azsekazvamdimitar wants to merge 3 commits from
github-pr/3331 into main
pull from: github-pr/3331
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: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!3331
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/3331"
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 branch is out-of-date with the base branch
Reviewers 0 approvals
Details
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Claimed in the coordination issue as: RT-INDIRECT-CLAMP-WINDOWS (https://github.com/ProjectLeonida/mandy/issues/3312#issuecomment-7377256952)
What and why
Two changes to gta6rt (
runtime/), both measured in the prologue cell on an RTX 3090 with Resizable BAR.1. Clamp windows: the clamped indirect draws of a run share one clamp pass and one rendering scope.
Every indirect draw the title records goes through the GPU argument clamp. Until now each clamped draw ended the
rendering scope, recorded its own clamp pass with two full
ALL_COMMANDSbarriers and a graphics/compute switch, andbegan rendering again (attachment transitions,
LOAD/STOREof every target). The cell issues about 3,800 such drawsa frame, and this per-draw overhead was most of the mesh time.
emit_commandsnow gathers the clamps of consecutive raster draws into a window (detail::clamp_window). It recordsthem in one pass before the window's first draw (
IndirectArgumentClamp::emittakes a span of calls: fills per call,one wait, one bind, a dispatch per call, one stats copy barrier, one release barrier). The later clamped draws of the
window keep the rendering scope when their attachments match. A window ends:
writes_buffer) or storage (writes_storage, new: any stagedeclaring a writable storage image or buffer,
spirv_declares_writable_storage);so the full barrier a clamp pass ends with still separates it from the draws before it, as on
main.Draws in one rendering scope get no barrier between them, so a later draw must not read what an earlier one of the
window wrote. Without the
writes_storagebreak the cell's interior went black: some pixel shaders write storageimages, which
writes_bufferdoes not cover. The clamp passes of a window charge the list's work budget in onedispatch, so if a list ever exhausts it (0 records over budget in every boot measured) which draw goes empty is not
fixed. Non-clamped draws that share a rendering scope after a storage-writing draw get no barrier either; that is
the same on
mainand not changed here.2. No default budget for overflow title-buffer windows.
#2865 added a default cap to
external_window_cap(2 GiB unstaged, 4 GiB staged). At world load the arena (4094 MiB,capped by
maxMemoryAllocationSize) fills, and the overflow windows outside it need more than that. Each refusal logsGPU address arena full ... title memory has no windowand leaves title memory without a GPU copy. In the cell thisloses the walls, the bunk bed and the photos (50 refusals in one boot, with the overflow at 512 blocks of 4 MiB, the
whole 2 GiB).
LEONIDA_EXTERNAL_WINDOWS_MBstill sets a budget (a whole number of MiB; anything else is ignored);unset, a window is refused only when memory runs out, which is what the code did before #2865
(
parse_external_windows_budget,docs/d3d12_vulkan.mdupdated). Only a 24 GB card was measured; on a smaller onethe overflow competes with everything else for VRAM and host-visible memory either way.
Tested
Measured on an RTX 3090 24 GB, NVIDIA 590.48.01, Debian 13 (Linux 6.12), GE-Proton (
gta6rt.exebuilt withclang-cl/xwin), Resizable BAR on and the default arena placement. Series S profile (1920x1080 output, 1280x720
internal). Each run is one 360 s boot from cold start into the prologue cell with a fixed input script. The fps is the
median of the runtime's 10 s
submit framewindows from t = 215 s (14 windows):title memory has no windowmain), default cap (2 GiB)writes_storagebreakGPU split with
LEONIDA_GPU_PROFILE=1(ms per frame, mean of the reports after t = 250 s). Without the clamp windows,the same runtime on a shader farm of the same speed (the profiler's own scope splits cost fps, so compare the split):
The heaviest pipeline (ped mesh + deferred ped pixel shader) went from 19.9 to 1.2 ms a frame. Screenshots of the last
minute of each boot show the cell complete (walls, window and yard, photos, bunk bed). They show game content, so they
are not attached.
Tests (Linux clang build of the portable subset, plus the Windows build of
gta6rtandd3d12_indirect_rt_test):replay_state_cache_testcase 5c-2: windows end at a buffer-writing draw, a storage-writing draw and adispatch, and a later clamped writer opens its own window. Case 5c-3: a skipped draw stays inside a window, and
inside a pipeline-statistics query each clamped draw gets its own pass between two segments. Red, each by one edit
of
detail::clamp_windowin a copy of the source: one-draw windows (the former behaviour) fail 5c-2 and 5c-3; awriter joining the window fails 5c-2; no statistics break fails 5c-3.
indirect_clamp_test(live Vulkan, RTX 3090): four calls in one pass, three sharing a list budget, clamp like fourseparate passes; validation errors 0.
arena_staging_testtest_external_windows_budget: red with the former 2 GiB default (unset, empty and invalidvalues give no budget,
2048gives 2 GiB,2Gis ignored).replay_dropped_indirect_clamp_testandctestpass. The exception isconsole_list_records, which does notcompile with Linux clang on
maineither (-Wc++11-narrowinginconsole_list_records_test.cpp:147-159, a file thisPR does not touch).
python -m unittest discover -s tests -p "test_docs_*.py"(59 tests pass).python -I scripts/check_no_game_data.pyon the changed files.GPUs tested: NVIDIA RTX 3090 24 GB, driver 590.48.01, Linux 6.12 + GE-Proton (Wine).
AI-assisted: yes. The changes were written with Claude Opus 5.5 and Gemini 4 Neon (OpenCode / oh-my-opencode) and
reviewed by a separate read-only reviewer agent (oh-my-opencode
oracle).Not in this PR (pre-existing, found while measuring):
LEONIDA_DEVICE_LOCAL_ARENA=1on a Resizable BAR card loses walls and window frames in the cell. Thishappens with or without this PR, and with builds from before #2865's last commit. The default (
auto) is notaffected.
TitleBufferWindows: a destroyed block keeps itsPublished::stagedpointer, andcommit_uploads/staging_statscheck only that pointer. Published slots are never reused, so after 4,096 block creations new blocks go
unpublished. No log of ours shows the churn needed to reach that.
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (no translator change)I tested
444a7509onb053a181with native Vulkan on an RTX 4070 SUPER (620.73.04) and the Ryzen 7800X3D iGPU (RADV 26.3.1).indirect_clamp_testpassed on both with Khronos synchronization validation enabled and zero validation errors. The replay-state-cache suite, SPIR-V storage classifier, arena-staging tests, and dropped-clamp test passed. A separate CPU replay fixture also verified that two read-only indirect draws can share a clamp pass across different attachments and still open separate rendering scopes. A direct storage-writing draw ended that window so the following draw got its own clamp pass.One small parser issue in
parse_external_windows_budget:std::strtoullaccepts a leading minus sign and negates in the unsigned result type. On this head,-18446744073709551615sets a 1 MiB cap, and-18446744073709551614sets a 2 MiB cap. Both should take the documented invalid-value path. The earlier parser used the same conversion. In a local test, rejecting a minus sign after leading whitespace fixed both cases and preserved the positive, zero, unset, and out-of-range controls.Synthetic CPU and GPU tests. AI-assisted (Codex).
Thanks for testing on the 4070 SUPER and RADV with sync validation, and good catch on
strtoullwrapping signed inputs.Fixed in bc5969f0a:
parse_external_windows_budgetnow skips leading whitespace and requires a leading digit before callingstd::strtoull(rejecting-and+). Added-1,-18446744073709551615,-18446744073709551614, and+2048cases totest_external_windows_budget(verified red on444a7509dat-18446744073709551615, green after the fix; rebuilt Windowsgta6rtand rancheck_no_game_data.py).Ran natively on Windows 11, head
bc5969f0amerged into currentmain(128579e9e, clean merge).Nothing broke. I have one small Windows point about the env parser.
LEONIDA_EXTERNAL_WINDOWS_MBwith a trailing space. In cmd,set LEONIDA_EXTERNAL_WINDOWS_MB=64 && gta6rt ...stores the value as64, with the space (measured:echo [!VAR!]prints[64 ]).parse_external_windows_budget("64 ")returns no budget. Before, that line gave a 64 MiB cap.64MBbehaves the same way. This matches the comment ("anything but a whole number of MiB: no budget"), but the failure direction has flipped. A sloppy value used to still give you a cap, and now it removes the cap without saying so. Trimming trailing whitespace, or one log line when the variable is set but rejected, would cover it.Parser values (measured by calling the header function directly). The "before" column is
main'sstrtoull+mb > 0logic, reproduced in the same probe.0,001,010,409664,\t6464,64\n64MB,64M,1.5,1e30x1017592186044415(largest that fits after<< 20)17592186044416up to past u64Read, not run: the shim reads the variable into a 32-byte buffer, so a value of 32 chars or more is "no budget" too.
Tests (measured). MSVC, Ninja, RelWithDebInfo, only the five targets this PR touches. Validation on with
LEONIDA_VK_VALIDATION=1(the tests add sync validation throughVkValidationFeaturesEXT), plusVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LAYER_VALIDATE_SYNC=1. This SDK's layer flagsVK_LAYER_ENABLESas deprecated and says it overrides the new settings, so I didn't use it for these runs.mainmainindirect_clamp_testreplay_state_cache_testd3d12_indirect_rt_testLEONIDA_UPLOAD_SYSMEM=1arena_staging_testreplay_dropped_indirect_clamp_testThe GPU tests picked the discrete NVIDIA card. The PR's test files don't compile against
main's sources. All five fail on the API change (emittaking a span,writes_storage,parse_external_windows_budget), so I couldn't show red/green by swapping files. MSVC/W4: a clean rebuild of the five targets gives 276 warnings on both, with the same count for every warning code.Window edge cases (measured). Throwaway cases in the trace fixture of
replay_state_cache_test, with the PR'sreads_onlypipeline unless the row says otherwise:clamp2 begin_rp draw_ind draw draw_ind end_rpclamp1 begin_rp draw_ind draw end_rp clamp1 begin_rp draw_ind end_rpclamp3 begin_rp draw_ind draw_idx_ind draw_ind end_rpclamp2 begin_rp draw_ind draw_ind end_rpclamp1 ... end_rp clamp2 begin_rp draw_ind draw_ind end_rpclamp1 ... end_rp begin_q clamp2 begin_rp draw_ind draw_ind end_rp end_qmax_count0, indclamp2 begin_rp draw_ind draw_ind end_rp(no draw recorded for the middle one)clamp1 ... end_rp begin_pred end_pred clamp2 begin_pred begin_rp draw_ind draw_ind end_rp end_predclamp1 ... clamp1 begin_rp draw_ind draw end_rp clamp1 begin_rp draw_ind end_rpAll match the rules in the docs. A direct draw that writes closes the window the same way an indirect one does, so the next clamp still gets its full barrier.
Read, not run: the replay records no secondary command buffers and no suspending/resuming rendering scopes, so a window can't cross one. Clears,
BeginQueryandSetPredicationare commands, so a window ends before them, and a load op can't change mid-window. A statistics query starting mid-sequence is theBeginQuerycase, and the PR's 5c-3 covers the per-draw segments.Conflicts: four open PRs touch the same files. #3142 and #3160 merge cleanly on top of this. #3228 and #2580 have the same conflicts with this PR as with
main. This PR adds none.Not checked: the game, and the frame-time numbers in the docs. What "no budget" does once VRAM is full. A GPU count that clamps to zero inside a pass with several jobs. A counted indirect draw inside a window (in my fixture case the counted draw recorded nothing).
GPUs tested: one NVIDIA desktop card (native Vulkan).
AI-assisted: yes (Claude Code).
Ran synthetic tests only on PR 3331 at bc5969f0a: native Linux clang build, RTX 3060 12GB, driver 615.78.08.
AI-assisted (Claude Code).
Thanks for the Windows run, the edge-case fixture table and the conflict check. The trailing-space case is a real trap with
set VAR=64 && ....Fixed in cc6a1acc0:
parse_external_windows_budgetnow accepts whitespace on both sides, so64and\t64\ngive a 64 MiB budget again.64MB,1.5,1e3,0x10, signed values, a number too large to shift, or a value too long for the 32-byte read) is still ignored, but no longer silently: the shim prints one[rt] d3d12: LEONIDA_EXTERNAL_WINDOWS_MB is not a whole number of MiB; ignored, ...line. Unset, blank and0still mean no budget, with no message.test_external_windows_budgetcovers the trimmed values, the largest value that fits, and the rejected flag for each of those inputs. It fails at"64 "with the trim removed and passes with it. Rebuilt Windowsgta6rt; the docs line says the same.AI-assisted (Claude Opus 5.5).