d3d12: destroy raw-texture image views at device teardown #2184
Closed
leonida/mandy
ammonium231 wants to merge 0 commits from
fix-raw-2d-imageview-leak into main
pull from: fix-raw-2d-imageview-leak
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2184
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-raw-2d-imageview-leak"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
set_raw_image_address never registered the title VA, so ~Resource did not forget the views and xbox_raw_2d_stripes and xbox_raw_2d_surface leaked 2 VkImageViews each (VUID-vkDestroyDevice-device-05137).
Claimed in the coordination issue as: RT-RAW-2D-IMAGEVIEW-LEAK
Depends on: none
Fixes: VUID-vkDestroyDevice-device-05137 in xbox_raw_2d_stripes and xbox_raw_2d_surface (no standalone issue).
What and why
set_raw_image_address overwrote image_address_ without note_image_address, so ~Resource skipped forget_image. It now registers the title VA the same way as place_at_title_address.
Tested
LEONIDA_VK_VALIDATION=1 after rebase onto 0b11d86bc: xbox_raw_2d_stripes and xbox_raw_2d_surface still 2 leaked VkImageViews to 0. Full ctest 472/475; xbox_present and d3d12_set_descriptor_heaps also fail on unpatched main; xmem_no_write_watch failed once under -j 4 and passed twice isolated.
GPUs tested: NVIDIA RTX 3090, driver 621.40, Windows 11
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Independent verification of head
ee0aa61a8merged into currentmain(ec91d695c), no conflicts.Machine: profile M (RTX 4070 SUPER 12 GB desktop, NVIDIA 621.01, Windows 11 Pro 26300), MSVC 14.52 (VS 2026, MSBuild generator), RelWithDebInfo. No game files.
Leak, before and after (
LEONIDA_VK_VALIDATION=1 ctest -R xbox_raw_2d -V):mainmain+ this PRxbox_raw_2d_stripesVkImageView(VUID-vkDestroyDevice-device-05137)xbox_raw_2d_surfaceVkImageView(same VUID)So the fix does what it says on NVIDIA too.
Full suite (
ctest -j 6, then failures rerun alone):mainalone: 488/501 under-j 6; after rerun still failing:xbox_present,d3d12_set_descriptor_heaps,xs_proxy_mock,d3d12_queue_handover_two_queues,big_compile_gate(timeout),api_ref_state(timeout).-j 6; after rerun onlyxbox_presentandd3d12_set_descriptor_heapsfail, both of which fail onmaintoo (known). No new failure.Diff read: the new body matches
place_at_title_address(same alignment andimage_address_guards), and~Resourceonly forgets an address it still owns (image_owner(...) == this), so two cached raw surfaces at the same address with different formats/sizes do not unregister each other on teardown. One behaviour change worth knowing: an address with low bits set (not 256-aligned) now keeps the resource's synthetic address instead of taking the raw one. A T# cannot name such an address anyway, so I see no practical effect.No problems found.
AI-assisted (Claude Code).
Thanks @Tyrannys for verifying on the 4070 SUPER. Marking ready for review.
Independent RTX 4080 validation of the runtime change in
ee0aa61a8249293c0e633deea2ac06cd73e5a911on baseline02f71ccfe78160997a02950607be583af87e1180. Windows 11 Pro 25H2, NVIDIA 621.01, Khronos Vulkan validation enabled. Synthetic fixtures only. No GTA VI files were used.MEASURED at device teardown (
VUID-vkDestroyDevice-device-05137):xbox_raw_2d_stripesxbox_raw_2d_surfaceThe ordinary harness reported passes despite the baseline diagnostics. I ran an identical local test-only check on both builds that reads the validation error count after the device is destroyed. With that check, baseline passed 8 of 10 textured-draw cases and failed exactly the two above. With #2184, all 10 passed. The PR runtime diff was applied unchanged.
Independent evidence review completed. AI-assisted: OpenAI Codex.
#2184 | head ee0aa61a8249293c0e633deea2ac06cd73e5a911 (merged cleanly with main 48bae6cade49aea69f63eb8871572dcd6931cd4b — no conflicts on current
main) |d3d12_m2_textured_test(LEONIDA_TEST_LARGE_RAW_TEXTURE=1,LEONIDA_TEST_RAW_TEXTURE=1, default) +ctest --test-dir runtime/build -C RelWithDebInfo -R "^d3d12_descriptor$" --output-on-failure(LEONIDA_VK_VALIDATION=1) | red on main: bothxbox_raw_2d_stripes(LEONIDA_TEST_LARGE_RAW_TEXTURE=1) andxbox_raw_2d_surface(LEONIDA_TEST_RAW_TEXTURE=1) emitvkDestroyDevice(): ... has 2 leaked objects that have not been destroyed(VkImageView) /VUID-vkDestroyDevice-device-05137at teardown | green on PR+main:xbox_raw_2d_stripes,xbox_raw_2d_surface,d3d12_m2_textured(4096 pixels, maximum RGBA8 channel error 0), andd3d12_descriptorall pass on RTX 3090 with0leakedVkImageViews and0Khronos validation errors;check_no_game_data.py0violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes@timbot103 Reproduced both on #2184 + main (RTX 3090, validation on): a second raw SRV of another width at the same VA dropped the first's hash entry (index 4096 → 0), and the slot-133 takeover left 1 VkImageView at vkDestroyDevice.
Fixed in e86a217d9: raw surfaces keep their views under their own registered key instead of owning the title VA. Added
xbox_raw_2d_same_vaandxbox_raw_2d_takeover, and the test now reads validation after device teardown. 13/13 raw/descriptor/m2 cases pass with 0 validation errors.Independent Wine check of the updated raw-view lifetime tests. I merged
e86a217d9onto8fb974878and kept its exact synthetic fixtures for two controls, restoring onlyruntime/shims/d3d12_vulkan_device.cppto main or to the earlier PR version (ee0aa61a8merged on the same base). No game files. CachyOS, Wine 11.22, clang-cl 23.1.5, Radeon 610M (RADV Mesa 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.04). Both GPUs gave the same results.xbox_raw_2d_stripesleakedVkImageViewsxbox_raw_2d_surfaceleakedVkImageViewsxbox_raw_2d_same_vafirst entry after adding the wider SRVxbox_raw_2d_takeoverleakedVkImageViewsThe updated head passed all six selected cases per GPU, including
d3d12_descriptorandd3d12_m2_textured. I verified that the Linux Vulkan loader inserted Khronos validation 1.4.363.1 (VK_LOADER_LAYERS_ENABLE=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer). Wine does not enumerate the host layer to the Windows fixture, so I checkedVUID-vkDestroyDevice-device-05137in the output separately from the exit status. The loader-enabled layer also reported the sameVK_EXT_external_memory_dma_bufextension-dependency VUID in all three builds. The leak counts above are for device teardown only. AI-assisted with OpenAI Codex (GPT-6).TAKEN by OreoFR (Windows, RTX 4070 8 GB)
Verified by OreoFR — NO RED (red only with validation on)
xbox_raw_2d_same_vaandxbox_raw_2d_takeoverpass on main as registered (raw same VA: slot 0 T# index 4096 before, 4096 after). Run by hand withLEONIDA_VK_VALIDATION=1, both fail on main with 1 validation error each,VUID-vkDestroyDevice-device-05137(objects still alive at vkDestroyDevice). So the tests show the bug only with validation on, which their ctest entries do not set.xbox_raw_2d_same_va,xbox_raw_2d_takeoverand the otherxbox_raw_2d_*andd3d12_m2_*tests pass as registered (the merge was not re-run with validation on before this PC moved to in-game runs only); ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p2 = main + #2184 + #2001 (no shared files): 507 tests, new failures vs main: none.dxgi_waitable_latencyfailed in the parallel run and passes when re-run alone (main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present)LEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty) in package p2; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32)view_key()) while its T# carries the title VA, and teardown forgets that key. Nit: the four newadd_test/set_tests_propertieslines inruntime/CMakeLists.txtare not indented like the lines around them.AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
xbox_raw_2d_same_va and xbox_raw_2d_takeover now set LEONIDA_VK_VALIDATION=1, so they fail on main with VUID-vkDestroyDevice-device-05137; both pass here on an RTX 3090 with validation on.
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.