radeonsi: cleanup includes, add missing license
[mesa.git] / src / gallium / drivers / radeonsi / si_uvd.c
1 /**************************************************************************
2 *
3 * Copyright 2011 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Christian König <christian.koenig@amd.com>
31 *
32 */
33
34 #include "si_pipe.h"
35 #include "radeon/radeon_uvd.h"
36
37 /**
38 * creates an video buffer with an UVD compatible memory layout
39 */
40 struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
41 const struct pipe_video_buffer *tmpl)
42 {
43 struct si_context *ctx = (struct si_context *)pipe;
44 struct r600_texture *resources[VL_NUM_COMPONENTS] = {};
45 struct radeon_surface *surfaces[VL_NUM_COMPONENTS] = {};
46 struct pb_buffer **pbs[VL_NUM_COMPONENTS] = {};
47 const enum pipe_format *resource_formats;
48 struct pipe_video_buffer template;
49 struct pipe_resource templ;
50 unsigned i, array_size;
51
52 assert(pipe);
53
54 /* first create the needed resources as "normal" textures */
55 resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format);
56 if (!resource_formats)
57 return NULL;
58
59 array_size = tmpl->interlaced ? 2 : 1;
60 template = *tmpl;
61 template.width = align(tmpl->width, VL_MACROBLOCK_WIDTH);
62 template.height = align(tmpl->height / array_size, VL_MACROBLOCK_HEIGHT);
63
64 vl_video_buffer_template(&templ, &template, resource_formats[0], 1, array_size, PIPE_USAGE_STATIC, 0);
65 /* TODO: get tiling working */
66 templ.bind = PIPE_BIND_LINEAR;
67 resources[0] = (struct r600_texture *)
68 pipe->screen->resource_create(pipe->screen, &templ);
69 if (!resources[0])
70 goto error;
71
72 if (resource_formats[1] != PIPE_FORMAT_NONE) {
73 vl_video_buffer_template(&templ, &template, resource_formats[1], 1, array_size, PIPE_USAGE_STATIC, 1);
74 templ.bind = PIPE_BIND_LINEAR;
75 resources[1] = (struct r600_texture *)
76 pipe->screen->resource_create(pipe->screen, &templ);
77 if (!resources[1])
78 goto error;
79 }
80
81 if (resource_formats[2] != PIPE_FORMAT_NONE) {
82 vl_video_buffer_template(&templ, &template, resource_formats[2], 1, array_size, PIPE_USAGE_STATIC, 2);
83 templ.bind = PIPE_BIND_LINEAR;
84 resources[2] = (struct r600_texture *)
85 pipe->screen->resource_create(pipe->screen, &templ);
86 if (!resources[2])
87 goto error;
88 }
89
90 for (i = 0; i < VL_NUM_COMPONENTS; ++i) {
91 if (!resources[i])
92 continue;
93
94 surfaces[i] = & resources[i]->surface;
95 pbs[i] = &resources[i]->resource.buf;
96 }
97
98 ruvd_join_surfaces(ctx->b.ws, templ.bind, pbs, surfaces);
99
100 for (i = 0; i < VL_NUM_COMPONENTS; ++i) {
101 if (!resources[i])
102 continue;
103
104 /* recreate the CS handle */
105 resources[i]->resource.cs_buf = ctx->b.ws->buffer_get_cs_handle(
106 resources[i]->resource.buf);
107 }
108
109 template.height *= array_size;
110 return vl_video_buffer_create_ex2(pipe, &template, (struct pipe_resource **)resources);
111
112 error:
113 for (i = 0; i < VL_NUM_COMPONENTS; ++i)
114 pipe_resource_reference((struct pipe_resource **)&resources[i], NULL);
115
116 return NULL;
117 }
118
119 /* set the decoding target buffer offsets */
120 static struct radeon_winsys_cs_handle* si_uvd_set_dtb(struct ruvd_msg *msg, struct vl_video_buffer *buf)
121 {
122 struct r600_texture *luma = (struct r600_texture *)buf->resources[0];
123 struct r600_texture *chroma = (struct r600_texture *)buf->resources[1];
124
125 msg->body.decode.dt_field_mode = buf->base.interlaced;
126
127 ruvd_set_dt_surfaces(msg, &luma->surface, &chroma->surface);
128
129 return luma->resource.cs_buf;
130 }
131
132 /**
133 * creates an UVD compatible decoder
134 */
135 struct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
136 const struct pipe_video_codec *templ)
137 {
138 return ruvd_create_decoder(context, templ, si_uvd_set_dtb);
139 }