Repository navigation
fix(agc): store resident linear color targets at completion points, limited to their drawn rectangles - #9685
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
The focused code review found a correctness gap in rectangle tracking. I ran python3 tools/check_conventions.py --base upstream/main --head refs/review/9685 with the PR title/body; it passed. GitHub’s product build/test jobs are skipped for this draft. I could not run the new AGC runtime tests in this checkout: there is no build configured for this head, and this host is the Xeon E5-1620 v2 used in prior Vulkan attempts that lacks the required CPU features. I did not treat the author’s Windows/Radeon runs as locally reproduced.
Please preserve the exact union of drawn row spans (or otherwise ensure the store cannot cover pixels between disjoint scissors), and add a regression that CPU-writes into such an internal gap after both draws. The present test’s two scissors have a bounding-box gap, but its sentinels are outside the bounding box; it therefore does not check that case. The repository performance-report rule also calls for the actual matching main and change summary lines with traces attached; the table is useful, but the traces/raw report are not attached here.
| } | ||
| drawnLeft = std::min(drawnLeft, left); | ||
| drawnTop = std::min(drawnTop, top); | ||
| drawnRight = std::max(drawnRight, right); |
There was a problem hiding this comment.
These min/max updates turn multiple scissor rectangles into their bounding box. With the test's first and second rectangles, e.g. pixels around (30, 6) lie inside that box but outside both draws. drawnSpans() then includes those pixels, so a CPU write there in the same write-watch block can be overwritten by writeback. Please track the union of row spans (or prove a safe alternative) and add a CPU sentinel in this internal gap; the current test only places sentinels outside the bounding box.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
jotitadev
left a comment
There was a problem hiding this comment.
Ran this on NVIDIA and lavapipe on Linux, which the PR lists as not tested. One part of the new coverage only runs on the NVIDIA card here, so CI's lavapipe doesn't guard it.
Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON, head c95a0fd31 (base d6eafa54d). The green and mutation rows were run on both 9d5263767 and c95a0fd31 with the same result; the red row on 9d5263767, whose tests c95a0fd31 does not change, ANYPS5_REQUIRE_VULKAN=1. GPUs: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), each picked with ANYPS5_GPU and checked in the Selected GPU line.
| RTX 3070 | lavapipe | |
|---|---|---|
the 6 new agc_driver_linear_target_* entries, this PR |
3/3 | 3/3 |
9 related (agc_driver_linear_target*, agc_driver_address_passes*), this PR |
3/3 | 3/3 |
red: d6eafa54d production files + the new tests |
completion_stores, cpu_writes, rectangle_bound fail; the 3 completion_points pass |
same |
mutation: ownNotes.clear() right before the PendingWriterSerial check in StorageTexture::FlushPending |
completion_stores fails |
6/6 pass |
The two devices take different branches of the tests:
- lavapipe:
[write-watch] host imports resolve write protection: yes, so the target is not write-watched.completion_storesprintsthe target is outside the write watch ... the submission checks are skipped, and theflip, write-watched memorycase ofcompletion_pointsruns withwatched at the store: 0. - RTX 3070:
host imports resolve write protection: no ... imported ranges stay watched, so the target stays watched, thewatched at the store: 1case runs, andcompletion_storesmakes itsrecorder->Submissions()checks.
With the mutation, a store waits for the target's previous store again, which is the "a store no longer waits for the same target's previous store" part of this PR. On the 3070 completion_stores catches it with the second label: storing the drawn linear target before the label waited for recorded work (1 submissions). On lavapipe all six pass, because those checks are skipped there. So a regression of that part would pass CI.
ctest -R "^agc" -j1 on the 3070 (867 tests, without the flip, DCC display and 64-bit LDS atomics tests): everything passes except agc_driver_sample_order, _grid_reference and _recipe_depth_locations, which fail the same way on d6eafa54d here (#9313).
GPUs tested: NVIDIA GeForce RTX 3070, driver 595.99.02, Ubuntu 26.04; lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
|
@MarcZX10 thanks, both points hold. Bounding box replaced by the exact union ( The regression is in Review fixes since your review. Two independent reviews of the first commit (huy's, and a four-dimension review on my side with an adversarial check of each finding) agree on these.
Left as they are:
Summary lines. PPSA14363, MGS1's PS1 part, with the targets resident through #1191's import line, applied locally on both sides (so both lines show
The summary lines of the trace window (200 to 220 s), {"commit":"d6eafa54d046","dirty":true,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":5724,"ms":20187.184},"presents":170,"frame_ms":{"p50":17.361,"p90":286.919,"p99":338.727,"max":339.723},"gpu_busy_ms_per_present":95.308,"worker_busy_pct":{"queue worker 0x0":90.450},"top_phases_ms_per_frame":{"Driver.Packet":107.404,"Graphics.Draw":106.712,"Graphics.Draw.draw_and_resource_release":106.333,"Recorder.Sync":102.637,"Driver.Packet.draw":100.244,"Driver.Draw":100.203,"Driver.Draw.draw_enqueued":98.609,"VideoOut.Flip":5.066},"trace_dropped":false,"trace":"aps5-trace-d6eafa54d046-7736.json.gz"}{"commit":"e430b0d07ab2","dirty":true,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":11855,"ms":20003.149},"presents":1199,"frame_ms":{"p50":16.684,"p90":16.920,"p99":17.372,"max":17.645},"gpu_busy_ms_per_present":1.676,"worker_busy_pct":{"queue worker 0x0":6.284},"top_phases_ms_per_frame":{"VideoOut.Flip":13.315,"VideoOut.Flip.vblank_wait":12.638,"Driver.Packet":1.046,"Driver.Packet.draw":0.705,"Driver.Draw":0.691,"Graphics.Draw":0.618,"VideoOut.Flip.present":0.594,"Driver.Present":0.591},"trace_dropped":false,"trace":"aps5-trace-e430b0d07ab2-1592.json.gz"}
|
| # | seconds | presents | p50 | p90 | p99 | max | GPU busy | busiest worker | largest phase |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0-10 | 502 | 16.7 | 17.1 | 40.4 | 841.9 | 1.3 | 2 % | VideoOut.Flip 12.1 |
| 2 | 10-20 | 594 | 16.7 | 17.0 | 19.6 | 80.3 | 1.5 | 3 % | VideoOut.Flip 5.4 |
| 3 | 20-30 | 576 | 16.7 | 16.9 | 20.2 | 304.6 | 5.2 | 8 % | VideoOut.Flip 13.7 |
| 4 | 30-40 | 600 | 16.7 | 17.0 | 23.8 | 24.6 | 3.3 | 9 % | VideoOut.Flip 10.5 |
| 5 | 40-50 | 600 | 16.7 | 16.9 | 23.4 | 24.1 | 3.6 | 13 % | VideoOut.Flip 11.0 |
| 6 | 50-60 | 509 | 16.7 | 41.3 | 41.8 | 42.3 | 6.2 | 27 % | VideoOut.Flip 10.0 |
| 7 | 60-70 | 436 | 20.1 | 43.9 | 44.6 | 44.7 | 11.1 | 47 % | Driver.Packet 10.8 |
| 8 | 70-80 | 562 | 16.7 | 21.1 | 47.7 | 48.2 | 6.3 | 32 % | VideoOut.Flip 10.2 |
| 9 | 80-90 | 169 | 17.0 | 128.6 | 225.0 | 230.4 | 44.6 | 82 % | Driver.Packet 48.8 |
| 10 | 90-100 | 168 | 68.0 | 120.5 | 127.7 | 132.4 | 44.8 | 82 % | Driver.Packet 49.0 |
| 11 | 100-110 | 138 | 98.7 | 127.3 | 461.5 | 480.0 | 53.8 | 85 % | Driver.Packet 61.6 |
| 12 | 110-120 | 70 | 186.1 | 342.8 | 435.4 | 435.4 | 121.0 | 91 % | Driver.Packet 132.4 |
| 13 | 120-130 | 153 | 16.3 | 162.8 | 202.7 | 205.8 | 49.6 | 82 % | Driver.Packet 53.8 |
| 14 | 130-140 | 129 | 88.8 | 168.6 | 182.6 | 183.0 | 61.1 | 85 % | Driver.Packet 67.0 |
| 15 | 140-151 | 108 | 147.7 | 188.9 | 204.0 | 206.1 | 73.1 | 88 % | Driver.Packet 81.8 |
| 16 | 151-161 | 126 | 16.8 | 184.4 | 542.9 | 567.7 | 61.0 | 87 % | Driver.Packet 69.7 |
| 17 | 161-171 | 46 | 366.7 | 481.7 | 520.1 | 520.1 | 189.0 | 94 % | Driver.Packet 210.8 |
| 18 | 171-181 | 50 | 362.6 | 421.5 | 444.9 | 444.9 | 174.3 | 94 % | Driver.Packet 194.0 |
| 19 | 181-191 | 74 | 207.8 | 297.5 | 367.2 | 367.2 | 114.0 | 91 % | Driver.Packet 124.8 |
| 20 | 191-202 | 134 | 82.2 | 167.0 | 193.2 | 201.2 | 58.7 | 86 % | Driver.Packet 64.7 |
| 21 | 202-212 | 88 | 17.4 | 249.6 | 286.9 | 286.9 | 92.0 | 90 % | Driver.Packet 103.9 |
| 22 | 212-222 | 70 | 214.0 | 314.9 | 339.7 | 339.7 | 115.7 | 90 % | Driver.Packet 130.2 |
| 23 | 222-232 | 60 | 283.8 | 345.4 | 370.2 | 370.2 | 139.6 | 93 % | Driver.Packet 156.2 |
| 24 | 232-242 | 74 | 195.6 | 313.6 | 329.6 | 329.6 | 113.8 | 91 % | Driver.Packet 124.6 |
| 25 | 242-252 | 82 | 16.8 | 276.7 | 300.8 | 300.8 | 99.5 | 90 % | Driver.Packet 110.9 |
| 26 | 252-262 | 83 | 16.9 | 273.7 | 300.3 | 300.3 | 98.8 | 90 % | Driver.Packet 108.4 |
| 27 | 262-272 | 156 | 85.0 | 137.3 | 143.3 | 145.2 | 48.5 | 82 % | Driver.Packet 53.0 |
| 28 | 272-282 | 145 | 16.8 | 112.3 | 546.6 | 559.0 | 51.4 | 84 % | Driver.Packet 59.2 |
| 29 | 282-293 | 54 | 16.7 | 556.9 | 574.4 | 574.4 | 155.0 | 92 % | Driver.Packet 174.4 |
p99 ms _....___=:##---@%#*-=+*+++:@@ 0-574.4
gpu ms ......_.::-*:---@%+-=*#+++::# 0-189.0
This PR e430b0d07a + import line:
29 intervals, 0.0 to 290.3 s, 17255 presents
AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1 (AMD proprietary shader compiler), Windows 10.0.26200, 1920x1080, commit e430b0d (dirty)
| # | seconds | presents | p50 | p90 | p99 | max | GPU busy | busiest worker | largest phase |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0-10 | 503 | 16.7 | 17.0 | 30.5 | 801.0 | 1.3 | 2 % | VideoOut.Flip 12.6 |
| 2 | 10-20 | 594 | 16.7 | 17.0 | 22.4 | 77.9 | 1.8 | 3 % | VideoOut.Flip 3.3 |
| 3 | 20-30 | 574 | 16.7 | 16.9 | 24.4 | 304.1 | 4.9 | 8 % | VideoOut.Flip 12.6 |
| 4 | 30-40 | 598 | 16.7 | 17.3 | 19.0 | 40.3 | 1.4 | 2 % | VideoOut.Flip 4.0 |
| 5 | 40-50 | 598 | 16.7 | 17.3 | 18.3 | 36.4 | 1.4 | 2 % | VideoOut.Flip 2.5 |
| 6 | 50-60 | 600 | 16.7 | 17.7 | 18.2 | 18.9 | 1.5 | 2 % | VideoOut.Flip 2.3 |
| 7 | 60-70 | 600 | 16.8 | 17.6 | 18.0 | 18.7 | 1.7 | 3 % | VideoOut.Flip 2.3 |
| 8 | 70-80 | 600 | 16.7 | 17.3 | 18.1 | 19.6 | 2.4 | 2 % | VideoOut.Flip 7.4 |
| 9 | 80-90 | 600 | 16.7 | 16.9 | 17.3 | 17.4 | 3.4 | 6 % | VideoOut.Flip 13.7 |
| 10 | 90-100 | 600 | 16.7 | 16.9 | 17.2 | 17.3 | 1.9 | 8 % | VideoOut.Flip 12.8 |
| 11 | 100-110 | 600 | 16.7 | 16.9 | 17.4 | 17.6 | 1.7 | 9 % | VideoOut.Flip 12.3 |
| 12 | 110-120 | 600 | 16.7 | 16.9 | 17.2 | 18.9 | 1.7 | 6 % | VideoOut.Flip 13.2 |
| 13 | 120-130 | 600 | 16.7 | 16.9 | 17.2 | 17.4 | 1.7 | 5 % | VideoOut.Flip 13.8 |
| 14 | 130-140 | 600 | 16.7 | 16.9 | 17.2 | 17.3 | 1.6 | 3 % | VideoOut.Flip 14.7 |
| 15 | 140-150 | 600 | 16.7 | 16.9 | 17.4 | 17.6 | 3.0 | 3 % | VideoOut.Flip 15.0 |
| 16 | 150-160 | 600 | 16.7 | 16.9 | 17.2 | 17.8 | 5.4 | 4 % | VideoOut.Flip 14.5 |
| 17 | 160-170 | 600 | 16.7 | 16.9 | 17.2 | 17.5 | 5.4 | 4 % | VideoOut.Flip 14.6 |
| 18 | 170-180 | 600 | 16.7 | 16.9 | 17.2 | 17.5 | 5.4 | 4 % | VideoOut.Flip 14.5 |
| 19 | 180-190 | 600 | 16.7 | 16.9 | 17.3 | 17.6 | 5.3 | 4 % | VideoOut.Flip 14.6 |
| 20 | 190-200 | 600 | 16.7 | 16.9 | 17.2 | 17.4 | 1.6 | 6 % | VideoOut.Flip 13.5 |
| 21 | 200-210 | 600 | 16.7 | 16.9 | 17.4 | 17.6 | 1.7 | 6 % | VideoOut.Flip 13.3 |
| 22 | 210-220 | 588 | 16.7 | 16.9 | 17.4 | 217.1 | 1.7 | 6 % | VideoOut.Flip 13.7 |
| 23 | 220-230 | 600 | 16.7 | 16.9 | 17.2 | 17.4 | 1.7 | 6 % | VideoOut.Flip 13.3 |
| 24 | 230-240 | 600 | 16.7 | 16.9 | 17.2 | 17.7 | 1.7 | 6 % | VideoOut.Flip 13.4 |
| 25 | 240-250 | 600 | 16.7 | 16.9 | 17.3 | 17.4 | 1.7 | 6 % | VideoOut.Flip 13.4 |
| 26 | 250-260 | 600 | 16.7 | 16.9 | 17.3 | 17.7 | 1.7 | 6 % | VideoOut.Flip 13.3 |
| 27 | 260-270 | 600 | 16.7 | 16.9 | 17.3 | 17.8 | 1.7 | 6 % | VideoOut.Flip 13.4 |
| 28 | 270-280 | 600 | 16.7 | 16.9 | 17.3 | 17.4 | 1.7 | 6 % | VideoOut.Flip 13.3 |
| 29 | 280-290 | 600 | 16.7 | 16.9 | 17.3 | 17.4 | 1.7 | 6 % | VideoOut.Flip 13.4 |
p99 ms @##*+++++++++++++++++++++++++ 0-30.5
gpu ms :-%::--=*-----+@@@@---------- 0-5.4
The trace files stay local, because the runs come from a commercial title; I asked on #9373 whether summary lines plus the tools' output are enough for such a title (comment).
A local counter over a 300 s run of the PS1 part (not committed) shows every store of these targets covering one rectangle, with no store at a draw and no fallback, so the 16-rectangle limit costs this title nothing.
Tested on e430b0d07a, RX 6700 XT, AMD Windows driver 32.0.21045.16010:
- The focused set of 15 tests passes 3 of 3: the 4 new executables (6
ctestentries),agc_driver_linear_target_resident,agc_driver_address_passesand_targets_split,agc_driver_clamped_global_fill,agc_driver_flip_stores_small_results,agc_driver_storage_flush_ordering,agc_driver_storage_read_during_idle_store,agc_driver_store_idle_resultsandagc_driver_store_over_untracked. - Khronos validation layer, the same 15 tests: 15 of 15 pass on
e430b0d07a. Withmain's production files atd6eafa54d0and these tests, 12 of 15 pass:completion_stores,cpu_writesandrectangle_boundfail, the last with all 3 outside sentinels and both sentinels between the rectangles lost. Both sides have 0VUID-lines, andVK_LOADER_DEBUG=layershows the layer inserted 25 times with no "was not found". - Red, one fix at a time: without the
AccessKeptByCpucheck,cpu_writesfails at the new driver read ("a driver read of row 0 before the store: pixel (0, 0) holds (0.000000, 0.000000, 0.000000, 1.000000), not the second draw's"). Witha27273ab06's bounding box,rectangle_boundfails as above. ctest -R "^agc_"(896 tests): 891 pass. The 5 failures are the onesmaind6eafa54d0has on this GPU and toolchain:agc_driver_sample_order,_grid_reference,_recipe_depth_locations,agc_driver_tessellationandagc_driver_image_array_window_past_layer_limit.tools/check_conventions.pypasses.
The description is updated to match.
|
The current overlap report flags #8246 for the shared I author #8246 and am available to coordinate. Could you clarify whether both PRs are intended to land as complementary changes, and if so which should merge first? If #9685 is instead intended to supersede #8246, please make that scope explicit for maintainers. I’m not asking for either PR to be preferred; the goal is a clear, non-conflicting sequence. |
|
Three more commits, from an independent review of
Tested on
|
|
@MarcZX10, sorry, my comment of 19:03Z went out without an answer to this one. Complementary, not a replacement. #9685 does not supersede #8246. The two split #8152 by ownership:
Proposed order: #9685 first, then #8246 with
Conflicts between the two heads (
The shared file. If you agree, I'll write the order into #9685's checklist and Overlap section; #9685 stays |
adriadam10
left a comment
There was a problem hiding this comment.
The full Linux Build (llvmpipe, run 39837492452) fails on the new test at 10a8319a94:
agc_driver_linear_target_draw_bindings:AGC graphics: the second copying draw submitted recorded work(LinearTargetDrawBindings.cpp:299,recorder->Submissions() == submitted + 1).maindoes not have this test, so it is not a pre-existing failure.- The runner has no
/dev/udmabuf(shared direct memory is copied instead of imported,dma-buf imports keep write protection: unknown), and the test passesHostImportFor(...)anyway, so the import here is not write-watched. With that, the second copying draw ends up submitting an extra batch.
Please decide whether that extra submit is correct for an unwatched import (then the test should assert what holds in both cases), or whether the store before a synchronous draw (10a8319a94) should not submit there. Either way the test has to pass on the CI runner, which cannot import dma-bufs; the earlier lavapipe runs from @jotitadev predate this test.
The rest of the diff is unchanged from the previous review.
|
Linux data point on @MarcZX10's CI question, since the runner's failure is the one thing left: llvmpipe (LLVM 23.1.1, 256 bits) via lavapipe, Mesa 26.2.4 (CI has 25.2.8), It is not the missing What submits. Breaking on A/B on the same binary and device. AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Thanks for the update. The PR now addresses the previously identified rectangle-union gap and reports the new completion-point / CPU-write coverage. However, the current exact head still has an unresolved CI-specific failure from the latest independent review: agc_driver_linear_target_draw_bindings fails 3/3 on the unwatched import path (the default and llvmpipe/CI path) because the second copying draw submits an extra batch. Please resolve that expectation/behavior and rerun the focused test on the CI-relevant path; the current hosted product jobs are skipped. I have not rerun locally because this host cannot execute the required Vulkan path.
10a8319 to
e5edf0c
Compare
|
@adriadam10 @MarcZX10, thanks, and thanks @Dextroid17 for the backtrace: it was exactly right. The extra submit is correct for memory outside the write watch. The second copying draw reads its source through an address, so its own store of the drawn linear targets also stores
Rebased onto The order with #8246 stays as proposed above: this PR first. |
…imited to their drawn rectangle A recorded draw into a resident linear color target stored the whole image to guest memory right after the draw. Every draw copied the full surface, waited for the previous draw's store in the open batch (the pending-writer check of FlushPending), and the recorded copy landed over CPU stores made after Draw returned (boykopovar#8152). A draw now records its scissor, clipped to the image, as a union rectangle in the target and lists the target as drawn. The listed targets are stored before each point where the guest can first observe the draws' completion: a flip (inside its locked block, before the flip's submit, so the flip's end-of-pipe interrupt and the presenter follow the store), a drain (which covers APS5_SYNC_FLIP=1), VulkanDevice::WaitIdle, a label the GPU writes for the graphics queue (WriteLabelOnGpu), and an interrupt-only RELEASE_MEM in preparePacketMemory and in commitLabel, which submit the store's batch before the interrupt can be delivered. The idle store, the access hooks and the eviction store are unchanged and also store by rectangle. A store of a drawn target copies the rectangle out of the image and writes it row by row at the guest pitch into the host import, stamped with one MarkWritten per run of 64 KiB blocks. A block that only other driver stores wrote since the target's generation keeps the old rule. In a block the CPU wrote, or that changed outside the write watch, only the rectangle's rows are stored, so CPU stores outside the rectangle stay, and the target re-uploads at its next use. A target with an attachment proxy, several mips or layers, a 3D or DCC surface, or results of a dispatch, fill or copy is stored whole at the same points. A store no longer waits for the same target's previous store: the pending-writer check skips the write notes of the target's own stores when it has a host import. APS5_PROFILE_DRAW adds the drawn targets' stores by reason and the pending drawn targets (count, MiB, oldest) to the [storage] line. The tests cover a target that stays pending across draws and labels until WaitIdle without a submission, boykopovar#8152's CPU stores after Draw (ported from boykopovar#8246, seeded and unseeded, inside and outside the write watch), CPU stores outside the drawn rectangle and in the gap before a target that starts past a 64 KiB boundary, and a flip, a drain, a label and an interrupt-only RELEASE_MEM through AgcDriver::Submit with the queue held by a WAIT_REG_MEM, inside and outside the write watch. Co-Authored-By: Claude <noreply@anthropic.com>
…ouches their memory With the store deferred to completion points, a draw or dispatch that reads a drawn linear target's guest memory through an address, or writes it through a buffer, saw the bytes from before the draw that rendered it, and the later rectangle store would land over its writes. agc_driver_address_passes caught the read: a draw reading through the address table the linear target the previous draw rendered read the bytes before it, where the per-draw store had stored them first. Before a recorded draw and a dispatch, the drawn targets whose memory the work reads in place or writes are stored, and all of them for address-based work, whose memory is unknown. Co-Authored-By: Claude <noreply@anthropic.com>
- A flush from a thread without the GPU lock takes the lock before it takes a drawn target out of the pending set, so a flip, label or interrupt on the queue worker cannot run between the two and get ahead of the target's store. - A label written on the GPU stores the drawn targets first and submits that store with the label, so the label's end-of-pipe interrupt is not held back to a later submission. - The pending-writer check skips the target's own earlier stores only when the flush stores that target alone. Co-Authored-By: Claude <noreply@anthropic.com>
…U-kept hooks - MarkDrawn registers the scissor while any layer is pending instead of while the image is dirty. A flush on another thread can take the image out of the pending set between MarkSliceDirty and the registration; layerPending changes only under the GPU lock, so the flusher, which reads the drawn area after taking that lock, stores the widened area. - AccessKeptByCpu no longer skips or evicts a drawn target. Its store writes CPU-stamped blocks inside the drawn rectangle, so the hook's CPU-kept rule would drop the draw's results. - A drawn target that is stored whole keeps main's rule that CPU-written 64 KiB blocks stay the CPU's. - A linear target that is no longer cached is stored after its draw, as before: the pending registry holds raw pointers. - LinearTargetCompletionPoints skips without host import, where the target is never resident. LinearTargetCpuWrites adds a driver read of the target between the CPU stores and the store. Co-Authored-By: Claude <noreply@anthropic.com>
|
@thuanquang I checked d6d8966. The merge retains the reviewed per-block fix and preserves both sides of the CMake test registrations. Thanks for the focused and validation reports. My source verdict carries; full final-head CI and the required game gate remain, including the direct-write test’s watched held-order output. |
|
@thuanquang the overlap check pairs this stack (#9685, #9879, #10656) with #10886, which keeps Proposal: your stack goes first, and #10886 rebases onto each PR as it merges (it declares them in |
|
@oneandonlydean Results for the final composition: Direct-write test, held-order output ( Import creation (#9879's test, same build, no "only the compared cases run" line): Focused set: the PRs' focused set plus Validation layer, same 57 entries,
Watched-import game check, PPSA14363 (own dump), with the composition's libraries (the summary lines carry Neither Not run here: Linux, and your full CI on both heads (on |
|
@thuanquang The reported vkAllocateMemory result -1000072003 is VK_ERROR_INVALID_EXTERNAL_HANDLE; the out-of-host/device-memory results are -1 and -2. The 76 MiB heap budget alone does not explain that error. Please preserve and attach the failed host_import_windows log and the import/allocation parameters around the remapped range, including its mapping generation, so the cause can be checked. The later alternating passes are useful, but do not identify the cause of the failed re-import. Please keep that failure distinct from the three failures shared with main. |
|
@oneandonlydean Here is what we have on that failure, kept apart from the three that Log. The whole output of the failing Parameters and the remapped range.
What we could and could not reproduce. On a build whose AGC driver is
So neither pinned memory in another process nor a per-process limit lowers the test's budget or makes the import fail. At 13:54:31 the PC itself was out of commit. Windows had logged "Virtual Memory Minimum Too Low" at 13:33. A hung process held 16 GB of commit. Two other processes aborted at 13:54:50, 19 s after this test, on allocation failures. The most likely reading is that AMD's Windows driver reports a host-pointer import that fails under system-wide commit exhaustion as Full output of the failing entry (round 3) |
The stamped-write skip now applies under the same condition as the own-store skip of boykopovar#9685: the flush stores a single image and that image has a host import. A flush of several images, or of an image without an import, waits for stamped writes as before. StorageFlushOrdering checks a single image stored again (the flush must not wait when the image has an import, and must wait without one) and two adjacent images stored again together (the flush must wait). A second registration runs the stored-again cases with APS5_NO_HOST_IMPORT=1.
The stamped-write skip now applies under the same condition as the own-store skip of boykopovar#9685: the flush stores a single image and that image has a host import. A flush of several images, or of an image without an import, waits for stamped writes as before. StorageFlushOrdering checks a single image stored again (the flush must not wait when the image has an import, and must wait without one) and two adjacent images stored again together (the flush must wait). A second registration runs the stored-again cases with APS5_NO_HOST_IMPORT=1.
Main's #9685 adds its drawn linear target figures to the end of the [storage] profile line, where this branch adds its refresh-proof counts; the merge keeps both, this branch's counts first.
Main's #9685 excepts drawn resident linear targets from the pending storage-image results entry and adds two entries after it; this branch rewrites the rest of that entry and adds its host-write entry. The merge keeps both: main's opening, this branch's text, main's two entries, then this branch's entry.
What
A recorded draw into a resident linear color target stored the whole image to guest memory right after the draw (
keepRecordedDraw'sFlushPending(..., "linear target")). Every draw copied the full surface and waited for the previous draw's store in the open batch (the pending-writer check ofFlushPending). The recorded copy also landed over CPU stores made afterDrawreturned (#8152).A draw now records its scissor, clipped to the image, in the target, and lists the target as drawn. The target keeps the rectangles themselves; two merge only when their union is a rectangle. The listed targets are stored before each point where the guest can first observe that the draws completed:
APS5_SYNC_FLIP=1;VulkanDevice::WaitIdle;WriteLabelOnGpu);RELEASE_MEMinpreparePacketMemoryand incommitLabel, which submit the store's batch before the interrupt can be delivered.The idle store, the access hooks and the eviction store run as before, and they also store by rectangles. The CPU-kept access hook no longer skips or evicts a drawn target, because that target's store writes CPU-written blocks inside its rectangles. This is the synchronization contract with regression coverage that @MarcZX10 asked for on #9217 (proposal).
A store of a drawn target copies the rectangles' bounding box out of the image and writes, row by row at the guest pitch, only the union of the rectangles' column runs on each row into the host import. Each run of 64 KiB blocks gets one
MarkWritten.main's rule that CPU-written 64 KiB blocks stay the CPU's.A store no longer waits for the same target's previous store: when the target has a host import, the pending-writer check skips the write notes of the target's own stores.
APS5_PROFILE_DRAWadds the drawn targets' stores by reason, and the pending drawn targets (count, MiB, oldest), to the[storage]line.With stores at completion points, #8126's rule that keeps newer image results over a direct write's completion stamp (
StampKeepingNewerResults) also covers targets with drawn results and images that are already being flushed. A dispatch that writes a drawn target's memory through its host import and has completion work can complete inside that target's store, and its second stamp made the draws recorded after it look older than the dispatch, so the store dropped them all. A drawn target is tracked as one unit, so after a change anywhere else in it (a CPU store into another 64 KiB block) the whole-image check fails; the stamped 64 KiB blocks are then checked one by one. A block with no change since the image's generation keeps its draws past the stamp (completionKept, whichwriteBackLayersreads), and a block the CPU wrote keeps the CPU's bytes outside the drawn rectangles. Whole-image keeps of drawn targets are rechecked for CPU stores after the stamp.Why
PPSA14363 (METAL GEAR SOLID - Master Collection Version, own dump) draws its PS1 game into three linear 3072x2048 RGBA8 color targets. With them resident (#1191's import-creating case, applied locally for these runs),
main's per-draw store copies up to 69.7 GB per 10 s out of the images, and the PS1 part runs slower than on the synchronous path. In MGS1's PS1 part every store of these targets covers one rectangle (a local counter over a 300 s run: no fallback to a whole or per-draw store). Bring-up thread: #9615.Tested
Windows 11 26200, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.Current head
d6d8966bba:mainb930da950dmerged in, for @oneandonlydean (comment). Onlycore/libs/prx/libSceAgcDriver/CMakeLists.txtconflicted:main's newagc_submit_progresstests and this PR's completion-point tests went into the sameif(BUILD_TESTING)block, and both are kept. It still merges cleanly withmainf595326943. On this head, on the RX 6700 XT, the build is clean. The focused set plusagc_driver_bda_*(54ctestentries) passes 3 of 3. With the Khronos validation layer, 54 of 54 pass with 0VUID-lines (the layer was inserted 73 times, no "was not found" line).ctest -R "^(agc|shader)_"passes 1011 of 1014; the 3 failures are thesample_ordertestsmainfails on this GPU.Earlier head
d36311d661: the per-block keep at the end of What, for @oneandonlydean's review (comment).agc_driver_linear_target_direct_write_completiongains that ordering as a third case, on write-watched and on unwatched memory: a fill over block 0 with completion work, a draw into block 0, a CPU store into block 1 made under the GPU mutex while the fill's completion is still pending (the test reads the fill's copied buffer in the same hold, and again at the label, so each run reports whether the completion was pending at the store and had run by the label), then the label. Red on5b5dcaeaff: the write-watched case fails, with 9984 of the 9984 pixels the draw covered holding the fill's pattern, the completion pending at the store and run by the label; the other three cases pass. Green on this head: 20 of 20, and 10 of 10 with the output kept, each write-watched run with the completion pending at the CPU store and run by the label. On unwatched memory the keep rule does not apply and the fill's completion had already run when the CPU store landed, so that variant passes before and after the change. The same test onmain8a85a5c848fails as well: the fill-then-draws case loses 9856 of the 19712 drawn pixels (the first draw), and in the third case the draw's own store onmainruns the fill's completion first, drops the draw's 9984 pixels, and its whole-target store writes the target's old bytes (0x5a5a5a5a) over the block-1 CPU store. Also on this head: the focused set above plusagc_driver_bda_*(53ctestentries) 3 of 3; with the Khronos validation layer 53 of 53, 0VUID-lines, the layer inserted 70 times;ctest -R "^(agc|shader)_"997 of 1000, with the same 3sample_orderfailures asmain.Earlier head
5b5dcaeaff:main11d6efa06cmerged in (eefe6d1380; onlycore/libs/prx/libSceAgcDriver/CMakeLists.txtconflicted, resolved as in @oneandonlydean's merge on #9879), then5b5dcaeaff, the keep-rule change at the end of What, with a new test. A review of the merge against #8126 found the dropped draws.agc_driver_linear_target_direct_write_completionhas two cases: a direct fill with completion work and then two draws, and the reverse order. It skips without a host import, and when the device does not keep the import write-watched. With the new test on7ad5d33a66(the same commits rebased onto11d6efa06c, without the change), the first case fails: at the label after the draws, 19712 of the 19712 pixels the draws covered hold the fill's pattern. With it, the test passes 20 of 20. The runs below are on605de8157c, the same change rebased onto11d6efa06c. Its tree differs from this head only in the position of oneadd_testblock inCMakeLists.txtand in the debt entry on this gap:agc_driver_direct_write_completion,main'sagc_driver_copied_writer_*,agc_driver_draw_cache_*and label-order entries: 46ctestentries, 3 of 3.agc_driver_copied_writer_label_orderand its_drainentry skip on this GPU (minStorageBufferOffsetAlignment 4), as onmain;VUID-lines, the layer inserted 64 times, no "was not found" line;ctest -R "^(agc|shader)_": 997 of 1000 pass; the 3 failures aremain'sagc_driver_sample_order,_grid_referenceand_recipe_depth_locationson this GPU.Other devices, on
cee2512ef8: @Dextroid17 on lavapipe (comment), and @BKlaasWerkman on Intel Arc with the validation layer (comment).Previous head
cee2512ef8, rebased ontomainff191e29d1because #6948 and #6682 made it conflict; it still merges cleanly with513ca7e558. RX 6700 XT, AMD driver 32.0.21045.16010: the focused set plusmain'sagc_driver_linear_readback_labelandagc_recorder_*entries, 25ctestentries, pass 3 of 3. With the Khronos validation layer on the same set,main513ca7e558passes 16 of 16 (the entries that exist there; layer inserted 19 times) and this head 25 of 25 (32 times), with 0VUID-lines and no "was not found" line on either. The rebase keeps #6948'sStoreReadbackBeforeLabelnext to this PR'sStoreDrawnLinearat labels and end-of-pipe interrupts, this PR's first, so its stored count still setsworkOpenfor the interrupt submit; the readback store then finds queue 0's drawn targets already stored, and on other queues it stores them limited to their drawn rectangles.e5edf0cd4afixedagc_driver_linear_target_draw_bindingsfor memory outside the write watch (llvmpipe CI): the test runs its scenario watched and with the block taken out of the write watch, and expects no submission from the second copying draw in the first case and exactly one in the second. The older results below are from the commits they name.New tests (4 executables, 6
ctestentries), on this branch onmaind6eafa54d0:agc_driver_linear_target_completion_points(with_sync_flipand_unpipelinedvariants): a flip, a drain, a label and an interrupt-onlyRELEASE_MEMthroughAgcDriver::Submit, with the queue held by aWAIT_REG_MEM, inside and outside the write watch. They pass onmaintoo, becausemainstores after every draw. They pin the contract, so a label-only policy would fail them. They skip on a device without host import, where the target is never resident.agc_driver_linear_target_completion_stores: a target stays pending across draws and labels untilWaitIdle, without a submission.agc_driver_linear_target_cpu_writes: AGC: a recorded draw into a resident linear color target stores the whole target back over CPU stores made after the draw #8152's CPU stores afterDraw, seeded and unseeded, inside and outside the write watch, each also with a driver read of the target (GuestMemory::Read) between the CPU stores and the store. Ported from @MarcZX10'sLinearTargetCpuWritesin fix(agc): preserve CPU writes after resident linear target draws #8246.agc_driver_linear_target_rectangle_bound: after one seeding draw and wait, two draws with different scissors, then CPU stores outside both rectangles, between them inside their bounding box, and in the gap before a target that starts past a 64 KiB boundary; and a second case with 17 one-row scissors and a CPU store between two of them.agc_driver_linear_target_draw_bindings,agc_driver_linear_target_dispatch_accessand theagc_driver_address_passes_draw_transitionsentry (withAddressPasses --synchronous-target-read) come with the last three commits: a draw's snapshot bindings prepared after its drawn-target store, the store before an address-based dispatch, and the store before a synchronous draw that reads a drawn target.ctestentries on10a8319a94).main's production files (atd6eafa54d0) and the new tests,completion_stores,cpu_writesandrectangle_boundfail; the threecompletion_pointsentries pass, as above. Without theAccessKeptByCpucheck,cpu_writesfails at the driver read. With the bounding box of the third commit,rectangle_boundfails with both sentinels between the rectangles lost.Khronos validation layer,
ctest -Von the focused set (15 tests ate430b0d07a; on10a8319a94the 18 entries pass with 0VUID-lines and the layer inserted 29 times) (the 6 above,agc_driver_linear_target_resident,agc_driver_address_passesand_targets_split,agc_driver_clamped_global_fill,agc_driver_flip_stores_small_results,agc_driver_storage_flush_ordering,agc_driver_storage_read_during_idle_store,agc_driver_store_idle_resultsandagc_driver_store_over_untracked): 15 of 15 pass on this branch, and 12 of 15 withmain's production files atd6eafa54d0(the three red tests above). Both sides have 0VUID-lines;VK_LOADER_DEBUG=layershows the layer inserted 25 times, with no "was not found" line.ctest -R "^agc_"(896 tests,-j 1) one430b0d07a: 891 pass; on10a8319a94(899 tests, run by huy): 894 pass. The 5 failures are the onesmaind6eafa54d0has on this GPU and toolchain:agc_driver_sample_order,_grid_reference,_recipe_depth_locationsandagc_driver_tessellation(AGC: agc_driver_sample_order tests read a depth target as all zeros on an NVIDIA Windows device and pass on Intel #9313 for the sample order; AGC: agc_driver_tessellation's merged hull program draws a different wrong patch on each run on AMD's Windows driver #8861 for tessellation, fixed by fix(shader): index tessellation attributes at a constant address with constants #8884);agc_driver_image_array_window_past_layer_limit(its 64 KiBalignaswith this MinGW toolchain).agc_driver_address_passesand its_targets_splitvariant failed on the first commit: the linear-target case reads, through the address table, the target the previous draw rendered in the same submission, and with the store deferred that read saw the bytes from before the draw. The second commit stores drawn targets before a draw or dispatch that reads their memory in place or writes it, and all of them for address-based work.PPSA14363, MGS1's PS1 part, with the targets resident through #1191's import line, applied locally on both sides (so both summary lines show
dirty):maind6eafa54d0againste430b0d07a, onlylibSceAgcDriver.prxswapped, both with #9115's trophy fix. Same scripted route, 300 s,APS5_TRACE_SUMMARY_EVERY=10, frame dumps only in the first 50 s, a trace window at 200 s, GPU and build locks held. Per 10 s window from 80 s, when the PS1 part starts, without the window that ends with the trace write:main+ import lineSummary lines of the trace window (200 to 220 s),
mainfirst:{"commit":"d6eafa54d046","dirty":true,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":5724,"ms":20187.184},"presents":170,"frame_ms":{"p50":17.361,"p90":286.919,"p99":338.727,"max":339.723},"gpu_busy_ms_per_present":95.308,"worker_busy_pct":{"queue worker 0x0":90.450},"top_phases_ms_per_frame":{"Driver.Packet":107.404,"Graphics.Draw":106.712,"Graphics.Draw.draw_and_resource_release":106.333,"Recorder.Sync":102.637,"Driver.Packet.draw":100.244,"Driver.Draw":100.203,"Driver.Draw.draw_enqueued":98.609,"VideoOut.Flip":5.066},"trace_dropped":false,"trace":"aps5-trace-d6eafa54d046-7736.json.gz"}{"commit":"e430b0d07ab2","dirty":true,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":11855,"ms":20003.149},"presents":1199,"frame_ms":{"p50":16.684,"p90":16.920,"p99":17.372,"max":17.645},"gpu_busy_ms_per_present":1.676,"worker_busy_pct":{"queue worker 0x0":6.284},"top_phases_ms_per_frame":{"VideoOut.Flip":13.315,"VideoOut.Flip.vblank_wait":12.638,"Driver.Packet":1.046,"Driver.Packet.draw":0.705,"Driver.Draw":0.691,"Graphics.Draw":0.618,"VideoOut.Flip.present":0.594,"Driver.Present":0.591},"trace_dropped":false,"trace":"aps5-trace-e430b0d07ab2-1592.json.gz"}In that window
mainspends 102.6 ms per frame inRecorder.Sync, behind the whole-target stores, and the GPU is busy 95.3 ms per present against 1.68 ms with this change.tools/performance_compare.pyon these lines and thetools/trace_digest.pytables of both runs are in this comment. Traces are not attached, because these runs come from a commercial title. An earlier 600 s run of the first commit onmain6ef5a1c4c9+ #9115, #9188, #9202 and #9373, with the same import line, reached Dock gameplay with no stop at 591 to 600 presents per 10 s.Overlap:
LinearTargetCpuWritestest with credit.PacketMemory.cpp,VulkanDevice.cppandTexture.cppfor label readback stores. Neither builds on the other, and whichever merges second rebases.Left for a follow-up, with a debt entry: a CPU store into a 64 KiB block of a drawn target that lands in the window while the direct write's completion checks and stamps that same block drops the draws in that block (the stamp's own collect records the store per page only, so the block reads as written by the driver). The CPU store itself survives.
Not tested: GPUs other than the RX 6700 XT, Linux, a title whose linear targets are resident on
mainwithout the import case.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code