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 **************************************************************************/
28 #include "util/u_inlines.h"
29 #include "util/u_memory.h"
31 #include "vl_mpeg12_context.h"
32 #include "vl_defines.h"
33 #include <pipe/p_shader_tokens.h>
34 #include <util/u_inlines.h>
35 #include <util/u_memory.h>
36 #include <util/u_keymap.h>
37 #include <util/u_rect.h>
38 #include <util/u_video.h>
39 #include <util/u_surface.h>
40 #include <util/u_sampler.h>
42 static const unsigned const_empty_block_mask_420
[3][2][2] = {
43 { { 0x20, 0x10 }, { 0x08, 0x04 } },
44 { { 0x02, 0x02 }, { 0x02, 0x02 } },
45 { { 0x01, 0x01 }, { 0x01, 0x01 } }
49 upload_buffer(struct vl_mpeg12_context
*ctx
,
50 struct vl_mpeg12_buffer
*buffer
,
51 struct pipe_mpeg12_macroblock
*mb
)
62 for (y
= 0; y
< 2; ++y
) {
63 for (x
= 0; x
< 2; ++x
, ++tb
) {
64 if (mb
->cbp
& (*ctx
->empty_block_mask
)[0][y
][x
]) {
65 vl_idct_add_block(&buffer
->idct_y
, mb
->mbx
* 2 + x
, mb
->mby
* 2 + y
, blocks
);
66 blocks
+= BLOCK_WIDTH
* BLOCK_HEIGHT
;
71 /* TODO: Implement 422, 444 */
72 assert(ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
74 for (tb
= 1; tb
< 3; ++tb
) {
75 if (mb
->cbp
& (*ctx
->empty_block_mask
)[tb
][0][0]) {
77 vl_idct_add_block(&buffer
->idct_cb
, mb
->mbx
, mb
->mby
, blocks
);
79 vl_idct_add_block(&buffer
->idct_cr
, mb
->mbx
, mb
->mby
, blocks
);
80 blocks
+= BLOCK_WIDTH
* BLOCK_HEIGHT
;
86 vl_mpeg12_buffer_destroy(struct pipe_video_buffer
*buffer
)
88 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
89 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
92 vl_ycbcr_buffer_cleanup(&buf
->idct_source
);
93 vl_ycbcr_buffer_cleanup(&buf
->idct_2_mc
);
94 vl_ycbcr_buffer_cleanup(&buf
->render_result
);
95 vl_vb_cleanup(&buf
->vertex_stream
);
96 vl_idct_cleanup_buffer(&ctx
->idct_y
, &buf
->idct_y
);
97 vl_idct_cleanup_buffer(&ctx
->idct_c
, &buf
->idct_cb
);
98 vl_idct_cleanup_buffer(&ctx
->idct_c
, &buf
->idct_cr
);
99 vl_mpeg12_mc_cleanup_buffer(&buf
->mc_y
);
100 vl_mpeg12_mc_cleanup_buffer(&buf
->mc_cb
);
101 vl_mpeg12_mc_cleanup_buffer(&buf
->mc_cr
);
107 vl_mpeg12_buffer_map(struct pipe_video_buffer
*buffer
)
109 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
110 struct vl_mpeg12_context
*ctx
;
113 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
116 vl_vb_map(&buf
->vertex_stream
, ctx
->pipe
);
117 vl_idct_map_buffers(&ctx
->idct_y
, &buf
->idct_y
);
118 vl_idct_map_buffers(&ctx
->idct_c
, &buf
->idct_cb
);
119 vl_idct_map_buffers(&ctx
->idct_c
, &buf
->idct_cr
);
123 vl_mpeg12_buffer_add_macroblocks(struct pipe_video_buffer
*buffer
,
124 unsigned num_macroblocks
,
125 struct pipe_macroblock
*macroblocks
)
127 struct pipe_mpeg12_macroblock
*mpeg12_macroblocks
= (struct pipe_mpeg12_macroblock
*)macroblocks
;
128 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
129 struct vl_mpeg12_context
*ctx
;
134 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
137 assert(num_macroblocks
);
139 assert(macroblocks
->codec
== PIPE_VIDEO_CODEC_MPEG12
);
141 for ( i
= 0; i
< num_macroblocks
; ++i
) {
142 vl_vb_add_block(&buf
->vertex_stream
, &mpeg12_macroblocks
[i
], ctx
->empty_block_mask
);
143 upload_buffer(ctx
, buf
, &mpeg12_macroblocks
[i
]);
148 vl_mpeg12_buffer_unmap(struct pipe_video_buffer
*buffer
)
150 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
151 struct vl_mpeg12_context
*ctx
;
154 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
157 vl_vb_unmap(&buf
->vertex_stream
, ctx
->pipe
);
158 vl_idct_unmap_buffers(&ctx
->idct_y
, &buf
->idct_y
);
159 vl_idct_unmap_buffers(&ctx
->idct_c
, &buf
->idct_cb
);
160 vl_idct_unmap_buffers(&ctx
->idct_c
, &buf
->idct_cr
);
164 vl_mpeg12_buffer_flush(struct pipe_video_buffer
*buffer
,
165 struct pipe_video_buffer
*refs
[2],
166 struct pipe_fence_handle
**fence
)
168 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
169 struct vl_mpeg12_buffer
*past
= (struct vl_mpeg12_buffer
*)refs
[0];
170 struct vl_mpeg12_buffer
*future
= (struct vl_mpeg12_buffer
*)refs
[1];
172 struct vl_ycbcr_surfaces
*surfaces
;
173 struct vl_ycbcr_sampler_views
*sv_past
;
174 struct vl_ycbcr_sampler_views
*sv_future
;
176 struct pipe_sampler_view
*sv_refs
[2];
177 unsigned ne_start
, ne_num
, e_start
, e_num
;
178 struct vl_mpeg12_context
*ctx
;
182 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
185 surfaces
= vl_ycbcr_get_surfaces(&buf
->render_result
);
187 sv_past
= past
? vl_ycbcr_get_sampler_views(&past
->render_result
) : NULL
;
188 sv_future
= future
? vl_ycbcr_get_sampler_views(&future
->render_result
) : NULL
;
190 vl_vb_restart(&buf
->vertex_stream
, &ne_start
, &ne_num
, &e_start
, &e_num
);
192 ctx
->pipe
->set_vertex_buffers(ctx
->pipe
, 2, buf
->vertex_bufs
.all
);
193 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend
);
196 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->ves_y
);
197 vl_idct_flush(&ctx
->idct_y
, &buf
->idct_y
, ne_num
);
199 sv_refs
[0] = sv_past
? sv_past
->y
: NULL
;
200 sv_refs
[1] = sv_future
? sv_future
->y
: NULL
;
202 vl_mpeg12_mc_renderer_flush(&ctx
->mc
, &buf
->mc_y
, surfaces
->y
,
203 sv_refs
, ne_start
, ne_num
, e_start
, e_num
, fence
);
205 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->ves_cb
);
206 vl_idct_flush(&ctx
->idct_c
, &buf
->idct_cb
, ne_num
);
208 sv_refs
[0] = sv_past
? sv_past
->cb
: NULL
;
209 sv_refs
[1] = sv_future
? sv_future
->cb
: NULL
;
211 vl_mpeg12_mc_renderer_flush(&ctx
->mc
, &buf
->mc_cb
, surfaces
->cb
,
212 sv_refs
, ne_start
, ne_num
, e_start
, e_num
, fence
);
214 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->ves_cr
);
215 vl_idct_flush(&ctx
->idct_c
, &buf
->idct_cr
, ne_num
);
217 sv_refs
[0] = sv_past
? sv_past
->cr
: NULL
;
218 sv_refs
[1] = sv_future
? sv_future
->cr
: NULL
;
220 vl_mpeg12_mc_renderer_flush(&ctx
->mc
, &buf
->mc_cr
, surfaces
->cr
,
221 sv_refs
, ne_start
, ne_num
, e_start
, e_num
, fence
);
225 vl_mpeg12_buffer_get_sampler_views(struct pipe_video_buffer
*buffer
,
226 struct pipe_sampler_view
*sampler_views
[3])
228 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
229 struct vl_ycbcr_sampler_views
*samplers
;
233 samplers
= vl_ycbcr_get_sampler_views(&buf
->render_result
);
237 pipe_sampler_view_reference(&sampler_views
[0], samplers
->y
);
238 pipe_sampler_view_reference(&sampler_views
[1], samplers
->cb
);
239 pipe_sampler_view_reference(&sampler_views
[2], samplers
->cr
);
243 vl_mpeg12_destroy(struct pipe_video_context
*vpipe
)
245 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
249 /* Asserted in softpipe_delete_fs_state() for some reason */
250 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
251 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
253 ctx
->pipe
->delete_blend_state(ctx
->pipe
, ctx
->blend
);
254 ctx
->pipe
->delete_rasterizer_state(ctx
->pipe
, ctx
->rast
);
255 ctx
->pipe
->delete_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
257 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc
);
258 vl_idct_cleanup(&ctx
->idct_y
);
259 vl_idct_cleanup(&ctx
->idct_c
);
260 ctx
->pipe
->delete_vertex_elements_state(ctx
->pipe
, ctx
->ves_y
);
261 ctx
->pipe
->delete_vertex_elements_state(ctx
->pipe
, ctx
->ves_cb
);
262 ctx
->pipe
->delete_vertex_elements_state(ctx
->pipe
, ctx
->ves_cr
);
263 pipe_resource_reference(&ctx
->quads
.buffer
, NULL
);
264 ctx
->pipe
->destroy(ctx
->pipe
);
270 vl_mpeg12_get_param(struct pipe_video_context
*vpipe
, int param
)
272 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
276 if (param
== PIPE_CAP_NPOT_TEXTURES
)
277 return !ctx
->pot_buffers
;
279 debug_printf("vl_mpeg12_context: Unknown PIPE_CAP %d\n", param
);
283 static struct pipe_surface
*
284 vl_mpeg12_create_surface(struct pipe_video_context
*vpipe
,
285 struct pipe_resource
*resource
,
286 const struct pipe_surface
*templ
)
288 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
292 return ctx
->pipe
->create_surface(ctx
->pipe
, resource
, templ
);
295 static struct pipe_sampler_view
*
296 vl_mpeg12_create_sampler_view(struct pipe_video_context
*vpipe
,
297 struct pipe_resource
*resource
,
298 const struct pipe_sampler_view
*templ
)
300 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
304 return ctx
->pipe
->create_sampler_view(ctx
->pipe
, resource
, templ
);
307 static struct pipe_video_buffer
*
308 vl_mpeg12_create_buffer(struct pipe_video_context
*vpipe
)
310 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
311 struct vl_mpeg12_buffer
*buffer
;
313 struct vl_ycbcr_sampler_views
*idct_views
, *mc_views
;
314 struct vl_ycbcr_surfaces
*idct_surfaces
;
318 buffer
= CALLOC_STRUCT(vl_mpeg12_buffer
);
322 buffer
->base
.context
= vpipe
;
323 buffer
->base
.destroy
= vl_mpeg12_buffer_destroy
;
324 buffer
->base
.map
= vl_mpeg12_buffer_map
;
325 buffer
->base
.add_macroblocks
= vl_mpeg12_buffer_add_macroblocks
;
326 buffer
->base
.unmap
= vl_mpeg12_buffer_unmap
;
327 buffer
->base
.flush
= vl_mpeg12_buffer_flush
;
328 buffer
->base
.get_sampler_views
= vl_mpeg12_buffer_get_sampler_views
;
330 buffer
->vertex_bufs
.individual
.quad
.stride
= ctx
->quads
.stride
;
331 buffer
->vertex_bufs
.individual
.quad
.buffer_offset
= ctx
->quads
.buffer_offset
;
332 pipe_resource_reference(&buffer
->vertex_bufs
.individual
.quad
.buffer
, ctx
->quads
.buffer
);
334 buffer
->vertex_bufs
.individual
.stream
= vl_vb_init(&buffer
->vertex_stream
, ctx
->pipe
,
335 ctx
->vertex_buffer_size
);
336 if (!buffer
->vertex_bufs
.individual
.stream
.buffer
)
337 goto error_vertex_stream
;
339 if (!vl_ycbcr_buffer_init(&buffer
->idct_source
, ctx
->pipe
,
340 ctx
->buffer_width
, ctx
->buffer_height
,
341 ctx
->base
.chroma_format
,
342 PIPE_FORMAT_R16G16B16A16_SNORM
,
344 goto error_idct_source
;
346 if (!vl_ycbcr_buffer_init(&buffer
->idct_2_mc
, ctx
->pipe
,
347 ctx
->buffer_width
, ctx
->buffer_height
,
348 ctx
->base
.chroma_format
,
349 PIPE_FORMAT_R16_SNORM
,
351 goto error_idct_2_mc
;
353 if (!vl_ycbcr_buffer_init(&buffer
->render_result
, ctx
->pipe
,
354 ctx
->buffer_width
, ctx
->buffer_height
,
355 ctx
->base
.chroma_format
,
356 PIPE_FORMAT_R8_SNORM
,
358 goto error_render_result
;
360 idct_views
= vl_ycbcr_get_sampler_views(&buffer
->idct_source
);
362 goto error_idct_views
;
364 idct_surfaces
= vl_ycbcr_get_surfaces(&buffer
->idct_2_mc
);
366 goto error_idct_surfaces
;
368 if (!vl_idct_init_buffer(&ctx
->idct_y
, &buffer
->idct_y
,
369 idct_views
->y
, idct_surfaces
->y
))
372 if (!vl_idct_init_buffer(&ctx
->idct_c
, &buffer
->idct_cb
,
373 idct_views
->cb
, idct_surfaces
->cb
))
376 if (!vl_idct_init_buffer(&ctx
->idct_c
, &buffer
->idct_cr
,
377 idct_views
->cr
, idct_surfaces
->cr
))
380 mc_views
= vl_ycbcr_get_sampler_views(&buffer
->idct_2_mc
);
384 if(!vl_mpeg12_mc_init_buffer(&ctx
->mc
, &buffer
->mc_y
, mc_views
->y
))
387 if(!vl_mpeg12_mc_init_buffer(&ctx
->mc
, &buffer
->mc_cb
, mc_views
->cb
))
390 if(!vl_mpeg12_mc_init_buffer(&ctx
->mc
, &buffer
->mc_cr
, mc_views
->cr
))
393 return &buffer
->base
;
396 vl_mpeg12_mc_cleanup_buffer(&buffer
->mc_cb
);
399 vl_mpeg12_mc_cleanup_buffer(&buffer
->mc_y
);
403 vl_idct_cleanup_buffer(&ctx
->idct_c
, &buffer
->idct_cr
);
406 vl_idct_cleanup_buffer(&ctx
->idct_c
, &buffer
->idct_cb
);
409 vl_idct_cleanup_buffer(&ctx
->idct_y
, &buffer
->idct_y
);
414 vl_ycbcr_buffer_cleanup(&buffer
->render_result
);
417 vl_ycbcr_buffer_cleanup(&buffer
->idct_2_mc
);
420 vl_ycbcr_buffer_cleanup(&buffer
->idct_source
);
423 vl_vb_cleanup(&buffer
->vertex_stream
);
431 vl_mpeg12_is_format_supported(struct pipe_video_context
*vpipe
,
432 enum pipe_format format
,
435 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
439 return ctx
->pipe
->screen
->is_format_supported(ctx
->pipe
->screen
, format
,
445 vl_mpeg12_clear_sampler(struct pipe_video_context
*vpipe
,
446 struct pipe_sampler_view
*dst
,
447 const struct pipe_box
*dst_box
,
450 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
451 struct pipe_transfer
*transfer
;
461 transfer
= ctx
->pipe
->get_transfer(ctx
->pipe
, dst
->texture
, 0, PIPE_TRANSFER_WRITE
, dst_box
);
465 map
= ctx
->pipe
->transfer_map(ctx
->pipe
, transfer
);
469 for ( i
= 0; i
< 4; ++i
)
472 util_fill_rect(map
, dst
->texture
->format
, transfer
->stride
, 0, 0,
473 dst_box
->width
, dst_box
->height
, &uc
);
475 ctx
->pipe
->transfer_unmap(ctx
->pipe
, transfer
);
478 ctx
->pipe
->transfer_destroy(ctx
->pipe
, transfer
);
482 vl_mpeg12_upload_sampler(struct pipe_video_context
*vpipe
,
483 struct pipe_sampler_view
*dst
,
484 const struct pipe_box
*dst_box
,
485 const void *src
, unsigned src_stride
,
486 unsigned src_x
, unsigned src_y
)
488 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
489 struct pipe_transfer
*transfer
;
497 transfer
= ctx
->pipe
->get_transfer(ctx
->pipe
, dst
->texture
, 0, PIPE_TRANSFER_WRITE
, dst_box
);
501 map
= ctx
->pipe
->transfer_map(ctx
->pipe
, transfer
);
505 util_copy_rect(map
, dst
->texture
->format
, transfer
->stride
, 0, 0,
506 dst_box
->width
, dst_box
->height
,
507 src
, src_stride
, src_x
, src_y
);
509 ctx
->pipe
->transfer_unmap(ctx
->pipe
, transfer
);
512 ctx
->pipe
->transfer_destroy(ctx
->pipe
, transfer
);
515 static struct pipe_video_compositor
*
516 vl_mpeg12_create_compositor(struct pipe_video_context
*vpipe
)
518 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
522 return vl_compositor_init(vpipe
, ctx
->pipe
);
526 init_pipe_state(struct vl_mpeg12_context
*ctx
)
528 struct pipe_rasterizer_state rast
;
529 struct pipe_blend_state blend
;
530 struct pipe_depth_stencil_alpha_state dsa
;
535 memset(&rast
, 0, sizeof rast
);
537 rast
.flatshade_first
= 0;
538 rast
.light_twoside
= 0;
540 rast
.cull_face
= PIPE_FACE_NONE
;
541 rast
.fill_back
= PIPE_POLYGON_MODE_FILL
;
542 rast
.fill_front
= PIPE_POLYGON_MODE_FILL
;
543 rast
.offset_point
= 0;
544 rast
.offset_line
= 0;
546 rast
.poly_smooth
= 0;
547 rast
.poly_stipple_enable
= 0;
548 rast
.sprite_coord_enable
= 0;
549 rast
.point_size_per_vertex
= 0;
550 rast
.multisample
= 0;
551 rast
.line_smooth
= 0;
552 rast
.line_stipple_enable
= 0;
553 rast
.line_stipple_factor
= 0;
554 rast
.line_stipple_pattern
= 0;
555 rast
.line_last_pixel
= 0;
557 rast
.point_smooth
= 0;
558 rast
.point_quad_rasterization
= 0;
559 rast
.point_size_per_vertex
= 1;
560 rast
.offset_units
= 1;
561 rast
.offset_scale
= 1;
562 rast
.gl_rasterization_rules
= 1;
564 ctx
->rast
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &rast
);
565 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rast
);
567 memset(&blend
, 0, sizeof blend
);
569 blend
.independent_blend_enable
= 0;
570 blend
.rt
[0].blend_enable
= 0;
571 blend
.rt
[0].rgb_func
= PIPE_BLEND_ADD
;
572 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
573 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ONE
;
574 blend
.rt
[0].alpha_func
= PIPE_BLEND_ADD
;
575 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
576 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ONE
;
577 blend
.logicop_enable
= 0;
578 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
579 /* Needed to allow color writes to FB, even if blending disabled */
580 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
582 ctx
->blend
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &blend
);
584 memset(&dsa
, 0, sizeof dsa
);
585 dsa
.depth
.enabled
= 0;
586 dsa
.depth
.writemask
= 0;
587 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
588 for (i
= 0; i
< 2; ++i
) {
589 dsa
.stencil
[i
].enabled
= 0;
590 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
591 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
592 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
593 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
594 dsa
.stencil
[i
].valuemask
= 0;
595 dsa
.stencil
[i
].writemask
= 0;
597 dsa
.alpha
.enabled
= 0;
598 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
599 dsa
.alpha
.ref_value
= 0;
600 ctx
->dsa
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &dsa
);
601 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
607 init_idct(struct vl_mpeg12_context
*ctx
, unsigned buffer_width
, unsigned buffer_height
)
609 unsigned chroma_width
, chroma_height
, chroma_blocks_x
, chroma_blocks_y
;
610 struct pipe_sampler_view
*idct_matrix
;
612 /* TODO: Implement 422, 444 */
613 assert(ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
614 ctx
->empty_block_mask
= &const_empty_block_mask_420
;
616 if (!(idct_matrix
= vl_idct_upload_matrix(ctx
->pipe
)))
617 goto error_idct_matrix
;
619 if (!vl_idct_init(&ctx
->idct_y
, ctx
->pipe
, buffer_width
, buffer_height
,
623 if (ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
) {
624 chroma_width
= buffer_width
/ 2;
625 chroma_height
= buffer_height
/ 2;
628 } else if (ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_422
) {
629 chroma_width
= buffer_width
;
630 chroma_height
= buffer_height
/ 2;
634 chroma_width
= buffer_width
;
635 chroma_height
= buffer_height
;
640 if(!vl_idct_init(&ctx
->idct_c
, ctx
->pipe
, chroma_width
, chroma_height
,
641 chroma_blocks_x
, chroma_blocks_y
, idct_matrix
))
644 pipe_sampler_view_reference(&idct_matrix
, NULL
);
648 vl_idct_cleanup(&ctx
->idct_y
);
651 pipe_sampler_view_reference(&idct_matrix
, NULL
);
657 struct pipe_video_context
*
658 vl_create_mpeg12_context(struct pipe_context
*pipe
,
659 enum pipe_video_profile profile
,
660 enum pipe_video_chroma_format chroma_format
,
661 unsigned width
, unsigned height
,
664 struct vl_mpeg12_context
*ctx
;
666 assert(u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG12
);
668 ctx
= CALLOC_STRUCT(vl_mpeg12_context
);
673 ctx
->base
.profile
= profile
;
674 ctx
->base
.chroma_format
= chroma_format
;
675 ctx
->base
.width
= width
;
676 ctx
->base
.height
= height
;
678 ctx
->base
.screen
= pipe
->screen
;
680 ctx
->base
.destroy
= vl_mpeg12_destroy
;
681 ctx
->base
.get_param
= vl_mpeg12_get_param
;
682 ctx
->base
.is_format_supported
= vl_mpeg12_is_format_supported
;
683 ctx
->base
.create_surface
= vl_mpeg12_create_surface
;
684 ctx
->base
.create_sampler_view
= vl_mpeg12_create_sampler_view
;
685 ctx
->base
.create_buffer
= vl_mpeg12_create_buffer
;
686 ctx
->base
.clear_sampler
= vl_mpeg12_clear_sampler
;
687 ctx
->base
.upload_sampler
= vl_mpeg12_upload_sampler
;
688 ctx
->base
.create_compositor
= vl_mpeg12_create_compositor
;
691 ctx
->pot_buffers
= pot_buffers
;
693 ctx
->quads
= vl_vb_upload_quads(ctx
->pipe
, 2, 2);
694 ctx
->vertex_buffer_size
= width
/ MACROBLOCK_WIDTH
* height
/ MACROBLOCK_HEIGHT
;
695 ctx
->ves_y
= vl_vb_get_elems_state(ctx
->pipe
, TGSI_SWIZZLE_X
);
696 ctx
->ves_cb
= vl_vb_get_elems_state(ctx
->pipe
, TGSI_SWIZZLE_Y
);
697 ctx
->ves_cr
= vl_vb_get_elems_state(ctx
->pipe
, TGSI_SWIZZLE_Z
);
699 ctx
->buffer_width
= pot_buffers
? util_next_power_of_two(width
) : align(width
, MACROBLOCK_WIDTH
);
700 ctx
->buffer_height
= pot_buffers
? util_next_power_of_two(height
) : align(height
, MACROBLOCK_HEIGHT
);
702 if (!init_idct(ctx
, ctx
->buffer_width
, ctx
->buffer_height
))
705 if (!vl_mpeg12_mc_renderer_init(&ctx
->mc
, ctx
->pipe
, ctx
->buffer_width
, ctx
->buffer_height
))
708 if (!init_pipe_state(ctx
))
709 goto error_pipe_state
;
714 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc
);
717 vl_idct_cleanup(&ctx
->idct_y
);
718 vl_idct_cleanup(&ctx
->idct_c
);
721 ctx
->pipe
->destroy(ctx
->pipe
);