console_heap_gpu: fix erase_overlapping overflow and keep newer slot flags on rollback (CONSOLE-HEAP-GPU-OVERFLOW-AND-ROLLBACK) #2454
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2454"
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?
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T10:56:26Z.
Claimed in the coordination issue as: CONSOLE-HEAP-GPU-OVERFLOW-AND-ROLLBACK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7216316918)
What and why
The fix is @KushGene's (commit
694ba09ff, unchanged, with them as its author). @enlight3d carried it after GitHub would not let KushGene's account open the pull request, and tested it on an RTX 3090. I'm opening it, withupstream/mainmerged in (no conflicts).It fixes two bugs in
runtime/src/console_heap_gpu.h, which runs only withLEONIDA_CONSOLE_HEAP_GPU=1:ConsoleHeapKeys::erase_overlappingoverflow.e.to + spanwrapped pastUINT64_MAX, so an entry at the top of the address space never counted as overlapping. The check is nowe.to >= start || span > start - e.to, which cannot wrap.ConsoleHeapGpu::commit(false, 0)rollback.kZeroFirst). It now re-queues only slots that are not already queued.std::stable_sort, so the newer data is written last.runtime/test/vk_console_heap_gpu_test.cppcovers both bugs.Tested
enlight3d, on
main2859d0c9b(RTX 3090, NVIDIA 621.40, Windows 11, MSVC RelWithDebInfo):ctest -R "^(vk_console_heap_gpu|vk_command_replay|vk_predicated_copy|vk_predicate_capture|vk_queue)$"passed 5/5. The new test fails withmain's header at line 63 and passes with the fix.Here, on the merge with
main63185f4a3(RTX 4070 SUPER, NVIDIA 621.01, Windows 11, MSVC RelWithDebInfo, Ninja):ctest -Rpasses 5/5.main'sconsole_heap_gpu.h,vk_console_heap_gpufails atline 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1.main's header plus only theerase_overlappingfix, it fails atline 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32). So the rollback checks catch the second bug too.GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40, Windows 11 (enlight3d); NVIDIA GeForce RTX 4070 SUPER 12 GB desktop, driver 621.01, Windows 11, profile M (ours)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-27T12:09:34Z.
Independently checked head
c741bd6daon Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK1.4.363.0, no game files.Local build & dual-GPU verification:
vk_console_heap_gpu_test(zero warnings in PR files).vk_console_heap_gpu_testwithLEONIDA_VK_VALIDATION=1:616.64): PASS (8 passes, 54004 slots, 6000 updates, 95537 misses, 1 overflows, 2 failed, 0 validation errors).25.10.30.02): PASS (8 passes, 54004 slots, 6000 updates, 95537 misses, 1 overflows, 2 failed, 0 validation errors).Static code review notes on
c741bd6da:erase_overlapping(runtime/src/console_heap_gpu.h:171-181) is sound for representable half-open queries (empty queries erase nothing, adjacent endpoints do not intersect; note callers constructings + bytesatd3d12_vulkan_device.cpp:6212-6217can still wrap before calling the helper). Slot flags are properly serialized under the shared mutex for a live heap, and the test exercises both directions ofkZeroFirst.runtime/src/console_heap_gpu.h:559-581, 748-749;vk_console_heap_gpu_test.cpp:536-564):vkCmdCopyBuffercall, which violatesVUID-vkCmdCopyBuffer-pRegions-12482(overlapping destination regions within one copy command).console_heap_gpu.h:390-415, 722-747), so a recreate reusing that index between record and rollback could enqueue old flags onto a fresh slot.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T12:13:11Z.
Review: COMMENTED
Tested
c741bd6dalocally merged ontomaina3bafd05d02bon Windows 11 with MSVC 19.44 (Release), NVIDIA GeForce RTX 5070 (610.88; Vulkan validation unavailable locally), plus WSL Ubuntu GCC 11.4 with-fsanitize=undefined,addressfor the CPUConsoleHeapKeyspaths.ConsoleHeapKeys::erase_overlappingoverflow fix andcommit(false, 0)slot-flag preservation are verified red/green:mainfailed at line 63 (erase_overlapping) and, with only that fix applied, at line 560 (kSlotKeep). All 5 CTests (vk_console_heap_gpu,vk_command_replay,vk_predicated_copy,vk_predicate_capture,vk_queue) and the GCC UBSan/ASan key checks passed on the PR.dstfrom different source buffers, and the new test does not currently exercise copy ordering. Details inline.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T12:13:12Z.
Code review location:
runtime/src/console_heap_gpu.h; line 560[P2]
std::stable_sortby(src, dst)still lets an older rolled-back copy overwrite a newer copy to the same destination.queue_copy(older_src, 0, dst, 0, 4096, keep1)(filled with0x11) and callsrecord(). Beforecommit(false, 0), a newer update queuesqueue_copy(newer_src, 0, dst, 0, 4096, keep2)(filled with0x22) from a distinctVkBufferwhose handle compares smaller (newer_src < older_src, which can happen inDeviceState::gpu_copy_shadowwhen a remappedShadowImportis recreated).commit(false, 0)prependsolder_srcahead ofnewer_src, thenstd::stable_sortsortsnewer_srcbeforeolder_src, sodstends up with the stale0x11bytes instead of0x22.(src, dst)overlap: even whenolder_src == newer_srcwith differentsrcOffsettargeting the samedstOffset, the loop below batches both regions into a singlevkCmdCopyBuffer, where overlapping destination regions violateVUID-vkCmdCopyBuffer-pRegions-00117and have no guaranteed execution order; distinctvkCmdCopyBuffercalls targeting the samedstalso have noTRANSFER_WRITE --> TRANSFER_WRITEbarrier between them.(src, dst)runs without sorting across differentsrc, and insert a transfer barrier before any copy overlapping a prior destination range in the pass), and verify with a test covering bothnewer_src < older_srcand same-srcoverlappingdst.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T12:13:12Z.
Code review location:
runtime/test/vk_console_heap_gpu_test.cpp; line 549[P3] The new rollback test uses disjoint destination offsets (
[0, 4096)and[4096, 8192)), so it does not verify the copy-ordering part of the change.With only the
copies_changes reverted (std::sortandcopies_.insert(copies_.end(), ...)),vk_console_heap_gpu_teststill passed on RTX 5070. Targeting overlappingdstbytes (including from two distinct sourceVkBuffers orderednewer_src < older_src) would make the test fail whenever rolled-back copies execute after newer ones.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:23:25Z.
#2454 | head
c741bd6dab(merged cleanly with mainadfb3821a2— no conflicts on currentmain) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vk_console_heap_gpu|vk_command_replay|vk_predicated_copy|vk_predicate_capture|vk_queue)$" --output-on-failure(LEONIDA_VK_VALIDATION=1) | red on main: buildingvk_console_heap_gpu_testagainstmain'sruntime/src/console_heap_gpu.hfailsvk_console_heap_gpuatline 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1; applying only theerase_overlappingoverflow fix onmainthen fails atline 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32)when rollback clobbers newer flags and queued copies | green on PR+main:5/5CTests (vk_console_heap_gpu—8 passes, 54004 slots, 6000 updates, 95537 misses, 1 overflows, 2 failed,vk_command_replay,vk_predicated_copy,vk_predicate_capture,vk_queue) pass in3.42 son RTX 3090 with0Khronos validation errors;check_no_game_data.py0violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesImported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:45:57Z.
Run of #2454 (ctest, red/green), by enlight3d. Nothing pushed.
Heads: PR
c741bd6da(merge of main63185f4a3into the branch), main1bc055e6c.git merge-tree --write-tree main <PR head>is clean (no conflicts).The PR changes
runtime/src/console_heap_gpu.hand adds checks toruntime/test/vk_console_heap_gpu_test.cpp. The header on main is the same as the PR's base, so the test is new and the code is changed.Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo,
-DLEONIDA_REQUIRE_VULKAN=ON.Commands (in the vcvars64 environment, only this target built):
vk_console_heap_gpuPassed (1/1, 0.30 s).console_heap_gpu.htaken from main, test kept): Failed atline 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1. This is a behavioural red: the test builds against main's header, it fails because of the overflow.erase_overlappingfix): Failed atline 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32), so the rollback checks catch the second bug too.I did not run the other four tests the PR description lists (vk_command_replay, vk_predicated_copy, vk_predicate_capture, vk_queue).
Link check: merged into main
1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:05:12Z.
Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and
gta6rt.exestill links) and a re-check here: no conflict withmain21f5baff1, same head as run,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.