gpu: allow live aliased indices with un-sliced placed vertex streams #2826

Merged
Holastor merged 1 commit from upstream-pr/2834 into main 2026-11-26 12:49:25 +00:00
Holastor commented 2026-11-26 12:43:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T12:43:07Z.


Summary

Fixes #2714.

Upstream PR #2724 enabled live_indices for direct indexed draws (list_draw_indexed / slot 13) when the index buffer was an aliased placed buffer, but explicitly restricted draws to those with no vertex streams:
std::none_of(tr->srvs.begin(), tr->srvs.end(), [](const Translation::Srv& srv) { return srv.source == 1; })

Because of this restriction, any draw referencing vertex streams from pass.vb fell back to snapshotting indices into upload ring memory at recording time (frame_copy) and slicing the stream via an index scan [low, high], ignoring pre-submission CPU writes to the index buffer.

This change:

  1. Replaces the blanket vertex stream check with stream_needs_slicing, which checks whether each referenced vertex stream requires upload ring slicing (unplaced, unaligned, or null placed alias).
  2. When all referenced vertex streams are aligned placed buffers (placed.alias != nullptr), live_indices is retained, vertex_first stays 0 (no slicing), and the root constant base_vertex is unbiased (base_vertex - 0).
  3. Retains placed vertex buffer alias resources alongside the recording using retain_with_recording.
  4. Extends tests/startup_direct_index_late_write_check.py and tests/startup_stream_draw.cpp with placed vertex stream test cases (visible-vb, clipped-vb, late-visible-vb, late-clipped-vb) and an unplaced negative control (late-visible-vb-unplaced) verifying that unplaced buffers correctly fall back to recording-time snapshots and index slicing.

Evidence

  • Commit under test: a859da17

  • Environment:

    • Windows 11 x64 (Build 26100)
    • Hardware adapter: AMD Radeon RX 6600M (driver 32.0.21045.11001, debug layer enabled)
    • Software backend: Microsoft Basic Render Driver / WARP (driver 10.0.26100.10068, debug layer enabled)
  • Test commands and results:

ctest --preset dev -R "^startup_direct_index_late_write" -V
1322: visible: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: clipped: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: late-visible: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: late-clipped: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: late-visible-r32: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: visible-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: clipped-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: late-visible-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: late-clipped-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1322: late-visible-vb-unplaced: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled
1/2 Test #1322: startup_direct_index_late_write_warp .......   Passed    1.36 sec

1366: visible: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: clipped: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: late-visible: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: late-clipped: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: late-visible-r32: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: visible-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: clipped-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: late-visible-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: late-clipped-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
1366: late-visible-vb-unplaced: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled
2/2 Test #1366: startup_direct_index_late_write_hardware ...   Passed    2.27 sec

100% tests passed, 0 tests failed out of 2
  • Regression check:
ctest --preset dev -R "^startup_(direct_index_late_write|stream_draw|placed_vertex|address_srv)" -V

All 8 tests passed across WARP and hardware backends.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6626892241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2834). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-26T12:43:07Z. --- ### Summary Fixes #2714. Upstream PR #2724 enabled `live_indices` for direct indexed draws (`list_draw_indexed` / slot 13) when the index buffer was an aliased placed buffer, but explicitly restricted draws to those with no vertex streams: `std::none_of(tr->srvs.begin(), tr->srvs.end(), [](const Translation::Srv& srv) { return srv.source == 1; })` Because of this restriction, any draw referencing vertex streams from `pass.vb` fell back to snapshotting indices into upload ring memory at recording time (`frame_copy`) and slicing the stream via an index scan `[low, high]`, ignoring pre-submission CPU writes to the index buffer. This change: 1. Replaces the blanket vertex stream check with `stream_needs_slicing`, which checks whether each referenced vertex stream requires upload ring slicing (unplaced, unaligned, or null placed alias). 2. When all referenced vertex streams are aligned placed buffers (`placed.alias != nullptr`), `live_indices` is retained, `vertex_first` stays 0 (no slicing), and the root constant `base_vertex` is unbiased (`base_vertex - 0`). 3. Retains placed vertex buffer alias resources alongside the recording using `retain_with_recording`. 4. Extends `tests/startup_direct_index_late_write_check.py` and `tests/startup_stream_draw.cpp` with placed vertex stream test cases (`visible-vb`, `clipped-vb`, `late-visible-vb`, `late-clipped-vb`) and an unplaced negative control (`late-visible-vb-unplaced`) verifying that unplaced buffers correctly fall back to recording-time snapshots and index slicing. ### Evidence - **Commit under test**: `a859da17` - **Environment**: - Windows 11 x64 (Build 26100) - Hardware adapter: AMD Radeon RX 6600M (driver 32.0.21045.11001, debug layer enabled) - Software backend: Microsoft Basic Render Driver / WARP (driver 10.0.26100.10068, debug layer enabled) - **Test commands and results**: ```powershell ctest --preset dev -R "^startup_direct_index_late_write" -V ``` ``` 1322: visible: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: clipped: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: late-visible: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: late-clipped: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: late-visible-r32: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: visible-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: clipped-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: late-visible-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: late-clipped-vb: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1322: late-visible-vb-unplaced: 32 exact pixels, adapter=Microsoft Basic Render Driver driver=10.0.26100.10068, debug layer enabled 1/2 Test #1322: startup_direct_index_late_write_warp ....... Passed 1.36 sec 1366: visible: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: clipped: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: late-visible: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: late-clipped: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: late-visible-r32: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: visible-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: clipped-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: late-visible-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: late-clipped-vb: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 1366: late-visible-vb-unplaced: 32 exact pixels, adapter=AMD Radeon RX 6600M driver=32.0.21045.11001, debug layer enabled 2/2 Test #1366: startup_direct_index_late_write_hardware ... Passed 2.27 sec 100% tests passed, 0 tests failed out of 2 ``` - **Regression check**: ```powershell ctest --preset dev -R "^startup_(direct_index_late_write|stream_draw|placed_vertex|address_srv)" -V ``` All 8 tests passed across WARP and hardware backends.
upstream-sync closed this pull request 2026-11-26 13:03:08 +00:00
tedin7 commented 2026-11-26 13:03:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T12:47:20Z.

Review: COMMENTED


Review of head a859da17 against current main (comment review, no approval).

What I checked

  • stream_needs_slicing in src/startup_stubs/d3d12_draw.inl keeps live indices only when every referenced vertex stream is a live, aligned, non-rejected placed alias. Anything else (unplaced, null alias, bad alignment, size not a multiple of 4, bad slot) still takes the recording-time snapshot and index scan path. Empty streams (SizeInBytes == 0) do not force slicing, which is fine.
  • With live indices, vertex_first and vertex_count stay 0, so no stream is sliced, and the root constant is base_vertex - 0. DrawIndexedInstanced is called with base 0 and the index offset is baked into the live view, so the shader sees index + base_vertex exactly as before. Consistent.
  • Each placed vertex alias is retained with the recording, so it cannot be released before submission.
  • Tests: startup_direct_index_late_write_check.py and startup_stream_draw.cpp add placed-stream cases (visible-vb, clipped-vb, late-visible-vb, late-clipped-vb) and an unplaced negative control (late-visible-vb-unplaced). The alias-count assertion distinguishes placed from unplaced. Existing direct-index cases are kept.
  • Reasoned mutation (not executed, this needs a Windows build): restoring the old source == 1 blanket check sends the vb cases back to the snapshot path, so late-visible-vb would read the stale index and fail the pixel check.
  • No other open or merged PR covers this slice (searched by key words); it follows #2724 and fixes #2714.
  • This PR cites only fixture results. It does not claim any game result, so no game verification is needed.

Commands run locally

  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: ok
  • python3 tests/bidi_controls_check.py: ok
  • python3 -m py_compile tests/startup_direct_index_late_write_check.py: ok

Next: Win2025 WARP dev + release run on this head; I will post the receipt.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6074371425 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2834#pullrequestreview-6074371425). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T12:47:20Z. **Review:** COMMENTED --- Review of head a859da17 against current main (comment review, no approval). What I checked - `stream_needs_slicing` in `src/startup_stubs/d3d12_draw.inl` keeps live indices only when every referenced vertex stream is a live, aligned, non-rejected placed alias. Anything else (unplaced, null alias, bad alignment, size not a multiple of 4, bad slot) still takes the recording-time snapshot and index scan path. Empty streams (`SizeInBytes == 0`) do not force slicing, which is fine. - With live indices, `vertex_first` and `vertex_count` stay 0, so no stream is sliced, and the root constant is `base_vertex - 0`. `DrawIndexedInstanced` is called with base 0 and the index offset is baked into the live view, so the shader sees `index + base_vertex` exactly as before. Consistent. - Each placed vertex alias is retained with the recording, so it cannot be released before submission. - Tests: `startup_direct_index_late_write_check.py` and `startup_stream_draw.cpp` add placed-stream cases (`visible-vb`, `clipped-vb`, `late-visible-vb`, `late-clipped-vb`) and an unplaced negative control (`late-visible-vb-unplaced`). The alias-count assertion distinguishes placed from unplaced. Existing direct-index cases are kept. - Reasoned mutation (not executed, this needs a Windows build): restoring the old `source == 1` blanket check sends the vb cases back to the snapshot path, so `late-visible-vb` would read the stale index and fail the pixel check. - No other open or merged PR covers this slice (searched by key words); it follows #2724 and fixes #2714. - This PR cites only fixture results. It does not claim any game result, so no game verification is needed. Commands run locally - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: ok - `python3 tests/bidi_controls_check.py`: ok - `python3 -m py_compile tests/startup_direct_index_late_write_check.py`: ok Next: Win2025 WARP dev + release run on this head; I will post the receipt. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 13:03:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T12:49:16Z.


Win2025 WARP receipt for head a859da17.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit a859da170d912725c5439836caaebd7e75cbc9c5:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_stream_consumer -- -j 2): 24.62s (configure 1.89s)
    • Test (ctest --preset dev -R 'startup_direct_index_late_write' --parallel 3 --no-tests=error --output-on-failure): 2/2 passed (1.78s: startup_direct_index_late_write_warp 1.64s, startup_direct_index_late_write_hardware 1.63s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_stream_consumer -- -j 2): 52.34s (configure 1.90s)
    • Test (ctest --preset release -R 'startup_direct_index_late_write' --parallel 3 --no-tests=error --output-on-failure): 2/2 passed (1.91s: startup_direct_index_late_write_warp 1.76s, startup_direct_index_late_write_hardware 1.76s)
  • sccache: 4/14 hits; wall 87.7s
  • Real-GPU run not available (RunPod stopped).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7192504420 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2834#issuecomment-7192504420). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T12:49:16Z. --- Win2025 WARP receipt for head a859da17. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `a859da170d912725c5439836caaebd7e75cbc9c5`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_stream_consumer -- -j 2`): `24.62s` (configure `1.89s`) - Test (`ctest --preset dev -R 'startup_direct_index_late_write' --parallel 3 --no-tests=error --output-on-failure`): **2/2 passed** (`1.78s`: `startup_direct_index_late_write_warp` `1.64s`, `startup_direct_index_late_write_hardware` `1.63s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_stream_consumer -- -j 2`): `52.34s` (configure `1.90s`) - Test (`ctest --preset release -R 'startup_direct_index_late_write' --parallel 3 --no-tests=error --output-on-failure`): **2/2 passed** (`1.91s`: `startup_direct_index_late_write_warp` `1.76s`, `startup_direct_index_late_write_hardware` `1.76s`) - `sccache`: 4/14 hits; wall `87.7s` - Real-GPU run not available (RunPod stopped). AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2826
No description provided.