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"
46 /* generate an stream handle */
47 unsigned rvid_alloc_stream_handle()
49 static unsigned counter
= 0;
50 unsigned stream_handle
= 0;
51 unsigned pid
= getpid();
54 for (i
= 0; i
< 32; ++i
)
55 stream_handle
|= ((pid
>> i
) & 1) << (31 - i
);
57 stream_handle
^= ++counter
;
61 /* create a buffer in the winsys */
62 bool rvid_create_buffer(struct radeon_winsys
*ws
, struct rvid_buffer
*buffer
,
63 unsigned size
, enum radeon_bo_domain domain
)
65 buffer
->domain
= domain
;
67 buffer
->buf
= ws
->buffer_create(ws
, size
, 4096, false, domain
);
71 buffer
->cs_handle
= ws
->buffer_get_cs_handle(buffer
->buf
);
72 if (!buffer
->cs_handle
)
78 /* destroy a buffer */
79 void rvid_destroy_buffer(struct rvid_buffer
*buffer
)
81 pb_reference(&buffer
->buf
, NULL
);
82 buffer
->cs_handle
= NULL
;
85 /* reallocate a buffer, preserving its content */
86 bool rvid_resize_buffer(struct radeon_winsys
*ws
, struct radeon_winsys_cs
*cs
,
87 struct rvid_buffer
*new_buf
, unsigned new_size
)
89 unsigned bytes
= MIN2(new_buf
->buf
->size
, new_size
);
90 struct rvid_buffer old_buf
= *new_buf
;
91 void *src
= NULL
, *dst
= NULL
;
93 if (!rvid_create_buffer(ws
, new_buf
, new_size
, new_buf
->domain
))
96 src
= ws
->buffer_map(old_buf
.cs_handle
, cs
, PIPE_TRANSFER_READ
);
100 dst
= ws
->buffer_map(new_buf
->cs_handle
, cs
, PIPE_TRANSFER_WRITE
);
104 memcpy(dst
, src
, bytes
);
105 if (new_size
> bytes
) {
108 memset(dst
, 0, new_size
);
110 ws
->buffer_unmap(new_buf
->cs_handle
);
111 ws
->buffer_unmap(old_buf
.cs_handle
);
112 rvid_destroy_buffer(&old_buf
);
117 ws
->buffer_unmap(old_buf
.cs_handle
);
118 rvid_destroy_buffer(new_buf
);
123 /* clear the buffer with zeros */
124 void rvid_clear_buffer(struct radeon_winsys
*ws
, struct radeon_winsys_cs
*cs
, struct rvid_buffer
* buffer
)
126 void *ptr
= ws
->buffer_map(buffer
->cs_handle
, cs
, PIPE_TRANSFER_WRITE
);
130 memset(ptr
, 0, buffer
->buf
->size
);
131 ws
->buffer_unmap(buffer
->cs_handle
);
135 * join surfaces into the same buffer with identical tiling params
136 * sumup their sizes and replace the backend buffers with a single bo
138 void rvid_join_surfaces(struct radeon_winsys
* ws
, unsigned bind
,
139 struct pb_buffer
** buffers
[VL_NUM_COMPONENTS
],
140 struct radeon_surface
*surfaces
[VL_NUM_COMPONENTS
])
142 unsigned best_tiling
, best_wh
, off
;
143 unsigned size
, alignment
;
144 struct pb_buffer
*pb
;
147 for (i
= 0, best_tiling
= 0, best_wh
= ~0; i
< VL_NUM_COMPONENTS
; ++i
) {
153 /* choose the smallest bank w/h for now */
154 wh
= surfaces
[i
]->bankw
* surfaces
[i
]->bankh
;
161 for (i
= 0, off
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
165 /* copy the tiling parameters */
166 surfaces
[i
]->bankw
= surfaces
[best_tiling
]->bankw
;
167 surfaces
[i
]->bankh
= surfaces
[best_tiling
]->bankh
;
168 surfaces
[i
]->mtilea
= surfaces
[best_tiling
]->mtilea
;
169 surfaces
[i
]->tile_split
= surfaces
[best_tiling
]->tile_split
;
171 /* adjust the texture layer offsets */
172 off
= align(off
, surfaces
[i
]->bo_alignment
);
173 for (j
= 0; j
< Elements(surfaces
[i
]->level
); ++j
)
174 surfaces
[i
]->level
[j
].offset
+= off
;
175 off
+= surfaces
[i
]->bo_size
;
178 for (i
= 0, size
= 0, alignment
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
179 if (!buffers
[i
] || !*buffers
[i
])
182 size
= align(size
, (*buffers
[i
])->alignment
);
183 size
+= (*buffers
[i
])->size
;
184 alignment
= MAX2(alignment
, (*buffers
[i
])->alignment
* 1);
190 /* TODO: 2D tiling workaround */
193 pb
= ws
->buffer_create(ws
, size
, alignment
, bind
, RADEON_DOMAIN_VRAM
);
197 for (i
= 0; i
< VL_NUM_COMPONENTS
; ++i
) {
198 if (!buffers
[i
] || !*buffers
[i
])
201 pb_reference(buffers
[i
], pb
);
204 pb_reference(&pb
, NULL
);
207 int rvid_get_video_param(struct pipe_screen
*screen
,
208 enum pipe_video_profile profile
,
209 enum pipe_video_entrypoint entrypoint
,
210 enum pipe_video_cap param
)
212 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
215 if (rscreen
->family
< CHIP_PALM
) {
216 enum pipe_video_format codec
= u_reduce_video_profile(profile
);
218 case PIPE_VIDEO_CAP_SUPPORTED
:
219 /* no support for MPEG4 */
220 return codec
!= PIPE_VIDEO_FORMAT_MPEG4
;
221 case PIPE_VIDEO_CAP_PREFERS_INTERLACED
:
222 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
:
223 /* and MPEG2 only with shaders */
224 return codec
!= PIPE_VIDEO_FORMAT_MPEG12
;
231 case PIPE_VIDEO_CAP_SUPPORTED
:
232 switch (u_reduce_video_profile(profile
)) {
233 case PIPE_VIDEO_FORMAT_MPEG12
:
234 case PIPE_VIDEO_FORMAT_MPEG4
:
235 case PIPE_VIDEO_FORMAT_MPEG4_AVC
:
236 return entrypoint
!= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
237 case PIPE_VIDEO_FORMAT_VC1
:
238 /* FIXME: VC-1 simple/main profile is broken */
239 return profile
== PIPE_VIDEO_PROFILE_VC1_ADVANCED
&&
240 entrypoint
!= PIPE_VIDEO_ENTRYPOINT_ENCODE
;
244 case PIPE_VIDEO_CAP_NPOT_TEXTURES
:
246 case PIPE_VIDEO_CAP_MAX_WIDTH
:
248 case PIPE_VIDEO_CAP_MAX_HEIGHT
:
250 case PIPE_VIDEO_CAP_PREFERED_FORMAT
:
251 return PIPE_FORMAT_NV12
;
252 case PIPE_VIDEO_CAP_PREFERS_INTERLACED
:
254 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED
:
256 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE
:
258 case PIPE_VIDEO_CAP_MAX_LEVEL
:
260 case PIPE_VIDEO_PROFILE_MPEG1
:
262 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
263 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
265 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
267 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
269 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
271 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
273 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
275 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
276 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
277 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
287 boolean
rvid_is_format_supported(struct pipe_screen
*screen
,
288 enum pipe_format format
,
289 enum pipe_video_profile profile
,
290 enum pipe_video_entrypoint entrypoint
)
292 /* we can only handle this one with UVD */
293 if (profile
!= PIPE_VIDEO_PROFILE_UNKNOWN
)
294 return format
== PIPE_FORMAT_NV12
;
296 return vl_video_buffer_is_format_supported(screen
, format
, profile
, entrypoint
);