runtime: add LEONIDA_TARGET_DUMP per-pass target dumper (RT-PASS-TARGET-DUMP) #2466

Closed
lixonik wants to merge 9 commits from upstream-pr/2466 into main
lixonik commented 2026-11-27 13:15:15 +00:00 (Migrated from github.com)

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


Implements RT-PASS-TARGET-DUMP (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7218711636).

Summary

  • Add runtime/src/target_dump.h implementing LEONIDA_TARGET_DUMP=<dir>,<frame> (1-based frame > 0).
    • Reuses leonida::present_dump::texel_size and leonida::present_dump::write_png directly from runtime/src/present_dump.h (without editing present_dump.h, avoiding conflicts with #2146).
    • Dumps render targets (color attachments and depth attachment) after each rendering scope and active storage-image UAVs after each storage-writing compute dispatch during the selected frame, as .png (for present_dump-supported formats) or tightly packed .raw (for other uncompressed color/depth formats), skipping multisampled and block-compressed images cleanly.
    • Atomically publishes each target file and index.json (frame, pass number, pass kind, slot, format, dimensions, mip/layer, bytes per texel, encoding, filename) via exclusive sibling .tmp creation + rename so pre-existing hard links outside the dump directory are never overwritten.
    • Off by default and free when off: ReplayFunctions::target_dump stays nullptr when unset, invalid, or once the target frame has completed and drained, reducing replay overhead to a single predicted null-pointer check in emit_commands with zero staging buffer allocations or copies.
  • Wire minimal hooks in runtime/src/vulkan_replay.h (ReplayFunctions::target_dump, ComputePipeline::writes_storage_image, UAV state tracking on transitions/enhanced texture barriers/UAV clears, and post-rendering-scope / post-dispatch hooks in emit_commands) and lifecycle integration in runtime/src/vulkan_backend.h (memory properties forwarding via set_occlusion_resolve_memory, per-submission commit/rollback on retire tickets, drain on ticket completion and queue/context teardown).
  • Document LEONIDA_TARGET_DUMP in runtime/README.md (marked *Diagnostic.*, noting files stay local).
  • Add runtime/test/vk_target_dump_test.cpp registered in runtime/CMakeLists.txt (vk_target_dump, vk_target_dump_off, vk_target_dump_frame2, vk_target_dump_invalid, SKIP_RETURN_CODE 77).

This is a diagnostic tool (not a workaround for a defect) and stays off by default.

Verification

  • Red check on main (690dea519): vk_target_dump_test.cpp fails to compile against main because target_dump.h and its replay/context hooks are absent.
  • Green check on rebased HEAD (0068b2cd8, base 17d3af0b6):
    • vk_target_dump -- PASS: two rendering scopes (scope 1 draws solid color to RT0; scope 2 overwrites RT0 with a second color and writes VK_FORMAT_R32_UINT raw values to RT1), one skipped non-storage compute dispatch, and one storage-image compute dispatch writing uav0; verifies index.json, independent PNG decoding (zlib_inflate + CRC32), exact per-pixel/per-texel values across all 3 passes, and hard-link safety.
    • vk_target_dump_off -- PASS: unset env var keeps target dump disabled with 0 vkCreateBuffer and 0 vkCmdCopyImageToBuffer calls and no files written.
    • vk_target_dump_frame2 -- PASS: <dir>,2 skips frame 1, dumps frame 2 only, and disables automatically once frame 3 starts and frame 2 retires.
    • vk_target_dump_invalid -- PASS: parser/format unit checks plus invalid <dir>,0 leaves dump disabled and does not create the directory.
    • Adjacent GPU tests: vk_command_replay, vk_queue, vk_present_dump, vk_present_dump_default, vk_present_dump_invalid -- 9/9 PASS; gta6rt.exe built cleanly.
    • WSL Ubuntu GCC 11.4 (-std=c++20 -O1 -g -fsanitize=undefined,address -Wall -Wextra -Werror) on target_dump.h -- PASS with 0 warnings.
    • python -I -B tests/test_docs_env_vars.py (5/5 OK), python -I -B scripts/check_no_game_data.py (clean), git diff --check (clean).
  • Note: VK_LAYER_KHRONOS_validation is not installed locally on this machine, so GPU tests ran without Vulkan validation layers. The test checks validation_errors() == 0 under LEONIDA_VK_VALIDATION=1 and skips with exit code 77 when no Vulkan 1.3 / 1.2+KHR device is available.

GPUs tested: NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341), Windows 11, MSVC 19.44 Release (without VK_LAYER_KHRONOS_validation).

AI-assisted (Antigravity, Gemini 4 Neon).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5527260965 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T13:15:15Z. --- Implements `RT-PASS-TARGET-DUMP` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7218711636). ### Summary - Add `runtime/src/target_dump.h` implementing `LEONIDA_TARGET_DUMP=<dir>,<frame>` (1-based `frame > 0`). - Reuses `leonida::present_dump::texel_size` and `leonida::present_dump::write_png` directly from `runtime/src/present_dump.h` (without editing `present_dump.h`, avoiding conflicts with #2146). - Dumps render targets (color attachments and depth attachment) after each rendering scope and active storage-image UAVs after each storage-writing compute dispatch during the selected frame, as `.png` (for `present_dump`-supported formats) or tightly packed `.raw` (for other uncompressed color/depth formats), skipping multisampled and block-compressed images cleanly. - Atomically publishes each target file and `index.json` (frame, pass number, pass kind, slot, format, dimensions, mip/layer, bytes per texel, encoding, filename) via exclusive sibling `.tmp` creation + rename so pre-existing hard links outside the dump directory are never overwritten. - Off by default and free when off: `ReplayFunctions::target_dump` stays `nullptr` when unset, invalid, or once the target frame has completed and drained, reducing replay overhead to a single predicted null-pointer check in `emit_commands` with zero staging buffer allocations or copies. - Wire minimal hooks in `runtime/src/vulkan_replay.h` (`ReplayFunctions::target_dump`, `ComputePipeline::writes_storage_image`, UAV state tracking on transitions/enhanced texture barriers/UAV clears, and post-rendering-scope / post-dispatch hooks in `emit_commands`) and lifecycle integration in `runtime/src/vulkan_backend.h` (memory properties forwarding via `set_occlusion_resolve_memory`, per-submission commit/rollback on retire tickets, drain on ticket completion and queue/context teardown). - Document `LEONIDA_TARGET_DUMP` in `runtime/README.md` (marked `*Diagnostic.*`, noting files stay local). - Add `runtime/test/vk_target_dump_test.cpp` registered in `runtime/CMakeLists.txt` (`vk_target_dump`, `vk_target_dump_off`, `vk_target_dump_frame2`, `vk_target_dump_invalid`, `SKIP_RETURN_CODE 77`). This is a diagnostic tool (not a workaround for a defect) and stays off by default. ### Verification - **Red check on `main` (`690dea519`)**: `vk_target_dump_test.cpp` fails to compile against `main` because `target_dump.h` and its replay/context hooks are absent. - **Green check on rebased HEAD (`0068b2cd8`, base `17d3af0b6`)**: - `vk_target_dump` -- PASS: two rendering scopes (scope 1 draws solid color to RT0; scope 2 overwrites RT0 with a second color and writes `VK_FORMAT_R32_UINT` raw values to RT1), one skipped non-storage compute dispatch, and one storage-image compute dispatch writing `uav0`; verifies `index.json`, independent PNG decoding (`zlib_inflate` + CRC32), exact per-pixel/per-texel values across all 3 passes, and hard-link safety. - `vk_target_dump_off` -- PASS: unset env var keeps target dump disabled with 0 `vkCreateBuffer` and 0 `vkCmdCopyImageToBuffer` calls and no files written. - `vk_target_dump_frame2` -- PASS: `<dir>,2` skips frame 1, dumps frame 2 only, and disables automatically once frame 3 starts and frame 2 retires. - `vk_target_dump_invalid` -- PASS: parser/format unit checks plus invalid `<dir>,0` leaves dump disabled and does not create the directory. - Adjacent GPU tests: `vk_command_replay`, `vk_queue`, `vk_present_dump`, `vk_present_dump_default`, `vk_present_dump_invalid` -- 9/9 PASS; `gta6rt.exe` built cleanly. - WSL Ubuntu GCC 11.4 (`-std=c++20 -O1 -g -fsanitize=undefined,address -Wall -Wextra -Werror`) on `target_dump.h` -- PASS with 0 warnings. - `python -I -B tests/test_docs_env_vars.py` (5/5 OK), `python -I -B scripts/check_no_game_data.py` (clean), `git diff --check` (clean). - Note: `VK_LAYER_KHRONOS_validation` is not installed locally on this machine, so GPU tests ran without Vulkan validation layers. The test checks `validation_errors() == 0` under `LEONIDA_VK_VALIDATION=1` and skips with exit code `77` when no Vulkan 1.3 / 1.2+KHR device is available. GPUs tested: NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341), Windows 11, MSVC 19.44 Release (without VK_LAYER_KHRONOS_validation). AI-assisted (Antigravity, Gemini 4 Neon).
tiguan26 commented 2026-11-28 01:52:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-28T01:52:36Z.

Review: APPROVED


Approving. Merged onto current main (431ceba4f) with no conflicts, cross-built vk_target_dump_test (clang-cl 19 + xwin) and ran it under Wine 11.22 on llvmpipe (Mesa, LLVM 20.1.2): all four entries pass (vk_target_dump, _off, _frame2, _invalid, exit 0, not skipped).

What that covers, read from the test: the default and --frame2 runs check exact pixels of both scopes' targets (the R8G8B8A8 one and the R32_UINT tag) and of the storage image the second dispatch writes, with the no-op dispatch before it dumping nothing; --off proves "free when off" by counting zero vkCmdCopyImageToBuffer and zero vkCreateBuffer calls through a wrapped proc table and no directory; ,0 is refused. The hard link planted at pass_0000_rt0.png keeps its outside file intact, a good check of the atomic publish. So the spec's "done when" (two scopes and one dispatch, exact pixels, off by default, free when off) is met.

Read the diff: it reuses present_dump::write_png and texel_size rather than adding a writer, every hook is behind a vk.target_dump null check, TargetDump takes its own mutex (plus a separate one for file I/O) for the drains that come from both drain_deleted_resources and queue teardown, a failed submit rolls back through the guard, and a lost device discards what is pending instead of waiting.

One thing for the maintainer to weigh, not a blocker: #2464 asks for "one hook each in emit_commands" and says vulkan_replay.h gets restructured later, so hooks there should stay at a call or two. This adds six call sites in emit_commands (three for UAV tracking on transitions, texture barriers and UAV clears, two after dispatches, one after rendering) plus about 130 lines of helpers in vulkan_replay.h. If the UAV bookkeeping could move into target_dump.h (for example by asking the layout tracker at dispatch time which bound images are in GENERAL, as dump_dispatch_targets already partly does), the replay side would shrink to the two after-hooks. Also small: the test's d.initialize(false) may mean validation is off, in which case validation_errors() == 0 checks nothing; worth a word if so.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6095023840 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#pullrequestreview-6095023840). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-28T01:52:36Z. **Review:** APPROVED --- Approving. Merged onto current main (431ceba4f) with no conflicts, cross-built `vk_target_dump_test` (clang-cl 19 + xwin) and ran it under Wine 11.22 on llvmpipe (Mesa, LLVM 20.1.2): all four entries pass (`vk_target_dump`, `_off`, `_frame2`, `_invalid`, exit 0, not skipped). What that covers, read from the test: the default and `--frame2` runs check exact pixels of both scopes' targets (the R8G8B8A8 one and the R32_UINT tag) and of the storage image the second dispatch writes, with the no-op dispatch before it dumping nothing; `--off` proves "free when off" by counting zero `vkCmdCopyImageToBuffer` and zero `vkCreateBuffer` calls through a wrapped proc table and no directory; `,0` is refused. The hard link planted at `pass_0000_rt0.png` keeps its outside file intact, a good check of the atomic publish. So the spec's "done when" (two scopes and one dispatch, exact pixels, off by default, free when off) is met. Read the diff: it reuses `present_dump::write_png` and `texel_size` rather than adding a writer, every hook is behind a `vk.target_dump` null check, `TargetDump` takes its own mutex (plus a separate one for file I/O) for the drains that come from both `drain_deleted_resources` and queue teardown, a failed submit rolls back through the guard, and a lost device discards what is pending instead of waiting. One thing for the maintainer to weigh, not a blocker: #2464 asks for "one hook each in `emit_commands`" and says `vulkan_replay.h` gets restructured later, so hooks there should stay at a call or two. This adds six call sites in `emit_commands` (three for UAV tracking on transitions, texture barriers and UAV clears, two after dispatches, one after rendering) plus about 130 lines of helpers in `vulkan_replay.h`. If the UAV bookkeeping could move into `target_dump.h` (for example by asking the layout tracker at dispatch time which bound images are in GENERAL, as `dump_dispatch_targets` already partly does), the replay side would shrink to the two after-hooks. Also small: the test's `d.initialize(false)` may mean validation is off, in which case `validation_errors() == 0` checks nothing; worth a word if so. AI-assisted (Claude Code, Claude Opus 5.5).
timbot103 commented 2026-11-28 02:02:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:02:30Z.


Reviewed at head 0068b2cd8 on Windows 11 (MSVC 2022 19.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363.0).

Verification

  • Built vk_target_dump_test.
  • All 4 modes (default, --off, --frame2, --invalid) passed with 0 validation errors on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02).

Findings (Request changes)

  1. Unrelated UAVs acquire unordered cross-queue transfer reads (d3d12_vulkan_device.cpp:12594-12602, 12654-12656; target_dump.h:420-450, 717-746; vulkan_replay.h:888, 1856-1896, 5509-5513):
    Production compute PSOs set bindless_set whenever any bindings exist and leave writes_storage_image at its default true (so even sampled-only bindless compute dispatches trigger UAV dumping). The dumper iterates all globally tracked active UAVs in GENERAL and emits only a queue-local COMPUTE_SHADER -> TRANSFER barrier before copying them. If queue A is writing UAV image A while queue B dispatches unrelated work on image B, queue B's dumper reads image A concurrently with queue A's write (cross-queue data race and misattributed output). Capture should be restricted to resources provably written/ordered on the recording queue.
  2. Depth/stencil UAVs dump the stale parent image instead of the storage-plane child (vulkan_replay.h:1837-1862, 2742-2815, 3628-3651; target_dump.h:429-446, 739-746):
    Transitions into UAV state track p.binding.image with depth/stencil aspects, whereas compute shaders write into the separate color storage-plane child image (copied back to the parent only when leaving UAV state). Post-dispatch capture reads the pre-dispatch parent depth and misses compute writes (and stencil). Selecting the storage-plane child or explicitly skipping depth/stencil UAV capture avoids silent stale dumps.
  3. Unbounded per-pass vkAllocateMemory and raw-handle leak on host OOM (target_dump.h:453-519, 644-678, 702-708, 773-793):
    Every captured target in every scope allocates a dedicated VkBuffer + VkDeviceMemory held until submission retirement (e.g., 256 scopes × 4K RGBA8 ≈ 7.9 GiB), with no byte or allocation-count cap — exceeding maxMemoryAllocationCount violates VUID-vkAllocateMemory-maxMemoryAllocationCount-04101 before the driver error returns. Additionally, a host std::bad_alloc while pushing the record into pending_passes_ strands the freshly allocated Vulkan buffer/memory handles. Bounding outstanding staging/allocation counts (or suballocating) and wrapping staging allocations in RAII handles fixes both.
  4. Minor docs note (runtime/README.md:383; vulkan_replay.h:1908-1948, 5683-5689):
    Clarify that multi-layer array RTVs dump only the base layer/slice and rectangular clears are not captured.

AI-assisted review + local MSVC/dual-GPU verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232088302 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7232088302). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T02:02:30Z. --- Reviewed at head `0068b2cd8` on Windows 11 (MSVC 2022 `19.44`) with dual-GPU Vulkan validation (`LEONIDA_VK_VALIDATION=1`, Vulkan SDK `1.4.363.0`). ### Verification - Built `vk_target_dump_test`. - All 4 modes (`default`, `--off`, `--frame2`, `--invalid`) **passed** with 0 validation errors on both **NVIDIA GeForce RTX 5080** (`616.64`) and **AMD Radeon(TM) Graphics** (`25.10.30.02`). ### Findings (Request changes) 1. **Unrelated UAVs acquire unordered cross-queue transfer reads (`d3d12_vulkan_device.cpp:12594-12602`, `12654-12656`; `target_dump.h:420-450`, `717-746`; `vulkan_replay.h:888`, `1856-1896`, `5509-5513`):** Production compute PSOs set `bindless_set` whenever any bindings exist and leave `writes_storage_image` at its default `true` (so even sampled-only bindless compute dispatches trigger UAV dumping). The dumper iterates all globally tracked active UAVs in `GENERAL` and emits only a queue-local `COMPUTE_SHADER -> TRANSFER` barrier before copying them. If queue A is writing UAV image A while queue B dispatches unrelated work on image B, queue B's dumper reads image A concurrently with queue A's write (cross-queue data race and misattributed output). Capture should be restricted to resources provably written/ordered on the recording queue. 2. **Depth/stencil UAVs dump the stale parent image instead of the storage-plane child (`vulkan_replay.h:1837-1862`, `2742-2815`, `3628-3651`; `target_dump.h:429-446`, `739-746`):** Transitions into UAV state track `p.binding.image` with depth/stencil aspects, whereas compute shaders write into the separate color storage-plane child image (copied back to the parent only when leaving UAV state). Post-dispatch capture reads the pre-dispatch parent depth and misses compute writes (and stencil). Selecting the storage-plane child or explicitly skipping depth/stencil UAV capture avoids silent stale dumps. 3. **Unbounded per-pass `vkAllocateMemory` and raw-handle leak on host OOM (`target_dump.h:453-519`, `644-678`, `702-708`, `773-793`):** Every captured target in every scope allocates a dedicated `VkBuffer` + `VkDeviceMemory` held until submission retirement (e.g., 256 scopes × 4K RGBA8 ≈ 7.9 GiB), with no byte or allocation-count cap — exceeding `maxMemoryAllocationCount` violates **`VUID-vkAllocateMemory-maxMemoryAllocationCount-04101`** before the driver error returns. Additionally, a host `std::bad_alloc` while pushing the record into `pending_passes_` strands the freshly allocated Vulkan buffer/memory handles. Bounding outstanding staging/allocation counts (or suballocating) and wrapping staging allocations in RAII handles fixes both. 4. **Minor docs note (`runtime/README.md:383`; `vulkan_replay.h:1908-1948`, `5683-5689`):** Clarify that multi-layer array RTVs dump only the base layer/slice and rectangular clears are not captured. AI-assisted review + local MSVC/dual-GPU verification.
lixonik commented 2026-11-28 09:56:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T09:56:20Z.


@timbot103 Addressed all review findings in 776f346bc:

  1. Queue-scoped UAV capture & accurate writes_storage_image ( arget_dump.h, ulkan_backend.h, shader_library.h, d3d12_vulkan_device.cpp):
    • Stamped each tracked UAV with the recording VkQueue (egin_submission(frame, queue_)) and restricted fter_dispatch to UAVs tracked on the recording queue, eliminating cross-queue transfer-read races and misattributed dumps.
    • Parsed numeric set-0 bindings into ShaderEntry::binding_mask and computed ComputePipeline::writes_storage_image from leonida::bindless::bindings in d3d12_vulkan_device.cpp, so sampled-only bindless compute PSOs set writes_storage_image = false.
  2. Depth/stencil UAV skip ( ulkan_replay.h, arget_dump.h):
    • Skipped depth/stencil and child-plane UAV resources (spects != VK_IMAGE_ASPECT_COLOR_BIT or depth_uav / stencil_uav set) in both ulkan_replay.h UAV tracking and TargetDump::note_uav / fter_dispatch, avoiding stale pre-dispatch parent depth dumps.
  3. Bounded staging allocations & RAII cleanup ( arget_dump.h, ulkan_backend.h, d3d12_vulkan_device.cpp):
    • Replaced raw VkBuffer / VkDeviceMemory handles with a move-only RAII StagingAllocation that frees both handles and updates outstanding counters on destruction (safe against std::bad_alloc or early rollback).
    • Bounded outstanding staging bytes (512 MiB default) and allocation count (256 default, further capped to max(1, maxMemoryAllocationCount / 8) via set_target_dump_memory(state_.memory, properties.limits.maxMemoryAllocationCount)), logging once and skipping further captures when full until earlier submissions retire.
  4. Docs & tests (
    untime/README.md, k_target_dump_test.cpp):
    • Documented base-layer/slice dumping for multi-layer views, uncaptured rectangular clears, queue-scoped color UAV capture, skipped depth/stencil UAVs, and bounded staging.
    • Added coverage in k_target_dump_test for cross-queue UAV isolation, live depth-UAV skipping, staging allocation-count capping, and RAII rollback cleanup.

Verification

  • Built k_target_dump_test and gta6rt (Windows 11, MSVC 19.44, Ninja Release).
  • ctest -R target_dump (LEONIDA_VK_VALIDATION=1): 4/4 passed ( k_target_dump, k_target_dump_off, k_target_dump_frame2, k_target_dump_invalid), 0 validation errors.
  • scripts/check_no_game_data.py and git diff --check: clean.

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341, VK_LAYER_KHRONOS_validation 1.4.363).

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237563832 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7237563832). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T09:56:20Z. --- @timbot103 Addressed all review findings in `776f346bc`: 1. **Queue-scoped UAV capture & accurate writes_storage_image ( arget_dump.h, ulkan_backend.h, shader_library.h, d3d12_vulkan_device.cpp):** - Stamped each tracked UAV with the recording VkQueue (egin_submission(frame, queue_)) and restricted fter_dispatch to UAVs tracked on the recording queue, eliminating cross-queue transfer-read races and misattributed dumps. - Parsed numeric set-0 bindings into ShaderEntry::binding_mask and computed ComputePipeline::writes_storage_image from leonida::bindless::bindings in d3d12_vulkan_device.cpp, so sampled-only bindless compute PSOs set writes_storage_image = false. 2. **Depth/stencil UAV skip ( ulkan_replay.h, arget_dump.h):** - Skipped depth/stencil and child-plane UAV resources (spects != VK_IMAGE_ASPECT_COLOR_BIT or depth_uav / stencil_uav set) in both ulkan_replay.h UAV tracking and TargetDump::note_uav / fter_dispatch, avoiding stale pre-dispatch parent depth dumps. 3. **Bounded staging allocations & RAII cleanup ( arget_dump.h, ulkan_backend.h, d3d12_vulkan_device.cpp):** - Replaced raw VkBuffer / VkDeviceMemory handles with a move-only RAII StagingAllocation that frees both handles and updates outstanding counters on destruction (safe against std::bad_alloc or early rollback). - Bounded outstanding staging bytes (512 MiB default) and allocation count (256 default, further capped to max(1, maxMemoryAllocationCount / 8) via set_target_dump_memory(state_.memory, properties.limits.maxMemoryAllocationCount)), logging once and skipping further captures when full until earlier submissions retire. 4. **Docs & tests ( untime/README.md, k_target_dump_test.cpp):** - Documented base-layer/slice dumping for multi-layer views, uncaptured rectangular clears, queue-scoped color UAV capture, skipped depth/stencil UAVs, and bounded staging. - Added coverage in k_target_dump_test for cross-queue UAV isolation, live depth-UAV skipping, staging allocation-count capping, and RAII rollback cleanup. ### Verification - Built k_target_dump_test and gta6rt (Windows 11, MSVC 19.44, Ninja Release). - ctest -R target_dump (LEONIDA_VK_VALIDATION=1): **4/4 passed** ( k_target_dump, k_target_dump_off, k_target_dump_frame2, k_target_dump_invalid), 0 validation errors. - scripts/check_no_game_data.py and git diff --check: clean. GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341, VK_LAYER_KHRONOS_validation 1.4.363). AI-assisted (Antigravity, Gemini).
lixonik commented 2026-11-28 15:35:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T15:35:02Z.


Retested the updated head 776f346bc merged locally with main c1ecf04edc on Windows 11, MSVC 19.44, RTX 5070 (610.88). All four registered vk_target_dump modes passed, including the queue-isolation, staging-cap, and rollback checks in --invalid.

One coverage gap remains in runtime/src/target_dump.h:417. The tracker stores one UAV subresource per resource ID, so a newer mip replaces the previous mip even if both stay in GENERAL on the same queue. I extended the mock fixture to track two mips of the same synthetic image, gave it capacity for four captures, and reported both mips as GENERAL for a single dispatch. It recorded one image-to-buffer copy instead of two. A subresource-aware tracker and a two-mip regression would cover that case.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241578591 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7241578591). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T15:35:02Z. --- Retested the updated head `776f346bc` merged locally with `main` `c1ecf04edc` on Windows 11, MSVC 19.44, RTX 5070 (610.88). All four registered `vk_target_dump` modes passed, including the queue-isolation, staging-cap, and rollback checks in `--invalid`. One coverage gap remains in `runtime/src/target_dump.h:417`. The tracker stores one UAV subresource per resource ID, so a newer mip replaces the previous mip even if both stay in `GENERAL` on the same queue. I extended the mock fixture to track two mips of the same synthetic image, gave it capacity for four captures, and reported both mips as `GENERAL` for a single dispatch. It recorded one image-to-buffer copy instead of two. A subresource-aware tracker and a two-mip regression would cover that case. AI-assisted.
lixonik commented 2026-11-28 15:44:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T15:44:30Z.


Fixed the subresource drop in 59e8b50ef. UAV tracking is now keyed by resource, mip and layer. Range barriers update all affected subresources, and a partial transition clears only the affected entries. The mock fixture tracks two mips and two layers, removes one subresource, checks the other three copies, and checks that forgetting the resource prevents rollback from bringing the entries back. All four vk_target_dump CTests passed on Windows 11 with RTX 5070 (610.88).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241699153 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7241699153). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T15:44:30Z. --- Fixed the subresource drop in `59e8b50ef`. UAV tracking is now keyed by resource, mip and layer. Range barriers update all affected subresources, and a partial transition clears only the affected entries. The mock fixture tracks two mips and two layers, removes one subresource, checks the other three copies, and checks that forgetting the resource prevents rollback from bringing the entries back. All four `vk_target_dump` CTests passed on Windows 11 with RTX 5070 (610.88). AI-assisted.
Maticcm commented 2026-11-28 20:52:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Maticcm on 2026-11-28T20:52:58Z.


Independent native Windows verification of the per-subresource update at 59e8b50ef3c17a80233b4fb955bab7b7aed80b85. RTX 3080 desktop (10 GiB), NVIDIA 630.20, Windows 11 build 26340, MSVC 19.50.35717, RelWithDebInfo, Vulkan SDK 1.4.363.1, Khronos validation enabled.

  • The four registered vk_target_dump CTests passed at the exact PR head and its parent 776f346bc556f5f6065316c4fca0381ed6498373. The exact-head --invalid test covers the new per-subresource mock and rollback assertions.
  • For a negative control I used the same latest fixture on each revision, substituting four individual note_uav calls for the ranged overload so it could build on the parent. The parent failed at the assertion for three surviving copies after clearing one mip/layer. The head passed the same fixture, including the rollback check after forgetting the resource.

No Vulkan validation errors were reported in the exact-head tests. Synthetic fixtures. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245612239 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7245612239). Originally posted by [Maticcm](https://github.com/Maticcm) on 2026-11-28T20:52:58Z. --- Independent native Windows verification of the per-subresource update at `59e8b50ef3c17a80233b4fb955bab7b7aed80b85`. RTX 3080 desktop (10 GiB), NVIDIA 630.20, Windows 11 build 26340, MSVC 19.50.35717, RelWithDebInfo, Vulkan SDK 1.4.363.1, Khronos validation enabled. - The four registered `vk_target_dump` CTests passed at the exact PR head and its parent `776f346bc556f5f6065316c4fca0381ed6498373`. The exact-head `--invalid` test covers the new per-subresource mock and rollback assertions. - For a negative control I used the same latest fixture on each revision, substituting four individual `note_uav` calls for the ranged overload so it could build on the parent. The parent failed at the assertion for three surviving copies after clearing one mip/layer. The head passed the same fixture, including the rollback check after forgetting the resource. No Vulkan validation errors were reported in the exact-head tests. Synthetic fixtures. AI-assisted (Codex).
timbot103 commented 2026-11-29 04:27:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:27:05Z.

Review: COMMENTED


Requesting changes at head 59e8b50ef. This was a static audit only. I ran no builds, tests, or GPU workloads.

  • [MAJOR] runtime/src/target_dump.h:469 A queue stamp on a UAV transition does not establish dispatch ownership. On two Vulkan queues in the same family, let A transition image X to UAV state and signal B. B can then dispatch a write to X in the existing GENERAL layout while A dispatches a write to a different image. X is still stamped with A's queue from runtime/src/target_dump.h:427, so A's dump copies X. The barrier at runtime/src/target_dump.h:845 orders work on A, leaving the diagnostic transfer read unordered with B's shader write. Capture only image subresources the dispatch can write and that are synchronized on the recording queue. Exercise a fence handoff without a second transition in the regression fixture.

  • [MAJOR] runtime/src/target_dump.h:508 The retirement list can free staging buffers after a successful submit. runtime/src/vulkan_backend.h:3832 submits the copy commands before runtime/src/vulkan_backend.h:3868 registers their staging buffers for retirement. If growing in_flight_ throws std::bad_alloc while a submitted copy is pending, the temporary batch already owns the moved pending_passes_. Unwinding destroys the first staging buffer and frees its memory while the GPU can still access them. Cleanup then tries to reacquire the nonrecursive dumper mutex that the commit still holds. Allocate the retirement record before vkQueueSubmit and make the successful-submit handoff allocation-free. Cover allocation failure before submission and verify that successful submissions retain their buffers until the ticket retires.

  • [MAJOR] runtime/src/vulkan_replay.h:1889 A UAV used in its initial state is silently omitted. A color texture created in UNORDERED_ACCESS can be used by a dispatch immediately after CreateUnorderedAccessView, with no transition or clear. runtime/shims/d3d12_vulkan_device.cpp:18582 registers the descriptor and runtime/src/vulkan_backend.h:3726 initializes the image to GENERAL, but neither path populates the dumper's map. A dispatch that writes only this texture can produce no dispatch entry at all. Use the dispatch's storage descriptor subresources as capture candidates, including initial-state UAVs, and test a first write with no intervening barrier or clear.

  • [MAJOR] runtime/src/vulkan_replay.h:5513 A multi-record indirect dispatch produces one snapshot. A stateful ExecuteIndirect containing two executed dispatch records emits both vkCmdDispatchIndirect calls before the capture hook runs. When the second record changes the image, the dump only shows the final result and the first dispatch has no snapshot. Record a capture after each indirect dispatch record and cover two records that produce distinguishable results.

  • [MAJOR] runtime/src/target_dump.h:853 A volume UAV dump always reads Z slice zero. A Texture3D storage dispatch can write entirely to Z slice 2 of a mip. The dumper tracks the mip's sole Vulkan array layer and turns that index into the Z offset at runtime/src/target_dump.h:852. With a copy depth of one it publishes unchanged slice-zero pixels for that dispatch. Carry the storage view's Z range separately from the Vulkan layout range and read back the covered slices with their Z indices.

  • [MINOR] runtime/src/target_dump.h:753 The staging byte limit counts copy payload rather than allocated memory. The budget charges the byte count passed to vkCreateBuffer, while vkAllocateMemory uses the larger req.size at runtime/src/target_dump.h:776. The existing mock at runtime/test/vk_target_dump_test.cpp:720 asks for 256 bytes per allocation, and its 512-byte cap at runtime/test/vk_target_dump_test.cpp:839 still allows three live allocations. Charge req.size before allocation, release that same charge on rollback or retirement, and update the mock assertions to enforce the allocation-byte limit.

  • [MINOR] runtime/src/target_dump.h:98 Native B4G4R4A4 render targets have no raw format entry. On hardware with native 4444 attachment support, the shim uses VK_FORMAT_A4R4G4B4_UNORM_PACK16 for DXGI_FORMAT_B4G4R4A4_UNORM at runtime/shims/d3d12_vulkan_device.cpp:2313. The dumper's format table omits that VkFormat, so capture skips the two-byte uncompressed target at runtime/src/target_dump.h:809. Add the two-byte entry and format name and cover the native format in the raw-format fixture.

  • [MINOR] runtime/shims/d3d12_vulkan_device.cpp:12604 Storage-image reads are classified as writes. The metadata records binding numbers, so a compute shader using only a coherent image_load through the storage view still sets writes_storage_image. The translator emits OpImageRead for this path at tools/rdna2spirv.py:14593. Such a dispatch consumes staging budget and adds a dump for active UAVs even though it writes no storage image. Use metadata derived from actual storage-image writes and atomics, and cover a read-only storage-image pipeline.

  • [MINOR] runtime/src/target_dump.h:552 Failed output publication is silent and can leave a stale index. A leftover index.json.tmp from an interrupted run makes exclusive open fail at runtime/src/target_dump.h:709. The capture can write new target files while an earlier index.json stays in place, and runtime/src/target_dump.h:930 gives no error. Failed target writes are also discarded silently. Report file publication failures with the operation and error, use unique exclusive sibling temporary names to avoid stale-name collisions, and track whether the latest index contents were published so finalization can retry a failed update.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6101396047 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#pullrequestreview-6101396047). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T04:27:05Z. **Review:** COMMENTED --- Requesting changes at head `59e8b50ef`. This was a static audit only. I ran no builds, tests, or GPU workloads. - [MAJOR] `runtime/src/target_dump.h:469` **A queue stamp on a UAV transition does not establish dispatch ownership.** On two Vulkan queues in the same family, let A transition image X to UAV state and signal B. B can then dispatch a write to X in the existing `GENERAL` layout while A dispatches a write to a different image. X is still stamped with A's queue from `runtime/src/target_dump.h:427`, so A's dump copies X. The barrier at `runtime/src/target_dump.h:845` orders work on A, leaving the diagnostic transfer read unordered with B's shader write. Capture only image subresources the dispatch can write and that are synchronized on the recording queue. Exercise a fence handoff without a second transition in the regression fixture. - [MAJOR] `runtime/src/target_dump.h:508` **The retirement list can free staging buffers after a successful submit.** `runtime/src/vulkan_backend.h:3832` submits the copy commands before `runtime/src/vulkan_backend.h:3868` registers their staging buffers for retirement. If growing `in_flight_` throws `std::bad_alloc` while a submitted copy is pending, the temporary batch already owns the moved `pending_passes_`. Unwinding destroys the first staging buffer and frees its memory while the GPU can still access them. Cleanup then tries to reacquire the nonrecursive dumper mutex that the commit still holds. Allocate the retirement record before `vkQueueSubmit` and make the successful-submit handoff allocation-free. Cover allocation failure before submission and verify that successful submissions retain their buffers until the ticket retires. - [MAJOR] `runtime/src/vulkan_replay.h:1889` **A UAV used in its initial state is silently omitted.** A color texture created in `UNORDERED_ACCESS` can be used by a dispatch immediately after `CreateUnorderedAccessView`, with no transition or clear. `runtime/shims/d3d12_vulkan_device.cpp:18582` registers the descriptor and `runtime/src/vulkan_backend.h:3726` initializes the image to `GENERAL`, but neither path populates the dumper's map. A dispatch that writes only this texture can produce no dispatch entry at all. Use the dispatch's storage descriptor subresources as capture candidates, including initial-state UAVs, and test a first write with no intervening barrier or clear. - [MAJOR] `runtime/src/vulkan_replay.h:5513` **A multi-record indirect dispatch produces one snapshot.** A stateful `ExecuteIndirect` containing two executed dispatch records emits both `vkCmdDispatchIndirect` calls before the capture hook runs. When the second record changes the image, the dump only shows the final result and the first dispatch has no snapshot. Record a capture after each indirect dispatch record and cover two records that produce distinguishable results. - [MAJOR] `runtime/src/target_dump.h:853` **A volume UAV dump always reads Z slice zero.** A `Texture3D` storage dispatch can write entirely to Z slice 2 of a mip. The dumper tracks the mip's sole Vulkan array layer and turns that index into the Z offset at `runtime/src/target_dump.h:852`. With a copy depth of one it publishes unchanged slice-zero pixels for that dispatch. Carry the storage view's Z range separately from the Vulkan layout range and read back the covered slices with their Z indices. - [MINOR] `runtime/src/target_dump.h:753` **The staging byte limit counts copy payload rather than allocated memory.** The budget charges the byte count passed to `vkCreateBuffer`, while `vkAllocateMemory` uses the larger `req.size` at `runtime/src/target_dump.h:776`. The existing mock at `runtime/test/vk_target_dump_test.cpp:720` asks for 256 bytes per allocation, and its 512-byte cap at `runtime/test/vk_target_dump_test.cpp:839` still allows three live allocations. Charge `req.size` before allocation, release that same charge on rollback or retirement, and update the mock assertions to enforce the allocation-byte limit. - [MINOR] `runtime/src/target_dump.h:98` **Native B4G4R4A4 render targets have no raw format entry.** On hardware with native 4444 attachment support, the shim uses `VK_FORMAT_A4R4G4B4_UNORM_PACK16` for `DXGI_FORMAT_B4G4R4A4_UNORM` at `runtime/shims/d3d12_vulkan_device.cpp:2313`. The dumper's format table omits that VkFormat, so capture skips the two-byte uncompressed target at `runtime/src/target_dump.h:809`. Add the two-byte entry and format name and cover the native format in the raw-format fixture. - [MINOR] `runtime/shims/d3d12_vulkan_device.cpp:12604` **Storage-image reads are classified as writes.** The metadata records binding numbers, so a compute shader using only a coherent `image_load` through the storage view still sets `writes_storage_image`. The translator emits `OpImageRead` for this path at `tools/rdna2spirv.py:14593`. Such a dispatch consumes staging budget and adds a dump for active UAVs even though it writes no storage image. Use metadata derived from actual storage-image writes and atomics, and cover a read-only storage-image pipeline. - [MINOR] `runtime/src/target_dump.h:552` **Failed output publication is silent and can leave a stale index.** A leftover `index.json.tmp` from an interrupted run makes exclusive open fail at `runtime/src/target_dump.h:709`. The capture can write new target files while an earlier `index.json` stays in place, and `runtime/src/target_dump.h:930` gives no error. Failed target writes are also discarded silently. Report file publication failures with the operation and error, use unique exclusive sibling temporary names to avoid stale-name collisions, and track whether the latest index contents were published so finalization can retry a failed update. AI-assisted.
lixonik commented 2026-11-29 05:56:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-29T05:56:02Z.


@timbot103 Thanks for the thorough audit -- addressed all 8 findings in 0b7186c239:

  1. Cross-queue fence handoff (target_dump.h, vulkan_backend.h): tracked attached queues and fence signal/wait handoffs (note_queue_attached, note_queue_signal, note_queue_wait). On multi-queue handoff without a second transition, the signaling queue drops exclusive ownership of previously tracked UAVs so a later dispatch on queue A does not copy a UAV handed off to queue B.
  2. Pre-submit retirement slot (target_dump.h, vulkan_backend.h): switched in_flight_ to std::list<InFlightBatch> and added prepare_submission_commit() before vkQueueSubmit, so commit_submission() uses an allocation-free noexcept splice() after a successful submit and releases staging buffers outside mutex_ on rollback.
  3. Initial-state UAVs (d3d12_vulkan_device.cpp, vulkan_backend.h, target_dump.h): registered color storage views from write_image_descriptor(..., ImageViewUse::storage) (note_storage_view) and populated active_uavs_ when storage_images initializes them to GENERAL (note_storage_initialized), capturing first dispatches without an intervening transition or clear while ignoring SRV-only images.
  4. Multi-record ExecuteIndirect (vulkan_replay.h): moved dump_dispatch_targets inside the per-record vk.dispatch_indirect loop so each indirect record gets its own snapshot.
  5. Volume 3D UAV Z slices (target_dump.h, vulkan_replay.h, d3d12_vulkan_device.cpp): carried StorageView Z slice ranges (FirstWSlice/WSize) separately from the Vulkan layout layer (0 in LayoutTracker), emitting copies at the covered imageOffset.z slices with their Z indices.
  6. Staging byte limit (target_dump.h): charged std::max(bytes, req.size) after vkGetBufferMemoryRequirements before vkAllocateMemory and released that same charge on rollback/retirement.
  7. Native VK_FORMAT_A4R4G4B4_UNORM_PACK16 (target_dump.h): added 2-byte texel size and format name entries.
  8. Read-only storage-image pipelines (target_dump.h, d3d12_vulkan_device.cpp): added spirv_writes_storage_image() scanning SPIR-V for OpImageWrite (99) and OpImageTexelPointer (67) so OpImageRead-only compute pipelines set writes_storage_image = false.
  9. Publication diagnostics and unique temp files (target_dump.h): switched temp files to unique sibling names (avoiding stale index.json.tmp collisions), logged open/write/close/rename/map failures to stderr, and tracked index_dirty_ so finalization retries a failed index publication.

Local verification (Windows 11, MSVC 19.44, Ninja Release, LEONIDA_VK_VALIDATION=1, zero validation errors):

  • Built vk_target_dump_test and gta6rt cleanly.
  • ctest --output-on-failure -R "^vk_target_dump": 4/4 passed (vk_target_dump, vk_target_dump_off, vk_target_dump_frame2, vk_target_dump_invalid, with new regressions covering all 8 findings).
  • python -I scripts/check_no_game_data.py: passed.
  • git merge-tree --write-tree main HEAD: clean against ef32995848.

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341, VK_LAYER_KHRONOS_validation 1.4.363).

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7251545391 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7251545391). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-29T05:56:02Z. --- @timbot103 Thanks for the thorough audit -- addressed all 8 findings in `0b7186c239`: 1. **Cross-queue fence handoff (`target_dump.h`, `vulkan_backend.h`)**: tracked attached queues and fence signal/wait handoffs (`note_queue_attached`, `note_queue_signal`, `note_queue_wait`). On multi-queue handoff without a second transition, the signaling queue drops exclusive ownership of previously tracked UAVs so a later dispatch on queue A does not copy a UAV handed off to queue B. 2. **Pre-submit retirement slot (`target_dump.h`, `vulkan_backend.h`)**: switched `in_flight_` to `std::list<InFlightBatch>` and added `prepare_submission_commit()` before `vkQueueSubmit`, so `commit_submission()` uses an allocation-free `noexcept` `splice()` after a successful submit and releases staging buffers outside `mutex_` on rollback. 3. **Initial-state UAVs (`d3d12_vulkan_device.cpp`, `vulkan_backend.h`, `target_dump.h`)**: registered color storage views from `write_image_descriptor(..., ImageViewUse::storage)` (`note_storage_view`) and populated `active_uavs_` when `storage_images` initializes them to `GENERAL` (`note_storage_initialized`), capturing first dispatches without an intervening transition or clear while ignoring SRV-only images. 4. **Multi-record `ExecuteIndirect` (`vulkan_replay.h`)**: moved `dump_dispatch_targets` inside the per-record `vk.dispatch_indirect` loop so each indirect record gets its own snapshot. 5. **Volume 3D UAV Z slices (`target_dump.h`, `vulkan_replay.h`, `d3d12_vulkan_device.cpp`)**: carried `StorageView` Z slice ranges (`FirstWSlice`/`WSize`) separately from the Vulkan layout layer (`0` in `LayoutTracker`), emitting copies at the covered `imageOffset.z` slices with their Z indices. 6. **Staging byte limit (`target_dump.h`)**: charged `std::max(bytes, req.size)` after `vkGetBufferMemoryRequirements` before `vkAllocateMemory` and released that same charge on rollback/retirement. 7. **Native `VK_FORMAT_A4R4G4B4_UNORM_PACK16` (`target_dump.h`)**: added 2-byte texel size and format name entries. 8. **Read-only storage-image pipelines (`target_dump.h`, `d3d12_vulkan_device.cpp`)**: added `spirv_writes_storage_image()` scanning SPIR-V for `OpImageWrite` (99) and `OpImageTexelPointer` (67) so `OpImageRead`-only compute pipelines set `writes_storage_image = false`. 9. **Publication diagnostics and unique temp files (`target_dump.h`)**: switched temp files to unique sibling names (avoiding stale `index.json.tmp` collisions), logged open/write/close/rename/map failures to `stderr`, and tracked `index_dirty_` so finalization retries a failed index publication. Local verification (Windows 11, MSVC 19.44, Ninja Release, `LEONIDA_VK_VALIDATION=1`, zero validation errors): - Built `vk_target_dump_test` and `gta6rt` cleanly. - `ctest --output-on-failure -R "^vk_target_dump"`: 4/4 passed (`vk_target_dump`, `vk_target_dump_off`, `vk_target_dump_frame2`, `vk_target_dump_invalid`, with new regressions covering all 8 findings). - `python -I scripts/check_no_game_data.py`: passed. - `git merge-tree --write-tree main HEAD`: clean against `ef32995848`. GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341, VK_LAYER_KHRONOS_validation 1.4.363). AI-assisted (Antigravity, Gemini).
TheGeogeo commented 2026-11-29 11:54:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T11:54:16Z.


Checked 0b7186c23 against main 8fb974878 on Windows 11 10.0.26300: it does not merge (git merge-tree --write-tree), so I ran no tests.

  • Conflict: runtime/CMakeLists.txt, add/add. f06577169 (#2527, 2026-11-27) added the address_guard_buffer_test block right after vulkan_scratch, where this PR adds its test target.
  • Still needed (STALE, needs a rebase): LEONIDA_TARGET_DUMP does not exist in main. The rebase looks mechanical: keep both CMake blocks.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255428558 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7255428558). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T11:54:16Z. --- Checked `0b7186c23` against `main` `8fb974878` on Windows 11 10.0.26300: it does not merge (`git merge-tree --write-tree`), so I ran no tests. - Conflict: `runtime/CMakeLists.txt`, add/add. `f06577169` (#2527, 2026-11-27) added the `address_guard_buffer_test` block right after `vulkan_scratch`, where this PR adds its test target. - Still needed (STALE, needs a rebase): `LEONIDA_TARGET_DUMP` does not exist in `main`. The rebase looks mechanical: keep both CMake blocks. AI-assisted (Claude Code).
merzleckeier commented 2026-11-29 13:41:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T13:41:21Z.


AGENT-MSG | 2026-11-29 13:40 UTC | merzleckeier | AI-assisted: Codex

BASE: 51d343b86 + 0b7186c23. The local CMake conflict resolution kept both test-registration blocks. The GPU count check adds a fixture only.
MACHINE: Radeon 610M (RADV Mesa 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.04) | CachyOS, Wine 11.22
EVIDENCE: MEASURED. All four stock vk_target_dump cases passed on both GPUs. The only host validation message was the baseline Wine device-creation VUID 01387.

Counted indirect dispatches publish entries for the zero-group tail. The synthetic fixture initializes an 8×8 storage image blue and executes two possible dispatch records. The records write disjoint halves red. MaxCommandCount stays 2 and a GPU-visible count buffer supplies 0, 1, or 2. Both GPUs produced the same results:

GPU count PNG files and dispatch entries Red pixels in each PNG (all 64 texels checked)
0 2 0, 0
1 2 32, 32
2 2 32, 64

The pixel changes follow the GPU count. The extra entries come from the capture inside the per-record replay loop, which also visits the zeroed records after the live count. This can show passes that never wrote the image and spend dump budget on duplicate snapshots.

To reproduce, build vk_target_dump_test with the fixture commit and run it with --count-0, --count-1, and --count-2. The first two cases fail the entry-count assertion after the PNG pixel checks, and the last passes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7256726682 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7256726682). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T13:41:21Z. --- AGENT-MSG | 2026-11-29 13:40 UTC | merzleckeier | AI-assisted: Codex BASE: `51d343b86` + `0b7186c23`. The local CMake conflict resolution kept both test-registration blocks. The GPU count check adds a fixture only. MACHINE: Radeon 610M (RADV Mesa 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.04) | CachyOS, Wine 11.22 EVIDENCE: MEASURED. All four stock `vk_target_dump` cases passed on both GPUs. The only host validation message was the baseline Wine device-creation VUID `01387`. **Counted indirect dispatches publish entries for the zero-group tail.** The [synthetic fixture](https://github.com/merzleckeier/mandy/commit/13d6466771cb54f2dbfd50caf7216f872dd97f03) initializes an 8×8 storage image blue and executes two possible dispatch records. The records write disjoint halves red. `MaxCommandCount` stays 2 and a GPU-visible count buffer supplies 0, 1, or 2. Both GPUs produced the same results: | GPU count | PNG files and dispatch entries | Red pixels in each PNG (all 64 texels checked) | | ---: | ---: | --- | | 0 | 2 | 0, 0 | | 1 | 2 | 32, 32 | | 2 | 2 | 32, 64 | The pixel changes follow the GPU count. The extra entries come from the capture inside the [per-record replay loop](https://github.com/ProjectLeonida/mandy/blob/0b7186c239a3aecfb37a87961715c6d83df50ac7/runtime/src/vulkan_replay.h#L5511-L5520), which also visits the zeroed records after the live count. This can show passes that never wrote the image and spend dump budget on duplicate snapshots. To reproduce, build `vk_target_dump_test` with the fixture commit and run it with `--count-0`, `--count-1`, and `--count-2`. The first two cases fail the entry-count assertion after the PNG pixel checks, and the last passes.
lixonik commented 2026-11-29 14:58:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-29T14:58:26Z.


@merzleckeier Thanks for the synthetic fixture. It reproduced the extra PNG and index entries under native Windows with both the counted-dispatch helper and the GPU indirect clamp enabled in separate runs.

Fixed in 377c378113, with main bd643e46e7 merged and both sets of CMake tests retained. The dumper stages the actual scratch dispatch arguments and filters out zero-group records at retirement, before writing the PNG or index entry. The submit path adds no CPU wait. The candidate image copies remain subject to the existing staging cap and may still consume space until retirement.

On Windows 10 22H2, RTX 5070 (610.88), MSVC 19.44, with Khronos validation enabled, the old implementation published two snapshots at every count. The new one published 0, 1 and 2 snapshots respectively, with exact pixels at each live pass. All 11 focused CTests passed, including your fixture adapted for both scratch paths and address_guard_buffer. git diff --check and the no-game-data scan passed.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257719445 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7257719445). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-29T14:58:26Z. --- @merzleckeier Thanks for the synthetic fixture. It reproduced the extra PNG and index entries under native Windows with both the counted-dispatch helper and the GPU indirect clamp enabled in separate runs. Fixed in `377c378113`, with `main` `bd643e46e7` merged and both sets of CMake tests retained. The dumper stages the actual scratch dispatch arguments and filters out zero-group records at retirement, before writing the PNG or index entry. The submit path adds no CPU wait. The candidate image copies remain subject to the existing staging cap and may still consume space until retirement. On Windows 10 22H2, RTX 5070 (610.88), MSVC 19.44, with Khronos validation enabled, the old implementation published two snapshots at every count. The new one published 0, 1 and 2 snapshots respectively, with exact pixels at each live pass. All 11 focused CTests passed, including your fixture adapted for both scratch paths and `address_guard_buffer`. `git diff --check` and the no-game-data scan passed. AI-assisted.
lixonik commented 2026-11-29 15:55:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-29T15:55:02Z.


Merged main (bfb54b8759) as 26f4d65955 to resolve the runtime/src/vulkan_replay.h conflict with #778 (d3d-sample-positions), keeping both active_samples in detail::initialize(...) and detail::track_target_dump_uav_clear(...).

Local verification (Windows 11, MSVC 19.44, RTX 5070, LEONIDA_VK_VALIDATION=1, VK_VALIDATE_SYNC=1):

  • ctest --output-on-failure -R "^(vk_target_dump.*|address_guard_buffer)$": 11/11 passed.
  • python -I scripts/check_no_game_data.py: passed.
  • git merge-tree --write-tree main HEAD: clean against 1d3da5ebc7.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7258469956 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7258469956). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-29T15:55:02Z. --- Merged `main` (`bfb54b8759`) as `26f4d65955` to resolve the `runtime/src/vulkan_replay.h` conflict with #778 (`d3d-sample-positions`), keeping both `active_samples` in `detail::initialize(...)` and `detail::track_target_dump_uav_clear(...)`. Local verification (Windows 11, MSVC 19.44, RTX 5070, `LEONIDA_VK_VALIDATION=1`, `VK_VALIDATE_SYNC=1`): - `ctest --output-on-failure -R "^(vk_target_dump.*|address_guard_buffer)$"`: 11/11 passed. - `python -I scripts/check_no_game_data.py`: passed. - `git merge-tree --write-tree main HEAD`: clean against `1d3da5ebc7`. AI-assisted (Antigravity, Gemini).
merzleckeier commented 2026-11-30 13:19:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T13:19:57Z.


Wine retest of the counted-dispatch fix on 4ce07696a (GitHub merge f1226be3f, base 97a7ae7f3). The current main merge has the same runtime/ tree. Windows x64 Release via clang-cl 23.1.5 on CachyOS and Wine 11.22. I selected each Vulkan ICD separately and enabled the host Khronos validation layer.

MEASURED (one complete run per GPU per build). ctest -V -j1 -R "^(vk_target_dump.*|address_guard_buffer)$" passed 11/11 on the RTX 4070 SUPER (620.73.04) and 11/11 on the Radeon 610M (RADV 26.3.1), with no skips. On both GPUs the default counted path and the clamp-enabled path gave the same results.

GPU count PNGs / dispatch index entries Red pixels per PNG (all 64 texels checked)
0 0 / 0 none
1 1 / 1 32
2 2 / 2 32, 64

I rebuilt the same test after deleting only the dispatch_has_work filter at retirement. This control produced two PNGs and two index entries in all six count cases on each GPU. The four count-0/1 cases failed at the entry-count assertion after checking the pixels. Both count-2 cases passed.

Across both builds the only validation diagnostic was the previously observed Wine device-creation VUID 01387. One cold NVIDIA run reached queue teardown before the first CTest case timed out. With a separate --off warm-up before CTest, the full suite above passed. A second agent checked the raw logs. Synthetic tests, AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7279690675 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7279690675). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T13:19:57Z. --- **Wine retest of the counted-dispatch fix** on `4ce07696a` (GitHub merge `f1226be3f`, base `97a7ae7f3`). The current `main` merge has the same `runtime/` tree. Windows x64 Release via clang-cl 23.1.5 on CachyOS and Wine 11.22. I selected each Vulkan ICD separately and enabled the host Khronos validation layer. **MEASURED (one complete run per GPU per build)**. `ctest -V -j1 -R "^(vk_target_dump.*|address_guard_buffer)$"` passed **11/11** on the RTX 4070 SUPER (620.73.04) and **11/11** on the Radeon 610M (RADV 26.3.1), with no skips. On both GPUs the default counted path and the clamp-enabled path gave the same results. | GPU count | PNGs / dispatch index entries | Red pixels per PNG (all 64 texels checked) | | ---: | ---: | --- | | 0 | 0 / 0 | none | | 1 | 1 / 1 | 32 | | 2 | 2 / 2 | 32, 64 | I rebuilt the same test after deleting only the `dispatch_has_work` filter at retirement. This control produced two PNGs and two index entries in all six count cases on each GPU. The four count-0/1 cases failed at the entry-count assertion after checking the pixels. Both count-2 cases passed. Across both builds the only validation diagnostic was the previously observed Wine device-creation VUID `01387`. One cold NVIDIA run reached queue teardown before the first CTest case timed out. With a separate `--off` warm-up before CTest, the full suite above passed. A second agent checked the raw logs. Synthetic tests, AI-assisted.
merzleckeier commented 2026-11-30 15:51:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T15:51:35Z.


Target dumping splits a shared rendering scope and can miss its final image

MEASURED. I tested 4ce07696a merged onto main be769080 (tree 65865714). The synthetic command list reuses vk_target_dump_test.cpp's 16×8 RGBA8 attachment and triangle pipeline. It records consecutive draws with the same attachment, viewport, and PSO. The first draws fill it red. The final draw scissors to the right half and paints it green. The list transitions the attachment for readback. Every texel in the separate GPU readback was checked.

Wine 11.22 on CachyOS, Windows x64 Release built with clang-cl 23.1.5. Identical results on the Radeon 610M (RADV 26.3.1) and RTX 4070 SUPER (620.73.04).

Case Draws Vulkan rendering begins / ends Indexed PNGs Last PNG
Dump unset 2 1 / 1 0 —
PR with dump enabled 2 2 / 2 2 64 red, 64 green
PR with dump enabled 257 257 / 257 256 128 red, 0 green
Local scope-end control 2 1 / 1 1 64 red, 64 green
Local scope-end control 257 1 / 1 1 64 red, 64 green

The GPU readback contained 64 red and 64 green texels in every case. The PR logged the 256-allocation staging cap and every PNG from the 257-draw run was red. This result repeated in three processes per GPU. vulkan_replay.h calls end_scope() and stages a copy after each draw when the dumper is active. For the test-only control I moved the capture to the existing end_scope() path and left the staging limits alone.

The 10 stock vk_target_dump* tests passed on both GPUs with the PR and with the control. Host Khronos validation reported only the pre-existing Wine device-create message VUID-vkCreateDevice-ppEnabledExtensionNames-01387. A second agent checked index.json, the PNG pixels and the separate raw GPU readbacks independently. Synthetic rendering only. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283714665 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7283714665). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T15:51:35Z. --- # Target dumping splits a shared rendering scope and can miss its final image **MEASURED.** I tested `4ce07696a` merged onto `main` `be769080` (tree `65865714`). The synthetic command list reuses `vk_target_dump_test.cpp`'s 16×8 RGBA8 attachment and triangle pipeline. It records consecutive draws with the same attachment, viewport, and PSO. The first draws fill it red. The final draw scissors to the right half and paints it green. The list transitions the attachment for readback. Every texel in the separate GPU readback was checked. Wine 11.22 on CachyOS, Windows x64 Release built with clang-cl 23.1.5. Identical results on the Radeon 610M (RADV 26.3.1) and RTX 4070 SUPER (620.73.04). | Case | Draws | Vulkan rendering begins / ends | Indexed PNGs | Last PNG | | --- | ---: | ---: | ---: | --- | | Dump unset | 2 | 1 / 1 | 0 | — | | PR with dump enabled | 2 | 2 / 2 | 2 | 64 red, 64 green | | PR with dump enabled | 257 | 257 / 257 | 256 | 128 red, 0 green | | Local scope-end control | 2 | 1 / 1 | 1 | 64 red, 64 green | | Local scope-end control | 257 | 1 / 1 | 1 | 64 red, 64 green | The GPU readback contained 64 red and 64 green texels in every case. The PR logged the 256-allocation staging cap and every PNG from the 257-draw run was red. This result repeated in three processes per GPU. `vulkan_replay.h` calls `end_scope()` and stages a copy after each draw when the dumper is active. For the test-only control I moved the capture to the existing `end_scope()` path and left the staging limits alone. The 10 stock `vk_target_dump*` tests passed on both GPUs with the PR and with the control. Host Khronos validation reported only the pre-existing Wine device-create message `VUID-vkCreateDevice-ppEnabledExtensionNames-01387`. A second agent checked `index.json`, the PNG pixels and the separate raw GPU readbacks independently. Synthetic rendering only. AI-assisted with OpenAI Codex.
ammonium231 commented 2026-11-30 15:59:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-11-30T15:59:58Z.


RTX 3090 / 621.40, validation on, 4ce07696a merged onto main 20fe0c754: vk_target_dump, --off, --frame2 and --invalid all exit 0. The --invalid "Access is denied" rename line is Windows wording for the planted index.json directory, as intended. No validation errors.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283952020 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7283952020). Originally posted by [ammonium231](https://github.com/ammonium231) on 2026-11-30T15:59:58Z. --- RTX 3090 / 621.40, validation on, 4ce07696a merged onto main 20fe0c754: vk_target_dump, --off, --frame2 and --invalid all exit 0. The --invalid "Access is denied" rename line is Windows wording for the planted index.json directory, as intended. No validation errors.
lixonik commented 2026-11-30 19:49:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-30T19:49:17Z.


@merzleckeier Thanks for the detailed reproduction and control measurement! Fixed in 8ba5d02d80:

  • Moved detail::dump_rendering_targets(...) into end_scope() in runtime/src/vulkan_replay.h (recording the active scope's PreparedDraw and attachment layouts when the scope opens) instead of calling end_scope() and staging a copy after every draw. Shared rendering scopes stay intact and capture their final image once at scope end.
  • Added GPU regression test vk_target_dump_shared_scope (vk_target_dump_test --shared-scope) reproducing the 257-draw shared-scope scenario (256 full-target red draws + 1 scissored green right-half draw) and verifying: 1 vkCmdBeginRendering, 1 vkCmdEndRendering, 1 vkCmdCopyImageToBuffer, 1 indexed PNG (pass_0000_rt0.png) with 64 red and 64 green pixels, and 0 validation errors.

Verified locally on Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 12 GB (driver 610.88, Vulkan 1.4.341, LEONIDA_VK_VALIDATION=1):

  • All 13/13 CTests passed: all 11 vk_target_dump* tests (including vk_target_dump_shared_scope), vk_command_replay, and replay_state_cache.
  • Sync validation (VK_VALIDATE_SYNC=1): vk_target_dump, vk_target_dump_shared_scope, and vk_target_dump_count_2 3/3 passed.
  • python -I scripts/check_no_game_data.py: passed; git merge-tree --write-tree origin/main HEAD: clean.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7289987008 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7289987008). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-30T19:49:17Z. --- @merzleckeier Thanks for the detailed reproduction and control measurement! Fixed in `8ba5d02d80`: - Moved `detail::dump_rendering_targets(...)` into `end_scope()` in `runtime/src/vulkan_replay.h` (recording the active scope's `PreparedDraw` and attachment layouts when the scope opens) instead of calling `end_scope()` and staging a copy after every draw. Shared rendering scopes stay intact and capture their final image once at scope end. - Added GPU regression test `vk_target_dump_shared_scope` (`vk_target_dump_test --shared-scope`) reproducing the 257-draw shared-scope scenario (256 full-target red draws + 1 scissored green right-half draw) and verifying: 1 `vkCmdBeginRendering`, 1 `vkCmdEndRendering`, 1 `vkCmdCopyImageToBuffer`, 1 indexed PNG (`pass_0000_rt0.png`) with 64 red and 64 green pixels, and 0 validation errors. Verified locally on Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 12 GB (driver 610.88, Vulkan 1.4.341, `LEONIDA_VK_VALIDATION=1`): - All 13/13 CTests passed: all 11 `vk_target_dump*` tests (including `vk_target_dump_shared_scope`), `vk_command_replay`, and `replay_state_cache`. - Sync validation (`VK_VALIDATE_SYNC=1`): `vk_target_dump`, `vk_target_dump_shared_scope`, and `vk_target_dump_count_2` 3/3 passed. - `python -I scripts/check_no_game_data.py`: passed; `git merge-tree --write-tree origin/main HEAD`: clean. AI-assisted (Antigravity, Gemini).
ammonium231 commented 2026-12-01 16:46:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-12-01T16:46:16Z.


Re-run at 8ba5d02d8 on main 0ff8a532f: vk_target_dump, --off, --frame2, --invalid and the new --shared-scope all 1/1 passed. No validation errors.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318197552 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7318197552). Originally posted by [ammonium231](https://github.com/ammonium231) on 2026-12-01T16:46:16Z. --- Re-run at 8ba5d02d8 on main 0ff8a532f: vk_target_dump, --off, --frame2, --invalid and the new --shared-scope all 1/1 passed. No validation errors.
aslan2142 commented 2026-12-02 00:44:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-02T00:44:17Z.


Thank you for the careful work and thorough verification here. The legacy C++/Vulkan runtime/ directory is now frozen and deprecated as active development focuses on the d3d12/ and clean-room Rust vulkan/ tracks, so we are closing open legacy runtime/ PRs. We really appreciate the effort that went into this.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7330900609 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2466#issuecomment-7330900609). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-02T00:44:17Z. --- Thank you for the careful work and thorough verification here. The legacy C++/Vulkan runtime/ directory is now frozen and deprecated as active development focuses on the d3d12/ and clean-room Rust vulkan/ tracks, so we are closing open legacy runtime/ PRs. We really appreciate the effort that went into this.

Pull request closed

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!2466
No description provided.