GPU: indirect records clamped into a ring of the list's behind one enhanced barrier, and in the list's prelude where the list did not write them #1000
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1000
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1000"
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?
@PiloteCode on GitHub · 2026-11-25 15:34 UTC · original
PiloteCode:pr/indirect-prelude→main· +1461 −92 · 11 files · 8 commits · openBased on
085ee7c4(the first version was on0b0074e0).mainhas since moved to9c184b35, five commits on: as of now the branch merges with it without conflict, and the merged tree builds and passes the checks (see "Tested"). Eight commits:main. The two this PR had before (draw.rs,indirect.rsandresource.rs;shadow.rs) are still needed, andmain's seven newer commits need a third (fpsbox.rs,pipeline/library.rs,queue.rs,shadow.rs; with all featuresdraw.rsandwatch.rs). Without themcargo clippy --workspace --all-targets --locked -- -D warningsfails on085ee7c4with the pinned toolchain: 8 errors invictory-gpu, 10 with--all-features. No change of behaviour; each can be left out on its own.indirect.rs, for runs of the suite on several threads (see "Tested").The changes are in
indirect.rs,host.rs,draw.rs,copystat.rsandshadow.rs. Everything new keepsmain's clamp program as it is: its group charging, the budget in the card's memory, the windows and the gathered records (both off by default).What changed since the first version
main's gathered records (VICTORY_INDIRECT_GATHER,465b94f5). The conflicts were inindirect.rs,draw.rs,host.rsand the README.main's gather is unchanged:gather,GatherSet,record_gather_as,record_gathersand the program's bit 2 are byte for bytemain's.record_clamp_asismain's, byte for byte. The first version rewrote its argument code into a helper. Now the helper (clamp_arguments) serves only the clamps that write room of the ring, and the clamp into the one scratch buffer keeps its own code.What was wrong
Every indirect execution's records are clamped by a compute pass of ours into the list's one scratch buffer. That costs two changes of state per clamp: the buffer goes from indirect arguments to unordered access before the pass, and back after it. Each change waits for all the card's work before it.
So every clamp waited for the last indirect call to have read the buffer, and the call after it waited for the clamp. The title makes about 2,500 such calls a frame in the gameplay. In a timing run of the gameplay's opening (RTX 5090, our tree, before
main's changes to the clamp), our clamps took 33 ms of the card's ~100 ms a frame.What changes
A ring of clamped records (
indirect::ring,HostList::indirect_ring)Each clamp writes room of its own in a ring of the list's, so it overwrites nothing an earlier call still reads:
The ring is on where the device reports enhanced barriers (
D3D12_OPTIONS12).VICTORY_INDIRECT_RING=0clamps into the one scratch buffer, as before, throughmain'srecord_clamp_as.Measured in that timing run: the clamps went from 33 to 19 ms of card time a frame, the card's commands from 102 to 95 ms, and frames from 179 to 171 ms (median) and 210 to 189 ms (mean). Part of the wait moved to the indirect calls: the card still switches from drawing to compute and back for each clamp.
Clamps in the list's prelude (
indirect::early,HostList::writes_declared)A clamp in the list still stops the card twice: it turns from drawing to compute and back, and the barrier after it holds up the indirect call, so the calls around it cannot overlap.
Some records are not written by any shader the list recorded before the command. The list now keeps the ranges its shaders declare written (
Step::GpuWrite), each once. For records outside them, the card holds them as they are when the list begins: the title's CPU or an earlier list wrote them. Their clamps (no count buffer) are noted for the list's prelude, which the card runs just before the list at each of its submissions:The command reads its room of the ring as before, and the list keeps its pipeline and root bindings: nothing of ours goes into the list for such a record.
The budget. The prelude's clamps are charged to a budget of their own (
HostList::early_budget, 256 bytes in the card's memory, made at the first such clamp), which the prelude zeroes first at each submission, the waymaindoes for its gathered records. The list's own budget is zeroed inside the list, where its first clamp is recorded, so a clamp that runs before the list can neither start from zero in it nor leave its charge there. A list's work is so bounded once for each place its records are clamped in: the prelude's gathered records, the prelude's clamps, the list.Of the clamps of a timing run of the gameplay, 788 draw clamps a frame had records from before the list and 228 had records written in it; dispatches, 228 and 679. Before this change, our clamps took 6.8 ms of card time a frame at the start of the gameplay. With it, they took about 1.25 ms a frame: about 0.5 ms for the ~990 clamps left in the lists and about 0.75 ms for the preludes. That second timing run was of a later build of our tree, which had other changes too.
The prelude needs the ring.
VICTORY_INDIRECT_EARLY=0clamps every record in the list, as before.Records in title memory in place. Shaders that write title memory in place (
VICTORY_INPLACE, off by default) declare nothing. Records in such memory are taken as written and clamped in the list.With
main's gathered records (VICTORY_INDIRECT_GATHER=1)Both put clamps in the prelude. They are kept apart:
main. What is not gathered (a dispatch, several records, a count buffer, shaders that store to buffers, a list that no longer gathers, a full set) is clamped by this PR's code: in the prelude if the list did not write it and it has no count buffer, otherwise in the list, into the ring.main's two changes of state a list. Gathered records do not go to the ring.main, then this PR's clamps. Up to and including the gathered passes the prelude is whatmainrecords; withVICTORY_INDIRECT_EARLY=0, or no such clamp, it ismain's prelude.Diagnostics (diagnostics builds)
VICTORY_GPU_TIMING) times the prelude as one command ("prelude (ours): N clamps"); the list keeps two of its timestamps for it.Measured effect, and what was not measured here
The numbers above are from timing runs of our tree on an RTX 5090. There these changes are on by default, and the general test runs of our integration branches with them (opening cutscene, gameplay from a save) had no device loss. HrHd ported the first version onto a tree of his own on current
mainand measured 253.9-272.8 → 227.7-231.7 ms a frame on an RTX 4060 Ti, with no device removal (comment above).This branch, as it is on
085ee7c4: its tests ran on the software adapter and on an RTX 5090 (see "Tested"); in the title it has not drawn an indirect command yet (see "Not tested").Switches
VICTORY_INDIRECT_RING=0: the one scratch buffer, as beforeVICTORY_INDIRECT_EARLY=0: every clamp in the list, as beforeTested
On
085ee7c4, with the host device on the software adapter (VICTORY_D3D12_WARP=1,--features diagnostics). The software adapter takes enhanced barriers, so the ring and prelude tests ran rather than being skipped. The test runs below were made at00c97825; the tipb333628bdiffers from it by three lines of a test's comment, and at it the checks that build, the serial run and 5 runs on several threads were made again: clippy clean both ways, the policy and both builds pass, 206 passed and 1 failed serially, and the 5 runs on several threads all completed with the same result.cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with--all-features: clean.cargo xtask policy: passes (host.rsis 425,559 bytes of the 524,288 allowed).cargo build --release -p victoryandcargo build --profile diag -p victory --features diagnostics: both pass.cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 206 passed, 1 failed, 6 ignored.VICTORY_INDIRECT_RING=0: serially 205 passed, 2 failed, 6 ignored; of 5 runs on several threads 4 completed (206 passed, 1 failed) and 1 died. The host-list tests that follow the switch (bound,bound_ahead, the window check) then takemain's scratch buffer; the tests that ask for the ring still run it.VICTORY_INDIRECT_GATHER=1(ring on): serially 205 passed, 2 failed, 6 ignored; 5 runs on several threads all completed (206 passed and 1 failed in 3, 205 and 2 in 1, 204 and 3 in 1). The switch is read indraw.rs, which no test reaches: what covers the two together is the test of a prelude with both, named below, whatever the switch.The failures are
main's:depth_bounds_pipeline_loads_and_filters_drawsfails in every run: the software adapter does not reject the pixels outside the depth bounds. The same onmain.watch's tests failed in one run on several threads (a_view_mapped_beside_a_guarded_one_makes_it_check_again); three others of them did so inmain's runs on several threads here.warp_budget_saturates_without_wraparound_and_preserves_draw_fieldsfails in some runs: its two groups of records may charge the budget in either order (#849, #970). It runsmain'srecord_clamp_as, which this PR does not change. Alone, it passed 2 times of 20 on plainmainhere, and 56 of 200 at this branch's tip.Plain
main(085ee7c4), run the same way: serially 199 passed, 1 failed (depth_bounds_pipeline_loads_and_filters_draws), 6 ignored. Of 10 runs on several threads, 4 completed (199 passed and 1 failed in 2, 198 and 2 in 2: the same two tests) and 6 died of an access violation.Runs on several threads. On plain
main, the suite run with the default test threads died of an access violation in 6 runs of 10 through cargo, and in 6 of 11 run earlier from the test binary, here: inside the software rasterizer (d3d10warp.dll), at a different place each time (in the two crash dumps read, which came from a build ofmainwith a change to the test harness, not plainmain: a null read in a call made by aqueue2test, and a wild write on one of the rasterizer's own threads). It needs the device tests ofindirect.rsrunning side by side: with none of that module's tests, none of 10 runs died. With the seven tests this PR adds it died more often (17 runs of 22). The last commit makes those tests take a lock of their module while they use a device, so that one of them runs at a time: of 39 runs with it (12 while trying it, the 12, 5 and 5 above, and 5 at the tip), 37 completed and 2 died, and in each of the 37 both tests of the ring and of the prelude passed: 12 and then 11 times in a row, and in all 5 at the tip. Nothing changes in a serial run. The cause inside the rasterizer was not found; this keeps the suite's own tests from meeting it.On an RTX 5090 (the branch's tip, the host device on the card, no
VICTORY_D3D12_WARP):cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 207 passed, 0 failed, 6 ignored. The card takes enhanced barriers, so the ring and prelude tests ran on it; the depth-bounds test and the budget test both passed there.Merged with
9c184b35(a trial merge, not pushed):cargo clippy --workspace --all-targets --locked -- -D warningsand the same with--all-featuresare clean,cargo xtask policypasses, and the serial run on the software adapter gives 205 passed, 2 failed, 6 ignored: the same two tests as above.main'sprofile::tests::stacks_that_mean_nothing_are_walked_without_a_faultwas left out of that run: on this machine it ends the test process with an access violation, onmainas well.The debug layer was not on. The D3D12 debug layer is not installed on the machine these ran on, so the tests' checks of its messages (
host.log_messages()) found nothing to read, for this version and for the first. What the debug layer says of the ring's barriers has not been seen.New and changed tests:
The ring: each clamp gets room of its own, a full ring is replaced by a bigger one, a submission runs with the enhanced barriers, and after a reset the room is taken from the ring's start.
The count buffer through the ring's path (the test's own device, a clamp made for it): the two executions of
main's count-buffer test, each clamped into room of its own in one buffer. The garbage past the count charges nothing, all five valid dispatches run, the title's records and counts stay as they were, and the second clamp leaves the first's room alone.The budget through the ring's path (the same way): it saturates without wrapping, two draws fit, every other one runs empty with its other words kept, and nothing is written before the clamp's room. The two draws that fit are the first two of either group: which group charges first is the card's choice.
The prelude on a host list: three clamps noted for a list's prelude run there at each submission. Each record is read clamped: a record of 70,000 groups runs 65,535, and one of all ones runs empty. The title's records stay as they were. A second submission, with records the CPU changed in between, clamps them again. A reset forgets the clamps.
The prelude on the test's own device (a clamp made for it, passed as an argument): a list recorded once runs twice behind a prelude recorded for each run; the budget then holds the second run's charge alone.
The two budgets: a list whose own clamps spend its budget leaves a record clamped in its prelude to run, at a second submission too; and the other way round.
Gathered records and the prelude's clamps side by side on a host list: each command reads its record clamped, from the set's scratch buffer or from the ring, at a second submission too; what one kind spends of its budget leaves the other kind's records theirs.
The scratch buffer's reuse is tested on its own path (the ring off).
The window executions run on both paths.
The budget test (
host_list_budget_starts_empty_at_each_submission) clamps its spending and the record after it together. Two clamps into the ring are not ordered on the card: a clamp has no barrier before it, and the one after it orders the indirect read, not the next clamp. A general test on the RTX 5090 found the second clamp's charge first.This is not a change of behaviour in the title. With the ring, a list's clamps charge its budget in the card's order, so once garbage records spend the budget, which records run empty is the card's choice. The budget still bounds the list's work.
The two points of the review
clamp_argumentsand the count path. Not reproduced. Each test alone on the software adapter, the two forms ofrecord_clamp_asbuilt from this branch's tip and run in turn:warp_count_buffer_ignores_garbage_tail_and_preserves_sourcepassed 20 times of 20 withmain's inline code and 20 of 20 with the first version's helper;warp_budget_saturates_without_wraparound_and_preserves_draw_fieldspassed 9 of 20 and 3 of 20, and over 200 runs each 56 and 52. That second test fails on plainmaintoo (2 passes of 20): it is the test of #849 and #970. The helper computes the same constants and addresses; no defect was found in it. Even sorecord_clamp_asis nowmain's own code, and the count buffer and the budget are also tested through the ring's path.mainas well (above). With the lock, both tests passed in each of the 37 runs that completed (of 39). The prelude's clamps also take the pipeline as an argument now, and a test runs them on its own device.Overlaps with open pull requests
indirect::boundandindirect::bound_ahead: the scratch size of a split dispatch, whose records are bigger. Whichever goes in second takes both changes, as in our tree: ascratch_bytessize passed to the ring or the scratch buffer. #993 also adds a kind to the clamp program, which this PR does not touch.indirect.rsordraw.rsnear these changes.Not tested
VICTORY_INDIRECT_WINDOW=1andVICTORY_INDIRECT_GATHER=1) had no device removal and no exception, but with this build's cold pipeline cache it was still loading when it ended: no indirect command was drawn. The first version ran on an RTX 4060 Ti in the reviewer's port.main(085ee7c4) is merged with the indirect code placed as in this branch (gathered records first, then the prelude's clamps with their own budget, the rest in the list into the ring). One run of the save's gameplay there on the RTX 5090 with all of it on, at about 3,900 draws a frame: 1,324 commands a frame read from a window, 1,195 read a gathered record, 843 were clamped in preludes and the rest in their lists; 210 s, no device removal, and neither of the two "could not be clamped in its prelude" errors. That tree has other changes too.main's path is taken.A clamp in the list stops the card twice: it turns from drawing to compute for the clamp and back, and the barrier after it waits for it before the indirect call, so the calls around it cannot overlap (the clamps took 19 ms of the card's ~95 a frame in the gameplay's timing run, 2,500 a frame; 6.8 ms in 1,021 at the start of the gameplay). Where no shader the list recorded before the command may write the records (by the writes its shaders declare, now kept per list as ranges of title memory), the card holds them as they are when the list begins: the title's CPU wrote them, or an earlier list's shaders. Their clamps now go to the list's prelude, which runs just before the list at each of its submissions: a wait for earlier shader writes, the clamps with no wait between them (each writes room of its own in the list's ring; the budget is taken atomically), and one barrier from their writes to the indirect reads. The command reads its room of the ring as before, and the list keeps its pipeline and root bindings. In that timing run's clamps: draws 788 a frame with records from before the list, 228 written in it; dispatches 228 and 679. The prelude's clamps are charged to a budget of their own, which the prelude zeroes first at each submission, as main's gathered records are to theirs. The list's own budget is zeroed inside the list, where its first clamp is recorded: a clamp in the prelude would find in it what the list's last run left, and what it charged would be zeroed away (as this change was first sent, it charged the list's budget so). Nothing of ours goes into the list for such a record, the zeroing of a budget included. With main's gathered records (VICTORY_INDIRECT_GATHER=1) the prelude records the gathered sets' passes first, as they are on main, then these clamps: the two write different buffers and charge different budgets, so neither changes what the other clamps or leaves empty. A draw's single record that misses its window is gathered first, as without this change; what is not gathered comes here if the list did not write it. A prelude that cannot record these clamps fails, as one that cannot record the gathered passes does: the rooms would hold no clamped records. The timing run times the prelude as one command ("prelude (ours)"), and the frame lines count the clamps by where their records come from. VICTORY_INDIRECT_EARLY=0 clamps every record in the list, as before; it needs the ring (enhanced barriers). Tested with the host device on the software adapter: the clamps noted for the prelude cut a record past 65,535 groups and empty one of all ones, leave the title's records as they were, and clamp anew at a second submission of the list; a list whose own clamps spend its budget leaves a record clamped in its prelude to run at each submission, and the other way round. And on the test's own device with a clamp made for it (the prelude's clamps take the clamp as an argument there): a list recorded once runs twice behind a prelude recorded for each run, and the budget holds the second run's charge alone.@HrHd on GitHub · 2026-11-25 20:32 UTC · original
Measured here on an RTX 4060 Ti at 1080p-in / 8-bit out, clamp + ambient on, 4.8k draws, four samples 70 s apart: 227.7, 229.3, 230.0, 231.7 ms (0.047 ms/draw), 0 device removals, picture unchanged. Before the ring the same configuration was 253.9-272.8 ms (0.052), so this is about 10 % off the clamp for free — thanks, it is the best rung so far.
Two things from porting it onto current
main(this branch is based on0b0074e0):clamp_argumentsregresses the count path.warp_count_buffer_ignores_garbage_tail_and_preserves_sourceandwarp_budget_saturates_without_wraparound_and_preserves_draw_fieldsfail, alone and on WARP, after the refactor: two of five valid dispatches are dropped and the budget keeps a second wave. Keepingrecord_clamp_as's old inline argument code (with the narrow-wait path) makes both pass again, so that is what runs here, anddispatch_clampserves onlyrecord_gather_as.ring_gives_each_clamp_room_of_its_own,early_clamps_run_in_the_prelude_at_each_submission) pass on their own but fail in the full suite on WARP: the clamp pipeline is a process-globalOnceLock, so a later test's device runs the first test's pipeline.The gather still works against the ring: its dispatch passes the offset table as root view 2, not the source (with the source there every slot stays 0xEEEEEEEE and the WARP gather test catches it).
@PiloteCode on GitHub · 2026-11-25 22:19 UTC · original
@HrHd thanks for porting it and for the numbers: 253.9-272.8 → 227.7-231.7 ms on a 4060 Ti with no device removal is the first measurement of this on a card that is not ours.
The branch is rebuilt on
085ee7c4, withmain's gathered records. On your two points:1.
clamp_argumentsand the count path. We could not reproduce a regression, on the software adapter, each test alone, the two forms ofrecord_clamp_asbuilt from the new tip and run in turn:main's inline codewarp_count_buffer_ignores_garbage_tail_and_preserves_sourcewarp_budget_saturates_without_wraparound_and_preserves_draw_fieldsThe budget test fails with either, and on plain
maintoo (2 passes of 20 here): its two groups of records may charge the budget in either order, which is what #849 and #970 fix. "The budget keeps a second wave" is that. The count-buffer test we never saw fail; the helper computes the same constants and addresses as the inline code, so if it dropped two dispatches in your tree, the place to look is where the merge met the narrow-wait path.Even so, you are right that the refactor bought nothing there:
record_clamp_asis nowmain's own code, byte for byte, andclamp_argumentsserves only the clamps that write room of the ring. The count buffer and the budget are now also tested through the ring's path, on the test's own device.2. The two new tests in a full run. The pipeline is not what fails:
clamp()is made on the host device, and both tests record on host lists of that same device. What we did find is that the whole suite dies on several test threads with the host device on the software adapter: an access violation insided3d10warp.dll, at a different place each time. Plainmaindoes it too (12 runs of 21 here); it needs the device tests ofindirect.rsrunning side by side (none of 10 runs died without them), and this PR's extra tests made it more frequent (17 of 22). The last commit makes those tests take a lock while they use a device: 2 runs of 39 have died since, and both tests passed in each of the other 37. The prelude's clamps also take the pipeline as an argument now, and a test runs them on its own device with a pipeline made for it.The gather.
record_gather_asis left asmainhas it (the table as root view 2). In the prelude the gathered sets' passes come first, then this PR's clamps; gathered records do not go to the ring.One thing your port has from the first version and may want changed: the prelude's clamps charged the list's own budget, which the list zeroes inside itself, so they started from what the list's last run had left and their charge was zeroed away. They now have a budget of their own, zeroed first in the prelude (
HostList::early_budget), asmain's gathered records have.On a card. The branch's tests on an RTX 5090 (the host device on the card): 207 passed, 0 failed, 6 ignored, the ring and prelude tests among them. In the title this exact branch has not drawn an indirect command yet: one 240 s run of a save was still loading when it ended (a cold pipeline cache for this build; no device removal). Our own tree, with
mainmerged and the indirect code placed as here, ran the save's gameplay with the ring, the prelude's clamps andVICTORY_INDIRECT_GATHER=1together: per frame 1,324 commands read from a window, 1,195 read a gathered record, 843 were clamped in preludes; 210 s, no device removal. If you run this version on your 4060 Ti, your numbers would be the first of it onmainproper.mainmoved on to9c184b35meanwhile: the branch merges with it without conflict, and the merged tree passes clippy, the policy check and the serial test run (205 passed, the two known failures).Not seen yet: what the D3D12 debug layer says of the ring's barriers (it is not installed on the machine the tests ran on).
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.