startup: bind GPU-backed table buffers for indirect draws #2228

Merged
R0Y00 merged 4 commits from upstream-pr/2236 into main 2026-11-25 07:23:09 +00:00
R0Y00 commented 2026-11-25 06:53:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T06:53:27Z.


Depends on #2232. Refs #870.

Reuse the translated indirect Draw binding path for table buffers whose complete byte range maps to a recording-owned upload allocation, a unique aliased placed buffer, or a wrapped desktop resource with no separate title backing. The runtime binds a desktop raw SRV and the descriptor's stride. It refuses ambiguous mappings, copied placements with unproven GPU contents, misaligned raw views, out-of-range descriptors, cross-device resources and reuse of the indirect argument resource as an SRV. Deferred guest roots can supply recorded tables to the translated desktop root.

The source-built fixture writes two colours to a default-heap GPU buffer and writes the Draw arguments in another GPU buffer. A view with nonzero offset and stride selects the second colour. A shorter view exposes only its declared range, so the same load reads zero. A non-aliased placement with distinct CPU and GPU data leaves the target clear. The raw descriptor case uses a recording-owned upload allocation and checks refusal when the range crosses that allocation. A matching deferred guest root also produces all eight expected pixels.

Local MSVC Release on Windows 11 build 26200.9974. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the debug layer enabled for the translated draw fixture.

cmake --build --preset release --target startup_indirect_draw_indexed startup_upload_arena startup_upload_lifetime startup_list_resubmit
ctest --preset release -j1 --no-tests=error -R '^startup_(indirect_(translated_draw|draw|draw_indexed|mesh|counts_control)|upload_|list_resubmit)' -V

21/21 passed, no skips. AI-assisted. Commands executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6598991859 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2236). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T06:53:27Z. --- Depends on #2232. Refs #870. Reuse the translated indirect Draw binding path for table buffers whose complete byte range maps to a recording-owned upload allocation, a unique aliased placed buffer, or a wrapped desktop resource with no separate title backing. The runtime binds a desktop raw SRV and the descriptor's stride. It refuses ambiguous mappings, copied placements with unproven GPU contents, misaligned raw views, out-of-range descriptors, cross-device resources and reuse of the indirect argument resource as an SRV. Deferred guest roots can supply recorded tables to the translated desktop root. The source-built fixture writes two colours to a default-heap GPU buffer and writes the Draw arguments in another GPU buffer. A view with nonzero offset and stride selects the second colour. A shorter view exposes only its declared range, so the same load reads zero. A non-aliased placement with distinct CPU and GPU data leaves the target clear. The raw descriptor case uses a recording-owned upload allocation and checks refusal when the range crosses that allocation. A matching deferred guest root also produces all eight expected pixels. Local MSVC Release on Windows 11 build 26200.9974. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the debug layer enabled for the translated draw fixture. ```powershell cmake --build --preset release --target startup_indirect_draw_indexed startup_upload_arena startup_upload_lifetime startup_list_resubmit ctest --preset release -j1 --no-tests=error -R '^startup_(indirect_(translated_draw|draw|draw_indexed|mesh|counts_control)|upload_|list_resubmit)' -V ``` 21/21 passed, no skips. AI-assisted. Commands executed locally.
tedin7 commented 2026-11-25 06:55:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T06:55:50Z.

Review: COMMENTED


Review of head 741e2ef7f0 (Linux-side review; no Windows run by me).

Commands executed locally:

  • git diff --stat origin/main...HEAD : 6 files, +525/-21 (d3d12_draw.inl, d3d12_xs_device.cpp, list_upload_pages.h, CMakeLists.txt, test, docs/experiments.md)
  • python3 tests/docs_links_check.py : self-test passed, 18 files, 412 links OK
  • python3 tests/bidi_controls_check.py : 1507 files, no bidi controls
  • git diff --check origin/main...HEAD : clean
  • gh pr checks 2236 : no CI checks reported on the branch; PR is MERGEABLE, title is neutral, body has no clean-room concerns.

Read-through findings (targeted reading of draw_translated, indirect_table_buffer, indirect_shader_entry, list_execute_indirect, Arena::range):

  • No P1 found. The path is opt-in (X2W_TRANSLATED_INDIRECT_DRAW) and every unproven case returns a refusal, so default behaviour is unchanged.
  • Good: the range check bytes > desc.Width - offset after offset > desc.Width cannot underflow; Arena::translate is kept as a wrapper over range, so existing callers are unchanged; the argument buffer is refused as an SRV; cross-device resources are refused.
  • P2 (d3d12_draw.inl, indirect_table_buffer, upload branch): when a recording-owned upload allocation matches but the view token names an owner, it returns {} silently. The refusal text is the generic "complete GPU-backed table buffer range", so a log reader cannot tell this case from a real range error. Suggest a distinct refusal reason.
  • P2 (d3d12_draw.inl, draw_translated indirect branch): view.upload skips require_state. That is right for UPLOAD heap buffers (GENERIC_READ), but a wrapped resource that was previously transitioned by the title would be skipped too if its heap is upload. Please add a short comment or a test line stating that upload-heap buffers never leave GENERIC_READ.
  • nit: draw_dump_after and the per-shader draw log are skipped for indirect draws. Fine, but the diagnostics budget (32 refusals, 16 records) is static and shared across shaders; worth a line in docs/experiments.md.
  • nit: independent_indirect_entry is cached per Translation; if the target-variant lookup (translation_for_targets) can return a different Translation with different uds, the cache is per variant, which looks correct. A one-line comment would help.

Mutation testing: not done. The touched tests (startup_indirect_draw_indexed.cpp, ctest startup_indirect_translated_draw_{warp,hardware}) are Windows D3D12 only and cannot build on this Linux host, so I could not run a mutation. A Windows WARP run is needed before Ready; the body cites a local Windows run, which I did not reproduce.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6053129553 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2236#pullrequestreview-6053129553). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T06:55:50Z. **Review:** COMMENTED --- Review of head 741e2ef7f05cb3ef475806719683f0fed672963b (Linux-side review; no Windows run by me). Commands executed locally: - `git diff --stat origin/main...HEAD` : 6 files, +525/-21 (d3d12_draw.inl, d3d12_xs_device.cpp, list_upload_pages.h, CMakeLists.txt, test, docs/experiments.md) - `python3 tests/docs_links_check.py` : self-test passed, 18 files, 412 links OK - `python3 tests/bidi_controls_check.py` : 1507 files, no bidi controls - `git diff --check origin/main...HEAD` : clean - `gh pr checks 2236` : no CI checks reported on the branch; PR is MERGEABLE, title is neutral, body has no clean-room concerns. Read-through findings (targeted reading of `draw_translated`, `indirect_table_buffer`, `indirect_shader_entry`, `list_execute_indirect`, `Arena::range`): - No P1 found. The path is opt-in (`X2W_TRANSLATED_INDIRECT_DRAW`) and every unproven case returns a refusal, so default behaviour is unchanged. - Good: the range check `bytes > desc.Width - offset` after `offset > desc.Width` cannot underflow; `Arena::translate` is kept as a wrapper over `range`, so existing callers are unchanged; the argument buffer is refused as an SRV; cross-device resources are refused. - P2 (d3d12_draw.inl, `indirect_table_buffer`, upload branch): when a recording-owned upload allocation matches but the view token names an `owner`, it returns `{}` silently. The refusal text is the generic "complete GPU-backed table buffer range", so a log reader cannot tell this case from a real range error. Suggest a distinct refusal reason. - P2 (d3d12_draw.inl, `draw_translated` indirect branch): `view.upload` skips `require_state`. That is right for UPLOAD heap buffers (GENERIC_READ), but a wrapped resource that was previously transitioned by the title would be skipped too if its heap is upload. Please add a short comment or a test line stating that upload-heap buffers never leave GENERIC_READ. - nit: `draw_dump_after` and the per-shader draw log are skipped for indirect draws. Fine, but the diagnostics budget (32 refusals, 16 records) is static and shared across shaders; worth a line in docs/experiments.md. - nit: `independent_indirect_entry` is cached per Translation; if the target-variant lookup (`translation_for_targets`) can return a different Translation with different `uds`, the cache is per variant, which looks correct. A one-line comment would help. Mutation testing: not done. The touched tests (`startup_indirect_draw_indexed.cpp`, ctest `startup_indirect_translated_draw_{warp,hardware}`) are Windows D3D12 only and cannot build on this Linux host, so I could not run a mutation. A Windows WARP run is needed before Ready; the body cites a local Windows run, which I did not reproduce. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 07:19:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T07:19:30Z.

Review: COMMENTED


Re-review of head 9f3706c1 (previous review was on 741e2ef7). Linux-side only; no Windows run by me.

Commands executed locally:

  • git diff --stat origin/main...HEAD : 5 files, +255/-39 (d3d12_draw.inl, d3d12_xs_device.cpp, list_upload_pages.h, test, docs/experiments.md). CMakeLists.txt dropped out of the diff after the merge of main.
  • python3 tests/docs_links_check.py : self-test passed, 18 files, 418 links OK
  • python3 tests/bidi_controls_check.py : 1520 files, no bidi controls
  • git diff --check origin/main...HEAD : clean
  • gh pr checks 2236 : no CI checks reported; PR is MERGEABLE, title neutral.
  • targeted reads: rg -n -C6 'if \(!view.upload\)' in d3d12_draw.inl, rg -n -i 'GENERIC_READ|upload' in the test, rg -n -i 'refusal|budget' in docs/experiments.md.

Status of the two earlier P2 items:

  • P2 #1 NOT resolved (d3d12_draw.inl, indirect_table_buffer, upload branch if (!owner) return {...}; return {};): a view token that names an owner and matches a recording-owned upload allocation still returns {}, and the caller still reports the generic "complete GPU-backed table buffer range". Same ambiguity as before. Please add a distinct refusal reason, or a comment saying why this case is deliberately folded into the generic text.
  • P2 #2 NOT resolved (d3d12_draw.inl, if (!view.upload) require_state(...)): no comment and no test line stating that upload-heap buffers stay in GENERIC_READ and so need no transition. The test creates its upload buffer in GENERIC_READ (startup_indirect_draw_indexed.cpp:424-425) but does not assert the skip. A one-line comment is enough.
  • Previous nits (diagnostics budget line in docs, per-variant cache comment): not addressed; still optional.

New in this head, read-through:

  • indirect_shader_entry now accepts a stride ud bound to a source-0 kind-0 SRV, and the srv.kind > 0 requirement was dropped from independent_indirect_entry. The accepted set is narrow (exact match on source and kind), so I see no P1.
  • No new P1 found. Default behaviour stays opt-in.

Mutation testing: not done. The touched tests are Windows D3D12 only and do not build on this Linux host. A Windows WARP dev+release run is still needed before Ready.

Counts: P1=0, P2=2 (both carried over, unresolved).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6053368857 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2236#pullrequestreview-6053368857). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T07:19:30Z. **Review:** COMMENTED --- Re-review of head 9f3706c1 (previous review was on 741e2ef7). Linux-side only; no Windows run by me. Commands executed locally: - `git diff --stat origin/main...HEAD` : 5 files, +255/-39 (d3d12_draw.inl, d3d12_xs_device.cpp, list_upload_pages.h, test, docs/experiments.md). CMakeLists.txt dropped out of the diff after the merge of main. - `python3 tests/docs_links_check.py` : self-test passed, 18 files, 418 links OK - `python3 tests/bidi_controls_check.py` : 1520 files, no bidi controls - `git diff --check origin/main...HEAD` : clean - `gh pr checks 2236` : no CI checks reported; PR is MERGEABLE, title neutral. - targeted reads: `rg -n -C6 'if \(!view.upload\)'` in d3d12_draw.inl, `rg -n -i 'GENERIC_READ|upload'` in the test, `rg -n -i 'refusal|budget'` in docs/experiments.md. Status of the two earlier P2 items: - P2 #1 NOT resolved (d3d12_draw.inl, `indirect_table_buffer`, upload branch `if (!owner) return {...}; return {};`): a view token that names an `owner` and matches a recording-owned upload allocation still returns `{}`, and the caller still reports the generic "complete GPU-backed table buffer range". Same ambiguity as before. Please add a distinct refusal reason, or a comment saying why this case is deliberately folded into the generic text. - P2 #2 NOT resolved (d3d12_draw.inl, `if (!view.upload) require_state(...)`): no comment and no test line stating that upload-heap buffers stay in GENERIC_READ and so need no transition. The test creates its upload buffer in GENERIC_READ (startup_indirect_draw_indexed.cpp:424-425) but does not assert the skip. A one-line comment is enough. - Previous nits (diagnostics budget line in docs, per-variant cache comment): not addressed; still optional. New in this head, read-through: - `indirect_shader_entry` now accepts a `stride` ud bound to a source-0 kind-0 SRV, and the `srv.kind > 0` requirement was dropped from `independent_indirect_entry`. The accepted set is narrow (exact match on source and kind), so I see no P1. - No new P1 found. Default behaviour stays opt-in. Mutation testing: not done. The touched tests are Windows D3D12 only and do not build on this Linux host. A Windows WARP dev+release run is still needed before Ready. Counts: P1=0, P2=2 (both carried over, unresolved). AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 08:04:54 +00:00
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!2228
No description provided.