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

Closed
pes7 wants to merge 2 commits from upstream-pr/2660 into main
pes7 commented 2026-11-25 17:42:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T17:42:53Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6610258655 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2660). Originally posted by [pes7](https://github.com/pes7) on 2026-11-25T17:42:53Z. --- 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`.
upstream-sync closed this pull request 2026-11-25 18:02:31 +00:00
pes7 commented 2026-11-25 18:02:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T17:43:35Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169912045 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2660#issuecomment-7169912045). Originally posted by [pes7](https://github.com/pes7) on 2026-11-25T17:43:35Z. --- 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

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
Marvisak/VIctory!2658
No description provided.