kk: Sanitize image copy through buffer extents

Use `util_format_get_nblocks(x/y/z)` for safer extent division, and
make sure 1D/2D extensions have extent y/z set to 1 as appropriate.

Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41873>
This commit is contained in:
squidbus 2026-05-28 04:36:58 -07:00
parent aeecafff95
commit 7c8de173d2

View file

@ -196,19 +196,27 @@ copy_through_buffer(struct kk_cmd_buffer *cmd, struct kk_image *src,
info.mtl_data.buffer_stride_B = buffer_stride_B;
info.mtl_data.buffer = buffer;
info.buffer_slice_size_B = buffer_size_2d_B;
struct mtl_size src_size = vk_extent_3d_to_mtl_size(&region->extent);
struct mtl_size dst_size = vk_extent_3d_to_mtl_size(&region->extent);
/* Need to adjust size to block dimensions */
if (is_src_compressed) {
dst_size.x /= util_format_get_blockwidth(src_format);
dst_size.y /= util_format_get_blockheight(src_format);
dst_size.z /= util_format_get_blockdepth(src_format);
dst_size.x = util_format_get_nblocksx(src_format, dst_size.x);
dst_size.y = util_format_get_nblocksy(src_format, dst_size.y);
dst_size.z = util_format_get_nblocksz(src_format, dst_size.z);
}
if (is_dst_compressed) {
dst_size.x *= util_format_get_blockwidth(dst_format);
dst_size.y *= util_format_get_blockheight(dst_format);
dst_size.z *= util_format_get_blockdepth(dst_format);
}
/* After adjusting for compression, sanitize destination extents for 1D/2D */
if (dst_plane->layout.height_px == 1)
dst_size.y = 1;
if (dst_plane->layout.depth_px == 1)
dst_size.z = 1;
struct mtl_origin src_origin =
vk_offset_3d_to_mtl_origin(&region->srcOffset);
struct mtl_origin dst_origin =