si_uvd.c revision 7d2f2a0c890b1993532a45c8c392c28950ddc06e
15b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König/************************************************************************** 25b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * 35b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * Copyright 2011 Advanced Micro Devices, Inc. 45b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * All Rights Reserved. 55b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * 65b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * Permission is hereby granted, free of charge, to any person obtaining a 75b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * copy of this software and associated documentation files (the 85b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * "Software"), to deal in the Software without restriction, including 95b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * without limitation the rights to use, copy, modify, merge, publish, 105b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * distribute, sub license, and/or sell copies of the Software, and to 115b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * permit persons to whom the Software is furnished to do so, subject to 125b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * the following conditions: 135b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * 145b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * The above copyright notice and this permission notice (including the 155b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * next paragraph) shall be included in all copies or substantial portions 165b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * of the Software. 175b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * 185b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 195b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 205b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 215b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR 225b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 235b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 245b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 255b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * 265b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König **************************************************************************/ 275b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 285b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König/* 295b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * Authors: 305b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * Christian König <christian.koenig@amd.com> 315b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * 325b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König */ 335b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 345b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include <sys/types.h> 355b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include <assert.h> 365b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include <errno.h> 375b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include <unistd.h> 385b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 395b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "pipe/p_video_decoder.h" 405b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 415b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "util/u_memory.h" 425b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "util/u_video.h" 435b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 445b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "vl/vl_defines.h" 455b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "vl/vl_mpeg12_decoder.h" 465b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 475b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "radeonsi_pipe.h" 485b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "radeon/radeon_uvd.h" 495b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König#include "sid.h" 505b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 515b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König/** 525b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * creates an video buffer with an UVD compatible memory layout 535b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König */ 545b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian Königstruct pipe_video_buffer *radeonsi_video_buffer_create(struct pipe_context *pipe, 555b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König const struct pipe_video_buffer *tmpl) 565b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König{ 575b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct r600_context *ctx = (struct r600_context *)pipe; 585b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct r600_resource_texture *resources[VL_NUM_COMPONENTS] = {}; 595b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct radeon_surface *surfaces[VL_NUM_COMPONENTS] = {}; 605b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct pb_buffer **pbs[VL_NUM_COMPONENTS] = {}; 615b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König const enum pipe_format *resource_formats; 625b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct pipe_video_buffer template; 635b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct pipe_resource templ; 647d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König unsigned i, array_size; 655b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 665b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König assert(pipe); 675b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 685b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König /* first create the needed resources as "normal" textures */ 695b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format); 705b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (!resource_formats) 715b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König return NULL; 725b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 737d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König array_size = tmpl->interlaced ? 2 : 1; 745b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König template = *tmpl; 755b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König template.width = align(tmpl->width, VL_MACROBLOCK_WIDTH); 767d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König template.height = align(tmpl->height / array_size, VL_MACROBLOCK_HEIGHT); 775b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 787d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König vl_vide_buffer_template(&templ, &template, resource_formats[0], array_size, PIPE_USAGE_STATIC, 0); 79c5c754d1844b3a4302842137ab1dbddc9beecb22Christian König /* TODO: Setting the transfer flag is only a workaround till we get tiling working */ 80c5c754d1844b3a4302842137ab1dbddc9beecb22Christian König templ.flags = R600_RESOURCE_FLAG_TRANSFER; 815b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König resources[0] = (struct r600_resource_texture *) 825b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König pipe->screen->resource_create(pipe->screen, &templ); 835b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (!resources[0]) 845b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König goto error; 855b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 865b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (resource_formats[1] != PIPE_FORMAT_NONE) { 877d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König vl_vide_buffer_template(&templ, &template, resource_formats[1], array_size, PIPE_USAGE_STATIC, 1); 88c5c754d1844b3a4302842137ab1dbddc9beecb22Christian König templ.flags = R600_RESOURCE_FLAG_TRANSFER; 895b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König resources[1] = (struct r600_resource_texture *) 905b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König pipe->screen->resource_create(pipe->screen, &templ); 915b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (!resources[1]) 925b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König goto error; 935b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König } 945b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 955b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (resource_formats[2] != PIPE_FORMAT_NONE) { 967d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König vl_vide_buffer_template(&templ, &template, resource_formats[2], array_size, PIPE_USAGE_STATIC, 2); 97c5c754d1844b3a4302842137ab1dbddc9beecb22Christian König templ.flags = R600_RESOURCE_FLAG_TRANSFER; 985b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König resources[2] = (struct r600_resource_texture *) 995b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König pipe->screen->resource_create(pipe->screen, &templ); 1005b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (!resources[2]) 1015b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König goto error; 1025b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König } 1035b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1045b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König for (i = 0; i < VL_NUM_COMPONENTS; ++i) { 1055b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (!resources[i]) 1065b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König continue; 1075b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1085b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König surfaces[i] = & resources[i]->surface; 1095b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König pbs[i] = &resources[i]->resource.buf; 1105b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König } 1115b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1125b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König ruvd_join_surfaces(ctx->ws, templ.bind, pbs, surfaces); 1135b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1145b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König for (i = 0; i < VL_NUM_COMPONENTS; ++i) { 1155b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König if (!resources[i]) 1165b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König continue; 1175b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1185b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König /* recreate the CS handle */ 1195b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König resources[i]->resource.cs_buf = ctx->ws->buffer_get_cs_handle( 1205b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König resources[i]->resource.buf); 1215b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König } 1225b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1237d2f2a0c890b1993532a45c8c392c28950ddc06eChristian König template.height *= array_size; 1245b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König return vl_video_buffer_create_ex2(pipe, &template, (struct pipe_resource **)resources); 1255b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1265b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian Königerror: 1275b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König for (i = 0; i < VL_NUM_COMPONENTS; ++i) 1285b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König pipe_resource_reference((struct pipe_resource **)&resources[i], NULL); 1295b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1305b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König return NULL; 1315b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König} 1325b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1335b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König/* set the decoding target buffer offsets */ 1345b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian Königstatic struct radeon_winsys_cs_handle* radeonsi_uvd_set_dtb(struct ruvd_msg *msg, struct vl_video_buffer *buf) 1355b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König{ 1365b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct r600_resource_texture *luma = (struct r600_resource_texture *)buf->resources[0]; 1375b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct r600_resource_texture *chroma = (struct r600_resource_texture *)buf->resources[1]; 1385b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1392c2c54b819d8e0bd940f56501a2c3699d7cc2397Christian König msg->body.decode.dt_field_mode = buf->base.interlaced; 1405b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1415b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König ruvd_set_dt_surfaces(msg, &luma->surface, &chroma->surface); 1425b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1435b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König return luma->resource.cs_buf; 1445b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König} 1455b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1465b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König/** 1475b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König * creates an UVD compatible decoder 1485b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König */ 1495b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian Königstruct pipe_video_decoder *radeonsi_uvd_create_decoder(struct pipe_context *context, 1505b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König enum pipe_video_profile profile, 1515b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König enum pipe_video_entrypoint entrypoint, 1525b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König enum pipe_video_chroma_format chroma_format, 1535b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König unsigned width, unsigned height, 1545b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König unsigned max_references, bool expect_chunked_decode) 1555b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König{ 1565b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König struct r600_context *ctx = (struct r600_context *)context; 1575b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König 1585b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König return ruvd_create_decoder(context, profile, entrypoint, chroma_format, 1595b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König width, height, max_references, expect_chunked_decode, 1605b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König ctx->ws, radeonsi_uvd_set_dtb); 1615b2855bfe79bfc3995969f2bf775d89b1bc1808aChristian König} 162