gpu: test overlapping placements in one existing heap (Part of #3676) #3723

Merged
timbot103 merged 2 commits from upstream-pr/3723 into main 2026-12-02 02:13:57 +00:00
timbot103 commented 2026-12-01 10:53:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-01T10:53:11Z.


Refs #3676 (item (e), standalone D3D12 fixture only — no runtime integration).

Summary

Adds a standalone D3D12 fixture (tests/existing_heap_shared_buffer_check.cpp, tests/cmake/existing_heap_shared_buffer.cmake, CMakePresets.json, docs/experiments/existing-heap-shared-buffer.md) that verifies overlapping unaligned logical buffer views over one desktop placed buffer in a single OpenExistingHeapFromAddress heap:

  • Allocates one committed 128 KiB MEM_PRIVATE VirtualAlloc region, opens it via ID3D12Device3::OpenExistingHeapFromAddress, and places one cross-adapter UAV-capable buffer over the whole allocation.
  • Defines two 256-byte logical ranges at sub-64 KiB offsets 0x100 (A) and 0x180 (B), overlapping on [0x180, 0x200) (32 dwords) with guard patterns filling the rest of the 128 KiB allocation:
    1. CPU → GPU: CPU writes distinct patterns to A then B; GPU copies both ranges to a readback buffer and verifies all 64 dwords of A and B (A's second half matches B's first half).
    2. GPU → CPU: Compute UAV writes B's first 32 dwords; after fence completion, CPU reads the VirtualAlloc pointer directly at both A's overlap offset and B's base and verifies all guards across the 128 KiB allocation.
    3. GPU → GPU: Compute UAV writes A's second half, executes a UAV barrier on the placed buffer, and a second dispatch reads B's first half and echoes it to B's second half; CPU verifies both the echo and full-allocation guards after the fence.
  • Negative control: --offset-control / --corrupt-offset binds B's UAV at byte 0 instead of 0x180, verifying that the overlap checks fail and that the write landed only in [0x000, 0x080) (direct --corrupt-offset exits with code 3).
  • Registers existing_heap_shared_buffer_{warp,hardware} and existing_heap_shared_buffer_offset_control_{warp,hardware} in CTest (SKIP_RETURN_CODE 77 when D3D12_FEATURE_EXISTING_HEAPS is unsupported) and includes both WARP cases in the pr smoke preset.

Verification

Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100. D3D12 debug layer unavailable on this host (D3D12GetDebugInterface=0x887a002d, reported honestly by the fixture; info-queue error checking is wired in when installed).

  • Debug (dev preset): ctest --preset dev --no-tests=error -R '^existing_heap_shared_buffer_' -V -> 4/4 passed:
    • WARP (Microsoft Basic Render Driver, driver 10.0.26100.9818, D3D12_FEATURE_EXISTING_HEAPS=1): positive + offset control passed
    • Hardware (NVIDIA GeForce RTX 5080, 10de:2c02, driver 32.0.16.2140, D3D12_FEATURE_EXISTING_HEAPS=1): positive + offset control passed
  • Release (release preset): ctest --preset release --no-tests=error -R '^existing_heap_shared_buffer_' -V -> 4/4 passed on both WARP and RTX 5080.
  • Direct --corrupt-offset verified exit code 3 on both WARP and RTX 5080.
  • git diff --check HEAD^ HEAD clean.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5584197545 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3723). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-01T10:53:11Z. --- Refs #3676 (item (e), standalone D3D12 fixture only — no runtime integration). ## Summary Adds a standalone D3D12 fixture (`tests/existing_heap_shared_buffer_check.cpp`, `tests/cmake/existing_heap_shared_buffer.cmake`, `CMakePresets.json`, `docs/experiments/existing-heap-shared-buffer.md`) that verifies overlapping unaligned logical buffer views over one desktop placed buffer in a single `OpenExistingHeapFromAddress` heap: - Allocates one committed 128 KiB `MEM_PRIVATE` `VirtualAlloc` region, opens it via `ID3D12Device3::OpenExistingHeapFromAddress`, and places one cross-adapter UAV-capable buffer over the whole allocation. - Defines two 256-byte logical ranges at sub-64 KiB offsets `0x100` (A) and `0x180` (B), overlapping on `[0x180, 0x200)` (32 dwords) with guard patterns filling the rest of the 128 KiB allocation: 1. **CPU → GPU:** CPU writes distinct patterns to A then B; GPU copies both ranges to a readback buffer and verifies all 64 dwords of A and B (A's second half matches B's first half). 2. **GPU → CPU:** Compute UAV writes B's first 32 dwords; after fence completion, CPU reads the `VirtualAlloc` pointer directly at both A's overlap offset and B's base and verifies all guards across the 128 KiB allocation. 3. **GPU → GPU:** Compute UAV writes A's second half, executes a UAV barrier on the placed buffer, and a second dispatch reads B's first half and echoes it to B's second half; CPU verifies both the echo and full-allocation guards after the fence. - **Negative control:** `--offset-control` / `--corrupt-offset` binds B's UAV at byte 0 instead of `0x180`, verifying that the overlap checks fail and that the write landed only in `[0x000, 0x080)` (direct `--corrupt-offset` exits with code `3`). - Registers `existing_heap_shared_buffer_{warp,hardware}` and `existing_heap_shared_buffer_offset_control_{warp,hardware}` in CTest (`SKIP_RETURN_CODE 77` when `D3D12_FEATURE_EXISTING_HEAPS` is unsupported) and includes both WARP cases in the `pr` smoke preset. ## Verification Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100. D3D12 debug layer unavailable on this host (`D3D12GetDebugInterface=0x887a002d`, reported honestly by the fixture; info-queue error checking is wired in when installed). - **Debug (`dev` preset):** `ctest --preset dev --no-tests=error -R '^existing_heap_shared_buffer_' -V` -> **4/4 passed**: - WARP (`Microsoft Basic Render Driver`, driver `10.0.26100.9818`, `D3D12_FEATURE_EXISTING_HEAPS=1`): positive + offset control passed - Hardware (`NVIDIA GeForce RTX 5080`, `10de:2c02`, driver `32.0.16.2140`, `D3D12_FEATURE_EXISTING_HEAPS=1`): positive + offset control passed - **Release (`release` preset):** `ctest --preset release --no-tests=error -R '^existing_heap_shared_buffer_' -V` -> **4/4 passed** on both WARP and RTX 5080. - Direct `--corrupt-offset` verified exit code `3` on both WARP and RTX 5080. - `git diff --check HEAD^ HEAD` clean. AI-assisted.
Leyukaka commented 2026-12-01 14:16:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T14:16:41Z.

Review: COMMENTED


In main, --offset-control exits successfully for both offset_mismatch and 0. If a regression sends the control down the positive path, CTest will still report a pass. Could the wrapper require result == offset_mismatch in control mode and return result directly in the other modes?

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6133065549 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3723#pullrequestreview-6133065549). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T14:16:41Z. **Review:** COMMENTED --- In `main`, `--offset-control` exits successfully for both `offset_mismatch` and `0`. If a regression sends the control down the positive path, CTest will still report a pass. Could the wrapper require `result == offset_mismatch` in control mode and return `result` directly in the other modes?
timbot103 commented 2026-12-01 22:43:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-01T22:43:43Z.


@Leyukaka Good catch — fixed in 4257a909: --offset-control now requires result == offset_mismatch (returning 1 with a failure message if it ever falls through with 0 or another code), while positive and --corrupt-offset modes return result directly. Re-verified 4/4 in Debug and Release on WARP (10.0.26100.9818) and RTX 5080 (32.0.16.2140), plus direct --corrupt-offset exit code 3 on both.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7328251005 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3723#issuecomment-7328251005). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-01T22:43:43Z. --- @Leyukaka Good catch — fixed in `4257a909`: `--offset-control` now requires `result == offset_mismatch` (returning `1` with a failure message if it ever falls through with `0` or another code), while positive and `--corrupt-offset` modes return `result` directly. Re-verified 4/4 in Debug and Release on WARP (`10.0.26100.9818`) and RTX 5080 (`32.0.16.2140`), plus direct `--corrupt-offset` exit code 3 on both.
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!3723
No description provided.