metal: an indirect draw of more than 2^20 instances or 2^26 vertices draws nothing (#79, #357) #463

Manually merged
github merged 2 commits from github-bot/gh-459 into main 2026-11-28 00:29:36 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 21:02 UTC · original
Olima34:fix/indirect-draw-limit → main · +58 −27 · 3 files · 2 commits · merged 2026-11-28 00:28 UTC

Refs #79, #360. Follow-up to #386, which gated indirect dispatches. This gates indirect draws.

The cause. Caught on preview b3c1a1b0 (M5 Pro 48 GB, Series S, headless, VICTORY_DEPTH_TWINS=0, VICTORY_PASSES_PER_BUFFER=1, VICTORY_TRACE_COMMITS=1), in 1 run of 5, at +230 s.

  • The one pass committed and never done is a render pass of one indirect draw (vertex 6adfc332b21374b3 / pixel 5d62a6c8f962e840).
  • The GPU read its record as [3, 864026624, 0, 0]: 3 vertices x 864,026,624 instances. 0x33800000 is the same stale float another record of the run held in y and z (f4554457: [9, 864026624, 864026624]).
  • GPU utilisation was 100% while it ran.

What follows it.

  • The time-outs: the kernel logs Cmd queue … sleep … timed out every 5 s, and the run ends with 43 time-outs and 1 out-of-memory.
  • Not a memory shortage: the residency set held 18.0–18.8 GB (81,000–94,000 allocations), the footprint was 21–22 GB, and the recommended working set is 38.3 GB.

Why the memory stays stranded (#360).

  1. SIGTERM came 12 s after the first time-out.
  2. The stop waited 3 s + 20 s ("15 command buffers still in flight … running on the GPU"), then exited with in_flight=15 left=9.
  3. The kernel logged GPURestart type=2 13 s later, and the driver kept 18.75 GB until a reboot.

So the stop on main gives memory back for waiting buffers, but not while the GPU is running work that never ends. Only not starting that work helps.

Change. Every indirect draw goes through the gate; counted draws, rectangle lists and mesh dispatches already did.

  • A record of more than 2^20 instances, or more than 2^26 vertices in all, draws nothing. So does a rectangle list of more than 2^20 rectangles.
  • The limits are ours (D3D12 has none), and are marked as a guess in the code and docs.
  • Each gate keeps the words the record asked for, so VICTORY_TRACE_GPU_FAILS still shows what the GPU read.

Also measured, in one clean run: #386's dispatch gate fired 25 times on other records, as read by the GPU:

  • negative counts: [4294965248,1,1] (that's -2048), -2000, -256 and -250 (8bed0aea, ffc12cdb, d8c23621);
  • [17047270,1,1] (2fcb1ef0, 3760b3db) and [22067255,1,1] (3214f4b1);
  • a family read one word early: [34117522, 6, 1] (43b08db3, 71483b46, 5e94fc8b, bdbb169a, 52eff199).

Their producers aren't identified yet. Every legitimate dispatch record seen is [n, 1, 1] (17,261 of 17,261, n ≤ 20,952).

Test: victory-metal an_indirect_draw_past_the_most_instances_draws_nothing, which fails without the change.

Checks: victory-hle, victory, victory-gpu, xtask and victory-metal tests pass (arm64). Windows clippy is clean with -D warnings, and cargo xtask policy passes.

Not done yet:

  • A game run with the change; this Mac needs a reboot first, and results will follow here.
  • A garbage record under the limits (e.g. 30,000 instances of a full-screen triangle) still runs.

@⁠LakshanSivakumar, this is ours, so it needs your approval and merge.

**@⁠Olima34** on GitHub · 2026-11-27 21:02 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459) `Olima34:fix/indirect-draw-limit` → `main` · +58 −27 · 3 files · 2 commits · merged 2026-11-28 00:28 UTC Refs #79, #360. Follow-up to #386, which gated indirect *dispatches*. This gates indirect *draws*. **The cause.** Caught on preview b3c1a1b0 (M5 Pro 48 GB, Series S, headless, `VICTORY_DEPTH_TWINS=0`, `VICTORY_PASSES_PER_BUFFER=1`, `VICTORY_TRACE_COMMITS=1`), in 1 run of 5, at +230 s. - The one pass committed and never done is a render pass of **one indirect draw** (vertex `6adfc332b21374b3` / pixel `5d62a6c8f962e840`). - The GPU read its record as **[3, 864026624, 0, 0]**: 3 vertices x 864,026,624 instances. `0x33800000` is the same stale float another record of the run held in y and z (`f4554457`: [9, 864026624, 864026624]). - GPU utilisation was 100% while it ran. **What follows it.** - **The time-outs:** the kernel logs `Cmd queue … sleep … timed out` every 5 s, and the run ends with 43 time-outs and 1 out-of-memory. - **Not a memory shortage:** the residency set held 18.0–18.8 GB (81,000–94,000 allocations), the footprint was 21–22 GB, and the recommended working set is 38.3 GB. **Why the memory stays stranded (#360).** 1. SIGTERM came 12 s after the first time-out. 2. The stop waited 3 s + 20 s ("15 command buffers still in flight … running on the GPU"), then exited with `in_flight=15 left=9`. 3. The kernel logged `GPURestart type=2` 13 s later, and the driver kept 18.75 GB until a reboot. So the stop on main gives memory back for *waiting* buffers, but not while the GPU is running work that never ends. Only not starting that work helps. **Change.** Every indirect draw goes through the gate; counted draws, rectangle lists and mesh dispatches already did. - A record of more than 2^20 instances, or more than 2^26 vertices in all, draws nothing. So does a rectangle list of more than 2^20 rectangles. - The limits are ours (D3D12 has none), and are marked as a guess in the code and docs. - Each gate keeps the words the record asked for, so `VICTORY_TRACE_GPU_FAILS` still shows what the GPU read. **Also measured, in one clean run:** #386's dispatch gate fired 25 times on other records, as read by the GPU: - negative counts: [4294965248,1,1] (that's -2048), -2000, -256 and -250 (`8bed0aea`, `ffc12cdb`, `d8c23621`); - [17047270,1,1] (`2fcb1ef0`, `3760b3db`) and [22067255,1,1] (`3214f4b1`); - a family read one word early: [34117522, 6, 1] (`43b08db3`, `71483b46`, `5e94fc8b`, `bdbb169a`, `52eff199`). Their producers aren't identified yet. Every legitimate dispatch record seen is [n, 1, 1] (17,261 of 17,261, n ≤ 20,952). **Test:** victory-metal `an_indirect_draw_past_the_most_instances_draws_nothing`, which fails without the change. **Checks:** victory-hle, victory, victory-gpu, xtask and victory-metal tests pass (arm64). Windows clippy is clean with `-D warnings`, and `cargo xtask policy` passes. **Not done yet:** - A game run with the change; this Mac needs a reboot first, and results will follow here. - A garbage record *under* the limits (e.g. 30,000 instances of a full-screen triangle) still runs. @⁠LakshanSivakumar, this is ours, so it needs your approval and merge.
The stop that still ended world runs after #383, caught on the 2026-11-28
preview (M5 Pro 48 GB, Series S, headless, one pass per command buffer,
VICTORY_TRACE_COMMITS): the one pass committed and never done was a render pass
of one indirect draw (vertex 6adfc332b21374b3, pixel 5d62a6c8f962e840) whose
record the GPU read as [3, 864026624, 0, 0]: 3 vertices, 864,026,624 instances,
stale float bits where the instance count should be. The GPU stayed at 100 %,
the waits behind it timed out 5 s apart (43 time-outs, one out-of-memory), the
stop on SIGTERM left after its 23 s with 9 command buffers still in flight, the
kernel restarted the GPU 13 s later and the driver kept 18.75 GB until a reboot.
4 runs of 5 on that tree had no GPU error.

Every indirect draw now goes through the gate (counted ones, rectangle lists and
mesh dispatches already did): a record of more than 2^20 instances, or of more
than 2^26 vertices in all, draws nothing; a rectangle list's of more than 2^20
rectangles too. The limits are ours (D3D12 has none); no draw of the title's is
known to come near them. Every gate keeps the words the record asked for after
the words it runs, so VICTORY_TRACE_GPU_FAILS still shows what the GPU read.

A stop cannot give the memory back while the GPU runs work that does not end
(#357): only not starting it does.

Test: an_indirect_draw_past_the_most_instances_draws_nothing (victory-metal),
which fails without the change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:03:20 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 22:03 UTC · original

Verified in game: preview b3c1a1b0 + the fatal-fault hook + this gate, 5 headless runs of 300 s each, Series S.

  • All 5 clean: 0 GPU errors, 0 time-outs, 0 out-of-memory. Frames reached: 2304, 2337, 2368, 2304, 2368. The driver's memory drained to 0 GB after every run. Before the gate, 1 run of 5 hung and stranded 18.75 GB.
  • Direct proof in run 5: the gate refused draw 0 [3, 864026624, 0, 0], the very record that hung the Mac earlier, and the run went on and ended cleanly.
  • Records past the limits, per run: 0, 1, 9, 33 and 94. All were refused, and none hung.

Where the garbage comes from, still being traced. The record makers are correct. For example, compute 82d069c164aa731a writes x = (counter + 63) / 64 with y = z = 1. But their input counters, and sometimes whole record buffers, get foreign data: in one run, the whole 512-record buffer was overwritten in one go with vertex- or tree-like triples while a skinning/build pass ran.

One host cause we found on main: heap buffer views held by one pool run aren't mirrored again when the title maps other pages under the same address. More than 2,048 such views really moved in one run. Following them didn't stop every garbage record, though, so we don't claim it as the fix yet. More soon.

**@⁠Olima34** on GitHub · 2026-11-27 22:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459#issuecomment-7228991701) Verified in game: preview b3c1a1b0 + the fatal-fault hook + this gate, 5 headless runs of 300 s each, Series S. - **All 5 clean:** 0 GPU errors, 0 time-outs, 0 out-of-memory. Frames reached: 2304, 2337, 2368, 2304, 2368. The driver's memory drained to 0 GB after every run. Before the gate, 1 run of 5 hung and stranded 18.75 GB. - **Direct proof in run 5:** the gate refused `draw 0 [3, 864026624, 0, 0]`, the very record that hung the Mac earlier, and the run went on and ended cleanly. - **Records past the limits, per run:** 0, 1, 9, 33 and 94. All were refused, and none hung. **Where the garbage comes from, still being traced.** The record makers are correct. For example, compute `82d069c164aa731a` writes x = (counter + 63) / 64 with y = z = 1. But their input counters, and sometimes whole record buffers, get foreign data: in one run, the whole 512-record buffer was overwritten in one go with vertex- or tree-like triples while a skinning/build pass ran. One host cause we found on main: heap buffer views held by one pool run aren't mirrored again when the title maps other pages under the same address. More than 2,048 such views really moved in one run. Following them didn't stop every garbage record, though, so we don't claim it as the fix yet. More soon.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 23:55 UTC · original

@⁠LakshanSivakumar merged current main (86cefd22) into this branch; the code merged without conflict. One note on the docs: the 86cefd22 merge dropped the "most groups a record may ask for" paragraph of "ExecuteIndirect on the native host" (the #386 dispatch gate, whose code and tests are still on main). This branch restores it, updated for draws. Checked on the merge: victory-gpu and victory-metal tests pass (arm64), Windows clippy -D warnings clean, cargo xtask policy ok. Ready for your review.

**@⁠Olima34** on GitHub · 2026-11-27 23:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459#issuecomment-7230506098) @⁠LakshanSivakumar merged current main (`86cefd22`) into this branch; the code merged without conflict. One note on the docs: the `86cefd22` merge dropped the "most groups a record may ask for" paragraph of "ExecuteIndirect on the native host" (the #386 dispatch gate, whose code and tests are still on main). This branch restores it, updated for draws. Checked on the merge: victory-gpu and victory-metal tests pass (arm64), Windows clippy `-D warnings` clean, `cargo xtask policy` ok. Ready for your review.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-28 00:22 UTC · original · approved these changes

**@⁠LakshanSivakumar** on GitHub · 2026-11-28 00:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459#pullrequestreview-6094575193) · **approved these changes**
github manually merged commit a6a5836147 into main 2026-11-28 00:29:36 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.