1 /**************************************************************************
3 * Copyright 2013 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>
36 #include "util/u_memory.h"
37 #include "util/u_video.h"
39 #include "vl/vl_defines.h"
40 #include "vl/vl_video_buffer.h"
42 #include "../../winsys/radeon/drm/radeon_winsys.h"
43 #include "r600_pipe_common.h"
44 #include "radeon_video.h"
45 #include "radeon_vce.h"
47 /* generate an stream handle */
48 unsigned rvid_alloc_stream_handle()
50 static unsigned counter
= 0;
51 unsigned stream_handle
= 0;
52 unsigned pid
= getpid();
55 for (i
= 0; i
< 32; ++i
)
56 stream_handle
|= ((pid
>> i
) & 1) << (31 - i
);
58 stream_handle
^= ++counter
;
62 /* create a buffer in the winsys */
63 bool rvid_create_buffer(struct radeon_winsys
*ws
, struct rvid_buffer
*buffer
,
64 unsigned size
, enum radeon_bo_domain domain
)
66 buffer
->domain
= domain
;
68 buffer
->buf
= ws
->buffer_create(ws
, size
, 4096, false, domain
);
72 buffer
->cs_handle
= ws
->buffer_get_cs_handle(buffer
->buf
);
73 if (!buffer
->cs_handle
)
79 /* destroy a buffer */
80 void rvid_destroy_buffer(struct rvid_buffer
*buffer
)
82 pb_reference(&buffer
->buf
, NULL
);
83 buffer
->cs_handle
= NULL
;
86 /* reallocate a buffer, preserving its content */
87 bool rvid_resize_buffer(struct radeon_winsys
*ws
, struct radeon_winsys_cs
*cs
,
88 struct rvid_buffer
*new_buf
, unsigned new_size
)
90 unsigned bytes
= MIN2(new_buf
->buf
->size
, new_size
);
91 struct rvid_buffer old_buf
= *new_buf
;
92 void *src
= NULL
, *dst
= NULL
;
94 if (!rvid_create_buffer(ws
, new_buf
, new_size
, new_buf
->domain
))
97 src
= ws
->buffer_map(old_buf
.cs_handle
, cs
, PIPE_TRANSFER_READ
);
101 dst
= ws
->buffer_map(new_buf
->cs_handle
, cs
, PIPE_TRANSFER_WRITE
);
105 memcpy(dst
, src
, bytes
);
106 if (new_size
> bytes
) {
109 memset(dst
, 0, new_size
);
111 ws
->buffer_unmap(new_buf
->cs_handle
);
112 ws
->buffer_unmap(old_buf
.cs_handle
);
113 rvid_destroy_buffer(&old_buf
);
118 ws
->buffer_unmap(old_buf
.cs_handle
);
119 rvid_destroy_buffer(new_buf
);
124 /* clear the buffer with zeros */
125 void rvid_clear_buffer(struct radeon_winsys
*ws
, struct radeon_winsys_cs
*cs
, struct rvid_buffer
* buffer
)
127 void *ptr
= ws
->buffer_map(buffer
->cs_handle
, cs
, PIPE_TRANSFER_WRITE
);
131 memset(ptr
, 0, buffer
->buf
->size
);
132 ws
->buffer_unmap(buffer
->cs_handle
);
136 * join surfaces into the same buffer with identical tiling params
137 * sumup their sizes and replace the backend buffers with a single bo
139 void rvid_join_surfaces(struct radeon_winsys
* ws
, unsigned bind
,
140 struct pb_buffer
** buffers
[VL_NUM_COMPONENTS
],
141 struct radeon_surface
*surfaces
[VL_NUM_COMPONENTS
])
143 unsigned best_tiling
, best_wh
, off
;
144 unsigned size
, alignment
;
145 struct pb_buffer
*pb
;
148 for (i
= 0, best_tiling
= 0, best_wh
= ~0; i
< VL_NUM_COMPONENTS
; ++i
) {
154 /* choose the smallest bank w/h for now */
155 wh
= surfaces
[i
]->bankw
* surfaces
[i
]->bankh
;
162 for (i
= 0, off
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
166 /* copy the tiling parameters */
167 surfaces
[i
]->bankw
= surfaces
[best_tiling
]->bankw
;
168 surfaces
[i
]->bankh
= surfaces
[best_tiling
]->bankh
;
169 surfaces
[i
]->mtilea
= surfaces
[best_tiling
]->mtilea
;
170 surfaces
[i
]->tile_split
= surfaces
[best_tiling
]->tile_split
;
172 /* adjust the texture layer offsets */
173 off
= align(off
, surfaces
[i
]->bo_alignment
);
174 for (j
= 0; j
< Elements(surfaces
[i
]->level
); ++j
)
175 surfaces
[i
]->level
[j
].offset
+= off
;
176 off
+= surfaces
[i
]->bo_size
;
179 for (i
= 0, size
= 0, alignment
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
180 if (!buffers
[i
] || !*buffers
[i
])
183 size
= align(size
, (*buffers
[i
])->alignment
);
184 size
+= (*buffers
[i
])->size
;
185 alignment
= MAX2(alignment
, (*buffers
[i
])->alignment
* 1);
191 /* TODO: 2D tiling workaround */
194 pb
= ws
->buffer_create(ws
, size
, alignment
, bind
, RADEON_DOMAIN_VRAM
);
198 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
199 if (!buffers
[i
] || !*buffers
[i
])
202 pb_reference(buffers
[i
], pb
);
205 pb_reference(&pb
, NULL
);
208 int rvid_get_video_param(struct pipe_screen
*screen
,
209 enum pipe_video_profile profile
,
210 enum pipe_video_entrypoint entrypoint
,
211 enum pipe_video_cap param
)
213 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
215 if (entrypoint
== PIPE_VIDEO_ENTRYPOINT_ENCODE
) {
217 case PIPE_VIDEO_CAP_SUPPORTED
:
218 return u_reduce_video_profile(profile
) == PIPE_VIDEO_FORMAT_MPEG4_AVC
&&
219 rvce_is_fw_version_supported(rscreen
);
220 case PIPE_VIDEO_CAP_NPOT_TEXTURES
:
222 case PIPE_VIDEO_CAP_MAX_WIDTH
:
224 case PIPE_VIDEO_CAP_MAX_HEIGHT
:
226 case PIPE_VIDEO_CAP_PREFERED_FORMAT
:
227 return PIPE_FORMAT_NV12
;
228 case PIPE_VIDEO_CAP_PREFERS_INTERLACED
:
230 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
:
232 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE
:
240 if (rscreen
->family
< CHIP_PALM
) {
241 enum pipe_video_format codec
= u_reduce_video_profile(profile
);
243 case PIPE_VIDEO_CAP_SUPPORTED
:
244 /* no support for MPEG4 */
245 return codec
!= PIPE_VIDEO_FORMAT_MPEG4
&&
246 /* FIXME: VC-1 simple/main profile is broken */
247 profile
!= PIPE_VIDEO_PROFILE_VC1_SIMPLE
&&
248 profile
!= PIPE_VIDEO_PROFILE_VC1_MAIN
;
249 case PIPE_VIDEO_CAP_PREFERS_INTERLACED
:
250 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
:
251 /* and MPEG2 only with shaders */
252 return codec
!= PIPE_VIDEO_FORMAT_MPEG12
;
259 case PIPE_VIDEO_CAP_SUPPORTED
:
260 switch (u_reduce_video_profile(profile
)) {
261 case PIPE_VIDEO_FORMAT_MPEG12
:
262 case PIPE_VIDEO_FORMAT_MPEG4
:
263 case PIPE_VIDEO_FORMAT_MPEG4_AVC
:
264 return entrypoint
!= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
265 case PIPE_VIDEO_FORMAT_VC1
:
266 /* FIXME: VC-1 simple/main profile is broken */
267 return profile
== PIPE_VIDEO_PROFILE_VC1_ADVANCED
&&
268 entrypoint
!= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
272 case PIPE_VIDEO_CAP_NPOT_TEXTURES
:
274 case PIPE_VIDEO_CAP_MAX_WIDTH
:
276 case PIPE_VIDEO_CAP_MAX_HEIGHT
:
278 case PIPE_VIDEO_CAP_PREFERED_FORMAT
:
279 return PIPE_FORMAT_NV12
;
280 case PIPE_VIDEO_CAP_PREFERS_INTERLACED
:
282 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
:
284 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE
:
286 case PIPE_VIDEO_CAP_MAX_LEVEL
:
288 case PIPE_VIDEO_PROFILE_MPEG1
:
290 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
291 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
293 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
295 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
297 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
299 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
301 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
303 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
304 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
305 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
315 boolean
rvid_is_format_supported(struct pipe_screen
*screen
,
316 enum pipe_format format
,
317 enum pipe_video_profile profile
,
318 enum pipe_video_entrypoint entrypoint
)
320 /* we can only handle this one with UVD */
321 if (profile
!= PIPE_VIDEO_PROFILE_UNKNOWN
)
322 return format
== PIPE_FORMAT_NV12
;
324 return vl_video_buffer_is_format_supported(screen
, format
, profile
, entrypoint
);