gpu: stage oversized image uploads in a private buffer instead of exiting #844

Closed
github-bot wants to merge 1 commit from gh-pr/844/head into gh-pr/844/base
Owner

@⁠theantipopau on GitHub · 2026-09-26 03:36 UTC · original
theantipopau:image-upload-fallback → main · +18 −2 · 1 files · 1 commits · closed without merging

What

BufferCache::ObtainBufferForImage staged image uploads through the shared 512 MiB m_staging_buffer and shared UploadCopies' hard failure mode: when StreamBuffer::Map cannot satisfy a reservation, it returns nullptr and the caller exited. Unlike UploadCopies, there was no fallback, so an image whose whole data range is at or above the staging capacity (a 512 MiB image, or anything larger, including a reservation padded past nonCoherentAtomSize) aborts the emulator at initialization with

BufferCache: failed to read mapped guest image backing

This adds the same fallback UploadCopies already uses for buffer uploads: copy the guest data into a private MemoryUsage::Upload buffer of exactly the requested size, flush it, and retire it through DeferOperation once the upload has been recorded.

Why this shape

  • The staging buffer is sized for throughput; a private exact-size allocation only happens on the rare oversized path, so the common path is untouched.
  • Map records nothing before failing and the fallback returns a buffer that is already populated and flushed, so there is no ordering interaction with the command scheduler.
  • The returned wrapper stays alive until the deferred release runs, which satisfies UploadImage's use of the Buffer*/offset pair.
  • The fallback keeps the same EXIT on an unreadable guest backing as the shared path, so the failure semantics for genuinely bad addresses do not change.

Testing

  • kyty_emulator builds clean with clang-cl/Ninja.
  • Not GPU-tested locally: the AMD driver here lacks VK_EXT_attachment_feedback_loop_dynamic_state, so production rasterization paths cannot run. The oversized path itself needs a title that uploads such an image; host-side behavior is unchanged for every image that fits the staging buffer.

Related: #829 (the download-side twin of this ceiling, fixed by #842), which is what led me to check the upload path.

**@⁠theantipopau** on GitHub · 2026-09-26 03:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/844) `theantipopau:image-upload-fallback` → `main` · +18 −2 · 1 files · 1 commits · closed without merging ## What `BufferCache::ObtainBufferForImage` staged image uploads through the shared 512 MiB `m_staging_buffer` and shared `UploadCopies`' hard failure mode: when `StreamBuffer::Map` cannot satisfy a reservation, it returns `nullptr` and the caller exited. Unlike `UploadCopies`, there was no fallback, so an image whose whole data range is at or above the staging capacity (a 512 MiB image, or anything larger, including a reservation padded past `nonCoherentAtomSize`) aborts the emulator at initialization with ``` BufferCache: failed to read mapped guest image backing ``` This adds the same fallback `UploadCopies` already uses for buffer uploads: copy the guest data into a private `MemoryUsage::Upload` buffer of exactly the requested size, flush it, and retire it through `DeferOperation` once the upload has been recorded. ## Why this shape - The staging buffer is sized for throughput; a private exact-size allocation only happens on the rare oversized path, so the common path is untouched. - `Map` records nothing before failing and the fallback returns a buffer that is already populated and flushed, so there is no ordering interaction with the command scheduler. - The returned wrapper stays alive until the deferred release runs, which satisfies `UploadImage`'s use of the `Buffer*`/offset pair. - The fallback keeps the same `EXIT` on an unreadable guest backing as the shared path, so the failure semantics for genuinely bad addresses do not change. ## Testing - `kyty_emulator` builds clean with clang-cl/Ninja. - Not GPU-tested locally: the AMD driver here lacks `VK_EXT_attachment_feedback_loop_dynamic_state`, so production rasterization paths cannot run. The oversized path itself needs a title that uploads such an image; host-side behavior is unchanged for every image that fits the staging buffer. Related: #829 (the download-side twin of this ceiling, fixed by #842), which is what led me to check the upload path.
ObtainBufferForImage exits when the shared 512 MiB staging buffer cannot
map an image's whole data range, so a game that uploads a 512 MiB or
larger image dies at initialization. Mirror the UploadCopies fallback:
copy the guest data into a private upload buffer of exactly the needed
size and retire it through a deferred operation once the upload has been
recorded.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:34:45 +00:00
github-bot closed this pull request 2026-11-26 09:34:45 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 03:43 UTC · original

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 90811297-e3c2-4adc-a71b-90c2ccca6b2a

📥 Commits

Reviewing files that changed from the base of the PR and between fd2e15ee73 and 8a4326cc5c.

📒 Files selected for processing (1)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp

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


📝 Walkthrough

Walkthrough

ObtainBufferForImage now allocates and fills a private upload buffer when mapping the shared staging buffer fails. It reads guest backing memory, with PRT backing as a fallback. After a successful read, it flushes the buffer, defers its release, and returns it at offset zero. The shared-buffer read path remains unchanged when mapping succeeds.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8a432

The temporary upload buffer remains available until its GPU upload completes. No concrete merge-blocking behavior is established in the reviewed change.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 8a432

No confirmed security regression was found. The new upload path retains the existing guest-memory reads and uses budget-checked allocations, but its behavior under repeated large uploads and shutdown was not fully established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly evidenced resource exposure is host upload memory in the emulator’s GPU renderer. The supplied impact map identifies one changed system and no changed dependency edges; it does not establish effects on other host workloads.

Trust Boundaries and Controls

  • observed — The fallback does not reinterpret a guest address as a host pointer: it reads guest backing through the existing memory APIs into its own mapped destination. Failure of both read attempts remains fatal.

Resilience and Maintainability Implications

  • inferred — Repeated fallback allocations could remain outstanding until their GPU ticks retire, but the evidence does not establish an upload-rate bound or that this worsens an attacker’s ability to terminate the emulator compared with the previous immediate exit. Image-initiation reachability during scheduler draining is also unresolved.

Hardening Proposals

  • proposed — Consider bounding outstanding private-upload bytes or applying backpressure, and establish that image initialization cannot publish a returned buffer while deferred cleanup takes the scheduler’s non-open path.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: using a private buffer for oversized image uploads instead of exiting.
Description check ✅ Passed The description directly explains the oversized image upload failure, the private-buffer fallback, deferred release, testing, and unchanged failure behavior.
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.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-09-26 03:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/844#issuecomment-5842867115) <!-- 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/844"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `90811297-e3c2-4adc-a71b-90c2ccca6b2a` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between fd2e15ee737ea9a671619246129bc2aae7e0bfda and 8a4326cc5ceb3633cbd19e89c745db3d0f92e32b. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `ObtainBufferForImage` now allocates and fills a private upload buffer when mapping the shared staging buffer fails. It reads guest backing memory, with PRT backing as a fallback. After a successful read, it flushes the buffer, defers its release, and returns it at offset zero. The shared-buffer read path remains unchanged when mapping succeeds. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"8a4326cc5ceb3633cbd19e89c745db3d0f92e32b" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `8a432` <!-- final_review_risk_coverage:{"sourceCommitId":"8a4326cc5ceb3633cbd19e89c745db3d0f92e32b","coveredCommitId":"8a4326cc5ceb3633cbd19e89c745db3d0f92e32b","kind":"reviewed"} --> The temporary upload buffer remains available until its GPU upload completes. No concrete merge-blocking behavior is established in the reviewed change. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `8a432` No confirmed security regression was found. The new upload path retains the existing guest-memory reads and uses budget-checked allocations, but its behavior under repeated large uploads and shutdown was not fully established. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The directly evidenced resource exposure is host upload memory in the emulator’s GPU renderer. The supplied impact map identifies one changed system and no changed dependency edges; it does not establish effects on other host workloads. **Trust Boundaries and Controls** - _observed_ — The fallback does not reinterpret a guest address as a host pointer: it reads guest backing through the existing memory APIs into its own mapped destination. Failure of both read attempts remains fatal. **Resilience and Maintainability Implications** - _inferred_ — Repeated fallback allocations could remain outstanding until their GPU ticks retire, but the evidence does not establish an upload-rate bound or that this worsens an attacker’s ability to terminate the emulator compared with the previous immediate exit. Image-initiation reachability during scheduler draining is also unresolved. **Hardening Proposals** - _proposed_ — Consider bounding outstanding private-upload bytes or applying backpressure, and establish that image initialization cannot publish a returned buffer while deferred cleanup takes the scheduler’s non-open path. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | 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 1 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ✅ Passed | The title clearly and concisely identifies the main change: using a private buffer for oversized image uploads instead of exiting. | | Description check | ✅ Passed | The description directly explains the oversized image upload failure, the private-buffer fallback, deferred release, testing, and unchanged failure behavior. | | 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. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠theantipopau on GitHub · 2026-09-26 06:11 UTC · original

Game-tested this branch locally: Terminator 2D No Fate (PPSA25872), clang-cl/Ninja Release build of this exact commit.

  • 90 s run: clean boot through Graphics init, shader compile steady state VS 5 | PS 3 | CS 6, no errors, no fatals.
  • 5-minute soak: stable for the full run (pipeline cache load/save exercised), same steady state, zero error lines.
  • Boot log is identical to an upstream/main (fd2e15ee) build apart from the usual dirty-build pipeline-cache line, so the shared-buffer fast path is byte-for-byte behavior-neutral for images that fit the staging buffer.

This title does not reach the oversized branch (its largest image is far below 512 MiB), so it validates no-regression, not the fallback itself — that still needs a title that uploads a ≥512 MiB image.

**@⁠theantipopau** on GitHub · 2026-09-26 06:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/844#issuecomment-5843790397) Game-tested this branch locally: **Terminator 2D No Fate (PPSA25872)**, clang-cl/Ninja Release build of this exact commit. - 90 s run: clean boot through Graphics init, shader compile steady state `VS 5 | PS 3 | CS 6`, no errors, no fatals. - 5-minute soak: stable for the full run (pipeline cache load/save exercised), same steady state, zero error lines. - Boot log is identical to an `upstream/main` (`fd2e15ee`) build apart from the usual dirty-build pipeline-cache line, so the shared-buffer fast path is byte-for-byte behavior-neutral for images that fit the staging buffer. This title does not reach the oversized branch (its largest image is far below 512 MiB), so it validates no-regression, not the fallback itself — that still needs a title that uploads a ≥512 MiB image.
Author
Owner

@⁠Nmzik on GitHub · 2026-09-29 18:20 UTC · original

in favour of 18a5f04d05

**@⁠Nmzik** on GitHub · 2026-09-29 18:20 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/844#issuecomment-5896066038) in favour of 18a5f04d057302d266ddcd0be207e6a75e2051c3

Pull request closed

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