gpu: emulate a shader-visible view heap larger than the driver accepts #1233

Merged
triggered02 merged 3 commits from upstream-pr/1240 into main 2026-11-24 06:06:38 +00:00
triggered02 commented 2026-11-24 04:59:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T04:59:38Z.


The title asks for one shader-visible CBV/SRV/UAV heap of 1,245,184 descriptors, which the console accepts. Desktop D3D12 documents a 1,048,576 ceiling, but drivers may accept less — this GTX 1660 SUPER rejects 1,048,576 as well and stops at exactly 1,000,000, so the limit is measured once and cached instead of assumed.

The stand-in now creates the desktop heap at the accepted maximum, keeps the title's own full-size descriptor memory (the extra[1] == bytes handshake still uses the requested byte count, so GetCPUDescriptorHandleForHeapStart keeps returning the title's arena base), and records the desktop capacity beside the title extent. A handle the title addresses past the desktop heap is logged once with its descriptor index rather than silently translated out of the allocation.

Measured with the offline stand-ins (tools/startup/run.ps1 -Render -FakeUser -GpuMirror -ContinueAsserts 1000 -InputScript 4@70), GTX 1660 SUPER, driver 32.0.16.1074, Windows 11 build 26200, G:\ package mount:

before after
stop point 2.02 s, NULL+0x30 in the title's arena allocator 130.95 s, later in the render path
frames presented 0 3,218 at 29.2 fps
x2w-d3d12 measured the shader-visible view heap limit: 1000000 descriptors
x2w-d3d12 Device::CreateDescriptorHeap: shortcut - title asked for 1245184 shader-visible view descriptors, this driver accepts 1000000; the rest stay in title memory
x2w-d3d12 heartbeat: 3218 frames presented in 110.0 s (29.2 fps overall)

The clamp is a logged shortcut, not a claim that the console contract is emulated: descriptors past the driver's heap stay in title memory and any use of them is reported. docs/startup-runtime.md calls these stand-ins experimental and opt-in, which suits this.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574974488 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T04:59:38Z. --- The title asks for one shader-visible CBV/SRV/UAV heap of **1,245,184** descriptors, which the console accepts. Desktop D3D12 documents a 1,048,576 ceiling, but drivers may accept less — this GTX 1660 SUPER rejects 1,048,576 as well and stops at exactly **1,000,000**, so the limit is measured once and cached instead of assumed. The stand-in now creates the desktop heap at the accepted maximum, keeps the title's own full-size descriptor memory (the `extra[1] == bytes` handshake still uses the **requested** byte count, so `GetCPUDescriptorHandleForHeapStart` keeps returning the title's arena base), and records the desktop capacity beside the title extent. A handle the title addresses past the desktop heap is logged once with its descriptor index rather than silently translated out of the allocation. Measured with the offline stand-ins (`tools/startup/run.ps1 -Render -FakeUser -GpuMirror -ContinueAsserts 1000 -InputScript 4@70`), GTX 1660 SUPER, driver 32.0.16.1074, Windows 11 build 26200, `G:\` package mount: | | before | after | |---|---|---| | stop point | 2.02 s, `NULL+0x30` in the title's arena allocator | 130.95 s, later in the render path | | frames presented | 0 | **3,218 at 29.2 fps** | ``` x2w-d3d12 measured the shader-visible view heap limit: 1000000 descriptors x2w-d3d12 Device::CreateDescriptorHeap: shortcut - title asked for 1245184 shader-visible view descriptors, this driver accepts 1000000; the rest stay in title memory x2w-d3d12 heartbeat: 3218 frames presented in 110.0 s (29.2 fps overall) ``` The clamp is a logged shortcut, not a claim that the console contract is emulated: descriptors past the driver's heap stay in title memory and any use of them is reported. `docs/startup-runtime.md` calls these stand-ins experimental and opt-in, which suits this.
upstream-sync closed this pull request 2026-11-24 06:47:12 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:47:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:02:18Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16761eed7b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033941362 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#pullrequestreview-6033941362). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:02:18Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `16761eed7b` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 06:47:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:03:58Z.

Review: COMMENTED


Reviewed commit 16761eed (Linux host; Windows build and runtime tests were not executed locally).

Code & Edge-Case Audit

  • src/startup_stubs/d3d12_xs_device.cpp:
    • accepted_view_heap_descriptors: probes once per process (guarded by InterlockedCompareExchange state 0 -> 1 -> 2) for shader-visible CBV_SRV_UAV heaps when CreateDescriptorHeap returns E_INVALIDARG and NumDescriptors > view_heap_probe_floor (65536), halving from 1,048,576 and bisecting upward.
    • device_create_descriptor_heap: clamps only the desktop CreateDescriptorHeap request while keeping bytes (std::uint64_t arithmetic), title_memory handshake (extra[1] == bytes), and note_heap at the requested NumDescriptors.
    • desktop_cpu_handle: checks offset < r.desktop_bytes || r.desktop_bytes == r.bytes and releases descriptor_lock before calling log(...) (up to 4 times via first_calls(reported, 4)).
    • Edge cases noted:
      1. If CreateDescriptorHeap were to fail even at view_heap_probe_floor (65536), the halving loop stops at ceiling == 65536 without confirming 65536 succeeds (unlikely on D3D12 drivers, but low would remain unverified).
      2. Out-of-range handles (offset >= r.desktop_bytes when r.desktop_bytes < r.bytes) leave result = handle (title memory); any D3D12 call passing that handle to the driver will still fail/fault, consistent with the PR's stated logged-shortcut scope.
      3. Concurrent threads spin up to 2000 * Sleep(1) (~2 s) and return 0 if probing has not finished, skipping clamping for that call.
  • Title-neutrality (AGENTS.md): compliant.

Checks Run (Linux / Python)

  • git diff --check origin/main...HEAD: pass (0 issues)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: pass (16 Markdown files, 280 links)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: pass (1046 files)
  • Windows build and runtime tests: not run locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033963460 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#pullrequestreview-6033963460). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:03:58Z. **Review:** COMMENTED --- Reviewed commit `16761eed` (Linux host; Windows build and runtime tests were not executed locally). ### Code & Edge-Case Audit - `src/startup_stubs/d3d12_xs_device.cpp`: - `accepted_view_heap_descriptors`: probes once per process (guarded by `InterlockedCompareExchange` state `0 -> 1 -> 2`) for shader-visible `CBV_SRV_UAV` heaps when `CreateDescriptorHeap` returns `E_INVALIDARG` and `NumDescriptors > view_heap_probe_floor` (`65536`), halving from `1,048,576` and bisecting upward. - `device_create_descriptor_heap`: clamps only the desktop `CreateDescriptorHeap` request while keeping `bytes` (`std::uint64_t` arithmetic), `title_memory` handshake (`extra[1] == bytes`), and `note_heap` at the requested `NumDescriptors`. - `desktop_cpu_handle`: checks `offset < r.desktop_bytes || r.desktop_bytes == r.bytes` and releases `descriptor_lock` before calling `log(...)` (up to 4 times via `first_calls(reported, 4)`). - Edge cases noted: 1. If `CreateDescriptorHeap` were to fail even at `view_heap_probe_floor` (`65536`), the halving loop stops at `ceiling == 65536` without confirming `65536` succeeds (unlikely on D3D12 drivers, but `low` would remain unverified). 2. Out-of-range handles (`offset >= r.desktop_bytes` when `r.desktop_bytes < r.bytes`) leave `result = handle` (title memory); any D3D12 call passing that handle to the driver will still fail/fault, consistent with the PR's stated logged-shortcut scope. 3. Concurrent threads spin up to `2000 * Sleep(1)` (~2 s) and return `0` if probing has not finished, skipping clamping for that call. - Title-neutrality (`AGENTS.md`): compliant. ### Checks Run (Linux / Python) - `git diff --check origin/main...HEAD`: pass (0 issues) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: pass (16 Markdown files, 280 links) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: pass (1046 files) - Windows build and runtime tests: not run locally.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:59:47Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T05:02:20.875101Z 16761ee PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122526430 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#issuecomment-7122526430). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T04:59:47Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"16761eed7b8a614a8de9087b360d301503fb7c1f","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T05:02:20.875101Z">2026-11-24T05:02:20.875101Z</relative-time> | `16761ee` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
triggered02 commented 2026-11-24 06:50:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T05:15:16Z.


Fixed in 692aa6ca, and the branch is rebased onto current main (it had gone conflicted after the descriptor-stride work landed; the clamp is now applied to that shape, with the range record carrying how many title descriptors the desktop heap covers).

On the P2: the floor is now probed. The measurement halves from the documented ceiling and tests every candidate including 65,536; if no candidate at or above the floor is accepted the shortcut is declined (returns 0, logs it) instead of caching 65,536 and retrying at a size the driver rejects. So a driver with a maximum below the floor falls back to the original failed create rather than failing the same way twice.

Re-verified on the rebased branch, GTX 1660 SUPER (driver 32.0.16.1074), Windows 11 build 26200, offline stand-ins:

x2w-d3d12 measured the shader-visible view heap limit: 1000000 descriptors
x2w-d3d12 Device::CreateDescriptorHeap: shortcut - title asked for 1245184 shader-visible view descriptors, this driver accepts 1000000; the rest stay in title memory
x2w-d3d12 heartbeat: 518 frames presented in 20.0 s (25.9 fps overall)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122772631 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#issuecomment-7122772631). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T05:15:16Z. --- Fixed in `692aa6ca`, and the branch is rebased onto current `main` (it had gone conflicted after the descriptor-stride work landed; the clamp is now applied to that shape, with the range record carrying how many title descriptors the desktop heap covers). On the P2: the floor is now probed. The measurement halves from the documented ceiling and tests every candidate **including** 65,536; if no candidate at or above the floor is accepted the shortcut is **declined** (returns 0, logs it) instead of caching 65,536 and retrying at a size the driver rejects. So a driver with a maximum below the floor falls back to the original failed create rather than failing the same way twice. Re-verified on the rebased branch, GTX 1660 SUPER (driver 32.0.16.1074), Windows 11 build 26200, offline stand-ins: ``` x2w-d3d12 measured the shader-visible view heap limit: 1000000 descriptors x2w-d3d12 Device::CreateDescriptorHeap: shortcut - title asked for 1245184 shader-visible view descriptors, this driver accepts 1000000; the rest stay in title memory x2w-d3d12 heartbeat: 518 frames presented in 20.0 s (25.9 fps overall) ```
tedin7 commented 2026-11-24 06:50:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:23:17Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 692aa6caf620fcb34432c4c81324e6f2c7f75a67:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_shim_check d3d12_xs_shim -- -j 6): 22.94s (configure 2.04s)
    • Test (ctest --preset dev -R '^d3d12_xs_shim_.*$' --parallel 4 --no-tests=error --output-on-failure): 5/5 passed (0.23s: d3d12_xs_shim_exports, d3d12_xs_shim_serialize, d3d12_xs_shim_deserialize, d3d12_xs_shim_iids, d3d12_xs_shim_warp_root)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_shim_check d3d12_xs_shim -- -j 6): 43.64s (configure 1.82s)
    • Test (ctest --preset release -R '^d3d12_xs_shim_.*$' --parallel 4 --no-tests=error --output-on-failure): 5/5 passed (0.22s: d3d12_xs_shim_exports, d3d12_xs_shim_serialize, d3d12_xs_shim_deserialize, d3d12_xs_shim_iids, d3d12_xs_shim_warp_root)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122899608 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#issuecomment-7122899608). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:23:17Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `692aa6caf620fcb34432c4c81324e6f2c7f75a67`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target d3d12_xs_shim_check d3d12_xs_shim -- -j 6`): `22.94s` (configure `2.04s`) - Test (`ctest --preset dev -R '^d3d12_xs_shim_.*$' --parallel 4 --no-tests=error --output-on-failure`): **5/5 passed** (`0.23s`: `d3d12_xs_shim_exports`, `d3d12_xs_shim_serialize`, `d3d12_xs_shim_deserialize`, `d3d12_xs_shim_iids`, `d3d12_xs_shim_warp_root`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target d3d12_xs_shim_check d3d12_xs_shim -- -j 6`): `43.64s` (configure `1.82s`) - Test (`ctest --preset release -R '^d3d12_xs_shim_.*$' --parallel 4 --no-tests=error --output-on-failure`): **5/5 passed** (`0.22s`: `d3d12_xs_shim_exports`, `d3d12_xs_shim_serialize`, `d3d12_xs_shim_deserialize`, `d3d12_xs_shim_iids`, `d3d12_xs_shim_warp_root`)
R0Y00 commented 2026-11-24 06:50:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T05:29:20Z.


@triggered02, I am using your c74485f5 as the upstream for the translated root-table follow-up. It will use the per-driver capacity your PR already probes. The scope is command-list slot 32 heap identity, slot 36 table resolution through the logical end, and safe descriptor creation/copy across the measured physical boundary. I am testing two heaps with independent sentinels via a translated draw on WARP and NVIDIA. No duplicate capacity probe is being submitted. Please flag any overlapping runtime changes in your branch. Refs #874.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122994595 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#issuecomment-7122994595). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T05:29:20Z. --- @triggered02, I am using your `c74485f5` as the upstream for the translated root-table follow-up. It will use the per-driver capacity your PR already probes. The scope is command-list slot 32 heap identity, slot 36 table resolution through the logical end, and safe descriptor creation/copy across the measured physical boundary. I am testing two heaps with independent sentinels via a translated draw on WARP and NVIDIA. No duplicate capacity probe is being submitted. Please flag any overlapping runtime changes in your branch. Refs #874.
triggered02 commented 2026-11-24 06:50:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T05:39:50Z.


@R0Y00 — here is exactly what c74485f5 changes in the runtime, and the two places it will meet your follow-up.

Surface: src/startup_stubs/d3d12_xs_device.cpp only (+115 lines; plus tests/startup_view_heap_check.cpp, a CMake entry and a docs entry). I do not touch command-list slots 32 or 36, root-table resolution, note_heap, or any command-list handler, so your slot 32 heap identity and slot 36 table resolution work should not collide with mine.

What the boundary is, in code. A DescriptorRange gains desktop_descriptors: how many title descriptors the desktop heap actually covers. It is stored under descriptor_lock alongside title / bytes / desktop. bytes deliberately stays the title's full extent (1,245,184 descriptors), while desktop is the clamped heap's start — so read desktop_descriptors, not bytes, when you decide where the physical boundary is.

The probe you are reusing. accepted_view_heap_descriptors(device, node_mask) — halves from 1,048,576, bisects up, releases each probe, declines (returns 0) if nothing at or above the 65,536 floor is accepted. It takes any failure of an oversized shader-visible CBV/SRV/UAV heap, because the codes differ by driver: E_INVALIDARG on my GTX 1660 SUPER, E_OUTOFMEMORY on the RTX 3060 you measured.

Two things you should know before you build on it, both mine to fix if you want:

  1. The probe cache is process-wide, not per adapter. cached / state are function-level statics, so a WARP device and an NVIDIA device in the same process would share one measurement. Your two-heap sentinel test is the first thing that would hit this. If you want, I will key the cache per adapter LUID and push it to this branch rather than have you work around it.

  2. The overrun is detected but not enforced — that is your scope, not mine. desktop_cpu_handle() sets past_limit, logs at most four times, and returns the untranslated title handle, so the device currently receives an address past the heap. I deliberately did not invent a sentinel there because three call sites share it and a wrong sentinel would silently corrupt them: the view-slot handlers (args[D] = desktop_cpu_handle(args[D])), device_copy_descriptors, and device_copy_descriptors_simple. Your safe creation/copy layer is the right place to skip the call instead. Tell me whether you want my log path removed or kept as a counter once yours lands — I would rather have one authority reporting the boundary than two.

One mismatched expectation to be aware of: the shortcut line is guarded by first_calls(shortcuts, 1), so only the first clamped heap in a process logs. Two oversized heaps with independent sentinels will produce one log line, not two. If your fixture asserts a line per heap, it will fail against this branch — say so and I will make it per heap.

If it is easier, I can put the LUID-keyed cache and the per-heap logging in one small commit on this branch today so your work starts from a probe that is correct across adapters.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123157737 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#issuecomment-7123157737). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T05:39:50Z. --- @R0Y00 — here is exactly what `c74485f5` changes in the runtime, and the two places it will meet your follow-up. **Surface: `src/startup_stubs/d3d12_xs_device.cpp` only** (+115 lines; plus `tests/startup_view_heap_check.cpp`, a CMake entry and a docs entry). I do not touch command-list slots 32 or 36, root-table resolution, `note_heap`, or any command-list handler, so your slot 32 heap identity and slot 36 table resolution work should not collide with mine. **What the boundary is, in code.** A `DescriptorRange` gains `desktop_descriptors`: how many title descriptors the desktop heap actually covers. It is stored under `descriptor_lock` alongside `title` / `bytes` / `desktop`. `bytes` deliberately stays the **title's** full extent (1,245,184 descriptors), while `desktop` is the clamped heap's start — so read `desktop_descriptors`, not `bytes`, when you decide where the physical boundary is. **The probe you are reusing.** `accepted_view_heap_descriptors(device, node_mask)` — halves from 1,048,576, bisects up, releases each probe, declines (returns 0) if nothing at or above the 65,536 floor is accepted. It takes **any** failure of an oversized shader-visible CBV/SRV/UAV heap, because the codes differ by driver: `E_INVALIDARG` on my GTX 1660 SUPER, `E_OUTOFMEMORY` on the RTX 3060 you measured. **Two things you should know before you build on it, both mine to fix if you want:** 1. **The probe cache is process-wide, not per adapter.** `cached` / `state` are function-level statics, so a WARP device and an NVIDIA device in the *same process* would share one measurement. Your two-heap sentinel test is the first thing that would hit this. If you want, I will key the cache per adapter LUID and push it to this branch rather than have you work around it. 2. **The overrun is detected but not enforced — that is your scope, not mine.** `desktop_cpu_handle()` sets `past_limit`, logs at most four times, and returns the **untranslated title handle**, so the device currently receives an address past the heap. I deliberately did not invent a sentinel there because three call sites share it and a wrong sentinel would silently corrupt them: the view-slot handlers (`args[D] = desktop_cpu_handle(args[D])`), `device_copy_descriptors`, and `device_copy_descriptors_simple`. Your safe creation/copy layer is the right place to skip the call instead. Tell me whether you want my log path removed or kept as a counter once yours lands — I would rather have one authority reporting the boundary than two. **One mismatched expectation to be aware of:** the shortcut line is guarded by `first_calls(shortcuts, 1)`, so only the *first* clamped heap in a process logs. Two oversized heaps with independent sentinels will produce one log line, not two. If your fixture asserts a line per heap, it will fail against this branch — say so and I will make it per heap. If it is easier, I can put the LUID-keyed cache and the per-heap logging in one small commit on this branch today so your work starts from a probe that is correct across adapters.
triggered02 commented 2026-11-24 06:50:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T06:06:42Z.


Reviewed ab1ea74a and verified it locally — it is the right correction to what I wrote, and it closes two gaps I had left in the test.

The narrowing is correct. My "any failure takes the clamp path" was over-corrected: it was right that E_OUTOFMEMORY had to be included alongside E_INVALIDARG, but FAILED(hr) also swallowed unrelated failures such as E_NOINTERFACE and E_POINTER and turned them into a capacity retry. Matching exactly the two capacity codes is what the situation actually calls for. Removing the redundant cached = 0 there is right too — the static is already zero at that point and the state move is what publishes the result.

Both test additions close real holes I left:

  • The E_NOINTERFACE negative control is the test that would have caught my over-correction. I had no case that asserted an unrelated failure is preserved, which is why the bug got through.
  • guest_cpu_base() restores the logical CPU-descriptor-base assertion I dropped. I had given up on it because calling GetCPUDescriptorHandleForHeapStart through the COM vtable returned 0, and I concluded the title never queries it — which was the wrong conclusion. Reading slot 9 directly with the one-word console ABI is the right way to ask, and the fixture is stronger for it.

Local verification (GTX 1660 SUPER, driver 32.0.16.1074, Windows 11 build 26200, release preset, at ab1ea74a):

x2w-d3d12 measured the shader-visible view heap limit: 1000000 descriptors
x2w-d3d12 Device::CreateDescriptorHeap: shortcut - title asked for 1245184 shader-visible view descriptors, this driver accepts 1000000; the rest stay in title memory
oversized heap accepted; shortcut logged once; 1245184 requested
startup_view_heap_hardware ....... Passed   0.60 sec
startup_view_heap_warp ........... Skipped  (WARP accepts the full request)

One thing still unanswered from my earlier note, which matters for your two-adapter sentinel test: the capacity measurement is cached in function-level statics, so it is process-wide, not per adapter. A WARP device and an NVIDIA device in the same process would share one measurement. I can key it per adapter LUID if you want it before your follow-up lands; otherwise your test will be measuring the first adapter's limit for both.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123594777 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#issuecomment-7123594777). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T06:06:42Z. --- Reviewed `ab1ea74a` and verified it locally — it is the right correction to what I wrote, and it closes two gaps I had left in the test. **The narrowing is correct.** My "any failure takes the clamp path" was over-corrected: it was right that `E_OUTOFMEMORY` had to be included alongside `E_INVALIDARG`, but `FAILED(hr)` also swallowed unrelated failures such as `E_NOINTERFACE` and `E_POINTER` and turned them into a capacity retry. Matching exactly the two capacity codes is what the situation actually calls for. Removing the redundant `cached = 0` there is right too — the static is already zero at that point and the state move is what publishes the result. **Both test additions close real holes I left:** - The `E_NOINTERFACE` negative control is the test that would have caught my over-correction. I had no case that asserted an unrelated failure is *preserved*, which is why the bug got through. - `guest_cpu_base()` restores the logical CPU-descriptor-base assertion I dropped. I had given up on it because calling `GetCPUDescriptorHandleForHeapStart` through the COM vtable returned 0, and I concluded the title never queries it — which was the wrong conclusion. Reading slot 9 directly with the one-word console ABI is the right way to ask, and the fixture is stronger for it. **Local verification** (GTX 1660 SUPER, driver 32.0.16.1074, Windows 11 build 26200, `release` preset, at `ab1ea74a`): ``` x2w-d3d12 measured the shader-visible view heap limit: 1000000 descriptors x2w-d3d12 Device::CreateDescriptorHeap: shortcut - title asked for 1245184 shader-visible view descriptors, this driver accepts 1000000; the rest stay in title memory oversized heap accepted; shortcut logged once; 1245184 requested startup_view_heap_hardware ....... Passed 0.60 sec startup_view_heap_warp ........... Skipped (WARP accepts the full request) ``` One thing still unanswered from my earlier note, which matters for your two-adapter sentinel test: the capacity measurement is cached in function-level statics, so it is **process-wide, not per adapter**. A WARP device and an NVIDIA device in the same process would share one measurement. I can key it per adapter LUID if you want it before your follow-up lands; otherwise your test will be measuring the first adapter's limit for both.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:02:18Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 163

@@ -98,20 +98,103 @@ struct DescriptorRange {
     std::uint64_t title;
     std::uint64_t bytes;
     std::uint64_t desktop;
+    std::uint64_t desktop_bytes;  // desktop heap extent when it is shorter than the title's memory
+    std::uint64_t increment;      // descriptor size, for reporting an out-of-range index
 };
 SRWLOCK descriptor_lock = SRWLOCK_INIT;
 std::vector<DescriptorRange> descriptor_ranges;
 
+// Desktop rejects a shader-visible CBV/SRV/UAV heap above a driver-specific descriptor count: the
+// API documents 1,048,576, but some drivers reject that and stop lower (1,000,000 on the GTX 1660
+// SUPER here), so the accepted maximum is measured once and cached. The stand-in then creates the
+// desktop heap at that maximum and keeps the title's own full-size memory, so startup can proceed;
+// a handle the title addresses past the desktop heap is logged rather than translated out of it.
+constexpr std::uint64_t view_heap_probe_floor = 65536;
+
+void log(const char* format, ...);
+bool first_calls(LONG& counter, LONG limit);
+std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mask);
+
 std::uint64_t desktop_cpu_handle(std::uint64_t handle)
 {
     AcquireSRWLockShared(&descriptor_lock);
     std::uint64_t result = handle;
-    for (const auto& r : descriptor_ranges)
-        if (handle >= r.title && handle < r.title + r.bytes) result = r.desktop + (handle - r.title);
+    bool past_limit = false;
+    std::uint64_t past_index = 0, past_capacity = 0;
+    for (const auto& r : descriptor_ranges) {
+        if (handle < r.title || handle >= r.title + r.bytes) continue;
+        const std::uint64_t offset = handle - r.title;
+        if (offset < r.desktop_bytes || r.desktop_bytes == r.bytes) {
+            result = r.desktop + offset;
+        } else {
+            past_limit = true;
+            past_index = r.increment ? offset / r.increment : offset;
+            past_capacity = r.increment ? r.desktop_bytes / r.increment : r.desktop_bytes;
+        }
+    }
+    // The lock is released before logging: log() opens the trap log, and a lock held across it can
+    // serialise every descriptor translation behind one file append.
     ReleaseSRWLockShared(&descriptor_lock);
+    if (past_limit) {
+        static LONG reported;
+        if (first_calls(reported, 4))
+            log("x2w-d3d12 descriptor beyond the emulated heap: index=%llu desktop_holds=%llu "
+                "(console heap is larger; the title must not place views here)", past_index, past_capacity);
+    }
     return result;
 }
 
+// Measure, once per process, the largest shader-visible CBV/SRV/UAV heap this driver creates. The
+// documented ceiling is 1,048,576 descriptors, but drivers may accept fewer, so halve from the
+// ceiling until a create succeeds and then bisect upward. Each probe heap is released before the
+// next one, so at most one probe holds memory at a time.
+std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mask)
+{
+    static std::uint64_t cached;
+    static LONG state;  // 0 none, 1 measuring, 2 measured
+    if (InterlockedCompareExchange(&state, 0, 0) == 2) return cached;
+    if (InterlockedCompareExchange(&state, 1, 0) != 0) {
+        // Another thread is measuring; wait for it rather than create a second set of probe heaps.
+        for (int spin = 0; spin < 2000 && InterlockedCompareExchange(&state, 0, 0) != 2; ++spin) Sleep(1);
+        return InterlockedCompareExchange(&state, 0, 0) == 2 ? cached : 0;
+    }
+
+    std::uint64_t ceiling = 1048576;  // the API documents this as the maximum
+    while (ceiling > view_heap_probe_floor) {

P2 Badge Probe before treating the floor as accepted

If a driver's largest accepted shader-visible view heap is below 65,536 descriptors, this loop reaches the floor without testing it. The following bisection initializes low to that unverified value and only tests larger sizes, so it caches 65,536 and retries the title heap at a size the driver rejects; the fallback still fails instead of finding a smaller usable heap or declining the shortcut.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675725748 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1240#discussion_r4675725748). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:02:18Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 163 ~~~~diff @@ -98,20 +98,103 @@ struct DescriptorRange { std::uint64_t title; std::uint64_t bytes; std::uint64_t desktop; + std::uint64_t desktop_bytes; // desktop heap extent when it is shorter than the title's memory + std::uint64_t increment; // descriptor size, for reporting an out-of-range index }; SRWLOCK descriptor_lock = SRWLOCK_INIT; std::vector<DescriptorRange> descriptor_ranges; +// Desktop rejects a shader-visible CBV/SRV/UAV heap above a driver-specific descriptor count: the +// API documents 1,048,576, but some drivers reject that and stop lower (1,000,000 on the GTX 1660 +// SUPER here), so the accepted maximum is measured once and cached. The stand-in then creates the +// desktop heap at that maximum and keeps the title's own full-size memory, so startup can proceed; +// a handle the title addresses past the desktop heap is logged rather than translated out of it. +constexpr std::uint64_t view_heap_probe_floor = 65536; + +void log(const char* format, ...); +bool first_calls(LONG& counter, LONG limit); +std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mask); + std::uint64_t desktop_cpu_handle(std::uint64_t handle) { AcquireSRWLockShared(&descriptor_lock); std::uint64_t result = handle; - for (const auto& r : descriptor_ranges) - if (handle >= r.title && handle < r.title + r.bytes) result = r.desktop + (handle - r.title); + bool past_limit = false; + std::uint64_t past_index = 0, past_capacity = 0; + for (const auto& r : descriptor_ranges) { + if (handle < r.title || handle >= r.title + r.bytes) continue; + const std::uint64_t offset = handle - r.title; + if (offset < r.desktop_bytes || r.desktop_bytes == r.bytes) { + result = r.desktop + offset; + } else { + past_limit = true; + past_index = r.increment ? offset / r.increment : offset; + past_capacity = r.increment ? r.desktop_bytes / r.increment : r.desktop_bytes; + } + } + // The lock is released before logging: log() opens the trap log, and a lock held across it can + // serialise every descriptor translation behind one file append. ReleaseSRWLockShared(&descriptor_lock); + if (past_limit) { + static LONG reported; + if (first_calls(reported, 4)) + log("x2w-d3d12 descriptor beyond the emulated heap: index=%llu desktop_holds=%llu " + "(console heap is larger; the title must not place views here)", past_index, past_capacity); + } return result; } +// Measure, once per process, the largest shader-visible CBV/SRV/UAV heap this driver creates. The +// documented ceiling is 1,048,576 descriptors, but drivers may accept fewer, so halve from the +// ceiling until a create succeeds and then bisect upward. Each probe heap is released before the +// next one, so at most one probe holds memory at a time. +std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mask) +{ + static std::uint64_t cached; + static LONG state; // 0 none, 1 measuring, 2 measured + if (InterlockedCompareExchange(&state, 0, 0) == 2) return cached; + if (InterlockedCompareExchange(&state, 1, 0) != 0) { + // Another thread is measuring; wait for it rather than create a second set of probe heaps. + for (int spin = 0; spin < 2000 && InterlockedCompareExchange(&state, 0, 0) != 2; ++spin) Sleep(1); + return InterlockedCompareExchange(&state, 0, 0) == 2 ? cached : 0; + } + + std::uint64_t ceiling = 1048576; // the API documents this as the maximum + while (ceiling > view_heap_probe_floor) { ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Probe before treating the floor as accepted** If a driver's largest accepted shader-visible view heap is below 65,536 descriptors, this loop reaches the floor without testing it. The following bisection initializes `low` to that unverified value and only tests larger sizes, so it caches 65,536 and retries the title heap at a size the driver rejects; the fallback still fails instead of finding a smaller usable heap or declining the shortcut. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!1233
No description provided.