Skip to content

startup: read translated compute inputs that live only in title memory from a snapshot - #2862

Open
tedin7 wants to merge 4 commits into
R0Y00:mainfrom
tedin7:c18-upstream-snapshot
Open

tedin7 wants to merge 4 commits into
R0Y00:mainfrom
tedin7:c18-upstream-snapshot

Conversation

@tedin7

@tedin7 tedin7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #870
Fixes #2860

What this unblocks: translated compute dispatches whose input buffers were written by the title (placed buffers that do not alias title memory) and dispatches with an unbound input run instead of being refused, also in a long run.

Change

Runtime only (d3d12_draw.inl, d3d12_xs_device.cpp, upload_reservation.h), plus a docs paragraph and test modes:

  • X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1 (opt-in): an input in a placed buffer that does not alias title memory is read from a GPU copy this list made, else from a snapshot of at most 16 MiB copied from title memory at the dispatch.
  • Snapshots have a pool of their own, built like the shared upload ring of fix(startup): reuse upload ring chunks after GPU completion #2849: 128 MiB in chunks of 16 MiB, a chunk is reused once no recording can submit its bytes and every queue that used it has finished, and a recording holds the chunks it used. Its chunks are numbered after the ring's in the same recording mask and per-queue table, so the two pools cannot collide. Draw and texture uploads cannot use up the snapshots' pool, and a long run is not stopped by it filling up: with snapshots in the shared ring, a long run reported on this PR hit snapshot ring reservation refused: no unused capacity (report), and a pool that is never reused fills up over time. A reservation the pool cannot serve logs x2w-draw snapshot pool reservation refused: no unused capacity.
  • An all-zero compute input descriptor is an unbound buffer and binds 16 zero bytes (taken from the snapshot pool). An empty range with any non-zero word stays refused.
  • The log names the source of each key's first input; the render totals count GPU copies and snapshots.

Verification

Linux (executed locally):

  • git diff --check origin/main...HEAD: clean
  • cmake -S . -B <dir> -DDXC_EXECUTABLE=/bin/true: configure rc 0
  • tests/upload_reservation_check.cpp (new check_snapshot_pool: pool numbering, holds and discard in both pools, per-queue completion of a snapshot chunk, reuse of a finished unheld chunk) built with g++ and run: passes
  • x86_64-w64-mingw32-g++ -fsyntax-only -std=c++20 on d3d12_xs_device.cpp: no error in the changed code (the MinGW headers stop on MSVC-only constructs that origin/main has too)

Win2025 (Windows Server 2025, Build 26100, MSVC 14.44.35207, D3D12 WARP) at 73b2d0ff73921cce81188d3e11cda6064ac3de87:

  • ctest --preset dev -R '^(startup_compute_dispatch_input_|upload_reservation$)' --no-tests=error --output-on-failure: 3/3 passed (startup_compute_dispatch_input_warp, startup_compute_dispatch_input_hardware, upload_reservation)
  • ctest --preset release -R '^(startup_compute_dispatch_input_|upload_reservation$)' --no-tests=error --output-on-failure: 3/3 passed
  • Mutant (snapshot pool never recycled), dev: startup_compute_dispatch_input_warp and _hardware fail with AssertionError: dispatch-input-snapshot-long: consumer exit 85 after x2w-draw snapshot pool reservation refused: no unused capacity; upload_reservation passes.

Tests: startup_compute_dispatch_input keeps dispatch-input-snapshot (off: refused; on: all 320 words match; zero title memory runs on zeros) and dispatch-input-null, and adds dispatch-input-snapshot-long: 48 frames of dispatches whose 8 MiB title-memory input is snapshotted each frame with the queue completed between frames (384 MiB in all, three times the pool). Every frame must translate and give the first frame's words, the last frame must match the CPU reference on the D3D12 adapter, and no reservation may be refused.

Real-hardware testing: @Makto94 - thanks for the help.

Source: Microsoft D3D12 documentation (placed resources, upload heaps, raw buffer SRVs).

…y from a snapshot, and bind unbound inputs as zeros

A compute input in a placed buffer that does not alias title memory is a committed default buffer that holds zeros, so the bytes the title wrote exist only in title memory. With X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1 (opt-in) the range (at most 16 MiB) is copied into a dedicated upload pool (128 MiB) so draw and texture uploads cannot starve it. A compute input whose four descriptor words are all zero is an unbound buffer: it reads zeros (16 bytes) instead of refusing the dispatch; an empty range with any non-zero word is still refused. The log names the source of each input and the render totals count GPU copies and snapshots.
@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 14:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T20:46:31.917087Z 73b2d0f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9fbfc86a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/experiments.md Resolved
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 4322d76f155c1878da11b3b3e2dee195b1886bfe:

  • Debug (ctest --preset dev -R 'startup_compute_dispatch_input' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (startup_compute_dispatch_input_warp, startup_compute_dispatch_input_hardware)
  • Release (ctest --preset release -R 'startup_compute_dispatch_input' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (same two tests)

AI-assisted; commands listed were executed locally.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work on this. The approach is sound:

  1. Dual upload pools (snapshot 128 MiB vs draw/texture 256 MiB) correctly prevents snapshots from starving draw uploads

  2. Resolution order is correct: GPU copy (from X2W_TRANSLATED_INDIRECT_COPY_RANGES) -> snapshot -> refusal. The fallback chain is safe and the 16 MiB cap on snapshots is reasonable

  3. Null descriptor handling: correctly produces 16 bytes of zeros for all-zero descriptor words, matching hardware behavior. The readable_window check before ring_copy is the right guard

  4. indirect_table_buffer API expansion: added allow_title_snapshot parameter cleanly propagated from record_translated_dispatch

  5. Tracking counters: atomic counters with snapshot KiB tracking gives good observability

Minor notes:

  • The InputSource source field in IndirectBufferView is a clear 4-value enum. When this stabilizes consider a typed enum (similar to NullCause) rather than int, but not urgent
  • The 128 MiB / 256 MiB split is hardcoded. If title pressure shows the pool balance needs tuning, make the split configurable. Not needed today

Looks good to merge. This unblocks #2860 and forms a solid foundation for the upload ring reuse work in #2847.

@Leyukaka

Copy link
Copy Markdown
Contributor

A run report for this PR, combined with #2902, on a local capture (counts only). The build and the run were done in an offline Windows Sandbox:

Without this PR (#2902 alone), the three compute pipelines that #2902 translates are all refused at Dispatch with an input is in a placed buffer that does not alias title memory. One is dispatched about once per presented frame, 17,378 refusals in that run; the other two are dispatched once each.

With this PR:

  • The log shows compute dispatches: translated 17407, refused 0, no translation 0.
  • In this run only the per-frame pipeline was dispatched, and its named input is a 2,704-byte snapshot.
  • The two other pipelines were dispatched once each in the earlier run described below, each with a 16-byte snapshot, and were translated.
  • Over the run, 34,814 inputs came from snapshots, 69,628 KiB in total.
  • The run kept 29.9 fps over 17,810 presented frames.

One difference from this PR as written: the merge with #2849 conflicted in reserve_upload_ring. I resolved it locally by keeping #2849's recycled upload ring and passing the snapshot flag through to it. Snapshots therefore shared that ring instead of the separate 128 MiB pool here.

In an earlier run of the same merge, the title went past its first screen:

  • Cumulative snapshots reached about 1.6 GiB after about 5.5 minutes.
  • Command-list recording dominated the frame time.
  • The shared ring also ran out (snapshot ring reservation refused: no unused capacity), which is what the separate pool is meant to avoid.

That run used the shared ring above, so it says nothing direct about the separate pool.

AI-assisted.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@Leyukaka thank you for this run report, and for testing this PR together with #2902 on top of current main.

Two things we take from it:

This PR currently conflicts with main in reserve_upload_ring after #2849. We have not pushed a resolution yet, and your report will shape it. The direction we are looking at is to keep snapshots in their own pool, built on #2849's design (chunks reused once the GPU has finished with them), instead of either the old never-reused pool or the shared ring. If we push it, the new head and a fresh Windows Server 2025 receipt will be posted here.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as draft November 26, 2026 19:49
…ts get their own recycled pool

Main's shared upload ring (reused once no recording can submit a chunk and every queue that used it has finished) is kept as it
is. The snapshots take a second pool built the same way (128 MiB, chunks numbered after the ring's in the recording mask and the
per-queue table) instead of the shared ring or a never-reused one, so a long run is not stopped by a full pool; the long-run
case dispatches 384 MiB of snapshots over 48 frames.
… alias title memory, and asserts the snapshot log line
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Stage-2 gate on the redesigned head (own recycled snapshot pool on top of #2849):

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 73b2d0ff73921cce81188d3e11cda6064ac3de87:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_stream_consumer upload_reservation_check -- -j 2): 32.15s (configure 0.00s)
    • Test (ctest --preset dev -R '^(startup_compute_dispatch_input_|upload_reservation$)' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (3.51s: startup_compute_dispatch_input_warp 3.05s, upload_reservation 0.08s, startup_compute_dispatch_input_hardware 3.26s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_stream_consumer upload_reservation_check -- -j 2): 61.48s (configure 0.00s)
    • Test (ctest --preset release -R '^(startup_compute_dispatch_input_|upload_reservation$)' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (2.24s: startup_compute_dispatch_input_hardware 2.06s, upload_reservation 0.01s, startup_compute_dispatch_input_warp 2.09s)

Mutant check (snapshot pool never recycled, dev): startup_compute_dispatch_input_warp and startup_compute_dispatch_input_hardware fail with AssertionError: dispatch-input-snapshot-long: consumer exit 85, after x2w-draw snapshot pool reservation refused: no unused capacity. So the long case does exercise recycling of the snapshot pool.

AI-assisted; commands listed were executed locally.

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.

Part of #870

3 participants