Skip to content

fix(test): destroy atomic-mode Vulkan resources and device before exiting vk_bindless_test - #5427

Open
Persudes wants to merge 1 commit into
ItsNotRexed:mainfrom
Persudes:fix/vk-bindless-atomic-teardown
Open

Persudes wants to merge 1 commit into
ItsNotRexed:mainfrom
Persudes:fix/vk-bindless-atomic-teardown

Conversation

@Persudes

Copy link
Copy Markdown
Contributor

Summary

Fixes an early return inside atomic_mode (ps_imgatomic) in runtime/test/vk_bindless_test.cpp that exited directly out of the configuration loop before destroying any Vulkan resources, BindlessSet, VkDevice, VkDebugUtilsMessengerEXT, or VkInstance.

Problem

In runtime/test/vk_bindless_test.cpp (previously lines 871-877):

  • atomic_mode returned right after vkDeviceWaitIdle(dev), skipping:
    1. Destruction of the 11 per-run/atomic Vulkan handles created in atomic_mode (atomic_readback VkBuffer, 4 atomic VkImageViews, 4 atomic VkImages, pipeline, pipeline_layout).
    2. Automatic BindlessSet::~BindlessSet() destruction at loop scope exit.
    3. Shared resource cleanup and vkDestroyDevice / vkDestroyDebugUtilsMessengerEXT / vkDestroyInstance (lines 1049-1066).
  • As a result, VK_LAYER_KHRONOS_validation never observed device/object teardown during ps_imgatomic, deferring live driver/layer handle teardown to process exit (DllMain(DLL_PROCESS_DETACH) on Windows — relevant to TEST-1199).

Fix (18a1ef23)

Verification (AMD Radeon RX 6900 XT, gfx1030, AMD 26.11.2 / 2.0.353, Windows 11 x64, Vulkan SDK 1.4.363.1, MSVC VS2026 RelWithDebInfo)

  • Red-first control (breaking to vkDestroyDevice without destroying the 11 atomic_mode handles, LEONIDA_VK_VALIDATION=1):
    • python -I -B scripts/run_gpu_tests.py --build runtime/build --filter ps_imgatomic failed with VUID-vkDestroyDevice-device-05137 (exit 1, 0/1 passed), proving atomic_mode previously masked live-handle teardown leaks from the validation layer.
  • After full teardown fix (18a1ef23):
    • Build: cmake --build runtime/build --target vk_bindless_test — 0 errors, 0 warnings.
    • scripts/run_gpu_tests.py --build runtime/build --filter ps_imgatomic (VK_LOADER_LAYERS_DISABLE=~implicit~):
      • LEONIDA_VK_VALIDATION=0: 1/1 passed (0 of 256 texels wrong; 0 of 4096 render-target pixels wrong).
      • LEONIDA_VK_VALIDATION=1: 1/1 passed (0 validation errors).
    • scripts/run_gpu_tests.py --build runtime/build --filter ps_tex: 10/10 passed under both LEONIDA_VK_VALIDATION=0 and LEONIDA_VK_VALIDATION=1.
    • Direct vk_bindless_test.exe vs_ids.spv ps_imgatomic.spv with LEONIDA_VK_VALIDATION=1 and VK_LOADER_LAYERS_DISABLE=~implicit~:
      • Core validation: exit 0 in 0.14s, 0 validation errors.
      • Sync validation (VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true): exit 0 in 0.13s, 0 validation errors.
      • GPU-AV (VK_KHRONOS_VALIDATION_GPUAV_ENABLE=true): exit 0 in 0.43s, 0 validation errors.
      • Best practices (VK_KHRONOS_VALIDATION_VALIDATE_BEST_PRACTICES=true): exit 0 in 0.13s, 0 validation errors.
  • Repo gates: python -I -B tests/test_ctest_registration.py (4/4 OK), scripts/check_no_game_data.py (exit 0), git diff --check (exit 0), CRLF=0, git merge-tree --write-tree upstream/main HEAD (1d5c88a55111f2fcbd44fc2bdf6e3643a416814b, exit 0).

AI-assisted (Gemini, Antigravity); no copyrighted game files or dumps used.

@thehollowedone

Copy link
Copy Markdown

Independent NVIDIA check of 18a1ef23 on 3faac557. Windows 11, RTX 3080 Ti / 621.35, MSVC 19.44.35230, Vulkan SDK 1.4.363.0.

The stock ps_imgatomic fixture passed with 0/256 wrong texels and 0/4,096 wrong render-target pixels. The stock ps_tex control also passed all 24 draws. Both direct runs exited 0 with Khronos core and synchronization validation enabled, including teardown, with zero validation messages. Synthetic fixtures only. AI-assisted.

@daemosofchaos

Copy link
Copy Markdown
Contributor

Integration check: #5427 (18a1ef23) with the PcTail cleanup in #4414 (fe21bbd0). Windows 11, MSVC 19.52, RTX 5070 Ti / NVIDIA 621.24, using synthetic fixtures only.

On #5427 alone, both the atomic and texture cases produced correct readbacks in the 128-byte push-constant fallback, but exited 1: Khronos validation reported six PcTail objects still live at device destruction (VUID 05137). Both cases passed without the fallback. This is also the existing ps_tex cleanup issue addressed by #4414, not evidence of incorrect pixels or a game failure.

I combined the two exact PR heads locally (clean merge tree, no branch pushed), rebuilt vk_bindless_test, and ran both cases with the fallback on and off. All four exited 0 with correct readbacks and no validation errors; the loader confirmed Khronos validation was inserted, with synchronization validation requested. The atomic case matched all 256 texels and 4,096 render-target pixels; the texture case matched its 24 draws. This checks the combined teardown on one GPU, not other drivers or all failure paths.

AI assistance was used. No game data was used.

— LocalFirst-AI

@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 18a1ef23 on AMD Radeon 610M (RDNA2 iGPU, AMD 26.11.2 / 32.0.21045.29003) and RTX 5070 Ti Laptop (NVIDIA 621.24), Windows 11 26200, MSVC 14.44 RelWithDebInfo (scripts\build_runtime.ps1), Vulkan SDK 1.4.363.0, VK_LOADER_LAYERS_DISABLE=~implicit~: pass. First AMD/RDNA2-on-Windows run, the platform of TEST-1199. The head merges cleanly onto main 3faac557 (built at its own base d0835dd9).

  • vk_bindless_test run directly, ps_imgatomic (vs_ids) and ps_tex (vs_tri), each GPU with validation off, core validation, +VALIDATE_SYNC and +GPUAV_ENABLE: 16/16 exit 0, 0 VUIDs; 0/256 texels and 0/4,096 RT pixels wrong, 24 draws with 0 bad pixels. The device: line confirmed each GPU.
  • run_gpu_tests.py --filter ps_imgatomic and --filter ps_tex (10 tests), both GPUs, LEONIDA_VK_VALIDATION=0 and 1: all pass.
  • Negative control: with the new vkDestroyPipeline(dev, pipeline, nullptr) removed locally, the layer now catches the leak at teardown: VUID-vkDestroyDevice-device-05137, ps_imgatomic: 1 validation errors, exit 1, on both GPUs. Restored, it exits 0 again. On main the early return skips vkDestroyDevice, so the same leak goes unreported.
  • Not covered: the 128-byte PcTail path (this 610M reports 256 push-constant bytes on 26.11.2, so it isn't forced). daemosofchaos's 05137 there is vk_pc_tail: destroy the --pc-tail-ubo block so ps_tex passes under validation #4414's.

TEST-1199 data point (not claiming): on the 610M, ps_imgatomic passes with validation on both on main and on this head (3 of 3 runs on main, 1.3-4.8 s), like the RX 6900 XT above. Two notes for anyone checking on a two-GPU machine:

AI-assisted (Claude Code). Synthetic fixtures only, no game data.

@Kam471 Kam471 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.

Head: 18a1ef23de997e72ed1cd0aa3c5ff145f947a846

Windows 11, RTX 5070 Ti, Vulkan 1.4.363; built vk_bindless_test (plus vk_compute_test/vk_store_test/vk_harness/vk_texture_test for the runner).

  • LEONIDA_VK_VALIDATION=1 VK_LOADER_LAYERS_DISABLE=~implicit~ LLVM_MC='wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc' python -I scripts/run_gpu_tests.py --build runtime/build --filter ps_imgatomic -> 1/1 passed, exit 0, 0 validation errors (only the loader's OBS_HOOK disable note).
  • --filter ps_tex under the same validation settings -> 10/10 passed (the first attempt failed only because vk_texture_test.exe was not built; after building it, all pass).
  • git diff --check main...HEAD -> clean

The atomic block now destroys its 11 handles, leaves the loop and lets the shared teardown destroy the device before the validation count is read; no double-destroy remains in the post-loop path.

Verdict: LGTM.

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 18a1ef23 on the RX 6800 that reproduced TEST-1199 on main (3faac557): pass — fixes the timeout.

  • Hardware / toolchain: Windows 11 build 26300, AMD Radeon RX 6800 (gfx1030), AMD 26.11.2 (32.0.21045.29003), VK_LAYER_KHRONOS_validation 1.4.363, LLVM-MinGW Clang 23.1.6 (RelWithDebInfo), VK_LOADER_LAYERS_DISABLE=~implicit~.
  • Control on main (3faac557): direct vk_bindless_test.exe vs_ids.spv ps_imgatomic.spv with LEONIDA_VK_VALIDATION=0 exits 0 in 0.26 s; with LEONIDA_VK_VALIDATION=1 it prints ps_imgatomic: 0 of 256 texels wrong ...; 0 of 4096 render-target pixels wrong (odd columns discarded) and then stalls past a 10 s timeout during process exit.
  • With #5427 (18a1ef23):
    • Direct vk_bindless_test.exe vs_ids.spv ps_imgatomic.spv (all 0 validation errors, 0/256 texels wrong, 0/4096 pixels wrong):
      • LEONIDA_VK_VALIDATION=0: exit 0 in 0.38 s
      • LEONIDA_VK_VALIDATION=1 (core): exit 0 in 0.30 s
      • LEONIDA_VK_VALIDATION=1 + sync validation (VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true): exit 0 in 0.26 s
      • LEONIDA_VK_VALIDATION=1 + GPU-AV (VK_KHRONOS_VALIDATION_GPUAV_ENABLE=true): exit 0 in 0.74 s
    • python -I scripts/run_gpu_tests.py --build ... --filter ps_imgatomic --require-pass with LEONIDA_VK_VALIDATION=1: 1/1 passed.
    • python -I scripts/run_gpu_tests.py --build ... --filter ps_tex --require-pass with LEONIDA_VK_VALIDATION=1: 10/10 passed.

Synthetic fixtures only, no game files. AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 18a1ef2 on Intel UHD Graphics 770, driver 32.0.101.7088, with the Khronos validation layer inserted by the loader: run_gpu_tests.py --filter ps_imgatomic passes 1/1, and the direct vk_bindless_test run prints "ps_imgatomic: 0 of 256 texels wrong (2D umax/umin/or 8x8 each, 3D umax 4x4x4); 0 of 4096 render-target pixels wrong (odd columns discarded)" with 0 "Validation Error" lines in stderr. --filter ps_tex gives 6/10 passed, 4 skipped: ps_texoff ("unsupported: VK_KHR_maintenance8") and ps_texture_grad_cl_a16 ("unsupported: shaderResourceMinLod") among the skips. The run without validation, the other validation modes and the control on the tree before the fix were not run.

AI-assisted.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 18a1ef2 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • Built vk_bindless_test with scripts\build_runtime.ps1 settings (MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.1): 0 warnings. Translated ps_imgatomic and ps_tex with rdna2spirv.py from the repo's own .asm test shaders (2 and 11 shaders, all pass spirv-val).
  • vk_bindless_test vs_ids.spv ps_imgatomic.spv and vk_bindless_test vs_tri.spv ps_tex.spv with VK_LOADER_LAYERS_DISABLE=~implicit~, four modes each: validation off, core validation, VALIDATE_SYNC, GPU-assisted. 8 of 8 exit 0, 0 VUIDs. ps_imgatomic: 0 of 256 texels wrong, 0 of 4096 render-target pixels wrong. The device: line names the RX 9070 XT.
  • run_gpu_tests.py --filter ps_imgatomic: 1/1 pass. --filter ps_tex: 10/10 pass, with LEONIDA_VK_VALIDATION=0 and 1.
  • Read the diff: after the readback the buffer, 4 views, 4 images, pipeline and layout are destroyed, then break; the exit code is decided after vkDestroyInstance (vk_bindless_test.cpp around 873-890 and 1074-1084), so validation errors raised by vkDestroyDevice still count. The image memory is freed by the shared vkFreeMemory loop (line 1065). I found no leak and no changed exit code on the paths I read.
  • Not done: the negative control (removing a destroy call to see the layer report it) is on the PR page from the RX 6900 XT run; I did not repeat it. The 128-byte push-constant path is not forced on this GPU. No run on the merge base.
  • Head rechecked at the end: 18a1ef2, unchanged.

AI-assisted (Claude Code).

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