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 enum pipe_format const_zscan_source_formats
[] = {
42 PIPE_FORMAT_R16_SNORM
,
43 PIPE_FORMAT_R16_SSCALED
46 static const unsigned num_zscan_source_formats
=
47 sizeof(const_zscan_source_formats
) / sizeof(enum pipe_format
);
49 static const enum pipe_format const_idct_source_formats
[] = {
50 PIPE_FORMAT_R16G16B16A16_SNORM
,
51 PIPE_FORMAT_R16G16B16A16_SSCALED
54 static const unsigned num_idct_source_formats
=
55 sizeof(const_idct_source_formats
) / sizeof(enum pipe_format
);
57 static const enum pipe_format const_idct_intermediate_formats
[] = {
58 PIPE_FORMAT_R16G16B16A16_FLOAT
,
59 PIPE_FORMAT_R16G16B16A16_SNORM
,
60 PIPE_FORMAT_R16G16B16A16_SSCALED
,
61 PIPE_FORMAT_R32G32B32A32_FLOAT
64 static const unsigned num_idct_intermediate_formats
=
65 sizeof(const_idct_intermediate_formats
) / sizeof(enum pipe_format
);
67 static const enum pipe_format const_mc_source_formats
[] = {
68 PIPE_FORMAT_R16_SNORM
,
69 PIPE_FORMAT_R16_SSCALED
72 static const unsigned num_mc_source_formats
=
73 sizeof(const_mc_source_formats
) / sizeof(enum pipe_format
);
76 init_zscan_buffer(struct vl_mpeg12_buffer
*buffer
)
78 enum pipe_format formats
[3];
80 struct pipe_sampler_view
**source
;
81 struct pipe_surface
**destination
;
83 struct vl_mpeg12_decoder
*dec
;
89 dec
= (struct vl_mpeg12_decoder
*)buffer
->base
.decoder
;
91 formats
[0] = formats
[1] = formats
[2] = dec
->zscan_source_format
;
92 buffer
->zscan_source
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
93 dec
->blocks_per_line
* BLOCK_WIDTH
* BLOCK_HEIGHT
,
94 dec
->max_blocks
/ dec
->blocks_per_line
,
95 1, PIPE_VIDEO_CHROMA_FORMAT_444
,
96 formats
, PIPE_USAGE_STATIC
);
97 if (!buffer
->zscan_source
)
100 source
= buffer
->zscan_source
->get_sampler_views(buffer
->zscan_source
);
104 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
105 destination
= buffer
->idct_source
->get_surfaces(buffer
->idct_source
);
107 destination
= buffer
->mc_source
->get_surfaces(buffer
->mc_source
);
112 for (i
= 0; i
< VL_MAX_PLANES
; ++i
)
113 if (!vl_zscan_init_buffer(i
== 0 ? &dec
->zscan_y
: &dec
->zscan_c
,
114 &buffer
->zscan
[i
], source
[i
], destination
[i
]))
121 vl_zscan_cleanup_buffer(&buffer
->zscan
[i
- 1]);
125 buffer
->zscan_source
->destroy(buffer
->zscan_source
);
132 cleanup_zscan_buffer(struct vl_mpeg12_buffer
*buffer
)
138 for (i
= 0; i
< VL_MAX_PLANES
; ++i
)
139 vl_zscan_cleanup_buffer(&buffer
->zscan
[i
]);
140 buffer
->zscan_source
->destroy(buffer
->zscan_source
);
144 init_idct_buffer(struct vl_mpeg12_buffer
*buffer
)
146 enum pipe_format formats
[3];
148 struct pipe_sampler_view
**idct_source_sv
, **idct_intermediate_sv
;
149 struct pipe_surface
**idct_surfaces
;
151 struct vl_mpeg12_decoder
*dec
;
157 dec
= (struct vl_mpeg12_decoder
*)buffer
->base
.decoder
;
159 formats
[0] = formats
[1] = formats
[2] = dec
->idct_source_format
;
160 buffer
->idct_source
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
161 dec
->base
.width
/ 4, dec
->base
.height
, 1,
162 dec
->base
.chroma_format
,
163 formats
, PIPE_USAGE_STATIC
);
164 if (!buffer
->idct_source
)
167 formats
[0] = formats
[1] = formats
[2] = dec
->idct_intermediate_format
;
168 buffer
->idct_intermediate
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
169 dec
->base
.width
/ dec
->nr_of_idct_render_targets
,
170 dec
->base
.height
/ 4, dec
->nr_of_idct_render_targets
,
171 dec
->base
.chroma_format
,
172 formats
, PIPE_USAGE_STATIC
);
174 if (!buffer
->idct_intermediate
)
175 goto error_intermediate
;
177 idct_source_sv
= buffer
->idct_source
->get_sampler_views(buffer
->idct_source
);
179 goto error_source_sv
;
181 idct_intermediate_sv
= buffer
->idct_intermediate
->get_sampler_views(buffer
->idct_intermediate
);
182 if (!idct_intermediate_sv
)
183 goto error_intermediate_sv
;
185 idct_surfaces
= buffer
->mc_source
->get_surfaces(buffer
->mc_source
);
189 for (i
= 0; i
< 3; ++i
)
190 if (!vl_idct_init_buffer(i
== 0 ? &dec
->idct_y
: &dec
->idct_c
,
191 &buffer
->idct
[i
], idct_source_sv
[i
],
192 idct_intermediate_sv
[i
], idct_surfaces
[i
]))
199 vl_idct_cleanup_buffer(i
== 1 ? &dec
->idct_c
: &dec
->idct_y
, &buffer
->idct
[i
- 1]);
202 error_intermediate_sv
:
204 buffer
->idct_intermediate
->destroy(buffer
->idct_intermediate
);
207 buffer
->idct_source
->destroy(buffer
->idct_source
);
214 cleanup_idct_buffer(struct vl_mpeg12_buffer
*buf
)
216 struct vl_mpeg12_decoder
*dec
;
219 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
222 vl_idct_cleanup_buffer(&dec
->idct_y
, &buf
->idct
[0]);
223 vl_idct_cleanup_buffer(&dec
->idct_c
, &buf
->idct
[1]);
224 vl_idct_cleanup_buffer(&dec
->idct_c
, &buf
->idct
[2]);
225 buf
->idct_source
->destroy(buf
->idct_source
);
226 buf
->idct_intermediate
->destroy(buf
->idct_intermediate
);
230 init_mc_buffer(struct vl_mpeg12_buffer
*buf
)
232 struct vl_mpeg12_decoder
*dec
;
233 enum pipe_format formats
[3];
234 struct pipe_sampler_view
**mc_source_sv
;
238 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
241 formats
[0] = formats
[1] = formats
[2] =dec
->mc_source_format
;
242 buf
->mc_source
= vl_video_buffer_init(dec
->base
.context
, dec
->pipe
,
243 dec
->base
.width
, dec
->base
.height
, 1,
244 dec
->base
.chroma_format
,
245 formats
, PIPE_USAGE_STATIC
);
248 goto error_mc_source
;
250 mc_source_sv
= buf
->mc_source
->get_sampler_views(buf
->mc_source
);
252 goto error_mc_source_sv
;
254 if(!vl_mc_init_buffer(&dec
->mc_y
, &buf
->mc
[0], mc_source_sv
[0]))
257 if(!vl_mc_init_buffer(&dec
->mc_c
, &buf
->mc
[1], mc_source_sv
[1]))
260 if(!vl_mc_init_buffer(&dec
->mc_c
, &buf
->mc
[2], mc_source_sv
[2]))
266 vl_mc_cleanup_buffer(&buf
->mc
[1]);
269 vl_mc_cleanup_buffer(&buf
->mc
[0]);
273 buf
->mc_source
->destroy(buf
->mc_source
);
280 cleanup_mc_buffer(struct vl_mpeg12_buffer
*buf
)
286 for (i
= 0; i
< VL_MAX_PLANES
; ++i
)
287 vl_mc_cleanup_buffer(&buf
->mc
[i
]);
289 buf
->mc_source
->destroy(buf
->mc_source
);
293 vl_mpeg12_buffer_destroy(struct pipe_video_decode_buffer
*buffer
)
295 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
296 struct vl_mpeg12_decoder
*dec
;
300 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
303 cleanup_zscan_buffer(buf
);
305 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
306 cleanup_idct_buffer(buf
);
308 cleanup_mc_buffer(buf
);
310 vl_vb_cleanup(&buf
->vertex_stream
);
316 vl_mpeg12_buffer_map(struct pipe_video_decode_buffer
*buffer
)
318 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
319 struct vl_mpeg12_decoder
*dec
;
321 struct pipe_sampler_view
**sampler_views
;
326 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
329 vl_vb_map(&buf
->vertex_stream
, dec
->pipe
);
331 sampler_views
= buf
->zscan_source
->get_sampler_views(buf
->zscan_source
);
333 assert(sampler_views
);
335 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
336 struct pipe_resource
*tex
= sampler_views
[i
]->texture
;
337 struct pipe_box rect
=
345 buf
->tex_transfer
[i
] = dec
->pipe
->get_transfer
348 0, PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_DISCARD
,
352 buf
->texels
[i
] = dec
->pipe
->transfer_map(dec
->pipe
, buf
->tex_transfer
[i
]);
356 static struct pipe_ycbcr_block
*
357 vl_mpeg12_buffer_get_ycbcr_stream(struct pipe_video_decode_buffer
*buffer
, int component
)
359 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
363 return vl_vb_get_ycbcr_stream(&buf
->vertex_stream
, component
);
367 vl_mpeg12_buffer_get_ycbcr_buffer(struct pipe_video_decode_buffer
*buffer
, int component
)
369 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
372 assert(component
< VL_MAX_PLANES
);
374 return buf
->texels
[component
];
378 vl_mpeg12_buffer_get_mv_stream_stride(struct pipe_video_decode_buffer
*buffer
)
380 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
384 return vl_vb_get_mv_stream_stride(&buf
->vertex_stream
);
387 static struct pipe_motionvector
*
388 vl_mpeg12_buffer_get_mv_stream(struct pipe_video_decode_buffer
*buffer
, int ref_frame
)
390 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
394 return vl_vb_get_mv_stream(&buf
->vertex_stream
, ref_frame
);
398 vl_mpeg12_buffer_unmap(struct pipe_video_decode_buffer
*buffer
)
400 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
401 struct vl_mpeg12_decoder
*dec
;
406 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
409 vl_vb_unmap(&buf
->vertex_stream
, dec
->pipe
);
411 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
412 dec
->pipe
->transfer_unmap(dec
->pipe
, buf
->tex_transfer
[i
]);
413 dec
->pipe
->transfer_destroy(dec
->pipe
, buf
->tex_transfer
[i
]);
418 vl_mpeg12_destroy(struct pipe_video_decoder
*decoder
)
420 struct vl_mpeg12_decoder
*dec
= (struct vl_mpeg12_decoder
*)decoder
;
424 /* Asserted in softpipe_delete_fs_state() for some reason */
425 dec
->pipe
->bind_vs_state(dec
->pipe
, NULL
);
426 dec
->pipe
->bind_fs_state(dec
->pipe
, NULL
);
428 dec
->pipe
->delete_depth_stencil_alpha_state(dec
->pipe
, dec
->dsa
);
430 vl_mc_cleanup(&dec
->mc_y
);
431 vl_mc_cleanup(&dec
->mc_c
);
433 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
) {
434 vl_idct_cleanup(&dec
->idct_y
);
435 vl_idct_cleanup(&dec
->idct_c
);
438 vl_zscan_cleanup(&dec
->zscan_y
);
439 vl_zscan_cleanup(&dec
->zscan_c
);
441 dec
->pipe
->delete_vertex_elements_state(dec
->pipe
, dec
->ves_ycbcr
);
442 dec
->pipe
->delete_vertex_elements_state(dec
->pipe
, dec
->ves_mv
);
444 pipe_resource_reference(&dec
->quads
.buffer
, NULL
);
445 pipe_resource_reference(&dec
->pos
.buffer
, NULL
);
450 static struct pipe_video_decode_buffer
*
451 vl_mpeg12_create_buffer(struct pipe_video_decoder
*decoder
)
453 struct vl_mpeg12_decoder
*dec
= (struct vl_mpeg12_decoder
*)decoder
;
454 struct vl_mpeg12_buffer
*buffer
;
458 buffer
= CALLOC_STRUCT(vl_mpeg12_buffer
);
462 buffer
->base
.decoder
= decoder
;
463 buffer
->base
.destroy
= vl_mpeg12_buffer_destroy
;
464 buffer
->base
.map
= vl_mpeg12_buffer_map
;
465 buffer
->base
.get_ycbcr_stream
= vl_mpeg12_buffer_get_ycbcr_stream
;
466 buffer
->base
.get_ycbcr_buffer
= vl_mpeg12_buffer_get_ycbcr_buffer
;
467 buffer
->base
.get_mv_stream_stride
= vl_mpeg12_buffer_get_mv_stream_stride
;
468 buffer
->base
.get_mv_stream
= vl_mpeg12_buffer_get_mv_stream
;
469 buffer
->base
.unmap
= vl_mpeg12_buffer_unmap
;
471 if (!vl_vb_init(&buffer
->vertex_stream
, dec
->pipe
,
472 dec
->base
.width
/ MACROBLOCK_WIDTH
,
473 dec
->base
.height
/ MACROBLOCK_HEIGHT
))
474 goto error_vertex_buffer
;
476 if (!init_mc_buffer(buffer
))
479 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
480 if (!init_idct_buffer(buffer
))
483 if (!init_zscan_buffer(buffer
))
486 return &buffer
->base
;
489 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
490 cleanup_idct_buffer(buffer
);
493 cleanup_mc_buffer(buffer
);
496 vl_vb_cleanup(&buffer
->vertex_stream
);
504 vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer
*buffer
,
505 unsigned num_ycbcr_blocks
[3],
506 struct pipe_video_buffer
*refs
[2],
507 struct pipe_video_buffer
*dst
,
508 struct pipe_fence_handle
**fence
)
510 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
511 struct vl_mpeg12_decoder
*dec
;
513 struct pipe_sampler_view
**sv
[2];
514 struct pipe_surface
**surfaces
;
516 struct pipe_vertex_buffer vb
[3];
522 dec
= (struct vl_mpeg12_decoder
*)buf
->base
.decoder
;
525 for (i
= 0; i
< 2; ++i
)
526 sv
[i
] = refs
[i
] ? refs
[i
]->get_sampler_views(refs
[i
]) : NULL
;
528 surfaces
= dst
->get_surfaces(dst
);
533 dec
->pipe
->bind_vertex_elements_state(dec
->pipe
, dec
->ves_mv
);
534 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
535 vl_mc_set_surface(&buf
->mc
[i
], surfaces
[i
]);
537 for (j
= 0; j
< 2; ++j
) {
538 if (sv
[j
] == NULL
) continue;
540 vb
[2] = vl_vb_get_mv(&buf
->vertex_stream
, j
);;
541 dec
->pipe
->set_vertex_buffers(dec
->pipe
, 3, vb
);
543 vl_mc_render_ref(&buf
->mc
[i
], sv
[j
][i
]);
547 dec
->pipe
->bind_vertex_elements_state(dec
->pipe
, dec
->ves_ycbcr
);
548 for (i
= 0; i
< VL_MAX_PLANES
; ++i
) {
549 if (num_ycbcr_blocks
[i
] == 0) continue;
551 vb
[1] = vl_vb_get_ycbcr(&buf
->vertex_stream
, i
);
552 dec
->pipe
->set_vertex_buffers(dec
->pipe
, 2, vb
);
554 vl_zscan_render(&buf
->zscan
[i
] , num_ycbcr_blocks
[i
]);
556 if (dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
)
557 vl_idct_flush(i
== 0 ? &dec
->idct_y
: &dec
->idct_c
, &buf
->idct
[i
], num_ycbcr_blocks
[i
]);
559 vl_mc_render_ycbcr(&buf
->mc
[i
], num_ycbcr_blocks
[i
]);
562 dec
->pipe
->flush(dec
->pipe
, fence
);
566 init_pipe_state(struct vl_mpeg12_decoder
*dec
)
568 struct pipe_depth_stencil_alpha_state dsa
;
573 memset(&dsa
, 0, sizeof dsa
);
574 dsa
.depth
.enabled
= 0;
575 dsa
.depth
.writemask
= 0;
576 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
577 for (i
= 0; i
< 2; ++i
) {
578 dsa
.stencil
[i
].enabled
= 0;
579 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
580 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
581 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
582 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
583 dsa
.stencil
[i
].valuemask
= 0;
584 dsa
.stencil
[i
].writemask
= 0;
586 dsa
.alpha
.enabled
= 0;
587 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
588 dsa
.alpha
.ref_value
= 0;
589 dec
->dsa
= dec
->pipe
->create_depth_stencil_alpha_state(dec
->pipe
, &dsa
);
590 dec
->pipe
->bind_depth_stencil_alpha_state(dec
->pipe
, dec
->dsa
);
595 static enum pipe_format
596 find_first_supported_format(struct vl_mpeg12_decoder
*dec
,
597 const enum pipe_format formats
[],
598 unsigned num_formats
,
599 enum pipe_texture_target target
)
601 struct pipe_screen
*screen
;
606 screen
= dec
->pipe
->screen
;
608 for (i
= 0; i
< num_formats
; ++i
)
609 if (screen
->is_format_supported(dec
->pipe
->screen
, formats
[i
], target
, 1,
610 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
))
613 return PIPE_FORMAT_NONE
;
617 init_zscan(struct vl_mpeg12_decoder
*dec
)
619 struct pipe_sampler_view
*layout
;
621 unsigned num_channels
;
625 dec
->blocks_per_line
= 4;
627 (dec
->base
.width
* dec
->base
.height
) /
628 (BLOCK_WIDTH
* BLOCK_HEIGHT
);
630 dec
->zscan_source_format
= find_first_supported_format(dec
, const_zscan_source_formats
,
631 num_zscan_source_formats
, PIPE_TEXTURE_2D
);
633 if (dec
->zscan_source_format
== PIPE_FORMAT_NONE
)
636 layout
= vl_zscan_linear(dec
->pipe
, dec
->blocks_per_line
);
638 num_channels
= dec
->base
.entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
? 4 : 1;
640 if (!vl_zscan_init(&dec
->zscan_y
, dec
->pipe
, dec
->base
.width
, dec
->base
.height
,
641 dec
->blocks_per_line
, dec
->max_blocks
, num_channels
))
644 vl_zscan_set_layout(&dec
->zscan_y
, layout
);
646 if (!vl_zscan_init(&dec
->zscan_c
, dec
->pipe
, dec
->chroma_width
, dec
->chroma_height
,
647 dec
->blocks_per_line
, dec
->max_blocks
, num_channels
))
650 vl_zscan_set_layout(&dec
->zscan_c
, layout
);
656 init_idct(struct vl_mpeg12_decoder
*dec
)
658 struct pipe_sampler_view
*matrix
, *transpose
= NULL
;
659 float matrix_scale
, transpose_scale
;
661 dec
->nr_of_idct_render_targets
= dec
->pipe
->screen
->get_param(dec
->pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
);
663 // more than 4 render targets usually doesn't makes any seens
664 dec
->nr_of_idct_render_targets
= MIN2(dec
->nr_of_idct_render_targets
, 4);
666 dec
->idct_source_format
= find_first_supported_format(dec
, const_idct_source_formats
,
667 num_idct_source_formats
, PIPE_TEXTURE_2D
);
669 if (dec
->idct_source_format
== PIPE_FORMAT_NONE
)
672 dec
->idct_intermediate_format
= find_first_supported_format(dec
, const_idct_intermediate_formats
,
673 num_idct_intermediate_formats
, PIPE_TEXTURE_3D
);
675 if (dec
->idct_intermediate_format
== PIPE_FORMAT_NONE
)
678 switch (dec
->idct_source_format
) {
679 case PIPE_FORMAT_R16G16B16A16_SSCALED
:
680 matrix_scale
= SCALE_FACTOR_SSCALED
;
683 case PIPE_FORMAT_R16G16B16A16_SNORM
:
684 matrix_scale
= SCALE_FACTOR_SNORM
;
692 if (dec
->idct_intermediate_format
== PIPE_FORMAT_R16G16B16A16_FLOAT
||
693 dec
->idct_intermediate_format
== PIPE_FORMAT_R32G32B32A32_FLOAT
)
694 transpose_scale
= 1.0f
;
696 transpose_scale
= matrix_scale
= sqrt(matrix_scale
);
698 if (dec
->mc_source_format
== PIPE_FORMAT_R16_SSCALED
)
699 transpose_scale
/= SCALE_FACTOR_SSCALED
;
701 if (!(matrix
= vl_idct_upload_matrix(dec
->pipe
, matrix_scale
)))
704 if (matrix_scale
!= transpose_scale
) {
705 if (!(transpose
= vl_idct_upload_matrix(dec
->pipe
, transpose_scale
)))
706 goto error_transpose
;
708 pipe_sampler_view_reference(&transpose
, matrix
);
710 if (!vl_idct_init(&dec
->idct_y
, dec
->pipe
, dec
->base
.width
, dec
->base
.height
,
711 dec
->nr_of_idct_render_targets
, matrix
, transpose
))
714 if(!vl_idct_init(&dec
->idct_c
, dec
->pipe
, dec
->chroma_width
, dec
->chroma_height
,
715 dec
->nr_of_idct_render_targets
, matrix
, transpose
))
718 pipe_sampler_view_reference(&matrix
, NULL
);
719 pipe_sampler_view_reference(&transpose
, NULL
);
723 vl_idct_cleanup(&dec
->idct_y
);
726 pipe_sampler_view_reference(&transpose
, NULL
);
729 pipe_sampler_view_reference(&matrix
, NULL
);
735 struct pipe_video_decoder
*
736 vl_create_mpeg12_decoder(struct pipe_video_context
*context
,
737 struct pipe_context
*pipe
,
738 enum pipe_video_profile profile
,
739 enum pipe_video_entrypoint entrypoint
,
740 enum pipe_video_chroma_format chroma_format
,
741 unsigned width
, unsigned height
)
743 struct vl_mpeg12_decoder
*dec
;
746 assert(u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG12
);
748 dec
= CALLOC_STRUCT(vl_mpeg12_decoder
);
753 dec
->base
.context
= context
;
754 dec
->base
.profile
= profile
;
755 dec
->base
.entrypoint
= entrypoint
;
756 dec
->base
.chroma_format
= chroma_format
;
757 dec
->base
.width
= width
;
758 dec
->base
.height
= height
;
760 dec
->base
.destroy
= vl_mpeg12_destroy
;
761 dec
->base
.create_buffer
= vl_mpeg12_create_buffer
;
762 dec
->base
.flush_buffer
= vl_mpeg12_decoder_flush_buffer
;
764 dec
->base
.width
= align(width
, MACROBLOCK_WIDTH
);
765 dec
->base
.height
= align(height
, MACROBLOCK_HEIGHT
);
769 dec
->quads
= vl_vb_upload_quads(dec
->pipe
);
770 dec
->pos
= vl_vb_upload_pos(
772 dec
->base
.width
/ MACROBLOCK_WIDTH
,
773 dec
->base
.height
/ MACROBLOCK_HEIGHT
776 dec
->ves_ycbcr
= vl_vb_get_ves_ycbcr(dec
->pipe
);
777 dec
->ves_mv
= vl_vb_get_ves_mv(dec
->pipe
);
779 /* TODO: Implement 422, 444 */
780 assert(dec
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
782 dec
->mc_source_format
= find_first_supported_format(dec
, const_mc_source_formats
,
783 num_mc_source_formats
, PIPE_TEXTURE_3D
);
785 if (dec
->mc_source_format
== PIPE_FORMAT_NONE
)
788 if (dec
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
) {
789 dec
->chroma_width
= dec
->base
.width
/ 2;
790 dec
->chroma_height
= dec
->base
.height
/ 2;
791 } else if (dec
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_422
) {
792 dec
->chroma_width
= dec
->base
.width
;
793 dec
->chroma_height
= dec
->base
.height
/ 2;
795 dec
->chroma_width
= dec
->base
.width
;
796 dec
->chroma_height
= dec
->base
.height
;
799 if (!init_zscan(dec
))
802 if (entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
) {
805 if (dec
->mc_source_format
== PIPE_FORMAT_R16_SSCALED
)
806 mc_scale
= SCALE_FACTOR_SSCALED
;
810 switch (dec
->mc_source_format
) {
811 case PIPE_FORMAT_R16_SNORM
:
812 mc_scale
= SCALE_FACTOR_SNORM
;
815 case PIPE_FORMAT_R16_SSCALED
:
816 mc_scale
= SCALE_FACTOR_SSCALED
;
825 if (!vl_mc_init(&dec
->mc_y
, dec
->pipe
, dec
->base
.width
, dec
->base
.height
, MACROBLOCK_HEIGHT
, mc_scale
))
829 if (!vl_mc_init(&dec
->mc_c
, dec
->pipe
, dec
->base
.width
, dec
->base
.height
, BLOCK_HEIGHT
, mc_scale
))
832 if (!init_pipe_state(dec
))
833 goto error_pipe_state
;
838 vl_mc_cleanup(&dec
->mc_c
);
841 vl_mc_cleanup(&dec
->mc_y
);
844 if (entrypoint
<= PIPE_VIDEO_ENTRYPOINT_IDCT
) {
845 vl_idct_cleanup(&dec
->idct_y
);
846 vl_idct_cleanup(&dec
->idct_c
);
850 vl_zscan_cleanup(&dec
->zscan_y
);
851 vl_zscan_cleanup(&dec
->zscan_c
);