test: cover slot 57 mesh buffer reads (soffset, structured stride, out of range) #2786

Closed
github-bot wants to merge 1 commit from gh-pr/2786/head into gh-pr/2786/base
Owner

@⁠tedin7 on GitHub · 2026-11-26 09:03 UTC · original
tedin7:x2w-mesh57-buffer-read → main · +198 −0 · 4 files · 1 commits · closed without merging

Part of #2413

What this unblocks: a picture-level guard for the buffer reads of translated slot 57 mesh programs (offset from an SGPR, structured loads with the descriptor stride, reads past the view), so a wrong buffer-view read can no longer hide geometry or colour unnoticed.

What changed

  • New tests/startup_mesh57_buffer_read_check.py, built on the slot 57 fixture of startup_mesh57_skeleton_check.py (its words are edited, nothing new is translated; no change to gfx2hlsl.py).
  • Three buffer-read shapes, each drawn on D3D12 and compared with a CPU model of the buffer address rules (byte address = soffset + voffset (offen) + index * stride (idxen) + instruction offset; a read outside the bound view returns 0):
    • soffset: the colour load takes its offset from an SGPR instead of the instruction offset (same picture as the plain fixture);
    • structured: position and colour loads use idxen, the stride comes from the descriptor (16: same picture);
    • out of range: the colour load starts past the 512-byte view (every colour channel reads 0).
  • Controls that must fail with exactly the number of pixels the model gives: a colour read one vertex too far (soffset 208), the read past the view drawn against the right picture, and the structured load with stride 0 (every vertex reads slot 0).
  • Default mode checks the translation (only the structured variant asks the runtime for the stride constant, one vertex SRV each); binary compares the embedded words with llvm-mc; draw runs the cases through offscreen_check --mesh-indexed.
  • Registered in CMake (plain test and startup_mesh57_buffer_read_draw_<adapter>), windows.yml (binary list and Python list) and AGENTS.md.

What stays untested: typed (buffer_load_format_*) reads are covered by the formatted mode of startup_mesh57_skeleton_check.py; a raw load that straddles the end of the view and the structured index/offset bounds (OOB_SELECT modes) are not covered, because the draw harness binds one fixed 512-byte view.

Source: AMD "RDNA 2" Instruction Set Architecture reference guide, chapter 8 (vector memory buffer instructions: address calculation and range checking); DirectX-Specs, Mesh Shader spec (output counts, indexed primitives).

Verification:

  • Linux: python3 -B tests/startup_mesh57_buffer_read_check.py -> ok
  • Linux: python3 -B tests/startup_mesh57_buffer_read_check.py binary llvm-mc-19 -> ok
  • Linux: python3 -B tests/startup_mesh57_skeleton_check.py binary llvm-mc-19 -> ok (unchanged)
  • Linux: python3 -B tests/docs_links_check.py and tests/bidi_controls_check.py -> pass; git diff --check origin/main...HEAD -> clean
  • Win2025 WARP dev+release: pending Stage-2

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 09:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786) `tedin7:x2w-mesh57-buffer-read` → `main` · +198 −0 · 4 files · 1 commits · closed without merging Part of #2413 What this unblocks: a picture-level guard for the buffer reads of translated slot 57 mesh programs (offset from an SGPR, structured loads with the descriptor stride, reads past the view), so a wrong buffer-view read can no longer hide geometry or colour unnoticed. What changed - New `tests/startup_mesh57_buffer_read_check.py`, built on the slot 57 fixture of `startup_mesh57_skeleton_check.py` (its words are edited, nothing new is translated; no change to `gfx2hlsl.py`). - Three buffer-read shapes, each drawn on D3D12 and compared with a CPU model of the buffer address rules (byte address = soffset + voffset (`offen`) + index * stride (`idxen`) + instruction offset; a read outside the bound view returns 0): - `soffset`: the colour load takes its offset from an SGPR instead of the instruction offset (same picture as the plain fixture); - `structured`: position and colour loads use `idxen`, the stride comes from the descriptor (16: same picture); - `out of range`: the colour load starts past the 512-byte view (every colour channel reads 0). - Controls that must fail with exactly the number of pixels the model gives: a colour read one vertex too far (soffset 208), the read past the view drawn against the right picture, and the structured load with stride 0 (every vertex reads slot 0). - Default mode checks the translation (only the structured variant asks the runtime for the stride constant, one vertex SRV each); `binary` compares the embedded words with llvm-mc; `draw` runs the cases through `offscreen_check --mesh-indexed`. - Registered in CMake (plain test and `startup_mesh57_buffer_read_draw_<adapter>`), `windows.yml` (binary list and Python list) and `AGENTS.md`. What stays untested: typed (`buffer_load_format_*`) reads are covered by the `formatted` mode of `startup_mesh57_skeleton_check.py`; a raw load that straddles the end of the view and the structured index/offset bounds (OOB_SELECT modes) are not covered, because the draw harness binds one fixed 512-byte view. Source: AMD "RDNA 2" Instruction Set Architecture reference guide, chapter 8 (vector memory buffer instructions: address calculation and range checking); DirectX-Specs, Mesh Shader spec (output counts, indexed primitives). Verification: - Linux: `python3 -B tests/startup_mesh57_buffer_read_check.py` -> ok - Linux: `python3 -B tests/startup_mesh57_buffer_read_check.py binary llvm-mc-19` -> ok - Linux: `python3 -B tests/startup_mesh57_skeleton_check.py binary llvm-mc-19` -> ok (unchanged) - Linux: `python3 -B tests/docs_links_check.py` and `tests/bidi_controls_check.py` -> pass; `git diff --check origin/main...HEAD` -> clean - Win2025 WARP dev+release: pending Stage-2 AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:22:40 +00:00
github-bot closed this pull request 2026-11-27 01:22:40 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 09:17 UTC · original

Independent review of head 0092b6f510: PASS.

Verification:

  • Windows Server 2025 (D3D12 WARP), ctest -R '^startup_mesh57_buffer_read': dev 3/3 and release 3/3 (startup_mesh57_buffer_read, startup_mesh57_buffer_read_draw_warp, startup_mesh57_buffer_read_draw_hardware).
  • Tested on RTX 3090 through vkd3d-proton (Linux): 3/3 on the same head.
  • Linux: python3 -B tests/startup_mesh57_buffer_read_check.py ok; ... binary llvm-mc-19 ok; tests/startup_mesh57_skeleton_check.py binary llvm-mc-19 ok (unchanged); git diff --check origin/main...HEAD clean.
  • The wrong variants (soffset one vertex too far, read past the view, structured stride 0) fail with exactly the pixel counts the model gives. Merging current main is clean; the translator break-it set is unchanged (173 same).

One open point for a follow-up, not blocking: the structured case loads with idxen offset:192 and stride 16 and expects the same picture. The range rule the repo already uses for the compute stores (RDNA 2 ISA, buffer out-of-range table: a structured access is out of range when voffset + instruction offset + element size exceeds the stride) would count that load as out of range on hardware. The base is better carried in soffset, with a control for an instruction offset larger than the stride.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 09:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#issuecomment-7187743924) Independent review of head 0092b6f5100b35936fcc47daf8721efcbe128879: PASS. Verification: - Windows Server 2025 (D3D12 WARP), `ctest -R '^startup_mesh57_buffer_read'`: dev 3/3 and release 3/3 (`startup_mesh57_buffer_read`, `startup_mesh57_buffer_read_draw_warp`, `startup_mesh57_buffer_read_draw_hardware`). - Tested on RTX 3090 through vkd3d-proton (Linux): 3/3 on the same head. - Linux: `python3 -B tests/startup_mesh57_buffer_read_check.py` ok; `... binary llvm-mc-19` ok; `tests/startup_mesh57_skeleton_check.py binary llvm-mc-19` ok (unchanged); `git diff --check origin/main...HEAD` clean. - The wrong variants (soffset one vertex too far, read past the view, structured stride 0) fail with exactly the pixel counts the model gives. Merging current main is clean; the translator break-it set is unchanged (173 same). One open point for a follow-up, not blocking: the structured case loads with `idxen offset:192` and stride 16 and expects the same picture. The range rule the repo already uses for the compute stores (RDNA 2 ISA, buffer out-of-range table: a structured access is out of range when voffset + instruction offset + element size exceeds the stride) would count that load as out of range on hardware. The base is better carried in soffset, with a control for an instruction offset larger than the stride. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 09:18 UTC · original · edited 2026-11-26 09:22 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T09:22:51.456240Z 0092b6f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 09:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#issuecomment-7187747674) · edited 2026-11-26 09:22 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"0092b6f5100b35936fcc47daf8721efcbe128879","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T09:22:51.456240Z">2026-11-26T09:22:51.456240Z</relative-time> | `0092b6f` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 09:22 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0092b6f510

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 09:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#pullrequestreview-6071469353) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `0092b6f510` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
@ -0,0 +113,4 @@
('soffset', SOFFSET_COLOUR, None, RIGHT, RIGHT),
('soffset one vertex too far', SOFFSET_WRONG, None,
model_image(lambda slot: 16 * slot, lambda slot: 208 + 16 * slot), RIGHT),
('out of range', SOFFSET_OUT_OF_RANGE, None, model_image(lambda slot: 16 * slot, lambda slot: 1024 + 16 * slot), RIGHT),
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 09:22 UTC · original

P2 Badge Use a bounded SRV for the out-of-range draw

In draw mode on a mesh-capable adapter, the harness binds the vertex buffer using SetGraphicsRootShaderResourceView (tests/mesh_entry_draw.cpp:160,334), not a sized descriptor-table SRV. Root descriptors carry no 512-byte view bound, and the generated shader emits unchecked r0.Load calls at 1024 + v4, beyond the upload resource's logical size. These accesses are not guaranteed to return zero, so this case relies on undefined out-of-range reads rather than validating the CPU model's view-bounds rule. Bind a sized raw SRV before exercising this case.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 09:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#discussion_r4706204048) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Use a bounded SRV for the out-of-range draw** In draw mode on a mesh-capable adapter, the harness binds the vertex buffer using `SetGraphicsRootShaderResourceView` (`tests/mesh_entry_draw.cpp:160,334`), not a sized descriptor-table SRV. Root descriptors carry no 512-byte view bound, and the generated shader emits unchecked `r0.Load` calls at `1024 + v4`, beyond the upload resource's logical size. These accesses are not guaranteed to return zero, so this case relies on undefined out-of-range reads rather than validating the CPU model's view-bounds rule. Bind a sized raw SRV before exercising this case. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -0,0 +154,4 @@
struct.pack_into('<I', constants, 4 * uds['stride', '0'], stride)
expected = sum(a != b for a, b in zip(drawn, compared))
path = Path(tmp) / 'case.bin'
path.write_bytes(bytes(constants) + VIEW + b'\xcd' * 80 + b''.join(map(bytes, compared)))
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 09:22 UTC · original

P2 Badge Compare negative-case pixels against their modeled images

For all three non-reference cases, expected is 259 mismatches against RIGHT. Using the fixture's CPU rasterizer, both a completely clear frame and solid-red triangles also produce exactly 259 mismatches, so either incorrect output passes these checks. In particular, the out-of-range load can return red instead of zero without failing, and the shifted-colour case can emit no geometry at all. Because only compared is serialized, the modeled drawn image is never actually verified. Render each case against its own drawn image with zero expected mismatches before retaining the wrong-reference comparisons as negative controls.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 09:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#discussion_r4706204059) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Compare negative-case pixels against their modeled images** For all three non-reference cases, `expected` is 259 mismatches against `RIGHT`. Using the fixture's CPU rasterizer, both a completely clear frame and solid-red triangles also produce exactly 259 mismatches, so either incorrect output passes these checks. In particular, the out-of-range load can return red instead of zero without failing, and the shifted-colour case can emit no geometry at all. Because only `compared` is serialized, the modeled `drawn` image is never actually verified. Render each case against its own `drawn` image with zero expected mismatches before retaining the wrong-reference comparisons as negative controls. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-26 09:56 UTC · original

I will check exact mesh colour readbacks at the last complete vector of the view and at a vector crossing its end. I will fill the final words with distinguishable colours and compare each complete reference image plus a deliberately wrong image on the local mesh-capable adapters. This extends the existing wholly out-of-range case.

**@⁠RavenCurseBurg** on GitHub · 2026-11-26 09:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#issuecomment-7188682318) I will check exact mesh colour readbacks at the last complete vector of the view and at a vector crossing its end. I will fill the final words with distinguishable colours and compare each complete reference image plus a deliberately wrong image on the local mesh-capable adapters. This extends the existing wholly out-of-range case.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 10:25 UTC · original

Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

**@⁠tedin7** on GitHub · 2026-11-26 10:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#issuecomment-7189357381) Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-26 10:32 UTC · original

Closing out the view-boundary test claim. The existing root SRV has no descriptor length. I added a raw descriptor-table SRV of exactly 128 dwords for the native indexed colour draw, then compared full 32×32 images. The guest mesh words and all input data are synthetic. The C++ binding change and image oracle are available together in the reproduction commit, based on 0092b6f5.

The provoking vertex starts its four-channel load at byte 496, 500, 504, 508 or 512. Distinct colours occupy the end of the 512-byte view. The five CPU images expect 4, 3, 2, 1 and 0 in-range channels respectively. WARP and RTX 4060 each matched all 1,024 pixels in all five images. Each reference shifted by one dword gave exactly 56 differing pixels. Intel UHD 770 returned skip 77 (mesh tier unavailable). An initial RTX pass stopped after pipeline creation at byte 508 without a readback; a separate complete run recorded the expected status and pixel count for all ten draws.

To repeat, build offscreen_check at the linked revision, then run:

python tests/verify_mesh_view_edge.py <dxc> <offscreen_check> warp

For the physical run select hardware with XBOX2WINDOWS_ADAPTER=NVIDIA. I used the modified repository mesh draw path in a local Zig/Clang build restricted to the indexed operation. Windows 11 26100.9711, WARP 10.0.26100.9711, NVIDIA driver 32.0.15.9579, no debug layer. The descriptor binding and expected images can also be used with a native shader frontend. AI-assisted with Codex.

**@⁠RavenCurseBurg** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2786#issuecomment-7189506843) Closing out the view-boundary test claim. The existing root SRV has no descriptor length. I added a raw descriptor-table SRV of exactly 128 dwords for the native indexed colour draw, then compared full 32×32 images. The guest mesh words and all input data are synthetic. The C++ binding change and image oracle are available together in [the reproduction commit](https://github.com/RavenCurseBurg/Xbox2Windows/commit/128b2bb1293cf5f1dc816147131f3c3cc3de800c), based on `0092b6f5`. The provoking vertex starts its four-channel load at byte 496, 500, 504, 508 or 512. Distinct colours occupy the end of the 512-byte view. The five CPU images expect 4, 3, 2, 1 and 0 in-range channels respectively. WARP and RTX 4060 each matched all 1,024 pixels in all five images. Each reference shifted by one dword gave exactly 56 differing pixels. Intel UHD 770 returned skip 77 (mesh tier unavailable). An initial RTX pass stopped after pipeline creation at byte 508 without a readback; a separate complete run recorded the expected status and pixel count for all ten draws. To repeat, build `offscreen_check` at the linked revision, then run: ```text python tests/verify_mesh_view_edge.py <dxc> <offscreen_check> warp ``` For the physical run select `hardware` with `XBOX2WINDOWS_ADAPTER=NVIDIA`. I used the modified repository mesh draw path in a local Zig/Clang build restricted to the indexed operation. Windows 11 26100.9711, WARP 10.0.26100.9711, NVIDIA driver 32.0.15.9579, no debug layer. The descriptor binding and expected images can also be used with a native shader frontend. AI-assisted with Codex.

Pull request closed

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