perf(agc): expand an HTILE on the GPU behind a pending mask clear kernel #8105

Merged
Celegans12 merged 1 commit from upstream-pr/8105 into main 2026-10-31 05:25:57 +00:00
Celegans12 commented 2026-10-19 21:49:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T21:49:21Z.


What

Binding a depth target behind an HTILE mask clear waited for GPU readback. Record its mask/value with the newest pending write and unique recorder ID; expand on the GPU when that write determines ZMask/SMem across the HTILE. Other patterns read back. Accept the structured-buffer variant seen in Ghost of Yōtei (PPSA26344).

The recorder-lifetime collision reported by @MarcZX10 and @adriadam10 is fixed by checking owner identity, removing its proofs at recorder teardown, and removing device proofs at depth cleanup. The global 64-record bound and conservative overlap invalidation remain.

The recognized clear carries its HTILE range through preparation, upload and binding. Only its pending native owner admits that range; ordinary writes, depth-plane accesses and color guards retain their checks. The exception ends at arm and cannot enter resource/recipe caches. @jotitadev's reproduction and supplied patch guided this guard fix.

Related: #7002 changes buffer/color checks. #7642/#9508/#6412/#10193 change reuse gates. #9533/#9717/#9742 extend clear fixtures. #9950/#10492/#10469/#10497 publish native depth through the fallback guard. #13021/#13023 add publication arguments and #6804 adds a PrepareDispatch parameter; compose those with this range. #6300/#6808 extend clear-generation proofs. #11602/#6192/#12921 change HTILE proof stamps; #10940 device-scopes texture write-back. None supplies this dispatch allowance or recorder-mask ownership; retain their independent refusal conditions.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 0835ec8bdc, -DBUILD_TESTING=ON: four focused targets build. NVIDIA: 9/9 tests, each repeated three times; lavapipe: 9/9 once. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V: layer loaded, no VUID errors. Registration and conventions pass.
  • agc_driver_htile_mask_lifetime fails 3/3 on the previous PR rebased onto this main: reused recorder storage, HTILE address and note 1 turn ordinary 0x0000000f words into 0xfffc000f without readback. All eight GPU assertions now run and pass: recreated/live owner isolation, same-owner fast path, recorder cleanup and both owners of a cleared device while preserving another device's proof. Checks compare both ThreadHookWaits and metadata bytes.
  • The previous round's agc_driver_native_depth_buffer_clear regression failed 3/3 before its guard fix; that test and seven neighbors remain in the current passing set. Historical paired main e2df06e661 controls passed 7/7 on both drivers; those controls were not rebuilt this round. Recorder/DepthSurface production files are unchanged between that main and 0835ec8bdc.
  • Both Windows drivers still lack the imported-HTILE write-coverage assertion: PM4 cases verify controlled refusal, not successful watched-clear sampling. The new lifetime test executes on both; unsupported host-import devices explicitly skip it. Not tested: Linux, AMD, Intel or titles this revision.
Historical performance evidence, 24 October; no new performance claim for the guard or lifetime fixes

main vs the original change on the same machine (RTX 3080 Laptop, driver 610.62, Windows 11), Ghost of Yōtei (PPSA26344 v1.008) title menu from the same save with no input, warm caches, interleaved runs in one session, perf-report protocol (only APS5_TRACE_FRAMES=150:60, no APS5_PROFILE_*): main a5a2c946a3 against main a5a2c946a3 + this PR. Frame p50 131.9 ms (3 runs) against 133.6 ms (2 runs), GPU busy 77.7 against 80.5 ms per present. That's inside the run-to-run spread (main's three runs: 128.2-135.1 ms), as expected for a scene that doesn't exercise this path; our open-world numbers, from our own tree, are in the comments. Traces and tools/trace_digest.py output per run: pl-main-1, pl-main-2, pl-main-3, pl-8105-1, pl-8105-2.

aps5-summary.jsonl, pl-main-3 and pl-8105-1 (the run closest to each side's mean; `title` written as `ō`, since the summary writer double-encodes it and GitHub mangles that escape)
{"commit":"a5a2c946a3a9","dirty":false,"env":{"APS5_NO_CLEAR_HAND_OVER":"1","APS5_NO_DEFERRED_SETTLES":"1","APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESIDENT_LINEAR":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_TRACE_FRAMES":"150:60"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz","cpu_threads":16,"memory_mib":32469,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 150:60","first_present":150,"ms":11388.409},"presents":60,"frame_ms":{"p50":132.237,"p90":378.788,"p99":2488.458,"max":2488.458},"gpu_busy_ms_per_present":76.739,"worker_busy_pct":{"queue worker 0x0":61.336,"queue worker 0x20":12.709,"queue worker 0x52":10.897,"queue worker 0x53":12.001,"queue worker 0x30":43.438,"queue worker 0x38":50.980,"queue worker 0x48":3.931},"top_phases_ms_per_frame":{"Driver.Packet":363.867,"Shader.PrepareArtifact":329.176,"Driver.Packet.dispatch":163.759,"Driver.Packet.memory_wait":130.658,"Driver.Dispatch":116.659,"Driver.Packet.prepare_memory":46.855,"GpuMutex.wait.dispatch":32.057,"Shader.Register":29.105},"trace_dropped":false,"trace":"aps5-trace-a5a2c946a3a9-16452.json.gz"}
{"commit":"b2bea6d90d06","dirty":false,"env":{"APS5_NO_CLEAR_HAND_OVER":"1","APS5_NO_DEFERRED_SETTLES":"1","APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESIDENT_LINEAR":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_TRACE_FRAMES":"150:60"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz","cpu_threads":16,"memory_mib":32469,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 150:60","first_present":150,"ms":12317.426},"presents":60,"frame_ms":{"p50":128.450,"p90":361.446,"p99":3476.353,"max":3476.353},"gpu_busy_ms_per_present":75.766,"worker_busy_pct":{"queue worker 0x0":56.658,"queue worker 0x52":9.090,"queue worker 0x20":10.824,"queue worker 0x53":10.181,"queue worker 0x30":39.973,"queue worker 0x38":46.768,"queue worker 0x48":4.182},"top_phases_ms_per_frame":{"Shader.PrepareArtifact":452.689,"Driver.Packet":359.164,"Driver.Packet.dispatch":157.312,"Driver.Packet.memory_wait":130.349,"Driver.Dispatch":113.443,"Driver.Packet.prepare_memory":45.684,"Shader.Register":33.281,"GpuMutex.wait.flush":29.871},"trace_dropped":false,"trace":"aps5-trace-b2bea6d90d06-17424.json.gz"}

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
  • 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: NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.62; lavapipe (Mesa 26.2.4, LLVM 22.1.8); both Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4927888978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-19T21:49:21Z. --- ### What Binding a depth target behind an HTILE mask clear waited for GPU readback. Record its mask/value with the newest pending write and unique recorder ID; expand on the GPU when that write determines ZMask/SMem across the HTILE. Other patterns read back. Accept the structured-buffer variant seen in Ghost of Yōtei (PPSA26344). The recorder-lifetime collision reported by @MarcZX10 and @adriadam10 is fixed by checking owner identity, removing its proofs at recorder teardown, and removing device proofs at depth cleanup. The global 64-record bound and conservative overlap invalidation remain. The recognized clear carries its HTILE range through preparation, upload and binding. Only its pending native owner admits that range; ordinary writes, depth-plane accesses and color guards retain their checks. The exception ends at arm and cannot enter resource/recipe caches. @jotitadev's reproduction and supplied patch guided this guard fix. Related: #7002 changes buffer/color checks. #7642/#9508/#6412/#10193 change reuse gates. #9533/#9717/#9742 extend clear fixtures. #9950/#10492/#10469/#10497 publish native depth through the fallback guard. #13021/#13023 add publication arguments and #6804 adds a `PrepareDispatch` parameter; compose those with this range. #6300/#6808 extend clear-generation proofs. #11602/#6192/#12921 change HTILE proof stamps; #10940 device-scopes texture write-back. None supplies this dispatch allowance or recorder-mask ownership; retain their independent refusal conditions. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 0835ec8bdc, `-DBUILD_TESTING=ON`: four focused targets build. NVIDIA: 9/9 tests, each repeated three times; lavapipe: 9/9 once. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V`: layer loaded, no VUID errors. Registration and conventions pass. - `agc_driver_htile_mask_lifetime` fails 3/3 on the previous PR rebased onto this main: reused recorder storage, HTILE address and note 1 turn ordinary `0x0000000f` words into `0xfffc000f` without readback. All eight GPU assertions now run and pass: recreated/live owner isolation, same-owner fast path, recorder cleanup and both owners of a cleared device while preserving another device's proof. Checks compare both `ThreadHookWaits` and metadata bytes. - The previous round's `agc_driver_native_depth_buffer_clear` regression failed 3/3 before its guard fix; that test and seven neighbors remain in the current passing set. Historical paired main e2df06e661 controls passed 7/7 on both drivers; those controls were not rebuilt this round. Recorder/DepthSurface production files are unchanged between that main and 0835ec8bdc. - Both Windows drivers still lack the imported-HTILE write-coverage assertion: PM4 cases verify controlled refusal, not successful watched-clear sampling. The new lifetime test executes on both; unsupported host-import devices explicitly skip it. Not tested: Linux, AMD, Intel or titles this revision. <details><summary>Historical performance evidence, 24 October; no new performance claim for the guard or lifetime fixes</summary> `main` vs the original change on the same machine (RTX 3080 Laptop, driver 610.62, Windows 11), Ghost of Yōtei (PPSA26344 v1.008) title menu from the same save with no input, warm caches, interleaved runs in one session, perf-report protocol (only `APS5_TRACE_FRAMES=150:60`, no `APS5_PROFILE_*`): `main` a5a2c946a3 against `main` a5a2c946a3 + this PR. Frame p50 131.9 ms (3 runs) against 133.6 ms (2 runs), GPU busy 77.7 against 80.5 ms per present. That's inside the run-to-run spread (`main`'s three runs: 128.2-135.1 ms), as expected for a scene that doesn't exercise this path; our open-world numbers, from our own tree, are in the comments. Traces and `tools/trace_digest.py` output per run: [pl-main-1](https://github.com/Celegans12/AnyPS5/tree/bringup-media/traces/title-2026-10-24/pl-main-1/), [pl-main-2](https://github.com/Celegans12/AnyPS5/tree/bringup-media/traces/title-2026-10-24/pl-main-2/), [pl-main-3](https://github.com/Celegans12/AnyPS5/tree/bringup-media/traces/title-2026-10-24/pl-main-3/), [pl-8105-1](https://github.com/Celegans12/AnyPS5/tree/bringup-media/traces/title-2026-10-24/pl-8105-1/), [pl-8105-2](https://github.com/Celegans12/AnyPS5/tree/bringup-media/traces/title-2026-10-24/pl-8105-2/). <details><summary><code>aps5-summary.jsonl</code>, pl-main-3 and pl-8105-1 (the run closest to each side's mean; `title` written as `ō`, since the summary writer double-encodes it and GitHub mangles that escape)</summary> ```json {"commit":"a5a2c946a3a9","dirty":false,"env":{"APS5_NO_CLEAR_HAND_OVER":"1","APS5_NO_DEFERRED_SETTLES":"1","APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESIDENT_LINEAR":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_TRACE_FRAMES":"150:60"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz","cpu_threads":16,"memory_mib":32469,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 150:60","first_present":150,"ms":11388.409},"presents":60,"frame_ms":{"p50":132.237,"p90":378.788,"p99":2488.458,"max":2488.458},"gpu_busy_ms_per_present":76.739,"worker_busy_pct":{"queue worker 0x0":61.336,"queue worker 0x20":12.709,"queue worker 0x52":10.897,"queue worker 0x53":12.001,"queue worker 0x30":43.438,"queue worker 0x38":50.980,"queue worker 0x48":3.931},"top_phases_ms_per_frame":{"Driver.Packet":363.867,"Shader.PrepareArtifact":329.176,"Driver.Packet.dispatch":163.759,"Driver.Packet.memory_wait":130.658,"Driver.Dispatch":116.659,"Driver.Packet.prepare_memory":46.855,"GpuMutex.wait.dispatch":32.057,"Shader.Register":29.105},"trace_dropped":false,"trace":"aps5-trace-a5a2c946a3a9-16452.json.gz"} ``` ```json {"commit":"b2bea6d90d06","dirty":false,"env":{"APS5_NO_CLEAR_HAND_OVER":"1","APS5_NO_DEFERRED_SETTLES":"1","APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESIDENT_LINEAR":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_TRACE_FRAMES":"150:60"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz","cpu_threads":16,"memory_mib":32469,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 150:60","first_present":150,"ms":12317.426},"presents":60,"frame_ms":{"p50":128.450,"p90":361.446,"p99":3476.353,"max":3476.353},"gpu_busy_ms_per_present":75.766,"worker_busy_pct":{"queue worker 0x0":56.658,"queue worker 0x52":9.090,"queue worker 0x20":10.824,"queue worker 0x53":10.181,"queue worker 0x30":39.973,"queue worker 0x38":46.768,"queue worker 0x48":4.182},"top_phases_ms_per_frame":{"Shader.PrepareArtifact":452.689,"Driver.Packet":359.164,"Driver.Packet.dispatch":157.312,"Driver.Packet.memory_wait":130.349,"Driver.Dispatch":113.443,"Driver.Packet.prepare_memory":45.684,"Shader.Register":33.281,"GpuMutex.wait.flush":29.871},"trace_dropped":false,"trace":"aps5-trace-b2bea6d90d06-17424.json.gz"} ``` </details> </details> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.62; lavapipe (Mesa 26.2.4, LLVM 22.1.8); both Windows 11 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-19 21:49:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T21:49:35Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278157591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6278157591). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T21:49:35Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
MarcZX10 commented 2026-10-19 22:54:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T22:54:04Z.


The #7233 RTX run exposed an ordering detail that likely affects this buffer-mask path: NoteHtileDepthClear runs before PrepareDispatch, and the HTILE host import can first happen while building dispatch resources. A clear baseline captured at NoteHtileDepthClear then treats that import-window stamp as a CPU race.

I am prototyping #7233 so recognition leaves the clear pending and the baseline is armed after resource imports, immediately before GPU writes are recorded. Your MatchHtileBufferMaskClear path also calls NoteHtileDepthClear and records the mask after dispatch, so it will need the same baseline transition at the right post-build point. My prototype is still local and only compile-validated here; the Xeon host stops before the GPU test. Let’s coordinate the two paths before either is merged; I can share/rebase the implementation once we agree on the hook for the mask dispatch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279134254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6279134254). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T22:54:04Z. --- The #7233 RTX run exposed an ordering detail that likely affects this buffer-mask path: `NoteHtileDepthClear` runs before `PrepareDispatch`, and the HTILE host import can first happen while building dispatch resources. A clear baseline captured at `NoteHtileDepthClear` then treats that import-window stamp as a CPU race. I am prototyping #7233 so recognition leaves the clear pending and the baseline is armed after resource imports, immediately before GPU writes are recorded. Your `MatchHtileBufferMaskClear` path also calls `NoteHtileDepthClear` and records the mask after dispatch, so it will need the same baseline transition at the right post-build point. My prototype is still local and only compile-validated here; the Xeon host stops before the GPU test. Let’s coordinate the two paths before either is merged; I can share/rebase the implementation once we agree on the hook for the mask dispatch.
MarcZX10 commented 2026-10-19 23:00:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T23:00:18Z.


I checked the call flow more closely. A shared path should work without changing your mask-write tracking: when NoteHtileDepthClear recognizes the buffer-mask clear, propagate its completion candidate through the existing Dispatch argument. Then recordDispatch can arm the baseline after resource imports and register the existing completion check; your later NoteHtileMaskOnGpu still associates the pending write note with the mask for store-back expansion. The global-store clear follows the same path.

Would you be comfortable sequencing #7233 first and rebasing #8105 on that API, or do you prefer another shared hook? The rebased #7233 prototype is local and not pushed yet; I want to avoid landing incompatible lifecycle changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279221873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6279221873). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T23:00:18Z. --- I checked the call flow more closely. A shared path should work without changing your mask-write tracking: when `NoteHtileDepthClear` recognizes the buffer-mask clear, propagate its completion candidate through the existing `Dispatch` argument. Then `recordDispatch` can arm the baseline after resource imports and register the existing completion check; your later `NoteHtileMaskOnGpu` still associates the pending write note with the mask for store-back expansion. The global-store clear follows the same path. Would you be comfortable sequencing #7233 first and rebasing #8105 on that API, or do you prefer another shared hook? The rebased #7233 prototype is local and not pushed yet; I want to avoid landing incompatible lifecycle changes.
Celegans12 commented 2026-10-19 23:49:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T23:49:28Z.


@MarcZX10, I checked this against #8105 and you're right. The buffer kernel goes through the same NoteHtileDepthClear call as the global-store one, before PrepareDispatch, and it passes nativeBytes equal to bytes. So for a sampled native multisample target it arms clearGeneration at the same early point, before the HTILE is imported for the dispatch. And if I read #7233 right, the buffer kernel's store is a descriptor-bound range there, so it only counts as a possible write. Without the completion hook, that path would then also fail the StoredAllSince check.

I'm fine with #7233 going first. The htileClearCompletion argument you already pass to Dispatch looks like the right shared hook to me. Once #7233 lands I'll rebase #8105 and set it from the buffer branch whenever NoteHtileDepthClear returns true, the same way the global-store branch does. NoteHtileMaskOnGpu stays as it is, since it only feeds the single-sample store-back. I'll add a test next to your DriverDispatch case that sends the buffer kernel through PM4 over a native multisample HTILE.

If your rebased version arms the baseline inside recordDispatch instead, that works for us too, as long as the buffer branch can pass the same address and byte count. Could you ping me here when it's pushed? Then I'll rebase onto it. Until then, on main alone, #8105 behaves for native multisample targets the same way the global-store kernel already does, so I'm leaving it as is.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279895723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6279895723). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-19T23:49:28Z. --- @MarcZX10, I checked this against #8105 and you're right. The buffer kernel goes through the same `NoteHtileDepthClear` call as the global-store one, before `PrepareDispatch`, and it passes `nativeBytes` equal to `bytes`. So for a sampled native multisample target it arms `clearGeneration` at the same early point, before the HTILE is imported for the dispatch. And if I read #7233 right, the buffer kernel's store is a descriptor-bound range there, so it only counts as a possible write. Without the completion hook, that path would then also fail the `StoredAllSince` check. I'm fine with #7233 going first. The `htileClearCompletion` argument you already pass to `Dispatch` looks like the right shared hook to me. Once #7233 lands I'll rebase #8105 and set it from the buffer branch whenever `NoteHtileDepthClear` returns true, the same way the global-store branch does. `NoteHtileMaskOnGpu` stays as it is, since it only feeds the single-sample store-back. I'll add a test next to your `DriverDispatch` case that sends the buffer kernel through PM4 over a native multisample HTILE. If your rebased version arms the baseline inside `recordDispatch` instead, that works for us too, as long as the buffer branch can pass the same address and byte count. Could you ping me here when it's pushed? Then I'll rebase onto it. Until then, on `main` alone, #8105 behaves for native multisample targets the same way the global-store kernel already does, so I'm leaving it as is.
Celegans12 commented 2026-10-19 23:49:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T23:49:29Z.


This one has no main numbers yet either. What I have comes from our Yōtei tree, where the same kernel recognition sits on top of a different local implementation of the GPU expansion. In the world, the depth store-back used to wait on the GPU 12-14 times per 10 s, 1.3-1.7 s in total. In the run just before this change those waits had moved into a pre-sync (about 1.1 s per 10 s). With the buffer kernel recognized there were none.

The traced frames of the closest pair don't show a frame-time difference beyond our run-to-run noise. That pair is the same scene, machine and environment, presents 880-891, before and after only this recognition: frame p50 went from 2,763 to 2,704 ms, but GPU busy went from 1,069 to 1,192 ms per present, and p90/p99 got worse in that window. Two runs of one build here have differed by 18% in p50. Where the saved time did show up is the queue-0 committer: it was 61% busy before and 46% after, in the untraced windows.

A main vs change pair needs a Yōtei run on main, and the machine is busy with other game work right now. I'll do it when it's free and post both lines here. If a different scene or a synthetic depth-clear benchmark would suit you better, tell me and I'll use that instead.

Summary lines (our tree, not main)

Before (long31-s1e5):

{"commit":"1cb08e3c4c5d","dirty":false,"env":{"APS5_BINDLESS_IMAGES":"1","APS5_BINDLESS_LAZY":"1","APS5_BINDLESS_STATS":"1","APS5_CACHE_SPIRV_BACKING":"1","APS5_COLD_SPIRV":"1","APS5_COLD_SPIRV_FILE":"1","APS5_DUMP_FRAMES":"300","APS5_DUMP_FRAMES_EVERY":"10","APS5_INLINE_SHADER_PREPARE":"1","APS5_MEM_STATS":"10","APS5_NO_ADDRESS_DRAW_REUSE":"1","APS5_NO_RESULT_MEMO":"1","APS5_PAD_SCRIPT":"100:cross,106:cross,112:cross,118:cross,124:cross,130:cross,136:cross,142:cross,148:cross,154:cross,160:cross,166:cross,172:cross,178:cross,184:cross,190:cross,196:cross,202:cross,208:cross,214:cross,220:cross,226:cross,232:cross,238:cross,244:cross,250:cross,256:cross,262:cross,268:cross,274:cross,280:cross,286:cross,292:cross,298:cross,304:cross,310:cross,316:cross,322:cross,328:cross,334:cross,340:cross,346:cross,352:cross,358:cross,364:cross,370:cross,376:cross,382:cross,388:cross,394:cross,400:cross,406:cross,412:cross,418:cross,424:cross,430:cross,436:cross,442:cross,448:cross,454:cross,460:cross,466:cross,472:cross,478:cross,484:cross,490:cross,496:cross,502:cross,508:cross,514:cross,520:cross,526:cross,532:cross,538:cross,544:cross,550:cross,556:cross,562:cross,568:cross,574:cross,580:cross","APS5_PAD_SCRIPT_REPEAT":"","APS5_PIPELINE_INDIRECT":"1","APS5_PROFILE_DRAW":"1","APS5_PROFILE_GPU":"1","APS5_SPANNED_WAVE":"1","APS5_STAGING_DIFF":"1","APS5_TEXTURE_OVERFLOW_MIB":"1024","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_FRAMES":"880:12","APS5_UNNORM_WRAP_GUARD":"1"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"frames 880:12","first_present":880,"ms":35992.963},"presents":12,"frame_ms":{"p50":2763.181,"p90":2911.173,"p99":5630.251,"max":5630.251},"gpu_busy_ms_per_present":1069.385,"worker_busy_pct":{"queue worker 0x0":94.692,"queue worker 0x52":49.055,"queue worker 0x20":56.191,"queue worker 0x53":47.992,"queue worker 0x30":82.793,"queue worker 0x48":3.548,"queue worker 0x38":83.449,"queue worker 0x51":4.364,"queue worker 0x50":45.901},"top_phases_ms_per_frame":{"Driver.Packet":14023.139,"Driver.Packet.memory_wait":8917.156,"Driver.Packet.dispatch":2607.674,"Driver.Dispatch":2162.854,"DrawPipeline.commit":1765.433,"Driver.Packet.draw":1505.629,"Driver.Draw":1500.810,"Graphics.Draw":1253.805},"trace_dropped":false,"trace":"aps5-trace-1cb08e3c4c5d-10200.json.gz"}

After (long33-s1e5h):

{"commit":"a6ea328656e3","dirty":false,"env":{"APS5_BINDLESS_IMAGES":"1","APS5_BINDLESS_LAZY":"1","APS5_BINDLESS_STATS":"1","APS5_CACHE_SPIRV_BACKING":"1","APS5_COLD_SPIRV":"1","APS5_COLD_SPIRV_FILE":"1","APS5_DUMP_FRAMES":"300","APS5_DUMP_FRAMES_EVERY":"10","APS5_INLINE_SHADER_PREPARE":"1","APS5_MEM_STATS":"10","APS5_NO_ADDRESS_DRAW_REUSE":"1","APS5_NO_RESULT_MEMO":"1","APS5_PAD_SCRIPT":"100:cross,106:cross,112:cross,118:cross,124:cross,130:cross,136:cross,142:cross,148:cross,154:cross,160:cross,166:cross,172:cross,178:cross,184:cross,190:cross,196:cross,202:cross,208:cross,214:cross,220:cross,226:cross,232:cross,238:cross,244:cross,250:cross,256:cross,262:cross,268:cross,274:cross,280:cross,286:cross,292:cross,298:cross,304:cross,310:cross,316:cross,322:cross,328:cross,334:cross,340:cross,346:cross,352:cross,358:cross,364:cross,370:cross,376:cross,382:cross,388:cross,394:cross,400:cross,406:cross,412:cross,418:cross,424:cross,430:cross,436:cross,442:cross,448:cross,454:cross,460:cross,466:cross,472:cross,478:cross,484:cross,490:cross,496:cross,502:cross,508:cross,514:cross,520:cross,526:cross,532:cross,538:cross,544:cross,550:cross,556:cross,562:cross,568:cross,574:cross,580:cross","APS5_PAD_SCRIPT_REPEAT":"","APS5_PIPELINE_INDIRECT":"1","APS5_PROFILE_DRAW":"1","APS5_PROFILE_GPU":"1","APS5_SPANNED_WAVE":"1","APS5_STAGING_DIFF":"1","APS5_TEXTURE_OVERFLOW_MIB":"1024","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_FRAMES":"880:12","APS5_UNNORM_WRAP_GUARD":"1"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"frames 880:12","first_present":880,"ms":36701.776},"presents":12,"frame_ms":{"p50":2703.958,"p90":3608.411,"p99":7357.782,"max":7357.782},"gpu_busy_ms_per_present":1191.815,"worker_busy_pct":{"queue worker 0x0":95.016,"queue worker 0x52":51.918,"queue worker 0x53":50.897,"queue worker 0x20":58.559,"queue worker 0x38":83.559,"queue worker 0x48":3.025,"queue worker 0x30":82.988,"queue worker 0x51":4.696,"queue worker 0x50":43.446},"top_phases_ms_per_frame":{"Driver.Packet":14472.703,"Driver.Packet.memory_wait":9587.032,"Driver.Packet.dispatch":2261.263,"Driver.Packet.draw":1797.523,"Driver.Draw":1793.000,"Driver.Dispatch":1762.886,"DrawPipeline.commit":1728.961,"Graphics.Draw":1583.262},"trace_dropped":false,"trace":"aps5-trace-a6ea328656e3-18376.json.gz"}
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279896014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6279896014). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-19T23:49:29Z. --- This one has no `main` numbers yet either. What I have comes from our Yōtei tree, where the same kernel recognition sits on top of a different local implementation of the GPU expansion. In the world, the depth store-back used to wait on the GPU 12-14 times per 10 s, 1.3-1.7 s in total. In the run just before this change those waits had moved into a pre-sync (about 1.1 s per 10 s). With the buffer kernel recognized there were none. The traced frames of the closest pair don't show a frame-time difference beyond our run-to-run noise. That pair is the same scene, machine and environment, presents 880-891, before and after only this recognition: frame p50 went from 2,763 to 2,704 ms, but GPU busy went from 1,069 to 1,192 ms per present, and p90/p99 got worse in that window. Two runs of one build here have differed by 18% in p50. Where the saved time did show up is the queue-0 committer: it was 61% busy before and 46% after, in the untraced windows. A `main` vs change pair needs a Yōtei run on `main`, and the machine is busy with other game work right now. I'll do it when it's free and post both lines here. If a different scene or a synthetic depth-clear benchmark would suit you better, tell me and I'll use that instead. <details><summary>Summary lines (our tree, not main)</summary> Before (long31-s1e5): ``` {"commit":"1cb08e3c4c5d","dirty":false,"env":{"APS5_BINDLESS_IMAGES":"1","APS5_BINDLESS_LAZY":"1","APS5_BINDLESS_STATS":"1","APS5_CACHE_SPIRV_BACKING":"1","APS5_COLD_SPIRV":"1","APS5_COLD_SPIRV_FILE":"1","APS5_DUMP_FRAMES":"300","APS5_DUMP_FRAMES_EVERY":"10","APS5_INLINE_SHADER_PREPARE":"1","APS5_MEM_STATS":"10","APS5_NO_ADDRESS_DRAW_REUSE":"1","APS5_NO_RESULT_MEMO":"1","APS5_PAD_SCRIPT":"100:cross,106:cross,112:cross,118:cross,124:cross,130:cross,136:cross,142:cross,148:cross,154:cross,160:cross,166:cross,172:cross,178:cross,184:cross,190:cross,196:cross,202:cross,208:cross,214:cross,220:cross,226:cross,232:cross,238:cross,244:cross,250:cross,256:cross,262:cross,268:cross,274:cross,280:cross,286:cross,292:cross,298:cross,304:cross,310:cross,316:cross,322:cross,328:cross,334:cross,340:cross,346:cross,352:cross,358:cross,364:cross,370:cross,376:cross,382:cross,388:cross,394:cross,400:cross,406:cross,412:cross,418:cross,424:cross,430:cross,436:cross,442:cross,448:cross,454:cross,460:cross,466:cross,472:cross,478:cross,484:cross,490:cross,496:cross,502:cross,508:cross,514:cross,520:cross,526:cross,532:cross,538:cross,544:cross,550:cross,556:cross,562:cross,568:cross,574:cross,580:cross","APS5_PAD_SCRIPT_REPEAT":"","APS5_PIPELINE_INDIRECT":"1","APS5_PROFILE_DRAW":"1","APS5_PROFILE_GPU":"1","APS5_SPANNED_WAVE":"1","APS5_STAGING_DIFF":"1","APS5_TEXTURE_OVERFLOW_MIB":"1024","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_FRAMES":"880:12","APS5_UNNORM_WRAP_GUARD":"1"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"frames 880:12","first_present":880,"ms":35992.963},"presents":12,"frame_ms":{"p50":2763.181,"p90":2911.173,"p99":5630.251,"max":5630.251},"gpu_busy_ms_per_present":1069.385,"worker_busy_pct":{"queue worker 0x0":94.692,"queue worker 0x52":49.055,"queue worker 0x20":56.191,"queue worker 0x53":47.992,"queue worker 0x30":82.793,"queue worker 0x48":3.548,"queue worker 0x38":83.449,"queue worker 0x51":4.364,"queue worker 0x50":45.901},"top_phases_ms_per_frame":{"Driver.Packet":14023.139,"Driver.Packet.memory_wait":8917.156,"Driver.Packet.dispatch":2607.674,"Driver.Dispatch":2162.854,"DrawPipeline.commit":1765.433,"Driver.Packet.draw":1505.629,"Driver.Draw":1500.810,"Graphics.Draw":1253.805},"trace_dropped":false,"trace":"aps5-trace-1cb08e3c4c5d-10200.json.gz"} ``` After (long33-s1e5h): ``` {"commit":"a6ea328656e3","dirty":false,"env":{"APS5_BINDLESS_IMAGES":"1","APS5_BINDLESS_LAZY":"1","APS5_BINDLESS_STATS":"1","APS5_CACHE_SPIRV_BACKING":"1","APS5_COLD_SPIRV":"1","APS5_COLD_SPIRV_FILE":"1","APS5_DUMP_FRAMES":"300","APS5_DUMP_FRAMES_EVERY":"10","APS5_INLINE_SHADER_PREPARE":"1","APS5_MEM_STATS":"10","APS5_NO_ADDRESS_DRAW_REUSE":"1","APS5_NO_RESULT_MEMO":"1","APS5_PAD_SCRIPT":"100:cross,106:cross,112:cross,118:cross,124:cross,130:cross,136:cross,142:cross,148:cross,154:cross,160:cross,166:cross,172:cross,178:cross,184:cross,190:cross,196:cross,202:cross,208:cross,214:cross,220:cross,226:cross,232:cross,238:cross,244:cross,250:cross,256:cross,262:cross,268:cross,274:cross,280:cross,286:cross,292:cross,298:cross,304:cross,310:cross,316:cross,322:cross,328:cross,334:cross,340:cross,346:cross,352:cross,358:cross,364:cross,370:cross,376:cross,382:cross,388:cross,394:cross,400:cross,406:cross,412:cross,418:cross,424:cross,430:cross,436:cross,442:cross,448:cross,454:cross,460:cross,466:cross,472:cross,478:cross,484:cross,490:cross,496:cross,502:cross,508:cross,514:cross,520:cross,526:cross,532:cross,538:cross,544:cross,550:cross,556:cross,562:cross,568:cross,574:cross,580:cross","APS5_PAD_SCRIPT_REPEAT":"","APS5_PIPELINE_INDIRECT":"1","APS5_PROFILE_DRAW":"1","APS5_PROFILE_GPU":"1","APS5_SPANNED_WAVE":"1","APS5_STAGING_DIFF":"1","APS5_TEXTURE_OVERFLOW_MIB":"1024","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_FRAMES":"880:12","APS5_UNNORM_WRAP_GUARD":"1"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"frames 880:12","first_present":880,"ms":36701.776},"presents":12,"frame_ms":{"p50":2703.958,"p90":3608.411,"p99":7357.782,"max":7357.782},"gpu_busy_ms_per_present":1191.815,"worker_busy_pct":{"queue worker 0x0":95.016,"queue worker 0x52":51.918,"queue worker 0x53":50.897,"queue worker 0x20":58.559,"queue worker 0x38":83.559,"queue worker 0x48":3.025,"queue worker 0x30":82.988,"queue worker 0x51":4.696,"queue worker 0x50":43.446},"top_phases_ms_per_frame":{"Driver.Packet":14472.703,"Driver.Packet.memory_wait":9587.032,"Driver.Packet.dispatch":2261.263,"Driver.Packet.draw":1797.523,"Driver.Draw":1793.000,"Driver.Dispatch":1762.886,"DrawPipeline.commit":1728.961,"Graphics.Draw":1583.262},"trace_dropped":false,"trace":"aps5-trace-a6ea328656e3-18376.json.gz"} ``` </details>
TheSovietWaffle commented 2026-10-20 07:40:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-20T07:40:12Z.


Tested on RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (1002:164e, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head 3bcacf596: agc_driver_depth_fast_clear_submit passes 3 of 3 on both GPUs.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285940862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6285940862). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-20T07:40:12Z. --- Tested on RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (`1002:164e`, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head `3bcacf596`: `agc_driver_depth_fast_clear_submit` passes 3 of 3 on both GPUs. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-20 20:33:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T20:33:32Z.

Review: CHANGES_REQUESTED


  • htileAfterMaskClear (DepthSurface.cpp:1435-1439) returns "cleared" without checking the ZMask bits of the mask: without stencil it never checks clear->mask & 0x3f0, and with stencil and a stencil value of 0 it returns before checking mask & 0xf0. The kernel computes (word & mask) | value, so a set mask bit keeps the earlier word's ZMask, which the description says must not happen ("the ZMask bits don't depend on the earlier words"). RecordedMaskClearClearsWithoutWait (DepthFastClearSubmit.cpp:284-286) fills words with a non-zero ZMask (0x010 & mask, ...) and still expects a cleared depth, so it pins this behaviour instead of catching it. Please require the ZMask bits of mask to be 0 and value to give a cleared ZMask in every branch, and add a case where the mask keeps a non-zero ZMask and the read-back path is expected.
  • The perf label needs the aps5-summary.jsonl line of main and of the change from the same title, scene and machine, plus tools/trace_digest.py output (bot comment above). The description says there is no main summary for the Yōtei scene; please capture both.
  • #7233 and #7371 change the same NoteHtileDepthClear call in Dispatch.cpp, and the thread with MarcZX10 agreed to sequence #7233 first; list it under Depends on and rebase once it lands.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5591358043 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#pullrequestreview-5591358043). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T20:33:32Z. **Review:** CHANGES_REQUESTED --- - `htileAfterMaskClear` (`DepthSurface.cpp:1435-1439`) returns "cleared" without checking the ZMask bits of the mask: without stencil it never checks `clear->mask & 0x3f0`, and with stencil and a stencil value of 0 it returns before checking `mask & 0xf0`. The kernel computes `(word & mask) | value`, so a set mask bit keeps the earlier word's ZMask, which the description says must not happen ("the ZMask bits don't depend on the earlier words"). `RecordedMaskClearClearsWithoutWait` (`DepthFastClearSubmit.cpp:284-286`) fills words with a non-zero ZMask (`0x010 & mask`, ...) and still expects a cleared depth, so it pins this behaviour instead of catching it. Please require the ZMask bits of `mask` to be 0 and `value` to give a cleared ZMask in every branch, and add a case where the mask keeps a non-zero ZMask and the read-back path is expected. - The `perf` label needs the `aps5-summary.jsonl` line of `main` and of the change from the same title, scene and machine, plus `tools/trace_digest.py` output (bot comment above). The description says there is no `main` summary for the Yōtei scene; please capture both. - #7233 and #7371 change the same `NoteHtileDepthClear` call in `Dispatch.cpp`, and the thread with MarcZX10 agreed to sequence #7233 first; list it under Depends on and rebase once it lands.
Celegans12 commented 2026-10-21 03:41:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-21T03:41:12Z.


Thanks for the careful read. I went through htileAfterMaskClear again, and I don't think a ZMask can survive there, because in this HTILE layout the ZMask is bits 3:0. That's the layout HtileFillClears and the expanded words on main use: a word clears the depth exactly when word & 0xf is 0. The first check in the function returns no clear, for every branch, when mask & 0xf or value & 0xf is non-zero. So whenever we report a clear, (word & mask) | value has ZMask 0.

The 0x3f0 bits aren't ZMask. With stencil in HTILE they hold the stencil state (SMem is 9:8). Without stencil they're part of Min/Max Z, which a cleared tile doesn't use (MixedClearedSliceClears on main already relies on that). In the stencil-0 branch the stencil is cleared as well, so the old stencil bits don't matter, and the store-back sets 0x3f0 anyway. That's also why the words in RecordedMaskClearClearsWithoutWait (0x010, 0x0a0, ...) only vary bits 4-9 and keep ZMask 0, so I left that test as it is.

You're right that the read-back case wasn't covered, though, so I added RecordedMaskKeepingZMaskReadsBack to agc_driver_depth_fast_clear_submit. It records a mask clear whose mask keeps the ZMask (0x3ff, or 0x0ff with stencil) over words with a non-zero ZMask. It expects the depth to stay as it was, and the bind to read the HTILE back. It passes on the branch. With the mask & 0xf check removed, it fails 3 of 3 times with "an HTILE mask clear that keeps non-zero ZMask bits cleared the depth". If I've got the layout wrong somewhere, point me at it and I'll change the check.

On Depends on: the current head doesn't use anything from #7233. It builds and passes on main alone, so I've left the field at none for now. Once #7233 lands, the plan is still to rebase onto its API (setting htileClearCompletion from the buffer branch, with a test next to MarcZX10's DriverDispatch case), and I'll change the field then. The main-vs-branch summary pair and the trace_digest.py output are still owed.

The branch is also rebased onto current main (dd0cb9849).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307465025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6307465025). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-21T03:41:12Z. --- Thanks for the careful read. I went through `htileAfterMaskClear` again, and I don't think a ZMask can survive there, because in this HTILE layout the ZMask is bits 3:0. That's the layout `HtileFillClears` and the expanded words on main use: a word clears the depth exactly when `word & 0xf` is 0. The first check in the function returns no clear, for every branch, when `mask & 0xf` or `value & 0xf` is non-zero. So whenever we report a clear, `(word & mask) | value` has ZMask 0. The 0x3f0 bits aren't ZMask. With stencil in HTILE they hold the stencil state (SMem is 9:8). Without stencil they're part of Min/Max Z, which a cleared tile doesn't use (`MixedClearedSliceClears` on main already relies on that). In the stencil-0 branch the stencil is cleared as well, so the old stencil bits don't matter, and the store-back sets 0x3f0 anyway. That's also why the words in `RecordedMaskClearClearsWithoutWait` (0x010, 0x0a0, ...) only vary bits 4-9 and keep ZMask 0, so I left that test as it is. You're right that the read-back case wasn't covered, though, so I added `RecordedMaskKeepingZMaskReadsBack` to `agc_driver_depth_fast_clear_submit`. It records a mask clear whose mask keeps the ZMask (0x3ff, or 0x0ff with stencil) over words with a non-zero ZMask. It expects the depth to stay as it was, and the bind to read the HTILE back. It passes on the branch. With the `mask & 0xf` check removed, it fails 3 of 3 times with "an HTILE mask clear that keeps non-zero ZMask bits cleared the depth". If I've got the layout wrong somewhere, point me at it and I'll change the check. On Depends on: the current head doesn't use anything from #7233. It builds and passes on main alone, so I've left the field at none for now. Once #7233 lands, the plan is still to rebase onto its API (setting `htileClearCompletion` from the buffer branch, with a test next to MarcZX10's `DriverDispatch` case), and I'll change the field then. The main-vs-branch summary pair and the `trace_digest.py` output are still owed. The branch is also rebased onto current main (dd0cb9849).
adriadam10 commented 2026-10-23 16:03:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T16:03:44Z.

Review: CHANGES_REQUESTED


Re-checked 18e8a7618 against the earlier review:

  • ZMask: you are right, I withdraw that point. htileAfterMaskClear returns no clear when mask & 0xf or value & 0xf is non-zero (DepthSurface.cpp:1685), and ZMask is bits 3:0, so the 0x3f0 bits are not ZMask. RecordedMaskKeepingZMaskReadsBack now pins the read-back case.
  • #7233 and #7371 are merged and the rebase onto htileClearCompletion plus the PM4 agc_driver_native_depth_buffer_clear test look right.
  • Still open: this is a perf PR. Please paste the aps5-summary.jsonl line of main and of the change from the same title, scene and machine, and the tools/trace_digest.py summaries of both (attach the traces). The Yōtei numbers from your own tree don't replace a main capture; if the Yōtei scene can't be run on main, a synthetic depth-clear scene run on both works.

Nothing else to change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5631005772 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#pullrequestreview-5631005772). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-23T16:03:44Z. **Review:** CHANGES_REQUESTED --- Re-checked 18e8a7618 against the earlier review: - ZMask: you are right, I withdraw that point. `htileAfterMaskClear` returns no clear when `mask & 0xf` or `value & 0xf` is non-zero (`DepthSurface.cpp:1685`), and ZMask is bits 3:0, so the `0x3f0` bits are not ZMask. `RecordedMaskKeepingZMaskReadsBack` now pins the read-back case. - #7233 and #7371 are merged and the rebase onto `htileClearCompletion` plus the PM4 `agc_driver_native_depth_buffer_clear` test look right. - Still open: this is a `perf` PR. Please paste the `aps5-summary.jsonl` line of `main` and of the change from the same title, scene and machine, and the `tools/trace_digest.py` summaries of both (attach the traces). The Yōtei numbers from your own tree don't replace a `main` capture; if the Yōtei scene can't be run on `main`, a synthetic depth-clear scene run on both works. Nothing else to change.
jotitadev commented 2026-10-30 17:41:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T17:41:11Z.

Review: COMMENTED


On the NVIDIA failure of agc_driver_native_depth_buffer_clear that @MarcZX10 asked about: it is not specific to that host. The test passes on the PR's own base and fails once the PR is merged with current main. Two merges from 28-30/10 now refuse the buffer kernel's HTILE write.

Setup: Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, lavapipe (Mesa 26.0.3; write-watch reports host imports keep write protection: yes). Head 18e8a7618d, main ed1e0ed08f.

tree agc_driver_native_depth_buffer_clear
PR merged onto its merge-base 3a2ca40dab passes
PR merged onto main ed1e0ed08f fails 3/3: compute shader ...: AGC graphics: sample-preserving guest publication of native multisample depth is not implemented (same message as the NVIDIA run)

Cause: a first-parent git bisect (PR merged at each step) lands on #11369 (26c20975ac, 28/10). It added RequireNoResidentDepthRead_nid_no_patch over every writable buffer range in GuestBufferMemory::UploadFinish. #6498 (341cf8beee, 30/10) then added RequireNoMultisampleTarget(..., "a shader buffer access") in ShaderResources::requireGuestBuffers.

The buffer variant of the mask clear binds the HTILE through a writable V#. Both checks see a buffer over the HTILE guard of a resident, host-written native 4x depth and throw, even though NoteHtileDepthClear already accepted that dispatch as the clear transition (clearPending). The global-store kernel does not go through a descriptor buffer, so DriverDispatch is unaffected. With both checks removed (diagnostic only), the focal passes 3/3. Removing only #11369's line still fails, because #6498's check catches it.

A fix that works here (22 lines, attached below): exempt a buffer range at those two call sites only when every resident depth guard it overlaps is the HTILE of a surface whose recognized clear is in flight (clearPending || clearGeneration != 0, no refusal). Anything else still goes through the existing checks, and CompleteHtileDepthClear still checks for racing CPU writes.

diff on top of the merge
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
index b29d2d0e3b..dfe967888a 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
@@ -40,6 +40,8 @@ std::uint64_t DirectDepthCopyCount();
 std::uint64_t MultisampledDepthBytes_nid_no_patch(VkExtent2D extent, std::uint32_t bytesPerTexel, std::uint32_t samples);
 void RequireNoResidentDepthRead_nid_no_patch(std::uint64_t address, std::size_t bytes);
 void AppendHostWrittenDepthRanges(std::uint64_t address, std::size_t bytes, std::vector<std::pair<std::uint64_t, std::uint64_t>>& ranges);
+// True when every resident native depth guard over the range is the HTILE of a surface whose recognized clear is in flight.
+bool AcceptedHtileClearCovers_nid_no_patch(std::uint64_t address, std::size_t bytes);
 bool HasResidentDepthGuards_nid_no_patch();
 void RetireUnmappedDepth_nid_no_patch(std::uintptr_t address, std::size_t bytes);
 void RequireNoNativeDepthFeedback_nid_no_patch(const Context& context, const DepthTarget& target, std::span<const std::shared_ptr<Texture>> sampled);
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
index ef143dde32..219c52c891 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
@@ -2161,6 +2161,22 @@ void AppendHostWrittenDepthRanges(std::uint64_t address, std::size_t bytes, std:
     }
 }
 
+bool AcceptedHtileClearCovers_nid_no_patch(std::uint64_t address, std::size_t bytes) {
+    if (bytes == 0u || !anyDepthGuard().load(std::memory_order_acquire)) return false;
+    std::lock_guard lock(surfacesMutex());
+    std::shared_lock guardLock(depthGuardMutex());
+    bool any = false;
+    for (const auto& range : depthGuards()) {
+        if (!(address < range.address + range.bytes && range.address < address + bytes)) continue;
+        const bool clearing = std::ranges::any_of(surfaces(), [&](const auto& surface) {
+            return surface->active == range.active && surface->samplingActive && surface->sampling.refusal.empty() && (surface->clearPending || surface->clearGeneration != 0u) && surface->sampling.initial[1].address == range.address && surface->sampling.initial[1].bytes == range.bytes;
+        });
+        if (!clearing) return false;
+        any = true;
+    }
+    return any;
+}
+
 void NoteDepthSurfaceWrite(const Context& context, const DepthTarget& target) {
     if (target.samples == 1u || !anyDepthGuard().load(std::memory_order_acquire)) return;
     std::lock_guard lock(surfacesMutex());
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
index 4658630beb..c25abf26cf 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
@@ -5450,7 +5450,9 @@ void GuestBufferMemory::UploadFinish(bool addressable) {
     if (space != nullptr) completeSpaceWrites();
     uploaded = true;
     for (const auto& region : regions) static_cast<void>(FlushDepthPlanes(region.begin, static_cast<std::size_t>(region.end - region.begin)));
-    for (const auto& [begin, end] : writes) RequireNoResidentDepthRead_nid_no_patch(begin, static_cast<std::size_t>(end - begin));
+    for (const auto& [begin, end] : writes) {
+        if (!AcceptedHtileClearCovers_nid_no_patch(begin, static_cast<std::size_t>(end - begin))) RequireNoResidentDepthRead_nid_no_patch(begin, static_cast<std::size_t>(end - begin));
+    }
     for (const auto& [begin, end] : writes) StorageTexture::FlushPending(begin, static_cast<std::size_t>(end - begin), nullptr, "written buffer range");
     if (context.hostImportAlignment != 0) {
         auto& state = Imports();
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
index e67f52d882..89e384febb 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
@@ -5910,7 +5910,7 @@ void ShaderResources::requireGuestBuffers(std::span<const MovedBuffer> moved) co
         const auto override = std::find_if(moved.begin(), moved.end(), [&](const MovedBuffer& entry) { return entry.allocation == index; });
         const auto address = override != moved.end() ? override->address : item.address;
         const auto bytes = override != moved.end() ? override->size : item.size;
-        RequireNoMultisampleTarget(address, bytes, "a shader buffer access");
+        if (!AcceptedHtileClearCovers_nid_no_patch(address, bytes)) RequireNoMultisampleTarget(address, bytes, "a shader buffer access");
     }
 }
 

With it, on the merge with ed1e0ed08f:

  • focal 3/3;
  • ^agc suite (without display/flip/lds64) 1129/1129 on lavapipe. main alone is 1128/1128; the extra test is the new one.
  • #11369's buffer-write cases (a GPU buffer write over the depth or HTILE released the unwritten surface, D16/D32 x 4/8 samples) and #6498's agc_driver_sample_multisample_target still pass.

The test also prints skipped native HTILE write-coverage assertion on lavapipe, both on the base and with the fix, so that assertion isn't exercised on this host.

The authors may prefer to put the exemption somewhere else (for example, passing htileClearCompletion down to the bind). I'm only showing that the guard interaction is the cause.

GPUs tested: lavapipe (Mesa 26.0.3) only.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5716281354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#pullrequestreview-5716281354). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-30T17:41:11Z. **Review:** COMMENTED --- On the NVIDIA failure of `agc_driver_native_depth_buffer_clear` that @MarcZX10 asked about: it is not specific to that host. The test passes on the PR's own base and fails once the PR is merged with current `main`. Two merges from 28-30/10 now refuse the buffer kernel's HTILE write. **Setup:** Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, lavapipe (Mesa 26.0.3; write-watch reports host imports keep write protection: yes). Head `18e8a7618d`, `main` `ed1e0ed08f`. | tree | `agc_driver_native_depth_buffer_clear` | |---|---| | PR merged onto its merge-base `3a2ca40dab` | passes | | PR merged onto `main` `ed1e0ed08f` | fails 3/3: `compute shader ...: AGC graphics: sample-preserving guest publication of native multisample depth is not implemented` (same message as the NVIDIA run) | **Cause:** a first-parent `git bisect` (PR merged at each step) lands on #11369 (26c20975ac, 28/10). It added `RequireNoResidentDepthRead_nid_no_patch` over every writable buffer range in `GuestBufferMemory::UploadFinish`. #6498 (341cf8beee, 30/10) then added `RequireNoMultisampleTarget(..., "a shader buffer access")` in `ShaderResources::requireGuestBuffers`. The buffer variant of the mask clear binds the HTILE through a writable V#. Both checks see a buffer over the HTILE guard of a resident, host-written native 4x depth and throw, even though `NoteHtileDepthClear` already accepted that dispatch as the clear transition (`clearPending`). The global-store kernel does not go through a descriptor buffer, so `DriverDispatch` is unaffected. With both checks removed (diagnostic only), the focal passes 3/3. Removing only #11369's line still fails, because #6498's check catches it. **A fix that works here** (22 lines, attached below): exempt a buffer range at those two call sites only when every resident depth guard it overlaps is the HTILE of a surface whose recognized clear is in flight (`clearPending || clearGeneration != 0`, no refusal). Anything else still goes through the existing checks, and `CompleteHtileDepthClear` still checks for racing CPU writes. <details><summary>diff on top of the merge</summary> ```diff diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp index b29d2d0e3b..dfe967888a 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp @@ -40,6 +40,8 @@ std::uint64_t DirectDepthCopyCount(); std::uint64_t MultisampledDepthBytes_nid_no_patch(VkExtent2D extent, std::uint32_t bytesPerTexel, std::uint32_t samples); void RequireNoResidentDepthRead_nid_no_patch(std::uint64_t address, std::size_t bytes); void AppendHostWrittenDepthRanges(std::uint64_t address, std::size_t bytes, std::vector<std::pair<std::uint64_t, std::uint64_t>>& ranges); +// True when every resident native depth guard over the range is the HTILE of a surface whose recognized clear is in flight. +bool AcceptedHtileClearCovers_nid_no_patch(std::uint64_t address, std::size_t bytes); bool HasResidentDepthGuards_nid_no_patch(); void RetireUnmappedDepth_nid_no_patch(std::uintptr_t address, std::size_t bytes); void RequireNoNativeDepthFeedback_nid_no_patch(const Context& context, const DepthTarget& target, std::span<const std::shared_ptr<Texture>> sampled); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp index ef143dde32..219c52c891 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp @@ -2161,6 +2161,22 @@ void AppendHostWrittenDepthRanges(std::uint64_t address, std::size_t bytes, std: } } +bool AcceptedHtileClearCovers_nid_no_patch(std::uint64_t address, std::size_t bytes) { + if (bytes == 0u || !anyDepthGuard().load(std::memory_order_acquire)) return false; + std::lock_guard lock(surfacesMutex()); + std::shared_lock guardLock(depthGuardMutex()); + bool any = false; + for (const auto& range : depthGuards()) { + if (!(address < range.address + range.bytes && range.address < address + bytes)) continue; + const bool clearing = std::ranges::any_of(surfaces(), [&](const auto& surface) { + return surface->active == range.active && surface->samplingActive && surface->sampling.refusal.empty() && (surface->clearPending || surface->clearGeneration != 0u) && surface->sampling.initial[1].address == range.address && surface->sampling.initial[1].bytes == range.bytes; + }); + if (!clearing) return false; + any = true; + } + return any; +} + void NoteDepthSurfaceWrite(const Context& context, const DepthTarget& target) { if (target.samples == 1u || !anyDepthGuard().load(std::memory_order_acquire)) return; std::lock_guard lock(surfacesMutex()); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp index 4658630beb..c25abf26cf 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp @@ -5450,7 +5450,9 @@ void GuestBufferMemory::UploadFinish(bool addressable) { if (space != nullptr) completeSpaceWrites(); uploaded = true; for (const auto& region : regions) static_cast<void>(FlushDepthPlanes(region.begin, static_cast<std::size_t>(region.end - region.begin))); - for (const auto& [begin, end] : writes) RequireNoResidentDepthRead_nid_no_patch(begin, static_cast<std::size_t>(end - begin)); + for (const auto& [begin, end] : writes) { + if (!AcceptedHtileClearCovers_nid_no_patch(begin, static_cast<std::size_t>(end - begin))) RequireNoResidentDepthRead_nid_no_patch(begin, static_cast<std::size_t>(end - begin)); + } for (const auto& [begin, end] : writes) StorageTexture::FlushPending(begin, static_cast<std::size_t>(end - begin), nullptr, "written buffer range"); if (context.hostImportAlignment != 0) { auto& state = Imports(); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp index e67f52d882..89e384febb 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp @@ -5910,7 +5910,7 @@ void ShaderResources::requireGuestBuffers(std::span<const MovedBuffer> moved) co const auto override = std::find_if(moved.begin(), moved.end(), [&](const MovedBuffer& entry) { return entry.allocation == index; }); const auto address = override != moved.end() ? override->address : item.address; const auto bytes = override != moved.end() ? override->size : item.size; - RequireNoMultisampleTarget(address, bytes, "a shader buffer access"); + if (!AcceptedHtileClearCovers_nid_no_patch(address, bytes)) RequireNoMultisampleTarget(address, bytes, "a shader buffer access"); } } ``` </details> With it, on the merge with `ed1e0ed08f`: - focal 3/3; - `^agc` suite (without display/flip/lds64) 1129/1129 on lavapipe. `main` alone is 1128/1128; the extra test is the new one. - #11369's buffer-write cases (`a GPU buffer write over the depth or HTILE released the unwritten surface`, D16/D32 x 4/8 samples) and #6498's `agc_driver_sample_multisample_target` still pass. The test also prints `skipped native HTILE write-coverage assertion` on lavapipe, both on the base and with the fix, so that assertion isn't exercised on this host. The authors may prefer to put the exemption somewhere else (for example, passing `htileClearCompletion` down to the bind). I'm only showing that the guard interaction is the cause. GPUs tested: lavapipe (Mesa 26.0.3) only. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-31 03:49:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T03:49:04Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The new process-wide HTILE-mask registry can mistake an unrelated write for a prior mask clear after a Recorder is recreated and its local write-note counter restarts.

What I ran

Reviewed head c8051ed3bab05296a22f49141a0553cefa10d837 against PR base de824c2919ca65086c6324a1e0388866a7327eea; the no-build merge preview against current main was clean. Environment: Linux x86_64, GCC 12.2.0, Python 3.11.2. I did not build or run C++/GPU tests.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 8105

Results

Check Result
Diff check and conventions Passed.
Dependency/mergeability preview Passed; clean against current main.
Hosted CI on this head Windows, conventions, library-portability, and labels were queued at the final check; Linux, relinker, ASAN, register-context, and write-watch were skipped. Eligibility and report passed.
Author-reported focused testing The author reports the guard regression reproduced 3/3 before the fix and passed 3/3 after it on an RTX 3080 Laptop; the eight focused tests passed with three repetitions on NVIDIA and once on Windows lavapipe. Linux, AMD, Intel, and title testing are reported as not run for this update.
Precheck helper execution The isolated checkout lacked the ABI and test-quality helper scripts; this is a precheck harness issue, not a PR failure.
Selected unedited precheck output
All conventions checks passed.
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-8105-c8051ed3bab0/head-c8051ed3bab0-acd88d27/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-8105-c8051ed3bab0/head-c8051ed3bab0-acd88d27/tools/pr_test_quality.py': [Errno 2] No such file or directory
Conclusion: checks failed

Negative control

Assertion Mutation/change Result
A stale mask record cannot authorize a later recorder's unrelated write Recreate the recorder, reuse the guest HTILE address and local write-note value, then call the readback path Not run; the current tests do not cover recorder identity reuse.

Findings

Blocking

HtileMaskWrite stores only the clear range/pattern and Recorder::PendingWritesOver's numeric note. htileAfterMaskClear accepts a record when its note equals Recorder::NewestWriteNote and the ranges cover. The write-note counter is per Recorder and starts at zero for each instance. The registry is process-static, capped at 64 entries, and otherwise entries survive until the 64-entry cap evicts them; ClearDepthSurfaces does not clear this registry. Thus a later recorder can produce the same note for an unrelated write to a reused guest address, causing the stale mask record to be accepted and the HTILE data to be expanded as if the old mask clear were still authoritative. This can produce incorrect depth/stencil contents.

Key each record and lookup to a unique recorder identity/generation (or make write-note IDs globally unique), and retire that recorder's records when its state is cleared. Add a regression test that recreates a recorder, reuses the address/note, and proves the unrelated write takes the ordinary readback path.

Non-blocking

The newly reported GPU regression fix and its focused tests are useful evidence, but they do not exercise this recorder-lifetime collision.

Sources

Not verified

I did not run builds, C++ tests, GPU tests, Linux/macOS validation, or console/title behavior. The author-provided GPU results were not independently reproduced.

To get this to a good state

Please bind mask records to a unique recorder generation, clean them up with that owner, and add the recorder-reuse regression test. I will rerun the same checks on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721024144 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#pullrequestreview-5721024144). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T03:49:04Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The new process-wide HTILE-mask registry can mistake an unrelated write for a prior mask clear after a `Recorder` is recreated and its local write-note counter restarts. ## What I ran Reviewed head `c8051ed3bab05296a22f49141a0553cefa10d837` against PR base `de824c2919ca65086c6324a1e0388866a7327eea`; the no-build merge preview against current `main` was clean. Environment: Linux x86_64, GCC 12.2.0, Python 3.11.2. I did not build or run C++/GPU tests. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 8105 ``` ## Results | Check | Result | |---|---| | Diff check and conventions | Passed. | | Dependency/mergeability preview | Passed; clean against current `main`. | | Hosted CI on this head | Windows, conventions, library-portability, and labels were queued at the final check; Linux, relinker, ASAN, register-context, and write-watch were skipped. Eligibility and report passed. | | Author-reported focused testing | The author reports the guard regression reproduced 3/3 before the fix and passed 3/3 after it on an RTX 3080 Laptop; the eight focused tests passed with three repetitions on NVIDIA and once on Windows lavapipe. Linux, AMD, Intel, and title testing are reported as not run for this update. | | Precheck helper execution | The isolated checkout lacked the ABI and test-quality helper scripts; this is a precheck harness issue, not a PR failure. | <details> <summary>Selected unedited precheck output</summary> ```text All conventions checks passed. /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-8105-c8051ed3bab0/head-c8051ed3bab0-acd88d27/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-8105-c8051ed3bab0/head-c8051ed3bab0-acd88d27/tools/pr_test_quality.py': [Errno 2] No such file or directory Conclusion: checks failed ``` </details> ## Negative control | Assertion | Mutation/change | Result | |---|---|---| | A stale mask record cannot authorize a later recorder's unrelated write | Recreate the recorder, reuse the guest HTILE address and local write-note value, then call the readback path | Not run; the current tests do not cover recorder identity reuse. | ## Findings ### Blocking `HtileMaskWrite` stores only the clear range/pattern and `Recorder::PendingWritesOver`'s numeric note. `htileAfterMaskClear` accepts a record when its note equals `Recorder::NewestWriteNote` and the ranges cover. The write-note counter is per `Recorder` and starts at zero for each instance. The registry is process-static, capped at 64 entries, and otherwise entries survive until the 64-entry cap evicts them; `ClearDepthSurfaces` does not clear this registry. Thus a later recorder can produce the same note for an unrelated write to a reused guest address, causing the stale mask record to be accepted and the HTILE data to be expanded as if the old mask clear were still authoritative. This can produce incorrect depth/stencil contents. Key each record and lookup to a unique recorder identity/generation (or make write-note IDs globally unique), and retire that recorder's records when its state is cleared. Add a regression test that recreates a recorder, reuses the address/note, and proves the unrelated write takes the ordinary readback path. ### Non-blocking The newly reported GPU regression fix and its focused tests are useful evidence, but they do not exercise this recorder-lifetime collision. ## Sources - [Registry lookup and note storage at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c8051ed3bab05296a22f49141a0553cefa10d837/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L1864-L1887) - [Mask-note registration and overlap eviction at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/c8051ed3bab05296a22f49141a0553cefa10d837/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2609-L2626) - [Per-instance write-note counter and initialization on current base](https://github.com/boykopovar/AnyPS5/blob/de824c2919ca65086c6324a1e0388866a7327eea/core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp#L863) - [Recorder construction and device cleanup on current base](https://github.com/boykopovar/AnyPS5/blob/de824c2919ca65086c6324a1e0388866a7327eea/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L1147), [depth-surface cleanup](https://github.com/boykopovar/AnyPS5/blob/c8051ed3bab05296a22f49141a0553cefa10d837/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2689-L2703) - [Author's report of the guard fix and GPU runs](https://github.com/boykopovar/AnyPS5/pull/8105#issuecomment-6538589146) ## Not verified I did not run builds, C++ tests, GPU tests, Linux/macOS validation, or console/title behavior. The author-provided GPU results were not independently reproduced. ## To get this to a good state Please bind mask records to a unique recorder generation, clean them up with that owner, and add the recorder-reuse regression test. I will rerun the same checks on the new head.
adriadam10 commented 2026-10-31 03:50:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-31T03:50:42Z.

Review: CHANGES_REQUESTED


Thanks for the guard fix. Agreeing with @MarcZX10's blocking point, checked against the code:

  • HtileMaskWrite (DepthSurface.cpp:1864) stores only the clear and a write-note number, and htileAfterMaskClear (DepthSurface.cpp:1886) accepts a record when write.note == newest and the ranges cover. The note is Recorder::writeNoteCount, a per-instance counter that starts at 0 (Recorder.cpp:3000), while htileMasks() is process-static and ClearDepthSurfaces (DepthSurface.cpp:2689) does not touch it. After a device/recorder is recreated, an unrelated write to a reused HTILE address can get the same note and be expanded as if the old mask clear were still pending.
  • Fix: key each record to its owner (the recorder, or a generation that is unique per recorder), compare it in htileAfterMaskClear, and erase the owner's records in ClearDepthSurfaces for that device.
  • Test: recreate the recorder, reuse the HTILE address and the same note value for an ordinary write, and assert the bind takes the readback path (words read back, ThreadHookWaits increases). It must fail without the owner check.

The guard change itself (recognized clear's range passed through preparation, upload and binding, only for the pending native owner, no resource/recipe cache) looks right to me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721035034 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8105#pullrequestreview-5721035034). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-31T03:50:42Z. **Review:** CHANGES_REQUESTED --- Thanks for the guard fix. Agreeing with @MarcZX10's blocking point, checked against the code: - `HtileMaskWrite` (`DepthSurface.cpp:1864`) stores only the clear and a write-note number, and `htileAfterMaskClear` (`DepthSurface.cpp:1886`) accepts a record when `write.note == newest` and the ranges cover. The note is `Recorder::writeNoteCount`, a per-instance counter that starts at 0 (`Recorder.cpp:3000`), while `htileMasks()` is process-static and `ClearDepthSurfaces` (`DepthSurface.cpp:2689`) does not touch it. After a device/recorder is recreated, an unrelated write to a reused HTILE address can get the same note and be expanded as if the old mask clear were still pending. - Fix: key each record to its owner (the recorder, or a generation that is unique per recorder), compare it in `htileAfterMaskClear`, and erase the owner's records in `ClearDepthSurfaces` for that device. - Test: recreate the recorder, reuse the HTILE address and the same note value for an ordinary write, and assert the bind takes the readback path (words read back, `ThreadHookWaits` increases). It must fail without the owner check. The guard change itself (recognized clear's range passed through preparation, upload and binding, only for the pending native owner, no resource/recipe cache) looks right to me.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
boykopovar/AnyPS5!8105
No description provided.