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

Merged
Olima34 merged 2 commits from upstream-pr/459 into main 2026-11-28 00:28:25 +00:00
Olima34 commented 2026-11-27 21:02:33 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T21:02:33Z.


Refs #79, #357. Follow-up to #383, 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 (#357).

  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: #383'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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5533057056 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T21:02:33Z. --- Refs #79, #357. Follow-up to #383, 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 (#357).** 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:** #383'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 commented 2026-11-27 22:03:37 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T22:03:37Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228991701 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459#issuecomment-7228991701). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T22:03:37Z. --- 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 commented 2026-11-27 23:55:09 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T23:55:09Z.


@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 #383 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7230506098 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/459#issuecomment-7230506098). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T23:55:09Z. --- @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 #383 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!459
No description provided.