1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 **************************************************************************/
31 #include <util/u_memory.h>
32 #include <util/u_rect.h>
33 #include <util/u_video.h>
35 #include "vl_mpeg12_decoder.h"
36 #include "vl_defines.h"
38 #define SCALE_FACTOR_SNORM (32768.0f / 256.0f)
39 #define SCALE_FACTOR_SSCALED (1.0f / 256.0f)
41 static const unsigned const_empty_block_mask_420
[3][2][2] = {
42 { { 0x20, 0x10 }, { 0x08, 0x04 } },
43 { { 0x02, 0x02 }, { 0x02, 0x02 } },
44 { { 0x01, 0x01 }, { 0x01, 0x01 } }
47 static const enum pipe_format const_idct_source_formats
[] = {
48 PIPE_FORMAT_R16G16B16A16_SNORM
,
49 PIPE_FORMAT_R16G16B16A16_SSCALED
52 static const unsigned num_idct_source_formats
=
53 sizeof(const_idct_source_formats
) / sizeof(enum pipe_format
);
55 static const enum pipe_format const_idct_intermediate_formats
[] = {
56 PIPE_FORMAT_R16G16B16A16_FLOAT
,
57 PIPE_FORMAT_R16G16B16A16_SNORM
,
58 PIPE_FORMAT_R16G16B16A16_SSCALED
,
59 PIPE_FORMAT_R32G32B32A32_FLOAT
62 static const unsigned num_idct_intermediate_formats
=
63 sizeof(const_idct_intermediate_formats
) / sizeof(enum pipe_format
);
65 static const enum pipe_format const_mc_source_formats
[] = {
66 PIPE_FORMAT_R16_SNORM
,
67 PIPE_FORMAT_R16_SSCALED
70 static const unsigned num_mc_source_formats
=
71 sizeof(const_mc_source_formats
) / sizeof(enum pipe_format
);
74 map_buffers(struct vl_mpeg12_decoder
*ctx
, struct vl_mpeg12_buffer
*buffer
)
76 struct pipe_sampler_view
**sampler_views
;
77 struct pipe_resource
*tex
;
80 assert(ctx
&& buffer
);
82 if (ctx
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
83 sampler_views
= buffer
->idct_source
->get_sampler_views(buffer
->idct_source
);
85 sampler_views
= buffer
->mc_source
->get_sampler_views(buffer
->mc_source
);
86 assert(sampler_views
);
88 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
89 tex
= sampler_views
[i
]->texture
;
91 struct pipe_box rect
=
99 buffer
->tex_transfer
[i
] = ctx
->pipe
->get_transfer
102 0, PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_DISCARD
,
106 buffer
->texels
[i
] = ctx
->pipe
->transfer_map(ctx
->pipe
, buffer
->tex_transfer
[i
]);
111 upload_block(struct vl_mpeg12_buffer
*buffer
, unsigned plane
, unsigned x
, unsigned y
, short *block
)
121 tex_pitch
= buffer
->tex_transfer
[plane
]->stride
/ sizeof(short);
122 texels
= buffer
->texels
[plane
] + y
* tex_pitch
* BLOCK_HEIGHT
+ x
* BLOCK_WIDTH
;
124 for (i
= 0; i
< BLOCK_HEIGHT
; ++i
)
125 memcpy(texels
+ i
* tex_pitch
, block
+ i
* BLOCK_WIDTH
, BLOCK_WIDTH
* sizeof(short));
129 upload_buffer(struct vl_mpeg12_decoder
*ctx
,
130 struct vl_mpeg12_buffer
*buffer
,
131 struct pipe_mpeg12_macroblock
*mb
)
142 for (y
= 0; y
< 2; ++y
) {
143 for (x
= 0; x
< 2; ++x
, ++tb
) {
144 if (mb
->cbp
& (*ctx
->empty_block_mask
)[0][y
][x
]) {
145 upload_block(buffer
, 0, mb
->mbx
* 2 + x
, mb
->mby
* 2 + y
, blocks
);
146 blocks
+= BLOCK_WIDTH
* BLOCK_HEIGHT
;
151 /* TODO: Implement 422, 444 */
152 assert(ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
154 for (tb
= 1; tb
< 3; ++tb
) {
155 if (mb
->cbp
& (*ctx
->empty_block_mask
)[tb
][0][0]) {
156 upload_block(buffer
, tb
, mb
->mbx
, mb
->mby
, blocks
);
157 blocks
+= BLOCK_WIDTH
* BLOCK_HEIGHT
;
163 unmap_buffers(struct vl_mpeg12_decoder
*ctx
, struct vl_mpeg12_buffer
*buffer
)
167 assert(ctx
&& buffer
);
169 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
170 ctx
->pipe
->transfer_unmap(ctx
->pipe
, buffer
->tex_transfer
[i
]);
171 ctx
->pipe
->transfer_destroy(ctx
->pipe
, buffer
->tex_transfer
[i
]);
176 cleanup_idct_buffer(struct vl_mpeg12_buffer
*buf
)
178 struct vl_mpeg12_decoder
*dec
;
181 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
184 buf
->idct_source
->destroy(buf
->idct_source
);
185 buf
->idct_intermediate
->destroy(buf
->idct_intermediate
);
186 vl_idct_cleanup_buffer(&dec
->idct_y
, &buf
->idct
[0]);
187 vl_idct_cleanup_buffer(&dec
->idct_c
, &buf
->idct
[1]);
188 vl_idct_cleanup_buffer(&dec
->idct_c
, &buf
->idct
[2]);
192 vl_mpeg12_buffer_destroy(struct pipe_video_decode_buffer
*buffer
)
194 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
195 struct vl_mpeg12_decoder
*dec
;
200 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
203 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
204 cleanup_idct_buffer(buf
);
206 buf
->mc_source
->destroy(buf
->mc_source
);
207 vl_vb_cleanup(&buf
->vertex_stream
);
208 for (i
= 0; i
< VL_MAX_PLANES
; ++i
)
209 vl_mc_cleanup_buffer(&buf
->mc
[i
]);
215 vl_mpeg12_buffer_map(struct pipe_video_decode_buffer
*buffer
)
217 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
218 struct vl_mpeg12_decoder
*dec
;
221 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
224 vl_vb_map(&buf
->vertex_stream
, dec
->pipe
);
225 map_buffers(dec
, buf
);
229 vl_mpeg12_buffer_add_macroblocks(struct pipe_video_decode_buffer
*buffer
,
230 unsigned num_macroblocks
,
231 struct pipe_macroblock
*macroblocks
)
233 struct pipe_mpeg12_macroblock
*mb
= (struct pipe_mpeg12_macroblock
*)macroblocks
;
234 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
235 struct vl_mpeg12_decoder
*dec
;
240 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
243 assert(num_macroblocks
);
245 assert(macroblocks
->codec
== PIPE_VIDEO_CODEC_MPEG12
);
247 for ( i
= 0; i
< num_macroblocks
; ++i
) {
248 vl_vb_add_block(&buf
->vertex_stream
, &mb
[i
], dec
->empty_block_mask
);
249 upload_buffer(dec
, buf
, &mb
[i
]);
254 vl_mpeg12_buffer_unmap(struct pipe_video_decode_buffer
*buffer
)
256 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
257 struct vl_mpeg12_decoder
*dec
;
260 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
263 vl_vb_unmap(&buf
->vertex_stream
, dec
->pipe
);
264 unmap_buffers(dec
, buf
);
268 vl_mpeg12_destroy(struct pipe_video_decoder
*decoder
)
270 struct vl_mpeg12_decoder
*dec
= (struct vl_mpeg12_decoder
*)decoder
;
275 /* Asserted in softpipe_delete_fs_state() for some reason */
276 dec
->pipe
->bind_vs_state(dec
->pipe
, NULL
);
277 dec
->pipe
->bind_fs_state(dec
->pipe
, NULL
);
279 dec
->pipe
->delete_depth_stencil_alpha_state(dec
->pipe
, dec
->dsa
);
281 vl_mc_cleanup(&dec
->mc_y
);
282 vl_mc_cleanup(&dec
->mc_c
);
284 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
) {
285 vl_idct_cleanup(&dec
->idct_y
);
286 vl_idct_cleanup(&dec
->idct_c
);
289 for (i
= 0; i
< VL_MAX_PLANES
; ++i
)
290 dec
->pipe
->delete_vertex_elements_state(dec
->pipe
, dec
->ves_eb
[i
]);
292 dec
->pipe
->delete_vertex_elements_state(dec
->pipe
, dec
->ves_mv
);
294 pipe_resource_reference(&dec
->quads
.buffer
, NULL
);
295 pipe_resource_reference(&dec
->pos
.buffer
, NULL
);
301 init_idct_buffer(struct vl_mpeg12_buffer
*buffer
)
303 enum pipe_format formats
[3];
305 struct pipe_sampler_view
**idct_source_sv
, **idct_intermediate_sv
;
306 struct pipe_surface
**idct_surfaces
;
308 struct vl_mpeg12_decoder
*dec
;
314 dec
= (struct vl_mpeg12_decoder
*)buffer
->base
.decoder
;
316 formats
[0] = formats
[1] = formats
[2] = dec
->idct_source_format
;
317 buffer
->idct_source
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
318 dec
->base
.width
/ 4, dec
->base
.height
, 1,
319 dec
->base
.chroma_format
,
320 formats
, PIPE_USAGE_STREAM
);
321 if (!buffer
->idct_source
)
324 formats
[0] = formats
[1] = formats
[2] = dec
->idct_intermediate_format
;
325 buffer
->idct_intermediate
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
326 dec
->base
.width
/ dec
->nr_of_idct_render_targets
,
327 dec
->base
.height
/ 4, dec
->nr_of_idct_render_targets
,
328 dec
->base
.chroma_format
,
329 formats
, PIPE_USAGE_STATIC
);
331 if (!buffer
->idct_intermediate
)
332 goto error_intermediate
;
334 idct_source_sv
= buffer
->idct_source
->get_sampler_views(buffer
->idct_source
);
336 goto error_source_sv
;
338 idct_intermediate_sv
= buffer
->idct_intermediate
->get_sampler_views(buffer
->idct_intermediate
);
339 if (!idct_intermediate_sv
)
340 goto error_intermediate_sv
;
342 idct_surfaces
= buffer
->mc_source
->get_surfaces(buffer
->mc_source
);
346 for (i
= 0; i
< 3; ++i
)
347 if (!vl_idct_init_buffer(i
== 0 ? &dec
->idct_y
: &dec
->idct_c
,
348 &buffer
->idct
[i
], idct_source_sv
[i
],
349 idct_intermediate_sv
[i
], idct_surfaces
[i
]))
356 vl_idct_cleanup_buffer(i
== 1 ? &dec
->idct_c
: &dec
->idct_y
, &buffer
->idct
[i
- 1]);
359 error_intermediate_sv
:
361 buffer
->idct_intermediate
->destroy(buffer
->idct_intermediate
);
364 buffer
->idct_source
->destroy(buffer
->idct_source
);
370 static struct pipe_video_decode_buffer
*
371 vl_mpeg12_create_buffer(struct pipe_video_decoder
*decoder
)
373 enum pipe_format formats
[3];
375 struct vl_mpeg12_decoder
*dec
= (struct vl_mpeg12_decoder
*)decoder
;
376 struct vl_mpeg12_buffer
*buffer
;
378 struct pipe_sampler_view
**mc_source_sv
;
382 buffer
= CALLOC_STRUCT(vl_mpeg12_buffer
);
386 buffer
->base
.decoder
= decoder
;
387 buffer
->base
.destroy
= vl_mpeg12_buffer_destroy
;
388 buffer
->base
.map
= vl_mpeg12_buffer_map
;
389 buffer
->base
.add_macroblocks
= vl_mpeg12_buffer_add_macroblocks
;
390 buffer
->base
.unmap
= vl_mpeg12_buffer_unmap
;
392 vl_vb_init(&buffer
->vertex_stream
, dec
->pipe
,
393 dec
->base
.width
/ MACROBLOCK_WIDTH
,
394 dec
->base
.height
/ MACROBLOCK_HEIGHT
);
396 formats
[0] = formats
[1] = formats
[2] =dec
->mc_source_format
;
397 buffer
->mc_source
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
398 dec
->base
.width
, dec
->base
.height
, 1,
399 dec
->base
.chroma_format
,
400 formats
, PIPE_USAGE_STATIC
);
402 if (!buffer
->mc_source
)
403 goto error_mc_source
;
405 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
406 if (!init_idct_buffer(buffer
))
409 mc_source_sv
= buffer
->mc_source
->get_sampler_views(buffer
->mc_source
);
411 goto error_mc_source_sv
;
413 if(!vl_mc_init_buffer(&dec
->mc_y
, &buffer
->mc
[0], mc_source_sv
[0]))
416 if(!vl_mc_init_buffer(&dec
->mc_c
, &buffer
->mc
[1], mc_source_sv
[1]))
419 if(!vl_mc_init_buffer(&dec
->mc_c
, &buffer
->mc
[2], mc_source_sv
[2]))
422 return &buffer
->base
;
425 vl_mc_cleanup_buffer(&buffer
->mc
[1]);
428 vl_mc_cleanup_buffer(&buffer
->mc
[0]);
432 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
433 cleanup_idct_buffer(buffer
);
436 buffer
->mc_source
->destroy(buffer
->mc_source
);
439 vl_vb_cleanup(&buffer
->vertex_stream
);
447 vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer
*buffer
,
448 struct pipe_video_buffer
*refs
[2],
449 struct pipe_video_buffer
*dst
,
450 struct pipe_fence_handle
**fence
)
452 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
453 struct vl_mpeg12_decoder
*dec
;
455 struct pipe_sampler_view
**sv
[2];
456 struct pipe_surface
**surfaces
;
458 struct pipe_vertex_buffer vb
[3];
460 unsigned num_instances
;
465 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
468 for (i
= 0; i
< 2; ++i
)
469 sv
[i
] = refs
[i
] ? refs
[i
]->get_sampler_views(refs
[i
]) : NULL
;
471 surfaces
= dst
->get_surfaces(dst
);
473 num_instances
= vl_vb_restart(&buf
->vertex_stream
);
478 dec
->pipe
->bind_vertex_elements_state(dec
->pipe
, dec
->ves_mv
);
479 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
480 vl_mc_set_surface(&buf
->mc
[i
], surfaces
[i
]);
482 for (j
= 0; j
< 2; ++j
) {
483 if (sv
[j
] == NULL
) continue;
485 vb
[2] = vl_vb_get_mv(&buf
->vertex_stream
, j
);;
486 dec
->pipe
->set_vertex_buffers(dec
->pipe
, 3, vb
);
488 vl_mc_render_ref(&buf
->mc
[i
], sv
[j
][i
]);
492 vb
[1] = vl_vb_get_ycbcr(&buf
->vertex_stream
);
493 dec
->pipe
->set_vertex_buffers(dec
->pipe
, 2, vb
);
495 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
496 dec
->pipe
->bind_vertex_elements_state(dec
->pipe
, dec
->ves_eb
[i
]);
497 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
498 vl_idct_flush(i
== 0 ? &dec
->idct_y
: &dec
->idct_c
, &buf
->idct
[i
], num_instances
);
500 vl_mc_render_ycbcr(&buf
->mc
[i
], num_instances
);
503 dec
->pipe
->flush(dec
->pipe
, fence
);
507 vl_mpeg12_decoder_clear_buffer(struct pipe_video_decode_buffer
*buffer
)
509 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
513 vl_vb_restart(&buf
->vertex_stream
);
517 init_pipe_state(struct vl_mpeg12_decoder
*dec
)
519 struct pipe_depth_stencil_alpha_state dsa
;
524 memset(&dsa
, 0, sizeof dsa
);
525 dsa
.depth
.enabled
= 0;
526 dsa
.depth
.writemask
= 0;
527 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
528 for (i
= 0; i
< 2; ++i
) {
529 dsa
.stencil
[i
].enabled
= 0;
530 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
531 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
532 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
533 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
534 dsa
.stencil
[i
].valuemask
= 0;
535 dsa
.stencil
[i
].writemask
= 0;
537 dsa
.alpha
.enabled
= 0;
538 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
539 dsa
.alpha
.ref_value
= 0;
540 dec
->dsa
= dec
->pipe
->create_depth_stencil_alpha_state(dec
->pipe
, &dsa
);
541 dec
->pipe
->bind_depth_stencil_alpha_state(dec
->pipe
, dec
->dsa
);
546 static enum pipe_format
547 find_first_supported_format(struct vl_mpeg12_decoder
*dec
,
548 const enum pipe_format formats
[],
549 unsigned num_formats
,
550 enum pipe_texture_target target
)
552 struct pipe_screen
*screen
;
557 screen
= dec
->pipe
->screen
;
559 for (i
= 0; i
< num_formats
; ++i
)
560 if (screen
->is_format_supported(dec
->pipe
->screen
, formats
[i
], target
, 1,
561 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
))
564 return PIPE_FORMAT_NONE
;
568 init_idct(struct vl_mpeg12_decoder
*dec
, unsigned buffer_width
, unsigned buffer_height
)
570 unsigned chroma_width
, chroma_height
, chroma_blocks_x
, chroma_blocks_y
;
571 struct pipe_sampler_view
*matrix
, *transpose
;
572 float matrix_scale
, transpose_scale
;
574 dec
->nr_of_idct_render_targets
= dec
->pipe
->screen
->get_param(dec
->pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
);
576 // more than 4 render targets usually doesn't makes any seens
577 dec
->nr_of_idct_render_targets
= MIN2(dec
->nr_of_idct_render_targets
, 4);
579 dec
->idct_source_format
= find_first_supported_format(dec
, const_idct_source_formats
,
580 num_idct_source_formats
, PIPE_TEXTURE_2D
);
582 if (dec
->idct_source_format
== PIPE_FORMAT_NONE
)
585 dec
->idct_intermediate_format
= find_first_supported_format(dec
, const_idct_intermediate_formats
,
586 num_idct_intermediate_formats
, PIPE_TEXTURE_3D
);
588 if (dec
->idct_intermediate_format
== PIPE_FORMAT_NONE
)
591 switch (dec
->idct_source_format
) {
592 case PIPE_FORMAT_R16G16B16A16_SSCALED
:
593 matrix_scale
= SCALE_FACTOR_SSCALED
;
596 case PIPE_FORMAT_R16G16B16A16_SNORM
:
597 matrix_scale
= SCALE_FACTOR_SNORM
;
605 if (dec
->idct_intermediate_format
== PIPE_FORMAT_R16G16B16A16_FLOAT
||
606 dec
->idct_intermediate_format
== PIPE_FORMAT_R32G32B32A32_FLOAT
)
607 transpose_scale
= 1.0f
;
609 transpose_scale
= matrix_scale
= sqrt(matrix_scale
);
611 if (dec
->mc_source_format
== PIPE_FORMAT_R16_SSCALED
)
612 transpose_scale
/= SCALE_FACTOR_SSCALED
;
614 if (!(matrix
= vl_idct_upload_matrix(dec
->pipe
, matrix_scale
)))
617 if (matrix_scale
!= transpose_scale
) {
618 if (!(transpose
= vl_idct_upload_matrix(dec
->pipe
, transpose_scale
)))
619 goto error_transpose
;
621 pipe_sampler_view_reference(&transpose
, matrix
);
623 if (!vl_idct_init(&dec
->idct_y
, dec
->pipe
, buffer_width
, buffer_height
,
624 2, 2, dec
->nr_of_idct_render_targets
, matrix
, transpose
))
627 if (dec
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
) {
628 chroma_width
= buffer_width
/ 2;
629 chroma_height
= buffer_height
/ 2;
632 } else if (dec
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_422
) {
633 chroma_width
= buffer_width
;
634 chroma_height
= buffer_height
/ 2;
638 chroma_width
= buffer_width
;
639 chroma_height
= buffer_height
;
644 if(!vl_idct_init(&dec
->idct_c
, dec
->pipe
, chroma_width
, chroma_height
,
645 chroma_blocks_x
, chroma_blocks_y
,
646 dec
->nr_of_idct_render_targets
, matrix
, transpose
))
649 pipe_sampler_view_reference(&matrix
, NULL
);
650 pipe_sampler_view_reference(&transpose
, NULL
);
654 vl_idct_cleanup(&dec
->idct_y
);
657 pipe_sampler_view_reference(&transpose
, NULL
);
660 pipe_sampler_view_reference(&matrix
, NULL
);
666 struct pipe_video_decoder
*
667 vl_create_mpeg12_decoder(struct pipe_video_context
*context
,
668 struct pipe_context
*pipe
,
669 enum pipe_video_profile profile
,
670 enum pipe_video_entrypoint entrypoint
,
671 enum pipe_video_chroma_format chroma_format
,
672 unsigned width
, unsigned height
)
674 struct vl_mpeg12_decoder
*dec
;
678 assert(u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG12
);
680 dec
= CALLOC_STRUCT(vl_mpeg12_decoder
);
685 dec
->base
.context
= context
;
686 dec
->base
.profile
= profile
;
687 dec
->base
.entrypoint
= entrypoint
;
688 dec
->base
.chroma_format
= chroma_format
;
689 dec
->base
.width
= width
;
690 dec
->base
.height
= height
;
692 dec
->base
.destroy
= vl_mpeg12_destroy
;
693 dec
->base
.create_buffer
= vl_mpeg12_create_buffer
;
694 dec
->base
.flush_buffer
= vl_mpeg12_decoder_flush_buffer
;
695 dec
->base
.clear_buffer
= vl_mpeg12_decoder_clear_buffer
;
697 dec
->base
.width
= align(width
, MACROBLOCK_WIDTH
);
698 dec
->base
.height
= align(height
, MACROBLOCK_HEIGHT
);
702 dec
->quads
= vl_vb_upload_quads(dec
->pipe
, 2, 2);
703 dec
->pos
= vl_vb_upload_pos(
705 dec
->base
.width
/ MACROBLOCK_WIDTH
,
706 dec
->base
.height
/ MACROBLOCK_HEIGHT
709 for (i
= 0; i
< VL_MAX_PLANES
; ++i
)
710 dec
->ves_eb
[i
] = vl_vb_get_ves_eb(dec
->pipe
, i
);
712 dec
->ves_mv
= vl_vb_get_ves_mv(dec
->pipe
);
714 /* TODO: Implement 422, 444 */
715 assert(dec
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
716 dec
->empty_block_mask
= &const_empty_block_mask_420
;
718 dec
->mc_source_format
= find_first_supported_format(dec
, const_mc_source_formats
,
719 num_mc_source_formats
, PIPE_TEXTURE_3D
);
721 if (dec
->mc_source_format
== PIPE_FORMAT_NONE
)
724 if (entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
) {
725 if (!init_idct(dec
, dec
->base
.width
, dec
->base
.height
))
727 if (dec
->mc_source_format
== PIPE_FORMAT_R16_SSCALED
)
728 mc_scale
= SCALE_FACTOR_SSCALED
;
732 switch (dec
->mc_source_format
) {
733 case PIPE_FORMAT_R16_SNORM
:
734 mc_scale
= SCALE_FACTOR_SNORM
;
737 case PIPE_FORMAT_R16_SSCALED
:
738 mc_scale
= SCALE_FACTOR_SSCALED
;
747 if (!vl_mc_init(&dec
->mc_y
, dec
->pipe
, dec
->base
.width
, dec
->base
.height
, MACROBLOCK_HEIGHT
, mc_scale
))
751 if (!vl_mc_init(&dec
->mc_c
, dec
->pipe
, dec
->base
.width
, dec
->base
.height
, BLOCK_HEIGHT
, mc_scale
))
754 if (!init_pipe_state(dec
))
755 goto error_pipe_state
;
760 vl_mc_cleanup(&dec
->mc_c
);
763 vl_mc_cleanup(&dec
->mc_y
);
766 if (entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
) {
767 vl_idct_cleanup(&dec
->idct_y
);
768 vl_idct_cleanup(&dec
->idct_c
);