Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"displayName": "Windows pull request smoke tests",
"filter": {
"include": {
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$"
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_mesh_argument_provenance_warp|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$"
}
}
},
Expand Down
206 changes: 206 additions & 0 deletions docs/experiments/mesh-argument-provenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# GPU-written Mesh arguments and descriptor history

Refs [#3310](https://github.com/R0Y00/Xbox2Windows/issues/3310).
This adds a source-built reproducer and an opt-in descriptor diagnostic. It
does not establish the issue's matched integration acceptance or repair the
zero launch count observed there.

## What the fixture measures

`startup_mesh_argument_provenance_hardware` uses the existing
`startup_indirect_draw_indexed` executable in `mesh-provenance` mode. All shader
and buffer inputs come from repository source. No external capture, shader
cache, game content or fitted parameters are required.

The fixture follows this chain:

1. Create a raw buffer SRV in a CPU-only guest descriptor heap. Copy it to a
shader-visible heap, overwrite the source SRV, then copy the updated view.
The guest token and desktop shadow record have different identities.
2. A source-built Compute dispatch writes the scalar input: `2` at byte 16
and `0` at byte 32. Copy those bytes to readback before the updater. After
fence 1 completes, verify that this GPU write supplied the nonzero input.
3. A second Compute dispatch reads `launch.Load(0)` through the copied SRV
and writes `(X,1,1)` into the argument buffer at byte 4. Copy the argument
buffer to a separate readback allocation and complete fence 1.
4. In a separate submission on the same DIRECT queue, copy that buffer again
immediately before the guest command-list slot 61 `ExecuteIndirect` call.
Complete fence 2 before mapping the second snapshot. Report the exact
consumed 12-byte interval, backing resource and byte offset.
5. Read back the scene-color target after fence 3. The positive case checks
every pixel of the 4 by 2 RGBA8 target: left red, right green. No compositor
participates. Check the argument buffer's leading, trailing and neighboring
record guards, device-removal status and debug-layer errors too.

The positive oracle requires the same resource **and** offset, identical
12-byte records with X greater than zero, intact guards and all eight expected
pixels. Each negative control must fail that same oracle while satisfying its
own expected record and pixel results:

| Case | Post-write record at byte 4 | Pre-consume record | 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 |

The missing-copy destination is explicitly initialized with a null SRV. The
stale-copy case copies the original view at byte 32, then overwrites the source
to byte 16 without copying again. The wrong-SRV case copies a view still
pointing at byte 32. The wrong-argument case consumes a valid zero record in
the same resource, so a same-resource-only comparison would miss the error.
The Python driver also repeats the positive case with history tracing disabled
and requires the same argument and pixel results without history lines.

## Runtime diagnostic

Set `X2W_D3D12_DESCRIPTOR_HISTORY=1` **before process startup**. The setting is
cached. Output follows the usual trap logger, stderr unless `X2W_TRAP_LOG` is
set. It emits `x2w-descriptor-history` lines for intercepted view creation into
tracked shadow slots and intercepted descriptor copies:

| Field | Meaning |
|---|---|
| `seq` | CPU shadow-publication order, serialized by `note_lock`; not GPU execution order |
| `op` | `create` or `copy`; a create with a different `old`/`new` ID is an overwrite |
| `guest`, `desktop`, `source` | Destination guest address, destination desktop handle, and source guest address for a copy |
| `old`, `new` | Shadow IDs before and after publication; 0 means unknown, otherwise the view-record index plus 1 |
| `slot` | Recorded device view-creation slot, for example 18 for SRV |
| `resource`, `backing` | Recorded guest resource identity and its unwrapped desktop backing resource |
| `first`, `stride` | Buffer SRV `FirstElement` and `StructureByteStride`; raw SRV byte offset is `first * 4` |
| `materialized` | Whether the recorded view was materialized on the desktop |
| `guest_bytes`, `guest_read`, `guest_before` | Requested token sample size, successful complete read flag, and up to eight hexadecimal DWORDs **before this operation writes the guest token** |

SRV tokens occupy 32 bytes. Sampler tokens use the shorter sampler stride; the
remaining printed words are zero padding. Only a sample with `guest_read=1`
can be interpreted. Guest token word 1 is a zero-based view-record index,
whereas `old`/`new` use one-based IDs. Native desktop descriptor bytes are
opaque and are not read as guest tokens.

This diagnostic is intended for the fixture and short startup reproductions
only. It is not a complete-history capture for a real integration run:
initialization can exhaust its 8,192-event process budget, and each copied
descriptor counts as one event, so a large copy can consume the budget by
itself. It emits one `truncated limit=8192` line at that limit. Later producer
history needs a separately targeted diagnostic; no filter, delayed start or
rolling history is implemented here. With
`X2W_D3D12_VIEW_CONTENT_TOKENS=1`, parked view records are reused, so the same
`old`/`new` ID can refer to different views at different sequence points.
Arbitrary guest CPU stores or `memcpy` operations are not intercepted. View creations
without a tracked desktop shadow slot and view-record allocation failures do
not produce creation events. The sequence describes shadow updates; guest
token memory writes occur afterward and concurrently reused slots still
require the caller's synchronization.

This switch adds no GPU commands, barriers, readbacks or waits. The source-built
fixture supplies its own fenced GPU snapshots. When the switch is unset, it
does not sample guest memory or add the per-descriptor history loop. The
diagnostic changes neither descriptor-copy policy nor the rendering path.

The fixture prints `provenance debug info_queue=present` or
`info_queue=absent` for each process. Only a present `ID3D12InfoQueue` supports
the debug-message check; an absent queue leaves pixel/argument checks active
but provides no evidence that the debug layer reported no errors.

## Reproduce

Use the ordinary Windows build prerequisites in
[CONTRIBUTING.md](../../CONTRIBUTING.md#build-and-test), including DXC and Python.
Mesh requires a capable adapter/runtime. On an older Windows installation,
configure the existing `OFFSCREEN_AGILITY_620_DIR` option with a local directory
containing the public Agility 620 `D3D12Core.dll` and `d3d12SDKLayers.dll`.
Neither DLL is part of this contribution.

```powershell
. .\tools\dev.ps1
cmake --preset dev
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)$'

cmake --preset release
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)$'
```

To inspect the unfiltered diagnostic for one case:

```powershell
$env:X2W_D3D12_DESCRIPTOR_HISTORY = '1'
$env:X2W_MESH_PROVENANCE_CASE = 'positive'
.\out\build\dev\startup_indirect_draw_indexed.exe hardware mesh-provenance
```

`startup_mesh_argument_provenance_warp` is included in the PR smoke-test preset.
Capability skips return 77 and must be reported separately from passes.

## Local result and remaining integration work

Tested on 28 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. Build: this change on base
`32dc3d7c3cdc4be79afdad4cc04709e76d99a795`.

Debug and Release each ran the 23 selected tests: 21 passed, zero failed,
and two capability skips (`startup_indirect_mesh_warp` and
`startup_mesh_argument_provenance_warp`, Mesh shaders unavailable on local
WARP). The hardware provenance test runs six processes: the positive case,
four negative controls and the positive case without tracing. All had the
expected records, pixel readback and descriptor history, with no debug-layer
ERROR/CORRUPTION messages or device removal.

### Merge refresh verification, 30 November 2026

Retested the tree after merging main
`44a3ad5aa9c679cc039b8cb8275738dd6e4405d2` into PR head
`42a185536bfd5e9df81d786d55fceb48046f1b32`, using the same hardware,
driver, OS and toolchain above. The merge preserves both the provenance
fixture and main's native fixed-Mesh/MRT fixture, together with all current
PR smoke selections.

Debug and Release builds of the four targets in the reproduction commands
passed. In each configuration the 23-test group again produced 21 passes,
zero failures and the same two WARP Mesh capability skips. All six hardware
provenance processes reported `info_queue=present`; the pixel, argument,
history and debug-message checks passed without device removal.

The additional conflict-specific regression command was run in both presets:

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

Each selected four tests: two hardware passes, zero failures and two WARP
Mesh capability skips.

A local mutation changed the copy-history call in
`src/startup_stubs/d3d12_capture.inl` from
`trace_descriptor_history("copy", ...)` to
`trace_descriptor_history("create", ...)`. The Debug build succeeded and
the previously passing hardware provenance test failed its descriptor-copy
history assertion while the positive pixel check still observed 8/8 pixels.
The mutation was restored, the target rebuilt, and the hardware provenance
test passed again. No mutation is included in this change.

Documentation links, bidirectional-control checks, Python AST syntax, CMake
preset JSON, PR-regex selection and diff whitespace checks also passed.

### Remaining integration work

The producers use desktop source-built HLSL on a native command list. View
creation/copy and the indirect Mesh consumer use the guest wrappers; queue
execution and fences are native. This does not exercise a translated gfx1013
producer, guest queue preprocessing, XMem argument refresh, or the real
integration's root/attachment state.

Issue #3310 remains open until a matched integration run identifies the actual
scalar-input write and descriptor history, reads identical nonzero records at
the same resource and offset after production and before consumption, and
observes a real Mesh submission changing scene color before composition. The
issue's reported 48 zero records were not reproduced by this fixture. No
matched integration configuration or capture is included in this change.
The native integration work in
[#3091](https://github.com/R0Y00/Xbox2Windows/pull/3091) and
[#3094](https://github.com/R0Y00/Xbox2Windows/pull/3094) was still open when this
result was recorded; it has not been substituted for a test of `main`.
1 change: 1 addition & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,7 @@ ctest --preset dev --no-tests=error -R '^startup_hook_(window|overlap)$' -V
| `X2W_D3D12_RETIRE_REASONS=1` | diagnostic only, effective with `X2W_D3D12_RELEASE_RETIRED=1` and `X2W_D3D12_BUDGET=1`: adds one `x2w-retire held:` line to the heartbeat that counts final-released resources whose desktop object is still alive, by reason ([details](#d3d12-resource-budget)). Unset, nothing is recorded |
| `X2W_D3D12_VIEW_DEFAULTS=all` or `=off` | `all` is experimental: UAV, RTV and DSV descriptions with `ViewDimension` 0 also get the resource's default view, which drops their requested format and component mapping. `off` skips the measured SRV case too. Unset, only SRVs of typed non-depth textures get the default view ([details](#unknown-and-mismatched-view-dimensions)) |
| `X2W_D3D12_VIEW_CENSUS=1` | diagnostic only: counts new distinct view records by device slot (a heartbeat line), and logs the record vector capacity and hash bucket count before either grows ([details](#d3d12-view-census)). Unset, nothing is counted or logged |
| `X2W_D3D12_DESCRIPTOR_HISTORY=1` | fixture/short-startup diagnostic only: logs the first 8,192 descriptor events, then truncates; it cannot establish a complete later integration history. Records guest token bytes, shadow IDs and backing identities. IDs can be reused with `X2W_D3D12_VIEW_CONTENT_TOKENS=1`; CPU order is separate from GPU execution ([fixture, controls and limits](experiments/mesh-argument-provenance.md)) |
| `X2W_D3D12_VIEW_CONTENT_TOKENS=1` | opt-in: constant buffer views and buffer shader-resource views are written into title descriptor memory as tokens that carry the view itself instead of a record id, and their records are freed and reused once no shadow slot names them, so the record count stays bounded ([details](#d3d12-view-content-tokens)). Off under `X2W_D3D12_CAPTURE`. Unset, every view keeps an id token and records are never removed |
| `X2W_D3D12_TABLE_LOCK=1` | opt-in: the resource, slot 133 placement and descriptor heap tables get their own lock, so the four lookups that read only them stop queueing on the view-record lock behind view creation and descriptor copies ([details](#d3d12-table-lock)). Unset, they take that lock as before |
| `X2W_DRAW_NULL_IDENTITY=1` | null descriptors read as identity values instead of zero |
Expand Down
Loading
Loading