gpu: emulate a shader-visible view heap larger than the driver accepts #1233
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1240"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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] == byteshandshake still uses the requested byte count, soGetCPUDescriptorHandleForHeapStartkeeps 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:NULL+0x30in the title's arena allocatorThe 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.mdcalls these stand-ins experimental and opt-in, which suits this.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
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".
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 byInterlockedCompareExchangestate0 -> 1 -> 2) for shader-visibleCBV_SRV_UAVheaps whenCreateDescriptorHeapreturnsE_INVALIDARGandNumDescriptors > view_heap_probe_floor(65536), halving from1,048,576and bisecting upward.device_create_descriptor_heap: clamps only the desktopCreateDescriptorHeaprequest while keepingbytes(std::uint64_tarithmetic),title_memoryhandshake (extra[1] == bytes), andnote_heapat the requestedNumDescriptors.desktop_cpu_handle: checksoffset < r.desktop_bytes || r.desktop_bytes == r.bytesand releasesdescriptor_lockbefore callinglog(...)(up to 4 times viafirst_calls(reported, 4)).CreateDescriptorHeapwere to fail even atview_heap_probe_floor(65536), the halving loop stops atceiling == 65536without confirming65536succeeds (unlikely on D3D12 drivers, butlowwould remain unverified).offset >= r.desktop_byteswhenr.desktop_bytes < r.bytes) leaveresult = 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.2000 * Sleep(1)(~2 s) and return0if probing has not finished, skipping clamping for that call.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)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.
16761eeℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T05:15:16Z.
Fixed in
692aa6ca, and the branch is rebased onto currentmain(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:
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:--preset dev):cmake --build --preset dev --target d3d12_xs_shim_check d3d12_xs_shim -- -j 6):22.94s(configure2.04s)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)/O2(--preset release):cmake --build --preset release --target d3d12_xs_shim_check d3d12_xs_shim -- -j 6):43.64s(configure1.82s)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)Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T05:29:20Z.
@triggered02, I am using your
c74485f5as 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.Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T05:39:50Z.
@R0Y00 — here is exactly what
c74485f5changes in the runtime, and the two places it will meet your follow-up.Surface:
src/startup_stubs/d3d12_xs_device.cpponly (+115 lines; plustests/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
DescriptorRangegainsdesktop_descriptors: how many title descriptors the desktop heap actually covers. It is stored underdescriptor_lockalongsidetitle/bytes/desktop.bytesdeliberately stays the title's full extent (1,245,184 descriptors), whiledesktopis the clamped heap's start — so readdesktop_descriptors, notbytes, 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_INVALIDARGon my GTX 1660 SUPER,E_OUTOFMEMORYon the RTX 3060 you measured.Two things you should know before you build on it, both mine to fix if you want:
The probe cache is process-wide, not per adapter.
cached/stateare 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.The overrun is detected but not enforced — that is your scope, not mine.
desktop_cpu_handle()setspast_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, anddevice_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.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T06:06:42Z.
Reviewed
ab1ea74aand 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_OUTOFMEMORYhad to be included alongsideE_INVALIDARG, butFAILED(hr)also swallowed unrelated failures such asE_NOINTERFACEandE_POINTERand turned them into a capacity retry. Matching exactly the two capacity codes is what the situation actually calls for. Removing the redundantcached = 0there 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:
E_NOINTERFACEnegative 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 callingGetCPUDescriptorHandleForHeapStartthrough 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,
releasepreset, atab1ea74a):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.
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 163If 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
lowto 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 👍 / 👎.