Demon's Souls: avoid full buffer sweeps during BDA preparation #1391

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

@⁠kewalker on GitHub · 2026-10-11 00:00 UTC · original
kewalker:perf/demons-souls-bda-dirty-worklist → main · +431 −88 · 8 files · 6 commits · closed without merging

I attest that the changes below have been verified and tested by me for correctness. The AI disclosure section at the end describes the exact usage.

During investigation, PrepareBda repeatedly traversed every mapped range and registered buffer before BDA draws and dispatches, including buffers with no CPU writes. This PR removes that unnecessary CPU work; it does not claim to resolve the game's overall low FPS or its readback stalls.

The tracker publishes CPU-dirty region hints in a fixed hierarchical atomic bitmap. The GPU thread consumes those hints and synchronizes only their intersections with mapped ranges. Existing locked page ownership checks still determine the bytes uploaded. Buffer registration queues the full new buffer span, and mapping queues the mapped range, so initial CPU-owned data and writes whose hints were consumed while unmapped are examined on the next pass. Consuming hints does not clear dirty-page ownership, and subsequent writes publish work for another pass. The fault-handler publication path does not allocate and has no bounded-log overflow case.

Related: #1286 pursues the same goal with bounded page-range logs and depends on another PR. This is an alternative based directly on current main, using coarse 4 MiB region hints. It can still examine unrelated buffers sharing a dirty region and adds roughly 520 KiB of bitmap storage per tracker. The repository's pinned formatting hook also reformatted existing declarations in the touched files.

Validation:

  • Windows Release emulator build with the development optimization stack passed. The focused PR's production sources and GPU test harness were separately compiled and linked, reusing unchanged current-main objects/libraries.
  • Isolated MemoryTrackerTests passed: new-region hints, deduplication, unchanged page ownership after consuming hints, registration hints, later writes, invalidation, and untracking.
  • Isolated --bda-dirty-worklist-only passed on Vulkan: registration after previously consumed hints, initial neighboring CPU-owned bytes, clean passes, CPU rewrites, and remapping after consuming an unmapped dirty hint. Registered as buffer_cache_bda_dirty_worklist in CTest and included in the full harness.
  • Existing isolated --mapped-range-only and --buffer-cache-range-only regression checks passed.
  • Clean 256 MiB tracker benchmark: existing single-range scan approximately 0.8–0.9 microseconds/pass; empty dirty-worklist consumption approximately 8 nanoseconds/pass. This measures tracker overhead, not game frame time.
  • Demon’s Souls development timing snapshots around the BDA change showed 523.47 ms / 2250 BDA calls (~233 microseconds/call) and 177.83 ms / 2207 calls (~81 microseconds/call). These are anecdotal snapshots with different workloads and other local changes, not a controlled A/B test. The contributor still reports approximately 2 FPS. Latest upstream changes have not yet been retested in the game.

Linux/macOS builds and controlled game A/B measurements have not been performed. Diagnostic instrumentation, shader readback changes, resource snapshot caching, completion-query changes, and pipeline-cache changes are excluded from this PR.

AI assistance: Codex implemented/extracted the change, wrote the tests, and ran the build, formatting, benchmark, and Vulkan validation at the contributor's request. The contributor provided Demon’s Souls timing logs and tested earlier development builds. Code was manually verified.

**@⁠kewalker** on GitHub · 2026-10-11 00:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1391) `kewalker:perf/demons-souls-bda-dirty-worklist` → `main` · +431 −88 · 8 files · 6 commits · closed without merging I attest that the changes below have been verified and tested by me for correctness. The AI disclosure section at the end describes the exact usage. During investigation, `PrepareBda` repeatedly traversed every mapped range and registered buffer before BDA draws and dispatches, including buffers with no CPU writes. This PR removes that unnecessary CPU work; it does not claim to resolve the game's overall low FPS or its readback stalls. The tracker publishes CPU-dirty region hints in a fixed hierarchical atomic bitmap. The GPU thread consumes those hints and synchronizes only their intersections with mapped ranges. Existing locked page ownership checks still determine the bytes uploaded. Buffer registration queues the full new buffer span, and mapping queues the mapped range, so initial CPU-owned data and writes whose hints were consumed while unmapped are examined on the next pass. Consuming hints does not clear dirty-page ownership, and subsequent writes publish work for another pass. The fault-handler publication path does not allocate and has no bounded-log overflow case. Related: #1286 pursues the same goal with bounded page-range logs and depends on another PR. This is an alternative based directly on current main, using coarse 4 MiB region hints. It can still examine unrelated buffers sharing a dirty region and adds roughly 520 KiB of bitmap storage per tracker. The repository's pinned formatting hook also reformatted existing declarations in the touched files. Validation: - Windows Release emulator build with the development optimization stack passed. The focused PR's production sources and GPU test harness were separately compiled and linked, reusing unchanged current-main objects/libraries. - Isolated `MemoryTrackerTests` passed: new-region hints, deduplication, unchanged page ownership after consuming hints, registration hints, later writes, invalidation, and untracking. - Isolated `--bda-dirty-worklist-only` passed on Vulkan: registration after previously consumed hints, initial neighboring CPU-owned bytes, clean passes, CPU rewrites, and remapping after consuming an unmapped dirty hint. Registered as `buffer_cache_bda_dirty_worklist` in CTest and included in the full harness. - Existing isolated `--mapped-range-only` and `--buffer-cache-range-only` regression checks passed. - Clean 256 MiB tracker benchmark: existing single-range scan approximately 0.8–0.9 microseconds/pass; empty dirty-worklist consumption approximately 8 nanoseconds/pass. This measures tracker overhead, not game frame time. - Demon’s Souls development timing snapshots around the BDA change showed 523.47 ms / 2250 BDA calls (~233 microseconds/call) and 177.83 ms / 2207 calls (~81 microseconds/call). These are anecdotal snapshots with different workloads and other local changes, not a controlled A/B test. The contributor still reports approximately 2 FPS. Latest upstream changes have not yet been retested in the game. Linux/macOS builds and controlled game A/B measurements have not been performed. Diagnostic instrumentation, shader readback changes, resource snapshot caching, completion-query changes, and pipeline-cache changes are excluded from this PR. AI assistance: Codex implemented/extracted the change, wrote the tests, and ran the build, formatting, benchmark, and Vulkan validation at the contributor's request. The contributor provided Demon’s Souls timing logs and tested earlier development builds. Code was manually verified.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:31 +00:00
github-bot closed this pull request 2026-11-26 09:55:31 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-11 00:34 UTC · original · edited 2026-10-16 02:12 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: feb55c3a-2d7b-4ee8-9a1d-fde911d8b231
📥 Commits

Reviewing files that changed from the base of the PR and between 1f2d44b18c and 0a9625c753.

📒 Files selected for processing: 3
  • src/graphics/host_gpu/memoryTracker.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.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.

📝 Walkthrough

MemoryTracker now records CPU-dirty region hints and provides APIs to queue and drain them. BufferCache queues registered and mapped ranges, then synchronizes dirty intersections with mapped ranges during BDA preparation. RenderContext queues newly mapped ranges and calls the synchronization method. The changes add memory-tracker tests, a GPU regression test, a test selector, and a CTest entry.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Refactor

Merge Risk: ⚪ Minimal · up to 0a962

The change reduces BDA preparation scanning overhead using dirty-region hints. No concrete merge-blocking risk was found in the supplied context, and the author reports focused tests passing.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: avoiding full buffer sweeps during BDA preparation.
Description check Passed The description directly explains the dirty-region worklist implementation, its scope, validation, limitations, and excluded changes.
Docstring Coverage Passed Docstring coverage is 89.87% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 79 functions across 6 files. (1 skipped: 1 …
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.
  • 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-11 00:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1391#issuecomment-6103803132) · edited 2026-10-16 02:12 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/1391?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 --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 0a9625c753427b4f003a01f4adc0b7be72e32f23 > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `feb55c3a-2d7b-4ee8-9a1d-fde911d8b231` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 1f2d44b18c689e09e9980d7874a61e277f2e2272 and 0a9625c753427b4f003a01f4adc0b7be72e32f23. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 3</strong></summary> <dl> <dd> * `src/graphics/host_gpu/memoryTracker.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </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. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> MemoryTracker now records CPU-dirty region hints and provides APIs to queue and drain them. BufferCache queues registered and mapped ranges, then synchronizes dirty intersections with mapped ranges during BDA preparation. RenderContext queues newly mapped ranges and calls the synchronization method. The changes add memory-tracker tests, a GPU regression test, a test selector, and a CTest entry. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"0a9625c753427b4f003a01f4adc0b7be72e32f23" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>0a962</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `0a962` --> <!-- final_review_risk_coverage:{"sourceCommitId":"0a9625c753427b4f003a01f4adc0b7be72e32f23","coveredCommitId":"0a9625c753427b4f003a01f4adc0b7be72e32f23","kind":"reviewed"} --> The change reduces BDA preparation scanning overhead using dirty-region hints. No concrete merge-blocking risk was found in the supplied context, and the author reports focused tests passing. <!-- 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> 5</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 primary change: avoiding full buffer sweeps during BDA preparation. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the dirty-region worklist implementation, its scope, validation, limitations, and excluded changes. | | Docstring Coverage | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Docstring coverage is 89.87% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 79 functions across 6 files. (1 skipped: 1 … | | 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> <!-- 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=1391)! 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 -->
Author
Owner

@⁠kewalker on GitHub · 2026-10-11 14:06 UTC · original

@⁠nmzik CodeRabbit suggested you as a reviewer for this Demon's Souls BDA buffer-preparation change. Would you be able to review it when you have time? Thank you.

**@⁠kewalker** on GitHub · 2026-10-11 14:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1391#issuecomment-6109855378) @⁠nmzik CodeRabbit suggested you as a reviewer for this Demon's Souls BDA buffer-preparation change. Would you be able to review it when you have time? Thank you.
Author
Owner

@⁠kewalker on GitHub · 2026-10-16 15:29 UTC · original

Closing as superseded by d58aefde (renderer: reduce synchronization and allocation overhead), which adds incremental BDA synchronization to main. This PR used a coarse atomic bitmap; any future comparison of that approach should be a separate, measured change.

**@⁠kewalker** on GitHub · 2026-10-16 15:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1391#issuecomment-6218860814) Closing as superseded by d58aefde (renderer: reduce synchronization and allocation overhead), which adds incremental BDA synchronization to main. This PR used a coarse atomic bitmap; any future comparison of that approach should be a separate, measured change.

Pull request closed

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