avutil/hwcontext_vulkan: Allocate pub and priv frames hwctx together

This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VulkanFramesPriv as one no longer has to
go through AVHWFramesInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-02-11 19:22:50 +01:00
parent 2d63379cae
commit e70e9b6554
1 changed files with 17 additions and 13 deletions

View File

@ -129,6 +129,11 @@ typedef struct VulkanDevicePriv {
} VulkanDevicePriv; } VulkanDevicePriv;
typedef struct VulkanFramesPriv { typedef struct VulkanFramesPriv {
/**
* The public AVVulkanFramesContext. See hwcontext_vulkan.h for it.
*/
AVVulkanFramesContext p;
/* Image conversions */ /* Image conversions */
FFVkExecPool compute_exec; FFVkExecPool compute_exec;
@ -2198,9 +2203,9 @@ static AVBufferRef *vulkan_pool_alloc(void *opaque, size_t size)
AVVkFrame *f; AVVkFrame *f;
AVBufferRef *avbuf = NULL; AVBufferRef *avbuf = NULL;
AVHWFramesContext *hwfc = opaque; AVHWFramesContext *hwfc = opaque;
AVVulkanFramesContext *hwctx = hwfc->hwctx;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx; VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
AVVulkanFramesContext *hwctx = &fp->p;
VkExternalMemoryHandleTypeFlags e = 0x0; VkExternalMemoryHandleTypeFlags e = 0x0;
VkExportMemoryAllocateInfo eminfo[AV_NUM_DATA_POINTERS]; VkExportMemoryAllocateInfo eminfo[AV_NUM_DATA_POINTERS];
@ -2271,7 +2276,7 @@ static void unlock_frame(AVHWFramesContext *fc, AVVkFrame *vkf)
static void vulkan_frames_uninit(AVHWFramesContext *hwfc) static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
{ {
VulkanDevicePriv *p = hwfc->device_ctx->hwctx; VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
if (fp->modifier_info) { if (fp->modifier_info) {
if (fp->modifier_info->pDrmFormatModifiers) if (fp->modifier_info->pDrmFormatModifiers)
@ -2288,8 +2293,8 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
{ {
int err; int err;
AVVkFrame *f; AVVkFrame *f;
AVVulkanFramesContext *hwctx = hwfc->hwctx; VulkanFramesPriv *fp = hwfc->hwctx;
VulkanFramesPriv *fp = hwfc->internal->priv; AVVulkanFramesContext *hwctx = &fp->p;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx; VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VkImageUsageFlagBits supported_usage; VkImageUsageFlagBits supported_usage;
const struct FFVkFormatEntry *fmt; const struct FFVkFormatEntry *fmt;
@ -2500,7 +2505,7 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
VulkanDevicePriv *p = ctx->hwctx; VulkanDevicePriv *p = ctx->hwctx;
AVVulkanDeviceContext *hwctx = &p->p; AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn; FFVulkanFunctions *vk = &p->vkctx.vkfn;
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)src->data[0]; const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)src->data[0];
VkBindImageMemoryInfo bind_info[AV_DRM_MAX_PLANES]; VkBindImageMemoryInfo bind_info[AV_DRM_MAX_PLANES];
VkBindImagePlaneMemoryInfo plane_info[AV_DRM_MAX_PLANES]; VkBindImagePlaneMemoryInfo plane_info[AV_DRM_MAX_PLANES];
@ -3005,7 +3010,7 @@ static int vulkan_transfer_data_from_cuda(AVHWFramesContext *hwfc,
CUcontext dummy; CUcontext dummy;
AVVkFrame *dst_f; AVVkFrame *dst_f;
AVVkFrameInternal *dst_int; AVVkFrameInternal *dst_int;
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format); const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format); const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format);
@ -3147,8 +3152,8 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
VulkanDevicePriv *p = hwfc->device_ctx->hwctx; VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
AVVulkanDeviceContext *hwctx = &p->p; AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn; FFVulkanFunctions *vk = &p->vkctx.vkfn;
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
AVVulkanFramesContext *hwfctx = hwfc->hwctx; AVVulkanFramesContext *hwfctx = &fp->p;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format); const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
VkImageDrmFormatModifierPropertiesEXT drm_mod = { VkImageDrmFormatModifierPropertiesEXT drm_mod = {
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
@ -3318,7 +3323,7 @@ static int transfer_image_buf(AVHWFramesContext *hwfc, AVFrame *f,
{ {
int err; int err;
AVVkFrame *frame = (AVVkFrame *)f->data[0]; AVVkFrame *frame = (AVVkFrame *)f->data[0];
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx; VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
FFVulkanFunctions *vk = &p->vkctx.vkfn; FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS]; VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
@ -3579,7 +3584,7 @@ static int vulkan_transfer_data_to_cuda(AVHWFramesContext *hwfc, AVFrame *dst,
CUcontext dummy; CUcontext dummy;
AVVkFrame *dst_f; AVVkFrame *dst_f;
AVVkFrameInternal *dst_int; AVVkFrameInternal *dst_int;
VulkanFramesPriv *fp = hwfc->internal->priv; VulkanFramesPriv *fp = hwfc->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format); const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format); const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format);
@ -3722,8 +3727,7 @@ const HWContextType ff_hwcontext_type_vulkan = {
.name = "Vulkan", .name = "Vulkan",
.device_hwctx_size = sizeof(VulkanDevicePriv), .device_hwctx_size = sizeof(VulkanDevicePriv),
.frames_hwctx_size = sizeof(AVVulkanFramesContext), .frames_hwctx_size = sizeof(VulkanFramesPriv),
.frames_priv_size = sizeof(VulkanFramesPriv),
.device_init = &vulkan_device_init, .device_init = &vulkan_device_init,
.device_uninit = &vulkan_device_uninit, .device_uninit = &vulkan_device_uninit,