gpu: cap slot 133 OpenExistingHeapFromAddress size and grow upload ring on demand #2757

Closed
opened 2026-11-26 06:46:39 +00:00 by triggered02 · 1 comment
triggered02 commented 2026-11-26 06:46:39 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T06:46:39Z.


Problem

In src/startup_stubs/d3d12_xs_device.cpp (device_place_resource_x, slot 133):

  1. x2w_local::commit_lazy_block(address) is called unconditionally at the start of the buffer branch (~line 4958), before checking (offset & 0xFFFF) == 0 && range.covered && range.type == MEM_PRIVATE. Even a tiny unaligned buffer or a MEM_MAPPED buffer that falls back to CreateCommittedResource commits the entire multi-GiB X2W_XMEM_LAZY_STARTUP block up front.
  2. OpenExistingHeapFromAddress(base) wraps the entire MEM_PRIVATE VirtualAlloc allocation regardless of size. In startup workloads this opens 2.15 GiB and 1.14 GiB (3.29 GiB total) D3D12 heaps just to alias ~160 MiB of placed buffers (including a 14 KiB buffer). As confirmed by a standalone D3D12 probe on GTX 1660 SUPER, OpenExistingHeapFromAddress(256 MiB) immediately pins WorkingSetSize +256.03 MiB and DXGI NonLocal +256.00 MiB even on untouched MEM_COMMIT pages. (slot 70 already guards against this via x2w_startup::unplaced_existing_heap_allowed at src/startup_stubs/memory_srv_buffer.h:136.)
  3. reserve_upload_ring (src/startup_stubs/d3d12_xs_device.cpp:2425) eagerly commits a single 256 MiB D3D12_HEAP_TYPE_UPLOAD buffer on the first translated draw even when only a few KiB are used.

Proposed changes

  1. Gate slot 133 OpenExistingHeapFromAddress by x2w_startup::unplaced_existing_heap_allowed(x2w_startup::allocation_bytes(base)) (<= 256 MiB, with an opt-in override if needed) and move commit_lazy_block(address) inside the OpenExistingHeapFromAddress branch so unaligned/non-private/oversized blocks only commit [address, address + width).
  2. Grow reserve_upload_ring incrementally (e.g., starting from a 16 MiB chunk and appending chunks on demand up to 256 MiB).

Acceptance

Source-built fixture startup_slot133_heap_cap_check verifying:

  • A slot 133 buffer in a > 256 MiB MEM_PRIVATE X2W_XMEM_LAZY_STARTUP block does not open an existing_heap (x2w-budget heap remains 0/0) and leaves untouched pages MEM_RESERVE;
  • A <= 256 MiB block still opens existing_heap (aliased);
  • reserve_upload_ring initially commits 16 MiB instead of 256 MiB and grows on demand.
    Command: ctest --preset dev --no-tests=error -R '^(startup_slot133_heap_cap|startup_placed_|startup_resource_budget)'

NOT established

  • Whether any workload places buffers in a > 256 MiB MEM_PRIVATE pool and relies on CPU-visible aliased writes without X2W_D3D12_LINEAR_BUFFERS=copy.

Refs #1199, #874.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6621155611 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2765). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-26T06:46:39Z. --- ### Problem In `src/startup_stubs/d3d12_xs_device.cpp` (`device_place_resource_x`, slot 133): 1. `x2w_local::commit_lazy_block(address)` is called unconditionally at the start of the buffer branch (`~line 4958`), before checking `(offset & 0xFFFF) == 0 && range.covered && range.type == MEM_PRIVATE`. Even a tiny unaligned buffer or a `MEM_MAPPED` buffer that falls back to `CreateCommittedResource` commits the entire multi-GiB `X2W_XMEM_LAZY_STARTUP` block up front. 2. `OpenExistingHeapFromAddress(base)` wraps the **entire** `MEM_PRIVATE` `VirtualAlloc` allocation regardless of size. In startup workloads this opens `2.15 GiB` and `1.14 GiB` (`3.29 GiB` total) D3D12 heaps just to alias ~`160 MiB` of placed buffers (including a `14 KiB` buffer). As confirmed by a standalone D3D12 probe on GTX 1660 SUPER, `OpenExistingHeapFromAddress(256 MiB)` immediately pins `WorkingSetSize +256.03 MiB` and DXGI `NonLocal +256.00 MiB` even on untouched `MEM_COMMIT` pages. (`slot 70` already guards against this via `x2w_startup::unplaced_existing_heap_allowed` at `src/startup_stubs/memory_srv_buffer.h:136`.) 3. `reserve_upload_ring` (`src/startup_stubs/d3d12_xs_device.cpp:2425`) eagerly commits a single `256 MiB` `D3D12_HEAP_TYPE_UPLOAD` buffer on the first translated draw even when only a few KiB are used. ### Proposed changes 1. Gate `slot 133` `OpenExistingHeapFromAddress` by `x2w_startup::unplaced_existing_heap_allowed(x2w_startup::allocation_bytes(base))` (`<= 256 MiB`, with an opt-in override if needed) and move `commit_lazy_block(address)` inside the `OpenExistingHeapFromAddress` branch so unaligned/non-private/oversized blocks only commit `[address, address + width)`. 2. Grow `reserve_upload_ring` incrementally (e.g., starting from a `16 MiB` chunk and appending chunks on demand up to `256 MiB`). ### Acceptance Source-built fixture `startup_slot133_heap_cap_check` verifying: - A `slot 133` buffer in a `> 256 MiB` `MEM_PRIVATE` `X2W_XMEM_LAZY_STARTUP` block does not open an `existing_heap` (`x2w-budget` `heap` remains `0/0`) and leaves untouched pages `MEM_RESERVE`; - A `<= 256 MiB` block still opens `existing_heap` (`aliased`); - `reserve_upload_ring` initially commits `16 MiB` instead of `256 MiB` and grows on demand. Command: `ctest --preset dev --no-tests=error -R '^(startup_slot133_heap_cap|startup_placed_|startup_resource_budget)'` ### NOT established - Whether any workload places buffers in a `> 256 MiB` `MEM_PRIVATE` pool and relies on CPU-visible `aliased` writes without `X2W_D3D12_LINEAR_BUFFERS=copy`. Refs #1199, #874.
R0Y00 commented 2026-11-26 08:01:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:04:35Z.


Please take the slot-133 heap and commit changes first and split upload-ring growth into a separate patch. The buffer path explicitly distinguishes an aliased buffer from a copied resource. Add a data test to the allocation probe: bind a buffer containing sentinel A, update the guest address to B before GPU submission, and require B at readback anywhere the new cap would switch backing. Check the existing small-block alias against the same input. Keep the old path for uses where copy synchronization has no equivalent, and verify untouched pages remain MEM_RESERVE. This can be tested independently of the lazy textures in #2764.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7185070183 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2765#issuecomment-7185070183). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T07:04:35Z. --- Please take the slot-133 heap and commit changes first and split upload-ring growth into a separate patch. The buffer path explicitly distinguishes an aliased buffer from a copied resource. Add a data test to the allocation probe: bind a buffer containing sentinel A, update the guest address to B before GPU submission, and require B at readback anywhere the new cap would switch backing. Check the existing small-block alias against the same input. Keep the old path for uses where copy synchronization has no equivalent, and verify untouched pages remain MEM_RESERVE. This can be tested independently of the lazy textures in #2764.
Sign in to join this conversation.
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#2757
No description provided.