Skip to content

test(d3d12): add post-vkDestroyDevice leak check, shared-texture handoff, and TIMEOUT 120 (#1081 follow-up) - #1081

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
totonicpu:pr/add-d3d12-multithread-test
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
totonicpu:pr/add-d3d12-multithread-test

Conversation

@totonicpu

Copy link
Copy Markdown
Contributor

Summary

Adds d3d12_multithread_test (runtime/test/d3d12_multithread_test.cpp, registered in CTest as d3d12_multithread with SKIP_RETURN_CODE 77 when no Vulkan GPU is available) to exercise concurrent multi-threaded D3D12-on-Vulkan execution paths that single-threaded tests do not cover:

  • Concurrent dual-queue submissions: two worker threads synchronize at a start barrier and submit 32 iterations each (64 total) on two independent ID3D12CommandQueues — transitioning render targets, clearing to iteration-unique colours, copying to readback buffers, waiting via ID3D12Fence::SetEventOnCompletion, and verifying every readback texel.
  • Concurrent resource churn: a third thread continuously creates and releases temporary ID3D12Resource buffers on the shared ID3D12Device1 while both queues are actively executing.
  • Multi-fence completion: verifies ID3D12Device1::SetEventOnMultipleFenceCompletion (D3D12_MULTIPLE_FENCE_WAIT_FLAG_ALL) across both queues' fences after concurrent work.

Verification

  • Built with MSVC x64 (/W4 /permissive-, 0 warnings) in both RelWithDebInfo and Debug.
  • ctest -R "^d3d12_multithread$" with LEONIDA_VK_VALIDATION=1 (Core + Synchronization Validation) on NVIDIA GeForce RTX 4070 Ti: PASS (0 validation errors) in both RelWithDebInfo (0.41s) and Debug (0.37s).

@LocranKing

Copy link
Copy Markdown
Contributor

Tested 7d42b49 on Windows 11 Build 26200, native MSVC 14.44.35207 (Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo via scripts\build_runtime.ps1), NVIDIA GeForce RTX 3060 Ti (driver 621.01, Vulkan 1.4.357): pass.

  • Build succeeded with 0 warnings.
  • d3d12_multithread_test.exe with LEONIDA_VK_VALIDATION=1 and VK_LOADER_LAYERS_DISABLE=~implicit~: PASS (2 queues x 32 concurrent submissions + resource churn + multi-fence wait; 0 validation errors).

AI-assisted. No game files.

@quackottu quackottu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 7d42b49 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest: 100% tests passed, 0 tests failed out of 51 (gameinput disabled, no SDL3).
  • d3d12_multithread_test (new here): exit 0, 0 validation messages.
  • 49 test programs exit 0 with 0 validation messages.
  • Same as main, not from this PR:
    • d3d12_clear_test: 3 formats differ from WARP (the NVIDIA 0.5 tie rounding, #521).
    • vk_binary_occlusion_test stops at its argument check.
    • d3d12_fence_timing_test and d3d12_vulkan_device_test: 3 VUID-vkCreateDevice-ppEnabledExtensionNames-01387 from the standalone device (fixed by #1027).

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested 7d42b49 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass

  • Build: 0 warnings. ctest: 100% passed, 0 failed out of 51.
  • d3d12_multithread_test: PASS, also with LEONIDA_VK_VALIDATION=1 (0 validation errors), and 5/5 repeated runs.

Two small notes from reading it:

  • The header comment says SetEventOnMultipleFenceCompletion is checked with ALL and ANY, but only ALL is exercised.
  • From std::atomic<int> failures down to the end of the block, the body isn't indented one level inside its {, and the final WaitForSingleObject line is indented one level too far.

AI-assisted. No game files.

@totonicpu

Copy link
Copy Markdown
Contributor Author

Thanks @undeadhuman37 (and @quackottu / @LocranKing) for testing! Fixed both notes in ${sha}\ (rebased onto \c63773d5): added the \D3D12_MULTIPLE_FENCE_WAIT_FLAG_ANY\ check alongside \ALL, and cleaned up the block indentation. Re-verified with \LEONIDA_VK_VALIDATION=1\ in both \RelWithDebInfo\ and \Debug: PASS (0 warnings, 0 validation errors).

@totonicpu
totonicpu force-pushed the pr/add-d3d12-multithread-test branch from 7d42b49 to 00aff09 Compare November 22, 2026 07:03
@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 7d42b49 (on main) on AMD RDNA2 iGPU and RTX 5070: pass.

Windows 11 Home 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo (scripts\build_runtime.ps1), LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~. One PC, two GPUs, picked with VK_LOADER_DRIVERS_SELECT: AMD Radeon iGPU of a Ryzen 7 9800X3D (RDNA2, 2 CUs, AMD 2026.04.17) and NVIDIA GeForce RTX 5070 (Blackwell, 617.42).

  • d3d12_multithread (ctest): passes on both GPUs with validation on.
  • ctest: 51/51 on both GPUs.

One thing to know: on the small iGPU the new test takes 18.3 s, against 0.22 s on the RTX 5070. It's well inside ctest's default timeout, but with validation on, an older or smaller iGPU could get close, so it may be worth giving it an explicit TIMEOUT property or a lighter iteration count.

AI-assisted (Claude Code). No game files.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested 00aff09 on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 19.44 (VS generator, RelWithDebInfo), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: pass

  • Build has 0 warnings. ctest (validation on): 50/50, including d3d12_multithread.
  • d3d12_multithread_test: PASS (2 queues x 32 concurrent submissions + resource churn + multi-fence wait; 0 validation errors), with the new WAIT_FLAG_ANY check. Looped 25 more times: 25/25, 0 validation messages. (7d42b49 before the rebase: also 26/26.)

This test already found a real bug. I dropped it into #927's earlier head (23d2e90) and looped it: 1 of 25 runs failed with THREADING ERROR : object of type VkBuffer is simultaneously used in current thread ... (vkDestroyBuffer) and thread ... (vkDestroyBuffer), and another leaked 16 objects at vkDestroyDevice. Details are on #927. So it's worth having in CI.

Two small suggestions:

  • The leak run still printed PASS: validation_errors() is read before the device is released, so messages from vkDestroyDevice (leaked objects) come after the verdict. Releasing the device before the check, or checking again after, would catch those.
  • No resource is shared between the queues: each thread has its own render target, readback buffer and fence, so the two queues never update the layout tracker for the same resource. That's the kind of bug cross-queue ordering changes can cause. A case where both queues transition and copy one texture, ordered with a fence Wait on the other queue, would cover it.

AI-assisted (Claude Code).

@totonicpu

Copy link
Copy Markdown
Contributor Author

Thanks @Parakeet-Wheat and @UlteriorMotive00 for the great suggestions! Updated in ${sha}:

  • Post-\�kDestroyDevice\ leak detection: \�ktest::Device\ now lives in an inner scope so ~Device()\ runs \�kDestroyDevice\ before checking \�ktest::validation_error_count() != 0\ (catching \VUID-vkDestroyDevice-device-05137\ leaks).
  • Cross-queue shared-texture handoff: added a two-round test where queue 0 clears a shared 4x4 RGBA8 texture and signals fence 0, and queue 1 \Wait()\s on fence 0, transitions the same shared texture to \COPY_SOURCE, copies to readback, and verifies all 16 texels.
  • CTest timeout: set \TIMEOUT 120\ on \d3d12_multithread\ for small iGPUs under validation.

Re-verified on NVIDIA GeForce RTX 4070 Ti (\LEONIDA_VK_VALIDATION=1): \RelWithDebInfo\ (0.39s), \Debug\ (0.37s), and 5/5 repeated runs PASS with 0 validation errors.

@totonicpu
totonicpu force-pushed the pr/add-d3d12-multithread-test branch from 00aff09 to bcea7c5 Compare November 22, 2026 07:36
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@ReSo72

ReSo72 commented Nov 22, 2026

Copy link
Copy Markdown

Tested bcea7c5 on two GPUs, Windows 11 26300, MSVC 14.50: pass.

  • d3d12_multithread_test run 10 times in a row on each GPU, exit 0 every time, 0 validation errors (dual-queue submissions, resource churn, shared-texture handoff, multi-fence ALL/ANY):
    • RTX 5070 Ti, NVIDIA 617.42
    • AMD Radeon iGPU (RDNA2, 1002:13C0), AMD 25.10.30
  • ctest on the 5070 Ti: 55/55 passed (gameinput disabled, built without SDL3).

The earlier head 00aff09 passed the same 10 runs on both GPUs.

@undeadhuman37

Copy link
Copy Markdown
Contributor

Re-tested bcea7c5 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass. Thanks for the fixes.

  • Build: 0 warnings. ctest: 56/56 passed (gameinput disabled).
  • d3d12_multithread_test: PASS 5 of 5 runs without validation and 5 of 5 with LEONIDA_VK_VALIDATION=1, 0 validation errors (2 queues x 32 concurrent submissions, resource churn, shared-texture handoff, multi-fence ALL/ANY).
  • GitHub shows this PR as conflicting with main now, probably in runtime/CMakeLists.txt. I tested the PR head as it is.

AI-assisted. No game files.

…texture handoff, and TIMEOUT 120 to d3d12_multithread
@totonicpu
totonicpu force-pushed the pr/add-d3d12-multithread-test branch from bcea7c5 to 81fc542 Compare November 22, 2026 08:00
@totonicpu totonicpu changed the title test(d3d12): add multi-threaded dual-queue submission, resource churn, and multi-fence GPU test test(d3d12): add post-vkDestroyDevice leak check, shared-texture handoff, and TIMEOUT 120 (#1081 follow-up) Nov 22, 2026
@ItsNotRexed
ItsNotRexed merged commit 3921cdf into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants