Mesa (master): venus: add vn_image_init_memory_requirements
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Apr 17 00:50:51 UTC 2021
Module: Mesa
Branch: master
Commit: e1787ec77dc57aa460326d159ad855df6825eb07
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e1787ec77dc57aa460326d159ad855df6825eb07
Author: Chia-I Wu <olvaffe at gmail.com>
Date: Fri Apr 16 12:22:16 2021 -0700
venus: add vn_image_init_memory_requirements
A helper called from vn_CreateImage to initialize memory requirements.
Signed-off-by: Chia-I Wu <olvaffe at gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10294>
---
src/virtio/vulkan/vn_image.c | 104 ++++++++++++++++++++++++-------------------
1 file changed, 57 insertions(+), 47 deletions(-)
diff --git a/src/virtio/vulkan/vn_image.c b/src/virtio/vulkan/vn_image.c
index b6b675a97d6..847bde88850 100644
--- a/src/virtio/vulkan/vn_image.c
+++ b/src/virtio/vulkan/vn_image.c
@@ -18,55 +18,17 @@
#include "vn_device.h"
#include "vn_device_memory.h"
-/* image commands */
-
-VkResult
-vn_CreateImage(VkDevice device,
- const VkImageCreateInfo *pCreateInfo,
- const VkAllocationCallbacks *pAllocator,
- VkImage *pImage)
+static void
+vn_image_init_memory_requirements(struct vn_image *img,
+ struct vn_device *dev,
+ const VkImageCreateInfo *create_info)
{
- struct vn_device *dev = vn_device_from_handle(device);
- const VkAllocationCallbacks *alloc =
- pAllocator ? pAllocator : &dev->base.base.alloc;
-
- /* TODO wsi_create_native_image uses modifiers or set wsi_info->scanout to
- * true. Instead of forcing VK_IMAGE_TILING_LINEAR, we should ask wsi to
- * use wsi_create_prime_image instead.
- */
- const struct wsi_image_create_info *wsi_info =
- vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
- VkImageCreateInfo local_create_info;
- if (wsi_info && wsi_info->scanout) {
- if (VN_DEBUG(WSI))
- vn_log(dev->instance, "forcing scanout image linear");
- local_create_info = *pCreateInfo;
- local_create_info.tiling = VK_IMAGE_TILING_LINEAR;
- pCreateInfo = &local_create_info;
- }
-
- struct vn_image *img = vk_zalloc(alloc, sizeof(*img), VN_DEFAULT_ALIGN,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- if (!img)
- return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
-
- vn_object_base_init(&img->base, VK_OBJECT_TYPE_IMAGE, &dev->base);
-
- VkImage img_handle = vn_image_to_handle(img);
- /* TODO async */
- VkResult result = vn_call_vkCreateImage(dev->instance, device, pCreateInfo,
- NULL, &img_handle);
- if (result != VK_SUCCESS) {
- vk_free(alloc, img);
- return vn_error(dev->instance, result);
- }
-
uint32_t plane_count = 1;
- if (pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
+ if (create_info->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
/* TODO VkDrmFormatModifierPropertiesEXT::drmFormatModifierPlaneCount */
- assert(pCreateInfo->tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT);
+ assert(create_info->tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT);
- switch (pCreateInfo->format) {
+ switch (create_info->format) {
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
@@ -108,9 +70,11 @@ vn_CreateImage(VkDevice device,
img->dedicated_requirements[i].pNext = NULL;
}
+ VkDevice dev_handle = vn_device_to_handle(dev);
+ VkImage img_handle = vn_image_to_handle(img);
if (plane_count == 1) {
vn_call_vkGetImageMemoryRequirements2(
- dev->instance, device,
+ dev->instance, dev_handle,
&(VkImageMemoryRequirementsInfo2){
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
.image = img_handle,
@@ -119,7 +83,7 @@ vn_CreateImage(VkDevice device,
} else {
for (uint32_t i = 0; i < plane_count; i++) {
vn_call_vkGetImageMemoryRequirements2(
- dev->instance, device,
+ dev->instance, dev_handle,
&(VkImageMemoryRequirementsInfo2){
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
.pNext =
@@ -133,6 +97,52 @@ vn_CreateImage(VkDevice device,
&img->memory_requirements[i]);
}
}
+}
+
+/* image commands */
+
+VkResult
+vn_CreateImage(VkDevice device,
+ const VkImageCreateInfo *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator,
+ VkImage *pImage)
+{
+ struct vn_device *dev = vn_device_from_handle(device);
+ const VkAllocationCallbacks *alloc =
+ pAllocator ? pAllocator : &dev->base.base.alloc;
+
+ /* TODO wsi_create_native_image uses modifiers or set wsi_info->scanout to
+ * true. Instead of forcing VK_IMAGE_TILING_LINEAR, we should ask wsi to
+ * use wsi_create_prime_image instead.
+ */
+ const struct wsi_image_create_info *wsi_info =
+ vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
+ VkImageCreateInfo local_create_info;
+ if (wsi_info && wsi_info->scanout) {
+ if (VN_DEBUG(WSI))
+ vn_log(dev->instance, "forcing scanout image linear");
+ local_create_info = *pCreateInfo;
+ local_create_info.tiling = VK_IMAGE_TILING_LINEAR;
+ pCreateInfo = &local_create_info;
+ }
+
+ struct vn_image *img = vk_zalloc(alloc, sizeof(*img), VN_DEFAULT_ALIGN,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (!img)
+ return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ vn_object_base_init(&img->base, VK_OBJECT_TYPE_IMAGE, &dev->base);
+
+ VkImage img_handle = vn_image_to_handle(img);
+ /* TODO async */
+ VkResult result = vn_call_vkCreateImage(dev->instance, device, pCreateInfo,
+ NULL, &img_handle);
+ if (result != VK_SUCCESS) {
+ vk_free(alloc, img);
+ return vn_error(dev->instance, result);
+ }
+
+ vn_image_init_memory_requirements(img, dev, pCreateInfo);
*pImage = img_handle;
More information about the mesa-commit
mailing list