vkback: flatten ListRec roots and remove per-op stack/pass allocations #14

Manually merged
github merged 2 commits from github-bot/gh-14 into gh-pr/14/base 2026-11-30 22:11:44 +00:00 AGit
Owner

@⁠olafix52 on GitHub · 2026-11-30 17:45 UTC · original
olafix52:perf/listrec-draw-hotpath → main · +369 −125 · 7 files · 2 commits · merged 2026-11-30 22:11 UTC

Summary

Flattens per-command-list root state in ListRec and removes repeated per-draw and per-call heap allocations on the renderer thread (live: run_list / rec: draw/dispatch).

Changes

  • listrec.rs: replace per-stage HashMap root tables/views/constants with flat [0..64] arrays + u64 presence bitmasks (spilling slots >= 64 to overflow maps), inline up to 16 u32 root constants per slot (ConstSlot), cache cbv_heap_start on set_heaps, and replace Vec<u32> vb_slots with a compact Copy VbSlots ([u8; 16], len).
  • lib.rs, viewdesc.rs: return stack ([u32; 64], usize) from push_block, build color attachments on a stack [vk::RenderingAttachmentInfo; 8] in draw_call_inner, cache vk::Extent2D in pass_open to skip attachment construction when continuing an open pass (same_pass(), preserving existing render-pass invalidation rules), and reuse ListRec Vec buffers in set_heaps/set_targets/set_viewports/set_scissors.
  • live.rs: decode ComputeConstants/GraphicsConstants (<= 64 dwords) and Targets (<= 8 RTVs) through stack buffers.
  • dump.rs, rtcheck.rs: update readers to ListRec accessors.
  • greenfield/tools/policy/oversize.txt: lower greenfield/vkback/src/lib.rs count from 4378 to 4368.
  • Kept (AGENTS.md rule 24): removes per-draw allocator churn cleanly on the renderer critical path, helping both now on renderer-heavy windows and as upstream bottlenecks shrink.

Measurements

  • Machine: AMD Ryzen 9 7900X (24T), 30 GiB RAM, AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.3.1), Linux 7.3.6-3-cachyos, Proton Experimental (experimental-11.0-20261123b).
  • Scene: prison cell, steady state (0..140 world s, warm shader store, VKTORY_LOCK=1 MEASURE=1, VKB_LAT + greenfield/tools/frec/frames.py 0 140 --no-perf), interleaved A B B A (measured pre-rebase 59bfca1 vs main 7403bee; rebased cleanly onto 8a3cb80 with identical code diff):
Arm Build FPS Mean / p50 / p90 / p99 / Max (ms) > 33.3 ms Renderer / Last-240 rend (ms) draw/dispatch (ms/f, ns/draw) run_list (ms/f)
A1 main (7403bee) 23.44 42.7 / 40.7 / 59.4 / 104.7 / 262.0 72.1% 33.8 / 30.1 5.70 (661 ns) 12.96
B1 listrec-hotpath 23.25 43.0 / 41.1 / 58.4 / 106.6 / 205.7 75.6% 31.7 / 28.1 4.39 (532 ns) 11.27
B2 listrec-hotpath 25.17 39.7 / 37.6 / 53.2 / 95.1 / 279.0 67.5% 29.1 / 26.3 4.07 (489 ns) 10.41
A2 main (7403bee) 25.02 40.0 / 37.4 / 56.1 / 88.9 / 188.9 66.2% 30.0 / 28.2 5.20 (608 ns) 11.90
  • Renderer CPU work separates cleanly across every pair: rec: draw/dispatch 5.45 -> 4.23 ms/f (634.5 -> 510.5 ns/draw, -19.5%), live: run_list 12.43 -> 10.84 ms/f (-12.8%), and settled last 240 frames renderer busy 29.15 -> 27.20 ms/f (-1.95 ms/f). Whole-frame FPS stayed within run-to-run variance because title wait absorbed part of the slack (7.55 -> 9.00 ms/f) alongside 26.1-26.3 ms GPU busy.

Verification (rebased 3d70e70 on 8a3cb80)

  • cargo test -p vkback --lib -j 6: 146 passed, 0 failed, 3 ignored.
  • cargo test -p vkback --test policy -j 6: 6 passed, 0 failed.
  • cargo xtask policy: asset policy: 533 files ok.
**@⁠olafix52** on GitHub · 2026-11-30 17:45 UTC · [original](https://github.com/vktory6/VKtory/pull/14) `olafix52:perf/listrec-draw-hotpath` → `main` · +369 −125 · 7 files · 2 commits · merged 2026-11-30 22:11 UTC ### Summary Flattens per-command-list root state in `ListRec` and removes repeated per-draw and per-call heap allocations on the renderer thread (`live: run_list` / `rec: draw/dispatch`). ### Changes - **`listrec.rs`**: replace per-stage `HashMap` root tables/views/constants with flat `[0..64]` arrays + `u64` presence bitmasks (spilling slots `>= 64` to overflow maps), inline up to 16 `u32` root constants per slot (`ConstSlot`), cache `cbv_heap_start` on `set_heaps`, and replace `Vec<u32>` `vb_slots` with a compact `Copy` `VbSlots` (`[u8; 16]`, `len`). - **`lib.rs`, `viewdesc.rs`**: return stack `([u32; 64], usize)` from `push_block`, build color attachments on a stack `[vk::RenderingAttachmentInfo; 8]` in `draw_call_inner`, cache `vk::Extent2D` in `pass_open` to skip attachment construction when continuing an open pass (`same_pass()`, preserving existing render-pass invalidation rules), and reuse `ListRec` `Vec` buffers in `set_heaps`/`set_targets`/`set_viewports`/`set_scissors`. - **`live.rs`**: decode `ComputeConstants`/`GraphicsConstants` (`<= 64` dwords) and `Targets` (`<= 8` RTVs) through stack buffers. - **`dump.rs`, `rtcheck.rs`**: update readers to `ListRec` accessors. - **`greenfield/tools/policy/oversize.txt`**: lower `greenfield/vkback/src/lib.rs` count from 4378 to 4368. - **Kept (`AGENTS.md` rule 24):** removes per-draw allocator churn cleanly on the renderer critical path, helping both now on renderer-heavy windows and as upstream bottlenecks shrink. ### Measurements - Machine: AMD Ryzen 9 7900X (24T), 30 GiB RAM, AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.3.1), Linux 7.3.6-3-cachyos, Proton Experimental (`experimental-11.0-20261123b`). - Scene: prison cell, steady state (`0..140` world s, warm shader store, `VKTORY_LOCK=1 MEASURE=1`, `VKB_LAT` + `greenfield/tools/frec/frames.py 0 140 --no-perf`), interleaved `A B B A` (measured pre-rebase `59bfca1` vs `main` `7403bee`; rebased cleanly onto `8a3cb80` with identical code diff): | Arm | Build | FPS | Mean / p50 / p90 / p99 / Max (ms) | > 33.3 ms | Renderer / Last-240 rend (ms) | `draw/dispatch` (ms/f, ns/draw) | `run_list` (ms/f) | |---|---|---:|---|---:|---|---:|---:| | A1 | `main` (`7403bee`) | 23.44 | 42.7 / 40.7 / 59.4 / 104.7 / 262.0 | 72.1% | 33.8 / 30.1 | 5.70 (661 ns) | 12.96 | | B1 | `listrec-hotpath` | 23.25 | 43.0 / 41.1 / 58.4 / 106.6 / 205.7 | 75.6% | 31.7 / **28.1** | **4.39 (532 ns)** | **11.27** | | B2 | `listrec-hotpath` | 25.17 | 39.7 / 37.6 / 53.2 / 95.1 / 279.0 | 67.5% | 29.1 / **26.3** | **4.07 (489 ns)** | **10.41** | | A2 | `main` (`7403bee`) | 25.02 | 40.0 / 37.4 / 56.1 / 88.9 / 188.9 | 66.2% | 30.0 / 28.2 | 5.20 (608 ns) | 11.90 | - Renderer CPU work separates cleanly across every pair: `rec: draw/dispatch` **5.45 -> 4.23 ms/f** (**634.5 -> 510.5 ns/draw, -19.5%**), `live: run_list` **12.43 -> 10.84 ms/f (-12.8%)**, and settled `last 240 frames` renderer busy **29.15 -> 27.20 ms/f (-1.95 ms/f)**. Whole-frame FPS stayed within run-to-run variance because `title wait` absorbed part of the slack (`7.55 -> 9.00 ms/f`) alongside `26.1-26.3 ms` GPU busy. ### Verification (rebased `3d70e70` on `8a3cb80`) - `cargo test -p vkback --lib -j 6`: 146 passed, 0 failed, 3 ignored. - `cargo test -p vkback --test policy -j 6`: 6 passed, 0 failed. - `cargo xtask policy`: `asset policy: 533 files ok`.
Flatten per-command-list root state and remove repeated per-draw/per-call
heap allocations on the renderer thread (`live: run_list` / `rec: draw/dispatch`).

Changes:
- `listrec.rs`: replace `HashMap` root tables/views/constants with flat
  per-stage arrays (`0..64`) + `u64` presence bitmasks (spilling `>= 64` to
  maps), inline up to 16 `u32` root constants per slot (`ConstSlot`), cache
  `cbv_heap_start` in `set_heaps`, and replace `Vec<u32>` `vb_slots` with a
  compact `Copy` `VbSlots` (`[u8; 16]`, `len`).
- `lib.rs`, `viewdesc.rs`: return stack `([u32; 64], usize)` from
  `push_block`, use stack `[RenderingAttachmentInfo; 8]` in `draw_call_inner`,
  cache `vk::Extent2D` in `pass_open` to skip attachment construction when
  continuing an already-open pass (`same_pass()`, keeping existing render-pass
  invalidation rules unchanged), and reuse `ListRec` `Vec` buffers in
  `set_heaps`/`set_targets`/`set_viewports`/`set_scissors`.
- `live.rs`: decode `ComputeConstants`/`GraphicsConstants` (`<= 64` dwords)
  and `Targets` (`<= 8` RTVs) through stack buffers.
- `dump.rs`, `rtcheck.rs`: update debug/check readers to `ListRec` accessors.
- `oversize.txt`: lower `greenfield/vkback/src/lib.rs` from 4378 to 4368.
- Kept (`AGENTS.md` rule 24): eliminates per-draw/per-op allocator pressure on
  the renderer critical path cleanly without hacks.

Measured (prison cell, steady state, 0..140 world s, A/B/B/A vs `main`
7403bee, AMD Ryzen 9 7900X + RX 9070 XT RADV Mesa 26.3.1, `VKB_LAT` +
`frames.py 0 140 --no-perf`):
- `rec: draw/dispatch`: 5.70 / 5.20 ms/f (661 / 608 ns/draw, A mean 5.45 ms/f,
  634.5 ns/draw) -> 4.39 / 4.07 ms/f (532 / 489 ns/draw, B mean 4.23 ms/f,
  510.5 ns/draw, -19.5% per draw), cleanly separated across every arm.
- `live: run_list (total)`: 12.96 / 11.90 ms/f (A mean 12.43) -> 11.27 /
  10.41 ms/f (B mean 10.84, -1.59 ms/f, -12.8%), cleanly separated.
- Settled `last 240 frames` renderer busy: 30.1 / 28.2 ms (A mean 29.15) ->
  28.1 / 26.3 ms (B mean 27.20, -1.95 ms/f).
- Whole-frame FPS stayed within variance (`23.44 / 25.02` vs `23.25 / 25.17`)
  as `title wait` absorbed part of the slack alongside 26.1-26.3 ms GPU busy.

Verification:
- `cargo test -p vkback --lib -j 6` + `cargo test -p vkback --test policy -j 6`
  + `cargo xtask policy`: all pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 17:49:45 +00:00
github-bot force-pushed github-bot/gh-14 from 3d70e7045e to 4e6182f05a 2026-11-30 21:12:54 +00:00 Compare
Author
Owner

@⁠olafix52 on GitHub · 2026-11-30 21:09 UTC · original

Rebased onto main (74587c3, after #13) and updated greenfield/tools/policy/oversize.txt (greenfield/vkback/src/lib.rs at 4366). New commit: 4e6182f.

Re-verification

  • cargo test -p vkback --lib -j 6: 148 passed; 0 failed; 3 ignored
  • cargo test -p vkback --test policy -j 6: 6 passed; 0 failed
  • cargo xtask policy: 533 files ok

Vulkan validation run (AGENTS.md rule 30)

Run under VK_LAYER_KHRONOS_validation (1.4.363, VK_KHRONOS_VALIDATION_REPORT_FLAGS=error, VK_KHRONOS_VALIDATION_DUPLICATE_MESSAGE_LIMIT=3) on the available world save (94.0 s startup + 65.8 s in the world):

  • 0 new errors beyond the baseline list in docs/ROADMAP.md (Vulkan validation errors).
  • 27 distinct VUIDs observed:
    • UNASSIGNED-Threading-MultipleThreads-Read
    • UNASSIGNED-Threading-MultipleThreads-Write
    • VUID-RuntimeSpirv-None-06288
    • VUID-VkBufferCreateInfo-size-06409
    • VUID-VkComputePipelineCreateInfo-layout-01687
    • VUID-VkDescriptorAddressInfoEXT-nullDescriptor-08938
    • VUID-VkDescriptorAddressInfoEXT-range-08940
    • VUID-VkDescriptorGetInfoEXT-type-12222
    • VUID-VkDescriptorGetInfoEXT-type-12223
    • VUID-VkExportMemoryAllocateInfo-handleTypes-09860
    • VUID-VkGraphicsPipelineCreateInfo-layout-01688
    • VUID-VkPipelineLayoutCreateInfo-descriptorType-03018
    • VUID-VkPipelineLayoutCreateInfo-descriptorType-03024
    • VUID-VkPipelineLayoutCreateInfo-descriptorType-03031
    • VUID-VkPipelineLayoutCreateInfo-pSetLayouts-03039
    • VUID-VkQueryPoolCreateInfo-meshShaderQueries-07069
    • VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428
    • VUID-VkRenderingInfo-None-08994
    • VUID-VkShaderModuleCreateInfo-pCode-08740
    • VUID-VkShaderModuleCreateInfo-pCode-08742
    • VUID-vkBindImageMemory-memory-02728
    • VUID-vkCmdClearColorImage-image-00007
    • VUID-vkCmdCopyBuffer-srcBuffer-00118
    • VUID-vkCmdCopyBufferToImage-dstImage-00177
    • VUID-vkCmdCopyImage-srcImage-01548
    • VUID-vkCmdFillBuffer-dstBuffer-00029
    • VUID-vkCmdPushConstants-size-arraylength
**@⁠olafix52** on GitHub · 2026-11-30 21:09 UTC · [original](https://github.com/vktory6/VKtory/pull/14#issuecomment-7291995359) Rebased onto `main` (`74587c3`, after #13) and updated `greenfield/tools/policy/oversize.txt` (`greenfield/vkback/src/lib.rs` at `4366`). New commit: `4e6182f`. ### Re-verification - `cargo test -p vkback --lib -j 6`: `148 passed; 0 failed; 3 ignored` - `cargo test -p vkback --test policy -j 6`: `6 passed; 0 failed` - `cargo xtask policy`: `533 files ok` ### Vulkan validation run (AGENTS.md rule 30) Run under `VK_LAYER_KHRONOS_validation` (`1.4.363`, `VK_KHRONOS_VALIDATION_REPORT_FLAGS=error`, `VK_KHRONOS_VALIDATION_DUPLICATE_MESSAGE_LIMIT=3`) on the available world save (`94.0 s` startup + `65.8 s` in the world): - **0 new errors** beyond the baseline list in `docs/ROADMAP.md` (`Vulkan validation errors`). - **27 distinct VUIDs observed:** - `UNASSIGNED-Threading-MultipleThreads-Read` - `UNASSIGNED-Threading-MultipleThreads-Write` - `VUID-RuntimeSpirv-None-06288` - `VUID-VkBufferCreateInfo-size-06409` - `VUID-VkComputePipelineCreateInfo-layout-01687` - `VUID-VkDescriptorAddressInfoEXT-nullDescriptor-08938` - `VUID-VkDescriptorAddressInfoEXT-range-08940` - `VUID-VkDescriptorGetInfoEXT-type-12222` - `VUID-VkDescriptorGetInfoEXT-type-12223` - `VUID-VkExportMemoryAllocateInfo-handleTypes-09860` - `VUID-VkGraphicsPipelineCreateInfo-layout-01688` - `VUID-VkPipelineLayoutCreateInfo-descriptorType-03018` - `VUID-VkPipelineLayoutCreateInfo-descriptorType-03024` - `VUID-VkPipelineLayoutCreateInfo-descriptorType-03031` - `VUID-VkPipelineLayoutCreateInfo-pSetLayouts-03039` - `VUID-VkQueryPoolCreateInfo-meshShaderQueries-07069` - `VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428` - `VUID-VkRenderingInfo-None-08994` - `VUID-VkShaderModuleCreateInfo-pCode-08740` - `VUID-VkShaderModuleCreateInfo-pCode-08742` - `VUID-vkBindImageMemory-memory-02728` - `VUID-vkCmdClearColorImage-image-00007` - `VUID-vkCmdCopyBuffer-srcBuffer-00118` - `VUID-vkCmdCopyBufferToImage-dstImage-00177` - `VUID-vkCmdCopyImage-srcImage-01548` - `VUID-vkCmdFillBuffer-dstBuffer-00029` - `VUID-vkCmdPushConstants-size-arraylength`
- Root constants: one Vec per stage and slot, kept across resets (a reset clears the set bits;
  a slot is emptied when it is next set, its memory kept). Replaces the 16-word inline part plus
  spill list: one path, no allocation once the slots have been used.
- No second path past D3D12's limits (64 root parameters, 64 constant words, 8 render targets):
  the maps for slots >= 64 and the heap paths for > 64 words / > 8 targets are gone. Such input
  fails loudly through listrec::beyond_d3d12, whose text says the path is missing on purpose.
- VbSlots: a slot past the 16 this backend keeps is reported, not silently dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot changed target branch from main to gh-pr/14/base 2026-11-30 22:11:43 +00:00
github manually merged commit a991679be6 into gh-pr/14/base 2026-11-30 22:11:44 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-11-30 22:11 UTC · original

Thanks, this is a clean win: −19.5 % per recorded draw, and fixed arrays are the natural shape for D3D12's root state. I pushed one commit on top (a991679) and will squash-merge with it:

  • Root constants: one reusable Vec per stage and slot, kept across resets (a reset clears only the set bits; a slot is emptied when it is next set, its memory kept). It replaces the 16-word inline part plus spill list: one code path, and no allocation once the slots have been used.
  • No second path past D3D12's limits (new rule 33 in docs/AGENTS.md: less code wins). The maps for root slots ≥ 64, and the heap paths for > 64 constant words and > 8 render targets, are gone. Such input can't come from the title, so it now fails loudly through listrec::beyond_d3d12, whose message says the path is missing on purpose and names the limit.
  • VbSlots: a vertex buffer slot past the 16 we keep is reported instead of silently left out.

Checks: cargo test -p vkback --lib (148) and --test policy pass, cargo xtask policy OK; validation run (rule 30) on current main: no new errors, and none of the new limit reports fired.

**@⁠vktory6** on GitHub · 2026-11-30 22:11 UTC · [original](https://github.com/vktory6/VKtory/pull/14#issuecomment-7293480421) Thanks, this is a clean win: −19.5 % per recorded draw, and fixed arrays are the natural shape for D3D12's root state. I pushed one commit on top (a991679) and will squash-merge with it: - **Root constants: one reusable `Vec` per stage and slot**, kept across resets (a reset clears only the set bits; a slot is emptied when it is next set, its memory kept). It replaces the 16-word inline part plus spill list: one code path, and no allocation once the slots have been used. - **No second path past D3D12's limits** (new rule 33 in docs/AGENTS.md: less code wins). The maps for root slots ≥ 64, and the heap paths for > 64 constant words and > 8 render targets, are gone. Such input can't come from the title, so it now fails loudly through `listrec::beyond_d3d12`, whose message says the path is missing on purpose and names the limit. - **`VbSlots`**: a vertex buffer slot past the 16 we keep is reported instead of silently left out. Checks: `cargo test -p vkback --lib` (148) and `--test policy` pass, `cargo xtask policy` OK; validation run (rule 30) on current main: no new errors, and none of the new limit reports fired.
This discussion has been locked. Commenting is limited to contributors.
No description provided.