Skip to content

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

Open
Leyukaka wants to merge 4 commits into
R0Y00:mainfrom
Leyukaka:scene-pr-dump
Open

Leyukaka wants to merge 4 commits into
R0Y00:mainfrom
Leyukaka:scene-pr-dump

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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:

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.

X2W_D3D12_WRITE_TRACE selects one sampled resource of a translated draw
(by key and SRV slot). Draws, dispatches, copies, clears and discards that
write the selected resource are logged with their operation and outcome,
including writers recorded in the previous frame. The trace is off unless
the variable is set.
X2W_D3D12_DRAW_DUMP=<frame>:<key>[,<key>...] copies the render targets of
the selected translated draws before and after the draw, plus their bound
SRVs, and writes them next to X2W_TRAP_LOG once the submit fence completes.
The files are written outside the submit lock. Copies are scheduled only for
the configured frame and keys, within a fixed total budget.
Each selected draw now logs one kind=state line with its desktop draw
arguments, topology, index buffer, viewports and scissors, 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.
Targets now draw on their own three quarters of a key's budget, ahead
of sampled views, which are limited to four subresources each, so a
large sampled array can no longer starve a later target copy.

The dump test imports struct, checks that the writer's before and
after copies differ and checks the state line of each selected draw.

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

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.

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.

2 participants