vkback/watch: break texture refill loop and defer unnamed refills #277

Open
opened 2026-12-02 20:39:15 +00:00 by github-bot · 0 comments
Owner

@⁠olafix52 on GitHub · 2026-12-02 20:34 UTC · original

Addresses docs/TASKS.md item: Texture refill loop.

What

Break the ~1,500 texture refills/frame self-feeding loop at its three measured causes while staying 100% faithful to console semantics (zero artificial caps on named textures, zero new toggles):

  1. Stop live_cover from self-looping on g.rests() (watch.rs, watch/live.rs):
    • Diagnostic profiling (boat-sarc1) showed 100% of uncovered feedback (13.5k-18.2k blocks/s re-injected into live_written() on live_take_written) came from protect_alias() honouring the 3 ms rests() window (fly=0, left=0, fail=0, bad_old=0). Because live_protect() re-arms the primary block immediately on live_take_written, parameterised protect_alias(..., honor_rest: bool) with false from live_cover (true kept for D3D12 cover()). Added unit test live_protect_alias_ignores_rest_when_asked.
  2. Only run live_take_written on Execute / Present / explicit flush() (vklive.rs):
    • Diagnostic counters showed Signal and CopyPageMappingsRanges accounted for over half of all live_take_written triggers (exec=418, sig=418, map=36, pres=19, flush=19 per sec). Split flush_now (all queue ops still flush immediately) from take_written (Execute and Present).
  3. Defer dirty refills of unnamed textures until named or read (texwatch.rs, refresh.rs, slotwrite.rs, lib.rs):
    • ~73% of refills (~75k-87k per 60 frames in boat-sarc1) belonged to textures with no active descriptor slot (!self.naming.contains_key(&id)). Dirty unnamed textures (already filled once) now move to TexWatch::deferred and skip dirty in written/tick until named in slotwrite::slot_set or needed by a GPU copy/resolve (ensure_fresh via used_now on copy_resource/copy_texture_region/resolve, and on copy_texture_region Subresource dst before gpu_wrote). Added unit tests in texwatch.rs.
  4. Recorded the Phase 2A/2B measurements in docs/learnings/cpu-perf-1.md.

The reference

  • D3D12 / console semantics: only textures bound to an active descriptor slot or read as a copy/resolve source are sampled by the GPU; ensure_fresh guarantees any texture copied or bound later is refreshed before GPU use.
  • D3D12 watch::cover() preserves its 3 ms rests() behaviour via protect_alias(..., honor_rest = true).

Evidence

Tested on RX 9070 XT (Mesa 26.3.1), base 4a9dbe5:

  • Automated checks (after final edits):

    • cargo test -p vkback --lib: 173 passed; 0 failed; 6 ignored
    • cargo test -p vkback --test policy: 6 passed; 0 failed
    • cargo clippy -p vkback --all-targets -- -D warnings: pass (0 warnings)
    • cargo xtask policy: asset policy: 535 files ok
    • ./tools/build.sh (pe, so, vk-store, translate): builds cleanly (note: the Windows-only watch/live.rs test compiles in the PE build step; not run separately under Wine).
  • Interleaved A/B/B/A (boat-sarc1, 0..140 s world window):

Metric A1 (current) A2 (current) B1 (refill-loop) B2 (refill-loop) Change (A mean → B mean)
presents / refreshed 4299 / 5,145,017 (54,109 MB) 4780 / 5,413,000 (72,435 MB) 4113 / 841,128 (28,305 MB) 4601 / 887,409 (27,820 MB) -83.6% refills, -55.6% MB
gpu: texture fills (GPU time / ops) 10,324 ms (5.29M) 11,370 ms (5.58M) 3,974 ms (994k) 4,397 ms (1.06M) -61.4% GPU time, -81.1% ops
tex: refresh dirty (CPU time) 14,904 ms 18,002 ms 6,412 ms 6,331 ms -61.3% (-10.1 s)
live: ev title memory written (CPU time) 2,979 ms 3,075 ms 1,922 ms 2,185 ms -32.1%
blocks guarded again (last 5 s avg) 24,991 /s 18,460 /s 6,180 /s 4,747 /s -74.9%
Overall FPS / mean (GPU busy) 18.16 / 55.1 ms (33.2 ms) 20.64 / 48.5 ms (31.5 ms) 17.35 / 57.6 ms (32.4 ms) 19.98 / 50.0 ms (30.4 ms) within scene/run variance (render:slots/descriptors dominates)
  • boat-sarc0 (2 comparison pairs, 110 s launches):
    • refreshed: 1,232,059 (68,547 MB) / 1,268,775 (15,051 MB) → 305,865 (6,739 MB) / 317,370 (4,886 MB) (-75% refills)
    • Last window tex: refresh dirty: 146 / 157 ms → 69 / 47 ms; FPS 14.5 / 20.6 → 19.6 / 20.1
  • Screenshot check (boat-sarc0, 2560x1440, +12 s world, rule 18): visual check shows identical, complete rendering with zero missing/stale textures; 0 UNKNOWN loud errors (63 and 76 known hits).
  • Vulkan validation run (boat-sarc0, ~125 s world, 1520 shown, rule 30): 0 new VUIDs; only the 4 listed VUIDs in docs/TASKS.md appeared:
    • VUID-VkBufferCreateInfo-size-06409
    • VUID-VkComputePipelineCreateInfo-layout-01687
    • VUID-VkGraphicsPipelineCreateInfo-layout-01688
    • VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428
    • loud.txt: 3 kind(s), 58 hit(s), 0 without an owner.

Checklist (docs/AGENTS.md)

  • Builds cleanly and clippy -p vkback --all-targets -- -D warnings passes with zero warnings
  • cargo test -p vkback --lib and cargo test -p vkback --test policy pass
  • cargo xtask policy passes
  • Zero new toggles (toggles.txt untouched) and oversize budgets respected (watch.rs / lib.rs)
  • docs/TASKS.md untouched (rule 29); docs/learnings/cpu-perf-1.md updated (rule 28)
  • Vulkan validation run completed with no new VUIDs (rule 30) and screenshot check verified (rule 18)

Pull request details or commits were not available from GitHub; kept as an issue.

**@⁠olafix52** on GitHub · 2026-12-02 20:34 UTC · [original](https://github.com/vktory6/VKtory/pull/277) Addresses `docs/TASKS.md` item: `Texture refill loop`. ## What Break the ~1,500 texture refills/frame self-feeding loop at its three measured causes while staying 100% faithful to console semantics (zero artificial caps on named textures, zero new toggles): 1. **Stop `live_cover` from self-looping on `g.rests()` (`watch.rs`, `watch/live.rs`):** - Diagnostic profiling (`boat-sarc1`) showed 100% of `uncovered` feedback (`13.5k-18.2k` blocks/s re-injected into `live_written()` on `live_take_written`) came from `protect_alias()` honouring the 3 ms `rests()` window (`fly=0, left=0, fail=0, bad_old=0`). Because `live_protect()` re-arms the primary block immediately on `live_take_written`, parameterised `protect_alias(..., honor_rest: bool)` with `false` from `live_cover` (`true` kept for D3D12 `cover()`). Added unit test `live_protect_alias_ignores_rest_when_asked`. 2. **Only run `live_take_written` on `Execute` / `Present` / explicit `flush()` (`vklive.rs`):** - Diagnostic counters showed `Signal` and `CopyPageMappingsRanges` accounted for over half of all `live_take_written` triggers (`exec=418, sig=418, map=36, pres=19, flush=19` per sec). Split `flush_now` (all queue ops still flush immediately) from `take_written` (`Execute` and `Present`). 3. **Defer dirty refills of `unnamed` textures until named or read (`texwatch.rs`, `refresh.rs`, `slotwrite.rs`, `lib.rs`):** - ~73% of refills (~75k-87k per 60 frames in `boat-sarc1`) belonged to textures with no active descriptor slot (`!self.naming.contains_key(&id)`). Dirty `unnamed` textures (already filled once) now move to `TexWatch::deferred` and skip `dirty` in `written`/`tick` until named in `slotwrite::slot_set` or needed by a GPU copy/resolve (`ensure_fresh` via `used_now` on `copy_resource`/`copy_texture_region`/`resolve`, and on `copy_texture_region` `Subresource` dst before `gpu_wrote`). Added unit tests in `texwatch.rs`. 4. Recorded the Phase 2A/2B measurements in `docs/learnings/cpu-perf-1.md`. ## The reference - D3D12 / console semantics: only textures bound to an active descriptor slot or read as a copy/resolve source are sampled by the GPU; `ensure_fresh` guarantees any texture copied or bound later is refreshed before GPU use. - D3D12 `watch::cover()` preserves its 3 ms `rests()` behaviour via `protect_alias(..., honor_rest = true)`. ## Evidence Tested on `RX 9070 XT` (`Mesa 26.3.1`), base `4a9dbe5`: - **Automated checks (after final edits):** - `cargo test -p vkback --lib`: `173 passed; 0 failed; 6 ignored` - `cargo test -p vkback --test policy`: `6 passed; 0 failed` - `cargo clippy -p vkback --all-targets -- -D warnings`: pass (0 warnings) - `cargo xtask policy`: `asset policy: 535 files ok` - `./tools/build.sh` (`pe`, `so`, `vk-store`, `translate`): builds cleanly (note: the Windows-only `watch/live.rs` test compiles in the PE build step; not run separately under Wine). - **Interleaved A/B/B/A (`boat-sarc1`, 0..140 s world window):** | Metric | A1 (`current`) | A2 (`current`) | B1 (`refill-loop`) | B2 (`refill-loop`) | Change (A mean → B mean) | | --- | --- | --- | --- | --- | --- | | `presents` / `refreshed` | 4299 / 5,145,017 (`54,109 MB`) | 4780 / 5,413,000 (`72,435 MB`) | 4113 / 841,128 (`28,305 MB`) | 4601 / 887,409 (`27,820 MB`) | **-83.6% refills, -55.6% MB** | | `gpu: texture fills` (GPU time / ops) | 10,324 ms (`5.29M`) | 11,370 ms (`5.58M`) | 3,974 ms (`994k`) | 4,397 ms (`1.06M`) | **-61.4% GPU time, -81.1% ops** | | `tex: refresh dirty` (CPU time) | 14,904 ms | 18,002 ms | 6,412 ms | 6,331 ms | **-61.3%** (`-10.1 s`) | | `live: ev title memory written` (CPU time) | 2,979 ms | 3,075 ms | 1,922 ms | 2,185 ms | **-32.1%** | | `blocks guarded again` (last 5 s avg) | 24,991 /s | 18,460 /s | 6,180 /s | 4,747 /s | **-74.9%** | | Overall FPS / mean (`GPU busy`) | 18.16 / 55.1 ms (`33.2 ms`) | 20.64 / 48.5 ms (`31.5 ms`) | 17.35 / 57.6 ms (`32.4 ms`) | 19.98 / 50.0 ms (`30.4 ms`) | within scene/run variance (`render:slots/descriptors` dominates) | - **`boat-sarc0` (2 comparison pairs, 110 s launches):** - `refreshed`: `1,232,059 (68,547 MB)` / `1,268,775 (15,051 MB)` → `305,865 (6,739 MB)` / `317,370 (4,886 MB)` (**-75% refills**) - Last window `tex: refresh dirty`: `146 / 157 ms` → `69 / 47 ms`; FPS `14.5 / 20.6` → `19.6 / 20.1` - **Screenshot check (`boat-sarc0`, `2560x1440`, +12 s world, rule 18):** visual check shows identical, complete rendering with zero missing/stale textures; `0 UNKNOWN` loud errors (`63` and `76` known hits). - **Vulkan validation run (`boat-sarc0`, ~125 s world, `1520` shown, rule 30):** `0` new VUIDs; only the 4 listed VUIDs in `docs/TASKS.md` appeared: - `VUID-VkBufferCreateInfo-size-06409` - `VUID-VkComputePipelineCreateInfo-layout-01687` - `VUID-VkGraphicsPipelineCreateInfo-layout-01688` - `VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428` - `loud.txt`: `3 kind(s), 58 hit(s), 0 without an owner`. ## Checklist (docs/AGENTS.md) - [x] Builds cleanly and `clippy -p vkback --all-targets -- -D warnings` passes with zero warnings - [x] `cargo test -p vkback --lib` and `cargo test -p vkback --test policy` pass - [x] `cargo xtask policy` passes - [x] Zero new toggles (`toggles.txt` untouched) and oversize budgets respected (`watch.rs` / `lib.rs`) - [x] `docs/TASKS.md` untouched (rule 29); `docs/learnings/cpu-perf-1.md` updated (rule 28) - [x] Vulkan validation run completed with no new VUIDs (rule 30) and screenshot check verified (rule 18) *Pull request details or commits were not available from GitHub; kept as an issue.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 20:39:15 +00:00
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/vktory6--VKtory#277
No description provided.