1 /**************************************************************************
3 * Copyright 2011 Advanced Micro Devices, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Christian König <christian.koenig@amd.com>
34 #include <sys/types.h>
39 #include "pipe/p_video_decoder.h"
41 #include "util/u_memory.h"
42 #include "util/u_video.h"
44 #include "vl/vl_defines.h"
45 #include "vl/vl_mpeg12_decoder.h"
47 #include "r600_pipe.h"
48 #include "radeon/radeon_uvd.h"
52 * creates an video buffer with an UVD compatible memory layout
54 struct pipe_video_buffer
*r600_video_buffer_create(struct pipe_context
*pipe
,
55 const struct pipe_video_buffer
*tmpl
)
57 struct r600_context
*ctx
= (struct r600_context
*)pipe
;
58 struct r600_texture
*resources
[VL_NUM_COMPONENTS
] = {};
59 struct radeon_surface
* surfaces
[VL_NUM_COMPONENTS
] = {};
60 struct pb_buffer
**pbs
[VL_NUM_COMPONENTS
] = {};
61 const enum pipe_format
*resource_formats
;
62 struct pipe_video_buffer
template;
63 struct pipe_resource templ
;
64 unsigned i
, array_size
;
68 /* first create the needed resources as "normal" textures */
69 resource_formats
= vl_video_buffer_formats(pipe
->screen
, tmpl
->buffer_format
);
70 if (!resource_formats
)
73 array_size
= tmpl
->interlaced
? 2 : 1;
75 template.width
= align(tmpl
->width
, VL_MACROBLOCK_WIDTH
);
76 template.height
= align(tmpl
->height
/ array_size
, VL_MACROBLOCK_HEIGHT
);
78 vl_video_buffer_template(&templ
, &template, resource_formats
[0], array_size
, PIPE_USAGE_STATIC
, 0);
79 if (ctx
->chip_class
< EVERGREEN
)
80 templ
.flags
= R600_RESOURCE_FLAG_TRANSFER
;
81 resources
[0] = (struct r600_texture
*)
82 pipe
->screen
->resource_create(pipe
->screen
, &templ
);
86 if (resource_formats
[1] != PIPE_FORMAT_NONE
) {
87 vl_video_buffer_template(&templ
, &template, resource_formats
[1], array_size
, PIPE_USAGE_STATIC
, 1);
88 if (ctx
->chip_class
< EVERGREEN
)
89 templ
.flags
= R600_RESOURCE_FLAG_TRANSFER
;
90 resources
[1] = (struct r600_texture
*)
91 pipe
->screen
->resource_create(pipe
->screen
, &templ
);
96 if (resource_formats
[2] != PIPE_FORMAT_NONE
) {
97 vl_video_buffer_template(&templ
, &template, resource_formats
[2], array_size
, PIPE_USAGE_STATIC
, 2);
98 if (ctx
->chip_class
< EVERGREEN
)
99 templ
.flags
= R600_RESOURCE_FLAG_TRANSFER
;
100 resources
[2] = (struct r600_texture
*)
101 pipe
->screen
->resource_create(pipe
->screen
, &templ
);
106 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
110 pbs
[i
] = &resources
[i
]->resource
.buf
;
111 surfaces
[i
] = &resources
[i
]->surface
;
114 ruvd_join_surfaces(ctx
->ws
, templ
.bind
, pbs
, surfaces
);
116 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
120 /* recreate the CS handle */
121 resources
[i
]->resource
.cs_buf
= ctx
->ws
->buffer_get_cs_handle(
122 resources
[i
]->resource
.buf
);
125 template.height
*= array_size
;
126 return vl_video_buffer_create_ex2(pipe
, &template, (struct pipe_resource
**)resources
);
129 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
)
130 pipe_resource_reference((struct pipe_resource
**)&resources
[i
], NULL
);
135 /* hw encode the number of memory banks */
136 static uint32_t eg_num_banks(uint32_t nbanks
)
151 /* set the decoding target buffer offsets */
152 static struct radeon_winsys_cs_handle
* r600_uvd_set_dtb(struct ruvd_msg
*msg
, struct vl_video_buffer
*buf
)
154 struct r600_screen
*rscreen
= (struct r600_screen
*)buf
->base
.context
->screen
;
155 struct r600_texture
*luma
= (struct r600_texture
*)buf
->resources
[0];
156 struct r600_texture
*chroma
= (struct r600_texture
*)buf
->resources
[1];
158 msg
->body
.decode
.dt_field_mode
= buf
->base
.interlaced
;
159 msg
->body
.decode
.dt_surf_tile_config
|= RUVD_NUM_BANKS(eg_num_banks(rscreen
->tiling_info
.num_banks
));
161 ruvd_set_dt_surfaces(msg
, &luma
->surface
, &chroma
->surface
);
163 return luma
->resource
.cs_buf
;
167 struct pipe_video_decoder
*r600_uvd_create_decoder(struct pipe_context
*context
,
168 enum pipe_video_profile profile
,
169 enum pipe_video_entrypoint entrypoint
,
170 enum pipe_video_chroma_format chroma_format
,
171 unsigned width
, unsigned height
,
172 unsigned max_references
, bool expect_chunked_decode
)
174 struct r600_context
*ctx
= (struct r600_context
*)context
;
176 return ruvd_create_decoder(context
, profile
, entrypoint
, chroma_format
,
177 width
, height
, max_references
, expect_chunked_decode
,
178 ctx
->ws
, r600_uvd_set_dtb
);
181 int r600_uvd_get_video_param(struct pipe_screen
*screen
,
182 enum pipe_video_profile profile
,
183 enum pipe_video_cap param
)
185 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
187 /* No support for MPEG4 on UVD 2.x */
188 if (param
== PIPE_VIDEO_CAP_SUPPORTED
&& rscreen
->family
< CHIP_CEDAR
&&
189 u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG4
)
192 return ruvd_get_video_param(screen
, profile
, param
);