WIP: feat(vk): count what the submit captures' copies are used for (RX_VK_CAPTURE_USE=1), and a RX_VK_CAPTURE_SKIP experiment #2051

Draft
siantm wants to merge 1 commit from siantm/Longshot:perf/vk-capture-use into main
Contributor

Summary

A submit's capture copies the pages written since the last one (capture_make), for whatever reads them before
they are captured again: a mirror's sync or a new mirror copying them in, the replay's own reads of guest memory as
submitted, the texture shadow. Nothing said how many of those copies any reader takes, which is what any attempt to copy
less has to know first.

RX_VK_CAPTURE_USE=1 (new, a diagnostic, bool, off) counts it: every 600 submits the copied pages by their pool's kind
(a mirrored pool, the texture storage, a small pool with no mirror, other) and how many the capture before (or one of
the five before it) copied too; every 600 takes, which reader read each copy first, and the copies replaced or let go
unread (cap_slot_read, cap_slot_unread, cap_buf_retire). Off, no copy changes and nothing is counted.

RX_VK_CAPTURE_SKIP=n (new, an attempt, int, off) is an experiment and is NOT the same GPU-visible memory: a page whose
last n copies nothing read is left out of the next captures (never a late page or the texture storage's, and every
32nd capture of a page copies it again); a reader that then wants it takes guest memory as it is, counted in the log
(cap_skip_check). It turns the counts on too. Both have their rows in gpu/vk/switches.def; unset, the code is main's.

Adapted to main: the replay's reads as submitted are counted in submitted_read_locked; main's memory_as_submitted
reads the texture shadow, not the captures, so it has no hook.

From a38a894b on exp/x86-asm-sync.

Read first: the block above cap_buf_retire (cap_slot_read, cap_slot_unread, cap_skip_check,
capture_leaves_out), capture_make and take_capture in gpu/vk/vk_memory.cpp, then tests/test_capture_use.py.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 3a28d0b5 on main 75317e1f. Build jobs of this PC's job queue, the checks in a hidden console: tests/run_all.py --strict --exact on tests/test_capture_use.py and every check --changed picks for the files this changes (batch CapCut3-b2, log t-CapCut3-vk-capture-use.log): 96 checks, 82 passed, 14 failed, 0 skipped; its own check passes, the switch's read included (fresh processes); the failing ones fail on their base too, run from a base worktree (t-CapCut3-base-main.log (batch CapCut3-b1)): tests/test_capture_read_once.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_crash_dialog.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_dev_ab.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_frame_overlap.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_guest_imported.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_linux_pressure.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_pending_guest_import.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_present_queue_default.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_replay_write_order.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_sparse_mirror.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_target_reuse_memory.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_texel_buffer_ownership.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log), tests/test_vk_occlusion_queries.py (fails on main @ 75317e1f too, log t-CapCut3-base-main.log); tests/test_direct_buffer_writes.py timed out at 60 s (it passes on main) in that run and passed when run again alone: batch CapCut4-b1, log t-CapCut4-vk-capture-use-r3.log.

It has NOT run in the game on this PC yet.

Still to test:

  • Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest, play three minutes turning the camera and walking into Link's house and out, with RX_VK_CAPTURE_USE=1 against unset, and once with RX_VK_CAPTURE_SKIP=4, expecting the capture copies and capture use lines every 600 submits and takes with it on, no FATAL, the same picture and frame times within the runs' spread with RX_VK_CAPTURE_USE=1; with RX_VK_CAPTURE_SKIP=4 the pages left out in the log and any difference in the picture noted (by hand)
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest, play three minutes, RX_VK_CAPTURE_USE=1 against unset, expecting no FATAL, the same picture and the two log lines (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest three minutes, RX_VK_CAPTURE_USE=1 against unset, the log, frame times and a screenshot)
  • Linux: build the renderer and run python3 -I -B tests/test_capture_use.py, expecting PASS (by hand)

Measurements

Nothing to measure in play yet: a diagnostic off by default and an experiment off by default; no micro-benchmark of this port and no run in the game on this PC yet.

Risks

What could break: with RX_VK_CAPTURE_USE=1, a little CPU time a submit for the counts; nothing else changes. With
RX_VK_CAPTURE_SKIP=n, by design, a reader of a page left out gets guest memory as it is then, not as it was at its
submit: a flicker, a stale or a wrong value is possible, which is what the experiment is for; it is never on unless
set. The test drives the counts, the tables, the choice of pages and copy_part through 4,000 random captures against a
model. Turn it off: leave both unset. Renderer code: the runtime is rebuilt; nothing changes for players' saves, options
or caches.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary A submit's capture copies the pages written since the last one (`capture_make`), for whatever reads them before they are captured again: a mirror's sync or a new mirror copying them in, the replay's own reads of guest memory as submitted, the texture shadow. Nothing said how many of those copies any reader takes, which is what any attempt to copy less has to know first. `RX_VK_CAPTURE_USE=1` (new, a diagnostic, bool, off) counts it: every 600 submits the copied pages by their pool's kind (a mirrored pool, the texture storage, a small pool with no mirror, other) and how many the capture before (or one of the five before it) copied too; every 600 takes, which reader read each copy first, and the copies replaced or let go unread (`cap_slot_read`, `cap_slot_unread`, `cap_buf_retire`). Off, no copy changes and nothing is counted. `RX_VK_CAPTURE_SKIP=n` (new, an attempt, int, off) is an experiment and is NOT the same GPU-visible memory: a page whose last n copies nothing read is left out of the next captures (never a late page or the texture storage's, and every 32nd capture of a page copies it again); a reader that then wants it takes guest memory as it is, counted in the log (`cap_skip_check`). It turns the counts on too. Both have their rows in `gpu/vk/switches.def`; unset, the code is main's. Adapted to main: the replay's reads as submitted are counted in `submitted_read_locked`; main's `memory_as_submitted` reads the texture shadow, not the captures, so it has no hook. From a38a894b on `exp/x86-asm-sync`. Read first: the block above `cap_buf_retire` (`cap_slot_read`, `cap_slot_unread`, `cap_skip_check`, `capture_leaves_out`), `capture_make` and `take_capture` in `gpu/vk/vk_memory.cpp`, then `tests/test_capture_use.py`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head `3a28d0b5` on main `75317e1f`. Build jobs of this PC's job queue, the checks in a hidden console: `tests/run_all.py --strict --exact` on `tests/test_capture_use.py` and every check `--changed` picks for the files this changes (batch `CapCut3-b2`, log `t-CapCut3-vk-capture-use.log`): 96 checks, 82 passed, 14 failed, 0 skipped; its own check passes, the switch's read included (fresh processes); the failing ones fail on their base too, run from a base worktree (`t-CapCut3-base-main.log` (batch `CapCut3-b1`)): `tests/test_capture_read_once.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_crash_dialog.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_dev_ab.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_frame_overlap.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_guest_imported.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_linux_pressure.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_pending_guest_import.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_present_queue_default.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_replay_write_order.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_sparse_mirror.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_target_reuse_memory.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_texel_buffer_ownership.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`), `tests/test_vk_occlusion_queries.py` (fails on main @ 75317e1f too, log `t-CapCut3-base-main.log`); `tests/test_direct_buffer_writes.py` timed out at 60 s (it passes on main) in that run and passed when run again alone: batch `CapCut4-b1`, log `t-CapCut4-vk-capture-use-r3.log`. **It has NOT run in the game on this PC yet.** **Still to test:** - Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest, play three minutes turning the camera and walking into Link's house and out, with `RX_VK_CAPTURE_USE=1` against unset, and once with `RX_VK_CAPTURE_SKIP=4`, expecting the `capture copies` and `capture use` lines every 600 submits and takes with it on, no FATAL, the same picture and frame times within the runs' spread with `RX_VK_CAPTURE_USE=1`; with `RX_VK_CAPTURE_SKIP=4` the pages left out in the log and any difference in the picture noted (by hand) - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest, play three minutes, `RX_VK_CAPTURE_USE=1` against unset, expecting no FATAL, the same picture and the two log lines (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest three minutes, RX_VK_CAPTURE_USE=1 against unset, the log, frame times and a screenshot) - Linux: build the renderer and run `python3 -I -B tests/test_capture_use.py`, expecting PASS (by hand) ## Measurements Nothing to measure in play yet: a diagnostic off by default and an experiment off by default; no micro-benchmark of this port and no run in the game on this PC yet. ## Risks What could break: with `RX_VK_CAPTURE_USE=1`, a little CPU time a submit for the counts; nothing else changes. With `RX_VK_CAPTURE_SKIP=n`, by design, a reader of a page left out gets guest memory as it is then, not as it was at its submit: a flicker, a stale or a wrong value is possible, which is what the experiment is for; it is never on unless set. The test drives the counts, the tables, the choice of pages and `copy_part` through 4,000 random captures against a model. Turn it off: leave both unset. Renderer code: the runtime is rebuilt; nothing changes for players' saves, options or caches. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
feat(vk): count what the submit captures' copies are used for (RX_VK_CAPTURE_USE=1); RX_VK_CAPTURE_SKIP=<n> experiment
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's πŸ‘ on the request
3a28d0b55d
- A submit's capture copies the pages written since the last one (capture_make), for whatever reads them before they are
  captured again: a mirror's sync or a new mirror copying them in, the replay's own reads of guest memory as submitted,
  the texture shadow. Nothing said how many of the copies any of those read.
- RX_VK_CAPTURE_USE=1 (diag, off): every 600 submits the copied pages by their pool's kind (a mirrored pool, the texture
  storage, a small pool with no mirror, other) and how many the capture before (or one of the five before it) copied
  too; every 600 takes, which reader read each copy first, and the copies replaced or let go unread (cap_slot_read,
  cap_slot_unread, cap_buf_retire). Off: no copy changes and nothing is counted.
- RX_VK_CAPTURE_SKIP=<n> (attempt, off; NOT the same GPU-visible memory): a page whose last n copies nothing read is left
  out of the next captures (never a late page or the texture storage's, and every 32nd capture of a page copies it
  again); a reader that then wants it takes guest memory as it is, counted in the log (cap_skip_check).
- Adapted to main: the replay's reads as submitted are counted in submitted_read_locked (main's split of
  memory_read_as_submitted); main's memory_as_submitted reads the texture shadow, not the captures, so it has no hook.
- From a38a894b on exp/x86-asm-sync. Not measured on main.
- Test: tests/test_capture_use.py cuts the counts, the per-page tables, capture_leaves_out, cap_buf_retire and copy_part
  and drives them through 4,000 random captures against a model (every copy counted once, its first reader or its end
  unread, the unread runs, the pages RX_VK_CAPTURE_SKIP leaves out, copy_part passing over them), and reads the
  capture, the take and the readers for their hooks.

Switch reads: the test also runs RX_VK_CAPTURE_USE and RX_VK_CAPTURE_SKIP as the source reads it, in fresh processes (unset, 0, 1, 2, off, each twice, the variable flipped after the first read: read once). RX_VK_CAPTURE_SKIP is read with strtoll and clamped to 0-255 (not a number: 0); the per-page tables are allocated with nothrow, one that fails counting nothing.

Assisted-by: Claude Code
Member

Possibly related, for context:

  • issue #1607 A texture re-upload reads a capture that may have been taken while the game was still writing the texture, and nothing tells it from a finished one β€” Related capture-reader behavior for texture uploads; this PR adds usage diagnostics but doesn't implement its proposed upload handling
  • PR #952 perf(vk): a recording's uniform copies shared, their reads made once a draw: Castle Town's market from 54.9 to 59.5 fps on a B580 with the uniform snapshot β€” Merged batched submitted-memory reads; this PR instruments the replay reads that path uses
  • PR #248 perf(vk): fix the late pages on the GPU, word by word, instead of waiting for their write-back β€” Merged late-page capture handling; captures and capture-time page selection are part of this code path
Possibly related, for context: - issue #1607 A texture re-upload reads a capture that may have been taken while the game was still writing the texture, and nothing tells it from a finished one β€” Related capture-reader behavior for texture uploads; this PR adds usage diagnostics but doesn't implement its proposed upload handling - PR #952 perf(vk): a recording's uniform copies shared, their reads made once a draw: Castle Town's market from 54.9 to 59.5 fps on a B580 with the uniform snapshot β€” Merged batched submitted-memory reads; this PR instruments the replay reads that path uses - PR #248 perf(vk): fix the late pages on the GPU, word by word, instead of waiting for their write-back β€” Merged late-page capture handling; captures and capture-time page selection are part of this code path
Author
Contributor

@Beanstalk This adds RX_VK_CAPTURE_USE, a diagnostic off by default: with RX_VK_CAPTURE_USE=1 the renderer counts how submit captures' copies are used and logs capture-use lines every 600 submits (gpu/vk); nothing else changes. It has not run in the game on these PCs yet. Please play Kokiri Forest for two minutes, walking into Link's house and out, the PR against main on the same PC, on the PR's side with RX_VK_CAPTURE_USE=1 and with it unset, with a picture compared with main's, on Windows with Intel and on Linux with AMD (RADV). The same picture, no crash or FATAL line; set, the capture-use lines every 600 submits; frame times alike either way. Please report those lines.

@Beanstalk This adds RX_VK_CAPTURE_USE, a diagnostic off by default: with RX_VK_CAPTURE_USE=1 the renderer counts how submit captures' copies are used and logs capture-use lines every 600 submits (gpu/vk); nothing else changes. It has not run in the game on these PCs yet. Please play Kokiri Forest for two minutes, walking into Link's house and out, the PR against main on the same PC, on the PR's side with RX_VK_CAPTURE_USE=1 and with it unset, with a picture compared with main's, on Windows with Intel and on Linux with AMD (RADV). The same picture, no crash or FATAL line; set, the capture-use lines every 600 submits; frame times alike either way. Please report those lines.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting πŸ‘ to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting πŸ‘ to it or to this comment.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's πŸ‘ on the request
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/vk-capture-use:siantm-perf/vk-capture-use'
git switch 'siantm-perf/vk-capture-use'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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
MagicBeanDev/Longshot!2051
No description provided.