frontend/va: Remove duplicate code in format support checking/reporting.

In config.c there are multiple copies of the code checking for VA_FORMAT_RT_*, this can lead
to confusion and is hard to maintain without knowing to change the code in all the places.

This commit extracts out the duplicated code into a function that checks format support
for a given profile and entrypoint, then this function is called from several places that
had the copies of this code in vlVaCreateConfig/vlVaGetConfigAttributes.

Please also note that after this change, all entrypoints/profiles will be checked for all
formats in the pipe_screen: YUV420/YUV420_10/YUV422/RGB32/YUV400/YUV444

Acked-by: Ruijing Dong <ruijing.dong@amd.com>
Tested-by: Sathishkumar S <sathishkumar.sundararaju@amd.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21466>
This commit is contained in:
Sil Vilerino 2023-02-22 08:44:26 -05:00
parent 1a6865eae3
commit ee129301a9

View file

@ -109,6 +109,66 @@ vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,
return VA_STATUS_SUCCESS;
}
static unsigned int get_screen_supported_va_rt_formats(struct pipe_screen *pscreen,
enum pipe_video_profile profile,
enum pipe_video_entrypoint entrypoint)
{
unsigned int supported_rt_formats = 0;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV,
profile,
entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV420;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
profile,
entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_400_UNORM,
profile,
entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV400;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_U8_V8_444_UNORM,
profile,
entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV444;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_UYVY,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YUYV,
profile,
entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV422;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UNORM,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UINT,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UNORM,
profile,
entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UINT,
profile,
entrypoint))
supported_rt_formats |= VA_RT_FORMAT_RGB32;
return supported_rt_formats;
}
VAStatus
vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
VAConfigAttrib *attrib_list, int num_attribs)
@ -131,39 +191,9 @@ vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint en
* Different gallium drivers will have different supported formats
* If modifying this, please query the driver like below
*/
value = 0;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
value |= VA_RT_FORMAT_YUV420;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
value |= VA_RT_FORMAT_YUV420_10BPP;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_400_UNORM,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
value |= VA_RT_FORMAT_YUV400;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_U8_V8_444_UNORM,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
value |= VA_RT_FORMAT_YUV444;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_UYVY,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YUYV,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
value |= VA_RT_FORMAT_YUV422;
value = get_screen_supported_va_rt_formats(pscreen,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_BITSTREAM);
break;
default:
value = VA_ATTRIB_NOT_SUPPORTED;
@ -173,28 +203,9 @@ vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint en
(vl_codec_supported(pscreen, ProfileToPipe(profile), true))) {
switch (attrib_list[i].type) {
case VAConfigAttribRTFormat:
/*
* Different gallium drivers will have different supported formats
* If modifying this, please query the driver like below
*/
value = 0;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_ENCODE) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_ENCODE) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_ENCODE))
value |= VA_RT_FORMAT_YUV420;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_ENCODE) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_ENCODE))
value |= VA_RT_FORMAT_YUV420_10BPP;
value = get_screen_supported_va_rt_formats(pscreen,
ProfileToPipe(profile),
PIPE_VIDEO_ENTRYPOINT_ENCODE);
break;
case VAConfigAttribRateControl:
value = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR;
@ -373,41 +384,9 @@ vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint en
} else if (entrypoint == VAEntrypointVideoProc) {
switch (attrib_list[i].type) {
case VAConfigAttribRTFormat:
/*
* Different gallium drivers will have different supported formats
* If modifying this, please query the driver like below
*/
value = 0;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING))
value |= VA_RT_FORMAT_YUV420;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING))
value |= VA_RT_FORMAT_YUV420_10BPP;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UNORM,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UINT,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UNORM,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UINT,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING))
value |= VA_RT_FORMAT_RGB32;
value = get_screen_supported_va_rt_formats(pscreen,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING);
break;
default:
value = VA_ATTRIB_NOT_SUPPORTED;
@ -453,41 +432,9 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin
config->entrypoint = PIPE_VIDEO_ENTRYPOINT_PROCESSING;
config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
/*
* Different gallium drivers will have different supported formats
* If modifying this, please query the driver like below
*/
supported_rt_formats = 0;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING))
supported_rt_formats |= VA_RT_FORMAT_YUV420;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING))
supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UNORM,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UINT,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UNORM,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UINT,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_ENTRYPOINT_PROCESSING))
supported_rt_formats |= VA_RT_FORMAT_RGB32;
supported_rt_formats = get_screen_supported_va_rt_formats(pscreen,
config->profile,
config->entrypoint);
for (int i = 0; i < num_attribs; i++) {
if (attrib_list[i].type == VAConfigAttribRTFormat) {
if (attrib_list[i].value & supported_rt_formats) {
@ -556,37 +503,9 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin
}
config->profile = p;
/*
* Different gallium drivers will have different supported formats
* If modifying this, please query the driver like below
*/
supported_rt_formats = 0;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12, p,
config->entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12, p,
config->entrypoint)||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV, p,
config->entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV420;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010, p,
config->entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016, p,
config->entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_400_UNORM,
ProfileToPipe(profile),
config->entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV400;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_U8_V8_444_UNORM,
ProfileToPipe(profile),
config->entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV444;
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_UYVY, p,
config->entrypoint) ||
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YUYV, p,
config->entrypoint))
supported_rt_formats |= VA_RT_FORMAT_YUV422;
supported_rt_formats = get_screen_supported_va_rt_formats(pscreen,
config->profile,
config->entrypoint);
for (int i = 0; i <num_attribs ; i++) {
if (attrib_list[i].type != VAConfigAttribRTFormat &&
entrypoint == VAEntrypointVLD ) {