runtime: check the per-adapter GPU usage total in either order #1499

Manually merged
github merged 1 commit from gh-pr/1499/head into gh-pr/1499/base 2026-11-26 23:12:01 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 13:00 UTC · original
Asimmimx:runtime/xmem-gpu-usage-check → main · +7 −1 · 2 files · 1 commits · merged 2026-11-24 13:30 UTC

Change

XMemGetWorkingSetStatistics publishes this process's GPU memory as the total that xmem_gpu_usage::total() combines from per-adapter readings (src/xmem_gpu_usage.{h,cpp}). docs/experiments.md gives the rules with no dependence on adapter order:

  • an unidentified adapter with memory, or linked adapters that only partly overlap, give no total;
  • aliases are counted once;
  • the sum is published only when it fits.

xmem_shim_working_set_aggregation already feeds total() synthetic readings. But each order-sensitive case lists the adapters in one order only, and no case sums to exactly UINT64_MAX. So three single-point mutants of the header left the aggregation, working-set and working-set WARP tests passing:

  • same_devices comparing in one direction only (within(a, b));
  • unknown_active |= written as =;
  • the overflow guard > written as >=, which refuses a sum of exactly UINT64_MAX.

This adds three hand-worked cases to the existing aggregation_checks() table:

Case Readings Expected
unidentified_first unidentified adapter with 64 MiB, then identified {gpu_a} with 64 MiB no total
linked_partial_overlap_second {gpu_a} then {gpu_a, gpu_b}, 64 MiB each no total
sum_fits_exactly UINT64_MAX - 1 on {gpu_a} plus 1 on {gpu_b} UINT64_MAX

The first two are the existing unidentified and linked_partial_overlap cases with the adapters swapped. Only tests/xmem_shim_check.cpp and one sentence in the xmem_shim_working_set_aggregation row of docs/experiments.md change. There is no new CTest.

Verification

Commit 3c6273ac (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 '^xmem_shim_(working_set_aggregation|working_set|working_set_warp)$' -V
#   3/3 passed. The new cases print: unidentified_first declined ok,
#   linked_partial_overlap_second declined ok, sum_fits_exactly total=18446744073709551615 ok

The 10 non-hardware xmem_shim_* tests passed after a clean rebuild. 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 xmem_shim_check, ran the three tests, then reverted. None of this is committed.

Mutant Existing With the new cases
control: drop the !enumeration_complete check killed killed
ignore the queried flag killed killed
alias counted twice killed killed
same_devices one direction only survived killed
`unknown_active =→=` survived
active > 1 → active > 2 killed killed
overflow guard > → >= survived killed
overflow guard dropped killed killed
exact == key comparison killed killed
max instead of sum killed killed
partial overlap → continue killed killed
domain_bytes reads only group 0 killed killed
nodes == 0 returns 0 killed killed
.cpp: domain.queried = true always survived survived

The last row is in process_bytes(), which only real DXGI reaches. Covering it would need a seam in src/, which this test-only change leaves out. There is no --mutate control here either, because the faults are in the inline header and the test cannot inject them without a src/ hook.

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).

**@⁠Asimmimx** on GitHub · 2026-11-24 13:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1499) `Asimmimx:runtime/xmem-gpu-usage-check` → `main` · +7 −1 · 2 files · 1 commits · merged 2026-11-24 13:30 UTC ## Change `XMemGetWorkingSetStatistics` publishes this process's GPU memory as the total that `xmem_gpu_usage::total()` combines from per-adapter readings (`src/xmem_gpu_usage.{h,cpp}`). `docs/experiments.md` gives the rules with no dependence on adapter order: - an unidentified adapter with memory, or linked adapters that only partly overlap, give no total; - aliases are counted once; - the sum is published only when it fits. `xmem_shim_working_set_aggregation` already feeds `total()` synthetic readings. But each order-sensitive case lists the adapters in one order only, and no case sums to exactly `UINT64_MAX`. So three single-point mutants of the header left the aggregation, working-set and working-set WARP tests passing: - `same_devices` comparing in one direction only (`within(a, b)`); - `unknown_active |=` written as `=`; - the overflow guard `>` written as `>=`, which refuses a sum of exactly `UINT64_MAX`. This adds three hand-worked cases to the existing `aggregation_checks()` table: | Case | Readings | Expected | |---|---|---| | `unidentified_first` | unidentified adapter with 64 MiB, then identified `{gpu_a}` with 64 MiB | no total | | `linked_partial_overlap_second` | `{gpu_a}` then `{gpu_a, gpu_b}`, 64 MiB each | no total | | `sum_fits_exactly` | `UINT64_MAX - 1` on `{gpu_a}` plus 1 on `{gpu_b}` | `UINT64_MAX` | The first two are the existing `unidentified` and `linked_partial_overlap` cases with the adapters swapped. Only `tests/xmem_shim_check.cpp` and one sentence in the `xmem_shim_working_set_aggregation` row of `docs/experiments.md` change. There is no new CTest. ## Verification Commit `3c6273ac` (`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 '^xmem_shim_(working_set_aggregation|working_set|working_set_warp)$' -V # 3/3 passed. The new cases print: unidentified_first declined ok, # linked_partial_overlap_second declined ok, sum_fits_exactly total=18446744073709551615 ok ``` The 10 non-hardware `xmem_shim_*` tests passed after a clean rebuild. `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 `xmem_shim_check`, ran the three tests, then reverted. None of this is committed. | Mutant | Existing | With the new cases | |---|---|---| | control: drop the `!enumeration_complete` check | killed | killed | | ignore the `queried` flag | killed | killed | | alias counted twice | killed | killed | | `same_devices` one direction only | **survived** | killed | | `unknown_active |=` → `=` | **survived** | killed | | `active > 1` → `active > 2` | killed | killed | | overflow guard `>` → `>=` | **survived** | killed | | overflow guard dropped | killed | killed | | exact `==` key comparison | killed | killed | | max instead of sum | killed | killed | | partial overlap → `continue` | killed | killed | | `domain_bytes` reads only group 0 | killed | killed | | `nodes == 0` returns 0 | killed | killed | | `.cpp`: `domain.queried = true` always | survived | survived | The last row is in `process_bytes()`, which only real DXGI reaches. Covering it would need a seam in `src/`, which this test-only change leaves out. There is no `--mutate` control here either, because the faults are in the inline header and the test cannot inject them without a `src/` hook. ## 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).
xmem_gpu_usage::total() combines the per-LUID readings behind the
XMemGetWorkingSetStatistics value at +8. Its documented rules do not
depend on adapter order, but xmem_shim_working_set_aggregation tested
the unknown-identity and partial-overlap rules only with the identified
or larger adapter first, and tested the overflow guard only past the
limit. Three single-point mutants left the aggregation, working_set and
working_set_warp tests passing: same_devices() checking one direction
only, unknown_active assigned instead of or-ed, and the overflow guard
comparing with >= so a sum of exactly UINT64_MAX is declined.

Add the two order-swapped cases (an unidentified active adapter before
an identified active one, and a key subset before its superset), which
must give no total, and a sum of exactly UINT64_MAX, which must be
published. Each of the three mutants now fails the test. Ten further
mutants (including dropping the enumeration_complete check, ignoring
queried, counting aliases twice, a dropped guard, exact key comparison,
max instead of sum, ignoring partial overlap, reading one segment group
and an unknown node count read as zero) were already caught.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:11:59 +00:00
github manually merged commit 53bbb4426c into gh-pr/1499/base 2026-11-26 23:12:01 +00:00
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-24 13:04 UTC · original

All three mutants are caught now — reproduced locally

Independent reviewer, not the author. Reviewed 53bbb442; nothing pushed to the branch. The mutations below were made
locally in src/xmem_gpu_usage.h, rebuilt, reverted; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11.

cmake --preset dev
cmake --build --preset dev --target xmem_shim_check
ctest --preset dev --no-tests=error -R '^xmem_shim_working_set'

Unmodified branch — 4 of 4 pass: xmem_shim_working_set, _aggregation, _warp and _hardware.

Mutant 1 — same_devices compares one direction

-return within(a, b) && within(b, a);
+return within(a, b);
xmem_shim_working_set ............... Passed
xmem_shim_working_set_aggregation ... ***Failed
xmem_shim_working_set_warp .......... Passed
xmem_shim_working_set_hardware ...... Passed

Mutant 2 — unknown_active assigned instead of or-ed

-unknown_active |= domain.devices.empty();
+unknown_active  = domain.devices.empty();
xmem_shim_working_set_aggregation ... ***Failed

Mutant 3 — overflow guard refuses an exact UINT64_MAX sum

-if (bytes > UINT64_MAX - sum) return false;
+if (bytes >= UINT64_MAX - sum) return false;
xmem_shim_working_set_aggregation ... ***Failed

For mutants 2 and 3 I re-ran only the aggregation case; for mutant 1 I ran all four and the other three stayed green,
which matches your statement that the three mutants previously survived.

One observation, not a request

The other cases in the same binary keep printing declined ok on every run, including the failing ones, so the only
signal in the output is the process exit code and the xmem_shim_working_set_aggregation: FAILED summary. If you
already rely on that, fine — a per-case name ok/name FAILED line would make a mutant run readable without the exit
code. Your call; it does not block anything.

Verdict

Reviewed 53bbb442. +7/-1 on one test file plus the docs line, all four cases pass as-is, and each of the three
single-point mutants you name now fails the aggregation case. No objection from me.

**@⁠ChazY11** on GitHub · 2026-11-24 13:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1499#issuecomment-7132302134) ## All three mutants are caught now — reproduced locally Independent reviewer, not the author. Reviewed `53bbb442`; nothing pushed to the branch. The mutations below were made locally in `src/xmem_gpu_usage.h`, rebuilt, reverted; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11. ```powershell cmake --preset dev cmake --build --preset dev --target xmem_shim_check ctest --preset dev --no-tests=error -R '^xmem_shim_working_set' ``` Unmodified branch — 4 of 4 pass: `xmem_shim_working_set`, `_aggregation`, `_warp` and `_hardware`. ### Mutant 1 — `same_devices` compares one direction ```diff -return within(a, b) && within(b, a); +return within(a, b); ``` ```text xmem_shim_working_set ............... Passed xmem_shim_working_set_aggregation ... ***Failed xmem_shim_working_set_warp .......... Passed xmem_shim_working_set_hardware ...... Passed ``` ### Mutant 2 — `unknown_active` assigned instead of or-ed ```diff -unknown_active |= domain.devices.empty(); +unknown_active = domain.devices.empty(); ``` ```text xmem_shim_working_set_aggregation ... ***Failed ``` ### Mutant 3 — overflow guard refuses an exact `UINT64_MAX` sum ```diff -if (bytes > UINT64_MAX - sum) return false; +if (bytes >= UINT64_MAX - sum) return false; ``` ```text xmem_shim_working_set_aggregation ... ***Failed ``` For mutants 2 and 3 I re-ran only the aggregation case; for mutant 1 I ran all four and the other three stayed green, which matches your statement that the three mutants previously survived. ### One observation, not a request The other cases in the same binary keep printing `declined ok` on every run, including the failing ones, so the only signal in the output is the process exit code and the `xmem_shim_working_set_aggregation: FAILED` summary. If you already rely on that, fine — a per-case `name ok`/`name FAILED` line would make a mutant run readable without the exit code. Your call; it does not block anything. ### Verdict Reviewed `53bbb442`. +7/-1 on one test file plus the docs line, all four cases pass as-is, and each of the three single-point mutants you name now fails the aggregation case. No objection from me.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 13:14 UTC · original · reviewed

Reviewed 53bbb4426ca3b8c27aaff8c4973c7803e4f83ae1 (tests/xmem_shim_check.cpp and docs/experiments.md).

Audit

  • Order-independence & boundary coverage: unidentified_first ({unidentified}, {gpu_a} -> std::nullopt) exercises unknown_active |= domain.devices.empty() in src/xmem_gpu_usage.h, linked_partial_overlap_second ({gpu_a}, {gpu_a, gpu_b} -> std::nullopt) exercises both directions of detail::same_devices(a, b), and sum_fits_exactly (UINT64_MAX - 1 + 1 -> UINT64_MAX) exercises the bytes > UINT64_MAX - sum guard in detail::add.
  • Docs & hygiene: docs/experiments.md accurately documents the new cases and reproduction command; title-neutral, no UB, and no unrelated changes.

Checks

  • Linux: tests/docs_links_check.py (16 Markdown files, 334 links), tests/bidi_controls_check.py (1223 tracked files), and git diff --check all passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): built xmem_shim_check (4.14s); ctest --preset dev -R '^xmem_shim_(working_set_aggregation|working_set|working_set_warp)$' --no-tests=error — 3/3 passed (0.23s).
    • Release /O2 (--preset release): built xmem_shim_check (2.17s); ctest --preset release -R '^xmem_shim_(working_set_aggregation|working_set|working_set_warp)$' --no-tests=error — 3/3 passed (0.23s).
**@⁠tedin7** on GitHub · 2026-11-24 13:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1499#pullrequestreview-6039832297) · **reviewed** Reviewed `53bbb4426ca3b8c27aaff8c4973c7803e4f83ae1` (`tests/xmem_shim_check.cpp` and `docs/experiments.md`). ### Audit - **Order-independence & boundary coverage**: `unidentified_first` (`{unidentified}, {gpu_a}` -> `std::nullopt`) exercises `unknown_active |= domain.devices.empty()` in `src/xmem_gpu_usage.h`, `linked_partial_overlap_second` (`{gpu_a}, {gpu_a, gpu_b}` -> `std::nullopt`) exercises both directions of `detail::same_devices(a, b)`, and `sum_fits_exactly` (`UINT64_MAX - 1` + `1` -> `UINT64_MAX`) exercises the `bytes > UINT64_MAX - sum` guard in `detail::add`. - **Docs & hygiene**: `docs/experiments.md` accurately documents the new cases and reproduction command; title-neutral, no UB, and no unrelated changes. ### Checks - **Linux**: `tests/docs_links_check.py` (16 Markdown files, 334 links), `tests/bidi_controls_check.py` (1223 tracked files), and `git diff --check` all passed. - **Windows Server 2025** (Build 26100, MSVC 14.44.35207 + D3D12 WARP): - **Debug (`--preset dev`)**: built `xmem_shim_check` (`4.14s`); `ctest --preset dev -R '^xmem_shim_(working_set_aggregation|working_set|working_set_warp)$' --no-tests=error` — **3/3 passed** (`0.23s`). - **Release `/O2` (`--preset release`)**: built `xmem_shim_check` (`2.17s`); `ctest --preset release -R '^xmem_shim_(working_set_aggregation|working_set|working_set_warp)$' --no-tests=error` — **3/3 passed** (`0.23s`).
This discussion has been locked. Commenting is limited to contributors.
No description provided.