gpu: check the raw UAV window validation and touching windows #1541

Merged
Asimmimx merged 1 commit from upstream-pr/1548 into main 2026-11-24 14:38:37 +00:00
Asimmimx commented 2026-11-24 13:48:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T13:48:29Z.


Change

This adds a device-free check for src/raw_buffer_uav.h. For a 4- or 16-byte store at a logical address, resolve_raw_uav_store finds the one window that contains it. Before it does, it validates every window: size in whole dwords, element count within UINT, a 16-byte-aligned resource offset inside the buffer, an extent within the buffer, no wrap past the last logical address, nonzero size and no overlap. It then returns the raw R32_TYPELESS UAV description for that window.

The header's only test is vm_raw_uav_warp. It uses two valid windows 4 GiB apart and refuses misaligned or out-of-window stores and four bad windows: too wide, unaligned, wrapping and overlapping. None of its windows is sized in partial dwords, has a misaligned or out-of-range resource offset, overruns its buffer, is empty, ends at the last logical address or touches another window. So 9 single-point mutants left it passing (table below).

raw_buffer_uav includes only the header. It resolves eight stores against a hand-worked window, offset, FirstElement and NumElements, and checks the format, dimension and raw flag. The stores cover:

  • both sides of two touching windows;
  • the last 16 logical bytes;
  • the widest window, of 0xffffffff elements.

It also refuses six bad windows and checks that each refusal leaves the result unchanged. raw_buffer_uav_adjacent_control (--mutate adjacent) expects the first byte of the upper window to resolve into the lower one, and must fail (WILL_FAIL).

The change is test, CMake and docs/experiments.md only. The CMake block follows the vm_raw_uav_${adapter} loop, and the doc sentence follows the vm_raw_uav_ run line.

Verification

Commit 309cfede (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0, WARP 10.0.26100.9818.

ctest --preset dev --no-tests=error -R '^(raw_buffer_uav(_adjacent_control)?|vm_raw_uav_warp)$' -V
#   3/3 passed; the control prints one FAIL line and exits 1, as intended

tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to the header alone, rebuilt, ran the tests, then reverted. None of this is committed.

Mutant vm_raw_uav_warp raw_buffer_uav
control: overlap guard selected != count dropped killed fails
bytes % 4 guard dropped survived fails
bytes / 4 > UINT_MAX guard dropped survived fails
resource_offset % 16 guard dropped survived fails
resource_offset > resource_width guard dropped survived fails
bytes > width - resource_offset guard dropped survived fails
wrap check bytes - 1 > → bytes > survived fails (window ending at the last logical address)
offset >= bytes → > survived fails (first byte of the upper touching window)
!window.bytes guard dropped survived fails (empty window in the set)
store-before-window guard < → <= survived fails (last dword and vector of the lower window)
FirstElement in bytes instead of elements killed fails
store-before-window guard deleted n/a survives (equivalent)

The last row is dead code under the alignment rules. Window bases are 16-aligned and the address is aligned to the store size, so the gap before a window is always at least the store size. Deleting the guard changes nothing.

No current caller builds two touching windows. The check treats them as accepted because the header requires only that a store fit inside one window. If you would rather treat touching windows as an error, I will change that case.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583253026 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1548). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T13:48:29Z. --- ## Change This adds a device-free check for `src/raw_buffer_uav.h`. For a 4- or 16-byte store at a logical address, `resolve_raw_uav_store` finds the one window that contains it. Before it does, it validates every window: size in whole dwords, element count within `UINT`, a 16-byte-aligned resource offset inside the buffer, an extent within the buffer, no wrap past the last logical address, nonzero size and no overlap. It then returns the raw `R32_TYPELESS` UAV description for that window. The header's only test is `vm_raw_uav_warp`. It uses two valid windows 4 GiB apart and refuses misaligned or out-of-window stores and four bad windows: too wide, unaligned, wrapping and overlapping. None of its windows is sized in partial dwords, has a misaligned or out-of-range resource offset, overruns its buffer, is empty, ends at the last logical address or touches another window. So 9 single-point mutants left it passing (table below). `raw_buffer_uav` includes only the header. It resolves eight stores against a hand-worked window, offset, `FirstElement` and `NumElements`, and checks the format, dimension and raw flag. The stores cover: - both sides of two touching windows; - the last 16 logical bytes; - the widest window, of 0xffffffff elements. It also refuses six bad windows and checks that each refusal leaves the result unchanged. `raw_buffer_uav_adjacent_control` (`--mutate adjacent`) expects the first byte of the upper window to resolve into the lower one, and must fail (`WILL_FAIL`). The change is test, CMake and `docs/experiments.md` only. The CMake block follows the `vm_raw_uav_${adapter}` loop, and the doc sentence follows the `vm_raw_uav_` run line. ## Verification Commit `309cfede` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0, WARP 10.0.26100.9818. ```powershell ctest --preset dev --no-tests=error -R '^(raw_buffer_uav(_adjacent_control)?|vm_raw_uav_warp)$' -V # 3/3 passed; the control prints one FAIL line and exits 1, as intended ``` `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to the header alone, rebuilt, ran the tests, then reverted. None of this is committed. | Mutant | `vm_raw_uav_warp` | `raw_buffer_uav` | |---|---|---| | control: overlap guard `selected != count` dropped | killed | fails | | `bytes % 4` guard dropped | **survived** | fails | | `bytes / 4 > UINT_MAX` guard dropped | **survived** | fails | | `resource_offset % 16` guard dropped | **survived** | fails | | `resource_offset > resource_width` guard dropped | **survived** | fails | | `bytes > width - resource_offset` guard dropped | **survived** | fails | | wrap check `bytes - 1 >` → `bytes >` | **survived** | fails (window ending at the last logical address) | | `offset >= bytes` → `>` | **survived** | fails (first byte of the upper touching window) | | `!window.bytes` guard dropped | **survived** | fails (empty window in the set) | | store-before-window guard `<` → `<=` | **survived** | fails (last dword and vector of the lower window) | | `FirstElement` in bytes instead of elements | killed | fails | | store-before-window guard deleted | n/a | survives (equivalent) | The last row is dead code under the alignment rules. Window bases are 16-aligned and the address is aligned to the store size, so the gap before a window is always at least the store size. Deleting the guard changes nothing. No current caller builds two touching windows. The check treats them as accepted because the header requires only that a store fit inside one window. If you would rather treat touching windows as an error, I will change that case. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 15:01:57 +00:00
Makto94 commented 2026-11-24 16:03:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-24T15:14:31Z.


Hardware check of this PR (head of pr-1548, clean worktree build).

  • Adapter: NVIDIA GeForce RTX 3070 Ti, driver 621.01; Windows 11 Pro build 26300 (Insider); debug layer not enabled explicitly
  • Command: ctest --preset dev --no-tests=error -R '^(raw_buffer_uav|raw_buffer_uav_adjacent_control|vm_raw_uav_(warp|hardware))$' -j1
Test Result
raw_buffer_uav (new, no device) Passed
raw_buffer_uav_adjacent_control (negative control, WILL_FAIL) Passed
vm_raw_uav_warp Passed
vm_raw_uav_hardware Passed

No capability skips. Code read: the hand-worked expectations for touching windows, the top-of-address-space window and the widest 32-bit element count match resolve_raw_uav_store; each refusal also checks that the output is left unchanged.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135691610 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1548#issuecomment-7135691610). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-24T15:14:31Z. --- Hardware check of this PR (head of pr-1548, clean worktree build). - Adapter: NVIDIA GeForce RTX 3070 Ti, driver 621.01; Windows 11 Pro build 26300 (Insider); debug layer not enabled explicitly - Command: `ctest --preset dev --no-tests=error -R '^(raw_buffer_uav|raw_buffer_uav_adjacent_control|vm_raw_uav_(warp|hardware))$' -j1` | Test | Result | |---|---| | raw_buffer_uav (new, no device) | Passed | | raw_buffer_uav_adjacent_control (negative control, WILL_FAIL) | Passed | | vm_raw_uav_warp | Passed | | vm_raw_uav_hardware | Passed | No capability skips. Code read: the hand-worked expectations for touching windows, the top-of-address-space window and the widest 32-bit element count match `resolve_raw_uav_store`; each refusal also checks that the output is left unchanged.
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!1541
No description provided.