Skip to content

fix(agc): keep draw snapshots without a collect epoch out of the unwritten table - #4

Draft
Stan2032 wants to merge 1 commit into
mainfrom
topic/agc-draw-snapshot-epoch-zero
Draft

Stan2032 wants to merge 1 commit into
mainfrom
topic/agc-draw-snapshot-epoch-zero

Conversation

@Stan2032

@Stan2032 Stan2032 commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

What

PrepareDrawBindings notes a copied read-only draw input in the recorder's unwritten-snapshot table under the stamp {TrackerGeneration, CollectEpoch, registry generation}. Later draws reuse the noted copy while that stamp is unchanged. The note was skipped for a zero collect epoch only on the upload path. A copy made through ReusableDrawSnapshot or a new buffer (!uploaded) was noted with stamp[1] == 0 as well.

A CPU store to a compared (unwatched) host import changes none of the three stamp words, so with no collect epoch every later draw reused the copy taken before the store. CollectEpoch() is 0 in two cases:

  • with APS5_NO_COLLECT_MEMO=1, which documents itself as only turning the memo off;
  • on a thread that has not bumped a collect epoch yet.

The change notes a snapshot only when stamp[1] != 0. Without an epoch, draws go through ReusableDrawSnapshot, which checks the range's collect generation.

agc_draw_snapshot_epoch_no_collect_memo runs the existing --draw-snapshot-epoch-only case with APS5_NO_COLLECT_MEMO=1. The two reuse checks in that case now hold only when there is a collect epoch, since reuse within an epoch is all they assert. The content checks stay unconditional.

Tested

Linux 6.18, lavapipe (llvmpipe, Mesa 25.2.8, LLVM 20.1.2), upstream main 06b3505 compared with this branch on the same machine.

  • Found by: running ctest -R '^agc_' with the cache and memo switches from docs/dev/ENVIRONMENT.md.

    • On main, APS5_NO_COLLECT_MEMO=1 fails agc_draw_snapshot_epoch and agc_driver_recorder with a draw snapshot does not hold the guest bytes of its draw.
    • Instrumenting the case shows the third draw returning the first copy: byte 7a, where guest memory holds 85.
  • Epoch 0 with the memo on: I instrumented the changed branch for one full ctest -R '^agc_' run with default settings. Nine other tests take a large draw snapshot with a collect epoch of 0, so the noted-snapshot path ran without an epoch outside the switch too:

    • agc_driver_address_draw_space_reuse and four of its variants
    • agc_driver_recorder and agc_driver_recorded_kept_bytes
    • agc_draw_snapshot_cap and agc_driver_volume_mip_targets

    All nine pass with this change. I have not measured how often a title's draw threads run before their first collect epoch.

  • New test on main: agc_draw_snapshot_epoch_no_collect_memo fails.

  • New test with this change: it passes in 3 of 3 runs, and agc_draw_snapshot_epoch still passes.

  • Mutation check: I restored !uploaded ||, and the new test fails again with a draw snapshot does not hold the guest bytes of its draw.

  • With APS5_NO_COLLECT_MEMO=1 across the whole sweep: agc_draw_snapshot_epoch and agc_driver_recorder now pass.

  • Full ctest -R '^agc_' (2324 tests): the results match main apart from the new test and agc_driver_msaa_resolve_publication_order. That test fails about 30% of runs on main with the guest arena gave no resolve destination below a multisampled source, and passed in this run.

  • Validation protocol: I ran the same focused tests on main and on this change with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer and validation layer 1.4.363.1. The test regex was ^agc_(driver_recorder|draw_snapshot.*|draw_input.*|owned_draw_inputs.*|draw_inputs_.*|untracked_forget|idle_publish_wait|recorder_.*)$.

    • main: 26 of 29 passed and 3 were skipped on this device. The loader inserted the layer, never logged was not found but was requested by env var VK_INSTANCE_LAYERS, and the log has 0 VUID- lines.
    • This change: 27 of 30 passed, with the same 3 skipped. The layer was inserted, and the log has 0 VUID- lines.
  • NVIDIA hardware, Dec 1: NVIDIA GeForce GTX 1050 (the machine's only Vulkan device), driver 582.67, Vulkan 1.4.312, validation layer 1.4.363, Windows 11, built with WinLibs GCC 15.2.0. This branch is 97 commits behind main, so I applied its commit onto main 483b81f and compared that with main 483b81f on the same machine; the branch head itself was not built. Every run used ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, each run's log shows the loader inserting the layer and none reports it missing, and no log has a VUID- line.

    • agc_driver_graphics, agc_driver_register_key and agc_draw_snapshot_epoch*: 3/3 pass on main; 4/4 with this change, the fourth being the new agc_draw_snapshot_epoch_no_collect_memo, which ran and passed.
    • The tests matching snapshot|recorder|collect: main 59 passed and 1 skipped of 60; this change 60 passed and 1 skipped of 61. The skipped test is agc_host_import_retire_snapshot on both.
  • Checks: tools/check_conventions.py passes. tools/pr_overlap.py --branch could not confirm 132 PRs that conflict with main, so I compared each one by hand.

    • 13809 edits the same condition, to !owned && (!uploaded || stamp[1] != 0). It keeps the zero-epoch note, so the two would conflict textually.
    • 13251, 14262, 15529, 15570, 6186 and 9712 add names to the same Windows ENVIRONMENT_MODIFICATION list.
    • 17943 re-indents the drawSnapshotEpochTests call.
    • No open PR changes the zero-epoch case.

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: none
  • Unblocks: none
  • GPUs tested: lavapipe (llvmpipe, Mesa 25.2.8, LLVM 20.1.2), Linux 6.18; NVIDIA GeForce GTX 1050 (driver 582.67), Windows 11, with this commit applied onto a newer main
  • AI-assisted: yes

https://claude.ai/code/session_0125gxvaRgLMwjs53eqvUzya


Generated by Claude Code

…itten table

A copied read-only draw input was noted for reuse under the stamp
{tracker generation, collect epoch, registry generation} even when the
collect epoch was 0. A CPU store to a compared (unwatched) host import
changes none of those, so later draws reused the copy taken before the
store. The collect epoch is 0 with APS5_NO_COLLECT_MEMO=1 and on a thread
that has not bumped one yet; such snapshots now go through the
generation-checked draw snapshot path instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0125gxvaRgLMwjs53eqvUzya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants