1
0
Fork 0

avcodec/vulkan_video: Merge dec part of FFVkCodecMap and extension props

All the fields of FFVkCodecMap are either decoder-only
or encoder-only (with the latter being unused and unset for now).
Yet there is already a per-decoder struct containing
static information about these decoders, namely
VkExtensionProperties.

This commit merges the decoder-parts of FFVkCodecMap
with the VkExtensionProperties into a common structure.

Given that FFVkCodecMap is now unused, it is removed.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-03-07 01:08:16 +01:00
parent 6c82b7bc0a
commit f7b227bec3
7 changed files with 50 additions and 73 deletions

View File

@ -23,9 +23,13 @@
/* Maximum number of tiles specified by any defined level */
#define MAX_TILES 256
const VkExtensionProperties ff_vk_dec_av1_ext = {
.extensionName = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION,
const FFVulkanDecodeDescriptor ff_vk_dec_av1_desc = {
.decode_extension = FF_VK_EXT_VIDEO_DECODE_AV1,
.decode_op = 0x01000000, /* TODO fix this */
.ext_props = {
.extensionName = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION,
},
};
typedef struct AV1VulkanDecodePicture {

View File

@ -20,38 +20,33 @@
#include "vulkan_video.h"
#include "vulkan_decode.h"
#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/vulkan_loader.h"
#if CONFIG_H264_VULKAN_HWACCEL
extern const VkExtensionProperties ff_vk_dec_h264_ext;
extern const FFVulkanDecodeDescriptor ff_vk_dec_h264_desc;
#endif
#if CONFIG_HEVC_VULKAN_HWACCEL
extern const VkExtensionProperties ff_vk_dec_hevc_ext;
extern const FFVulkanDecodeDescriptor ff_vk_dec_hevc_desc;
#endif
#if CONFIG_AV1_VULKAN_HWACCEL
extern const VkExtensionProperties ff_vk_dec_av1_ext;
extern const FFVulkanDecodeDescriptor ff_vk_dec_av1_desc;
#endif
static const VkExtensionProperties *dec_ext[] = {
static const FFVulkanDecodeDescriptor *dec_descs[] = {
#if CONFIG_H264_VULKAN_HWACCEL
[AV_CODEC_ID_H264] = &ff_vk_dec_h264_ext,
[AV_CODEC_ID_H264] = &ff_vk_dec_h264_desc,
#endif
#if CONFIG_HEVC_VULKAN_HWACCEL
[AV_CODEC_ID_HEVC] = &ff_vk_dec_hevc_ext,
[AV_CODEC_ID_HEVC] = &ff_vk_dec_hevc_desc,
#endif
#if CONFIG_AV1_VULKAN_HWACCEL
[AV_CODEC_ID_AV1] = &ff_vk_dec_av1_ext,
[AV_CODEC_ID_AV1] = &ff_vk_dec_av1_desc,
#endif
};
static const FFVkCodecMap *get_codecmap(enum AVCodecID codec_id)
static const FFVulkanDecodeDescriptor *get_codecdesc(enum AVCodecID codec_id)
{
for (size_t i = 0; i < FF_ARRAY_ELEMS(ff_vk_codec_map); i++)
if (ff_vk_codec_map[i].codec_id == codec_id)
return &ff_vk_codec_map[i];
av_assert1(!"unreachable");
return NULL;
return dec_descs[codec_id];
}
static const VkVideoProfileInfoKHR *get_video_profile(FFVulkanDecodeShared *ctx, enum AVCodecID codec_id)
@ -671,7 +666,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
FFVulkanDecodeProfileData *prof,
AVVulkanDeviceContext *hwctx,
FFVulkanFunctions *vk,
const struct FFVkCodecMap *vk_codec,
const FFVulkanDecodeDescriptor *vk_desc,
VkVideoDecodeH264CapabilitiesKHR *h264_caps,
VkVideoDecodeH265CapabilitiesKHR *h265_caps,
VkVideoDecodeAV1CapabilitiesMESA *av1_caps,
@ -722,7 +717,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
profile->sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR;
profile->pNext = usage;
profile->videoCodecOperation = vk_codec->decode_op;
profile->videoCodecOperation = vk_desc->decode_op;
profile->chromaSubsampling = ff_vk_subsampling_from_av_desc(desc);
profile->lumaBitDepth = ff_vk_depth_from_av_depth(desc->comp[0].depth);
profile->chromaBitDepth = profile->lumaBitDepth;
@ -748,7 +743,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
{
VkResult ret;
int max_level, base_profile, cur_profile;
const FFVkCodecMap *vk_codec = get_codecmap(avctx->codec_id);
const FFVulkanDecodeDescriptor *vk_desc = get_codecdesc(avctx->codec_id);
AVHWFramesContext *frames = (AVHWFramesContext *)frames_ref->data;
AVHWDeviceContext *device = (AVHWDeviceContext *)frames->device_ref->data;
AVVulkanDeviceContext *hwctx = device->hwctx;
@ -780,11 +775,11 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
VkVideoFormatPropertiesKHR *ret_info;
uint32_t nb_out_fmts = 0;
if (!vk_codec->decode_op || !vk_codec->decode_extension) {
if (!vk_desc->decode_op || !vk_desc->decode_extension) {
av_log(avctx, AV_LOG_ERROR, "Unsupported codec for Vulkan decoding: %s!\n",
avcodec_get_name(avctx->codec_id));
return AVERROR(ENOSYS);
} else if (!(vk_codec->decode_extension & ctx->s.extensions)) {
} else if (!(vk_desc->decode_extension & ctx->s.extensions)) {
av_log(avctx, AV_LOG_ERROR, "Device does not support decoding %s!\n",
avcodec_get_name(avctx->codec_id));
return AVERROR(ENOSYS);
@ -796,7 +791,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
avctx->codec_id == AV_CODEC_ID_AV1 ? STD_VIDEO_AV1_MESA_PROFILE_MAIN :
0;
ret = vulkan_setup_profile(avctx, prof, hwctx, vk, vk_codec,
ret = vulkan_setup_profile(avctx, prof, hwctx, vk, vk_desc,
&h264_caps,
&h265_caps,
&av1_caps,
@ -812,7 +807,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
avcodec_profile_name(avctx->codec_id, cur_profile),
avcodec_profile_name(avctx->codec_id, base_profile));
cur_profile = base_profile;
ret = vulkan_setup_profile(avctx, prof, hwctx, vk, vk_codec,
ret = vulkan_setup_profile(avctx, prof, hwctx, vk, vk_desc,
&h264_caps,
&h265_caps,
&av1_caps,
@ -867,10 +862,10 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
caps->maxActiveReferencePictures);
av_log(avctx, AV_LOG_VERBOSE, " Codec header name: '%s' (driver), '%s' (compiled)\n",
caps->stdHeaderVersion.extensionName,
dec_ext[avctx->codec_id]->extensionName);
vk_desc->ext_props.extensionName);
av_log(avctx, AV_LOG_VERBOSE, " Codec header version: %i.%i.%i (driver), %i.%i.%i (compiled)\n",
CODEC_VER(caps->stdHeaderVersion.specVersion),
CODEC_VER(dec_ext[avctx->codec_id]->specVersion));
CODEC_VER(vk_desc->ext_props.specVersion));
av_log(avctx, AV_LOG_VERBOSE, " Decode modes:%s%s%s\n",
dec_caps->flags ? "" :
" invalid",
@ -1122,7 +1117,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
FFVulkanContext *s;
FFVulkanFunctions *vk;
const VkVideoProfileInfoKHR *profile;
const FFVkCodecMap *vk_codec;
const FFVulkanDecodeDescriptor *vk_desc;
VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = {
.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR,
@ -1179,9 +1174,9 @@ int ff_vk_decode_init(AVCodecContext *avctx)
/* Create queue context */
qf = ff_vk_qf_init(s, &ctx->qf, VK_QUEUE_VIDEO_DECODE_BIT_KHR);
vk_codec = get_codecmap(avctx->codec_id);
vk_desc = get_codecdesc(avctx->codec_id);
/* Check for support */
if (!(s->video_props[qf].videoCodecOperations & vk_codec->decode_op)) {
if (!(s->video_props[qf].videoCodecOperations & vk_desc->decode_op)) {
av_log(avctx, AV_LOG_ERROR, "Decoding %s not supported on the given "
"queue family %i!\n", avcodec_get_name(avctx->codec_id), qf);
return AVERROR(EINVAL);
@ -1198,7 +1193,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
session_create.maxActiveReferencePictures = ctx->caps.maxActiveReferencePictures;
session_create.pictureFormat = s->hwfc->format[0];
session_create.referencePictureFormat = session_create.pictureFormat;
session_create.pStdHeaderVersion = dec_ext[avctx->codec_id];
session_create.pStdHeaderVersion = &vk_desc->ext_props;
session_create.pVideoProfile = profile;
/* Create decode exec context for this specific main thread.

View File

@ -25,6 +25,13 @@
#include "vulkan_video.h"
typedef struct FFVulkanDecodeDescriptor {
FFVulkanExtensions decode_extension;
VkVideoCodecOperationFlagBitsKHR decode_op;
VkExtensionProperties ext_props;
} FFVulkanDecodeDescriptor;
typedef struct FFVulkanDecodeProfileData {
VkVideoDecodeH264ProfileInfoKHR h264_profile;
VkVideoDecodeH265ProfileInfoKHR h265_profile;

View File

@ -21,9 +21,13 @@
#include "vulkan_decode.h"
const VkExtensionProperties ff_vk_dec_h264_ext = {
.extensionName = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME,
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION,
const FFVulkanDecodeDescriptor ff_vk_dec_h264_desc = {
.decode_extension = FF_VK_EXT_VIDEO_DECODE_H264,
.decode_op = VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR,
.ext_props = {
.extensionName = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME,
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION,
},
};
typedef struct H264VulkanDecodePicture {

View File

@ -22,9 +22,13 @@
#include "vulkan_decode.h"
const VkExtensionProperties ff_vk_dec_hevc_ext = {
.extensionName = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME,
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION,
const FFVulkanDecodeDescriptor ff_vk_dec_hevc_desc = {
.decode_extension = FF_VK_EXT_VIDEO_DECODE_H265,
.decode_op = VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR,
.ext_props = {
.extensionName = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME,
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION,
},
};
typedef struct HEVCHeaderSPS {

View File

@ -16,34 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "codec_id.h"
#include "vulkan_video.h"
const FFVkCodecMap ff_vk_codec_map[3] = {
{
.codec_id = AV_CODEC_ID_H264,
0,
0,
FF_VK_EXT_VIDEO_DECODE_H264,
VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR,
},
{
.codec_id = AV_CODEC_ID_HEVC,
0,
0,
FF_VK_EXT_VIDEO_DECODE_H265,
VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR
},
{
.codec_id = AV_CODEC_ID_AV1,
0,
0,
FF_VK_EXT_VIDEO_DECODE_AV1,
0x01000000 /* TODO fix this */
},
};
#define ASPECT_2PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT)
#define ASPECT_3PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT)

View File

@ -19,7 +19,6 @@
#ifndef AVCODEC_VULKAN_VIDEO_H
#define AVCODEC_VULKAN_VIDEO_H
#include "codec_id.h"
#include "vulkan.h"
#include <vk_video/vulkan_video_codecs_common.h>
@ -31,14 +30,6 @@
#define CODEC_VER_PAT(ver) (ver & ((1 << 12) - 1))
#define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver)
typedef struct FFVkCodecMap {
enum AVCodecID codec_id;
FFVulkanExtensions encode_extension;
VkVideoCodecOperationFlagBitsKHR encode_op;
FFVulkanExtensions decode_extension;
VkVideoCodecOperationFlagBitsKHR decode_op;
} FFVkCodecMap;
typedef struct FFVkVideoSession {
VkVideoSessionKHR session;
VkDeviceMemory *mem;
@ -47,8 +38,6 @@ typedef struct FFVkVideoSession {
AVBufferPool *buf_pool;
} FFVkVideoCommon;
extern const FFVkCodecMap ff_vk_codec_map[3];
/**
* Get pixfmt from a Vulkan format.
*/