vkback: co-locate SlotMasks dirty bits into SlotFlags #172

Open
github-bot wants to merge 1 commit from github-bot/gh-172 into main AGit
Owner

@⁠Mhyster on GitHub · 2026-12-01 23:51 UTC · original
Mhyster:opt/colocate-slot-masks → main · +154 −164 · 3 files · 1 commits · open

What

Overlap note: Overlaps issue #57 and the docs/TASKS.md item "Descriptor heap as one array, not seven typed ones" (two mutable descriptor families, which reduces per-slot bindings from 9 to 3 and will simplify the dirty-binding mask tracked here). Builds cleanly on vktory6/main after #143 (1befc31).

Co-locates SlotMasks's 9-bit per-slot dirty descriptor-binding mask (bits 0..=8, bindings 0..=6 plus raw-twin bindings 4/5) with SlotFlags's 4-bit per-slot flags (FLAG_HOOK | FLAG_BUFFER | FLAG_IMAGE | FLAG_RETRY, bits 9..=12) into a single Box<[u16]> inside SlotFlags (greenfield/vkback/src/slotcache.rs):

  • Cuts per-slot state from two separate allocations (SlotFlags::nibbles 1 MiB + Aside::dirty 4 MiB = 5 MiB) to one contiguous 4 MiB array (32 slots per 64-byte cache line), so write_null_slot_with_stride, queue_desc, and run_job hit one cache line instead of two.
  • Removes SlotMasks from RefCell<Aside>: queue_desc, run_job, and aside_null_slot read/update dirty bits directly on self.slot_flags with zero RefCell borrow.
  • When aside_null_slot nulls an already-clean slot with stride_entry == None, it returns immediately without borrowing self.aside at all.
  • Keeps the exact same descriptor bytes, dirty-binding invalidation rules, and conservative DIRTY_ALL (0x1ff) fallback for index >= RAW_TWIN.

The reference

  • Counterpart: crates/victory-gpu/src/descriptor/host.rs (HostHeap::make_at / null_for) writes a single D3D12 descriptor per slot; vkback fans each console slot across 9 Vulkan descriptor-buffer bindings (0..=6 at index, plus raw twins 4/5 at index + RAW_TWIN).
  • Invalidation rules carried over verbatim (rule 17):
    • Startup: null_fill initializes all 9 bindings to null_blobs[b], and use_direct_descriptors copies dbuf0 byte-for-byte, so initial mask 0 matches dbuf0.
    • Marking: every non-null descriptor write ORs its binding bits in queue_desc (SlotFlags::mark_desc) or run_job (SlotFlags::mark_dirty with BufJob::write_mask).
    • Clearing: bits clear only in aside_null_slot (SlotFlags::take_dirty) when Job::Null is queued for all dirty bits, or in run_job (SlotFlags::clear_dirty) when a synchronous BufJob fails (Located::Uncommitted / Located::Short) and nulls null_mask.
    • Fallback & enforcement: index >= RAW_TWIN conservatively returns DIRTY_ALL; queue_write continues to report any write to dbuf0 bypassing queue_desc and descriptor jobs.

Evidence

  • Machine: Linux (CachyOS), Ryzen 5 9600X + AMD RX 9070 XT (Mesa RADV 26.3.1).
  • Offline tests and CI checks run and passing:
    • cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked (all passed, including xtask asset policy).
    • (cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked) (13 frame, 22 umem, 168 vkback, 6 policy passed; includes new slot_flags_dirty_masks_and_twins_preserve_flags and updated collect_null_and_stride_writes_fuse_or_skip_empty).
    • Clippy with --locked -- -D warnings: native root crates, greenfield, greenfield/wine, and greenfield/vkback/translate all clean.
  • Checks NOT run in this PR (live game runs were paused because another agent was actively using the game/GPU on this machine):
    • Boat scene A B B A performance measurement (VKB_LAT + greenfield/tools/frec/frames.py).
    • House scene ~60 s Vulkan validation run (VK_LAYER_KHRONOS_validation).
    • Before/after screenshots (rule 18).
    • PE-side cargo xwin clippy (CI will verify; this change touches only greenfield/vkback/src/{slotcache,descjob,lib}.rs).

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the related 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)
**@⁠Mhyster** on GitHub · 2026-12-01 23:51 UTC · [original](https://github.com/vktory6/VKtory/pull/172) `Mhyster:opt/colocate-slot-masks` → `main` · +154 −164 · 3 files · 1 commits · open ## What > **Overlap note:** Overlaps issue #57 and the `docs/TASKS.md` item *"Descriptor heap as one array, not seven typed ones"* (two mutable descriptor families, which reduces per-slot bindings from 9 to 3 and will simplify the dirty-binding mask tracked here). Builds cleanly on `vktory6/main` after #143 (`1befc31`). Co-locates `SlotMasks`'s 9-bit per-slot dirty descriptor-binding mask (bits `0..=8`, bindings `0..=6` plus raw-twin bindings `4`/`5`) with `SlotFlags`'s 4-bit per-slot flags (`FLAG_HOOK | FLAG_BUFFER | FLAG_IMAGE | FLAG_RETRY`, bits `9..=12`) into a single `Box<[u16]>` inside `SlotFlags` (`greenfield/vkback/src/slotcache.rs`): - Cuts per-slot state from two separate allocations (`SlotFlags::nibbles` 1 MiB + `Aside::dirty` 4 MiB = 5 MiB) to one contiguous 4 MiB array (32 slots per 64-byte cache line), so `write_null_slot_with_stride`, `queue_desc`, and `run_job` hit one cache line instead of two. - Removes `SlotMasks` from `RefCell<Aside>`: `queue_desc`, `run_job`, and `aside_null_slot` read/update dirty bits directly on `self.slot_flags` with zero `RefCell` borrow. - When `aside_null_slot` nulls an already-clean slot with `stride_entry == None`, it returns immediately without borrowing `self.aside` at all. - Keeps the exact same descriptor bytes, dirty-binding invalidation rules, and conservative `DIRTY_ALL` (`0x1ff`) fallback for `index >= RAW_TWIN`. ## The reference - Counterpart: `crates/victory-gpu/src/descriptor/host.rs` (`HostHeap::make_at` / `null_for`) writes a single D3D12 descriptor per slot; `vkback` fans each console slot across 9 Vulkan descriptor-buffer bindings (`0..=6` at `index`, plus raw twins `4`/`5` at `index + RAW_TWIN`). - Invalidation rules carried over verbatim (rule 17): - Startup: `null_fill` initializes all 9 bindings to `null_blobs[b]`, and `use_direct_descriptors` copies `dbuf0` byte-for-byte, so initial mask `0` matches `dbuf0`. - Marking: every non-null descriptor write ORs its binding bits in `queue_desc` (`SlotFlags::mark_desc`) or `run_job` (`SlotFlags::mark_dirty` with `BufJob::write_mask`). - Clearing: bits clear only in `aside_null_slot` (`SlotFlags::take_dirty`) when `Job::Null` is queued for all dirty bits, or in `run_job` (`SlotFlags::clear_dirty`) when a synchronous `BufJob` fails (`Located::Uncommitted` / `Located::Short`) and nulls `null_mask`. - Fallback & enforcement: `index >= RAW_TWIN` conservatively returns `DIRTY_ALL`; `queue_write` continues to report any write to `dbuf0` bypassing `queue_desc` and descriptor jobs. ## Evidence - Machine: Linux (CachyOS), Ryzen 5 9600X + AMD RX 9070 XT (Mesa RADV 26.3.1). - Offline tests and CI checks run and passing: - `cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked` (all passed, including `xtask` asset policy). - `(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)` (13 `frame`, 22 `umem`, 168 `vkback`, 6 `policy` passed; includes new `slot_flags_dirty_masks_and_twins_preserve_flags` and updated `collect_null_and_stride_writes_fuse_or_skip_empty`). - Clippy with `--locked -- -D warnings`: native root crates, `greenfield`, `greenfield/wine`, and `greenfield/vkback/translate` all clean. - **Checks NOT run in this PR** (live game runs were paused because another agent was actively using the game/GPU on this machine): - Boat scene A B B A performance measurement (`VKB_LAT` + `greenfield/tools/frec/frames.py`). - House scene ~60 s Vulkan validation run (`VK_LAYER_KHRONOS_validation`). - Before/after screenshots (rule 18). - PE-side `cargo xwin clippy` (CI will verify; this change touches only `greenfield/vkback/src/{slotcache,descjob,lib}.rs`). ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the related 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 23:53:40 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 19:45 UTC · original

Thanks. I read it against HostHeap::make_at/null_for. Your invalidation summary matches the code: marks in queue_desc/run_job, clears only in aside_null_slot and on a failed synchronous job, DIRTY_ALL at and past RAW_TWIN. One array instead of two, with no RefCell borrow on the clean path, is the cleaner layout.

Two things are missing before a merge, and both need the card you have (the RX 9070 XT is our reference card too):

  1. Measurement (rule 27 / 24): this is a performance change, so it needs an interleaved A B B A on the boat start with its cutscenes (START=boat, cutscenes not skipped, about 140 world s, VKB_LAT + frames.py), with renderer CPU per frame and fps for each arm. If it shows no gain, the rule-24 questions decide keep or drop on purpose. Fewer allocations and no borrow would most likely count as "keep" then.
  2. Validation run (rule 30): the descriptor writes go through new code, so the house scene, about 60 s, under VK_LAYER_KHRONOS_validation, with the distinct errors listed.

Overlap: the "Descriptor heap as one array" task (#57) will change this mask again, from 9 bits to 3. That is no reason to hold this one; whichever lands second adapts.

**@⁠vktory6** on GitHub · 2026-12-02 19:45 UTC · [original](https://github.com/vktory6/VKtory/pull/172#issuecomment-7356662678) Thanks. I read it against `HostHeap::make_at`/`null_for`. Your invalidation summary matches the code: marks in `queue_desc`/`run_job`, clears only in `aside_null_slot` and on a failed synchronous job, `DIRTY_ALL` at and past `RAW_TWIN`. One array instead of two, with no `RefCell` borrow on the clean path, is the cleaner layout. Two things are missing before a merge, and both need the card you have (the RX 9070 XT is our reference card too): 1. **Measurement (rule 27 / 24):** this is a performance change, so it needs an interleaved A B B A on the boat start with its cutscenes (`START=boat`, cutscenes not skipped, about 140 world s, `VKB_LAT` + `frames.py`), with renderer CPU per frame and fps for each arm. If it shows no gain, the rule-24 questions decide keep or drop on purpose. Fewer allocations and no borrow would most likely count as "keep" then. 2. **Validation run (rule 30):** the descriptor writes go through new code, so the house scene, about 60 s, under `VK_LAYER_KHRONOS_validation`, with the distinct errors listed. Overlap: the "Descriptor heap as one array" task (#57) will change this mask again, from 9 bits to 3. That is no reason to hold this one; whichever lands second adapts.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/172/head:github-bot/gh-172'
git switch 'github-bot/gh-172'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-172'
git switch 'github-bot/gh-172'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-172'
git switch 'github-bot/gh-172'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-172'
git switch 'main'
git merge --squash 'github-bot/gh-172'
git switch 'main'
git merge --ff-only 'github-bot/gh-172'
git switch 'main'
git merge 'github-bot/gh-172'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.