Skip to content

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

Closed
PiloteCode wants to merge 8 commits into
fxceless:mainfrom
PiloteCode:pr/indirect-prelude
Closed

PiloteCode wants to merge 8 commits into
fxceless:mainfrom
PiloteCode:pr/indirect-prelude

Conversation

@PiloteCode

@PiloteCode PiloteCode commented Nov 25, 2026 •

Copy link
Copy Markdown

Based on 085ee7c4 (the first version was on 0b0074e0). main has since moved to 9c184b35, 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:

  • Three clippy fixes for main. The two this PR had before (draw.rs, indirect.rs and resource.rs; shadow.rs) are still needed, and main's seven newer commits need a third (fpsbox.rs, pipeline/library.rs, queue.rs, shadow.rs; with all features draw.rs and watch.rs). Without them cargo clippy --workspace --all-targets --locked -- -D warnings fails on 085ee7c4 with the pinned toolchain: 8 errors in victory-gpu, 10 with --all-features. No change of behaviour; each can be left out on its own.
  • The ring.
  • The clamps in the prelude.
  • A guard for title memory in place.
  • One README line.
  • A lock in the tests of indirect.rs, for runs of the suite on several threads (see "Tested").

The changes are in indirect.rs, host.rs, draw.rs, copystat.rs and shadow.rs. Everything new keeps main'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

  • Rebuilt on main's gathered records (VICTORY_INDIRECT_GATHER, 465b94f). The conflicts were in indirect.rs, draw.rs, host.rs and the README. main's gather is unchanged: gather, GatherSet, record_gather_as, record_gathers and the program's bit 2 are byte for byte main's.
  • record_clamp_as is main'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.
  • The prelude's clamps have a budget of their own, zeroed first in the prelude. In the first version they charged the list's own budget, which the list zeroes inside itself: they started from what the list's last run had left, and what they charged was zeroed away. Found while placing them beside the gathered records; a test now holds it.
  • A prelude that cannot record its clamps fails, as one that cannot record the gathered passes does. In the first version it recorded nothing and the list ran.
  • The window check is told where its record is: in the list's ring (an enhanced barrier) or in a scratch buffer (changes of state), which a gathered record's slot always is.
  • Tests: the count buffer and the budget through the ring's path, and the prelude's clamps, on the test's own device with a clamp made for it; the two budgets; a prelude with gathered records and clamps side by side.

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:

  • one barrier of the enhanced kind (compute writes → indirect argument read) replaces the two changes of state around the clamp, with no barrier before it;
  • a full ring is replaced by one twice as big (the old one is kept until the list is reset), and after a reset the ring is taken from its start;
  • the clamp now returns where in its buffer the records start; a window keeps that place, and the window check reads a ring record behind an enhanced barrier.

The ring is on where the device reports enhanced barriers (D3D12_OPTIONS12). VICTORY_INDIRECT_RING=0 clamps into the one scratch buffer, as before, through main's record_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 prelude's budget zeroed;
  • a global barrier after every earlier shader write;
  • the clamps, with no wait between them (each writes room of its own in the ring; the budget is taken atomically);
  • 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: 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 way main does 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=0 clamps 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:

  • Which record goes where. A draw's single record that misses its window is gathered first, exactly as on 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.
  • Buffers. A gathered record's slot stays in its set's scratch buffer, with main's two changes of state a list. Gathered records do not go to the ring.
  • Order in the prelude. The gathered sets' passes are recorded first, as on main, then this PR's clamps. Up to and including the gathered passes the prelude is what main records; with VICTORY_INDIRECT_EARLY=0, or no such clamp, it is main's prelude.
  • Budgets. The gathered records keep theirs, the prelude's clamps have theirs, the list has its own. Neither kind changes what the other clamps or leaves empty, so the order between the two decides nothing but which waits first.
  • Diagnostics. The frame shot's line for the prelude also counts this PR's clamps.

Diagnostics (diagnostics builds)

  • The timing run (VICTORY_GPU_TIMING) times the prelude as one command ("prelude (ours): N clamps"); the list keeps two of its timestamps for it.
  • The frame line counts the clamps by where their records come from: draws and dispatches, written in the list or from before it, and those clamped in preludes.

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 main and 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

Switch Default Effect
VICTORY_INDIRECT_RING on where enhanced barriers are supported =0: the one scratch buffer, as before
VICTORY_INDIRECT_EARLY on with the ring =0: every clamp in the list, as before

Tested

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 at 00c97825; the tip b333628b differs 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.rs is 425,559 bytes of the 524,288 allowed).
  • cargo build --release -p victory and cargo 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.
  • The same with the default test threads (32 here), 12 runs: 11 completed (206 passed and 1 failed in 7 of them, 205 and 2 in 4), and 1 died of an access violation (below).
  • 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 take main'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 in draw.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:

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 of main with a change to the test harness, not plain main: a null read in a call made by a queue2 test, and a wild write on one of the rasterizer's own threads). It needs the device tests of indirect.rs running 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 warnings and the same with --all-features are clean, cargo xtask policy passes, and the serial run on the software adapter gives 205 passed, 2 failed, 6 ignored: the same two tests as above. main's profile::tests::stacks_that_mean_nothing_are_walked_without_a_fault was left out of that run: on this machine it ends the test process with an access violation, on main as 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

  1. clamp_arguments and the count path. Not reproduced. Each test alone on the software adapter, the two forms of record_clamp_as built from this branch's tip and run in turn: warp_count_buffer_ignores_garbage_tail_and_preserves_source passed 20 times of 20 with main's inline code and 20 of 20 with the first version's helper; warp_budget_saturates_without_wraparound_and_preserves_draw_fields passed 9 of 20 and 3 of 20, and over 200 runs each 56 and 52. That second test fails on plain main too (2 passes of 20): it is the test of Indirect test: the two groups charge the budget in either order (the test failed 5 runs in 6) #849 and Warp budget test: accept either group charging first (rebased on main, +12/−1) #970. The helper computes the same constants and addresses; no defect was found in it. Even so record_clamp_as is now main's own code, and the count buffer and the budget are also tested through the ring's path.
  2. The two new tests in a full run. The clamp pipeline is made on the host device, and both tests record on host lists of that device, so they run the pipeline of their own device; alone and in serial runs they pass. What does fail is the whole suite on several threads, on plain main as 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

Not tested

  • This branch in the title. One run of the save on the RTX 5090 (240 s, the ring, the prelude's clamps, VICTORY_INDIRECT_WINDOW=1 and VICTORY_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.
  • What stands in for it: our own tree, where 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.
  • GPUs without enhanced barriers: the ring and the prelude are off there, and main's path is taken.
  • The D3D12 debug layer's view of the barriers; AMD and Intel GPUs; Linux/Proton.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…g & shared indirect rendering scopes

- Replace per-ExecuteIndirect vkCreateBuffer/vkAllocateMemory in IndirectDispatchCounter::Batch
  with a persistent per-slot/per-queue reusable device-local ring buffer (64 KiB initial,
  16-byte aligned bump suballocation, 2x growth with overflow retention until GPU completion,
  reset_for_reuse() frees overflow rings and zeroes cursor; bounded pool of 8 rings on
  VulkanQueue for ZERO vkAllocateMemory per frame in steady state).
  Adapted from fxceless/victory-fork#1000 (PiloteCode, GPL-3.0).
- Add IndirectDispatchCounter::emit_batch() emitting 1 before-barrier, 1 compute pipeline bind,
  N back-to-back disjoint dispatches, and 1 tightly-scoped COMPUTE_SHADER -> DRAW_INDIRECT
  after-barrier (replacing per-draw ALL_COMMANDS -> COMPUTE / COMPUTE -> ALL_COMMANDS barriers).
- Add plan_indirect_clamp_batches() in vulkan_replay.h to hoist and batch indirect clamps across
  contiguous barrier-free draw runs (ExecuteIndirect DRAW/DRAW_INDEXED and Draw mesh_indirect)
  and indirect dispatch runs ahead of the rendering scope, keeping compatible indirect and direct
  draws inside one unbroken dynamic rendering scope (#1877).
  Adapted from Marvisak/VIctory#2472 (ESAT586, GPL-3.0) and fxceless/victory-fork#1000 (GPL-3.0).
- Verify ubiquitarianism/leonida#1929 (zero-Z mesh draw drop in CommandList::draw(Draw&&)) is
  already superseded by CommandList::has_draw_work() and add explicit regression coverage.
- Add unit and live-GPU validation tests for zero-alloc steady-state ring reuse, 2x growth,
  pre-scope clamp batching with unbroken rendering scopes, and multi-frame GPU parity.
@HrHd

HrHd commented Nov 25, 2026

Copy link
Copy Markdown

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 on 0b0074e0):

  1. clamp_arguments regresses the count path. warp_count_buffer_ignores_garbage_tail_and_preserves_source and warp_budget_saturates_without_wraparound_and_preserves_draw_fields fail, alone and on WARP, after the refactor: two of five valid dispatches are dropped and the budget keeps a second wave. Keeping record_clamp_as's old inline argument code (with the narrow-wait path) makes both pass again, so that is what runs here, and dispatch_clamp serves only record_gather_as.
  2. The two new tests (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-global OnceLock, 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).

…s-only count

`cargo clippy --workspace --all-targets -- -D warnings` (CI) fails on 9376fd6
with this toolchain: unnecessary_sort_by in draw.rs, the bench's
depth_written in indirect.rs never read, and placed_filler_twins unused
without the diagnostics feature. No code changes.
…rt, an if joined to its let, counts tested with is_multiple_of)

`cargo clippy --workspace --all-targets --locked -- -D warnings` fails on
085ee7c with the pinned toolchain (1.98.1), after the two fixes before
this one too: map_entry in fpsbox.rs, collapsible_if in
pipeline/library.rs, manual_is_multiple_of in queue.rs and shadow.rs, and
with --all-features in draw.rs and watch.rs (twice). No change of
behaviour.
dkdknight added a commit to dkdknight/victory-fork that referenced this pull request Nov 25, 2026
…d barrier, in its prelude where the list did not write them (all off)

Ported from fxceless/victory-fork PR fxceless#1000 (by PiloteCode / Pilote
Production: "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") and PR fxceless#1016 (a one-lane clamp for single records) onto our clamp,
which keeps its budget on the card, VICTORY_CLAMP_WAIT, VICTORY_INDIRECT_LAZY,
VICTORY_INDIRECT_AMPLIFY and the ahead windows. Not merged: our indirect.rs
differs too much from theirs.

Each host list reads the switches once, when it begins recording (made or
reset), and keeps them until its next reset; the live file's
indirect_ring= / indirect_prelude= / indirect_single= lines override the
environment, so a run can toggle them without a restart and no list mixes
two ways.

- VICTORY_INDIRECT_RING=1: each clamp writes room of its own in a ring of
  the list's, so no clamp overwrites records an earlier indirect call still
  reads. The change of state before the clamp goes; the one after it is one
  enhanced barrier on the ring (compute shading / unordered access ->
  execute indirect / indirect argument). The wait for the title's shader
  writes before the clamp stays as VICTORY_CLAMP_WAIT says (fxceless#1000 dropped
  it). The ring is made as the scratch buffer is, as fxceless#1000 makes it, and
  only enhanced barriers ever name it; the scratch buffer keeps its legacy
  changes of state. A full ring is replaced by one twice as big, the old one
  held until the reset. Without EnhancedBarriersSupported a warning is
  logged once and the lists use the scratch buffer.
- VICTORY_INDIRECT_PRELUDE=1, with the ring: records no shader recorded
  before in the list may write (by the ranges the list's shaders declare;
  count buffers and title memory in place stay in the list) are clamped in
  the list's prelude at each submission: a global barrier for earlier
  shader and copy writes, the clamps, one barrier per ring. The list's
  budget on the card is zeroed there instead of in the list, so the
  prelude's charges are not forgotten.
- VICTORY_INDIRECT_SINGLE=1: a single record is clamped by a group of one
  lane. Our clamp charges the budget lane by lane, so it is the same code
  in a group of one.

The frame log gets two lines (clamps into rings and scratch buffers,
enhanced barriers, lists begun each way, rings made, grown, largest, most
taken, fallbacks by reason; prelude clamps noted and recorded, records
left in the list by reason, one-lane clamps), a line when the asked
switches change, and a removed device's report says per list its form,
how far its ring was taken and its address, and its prelude's clamps.

Tests: the same records (dispatches, draws, indexed draws, mesh records,
an ahead window, a count buffer) through the scratch buffer, the ring, the
ring with the prelude, and with the one-lane clamp come out the same; the
prelude clamps anew at a second submission; the ring gives each clamp room
of its own, grows, and starts again after a reset; the one-lane clamp
matches the clamp of 64 lanes on WARP (after fxceless#1016's test). Run on the
RTX and on WARP with the debug layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dkdknight added a commit to dkdknight/victory-fork that referenced this pull request Nov 25, 2026
… what to read in the log

From fxceless/victory-fork PRs fxceless#1000 (PiloteCode) and fxceless#1016. Not measured
yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed barrier

Each clamp writes room of its own, so it no longer waits for the last
indirect call to have read the one scratch buffer, and one barrier of the
host's enhanced kind (compute writes -> indirect argument read) replaces
the two changes of state around it. Timing run of the opening of the
gameplay (RTX 5090, our tree before main's second-night changes to the
clamp): the clamps 33 -> 19 ms a frame, the card's commands 102 -> 95 ms;
frames 179 -> 171 ms (median), 210 -> 189 ms (mean). On where the host
takes enhanced barriers; VICTORY_INDIRECT_RING=0 clamps into the one
scratch buffer as before.

The clamp now says where in its buffer the records start: a window keeps
it, and the window check reads a record of the ring behind an enhanced
barrier.

The clamp into the one scratch buffer (record_clamp_as) is left as main
has it. A clamp into the ring works out its root constants and addresses
in a helper of its own (clamp_arguments) and records the pass with no
barrier (record_clamp_into).

Records gathered for a list's prelude (VICTORY_INDIRECT_GATHER) do not go
to the ring: they keep their sets' scratch buffers and changes of state,
and the window check is told which of the two it reads from.

Tests: the scratch buffer's reuse on its own path; the ring gives each
clamp room of its own, replaces a full ring, and starts from its
beginning after a reset; the window executions run on both paths. The
budget test clamps its spending and the record after it together: two
clamps into the ring are not ordered on the card (a general test on the
RTX 5090 found the small record's charge first). The count-buffer test
and the budget test of the software adapter also run through the ring's
path, on the test's own device with a clamp made for it: the garbage past
the count charges nothing, every valid dispatch runs, the title's records
stay as they were, and a second clamp leaves the first's room alone.
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.
…t its prelude

A list's indirect records go to its prelude when no shader recorded before
in the list may write them, as the shaders declare their writes. Shaders
that write title memory in place (VICTORY_INPLACE, off by default) do not
declare their writes: records there are taken as written and clamped in
the list, behind the shaders before them, as before the prelude clamps.
…de where the list did not write them

One line in the speed section: the ring (clamps 33 -> 19 ms of card time a
frame in a timing run of the gameplay's opening, VICTORY_INDIRECT_RING=0)
and the clamps in the prelude (our clamps 6.8 ms of card time a frame at
the start of the gameplay before, about 1.25 ms after, in timing runs of
two builds of our tree; VICTORY_INDIRECT_EARLY=0).
Run side by side on the software adapter, the tests of indirect.rs that
use a device brought the whole suite down with an access violation
inside the rasterizer (d3d10warp.dll), at a different place each time: on
a thread of its own, or in a call of another module's test. With the host
device on the software adapter (VICTORY_D3D12_WARP=1, diagnostics) and 32
test threads, main's suite (085ee7c) died so in 12 runs of 21, and in
none of 10 without this module's tests; with the seven tests this branch
adds, in 17 of 22.

They now take a lock of the test module for as long as they use a device,
the software adapter's harness and the tests on host lists alike: 2 runs
of 34 died, and the tests of the ring and of the prelude passed in each
of the 32 that completed. One after the other these tests take about a
second and a half. Run serially (--test-threads=1) nothing changes. What
in the rasterizer fails was not found: the lock keeps this module's tests
from meeting it among themselves, not the other modules' from meeting it.
@PiloteCode

Copy link
Copy Markdown
Author

@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, with main's gathered records. On your two points:

1. clamp_arguments and the count path. We could not reproduce a regression, on the software adapter, each test alone, the two forms of record_clamp_as built from the new tip and run in turn:

Test main's inline code the first version's helper
warp_count_buffer_ignores_garbage_tail_and_preserves_source 20 of 20 20 of 20
warp_budget_saturates_without_wraparound_and_preserves_draw_fields 9 of 20, 56 of 200 3 of 20, 52 of 200

The budget test fails with either, and on plain main too (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_as is now main's own code, byte for byte, and clamp_arguments serves 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 inside d3d10warp.dll, at a different place each time. Plain main does it too (12 runs of 21 here); it needs the device tests of indirect.rs running 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_as is left as main has 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), as main'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 main merged and the indirect code placed as here, ran the save's gameplay with the ring, the prelude's clamps and VICTORY_INDIRECT_GATHER=1 together: 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 on main proper.

main moved on to 9c184b35 meanwhile: 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).

nullexxx pushed a commit to nullexxx/victory-fork that referenced this pull request Nov 25, 2026
A load still took the library's lock to clone the interface, and a save
holds that lock while it serialises the whole library (230-600 MB in the
world, #1683, #1653). Saves run every 20 s while pipelines are being
made, some on the pipeline workers themselves, so every load waited out
each save: the part of #1615 that fxceless#1000 left.

The library is kept a second time beside its lock, and loads use that
one without locking. A load adds nothing to the library, so the size a
save asks for still holds when it serialises; the library is
free-threaded but for loads of one name, which NAMES keeps apart. Stores
and saves keep the lock.

New test: a stored pipeline loads while the lock is held as a save holds
it. With the old locking it times out.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
PiloteCode pushed a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…oads

GPU: pipelines of different names load from the library at the same time
PiloteCode added a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…ull requests and the host FidelityFX on our layer; our translator, title memory and copy-back kept

319 commits past ffe310e, merged onto wave4. Most of its runtime pull
requests were here already, picked one by one (fxceless#653 and fxceless#716,
prhle, offpr): where a change arrived both ways, the copy this branch had
is kept (net, audio, xg, runtime, lifecycle with its one stand-in window
(#1677), files, kernel, xasync, xgamesave, xmem, gameinput, the loader's
crash, clzero and publish code, the pipeline cache, #1658's staging clamp).
The rest is the resolution first made on wave2 (offm-on-wave2, ab1d525),
carried over:

- crates/victory-shader: ours (every conflict --ours). Kept from theirs
  only what landed whole: fxceless#661 SP3 text operands, fxceless#1021 s_atc_probe's
  immediate, #1636 FLAT offsets. Reverted where half landed: fxceless#1180, range.rs,
  fxceless#617's bench, #1337's sampler, ACCC, SOURCE_HASH, and new test files whose
  mod lines are in conflicted files. The rest is to be ported on its own.
- victory-gpu: ours plus the official units taken, each from its own
  diff: host.rs (fxceless#615 switch=0 is off, fxceless#1082 TDR log, #1626 swap-chain
  retries throttled), descriptor/host.rs (fxceless#974, its walk no longer cut at
  2^18 steps by ours), descriptor.rs (fxceless#52: a mirror holds the heaps' lock
  while it uses the heap, a read lock on this branch's RwLock, and so does
  our re-mirror of waiting slots), resource.rs (fxceless#52, fxceless#504 depth/stencil
  footprints, #1390 A8), pipeline/host.rs (fxceless#618), pipeline.rs (a stream
  subobject past its end not read), capture.rs (fxceless#615, fxceless#1146, a D24 depth
  plane dumped as depth), frame.rs (fxceless#174, with our late-wait shortcut inside
  the tick reservation), device.rs (fxceless#928, feature queries 7/8/23), list.rs
  (#1446, fxceless#52), external.rs (host FidelityFX, VICTORY_FIDELITYFX_DIR, off
  unless set), switch.rs, tdr.rs, and the small PRs (fxceless#553, #1562, fxceless#270,
  fxceless#153, #1453, #1204, fxceless#1173, #1206, fxceless#474).
- Not taken, ours kept: title memory at raw addresses (27c3dc9, 0f63757,
  6d021fe: their memory.rs and Upload), page marks (cd94d35, 940d32f: with
  our shaders every write through a view would be lost), bindless.rs and the
  change journal (c75fdba), root views and retirement at execute end
  (d71c388: unsafe with flights in the air), rectangle GS and table
  constants in place (683ad7a), twins and shared host textures (13bbd6f),
  heap copies (86a5ed6, bacb06a), the shader cache key, warm-up, pipeline
  queue and library (c47b529, 9c58a1c, fxceless#1000, #1660), #1510, #1635, #1246,
  fxceless#322, #1322, fxceless#669, fxceless#197 (turned down by prhle), #1726 (ours waits longer;
  its test added), the console upscaler's UAV clears. `translate --cache` is
  `--warm all` (with the adapter probe); the pipeline pre-build is not in.
- Also taken: the shader pack and the database's effects (shader-info), the
  startup archive check (fxceless#12, on this branch's KnownBuild with its patches),
  and the runtime PRs not here yet (FidelityFX's config and module).
- The title is not named in the merged-in comments (4e17478).

Details, the overlaps and what to watch: README, "The official
repository, merged".
@PiloteCode

Copy link
Copy Markdown
Author

Closing this one: main has moved past it, and rebuilding it would mostly re-argue what main already does.

  • The prelude half is superseded by main's gathered records (VICTORY_INDIRECT_GATHER), with their window check on the card and the gather segments.
  • The ring was measured against about 2,500 clamp passes a frame. main's clamp windows and lean clamps, both on by default now, removed most of those passes.
  • What is left is the one enhanced barrier after a clamp pass in place of two changes of state. If that is still worth something on today's main, it should come back as a small PR of its own, measured there.

@HrHd, thank you for porting it and for the numbers on the 4060 Ti (253.9-272.8 → 227.7-231.7 ms at the time): they were the first measurement of it on a card that is not ours.

For reference, from our own tree (PiloteBox, another lineage of the layer), measured this week on an RTX 5090: once the host copies of title buffers and the windows of title memory live in the card's memory, the clamp passes are a small part of the indirect executions' time (372 passes a frame for 4,449 executions; our estimate is 2 to 5 ms of 15.4 ms, to be measured). The larger effect was the placement itself: the card's work by command went from 53.8 to 26.6 ms a frame. A PR with that placement for main follows once it is measured on main's code.

@PiloteCode PiloteCode closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants