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

Merged
Asimmimx merged 1 commit from upstream-pr/1499 into main 2026-11-24 13:30:19 +00:00
Asimmimx commented 2026-11-24 13:00:42 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582353220 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1499). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T13:00:42Z. --- ## 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).
upstream-sync closed this pull request 2026-11-24 14:02:58 +00:00
tedin7 commented 2026-11-24 14:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:14:56Z.

Review: COMMENTED


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).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039832297 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1499#pullrequestreview-6039832297). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:14:56Z. **Review:** COMMENTED --- 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`).
ChazY11 commented 2026-11-24 14:03:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T13:04:04Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132302134 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1499#issuecomment-7132302134). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T13:04:04Z. --- ## 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.
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!1492
No description provided.