Skip to content

GPU: run indirect rectangle-list draws (#255) - #282

Closed
artor410 wants to merge 3 commits into
Marvisak:mainfrom
artor410:indirect-rectangles
Closed

artor410 wants to merge 3 commits into
Marvisak:mainfrom
artor410:indirect-rectangles

Conversation

@artor410

@artor410 artor410 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Refs #255: the non-indexed draws its diagnostics name. Left open for someone to confirm with the game.

Summary

State::execute_indirect used to refuse indirect draws with the rectangle-list topology. They now go through:

 execute_indirect(DRAW, stride, max, arguments, count)
   bound()                                  # clamp + budget, as before
+  if topology == RECTANGLES
+    rectangle_vertices()                   # vertices the bound per-vertex buffers hold, whole rects, <= 4 MiB expanded
+    indirect::rectangles()                 # compute pass: each record -> our own 16-byte record
+      (n, inst, first, first_inst) -> (6*(n/3), inst, 6*(first/3), first_inst)
+      first % 3 != 0 or past the expanded vertices -> draws nothing
+    prepare(); rectangles(list, vertices, 0)   # existing CPU expansion, whole buffers from vertex 0
+  ExecuteIndirect(DRAW stride 16, our records, title's count buffer)
  • The title's records are not modified. The rewrite isn't idempotent, and the shadow copy is reused across submissions. The title's buffer goes back to INDIRECT_ARGUMENT after the pass, so a count kept beside the records stays valid.
  • HostList::argument_space: per-list 64 KiB chunks of shader-writable memory for the rewritten records, reused after a reset.
  • indirect::make now takes the source and a name, so the clamp and the new pass share it.

Evidence

No game files were used, and this is untested against the game.

  • New GPU test indirect::rectangle_records_become_triangle_records. It runs the real bound → rectangles → done sequence on the host device:
    [6,2,0,1] [7,1,3,0] [3,1,1,0] [3,1,9,0] (stride 20, 9 expanded vertices) → [12,2,0,1] [12,1,6,0] [0] [0], and the title's records come out unchanged.
    Before: it does not compile (no pass). After: it passes on an RDNA GPU with mesh shaders.
  • cargo test -p victory-gpu: 44 passed, 1 ignored. Clippy (with and without diagnostics) adds no warnings, and cargo xtask policy passes.

Known gaps (marked shortcut: in the code):

  • Indexed rectangle draws are still dropped.
  • The vertices are expanded on the CPU at submission, as for direct rectangle draws. Vertex data the GPU writes in the same submission is not seen, and each call copies the bound buffers whole (up to 4 MiB of expanded data per buffer).
  • Pipelines that read only SV_VertexID see expanded ids, the same as direct rectangle draws today.
  • The budget is charged the title's count, half of the triangle vertices actually drawn.
  • At most 4,096 records per call.

Merge Danger

Door: two-way

Blast Radius: small

This only runs with VICTORY_INDIRECT=1 (diagnostics builds), for draws that were dropped before.

🤖 Generated with Claude Code

artor410 and others added 2 commits November 23, 2026 22:58
ExecuteIndirect draws with the console's rectangle-list topology were
refused, as rectangles are expanded on the CPU and an indirect draw's
vertex count is only on the GPU. Now the bound vertex buffers are expanded
whole (as direct rectangle draws are, up to 4 MiB of expanded vertices per
buffer), and a small compute pass rewrites each clamped record into a
triangle-list record of our own: 6 * (count / 3) vertices from 6 * (first
/ 3). Records that start inside a rectangle or reach past the expanded
vertices draw nothing; the title's records are left unchanged.

Indexed rectangle draws are still dropped.

Refs Marvisak#255.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The count may sit beside the records, so the rectangle pass puts the
title's buffer back where the clamp left it; the signature is found before
the pass; triangle records stay within the clamp's 2^24 vertices; our
compute passes are named in compile errors; the 4,096-record limit is
marked as a shortcut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I tested the non-indexed rectangle rewrite together with #242 on Windows 10 using Microsoft WARP. Both patches modify the lifetime and layout of the indirect argument buffer. We combined the rectangle rewrite with #242’s count-aware clamp so it can read the title arguments once, write the expanded draw into the existing scratch record, and charge the budget for the expanded vertices.

The software execution test read the rewritten records back and checked vertex counts and offsets, instance fields, stride padding, the active count, and the unchanged source. All seven indirect tests passed. This test covers argument generation. It does not establish visible world geometry. The original CPU expansion still cannot see vertex data written by the GPU earlier in the same submission.

Integration commit and software test. AI-assisted implementation and verification.

@gw1337x

gw1337x commented Nov 24, 2026

Copy link
Copy Markdown

Tested in game on an RX 7800 XT (Windows 11 26200), diag build, VICTORY_D3D12_DRED=1. Build: main d2a4bae + #135 + #124 + #130 + this PR (clean merge), one run into the opening cutscene.

What the PR fixes: the rectangle drops are gone. The drop summary had indirect kind 0: pipeline mismatch (... topology 17) at about 246 per frame before. With this PR that line never appears, and neither does rectangles not expanded. The draws go through.

The picture: no visible change. The cutscene still shows only its intro card and subtitles over black, at about 1–1.7 fps. So on its own this isn't what keeps the world black. The largest remaining drops are the untranslated shaders listed in #293: the mesh shader 910b4be059bfb28f, the compute shader e30970f1727063fd, and the "address in an SGPR" group.

How the run ended: the usual page fault inside freed textures (three 2048×2048 BC7), at about 113 s (#135's remaining case).

Merge note: this PR conflicts with #242, which rewrites the same clamp path into a scratch copy (draw.rs execute_indirect, host.rs argument memory, indirect.rs done). Whichever lands second will need its rectangle pass to read the clamped records from #242's copy.

@tanishq-dubey

Copy link
Copy Markdown

Independent title run of head ba9864dd48177e9a78a5dc95e54ca7a70a26db5e on RTX 5090, NVIDIA 620.70.06, Linux/Wine 11.22, vkd3d-proton 3.2.0, diagnostics build. Kept separately tested local handle-type, sparse-copy, indirect-budget and self-swap corrections; no wave64/waterfall stack. The world remained black and ran at roughly 0.3–0.6 fps in sampled intervals before a title null-write termination after a long stall. During early world intervals the drop summary reported indirect kind 0: rectangles not expanded (192–512 per frame, while pipelines were still building). That reason combines missing/pending host pipeline, unavailable vertex input, signature and rewrite failures, so this does not establish which condition occurred or whether later eligible rectangles ran. Other shader translations still fail. No game data attached. AI-assisted.

@ChruutvoLuzi

Copy link
Copy Markdown

Confirmation on NVIDIA in game. RTX 4090, driver 621.01, Windows 11, diag build with VICTORY_D3D12_DRED=1, the first mission's opening. d2a4bae with #189, #205, #206, #134, #123, #89, #136 and #193 merged locally, once without and once with this PR at ba9864d (#388 was also added in the second run; it doesn't touch the indirect path).

On this base the dropped rectangle draws are labelled differently from the AMD report: execute_indirect sends DRAW/INDEXED with the rectangle topology to prepare, so the drop summary says indirect kind 0: prepare failed (compute false, mesh false) instead of pipeline mismatch (... topology 17). It's the same refusal.

Without this PR With this PR
indirect kind 0: prepare failed about 258 per frame (2,581 over 10 world reporting intervals) never logged
Indirect executions dropped per frame, all reasons about 1,110 about 940
End 0x887A0006 after about 60 s in the world 0x887A0006 after about 90 s

So the rectangle drops are gone on NVIDIA too, at about the rate the AMD run above saw. After it the drop summary names no indirect-specific reason; what it still lists is per program without a host pipeline. The hang at the end is the one in #71 and not related to this PR. I didn't capture frames, so I can't say whether anything new shows up on screen.

AI-assisted (Claude Code).

@lordon1a

Copy link
Copy Markdown
Contributor

AI-assisted.

Tested ba9864dd4 on Windows 11 Home 26H2 (build 26200) with Intel(R) Iris(R) Xe Graphics (8086:46a6, driver 32.0.101.7088, DXGI Adapter 0), rustc 1.100.0 (x86_64-pc-windows-gnullvm):

  • cargo xtask policy: 151 files ok
  • cargo test -p victory-gpu -- --test-threads=1: 44 passed, 0 failed, 1 ignored (benchmark) in 0.24s, including indirect::tests::rectangle_records_become_triangle_records and indirect::tests::argument_clamp_builds.
  • Zero new compiler warnings in the touched files (draw.rs, host.rs, indirect.rs).

(Unit/host D3D12 verification only; no title dump run.)

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Review note (built on main d2a4bae; cargo test -p victory-gpu passes on an RTX 5070). One case that is refused although it is a complete rectangle list: the helper shader requires the start vertex to be a multiple of 3,

bool whole = a.z % 3 == 0 && a.z <= vertices && rects * 3 <= vertices - a.z;

A record [3, 1, 1, 0] (three vertices, one instance, starting at vertex 1) is one whole rectangle, formed from vertices 1, 2, 3: primitives are grouped from the record's start vertex, not from vertex 0. Here it becomes an empty draw, and the test encodes that as expected. Grouping relative to a.z would keep it (#346 expands on the GPU from the record's start).

These are the roughly 250 dropped draws per frame of #255, so if a tester has the numbers: how many of the world's rectangle-list records have a start vertex that is not a multiple of 3? If none, this does not matter in practice.

From reading and synthetic tests only; I have no copy of the title.

@SpaghettiMaster545

Copy link
Copy Markdown

Confirmed with the title on ba9864d merged alone onto main d2a4bae (clean), against two main runs made the same way (#255).

  • NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124); Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1. Diag build, its own empty VICTORY_CACHE_DIR, VICTORY_KEYS into story mode, until the host GPU failure (NVIDIA RTX 5070 Ti: world hang (DEVICE_HUNG) on 97c78d1 is not one program, not loops, not barriers; 77 compute pipelines refused #71, unrelated).
  • dropped N/frame without a host pipeline: indirect kind 0, every 5 s line, from the first world line to the hang:
  • What is left is the new reason rectangles not expanded, so some records still fall outside what the expansion takes (whole rectangles within the bound vertices, the 4 MiB cap, or first % 3 != 0). I did not split those further.
  • Nothing else changes: program by program the translation is as on main, and the world hang is at the same point (84 s, within main's 59–111 s).

Not tested

  • Whether the scene behind the cutscene is drawn now: I did not capture frames, so this report confirms only that the draws are run.
  • AMD GPUs, a release build.

(Claude Code, Claude Opus 5.5: ran the title on both builds and compared the drop lines.)

A rectangle-list record groups its rectangles from its own first vertex,
so `[3, 1, 1, 0]` is one whole rectangle (vertices 1, 2, 3). The rewrite
refused records whose first vertex was not a multiple of 3. The bound
buffers are now expanded from each of their first three vertices, one
expansion after the other, and a record reads the expansion its first
vertex falls in. The expansions share the former 4 MiB per buffer.

Raised by r4tedx on Marvisak#282.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@artor410

Copy link
Copy Markdown
Contributor Author

Thanks, r4tedx: fixed in 4d3d003. The bound buffers are now expanded from each of their first three vertices, one expansion after the other, and a record reads the expansion its first vertex falls in. So [3, 1, 1, 0] draws vertices 1, 2, 3 (the test now expects this, plus a start at 5). The three expansions share the former 4 MiB per buffer, and the CPU copy runs three times per draw. Synthetic tests only (cargo test -p victory-gpu: 44 passed); untested against the title.

On #242 (gw1337x, ifBars): agreed, whichever lands second has to read the clamped records from #242's copy. I'll rebase onto it if it merges first.

@SpaghettiMaster545

Copy link
Copy Markdown

Follow-up for the new head 4d3d003, the same setup as my report above: three runs, but each ended at the world hang (#71) after only 47, 52 and 64 s, so they reach just the first one or two drop lines. Those read 192, then 96–146 rectangles not expanded per frame, falling the same way as on ba9864d (214 → 20 over an 84 s run). That is too short to tell whether the first % 3 change removes the rest of the drops.

All three 4d3d003 runs hung a bit earlier than main (59–111 s over three runs) and ba9864d (84 s). With so few runs, and the hang time varying this much on main alone, I would not read anything into that yet.

(Claude Code, Claude Opus 5.5.)

@Exorion1er

Copy link
Copy Markdown
Contributor

For whoever picks between this and #346, which handle the same draws (#255):

  • GPU: expand indirect rectangle-list draws on the GPU #346 expands indirect rectangle lists on the GPU after the clamp, with a byte-for-byte GPU-vs-CPU test.
  • Its head (c256f83) builds under stock Proton.
  • On an RX 9070 XT under Proton, the rectangle-list draws ran in the title with it, with no GPU fault from the expander.
  • This PR takes a CPU route and says it was left open for a game confirmation.
  • Both touch the same functions in draw.rs and indirect.rs, so only one can land.

AI-assisted (Claude Code).

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

In-game confirmation on NVIDIA, as asked. RTX 4070, driver 32.0.16.2101, on top of #493 + #483 (needed to keep this GPU alive in the world). Merges cleanly. Default loop limit, 300 s, DRED=1 + GPU_TIMING=1, 2 runs each, alternating, idle CPU.

rectangle drops (indirect kind 0: prepare failed, per frame, last report) device removed time in world
base 256, 256 no, no 225 s, 217 s
base + this PR 47, 12 no, no 225 s, 218 s

AI-assisted.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Resolved by adapting the PR's rectangle pass to HEAD's indirect barrier model: indirect::rectangles uses enhanced buffer barriers (common <-> compute UAV) when the list has them and legacy transitions otherwise; done() keeps HEAD's (args, count) form, called for the rewritten records and then the title's. Test updated to HEAD's bound/done signatures; passes with and without VICTORY_TEST_LEGACY_INDIRECT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
The tester tree (upstream main ffe310e plus its PRs, update 8; see its
INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a
device removal. Where both sides carry the same PR (the wave64 stack
#223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the
tester tree's newer head is taken; our own work and the PRs only we
merged are kept.

Conflicts, file by file:

- descriptor/host.rs: the tester layout (`spare`, the guard slot after the
  dynamic slots, `free_table`, the capped sampler heap). A capped view
  heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the
  tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in
  diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics
  (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`,
  `timed_valid_title_address`, `timed_find`, `title_bounds`) and the
  revision triple are kept beside the tester's `guard_slot`.
- Buffer states: the tester tree's buffer-state tracker (#334: every list
  moves host copies of title memory between GENERIC_READ and
  UNORDERED_ACCESS and back to common before it closes) and depth twins
  (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect
  prelude, `use_indirect_buffers`, the title buffer handoff mirrored in
  `host_barrier`) cannot share buffers with that tracker and are dropped;
  #40's argument checks (`byte_len`, exact spans, overflow-safe clamp
  shader, aligned counts) stay. `indirect::bound` and #282's
  `rectangles` go through `buffer_state`, and `indirect::execute` (#334)
  replaces `done`. #178's DXC fallback compiles both of our passes.
  Our segments (#387: `close` ends the segment, `close_native` closes a
  native list) carry the tracker: each native list returns its buffers
  to common and its twins to their depth targets, and each prelude also
  holds our texture uploads.
- shadow.rs: our write flow (`queue_write`, one `snapshot` after the
  batch's refreshes, `finish_writes`, the unchanged-page cache) with
  #261's copy-back that also gives the snapshot the title's bytes; its
  tests run through our flow.
- pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair,
  with our compute waits (a dispatch waits for its pipeline, up to 20 s).
- pipeline/library.rs: the tester version (#347, #275's saver thread);
  our concurrent-write test kept. shader_cache.rs: our byte-returning
  cache API with #358's "translated, only not kept".
- draw.rs: #493's root SRV tables; where no table can stand in, our
  drop of a draw whose root view is unset or outside title buffers. Our
  refusal of a table offset past the capped heap stays.
- resource.rs: `HostTexture` has both our `staged` generation and the
  depth twin.
- Shaders: the tester's lower.rs for the wave64 stack, #160's image
  sampling (it covers our #73 and #136 sample forms) and #453/#587; kept
  from our side: #136's preference for an image or buffer use of a
  descriptor read as data and its `s_buffer_` arm, #422's nearest-even
  narrowing (also for #169's d16 loads and #453's interpolation), #452's
  spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in
  `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the
  tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and
  docs/wave64-on-wave32.md are the tester versions (the same PRs at newer
  heads).
- Tests: #483's heap guard dwords filled in our GPU tests of #200
  (v_div_scale) and #437 (scalar loads from a raw view), which read
  through the guard slot otherwise; #334's debug-layer test passes an
  offset to our `indirect::bound`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lines9686-rgb added a commit to lines9686-rgb/VIctory that referenced this pull request Nov 24, 2026
…ometry stage

Merges Gargalindis's 39e056a over Marvisak#282's rectangle expansion and the
depth-twin work.

A rectangle-topology pipeline whose vertex stage reads per-vertex input
keeps Marvisak#282's path: its buffers are expanded (direct draws on the CPU,
indirect draws through the record rewrite). One without per-vertex input
that got Marvisak#1020's geometry stage (rect_gs) is not expanded: its direct
draws keep the title's vertex count and first vertex, its non-indexed
indirect draws execute the title's records with the title's signature.
Whether a direct draw expands is asked after prepare, and the indirect
expansion refuses a geometry-stage pipeline, so a pipeline made ready on
another thread mid-draw is never both expanded and completed. Indexed
rectangle lists stay undrawn.

HostPipeline keeps both depth_format/stencil (depth twins) and rect_gs.
Diagnostics: the listed-frame pass lines say "rect gs true|false" for
direct and indirect draws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…) onto Marvisak#334 + integ/next

Taken instead of Marvisak#282 (same draws, Marvisak#255; only one can land): Marvisak#346 expands on
the GPU after the clamp, so vertex data the GPU wrote earlier in the
submission is seen, and its record grouping starts at each record's first
vertex. It has the stronger title evidence: the loading screen renders
(justlovett0, RTX 3080), the `prepare failed`/topology-17 drops go from 256
per frame to 0 with no device removal (neonbyte1, RTX 5090/Wine; Exorion1er,
RX 9070 XT/Proton; iurysf, RTX 4070), and every defect reported on it was
fixed by a later commit (scratch layout cee702e, record bounds 0aebe86,
count buffer 7ff1184, Wine compiler c256f83). Marvisak#282 expands on the CPU (does
not see GPU-written vertices, copies bound buffers whole, three times per
draw after 4d3d003) and its last head was only checked in short runs.

Conflicts:
1. crates/victory-gpu/src/indirect.rs, module doc: the stack's (Wine-safe
   clamp in structured buffers, root signature made beside it) kept, with
   Marvisak#346's sentence on the rectangle expansion added.
2. indirect.rs, `bound`: Marvisak#346 splits it into `clamp_uav` (clamp + UAV
   barrier) and `bound` (then a fixed UAV -> INDIRECT_ARGUMENT transition);
   Marvisak#334 (merged just before) replaced the fixed transitions with its buffer
   states (`bound` asks for BUFFER_WRITE, `execute` for BUFFER_READ). Kept
   Marvisak#346's split with Marvisak#334's tracking, the resolution justlovett0 and the
   author agreed on (Marvisak#346 comments 7121242441, 7121274527): `clamp_uav` takes
   the buffer, starts a command and asks for BUFFER_WRITE; `bound` is
   `clamp_uav` (the read state comes from `execute`), no fixed transition.
3. crates/victory-gpu/src/host.rs: the stack's `PooledUpload` and Marvisak#346's
   `RectScratch` added at the same place; both kept.

Non-textual fixes:
- rectangles.rs calls `clamp_uav(list, &args.buffer, ..)` (new parameter).
- rectangles.rs: the rewrite and expand passes bind the count's and the
  vertex buffers' host copies as root UAVs. With Marvisak#334 those copies' states
  are tracked, so they now ask for BUFFER_WRITE in the clamp's command
  (otherwise a copy a draw had moved to GENERIC_READ would be bound as a
  UAV in a read state). The draw's own `prepare` then asks for the read
  state as before. The list-owned scratch keeps Marvisak#346's own barriers.
- primitive.rs: Marvisak#346's half-float rounding commit (8c7ac43) is already here
  through Marvisak#1220 (in Marvisak#1418), so `half_midpoints_round_to_even` is not added
  twice: the PR adds 8 tests, 7 are new here.
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…sak#98, Marvisak#334 to Marvisak#492, validation)

The line rebuilt on the bundles' current heads (Marvisak#1402 119b763, Marvisak#1492 5bbc098
without Marvisak#98, Marvisak#1504 1d41891, Marvisak#1511 ca601f0) with every merge replayed, and the
merges after this file's first version (Marvisak#334, Marvisak#346, Marvisak#1024, Marvisak#211, Marvisak#492): merge
order, the runner's numbers on 967d3ae (RTX 571, WARP 570 + the known Marvisak#1084
failure, all features 580; Marvisak#98's one test leaves), what is not included (Marvisak#98,
Marvisak#282 for Marvisak#346, Marvisak#693 for Marvisak#1024, Marvisak#306's latest commit), and the open pull
requests whose head is contained here (109, from the 18:24 collection).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak Marvisak closed this Nov 24, 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.