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_codec.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"
48 #include "radeon/radeon_uvd.h"
52 * creates an video buffer with an UVD compatible memory layout
54 struct pipe_video_buffer
*si_video_buffer_create(struct pipe_context
*pipe
,
55 const struct pipe_video_buffer
*tmpl
)
57 struct si_context
*ctx
= (struct si_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], 1, array_size
, PIPE_USAGE_STATIC
, 0);
79 /* TODO: get tiling working */
80 templ
.bind
= PIPE_BIND_LINEAR
;
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], 1, array_size
, PIPE_USAGE_STATIC
, 1);
88 templ
.bind
= PIPE_BIND_LINEAR
;
89 resources
[1] = (struct r600_texture
*)
90 pipe
->screen
->resource_create(pipe
->screen
, &templ
);
95 if (resource_formats
[2] != PIPE_FORMAT_NONE
) {
96 vl_video_buffer_template(&templ
, &template, resource_formats
[2], 1, array_size
, PIPE_USAGE_STATIC
, 2);
97 templ
.bind
= PIPE_BIND_LINEAR
;
98 resources
[2] = (struct r600_texture
*)
99 pipe
->screen
->resource_create(pipe
->screen
, &templ
);
104 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
108 surfaces
[i
] = & resources
[i
]->surface
;
109 pbs
[i
] = &resources
[i
]->resource
.buf
;
112 ruvd_join_surfaces(ctx
->b
.ws
, templ
.bind
, pbs
, surfaces
);
114 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
118 /* recreate the CS handle */
119 resources
[i
]->resource
.cs_buf
= ctx
->b
.ws
->buffer_get_cs_handle(
120 resources
[i
]->resource
.buf
);
123 template.height
*= array_size
;
124 return vl_video_buffer_create_ex2(pipe
, &template, (struct pipe_resource
**)resources
);
127 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
)
128 pipe_resource_reference((struct pipe_resource
**)&resources
[i
], NULL
);
133 /* set the decoding target buffer offsets */
134 static struct radeon_winsys_cs_handle
* si_uvd_set_dtb(struct ruvd_msg
*msg
, struct vl_video_buffer
*buf
)
136 struct r600_texture
*luma
= (struct r600_texture
*)buf
->resources
[0];
137 struct r600_texture
*chroma
= (struct r600_texture
*)buf
->resources
[1];
139 msg
->body
.decode
.dt_field_mode
= buf
->base
.interlaced
;
141 ruvd_set_dt_surfaces(msg
, &luma
->surface
, &chroma
->surface
);
143 return luma
->resource
.cs_buf
;
147 * creates an UVD compatible decoder
149 struct pipe_video_codec
*si_uvd_create_decoder(struct pipe_context
*context
,
150 const struct pipe_video_codec
*templ
)
152 return ruvd_create_decoder(context
, templ
, si_uvd_set_dtb
);