gpu: bind translated startup sampler heaps #1230

Merged
Jess-Doit merged 2 commits from upstream-pr/1237 into main 2026-11-24 05:00:38 +00:00
Jess-Doit commented 2026-11-24 04:52:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T04:52:47Z.


Refs #1143. Stacked on #1217.

Change

Bind the manifest's 2,048-entry sampler table at s0, space1 beside the translated static samplers. The stand-in snapshots the bound heap's 16-byte entries, decodes the sampler words, and publishes a private shader-visible heap. Unavailable entries use a transparent-black border sampler and are counted by cause. Recorded heaps stay alive through queue completion. The guarded manifest reserves entry 2047, and the original manifest can address all 2,048 entries. Translation stays opt-in through X2W_SAMPLER_HEAP=1.

Keep the 16-byte wrapped source stride separate from the adapter's desktop increment when creating and copying samplers.

Verification

Tested 2cf332e3 (this change merged with #1217's head 1e0a9834) on Windows 10 22H2 19045.6456, GTX 1060 6 GB 32.0.15.6094, and in-box WARP 10.0.19041.5794, with the D3D12 debug layer enabled. Debug and Release each passed 19/19 with zero skips: the 12 focused checks below plus main's neighbouring startup_cb_blend_* (4) and startup_stream_* (3) fixtures. The source-built desktop readback shares the stand-in's binding helpers and uses DXC and FXC. It verifies separate wrap and clamp results, an unreadable entry, the reserved fallback, and static-only manifests. Wrapped-device checks verify the 16-byte CPU handles and single and ranged copies against desktop increments of 32 and 152 bytes, respectively.

Two draws recorded before one submission sample the same index. The first heap clamps and the new heap wraps, producing 0.75 and 0.25. Rebinding the old heap for the second draw gives 0.75 again and fails the second pixel check. A separate source mutation decoded slot zero for every readable entry. Both adapters failed at offset 16 with expected=3f400000 actual=3e800000. Restoring the source passed all 12 focused CTests in each preset with zero skips and zero D3D12 warnings or errors.

After merging the updated #1217 branch, Debug and Release each passed 12/12 sampler, 4/4 CB blend, and 3/3 stream tests with zero skips. The GTX 1060 and WARP stream draws matched all 32 RGBA pixels and the shader swap changed exactly 16.

Set $python to a Python interpreter with the repository's test dependencies.

. .\tools\dev.ps1
$env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0'
$env:XBOX2WINDOWS_ADAPTER = '1060'
$filter = '^(startup_sampler_heap_|dynamic_sampler_index_|descriptor_heap_paging_|offscreen_capability_table_self_test$)'
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset "-DINTAKE_PYTHON=$python"
    cmake --build --preset $preset --target d3d12_xs_shim offscreen_check startup_stream_consumer -j 2
    ctest --preset $preset --no-tests=error -R $filter -V
    ctest --preset $preset --no-tests=error -R startup_cb_blend -V
    ctest --preset $preset --no-tests=error -R startup_stream_ -V
}

Until #1217 merges, this PR's diff also shows #1217's commits; the change here is the last commit before the merge (f1fa4355) and the merge itself.

AI-assisted (Codex, reviewed with Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574890104 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1237). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T04:52:47Z. --- Refs #1143. Stacked on #1217. ## Change Bind the manifest's 2,048-entry sampler table at `s0, space1` beside the translated static samplers. The stand-in snapshots the bound heap's 16-byte entries, decodes the sampler words, and publishes a private shader-visible heap. Unavailable entries use a transparent-black border sampler and are counted by cause. Recorded heaps stay alive through queue completion. The guarded manifest reserves entry 2047, and the original manifest can address all 2,048 entries. Translation stays opt-in through `X2W_SAMPLER_HEAP=1`. Keep the 16-byte wrapped source stride separate from the adapter's desktop increment when creating and copying samplers. ## Verification Tested `2cf332e3` (this change merged with #1217's head `1e0a9834`) on Windows 10 22H2 `19045.6456`, GTX 1060 6 GB `32.0.15.6094`, and in-box WARP `10.0.19041.5794`, with the D3D12 debug layer enabled. Debug and Release each passed 19/19 with zero skips: the 12 focused checks below plus main's neighbouring `startup_cb_blend_*` (4) and `startup_stream_*` (3) fixtures. The source-built desktop readback shares the stand-in's binding helpers and uses DXC and FXC. It verifies separate wrap and clamp results, an unreadable entry, the reserved fallback, and static-only manifests. Wrapped-device checks verify the 16-byte CPU handles and single and ranged copies against desktop increments of 32 and 152 bytes, respectively. Two draws recorded before one submission sample the same index. The first heap clamps and the new heap wraps, producing 0.75 and 0.25. Rebinding the old heap for the second draw gives 0.75 again and fails the second pixel check. A separate source mutation decoded slot zero for every readable entry. Both adapters failed at offset 16 with `expected=3f400000 actual=3e800000`. Restoring the source passed all 12 focused CTests in each preset with zero skips and zero D3D12 warnings or errors. After merging the updated #1217 branch, Debug and Release each passed 12/12 sampler, 4/4 CB blend, and 3/3 stream tests with zero skips. The GTX 1060 and WARP stream draws matched all 32 RGBA pixels and the shader swap changed exactly 16. Set `$python` to a Python interpreter with the repository's test dependencies. ```powershell . .\tools\dev.ps1 $env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0' $env:XBOX2WINDOWS_ADAPTER = '1060' $filter = '^(startup_sampler_heap_|dynamic_sampler_index_|descriptor_heap_paging_|offscreen_capability_table_self_test$)' foreach ($preset in 'dev', 'release') { cmake --preset $preset "-DINTAKE_PYTHON=$python" cmake --build --preset $preset --target d3d12_xs_shim offscreen_check startup_stream_consumer -j 2 ctest --preset $preset --no-tests=error -R $filter -V ctest --preset $preset --no-tests=error -R startup_cb_blend -V ctest --preset $preset --no-tests=error -R startup_stream_ -V } ``` Until #1217 merges, this PR's diff also shows #1217's commits; the change here is the last commit before the merge (`f1fa4355`) and the merge itself. AI-assisted (Codex, reviewed with Claude Code).
upstream-sync closed this pull request 2026-11-24 06:47:10 +00:00
tedin7 commented 2026-11-24 06:47:10 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed 2cf332e3 on Linux (Windows build/tests were not run locally).

Stacking & diff audit

  • #1217 is already merged (1e0a9834) and merged into this branch at 2cf332e3.
  • src/startup_stubs/translated_sampler_bindings.h:
    • Parses smpheap 2048 1 and smpheap 2048 1 fallback 2047 manifests; create_translated_root binds the 2,048-entry sampler descriptor table at s0, space1 via sampler_root_parameter(srvs) (2 when srvs > 0, 1 when srvs == 0).
    • snapshot_samplers guards pointer overflow (source.address > UINTPTR_MAX - translated_sampler_count * title_sampler_stride), reads page-aligned runs with ReadProcessMemory, and zeros words on partial/failed reads.
    • create_sampler_snapshot_heap creates a 2,048-entry shader-visible sampler heap, tracks unbound/out_of_range/unreadable/invalid_token counts, and fills missing/invalid entries with transparent-black border_sampler().
  • src/startup_stubs/d3d12_draw.inl & src/startup_stubs/d3d12_xs_device.cpp & src/startup_stubs/d3d12_capture.inl:
    • device_create_descriptor_heap / desktop_cpu_handle / title_descriptor_stride keep the 16-byte title sampler stride separate from the desktop descriptor increment.
    • list_set_descriptor_heaps (slot 32) tracks the active shader-visible sampler heap; retire_draw_sampler_heaps retains submitted heaps behind a signaled ID3D12Fence (and retains indefinitely if fence creation/signal fails).
  • docs/startup-runtime.md, tests/startup_sampler_heap.cpp, tests/startup_sampler_heap_check.py, CMakeLists.txt: 100% title-neutral.

Linux checks (2cf332e3)

  • tests/startup_sampler_heap_check.py (default Python/manifest self-test mode): passed (exit 0).
  • docs_links_check.py: passed (16 Markdown files, 280 links).
  • bidi_controls_check.py: passed (1047 files).
  • form_coverage_check.py: passed.
  • git diff --check: clean.
  • Windows startup_sampler_heap_{warp,hardware} and startup_sampler_heap_wrapped_{warp,hardware}: not built or run locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033899230 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1237#pullrequestreview-6033899230). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:58:39Z. **Review:** COMMENTED --- Reviewed `2cf332e3` on Linux (Windows build/tests were not run locally). ### Stacking & diff audit - `#1217` is already merged (`1e0a9834`) and merged into this branch at `2cf332e3`. - `src/startup_stubs/translated_sampler_bindings.h`: - Parses `smpheap 2048 1` and `smpheap 2048 1 fallback 2047` manifests; `create_translated_root` binds the 2,048-entry sampler descriptor table at `s0, space1` via `sampler_root_parameter(srvs)` (`2` when `srvs > 0`, `1` when `srvs == 0`). - `snapshot_samplers` guards pointer overflow (`source.address > UINTPTR_MAX - translated_sampler_count * title_sampler_stride`), reads page-aligned runs with `ReadProcessMemory`, and zeros words on partial/failed reads. - `create_sampler_snapshot_heap` creates a 2,048-entry shader-visible sampler heap, tracks `unbound`/`out_of_range`/`unreadable`/`invalid_token` counts, and fills missing/invalid entries with transparent-black `border_sampler()`. - `src/startup_stubs/d3d12_draw.inl` & `src/startup_stubs/d3d12_xs_device.cpp` & `src/startup_stubs/d3d12_capture.inl`: - `device_create_descriptor_heap` / `desktop_cpu_handle` / `title_descriptor_stride` keep the 16-byte title sampler stride separate from the desktop descriptor increment. - `list_set_descriptor_heaps` (slot 32) tracks the active shader-visible sampler heap; `retire_draw_sampler_heaps` retains submitted heaps behind a signaled `ID3D12Fence` (and retains indefinitely if fence creation/signal fails). - `docs/startup-runtime.md`, `tests/startup_sampler_heap.cpp`, `tests/startup_sampler_heap_check.py`, `CMakeLists.txt`: 100% title-neutral. ### Linux checks (`2cf332e3`) - `tests/startup_sampler_heap_check.py` (default Python/manifest self-test mode): passed (exit 0). - `docs_links_check.py`: passed (16 Markdown files, 280 links). - `bidi_controls_check.py`: passed (1047 files). - `form_coverage_check.py`: passed. - `git diff --check`: clean. - Windows `startup_sampler_heap_{warp,hardware}` and `startup_sampler_heap_wrapped_{warp,hardware}`: not built or run locally.
tedin7 commented 2026-11-24 06:50:24 +00:00 (Migrated from github.com)

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


Tested on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 2cf332e3:

  • Debug (--preset dev):
    • Build: cmake --preset dev && cmake --build out/build/dev -j 6 --target d3d12_xs_shim offscreen_check
    • Test: ctest --test-dir out/build/dev -R "^startup_sampler_heap_(controls|warp|wrapped_warp)$" --output-on-failure -> 3/3 passed (2.17s total: startup_sampler_heap_controls 0.18s, startup_sampler_heap_warp 1.72s, startup_sampler_heap_wrapped_warp 0.24s)
  • Release /O2 (--preset release):
    • Build: cmake --preset release && cmake --build out/build/release -j 6 --target d3d12_xs_shim offscreen_check
    • Test: ctest --test-dir out/build/release -R "^startup_sampler_heap_(controls|warp|wrapped_warp)$" --output-on-failure -> 3/3 passed (1.93s total: startup_sampler_heap_controls 0.17s, startup_sampler_heap_warp 1.50s, startup_sampler_heap_wrapped_warp 0.22s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122669643 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1237#issuecomment-7122669643). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:08:56Z. --- Tested on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `2cf332e3`: - **Debug (`--preset dev`)**: - Build: `cmake --preset dev && cmake --build out/build/dev -j 6 --target d3d12_xs_shim offscreen_check` - Test: `ctest --test-dir out/build/dev -R "^startup_sampler_heap_(controls|warp|wrapped_warp)$" --output-on-failure` -> **3/3 passed** (`2.17s` total: `startup_sampler_heap_controls` `0.18s`, `startup_sampler_heap_warp` `1.72s`, `startup_sampler_heap_wrapped_warp` `0.24s`) - **Release `/O2` (`--preset release`)**: - Build: `cmake --preset release && cmake --build out/build/release -j 6 --target d3d12_xs_shim offscreen_check` - Test: `ctest --test-dir out/build/release -R "^startup_sampler_heap_(controls|warp|wrapped_warp)$" --output-on-failure` -> **3/3 passed** (`1.93s` total: `startup_sampler_heap_controls` `0.17s`, `startup_sampler_heap_warp` `1.50s`, `startup_sampler_heap_wrapped_warp` `0.22s`)
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!1230
No description provided.