renderer: publish linear storage images before CPU access #537

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

@⁠CheesyPoofs346 on GitHub · 2026-09-09 07:39 UTC · original
CheesyPoofs346:renderer-publish-linear-storage → main · +510 −16 · 13 files · 1 commits · closed without merging

Problem. A linear image the GPU has written is not visible to the guest CPU until its contents are downloaded to the backing. The page-fault path published GPU-modified buffers but not linear storage images, so a title that writes a linear storage image on the GPU and then reads it on the CPU observed whatever the backing happened to hold — stale bytes, or never-written ones.

Change. Track linear storage images the GPU has modified, and publish them to their backing before the CPU is allowed to observe the page, through the same fault path that already publishes buffers. The page manager learns to ask the resource manager for an image publication, and the texture cache performs the download.

Effect. CPU reads of a GPU-written linear storage image return the written contents. No performance change was measured, and none is claimed; the publication happens on the faulting path, so it costs a download only when the CPU actually touches such an image.

Verification. Device-backed coverage included and passing:

  • LinearImageCpuReadback — writes a linear image on the GPU, then reads it back on the CPU through the guest path and compares.
  • PrivateBufferUpload — covers the buffer path that the same publication mechanism uses.
  • HostImageAllocation and the existing PageManagerTests still pass.
    Full ShaderRecompilerComputeTests and PageManagerTests suites pass.

Limitations.

  • Covers linear storage images. Tiled images are not published by this path, since the CPU cannot interpret their layout directly.
  • The tests exercise a written-then-read sequence on one image; they do not cover concurrent GPU writes racing a CPU read, which remains ordered by the fault only.

References

No external specification. Correctness argument only: a GPU write to a linear image lands in device memory, and the guest's view of that memory is the backing, so the CPU's first observation of the page must be preceded by a download — the same invariant the buffer path already maintains.

**@⁠CheesyPoofs346** on GitHub · 2026-09-09 07:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/537) `CheesyPoofs346:renderer-publish-linear-storage` → `main` · +510 −16 · 13 files · 1 commits · closed without merging **Problem.** A linear image the GPU has written is not visible to the guest CPU until its contents are downloaded to the backing. The page-fault path published GPU-modified *buffers* but not linear storage images, so a title that writes a linear storage image on the GPU and then reads it on the CPU observed whatever the backing happened to hold — stale bytes, or never-written ones. **Change.** Track linear storage images the GPU has modified, and publish them to their backing before the CPU is allowed to observe the page, through the same fault path that already publishes buffers. The page manager learns to ask the resource manager for an image publication, and the texture cache performs the download. **Effect.** CPU reads of a GPU-written linear storage image return the written contents. No performance change was measured, and none is claimed; the publication happens on the faulting path, so it costs a download only when the CPU actually touches such an image. **Verification.** Device-backed coverage included and passing: - `LinearImageCpuReadback` — writes a linear image on the GPU, then reads it back on the CPU through the guest path and compares. - `PrivateBufferUpload` — covers the buffer path that the same publication mechanism uses. - `HostImageAllocation` and the existing `PageManagerTests` still pass. Full `ShaderRecompilerComputeTests` and `PageManagerTests` suites pass. **Limitations.** - Covers linear storage images. Tiled images are not published by this path, since the CPU cannot interpret their layout directly. - The tests exercise a written-then-read sequence on one image; they do not cover concurrent GPU writes racing a CPU read, which remains ordered by the fault only. **References** No external specification. Correctness argument only: a GPU write to a linear image lands in device memory, and the guest's view of that memory is the backing, so the CPU's first observation of the page must be preceded by a download — the same invariant the buffer path already maintains.
A linear image the GPU has written is not visible to the guest CPU until its
contents are downloaded. Reading one back through the page-fault path returned
whatever the backing held, so a title that writes a linear storage image on the
GPU and then reads it on the CPU saw stale bytes.

Track linear storage images that the GPU has modified and publish them to the
backing before the CPU is allowed to observe the page, alongside the existing
buffer download path.

Adds device-backed coverage: LinearImageCpuReadback writes an image on the GPU
and reads it back on the CPU, and PrivateBufferUpload covers the buffer path the
same publication uses.

Co-Authored-By: Claude Opus 5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:24:52 +00:00
github-bot closed this pull request 2026-11-26 09:24:52 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-09-09 07:39 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-09-09 07:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/537#pullrequestreview-5151201921) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-09-09 07:48 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c72265ae13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-09-09 07:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/537#pullrequestreview-5151294494) · **reviewed** ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `c72265ae13` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
@ -1478,0 +1491,4 @@
!info.IsDepth() && !info.IsBlock() && !info.HasMetadata() && !info.HasStencil() &&
!info.IsVolume() && info.resources == ImageSubresources {1, 1} && info.data.Valid() &&
info.data.size <= m_buffer_cache.GetUtilityBuffer(MemoryUsage::Download).Size() &&
BuildDownload(image).valid) {
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-09-09 07:48 UTC · original

P1 Badge Avoid arming readback for private guest images

When a linear storage image resides in committed code/runtime memory rather than direct or PRT-backed memory, this condition still installs a no-access CPU watcher. On the first CPU access, TryDownloadImage requires TryReadBacking to initialize the download buffer (and later uses WriteBacking), but those backing APIs reject private committed ranges—as the new private-upload test itself demonstrates—so ReadMemory terminates the emulator instead of releasing the fault. Either support publishing into private committed mappings or exclude such images before installing the watcher.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-09-09 07:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/537#discussion_r3965917262) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Avoid arming readback for private guest images** When a linear storage image resides in committed code/runtime memory rather than direct or PRT-backed memory, this condition still installs a no-access CPU watcher. On the first CPU access, `TryDownloadImage` requires `TryReadBacking` to initialize the download buffer (and later uses `WriteBacking`), but those backing APIs reject private committed ranges—as the new private-upload test itself demonstrates—so `ReadMemory` terminates the emulator instead of releasing the fault. Either support publishing into private committed mappings or exclude such images before installing the watcher. Useful? React with 👍 / 👎.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-06 17:21 UTC · original

#423 duplicate

**@⁠Nmzik** on GitHub · 2026-10-06 17:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/537#issuecomment-6021636179) #423 duplicate

Pull request closed

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