Repository navigation
Conversation
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
reviewed
Dec 2, 2026
R0Y00
left a comment
Owner
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.x2w-write-tracelines 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.X2W_TRAP_LOGonce the submit fence completes, outside the submit lock. Textures are DX10 DDS files. Buffer SRV ranges are raw files with a small header.runtime: log the submitted state of targeted dump drawskind=stateline: 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.docs/startup-runtime.mdgains rows forX2W_D3D12_DRAW_DUMPand the threeX2W_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:
d3d12_draw.inlandd3d12_xs_device.cppfor an unrelated depth-view behaviour. A textual rebase may be needed depending on which lands first.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.
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.pyis new. It is registered asstartup_resource_write_trace_<backend>and, indumpmode, asstartup_targeted_draw_dump_<backend>. It renders a writer pipeline into a target that a reader pipeline then samples.kind=statelines with the fixture's draw arguments, viewport, scissor, target format and pipeline state, and no budget or cap status.x2w-targeted-dumpline.startup_stream_drawis in the filter because its harness gains the writer fixture. The fixture shaders are written for this test.Checklist
X2W_D3D12_DRAW_DUMPand theX2W_D3D12_WRITE_TRACE*switches are added.