runtime: add an opt-in resource write trace and a targeted draw dump #3820

Open
Leyukaka wants to merge 4 commits from upstream-pr/3820 into main
Leyukaka commented 2026-12-02 03:12:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T03:12:42Z.


Problem

When a translated draw samples a resource with unexpected content, or leaves its targets unchanged, the existing diagnostics do not answer two questions directly:

  • which draws, dispatches, copies, clears or discards wrote the resource that this pipeline samples, and with what outcome;
  • what the render targets, the depth target and the sampled inputs of that one draw contained before and after it, and with which state the draw was submitted.

Today, answering them means adding temporary logging around the draw path each time.

Change

Diagnostics only. Each part is off unless its environment variable is set. When the variables are unset, nothing is traced and no copy is scheduled.

runtime: trace writes to a selected D3D12 resource (d3d12_write_trace.inl)

  • X2W_D3D12_WRITE_TRACE=srv-of:<hex pipeline key>:<SRV index> selects the resource that the given translated pipeline samples at that SRV slot. A plain hex address selects by address instead.
  • Operations that write the selected resource are logged as x2w-write-trace lines with the operation, its outcome and the frame: translated draws, compute dispatches, buffer and texture copies, clears and discards. Writers recorded in the frame before the sampling draw are included.
  • X2W_D3D12_WRITE_TRACE_DRAWS=<n> limits the number of matching draws (default 16, maximum 32). X2W_D3D12_WRITE_TRACE_COMPOSITE=<key>:<index> restricts an address filter to one draw.

runtime: dump selected draw targets at one frame (d3d12_targeted_dump.inl)

  • X2W_D3D12_DRAW_DUMP=<frame>:<key>[,<key>...] copies the render targets of the selected translated draws before and after each draw, plus their bound SRVs, in one recording frame.
  • The files are written next to X2W_TRAP_LOG once the submit fence completes, outside the submit lock. Textures are DX10 DDS files. Buffer SRV ranges are raw files with a small header.
  • Copies are scheduled only for the configured frame and keys, within a total budget of 256 MiB divided among the keys.

runtime: log the submitted state of targeted dump draws

  • Each selected draw logs one kind=state line: draw arguments, topology, index buffer, viewports and scissors, the bound targets (and whether the dumped target is the bound one) and the fixed-function pipeline state the translated pipeline was built from.
  • The depth view is copied before and after the draw like the render targets. Depth formats with a stencil plane are logged and skipped.
  • Three quarters of a key's budget go to its targets, which are copied first. Sampled views get the rest, at most four subresources each, so a large sampled array cannot starve a target copy.

docs/startup-runtime.md gains rows for X2W_D3D12_DRAW_DUMP and the three X2W_D3D12_WRITE_TRACE* switches (syntax, what is logged, cost when off).

This PR is about 1600 lines. If a smaller review unit is preferred, I can split it into a tracer PR followed by a dump PR. The dump includes from the tracer, so it would land second.

Related open work:

  • #3818 touches d3d12_draw.inl and d3d12_xs_device.cpp for an unrelated depth-view behaviour. A textual rebase may be needed depending on which lands first.
  • #3772 and #3321 add descriptor-history and argument-provenance diagnostics, mainly in d3d12_capture.inl. They report which descriptor was bound; this PR reports who wrote a resource and what one draw saw. They share no environment variable or log prefix with this PR.

I found no open PR that adds a write trace or a per-draw target dump.

Validation

Windows, MSVC. GPU tests were run serially.

cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^(startup_resource_write_trace_(warp|hardware)|startup_targeted_draw_dump_(warp|hardware)|startup_stream_draw_(warp|hardware))$"

These tests pass on WARP and on a hardware adapter on this PR (the last commit only adds documentation rows).

tests/startup_resource_write_trace_check.py is new. It is registered as startup_resource_write_trace_<backend> and, in dump mode, as startup_targeted_draw_dump_<backend>. It renders a writer pipeline into a target that a reader pipeline then samples.

  • Trace: the two sampling draws are reported with the expected frame and resource, the writer is reported once in its own frame (also when it ran in the previous frame), and the rendered image is the same as without tracing.
  • Trace negative controls: no variable, a pipeline key that does not match, and an address that matches nothing each produce no trace lines.
  • Dump: 11 files, each with a checked DDS header and size. The writer's before copy equals the clear colour and differs from its after copy. The reader's SRV copy equals the writer's output, and its after copy equals the expected image. There are four kind=state lines with the fixture's draw arguments, viewport, scissor, target format and pipeline state, and no budget or cap status.
  • Dump negative control: with the variable unset there are no files and no x2w-targeted-dump line.
  • No D3D12 error in any run.

startup_stream_draw is in the filter because its harness gains the writer fixture. The fixture shaders are written for this test.

Checklist

  • Opt-in diagnostics only.
  • Negative controls are included for the new fixtures.
  • Docs rows for X2W_D3D12_DRAW_DUMP and the X2W_D3D12_WRITE_TRACE* switches are added.
  • No guest files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5599081139 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3820). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T03:12:42Z. --- ## Problem When a translated draw samples a resource with unexpected content, or leaves its targets unchanged, the existing diagnostics do not answer two questions directly: - which draws, dispatches, copies, clears or discards wrote the resource that this pipeline samples, and with what outcome; - what the render targets, the depth target and the sampled inputs of that one draw contained before and after it, and with which state the draw was submitted. Today, answering them means adding temporary logging around the draw path each time. ## Change Diagnostics only. Each part is off unless its environment variable is set. When the variables are unset, nothing is traced and no copy is scheduled. **`runtime: trace writes to a selected D3D12 resource`** (`d3d12_write_trace.inl`) - `X2W_D3D12_WRITE_TRACE=srv-of:<hex pipeline key>:<SRV index>` selects the resource that the given translated pipeline samples at that SRV slot. A plain hex address selects by address instead. - Operations that write the selected resource are logged as `x2w-write-trace` lines with the operation, its outcome and the frame: translated draws, compute dispatches, buffer and texture copies, clears and discards. Writers recorded in the frame before the sampling draw are included. - `X2W_D3D12_WRITE_TRACE_DRAWS=<n>` limits the number of matching draws (default 16, maximum 32). `X2W_D3D12_WRITE_TRACE_COMPOSITE=<key>:<index>` restricts an address filter to one draw. **`runtime: dump selected draw targets at one frame`** (`d3d12_targeted_dump.inl`) - `X2W_D3D12_DRAW_DUMP=<frame>:<key>[,<key>...]` copies the render targets of the selected translated draws before and after each draw, plus their bound SRVs, in one recording frame. - The files are written next to `X2W_TRAP_LOG` once the submit fence completes, outside the submit lock. Textures are DX10 DDS files. Buffer SRV ranges are raw files with a small header. - Copies are scheduled only for the configured frame and keys, within a total budget of 256 MiB divided among the keys. **`runtime: log the submitted state of targeted dump draws`** - Each selected draw logs one `kind=state` line: draw arguments, topology, index buffer, viewports and scissors, the bound targets (and whether the dumped target is the bound one) and the fixed-function pipeline state the translated pipeline was built from. - The depth view is copied before and after the draw like the render targets. Depth formats with a stencil plane are logged and skipped. - Three quarters of a key's budget go to its targets, which are copied first. Sampled views get the rest, at most four subresources each, so a large sampled array cannot starve a target copy. `docs/startup-runtime.md` gains rows for `X2W_D3D12_DRAW_DUMP` and the three `X2W_D3D12_WRITE_TRACE*` switches (syntax, what is logged, cost when off). This PR is about 1600 lines. If a smaller review unit is preferred, I can split it into a tracer PR followed by a dump PR. The dump includes from the tracer, so it would land second. Related open work: - #3818 touches `d3d12_draw.inl` and `d3d12_xs_device.cpp` for an unrelated depth-view behaviour. A textual rebase may be needed depending on which lands first. - #3772 and #3321 add descriptor-history and argument-provenance diagnostics, mainly in `d3d12_capture.inl`. They report which descriptor was bound; this PR reports who wrote a resource and what one draw saw. They share no environment variable or log prefix with this PR. I found no open PR that adds a write trace or a per-draw target dump. ## Validation Windows, MSVC. GPU tests were run serially. ``` cmake --build --preset dev ctest --preset dev --no-tests=error -R "^(startup_resource_write_trace_(warp|hardware)|startup_targeted_draw_dump_(warp|hardware)|startup_stream_draw_(warp|hardware))$" ``` These tests pass on WARP and on a hardware adapter on this PR (the last commit only adds documentation rows). `tests/startup_resource_write_trace_check.py` is new. It is registered as `startup_resource_write_trace_<backend>` and, in `dump` mode, as `startup_targeted_draw_dump_<backend>`. It renders a writer pipeline into a target that a reader pipeline then samples. - Trace: the two sampling draws are reported with the expected frame and resource, the writer is reported once in its own frame (also when it ran in the previous frame), and the rendered image is the same as without tracing. - Trace negative controls: no variable, a pipeline key that does not match, and an address that matches nothing each produce no trace lines. - Dump: 11 files, each with a checked DDS header and size. The writer's before copy equals the clear colour and differs from its after copy. The reader's SRV copy equals the writer's output, and its after copy equals the expected image. There are four `kind=state` lines with the fixture's draw arguments, viewport, scissor, target format and pipeline state, and no budget or cap status. - Dump negative control: with the variable unset there are no files and no `x2w-targeted-dump` line. - No D3D12 error in any run. `startup_stream_draw` is in the filter because its harness gains the writer fixture. The fixture shaders are written for this test. ## Checklist - [x] Opt-in diagnostics only. - [x] Negative controls are included for the new fixtures. - [x] Docs rows for `X2W_D3D12_DRAW_DUMP` and the `X2W_D3D12_WRITE_TRACE*` switches are added. - [x] No guest files, dumps, distribution links or secrets.
R0Y00 commented 2026-12-02 05:30:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:30:30Z.

Review: COMMENTED


Please take the split you proposed. Put resource writer tracing and its output-equivalence/negative controls in the first PR. Stack targeted before/after capture and draw-state logging on top, with its fence, file output and budget controls. That gives the tracer a review path independent of the new GPU copy and readback lifetime. Please keep the corresponding WARP/hardware commands and adapter receipts on each PR.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145275020 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3820#pullrequestreview-6145275020). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:30:30Z. **Review:** COMMENTED --- Please take the split you proposed. Put resource writer tracing and its output-equivalence/negative controls in the first PR. Stack targeted before/after capture and draw-state logging on top, with its fence, file output and budget controls. That gives the tracer a review path independent of the new GPU copy and readback lifetime. Please keep the corresponding WARP/hardware commands and adapter receipts on each PR.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3820:upstream-pr/3820'
git switch 'upstream-pr/3820'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3820'
git switch 'upstream-pr/3820'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3820'
git switch 'upstream-pr/3820'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3820'
git switch 'main'
git merge --squash 'upstream-pr/3820'
git switch 'main'
git merge --ff-only 'upstream-pr/3820'
git switch 'main'
git merge 'upstream-pr/3820'
git push origin 'main'
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
R0Y00/Xbox2Windows!3820
No description provided.