[Mesa-dev] [PATCH 1/9] st/va: add encode entrypoint v2
From: Boyuan ZhangVAAPI passes PIPE_VIDEO_ENTRYPOINT_ENCODE as entry point for encoding case. We will save this encode entry point in config. config_id was used as profile previously. Now, config has both profile and entrypoint field, and config_id is used to get the config object. Later on, we pass this entrypoint to context->templat.entrypoint instead of always hardcoded to PIPE_VIDEO_ENTRYPOINT_BITSTREAM for decoding case previously. Encode entrypoint is not accepted by driver until we enable Vaapi encode in later patch. v2 (chk): fix commit message to match 80 chars, use switch instead of ifs, fix memory leaks in the error path, implement vlVaQueryConfigEntrypoints as well, drop VAEntrypointEncPicture (only used for JPEG). Signed-off-by: Boyuan Zhang Signed-off-by: Christian König --- src/gallium/state_trackers/va/config.c | 111 + src/gallium/state_trackers/va/context.c| 59 --- src/gallium/state_trackers/va/surface.c| 14 +++- src/gallium/state_trackers/va/va_private.h | 5 ++ 4 files changed, 150 insertions(+), 39 deletions(-) diff --git a/src/gallium/state_trackers/va/config.c b/src/gallium/state_trackers/va/config.c index 9ca0aa8..7742087 100644 --- a/src/gallium/state_trackers/va/config.c +++ b/src/gallium/state_trackers/va/config.c @@ -34,6 +34,8 @@ #include "va_private.h" +#include "util/u_handle_table.h" + DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false) VAStatus @@ -88,10 +90,18 @@ vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile, return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; pscreen = VL_VA_PSCREEN(ctx); - if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED)) - return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, + PIPE_VIDEO_CAP_SUPPORTED)) + entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD; - entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD; +#if 0 + if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, + PIPE_VIDEO_CAP_SUPPORTED)) + entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncSlice; +#endif + + if (num_entrypoints == 0) + return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; return VA_STATUS_SUCCESS; } @@ -128,29 +138,73 @@ VAStatus vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint, VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id) { + vlVaDriver *drv; + vlVaConfig *config; struct pipe_screen *pscreen; enum pipe_video_profile p; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; + drv = VL_VA_DRIVER(ctx); + + if (!drv) + return VA_STATUS_ERROR_INVALID_CONTEXT; + + config = CALLOC(1, sizeof(vlVaConfig)); + if (!config) + return VA_STATUS_ERROR_ALLOCATION_FAILED; + if (profile == VAProfileNone && entrypoint == VAEntrypointVideoProc) { - *config_id = PIPE_VIDEO_PROFILE_UNKNOWN; + config->entrypoint = VAEntrypointVideoProc; + config->profile = PIPE_VIDEO_PROFILE_UNKNOWN; + pipe_mutex_lock(drv->mutex); + *config_id = handle_table_add(drv->htab, config); + pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; } p = ProfileToPipe(profile); - if (p == PIPE_VIDEO_PROFILE_UNKNOWN) + if (p == PIPE_VIDEO_PROFILE_UNKNOWN) { + FREE(config); return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + } pscreen = VL_VA_PSCREEN(ctx); - if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED)) - return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; - if (entrypoint != VAEntrypointVLD) + switch (entrypoint) { + case VAEntrypointVLD: + if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, + PIPE_VIDEO_CAP_SUPPORTED)) { + FREE(config); + return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + } + + config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; + break; + +#if 0 + case VAEntrypointEncSlice: + if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, + PIPE_VIDEO_CAP_SUPPORTED)) { + FREE(config); + return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; + } + + config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE; + break; +#endif + + default: + FREE(config); return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + } - *config_id = p; + config->profile = p; + + pipe_mutex_lock(drv->mutex); + *config_id = handle_table_add(drv->htab, config); + pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; } @@ -158,9 +212,27 @@
[Mesa-dev] [PATCH 1/9] st/va: add encode entrypoint
VAAPI passes PIPE_VIDEO_ENTRYPOINT_ENCODE as entry point for encoding case. We will save this encode entry point in config. config_id was used as profile previously. Now, config has both profile and entrypoint field, and config_id is used to get the config object. Later on, we pass this entrypoint to context->templat.entrypoint instead of always hardcoded to PIPE_VIDEO_ENTRYPOINT_BITSTREAM for decoding case previously. Encode entrypoint is not accepted by driver until we enable Vaapi encode in later patch. Signed-off-by: Boyuan Zhang--- src/gallium/state_trackers/va/config.c | 71 +++--- src/gallium/state_trackers/va/context.c| 59 +++-- src/gallium/state_trackers/va/surface.c| 14 -- src/gallium/state_trackers/va/va_private.h | 5 +++ 4 files changed, 117 insertions(+), 32 deletions(-) diff --git a/src/gallium/state_trackers/va/config.c b/src/gallium/state_trackers/va/config.c index 9ca0aa8..3aacc63 100644 --- a/src/gallium/state_trackers/va/config.c +++ b/src/gallium/state_trackers/va/config.c @@ -34,6 +34,8 @@ #include "va_private.h" +#include "util/u_handle_table.h" + DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false) VAStatus @@ -128,14 +130,29 @@ VAStatus vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint, VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id) { + vlVaDriver *drv; + vlVaConfig *config; struct pipe_screen *pscreen; enum pipe_video_profile p; if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; + drv = VL_VA_DRIVER(ctx); + + if (!drv) + return VA_STATUS_ERROR_INVALID_CONTEXT; + + config = CALLOC(1, sizeof(vlVaConfig)); + if (!config) + return VA_STATUS_ERROR_ALLOCATION_FAILED; + if (profile == VAProfileNone && entrypoint == VAEntrypointVideoProc) { - *config_id = PIPE_VIDEO_PROFILE_UNKNOWN; + config->entrypoint = VAEntrypointVideoProc; + config->profile = PIPE_VIDEO_PROFILE_UNKNOWN; + pipe_mutex_lock(drv->mutex); + *config_id = handle_table_add(drv->htab, config); + pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; } @@ -150,7 +167,18 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin if (entrypoint != VAEntrypointVLD) return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; - *config_id = p; +#if 0 + if (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointEncPicture) + config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE; + else +#endif + config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM; + + config->profile = p; + + pipe_mutex_lock(drv->mutex); + *config_id = handle_table_add(drv->htab, config); + pipe_mutex_unlock(drv->mutex); return VA_STATUS_SUCCESS; } @@ -158,9 +186,27 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin VAStatus vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id) { + vlVaDriver *drv; + vlVaConfig *config; + if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; + drv = VL_VA_DRIVER(ctx); + + if (!drv) + return VA_STATUS_ERROR_INVALID_CONTEXT; + + pipe_mutex_lock(drv->mutex); + config = handle_table_get(drv->htab, config_id); + + if (!config) + return VA_STATUS_ERROR_INVALID_CONFIG; + + FREE(config); + handle_table_remove(drv->htab, config_id); + pipe_mutex_unlock(drv->mutex); + return VA_STATUS_SUCCESS; } @@ -168,18 +214,33 @@ VAStatus vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile, VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs) { + vlVaDriver *drv; + vlVaConfig *config; + if (!ctx) return VA_STATUS_ERROR_INVALID_CONTEXT; - *profile = PipeToProfile(config_id); + drv = VL_VA_DRIVER(ctx); + + if (!drv) + return VA_STATUS_ERROR_INVALID_CONTEXT; + + pipe_mutex_lock(drv->mutex); + config = handle_table_get(drv->htab, config_id); + pipe_mutex_unlock(drv->mutex); + + if (!config) + return VA_STATUS_ERROR_INVALID_CONFIG; + + *profile = PipeToProfile(config->profile); - if (config_id == PIPE_VIDEO_PROFILE_UNKNOWN) { + if (config->profile == PIPE_VIDEO_PROFILE_UNKNOWN) { *entrypoint = VAEntrypointVideoProc; *num_attribs = 0; return VA_STATUS_SUCCESS; } - *entrypoint = VAEntrypointVLD; + *entrypoint = config->entrypoint; *num_attribs = 1; attrib_list[0].type = VAConfigAttribRTFormat; diff --git a/src/gallium/state_trackers/va/context.c b/src/gallium/state_trackers/va/context.c index 402fbb2..8882cba 100644 --- a/src/gallium/state_trackers/va/context.c +++ b/src/gallium/state_trackers/va/context.c @@ -195,18 +195,23 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width, { vlVaDriver *drv; vlVaContext