d3d12/vulkan: batch indirect clamp windows and lift default overflow cap (RT-INDIRECT-CLAMP-WINDOWS) #3331
Open
github-bot
wants to merge 3 commits from
github-bot/gh-3331 into main
AGit
pull from: github-bot/gh-3331
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
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
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!3331
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@azsekazvamdimitar on GitHub · 2026-12-03 12:58 UTC · original
azsekazvamdimitar:perf/indirect-clamp-windows→main· +359 −91 · 11 files · 3 commits · openClaimed in the coordination issue as: RT-INDIRECT-CLAMP-WINDOWS (#3312)
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)@merzleckeier on GitHub · 2026-12-03 13:04 UTC · original
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).
@azsekazvamdimitar on GitHub · 2026-12-03 13:13 UTC · original
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).@Kal0s-design on GitHub · 2026-12-03 14:46 UTC · original
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).
@moffington on GitHub · 2026-12-03 15:11 UTC · original
Ran synthetic tests only on PR 3331 at
bc5969f0a: native Linux clang build, RTX 3060 12GB, driver 615.78.08.AI-assisted (Claude Code).
@azsekazvamdimitar on GitHub · 2026-12-03 15:50 UTC · original
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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.