renderer: check scalar reads against merged write ranges #1285

Closed
github-bot wants to merge 2 commits from gh-pr/1285/head into gh-pr/1285/base
Owner

@⁠NeySlim on GitHub · 2026-10-09 07:25 UTC · original
NeySlim:perf/scalar-read-overlap → main · +136 −0 · 3 files · 2 commits · closed without merging

Problem

Before recording a draw or dispatch, CommitBindings checks that the guest memory read to specialize its shaders (ResourceSnapshot::specialization_reads) is not written by the same draw. For every read it walks every bound image (a slot lookup each) and every written shader buffer. In God of War Ragnarök (PPSA08332, 05.005) a frame records about 2,100 draws and dispatches with about 255,000 such reads, so about 1.3 million range comparisons per frame. In a profile of the opening cutscene the check takes 6% of the samples of the GPU command thread (ImageRangeOverlaps alone 3.3%), on a branch that already collects the written ranges once per draw instead of once per read.

Change

  • GatherWriteRanges collects the ranges written by the bound images (data, stencil and metadata) and shader buffers of the draw once, the first time a stage has reads to check, then sorts and merges those that overlap or touch.
  • ScalarReadsMayOverlap checks each read against the merged ranges with a binary search.
  • Only when it reports an overlap, or an invalid read, does the existing loop run, so the error message and the failure on an invalid read are unchanged.
  • MergeGuestRanges exits on an empty or wrapping write range, as ImageRangeOverlaps did for every write before, so an invalid write range still stops the emulator instead of being merged with a wrapped end.

A read overlaps the union of the writes exactly when it overlaps one of them, so the decision is the same as before.

Test

New host check ScalarReadOverlap in shader_recompiler_compute_tests (runs with every invocation): range merging, reads that touch a write without overlapping it, reads spanning several writes, invalid reads, and 2,000 random draws compared with the pairwise check. Breaking the merge (merging only overlapping ranges, or comparing ends with <=) makes it fail. ScalarReadOverlapWrappingWrite (non-Windows, it forks like the other fatal checks) expects a wrapping write range to exit; it fails without the range check in MergeGuestRanges.

Validation

Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.3.

God of War Ragnarök from a new game, alternating every 5 s between this change and the previous code within one session. Measured on a branch with other pending GPU thread changes, which already collects the written ranges once per draw, per frame:

Per frame Cutscene, before after Sled, before after
CommitBindings on the GPU command thread 4.8 ms 2.3 ms 5.4 ms 2.5 ms

11 (cutscene) and 18 (sled) pairs of 5 s periods. Frame time differences stayed within the noise of these scenes.

  • resource_tracking_tests and resource_materialization_tests pass.
  • shader_recompiler_compute_tests, one case per process: same results as origin/main (597 of 607 cases pass on both; the same 10 fail on this RADV setup).

Not tested on Windows or macOS. The change is platform-independent C++ in the renderer.

Overlap with #1211

#1211 also rewrites the scalar-read loop in CommitBindings (it collects the image write ranges once per draw). The two branches conflict in descriptors.cpp; whichever is merged second needs a rebase, and this PR replaces that part of #1211.

AI use

I used Claude Code (AI agent) to profile the GPU command thread, write the change and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.

**@⁠NeySlim** on GitHub · 2026-10-09 07:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1285) `NeySlim:perf/scalar-read-overlap` → `main` · +136 −0 · 3 files · 2 commits · closed without merging ## Problem Before recording a draw or dispatch, `CommitBindings` checks that the guest memory read to specialize its shaders (`ResourceSnapshot::specialization_reads`) is not written by the same draw. For every read it walks every bound image (a slot lookup each) and every written shader buffer. In God of War Ragnarök (PPSA08332, 05.005) a frame records about 2,100 draws and dispatches with about 255,000 such reads, so about 1.3 million range comparisons per frame. In a profile of the opening cutscene the check takes 6% of the samples of the GPU command thread (`ImageRangeOverlaps` alone 3.3%), on a branch that already collects the written ranges once per draw instead of once per read. ## Change - `GatherWriteRanges` collects the ranges written by the bound images (data, stencil and metadata) and shader buffers of the draw once, the first time a stage has reads to check, then sorts and merges those that overlap or touch. - `ScalarReadsMayOverlap` checks each read against the merged ranges with a binary search. - Only when it reports an overlap, or an invalid read, does the existing loop run, so the error message and the failure on an invalid read are unchanged. - `MergeGuestRanges` exits on an empty or wrapping write range, as `ImageRangeOverlaps` did for every write before, so an invalid write range still stops the emulator instead of being merged with a wrapped end. A read overlaps the union of the writes exactly when it overlaps one of them, so the decision is the same as before. ## Test New host check `ScalarReadOverlap` in `shader_recompiler_compute_tests` (runs with every invocation): range merging, reads that touch a write without overlapping it, reads spanning several writes, invalid reads, and 2,000 random draws compared with the pairwise check. Breaking the merge (merging only overlapping ranges, or comparing ends with `<=`) makes it fail. `ScalarReadOverlapWrappingWrite` (non-Windows, it forks like the other fatal checks) expects a wrapping write range to exit; it fails without the range check in `MergeGuestRanges`. ## Validation Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.3. God of War Ragnarök from a new game, alternating every 5 s between this change and the previous code within one session. Measured on a branch with other pending GPU thread changes, which already collects the written ranges once per draw, per frame: | Per frame | Cutscene, before | after | Sled, before | after | |---|---|---|---|---| | `CommitBindings` on the GPU command thread | 4.8 ms | 2.3 ms | 5.4 ms | 2.5 ms | 11 (cutscene) and 18 (sled) pairs of 5 s periods. Frame time differences stayed within the noise of these scenes. - `resource_tracking_tests` and `resource_materialization_tests` pass. - `shader_recompiler_compute_tests`, one case per process: same results as `origin/main` (597 of 607 cases pass on both; the same 10 fail on this RADV setup). Not tested on Windows or macOS. The change is platform-independent C++ in the renderer. ## Overlap with #1211 #1211 also rewrites the scalar-read loop in `CommitBindings` (it collects the image write ranges once per draw). The two branches conflict in `descriptors.cpp`; whichever is merged second needs a rebase, and this PR replaces that part of #1211. ## AI use I used Claude Code (AI agent) to profile the GPU command thread, write the change and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:26 +00:00
github-bot closed this pull request 2026-11-26 09:51:26 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:29 UTC · original · edited 2026-10-17 11:05 UTC

Review in Change Stack →

📝 Walkthrough

The change adds helpers to merge guest-memory write ranges and check scalar-read overlap. RenderExecutor gathers writable image and shader-buffer ranges, then uses the overlap check in CommitBindings before detailed per-resource checks. Host tests cover merging, interval boundaries, invalid ranges, and generated overlap cases.

Suggested reviewers: defektu

Priority: ➖ Normal

Change: Refactor

Merge Risk: 🟠 High · up to 8e87b

Valid shader reads can bypass write-conflict checks, and the host test detects the error. Fix the search before merging.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: checking scalar reads against merged write ranges in the renderer.
Description check Passed The description is directly related to the changeset and explains the performance motivation, implementation, tests, validation, and compatibility considerations.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1285#issuecomment-6076489411) · edited 2026-10-17 11:05 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1285?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds helpers to merge guest-memory write ranges and check scalar-read overlap. `RenderExecutor` gathers writable image and shader-buffer ranges, then uses the overlap check in `CommitBindings` before detailed per-resource checks. Host tests cover merging, interval boundaries, invalid ranges, and generated overlap cases. **Suggested reviewers:** `defektu` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"8e87bdf0e117c9c44cc4acc96b2a1afbe0120470" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🟠 High</strong> · up to <code>8e87b</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟠 High** · up to `8e87b` --> <!-- final_review_risk_coverage:{"sourceCommitId":"8e87bdf0e117c9c44cc4acc96b2a1afbe0120470","coveredCommitId":"8e87bdf0e117c9c44cc4acc96b2a1afbe0120470","kind":"reviewed"} --> Valid shader reads can bypass write-conflict checks, and the host test detects the error. Fix the search before merging. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: checking scalar reads against merged write ranges in the renderer. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changeset and explains the performance motivation, implementation, tests, validation, and compatibility considerations. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1285)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -887,0 +914,4 @@
const auto next = std::upper_bound(
writes.begin(), writes.end(), address,
[](uint64_t value, const GuestRange& range) { return value < range.End(); });
if (next != writes.end() && next->address < address + size) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 11:05 UTC · original · edited 2026-10-17 11:28 UTC

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '885,1028p' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
sed -n '1300,1375p' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 9281


🏁 Script executed:

python3 - <<'PY'
from bisect import bisect_right

MASK = (1 << 64) - 1

def end(r):
    return r[0] + r[1]

def merge(ranges):
    ranges = sorted(ranges)
    out = []
    for address, size in ranges:
        if not size or address > MASK - size:
            raise ValueError("invalid")
        if out and address <= end(out[-1]):
            a, s = out[-1]
            out[-1] = (a, max(end(out[-1]), address + size) - a)
        else:
            out.append((address, size))
    return out

# Model the standard binary-search steps used by libstdc++'s upper_bound:
# find the first range for which !(value < range.End()).
def scalar(reads, writes):
    if not writes:
        return False
    for address, size in reads:
        if not size or address > MASK - size:
            return True
        lo, hi = 0, len(writes)
        while lo < hi:
            mid = lo + (hi - lo) // 2
            if address < end(writes[mid]):
                lo = mid + 1
            else:
                hi = mid
        next_i = lo
        if next_i < len(writes) and writes[next_i][0] < address + size:
            return True
    return False

state = 0x9e3779b97f4a7c15
def nextv(bound):
    global state
    state ^= (state << 13) & MASK
    state ^= state >> 7
    state ^= (state << 17) & MASK
    state &= MASK
    return state % bound

for draw in range(2000):
    written = []
    count = nextv(6)
    while count:
        written.append((0x10000 + nextv(64) * 0x40, 1 + nextv(0x200)))
        count -= 1
    reads = []
    count = 1 + nextv(8)
    while count:
        reads.append((0x10000 + nextv(80) * 0x30, 1 + nextv(0x80)))
        count -= 1
    pairwise = any(
        address < end(r) and r[0] < address + size
        for address, size in reads
        for r in written
    )
    merged = merge(written)
    fast = scalar(reads, merged)
    if fast != pairwise:
        print("first mismatch:", draw)
        print("written:", written)
        print("merged:", merged)
        print("reads:", reads)
        print("pairwise:", pairwise, "fast:", fast)
        break
else:
    print("no mismatch in 2000 draws")
PY

Repository: KytyPS5/KytyPS5

Length of output: 319


Fix the binary-search comparator for reads inside a write range.

For a read inside a single merged write, the current comparator makes std::upper_bound return writes.end(). ScalarReadsMayOverlap returns false, so CommitBindings skips the detailed conflict checks.

Suggested fix
--- "a/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp"
+++ "b/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp"
@@ -911,9 +911,9 @@
 		if (size == 0 || address > UINT64_MAX - size) {
 			return true;
 		}
-		const auto next = std::upper_bound(
-		    writes.begin(), writes.end(), address,
-		    [](uint64_t value, const GuestRange& range) { return value < range.End(); });
+		const auto next = std::lower_bound(
+		    writes.begin(), writes.end(), address,
+		    [](const GuestRange& range, uint64_t value) { return range.End() <= value; });
 		if (next != writes.end() && next->address < address + size) {
 			return true;
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		const auto next = std::lower_bound(
		    writes.begin(), writes.end(), address,
		    [](const GuestRange& range, uint64_t value) { return range.End() <= value; });
		if (next != writes.end() && next->address < address + size) {
**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 11:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1285#discussion_r4302445575) · edited 2026-10-17 11:28 UTC **🗄️ Data Integrity & Integration** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '885,1028p' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp sed -n '1300,1375p' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 9281 --- 🏁 Script executed: ```bash python3 - <<'PY' from bisect import bisect_right MASK = (1 << 64) - 1 def end(r): return r[0] + r[1] def merge(ranges): ranges = sorted(ranges) out = [] for address, size in ranges: if not size or address > MASK - size: raise ValueError("invalid") if out and address <= end(out[-1]): a, s = out[-1] out[-1] = (a, max(end(out[-1]), address + size) - a) else: out.append((address, size)) return out # Model the standard binary-search steps used by libstdc++'s upper_bound: # find the first range for which !(value < range.End()). def scalar(reads, writes): if not writes: return False for address, size in reads: if not size or address > MASK - size: return True lo, hi = 0, len(writes) while lo < hi: mid = lo + (hi - lo) // 2 if address < end(writes[mid]): lo = mid + 1 else: hi = mid next_i = lo if next_i < len(writes) and writes[next_i][0] < address + size: return True return False state = 0x9e3779b97f4a7c15 def nextv(bound): global state state ^= (state << 13) & MASK state ^= state >> 7 state ^= (state << 17) & MASK state &= MASK return state % bound for draw in range(2000): written = [] count = nextv(6) while count: written.append((0x10000 + nextv(64) * 0x40, 1 + nextv(0x200))) count -= 1 reads = [] count = 1 + nextv(8) while count: reads.append((0x10000 + nextv(80) * 0x30, 1 + nextv(0x80))) count -= 1 pairwise = any( address < end(r) and r[0] < address + size for address, size in reads for r in written ) merged = merge(written) fast = scalar(reads, merged) if fast != pairwise: print("first mismatch:", draw) print("written:", written) print("merged:", merged) print("reads:", reads) print("pairwise:", pairwise, "fast:", fast) break else: print("no mismatch in 2000 draws") PY ``` Repository: KytyPS5/KytyPS5 Length of output: 319 --- </details> **Fix the binary-search comparator for reads inside a write range.** For a read inside a single merged write, the current comparator makes `std::upper_bound` return `writes.end()`. `ScalarReadsMayOverlap` returns false, so `CommitBindings` skips the detailed conflict checks. <details> <summary>Suggested fix</summary> ```diff --- "a/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp" +++ "b/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp" @@ -911,9 +911,9 @@ if (size == 0 || address > UINT64_MAX - size) { return true; } - const auto next = std::upper_bound( - writes.begin(), writes.end(), address, - [](uint64_t value, const GuestRange& range) { return value < range.End(); }); + const auto next = std::lower_bound( + writes.begin(), writes.end(), address, + [](const GuestRange& range, uint64_t value) { return range.End() <= value; }); if (next != writes.end() && next->address < address + size) { return true; } ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const auto next = std::lower_bound( writes.begin(), writes.end(), address, [](const GuestRange& range, uint64_t value) { return range.End() <= value; }); if (next != writes.end() && next->address < address + size) { ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:8205e3a374d5284cc64e2b8e --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 11:05 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73f46ca7-b2e2-4aa9-8577-43498a657b30
📥 Commits

Reviewing files that changed from the base of the PR and between b57e4252dcf857df173a0a8f37b6c4fe86a45faa and 8e87bdf0e1.

📒 Files selected for processing: 3
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/render.h
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 11:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1285#pullrequestreview-5557510410) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `73f46ca7-b2e2-4aa9-8577-43498a657b30` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b57e4252dcf857df173a0a8f37b6c4fe86a45faa and 8e87bdf0e117c9c44cc4acc96b2a1afbe0120470. </details> <details> <summary>📒 Files selected for processing: 3</summary> * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/render.h` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=833dc81b-c9a0-41f3-9d64-ed1a14542f0d attempt=5390be94-1bc6-4c5a-a09b-4cf1f2466107 batch=1/1 -->
@ -887,0 +914,4 @@
const auto next = std::upper_bound(
writes.begin(), writes.end(), address,
[](uint64_t value, const GuestRange& range) { return value < range.End(); });
if (next != writes.end() && next->address < address + size) {
Author
Owner

@⁠NeySlim on GitHub · 2026-10-17 11:28 UTC · original

I don't think so: upper_bound calls the comparator as comp(value, element), so it returns the first write whose end is past the read address. For a read inside [0x1000, 0x1180) that's the write itself, not end(), and next->address < address + size catches it. The random draws in CheckScalarReadOverlap compare against the pairwise check and include reads inside a single write, and they pass.

**@⁠NeySlim** on GitHub · 2026-10-17 11:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1285#discussion_r4302498618) I don't think so: `upper_bound` calls the comparator as `comp(value, element)`, so it returns the first write whose end is past the read address. For a read inside `[0x1000, 0x1180)` that's the write itself, not `end()`, and `next->address < address + size` catches it. The random draws in `CheckScalarReadOverlap` compare against the pairwise check and include reads inside a single write, and they pass.
@ -887,0 +914,4 @@
const auto next = std::upper_bound(
writes.begin(), writes.end(), address,
[](uint64_t value, const GuestRange& range) { return value < range.End(); });
if (next != writes.end() && next->address < address + size) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 11:28 UTC · original

@⁠NeySlim You’re right. My Python model reversed the std::upper_bound branches, so its mismatch did not demonstrate a defect in your code.

The comparator finds the first write with range.End() > address. Because the merged writes are sorted and disjoint, their ends are increasing. For a read inside [0x1000, 0x1180), the search returns that write, and the remaining check detects the overlap.

No comparator change is needed. I withdraw this finding. Thanks for the correction.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1285
File: src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:914-917
Timestamp: 2026-10-17T11:28:45.634Z
Learning: In src/graphics/host_gpu/renderer/pipeline/descriptors.cpp, the C++ ScalarReadsMayOverlap function correctly uses std::upper_bound with comp(value, element) defined as value < range.End(). MergeGuestRanges produces sorted, disjoint writes with increasing ends, so this search returns the first write whose end exceeds the read address. Do not flag this comparator as reversed.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 11:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1285#discussion_r4302499586) @⁠NeySlim You’re right. My Python model reversed the `std::upper_bound` branches, so its mismatch did not demonstrate a defect in your code. The comparator finds the first write with `range.End() > address`. Because the merged writes are sorted and disjoint, their ends are increasing. For a read inside `[0x1000, 0x1180)`, the search returns that write, and the remaining check detects the overlap. No comparator change is needed. I withdraw this finding. Thanks for the correction. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1285 File: src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:914-917 Timestamp: 2026-10-17T11:28:45.634Z Learning: In src/graphics/host_gpu/renderer/pipeline/descriptors.cpp, the C++ ScalarReadsMayOverlap function correctly uses std::upper_bound with comp(value, element) defined as value < range.End(). MergeGuestRanges produces sorted, disjoint writes with increasing ends, so this search returns the first write whose end exceeds the read address. Do not flag this comparator as reversed. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> <!-- <review_comment_withdrawn> --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.