Repository navigation
Conversation
|
Main now has #588 (scoped indirect clamp barriers) and #584, which both touch the same code in |
ef73e3c to
42d8285
Compare
|
Tried this on an M1 Max (32 GB, macOS 15.7.3, D3DMetal 4.0b3) on top of main With But the picture breaks. In a 7-minute walk around the cell, brightness jumps went from 1.5 to 11.1 per 100 frames. Mean brightness went from about 90 to 144. The frames show white radial rays and tile-shaped blocks in the light, and whole frames washed out white for a few frames at a time. These are the same shapes the local lights' shadow rays made before #660 left them out. My guess is that some indirect draws or dispatches read arguments clamped before the culling pass that writes them, so they use the previous frame's records. Happy to run a diagnostics build with a log level or switch you name. |
|
Thanks @Zeyphers, that's a clear report. The rebased head still fails |
…OUPS=1) pragyaangaur#453 hoists an indirect execution's clamp into its list's prelude only when nothing earlier in the list wrote its arguments. pragyaangaur#570 starts a new host list for a clamp the list cannot hoist, so the clamps after it, up to the next write, are hoisted into that list's prelude. A world frame in the prison cell has ~4,000 such clamps (the title's culling passes write the arguments in the same list); inline, each is a compute dispatch and three barrier calls between two draws, which D3DMetal records as a compute encoder and a new render encoder (Metal System Trace, M5 Pro: 6,917 encoders a frame). With VICTORY_CLAMP_GROUPS=1 (off by default) a held-out clamp goes into a group pass instead, recorded where its inline clamp would be, in the same host list: one dispatch reading a table of jobs the CPU goes on filling while the list records. It clamps every execution after it until a command writes what the next one reads (the list's tracker of written ranges, also kept per pass), an inline clamp is recorded, its 512 jobs are taken, or a record is in none of the eight buffers it binds. Each execution has its own job and slot, charged to the list's budget in recorded order: the records are word for word what inline clamps write. One record without a count (all of the title's) is grouped. A pass costs two barrier calls; its output stays readable as arguments until the list closes. The prelude's batch puts runs of such clamps in group passes too, one barrier per pass instead of one per clamp. The decision is: hoist, else group, else a cut (pragyaangaur#570, where it pays), else inline. A cut is then made only for what no group takes (a count, several records, a record outside the bound buffers, no pipeline). The frame line keeps pragyaangaur#570's reasons for inline clamps and the cuts, and also counts clamps in prelude group passes, executions in group passes and the passes, why clamps stayed out of the prelude, the clamps' barrier calls and barriers, and draws recorded after compute in one host list (render passes split). A hook, indirect::clamped_in_place, clamps arguments read in place in title memory inline (never hoisted, grouped or cut for) for in-place section views. With VICTORY_CLAMP_SYNC=1 (pragyaangaur#588) every clamp path records its enhanced global barriers, group passes included, and their outputs stay common. The barrier before a group pass waits for every shader stage, not only compute as an inline clamp's does: an execution that joins the pass may read a record written before it whose title barrier comes after it. In the prelude the budget's barrier between dispatches is one per group run. A culling dispatch that writes the records again after a pass ends its group: tests run culling dispatches and indirect draws in one list, and the culling write through a table's view (as a title dispatch binds it, with VICTORY_TABLE_MEMO on or off); with the check of writes since the pass taken out, the draws after the second culling draw the first one's records. On Windows the group pass did not build (fxc), so the group tests found no seat; Wine's compiler took it. The pass now walks the eight tiles a table holds whatever its count (fxc refuses barriers in a loop up to a count read from memory, as indirect-clamp.hlsl notes), its constant buffer is no longer named Pass (an effects keyword), and argument_clamp_builds shows the compiler's messages if it fails. The design follows avatarmanz's VIctory-7900XTX 0375962 (clamps of many executions in one pass from a job table filled while the list records) and cc11ccc (clamped records left in INDIRECT_ARGUMENT), GPL-3.0. On macOS, halfwave50's VICTORY_BATCH_CLAMPS (main-mac, from 64bitMango 18872f48 and 131721b7, after Belobug ccab973) batches a run's clamps in one dispatch walking a table in draw order, recorded in a host list cut before the drawing one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every clamp charges a host list's indirect executions to one budget of 2^27 (vertex instances, threads), and a record past what is left runs empty. One record costs at most half of it (2^26 instances or 2^20 groups of 64), so a list that spent half or less emptied nothing for the budget. With pragyaangaur#570's cuts each new host list has a budget of its own; clamp groups keep a title list in one host list and one budget, as inline clamps do. At a list's reset the word it spent is read (and cleared), and the clamp part of the frame line now ends with how many host lists a frame spent more than half of their budget, and the most one spent. A run with and without VICTORY_CLAMP_GROUPS=1 shows whether groups empty records there that cuts did not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42d8285 to
5518b81
Compare
|
Thanks, this is exactly the kind of run the switch needed. I checked the guess first. A group pass takes an execution only if nothing recorded since the pass writes that One difference from main's default is the clamp budget (though see our numbers below: in our runs no list came near it). Every host list's indirect executions share a budget of If you can, three runs would separate the causes:
On an M5 Pro (main 4396e31 + this PR at 5518b81, one exe, A0 B C C B A0, 5-minute runs, walking and turning in the cell from 150 s):
So here no list comes near its budget, and I couldn't make the white shapes appear with groups on. Shots are every 20 s, so one-frame flashes can slip between them. I also checked that |
|
Confirmed on an M2 Ultra (64 GB, macOS 26.7.1, D3DMetal 4.0b3) at |
|
Thanks @buddybot89. That covers the check I couldn't do here: the group pass hands lane costs through device memory, and on the M5 Pro every word matched the inline clamps, so a pass on another GPU family (M2 Ultra) at |
|
Keep this draft for one more measurement pass. It needs the M1 budget/ray-skip data to separate causes before merging. The current head's CI is green, but I'd not merge the draft until the in-game data is in. |
What. #453 hoists an indirect execution's argument clamp into its list's prelude when nothing earlier in the list wrote the arguments. #570 starts a new host list for a clamp the list cannot hoist, so the clamps after it, up to the next write, are hoisted into that list's prelude. With
VICTORY_CLAMP_GROUPS=1(off by default), a clamp held out of the prelude goes into a group pass instead, in the same host list:Where a pass goes. One dispatch is recorded where the first held-out execution's inline clamp would have been. It reads a table of jobs in the list's upload memory. The CPU keeps adding jobs while the list records, and the table is complete before the list runs.
Which executions join. Executions after it join the pass until one of these happens:
Only the pass recorded last takes executions, and no clamp is hoisted after a pass, so every clamp of a host list is charged to its budget in recorded order.
Exact results. Each execution has its own job and its own 32-byte output slot. The pass's shader is the words clamp walking jobs instead of consecutive records, 64 lanes per tile with the budget charged by lane 0 in order. Its records are word for word what the inline clamps write.
Which executions are grouped. One record, no count buffer, 12 to 32 bytes: all of Grand Theft Auto VI's indirect executions.
The order of choices. A held-out clamp is put in a group if one can take it, else in a new host list where perf(gpu): start a host list for a clamp the list cannot hoist, instead of clamping every later draw inline #570's cut pays, else inline. A cut then only happens for what no group takes: a count, several records, a record outside the buffers a pass can bind.
Barriers. A pass costs two barrier calls. Its output stays readable as indirect arguments until the list closes, with no round trip through
COMMONbetween passes (as in cc11ccc).Prelude. The prelude's hoisted batch, in every list including perf(gpu): start a host list for a clamp the list cannot hoist, instead of clamping every later draw inline #570's cut ones, puts runs of such clamps into group passes too: one dispatch per run, instead of one dispatch per clamp with a UAV barrier after each.
In-place hook.
indirect::clamped_in_place(arguments, len, count)returns false today. It is there for title memory read in place: such executions are clamped inline, never hoisted, grouped or cut for (avatarmanz 631400f).The frame line keeps #570's reasons for inline clamps and its count of host lists started for clamps, with "read in place" added to the reasons. It also gives, per frame:
Why. In the prison cell, a frame logs about 4,000 clamps that cannot be hoisted: the title's culling compute writes the arguments of the draws after it in the same list. Inline, each is a dispatch and three barrier calls between two draws, and D3DMetal ends the render pass for it and starts another after it. A Metal System Trace of a frame on an M5 Pro counted 6,917 encoders (3,463 render, 3,453 compute). One command buffer held 1,789 compute/render pairs in turn. An encoder costs ~11 µs of D3DMetal and ~21 µs of kernel driver time. A probe of the turn itself (dispatch, barrier, indirect draw into a render target) measured 12–37 µs of recording and 16–20 µs of submission per turn with the barrier. It measured 0.03 µs and 0.2 µs without it, and recording grew with the square of the turns in one list.
#570's cuts remove the same turns. Each cut costs a new host list: its state is set again, its tables and root views are made again, and it has its own prelude and submission-time steps. A cut list's held-out clamps cut again or go inline. A group pass costs one dispatch in the list, usually in the producer's compute encoder. In game (below) #570 already removes most of the cost; groups add a modest gain on top of it and far fewer barriers.
Tests
indirect::tests::group_passes_clamp_as_inline_clamps_do. In one list, a dispatch writes every record over stale words, then an inline clamp spends half the budget. Then come executions of every kind: strides 12–32, 12 source buffers (past the eight one pass binds), one clamped inline among them (with a count), and records the budget no longer holds. Their group passes write word for word what inline clamps after the same producer write, reading what the producer wrote. Passes open at exactly the expected executions.indirect::tests::a_write_ends_the_group_of_what_it_writes. Producer, four indirect dispatches, a write elsewhere (the group goes on), the producer again over the same records, four more dispatches. The executions after the second write get a pass of their own, and each dispatch runs the groups written last before it. The test runs twice through one list, reset between. A record outside its buffer is not grouped.indirect::tests::prelude_group_passes_clamp_as_inline_clamps_do. Hoisted clamps of one record from ten buffers, mixed with multi-record, counted and empty ones, match inline clamps word for word, including records past the budget.indirect::tests::groups_take_one_record_of_12_to_32_bytes_with_no_count,clamp_groups_switch_toggles_per_thread: what can be grouped, the shader's job cap matching the constant, and the switch.a_clamp_cut_prelude_sees_the_write_of_the_list_beforeandwrite_hazard_names_what_blocks_a_clamp, unchanged, still pass.tools/macos/test-wine.sh -p victory-gpu --lib -- indirect:: draw::: 72 passed, including perf(gpu): start a host list for a clamp the list cannot hoist, instead of clamping every later draw inline #570's tests.--all-targets -D warningsforvictory-gpu, with and without--all-features: clean.cargo xtask policy: ok.test-wine.sh -p victory-gpu: 548 passed. Two descriptor tests and one list test, which also fail on plain main under load, failed in earlier parallel runs and passed alone.test-wine.sh -p victory-shader: passed.cargo test -p victory-gpu: 188 passed.In game, on top of #570. M5 Pro, macOS 27, release build of this branch on main 74d26f9. One binary, three arms, runs in the order A B C C B A, last 120 s of each.
VICTORY_CLAMP_CUTS=0, inline, as before perf(gpu): start a host list for a clamp the list cannot hoist, instead of clamping every later draw inline #570.VICTORY_CLAMP_GROUPS=1, groups, with cuts where no group can take a clamp.In C, 4,151–4,155 clamps a frame are in 72–73 group passes.
#570 takes most of the gain: against inline, the wait for the GPU drops by ~126 ms. On top of #570, groups take another ~9 ms off the GPU wait and ~14 ms off the frame, a modest gain. They also cut the clamp path's barrier calls 23-fold (from ~5,900 to ~260 a frame), and the draws recorded right after compute drop from 109 to 43. Fewer barriers should count for more on hosts where a barrier stalls the GPU longer than it does under D3DMetal on an M5 Pro (not measured here). Groups also keep each list whole and its one budget charged in recorded order.
In game, before #570 (M5 Pro, macOS 27, release build of this change on main 1fcc386, runs interleaved A B B A, last 120 s of each). Arm A leaves
VICTORY_CLAMP_GROUPSunset (inline, main's behaviour then); arm B setsVICTORY_CLAMP_GROUPS=1.VICTORY_CLAMP_GROUPS=1(2 runs)Counters per frame, A → B:
The wait for the GPU drops by ~140 ms a frame. Preparing does not change (160–170 ms in both arms).
The same switch in an integration build that has this change with other pending fixes (7c216b0). Runs were interleaved A B C D D C B A, and arms B and C differ only by this switch. Last 120 s, medians of the frame line:
VICTORY_CLAMP_GROUPSunset (2 runs)VICTORY_CLAMP_GROUPS=1(2 runs)Picture. Diagnostics captures were taken in the integration build, of the prison cell at +600, +700 and +800 s into the world. With
VICTORY_CLAMP_GROUPSunset and with it set (and nothing else changed), they show the same content. The per-pixel differences between the two arms (mean 5–6) are the size of the frame-to-frame variation within one run (mean 5.07).Prior art. The design follows avatarmanz's VIctory-7900XTX 0375962: one pass clamps many executions from a table of jobs that the CPU fills while the list records. It also follows their cc11ccc: clamped records left in
INDIRECT_ARGUMENT. halfwave50's main-macVICTORY_BATCH_CLAMPS, from 64bitMango 18872f48 and 131721b7 after Belobug ccab973, batches a run's clamps on macOS in one dispatch walking a table in draw order, recorded in a host list cut before the drawing one. #570 cuts the list in the same place. Here the pass stays in the drawing list, a group ends only where a write meets what the next execution reads, and the list's budget is charged in recorded order. All three forks are GPL-3.0.🤖 Generated with Claude Code