d3d12_xs: strip buffer-only read states from texture barriers and initial states #18

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

@⁠QuentinDanblon on GitHub · 2026-11-21 17:30 UTC · original
QuentinDanblon:fix/texture-barrier-buffer-states → main · +192 −42 · 5 files · 2 commits · closed without merging

Library / area: d3d12_xs (resource barriers, resource creation states)

Exports changed (exports.txt rows): none

Source of the behaviour: PC D3D12 accepts VERTEX_AND_CONSTANT_BUFFER (0x1) and INDEX_BUFFER (0x2) only on buffers. Ported from brcly/TomBox (crates declare MIT OR Apache-2.0), GDAgent: dde663f and barriers.rs.

Xbox titles transition textures with the 0x3 bits set (render-target reads 0x8c3, GENERIC_READ 0xac3) and also pass them as creation states. On PC, command-list Close fails and the device is removed. At 226938c, xone_barrier::sanitize only stripped 0x400000 and turned aliasing barriers into UAV barriers. The graphics path (cmdlist_x.rs resource_barrier_x) and CreateCommittedResource / CreatePlacedResource / CreatePlacedResourceX passed the bits through. The copy queue was already safe (dma_list.rs copy_legal_barriers).

Changes:

  • xone_barrier.rs: a pure rewrite() drops 0x3 from both states of a transition on a non-buffer resource (GetDesc slot 10, same ABI as cl_ext.rs/present.rs). It removes transitions that the rewrite collapses to before == after. It keeps the title's own no-op transitions, split flags, subresource, opaque barrier bytes and order. It allocates only on the first change.
  • resource_barrier_x and the cmdlist_validate replay use the rewritten (possibly shorter) count. An empty batch is not forwarded.
  • Creation paths use initial_state(dim, s), so gpu_va, placed (upload.rs barriers) and rtcap track the same PC-legal state.
  • Separate commit: declare COND_POOL_TEST. cargo test -p d3d12_xs --lib did not compile at 226938c (E0425 in gpu_wait.rs:666,720).

Tests: cargo test -p d3d12_xs xone_barrier: 6 passed. They cover a mixed batch (order, flags, collapse, opaque bytes, input untouched), a fully collapsed batch, a clean batch left untouched, aliasing, and the 0x400000 strip. Full cargo test -p d3d12_xs: lib 237 passed, 6 ignored (hw); process_debug_off/on passed. Not run against a title; I don't have one.

Build note: a fresh checkout of 226938c does not build d3d12_xs. compat-common/backend_data/* is not in the repo, and query_accum.dxil needs TOMBOX_DXC_DIR. I built with local placeholders, which are not committed.

  • cargo test -p d3d12_xs passes
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
**@⁠QuentinDanblon** on GitHub · 2026-11-21 17:30 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/18) `QuentinDanblon:fix/texture-barrier-buffer-states` → `main` · +192 −42 · 5 files · 2 commits · closed without merging **Library / area:** d3d12_xs (resource barriers, resource creation states) **Exports changed (exports.txt rows):** none **Source of the behaviour:** PC D3D12 accepts VERTEX_AND_CONSTANT_BUFFER (0x1) and INDEX_BUFFER (0x2) only on buffers. Ported from brcly/TomBox (crates declare MIT OR Apache-2.0), GDAgent: [dde663f](https://github.com/brcly/TomBox/commit/dde663f25bc650edfe062c7752628fcf17895d06) and [barriers.rs](https://github.com/brcly/TomBox/blob/master/crates/compat/d3d12_xs/src/barriers.rs). Xbox titles transition textures with the 0x3 bits set (render-target reads 0x8c3, GENERIC_READ 0xac3) and also pass them as creation states. On PC, command-list Close fails and the device is removed. At 226938c, `xone_barrier::sanitize` only stripped 0x400000 and turned aliasing barriers into UAV barriers. The graphics path (`cmdlist_x.rs` `resource_barrier_x`) and `CreateCommittedResource` / `CreatePlacedResource` / `CreatePlacedResourceX` passed the bits through. The copy queue was already safe (`dma_list.rs` `copy_legal_barriers`). Changes: - `xone_barrier.rs`: a pure `rewrite()` drops 0x3 from both states of a transition on a non-buffer resource (`GetDesc` slot 10, same ABI as `cl_ext.rs`/`present.rs`). It removes transitions that the rewrite collapses to before == after. It keeps the title's own no-op transitions, split flags, subresource, opaque barrier bytes and order. It allocates only on the first change. - `resource_barrier_x` and the `cmdlist_validate` replay use the rewritten (possibly shorter) count. An empty batch is not forwarded. - Creation paths use `initial_state(dim, s)`, so `gpu_va`, `placed` (upload.rs barriers) and `rtcap` track the same PC-legal state. - Separate commit: declare `COND_POOL_TEST`. `cargo test -p d3d12_xs --lib` did not compile at 226938c (E0425 in gpu_wait.rs:666,720). Tests: `cargo test -p d3d12_xs xone_barrier`: 6 passed. They cover a mixed batch (order, flags, collapse, opaque bytes, input untouched), a fully collapsed batch, a clean batch left untouched, aliasing, and the 0x400000 strip. Full `cargo test -p d3d12_xs`: lib 237 passed, 6 ignored (hw); process_debug_off/on passed. Not run against a title; I don't have one. Build note: a fresh checkout of 226938c does not build d3d12_xs. `compat-common/backend_data/*` is not in the repo, and `query_accum.dxil` needs `TOMBOX_DXC_DIR`. I built with local placeholders, which are not committed. - [x] `cargo test -p d3d12_xs` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
The two condition-fence pool tests referenced a test lock that was never
declared, so `cargo test -p d3d12_xs --lib` did not compile at 226938c.
Xbox titles transition textures with VERTEX_AND_CONSTANT_BUFFER | INDEX_BUFFER
(0x3) set, e.g. 0x8c3 render-target read states and GENERIC_READ 0xac3, and
also pass them as creation states. PC D3D12 accepts those bits only for
buffers: command-list Close fails and the device is removed on execute.

xone_barrier::sanitize now rewrites a batch through a pure rewrite() helper:
for a transition whose resource is not a buffer (ID3D12Resource::GetDesc,
slot 10, Dimension != BUFFER) the 0x3 bits are dropped from both states. A
transition that our rewrite collapses to before == after (also possible via
the existing 0x400000 strip) is removed; the title's own no-op transitions,
split-barrier flags, subresource, opaque barrier bytes and batch order are
kept. The output is allocated only on the first change. resource_barrier_x
and the cmdlist_validate replay pass the possibly shorter count; an emptied
batch is not forwarded.

CreateCommittedResource, CreatePlacedResource and CreatePlacedResourceX pass
a texture-safe initial state, and that same state is what gpu_va, placed
(upload.rs barriers on a real PC list) and rtcap record.

Ported from brcly/TomBox (MIT OR Apache-2.0), GDAgent team:
dde663f25b
and the later batch translation in
https://github.com/brcly/TomBox/blob/master/crates/compat/d3d12_xs/src/barriers.rs
adapted to this crate's byte-level barrier sanitiser.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:22 +00:00
github-bot closed this pull request 2026-11-26 06:07:22 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 21:03 UTC · original

Merged in the source sync 1159c96 (adapted). Thanks! Closing.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/18#issuecomment-7069201330) Merged in the source sync 1159c96 (adapted). Thanks! Closing.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.