startup: check every field of a buffer memory SRV #1670

Merged
Asimmimx merged 1 commit from upstream-pr/1677 into main 2026-11-24 17:12:11 +00:00
Asimmimx commented 2026-11-24 16:56:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T16:56:46Z.


Refs #1149.

Change

src/startup_stubs/memory_srv_buffer.h validates and resolves buffer memory SRVs for device slot 70. supports_buffer_memory_srv checks the buffer description and the view (raw R32_TYPELESS, structured with a stride that is a multiple of 4 up to 2048, or typed) against the buffer width. resolve_buffer_srv_desc turns a title address inside a live buffer into a view with an adjusted FirstElement and checks bounds and raw 16-byte alignment. typed_buffer_format_bytes also gives the element stride that translated draws bind (d3d12_draw.inl).

Two tests reach the header:

  • startup_memory_srv_buffer is device-free and calls the three functions directly;
  • startup_address_buffer_srv_* runs the resolve path on a device, with valid addresses only.

24 of 34 single-point mutants of the header left the device-free check passing (table below). Among them were every buffer description field except the deny flag, exact-fit bounds, 32-bit truncation of the width and of the resolved first element, and five typed element-size mutants. A wrong element size there also gives translated draws the wrong stride.

This PR adds hand-worked cases to tests/startup_memory_srv_buffer_check.cpp and does not change any existing case:

Case What it pins
Height 2, DepthOrArraySize 2, MipLevels 2, Format R32_TYPELESS, 4 samples, quality 1, layout UNKNOWN, alignment 4 KiB: each refused each buffer description field, changed alone
alignment 64 KiB accepted the second allowed alignment
view dimension TEXTURE2D, mapping (3,2,1,0), flag bit 2 on a typed and on a raw view: each refused view fields outside the element size
structured stride 2048: 2048 element bytes, accepted on a 4096-byte buffer the inclusive stride limit
element bytes of all 42 typed formats in the switch, from bits per element every table entry
raw_view(0, 256) and R8 typed_view(0, 1024) on 1024 bytes accepted; (1, 256), (256, 1) and R8 1025 refused exact fit in supports_buffer_memory_srv
resolve at +0x10 (252 elements left): raw_view(4, 248) gives FirstElement 8, NumElements 248; raw_view(4, 249) refused exact fit in resolve
resolve at +0x20, stride 16 (62 left): FirstElement 63 refused the FirstElement bound in resolve (it would otherwise wrap)
raw (1, 4) at offset 12 gives FirstElement 4; at offset 16 refused raw alignment of the adjusted first element, not of the offset
width 0x100000400: raw_view(0x40000000, 0x40) accepted, 0x101 refused 64-bit width
R8 at base 0x200000000, width 8 GiB: address +4 GiB with FirstElement 0x10 gives 0x100000010; FirstElement 0x100000000 at the base is kept 64-bit resolved first element

Three negative controls are registered with WILL_FAIL next to the existing test:

Control Expects Fails on
startup_memory_srv_buffer_height_control a Height 2 buffer accepted resource height 2
startup_memory_srv_buffer_exact-fit_control an exact-fit view refused raw exact fit, typed R8 exact fit, raw resolve exact fit
startup_memory_srv_buffer_first-32_control the resolved FirstElement cut to 32 bits typed R8 resolve 4 GiB in, typed R8 resolve 64-bit first element

The change also corrects the check's top comment and the CMake comment, which said the check covers acceleration-structure views (the header refuses them). It adds two sentences and the control command to the "Buffer memory SRVs (device slot 70)" section of docs/startup-runtime.md. The header itself is not changed.

Mutation probe

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

Mutant Existing check With the new cases
Height == 1 dropped survived killed
DepthOrArraySize == 1 dropped survived killed
MipLevels == 1 dropped survived killed
resource Format == UNKNOWN dropped survived killed
sample count and quality dropped survived killed
Layout == ROW_MAJOR dropped survived killed
64 KiB alignment refused survived killed
any alignment accepted survived killed
deny-shader-resource flag ignored killed killed
ViewDimension == BUFFER dropped survived killed
component mapping check dropped survived killed
NumElements == 0 accepted killed killed
unknown view flags accepted survived killed
raw format check dropped killed killed
raw stride check dropped killed killed
structured format check dropped killed killed
stride > 2048 to >= 2048 survived killed
stride % 4 to % 2 killed killed
8-byte formats return 4 survived killed
4-byte formats return 8 survived killed
1-byte formats return 2 survived killed
R11G11B10_FLOAT moved to the 8-byte group survived killed
R10G10B10A2_UINT dropped (returns 0) survived killed
supports: NumElements <= to < survived killed
supports: width cut to 32 bits survived killed
resolve: !buffer_title_base dropped survived survived (not pinned, see below)
resolve: offset alignment dropped killed killed
resolve: FirstElement > avail dropped survived killed
resolve: NumElements > to >= survived killed
resolve: offset added in bytes, not elements killed killed
resolve: adjusted FirstElement cut to 32 bits survived killed
raw alignment of the offset only survived killed
raw alignment of the view's FirstElement only killed killed
raw alignment check dropped killed killed

Not pinned:

  • The !buffer_title_base guard in resolve_buffer_srv_desc. The only caller (device_memory_srv) passes the title memory of a buffer that existing_memory_buffer has already found at the address, so the guard cannot be reached from it.
  • Some mutants have the same behaviour as the header and are left out of the table: Width > 0 (a zero width leaves no element for a view with NumElements > 0), FirstElement <= to < in supports, address < base (the offset wraps and fails offset >= width), and offset >= to > in resolve.

Verification

Commit cd4ea26a on main c864f138, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0. No GPU is used.

cmake --build --preset dev --target startup_memory_srv_buffer_check
ctest --preset dev --no-tests=error -R '^startup_memory_srv_buffer' -V
#   4/4 passed: startup_memory_srv_buffer prints "slot 70 buffer memory SRV validation: all checks passed";
#   the height, exact-fit and first-32 controls exit 1 with the FAIL lines listed above (WILL_FAIL)
.\out\build\dev\startup_memory_srv_buffer_check.exe --mutate bogus
#   prints the usage line, exit 2

tests/docs_links_check.py (16 files, 350 links), tests/bidi_controls_check.py and git diff --check passed.

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:6587036352 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1677). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T16:56:46Z. --- Refs #1149. ## Change `src/startup_stubs/memory_srv_buffer.h` validates and resolves buffer memory SRVs for device slot 70. `supports_buffer_memory_srv` checks the buffer description and the view (raw `R32_TYPELESS`, structured with a stride that is a multiple of 4 up to 2048, or typed) against the buffer width. `resolve_buffer_srv_desc` turns a title address inside a live buffer into a view with an adjusted `FirstElement` and checks bounds and raw 16-byte alignment. `typed_buffer_format_bytes` also gives the element stride that translated draws bind (`d3d12_draw.inl`). Two tests reach the header: - `startup_memory_srv_buffer` is device-free and calls the three functions directly; - `startup_address_buffer_srv_*` runs the resolve path on a device, with valid addresses only. 24 of 34 single-point mutants of the header left the device-free check passing (table below). Among them were every buffer description field except the deny flag, exact-fit bounds, 32-bit truncation of the width and of the resolved first element, and five typed element-size mutants. A wrong element size there also gives translated draws the wrong stride. This PR adds hand-worked cases to `tests/startup_memory_srv_buffer_check.cpp` and does not change any existing case: | Case | What it pins | |---|---| | Height 2, DepthOrArraySize 2, MipLevels 2, Format `R32_TYPELESS`, 4 samples, quality 1, layout UNKNOWN, alignment 4 KiB: each refused | each buffer description field, changed alone | | alignment 64 KiB accepted | the second allowed alignment | | view dimension TEXTURE2D, mapping `(3,2,1,0)`, flag bit 2 on a typed and on a raw view: each refused | view fields outside the element size | | structured stride 2048: 2048 element bytes, accepted on a 4096-byte buffer | the inclusive stride limit | | element bytes of all 42 typed formats in the switch, from bits per element | every table entry | | `raw_view(0, 256)` and R8 `typed_view(0, 1024)` on 1024 bytes accepted; `(1, 256)`, `(256, 1)` and R8 1025 refused | exact fit in `supports_buffer_memory_srv` | | resolve at `+0x10` (252 elements left): `raw_view(4, 248)` gives FirstElement 8, NumElements 248; `raw_view(4, 249)` refused | exact fit in resolve | | resolve at `+0x20`, stride 16 (62 left): FirstElement 63 refused | the FirstElement bound in resolve (it would otherwise wrap) | | raw `(1, 4)` at offset 12 gives FirstElement 4; at offset 16 refused | raw alignment of the adjusted first element, not of the offset | | width `0x100000400`: `raw_view(0x40000000, 0x40)` accepted, `0x101` refused | 64-bit width | | R8 at base `0x200000000`, width 8 GiB: address `+4 GiB` with FirstElement 0x10 gives `0x100000010`; FirstElement `0x100000000` at the base is kept | 64-bit resolved first element | Three negative controls are registered with `WILL_FAIL` next to the existing test: | Control | Expects | Fails on | |---|---|---| | `startup_memory_srv_buffer_height_control` | a Height 2 buffer accepted | `resource height 2` | | `startup_memory_srv_buffer_exact-fit_control` | an exact-fit view refused | `raw exact fit`, `typed R8 exact fit`, `raw resolve exact fit` | | `startup_memory_srv_buffer_first-32_control` | the resolved FirstElement cut to 32 bits | `typed R8 resolve 4 GiB in`, `typed R8 resolve 64-bit first element` | The change also corrects the check's top comment and the CMake comment, which said the check covers acceleration-structure views (the header refuses them). It adds two sentences and the control command to the "Buffer memory SRVs (device slot 70)" section of `docs/startup-runtime.md`. The header itself is not changed. ## Mutation probe I applied each mutation to the header alone, rebuilt `startup_memory_srv_buffer_check`, ran it, then reverted. None of this is committed. | Mutant | Existing check | With the new cases | |---|---|---| | `Height == 1` dropped | **survived** | killed | | `DepthOrArraySize == 1` dropped | **survived** | killed | | `MipLevels == 1` dropped | **survived** | killed | | resource `Format == UNKNOWN` dropped | **survived** | killed | | sample count and quality dropped | **survived** | killed | | `Layout == ROW_MAJOR` dropped | **survived** | killed | | 64 KiB alignment refused | **survived** | killed | | any alignment accepted | **survived** | killed | | deny-shader-resource flag ignored | killed | killed | | `ViewDimension == BUFFER` dropped | **survived** | killed | | component mapping check dropped | **survived** | killed | | `NumElements == 0` accepted | killed | killed | | unknown view flags accepted | **survived** | killed | | raw format check dropped | killed | killed | | raw stride check dropped | killed | killed | | structured format check dropped | killed | killed | | stride `> 2048` to `>= 2048` | **survived** | killed | | stride `% 4` to `% 2` | killed | killed | | 8-byte formats return 4 | **survived** | killed | | 4-byte formats return 8 | **survived** | killed | | 1-byte formats return 2 | **survived** | killed | | `R11G11B10_FLOAT` moved to the 8-byte group | **survived** | killed | | `R10G10B10A2_UINT` dropped (returns 0) | **survived** | killed | | supports: `NumElements <=` to `<` | **survived** | killed | | supports: width cut to 32 bits | **survived** | killed | | resolve: `!buffer_title_base` dropped | **survived** | **survived** (not pinned, see below) | | resolve: offset alignment dropped | killed | killed | | resolve: `FirstElement > avail` dropped | **survived** | killed | | resolve: `NumElements >` to `>=` | **survived** | killed | | resolve: offset added in bytes, not elements | killed | killed | | resolve: adjusted FirstElement cut to 32 bits | **survived** | killed | | raw alignment of the offset only | **survived** | killed | | raw alignment of the view's FirstElement only | killed | killed | | raw alignment check dropped | killed | killed | Not pinned: - The `!buffer_title_base` guard in `resolve_buffer_srv_desc`. The only caller (`device_memory_srv`) passes the title memory of a buffer that `existing_memory_buffer` has already found at the address, so the guard cannot be reached from it. - Some mutants have the same behaviour as the header and are left out of the table: `Width > 0` (a zero width leaves no element for a view with NumElements > 0), `FirstElement <=` to `<` in supports, `address < base` (the offset wraps and fails `offset >= width`), and `offset >=` to `>` in resolve. ## Verification Commit `cd4ea26a` on `main` `c864f138`, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0. No GPU is used. ```powershell cmake --build --preset dev --target startup_memory_srv_buffer_check ctest --preset dev --no-tests=error -R '^startup_memory_srv_buffer' -V # 4/4 passed: startup_memory_srv_buffer prints "slot 70 buffer memory SRV validation: all checks passed"; # the height, exact-fit and first-32 controls exit 1 with the FAIL lines listed above (WILL_FAIL) .\out\build\dev\startup_memory_srv_buffer_check.exe --mutate bogus # prints the usage line, exit 2 ``` `tests/docs_links_check.py` (16 files, 350 links), `tests/bidi_controls_check.py` and `git diff --check` passed. ## 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 18:02:26 +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!1670
No description provided.