Skip to content

gpu: trace descriptor history and GPU-written Mesh arguments - #3321

Open
wish131400 wants to merge 2 commits into
R0Y00:mainfrom
wish131400:gpu/mesh-argument-provenance
Open

wish131400 wants to merge 2 commits into
R0Y00:mainfrom
wish131400:gpu/mesh-argument-provenance

Conversation

@wish131400

@wish131400 wish131400 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Change

Refs #3310. A zero indirect Mesh count can come from a missing or stale descriptor copy, an SRV pointing at the wrong scalar, or the consumer using a different argument offset. Add a source-built fixture that distinguishes these cases and an opt-in runtime descriptor-history diagnostic.

The fixture follows a Compute write of scalar 2, an SRV-driven updater writing (2,1,1), fenced post-write and pre-consume snapshots of the same 12-byte interval, and a guest ExecuteIndirect Mesh submission. It checks every pixel of the 4x2 scene-color target. Missing-copy, stale-copy, wrong-SRV-offset and wrong-argument-offset controls must fail the same positive oracle. A sixth process repeats the positive case with history disabled.

X2W_D3D12_DESCRIPTOR_HISTORY=1 records guest token bytes before publication, old/new shadow IDs, create/copy/overwrite order, descriptor identities, buffer SRV first element/stride and backing resources. CPU publication sequence is separate from GPU queue/fence evidence. The switch is off by default and adds no GPU commands or synchronization.

The diagnostic supports this fixture and short startup reproductions only. It records the first 8,192 events and then truncates. Initialization or a large descriptor copy can exhaust that budget before a later producer runs; each copied descriptor counts separately. No filtering, delayed start or rolling history is implemented. Later integration history needs a separately targeted diagnostic. Arbitrary guest CPU stores are not intercepted. With X2W_D3D12_VIEW_CONTENT_TOKENS=1, shadow-record IDs can be reused at different sequence points.

Each fixture process explicitly prints provenance debug info_queue=present or info_queue=absent, and the driver requires this report. An absent queue leaves pixel/argument checks active but provides no evidence about debug-layer errors.

Experiment, reproduction commands and limits are documented with the runtime switch. The fixture reuses the existing indirect Mesh executable and source-built shaders. Its WARP variant is in the PR smoke preset.

Verification

Tested merge commit 029dfefef4c273b5d9c5565fbff1ee2acfd9a3ca, which merges main 44a3ad5aa9c679cc039b8cb8275738dd6e4405d2 into the published PR head 42a185536bfd5e9df81d786d55fceb48046f1b32. Conflict resolution preserves main's current smoke-test selections and native fixed-Mesh/MRT fixture alongside the provenance fixture.

30 November 2026: Windows 10 Pro build 19045; NVIDIA GeForce RTX 4070 Ti SUPER; driver 32.0.15.7270; MSVC 19.43.34810; DXC 1.9.2609; Agility SDK 620; D3D12 debug layer enabled. GPU tests ran serially.

cmake --build --preset dev --target startup_indirect_draw_indexed startup_compute_binding_trace startup_view_alloc startup_view_census
ctest --preset dev --no-tests=error -j 1 -V -R '^startup_(mesh_argument_provenance_(warp|hardware)|indirect_mesh_(warp|hardware)|view_alloc_.*|view_census_.*|compute_binding_trace_warp)$'
ctest --preset dev --no-tests=error -j 1 -V -R '^native_fixed_mesh57(_mrt)?_(warp|hardware)$'

cmake --build --preset release --target startup_indirect_draw_indexed startup_compute_binding_trace startup_view_alloc startup_view_census
ctest --preset release --no-tests=error -j 1 -V -R '^startup_(mesh_argument_provenance_(warp|hardware)|indirect_mesh_(warp|hardware)|view_alloc_.*|view_census_.*|compute_binding_trace_warp)$'
ctest --preset release --no-tests=error -j 1 -V -R '^native_fixed_mesh57(_mrt)?_(warp|hardware)$'

Both builds passed. Each configuration produced:

Group Selected Passed Failed Capability skips
Provenance, indirect Mesh, view allocation/census and compute binding trace 23 21 0 2
Native fixed-Mesh/MRT regression 4 2 0 2

The four skips in each configuration were startup_indirect_mesh_warp, startup_mesh_argument_provenance_warp, native_fixed_mesh57_warp and native_fixed_mesh57_mrt_warp: Mesh shaders are unavailable on this host's WARP adapter. Hardware tests passed. All six hardware provenance processes reported info_queue=present, with no device removal or debug-layer ERROR/CORRUPTION messages.

Case After producer, byte 4 Before consumer Changed pixels
Positive (2,1,1) byte 4: (2,1,1) 8/8
Missing copy (0,1,1) byte 4: (0,1,1) 0/8
Stale copy (0,1,1) byte 4: (0,1,1) 0/8
Wrong SRV offset (0,1,1) byte 4: (0,1,1) 0/8
Wrong argument offset (2,1,1) byte 20: (0,1,1) 0/8

Mutation check: locally changed src/startup_stubs/d3d12_capture.inl:855 from trace_descriptor_history("copy", ...) to trace_descriptor_history("create", ...). The Debug build succeeded; the previously passing startup_mesh_argument_provenance_hardware test failed its copy-history assertion, while positive pixel readback remained 8/8. Restored the mutation, rebuilt, and confirmed the hardware test passes again. The mutation is not committed.

Also passed:

  • python -B tests/docs_links_check.py: 182 Markdown files, 728 links.
  • python -B tests/bidi_controls_check.py: 2,695 tracked source, script and build/CI files.
  • Python AST syntax, CMake preset JSON and PR-regex selection checks.
  • git diff --cached origin/main --check before the merge commit.

The previous head 42a18553 passed Actions run 46130729442, including the provenance test on hosted WARP. Those historical CI results do not establish CI status for the new merge commit; its checks must run again.

Evidence and follow-up

The fixture is original source under the repository's MIT license. Inputs are source-built or synthetic. Producer HLSL and submission/fences are native desktop D3D12; descriptor creation/copy and the indirect Mesh consumer use guest wrappers.

This supplies the fixture and diagnostic portion of #3310. Its matched integration acceptance remains outstanding: the reported 48 zero records were not reproduced. A matching integration must identify its scalar-input write and descriptor history, prove identical nonzero records at the same resource/offset, and show a Mesh submission changing scene color before composition. This fixture does not exercise translated gfx1013 producer code, guest queue preprocessing or XMem refresh. Keep #3310 open; integration work referenced in #3091/#3094 needs its own execution evidence.

AI-assisted implementation, conflict resolution and local verification.

@wish131400

Copy link
Copy Markdown
Contributor Author

Follow-up integration check, separate from the passing fixture in this PR:

I found an existing source-built scalar-input positive failing on the public #3248 head 7f97cb5b. The compiler succeeds, but the table-1/byte-64 scalar window is refused before dispatch, leaving all 288 result words at the sentinel. The integration head retains scalar_window metadata but drops the bounded unplaced-window handling present in public #3094. The focused restoration and before/after evidence are reported on #3248, with source-only commit c6c7688b. Hardware: 7/7 related tests pass after restoration; local WARP: 2 passes and 1 native-wave32 capability skip. Existing negative assertions were unchanged.

Two bounded local integration runs did not reach a valid Mesh argument capture. The later run reached native Compute attempts but stopped earlier in the rendering dependency chain: one PSO creation failure and two unsupported texture-UAV bindings, with zero translated draws/Mesh submissions. #3049 already supplies the relevant broader in-process texture binding work.

A separate original-source constant-store WaveSize(32) shader confirms the local runtime prerequisite: the installed in-box Windows 10 D3D12 reports SM 6.5 and refuses the cs_6_6 PSO (80070057), while an EXE selecting Agility 620 reports SM 6.6 and creates the same PSO (00000000) on the same RTX 4070 Ti SUPER/driver 32.0.15.7270. Enabling Agility for the test EXEs does not select it for another startup process. This is not proof of the captured PSO's only failure cause.

The generic descriptor history also reaches its 8192-event truncation limit during initialization; it must be targeted before claiming complete later producer history. This PR remains draft and does not close #3310: the actual producer, same-resource/same-offset nonzero post-write/pre-consume records, and a real Mesh scene-color change remain unverified. No title assets, shader bytes, captures or private logs are included here.

@wish131400
wish131400 marked this pull request as ready for review November 28, 2026 11:19

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 42a18553 by its diff. Writes go through the existing log() only, tracing off costs one cached flag check, and the GPU readbacks wait on the fence. Three points:

  1. Conflicts with main. main added native_fixed_mesh_fixture in tests/startup_indirect_draw_indexed.cpp where this PR adds its #include "startup_mesh_argument_provenance.inl"; a rebase is needed.
  2. The trace does not fit a real run. As your comment says, the 8192-event cap is reached during initialization, and a copy is counted per descriptor, so one large CopyDescriptors can use the whole budget. A filter (address or heap range, slot, start after N events) or a ring of the last N events would make it usable; otherwise the docs should say it is for the fixture only.
  3. The debug-layer check passes when there is no ID3D12InfoQueue. The test should print whether the info queue was present, since the docs list "no debug-layer ERROR/CORRUPTION" as part of the check.

The PR is not marked draft on GitHub while your comment calls it a draft; marking it would match that. Request changes for 1-2.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

I reviewed 42a18553 by reading the diff and a trial merge into main af1cab5c; I built and ran nothing. Leyukaka's change request still applies, and I don't repeat it here. Two additions:

  • More files conflict now. git merge-tree --write-tree origin/main 42a18553 conflicts in CMakePresets.json, docs/startup-runtime.md and tests/startup_indirect_draw_indexed.cpp. src/startup_stubs/d3d12_capture.inl merges cleanly, and in the merged file both trace_descriptor_history calls still run with note_lock held exclusive. Please rebase.
  • CI at this head ran the new test: the Windows job shows startup_mesh_argument_provenance_warp ... Passed and 100% tests passed out of 74. On an export of the head, tests/docs_links_check.py (Checked 154 Markdown files and 676 links.) and tests/bidi_controls_check.py pass.

MUST
None beyond Leyukaka's points 1 and 2.

SHOULD
None.

NIT

  1. Since startup: opt-in content view tokens so view records can be freed #3377, X2W_D3D12_VIEW_CONTENT_TOKENS=1 reuses parked view records: take_parked_record() clears a record and gives its id to the next new view. With both switches on, an old= or new= id in the history can name different views at different points in one run. The fixture doesn't set the token switch, so it isn't affected. One sentence in the environment row or the experiment note would stop readers from treating a reused id as a single view.

AI-assisted.

@R0Y00 R0Y00 added the priority: P0 Highest project priority label Nov 30, 2026 — with ChatGPT Codex Connector

@lukaslw-lab lukaslw-lab 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.

Reviewed 029dfefe by reading the diff; not built or run.

Verdict: approve. The switch is inert when unset, and the history it records reflects the order shadow slots are updated in. It conflicts with main again (below). No MUST.

  • Off path (d3d12_capture.inl:851, :809). Unset, note_copy adds one cached flag check and skips both title_descriptor_stride calls. note_view returns from trace_descriptor_history on the same flag. When the switch is on, title_descriptor_stride takes descriptor_lock before note_lock, not under it, so this adds no new lock order.
  • "guest_before" is really before. The create event reads guest bytes before *slot_ptr and the token write. The copy events run under note_lock, and the title-memory memmove happens only after the lock is released (:896-901). The per-index to[i]/from[i] reads come before the shadow memmove, so overlapping copies log pre-copy ids.
  • SHOULD: copies into or out of untracked slots log as empty (:851-857). When the destination has no shadow slot, previous and next are both 0. When the source is untracked, next is 0, the same as copying an empty descriptor. In both cases the event doesn't say which view was copied: source is only the title address. A missing or stale copy is exactly what the diagnostic should catch, so a source_id= field (from[i] when tracked) would separate "copied an untracked view" from "copied nothing". The fixture reaches none of these branches, nor the 8,192 truncation: every event it checks is a tracked slot-18 SRV (check script :64-66).
  • Conflict: git merge-tree --write-tree against main 903fcc85 conflicts in CMakePresets.json only (the pr test filter).

Tests: the six processes pin the positive oracle and four controls against the same pixels. The trace-off run proves no x2w-descriptor-history line is written when the switch is unset. CI ran startup_mesh_argument_provenance_warp at this head (Windows job: Passed, 87/87). The red Linux job is startup_triage_run_check.py on base 44a3ad5a; main has fixed that since #3542.

@Jess-Doit

Copy link
Copy Markdown
Contributor

Reviewed 029dfefe against main bee9c64d. Release build, diff whitespace, Markdown links, bidi controls and the portable oracle checks pass. Both in-box WARP cases skip on Mesh capability here, and our GTX 1060 has no Mesh shaders, so I ran no GPU positive.

These are separate from lukaslw-lab's source_id= point, which covers untracked slots:

  1. An intercepted copy can log matching ids while guest and desktop bytes differ (d3d12_capture.inl:851-857, :896-901). The copy event records shadow ids only. The guest memmove runs after note_lock is released and only when both ranges are title-backed with equal strides, and nothing records whether it ran or which guest token it carried. If a CPU write changes the source's guest bytes without touching its shadow, both slots stay tracked and the history still reads as a clean copy. Logging the source guest token and whether the guest copy happened, plus one divergent-token control, would catch that. A portable probe of the checker accepts a mismatched source token in the fixture's observations.
  2. Typed buffer SRVs omit their byte range (:719, :728). A raw SRV and a typed 16-bit SRV over the same buffer can log the same first element and zero stride while covering different bytes. Format, raw flag and element count, or the decoded byte range, would let the history tell them apart.
  3. Nit: the walk continues after the trace cap (:704, :851). Once the truncation marker is written, a large copy still loops over every descriptor under the exclusive lock. It could stop there.

The CMakePresets.json pr filter conflict lukaslw-lab mentioned is the only one I see against bee9c64d too.

AI-assisted.

Ready for more review

@Vilify-13

Vilify-13 commented Nov 30, 2026 •

Copy link
Copy Markdown

Independent reproduction and proposed follow-up

I've independently reproduced 029dfefef4c273b5d9c5565fbff1ee2acfd9a3ca in both Debug and Release configurations.

Test environment

  • OS: Windows 11 Home 26H2, build 26300.9974

  • GPU: NVIDIA GeForce RTX 4060

  • GPU driver: 32.0.16.2114

  • WARP driver: 10.0.26100.9818

  • MSVC: 19.44.35230

  • DXC: 1.9.2602.17

  • D3D12: Installed Windows runtime, without a separately provisioned Agility SDK

  • Debug layer: Enabled

Verification

GPU tests were executed serially using the reproduction commands documented in this PR:

foreach ($preset in @("dev", "release")) {
    cmake --build --preset $preset --parallel 8 --target `
        startup_indirect_draw_indexed `
        startup_compute_binding_trace `
        startup_view_alloc `
        startup_view_census
ctest --preset $preset --no-tests=error -j 1 -V `
    -R '^startup_(mesh_argument_provenance_(warp|hardware)|indirect_mesh_(warp|hardware)|view_alloc_.*|view_census_.*|compute_binding_trace_warp)$'

ctest --preset $preset --no-tests=error -j 1 -V `
    -R '^native_fixed_mesh57(_mrt)?_(warp|hardware)$'

}

Configuration Selected Passed Failed Capability skips
Debug 27 27 0 0
Release 27 27 0 0
Total 54 54 0 0

The reproduction used the unmodified PR revision and source-built fixtures.

Proposed contribution

Building on the descriptor-history implementation in this PR, the event-budget limitation identified by @Leyukaka, and the post-truncation traversal observation from @Jess-Doit, I'd like to develop a focused follow-up addressing targeted descriptor-history filtering.

The proposed scope is:

  • Apply optional descriptor-range filtering before event-budget consumption and guest-token sampling.

  • Match descriptor copies against both source and destination ranges.

  • Calculate matching descriptor indices efficiently, avoiding unnecessary per-descriptor diagnostic traversal during large copies.

  • Terminate diagnostic-only traversal once the event budget is exhausted.

  • Add source-built regression coverage demonstrating that unrelated initialization events do not prevent relevant later descriptor history from being captured.

  • Measure diagnostic traversal overhead and perform mutation testing to verify the new regression coverage.

I'm currently evaluating absolute-address and heap-relative filtering, particularly how relevant descriptor ranges can be identified reliably across separate executions.

The intention is to preserve existing unfiltered behavior, descriptor-copy semantics, lock ordering and GPU synchronization.

I would keep the other diagnostic correctness findings raised during review outside this initial contribution so that each change remains independently reviewable.

This follow-up would reference #3310 and depend on #3321. It would not claim to satisfy #3310's remaining integration acceptance criteria.

Are you currently working on targeted descriptor-history filtering, or would you be comfortable with me developing this as a separate follow-up contribution?

AI-assisted architectural research, implementation planning and independent verification.

@Vilify-13

Copy link
Copy Markdown

Targeted descriptor history follow-up — implementation complete

@wish131400

Following the previous comment, I've finished work on the targeted descriptor-history filtering implementation, including compatibility integration of your contribution against upstream revision 959306d4.

Verification results:

  • Dependency integration: 108/108 tests passed.
  • Consolidated implementation: 118/118 tests passed across Debug and Release, including 112 new live fixture executions.
  • Six portable mutation controls and three integrated runtime mutations successfully detected.
  • Official Windows PR smoke suite: 258 passed, three OS-dependent capability skips, zero failures.

The implementation introduces optional heap-relative filtering, source and destination range selection, bounded history admission, conservative descriptor attribution, and early termination of diagnostic traversal following truncation.

Given the existing merge conflicts in #3321, I'm preparing an integrated upstream draft PR that incorporates your original contribution with preserved Git authorship, followed by a separate commit containing the filtering implementation, regression coverage, and documentation.

Credit will also be given to @Leyukaka and @Jess-Doit for their relevant review findings.

The contribution will reference #3310 without claiming to satisfy its remaining integration acceptance criteria.

Thank you for establishing the foundation for this work. Any feedback during the review process is welcome.

AI-assisted implementation, testing and verification.

@Vilify-13

Copy link
Copy Markdown

@wish131400 Heyo, following up regarding this after the reviews on PR #3772

The remaining blocking concern is coordination between this PR and #3772. Would you prefer to land your PR independently first, after which I would rebase #3772, or would you be comfortable with #3772 superseding this PR? I'm perfectly fine with either way you'd like to handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Highest project priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants