d3d12: count slot 133 placements by backing #3679

Manually merged
github merged 3 commits from github-bot/gh-3677 into main 2026-12-01 01:25:49 +00:00 AGit
Owner

@⁠Not-Saii on GitHub · 2026-12-01 00:33 UTC · original
Not-Saii:claude/xbox2windows-issue-3676-df1c44 → main · +369 −8 · 5 files · 3 commits · merged 2026-12-01 01:25 UTC

Change

Item (b) of #3678: a census of how device slot 133 backs the buffers it places, so the "Use by allocation" measurement from #1914 can be read from any run. Logging and counters only. The backing slot 133 chooses for a buffer is unchanged.

  • placed_refusal in src/startup_stubs/placed_buffer_range.h returns the first reason the default backing refuses the existing heap. The checks run in this order: mapped, uncovered, unaligned, acceleration-structure. The caller then checks the opt-in size cap (capped), keeping the region query short-circuited as before. Because of this order, unaligned means private, fully committed memory that is refused only by the 64 KiB offset rule. #3678 guesses that is why about 7,600 placements are not shared; this census can confirm or refute that.
  • Each placement slot 133 returns is counted in one class: shared, copied-at-submit (linear backing), the five refusals, or create-failed (every precondition held, but D3D12 refused the heap or the placement). Each class keeps buffer count, requested bytes (Width), and the UAV-capable share (sanitized ALLOW_UNORDERED_ACCESS at creation, the linear line's definition; not an observed GPU write). Placements that fail with E_INVALIDARG are not counted.
  • The default slot 133 line now ends with type=0x… backing=<class>. The fields are appended after gpuva= so triage_run.py and startup_direct_index_late_write_check.py still match.
  • A new five-second line follows the existing placed-buffer totals: x2w-d3d12 placed buffers by backing: shared N/bytes (uav-capable N/bytes), …. It lists every class, zeros included, with counts since the start (like placed_buffer_calls).
  • A new export, x2w_d3d12_placed_backing_snapshot, returns the counts for tests.
  • docs/startup-runtime.md describes the fields and the order.

Shared interface: the slot 133 log line (appended fields only). Leaves (a), (c), (d) and (e) of #3678 alone.

Refs #3678, Refs #1914

Verification

Base: rebased on main at a3bfd019. Build: cmake --preset dev, then cmake --build --preset dev --target startup_placed_backing_census_check startup_slot133_heap_cap_check d3d12_xs_shim xmem_shim, on Windows 11 build 26300 with Windows SDK 10.0.26100. Debug layer off.

ctest --preset dev --no-tests=error -R '^(startup_placed_backing_census_(warp|hardware)|startup_slot133_heap_cap_(capped_)?warp(_debug0)?)$'
Test Adapter Result
startup_placed_backing_census_warp Microsoft Basic Render Driver 10.0.26100.9818 Passed
startup_placed_backing_census_hardware NVIDIA GeForce RTX 4090, driver 32.0.16.1088 Passed
startup_slot133_heap_cap_warp_debug0 WARP Passed
startup_slot133_heap_cap_capped_warp WARP Passed

No capability skips. Both adapters print the same census:

x2w-d3d12 placed buffers by backing: shared 2/131072 (uav-capable 1/65536), copied-at-submit 0/0 (uav-capable 0/0), mapped 1/4096 (uav-capable 0/0), uncovered 1/131072 (uav-capable 0/0), unaligned 2/12288 (uav-capable 1/8192), acceleration-structure 1/65536 (uav-capable 1/65536), capped 1/65536 (uav-capable 0/0), create-failed 1/65536 (uav-capable 0/0)

tests/startup_triage_run_check.py: 0 failed. tests/docs_links_check.py: 195 files, 755 links checked.

Negative control. placed_refusal was changed locally to test the offset first, and d3d12_xs.dll was rebuilt. startup_placed_backing_census_warp then failed 8 checks: the mapped and uncovered buffers, which sit at offsets that are not multiples of 64 KiB, were counted as unaligned 4/147456. The change was reverted before the runs above.

Not run: the X2W_D3D12_DEBUG=1 variants, copied-at-submit (it needs X2W_D3D12_LINEAR_BUFFERS; the fixture clears it and checks 0), and any title run.

Evidence and follow-up

The fixture tests/startup_placed_backing_census_check.cpp is source-built and uses only VirtualAlloc and page-file section memory. It contains no title data.

  • shared: a private, fully committed allocation, placed at aligned offsets.
  • unaligned: the same allocation at +132 KiB and +140 KiB.
  • acceleration-structure: the same allocation at +256 KiB, in RTAS state.
  • mapped: a section view at +4 KiB.
  • uncovered: 128 KiB at +4 KiB in a 256 KiB reservation of which only the first 64 KiB is committed.
  • capped: a 260 MiB reservation with 64 KiB committed, with X2W_D3D12_CAP_EXISTING_HEAP=1.
  • create-failed: a private, fully committed allocation made PAGE_READONLY. It passes every precondition, and OpenExistingHeapFromAddress refuses it on both adapters above. That is an observed driver behaviour, not a documented contract.

The test skips (77) on an adapter without D3D12_FEATURE_EXISTING_HEAPS.

Assumption: mapped covers every non-private type, MEM_IMAGE included. The line's type= field separates them.

Follow-up for #3678: the census does not record XMem attributes or page size, so it covers only part of the "Use by allocation" ask in #1914. Whether the CPU rewrites memory after submission is the dirty-signal work already claimed on #1914.

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.

This change was AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠Not-Saii** on GitHub · 2026-12-01 00:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3677) `Not-Saii:claude/xbox2windows-issue-3676-df1c44` → `main` · +369 −8 · 5 files · 3 commits · merged 2026-12-01 01:25 UTC ## Change Item (b) of #3678: a census of how device slot 133 backs the buffers it places, so the "Use by allocation" measurement from #1914 can be read from any run. Logging and counters only. The backing slot 133 chooses for a buffer is unchanged. - `placed_refusal` in `src/startup_stubs/placed_buffer_range.h` returns the first reason the default backing refuses the existing heap. The checks run in this order: `mapped`, `uncovered`, `unaligned`, `acceleration-structure`. The caller then checks the opt-in size cap (`capped`), keeping the region query short-circuited as before. Because of this order, `unaligned` means private, fully committed memory that is refused only by the 64 KiB offset rule. #3678 guesses that is why about 7,600 placements are not shared; this census can confirm or refute that. - Each placement slot 133 returns is counted in one class: `shared`, `copied-at-submit` (linear backing), the five refusals, or `create-failed` (every precondition held, but D3D12 refused the heap or the placement). Each class keeps buffer count, requested bytes (`Width`), and the UAV-capable share (sanitized `ALLOW_UNORDERED_ACCESS` at creation, the linear line's definition; not an observed GPU write). Placements that fail with `E_INVALIDARG` are not counted. - The default slot 133 line now ends with `type=0x… backing=<class>`. The fields are appended after `gpuva=` so `triage_run.py` and `startup_direct_index_late_write_check.py` still match. - A new five-second line follows the existing placed-buffer totals: `x2w-d3d12 placed buffers by backing: shared N/bytes (uav-capable N/bytes), …`. It lists every class, zeros included, with counts since the start (like `placed_buffer_calls`). - A new export, `x2w_d3d12_placed_backing_snapshot`, returns the counts for tests. - `docs/startup-runtime.md` describes the fields and the order. Shared interface: the slot 133 log line (appended fields only). Leaves (a), (c), (d) and (e) of #3678 alone. Refs #3678, Refs #1914 ## Verification Base: rebased on `main` at `a3bfd019`. Build: `cmake --preset dev`, then `cmake --build --preset dev --target startup_placed_backing_census_check startup_slot133_heap_cap_check d3d12_xs_shim xmem_shim`, on Windows 11 build 26300 with Windows SDK 10.0.26100. Debug layer off. ``` ctest --preset dev --no-tests=error -R '^(startup_placed_backing_census_(warp|hardware)|startup_slot133_heap_cap_(capped_)?warp(_debug0)?)$' ``` | Test | Adapter | Result | |---|---|---| | `startup_placed_backing_census_warp` | Microsoft Basic Render Driver 10.0.26100.9818 | Passed | | `startup_placed_backing_census_hardware` | NVIDIA GeForce RTX 4090, driver 32.0.16.1088 | Passed | | `startup_slot133_heap_cap_warp_debug0` | WARP | Passed | | `startup_slot133_heap_cap_capped_warp` | WARP | Passed | No capability skips. Both adapters print the same census: ``` x2w-d3d12 placed buffers by backing: shared 2/131072 (uav-capable 1/65536), copied-at-submit 0/0 (uav-capable 0/0), mapped 1/4096 (uav-capable 0/0), uncovered 1/131072 (uav-capable 0/0), unaligned 2/12288 (uav-capable 1/8192), acceleration-structure 1/65536 (uav-capable 1/65536), capped 1/65536 (uav-capable 0/0), create-failed 1/65536 (uav-capable 0/0) ``` `tests/startup_triage_run_check.py`: 0 failed. `tests/docs_links_check.py`: 195 files, 755 links checked. **Negative control.** `placed_refusal` was changed locally to test the offset first, and `d3d12_xs.dll` was rebuilt. `startup_placed_backing_census_warp` then failed 8 checks: the mapped and uncovered buffers, which sit at offsets that are not multiples of 64 KiB, were counted as `unaligned 4/147456`. The change was reverted before the runs above. Not run: the `X2W_D3D12_DEBUG=1` variants, `copied-at-submit` (it needs `X2W_D3D12_LINEAR_BUFFERS`; the fixture clears it and checks 0), and any title run. ## Evidence and follow-up The fixture `tests/startup_placed_backing_census_check.cpp` is source-built and uses only `VirtualAlloc` and page-file section memory. It contains no title data. - `shared`: a private, fully committed allocation, placed at aligned offsets. - `unaligned`: the same allocation at +132 KiB and +140 KiB. - `acceleration-structure`: the same allocation at +256 KiB, in RTAS state. - `mapped`: a section view at +4 KiB. - `uncovered`: 128 KiB at +4 KiB in a 256 KiB reservation of which only the first 64 KiB is committed. - `capped`: a 260 MiB reservation with 64 KiB committed, with `X2W_D3D12_CAP_EXISTING_HEAP=1`. - `create-failed`: a private, fully committed allocation made `PAGE_READONLY`. It passes every precondition, and `OpenExistingHeapFromAddress` refuses it on both adapters above. That is an observed driver behaviour, not a documented contract. The test skips (77) on an adapter without `D3D12_FEATURE_EXISTING_HEAPS`. Assumption: `mapped` covers every non-private type, `MEM_IMAGE` included. The line's `type=` field separates them. Follow-up for #3678: the census does not record XMem attributes or page size, so it covers only part of the "Use by allocation" ask in #1914. Whether the CPU rewrites memory after submission is the dirty-signal work already claimed on #1914. ## 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. This change was AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Each buffer slot 133 returns is counted in one class: shared, copied-at-submit,
mapped, uncovered, unaligned, acceleration-structure, capped or create-failed,
with requested bytes and the GPU-written share. The slot 133 line ends with
type= and backing=, a five-second "placed buffers by backing" line follows the
placed-buffer totals, and x2w_d3d12_placed_backing_snapshot exports the counts.
The backing chosen is unchanged.

Refs #3676

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #3676

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 00:37:32 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-01 01:12 UTC · original · requested changes

Please label these counts UAV-capable throughout the log, exported snapshot, and docs. Both paths use ALLOW_UNORDERED_ACCESS to increment them at allocation time, which measures capability. The #3642 trace has a UAV-capable placement with changing application bytes and no GPU write observed on the desktop backing. Calling this counter gpu-written would misclassify that case during the producer investigation.

**@⁠R0Y00** on GitHub · 2026-12-01 01:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3677#pullrequestreview-6123412640) · **requested changes** Please label these counts `UAV-capable` throughout the log, exported snapshot, and docs. Both paths use `ALLOW_UNORDERED_ACCESS` to increment them at allocation time, which measures capability. The #3642 trace has a UAV-capable placement with changing application bytes and no GPU write observed on the desktop backing. Calling this counter `gpu-written` would misclassify that case during the producer investigation.
@ -140,0 +176,4 @@
{
int n = std::snprintf(out, size, "x2w-d3d12 placed buffers by backing:");
for (int i = 0; i < static_cast<int>(PlacedBacking::count) && n > 0 && static_cast<std::size_t>(n) < size; ++i)
n += std::snprintf(out + n, size - n, "%s %s %lld/%lld (gpu-written %lld/%lld)", i ? "," : "",
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-01 01:12 UTC · original

These totals are computed from ALLOW_UNORDERED_ACCESS when the buffer is placed. Use uav-capable so readers can tell the allocation flag from an observed GPU write.

**@⁠R0Y00** on GitHub · 2026-12-01 01:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3677#discussion_r4747849313) These totals are computed from `ALLOW_UNORDERED_ACCESS` when the buffer is placed. Use `uav-capable` so readers can tell the allocation flag from an observed GPU write.
The counts come from the creation flag, not from an observed GPU write, so
"gpu-written" would misclassify a UAV-capable buffer that only the CPU changes
(#3640). Renamed in the log line, PlacedBackingCounts (uav_buffers, uav_bytes),
the fixture and docs/startup-runtime.md.

Refs #3676

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠Not-Saii on GitHub · 2026-12-01 01:16 UTC · original
On src/startup_stubs/placed_buffer_range.h line 179 (outdated):

@@ -137,6 +139,47 @@ inline bool measure_placed_buffer(const void* address, std::uint64_t width, Plac
     return committed;
 }
 
+// How slot 133 backed a placed buffer it returned, for the census line and x2w_d3d12_placed_backing_snapshot
+// (#3676). shared: placed on the allocation's existing heap; copied_at_submit: the linear backing's copy
+// (X2W_D3D12_LINEAR_BUFFERS); every other class is a committed desktop copy and names the reason.
+enum class PlacedBacking : int {
+    shared, copied_at_submit, mapped, uncovered, unaligned, acceleration, capped, create_failed, count
+};
+constexpr const char* placed_backing_names[] = {"shared", "copied-at-submit", "mapped", "uncovered", "unaligned",
+                                                "acceleration-structure", "capped", "create-failed"};
+static_assert(sizeof(placed_backing_names) / sizeof(*placed_backing_names) == static_cast<int>(PlacedBacking::count));
+
+// Why the default backing refuses the existing heap, or shared when nothing refuses it. Checked in this order, so
+// unaligned means a private, covered range refused only by the 64 KiB offset rule. The opt-in size cap
+// (X2W_D3D12_CAP_EXISTING_HEAP) costs a region query and is checked by the caller after this returns shared.
+// Type 0 (a re-measure that found nothing committed) is not mapped memory; it falls through to uncovered.
+inline PlacedBacking placed_refusal(DWORD type, bool covered, std::uint64_t offset, bool acceleration)
+{
+    if (type && type != MEM_PRIVATE) return PlacedBacking::mapped;
+    if (!covered) return PlacedBacking::uncovered;
+    if (offset & 0xFFFF) return PlacedBacking::unaligned;
+    if (acceleration) return PlacedBacking::acceleration;
+    return PlacedBacking::shared;
+}
+
+// Placements slot 133 returned since the start, by class: buffers and requested bytes, then the GPU-written
+// (ALLOW_UNORDERED_ACCESS) share of each.
+struct PlacedBackingCounts {
+    long long buffers[static_cast<int>(PlacedBacking::count)];
+    long long bytes[static_cast<int>(PlacedBacking::count)];
+    long long gpu_buffers[static_cast<int>(PlacedBacking::count)];
+    long long gpu_bytes[static_cast<int>(PlacedBacking::count)];
+};
+
+// "x2w-d3d12 placed buffers by backing: shared N/bytes (gpu-written N/bytes), ..." with every class, zeros included.
+inline void placed_backing_line(const PlacedBackingCounts& c, char* out, std::size_t size)
+{
+    int n = std::snprintf(out, size, "x2w-d3d12 placed buffers by backing:");
+    for (int i = 0; i < static_cast<int>(PlacedBacking::count) && n > 0 && static_cast<std::size_t>(n) < size; ++i)
+        n += std::snprintf(out + n, size - n, "%s %s %lld/%lld (gpu-written %lld/%lld)", i ? "," : "",

Renamed in eb0c3ca3: uav_buffers/uav_bytes in PlacedBackingCounts, (uav-capable N/bytes) in the census line, and the comment now says the share comes from ALLOW_UNORDERED_ACCESS at creation, not from an observed GPU write.

**@⁠Not-Saii** on GitHub · 2026-12-01 01:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3677#discussion_r4747874993) On `src/startup_stubs/placed_buffer_range.h` line 179 (outdated): ```diff @@ -137,6 +139,47 @@ inline bool measure_placed_buffer(const void* address, std::uint64_t width, Plac return committed; } +// How slot 133 backed a placed buffer it returned, for the census line and x2w_d3d12_placed_backing_snapshot +// (#3676). shared: placed on the allocation's existing heap; copied_at_submit: the linear backing's copy +// (X2W_D3D12_LINEAR_BUFFERS); every other class is a committed desktop copy and names the reason. +enum class PlacedBacking : int { + shared, copied_at_submit, mapped, uncovered, unaligned, acceleration, capped, create_failed, count +}; +constexpr const char* placed_backing_names[] = {"shared", "copied-at-submit", "mapped", "uncovered", "unaligned", + "acceleration-structure", "capped", "create-failed"}; +static_assert(sizeof(placed_backing_names) / sizeof(*placed_backing_names) == static_cast<int>(PlacedBacking::count)); + +// Why the default backing refuses the existing heap, or shared when nothing refuses it. Checked in this order, so +// unaligned means a private, covered range refused only by the 64 KiB offset rule. The opt-in size cap +// (X2W_D3D12_CAP_EXISTING_HEAP) costs a region query and is checked by the caller after this returns shared. +// Type 0 (a re-measure that found nothing committed) is not mapped memory; it falls through to uncovered. +inline PlacedBacking placed_refusal(DWORD type, bool covered, std::uint64_t offset, bool acceleration) +{ + if (type && type != MEM_PRIVATE) return PlacedBacking::mapped; + if (!covered) return PlacedBacking::uncovered; + if (offset & 0xFFFF) return PlacedBacking::unaligned; + if (acceleration) return PlacedBacking::acceleration; + return PlacedBacking::shared; +} + +// Placements slot 133 returned since the start, by class: buffers and requested bytes, then the GPU-written +// (ALLOW_UNORDERED_ACCESS) share of each. +struct PlacedBackingCounts { + long long buffers[static_cast<int>(PlacedBacking::count)]; + long long bytes[static_cast<int>(PlacedBacking::count)]; + long long gpu_buffers[static_cast<int>(PlacedBacking::count)]; + long long gpu_bytes[static_cast<int>(PlacedBacking::count)]; +}; + +// "x2w-d3d12 placed buffers by backing: shared N/bytes (gpu-written N/bytes), ..." with every class, zeros included. +inline void placed_backing_line(const PlacedBackingCounts& c, char* out, std::size_t size) +{ + int n = std::snprintf(out, size, "x2w-d3d12 placed buffers by backing:"); + for (int i = 0; i < static_cast<int>(PlacedBacking::count) && n > 0 && static_cast<std::size_t>(n) < size; ++i) + n += std::snprintf(out + n, size - n, "%s %s %lld/%lld (gpu-written %lld/%lld)", i ? "," : "", ``` Renamed in eb0c3ca3: `uav_buffers`/`uav_bytes` in `PlacedBackingCounts`, `(uav-capable N/bytes)` in the census line, and the comment now says the share comes from `ALLOW_UNORDERED_ACCESS` at creation, not from an observed GPU write.
Author
Owner

@⁠Not-Saii on GitHub · 2026-12-01 01:16 UTC · original

Addressed in eb0c3ca3. The counts are labelled uav-capable throughout: the census line, the exported snapshot (PlacedBackingCounts::uav_buffers and uav_bytes), the fixture's cases and expected strings, and docs/startup-runtime.md. The doc now says the share comes from ALLOW_UNORDERED_ACCESS at creation and does not show that the GPU wrote the buffer. Nothing else changed. The linear backing's existing use=gpu-written|gpu-read field predates this PR and is unchanged. Not rebuilt locally after the rename; the Windows CI job builds it.

**@⁠Not-Saii** on GitHub · 2026-12-01 01:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3677#issuecomment-7297299619) Addressed in eb0c3ca3. The counts are labelled `uav-capable` throughout: the census line, the exported snapshot (`PlacedBackingCounts::uav_buffers` and `uav_bytes`), the fixture's cases and expected strings, and `docs/startup-runtime.md`. The doc now says the share comes from `ALLOW_UNORDERED_ACCESS` at creation and does not show that the GPU wrote the buffer. Nothing else changed. The linear backing's existing `use=gpu-written|gpu-read` field predates this PR and is unchanged. Not rebuilt locally after the rename; the Windows CI job builds it.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-01 01:19 UTC · original · approved these changes

The revised head names the allocation flag uav-capable in the log, the snapshot fields and documentation. I rechecked the formatting and both creation paths. ctest --test-dir <build> --no-tests=error -j1 -R '^startup_placed_backing_census_(warp|hardware)$' --output-on-failure passed in the integration on WARP and RTX 4060 Laptop. The adapter and Mesh57 runtime regressions also passed.

**@⁠R0Y00** on GitHub · 2026-12-01 01:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3677#pullrequestreview-6123477199) · **approved these changes** The revised head names the allocation flag `uav-capable` in the log, the snapshot fields and documentation. I rechecked the formatting and both creation paths. `ctest --test-dir <build> --no-tests=error -j1 -R '^startup_placed_backing_census_(warp|hardware)$' --output-on-failure` passed in the integration on WARP and RTX 4060 Laptop. The adapter and Mesh57 runtime regressions also passed.
github manually merged commit 1a9ccbc4e2 into main 2026-12-01 01:25:49 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.