vulkan: add vk_image_memory_copy_layout()
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40385>
This commit is contained in:
Samuel Pitoiset 2025-02-14 07:46:09 +01:00 committed by Marge Bot
parent 045c1fff7d
commit 770a94e126
2 changed files with 36 additions and 0 deletions

View file

@ -368,6 +368,38 @@ vk_image_buffer_copy_layout(const struct vk_image *image,
};
}
struct vk_image_buffer_layout
vk_image_memory_copy_layout(const struct vk_image *image,
const VkDeviceMemoryImageCopyKHR* region)
{
VkExtent3D extent = vk_image_sanitize_extent(image, region->imageExtent);
const uint32_t row_length = region->addressRowLength ?
region->addressRowLength : extent.width;
const uint32_t image_height = region->addressImageHeight ?
region->addressImageHeight : extent.height;
const VkImageAspectFlags aspect = region->imageSubresource.aspectMask;
VkFormat format = vk_format_get_aspect_format(image->format, aspect);
const struct util_format_description *fmt = vk_format_description(format);
assert(fmt->block.bits % 8 == 0);
const uint32_t element_size_B = fmt->block.bits / 8;
const uint32_t row_stride_B =
DIV_ROUND_UP(row_length, fmt->block.width) * element_size_B;
const uint64_t image_stride_B =
DIV_ROUND_UP(image_height, fmt->block.height) * (uint64_t)row_stride_B;
return (struct vk_image_buffer_layout) {
.row_length = row_length,
.image_height = image_height,
.element_size_B = element_size_B,
.row_stride_B = row_stride_B,
.image_stride_B = image_stride_B,
};
}
struct vk_image_buffer_layout
vk_memory_to_image_copy_layout(const struct vk_image *image,
const VkMemoryToImageCopyEXT* region)

View file

@ -252,6 +252,10 @@ struct vk_image_buffer_layout
vk_image_buffer_copy_layout(const struct vk_image *image,
const VkBufferImageCopy2* region);
struct vk_image_buffer_layout
vk_image_memory_copy_layout(const struct vk_image *image,
const VkDeviceMemoryImageCopyKHR* region);
struct vk_image_buffer_layout
vk_memory_to_image_copy_layout(const struct vk_image *image,
const VkMemoryToImageCopyEXT* region);