gpu: give a descriptor heap plain memory when its desktop start is not an address #1396

Merged
JohnConnorNPC merged 2 commits from upstream-pr/1403 into main 2026-11-24 11:07:18 +00:00
JohnConnorNPC commented 2026-11-24 10:41:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T10:41:29Z.


Change

A console executable treats the CPU start of a descriptor heap as an address. A desktop CPU descriptor handle is opaque, and a translation layer may keep tag bits in its low bits. Through vkd3d-proton a sampler heap starts at ...007.

For a view heap created without memory of its own, the device wrapper already gives the executable plain memory as the heap's CPU side and translates handles on each call. Heaps of the other types were handed the desktop start as it is.

This PR extends the existing rule: a heap of any type gets plain memory when its desktop start is not pointer-aligned (src/startup_stubs/title_heap_memory.h, one condition in device_create_descriptor_heap). Heaps whose desktop start is an address are unchanged, so nothing changes on an adapter whose handles are addresses.

What was measured

One console executable under the startup debugger, main at da8bfc74, clang-cl build under Wine 11.0 with vkd3d-proton on an RTX 4070 Ti SUPER, X2W_HOST_CPU=1:

Without this change With it
Sampler heap starts given to the executable 0x74adb007, 0x74add007 aligned addresses
Outcome access violation inside the translation layer after 1.39 s 110 s timeout, 2,623 frames presented
Translated draws none reached 37,162, none skipped, 14 of 14 pipelines

In the failing run the wrapper's call into the layer had destination 0x74add007 and source 0xfd00000074adb007: the staging heap's start, and the shader-visible heap's start with 0xfd in its top byte. How the executable arrives at that source handle is not known; only the handle and the fault were observed. With aligned starts the same copies arrive with intact handles.

Tests

New tests/startup_title_heap_check.cpp:

  • startup_title_heap: the rule without a device, on the four starts measured through the layer and on aligned starts of each heap type. startup_title_heap_tags_control runs it with the alignment test removed and must fail (WILL_FAIL).
  • startup_title_heap_device_warp / _hardware: through the wrapper, with the four heaps the executable creates without memory (two sampler heaps of 128, a render-target heap of 4,096, a depth heap of 2,048). For each it creates the same heap on the desktop device, prints both starts, and requires the wrapper's start to be an aligned address; where the desktop start is tagged the heap must have memory of its own. Then three samplers are created in the staging heap and copied to the shader-visible one through handles computed as start plus index times stride, and the device must not be removed.

Results

At ea978727, same host:

$ startup_title_heap_check
startup_title_heap: PASS (9 starts)
$ startup_title_heap_check --mutate tags
FAIL render-target heap, tagged start: 0, expected 1
startup_title_heap: 3 FAILED
$ startup_title_heap_check hardware
shader-visible sampler heap: desktop start 0x140d007 (low bits 0x7), wrapper start 0x1370000, stride 32, plain memory
staging sampler heap: desktop start 0x140d007 (low bits 0x7), wrapper start 0x36c0000, stride 32, plain memory
render-target heap: desktop start 0x1413b20 (low bits 0x0), wrapper start 0x1434000, stride 32, desktop handle
depth heap: desktop start 0x1413b20 (low bits 0x0), wrapper start 0x1454500, stride 32, desktop handle
startup_title_heap_device: PASS (4 heaps with aligned starts, plain memory where the desktop start is tagged, desktop handles where it is an address; 3 samplers created and copied)

Negative control for the device check: the same test binary against a wrapper built with the condition reverted to view heaps only:

shader-visible sampler heap: desktop start 0x140d007 (low bits 0x7), wrapper start 0x1410007, stride 32, desktop handle
FAIL shader-visible sampler heap: the start given to the executable is not an aligned address

docs_links_check.py passes.

Not verified

  • Windows and WARP. I expect native handles to be addresses, in which case every heap takes the unchanged branch and the device check reports desktop handle four times; that has not been run.
  • That an adapter with pointer-aligned but otherwise unusual handles needs nothing. The rule only looks at alignment.
  • The device check does not sample through the copied samplers. It shows that the calls are accepted, not what they draw; the 110 s run above is the only evidence that drawing works with sampler heaps on plain memory.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6579961034 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1403). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-24T10:41:29Z. --- ## Change A console executable treats the CPU start of a descriptor heap as an address. A desktop CPU descriptor handle is opaque, and a translation layer may keep tag bits in its low bits. Through vkd3d-proton a sampler heap starts at `...007`. For a view heap created without memory of its own, the device wrapper already gives the executable plain memory as the heap's CPU side and translates handles on each call. Heaps of the other types were handed the desktop start as it is. This PR extends the existing rule: a heap of any type gets plain memory when its desktop start is not pointer-aligned (`src/startup_stubs/title_heap_memory.h`, one condition in `device_create_descriptor_heap`). Heaps whose desktop start is an address are unchanged, so nothing changes on an adapter whose handles are addresses. ## What was measured One console executable under the startup debugger, `main` at `da8bfc74`, clang-cl build under Wine 11.0 with vkd3d-proton on an RTX 4070 Ti SUPER, `X2W_HOST_CPU=1`: | | Without this change | With it | |---|---|---| | Sampler heap starts given to the executable | `0x74adb007`, `0x74add007` | aligned addresses | | Outcome | access violation inside the translation layer after 1.39 s | 110 s timeout, 2,623 frames presented | | Translated draws | none reached | 37,162, none skipped, 14 of 14 pipelines | In the failing run the wrapper's call into the layer had destination `0x74add007` and source `0xfd00000074adb007`: the staging heap's start, and the shader-visible heap's start with `0xfd` in its top byte. How the executable arrives at that source handle is not known; only the handle and the fault were observed. With aligned starts the same copies arrive with intact handles. ## Tests New `tests/startup_title_heap_check.cpp`: - `startup_title_heap`: the rule without a device, on the four starts measured through the layer and on aligned starts of each heap type. `startup_title_heap_tags_control` runs it with the alignment test removed and must fail (`WILL_FAIL`). - `startup_title_heap_device_warp` / `_hardware`: through the wrapper, with the four heaps the executable creates without memory (two sampler heaps of 128, a render-target heap of 4,096, a depth heap of 2,048). For each it creates the same heap on the desktop device, prints both starts, and requires the wrapper's start to be an aligned address; where the desktop start is tagged the heap must have memory of its own. Then three samplers are created in the staging heap and copied to the shader-visible one through handles computed as start plus index times stride, and the device must not be removed. ## Results At `ea978727`, same host: ```text $ startup_title_heap_check startup_title_heap: PASS (9 starts) $ startup_title_heap_check --mutate tags FAIL render-target heap, tagged start: 0, expected 1 startup_title_heap: 3 FAILED $ startup_title_heap_check hardware shader-visible sampler heap: desktop start 0x140d007 (low bits 0x7), wrapper start 0x1370000, stride 32, plain memory staging sampler heap: desktop start 0x140d007 (low bits 0x7), wrapper start 0x36c0000, stride 32, plain memory render-target heap: desktop start 0x1413b20 (low bits 0x0), wrapper start 0x1434000, stride 32, desktop handle depth heap: desktop start 0x1413b20 (low bits 0x0), wrapper start 0x1454500, stride 32, desktop handle startup_title_heap_device: PASS (4 heaps with aligned starts, plain memory where the desktop start is tagged, desktop handles where it is an address; 3 samplers created and copied) ``` Negative control for the device check: the same test binary against a wrapper built with the condition reverted to view heaps only: ```text shader-visible sampler heap: desktop start 0x140d007 (low bits 0x7), wrapper start 0x1410007, stride 32, desktop handle FAIL shader-visible sampler heap: the start given to the executable is not an aligned address ``` `docs_links_check.py` passes. ## Not verified - Windows and WARP. I expect native handles to be addresses, in which case every heap takes the unchanged branch and the device check reports `desktop handle` four times; that has not been run. - That an adapter with pointer-aligned but otherwise unusual handles needs nothing. The rule only looks at alignment. - The device check does not sample through the copied samplers. It shows that the calls are accepted, not what they draw; the 110 s run above is the only evidence that drawing works with sampler heaps on plain memory.
tedin7 commented 2026-11-24 11:02:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:52:25Z.

Review: COMMENTED


Reviewed commit ea9787279d53e3d802ce0ed148d21aa218d84560:

  • Diff & scope: Cleanly adds x2w_startup::heap_needs_title_memory in src/startup_stubs/title_heap_memory.h (returns true for CBV_SRV_UAV or non-pointer-aligned desktop_cpu_start) and wires it into device_create_descriptor_heap in src/startup_stubs/d3d12_xs_device.cpp with VirtualAlloc fallback and descriptor_ranges tracking, plus tests/startup_title_heap_check.cpp (9 unit cases, --mutate tags negative control, and device test creating 4 heaps and copying 3 samplers via CopyDescriptorsSimple) and docs/startup-runtime.md.
  • Linux checks: git diff --check clean; tests/docs_links_check.py (16 Markdown files, 316 links) and tests/bidi_controls_check.py (1178 files) passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev, startup_title_heap_check): 4/4 passed (startup_title_heap, startup_title_heap_tags_control, startup_title_heap_device_warp, startup_title_heap_device_hardware).
    • Release /O2 (--preset release, startup_title_heap_check): 4/4 passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037894697 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1403#pullrequestreview-6037894697). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:52:25Z. **Review:** COMMENTED --- Reviewed commit `ea9787279d53e3d802ce0ed148d21aa218d84560`: - **Diff & scope**: Cleanly adds `x2w_startup::heap_needs_title_memory` in `src/startup_stubs/title_heap_memory.h` (returns true for `CBV_SRV_UAV` or non-pointer-aligned `desktop_cpu_start`) and wires it into `device_create_descriptor_heap` in `src/startup_stubs/d3d12_xs_device.cpp` with `VirtualAlloc` fallback and `descriptor_ranges` tracking, plus `tests/startup_title_heap_check.cpp` (9 unit cases, `--mutate tags` negative control, and device test creating 4 heaps and copying 3 samplers via `CopyDescriptorsSimple`) and `docs/startup-runtime.md`. - **Linux checks**: `git diff --check` clean; `tests/docs_links_check.py` (16 Markdown files, 316 links) and `tests/bidi_controls_check.py` (1178 files) passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Debug (`--preset dev`, `startup_title_heap_check`): **4/4 passed** (`startup_title_heap`, `startup_title_heap_tags_control`, `startup_title_heap_device_warp`, `startup_title_heap_device_hardware`). - Release `/O2` (`--preset release`, `startup_title_heap_check`): **4/4 passed**.
R0Y00 commented 2026-11-24 11:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:58:06Z.


Pushed 85c6183e so heap creation returns E_OUTOFMEMORY if it needs CPU backing and that allocation fails. The wrapper therefore never publishes the tagged handle as a CPU address on that path. The control injects a failed allocation for a tagged sampler and verifies that an aligned sampler or caller-supplied backing does not allocate. All four startup_title_heap Release checks passed, including WARP and RTX 4060 Laptop.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129479585 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1403#issuecomment-7129479585). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T10:58:06Z. --- Pushed 85c6183e so heap creation returns E_OUTOFMEMORY if it needs CPU backing and that allocation fails. The wrapper therefore never publishes the tagged handle as a CPU address on that path. The control injects a failed allocation for a tagged sampler and verifies that an aligned sampler or caller-supplied backing does not allocate. All four startup_title_heap Release checks passed, including WARP and RTX 4060 Laptop.
upstream-sync closed this pull request 2026-11-24 12:02:44 +00:00
tedin7 commented 2026-11-24 12:02:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:08:19Z.

Review: COMMENTED


Retested at commit 85c6183e (delta over ea978727):

  • Code & controls: ensure_title_heap_memory in src/startup_stubs/title_heap_memory.h cleanly extracts the required-backing check and rejects OOM when heap_needs_title_memory requires CPU backing and allocation fails (E_OUTOFMEMORY in device_create_descriptor_heap, releasing heap), while preserving caller-provided title_memory without extra allocation; tests/startup_title_heap_check.cpp covers OOM rejection, empty backing on failure, aligned sampler skip, and caller-provided memory retention.
  • Linux: git diff --check clean; tests/docs_links_check.py passed (16 Markdown files, 316 links); tests/bidi_controls_check.py passed (1178 files).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): startup_title_heap_check built; ctest -R '^startup_title_heap' 4/4 passed (startup_title_heap, startup_title_heap_tags_control, startup_title_heap_device_warp, startup_title_heap_device_hardware).
    • Release /O2 (--preset release): startup_title_heap_check built; ctest -R '^startup_title_heap' 4/4 passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038101598 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1403#pullrequestreview-6038101598). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:08:19Z. **Review:** COMMENTED --- Retested at commit `85c6183e` (delta over `ea978727`): - **Code & controls**: `ensure_title_heap_memory` in `src/startup_stubs/title_heap_memory.h` cleanly extracts the required-backing check and rejects OOM when `heap_needs_title_memory` requires CPU backing and allocation fails (`E_OUTOFMEMORY` in `device_create_descriptor_heap`, releasing `heap`), while preserving caller-provided `title_memory` without extra allocation; `tests/startup_title_heap_check.cpp` covers OOM rejection, empty backing on failure, aligned sampler skip, and caller-provided memory retention. - **Linux**: `git diff --check` clean; `tests/docs_links_check.py` passed (16 Markdown files, 316 links); `tests/bidi_controls_check.py` passed (1178 files). - **Windows Server 2025** (Build 26100, MSVC 14.44.35207 + D3D12 WARP): - **Debug (`--preset dev`)**: `startup_title_heap_check` built; `ctest -R '^startup_title_heap'` **4/4 passed** (`startup_title_heap`, `startup_title_heap_tags_control`, `startup_title_heap_device_warp`, `startup_title_heap_device_hardware`). - **Release `/O2` (`--preset release`)**: `startup_title_heap_check` built; `ctest -R '^startup_title_heap'` **4/4 passed**.
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!1396
No description provided.