vkback: primary-heap fast path, fused null/stride jobs, and flat Issues for index slots #143

Manually merged
github merged 1 commit from github-bot/gh-143 into gh-pr/143/base 2026-12-01 22:01:53 +00:00 AGit
Owner

@⁠olafix52 on GitHub · 2026-12-01 21:17 UTC · original
olafix52:perf/slot-reads-fast-path → main · +526 −127 · 9 files · 1 commits · merged 2026-12-01 21:56 UTC

What

Addresses docs/TASKS.md item "Renderer CPU: index slots". Reproduces the console's descriptor-heap resolution behaviour faster on the renderer CPU without changing slot semantics (no silent fallbacks; existing retry/null rules preserved).

  • greenfield/vkback/src/slotcache.rs: add direct 32-byte-strided flat primary table over [primary_start, primary_end) with bidirectional entry migration between primary and pages, plus unit test primary_table_migrates_and_serves_direct_lookups.
  • greenfield/vkback/src/live/slots.rs & greenfield/vkback/src/slotwrite.rs: hoist primary_view_heap(), set_primary(ps, pe), and trace.is_some(); take primary-heap direct index fast path in slot_reads_inner, pass precomputed index into slot_read_at_index / write_slot_uncounted_at / slot_retry_fail_at / slot_retry_done_at, and batch ev_counts[6..=8].
  • greenfield/vkback/src/descjob.rs, greenfield/vkback/src/slotwrite.rs & greenfield/vkback/src/bufview.rs: fuse optional (stride_entry, view_address = 0) update into Job::Null { index, mask, stride_entry } (Ctx::run_null_stride), merge duplicate aside borrows in run_job, add Aside::collect_null / aside_null_slot skipping empty pushes, add write_null_slot_with_stride (stride_owed zeros + addr == 0 buffer view path), plus unit test collect_null_and_stride_writes_fuse_or_skip_empty.
  • greenfield/vkback/src/notes.rs, greenfield/vkback/src/descjob.rs & greenfield/vkback/src/lib.rs: replace Issues FxMap<String, Issue> with move-to-front Vec<(Cow<'static, str>, Issue)> to eliminate string hashing on hot slot writes, plus unit test move_to_front_promotes_hot_kinds_and_window_lines_sorts.
  • greenfield/frame/src/d3d.rs & greenfield/vkback/src/slotwrite.rs: add ResourceDesc::from_words and flags_of_words (with unit test from_words_matches_parse_and_flags_offset); in ViewRef::Placed drop 56-byte copies, redundant parse, unreachable None exit, and 5 per-slot Tick::now()/pf spans while preserving be: of which placed image creation (write_view).
  • docs/learnings/vkback-live-cpu.md: update Current state and document the optimization findings.

The reference

  • vkback's slot cache, async descriptor helper, and issue counter are vkback-specific mechanisms with no D3D12 counterpart in crates/victory-gpu.
  • frame::d3d::ResourceDesc::from_words and flags_of_words mirror frame::d3d::ResourceDesc::parse and D3D12_RESOURCE_DESC.

Evidence

  • Clippy & tests (rebased on origin/main bb383d5):
    • cargo clippy --all-targets -j 6 -- -D warnings in greenfield/ and greenfield/wine/: 0 warnings, exit 0.
    • cargo test -j 6 in greenfield/: 0 failures (frame: 13 passed; umem: 22 unit + 1 bench + 12 gpu + other crates passed, 3 ignored sparse probes; vkback lib: 167 passed / 3 ignored; alias_binding: 1 passed; mutable_layout_probe: 1 passed; policy: 6 passed).
  • Interleaved A/B/B/A benchmark (measured on base ab7b4e6, boat-sarc0, RUN_SECS=105, VICTORY_HOST_PADS=off, RX 9070 XT, Mesa 26.3.1, steady 60-present windows shown >= 1150; loud.txt: 0 unowned errors across all runs):
Run FPS med (ms) idx (ms/f) list (ms/f) help (ms/f) wait (ms/f) all (ms/f) cpu (ms/f) ns/r reads/60f
A1 17.89 55.87 12.76 5.04 10.19 1.97 41.82 38.92 46.5 22.98M
A2 18.91 52.95 13.05 4.81 9.78 1.22 39.94 37.23 53.0 20.24M
B1 20.04 50.01 9.72 4.37 9.17 1.12 34.36 31.98 41.5 20.37M
B2 20.51 48.79 9.09 3.91 8.17 0.79 33.17 30.87 40.5 19.25M
Mean A 18.40 54.41 12.91 4.92 9.98 1.59 40.88 38.08 49.8 21.61M
Mean B 20.27 49.40 9.41 4.14 8.67 0.96 33.77 31.43 41.0 19.81M
Delta (B vs A) +10.2% -9.2% -27.1% -15.9% -13.2% -40.1% -17.4% -17.5% -17.6% -8.3%
  • Screenshot check (rule 18): visually verified clean (loud.txt: 0 unowned).
  • Vulkan validation run (rule 30): ~4m38s in world (2,425 shown frames, 3,092 pipelines built), loud.txt: 0 unowned; distinct VUIDs: VUID-VkBufferCreateInfo-size-06409, VUID-VkComputePipelineCreateInfo-layout-01687, VUID-VkGraphicsPipelineCreateInfo-layout-01688, VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428 (0 non-VUID errors, all 4 on docs/TASKS.md allowlist).
  • Why this is enough (rule 27): unit and policy tests verify the new data structures, struct offsets, fused null/stride path, and rule checks directly against production code; interleaved A/B/B/A runs prove the renderer-CPU gain (idx -27.1%, cpu -17.5%, FPS +10.2%); the screenshot check covers descriptor/slot writes (rule 18); and the validation run confirms zero new Vulkan errors (rule 30).

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the fixed item named above (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits)
  • No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9)
  • Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b)
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2)
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35)
  • Every unsafe block has a // SAFETY: comment; no raw pointer around the borrow checker (rule 36)
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION bumped if the translator's output changes (rule 27)
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
**@⁠olafix52** on GitHub · 2026-12-01 21:17 UTC · [original](https://github.com/vktory6/VKtory/pull/143) `olafix52:perf/slot-reads-fast-path` → `main` · +526 −127 · 9 files · 1 commits · merged 2026-12-01 21:56 UTC ## What Addresses `docs/TASKS.md` item **"Renderer CPU: index slots"**. Reproduces the console's descriptor-heap resolution behaviour faster on the renderer CPU without changing slot semantics (no silent fallbacks; existing retry/null rules preserved). - `greenfield/vkback/src/slotcache.rs`: add direct 32-byte-strided flat `primary` table over `[primary_start, primary_end)` with bidirectional entry migration between `primary` and `pages`, plus unit test `primary_table_migrates_and_serves_direct_lookups`. - `greenfield/vkback/src/live/slots.rs` & `greenfield/vkback/src/slotwrite.rs`: hoist `primary_view_heap()`, `set_primary(ps, pe)`, and `trace.is_some()`; take primary-heap direct index fast path in `slot_reads_inner`, pass precomputed `index` into `slot_read_at_index` / `write_slot_uncounted_at` / `slot_retry_fail_at` / `slot_retry_done_at`, and batch `ev_counts[6..=8]`. - `greenfield/vkback/src/descjob.rs`, `greenfield/vkback/src/slotwrite.rs` & `greenfield/vkback/src/bufview.rs`: fuse optional `(stride_entry, view_address = 0)` update into `Job::Null { index, mask, stride_entry }` (`Ctx::run_null_stride`), merge duplicate `aside` borrows in `run_job`, add `Aside::collect_null` / `aside_null_slot` skipping empty pushes, add `write_null_slot_with_stride` (`stride_owed` zeros + `addr == 0` buffer view path), plus unit test `collect_null_and_stride_writes_fuse_or_skip_empty`. - `greenfield/vkback/src/notes.rs`, `greenfield/vkback/src/descjob.rs` & `greenfield/vkback/src/lib.rs`: replace `Issues` `FxMap<String, Issue>` with move-to-front `Vec<(Cow<'static, str>, Issue)>` to eliminate string hashing on hot slot writes, plus unit test `move_to_front_promotes_hot_kinds_and_window_lines_sorts`. - `greenfield/frame/src/d3d.rs` & `greenfield/vkback/src/slotwrite.rs`: add `ResourceDesc::from_words` and `flags_of_words` (with unit test `from_words_matches_parse_and_flags_offset`); in `ViewRef::Placed` drop 56-byte copies, redundant `parse`, unreachable `None` exit, and 5 per-slot `Tick::now()`/`pf` spans while preserving `be: of which placed image creation (write_view)`. - `docs/learnings/vkback-live-cpu.md`: update `Current state` and document the optimization findings. ## The reference - `vkback`'s slot cache, async descriptor helper, and issue counter are `vkback`-specific mechanisms with no D3D12 counterpart in `crates/victory-gpu`. - `frame::d3d::ResourceDesc::from_words` and `flags_of_words` mirror `frame::d3d::ResourceDesc::parse` and `D3D12_RESOURCE_DESC`. ## Evidence - **Clippy & tests (rebased on `origin/main` `bb383d5`):** - `cargo clippy --all-targets -j 6 -- -D warnings` in `greenfield/` and `greenfield/wine/`: 0 warnings, exit 0. - `cargo test -j 6` in `greenfield/`: 0 failures (`frame`: 13 passed; `umem`: 22 unit + 1 bench + 12 gpu + other crates passed, 3 ignored sparse probes; `vkback` lib: 167 passed / 3 ignored; `alias_binding`: 1 passed; `mutable_layout_probe`: 1 passed; `policy`: 6 passed). - **Interleaved A/B/B/A benchmark** (measured on base `ab7b4e6`, `boat-sarc0`, `RUN_SECS=105`, `VICTORY_HOST_PADS=off`, RX 9070 XT, Mesa 26.3.1, steady 60-present windows `shown >= 1150`; `loud.txt`: 0 unowned errors across all runs): | Run | FPS | med (ms) | idx (ms/f) | list (ms/f) | help (ms/f) | wait (ms/f) | all (ms/f) | cpu (ms/f) | ns/r | reads/60f | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | A1 | 17.89 | 55.87 | 12.76 | 5.04 | 10.19 | 1.97 | 41.82 | 38.92 | 46.5 | 22.98M | | A2 | 18.91 | 52.95 | 13.05 | 4.81 | 9.78 | 1.22 | 39.94 | 37.23 | 53.0 | 20.24M | | B1 | 20.04 | 50.01 | 9.72 | 4.37 | 9.17 | 1.12 | 34.36 | 31.98 | 41.5 | 20.37M | | B2 | 20.51 | 48.79 | 9.09 | 3.91 | 8.17 | 0.79 | 33.17 | 30.87 | 40.5 | 19.25M | | **Mean A** | 18.40 | 54.41 | 12.91 | 4.92 | 9.98 | 1.59 | 40.88 | 38.08 | 49.8 | 21.61M | | **Mean B** | 20.27 | 49.40 | 9.41 | 4.14 | 8.67 | 0.96 | 33.77 | 31.43 | 41.0 | 19.81M | | **Delta (B vs A)** | **+10.2%** | **-9.2%** | **-27.1%** | **-15.9%** | **-13.2%** | **-40.1%** | **-17.4%** | **-17.5%** | **-17.6%** | **-8.3%** | - **Screenshot check (rule 18):** visually verified clean (`loud.txt`: 0 unowned). - **Vulkan validation run (rule 30):** ~4m38s in world (`2,425` shown frames, `3,092` pipelines built), `loud.txt`: 0 unowned; distinct VUIDs: `VUID-VkBufferCreateInfo-size-06409`, `VUID-VkComputePipelineCreateInfo-layout-01687`, `VUID-VkGraphicsPipelineCreateInfo-layout-01688`, `VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428` (0 non-VUID errors, all 4 on `docs/TASKS.md` allowlist). - **Why this is enough (rule 27):** unit and policy tests verify the new data structures, struct offsets, fused null/stride path, and rule checks directly against production code; interleaved A/B/B/A runs prove the renderer-CPU gain (`idx` -27.1%, `cpu` -17.5%, FPS +10.2%); the screenshot check covers descriptor/slot writes (rule 18); and the validation run confirms zero new Vulkan errors (rule 30). ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the fixed item named above (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits) - [x] No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9) - [x] Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b) - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2) - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35) - [x] Every `unsafe` block has a `// SAFETY:` comment; no raw pointer around the borrow checker (rule 36) - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION` bumped if the translator's output changes (rule 27) - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
Addresses docs/TASKS.md item 'Renderer CPU: index slots'.

Changes:
- slotcache.rs: add direct 32-byte-strided flat primary table over [primary_start, primary_end) with bidirectional entry migration between primary and pages, plus unit test primary_table_migrates_and_serves_direct_lookups.
- live/slots.rs & slotwrite.rs: hoist primary_view_heap(), set_primary(ps, pe), and trace.is_some(); take primary-heap direct index fast path in slot_reads_inner and pass precomputed index to slot_read_at_index / write_slot_uncounted_at / slot_retry_fail_at / slot_retry_done_at; batch ev_counts[6..=8].
- descjob.rs, slotwrite.rs & bufview.rs: fuse optional (stride_entry, view_address = 0) update into Job::Null { index, mask, stride_entry } (Ctx::run_null_stride), merge duplicate aside borrows in run_job, add Aside::collect_null / aside_null_slot skipping empty pushes, add write_null_slot_with_stride (stride_owed zeros + addr == 0 buffer view path), plus unit test collect_null_and_stride_writes_fuse_or_skip_empty.
- notes.rs, descjob.rs & lib.rs: replace Issues FxMap<String, Issue> with move-to-front Vec<(Cow<'static, str>, Issue)> to eliminate string hashing on hot slot writes, plus unit test move_to_front_promotes_hot_kinds_and_window_lines_sorts.
- frame/src/d3d.rs & slotwrite.rs: add ResourceDesc::from_words and flags_of_words (with unit test from_words_matches_parse_and_flags_offset); in ViewRef::Placed drop 56-byte copies, redundant parse, unreachable None exit, and 5 per-slot Tick::now()/pf spans while preserving 'be:  of which placed image creation (write_view)'.
- docs/learnings/vkback-live-cpu.md: update Current state and document findings.

Reference counterpart status (rule 12):
- vkback's slot cache, async descriptor helper, and issue counter are vkback-specific mechanisms with no D3D12 counterpart in crates/victory-gpu.
- frame::d3d::ResourceDesc::from_words and flags_of_words mirror frame::d3d::ResourceDesc::parse and D3D12_RESOURCE_DESC.

Verification (on base ab7b4e6):
- Interleaved A/B/B/A (boat-sarc0, RUN_SECS=105, VICTORY_HOST_PADS=off, RX 9070 XT, Mesa 26.3.1, steady 60-present windows shown >= 1150):
  A1: 17.89 fps, med 55.87 ms, idx 12.76 ms/f, all 41.82 ms/f, cpu 38.92 ms/f, 46.5 ns/r (22.98M/60f)
  B1: 20.04 fps, med 50.01 ms, idx 9.72 ms/f,  all 34.36 ms/f, cpu 31.98 ms/f, 41.5 ns/r (20.37M/60f)
  B2: 20.51 fps, med 48.79 ms, idx 9.09 ms/f,  all 33.17 ms/f, cpu 30.87 ms/f, 40.5 ns/r (19.25M/60f)
  A2: 18.91 fps, med 52.95 ms, idx 13.05 ms/f, all 39.94 ms/f, cpu 37.23 ms/f, 53.0 ns/r (20.24M/60f)
  loud.txt: 0 unowned errors across all runs.
- Screenshot check (rule 18): visually verified clean (loud.txt: 0 unowned).
- Vulkan validation run (rule 30): ~4m38s in world (2,425 shown frames, 3,092 pipelines built), loud.txt 0 unowned; distinct VUIDs: VUID-VkBufferCreateInfo-size-06409, VUID-VkComputePipelineCreateInfo-layout-01687, VUID-VkGraphicsPipelineCreateInfo-layout-01688, VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428 (all on docs/TASKS.md allowlist; 0 new/non-VUID errors).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 21:19:36 +00:00
github-bot referenced this pull request from a commit 2026-12-01 22:01:52 +00:00
github-bot changed target branch from main to gh-pr/143/base 2026-12-01 22:01:52 +00:00
github manually merged commit c2d93fc842 into gh-pr/143/base 2026-12-01 22:01:53 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 21:57 UTC · original

Merged as github.com/vktory6/VKtory@1befc31, thank you: a clear A/B/B/A and a real gain on the top anti-stutter item (index slots -27%, renderer CPU -17%, +10% fps).

Review notes, all fine as they are: from_words can drop parse's failure path because the only failure was a short buffer; skipping alias_at without a target at the address matches its own first check; and null slots' stride writes now take the same helper-job order as other buffer views, which removes an ordering hazard rather than adding one. Our check: tests pass, house validation run with no new errors.

The task is updated: github.com/vktory6/VKtory@1864b6e. The next step there is the fix shape in "Renderer CPU: index slots": keep every slot's resolution, "not a view" included, until the title writes the slot, so an unchanged slot costs a lookup instead of a resolve. If you'd like to continue on the anti-stutter work, that one or "Texture fills on the GPU" have the biggest measured payoff.

**@⁠vktory6** on GitHub · 2026-12-01 21:57 UTC · [original](https://github.com/vktory6/VKtory/pull/143#issuecomment-7327070704) Merged as https://github.com/vktory6/VKtory/commit/1befc31, thank you: a clear A/B/B/A and a real gain on the top anti-stutter item (index slots -27%, renderer CPU -17%, +10% fps). Review notes, all fine as they are: `from_words` can drop `parse`'s failure path because the only failure was a short buffer; skipping `alias_at` without a target at the address matches its own first check; and null slots' stride writes now take the same helper-job order as other buffer views, which removes an ordering hazard rather than adding one. Our check: tests pass, house validation run with no new errors. The task is updated: https://github.com/vktory6/VKtory/commit/1864b6e. The next step there is the fix shape in "Renderer CPU: index slots": keep every slot's resolution, "not a view" included, until the title writes the slot, so an unchanged slot costs a lookup instead of a resolve. If you'd like to continue on the anti-stutter work, that one or "Texture fills on the GPU" have the biggest measured payoff.
This discussion has been locked. Commenting is limited to contributors.
No description provided.