anv: implement GetDeviceImageSubresourceLayoutKHR/GetImageSubresourceLayout2KHR

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24387>
This commit is contained in:
Lionel Landwerlin 2023-03-08 14:08:47 +02:00
parent 8b662d41b4
commit fb61bb6af4

View file

@ -1975,16 +1975,14 @@ VkResult anv_BindImageMemory2(
return VK_SUCCESS;
}
void anv_GetImageSubresourceLayout(
VkDevice device,
VkImage _image,
const VkImageSubresource* subresource,
VkSubresourceLayout* layout)
static void
anv_get_image_subresource_layout(const struct anv_image *image,
const VkImageSubresource2KHR *subresource,
VkSubresourceLayout2KHR *layout)
{
ANV_FROM_HANDLE(anv_image, image, _image);
const struct anv_surface *surface;
assert(__builtin_popcount(subresource->aspectMask) == 1);
assert(__builtin_popcount(subresource->imageSubresource.aspectMask) == 1);
/* The Vulkan spec requires that aspectMask be
* VK_IMAGE_ASPECT_MEMORY_PLANE_i_BIT_EXT if tiling is
@ -2004,7 +2002,7 @@ void anv_GetImageSubresourceLayout(
if (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
/* TODO(chadv): Drop this workaround when WSI gets fixed. */
uint32_t mem_plane;
switch (subresource->aspectMask) {
switch (subresource->imageSubresource.aspectMask) {
case VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT:
case VK_IMAGE_ASPECT_PLANE_0_BIT:
mem_plane = 0;
@ -2035,33 +2033,85 @@ void anv_GetImageSubresourceLayout(
}
} else {
const uint32_t plane =
anv_image_aspect_to_plane(image, subresource->aspectMask);
anv_image_aspect_to_plane(image, subresource->imageSubresource.aspectMask);
surface = &image->planes[plane].primary_surface;
}
layout->offset = surface->memory_range.offset;
layout->rowPitch = surface->isl.row_pitch_B;
layout->depthPitch = isl_surf_get_array_pitch(&surface->isl);
layout->arrayPitch = isl_surf_get_array_pitch(&surface->isl);
layout->subresourceLayout.offset = surface->memory_range.offset;
layout->subresourceLayout.rowPitch = surface->isl.row_pitch_B;
layout->subresourceLayout.depthPitch = isl_surf_get_array_pitch(&surface->isl);
layout->subresourceLayout.arrayPitch = isl_surf_get_array_pitch(&surface->isl);
if (subresource->mipLevel > 0 || subresource->arrayLayer > 0) {
if (subresource->imageSubresource.mipLevel > 0 ||
subresource->imageSubresource.arrayLayer > 0) {
assert(surface->isl.tiling == ISL_TILING_LINEAR);
uint64_t offset_B;
isl_surf_get_image_offset_B_tile_sa(&surface->isl,
subresource->mipLevel,
subresource->arrayLayer,
subresource->imageSubresource.mipLevel,
subresource->imageSubresource.arrayLayer,
0 /* logical_z_offset_px */,
&offset_B, NULL, NULL);
layout->offset += offset_B;
layout->size = layout->rowPitch * u_minify(image->vk.extent.height,
subresource->mipLevel) *
image->vk.extent.depth;
layout->subresourceLayout.offset += offset_B;
layout->subresourceLayout.size =
layout->subresourceLayout.rowPitch *
u_minify(image->vk.extent.height,
subresource->imageSubresource.mipLevel) *
image->vk.extent.depth;
} else {
layout->size = surface->memory_range.size;
layout->subresourceLayout.size = surface->memory_range.size;
}
}
void anv_GetImageSubresourceLayout(
VkDevice device,
VkImage _image,
const VkImageSubresource* pSubresource,
VkSubresourceLayout* pLayout)
{
ANV_FROM_HANDLE(anv_image, image, _image);
VkImageSubresource2KHR subresource = {
.sType = VK_STRUCTURE_TYPE_IMAGE_SUBRESOURCE_2_KHR,
.imageSubresource = *pSubresource,
};
VkSubresourceLayout2KHR layout = {
.sType = VK_STRUCTURE_TYPE_SUBRESOURCE_LAYOUT_2_KHR
};
anv_get_image_subresource_layout(image, &subresource, &layout);
*pLayout = layout.subresourceLayout;
}
void anv_GetDeviceImageSubresourceLayoutKHR(
VkDevice _device,
const VkDeviceImageSubresourceInfoKHR* pInfo,
VkSubresourceLayout2KHR* pLayout)
{
ANV_FROM_HANDLE(anv_device, device, _device);
struct anv_image image = { 0 };
if (anv_image_init_from_create_info(device, &image, pInfo->pCreateInfo,
true) != VK_SUCCESS) {
pLayout->subresourceLayout = (VkSubresourceLayout) { 0, };
return;
}
anv_get_image_subresource_layout(&image, pInfo->pSubresource, pLayout);
}
void anv_GetImageSubresourceLayout2KHR(
VkDevice device,
VkImage _image,
const VkImageSubresource2KHR* pSubresource,
VkSubresourceLayout2KHR* pLayout)
{
ANV_FROM_HANDLE(anv_image, image, _image);
anv_get_image_subresource_layout(image, pSubresource, pLayout);
}
/**
* This function returns the assumed isl_aux_state for a given VkImageLayout.
* Because Vulkan image layouts don't map directly to isl_aux_state enums, the