GPU: draws that only read-mark join clamp hoists and windows #3531
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3531
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@neonbyte1 on GitHub · 2026-11-27 14:58 UTC · original
neonbyte1:pr/clamp-read-mark-rule→main· +13301 −2307 · 59 files · 166 commits · draftStacked 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.
A console wave64 program that reads masks whole or lanes of the other half now runs on a host without 64-lane waves when its group is one console wave (64 threads or fewer, no LDS). It runs as the console does ("console flow"): - `structure::structure_console` never resolves mask joins from what the lanes arriving know (every lane arrives); `Structured::execs` gives each vector instruction's EXEC bit. - Vector instructions are guarded by EXEC. Branches are the console's s_cbranch_*: EXEC, VCC and mask-operation SCC tests are the console wave's, from both halves' ballots exchanged through group-shared memory between group barriers, which every thread reaches since both halves branch alike. - Masks read whole are the exchanged ballots. v_readlane and v_readfirstlane read the owning half; v_writelane, v_mbcnt and mask bit tests use the console lane. The per-lane form is tried first; a program that needs the console flow is lowered again from the console structure. GPU tests on an RTX 5070 are exact against the console: s_bcnt1 over both halves (64, 48 and 32 threads), v_readlane 40, an exchange inside a branch only the lower half takes, and a loop the halves leave at different iterations with a lane read in each. The last one shows that the per-lane form, which hosts with 64-lane waves get, is wrong for it (on a Radeon iGPU): noted in docs/wave64-on-wave32.md, not changed. Co-Authored-By: Claude Opus 5.5 <[email protected]>The validator's message for an operation the stage or the entry's properties do not allow ("Entry function performs some operation that is incompatible with the shader stage or other entry properties") names neither the operation nor the property, and it is the only message when the call is in the entry function itself. `victory translate --validate` now adds to each validator failure what our own module declares and calls: its thread-group size, its wave size and its dx.op operations (`emit::last_module_summary`, kept per thread when a module is finished). Nothing of the console program is in it, so a report of counts per reason is enough to see what the refused modules have in common. Prompted by a report on #233: modules that fail validation with that message and still create pipelines, 20 of them new with #320, which I cannot reproduce with hand-assembled programs. Co-Authored-By: Claude Fable 5.2 <[email protected]>1a8a3ed) 3c961b5ea0e4246fd) 1e17e572a0b623fd3) bf13a276c5cbcef55) bf0f9511c541369c9) 28aca3b718940d32f) into the host wave sizes branch 02b955ffc902b955f) into the console flow e5ffedbb8b1e247b1) into the lane reads branch 49f31ec4ff49f31ec) into the console wave LDS branch 61568ae3307147671) eb12838eefeb12838) 5a11cf48143fab5a1) 5e4ebf3fb1The title asks for 1 245 184 descriptor slots, more than the 1 000 000 a host heap holds, and it walks them in increasing order. "Log when the high-water mark moves" is therefore one line per distinct slot: 199 846 of the first 200 000 lines of a run, ~8 000 a second, on the thread recording the frame. That was the whole of the first frame's stall: before 310 932 lines in the run, first frame 21 433 ms after 231 lines in the run, first frame 33 ms Same build, same warm caches (926 MB pipeline library, 1 347 MB shader cache), same 150 s window. What the line said - that slots above the host heap's count are not mirrored - is what the one line now says. The underlying problem is not this change: 245 184 title slots can never be mirrored because they exceed the tier-2 heap limit, which needs either several host heaps with the index arithmetic adjusted or the views above 1 M placed elsewhere. That is why the first world frames get null views. cargo test --workspace --locked; both clippy configurations with -D warnings; cargo xtask policy.In the user-data loop, a dword numbered `ROOT_VIEW_OFFSET` (4) was taken for a root view's offset without asking whether the parameter was a root descriptor at all. Root constants with five or more dwords have a real dword 4; it was looked up as a root view, none was found, and the draw or dispatch was refused ("a root view's offset: no root view, or outside title buffers") with no log line. The ray-tracing builder's dispatches were among the casualties. Ask `u.root == RootType::Descriptor` too, through a helper beside `is_root_view`, so a root constant's dword 4 goes to the title's user data as the value it is. The test pins the predicate: descriptor dword 4 is an offset, constants and table dword 4 are not.A UAV read as float and also used by an atomic needs two handles: an atomic on the float handle is invalid SPIR-V after conversion ("AtomicOr/AtomicUMax: expected Result Type to be integer scalar type") and crashes NVIDIA's compiler in vkCreateComputePipelines. #177 added the element type to the `handles` key. main has since added `entry_handles` and `join_handles`, which had the same problem; they are keyed by both property words now as well. Includes #177's test, with `view_marks` added for the current `Parts`. Co-authored-by: Ortomanic <[email protected]> Co-authored-by: gingertonik <[email protected]>Translated shaders clamp view indices below HEAP_VIEWS (2^21) and read the null buffer views two below it, which assumes a host heap that large. NVIDIA caps shader-visible view heaps at 1,000,000: the heap fell back to the cap with 2^16 dynamic slots, no room for the null buffer views ("no room for the null buffer views"), title slots past its end, and indices up to 2^21 - 1 that read past the heap. On a Windows 10 machine with an NVIDIA card the device was removed (DXGI_ERROR_INVALID_CALL) about a minute in, still loading. Whether the host takes a heap of HEAP_VIEWS is now asked once, before the first translation and the first heap (probe_view_limit). A host that does not lowers the view limit to its cap (set_view_heap_limit): shaders clamp below it and read the null buffer views two below it, and the heap is made at the cap with the full 2^18 dynamic range (2^16 ran out in the world there), room for 8,192 copy view pairs, the null views and a last null slot at its top, and the title's slots below them (721,469; the title's highest index seen is about 720,000). The limit is part of the shader cache key. On that machine the heap and title-memory tests (dynamic slots, lists_share_a_table) now pass; hosts that take HEAP_VIEWS are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018sSQTeDQ6Kc6DEkgPbAww8219878a) into wip/main-base df92de20f6Under Wine, D3DCompile is Wine's d3dcompiler_47 (vkd3d-shader HLSL): it has no methods on writable byte address buffers (E5005 'Load' is not defined on RWByteAddressBuffer) and ignores a [RootSignature] attribute, so the code holds no root signature to make. Every run-time shader of ours failed there: the argument clamp ("no argument clamp: indirect execution dropped", every indirect draw and dispatch then dropped as not bounded), the depth twin's 16-bit conversion ("no depth conversion"), and the tests' own shaders. A new module, compute, compiles a shader and serializes its root signature in Rust from the parameters the host binds. The clamp keeps main's design (one group, tiles of 64, groupshared costs charged in order, the list's budget, the record's rest copied) with the title's records a StructuredBuffer<uint> (t0) and the clamped records and the budget RWStructuredBuffer<uint> (u0, u1), indexed in words: bound() already refuses addresses and strides not multiples of 4. Its root signature is b0 (4 constants), SRV t0, UAV u1, UAV u0, as bound() binds them. The depth conversion indexes its scratch buffer in words (footprint offsets and pitches are multiples of 4) with b0 (8 constants) and UAV u0. Test shaders lose their RootSignature attributes the same way. A new test checks every word the clamp writes for draws, indexed draws, dispatches, mesh dispatches, records past the budget and the budget spent. The approach is Mumogg's (#1279: structured buffers indexed in words, the root signature serialized beside the shader), ported to main's rewritten clamp and extended to the depth conversion.lowershelper takes the console flow as emit does 3213bb8e7863bcca4) into #439 f7d4feb43f63bcca4) f93574a1a1open() made the empty library from an empty slice, whose pointer is not null. vkd3d-proton (Wine) refuses a blob pointer with no bytes (d3d12_pipeline_library_init: `!blob_length && blob` is E_INVALIDARG), so under Wine no host pipeline library was made ("no host pipeline library: pipelines are not kept"), also after a rejected blob; the library tests failed with "an empty library". The empty library is now asked for with a null blob, which D3D12 takes as well.Partsliteral 51b95f4d52d6c32b03) 6983aa3f0a@ColorMeBoom on GitHub · 2026-11-27 16:28 UTC · original
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).
@neonbyte1 on GitHub · 2026-11-27 16:39 UTC · original
@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.
@ColorMeBoom on GitHub · 2026-11-27 17:09 UTC · original
@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.