tu: Implement vkGetImageSubresourceLayout2KHR and vkGetDeviceImageSubresourceLayoutKHR
authorConnor Abbott <cwabbott0@gmail.com>
Fri, 1 Sep 2023 13:31:57 +0000 (15:31 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 27 Sep 2023 19:07:22 +0000 (19:07 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25001>

src/freedreno/vulkan/tu_image.cc

index f4d1e7f..73276a9 100644 (file)
@@ -840,33 +840,61 @@ tu_GetDeviceImageSparseMemoryRequirements(
    tu_stub();
 }
 
-VKAPI_ATTR void VKAPI_CALL
-tu_GetImageSubresourceLayout(VkDevice _device,
-                             VkImage _image,
-                             const VkImageSubresource *pSubresource,
-                             VkSubresourceLayout *pLayout)
+static void
+tu_get_image_subresource_layout(struct tu_image *image,
+                                const VkImageSubresource2KHR *pSubresource,
+                                VkSubresourceLayout2KHR *pLayout)
 {
-   TU_FROM_HANDLE(tu_image, image, _image);
-
    struct fdl_layout *layout =
-      &image->layout[tu6_plane_index(image->vk.format, pSubresource->aspectMask)];
-   const struct fdl_slice *slice = layout->slices + pSubresource->mipLevel;
-
-   pLayout->offset =
-      fdl_surface_offset(layout, pSubresource->mipLevel, pSubresource->arrayLayer);
-   pLayout->rowPitch = fdl_pitch(layout, pSubresource->mipLevel);
-   pLayout->arrayPitch = fdl_layer_stride(layout, pSubresource->mipLevel);
-   pLayout->depthPitch = slice->size0;
-   pLayout->size = pLayout->depthPitch * layout->depth0;
-
-   if (fdl_ubwc_enabled(layout, pSubresource->mipLevel)) {
+      &image->layout[tu6_plane_index(image->vk.format,
+                                     pSubresource->imageSubresource.aspectMask)];
+   const struct fdl_slice *slice = layout->slices +
+      pSubresource->imageSubresource.mipLevel;
+
+   pLayout->subresourceLayout.offset =
+      fdl_surface_offset(layout, pSubresource->imageSubresource.mipLevel,
+                         pSubresource->imageSubresource.arrayLayer);
+   pLayout->subresourceLayout.rowPitch =
+      fdl_pitch(layout, pSubresource->imageSubresource.mipLevel);
+   pLayout->subresourceLayout.arrayPitch =
+      fdl_layer_stride(layout, pSubresource->imageSubresource.mipLevel);
+   pLayout->subresourceLayout.depthPitch = slice->size0;
+   pLayout->subresourceLayout.size = slice->size0 * layout->depth0;
+
+   if (fdl_ubwc_enabled(layout, pSubresource->imageSubresource.mipLevel)) {
       /* UBWC starts at offset 0 */
-      pLayout->offset = 0;
+      pLayout->subresourceLayout.offset = 0;
       /* UBWC scanout won't match what the kernel wants if we have levels/layers */
       assert(image->vk.mip_levels == 1 && image->vk.array_layers == 1);
    }
 }
 
+VKAPI_ATTR void VKAPI_CALL
+tu_GetImageSubresourceLayout2KHR(VkDevice _device,
+                                 VkImage _image,
+                                 const VkImageSubresource2KHR *pSubresource,
+                                 VkSubresourceLayout2KHR *pLayout)
+{
+   TU_FROM_HANDLE(tu_image, image, _image);
+
+   tu_get_image_subresource_layout(image, pSubresource, pLayout);
+}
+
+VKAPI_ATTR void VKAPI_CALL
+tu_GetDeviceImageSubresourceLayoutKHR(VkDevice _device,
+                                      const VkDeviceImageSubresourceInfoKHR *pInfo,
+                                      VkSubresourceLayout2KHR *pLayout)
+{
+   TU_FROM_HANDLE(tu_device, device, _device);
+
+   struct tu_image image = {0};
+
+   tu_image_init(device, &image, pInfo->pCreateInfo, DRM_FORMAT_MOD_INVALID,
+                 NULL);
+
+   tu_get_image_subresource_layout(&image, pInfo->pSubresource, pLayout);
+}
+
 VKAPI_ATTR VkResult VKAPI_CALL
 tu_CreateImageView(VkDevice _device,
                    const VkImageViewCreateInfo *pCreateInfo,