v3dv: add a v3dv_image_init helper

This is different from the internal create_image in that it doesn't
allocate memory for an image object, instead it expects the object
to be created and it initializes it from a VkImageCreateInfo struct.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18246>
This commit is contained in:
Iago Toral Quiroga 2022-08-25 09:01:10 +02:00 committed by Marge Bot
parent 2c388c1d49
commit c354ca69c6
2 changed files with 36 additions and 18 deletions

View file

@ -242,18 +242,12 @@ v3dv_layer_offset(const struct v3dv_image *image, uint32_t level, uint32_t layer
return image->mem_offset + slice->offset + layer * image->cube_map_stride;
}
static VkResult
create_image(struct v3dv_device *device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
VkResult
v3dv_image_init(struct v3dv_device *device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
struct v3dv_image *image)
{
struct v3dv_image *image = NULL;
image = vk_image_create(&device->vk, pCreateInfo, pAllocator, sizeof(*image));
if (image == NULL)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
/* When using the simulator the WSI common code will see that our
* driver wsi device doesn't match the display device and because of that
* it will not attempt to present directly from the swapchain images,
@ -306,11 +300,10 @@ create_image(struct v3dv_device *device,
if (native_buffer != NULL) {
VkResult result = v3dv_gralloc_info(device, native_buffer, &native_buf_fd,
&native_buf_stride, &native_buf_size, &modifier);
if (result != VK_SUCCESS) {
vk_image_destroy(&device->vk, pAllocator, &image->vk);
&native_buf_stride, &native_buf_size,
&modifier);
if (result != VK_SUCCESS)
return result;
}
if (modifier != DRM_FORMAT_MOD_BROADCOM_UIF)
tiling = VK_IMAGE_TILING_LINEAR;
@ -349,13 +342,32 @@ create_image(struct v3dv_device *device,
VkResult result = v3dv_import_native_buffer_fd(v3dv_device_to_handle(device),
native_buf_fd, pAllocator,
v3dv_image_to_handle(image));
if (result != VK_SUCCESS) {
vk_object_free(&device->vk, pAllocator, image);
if (result != VK_SUCCESS)
return result;
}
}
#endif
return VK_SUCCESS;
}
static VkResult
create_image(struct v3dv_device *device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
{
struct v3dv_image *image = NULL;
image = vk_image_create(&device->vk, pCreateInfo, pAllocator, sizeof(*image));
if (image == NULL)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
VkResult result = v3dv_image_init(device, pCreateInfo, pAllocator, image);
if (result != VK_SUCCESS) {
vk_image_destroy(&device->vk, pAllocator, &image->vk);
return result;
}
*pImage = v3dv_image_to_handle(image);
return VK_SUCCESS;

View file

@ -607,6 +607,12 @@ struct v3dv_image {
#endif
};
VkResult
v3dv_image_init(struct v3dv_device *device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
struct v3dv_image *image);
VkImageViewType v3dv_image_type_to_view_type(VkImageType type);
/* Pre-generating packets needs to consider changes in packet sizes across hw