mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-27 12:40:09 +01:00
vulkan/wsi: Add a helper for the configure/create/bind pattern
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12031>
This commit is contained in:
parent
5b13d74583
commit
830d9967db
3 changed files with 49 additions and 23 deletions
|
|
@ -456,6 +456,39 @@ wsi_destroy_image_info(const struct wsi_swapchain *chain,
|
|||
vk_free(&chain->alloc, info->modifier_props);
|
||||
}
|
||||
|
||||
VkResult
|
||||
wsi_create_image(const struct wsi_swapchain *chain,
|
||||
const struct wsi_image_info *info,
|
||||
struct wsi_image *image)
|
||||
{
|
||||
const struct wsi_device *wsi = chain->wsi;
|
||||
VkResult result;
|
||||
|
||||
memset(image, 0, sizeof(*image));
|
||||
for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
|
||||
image->fds[i] = -1;
|
||||
|
||||
result = wsi->CreateImage(chain->device, &info->create,
|
||||
&chain->alloc, &image->image);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = info->create_mem(chain, info, image);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = wsi->BindImageMemory(chain->device, image->image,
|
||||
image->memory, 0);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
return VK_SUCCESS;
|
||||
|
||||
fail:
|
||||
wsi_destroy_image(chain, image);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
wsi_destroy_image(const struct wsi_swapchain *chain,
|
||||
struct wsi_image *image)
|
||||
|
|
|
|||
|
|
@ -136,6 +136,11 @@ get_modifier_props(const struct wsi_image_info *info, uint64_t modifier)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
wsi_create_native_image_mem(const struct wsi_swapchain *chain,
|
||||
const struct wsi_image_info *info,
|
||||
struct wsi_image *image);
|
||||
|
||||
VkResult
|
||||
wsi_configure_native_image(const struct wsi_swapchain *chain,
|
||||
const VkSwapchainCreateInfoKHR *pCreateInfo,
|
||||
|
|
@ -270,6 +275,7 @@ wsi_configure_native_image(const struct wsi_swapchain *chain,
|
|||
}
|
||||
|
||||
info->alloc_shm = alloc_shm;
|
||||
info->create_mem = wsi_create_native_image_mem;
|
||||
|
||||
return VK_SUCCESS;
|
||||
|
||||
|
|
@ -422,13 +428,8 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
|
|||
uint8_t *(alloc_shm)(struct wsi_image *image, unsigned size),
|
||||
struct wsi_image *image)
|
||||
{
|
||||
const struct wsi_device *wsi = chain->wsi;
|
||||
VkResult result;
|
||||
|
||||
memset(image, 0, sizeof(*image));
|
||||
for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
|
||||
image->fds[i] = -1;
|
||||
|
||||
struct wsi_image_info info;
|
||||
result = wsi_configure_native_image(chain, pCreateInfo,
|
||||
num_modifier_lists,
|
||||
|
|
@ -437,27 +438,10 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
|
|||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
result = wsi->CreateImage(chain->device, &info.create,
|
||||
&chain->alloc, &image->image);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = wsi_create_native_image_mem(chain, &info, image);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = wsi->BindImageMemory(chain->device, image->image,
|
||||
image->memory, 0);
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
result = wsi_create_image(chain, &info, image);
|
||||
|
||||
wsi_destroy_image_info(chain, &info);
|
||||
|
||||
return VK_SUCCESS;
|
||||
|
||||
fail:
|
||||
wsi_destroy_image_info(chain, &info);
|
||||
wsi_destroy_image(chain, image);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include "vulkan/runtime/vk_object.h"
|
||||
|
||||
struct wsi_image;
|
||||
struct wsi_swapchain;
|
||||
|
||||
struct wsi_image_info {
|
||||
VkImageCreateInfo create;
|
||||
|
|
@ -42,6 +43,10 @@ struct wsi_image_info {
|
|||
struct VkDrmFormatModifierPropertiesEXT *modifier_props;
|
||||
|
||||
uint8_t *(*alloc_shm)(struct wsi_image *image, unsigned size);
|
||||
|
||||
VkResult (*create_mem)(const struct wsi_swapchain *chain,
|
||||
const struct wsi_image_info *info,
|
||||
struct wsi_image *image);
|
||||
};
|
||||
|
||||
struct wsi_image {
|
||||
|
|
@ -147,6 +152,10 @@ wsi_configure_image(const struct wsi_swapchain *chain,
|
|||
void
|
||||
wsi_destroy_image_info(const struct wsi_swapchain *chain,
|
||||
struct wsi_image_info *info);
|
||||
VkResult
|
||||
wsi_create_image(const struct wsi_swapchain *chain,
|
||||
const struct wsi_image_info *info,
|
||||
struct wsi_image *image);
|
||||
void
|
||||
wsi_destroy_image(const struct wsi_swapchain *chain,
|
||||
struct wsi_image *image);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue