graphics: avoid unnecessary GPU drains for bool predicates #702
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!702
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/702/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MehmetCambaz on GitHub · 2026-09-18 16:59 UTC · original
MehmetCambaz:perf/bool-predicate-producer-sync-pr→main· +309 −3 · 6 files · 1 commits · closed without mergingSummary
SET_PREDICATIONwith wait semantics performed a full GPU drain before every memory-predicate read. The drain ran unconditionally, including when nothing the GPU had queued could change the predicate bytes.This synchronizes against the actual producer instead. The predicate range is classified by resource ownership:
It also accounts for deferred image write-backs, so guest memory is never sampled before a scheduled
WriteBackinghas applied its bytes.Correctness
Image garbage collection schedules a download and defers the write-back into guest memory as a priority operation. It then frees the image, which clears its GPU-modified state immediately. Between those two points nothing reports ownership of the range, while guest memory still holds the old bytes.
The previous unconditional
FlushAndWaitdoes not close this: it submits the recorded tick and waits for the GPU, which is exactly what releases the priority runner, but it never waits for the runner itself. A deterministic regression test that holds the write-back pending fails against the old code as well.So the write-back ranges are now tracked explicitly. A range is published before the priority operation is queued and removed only after
WriteBackinghas run, and the predicate path treats a pending write-back the same as a live GPU-modified image. After submitting and completing the relevant tick, it waits for the priority operations queued up to that tick —CurrentTick() - 1, the tick just completed. Waiting onCurrentTick()would be a deadlock, since that is the still-open, unsubmitted tick.Ambiguous ownership fails closed: any image condition selects the drain.
Tests
tests/ShaderRecompilerComputeTests.cpp, registered aspm4_bool_predication_syncandpm4_predicate_writeback:The write-back case is deterministic rather than timing-dependent: a blocking priority operation is enqueued first, and the runner is FIFO, so the write-back is provably still pending while the predicate is read. No sleeps are involved.
Negative validation: removing the wait for pending write-backs, always selecting or never selecting the drain, and ignoring the image producer each make the matching test fail.
ctestpasses 40/41. The one failure iskernel_file_system, which does not link on Windows (undefined symbol: main) on unmodifiedmainas well; it is unrelated to this change and is addressed by #565.Performance
Measured in a profiled Kena workload: wait-enabled bool predicates occurred about 6.6 times per frame, and predicate synchronization cost dropped from roughly 4.6 ms/frame to effectively zero. Drains that are genuinely required remained rare, and waiting for pending image write-backs did not register a measurable cost.
This is real-world validation of the change, not the correctness argument; the correctness argument is the ownership invariant and the tests above.
AI disclosure
AI assistance was used during investigation, implementation and testing. I reviewed the resulting change and validation before submitting it.
@coderabbitai[bot] on GitHub · 2026-09-18 17:10 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
7fdb5bff-1302-47d0-8ae2-11afddc75c0e📥 Commits
Reviewing files that changed from the base of the PR and between
5b7d3343cfandcce148ea00.📒 Files selected for processing (6)
CMakeLists.txtsrc/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.htests/ShaderRecompilerComputeTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough
The change tracks deferred image write-backs in
TextureCacheand exposes range-overlap checks.CommandProcessorclassifies predicate synchronization as draining queued work, downloading dirty buffer data, or doing nothing.SetPredicationvalidates the address and uses this targeted synchronization. New compute tests cover image write-back and boolean predication cases, with dedicated CTest registrations and command-line modes.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
cce14No concrete correctness or stability issue remains; the change is ready to merge after normal checks.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. (2 skipped: 1 unsupported, 1 too large.)
Comment
@coderabbitai helpto get the list of available commands.@Nmzik on GitHub · 2026-10-21 19:41 UTC · original
Superseded by
840b9f575.Pull request closed