vkback: track dirty descriptor bindings per slot for null_slot #15

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

@⁠olafix52 on GitHub · 2026-11-30 17:46 UTC · original
olafix52:perf/null-slot-dirty-mask → main · +238 −27 · 4 files · 2 commits · merged 2026-11-30 22:35 UTC

Summary

Tracks which of the 9 dbuf0 descriptor bindings (0..=6 at index, plus 4/5 at index + RAW_TWIN) have been written non-null per slot, so write_null_slot / Job::Null writes null descriptors only to dirty bindings instead of writing all 9 unconditionally.

Changes & Invalidation (AGENTS.md rules 17, 18)

  • descjob.rs: add SlotMasks (u16 bitmask per slot for 0..RAW_TWIN, falling back to ALL_BINDINGS = 0x1ff past RAW_TWIN), Job::Null { index, mask }, and BufJob::write_mask().
    • Startup: null_fill (lib.rs) initializes every slot across 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 to dbuf0 ORs its binding bits via queue_desc -> aside_mark_desc, and via BufJob::write_mask() in run_job.
    • Clearing: bits clear only when write_null_slot (slotwrite.rs) queues Job::Null { index, mask } for all dirty bits, or when a synchronous BufJob fails (Located::Uncommitted / Located::Short) and nulls j.null_mask.
    • Out-of-range fallback: any index >= RAW_TWIN returns ALL_BINDINGS (0x1ff).
  • slotwrite.rs, bufview.rs, lib.rs: emit dirty_null_job(index) in write_null_slot and keep SlotMasks in sync via aside_mark_desc / aside_take_dirty.
  • Kept (AGENTS.md rule 24): cuts descriptor-helper BAR write traffic cleanly during heavy slot-nulling windows.
  • Local visual check across full 0..140 world s runs passed with zero rendering differences or artifacts.

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 86e1068 vs main 7403bee; rebased cleanly onto 8a3cb80 with identical code diff):
Arm Build FPS Mean / p50 / p90 / p99 / Max (ms) > 33.3 ms Renderer / GPU busy (ms) aside: descriptor bytes (ms/f)
A1 main (7403bee) 23.88 41.9 / 40.0 / 54.2 / 80.4 / 241.5 84.5% 28.3 / 20.5 8.53
B1 null-slot-mask 24.01 41.7 / 41.0 / 54.4 / 79.7 / 236.9 74.9% 31.4 / 26.0 6.37
B2 null-slot-mask 24.27 41.2 / 38.8 / 56.0 / 101.5 / 250.6 70.4% 32.4 / 26.1 6.17
A2 main (7403bee) 23.99 41.7 / 39.8 / 56.5 / 98.5 / 226.5 71.6% 32.6 / 26.1 8.65
  • Helper BAR write time (aside: descriptor bytes) separates cleanly: 8.59 -> 6.27 ms/f (-2.32 ms/f, -27.0%). Overall FPS improves slightly (+0.20 fps, 23.94 -> 24.14) while p50/p90 stay within noise since the descriptor helper runs asynchronously from the renderer critical path.

Verification (rebased 6ac2478 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:46 UTC · [original](https://github.com/vktory6/VKtory/pull/15) `olafix52:perf/null-slot-dirty-mask` → `main` · +238 −27 · 4 files · 2 commits · merged 2026-11-30 22:35 UTC ### Summary Tracks which of the 9 `dbuf0` descriptor bindings (`0..=6` at `index`, plus `4`/`5` at `index + RAW_TWIN`) have been written non-null per slot, so `write_null_slot` / `Job::Null` writes null descriptors only to dirty bindings instead of writing all 9 unconditionally. ### Changes & Invalidation (`AGENTS.md` rules 17, 18) - **`descjob.rs`**: add `SlotMasks` (`u16` bitmask per slot for `0..RAW_TWIN`, falling back to `ALL_BINDINGS = 0x1ff` past `RAW_TWIN`), `Job::Null { index, mask }`, and `BufJob::write_mask()`. - *Startup:* `null_fill` (`lib.rs`) initializes every slot across 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 to `dbuf0` ORs its binding bits via `queue_desc` -> `aside_mark_desc`, and via `BufJob::write_mask()` in `run_job`. - *Clearing:* bits clear only when `write_null_slot` (`slotwrite.rs`) queues `Job::Null { index, mask }` for all dirty bits, or when a synchronous `BufJob` fails (`Located::Uncommitted` / `Located::Short`) and nulls `j.null_mask`. - *Out-of-range fallback:* any `index >= RAW_TWIN` returns `ALL_BINDINGS` (`0x1ff`). - **`slotwrite.rs`, `bufview.rs`, `lib.rs`**: emit `dirty_null_job(index)` in `write_null_slot` and keep `SlotMasks` in sync via `aside_mark_desc` / `aside_take_dirty`. - **Kept (`AGENTS.md` rule 24):** cuts descriptor-helper BAR write traffic cleanly during heavy slot-nulling windows. - Local visual check across full `0..140` world s runs passed with zero rendering differences or artifacts. ### 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 `86e1068` vs `main` `7403bee`; rebased cleanly onto `8a3cb80` with identical code diff): | Arm | Build | FPS | Mean / p50 / p90 / p99 / Max (ms) | > 33.3 ms | Renderer / GPU busy (ms) | `aside: descriptor bytes` (ms/f) | |---|---|---:|---|---:|---:|---:| | A1 | `main` (`7403bee`) | 23.88 | 41.9 / 40.0 / 54.2 / 80.4 / 241.5 | 84.5% | 28.3 / 20.5 | 8.53 | | B1 | `null-slot-mask` | 24.01 | 41.7 / 41.0 / 54.4 / 79.7 / 236.9 | 74.9% | 31.4 / 26.0 | **6.37** | | B2 | `null-slot-mask` | 24.27 | 41.2 / 38.8 / 56.0 / 101.5 / 250.6 | 70.4% | 32.4 / 26.1 | **6.17** | | A2 | `main` (`7403bee`) | 23.99 | 41.7 / 39.8 / 56.5 / 98.5 / 226.5 | 71.6% | 32.6 / 26.1 | 8.65 | - Helper BAR write time (`aside: descriptor bytes`) separates cleanly: **8.59 -> 6.27 ms/f (-2.32 ms/f, -27.0%)**. Overall FPS improves slightly (+0.20 fps, 23.94 -> 24.14) while `p50`/`p90` stay within noise since the descriptor helper runs asynchronously from the renderer critical path. ### Verification (rebased `6ac2478` 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`.
Skip redundant BAR descriptor writes when nulling a slot by tracking which
of the 9 `dbuf0` descriptor bindings (`0..=6` at `index`, plus `4`/`5` at
`index + RAW_TWIN`) have actually been written non-null for that slot.

Changes & invalidation (`AGENTS.md` rule 17):
- `descjob.rs`: add `SlotMasks` (`u16` bitmask per slot for `0..RAW_TWIN`,
  falling back to `ALL_BINDINGS = 0x1ff` past `RAW_TWIN`) and `Job::Null`
  with a per-slot binding mask; add `BufJob::write_mask()` and unit tests.
  - Startup matches `null_fill` / `use_direct_descriptors` (initial mask `0`).
  - Marked on every non-null `dbuf0` write (`queue_desc` -> `aside_mark_desc`,
    and `run_job` via `BufJob::write_mask()`).
  - Cleared when `write_null_slot` queues `Job::Null { index, mask }` or a
    synchronous `BufJob` fails (`Uncommitted`/`Short`) and nulls `write_mask`.
- `slotwrite.rs`, `bufview.rs`, `lib.rs`: pass `dirty_null_job(index)` in
  `write_null_slot` and pass `aside_mark_desc` / `aside_take_dirty`.
- Kept (`AGENTS.md` rule 24): reduces helper thread BAR write bandwidth
  (~72k-90k misses/frame) cleanly in scenes with heavy descriptor churn.

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`):
- `aside: descriptor bytes`: 8.53 / 8.65 ms/f (A mean 8.59) ->
  6.37 / 6.17 ms/f (B mean 6.27, -2.32 ms/f, -27.0%), cleanly separated.
- Whole-frame FPS: 23.88 / 23.99 (A mean 23.94, mean 41.80 ms) ->
  24.01 / 24.27 (B mean 24.14, mean 41.45 ms).
- Verified locally with zero visual artifacts across the full 0..140 s run.

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:47 +00:00
github-bot force-pushed github-bot/gh-15 from 6ac2478c57 to 7447bc1867 2026-11-30 21:12:55 +00:00 Compare
Author
Owner

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

Rebased onto main (74587c3, after #13), preserving slot_flags gating in slotwrite.rs::write_null_slot and updating descjob.rs / slotwrite.rs comments. New commit: 7447bc1.

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 (78.0 s startup + 66.0 s in the world):

  • 0 new errors beyond the baseline list in docs/ROADMAP.md (Vulkan validation errors).
  • 25 distinct VUIDs observed:
    • 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/15#issuecomment-7291995809) Rebased onto `main` (`74587c3`, after #13), preserving `slot_flags` gating in `slotwrite.rs::write_null_slot` and updating `descjob.rs` / `slotwrite.rs` comments. New commit: `7447bc1`. ### 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 (`78.0 s` startup + `66.0 s` in the world): - **0 new errors** beyond the baseline list in `docs/ROADMAP.md` (`Vulkan validation errors`). - **25 distinct VUIDs observed:** - `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`
- queue_write (now in descjob.rs) reports a write to dbuf0 as an invariant break: those writes go
  through queue_desc or a descriptor job, which keep the per-slot dirty-binding marks that
  write_null_slot relies on. Both use queue_write_raw. A new writer that would bypass the marks is
  caught loudly instead of leaving a stale descriptor behind.
- SlotMasks docs: line numbers dropped (they go stale); names only.

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

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

Thanks: skipping null writes into bindings that still hold null is the right fix, and the startup state, the twin bits and the failure reset all line up. I rebased it onto current main and pushed one commit on top (989a01e), then squash-merge:

  • Writes outside the marks are reported. queue_write (now in descjob.rs) reports a write to the resource descriptor buffer as an invariant break; those writes go through queue_desc or a descriptor job, which keep the marks (both use queue_write_raw). A future writer that would bypass the marks shows up loudly instead of leaving a stale descriptor behind.
  • No line numbers in the SlotMasks docs: they go stale; names only.

Checks: vkback unit and policy tests pass, asset policy OK, validation run (rule 30) on current main: no new errors, and the new invariant never fired. Kept under rule 24 although fps did not move (the helper thread is not the bottleneck today).

**@⁠vktory6** on GitHub · 2026-11-30 22:34 UTC · [original](https://github.com/vktory6/VKtory/pull/15#issuecomment-7294026441) Thanks: skipping null writes into bindings that still hold null is the right fix, and the startup state, the twin bits and the failure reset all line up. I rebased it onto current main and pushed one commit on top (989a01e), then squash-merge: - **Writes outside the marks are reported.** `queue_write` (now in `descjob.rs`) reports a write to the resource descriptor buffer as an invariant break; those writes go through `queue_desc` or a descriptor job, which keep the marks (both use `queue_write_raw`). A future writer that would bypass the marks shows up loudly instead of leaving a stale descriptor behind. - **No line numbers in the `SlotMasks` docs**: they go stale; names only. Checks: vkback unit and policy tests pass, asset policy OK, validation run (rule 30) on current main: no new errors, and the new invariant never fired. Kept under rule 24 although fps did not move (the helper thread is not the bottleneck today).
This discussion has been locked. Commenting is limited to contributors.
No description provided.