graphics: clamp CopyImageWithBuffer uploads to the destination extent #1742
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1742
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1742/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@theantipopau on GitHub · 2026-10-20 00:47 UTC · original
theantipopau:fix/texture-buffer-copy-clamp→main· +43 −11 · 1 files · 3 commits · closed without mergingCompanion to
440245f6(which clamped the direct CopyImage path): the buffer-staged path reused the source extent for copyBufferToImage, so a larger source into a smaller destination writes out of bounds — the remaining Jusant #1636 validation error (60x33x26 into 54x33x26 B10G11R11). Clamps width/height per level and pins the source stride via bufferRowLength/bufferImageHeight; no behavior change when the destination covers the source.@coderabbitai[bot] on GitHub · 2026-10-20 00:51 UTC · original · edited 2026-10-22 03:29 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
447eeba2-703e-43d3-b733-be793fd9c2f7📥 Commits
Reviewing files that changed from the base of the PR and between
d42a484987and7be529ddb3.📒 Files selected for processing: 1
src/graphics/host_gpu/renderer/image/image.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Image::CopyImageWithBufferclamps copied width and height to the destination mip dimensions. It limits the slice count to the source and destination depths. It derives block-row chunking from the clamped height, preserves full source-row downloads, and sets explicit buffer row and image strides for the upload.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
7be52The copy changes appear ready to merge after normal checks. The requested 16-case Vulkan matrix rerun has not been reported.
Pre-merge checks:
4 ·
1
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 helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-20 00:51 UTC · original · edited 2026-10-20 07:30 UTC
On
src/graphics/host_gpu/renderer/image/image.cppline 525 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Keep the source download extent valid after a height clamp.
If a block-compressed source is 8 rows high and the destination is 5 rows high,
chunk_heightbecomes 5. The subsequentsource_copydownloads 5 rows, but that extent ends inside the source and is not a multiple of the 4-row block height. Download complete source blocks into the staging buffer, then upload only the clamped destination height. (docs.vulkan.org)✅ Addressed in commit
d42a484@coderabbitai[bot] on GitHub · 2026-10-20 00:51 UTC · original · edited 2026-10-20 07:30 UTC
On
src/graphics/host_gpu/renderer/image/image.cppline 540 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9918
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32832
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32405
Keep explicit buffer strides block-aligned.
widthandchunk_heightare texel dimensions, not block counts. For block-compressed images, they can be non-multiples of the 4×4 block dimensions because mip extents use direct bit shifts and are not aligned.The source copy uses a tightly packed layout. Its row size is based on the rounded-up block count. Round the explicit destination strides to preserve that layout and satisfy Vulkan. Do not set them to zero because
copy_widthcan be narrower than the source width.🐛 Suggested fix
📝 Committable suggestion
✅ Addressed in commit
d42a484@coderabbitai[bot] on GitHub · 2026-10-20 00:52 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
361b8199-1feb-4cda-a947-2f3316aa1b9c📥 Commits
Reviewing files that changed from the base of the PR and between
742fe17173and 2294b534be9476410229ae4791382fb091aa69f6.📒 Files selected for processing: 1
src/graphics/host_gpu/renderer/image/image.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@theantipopau on GitHub · 2026-10-20 07:30 UTC · original
On
src/graphics/host_gpu/renderer/image/image.cppline 525 (outdated):Good catch — fixed in
d42a484. The loop now iterates over full source block rows (block_rows = ceil(copy_height / source_block)) sosource_copy.imageExtentstays block-aligned for compressed formats, and only the upload is clamped via a newupload_height = min(chunk_height, copy_height - y)fordestination_copy.imageExtent. Sinceblock_rowscoversceil(copy_height/block),y < copy_heightalways holds in-loop, so every upload writes at least one row and neitherheight - ynorcopy_height - ycan underflow.@theantipopau on GitHub · 2026-10-20 07:30 UTC · original
On
src/graphics/host_gpu/renderer/image/image.cppline 540 (outdated):Applied as suggested in
d42a484(verified against the staging layout rather than blindly — the download packs tight block rows, so the rounding is exact). bufferRowLength/bufferImageHeight are now block-rounded from the full source width/chunk height, while the destination extent uses the clamped copy_width/upload_height. Mixed-compression cases stay guarded by the existing source_block == destination_block check.@coderabbitai[bot] on GitHub · 2026-10-20 07:30 UTC · original
On
src/graphics/host_gpu/renderer/image/image.cppline 525 (outdated):@theantipopau Thanks for the fix. The supplied code keeps source downloads block-aligned or ending at the source edge, then clamps only the upload. The loop bounds also prevent both subtractions from underflowing. This addresses the finding.
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-20 07:30 UTC · original
On
src/graphics/host_gpu/renderer/image/image.cppline 540 (outdated):@theantipopau Thanks for checking the staging layout. The block-rounded strides match the tightly packed source block rows. The clamped
copy_widthandupload_heightlimit the destination upload. This addresses the stride-alignment finding.✏️ Learnings added
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.
@theantipopau on GitHub · 2026-10-20 08:32 UTC · original
Follow-up fixed both Major review findings in
d42a484:block_rows = ceil(copy_height / source_block)sosource_copy.imageExtentuses full source width/chunk height (valid for compressed formats); only the upload is clamped via newupload_height = min(chunk_height, copy_height - y).bufferRowLength/bufferImageHeightrounded up to block multiples from the full source extent — exact because the staging download packs tight block rows. Destination extent uses clampedcopy_width/upload_height.Loop bounds guarantee
y < copy_heightin-loop, so every upload is non-empty and neither subtraction underflows. Mixed-compression stays guarded by the existingsource_block == destination_blockcheck. CI is green and both threads are resolved.@Nawid3333 on GitHub · 2026-10-20 14:16 UTC · original
Sharing measured data in case it helps: I have a small lab copy harness (local, not in upstream) that runs 16 image-copy cases through both the direct path and the buffer path under the Vulkan validation layer, on an RX 9070 XT and a Ryzen 7600X iGPU.
On main
e5f0ee7fwith this PR's diff applied (run 2026-10-20): buffer cases 0, 1, 4, 5 and 7 go from validation errors on main (07971/00207) to clean, and the texel readbacks are equal (16/16, identical on both GPUs). Case 0 is Jusant's 3D B10G11R11 copy (60x33x26 -> 54x33x26).Buffer case 6 (BC5 6x6 -> 16x16) still reports VUID-vkCmdCopyBufferToImage-dstImage-00207: the clamp keeps width 6, which is neither a multiple of the 4x4 block nor the destination edge (16).
The direct CopyImage cases that fail on main (5, 7, 9, 11, 13) are unchanged with this diff (expected, it does not touch CopyImage). Those five and buffer case 6 pass with #1176; I posted that matrix on #1176 earlier.
Happy to post the per-case list here if useful.
@theantipopau on GitHub · 2026-10-22 03:26 UTC · original
@Nawid3333 that per-case data is exactly what this needed — thank you. Case 6 is fixed in
7be529dd: clamping to the destination extent was the wrong shape for a block-compressed destination, because VUID-vkCmdCopyBufferToImage-dstImage-00207 wantsimageExtentto be whole blocks (or to reach the mip edge), not just in bounds. A BC5 6x6 source into a 16x16 image kept width 6, which is neither.The upload extent is now rounded up to the source block size and capped by the destination mip extent and remaining height:
bufferRowLength8 texels / 32 bytes, which is exactly the pitch the download already wrote, so no read past the staged data.imageOffset + imageExtent == imageExtentof the mip is the accepted alternative.The source download is untouched, so its extents still end at the source mip edge.
If you can rerun your 16-case matrix against
7be529dd, the thing to look at is buffer case 6 clearing 00207 and its texel readback still matching. The five directCopyImagecases are outside this PR as you noted — #1176 is where those belong.@Nawid3333 on GitHub · 2026-10-22 21:12 UTC · original
@theantipopau I reran the matrix on
7be529dd(on maine5f0ee7flike the previous run, Windows 11, RX 9070 XT and the Ryzen 7600X iGPU, validation layer on, one copy per process):dstImage-00207is gone on both GPUs, and the data is right. I added a block check to the matrix for this: the 4 copied blocks match the source blocks exactly, and the 12 destination blocks outside the copied region stay untouched.CopyImagecases are unchanged, as expected.@Nawid3333 on GitHub · 2026-11-08 15:52 UTC · original
Game evidence: Abiotic Factor (#2163). With Vulkan validation on, the game stopped when the camera turned, on
vkCmdCopyBufferToImageVUID 07971 (extent.width (128) exceeds imageSubresource width extent (64), a 128-wide source copied into a 64x128 R16_UNORM image). Ekt0re played a build of main27f290e95+ this PR at7be529dd(plus the MSVC build fix that is nowf47da249bin main) past the same spot, and the stop is gone: #2163Pull request closed