Batch buffer_ops dispatches and avoid duplicate D3D12 device creation #136

Merged
PrivacyOnion merged 1 commit from upstream-pr/137 into main 2026-11-21 17:57:49 +00:00
PrivacyOnion commented 2026-11-21 16:52:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by PrivacyOnion on 2026-11-21T16:52:50Z.


## Change

  1. tests/offscreen_check.cpp:
    • Create and retain the ComPtr<ID3D12Device> directly inside select_adapter (using device_factory->CreateDevice when OFFSCREEN_AGILITY_620 is enabled or D3D12CreateDevice otherwise) instead of probing hardware adapters with D3D12CreateDevice(..., nullptr) and then creating the device a second time in main().
  2. tests/buffer_ops.cpp:
    • Allocate the upload ((case_count + 1) * sizeof(Words)), output (sizeof(Words)), and readback (case_count * sizeof(Words)) buffers once in check_buffer_ops and record all 26 CopyBlocks, FillBlocks, NumberBlocks, CopySpan, and ResetBounds cases into a single ComputeCommands command list before calling submit_and_wait and verifying all 26 readback slices.
    • Replaces 78 per-case CreateCommittedResource calls and 26 separate ComputeCommands queues, allocators, command lists, fences, and CPU-GPU sync waits with a single submission (bvh_buffer_ops_hardware drops from 1.07s to 0.34s; bvh_buffer_ops_warp drops from 0.13s to 0.05s).

Verification

.\tools\dev.ps1
cmake --build --preset dev --target offscreen_check
ctest --preset dev -R "^(offscreen_|bvh_buffer_ops_)" --no-tests=error -V
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531709756 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/137). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T16:52:50Z. --- ## Change 1. **`tests/offscreen_check.cpp`**: - Create and retain the `ComPtr<ID3D12Device>` directly inside `select_adapter` (using `device_factory->CreateDevice` when `OFFSCREEN_AGILITY_620` is enabled or `D3D12CreateDevice` otherwise) instead of probing hardware adapters with `D3D12CreateDevice(..., nullptr)` and then creating the device a second time in `main()`. 2. **`tests/buffer_ops.cpp`**: - Allocate the `upload` (`(case_count + 1) * sizeof(Words)`), `output` (`sizeof(Words)`), and `readback` (`case_count * sizeof(Words)`) buffers once in `check_buffer_ops` and record all 26 `CopyBlocks`, `FillBlocks`, `NumberBlocks`, `CopySpan`, and `ResetBounds` cases into a single `ComputeCommands` command list before calling `submit_and_wait` and verifying all 26 readback slices. - Replaces 78 per-case `CreateCommittedResource` calls and 26 separate `ComputeCommands` queues, allocators, command lists, fences, and CPU-GPU sync waits with a single submission (`bvh_buffer_ops_hardware` drops from `1.07s` to `0.34s`; `bvh_buffer_ops_warp` drops from `0.13s` to `0.05s`). ## Verification ```powershell .\tools\dev.ps1 cmake --build --preset dev --target offscreen_check ctest --preset dev -R "^(offscreen_|bvh_buffer_ops_)" --no-tests=error -V ```
upstream-sync closed this pull request 2026-11-24 06:41:29 +00:00
R0Y00 commented 2026-11-24 06:47:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:17:42Z.


Please coordinate with #116 before landing the select_adapter rewrite. Rebase the device-selection change after #116 and verify explicit adapter selection, WARP and the batched buffer-ops results together.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066366141 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/137#issuecomment-7066366141). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T17:17:42Z. --- Please coordinate with #116 before landing the select_adapter rewrite. Rebase the device-selection change after #116 and verify explicit adapter selection, WARP and the batched buffer-ops results together.
PrivacyOnion commented 2026-11-24 06:47:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by PrivacyOnion on 2026-11-21T17:50:18Z.


Rebased onto main and integrated the XBOX2WINDOWS_ADAPTER substring filter from #116 into select_adapter:

  • When XBOX2WINDOWS_ADAPTER is unset or matches desc.Description (case-insensitive), select_adapter creates and retains the ComPtr<ID3D12Device> once on that adapter.
  • When XBOX2WINDOWS_ADAPTER does not match a D3D12 hardware adapter, it probes support without allocating a full device, logs XBOX2WINDOWS_ADAPTER: skipping <Description>, and fails with No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=<filter> if no adapter matches.

Verified explicit adapter selection (XBOX2WINDOWS_ADAPTER="RTX 5070" and unmatched XBOX2WINDOWS_ADAPTER="no adapter has this name"), WARP, and the batched 26-case buffer_ops run together:

> $env:XBOX2WINDOWS_ADAPTER = "RTX 5070"
> .\out\build\dev\offscreen_check.exe hardware --buffer-ops
backend=hardware debug_layer=enabled
adapter=NVIDIA GeForce RTX 5070 vendor=10de device=2f04
driver=32.0.16.1664
shader_model_capped_at_6_5=0x65
buffer_cases=26 words_per_case=384 mismatches=0
debug_errors=0 debug_warnings=0

> $env:XBOX2WINDOWS_ADAPTER = "no adapter has this name"
> .\out\build\dev\offscreen_check.exe hardware --buffer-ops
XBOX2WINDOWS_ADAPTER: skipping NVIDIA GeForce RTX 5070
No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=no adapter has this name
Select adapter
(exit code 1)

1/4 Test #13: offscreen_hardware ...............   Passed    0.30 sec
2/4 Test #21: bvh_buffer_ops_hardware ..........   Passed    0.29 sec
3/4 Test #31: offscreen_warp ...................   Passed    0.05 sec
4/4 Test #39: bvh_buffer_ops_warp ..............   Passed    0.05 sec
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066782388 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/137#issuecomment-7066782388). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T17:50:18Z. --- Rebased onto `main` and integrated the `XBOX2WINDOWS_ADAPTER` substring filter from #116 into `select_adapter`: - When `XBOX2WINDOWS_ADAPTER` is unset or matches `desc.Description` (case-insensitive), `select_adapter` creates and retains the `ComPtr<ID3D12Device>` once on that adapter. - When `XBOX2WINDOWS_ADAPTER` does not match a D3D12 hardware adapter, it probes support without allocating a full device, logs `XBOX2WINDOWS_ADAPTER: skipping <Description>`, and fails with `No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=<filter>` if no adapter matches. Verified explicit adapter selection (`XBOX2WINDOWS_ADAPTER="RTX 5070"` and unmatched `XBOX2WINDOWS_ADAPTER="no adapter has this name"`), `WARP`, and the batched 26-case `buffer_ops` run together: ```text > $env:XBOX2WINDOWS_ADAPTER = "RTX 5070" > .\out\build\dev\offscreen_check.exe hardware --buffer-ops backend=hardware debug_layer=enabled adapter=NVIDIA GeForce RTX 5070 vendor=10de device=2f04 driver=32.0.16.1664 shader_model_capped_at_6_5=0x65 buffer_cases=26 words_per_case=384 mismatches=0 debug_errors=0 debug_warnings=0 > $env:XBOX2WINDOWS_ADAPTER = "no adapter has this name" > .\out\build\dev\offscreen_check.exe hardware --buffer-ops XBOX2WINDOWS_ADAPTER: skipping NVIDIA GeForce RTX 5070 No D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=no adapter has this name Select adapter (exit code 1) 1/4 Test #13: offscreen_hardware ............... Passed 0.30 sec 2/4 Test #21: bvh_buffer_ops_hardware .......... Passed 0.29 sec 3/4 Test #31: offscreen_warp ................... Passed 0.05 sec 4/4 Test #39: bvh_buffer_ops_warp .............. Passed 0.05 sec ```
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!136
No description provided.