Repository navigation
Conversation
…OW=1) Each indirect execution had a clamp of its own: a wait for all earlier work, a compute dispatch, another wait, then the draw, about 5,100 times a world frame. With the switch, an indirect draw opens a window: one clamp pass recorded where the single clamp would be, reading a table the CPU fills while recording. The indirect draws after it that store to no buffer add their records to that table and read them clamped from the window's part of the argument buffer, with no pass and no barrier of their own. The pass clamps in draw order and charges the list's budget in that order, as the single clamps did. A window ends at any draw, dispatch or unordered-access clear other than a joining indirect draw, at an indirect dispatch, at an indirect draw whose shaders may store, at work a host library records and at the list's end; a draw opens a new one when the table, the bytes or the records are full or its arguments lie in a host copy the pass has no view of. Off by default; the clamp shader is the host's own, so the translator's source hash and the shader cache stay as they are. Counters per frame in the copy statistics line (diagnostics).
Regression test for the case reported on Marvisak#3197 together with Marvisak#2996 (5385cc6).
The window's pass carried its own copy of the mesh bounds; a change to the single clamp's rule (Marvisak#2996, 5385cc6) left the window on the old one and dropped mesh groups (reported on Marvisak#3197). Both shaders now take the rule from one HLSL function.
The window's mesh rule divergence fixed in bdc4167 was found and integrated first by Andrew (d16ae7d) on Marvisak#3197. Co-authored-by: Andrew <296776509+andrewpozdnakov7-jpg@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #3197 (
pr/clamp-window,0c997d40) — draft until it lands. The diff against0c997d40is the one commit here and nothing else (crates/victory-gpu/src/{indirect,draw,list,copystat}.rs). #2472 is not needed; #3531 (our read-mark rule) is not needed but composes (see Overlap).What's wrong
#3197's windows refuse every indirect dispatch (
kind != DISPATCHindraw::execute_indirect) and every execution whose shaders may store (draw::may_store). Each of those keeps a clamp of its own: a wait for all earlier work, a one-group compute pass, another wait, the execution, then the transition back that waits for its compute work. Two traced world frames: 1,618 of 1,822 indirect dispatches were recorded right after another indirect dispatch with nothing between it and them (no barrier, no barrier group, no pipeline sync, no other command); each had a clamp of its own and ran alone.The rule, and why it is safe
A window's pass clamps every record before the window's first execution runs. An execution that stores can write the records of a later one; on the console, a later execution reads its records when the command processor reaches it, which may be while an earlier one still runs — unless the title put a barrier or a pipeline sync between them. Records written by one execution and read by the next with neither between race on the console too, so the title does not do that. So, with a window open:
List::Barrier), barrier group (BarrierGroups) or pipeline sync (Sync) came between (indirect::Run,indirect::stale_window). A barrier after an execution that may store ends what the window takes: the next execution opens a window of its own, whose pass runs (and waits) after the earlier execution.end_window).Nothing about which executions run, in what order, or what they read changes; only where their records are clamped moves. The executions also run without our waits between them, as the title recorded them: in base each indirect dispatch was ordered against its neighbours only by our clamps' barriers, which the title never asked for (direct dispatches have none either).
What changes
indirect.rs:windowedtakesstoresand records it in a per-windowRun(stored,fresh);Run::takesrefuses the next execution after a barrier or pipeline sync following one that may store.stale_window(list)is the barrier/sync hook. The window's pass needed no change: it already clamps a dispatch record with the single clamp's bounds (x groups past 65,535, more than 2^20 groups in all, 64 threads a group, the list's budget in window order), and mesh/draw/indexed records as before.list.rs:barrier,barrier_groupsandsynccallstale_window.syncdid nothing and records nothing; it is one cached-flag check now.draw.rs:execute_indirectasks only for the switch and a host pipeline; the kind andmay_storeare no longer part of the decision (a dispatch, and an execution that may store, join).may_storeis asked only with the switch on, so an off build does the work GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #3197 promises (one flag check). An execution the window cannot take is clamped on its own as before, which ends the window.copystat.rs(diagnostics):clamps per framenow splits the windowed executions into indirect dispatches and draws that may store, and counts the executions that opened a window because a barrier or pipeline sync came after one that may store (ClampWindowDispatches,ClampWindowStores,ClampStale);ClampStoringis now only the draws that may store that a window refused (alignment, size, a full table or records, a fifth source buffer).The switch is unchanged:
VICTORY_CLAMP_WINDOW=1, off by default, and with it unset the added work is one cached-flag check per draw plus one per barrier, barrier group and sync.Tests
GPU test status: observed on a Wine-fixed scaffold, not on the branch itself. #3197's head cannot run any clamp test under Wine here: its clamp shaders put their root signature in a
[RootSignature]attribute (which Wine'sD3DCompileignores) and read the budget throughRWByteAddressBuffer::Load(E5005 there), soclamp()isNoneandargument_clamp_builds— #3197's own test — fails, as do all 14 clamp tests onef4224db1and on0c997d40alike (scratch/PrGaps/gpu.log,gpu-window.log). That fix is the one Slay326 is taking into #3197 (1aa472de7/916655cc), not in its head. I therefore built a throwaway scaffold,tmp/gaps-wine-test= this commit + that fix'scrate::computeand shader idiom (root signatures serialized in Rust, the budget aRWStructuredBuffer<uint>; no logic changed), and ran the same device tests there: all 15indirect::tests::pass, including the three below (scratch/PrGaps/wine-gpu.log, exit 101 only from sevendraw::tests::a_*texture tests, which fail atdraw.rs:2552on that tree's own test helper building a root signature from a blob — the same Wine gap, untouched by this change).CPU (no device; observed):
indirect::tests::a_window_takes_after_stores_only_until_a_barrier— theRunrule: an empty window takes; a barrier after executions that do not store leaves it taking; right after one that may store it takes; a barrier after that one stops it. Passes onef4224db1. Fails without the change (the window takes anything that fits).GPU (device; the tests write their own records, no game data):
indirect::tests::dispatch_windows_clamp_as_single_clamps_do— passes ontmp/gaps-wine-test. 60 indirect dispatch records from one buffer with draws interleaved in the same windows, and a 6-record dispatch at the end: every record is the single clamp's word for word (same()runs the same steps twice, once clamped one at a time and once windowed). Covers x groups past 65,535, more than 2^20 groups in all, plain records, all-ones garbage, the limit case(1024,1024,1), zero groups, and a budget that runs out in the middle of the window (the records after it run empty).indirect::tests::a_barrier_after_a_store_ends_what_the_window_takes— passes ontmp/gaps-wine-test. A store between two executions, with and without a barrier: with the barrier the second record is clamped from the value the store wrote ([9,1,1], the single clamp's answer); without it one window clamps both up front ([5,1,1]). The barrier half fails without the change.windows_clamp_as_single_clamps_do,a_store_ends_the_window,a_window_clamps_max_records_whatever_the_count,windows_leave_the_argument_buffer_common,a_spent_budget_stays_spent,rejected_records_do_not_wrap_the_budget,the_budget_goes_to_the_first_records,a_record_that_does_not_fit_ends_the_budget,windowed_mesh_grids_are_the_single_clamps,argument_buffers_move_from_their_current_states,argument_clamp_builds) still pass with the newwindowedsignature and theRunrule.host()isNone).Measured
Our test stack (
perf/gpu-gaps@c3886d64d: upstreammainplus the open NVIDIA/Wine stack — among them #3197, #2472, #2312, #3531 and the Wine compiler fix), RTX 5090, Linux/Wine 11.22 + vkd3d-proton (GE-Proton11-14), headless gamescope, the title's window fitted to 1920×1080 (console Xbox Series X), prison yard after the intro, warm shader cache, 420 s runs, A(on)-B(off) then A-B again. Medians of the last 30 frame reports; the only difference between A and B isVICTORY_GPU_GAPS=1— the same code this branch ships behindVICTORY_CLAMP_WINDOWalone.Env, both:
VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_LOG=info VICTORY_EARLY_RELEASE=1 VICTORY_EARLY_BARRIERS=1; A addsVICTORY_GPU_GAPS=1.Runs:
09034a7-gaps-on-u1,09034a8-gaps-off-u1(pair 1),09034a8d-gaps-on-u2,09034a8e-gaps-off-u2(pair 2). No device removal, no crash in any of the four.Read that table carefully: on that stack every indirect dispatch takes #2312's spread layout (930 and 924 a frame,
clamps per frame by reason), and only the single clamp writes a spread record — so on that stack the joins came from the ~110 indirect draws whose shaders may store, and the dispatch half of this change contributed nothing measurable there. The dispatch saving is expected on a tree without #2312 (upstreammain, where those records clamp to 65,535 groups in x), and on a tree with it only once the window's pass can spread a record too. I have not measured the dispatch half in game; the 1,618-of-1,822 figure above is a count from two traced world frames, not a frame-time result.Picture check against the control at frames 1700 and 2048 (luma, from the saved frames of the four runs): mean luma 45.5 vs 45.8 and 45.0 vs 45.2 (pair 1), 45.6 vs 45.5 and 44.9 vs 45.0 (pair 2); share of pixels differing by more than 32 of 255: 7.5 % and 7.7 % (pair 1 — the character's animation phase and input hint differ, the same order as two runs of one binary), 0.3 % and 0.5 % (pair 2). No missing geometry, shadows or lighting.
Not tested
1aa472de7/916655cc) the stack has, so it does not run under Wine here yet; the GPU tests were run ontmp/gaps-wine-test(this commit plus that fix's compiler/root-signature mechanics only), not on the branch itself. The in-game numbers come from the same change on the stack (above), which is why GPU, Shaders: spread compute dispatches past 65,535 groups in x across z (fixes #2256) #2312 hides the dispatch half there.draw.rsrouting (which execution opens, joins or ends a window) has no CPU test:execute_indirectneeds a host pipeline and a list. The window pass's records are covered by the GPU tests above; the routing is covered by the runs.Overlap
windowed, so theRunrule only applies to windows. On a tree with both, a storing execution that a prelude hoisted keeps its ordering as GPU: hoist and batch indirect argument clamps into the list prelude #2472 gives it; not measured.may_storeto "may write arguments". Composes: fewer executions count as storing, so fewer barriers end a window; this branch does not touch that predicate.AI-assisted (Claude); measured on my machine, no game data shared.