d3d12: do not wrap large allocations for unplaced memory SRVs #2603

Merged
lukaslw-lab merged 1 commit from upstream-pr/2611 into main 2026-11-25 23:42:28 +00:00
lukaslw-lab commented 2026-11-25 23:18:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-25T23:18:48Z.


Change

Fixes #2610 (startup stall of ~120 s since #2395).

unplaced_memory_buffer (device slot 70, #2395) wraps the whole allocation holding a view with OpenExistingHeapFromAddress. Now it creates that wrap only when the allocation is at most 256 MiB, the limit unplaced_buffer_extent already applies to the span. Larger allocations take the existing upload copy. A heap that is already wrapped for the same base is still reused.

  • memory_srv_buffer.h: unplaced_max_span and unplaced_existing_heap_allowed(allocation_bytes) (0 = unknown → no wrap).
  • placed_buffer_range.h: allocation_bytes(address) gets the allocation size from one region-information call, without a page-table scan.
  • Overlap: draft #2603 replaces this call with an opt-in standin_memory_buffer path. This PR keeps the current design and only bounds it.

Verification

Windows 10 22H2, RTX 3080 Ti (driver 32.0.16.1047), WARP; dev and release; commit 0a40a0fd (on a6967446).

ctest --preset dev     -R '^startup_memory_srv_buffer|^startup_address_buffer_srv_|^startup_address_srv_|^startup_placed_buffer_range|^startup_memory_srv_diag'
ctest --preset release -R (same)

17/17 passed in each, with no capability skips (dev at b45a19e4 on f03cf16f; rerun at 0a40a0fd after the rebase: result to follow in a comment).

  • startup_memory_srv_buffer: limit cases (64 KiB, 256 MiB, 256 MiB + 64 KiB, 2 GiB, unknown size). New negative control startup_memory_srv_buffer_unplaced-heap-limit_control (it accepts 2 GiB) fails as expected.
  • startup_placed_buffer_range case 10: allocation_bytes on 64 KiB and 256 MiB + 64 KiB reservations with only their first page committed, queried at the base and at the last byte.
  • startup_address_buffer_srv_{warp,hardware} column 7: a view in a 256 MiB + 64 KiB allocation still publishes the right value, now through the upload copy.
  • Limitation: column 7 cannot tell the heap path from the upload copy, because both show the value at the slot 70 call. A variant that wrote again after the call also passed with the limit removed, so I dropped it. The path choice was checked once with a temporary log in unplaced_memory_buffer (not in this PR). Without the limit, both the 64 KiB and the large allocation are wrapped (WARP and hardware). With it, 64 KiB is wrapped and the large one takes the upload copy.
  • Startup run (release, warm cache, same input script as in the issue): at 0a40a0fd, 3,254 DirectStorage requests completed at 10 s and first input poll at 5.8 s (with #2395 alone: 0 at 30 s, first poll ~122 s); no device removal in 180 s.

Evidence and follow-up

  • Fixtures are source-built (VirtualAlloc in the test); no title data.
  • Cost: an unplaced view in an allocation above 256 MiB now gets the upload copy, which is refreshed on each slot 70 call, instead of a zero-copy alias. In this title that affects the two small views in the ~2.15 GiB block. Why the wrap slows later VirtualQuery calls over that allocation is not proven (see the issue).

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. (none changed)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: the change, tests and this description were written with Claude; I ran the bisect and the startup runs.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6615758595 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2611). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-25T23:18:48Z. --- ## Change Fixes #2610 (startup stall of ~120 s since #2395). `unplaced_memory_buffer` (device slot 70, #2395) wraps the whole allocation holding a view with `OpenExistingHeapFromAddress`. Now it creates that wrap only when the allocation is at most 256 MiB, the limit `unplaced_buffer_extent` already applies to the span. Larger allocations take the existing upload copy. A heap that is already wrapped for the same base is still reused. - `memory_srv_buffer.h`: `unplaced_max_span` and `unplaced_existing_heap_allowed(allocation_bytes)` (0 = unknown → no wrap). - `placed_buffer_range.h`: `allocation_bytes(address)` gets the allocation size from one region-information call, without a page-table scan. - Overlap: draft #2603 replaces this call with an opt-in `standin_memory_buffer` path. This PR keeps the current design and only bounds it. ## Verification Windows 10 22H2, RTX 3080 Ti (driver 32.0.16.1047), WARP; dev and release; commit `0a40a0fd` (on `a6967446`). ``` ctest --preset dev -R '^startup_memory_srv_buffer|^startup_address_buffer_srv_|^startup_address_srv_|^startup_placed_buffer_range|^startup_memory_srv_diag' ctest --preset release -R (same) ``` 17/17 passed in each, with no capability skips (dev at `b45a19e4` on `f03cf16f`; rerun at `0a40a0fd` after the rebase: result to follow in a comment). - `startup_memory_srv_buffer`: limit cases (64 KiB, 256 MiB, 256 MiB + 64 KiB, 2 GiB, unknown size). New negative control `startup_memory_srv_buffer_unplaced-heap-limit_control` (it accepts 2 GiB) fails as expected. - `startup_placed_buffer_range` case 10: `allocation_bytes` on 64 KiB and 256 MiB + 64 KiB reservations with only their first page committed, queried at the base and at the last byte. - `startup_address_buffer_srv_{warp,hardware}` column 7: a view in a 256 MiB + 64 KiB allocation still publishes the right value, now through the upload copy. - Limitation: column 7 cannot tell the heap path from the upload copy, because both show the value at the slot 70 call. A variant that wrote again after the call also passed with the limit removed, so I dropped it. The path choice was checked once with a temporary log in `unplaced_memory_buffer` (not in this PR). Without the limit, both the 64 KiB and the large allocation are wrapped (WARP and hardware). With it, 64 KiB is wrapped and the large one takes the upload copy. - Startup run (release, warm cache, same input script as in the issue): at `0a40a0fd`, 3,254 DirectStorage requests completed at 10 s and first input poll at 5.8 s (with #2395 alone: 0 at 30 s, first poll ~122 s); no device removal in 180 s. ## Evidence and follow-up - Fixtures are source-built (`VirtualAlloc` in the test); no title data. - Cost: an unplaced view in an allocation above 256 MiB now gets the upload copy, which is refreshed on each slot 70 call, instead of a zero-copy alias. In this title that affects the two small views in the ~2.15 GiB block. Why the wrap slows later `VirtualQuery` calls over that allocation is not proven (see the issue). ## 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. (none changed) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: the change, tests and this description were written with Claude; I ran the bisect and the startup runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-26 00:00:57 +00:00
tedin7 commented 2026-11-26 00:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:21:17Z.

Review: COMMENTED


Review of head 0a40a0fd (comment only, no approval).

Code looks sound:

  • unplaced_existing_heap_allowed (memory_srv_buffer.h): 0 (unknown) and anything above 256 MiB fall back to the upload copy; an already wrapped heap is still reused (the existing_heaps lookup runs before the new check in d3d12_memory_srv.inl).
  • allocation_bytes (placed_buffer_range.h): one region-information call, returns 0 on a missing or failed call, so it fails closed.
  • unplaced_max_span is now shared with unplaced_buffer_extent, so the two limits cannot drift apart.
  • Test: startup_memory_srv_buffer covers 64 KiB, 256 MiB, 256 MiB + 64 KiB, 2 GiB and unknown size. The unplaced-heap-limit mutation flips only the 2 GiB case, so it is a real negative control. I read it; I did not build it (Windows-only tests).
  • Sibling checks (startup_address_buffer_srv_check.py, startup_address_srv.cpp, startup_placed_buffer_range_check.cpp) are extended consistently.
  • No other open or merged PR covers the same slice except draft #2603, which the body already names as overlapping; the choice between the two is for @R0Y00.

Not verified by me, and why it is not merged by this review:

  • The PR fixes a ~120 s startup stall seen while running the title (#2610). We do not run the title, so that claim needs verification by MasterDomino or @R0Y00 on the game.
  • CI was still pending and there is no Win2025 receipt on this head yet at the time of review.

Linux commands run: git diff --stat origin/main...HEAD, git diff --check origin/main...HEAD (clean), python3 tests/docs_links_check.py (19 files, 506 links ok), python3 tests/bidi_controls_check.py (ok).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066341865 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2611#pullrequestreview-6066341865). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:21:17Z. **Review:** COMMENTED --- Review of head `0a40a0fd` (comment only, no approval). Code looks sound: - `unplaced_existing_heap_allowed` (`memory_srv_buffer.h`): 0 (unknown) and anything above 256 MiB fall back to the upload copy; an already wrapped heap is still reused (the `existing_heaps` lookup runs before the new check in `d3d12_memory_srv.inl`). - `allocation_bytes` (`placed_buffer_range.h`): one region-information call, returns 0 on a missing or failed call, so it fails closed. - `unplaced_max_span` is now shared with `unplaced_buffer_extent`, so the two limits cannot drift apart. - Test: `startup_memory_srv_buffer` covers 64 KiB, 256 MiB, 256 MiB + 64 KiB, 2 GiB and unknown size. The `unplaced-heap-limit` mutation flips only the 2 GiB case, so it is a real negative control. I read it; I did not build it (Windows-only tests). - Sibling checks (`startup_address_buffer_srv_check.py`, `startup_address_srv.cpp`, `startup_placed_buffer_range_check.cpp`) are extended consistently. - No other open or merged PR covers the same slice except draft #2603, which the body already names as overlapping; the choice between the two is for @R0Y00. Not verified by me, and why it is not merged by this review: - The PR fixes a ~120 s startup stall seen while running the title (#2610). We do not run the title, so that claim needs verification by MasterDomino or @R0Y00 on the game. - CI was still pending and there is no Win2025 receipt on this head yet at the time of review. Linux commands run: `git diff --stat origin/main...HEAD`, `git diff --check origin/main...HEAD` (clean), `python3 tests/docs_links_check.py` (19 files, 506 links ok), `python3 tests/bidi_controls_check.py` (ok). AI-assisted; commands listed were executed locally.
lukaslw-lab commented 2026-11-26 00:01:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-25T23:19:32Z.


Rerun after the rebase, at 0a40a0fd (on a6967446), same selection (^startup_memory_srv_buffer|^startup_address_buffer_srv_|^startup_address_srv_|^startup_placed_buffer_range|^startup_memory_srv_diag): dev 17/17 passed, release 17/17 passed, no capability skips.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177410305 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2611#issuecomment-7177410305). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-25T23:19:32Z. --- Rerun after the rebase, at `0a40a0fd` (on `a6967446`), same selection (`^startup_memory_srv_buffer|^startup_address_buffer_srv_|^startup_address_srv_|^startup_placed_buffer_range|^startup_memory_srv_diag`): dev 17/17 passed, release 17/17 passed, no capability skips.
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!2603
No description provided.