runtime: validate translated indexed indirect draws on the GPU #2244

Merged
R0Y00 merged 2 commits from upstream-pr/2252 into main 2026-11-25 08:30:56 +00:00
R0Y00 commented 2026-11-25 07:56:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T07:56:06Z.


Refs #1759. Builds on the native indexed path in #1891 and the translated resource binding work in #2232 and #2236.

Route one translated DrawIndexed record through slot 61 when X2W_TRANSLATED_INDIRECT_DRAW=1. Start with the existing index-view and argument allocation checks. Keep the guest root, target and graphics-state checks and require complete GPU-backed input ranges. A small compute step validates the argument and index bytes on the recording, then supplies the translated base-vertex constant alongside the indexed argument. A rejected argument produces a zero draw count.

The profile accepts a complete vertex stream at slot zero, a single instance starting at zero, and at most 4,096 indices in a triangle list. It refuses a live guest compute binding and shader inputs outside the verified translation profile. Allocator lifetime tracking holds the scratch buffer through execution and reuse. Microsoft HLSL extended command information

Verification

Windows build 26200, Release MSVC 19.51.36244.0, D3D12 debug layer. WARP 10.0.26100.9818 and RTX 4060 Laptop GPU 32.0.16.1656. All 10 selected tests passed.

cmake --build --preset release --target startup_indirect_draw_indexed
ctest --preset release --no-tests=error -R '^startup_indirect_(translated_indexed|translated_draw|draw_indexed|copy_provenance(_off)?)_(warp|hardware)$' --output-on-failure

The source-built shader manually fetches a vertex value from the bound stream. R16/base zero and R32/base three at different argument and index-view offsets paint opposite halves. The check reads all eight pixels and the original GPU argument words and guards. Bad index/vertex ranges, an invalid adjusted index, a short argument record and an omitted writer leave the target clear. With the previous shim, both adapters left pixel (0,0) black (0xff000000) when red (0xff0000ff) was expected.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6599872581 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2252). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T07:56:06Z. --- Refs #1759. Builds on the native indexed path in #1891 and the translated resource binding work in #2232 and #2236. Route one translated `DrawIndexed` record through slot 61 when `X2W_TRANSLATED_INDIRECT_DRAW=1`. Start with the existing index-view and argument allocation checks. Keep the guest root, target and graphics-state checks and require complete GPU-backed input ranges. A small compute step validates the argument and index bytes on the recording, then supplies the translated base-vertex constant alongside the indexed argument. A rejected argument produces a zero draw count. The profile accepts a complete vertex stream at slot zero, a single instance starting at zero, and at most 4,096 indices in a triangle list. It refuses a live guest compute binding and shader inputs outside the verified translation profile. Allocator lifetime tracking holds the scratch buffer through execution and reuse. [Microsoft HLSL extended command information](https://microsoft.github.io/hlsl-specs/proposals/0015-extended-command-info/) ### Verification Windows build 26200, Release MSVC 19.51.36244.0, D3D12 debug layer. WARP 10.0.26100.9818 and RTX 4060 Laptop GPU 32.0.16.1656. All 10 selected tests passed. ```powershell cmake --build --preset release --target startup_indirect_draw_indexed ctest --preset release --no-tests=error -R '^startup_indirect_(translated_indexed|translated_draw|draw_indexed|copy_provenance(_off)?)_(warp|hardware)$' --output-on-failure ``` The source-built shader manually fetches a vertex value from the bound stream. R16/base zero and R32/base three at different argument and index-view offsets paint opposite halves. The check reads all eight pixels and the original GPU argument words and guards. Bad index/vertex ranges, an invalid adjusted index, a short argument record and an omitted writer leave the target clear. With the previous shim, both adapters left pixel (0,0) black (`0xff000000`) when red (`0xff0000ff`) was expected.
tedin7 commented 2026-11-25 07:57:40 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 0b6a07a613 (comment only, not an approval).

Commands executed locally (Linux):

  • git diff --stat origin/main...HEAD: 6 files, +385/-48.
  • python3 tests/docs_links_check.py: pass (18 files, 428 links).
  • python3 tests/bidi_controls_check.py: pass.
  • git diff --check origin/main...HEAD: clean.
  • gh pr checks 2252: Linux Python checks pass; the Windows build and the gfx1013 job were still pending when I looked.

Not run: the changed tests are Windows/D3D12 only (startup_indirect_draw_indexed), so I did not build them or mutate the guard on Linux. Please rely on the Windows jobs and the verification block for GPU results. Title is neutral, the diff has no clean-room concerns, and the PR is mergeable.

Read-through of indexed_indirect_guard.h and d3d12_draw.inl:

  • The guard's bounds math looks right: argument offset and size, index offset and size alignment, args.x limited to 3..4096 and divisible by 3, start-instance zero, one instance, and the index range inside the view.
  • The adjusted-index overflow check is right for both signs of base vertex. The check against vertices is also right.
  • The word load for 16-bit indices stays inside the backing size.
  • Rejection writes a zero count first, so a refused record draws nothing.

P1: none found.

P2:

  • d3d12_draw.inl (validate_indexed_arguments): if the argument buffer was tracked as COMMON before validation, it is not transitioned back (argument_previous != COMMON guard). It stays in NON_PIXEL_SHADER_RESOURCE for later guest use. Please confirm the pass state tracker handles this, or restore it to COMMON. A test that reuses the same buffer for a later copy or write would show it.
  • Same function: indexed_vertices stays UINT_MAX when the translation has no slot-zero vertex-stream SRV. The guard then does not bound adjusted indices by any vertex extent. It is safe only if such a translation cannot fetch vertices. Please state that invariant or require a stream whenever the base-vertex entry is present.

Nits:

  • docs/experiments.md ctest regex lists translated_indexed|translated_draw|draw_indexed. The PR body also includes copy_provenance(_off)?, so the two commands differ.
  • The static validation pipeline is created once per process with the first device. A later device falls back to a refusal (compute.device != device). A one-line comment on that would help readers.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6053778159 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2252#pullrequestreview-6053778159). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T07:57:40Z. **Review:** COMMENTED --- Review of head 0b6a07a6133a472ed7cda25b7f309653a6bda658 (comment only, not an approval). Commands executed locally (Linux): - `git diff --stat origin/main...HEAD`: 6 files, +385/-48. - `python3 tests/docs_links_check.py`: pass (18 files, 428 links). - `python3 tests/bidi_controls_check.py`: pass. - `git diff --check origin/main...HEAD`: clean. - `gh pr checks 2252`: Linux Python checks pass; the Windows build and the gfx1013 job were still pending when I looked. Not run: the changed tests are Windows/D3D12 only (`startup_indirect_draw_indexed`), so I did not build them or mutate the guard on Linux. Please rely on the Windows jobs and the verification block for GPU results. Title is neutral, the diff has no clean-room concerns, and the PR is mergeable. Read-through of `indexed_indirect_guard.h` and `d3d12_draw.inl`: - The guard's bounds math looks right: argument offset and size, index offset and size alignment, `args.x` limited to 3..4096 and divisible by 3, start-instance zero, one instance, and the index range inside the view. - The adjusted-index overflow check is right for both signs of base vertex. The check against `vertices` is also right. - The word load for 16-bit indices stays inside the backing size. - Rejection writes a zero count first, so a refused record draws nothing. P1: none found. P2: - `d3d12_draw.inl` (`validate_indexed_arguments`): if the argument buffer was tracked as COMMON before validation, it is not transitioned back (`argument_previous != COMMON` guard). It stays in NON_PIXEL_SHADER_RESOURCE for later guest use. Please confirm the pass state tracker handles this, or restore it to COMMON. A test that reuses the same buffer for a later copy or write would show it. - Same function: `indexed_vertices` stays `UINT_MAX` when the translation has no slot-zero vertex-stream SRV. The guard then does not bound adjusted indices by any vertex extent. It is safe only if such a translation cannot fetch vertices. Please state that invariant or require a stream whenever the base-vertex entry is present. Nits: - `docs/experiments.md` ctest regex lists `translated_indexed|translated_draw|draw_indexed`. The PR body also includes `copy_provenance(_off)?`, so the two commands differ. - The static validation pipeline is created once per process with the first device. A later device falls back to a refusal (`compute.device != device`). A one-line comment on that would help readers. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 08:30:53 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Re-review of head ab83bffd4a (comment only, not an approval). Previous review was on 0b6a07a6.

Commands executed locally (Linux):

  • git diff --stat origin/main...HEAD: 6 files, +385/-48.
  • python3 tests/docs_links_check.py: pass (18 files, 428 links).
  • python3 tests/bidi_controls_check.py: pass (1541 files).
  • git diff --check origin/main...HEAD: clean.
  • gh pr checks 2252: Linux Python checks and gfx1013 fixtures pass; "Build and test on Windows" was still pending, the /O2 job skipped.

Not run: the changed test (startup_indirect_draw_indexed) and the guard (HLSL in indexed_indirect_guard.h) only run on Windows/D3D12, so I did not mutate the guard on Linux. Please rely on the Windows job for GPU results. Title is neutral, no clean-room concerns, PR is mergeable.

Previous P2 items:

  1. Argument buffer state after validation: RESOLVED. When the buffer was COMMON, require_state still records it in pass.states, and release_targets (d3d12_xs_device.cpp, around line 2188) transitions every tracked resource back to COMMON at list end. So the argument_previous != COMMON guard in d3d12_draw.inl:1573 is correct: nothing is left behind.
  2. indexed_vertices staying UINT_MAX: PARTLY OPEN. With a source-1 SRV, a missing slot-zero stream now refuses the draw (d3d12_draw.inl:1879), and otherwise the extent is SizeInBytes / StrideInBytes (line 1874). The only remaining unbounded path is a translation with no source-1 SRV, which cannot fetch vertices, so I think it is safe. No comment states that invariant yet. See nit.

P1: none found.

P2: none new.

Nits:

  • Add a one-line comment at d3d12_draw.inl:1751 saying UINT_MAX is used only when the translation has no vertex-stream SRV.
  • The static validation pipeline is tied to the first device (compute.device != device returns null at line 1508, which becomes a refusal). A one-line comment would help readers.
  • Check that the ctest regex in docs/experiments.md matches the one in the PR body (copy_provenance(_off)? was missing earlier); I did not re-diff it.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6054160220 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2252#pullrequestreview-6054160220). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T08:30:53Z. **Review:** COMMENTED --- Re-review of head ab83bffd4aa640be2f6c8ae717d44b7b9b1e3418 (comment only, not an approval). Previous review was on 0b6a07a6. Commands executed locally (Linux): - `git diff --stat origin/main...HEAD`: 6 files, +385/-48. - `python3 tests/docs_links_check.py`: pass (18 files, 428 links). - `python3 tests/bidi_controls_check.py`: pass (1541 files). - `git diff --check origin/main...HEAD`: clean. - `gh pr checks 2252`: Linux Python checks and gfx1013 fixtures pass; "Build and test on Windows" was still pending, the /O2 job skipped. Not run: the changed test (`startup_indirect_draw_indexed`) and the guard (HLSL in `indexed_indirect_guard.h`) only run on Windows/D3D12, so I did not mutate the guard on Linux. Please rely on the Windows job for GPU results. Title is neutral, no clean-room concerns, PR is mergeable. Previous P2 items: 1. Argument buffer state after validation: RESOLVED. When the buffer was COMMON, `require_state` still records it in `pass.states`, and `release_targets` (`d3d12_xs_device.cpp`, around line 2188) transitions every tracked resource back to COMMON at list end. So the `argument_previous != COMMON` guard in `d3d12_draw.inl:1573` is correct: nothing is left behind. 2. `indexed_vertices` staying `UINT_MAX`: PARTLY OPEN. With a source-1 SRV, a missing slot-zero stream now refuses the draw (`d3d12_draw.inl:1879`), and otherwise the extent is `SizeInBytes / StrideInBytes` (line 1874). The only remaining unbounded path is a translation with no source-1 SRV, which cannot fetch vertices, so I think it is safe. No comment states that invariant yet. See nit. P1: none found. P2: none new. Nits: - Add a one-line comment at `d3d12_draw.inl:1751` saying `UINT_MAX` is used only when the translation has no vertex-stream SRV. - The static validation pipeline is tied to the first device (`compute.device != device` returns null at line 1508, which becomes a refusal). A one-line comment would help readers. - Check that the ctest regex in `docs/experiments.md` matches the one in the PR body (`copy_provenance(_off)?` was missing earlier); I did not re-diff it. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 09:04:01 +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!2244
No description provided.