vkback: cache image-view and sampler descriptor blobs #269

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

@⁠olafix52 on GitHub · 2026-12-02 19:25 UTC · original
olafix52:perf/cache-desc-blobs → main · +163 −35 · 5 files · 1 commits · open

Cache the output of vkGetDescriptorEXT so slot writes and twin views reuse already-resolved descriptor bytes via copy_from_slice instead of calling into the driver on every write:

  • Image views: store [Option; 2] (0 = SAMPLED_IMAGE, 1 = STORAGE_IMAGE) in imgview::CachedView inside self.views; unify blob generation in imgview::img_blob_with and use view_for(..., binding) in both slotwrite and twin_view.
  • Samplers: change self.sampler_cache from HashMap<[u32; 13], vk::Sampler> to HashMap<[u32; 13], Blob>, bypassing viewdesc::sampler decoding on cache hits (Drop still drains self.samplers for vk::Sampler lifetimes).
  • Keep lib.rs under its oversize debt budget (-4 lines) with zero toggles.

Reference (rule 12): victory-gpu HostHeap::make_at (crates/victory-gpu/src/descriptor/host.rs) writes a D3D12 descriptor per slot; there is no D3D12 counterpart for caching Vulkan descriptor byte blobs, while self.views and self.sampler_cache already cached the underlying Vulkan handles.

Evidence (RX 9070 XT, Mesa 26.3.1, base 88d66ae):

  • Interleaved A/B/B/A on boat-sarc1 (0..140 s world): slot_reads at Execute 10.77/11.45 -> 10.55/10.53 ms/f (-5.1%), slot_reads in lists 4.16/4.69 -> 4.33/4.15 ms/f (-4.2%), frame rate 19.27/20.52 -> 21.09/21.57 fps (GPU load also varied across runs: GPU busy 33.6/32.4 vs 32.7/30.7).
  • Single baseline vs branch on boat-sarc0 (matched phase idx/wv): lighter ~97.5 -> ~93.0 ns/wv (-4.6%), heavier ~85.6 -> ~83.3 ns/wv (-2.7%).
  • Screenshot check (boat-sarc0, 2560x1440): Mean byte A=114.49 B=113.92, PSNR=24.15 dB, MAE=5.06/255, 0 UNKNOWN loud errors.
  • VVL (boat-sarc0, ~125 s world, 1748 presents): 0 new errors (only the 4 listed VUIDs in docs/TASKS.md: VUID-VkBufferCreateInfo-size-06409, VUID-VkComputePipelineCreateInfo-layout-01687, VUID-VkGraphicsPipelineCreateInfo-layout-01688, VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428).

What

The reference

Evidence

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-02 19:25 UTC · [original](https://github.com/vktory6/VKtory/pull/269) `olafix52:perf/cache-desc-blobs` → `main` · +163 −35 · 5 files · 1 commits · open Cache the output of vkGetDescriptorEXT so slot writes and twin views reuse already-resolved descriptor bytes via copy_from_slice instead of calling into the driver on every write: - Image views: store [Option<Blob>; 2] (0 = SAMPLED_IMAGE, 1 = STORAGE_IMAGE) in imgview::CachedView inside self.views; unify blob generation in imgview::img_blob_with and use view_for(..., binding) in both slotwrite and twin_view. - Samplers: change self.sampler_cache from HashMap<[u32; 13], vk::Sampler> to HashMap<[u32; 13], Blob>, bypassing viewdesc::sampler decoding on cache hits (Drop still drains self.samplers for vk::Sampler lifetimes). - Keep lib.rs under its oversize debt budget (-4 lines) with zero toggles. Reference (rule 12): victory-gpu HostHeap::make_at (crates/victory-gpu/src/descriptor/host.rs) writes a D3D12 descriptor per slot; there is no D3D12 counterpart for caching Vulkan descriptor byte blobs, while self.views and self.sampler_cache already cached the underlying Vulkan handles. Evidence (RX 9070 XT, Mesa 26.3.1, base 88d66ae): - Interleaved A/B/B/A on boat-sarc1 (0..140 s world): slot_reads at Execute 10.77/11.45 -> 10.55/10.53 ms/f (-5.1%), slot_reads in lists 4.16/4.69 -> 4.33/4.15 ms/f (-4.2%), frame rate 19.27/20.52 -> 21.09/21.57 fps (GPU load also varied across runs: GPU busy 33.6/32.4 vs 32.7/30.7). - Single baseline vs branch on boat-sarc0 (matched phase idx/wv): lighter ~97.5 -> ~93.0 ns/wv (-4.6%), heavier ~85.6 -> ~83.3 ns/wv (-2.7%). - Screenshot check (boat-sarc0, 2560x1440): Mean byte A=114.49 B=113.92, PSNR=24.15 dB, MAE=5.06/255, 0 UNKNOWN loud errors. - VVL (boat-sarc0, ~125 s world, 1748 presents): 0 new errors (only the 4 listed VUIDs in docs/TASKS.md: VUID-VkBufferCreateInfo-size-06409, VUID-VkComputePipelineCreateInfo-layout-01687, VUID-VkGraphicsPipelineCreateInfo-layout-01688, VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428). ## What <!-- One topic. What the change does, and the console behaviour it reproduces (rule 9 / PHILOSOPHY.md). --> ## The reference <!-- The vkd3d-proton / D3D12-path counterpart you read (function, file:line) and the guards you carry over or leave out, or "no counterpart" (rule 12). --> ## Evidence <!-- What proves it and why that is enough (rule 27): tests, validation run with its distinct errors (rule 30), measurements (A B B A, frames.py), screenshots for visible changes. The machine you ran it on. --> ## 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)
Cache the output of vkGetDescriptorEXT so slot writes and twin views reuse
already-resolved descriptor bytes via copy_from_slice instead of calling into
the driver on every write:

- Image views: store [Option<Blob>; 2] (0 = SAMPLED_IMAGE, 1 = STORAGE_IMAGE)
  in imgview::CachedView inside self.views; unify blob generation in
  imgview::img_blob_with and use view_for(..., binding) in both slotwrite and
  twin_view.
- Samplers: change self.sampler_cache from HashMap<[u32; 13], vk::Sampler> to
  HashMap<[u32; 13], Blob>, bypassing viewdesc::sampler decoding on cache hits
  (Drop still drains self.samplers for vk::Sampler lifetimes).
- Keep lib.rs under its oversize debt budget (-4 lines) with zero toggles.

Reference (rule 12): victory-gpu HostHeap::make_at
(crates/victory-gpu/src/descriptor/host.rs) writes a D3D12 descriptor per slot;
there is no D3D12 counterpart for caching Vulkan descriptor byte blobs, while
self.views and self.sampler_cache already cached the underlying Vulkan handles.

Evidence (RX 9070 XT, Mesa 26.3.1, base 88d66ae):
- Interleaved A/B/B/A on boat-sarc1 (0..140 s world): slot_reads at Execute
  10.77/11.45 -> 10.55/10.53 ms/f (-5.1%), slot_reads in lists 4.16/4.69 ->
  4.33/4.15 ms/f (-4.2%), frame rate 19.27/20.52 -> 21.09/21.57 fps (GPU load
  also varied across runs: GPU busy 33.6/32.4 vs 32.7/30.7).
- Single baseline vs branch on boat-sarc0 (matched phase idx/wv): lighter
  ~97.5 -> ~93.0 ns/wv (-4.6%), heavier ~85.6 -> ~83.3 ns/wv (-2.7%).
- Screenshot check (boat-sarc0, 2560x1440): Mean byte A=114.49 B=113.92,
  PSNR=24.15 dB, MAE=5.06/255, 0 UNKNOWN loud errors.
- VVL (boat-sarc0, ~125 s world, 1748 presents): 0 new errors (only the 4
  listed VUIDs in docs/TASKS.md: VUID-VkBufferCreateInfo-size-06409,
  VUID-VkComputePipelineCreateInfo-layout-01687,
  VUID-VkGraphicsPipelineCreateInfo-layout-01688,
  VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 19:38:56 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 20:11 UTC · original

Thanks. Caching the vkGetDescriptorEXT bytes next to the view, and invalidating them with it in take_views, is sound. A blob depends only on (binding, view), with the layout fixed at GENERAL. Your interleaved A B B A on the RX 9070 XT (our reference card too) is the evidence we need for the speed side. I checked it against #267, which works on the same slot path: no duplication, as #267 removes a probe and swaps two hashers, and the two touch different lines.

One rebase is needed: #167 merged today. It made samplers one per description for the device's life (Dev::samplers, layout::sampler) and removed heap_samplers. Your sampler_cache comment and its lifetime argument point at heap_samplers. After the rebase, the blob cache keys on the description as before, but the sampler handles now live in Dev::samplers until destroy_samplers at the backend's drop. Please restate the lifetime argument against that.

After the rebase we run our check (build, tests, validation run) and merge.

**@⁠vktory6** on GitHub · 2026-12-02 20:11 UTC · [original](https://github.com/vktory6/VKtory/pull/269#issuecomment-7357346928) Thanks. Caching the `vkGetDescriptorEXT` bytes next to the view, and invalidating them with it in `take_views`, is sound. A blob depends only on (binding, view), with the layout fixed at GENERAL. Your interleaved A B B A on the RX 9070 XT (our reference card too) is the evidence we need for the speed side. I checked it against https://git.gtahub.st/github/vktory6--VKtory/pulls/267, which works on the same slot path: no duplication, as #267 removes a probe and swaps two hashers, and the two touch different lines. One rebase is needed: https://git.gtahub.st/github/vktory6--VKtory/pulls/167 merged today. It made samplers one per description for the device's life (`Dev::samplers`, `layout::sampler`) and removed `heap_samplers`. Your `sampler_cache` comment and its lifetime argument point at `heap_samplers`. After the rebase, the blob cache keys on the description as before, but the sampler handles now live in `Dev::samplers` until `destroy_samplers` at the backend's drop. Please restate the lifetime argument against that. After the rebase we run our check (build, tests, validation run) and merge.
This pull request has changes conflicting with the target branch.
  • greenfield/vkback/src/slotwrite.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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