Repository navigation
Conversation
bcf6733 to
b2ed1d9
Compare
|
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.
|
|
I marked this PR draft after a second correctness review. Deferring writeback alone is insufficient: the current write-watch policy preserves whole 64 KiB blocks, which can discard the draw output in the same block as a post-draw CPU store. Also, a writeback recorded during a completion needs to execute synchronously rather than remain in a newly opened recorder batch. I am working through a region-aware writeback path and will update the PR when the regression and completion ordering are addressed. |
|
Update after checking the reporter’s run on current |
|
I pushed two commits to #8246: |
fogydes
left a comment
There was a problem hiding this comment.
Reviewed the diff, CI, and verified the existing test on current main.
Production code (Draw.cpp): The fix defers the resident linear color target writeback from draw-recording time to batch completion via recorder.OnComplete(). Before this change, StorageTexture::FlushPending ran synchronously during recording — scheduling a whole-target copyout before any CPU stores the game makes after Draw returns. At completion, the OnComplete lambda:
- Acquires
GuestMemory::GpuMutex()— correct, sinceFlushPendingandWriteBackmutate shared guest-memory state. - Flushes pending overlapping aliases (preserving prior alias reconciliation behavior).
- Calls
keep->WriteBack()to write the GPU results back.
The keep shared_ptr capture extends the resident's lifetime until the completion callback runs, preventing a use-after-free if the texture is otherwise released. This is sound.
Test (LinearTargetResident.cpp): The regression sequence is well-designed:
Program()now takes ablueConstantparameter (default0x80), allowing the second draw to write a distinct blue value (0xf4).Draw()now takesscissorWidth(defaultWidth), allowing a left-scissored second draw.- The
runlambda executes two draws: full-width blue=0x80, then left-half blue=0xf4. Between draws, theseedvariant writes0x5ato the left half of the CPU buffer. After both draws, the CPU writes0x42to the right half. AfterWaitIdle(), it checks:- Left half: second draw's output (
x, y, 2.0, 1.0with0xf4blue → float2.0viav_mov_b32encoding) preserved. - Right half: CPU-written
0x42bytes preserved (not overwritten by GPU writeback).
- Left half: second draw's output (
- Both
run(true)(seeded) andrun(false)(unseeded) are exercised.
The instruction encoding 0x7e000200u | blueConstant | (22u << 17u) is a v_mov_b32 with an inline constant — the constant index formula is correct for GCN/RDNA ISA.
CI: conventions, labels pass. Build/platform jobs skip (AGC change, no CI GPU runner).
Local verification: Built agc_driver_linear_target_resident_tests and ran ctest -R "^agc_driver_linear_target_resident$" -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 on current main — Passed (0.56s, NVIDIA GeForce RTX 5050 Laptop GPU). The test passes on the existing code; the enhanced test from this PR would exercise the new writeback path.
PR body: Honest about the hardware limitation (Xeon E5-1620 v2 can't run Vulkan tests). Template complete.
One observation: the PR doesn't note VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation testing, but the host CPU guard prevents the runtime from reaching Vulkan initialization anyway, so this is consistent with the limitation.
No blocking issues found.
|
Follow-up: I found the first byte-merge revision could compare against an upload baseline that was stale across recorded draws. Commit |
|
Thanks for the detailed review and for checking the previous code on your RTX 5050. Since that review, the fix changed: it now leaves target results pending after batch completion and stores them on the later read/flush path; commit |
|
Sharing a tested alternative implementation and regression coverage for #8152 so we can coordinate with this PR. Branch: rajvveer/AnyPS5 — fix/agc-linear-target-cpu-writes This approach captures the actual image on the GPU before a recorded linear draw and merges only changed bytes into guest memory. Atomic word updates preserve untouched channels sharing a word. Image and guest baselines remain separate for subsequent refresh; CPU write-back and padded array layers are covered too. It keeps the recorded path. The tests extend Celegans12's reproducer: seeded/unseeded partial draws, masked float/RGBA8 channels, partial geometry, later blending, queued overlapping draws, actual cached-recipe replay, and GPU retile cases for 1/2/4/8/16-byte elements. Recipe replay is unseeded so a deferred re-upload cannot mask the original bug. Validation: Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release with SPIRV-Tools; NVIDIA RTX 5070 (617.42) and AMD Radeon(TM) Graphics (32.0.21030.2001).
These results apply to the linked branch; I have not executed this PR's current Would incorporating the implementation or regression coverage here be useful, or would you prefer a coordinated alternative PR? I have kept the separate PR on hold. |
50f477f to
e32a19b
Compare
|
I chose to integrate your implementation and regression commits into #8246 rather than open a second PR for the same issue. Both commits remain authored by you ( |
|
Correction to my previous note: I said I would keep the PR draft open, but GitHub shows it was already marked ready for review at 07:46 UTC. I had the state wrong; I did not change the draft/ready setting as part of integrating your commits. The PR remains ready for review, with the current-head runtime rerun still outstanding. |
|
The requested exact-head rerun is complete: Hardware: Windows 11 Pro 26200, NVIDIA GeForce RTX 5070 / driver 617.42, and AMD Radeon(TM) Graphics / driver 32.0.21030.2001; GCC 15.2.0 Release with SPIRV-Tools. The matrix was five resident modes (default, unwatched, draw transitions, eager write-back, synchronous linear targets) plus cached-recipe replay, three repetitions on each GPU. Every process confirmed the intended GPU and loaded Khronos validation layer, with A small test-only follow-up is also available: 66f62d174 — strengthen linear target replay and array coverage. It changes only
The follow-up was separately built and tested at Please cherry-pick |
|
I rebuilt exact head Attached is a tested correction extending Rajveer Shekhawat’s implementation and MarcZX10’s integration. The seeded/unseeded regression derives from Celegans12’s reproduction. I’m offering this for integration into the existing PR. Confirmed failures and correctionThe concurrent regression uses a 64 × 4096 RGBA8 target. The GPU writes only blue while a CPU thread updates counters in red/green and checks the preceding values. On GPU word-level compare-and-swap does not provide atomicity with ordinary CPU stores to adjacent bytes. The correction uses a separate publication shader with write-only A second regression exposed a stale-baseline problem: an actual GPU write equal to stale image contents can be omitted by the before/after comparison. The comparison is not treated as a write-coverage detector. It depends on establishing a coherent baseline first. Unsynchronized CPU/GPU stores to the same byte still require ordering. Publication remains in the recorded command stream, with the existing reader/host barriers and resource retention. The new checks use the established TestedHardware: NVIDIA GeForce RTX 4070 Laptop GPU, NVIDIA 592.82 / Windows driver 32.0.15.9282, Windows 11 Pro 10.0.26300. WinLibs GCC 15.2.0 r7, Release, Ninja; Khronos validation layer 1.4.363.0.
Every GPU run used: Actual validation-layer loading was verified. Base and correction logs contain zero VUIDs, synchronization hazards, missing-layer warnings or skips. The shared deprecated-setting notice is not counted as a new validation error. Focused candidate command: ctest --test-dir build-review-8152 -R '^agc_driver_(linear_target_(concurrent_bytes|cpu_writes.*|publication.*|resident|recipe)|graphics|alias_copy_label|array_layer_target)$' -V --timeout 30Convention and whitespace checks pass. The attachment is a plain unified diff against SHA256: The additional upload/snapshot costs work and temporary memory. No game compatibility, performance improvement, Linux/macOS runtime, fresh full-suite or other-GPU result is claimed for this correction. AI-assisted: yes. |
f063d00 to
030409a
Compare
|
Integrated the offered correction into #8246 as commit The contributor-reported RTX 4070 Laptop run and correction-tree test results are recorded in the PR description, explicitly as pre-latest-rebase results. On the rebased head, |
|
This is a runtime run of the exact current head Setup: Windows 11 (26300), WinLibs GCC 15.2.0, Release,
Not measured: the cost per draw. AI-assisted: yes (Claude Code); results above were run on this machine. |
|
I tested #8246 with Ghost of Yōtei (PPSA26344) on Windows 11 and an RTX 3080 Laptop, since #6892's resident linear targets are what broke our warm world runs in the first place. The unit-level fix holds up well on our tree. In the game, though, it doesn't fix the spawn: with resident linear targets on, Atsu still isn't at the river. One caveat first: this isn't plain main. Our tree is main b509767 merged with our local Yōtei work ( The tests all pass. Your new tests, the upstream resident-linear tests and the nearby storage and write-tracking tests went 22/22, three times each, with resident linear on. My #8152 reproducer passes 5/5 in both the seeded and the unseeded case. With only your Draw.cpp hooks taken out again, it fails 3/3 with 7,680 of the 8,192 right-half bytes rolled back, as before. In the game, the warm run from our Ainu-village save never shows Atsu. From frame 078 on, the camera sits under the water looking up at the forest. That's the same family of symptoms as our earlier resident-linear runs (T-pose in the sky). With resident linear off, the same save spawns him at the river every time. The path does run there: in the world, about 15-43 recorded draws per 10 s go into resident linear targets, and each one gets your "linear draw baseline" upload. I also wanted to know whether the game just reads those targets before the recorded write-back lands. So I added a local debug switch that does a full If it helps, I can run an instrumented build next. For example, it could dump a linear target's guest bytes after one of these draws with resident linear on and off and diff them. Or I can try a newer head. Is there anything you'd want me to log in particular? Details
|
|
@Celegans12, thanks for offering. A targeted capture on the current head |
|
Thanks for the detailed title run and the sync control. That changes the next question: the isolated CPU-write regressions pass, but this title still diverges even when each writeback is forced to complete before the next packet, so completion ordering alone does not explain the spawn failure. The most useful next capture would be the first target/draw that differs between resident-linear on and off: guest address, dimensions/format/pitch, bytes before the draw, resident image bytes after it, bytes written back, and the next consumer’s read. A narrow capture around the first divergence should distinguish stale baseline/image contents from a format/layout or alias mismatch. If you can share such a trace (or an instrumented reproducer), I can investigate the next fix in this PR. |
|
Thanks, this separates the #8152 byte-preservation case from the remaining Yōtei spawn failure: the focused CPU-write/repro tests and their negative control still validate the intended fix, while the title remains below water even with the per-draw sync switch. For the first affected target, could you log a compact identity (guest address, format, extent/pitch) and a hash plus a few sampled bytes at three points: after |
|
Thanks for the detailed run. The result narrows this down: the reproducer confirms the CPU write-back regression is fixed, while forcing a full sync after each recorded draw does not fix the Yōtei scene, so I agree we should look at the bytes and resident image contents rather than add more ordering waits. If you can run one instrumented comparison, please pick a target touched during frames 078–090 and log/dump:
Please capture resident-on and resident-off runs from the same save and report the first differing byte/pixel with the owning draw. A small bounded set around one target is enough; no need for a full frame dump. That should tell us whether the mismatch is in the write-back, the resident image used by the next draw, or another local Yōtei change. |
recordPreparedDraw does the same for the targets it binds when the draw is recorded. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
The completion store of a drawn linear target goes through FinishLinearDraw. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
Write-back compares the 64 KiB blocks written since the draw's snapshot and leaves the ones the CPU changed. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com> Ported onto main: main renamed the per-target tracked flag to layerTracked, so the new block and the unknown check use layerTracked.
A write-back that used the draw's snapshot publishes the whole shadow, not the partial units. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
The write-back detiles into the buffer the draw started from instead of a new one and keeps it with its size. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
…napshot With a snapshot the write-back runs the changed-only detile against the draw's original bytes and no longer copies the tiled scratch over the import. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com> Ported onto main: main moved the direct host-import retile into its own branch, so the snapshot retile runs only in the scratch branch (else). The import-retile gate also skips snapshot targets, as the PR's own version did, so they never take the direct whole-layer import.
A copy of the destination is taken before the store and the bytes the write-back did not change are put back, so concurrent CPU bytes survive. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
…napshot main stores a drawn linear target through storeDrawnRect, which copies the whole drawn rectangle over the import and so overwrites the bytes of channels the draw masked out that the CPU wrote since. A target with a draw snapshot already stores only the bytes that changed, so writeBackLayers takes the rectangle path only when there is no snapshot. Ported onto main: main renamed the tracked flag to layerTracked, so the condition keeps layerTracked where the PR used tracked.
Resources, the detiler and the standard headers it now uses. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
…rget A left-half geometry and a program whose blue constant can be chosen. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
…k and vertices The draw helper can halve the destination with blending, restrict the color write mask and the scissor, and take its own vertices. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
…in the resident test The resident test gets a Coverage mode, the APS5_NO_RESIDENT_LINEAR flag, checks of queued and cached draws and of the bytes a draw leaves alone, a CPU snapshot check, a changed-only retile check and a --recipe mode that replays the draw through a draw recipe. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
agc_driver_linear_target_recipe runs agc_driver_linear_target_resident_tests --recipe. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
Draws into a linear target while the CPU writes other bytes of it and checks that the CPU's bytes are kept. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
Six cases (mask, geometry, reader, eviction, alias, same) check what a resident linear target publishes after a draw; registered per case. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
A CPU-write regression with two switches, APS5_LINEAR_SAME_OUTPUT and APS5_LINEAR_SEED_LEFT, and a seeded registration; the switches are documented in ENVIRONMENT.md. Co-authored-by: Rajveer Shekhawat <rajveershekhawat626@gmail.com> Co-authored-by: embersas <30363137+embersas@users.noreply.github.com>
…he whole target The write-back of the previous draw leaves the image current, so the forced whole-surface upload before every recorded draw copied bytes the image already held. Refresh uploads only the layers whose guest memory changed since the image was last current, which includes the CPU's writes.
3ab861c to
3d135a1
Compare
|
@MarcZX10 I compared 3d135a1 with 3ab861c. Apart from the rebase onto main the code is the same, so the requests from @adriadam10 on 6 Nov still stand: bound the snapshot memory, explain the 315 to 397 ms stall at 180 draws and the first-frame cost, rerun the alias test on a write-watched host, and update the Tested section. On the memory, I think I see the cause. Each PrepareLinearDraw allocates a buffer twice the target's size, and recorder->Keep holds it until the work retires, so resetting linearDrawOriginal in FinishLinearDraw frees nothing. For the 24 MiB target that is 48 MiB per recorded draw, which fits the 71 against 24 MiB measured. My earlier question also stands: which CPU writes does this still save that main's drawn-rectangle store loses? |
|
NVIDIA Linux run with the Khronos validation layer of the current head Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
One test the PR adds fails, deterministically (2 of 2 runs with the layer, and once more without it): The other five No AI-assisted: yes (Claude Code) |
|
@oneandonlydean @adriadam10 Decision on the open requests for head 3d135a1 (no new commit pushed in this pass). Memory design: shared snapshot per target, not a cap. I read Not done here:
Next step for the author: a minimal test on main that loses a CPU write, plus the shared-snapshot change with memory and trace numbers from a write-watched host. |
|
RTX 3070 on Windows at the current head Setup: NVIDIA GeForce RTX 3070 (Ampere), driver 616.56, Windows 11 Pro 10.0.26100, WinLibs GCC 15.2.0 r7, Release, Vulkan validation layer 1.4.363. Head merged onto
Both failures: The alias numbers match the 4090's exactly: half of the CPU bytes are lost and the GPU pixels are all correct. The reader failure is new; it differs from the alias one and happens on every run here. The write-watch probe reports that host imports of write-watched memory keep the watch on this machine, if that helps narrow it down. AI-assisted (Claude Code). |
|
Tested
Not covered: GPU. This pull request changes GPU code, and the GitHub-hosted runners above have no GPU, so the Vulkan and GPU tests fail there on main and on this pull request alike. This result says nothing about the changed GPU paths; they still need a run on a real GPU. AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |

What
Fixes #8152: a later write-back from a recorded linear-target draw could overwrite CPU stores made after
Drawreturned.This PR uses the coordinated implementation authored by Rajveer Shekhawat (two commits) and the concurrent-byte correction authored by embersas. The original three commits were split into a series of smaller ones, so each commit derived from their work carries
Co-authored-bytrailers for both; the drawn-rectangle fix (leave the drawn-rectangle store to targets without a draw snapshot) and the finalRefresh()commit are mine and carry none. It snapshots the resident image around a recorded linear draw and merges changed bytes through the linear detiler so untouched guest bytes and CPU writes survive. The regression coverage includes seeded and unseeded partial draws, masked channels, partial geometry, later blending, queued overlapping draws, cached-recipe replay and GPU detiles for supported element widths.This is separate from #1191's resident-target performance path and #7154's depth-plane buffer coherence. It does not depend on either PR.
Tested
Current head
db12f5d6fb(30 commits, rebased ontomain3fea2a937b):agc_driver_linear_target_*tests plusagc_driver_graphics: 22 pass and 2 skip on lavapipe (direct_write_completion,import_creation). WithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationthere are 0VUID-lines (the layer is inserted at instance and device level). The same run onmainis not posted yet.main, flat in the number of draws and targets (one live snapshot per draw). Per-draw cost was measured only with the guest memory not write-watched (kernel 6.1, no write watch), where the target is compared or uploaded whole: about 44 ms onmainand 74 to 99 ms with this PR depending on whether the CPU writes before each draw. No number from a write-watched host and notools/trace_digest.pysummary are available yet. Details are in the comments below.python3 tools/check_conventions.py --base upstream/mainandgit diff --checkpass.Earlier reports, on older heads and not repeated on this one:
e5b9ac546against base3fd1cc393, the author reports 36/36 fresh focused runs passed on NVIDIA RTX 5070 (driver 617.42) and AMD Radeon(TM) Graphics (driver 32.0.21030.2001), Windows 11 Pro 26200, GCC 15.2 Release with SPIRV-Tools and Khronos validation/synchronization validation enabled, with no new VUIDs or validation warnings, and 118/118 common selected tests per GPU on both base and change.fea0c0cd8a2e8f85454e0d4b5b917915e0e3035b), 15/15 focused tests and 20/20 repeated key-case executions on a Windows 11 RTX 4070 Laptop, NVIDIA 592.82, with Khronos synchronization validation. The concurrent regression recorded 5,668 lost CPU updates on the then-current head and the original unseeded control onmainlost 7,680 of 8,192 CPU-written bytes; the corrected cases passed 20/20 repeats with zero lost updates.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)e5b9ac546); NVIDIA RTX 4070 Laptop / driver 592.82 on Windows 11 Pro (reported by Embersas on an older correction tree)