Repository navigation
Conversation
The coalesced pump and `take_ready_with` join ready segments of several queues into one host submission (pragyaangaur#419). The lists of a piece are prepared together: all their steps run on the CPU before the GPU runs the first command of any of them. `can_join` keeps a list that reads title memory when its steps run (a copy, a move, a fill) out of a piece whose shaders write or that has work to do after it ran. It was asked only across queues, across a wait the piece's bottom-of-pipe writes hold, and across a fence wait on a deferred Signal; across queues, of the first segment of the queue's run only. Three places where the per-queue pump ran the piece first took the next segment with no question: - the queue's own Signal, deferred behind the piece: two submissions of one queue, ready together, became one piece; - a segment whose waits already hold, behind segments of its own queue (a list that starts with a wait, or the second half of a list cut at a wait); - the later segments of a queue's run joined across queues. In each, a list that reads title memory was prepared before the shaders of a segment ahead of it in the piece had run, and read the bytes of before. Now a segment of a queue whose Signal waits behind the piece, and a segment with waits, are join boundaries while the piece is not empty, and at every boundary `can_join` is asked of each segment of the run the per-queue pump kept together from there (`run_from_head`: the segment, then the segments after it with no waits, across fence waits that already hold, up to the queue's next Signal, segment with waits, wait that does not hold, or action). The run joins whole, or the piece runs and the run starts the next piece whole. So no run that pump kept together is split, and a piece never starts where that pump did not start one: a frame gets at most the pieces the per-queue pump gave. Where `can_join` agrees, nothing changes. A split is counted in `hazard_splits`. VICTORY_COALESCE_PIECES=0 still gives the per-queue pump. Tests (native): six in hold::tests, each failing on the commit before with the writer and the reader in one piece and no join asked, and passing here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…writes A list's title copies run on the CPU when it is submitted, in recorded order with the refreshes of host copies, and all before the GPU runs the submission's first command. A buffer's host copy so has one content per submission: what the last copy left. A pass that reads constants through a table, followed in the same submission by a title copy into them, reads the later values. This adds the bookkeeping that finds such ranges (`crate::rewritten`), with nothing using it yet: `Reads` holds the constant ranges a submission's passes read so far and the bytes its shaders were declared to write; a title copy into a read range enters the shared bytes in `Known`, from which the next recording takes a snapshot. The first submission showing a range is counted, not helped; a range not shown for 64 to 128 frames is forgotten; a range a shader of the submission writes before the pass is left in place. `VICTORY_SNAPSHOT_CONSTANTS=0` turns it off. `Ranges` gains `new` (const, for a static) and `overlaps`. The module is allowed to be unused until the commit that wires it into draws and submission. Tests (native): the learning rules in rewritten.rs and `overlapping_is_sharing_a_byte` in ranges.rs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A shader reads the title's descriptor tables in place unless something has to differ for it: the table reaches past a capped host heap, or the shader moves 16-bit float or signed buffer views as integers and is shown their unsigned twins. A constant view reading a snapshot (the commit before) is a third reason. `crate::fresh` holds why a table is made afresh (`Why`) and the key that tells two such tables apart within a list: each slot's record, whether the shader moves halves there, the snapshot a constant view reads there, and whether the slots are made again at submission. A table needing a twin and a snapshot is one table holding both, and no table with only one of them stands for it. Plain std, used from the next commit (allowed to be unused until then). Tests (native): the twin-and-snapshot key tests in fresh.rs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…mission rewrites A list's title copies run on the CPU when it is submitted, in recorded order with the refreshes of host copies, and all before the GPU runs the submission's first command. A buffer's host copy (or the title memory a host buffer shares its pages with) so has one content per submission: what the last copy left. A title that keeps one constant buffer and copies new values into it between two passes of a submission had both passes read the later values: a pass dispatched for a full-size target read a half size copied in for a later pass, and drew one quarter of it. A constant view in a table now reads a snapshot taken at its place among the list's steps once a title copy has been seen to write its bytes after a pass of the same submission read them (`crate::rewritten`, two commits before). This wires that learning and the tables made afresh (`crate::fresh`, the commit before) into the draws and the submission: `Step::Snapshot`, `Step::Constant` and `Step::Table` in the list's steps, `HostHeap::remake_at` for the slots made again at submission, and the unused-code allowances of the two commits before removed. - The table is made afresh in dynamic slots with that view on the list's scratch memory, as unaligned root constant views already read scratch. Its other slots follow the title's records at submission, as a table in place would; a table that also needs a 16-bit view as its unsigned twin is made afresh once with both (`crate::fresh`). - Which ranges need it is learnt at submission: a pass notes the constant ranges it reads through tables, a title copy into one later in the submission makes the shared bytes known, and the next recording snapshots them. The first submission showing a range is not helped and is counted; a range not shown for 64 to 128 frames is forgotten. - A snapshot cannot hold what a shader of the same submission wrote before its pass: where a shader write is declared over the constants before the pass, the pass reads them in place as before, and a snapshot already given is counted. - A snapshot reads title memory when the list is prepared, so `batch_flags` counts it as a fill: a list holding one joins no piece after a shader's writes (with the commit before, at every place the per-queue pump ran the work before first). - With the table memo (`VICTORY_TABLE_MEMO=1`) a remembered entry does not stand for a snapshot. Cost: one note per constant range and list for buffers no copy rewrites under a pass. One log line the first time, and a line with each frame-rate report that has snapshots or late reads to count (snapshots, tables made afresh with their host views and record bytes, late reads). In a diagnostics build the operation list says `snapshot` beside the view and describes the table made afresh. VICTORY_SNAPSHOT_CONSTANTS=0 turns all of it off. Tests: `a_pass_reads_its_constants_as_they_were_before_a_later_copy_of_its_submission` (GPU, under Wine; fails without the snapshots: the first pass reads the later copy's values), the twin, slot, memo, shader-write and count tests in draw.rs and the join test in host.rs (native). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…acos.md Says what a pass reading constants a later copy of its submission rewrites looked like, what the layer does about it now, what it costs, and the two switches: VICTORY_SNAPSHOT_CONSTANTS=0 and VICTORY_COALESCE_PIECES=0. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.
This series sits on
mainat 2738044.What is wrong today
Two faults.
1. The join rule of the coalesced pump (
hold.rs). Since #419,pump_coalescedandtake_ready_withjoin ready segments of several queues into one host submission. All lists of a piece are prepared together: their steps run on the CPU before the GPU runs the first command of any of them.can_joinis there to keep a list that reads title memory when its steps run (a copy, a move, a fill) out of a piece whose shaders write. But it is asked in only three places: when a segment of another queue joins, when a segment's wait is satisfied by the piece's own bottom-of-pipe writes, and when a fence wait on a deferred Signal is crossed. Even across queues, it is asked only of the first segment of a run. In three places where the per-queue pump ran the piece first, the next segment is taken with no question:In each case a reader is prepared before the shaders ahead of it in the piece have run, and so it reads the bytes from before those shaders.
2. Constants a later title copy rewrites (
draw.rs,host.rs). A list's title copies run on the CPU at submission, in recorded order, all before the GPU runs the submission. So a buffer's host copy has one content per submission, which is whatever the last copy left. Take a title that keeps one constant buffer and copies new values into it between two passes of one submission: the earlier pass reads the later values. One shape of this is a pass dispatched for a full-size target that reads a half size copied in for a later pass, and so draws only one quarter of its target.The commits
fix(gpu): ask the join of the whole run the per-queue pump kept together(hold.rs, six tests). Every place where the per-queue pump started a piece becomes a join boundary: a deferred Signal of the segment's own queue, and a segment with waits while the piece is not empty. At each boundary,can_joinis asked of every segment of the run the per-queue pump kept together from there (run_from_head). The run joins whole, or the piece runs first and the run starts the next piece whole. No run that the per-queue pump kept together is split, and a piece never starts where that pump did not start one, so a frame never gets more pieces than the per-queue pump gave. Wherecan_joinagrees, nothing changes. The rule also covers the lists that already copy, move or fill title memory onmaintoday: this commit fixes the fault for them on its own, without the snapshots of commits 2 to 4.fix(gpu): learn which constant ranges a later copy of a submission rewrites(rewritten.rs,ranges.rs). The bookkeeping, plain std, with its tests and nothing using it yet: a pass notes the constant ranges it reads through tables, a title copy into one later in the submission makes the shared bytes known, and the next recording snapshots them. The first submission that shows a range is not helped (it is counted), and a range not seen for 64 to 128 frames is forgotten. A range a shader of the submission was declared to write before the pass is left in place.fix(gpu): tell tables made afresh apart by twin, cap and snapshot(fresh.rs). Why a table is made afresh, and the key that tells two such tables apart within a list, so that a table that needs a 16-bit unsigned twin and a snapshot is made once, with both.fix(gpu): give a pass a snapshot of constants a later copy of its submission rewrites(draw.rs,host.rs,descriptor/host.rs). The wiring: a constant view in a table reads a snapshot taken at its place among the list's steps, in a table made afresh in dynamic slots with the view on the list's scratch memory; the table's other slots follow the title's records at submission. A snapshot counts as a CPU read inbatch_flags, so the rule of commit 1 keeps it out of a piece behind a shader's write. Commits 2 and 3 carry an#[allow(dead_code)]on their module until this commit uses them, and this commit removes it.docs: describe the snapshots of constants and the join rule in docs/macos.md.On 2738044, the new list steps fit the list-steps line as
main's own do: a snapshot counts with the title copies and fills, a constant read with the refreshes, and a remade table with the slots.VICTORY_SLOT_ONCEleaves a remade table out: it runs at every submission, as before.Each of commits 1 to 4 builds, and passes the crate's native tests and the Windows clippy runs (with and without
--all-features) on its own: 240, 252, 254 and 254 tests passed, none failed, 1 ignored. Commit 5 changes only the docs.Defaults
Both changes are on by default, each with a way back:
VICTORY_COALESCE_PIECES=0gives the per-queue pump, as before perf(gpu): coalesce cross-queue and bottom-of-pipe dependent held pieces #419, which does not have the fault.VICTORY_SNAPSHOT_CONSTANTS=0turns all of commits 2 to 4 off; with it off, the paths are those ofmainapart from an empty field or two and one range removal per title copy.We kept them on because both fix wrong pictures, not speed. If you would rather have either behind a switch that is off by default, we will gladly change it.
Tests
The faults without the series. Measured on 5b57b11 (an earlier commit of
main) with only the tests added. The failing run was not repeated on 2738044:hold.rsis the same file in both, but other files on the constants path (draw.rs,host.rs,descriptor/host.rs) changed between the two commits. On 2738044 all of them pass with the series (they are in the counts of the table).hold::tests(native) fail. Each one puts the writer and the reader in one piece with no join asked.a_pass_reads_its_constants_as_they_were_before_a_later_copy_of_its_submission(GPU, under Wine with D3DMetal) runs three passes around two copies of one constant buffer in one submission. It checks the bytes once in a buffer with a host copy and once in title memory on a host buffer's pages. It fails: the first pass reads the values of the copy made after it (frame 1:0x21xxwhere0x11xxwas copied before the pass).Both test runs CONTRIBUTING asks for, on this branch and on plain
main, both at 2738044:maincargo test --workspaceThe Wine run: every test binary that
cargo test --workspace --target x86_64-pc-windows-gnullvmbuilds (24), each run once under CrossOver's Wine with D3DMetal, withWINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b"and the HLE probe fixture astools/macos/test-wine.shsets them up. We ran the binaries one by one rather than through the script itself.main.draw::tests::tracked_rows::block_compressed_rows_keep_their_block_alignment_across_pagesand fourindirect::enhanced-barrier tests (enhanced_barriers_supported_and_command_list7_availableand threenarrow_clamp_sync_*).replayintegration test binary aborts and gives no count; it is not in the numbers above.victory-hletest binary, which this series does not touch, was not steady on our machine, which other work kept busy during these runs. On plainmainit ran past our five-minute limit in the full run (modules::xmem::tests::the_titles_virtual_free_is_oursfailed andmodules::xmem::tests::transfers_shrink_the_title_budgetdid not end); run alone four more times it passed whole each time (226 passed, 0 failed, 2 ignored), and that count is the one in the table. On this branch it passed whole in the full run and in two of four more runs; one of the other two stopped aftermodules::dstorage::tests::a_page_list_filled_after_its_request_startsfailed, and one hung the same way as on plainmain.hold::tests among them. WithVICTORY_SNAPSHOT_CONSTANTS=0, the crate's snapshot, constant, twin, hold, rewritten and fresh tests pass too (113 passed, 0 failed, 4 ignored); the GPU test above then expects the old values.Also on this branch, at 2738044:
cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings, with and without--all-features: clean. Host-target clippy fails on plainmaintoo, with dead code (82 errors invictory-gpu), as CONTRIBUTING says. This branch has 84 there: the 2 more arerun_from_headandrun_joins, unused on the host likeCanJoinandWorld.cargo xtask policy: ok.Tested on an Apple Silicon Mac, CrossOver 26.3, D3DMetal 3.0.
What was measured, and what was not
Measured in a real workload on earlier heads of the fork (before #419, and on two heads after it):
Not measured:
Note
This work was AI-assisted: prepared with Claude Code, and reviewed and tested as described above.
🤖 Generated with Claude Code