GPU: draws that only read-mark join clamp hoists and windows #3531
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3531"
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?
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T14:58:21Z.
Stacked on #2472 and #3197 (plus the Wine compile fix Slay326 is taking into #3197), so this is a draft until they land. The change to review is the last commit,
d4e44ed5(draw.rs,copystat.rs). Follow-up to #3197 as Slay326 asked there.What's wrong
#2472's hoist and #3197's window both refuse every pipeline that has view marks at all
(
pipeline_writes_uavtestedp.marks.is_some(),may_storetestsmarksandview_marks). Nearly every pixel shader in the title read-marks the textures it takes fromthe heap, so the hoisted prefix ends at the first G-buffer draw and almost every G-buffer
draw is clamped on its own. On my stack (RTX 5090, Wine + vkd3d-proton) that is 4,909
single clamps a frame, 35.4 ms of GPU command time; with the rule 1,133 clamps and 9.7 ms
(155.4 → 64.8 ms of command time a frame, 398 → 311 ms a frame in game).
The rule, and why it is safe
Marks come in two kinds, and only one of them can write an argument.
the heap.
mark_view_writeonly marks handles inview_index, and onlyheap_handle(heap-made views) puts them there; such a view is a table's, the heap's own, or a root
UAV's view, so a stage that writes marks has one of those write flags anyway. The page
table's write handle was removed from
view_index, and title-memory writes go throughmemory.u1(VIEW_WRITES) inMEMORY_SPACE. Thatbuffer is host-owned and is never title memory, so it can never be an argument or count
buffer.
So a stage with marks and none of the write flags only sets read marks, and a draw or
dispatch whose only extra write is that bitmap cannot change what any later execution
reads as arguments. The DXIL of the census shaders agrees: the G-buffer pixel shaders
(
43e24028,94d28115,62f761fb) and the mesh shaders (b7a81f5b,df4b2c77) have nostore op at all, and the one handle they write through is
createHandleFromBinding(.. [1, 1, 2, i8 1]), props4107(a typed buffer), written onlyby read-mark atomics (7, 29, 29, 1, 4 of them); every other handle they make is read.
43fba464(one store) and5ad3a82b(ten) also store through a heap texture UAV, and theystill clamp on their own.
What changes
One predicate, one decision.
draw::may_write_arguments(withdraw::stage_may_write_arguments) replacespipeline_writes_uavandmay_storeand testsonly the write flags: table UAVs (
used), heap writes (heap_writes), root UAVs as rootdescriptors or as their heap views (
ROOT_UAV_VIEW), and title memory (memory,memory_writes, and the stage'smemory/memory_dirty).marksandview_marksare notamong them.
draw::clamp_routeis that rule's decision, andexecute_indirectasks it once:the prelude has room for and whatever the window switch says;
window when
VICTORY_CLAMP_WINDOW=1(#3197), else clamped on its own.bindends the hoisted prefix with the same predicate when a command writes. A draw thatmay write and is clamped on its own goes through
crate::indirect::bound, which callsend_windowfirst, so the writer always ends the window: no later record can be clampedby a pass that runs after the writer's stores, and the writer's own clamp is not moved
before the window's earlier draws' reads.
Titles are unaffected: nothing about which draws run, in which order, or what they read
changes. Only the record clamp of an indirect draw moves, from its own pass into a pass
that runs before the same draw. Diagnostics:
clamps per frame:is now logged whateverthe switch and splits passes into singles and windows, with draws per window, draws
hoisted to preludes, the hoisted/windowed ones this rule let in (
ClampReadMarked), andthe ones left alone as they may write arguments (
ClampStoring).Tests (CPU, no device)
draw::tests::a_stage_that_only_read_marks_may_join_a_clamp_batchdraw::tests::a_table_uav_store_ends_a_clamp_batchdraw::tests::a_heap_store_ends_a_clamp_batchdraw::tests::a_root_uav_ends_a_clamp_batch(root descriptor, stage facts,ROOT_UAV_VIEW; aROOT_SRV_VIEWdoes not disqualify)draw::tests::title_memory_ends_a_clamp_batch(shader flags, stagememoryandmemory_dirty)draw::tests::a_read_marking_draw_may_join_a_window_and_the_writer_ends_it: aread-marking draw joins a window, the argument-writing draw after it is clamped alone
(which ends the window) and the next read-marking draw opens a new one; the writer is not
hoisted even with a free prelude, a dispatch is never hoisted or windowed.
indirect::tests::every_clamp_compiles_without_a_root_signature_attributestill coversthe single, batched and window shaders.
Measured share of the rule (perf stack, #2472 + #3197 + the Wine fix)
Same tree (
perf/best2), same binary but for this commit reverted, same switches(
VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_LOG=info), 420 s runs, medians of thelast 30 heavy reports; RTX 5090, Wine + vkd3d-proton:
on the GPUOverlap
Because the rule gates both, this branch is stacked: #3197's head
0c997d40merged onto#2472 as
055b5c89, the Wine compile fix916655cc(Slay326 is taking that into #3197with my authorship), then the rule as one commit. Against
0c997d40the branch thereforealso shows #2472 and our fork's history (59 files); the change to review is
d4e44ed5alone —
git diff 916655cc d4e44ed5,draw.rsandcopystat.rs— or rebased onto yourhead once #2472 and
916655ccare in.storing draw join a window as its last member and end the window right after it is
recorded, mine widens which draws may be ordinary members. Both go through
indirect::windowedand both end the window before anything that follows can beclamped. His next step (track written table UAVs instead of every table UAV,
stores()counts
used, not written) would narrow the predicate further; I keepusedbecause atable's UAV is not classified read or written here yet.
VICTORY_CLAMP_WINDOWstays off by default, as you asked. The rule helps with theswitch either way: without windows it extends the hoisted prefix, with them it fills the
windows.
AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T16:28:26Z.
The CI failure is WARP's wave size, not the change. Your head
d4e44edmerged ontomain63bcca4, RX 5700 XT (RDNA1, 32–64 lanes):wave_coalesced_marks_equal_per_lane_marks_on_the_gpupasses: "hardware: coalesced marks and results equal the per-lane ones" for all four wave64/coalesced variants. WARP printsno 32-lane waves; skipped.VICTORY_WARP=1(what the CI runner has): both adapters printno 32-lane waves; skipped, thenmemory_tests.rs:1220panics withneither hardware nor WARP SM 6.6 device available. That's the CI failure, not a wrong result.The fix is the same one
valu_tests::run_cases_onuses for a wave of 32 (and that I proposed for the same failure on #2920): remember the wave-size skip, and accept it in the final assert.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T16:39:06Z.
@ColorMeBoom thanks, that's exactly it, and thanks for running it on RDNA1 hardware. Taken as you proposed in
869abe58: the wave-size skip is remembered and the final assert accepts it. I checked it with clippy (-D warnings) and formatting; the test itself only runs on a 32-lane adapter here, so the WARP case is your CI run's to confirm.For reviewers: this test isn't part of the read-mark rule. It comes from the stack this draft sits on (#2958's coalesced marks, compared with per-lane marks), which is why it shows up in this PR's diff against
main. The change to review stays the last functional commit,d4e44ed5(draw.rs,copystat.rs).AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T17:09:45Z.
@neonbyte1 confirmed at
869abe5, merged ontomain63bcca4:VICTORY_WARP=1(CI's case):wave_coalesced_marks_equal_per_lane_marks_on_the_gpupasses, with both adapters printingno 32-lane waves; skipped.869abe5is green.AI use: Claude Code (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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.