Batch buffer_ops dispatches and avoid duplicate D3D12 device creation #137

Manually merged
github merged 1 commit from gh-pr/137/head into gh-pr/137/base 2026-11-26 21:29:31 +00:00
Owner

@⁠PrivacyOnion on GitHub · 2026-11-21 16:52 UTC · original
PrivacyOnion:batch-buffer-ops-and-single-device → main · +133 −68 · 2 files · 1 commits · merged 2026-11-21 17:57 UTC

## 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
**@⁠PrivacyOnion** on GitHub · 2026-11-21 16:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/137) `PrivacyOnion:batch-buffer-ops-and-single-device` → `main` · +133 −68 · 2 files · 1 commits · merged 2026-11-21 17:57 UTC ## 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 ```
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:29:29 +00:00
github manually merged commit 0a016ecda7 into gh-pr/137/base 2026-11-26 21:29:31 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 17:17 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-21 17:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/137#issuecomment-7066366141) 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.
Author
Owner

@⁠PrivacyOnion on GitHub · 2026-11-21 17:50 UTC · original

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
**@⁠PrivacyOnion** on GitHub · 2026-11-21 17:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/137#issuecomment-7066782388) 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 ```
This discussion has been locked. Commenting is limited to contributors.
No description provided.