mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 18:08:40 +02:00
pvr: refactor image initialization with helper functions
Extract image initialization & cleanup logic into reusable helper functions. - Create pvr_image_init() and pvr_image_fini() for refactoring - Refactor pvr_CreateImage(), pvr_CreateBuffer() Signed-off-by: Leon Perianu <leon.perianu@imgtec.com> Reviewed-by: Frank Binns <frank.binns@imgtec.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39776>
This commit is contained in:
parent
bf3b011919
commit
f0b7e2c1ea
2 changed files with 38 additions and 27 deletions
|
|
@ -270,10 +270,6 @@ VkResult pvr_CreateImage(VkDevice _device,
|
|||
{
|
||||
VK_FROM_HANDLE(pvr_device, device, _device);
|
||||
struct pvr_image *image;
|
||||
uint64_t modifier = DRM_FORMAT_MOD_INVALID;
|
||||
VkResult res;
|
||||
|
||||
unsigned pbe_stride_align = get_pbe_stride_align(&device->pdevice->dev_info);
|
||||
|
||||
if (wsi_common_is_swapchain_image(pCreateInfo)) {
|
||||
return wsi_common_create_swapchain_image(&device->pdevice->wsi_device,
|
||||
|
|
@ -281,32 +277,12 @@ VkResult pvr_CreateImage(VkDevice _device,
|
|||
pImage);
|
||||
}
|
||||
|
||||
if (pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
|
||||
res = pvr_pick_modifier(pCreateInfo, pbe_stride_align,
|
||||
&modifier);
|
||||
if (res != VK_SUCCESS)
|
||||
return vk_error(device, res);
|
||||
|
||||
assert(modifier == DRM_FORMAT_MOD_LINEAR);
|
||||
}
|
||||
|
||||
image =
|
||||
vk_image_create(&device->vk, pCreateInfo, pAllocator, sizeof(*image));
|
||||
if (!image)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
if (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
|
||||
image->vk.drm_format_mod = modifier;
|
||||
}
|
||||
|
||||
image->alignment = device->pdevice->ws->page_size;
|
||||
|
||||
image->plane_count = vk_format_get_plane_count(image->vk.format);
|
||||
|
||||
/* Initialize the image using the saved information from pCreateInfo */
|
||||
pvr_image_init_memlayout(image);
|
||||
pvr_image_init_physical_extent(image, pCreateInfo, pbe_stride_align);
|
||||
pvr_image_setup_mip_levels(image);
|
||||
pvr_image_init(device, pCreateInfo, image);
|
||||
|
||||
*pImage = pvr_image_to_handle(image);
|
||||
|
||||
|
|
@ -323,10 +299,38 @@ void pvr_DestroyImage(VkDevice _device,
|
|||
if (!image)
|
||||
return;
|
||||
|
||||
pvr_image_fini(device, image);
|
||||
vk_image_destroy(&device->vk, pAllocator, &image->vk);
|
||||
}
|
||||
|
||||
void pvr_image_init(struct pvr_device *device,
|
||||
const VkImageCreateInfo *pCreateInfo,
|
||||
struct pvr_image *image)
|
||||
{
|
||||
unsigned pbe_stride_align = get_pbe_stride_align(&device->pdevice->dev_info);
|
||||
|
||||
image->plane_count = vk_format_get_plane_count(image->vk.format);
|
||||
image->alignment = device->pdevice->ws->page_size;
|
||||
|
||||
if (pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
|
||||
VkResult res = pvr_pick_modifier(pCreateInfo,
|
||||
pbe_stride_align,
|
||||
&image->vk.drm_format_mod);
|
||||
if (res != VK_SUCCESS)
|
||||
assert(res == VK_SUCCESS);
|
||||
|
||||
assert(image->vk.drm_format_mod == DRM_FORMAT_MOD_LINEAR);
|
||||
}
|
||||
|
||||
pvr_image_init_memlayout(image);
|
||||
pvr_image_init_physical_extent(image, pCreateInfo, pbe_stride_align);
|
||||
pvr_image_setup_mip_levels(image);
|
||||
}
|
||||
|
||||
void pvr_image_fini(struct pvr_device *device, struct pvr_image *image)
|
||||
{
|
||||
if (image->vma)
|
||||
pvr_unbind_memory(device, image->vma);
|
||||
|
||||
vk_image_destroy(&device->vk, pAllocator, &image->vk);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#define PVR_MAX_PLANE_COUNT 3
|
||||
|
||||
struct pvr_device;
|
||||
|
||||
struct pvr_mip_level {
|
||||
/* Offset of the mip level in bytes */
|
||||
uint32_t offset;
|
||||
|
|
@ -167,4 +169,9 @@ void pvr_get_image_subresource_layout(const struct pvr_image *image,
|
|||
const VkImageSubresource *subresource,
|
||||
VkSubresourceLayout *layout);
|
||||
|
||||
void pvr_image_init(struct pvr_device *device,
|
||||
const VkImageCreateInfo *pCreateInfo,
|
||||
struct pvr_image *image);
|
||||
void pvr_image_fini(struct pvr_device *device, struct pvr_image *image);
|
||||
|
||||
#endif /* PVR_IMAGE_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue