victory-gpu: leave host copies of title memory in the common state (debug layer: 704 + 37 state errors -> 0) #2660

Closed
github-bot wants to merge 2 commits from gh-pr/2660/head into gh-pr/2660/base
Owner

@⁠pes7 on GitHub · 2026-11-25 17:42 UTC · original
pes7:perf/buffer-states → main · +27 −38 · 3 files · 2 commits · closed without merging

The first world frames move a host copy of title memory into a state it is never in, and leave it there. The debug layer says so about 40 times a minute.

A host copy of title memory (crate::shadow) is made in D3D12_RESOURCE_STATE_COMMON and normally never moved: every use a copy has - unordered access, vertex and index buffers, indirect arguments, constant data - is served by the host's implicit promotion out of the common state. One place did move one: the indirect clamp.

l.ResourceBarrier(&[uav_barrier(),
    transition(buffer, UNORDERED_ACCESS, INDIRECT_ARGUMENT)]);
...
l.ResourceBarrier(&[transition(buffer, INDIRECT_ARGUMENT, UNORDERED_ACCESS)]);

Those are the only transitions of a buffer in the crate, and both name a state the copy was not in. The title's own argument passes write the arguments through a descriptor, with no transition of ours, so the copy is still common when the first barrier claims it was in unordered access:

ID3D12CommandList::ResourceBarrier: Before state (0x8: D3D12_RESOURCE_STATE_UNORDERED_ACCESS) of
resource ... does not match with the state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) specified in
preceding ResourceBarrier or as InitialState

and the second barrier leaves the copy in unordered access for good, so the next draw that binds the same memory as a vertex buffer is invalid:

Using IASetVertexBuffers: Resource state (0x8: UNORDERED_ACCESS) ... is invalid for use as a vertex
buffer. Expected State Bits (all): 0x1: VERTEX_AND_CONSTANT_BUFFER

The same memory is read as arguments and then as vertices in these frames, which is why the two go together.

Measured with the debug layer on the title (diagnostics build, VICTORY_D3D12_DEBUG=1, warm caches), counting its messages:

debug layer message before after
id=527, "Before state ... does not match" 704 0
id=538, vertex buffer in unordered access 37 0
the rest (pipeline library misses, one sampler-heap note) 861 332

The run after the change went further than the one before it - it reached the world frames, 5-20 fps, instead of stopping in the menu - and still had no state mismatch of either kind.

What stays is the UAV barrier, which is the ordering the clamp needs (it must read what the title's argument passes wrote). The transitions go, and so does done(): there is nothing to put back.

cargo test --workspace --locked, both clippy configurations with -D warnings, cargo xtask policy.

**@⁠pes7** on GitHub · 2026-11-25 17:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2660) `pes7:perf/buffer-states` → `main` · +27 −38 · 3 files · 2 commits · closed without merging The first world frames move a host copy of title memory into a state it is never in, and leave it there. The debug layer says so about 40 times a minute. A host copy of title memory (`crate::shadow`) is made in `D3D12_RESOURCE_STATE_COMMON` and normally never moved: every use a copy has - unordered access, vertex and index buffers, indirect arguments, constant data - is served by the host's implicit promotion out of the common state. One place did move one: the indirect clamp. l.ResourceBarrier(&[uav_barrier(), transition(buffer, UNORDERED_ACCESS, INDIRECT_ARGUMENT)]); ... l.ResourceBarrier(&[transition(buffer, INDIRECT_ARGUMENT, UNORDERED_ACCESS)]); Those are the only transitions of a buffer in the crate, and both name a state the copy was not in. The title's own argument passes write the arguments through a descriptor, with no transition of ours, so the copy is still common when the first barrier claims it was in unordered access: ID3D12CommandList::ResourceBarrier: Before state (0x8: D3D12_RESOURCE_STATE_UNORDERED_ACCESS) of resource ... does not match with the state (0x0: D3D12_RESOURCE_STATE_[COMMON|PRESENT]) specified in preceding ResourceBarrier or as InitialState and the second barrier leaves the copy in unordered access for good, so the next draw that binds the same memory as a vertex buffer is invalid: Using IASetVertexBuffers: Resource state (0x8: UNORDERED_ACCESS) ... is invalid for use as a vertex buffer. Expected State Bits (all): 0x1: VERTEX_AND_CONSTANT_BUFFER The same memory is read as arguments and then as vertices in these frames, which is why the two go together. Measured with the debug layer on the title (diagnostics build, `VICTORY_D3D12_DEBUG=1`, warm caches), counting its messages: | debug layer message | before | after | |---|---:|---:| | id=527, "Before state ... does not match" | 704 | **0** | | id=538, vertex buffer in unordered access | 37 | **0** | | the rest (pipeline library misses, one sampler-heap note) | 861 | 332 | The run after the change went further than the one before it - it reached the world frames, 5-20 fps, instead of stopping in the menu - and still had no state mismatch of either kind. What stays is the UAV barrier, which is the ordering the clamp needs (it must read what the title's argument passes wrote). The transitions go, and so does `done()`: there is nothing to put back. `cargo test --workspace --locked`, both clippy configurations with `-D warnings`, `cargo xtask policy`.
The title asks for 1 245 184 descriptor slots, more than the 1 000 000 a host
heap holds, and it walks them in increasing order. "Log when the high-water
mark moves" is therefore one line per distinct slot: 199 846 of the first
200 000 lines of a run, ~8 000 a second, on the thread recording the frame.

That was the whole of the first frame's stall:

    before   310 932 lines in the run, first frame 21 433 ms
    after        231 lines in the run, first frame     33 ms

Same build, same warm caches (926 MB pipeline library, 1 347 MB shader cache),
same 150 s window. What the line said - that slots above the host heap's count
are not mirrored - is what the one line now says.

The underlying problem is not this change: 245 184 title slots can never be
mirrored because they exceed the tier-2 heap limit, which needs either several
host heaps with the index arithmetic adjusted or the views above 1 M placed
elsewhere. That is why the first world frames get null views.

cargo test --workspace --locked; both clippy configurations with -D warnings;
cargo xtask policy.
A host copy of title memory (crate::shadow) is made in the common resource
state and normally never moved: unordered access, vertex and index
buffers, indirect arguments and constant data all come from the host's
implicit promotion out of that state. The indirect clamp was the one place
that moved one, and it moved it to a state it was never in:

    l.ResourceBarrier(&[uav_barrier(),
        transition(buffer, UNORDERED_ACCESS, INDIRECT_ARGUMENT)]);
    ...
    l.ResourceBarrier(&[transition(buffer, INDIRECT_ARGUMENT, UNORDERED_ACCESS)]);

The title writes the arguments it hands over through a descriptor, with no
transition of ours, so the copy is still common when the first barrier
claims it was in unordered access (the debug layer's "Before state
(UNORDERED_ACCESS) ... does not match with the state (COMMON)"), and the
pair's second half left it in unordered access for good, where the next
draw that binds the same memory as a vertex buffer is invalid ("state is
invalid for use as a vertex buffer", ~40 a minute in the first world
frames).

The debug layer, on the title, diagnostics build with VICTORY_D3D12_DEBUG,
warm caches:

    id=527 "Before state ... does not match"          704 -> 0
    id=538 vertex buffer in unordered access           37 -> 0

and the run after the change went further than the one before it (it
reached the world frames instead of stopping in the menu) with no state
mismatch of either kind.

The UAV barrier stays: it is the ordering the clamp needs, and it is what
the clamp's tests check. cargo test --workspace --locked; both clippy
configurations with -D warnings; cargo xtask policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:26 +00:00
github-bot closed this pull request 2026-11-26 05:11:26 +00:00
Author
Owner

@⁠pes7 on GitHub · 2026-11-25 17:43 UTC · original

Superseded by 315cea1 on main ("barriers start from the states resources are in: prelude order, the clamp's own buffer"), which fixes the same thing better: the clamp no longer writes the copy of the title's memory at all - it reads the title's records through a root view and writes the clamped ones into an argument buffer of the list's own, and only that one is transitioned. Title buffers' copies are then never transitioned, which is what this PR's one change (dropping the clamp's transitions and done) set out to do.

For the record, the debug-layer counts I measured on the way, since they agree with the ones in that commit: on the title with VICTORY_D3D12_DEBUG=1 and warm caches, main before any of this reported id=527 ("Before state ... does not match") 704 times and id=538 (vertex buffer in UNORDERED_ACCESS) 37 times; with only the clamp's transitions dropped they were 0 and 0, in a run that went further (it reached the world frames instead of stopping in the menu).

Closing rather than rebasing: main's version is strictly better, and tests for it are in that commit.

**@⁠pes7** on GitHub · 2026-11-25 17:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2660#issuecomment-7169912045) Superseded by `315cea1` on main ("barriers start from the states resources are in: prelude order, the clamp's own buffer"), which fixes the same thing better: the clamp no longer writes the copy of the title's memory at all - it reads the title's records through a root view and writes the clamped ones into an argument buffer of the list's own, and only that one is transitioned. Title buffers' copies are then never transitioned, which is what this PR's one change (dropping the clamp's transitions and `done`) set out to do. For the record, the debug-layer counts I measured on the way, since they agree with the ones in that commit: on the title with `VICTORY_D3D12_DEBUG=1` and warm caches, `main` before any of this reported id=527 ("Before state ... does not match") 704 times and id=538 (vertex buffer in UNORDERED_ACCESS) 37 times; with only the clamp's transitions dropped they were 0 and 0, in a run that went further (it reached the world frames instead of stopping in the menu). Closing rather than rebasing: main's version is strictly better, and tests for it are in that commit.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2660
No description provided.