Mesa (main): anv: move VkImage object allocation to anv_CreateImage
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Oct 6 02:41:06 UTC 2021
Module: Mesa
Branch: main
Commit: 9058fd897932c9e8c1e1095794c3523746a3bca3
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9058fd897932c9e8c1e1095794c3523746a3bca3
Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date: Wed Jul 28 13:36:51 2021 +0300
anv: move VkImage object allocation to anv_CreateImage
v2 (Jason Ekstrand):
- Switch the order of arguments to be device, image, other stuff
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13199>
---
src/intel/vulkan/anv_android.c | 25 +++----
src/intel/vulkan/anv_android.h | 9 ++-
src/intel/vulkan/anv_android_stubs.c | 9 ++-
src/intel/vulkan/anv_image.c | 126 +++++++++++++++++++++--------------
src/intel/vulkan/anv_private.h | 8 +--
5 files changed, 95 insertions(+), 82 deletions(-)
diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c
index f4f00c159f7..b3b102d4202 100644
--- a/src/intel/vulkan/anv_android.c
+++ b/src/intel/vulkan/anv_android.c
@@ -451,16 +451,11 @@ anv_create_ahw_memory(VkDevice device_h,
}
VkResult
-anv_image_from_gralloc(VkDevice device_h,
- const VkImageCreateInfo *base_info,
- const VkNativeBufferANDROID *gralloc_info,
- const VkAllocationCallbacks *alloc,
- VkImage *out_image_h)
-
+anv_image_init_from_gralloc(struct anv_device *device,
+ struct anv_image *image,
+ const VkImageCreateInfo *base_info,
+ const VkNativeBufferANDROID *gralloc_info)
{
- ANV_FROM_HANDLE(anv_device, device, device_h);
- VkImage image_h = VK_NULL_HANDLE;
- struct anv_image *image = NULL;
struct anv_bo *bo = NULL;
VkResult result;
@@ -532,10 +527,9 @@ anv_image_from_gralloc(VkDevice device_h,
base_info->tiling);
assert(format != ISL_FORMAT_UNSUPPORTED);
- result = anv_image_create(device_h, &anv_info, alloc, &image_h);
- image = anv_image_from_handle(image_h);
+ result = anv_image_init(device, image, &anv_info);
if (result != VK_SUCCESS)
- goto fail_create;
+ goto fail_init;
VkMemoryRequirements2 mem_reqs = {
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
@@ -566,14 +560,11 @@ anv_image_from_gralloc(VkDevice device_h,
image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo = bo;
image->from_gralloc = true;
- /* Don't clobber the out-parameter until success is certain. */
- *out_image_h = image_h;
-
return VK_SUCCESS;
fail_size:
- anv_DestroyImage(device_h, image_h, alloc);
- fail_create:
+ anv_image_finish(image);
+ fail_init:
fail_tiling:
anv_device_release_bo(device, bo);
diff --git a/src/intel/vulkan/anv_android.h b/src/intel/vulkan/anv_android.h
index 54cafac8e2a..4490d3b2437 100644
--- a/src/intel/vulkan/anv_android.h
+++ b/src/intel/vulkan/anv_android.h
@@ -35,11 +35,10 @@ struct anv_device_memory;
struct anv_device;
struct anv_image;
-VkResult anv_image_from_gralloc(VkDevice device_h,
- const VkImageCreateInfo *base_info,
- const VkNativeBufferANDROID *gralloc_info,
- const VkAllocationCallbacks *alloc,
- VkImage *pImage);
+VkResult anv_image_init_from_gralloc(struct anv_device *device,
+ struct anv_image *image,
+ const VkImageCreateInfo *base_info,
+ const VkNativeBufferANDROID *gralloc_info);
VkResult anv_image_bind_from_gralloc(struct anv_device *device,
struct anv_image *image,
diff --git a/src/intel/vulkan/anv_android_stubs.c b/src/intel/vulkan/anv_android_stubs.c
index cf091740f4a..d5bc11949ab 100644
--- a/src/intel/vulkan/anv_android_stubs.c
+++ b/src/intel/vulkan/anv_android_stubs.c
@@ -24,11 +24,10 @@
#include "anv_android.h"
VkResult
-anv_image_from_gralloc(VkDevice device_h,
- const VkImageCreateInfo *base_info,
- const VkNativeBufferANDROID *gralloc_info,
- const VkAllocationCallbacks *alloc,
- VkImage *pImage)
+anv_image_init_from_gralloc(struct anv_device *device,
+ struct anv_image *image,
+ const VkImageCreateInfo *base_info,
+ const VkNativeBufferANDROID *gralloc_info)
{
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 12a99d24088..7f152fe085e 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -1255,21 +1255,15 @@ alloc_private_binding(struct anv_device *device,
}
VkResult
-anv_image_create(VkDevice _device,
- const struct anv_image_create_info *create_info,
- const VkAllocationCallbacks* alloc,
- VkImage *pImage)
+anv_image_init(struct anv_device *device, struct anv_image *image,
+ const struct anv_image_create_info *create_info)
{
- ANV_FROM_HANDLE(anv_device, device, _device);
const VkImageCreateInfo *pCreateInfo = create_info->vk_info;
const struct VkImageDrmFormatModifierExplicitCreateInfoEXT *mod_explicit_info = NULL;
const struct isl_drm_modifier_info *isl_mod_info = NULL;
- struct anv_image *image = NULL;
VkResult r;
- image = vk_image_create(&device->vk, pCreateInfo, alloc, sizeof(*image));
- if (image == NULL)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+ vk_image_init(&device->vk, &image->vk, pCreateInfo);
image->vk.usage = anv_image_create_usage(pCreateInfo, image->vk.usage);
image->vk.stencil_usage =
@@ -1306,7 +1300,6 @@ anv_image_create(VkDevice _device,
if (image->vk.external_handle_types &
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) {
image->from_ahb = true;
- *pImage = anv_image_to_handle(image);
return VK_SUCCESS;
}
@@ -1351,15 +1344,35 @@ anv_image_create(VkDevice _device,
if (r != VK_SUCCESS)
goto fail;
- *pImage = anv_image_to_handle(image);
-
return VK_SUCCESS;
fail:
- vk_image_destroy(&device->vk, alloc, &image->vk);
+ vk_image_finish(&image->vk);
return r;
}
+void
+anv_image_finish(struct anv_image *image)
+{
+ struct anv_device *device =
+ container_of(image->vk.base.device, struct anv_device, vk);
+
+ if (image->from_gralloc) {
+ assert(!image->disjoint);
+ assert(image->n_planes == 1);
+ assert(image->planes[0].primary_surface.memory_range.binding ==
+ ANV_IMAGE_MEMORY_BINDING_MAIN);
+ assert(image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo != NULL);
+ anv_device_release_bo(device, image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo);
+ }
+
+ struct anv_bo *private_bo = image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo;
+ if (private_bo)
+ anv_device_release_bo(device, private_bo);
+
+ vk_image_finish(&image->vk);
+}
+
static struct anv_image *
anv_swapchain_get_image(VkSwapchainKHR swapchain,
uint32_t index)
@@ -1380,11 +1393,10 @@ anv_swapchain_get_image(VkSwapchainKHR swapchain,
}
static VkResult
-anv_image_from_swapchain(VkDevice device,
- const VkImageCreateInfo *pCreateInfo,
- const VkImageSwapchainCreateInfoKHR *swapchain_info,
- const VkAllocationCallbacks *pAllocator,
- VkImage *pImage)
+anv_image_init_from_swapchain(struct anv_device *device,
+ struct anv_image *image,
+ const VkImageCreateInfo *pCreateInfo,
+ const VkImageSwapchainCreateInfoKHR *swapchain_info)
{
struct anv_image *swapchain_image = anv_swapchain_get_image(swapchain_info->swapchain, 0);
assert(swapchain_image);
@@ -1421,25 +1433,22 @@ anv_image_from_swapchain(VkDevice device,
assert(swapchain_image->vk.tiling == local_create_info.tiling);
assert(swapchain_image->vk.usage == local_create_info.usage);
- return anv_image_create(device,
+ return anv_image_init(device, image,
&(struct anv_image_create_info) {
.vk_info = &local_create_info,
- },
- pAllocator,
- pImage);
+ });
}
-VkResult
-anv_CreateImage(VkDevice device,
- const VkImageCreateInfo *pCreateInfo,
- const VkAllocationCallbacks *pAllocator,
- VkImage *pImage)
+static VkResult
+anv_image_init_from_create_info(struct anv_device *device,
+ struct anv_image *image,
+ const VkImageCreateInfo *pCreateInfo)
{
const VkNativeBufferANDROID *gralloc_info =
vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
if (gralloc_info)
- return anv_image_from_gralloc(device, pCreateInfo, gralloc_info,
- pAllocator, pImage);
+ return anv_image_init_from_gralloc(device, image, pCreateInfo,
+ gralloc_info);
#ifndef VK_USE_PLATFORM_ANDROID_KHR
/* Ignore swapchain creation info on Android. Since we don't have an
@@ -1448,17 +1457,42 @@ anv_CreateImage(VkDevice device,
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
- if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE)
- return anv_image_from_swapchain(device, pCreateInfo, swapchain_info,
- pAllocator, pImage);
+ if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
+ return anv_image_init_from_swapchain(device, image, pCreateInfo,
+ swapchain_info);
+ }
#endif
- return anv_image_create(device,
- &(struct anv_image_create_info) {
- .vk_info = pCreateInfo,
- },
- pAllocator,
- pImage);
+ return anv_image_init(device, image,
+ &(struct anv_image_create_info) {
+ .vk_info = pCreateInfo,
+ });
+}
+
+VkResult anv_CreateImage(
+ VkDevice _device,
+ const VkImageCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkImage* pImage)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+
+ struct anv_image *image =
+ vk_object_zalloc(&device->vk, pAllocator, sizeof(*image),
+ VK_OBJECT_TYPE_IMAGE);
+ if (!image)
+ return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ VkResult result = anv_image_init_from_create_info(device, image,
+ pCreateInfo);
+ if (result != VK_SUCCESS) {
+ vk_object_free(&device->vk, pAllocator, image);
+ return result;
+ }
+
+ *pImage = anv_image_to_handle(image);
+
+ return result;
}
void
@@ -1471,20 +1505,10 @@ anv_DestroyImage(VkDevice _device, VkImage _image,
if (!image)
return;
- if (image->from_gralloc) {
- assert(!image->disjoint);
- assert(image->n_planes == 1);
- assert(image->planes[0].primary_surface.memory_range.binding ==
- ANV_IMAGE_MEMORY_BINDING_MAIN);
- assert(image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo != NULL);
- anv_device_release_bo(device, image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo);
- }
-
- struct anv_bo *private_bo = image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo;
- if (private_bo)
- anv_device_release_bo(device, private_bo);
+ assert(&device->vk == image->vk.base.device);
+ anv_image_finish(image);
- vk_image_destroy(&device->vk, pAllocator, &image->vk);
+ vk_free2(&device->vk.alloc, pAllocator, image);
}
/* We are binding AHardwareBuffer. Get a description, resolve the
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index ccde5349ee0..c9ee3b853ef 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -4415,10 +4415,10 @@ struct anv_image_create_info {
isl_surf_usage_flags_t isl_extra_usage_flags;
};
-VkResult anv_image_create(VkDevice _device,
- const struct anv_image_create_info *info,
- const VkAllocationCallbacks* alloc,
- VkImage *pImage);
+VkResult anv_image_init(struct anv_device *device, struct anv_image *image,
+ const struct anv_image_create_info *create_info);
+
+void anv_image_finish(struct anv_image *image);
void anv_image_get_memory_requirements(struct anv_device *device,
struct anv_image *image,
More information about the mesa-commit
mailing list