Skip to content

feat(kyty): record frame captures for offline replay - #220

Closed
mjnhbg3 wants to merge 3 commits into
simnJS:AnyKytyfrom
mjnhbg3:feat/kyty-frame-capture
Closed

mjnhbg3 wants to merge 3 commits into
simnJS:AnyKytyfrom
mjnhbg3:feat/kyty-frame-capture

Conversation

@mjnhbg3

@mjnhbg3 mjnhbg3 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Restore frame capture for the linked Kyty build using the existing format consumed by agc_frame_replay. Capture records the driver calls in acceptance order, snapshots coherent guest memory at the first boundary, records changes at later handoffs, and saves final display references. It stops capture-only serial tracking on completion or failure.

Capture currently needs stable guest mappings and readable GPU state. Parked queues, GPU-owned images without a coherent guest copy, deferred REWIND flips and the external kyty_gpu.prx build are documented limitations.

Tested

  • Windows 11 Pro 25H2 (26200.9974), NVIDIA GeForce RTX 5070 Ti, driver 616.64, WinLibs GCC 15.2.0 and LLVM 21.1.8.
  • Matched stock 3f7863d6a4a7 and candidate 71bed426935e using ctest --test-dir build -R '^kyty_shim_' -V --timeout 300 --no-tests=error, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer. The loader inserted Khronos validation 1.4.350 on both builds. Neither log had a missing-layer message or a VUID- error. Stock: 67 of 69 passed. Candidate: 68 of 70 passed. Both have the same Windows replay-launch failures reported in #203.
  • kyty_shim_frame_capture_round_trip records two real DMA submissions from separate caller threads and checks both known display patterns. Strict offline replay compared two buffers with pixels_identical=1.000000, max_channel_diff=0, skipped_bytes=0 and unfinished=0.
  • DriftCheck 01.000.000 (PPSA98766), relinked with --windows --to-intel --frame-red-zone: on the final candidate, capture began at flip 12 and recorded two more frames with APS5_SYNC_FLIP=1. agc_frame_replay --strict --no-synthesize --repeat 1 --cold-pipelines compared two display buffers, both pixel-identical, with zero skipped bytes and no VUIDs on record or replay.
  • Linux regression on Ubuntu 24.04.5 LTS (kernel 6.8.0-147-generic), Intel Arc A380, Mesa 25.2.8. Built both revisions in Release with GCC 13.3, Clang/LLD 21.1.8, and ThinLTO. Ran ctest -R '^kyty_shim_frame_capture_round_trip$' -V --no-tests=error under Xvfb with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer.
  • ced58710dd reproduced a shared guest mapping has no replayable direct memory identity. 1329afeb5a passed three runs, including one with APS5_NO_PROCMAP_QUERY=1. Strict replay compared two frames per run with pixels_identical=1.000000, max_channel_diff=0, skipped_bytes=0, and unfinished=0. The loader inserted Khronos validation 1.4.350 on both revisions, with zero missing-layer messages or VUIDs.
  • Hosted AnyKyty CI and Offline checks passed on 1329afeb5a. The lavapipe job skips the round trip because that driver lacks Vulkan features required by the replay.
  • Conventions passed against origin/AnyKyty. The required origin/main comparison has the same inherited findings on both arms. The overlap script could not merge feat(kyty): read V#-described buffers by mirror address behind KYTY_E2_VSHARP_MIRROR #181 into the base. Its actual patch shares only the shim test CMake file, with separate hunks that apply cleanly to this branch.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Fixes tools: record frame captures from the Kyty driver #212
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5070 Ti, 616.64, Windows 11 Pro 25H2 and Intel Arc A380, Mesa 25.2.8, Ubuntu 24.04.5 LTS
  • AI-assisted: yes

@simnJS simnJS added area: tools-ci Tests, CI, measurement and analysis tools enhancement New feature or request labels Nov 22, 2026
@simnJS

simnJS commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks for the quick update: the .esbak part is good, and the four tests now pass. We still can't merge the FDE part, because
the rule is wider than the one we discussed. In CodeInstructionCollector.cpp, a TLS access that crosses the range end is
only refused when address == begin || sawTerminator. In every other case the range is skipped and the conversion carries
on, although the commit message says "a TLS access split across the boundary still fails the conversion".

We checked it with the images of test_tls_function_coverage.py (TLS_LOAD at 0x1240, a 0x46-byte range): with the jmp rax
before it, both AnyKyty and this PR refuse (exit 2). With that jmp rax replaced by two nops, AnyKyty still refuses,
but this PR converts with exit 0 and logs "skipped a range that ends inside an instruction at 0x1240", for both unwind and
symbol metadata. The four existing tests all have a terminator before the TLS access, so none of them covers this case.

Could you refuse every TLS access that crosses the range end (drop the address == begin || sawTerminator condition, or
explain why that case is safe), and add that case to test_tls_function_coverage.py as a refusal? If you'd like to land the
.esbak fix sooner, you can split it into its own PR and we'll take it as it is.
Thanks for bringing frame capture back to the linked Kyty build. The off path looks right to us: with APS5_FRAME_CAPTURE
unset, each hooked driver call costs one static load and a null check, and IsRegionGpuModified keeps its old result by
default.

We can't merge it yet, because CI is red on 71bed42:

  • Linux kyty, asan, tsan and the lavapipe job fail to link libSceAgcDriver.prx: multiple definition of ZSTD_createDCtx
    (and the rest of zstd). libkyty_gpu.a's prelinked object already carries zstd, so
    target_link_libraries(libSceAgcDriver PRIVATE libzstd_static) brings in a second copy. Linking against the copy in the
    core (or keeping zstd out of one side) should fix it. Please check that a Linux build links.
  • Windows kyty: kyty_shim_frame_capture_round_trip fails in the job (test 1669).

Push an update once CI is green, and it goes into the next integration.

@mjnhbg3
mjnhbg3 force-pushed the feat/kyty-frame-capture branch from 71bed42 to f10a167 Compare November 22, 2026 19:27
@simnJS

simnJS commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks for the update: both points from the last review are fixed (zstd is linked once, the Windows job is green), and the off
path still costs nothing.

We can't merge it yet, because the round-trip test fails on Linux with a real GPU. On our PC (Ryzen 9 7950X3D, RTX 4080 SUPER,
NVIDIA 595.99, ANYPS5_REQUIRE_VULKAN=1), kyty_shim_frame_capture_round_trip fails 3 times out of 3:

[frame-capture] stopped: a shared guest mapping has no replayable direct memory identity
kyty_shim_frame_capture_round_trip: frame capture: cannot open …/frame capture round trip/<n>/calls.bin

CI can't catch it: the test is in tools/lavapipe_skip.txt and in GPU_TESTS, which the sanitizer jobs exclude, so no Linux
job runs it on a GPU.

What we think happens: on Linux, the Kyty build maps guest memory through a shared file (the "second view of guest memory"
line at start-up). So HostMapping::Walk reports the fixture's arena memory (GuestArenaAllocateAtOrAbove +
GuestArenaCommit) as shared, CheckSharedRange calls sceKernelVirtualQuery, gets is_direct == 0 and throws. On Windows
the same memory is MEM_PRIVATE, so it never reaches that check. A real title's arena memory would be refused the same way.
The Linux branch probably needs to recognise mappings of the guest memory file itself as ordinary guest memory (for example by
the file's identity), and keep CheckSharedRange for other shared mappings.

Could you fix that and add a note to the PR on how you checked it on Linux (a run of the test on a Linux GPU, or a Linux job that
runs it)? Then it goes into the next integration.

@simnJS

simnJS commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for ced58710dd. We ran the round-trip test again on the new head, on top of the current AnyKyty and tonight's other
PRs, on our Linux PC (Ryzen 9 7950X3D, RTX 4080 SUPER, NVIDIA 595.99, ANYPS5_REQUIRE_VULKAN=1). It still fails 3 times out of
3, with the same message:

[frame-capture] stopped: a shared guest mapping has no replayable direct memory identity
kyty_shim_frame_capture_round_trip: frame capture: cannot open …/frame capture round trip/<n>/calls.bin

The new commit changes which shader registrations are checked during a replay, but the failure comes from the capture side:
on Linux the fixture's arena memory is a shared mapping of the guest memory file, and CheckSharedRange refuses it (see our
previous comment). On the same build, every other test of the shim GPU run passes (107 of 110; besides this one, the RT corpus
is skipped without its corpus, and one CLI test did not run because its helper binary was missing from our copy). So the fix still needs to make the Linux branch accept mappings of the guest memory file
itself. A run of the test on any Linux machine with a GPU (or with lavapipe, if you take it out of tools/lavapipe_skip.txt
for the check) should show it.

@simnJS

simnJS commented Nov 25, 2026

Copy link
Copy Markdown
Owner

The Linux change now checks the guest file's device, inode and mapping offset, and your three successful Arc A380 round trips address the original diagnosis. Our previous RTX 4080 SUPER failures were on ced58710dd. We had no round-trip binary for 1329afeb5a on that PC during this review, so the RTX retest is still outstanding on our side.

@Celegans12

Copy link
Copy Markdown
Collaborator

I ran the round trip on our Windows laptop at 1329afeb5a (the PR head, built as is): i9-11900H, RTX 3080 Laptop, NVIDIA 621.14, Windows 11. Plain non-DLL Release build with BUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1, and the Khronos validation layer on (SDK 1.4.363, KYTY_VULKAN_VALIDATION=1 plus VK_INSTANCE_LAYERS).

kyty_shim_frame_capture_round_trip passed 3 of 3 runs (1.07, 1.05 and 1.12 s). Each run recorded 2 frames and replayed them with frames_compared: 2 and pixels_identical: 1.0. The layer loaded in both the capture and the replay process, and there were no VUID lines.

One caveat: this doesn't stand in for your Linux RTX retest. On Windows the fixture's arena memory is MEM_PRIVATE, so the new Linux guest file check (device, inode, offset) never runs here. It only shows the Windows side still works on NVIDIA hardware.

The rest of the shim set on the same build

ctest -R '^kyty_shim_' with validation on: 88 of 91 pass, kyty_shim_rt_corpus skips (no corpus), and two time out at 120 s: kyty_shim_bda_load_forms and kyty_shim_wave_split_written_reads. Those two also time out without the validation layer, and they time out the same way on #289's head, which is on a different base. This PR doesn't touch either one, so they look like an existing NVIDIA/Windows issue, not this change. No VUID lines anywhere in the pass.

This laptop has an Intel iGPU too, and with the default loader order several shim tests ended up on the Intel device. So all the runs above used VK_LOADER_DRIVERS_SELECT=*nv-vk64.json and ANYPS5_GPU=NVIDIA, and every loader "Using" line in the logs names the RTX 3080. Anyone testing on a hybrid laptop should check that.

git merge-tree also merges 1329afeb5a into current AnyKyty (dcdde0a389) without conflicts. I didn't build that merge.

AI-assisted: yes

@simnJS

simnJS commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks, that settles the Windows/NVIDIA side, and the caveat is right: the device, inode and offset check only runs on Linux. We owe the Linux RTX retest at 1329afeb5a and are running it on the RTX 4080 SUPER now; we will post the result here and merge if it passes. The two 120 s timeouts (bda_load_forms, wave_split_written_reads) are not from this PR; thanks for checking them on #289's head too.

@simnJS

simnJS commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged into AnyKyty (your three commits, rebased onto the current head with no conflicts, all checks green). The Linux round trip passed 3 of 3 on an RTX 4080 SUPER (driver 595.99.02) with the validation layer on: frames_compared=2, pixels_identical=1.0, no VUID. Together with the Arc A380 runs and Celegans12's Windows/NVIDIA runs, that covers the original failure. Thanks @mjnhbg3, and thanks @Celegans12 for the Windows check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tools-ci Tests, CI, measurement and analysis tools enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools: record frame captures from the Kyty driver

3 participants