console_heap_gpu: fix erase_overlapping overflow and keep newer slot flags on rollback (CONSOLE-HEAP-GPU-OVERFLOW-AND-ROLLBACK) #2454

Merged
Tyrannys merged 2 commits from upstream-pr/2454 into main 2026-11-29 01:05:10 +00:00
Tyrannys commented 2026-11-27 10:56:26 +00:00 (Migrated from github.com)

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, with upstream/main merged in (no conflicts).

It fixes two bugs in runtime/src/console_heap_gpu.h, which runs only with LEONIDA_CONSOLE_HEAP_GPU=1:

  • ConsoleHeapKeys::erase_overlapping overflow. e.to + span wrapped past UINT64_MAX, so an entry at the top of the address space never counted as overlapping. The check is now e.to >= start || span > start - e.to, which cannot wrap.
  • ConsoleHeapGpu::commit(false, 0) rollback.
    • A rolled-back batch re-queued its slots even where a newer queue already held them, which overwrote the newer flags (kZeroFirst). It now re-queues only slots that are not already queued.
    • Rolled-back copies and keeps went to the back of the pending lists, behind newer ones. They now go to the front, and the copies are sorted with std::stable_sort, so the newer data is written last.

runtime/test/vk_console_heap_gpu_test.cpp covers both bugs.

Tested

enlight3d, on main 2859d0c9b (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 with main's header at line 63 and passes with the fix.

Here, on the merge with main 63185f4a3 (RTX 4070 SUPER, NVIDIA 621.01, Windows 11, MSVC RelWithDebInfo, Ninja):

  • The same ctest -R passes 5/5.
  • With main's console_heap_gpu.h, vk_console_heap_gpu fails at line 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1.
  • With main's header plus only the erase_overlapping fix, it fails at line 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32). So the rollback checks catch the second bug too.
  • With the full fix it passes.

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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5525445372 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2454). Originally posted by [Tyrannys](https://github.com/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, with `upstream/main` merged in (no conflicts). It fixes two bugs in `runtime/src/console_heap_gpu.h`, which runs only with `LEONIDA_CONSOLE_HEAP_GPU=1`: - **`ConsoleHeapKeys::erase_overlapping` overflow.** `e.to + span` wrapped past `UINT64_MAX`, so an entry at the top of the address space never counted as overlapping. The check is now `e.to >= start || span > start - e.to`, which cannot wrap. - **`ConsoleHeapGpu::commit(false, 0)` rollback.** - A rolled-back batch re-queued its slots even where a newer queue already held them, which overwrote the newer flags (`kZeroFirst`). It now re-queues only slots that are not already queued. - Rolled-back copies and keeps went to the back of the pending lists, behind newer ones. They now go to the front, and the copies are sorted with `std::stable_sort`, so the newer data is written last. `runtime/test/vk_console_heap_gpu_test.cpp` covers both bugs. ### Tested enlight3d, on `main` 2859d0c9b (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 with `main`'s header at line 63 and passes with the fix. Here, on the merge with `main` 63185f4a3 (RTX 4070 SUPER, NVIDIA 621.01, Windows 11, MSVC RelWithDebInfo, Ninja): - The same `ctest -R` passes 5/5. - With `main`'s `console_heap_gpu.h`, `vk_console_heap_gpu` fails at `line 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1`. - With `main`'s header plus only the `erase_overlapping` fix, it fails at `line 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32)`. So the rollback checks catch the second bug too. - With the full fix it passes. 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timbot103 commented 2026-11-27 12:09:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-27T12:09:34Z.


Independently checked head c741bd6da on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK 1.4.363.0, no game files.

Local build & dual-GPU verification:

  • Clean MSVC build of vk_console_heap_gpu_test (zero warnings in PR files).
  • vk_console_heap_gpu_test with LEONIDA_VK_VALIDATION=1:
    • NVIDIA GeForce RTX 5080 (616.64): PASS (8 passes, 54004 slots, 6000 updates, 95537 misses, 1 overflows, 2 failed, 0 validation errors).
    • AMD Radeon(TM) Graphics (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:

  • What checks out: the subtraction-based range check in 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 constructing s + bytes at d3d12_vulkan_device.cpp:6212-6217 can 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 of kZeroFirst.
  • Copy ordering gap on overlapping rolled-back writes (runtime/src/console_heap_gpu.h:559-581, 748-749; vk_console_heap_gpu_test.cpp:536-564):
    • While the test writes two disjoint 4 KiB halves (so reversing them yields identical bytes), rolling back two writes that overlap the same destination bytes can still fail to ensure the newer copy wins:
      • From the same source/destination buffer pair, both regions are emitted in a single vkCmdCopyBuffer call, which violates VUID-vkCmdCopyBuffer-pRegions-12482 (overlapping destination regions within one copy command).
      • From different source buffers, grouping sorts by buffer handle (which can reorder newer before older) and the only transfer barrier is emitted after all copies.
    • Although the grouping predates this PR, it breaks the PR's stated "newer copy wins" rollback guarantee for overlapping writes. Preserving enqueue order for overlapping destination ranges — either trimming superseded destination bytes or inserting a transfer dependency between overlapping copies — and testing partial overlap (both same-source and distinct-source) would close this.
  • Minor inherited note: heap removal vacates an integer heap index before waiting for uncommitted passes (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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7217908394 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2454#issuecomment-7217908394). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-27T12:09:34Z. --- Independently checked head `c741bd6da` on Windows 11 Pro 26200, MSVC 2022 (`19.44.35230.0`, RelWithDebInfo, Ninja), Vulkan SDK `1.4.363.0`, no game files. **Local build & dual-GPU verification:** - Clean MSVC build of `vk_console_heap_gpu_test` (zero warnings in PR files). - `vk_console_heap_gpu_test` with `LEONIDA_VK_VALIDATION=1`: - **NVIDIA GeForce RTX 5080** (`616.64`): **PASS** (`8 passes, 54004 slots, 6000 updates, 95537 misses, 1 overflows, 2 failed`, 0 validation errors). - **AMD Radeon(TM) Graphics** (`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`:** - **What checks out:** the subtraction-based range check in `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 constructing `s + bytes` at `d3d12_vulkan_device.cpp:6212-6217` can 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 of `kZeroFirst`. - **Copy ordering gap on overlapping rolled-back writes (`runtime/src/console_heap_gpu.h:559-581, 748-749`; `vk_console_heap_gpu_test.cpp:536-564`):** - While the test writes two disjoint 4 KiB halves (so reversing them yields identical bytes), rolling back two writes that overlap the **same** destination bytes can still fail to ensure the newer copy wins: - From the same source/destination buffer pair, both regions are emitted in a single `vkCmdCopyBuffer` call, which violates `VUID-vkCmdCopyBuffer-pRegions-12482` (overlapping destination regions within one copy command). - From different source buffers, grouping sorts by buffer handle (which can reorder newer before older) and the only transfer barrier is emitted after all copies. - Although the grouping predates this PR, it breaks the PR's stated "newer copy wins" rollback guarantee for overlapping writes. Preserving enqueue order for overlapping destination ranges — either trimming superseded destination bytes or inserting a transfer dependency between overlapping copies — and testing partial overlap (both same-source and distinct-source) would close this. - **Minor inherited note:** heap removal vacates an integer heap index before waiting for uncommitted passes (`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.
lixonik commented 2026-11-27 12:13:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T12:13:11Z.

Review: COMMENTED


Tested c741bd6da locally merged onto main a3bafd05d02b on 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,address for the CPU ConsoleHeapKeys paths.

  • ConsoleHeapKeys::erase_overlapping overflow fix and commit(false, 0) slot-flag preservation are verified red/green: main failed 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.
  • A scratch GPU check of overlapping rolled-back copies found a remaining ordering bug when two copies target the same dst from different source buffers, and the new test does not currently exercise copy ordering. Details inline.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6087943989 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2454#pullrequestreview-6087943989). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T12:13:11Z. **Review:** COMMENTED --- Tested `c741bd6da` locally merged onto `main` `a3bafd05d02b` on 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,address` for the CPU `ConsoleHeapKeys` paths. - `ConsoleHeapKeys::erase_overlapping` overflow fix and `commit(false, 0)` slot-flag preservation are verified red/green: `main` failed 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. - A scratch GPU check of overlapping rolled-back copies found a remaining ordering bug when two copies target the same `dst` from different source buffers, and the new test does not currently exercise copy ordering. Details inline. AI-assisted.
lixonik commented 2026-11-27 12:13:12 +00:00 (Migrated from github.com)

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

@@ -556,7 +557,7 @@ class ConsoleHeapGpu {
         const auto push = fn<PFN_vkCmdPushConstants>("vkCmdPushConstants");
         // The copies first (another kind of work in the same prelude), then what reads their destinations may run.
         if (!copies_.empty()) {
-            std::sort(copies_.begin(), copies_.end(), [](const Copy& a, const Copy& b) {
+            std::stable_sort(copies_.begin(), copies_.end(), [](const Copy& a, const Copy& b) {

[P2] std::stable_sort by (src, dst) still lets an older rolled-back copy overwrite a newer copy to the same destination.

  • Condition: Pass 1 queues queue_copy(older_src, 0, dst, 0, 4096, keep1) (filled with 0x11) and calls record(). Before commit(false, 0), a newer update queues queue_copy(newer_src, 0, dst, 0, 4096, keep2) (filled with 0x22) from a distinct VkBuffer whose handle compares smaller (newer_src < older_src, which can happen in DeviceState::gpu_copy_shadow when a remapped ShadowImport is recreated).
  • Actual result on RTX 5070: commit(false, 0) prepends older_src ahead of newer_src, then std::stable_sort sorts newer_src before older_src, so dst ends up with the stale 0x11 bytes instead of 0x22.
  • Same-(src, dst) overlap: even when older_src == newer_src with different srcOffset targeting the same dstOffset, the loop below batches both regions into a single vkCmdCopyBuffer, where overlapping destination regions violate VUID-vkCmdCopyBuffer-pRegions-00117 and have no guaranteed execution order; distinct vkCmdCopyBuffer calls targeting the same dst also have no TRANSFER_WRITE --> TRANSFER_WRITE barrier between them.
  • Expected / how to verify: preserve submission order across overlapping destination copies (e.g. batch only contiguous same-(src, dst) runs without sorting across different src, and insert a transfer barrier before any copy overlapping a prior destination range in the pass), and verify with a test covering both newer_src < older_src and same-src overlapping dst.
<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4719224918 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2454#discussion_r4719224918). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T12:13:12Z. **Code review location:** `runtime/src/console_heap_gpu.h`; line 560 ~~~~diff @@ -556,7 +557,7 @@ class ConsoleHeapGpu { const auto push = fn<PFN_vkCmdPushConstants>("vkCmdPushConstants"); // The copies first (another kind of work in the same prelude), then what reads their destinations may run. if (!copies_.empty()) { - std::sort(copies_.begin(), copies_.end(), [](const Copy& a, const Copy& b) { + std::stable_sort(copies_.begin(), copies_.end(), [](const Copy& a, const Copy& b) { ~~~~ --- [P2] `std::stable_sort` by `(src, dst)` still lets an older rolled-back copy overwrite a newer copy to the same destination. - Condition: Pass 1 queues `queue_copy(older_src, 0, dst, 0, 4096, keep1)` (filled with `0x11`) and calls `record()`. Before `commit(false, 0)`, a newer update queues `queue_copy(newer_src, 0, dst, 0, 4096, keep2)` (filled with `0x22`) from a distinct `VkBuffer` whose handle compares smaller (`newer_src < older_src`, which can happen in `DeviceState::gpu_copy_shadow` when a remapped `ShadowImport` is recreated). - Actual result on RTX 5070: `commit(false, 0)` prepends `older_src` ahead of `newer_src`, then `std::stable_sort` sorts `newer_src` before `older_src`, so `dst` ends up with the stale `0x11` bytes instead of `0x22`. - Same-`(src, dst)` overlap: even when `older_src == newer_src` with different `srcOffset` targeting the same `dstOffset`, the loop below batches both regions into a single `vkCmdCopyBuffer`, where overlapping destination regions violate `VUID-vkCmdCopyBuffer-pRegions-00117` and have no guaranteed execution order; distinct `vkCmdCopyBuffer` calls targeting the same `dst` also have no `TRANSFER_WRITE --> TRANSFER_WRITE` barrier between them. - Expected / how to verify: preserve submission order across overlapping destination copies (e.g. batch only contiguous same-`(src, dst)` runs without sorting across different `src`, and insert a transfer barrier before any copy overlapping a prior destination range in the pass), and verify with a test covering both `newer_src < older_src` and same-`src` overlapping `dst`.
lixonik commented 2026-11-27 12:13:12 +00:00 (Migrated from github.com)

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

@@ -494,6 +508,62 @@ int main() {
         EXPECT(dw[8192] == 0 && dw[32768 + 4096] == 0);
     }
     std::puts("console heap pass, queued copies: ok");
+    {
+        // Failed-submission rollback must not clobber newer queued slot flags (kZeroFirst) or reorder copies.
+        constexpr std::uint32_t kSlotKeep = 1, kSlotZero = 2;
+        const std::array<std::uint32_t, 8> keep_words{0x12345678u, 0x9abcdef0u, 0x0fedcba9u, 0x80000001u,
+                                                      0x11112222u, 0x33334444u, 0x55556666u, 0x77778888u};
+        const std::array<std::uint32_t, 8> zero_words{0x2468ace0u, 0x13579bdfu, 0x01020304u, 0x80000002u,
+                                                      0xaaaaaaaau, 0xbbbbbbbbu, 0xccccccccu, 0xddddddddu};
+        std::memcpy(in + 8 * kSlotKeep, keep_words.data(), 32);
+        std::memcpy(in + 8 * kSlotZero, zero_words.data(), 32);
+        std::memset(out, 0xcd, std::size_t(kSlots) * 32);
+
+        constexpr VkDeviceSize kCopyBytes = 8192;
+        void* copy_src_data = nullptr;
+        void* copy_dst_data = nullptr;
+        const VkBuffer copy_src = d.buffer(kCopyBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &copy_src_data);
+        const VkBuffer copy_dst = d.buffer(kCopyBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &copy_dst_data);
+        EXPECT(copy_src && copy_dst && copy_src_data && copy_dst_data);
+        std::memset(copy_src_data, 0x11, 4096);
+        std::memset(static_cast<std::uint8_t*>(copy_src_data) + 4096, 0x22, 4096);
+        std::memset(copy_dst_data, 0, kCopyBytes);
+
+        auto keep1 = std::make_shared<int>(1);
+        auto keep2 = std::make_shared<int>(2);
+        std::weak_ptr<int> watch1 = keep1, watch2 = keep2;
+
+        gpu.queue(heap, kSlotKeep | leonida::ConsoleHeapGpu::kZeroFirst);
+        gpu.queue(heap, kSlotZero);
+        gpu.queue_copy(copy_src, 0, copy_dst, 0, 4096, keep1);
+        keep1.reset();
+        bool recorded = false;
+        d.run([&](VkCommandBuffer cb) {
+            recorded = gpu.record(cb);
+            return false;  // keep Pass 1 uncommitted to test rollback
+        });
+        EXPECT(recorded && !watch1.expired());
+        // Newer updates arrive after record() and before Pass 1's rollback commit(false, 0).
+        gpu.queue(heap, kSlotKeep);
+        gpu.queue(heap, kSlotZero | leonida::ConsoleHeapGpu::kZeroFirst);
+        gpu.queue_copy(copy_src, 4096, copy_dst, 4096, 4096, keep2);

[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::sort and copies_.insert(copies_.end(), ...)), vk_console_heap_gpu_test still passed on RTX 5070. Targeting overlapping dst bytes (including from two distinct source VkBuffers ordered newer_src < older_src) would make the test fail whenever rolled-back copies execute after newer ones.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4719224936 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2454#discussion_r4719224936). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T12:13:12Z. **Code review location:** `runtime/test/vk_console_heap_gpu_test.cpp`; line 549 ~~~~diff @@ -494,6 +508,62 @@ int main() { EXPECT(dw[8192] == 0 && dw[32768 + 4096] == 0); } std::puts("console heap pass, queued copies: ok"); + { + // Failed-submission rollback must not clobber newer queued slot flags (kZeroFirst) or reorder copies. + constexpr std::uint32_t kSlotKeep = 1, kSlotZero = 2; + const std::array<std::uint32_t, 8> keep_words{0x12345678u, 0x9abcdef0u, 0x0fedcba9u, 0x80000001u, + 0x11112222u, 0x33334444u, 0x55556666u, 0x77778888u}; + const std::array<std::uint32_t, 8> zero_words{0x2468ace0u, 0x13579bdfu, 0x01020304u, 0x80000002u, + 0xaaaaaaaau, 0xbbbbbbbbu, 0xccccccccu, 0xddddddddu}; + std::memcpy(in + 8 * kSlotKeep, keep_words.data(), 32); + std::memcpy(in + 8 * kSlotZero, zero_words.data(), 32); + std::memset(out, 0xcd, std::size_t(kSlots) * 32); + + constexpr VkDeviceSize kCopyBytes = 8192; + void* copy_src_data = nullptr; + void* copy_dst_data = nullptr; + const VkBuffer copy_src = d.buffer(kCopyBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &copy_src_data); + const VkBuffer copy_dst = d.buffer(kCopyBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &copy_dst_data); + EXPECT(copy_src && copy_dst && copy_src_data && copy_dst_data); + std::memset(copy_src_data, 0x11, 4096); + std::memset(static_cast<std::uint8_t*>(copy_src_data) + 4096, 0x22, 4096); + std::memset(copy_dst_data, 0, kCopyBytes); + + auto keep1 = std::make_shared<int>(1); + auto keep2 = std::make_shared<int>(2); + std::weak_ptr<int> watch1 = keep1, watch2 = keep2; + + gpu.queue(heap, kSlotKeep | leonida::ConsoleHeapGpu::kZeroFirst); + gpu.queue(heap, kSlotZero); + gpu.queue_copy(copy_src, 0, copy_dst, 0, 4096, keep1); + keep1.reset(); + bool recorded = false; + d.run([&](VkCommandBuffer cb) { + recorded = gpu.record(cb); + return false; // keep Pass 1 uncommitted to test rollback + }); + EXPECT(recorded && !watch1.expired()); + // Newer updates arrive after record() and before Pass 1's rollback commit(false, 0). + gpu.queue(heap, kSlotKeep); + gpu.queue(heap, kSlotZero | leonida::ConsoleHeapGpu::kZeroFirst); + gpu.queue_copy(copy_src, 4096, copy_dst, 4096, 4096, keep2); ~~~~ --- [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::sort` and `copies_.insert(copies_.end(), ...)`), `vk_console_heap_gpu_test` still passed on RTX 5070. Targeting overlapping `dst` bytes (including from two distinct source `VkBuffer`s ordered `newer_src < older_src`) would make the test fail whenever rolled-back copies execute after newer ones.
zmasi commented 2026-11-28 23:23:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:23:25Z.


#2454 | head c741bd6dab (merged cleanly with main adfb3821a2 — no conflicts on current main) | 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: building vk_console_heap_gpu_test against main's runtime/src/console_heap_gpu.h fails vk_console_heap_gpu at line 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1; applying only the erase_overlapping overflow fix on main then fails at line 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32) when rollback clobbers newer flags and queued copies | green on PR+main: 5/5 CTests (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 in 3.42 s on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247398229 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2454#issuecomment-7247398229). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T23:23:25Z. --- #2454 | head c741bd6dab24d54e8c462554fce493a328dfce09 (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current `main`) | `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: building `vk_console_heap_gpu_test` against `main`'s `runtime/src/console_heap_gpu.h` fails `vk_console_heap_gpu` at `line 63: keys.erase_overlapping(UINT64_MAX - 8, UINT64_MAX) == 1`; applying only the `erase_overlapping` overflow fix on `main` then fails at `line 560: !std::memcmp(out + 8 * kSlotKeep, keep_words.data(), 32)` when rollback clobbers newer flags and queued copies | green on PR+main: `5/5` CTests (`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 in `3.42 s` on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
enlight3d commented 2026-11-29 00:45:57 +00:00 (Migrated from github.com)

Imported 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 main 63185f4a3 into the branch), main 1bc055e6c. git merge-tree --write-tree main <PR head> is clean (no conflicts).
The PR changes runtime/src/console_heap_gpu.h and adds checks to runtime/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):

cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build bld --target vk_console_heap_gpu_test -j 8
ctest --test-dir bld -R "^vk_console_heap_gpu$" --output-on-failure
  • GREEN (PR head): vk_console_heap_gpu Passed (1/1, 0.30 s).
  • RED 1 (PR head, with console_heap_gpu.h taken from main, test kept): Failed at line 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.
  • RED 2 (main's header plus only the erase_overlapping fix): Failed at line 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248335563 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2454#issuecomment-7248335563). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T00:45:57Z. --- Run of #2454 (ctest, red/green), by enlight3d. Nothing pushed. Heads: PR `c741bd6da` (merge of main 63185f4a3 into the branch), main `1bc055e6c`. `git merge-tree --write-tree main <PR head>` is clean (no conflicts). The PR changes `runtime/src/console_heap_gpu.h` and adds checks to `runtime/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): ``` cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build bld --target vk_console_heap_gpu_test -j 8 ctest --test-dir bld -R "^vk_console_heap_gpu$" --output-on-failure ``` - GREEN (PR head): `vk_console_heap_gpu` Passed (1/1, 0.30 s). - RED 1 (PR head, with `console_heap_gpu.h` taken from main, test kept): Failed at `line 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. - RED 2 (main's header plus only the `erase_overlapping` fix): Failed at `line 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.
MoonEyes commented 2026-11-29 01:05:12 +00:00 (Migrated from github.com)

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.exe still links) and a re-check here: no conflict with main 21f5baff1, same head as run, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248549630 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2454#issuecomment-7248549630). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T01:05:12Z. --- Merged after **enlight3d** (Thib)'s red/green run ([RUN](https://github.com/ProjectLeonida/mandy/pull/2454#issuecomment-7248335563), RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and `gta6rt.exe` still links) and a re-check here: no conflict with `main` 21f5baff1, same head as run, `no-game-data` green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on `main` or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2454
No description provided.