Path: blob/21.2-virgl/src/gallium/frontends/va/config.c
4561 views
/**************************************************************************1*2* Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.3* Copyright 2014 Advanced Micro Devices, Inc.4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* The above copyright notice and this permission notice (including the15* next paragraph) shall be included in all copies or substantial portions16* of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS19* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF20* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.21* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR22* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,23* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE24* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.25*26**************************************************************************/2728#include "pipe/p_screen.h"2930#include "util/u_video.h"31#include "util/u_memory.h"3233#include "vl/vl_winsys.h"3435#include "va_private.h"3637#include "util/u_handle_table.h"3839DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false)4041VAStatus42vlVaQueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list, int *num_profiles)43{44struct pipe_screen *pscreen;45enum pipe_video_profile p;46VAProfile vap;4748if (!ctx)49return VA_STATUS_ERROR_INVALID_CONTEXT;5051*num_profiles = 0;5253pscreen = VL_VA_PSCREEN(ctx);54for (p = PIPE_VIDEO_PROFILE_MPEG2_SIMPLE; p <= PIPE_VIDEO_PROFILE_VP9_PROFILE2; ++p) {55if (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 && !debug_get_option_mpeg4())56continue;5758if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED) ||59pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED)) {60vap = PipeToProfile(p);61if (vap != VAProfileNone)62profile_list[(*num_profiles)++] = vap;63}64}6566/* Support postprocessing through vl_compositor */67profile_list[(*num_profiles)++] = VAProfileNone;6869return VA_STATUS_SUCCESS;70}7172VAStatus73vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,74VAEntrypoint *entrypoint_list, int *num_entrypoints)75{76struct pipe_screen *pscreen;77enum pipe_video_profile p;7879if (!ctx)80return VA_STATUS_ERROR_INVALID_CONTEXT;8182*num_entrypoints = 0;8384if (profile == VAProfileNone) {85entrypoint_list[(*num_entrypoints)++] = VAEntrypointVideoProc;86return VA_STATUS_SUCCESS;87}8889p = ProfileToPipe(profile);90if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||91(u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&92!debug_get_option_mpeg4()))93return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;9495pscreen = VL_VA_PSCREEN(ctx);96if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,97PIPE_VIDEO_CAP_SUPPORTED))98entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD;99100if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE,101PIPE_VIDEO_CAP_SUPPORTED))102entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncSlice;103104if (*num_entrypoints == 0)105return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;106107assert(*num_entrypoints <= ctx->max_entrypoints);108109return VA_STATUS_SUCCESS;110}111112VAStatus113vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,114VAConfigAttrib *attrib_list, int num_attribs)115{116struct pipe_screen *pscreen;117int i;118119if (!ctx)120return VA_STATUS_ERROR_INVALID_CONTEXT;121122pscreen = VL_VA_PSCREEN(ctx);123124for (i = 0; i < num_attribs; ++i) {125unsigned int value;126if ((entrypoint == VAEntrypointVLD) &&127(pscreen->get_video_param(pscreen, ProfileToPipe(profile),128PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED))) {129switch (attrib_list[i].type) {130case VAConfigAttribRTFormat:131value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422;132if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,133ProfileToPipe(profile),134PIPE_VIDEO_ENTRYPOINT_BITSTREAM) ||135pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,136ProfileToPipe(profile),137PIPE_VIDEO_ENTRYPOINT_BITSTREAM))138value |= VA_RT_FORMAT_YUV420_10BPP;139break;140default:141value = VA_ATTRIB_NOT_SUPPORTED;142break;143}144} else if ((entrypoint == VAEntrypointEncSlice) &&145(pscreen->get_video_param(pscreen, ProfileToPipe(profile),146PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED))) {147switch (attrib_list[i].type) {148case VAConfigAttribRTFormat:149value = VA_RT_FORMAT_YUV420;150if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,151ProfileToPipe(profile),152PIPE_VIDEO_ENTRYPOINT_ENCODE) ||153pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,154ProfileToPipe(profile),155PIPE_VIDEO_ENTRYPOINT_ENCODE))156value |= VA_RT_FORMAT_YUV420_10BPP;157break;158case VAConfigAttribRateControl:159value = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR;160break;161case VAConfigAttribEncPackedHeaders:162value = VA_ENC_PACKED_HEADER_NONE;163if (u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_MPEG4_AVC ||164u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_HEVC)165value |= VA_ENC_PACKED_HEADER_SEQUENCE;166break;167case VAConfigAttribEncMaxRefFrames:168value = 1;169break;170default:171value = VA_ATTRIB_NOT_SUPPORTED;172break;173}174} else if (entrypoint == VAEntrypointVideoProc) {175switch (attrib_list[i].type) {176case VAConfigAttribRTFormat:177value = (VA_RT_FORMAT_YUV420 |178VA_RT_FORMAT_YUV420_10BPP |179VA_RT_FORMAT_RGB32);180break;181default:182value = VA_ATTRIB_NOT_SUPPORTED;183break;184}185} else {186value = VA_ATTRIB_NOT_SUPPORTED;187}188attrib_list[i].value = value;189}190191return VA_STATUS_SUCCESS;192}193194VAStatus195vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,196VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id)197{198vlVaDriver *drv;199vlVaConfig *config;200struct pipe_screen *pscreen;201enum pipe_video_profile p;202unsigned int supported_rt_formats;203204if (!ctx)205return VA_STATUS_ERROR_INVALID_CONTEXT;206207drv = VL_VA_DRIVER(ctx);208209if (!drv)210return VA_STATUS_ERROR_INVALID_CONTEXT;211212config = CALLOC(1, sizeof(vlVaConfig));213if (!config)214return VA_STATUS_ERROR_ALLOCATION_FAILED;215216if (profile == VAProfileNone) {217if (entrypoint != VAEntrypointVideoProc) {218FREE(config);219return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;220}221222config->entrypoint = PIPE_VIDEO_ENTRYPOINT_UNKNOWN;223config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;224supported_rt_formats = VA_RT_FORMAT_YUV420 |225VA_RT_FORMAT_YUV420_10BPP |226VA_RT_FORMAT_RGB32;227for (int i = 0; i < num_attribs; i++) {228if (attrib_list[i].type == VAConfigAttribRTFormat) {229if (attrib_list[i].value & supported_rt_formats) {230config->rt_format = attrib_list[i].value;231} else {232FREE(config);233return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;234}235} else {236/*other attrib_types are not supported.*/237FREE(config);238return VA_STATUS_ERROR_INVALID_VALUE;239}240}241242/* Default value if not specified in the input attributes. */243if (!config->rt_format)244config->rt_format = supported_rt_formats;245246mtx_lock(&drv->mutex);247*config_id = handle_table_add(drv->htab, config);248mtx_unlock(&drv->mutex);249return VA_STATUS_SUCCESS;250}251252p = ProfileToPipe(profile);253if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||254(u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&255!debug_get_option_mpeg4())) {256FREE(config);257return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;258}259260pscreen = VL_VA_PSCREEN(ctx);261262switch (entrypoint) {263case VAEntrypointVLD:264supported_rt_formats = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422;265if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,266PIPE_VIDEO_CAP_SUPPORTED)) {267FREE(config);268return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;269}270271config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;272break;273274case VAEntrypointEncSlice:275supported_rt_formats = VA_RT_FORMAT_YUV420;276if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE,277PIPE_VIDEO_CAP_SUPPORTED)) {278FREE(config);279return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;280}281282config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE;283break;284285default:286FREE(config);287return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;288}289290config->profile = p;291if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010, p,292config->entrypoint) ||293pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016, p,294config->entrypoint))295supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP;296297for (int i = 0; i <num_attribs ; i++) {298if (attrib_list[i].type != VAConfigAttribRTFormat &&299entrypoint == VAEntrypointVLD ) {300FREE(config);301return VA_STATUS_ERROR_INVALID_VALUE;302}303if (attrib_list[i].type == VAConfigAttribRateControl) {304if (attrib_list[i].value == VA_RC_CBR)305config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT;306else if (attrib_list[i].value == VA_RC_VBR)307config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE;308else if (attrib_list[i].value == VA_RC_CQP)309config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE;310else {311FREE(config);312return VA_STATUS_ERROR_INVALID_VALUE;313}314}315if (attrib_list[i].type == VAConfigAttribRTFormat) {316if (attrib_list[i].value & supported_rt_formats) {317config->rt_format = attrib_list[i].value;318} else {319FREE(config);320return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;321}322}323if (attrib_list[i].type == VAConfigAttribEncPackedHeaders) {324if (attrib_list[i].value > 1 ||325config->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE) {326FREE(config);327return VA_STATUS_ERROR_INVALID_VALUE;328}329}330}331332/* Default value if not specified in the input attributes. */333if (!config->rt_format)334config->rt_format = supported_rt_formats;335336mtx_lock(&drv->mutex);337*config_id = handle_table_add(drv->htab, config);338mtx_unlock(&drv->mutex);339340return VA_STATUS_SUCCESS;341}342343VAStatus344vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id)345{346vlVaDriver *drv;347vlVaConfig *config;348349if (!ctx)350return VA_STATUS_ERROR_INVALID_CONTEXT;351352drv = VL_VA_DRIVER(ctx);353354if (!drv)355return VA_STATUS_ERROR_INVALID_CONTEXT;356357mtx_lock(&drv->mutex);358config = handle_table_get(drv->htab, config_id);359360if (!config) {361mtx_unlock(&drv->mutex);362return VA_STATUS_ERROR_INVALID_CONFIG;363}364365FREE(config);366handle_table_remove(drv->htab, config_id);367mtx_unlock(&drv->mutex);368369return VA_STATUS_SUCCESS;370}371372VAStatus373vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,374VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs)375{376vlVaDriver *drv;377vlVaConfig *config;378379if (!ctx)380return VA_STATUS_ERROR_INVALID_CONTEXT;381382drv = VL_VA_DRIVER(ctx);383384if (!drv)385return VA_STATUS_ERROR_INVALID_CONTEXT;386387mtx_lock(&drv->mutex);388config = handle_table_get(drv->htab, config_id);389mtx_unlock(&drv->mutex);390391if (!config)392return VA_STATUS_ERROR_INVALID_CONFIG;393394*profile = PipeToProfile(config->profile);395396switch (config->entrypoint) {397case PIPE_VIDEO_ENTRYPOINT_BITSTREAM:398*entrypoint = VAEntrypointVLD;399break;400case PIPE_VIDEO_ENTRYPOINT_ENCODE:401*entrypoint = VAEntrypointEncSlice;402break;403case PIPE_VIDEO_ENTRYPOINT_UNKNOWN:404*entrypoint = VAEntrypointVideoProc;405break;406default:407return VA_STATUS_ERROR_INVALID_CONFIG;408}409410*num_attribs = 1;411attrib_list[0].type = VAConfigAttribRTFormat;412attrib_list[0].value = config->rt_format;413414return VA_STATUS_SUCCESS;415}416417418