graphics: keep image-to-image copies inside both images #1176

Open
github-bot wants to merge 2 commits from github-bot/gh-1176 into main AGit
Owner

@⁠overlordxrz-source on GitHub · 2026-10-08 01:14 UTC · original
overlordxrz-source:graphics/clamp-image-copy-extent → main · +86 −6 · 3 files · 2 commits · open

Image::CopyImage and Image::CopyImageWithBuffer size every mip level of the copy from the source image only. When the cache copies a larger image into a smaller one (for example a replacement whose descriptor asks for a smaller extent), the region runs past the destination. That is out of bounds for vkCmdCopyImage / vkCmdCopyBufferToImage: the validation layer reports it, and without the layers the copy writes past the destination image on the GPU.

This clamps the copy to what fits in both images:

  • new Image::CopyExtent helper. Vulkan measures a copy region in source texels and scales it by the texel block ratio on the destination, so it converts the destination size into source texels before taking the minimum. For formats with the same block shape it is just min(source, destination).
  • both copy paths use it for the width and height of each level, and skip a level that has no room in the destination
  • the 2D <-> 3D branch of CopyImage had the same problem in the third dimension: it copied as many layers as the 3D image had slices (or the reverse) without checking the 2D image had that many layers. That count is clamped too.

One thing I'm not sure about: when two block-compressed images differ in size, the clamped extent can end on a partial block of the smaller image. I haven't seen this case in a log.

Evidence

  • #1153 The Adventures of Elliot (build 2026-10-07-d2413fc, windowed mode), with the Vulkan SDK installed:

    vkCmdCopyImage(): pRegions[0].dstOffset.x (0) + extent.width (475) exceeds miplevel 0 which has a width of 455.
    srcImage: VK_IMAGE_TYPE_3D VK_FORMAT_B10G11R11_UFLOAT_PACK32 [475, 5, 5]
    dstImage: VK_IMAGE_TYPE_3D VK_FORMAT_R8G8B8A8_UNORM [455, 5, 5]
    

    Both formats are 4 bytes per texel, so this is the plain min(475, 455) case.

  • The same game is reported in #1124 and #1042. #1124 stops earlier on a mesh shader Not implemented, and #1042 reports broken graphics in game with no log, so I can't say this copy is the cause there. I'm not claiming this fixes the game's rendering.

Testing

tests/ShaderRecompilerComputeTests.cpp: ImageTestAccess exposes CopyExtent, and a new check next to the CopyRows one covers the #1153 sizes in both directions, equal and different block widths, a level that doesn't fit, and a zero block size.

I couldn't run shader_recompiler_compute_tests. It needs a Vulkan device, and my machine is aarch64 Linux with no Vulkan. Here is what I did instead:

  • compiled image.cpp for x86_64-linux-gnu and x86_64-windows-gnu (mingw), and the updated test file for x86_64-linux-gnu, with clang (zig c++) at -Wall -Wextra. The changed lines add no warnings.
  • ran the same CopyExtent cases (10) in a small native harness built from image.cpp. All pass. This only covers the extent math, not an actual copy on a GPU.
  • the changed src/ lines are clean under src/.clang-format (clang-format 23.1.3)

Not run with the validation layers or with the game.

AI assistance

An AI assistant helped me find the out-of-bounds copy from the issue log, write the change and the test, and run the builds above. I reviewed the code and the results.

**@⁠overlordxrz-source** on GitHub · 2026-10-08 01:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176) `overlordxrz-source:graphics/clamp-image-copy-extent` → `main` · +86 −6 · 3 files · 2 commits · open `Image::CopyImage` and `Image::CopyImageWithBuffer` size every mip level of the copy from the source image only. When the cache copies a larger image into a smaller one (for example a replacement whose descriptor asks for a smaller extent), the region runs past the destination. That is out of bounds for `vkCmdCopyImage` / `vkCmdCopyBufferToImage`: the validation layer reports it, and without the layers the copy writes past the destination image on the GPU. This clamps the copy to what fits in both images: - new `Image::CopyExtent` helper. Vulkan measures a copy region in source texels and scales it by the texel block ratio on the destination, so it converts the destination size into source texels before taking the minimum. For formats with the same block shape it is just `min(source, destination)`. - both copy paths use it for the width and height of each level, and skip a level that has no room in the destination - the 2D <-> 3D branch of `CopyImage` had the same problem in the third dimension: it copied as many layers as the 3D image had slices (or the reverse) without checking the 2D image had that many layers. That count is clamped too. One thing I'm not sure about: when two block-compressed images differ in size, the clamped extent can end on a partial block of the smaller image. I haven't seen this case in a log. ## Evidence - #1153 The Adventures of Elliot (build 2026-10-07-d2413fc, windowed mode), with the Vulkan SDK installed: ``` vkCmdCopyImage(): pRegions[0].dstOffset.x (0) + extent.width (475) exceeds miplevel 0 which has a width of 455. srcImage: VK_IMAGE_TYPE_3D VK_FORMAT_B10G11R11_UFLOAT_PACK32 [475, 5, 5] dstImage: VK_IMAGE_TYPE_3D VK_FORMAT_R8G8B8A8_UNORM [455, 5, 5] ``` Both formats are 4 bytes per texel, so this is the plain `min(475, 455)` case. - The same game is reported in #1124 and #1042. #1124 stops earlier on a mesh shader `Not implemented`, and #1042 reports broken graphics in game with no log, so I can't say this copy is the cause there. I'm not claiming this fixes the game's rendering. ## Testing `tests/ShaderRecompilerComputeTests.cpp`: `ImageTestAccess` exposes `CopyExtent`, and a new check next to the `CopyRows` one covers the #1153 sizes in both directions, equal and different block widths, a level that doesn't fit, and a zero block size. I couldn't run `shader_recompiler_compute_tests`. It needs a Vulkan device, and my machine is aarch64 Linux with no Vulkan. Here is what I did instead: - compiled `image.cpp` for `x86_64-linux-gnu` and `x86_64-windows-gnu` (mingw), and the updated test file for `x86_64-linux-gnu`, with clang (zig c++) at `-Wall -Wextra`. The changed lines add no warnings. - ran the same `CopyExtent` cases (10) in a small native harness built from `image.cpp`. All pass. This only covers the extent math, not an actual copy on a GPU. - the changed `src/` lines are clean under `src/.clang-format` (clang-format 23.1.3) Not run with the validation layers or with the game. ## AI assistance An AI assistant helped me find the out-of-bounds copy from the issue log, write the change and the test, and run the builds above. I reviewed the code and the results.
Image::CopyImage and Image::CopyImageWithBuffer sized every mip level of
the copy from the source image only. When the cache copies a larger
image into a smaller one (a replacement whose descriptor asks for a
smaller extent, for example) the region runs past the destination, which
is out of bounds for vkCmdCopyImage / vkCmdCopyBufferToImage.

The Adventures of Elliot (#1153) trips the validation layer on exactly
this, with a 3D LUT that is 475 texels wide in the cached image and 455
in its replacement:

  vkCmdCopyImage(): pRegions[0].dstOffset.x (0) + extent.width (475)
  exceeds miplevel 0 which has a width of 455.
  srcImage: VK_IMAGE_TYPE_3D B10G11R11_UFLOAT_PACK32 [475, 5, 5]
  dstImage: VK_IMAGE_TYPE_3D R8G8B8A8_UNORM [455, 5, 5]

Without the layers the copy writes past the destination on the GPU.

Clamp the width and height of each level to what fits in both images.
Vulkan measures the region in source texels and scales it by the texel
block ratio on the destination, so CopyExtent converts the destination
size into source texels before taking the minimum; for formats with the
same block shape it is just min(source, destination). A level that has
no room in the destination is skipped.

The 2D <-> 3D branch of CopyImage had the same problem in the third
dimension: it copied as many layers as the 3D image had slices (or the
reverse), without checking the 2D image had that many layers. Clamp
that count too.

tests: check CopyExtent through ImageTestAccess next to CopyRows.
Review on #1176 pointed out that CopyExtent could clamp a compressed
copy to a width that ends inside a block. With 4x4 blocks, a source 475
texels wide and a destination 455 wide gave 455, which is neither a
whole number of source blocks nor the edge of the source image, so
vkCmdCopyImage and vkCmdCopyImageToBuffer reject it.

After clamping to both images, CopyExtent now keeps a partial block only
when the region reaches the edge of the source and the destination
region is whole blocks or reaches the destination edge. Otherwise it
rounds down to the source block size. This applies to width and height
in both CopyImage and CopyImageWithBuffer. CopyImageWithBuffer now skips
a level that has no whole block left, as CopyImage already did, instead
of hitting the rows_per_copy assert.

tests: add compressed cases to the CopyExtent check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:46:39 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 01:16 UTC · original · edited 2026-10-08 01:46 UTC

Review in Change Stack →

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: af216529-5f97-435d-8809-91fb488ff85f
📥 Commits

Reviewing files that changed from the base of the PR and between 32ab50548b and c2f7a2651b.

📒 Files selected for processing (2)
  • src/graphics/host_gpu/renderer/image/image.cpp
  • tests/ShaderRecompilerComputeTests.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/ShaderRecompilerComputeTests.cpp
  • src/graphics/host_gpu/renderer/image/image.cpp

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


📝 Walkthrough

Walkthrough

Image copies now calculate width and height using both images’ dimensions and texel-block sizes. CopyImage and CopyImageWithBuffer skip mip levels when either computed dimension is zero. CopyImage also clamps layer counts for 2D-to-3D and 3D-to-2D copies. Tests cover extent bounds, block alignment, image edges, and zero block sizes.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to c2f7a

No actionable risk introduced by this PR remains identified. Merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ 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 checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: keeping image-to-image copies within the bounds of both images.
Description check ✅ Passed The description directly explains the out-of-bounds copy issue, the extent-clamping changes, affected copy paths, testing, and known limitations.
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.)

  • Autopilot · 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-08 01:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#issuecomment-6050161359) · edited 2026-10-08 01:46 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/1176?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><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> <!-- 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**: `af216529-5f97-435d-8809-91fb488ff85f` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 32ab50548bd3cbe7c06acf7e9bff29c0b4c527c7 and c2f7a2651b27ec5b39c5155ad83ee4f20ec42a61. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/host_gpu/renderer/image/image.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * tests/ShaderRecompilerComputeTests.cpp * src/graphics/host_gpu/renderer/image/image.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Image copies now calculate width and height using both images’ dimensions and texel-block sizes. `CopyImage` and `CopyImageWithBuffer` skip mip levels when either computed dimension is zero. `CopyImage` also clamps layer counts for 2D-to-3D and 3D-to-2D copies. Tests cover extent bounds, block alignment, image edges, and zero block sizes. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"c2f7a2651b27ec5b39c5155ad83ee4f20ec42a61" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `c2f7a` <!-- final_review_risk_coverage:{"sourceCommitId":"c2f7a2651b27ec5b39c5155ad83ee4f20ec42a61","coveredCommitId":"c2f7a2651b27ec5b39c5155ad83ee4f20ec42a61","kind":"reviewed"} --> No actionable risk introduced by this PR remains identified. Merge after normal checks. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❓ 1</summary> ### ❌ 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. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ✅ Passed | The title clearly and concisely describes the main change: keeping image-to-image copies within the bounds of both images. | | Description check | ✅ Passed | The description directly explains the out-of-bounds copy issue, the extent-clamping changes, affected copy paths, testing, and known limitations. | | 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> <summary>Full details: Docstring Coverage</summary> **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.) </details> </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">Autopilot</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=1176)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 01:16 UTC · original · edited 2026-10-08 01:40 UTC
On src/graphics/host_gpu/renderer/image/image.cpp line 475 (outdated):

@@ -450,6 +464,17 @@ void Image::Resolve(Image& source, const ImageSubresourceRange& source_range,
 	}
 }
 
+uint32_t Image::CopyExtent(uint32_t source, uint32_t destination, uint32_t source_block,
+                           uint32_t destination_block) noexcept {
+	if (source_block == 0 || destination_block == 0) {
+		return 0;
+	}
+	// Copy regions are measured in source texels and scaled by the block ratio on the
+	// destination, so keep the region inside both images.
+	const auto fit = static_cast<uint64_t>(destination) * source_block / destination_block;
+	return static_cast<uint32_t>(std::min<uint64_t>(source, fit));

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Align extents when the destination truncates a compressed copy. CopyExtent bounds the copy but can return a partial source block inside the source image. For example, source width 475, destination width 455, and four-texel blocks produce width 455. Vulkan requires a non-edge compressed source extent to be block-aligned. Correct both width and height without exceeding either image. (docs.vulkan.org)

  • src/graphics/host_gpu/renderer/image/image.cpp#L474-L475: make the bounded extent respect the source block boundary when it does not reach the source edge.
  • src/graphics/host_gpu/renderer/image/image.cpp#L360-L365: use the corrected extent for direct image copies.
  • src/graphics/host_gpu/renderer/image/image.cpp#L524-L529: use the corrected extent for buffer-mediated copies.
📍 Affects 1 file
  • src/graphics/host_gpu/renderer/image/image.cpp#L474-L475 (this comment)
  • src/graphics/host_gpu/renderer/image/image.cpp#L360-L365
  • src/graphics/host_gpu/renderer/image/image.cpp#L524-L529

✅ Confirmed as addressed by @⁠overlordxrz-source

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 01:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#discussion_r4213648226) · edited 2026-10-08 01:40 UTC On `src/graphics/host_gpu/renderer/image/image.cpp` line 475 (outdated): ```diff @@ -450,6 +464,17 @@ void Image::Resolve(Image& source, const ImageSubresourceRange& source_range, } } +uint32_t Image::CopyExtent(uint32_t source, uint32_t destination, uint32_t source_block, + uint32_t destination_block) noexcept { + if (source_block == 0 || destination_block == 0) { + return 0; + } + // Copy regions are measured in source texels and scaled by the block ratio on the + // destination, so keep the region inside both images. + const auto fit = static_cast<uint64_t>(destination) * source_block / destination_block; + return static_cast<uint32_t>(std::min<uint64_t>(source, fit)); ``` **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** **Align extents when the destination truncates a compressed copy.** `CopyExtent` bounds the copy but can return a partial source block inside the source image. For example, source width 475, destination width 455, and four-texel blocks produce width 455. Vulkan requires a non-edge compressed source extent to be block-aligned. Correct both width and height without exceeding either image. ([docs.vulkan.org](https://docs.vulkan.org/refpages/latest/refpages/source/vkCmdCopyImage.html)) - `src/graphics/host_gpu/renderer/image/image.cpp#L474-L475`: make the bounded extent respect the source block boundary when it does not reach the source edge. - `src/graphics/host_gpu/renderer/image/image.cpp#L360-L365`: use the corrected extent for direct image copies. - `src/graphics/host_gpu/renderer/image/image.cpp#L524-L529`: use the corrected extent for buffer-mediated copies. <details> <summary>📍 Affects 1 file</summary> - `src/graphics/host_gpu/renderer/image/image.cpp#L474-L475` (this comment) - `src/graphics/host_gpu/renderer/image/image.cpp#L360-L365` - `src/graphics/host_gpu/renderer/image/image.cpp#L524-L529` </details> <!-- consolidated_sites_start --> <!-- <consolidated_sites> <site> <role>anchor</role> <file>src/graphics/host_gpu/renderer/image/image.cpp</file> <line_range>474-475</line_range> </site> <site> <role>sibling</role> <file>src/graphics/host_gpu/renderer/image/image.cpp</file> <line_range>360-365</line_range> </site> <site> <role>sibling</role> <file>src/graphics/host_gpu/renderer/image/image.cpp</file> <line_range>524-529</line_range> </site> </consolidated_sites> --> <!-- consolidated_sites_end --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:5cf3f42adabdfea8451c0b5b --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠overlordxrz-source <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 01:16 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: ccda6d8b-8859-43d8-91e5-24898f247e27
📥 Commits

Reviewing files that changed from the base of the PR and between 5a8808086a and 32ab50548b.

📒 Files selected for processing (3)
  • src/graphics/host_gpu/renderer/image/image.cpp
  • src/graphics/host_gpu/renderer/image/image.h
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 01:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#pullrequestreview-5450279238) · **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**: `ccda6d8b-8859-43d8-91e5-24898f247e27` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5a8808086a9815b67d4822cd20cf1e8a7a05f002 and 32ab50548bd3cbe7c06acf7e9bff29c0b4c527c7. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/host_gpu/renderer/image/image.cpp` * `src/graphics/host_gpu/renderer/image/image.h` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=50a7e808-c23a-4f46-8db6-08bfc5e8df07 attempt=38307a2f-fcc0-40a8-8b3f-aae12a69e5c1 batch=1/1 -->
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-08 01:39 UTC · original
On src/graphics/host_gpu/renderer/image/image.cpp line 475 (outdated):

@@ -450,6 +464,17 @@ void Image::Resolve(Image& source, const ImageSubresourceRange& source_range,
 	}
 }
 
+uint32_t Image::CopyExtent(uint32_t source, uint32_t destination, uint32_t source_block,
+                           uint32_t destination_block) noexcept {
+	if (source_block == 0 || destination_block == 0) {
+		return 0;
+	}
+	// Copy regions are measured in source texels and scaled by the block ratio on the
+	// destination, so keep the region inside both images.
+	const auto fit = static_cast<uint64_t>(destination) * source_block / destination_block;
+	return static_cast<uint32_t>(std::min<uint64_t>(source, fit));

Agreed, thanks. With 4x4 blocks, 475 -> 455 clamped to 455, which is neither a whole number of source blocks nor the source edge.

Fixed in "graphics: keep clamped compressed copies on block boundaries". CopyExtent now keeps a partial block only when the region reaches the source edge and the destination region is whole blocks or reaches the destination edge. Otherwise it rounds down to the source block size, so 475 -> 455 now copies 452. Width and height go through the same helper in CopyImage and CopyImageWithBuffer. CopyImageWithBuffer now skips a level with no whole block left, as CopyImage already did. In a case like this, the last partial block of the smaller image is not copied, because no valid region covers it.

I added compressed cases to the CopyExtent test. I also checked the helper against a brute-force model of the vkCmdCopyImage extent rules for every width up to 300 with 1x1/4x4 block pairs.

**@⁠overlordxrz-source** on GitHub · 2026-10-08 01:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#discussion_r4213758455) On `src/graphics/host_gpu/renderer/image/image.cpp` line 475 (outdated): ```diff @@ -450,6 +464,17 @@ void Image::Resolve(Image& source, const ImageSubresourceRange& source_range, } } +uint32_t Image::CopyExtent(uint32_t source, uint32_t destination, uint32_t source_block, + uint32_t destination_block) noexcept { + if (source_block == 0 || destination_block == 0) { + return 0; + } + // Copy regions are measured in source texels and scaled by the block ratio on the + // destination, so keep the region inside both images. + const auto fit = static_cast<uint64_t>(destination) * source_block / destination_block; + return static_cast<uint32_t>(std::min<uint64_t>(source, fit)); ``` Agreed, thanks. With 4x4 blocks, 475 -> 455 clamped to 455, which is neither a whole number of source blocks nor the source edge. Fixed in "graphics: keep clamped compressed copies on block boundaries". CopyExtent now keeps a partial block only when the region reaches the source edge and the destination region is whole blocks or reaches the destination edge. Otherwise it rounds down to the source block size, so 475 -> 455 now copies 452. Width and height go through the same helper in CopyImage and CopyImageWithBuffer. CopyImageWithBuffer now skips a level with no whole block left, as CopyImage already did. In a case like this, the last partial block of the smaller image is not copied, because no valid region covers it. I added compressed cases to the CopyExtent test. I also checked the helper against a brute-force model of the vkCmdCopyImage extent rules for every width up to 300 with 1x1/4x4 block pairs.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 01:40 UTC · original
On src/graphics/host_gpu/renderer/image/image.cpp line 475 (outdated):

@@ -450,6 +464,17 @@ void Image::Resolve(Image& source, const ImageSubresourceRange& source_range,
 	}
 }
 
+uint32_t Image::CopyExtent(uint32_t source, uint32_t destination, uint32_t source_block,
+                           uint32_t destination_block) noexcept {
+	if (source_block == 0 || destination_block == 0) {
+		return 0;
+	}
+	// Copy regions are measured in source texels and scaled by the block ratio on the
+	// destination, so keep the region inside both images.
+	const auto fit = static_cast<uint64_t>(destination) * source_block / destination_block;
+	return static_cast<uint32_t>(std::min<uint64_t>(source, fit));

@overlordxrz-source Thanks for the fix. The supplied code addresses this finding: CopyExtent(475, 455, 4, 4) returns 452, and both copy paths skip levels with zero width or height.

The source-edge exception also checks the destination block boundary or destination edge before retaining a partial block.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 01:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#discussion_r4213760028) On `src/graphics/host_gpu/renderer/image/image.cpp` line 475 (outdated): ```diff @@ -450,6 +464,17 @@ void Image::Resolve(Image& source, const ImageSubresourceRange& source_range, } } +uint32_t Image::CopyExtent(uint32_t source, uint32_t destination, uint32_t source_block, + uint32_t destination_block) noexcept { + if (source_block == 0 || destination_block == 0) { + return 0; + } + // Copy regions are measured in source texels and scaled by the block ratio on the + // destination, so keep the region inside both images. + const auto fit = static_cast<uint64_t>(destination) * source_block / destination_block; + return static_cast<uint32_t>(std::min<uint64_t>(source, fit)); ``` `@overlordxrz-source` Thanks for the fix. The supplied code addresses this finding: `CopyExtent(475, 455, 4, 4)` returns `452`, and both copy paths skip levels with zero width or height. The source-edge exception also checks the destination block boundary or destination edge before retaining a partial block. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Compressed%20Vulkan%20copies%20need%20block-aligned%20extents%20when%20clamped.%20%40coderabbitai%20caught%20the%20edge%20case%20and%20helped%20ensure%20safe%20copies%20across%20image%20paths%E2%80%94try%20it%20on%20your%20next%20PR!%20%F0%9F%A7%B1%E2%9A%A1&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1176%23discussion_r4213648226)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 19:07 UTC · original

I tested this PR's two commits (32ab5054, c2f7a265), applied on 763d3be3 with my local test runners, on an RX 9070 XT and a Ryzen 7600X iGPU (AMD driver 26.8.1, Windows 11), with the Khronos validation layer from Vulkan SDK 1.4.363.0. Jusant (#1636) stops on the same kind of error: a 60x33x26 3D B10G11R11 image copied into a 54x33x26 one.

  • Copies through the texture cache (images from TextureCache::FindImage, copied with TextureCache::CopyImage, and with Image::CopyImageWithBuffer where the block sizes match). Without this PR the layer rejects 7 of 16 direct copies (vkCmdCopyImage dstOffset-00150, and dstOffset-00153 plus dstSubresource-07968 for a 16x16x8 3D image copied into a 2D array with 4 layers) and 6 of 11 buffer copies (vkCmdCopyBufferToImage 07971 and 00207). The Jusant case gives the report's message word for word. With this PR it rejects none on either GPU, including the BC5 partial-block cases you weren't sure about (16x16 into 6x6, 6x6 into 16x16, 7x7 into 6x6), and in the four cases with a texel check the last copied texel matches the source.
  • ImageTransitionState with your new CopyExtent checks passes on the RX 9070 XT. On the iGPU it stops later, at "combined depth/stencil mip copy lost an aspect", with and without this PR (an AMD driver bug I reported to AMD).
  • CopyExtent against a model of the Vulkan copy rules, for every pair of lengths from 1 to 1024 and block widths 1/1, 4/4, 4/1 and 1/4: the result is always valid for both images and the largest valid length.
  • On both GPUs, the compute suite (808 entries, native and with the harness forced to 32-wide subgroups, a local switch) and the 30 graphics cases give the same results with and without this PR.
  • Cherry-picked onto current main (099de8de), it builds and passes the tests on Windows, Linux and macOS: https://github.com/Nawid3333/KytyPS5/actions/runs/39154477473

Written with Claude Code (AI): it ran these tests on my PC; I read this before posting.

**@⁠Nawid3333** on GitHub · 2026-10-18 19:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#issuecomment-6253929246) I tested this PR's two commits (32ab5054, c2f7a265), applied on 763d3be3 with my local test runners, on an RX 9070 XT and a Ryzen 7600X iGPU (AMD driver 26.8.1, Windows 11), with the Khronos validation layer from Vulkan SDK 1.4.363.0. Jusant (#1636) stops on the same kind of error: a 60x33x26 3D B10G11R11 image copied into a 54x33x26 one. - Copies through the texture cache (images from `TextureCache::FindImage`, copied with `TextureCache::CopyImage`, and with `Image::CopyImageWithBuffer` where the block sizes match). Without this PR the layer rejects 7 of 16 direct copies (`vkCmdCopyImage` dstOffset-00150, and dstOffset-00153 plus dstSubresource-07968 for a 16x16x8 3D image copied into a 2D array with 4 layers) and 6 of 11 buffer copies (`vkCmdCopyBufferToImage` 07971 and 00207). The Jusant case gives the report's message word for word. With this PR it rejects none on either GPU, including the BC5 partial-block cases you weren't sure about (16x16 into 6x6, 6x6 into 16x16, 7x7 into 6x6), and in the four cases with a texel check the last copied texel matches the source. - `ImageTransitionState` with your new `CopyExtent` checks passes on the RX 9070 XT. On the iGPU it stops later, at "combined depth/stencil mip copy lost an aspect", with and without this PR (an AMD driver bug I reported to AMD). - `CopyExtent` against a model of the Vulkan copy rules, for every pair of lengths from 1 to 1024 and block widths 1/1, 4/4, 4/1 and 1/4: the result is always valid for both images and the largest valid length. - On both GPUs, the compute suite (808 entries, native and with the harness forced to 32-wide subgroups, a local switch) and the 30 graphics cases give the same results with and without this PR. - Cherry-picked onto current main (099de8de), it builds and passes the tests on Windows, Linux and macOS: https://github.com/Nawid3333/KytyPS5/actions/runs/39154477473 Written with Claude Code (AI): it ran these tests on my PC; I read this before posting.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-19 12:30 UTC · original

Main took a plain clamp for this in 440245f6 (the std::min of both extents in Image::CopyImage), so this PR conflicts with main now. I ran my copy matrix again on e5f0ee7f, under the validation layer, on an RX 9070 XT and a Ryzen 7600X iGPU (same results on both):

  • main: Jusant's copy (3D B10G11R11 60x33x26 into 54x33x26) passes now. Still rejected:
    • BC5 16x16 into 6x6, BC5 7x7 into 6x6 and BC5 16x16 into RGBA32UI 3x3: VUID-vkCmdCopyImage-srcImage-01728 (the region ends inside a block). BC5 7x7 into 6x6 passed before 440245f6.
    • RGBA32UI 4x4 into BC5 12x12: VUID-vkCmdCopyImage-dstOffset-00150 (the block ratio is not applied).
    • 3D 16x16x8 into a 2D image with 4 layers: VUID-vkCmdCopyImage-dstOffset-00153 and VUID-vkCmdCopyImage-dstSubresource-07968.
    • CopyImageWithBuffer: the five cases that copy a 2D or 3D image into a smaller one (Jusant's images among them) and BC5 6x6 into 16x16, with VUID-vkCmdCopyBufferToImage-imageSubresource-07971 or dstImage-00207.
  • this PR on e5f0ee7f, with the conflict resolved by keeping your CopyExtent calls in place of the two std::min lines: all of these pass, and every texel read back has the expected value.
All cases (ok, or the number of the VUID the validation layer rejects the copy with; both GPUs give the same table)
case main, direct this PR, direct main, buffer this PR, buffer
3D B10G11R11 60x33x26 into 54x33x26 ok ok 07971 (10 errors) ok
RGBA8 64x48 into 50x30 ok ok 07971 ok
RGBA8 50x30 into 64x48 ok ok ok ok
RGBA8 64x64 into 64x64 ok ok ok ok
BC5 16x16 into 8x8 ok ok 07971 ok
BC5 16x16 into 6x6 01728 ok 07971 ok
BC5 6x6 into 16x16 ok ok 00207 ok
BC5 7x7 into 6x6 01728 ok 00207, 07971 ok
BC5 16x16 into RGBA32UI 4x4 ok ok
BC5 16x16 into RGBA32UI 3x3 01728 ok
RGBA32UI 4x4 into BC5 16x16 ok ok
RGBA32UI 4x4 into BC5 12x12 00150 ok
RGBA32UI 2x2 into BC5 6x6 ok ok
3D 16x16x8 into 2D 16x16, 4 layers 00153, 07968 ok ok ok
2D 16x16, 8 layers into 3D 16x16x4 ok ok ok ok
3D 16x16x4 into 2D 16x16, 4 layers ok ok ok ok

The buffer path is not run for the cases where the two formats have different block sizes: CopyImageWithBuffer stops on purpose there (its EXIT_IF on different block sizes), with and without this PR.

**@⁠Nawid3333** on GitHub · 2026-10-19 12:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1176#issuecomment-6267256859) Main took a plain clamp for this in 440245f6 (the `std::min` of both extents in `Image::CopyImage`), so this PR conflicts with main now. I ran my copy matrix again on e5f0ee7f, under the validation layer, on an RX 9070 XT and a Ryzen 7600X iGPU (same results on both): - **main:** Jusant's copy (3D B10G11R11 60x33x26 into 54x33x26) passes now. Still rejected: - BC5 16x16 into 6x6, BC5 7x7 into 6x6 and BC5 16x16 into RGBA32UI 3x3: `VUID-vkCmdCopyImage-srcImage-01728` (the region ends inside a block). BC5 7x7 into 6x6 passed before 440245f6. - RGBA32UI 4x4 into BC5 12x12: `VUID-vkCmdCopyImage-dstOffset-00150` (the block ratio is not applied). - 3D 16x16x8 into a 2D image with 4 layers: `VUID-vkCmdCopyImage-dstOffset-00153` and `VUID-vkCmdCopyImage-dstSubresource-07968`. - `CopyImageWithBuffer`: the five cases that copy a 2D or 3D image into a smaller one (Jusant's images among them) and BC5 6x6 into 16x16, with `VUID-vkCmdCopyBufferToImage-imageSubresource-07971` or `dstImage-00207`. - **this PR on e5f0ee7f**, with the conflict resolved by keeping your `CopyExtent` calls in place of the two `std::min` lines: all of these pass, and every texel read back has the expected value. <details><summary>All cases (ok, or the number of the VUID the validation layer rejects the copy with; both GPUs give the same table)</summary> | case | main, direct | this PR, direct | main, buffer | this PR, buffer | |---|---|---|---|---| | 3D B10G11R11 60x33x26 into 54x33x26 | ok | ok | `07971` (10 errors) | ok | | RGBA8 64x48 into 50x30 | ok | ok | `07971` | ok | | RGBA8 50x30 into 64x48 | ok | ok | ok | ok | | RGBA8 64x64 into 64x64 | ok | ok | ok | ok | | BC5 16x16 into 8x8 | ok | ok | `07971` | ok | | BC5 16x16 into 6x6 | `01728` | ok | `07971` | ok | | BC5 6x6 into 16x16 | ok | ok | `00207` | ok | | BC5 7x7 into 6x6 | `01728` | ok | `00207`, `07971` | ok | | BC5 16x16 into RGBA32UI 4x4 | ok | ok | | | | BC5 16x16 into RGBA32UI 3x3 | `01728` | ok | | | | RGBA32UI 4x4 into BC5 16x16 | ok | ok | | | | RGBA32UI 4x4 into BC5 12x12 | `00150` | ok | | | | RGBA32UI 2x2 into BC5 6x6 | ok | ok | | | | 3D 16x16x8 into 2D 16x16, 4 layers | `00153`, `07968` | ok | ok | ok | | 2D 16x16, 8 layers into 3D 16x16x4 | ok | ok | ok | ok | | 3D 16x16x4 into 2D 16x16, 4 layers | ok | ok | ok | ok | The buffer path is not run for the cases where the two formats have different block sizes: `CopyImageWithBuffer` stops on purpose there (its `EXIT_IF` on different block sizes), with and without this PR. </details>
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/image/image.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1176/head:github-bot/gh-1176'
git switch 'github-bot/gh-1176'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1176'
git switch 'github-bot/gh-1176'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1176'
git switch 'github-bot/gh-1176'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1176'
git switch 'main'
git merge --squash 'github-bot/gh-1176'
git switch 'main'
git merge --ff-only 'github-bot/gh-1176'
git switch 'main'
git merge 'github-bot/gh-1176'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.