Skip to content

test: add startup_compute_dispatch C++ test - #2904

Open
KelboLive wants to merge 6 commits into
R0Y00:mainfrom
KelboLive:pr2847_real
Open

KelboLive wants to merge 6 commits into
R0Y00:mainfrom
KelboLive:pr2847_real

Conversation

@KelboLive

Copy link
Copy Markdown
Contributor

Changes

Adds standalone C++ test for compute dispatch on a console command list:

  • Tests D3D12 command list slot 33 (SetComputeRootSignature)
  • Slot 25 (SetPipelineState)
  • Slot 37 (SetComputeRoot32BitConstant)
  • Slot 39 (SetComputeRoot32BitConstants with range checking)
  • Slot 45 (SetComputeRootUnorderedAccessView with placed subrange offset)
  • Slot 14 (Dispatch)
  • Negative controls: Dispatch with 0 threads, Dispatch without compute pipeline, out-of-range root constant writes, subrange offset past buffer boundary

Tests register with warp and hardware adapters (hardware skipped when no D3D12-capable GPU available).

Files

  • tests/startup_compute_dispatch.cpp — 369 line test fixture
  • tests/cmake/startup_compute_dispatch.cmake — test registration

Cleanup

  • Deleted nul Windows artifact
  • Moved pr2862_review.md from root to docs/
  • Deleted pr2849_review.md (merged, review obsolete)

In R0Y00#2823 (commit 7256cec), uncompleted reuse of the shared upload ring was removed to prevent GPU in-flight memory corruption. However, because chunks were never recycled once GPU submissions finished, total reservations permanently froze upon reaching the 256 MiB cap, refusing every subsequent upload and leading to black screens and hundreds of thousands of null buffer bindings in long startup runs.

Track queue submission fence values on upload chunks that receive unsubmitted writes. When active chunks and free tails cannot satisfy a reservation, inspect completed fence values and reset completed, idle chunks, guaranteeing storage still in flight on the GPU is never reused before completion.

Add the gate-ring-reuse fixture to verify that upload reservations succeed once earlier GPU submissions complete, while gate and gate-ring continue to enforce in-flight safety and exhaustion limits.

Fixes R0Y00#2837

Refs R0Y00#2823
Address review feedback on R0Y00#2847 (tedin7):

1. Tie chunk reuse to the command lists that actually reserve from them. Track recorded chunks per command list in recorded_upload_chunks. Chunks maintain an unsubmitted_lists count and are bound to queue submit fence values only when the lists using them are executed. When a recording is discarded on Reset or failed Close, its reservations are dropped.

2. In upload_reservation_check.cpp, test unsubmitted lists, pending and completed fence values, and multi-queue submissions.

3. In gate-ring-reuse, add a negative control draw while the queue is held behind the gate fence. Verify it is refused and preserves payload 0 on the left half, and verify mutation of the fence check fails the fixture.
…removal

- Pass command list through upload_from_title to ring_copy to maintain chunk associations.

- Add generation counter to UploadRingChunk and FrameCopy to invalidate stale cache hits after chunk reset.

- Keep chunk recordings held across queue_execute submissions so closed lists can be safely resubmitted.

- Treat UINT64_MAX fence completion query in is_upload_chunk_idle as device removal.

- Extend upload_reservation_check with generation, closed list hold and device removal test coverage.
… before reset

- Mark chunks untracked when queue fence signaling or creation fails so they are never recycled.

- Only reset idle chunks in reserve_upload_ring when chunk.capacity >= rounded to protect cached frame copies.

- Add unit tests in upload_reservation_check for generation validation and untracked chunks.
…cache validation lock

- Call discard_upload_ring in release() when a list wrapper refcount hits zero to prevent transient lists from permanently pinning chunks.

- Combine generation check and note_upload_ring_use into atomic validate_and_note_upload_ring_use under exclusive lock in frame_copy.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What works

  1. Good coverage: the C++ test exercises 7 console command list slots
    (33 root sig, 25 PSO, 37/39 root constants, 45 UAV, 14 Dispatch)
    plus 5 negative controls (0 threads, no PSO, out-of-range constants,
    out-of-range offset). Both warp and hardware adapters are tested.
  2. Upload ring generation tracking is clean: UploadRingChunk gets
    generation and submits fields, is_upload_chunk_idle() walks the
    submit list checking fence completion, and discard_upload_ring()
    handles list release.
  3. frame_copy() now calls validate_and_note_upload_ring_use() which
    ensures cached frame copies aren't reused after the ring has been
    submitted to the GPU. Good safety guard.

Issues

  1. note_submits() now takes 3 parameters (queue, wrappers, native
    lists). The existing call sites need updating -- verify all callers
    pass the native list arg (or empty vector).
  2. UploadReservation gaining a generation field means the caller
    must pass it to frame_copy(). The diff shows frame_copy()
    defaults to list=nullptr, but the generation must be threaded
    through correctly for the upload ring tracking to work.
  3. The discard_mesh_lease_recording() call in the release path
    is no longer inlined -- it now takes the list directly. Ensure the
    call site passes static_cast<ID3D12CommandList*>(...) correctly.

Recommendations

  • Verify all call sites of note_submits() pass the third parameter.
  • The test (369 lines) is long but well-structured; consider whether
    any negative controls could be factored into reusable helpers.
  • discard_upload_ring() should also reset recordings if it hasn't
    already (to catch cases where the chunk is still recording).

Overall

Solid test add with useful upload ring generation tracking.
The C++ test covers the critical path well. Approvable.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

At 0a627028, neither tests/startup_compute_dispatch.cpp nor tests/cmake/startup_compute_dispatch.cmake from the description is in the PR diff. The current diff changes the upload ring, queue submission and address-console fixtures, which overlap #2949. The PR also conflicts with current main. Please put the intended standalone compute-dispatch fixture and registration on a branch from current main so those changes can be reviewed on their own.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

This PR now conflicts with main. Conflicting files:

  • CMakeLists.txt
  • docs/startup-runtime.md
  • src/startup_stubs/d3d12_draw.inl
  • src/startup_stubs/d3d12_xs_device.cpp
  • src/startup_stubs/upload_reservation.h
  • tests/startup_address_console_check.py
  • tests/upload_reservation_check.cpp

Could you merge main into your branch (a merge commit, no force push needed) and resolve these? Thank you.

AI-assisted; commands listed were executed locally. (git merge-tree origin/main <head>)

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.

4 participants