2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
34 #include <va/va_backend.h>
36 #include "intel_batchbuffer.h"
37 #include "intel_driver.h"
38 #include "i965_defines.h"
39 #include "i965_structs.h"
40 #include "i965_drv_video.h"
41 #include "i965_post_processing.h"
42 #include "i965_render.h"
44 #define HAS_PP(ctx) (IS_IRONLAKE((ctx)->intel.device_id) || \
45 IS_GEN6((ctx)->intel.device_id) || \
46 IS_GEN7((ctx)->intel.device_id))
48 #define SURFACE_STATE_PADDED_SIZE_0_I965 ALIGN(sizeof(struct i965_surface_state), 32)
49 #define SURFACE_STATE_PADDED_SIZE_1_I965 ALIGN(sizeof(struct i965_surface_state2), 32)
50 #define SURFACE_STATE_PADDED_SIZE_I965 MAX(SURFACE_STATE_PADDED_SIZE_0_I965, SURFACE_STATE_PADDED_SIZE_1_I965)
52 #define SURFACE_STATE_PADDED_SIZE SURFACE_STATE_PADDED_SIZE_I965
53 #define SURFACE_STATE_OFFSET(index) (SURFACE_STATE_PADDED_SIZE * index)
54 #define BINDING_TABLE_OFFSET SURFACE_STATE_OFFSET(MAX_PP_SURFACES)
56 static const uint32_t pp_null_gen5[][4] = {
57 #include "shaders/post_processing/gen5_6/null.g4b.gen5"
60 static const uint32_t pp_nv12_load_save_nv12_gen5[][4] = {
61 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g4b.gen5"
64 static const uint32_t pp_nv12_load_save_pl3_gen5[][4] = {
65 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g4b.gen5"
68 static const uint32_t pp_pl3_load_save_nv12_gen5[][4] = {
69 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g4b.gen5"
72 static const uint32_t pp_pl3_load_save_pl3_gen5[][4] = {
73 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g4b.gen5"
76 static const uint32_t pp_nv12_scaling_gen5[][4] = {
77 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g4b.gen5"
80 static const uint32_t pp_nv12_avs_gen5[][4] = {
81 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g4b.gen5"
84 static const uint32_t pp_nv12_dndi_gen5[][4] = {
85 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g4b.gen5"
88 static const uint32_t pp_nv12_dn_gen5[][4] = {
89 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g4b.gen5"
92 static VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
93 const struct i965_surface *src_surface,
94 const VARectangle *src_rect,
95 struct i965_surface *dst_surface,
96 const VARectangle *dst_rect,
98 static VAStatus pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
99 const struct i965_surface *src_surface,
100 const VARectangle *src_rect,
101 struct i965_surface *dst_surface,
102 const VARectangle *dst_rect,
104 static VAStatus pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
105 const struct i965_surface *src_surface,
106 const VARectangle *src_rect,
107 struct i965_surface *dst_surface,
108 const VARectangle *dst_rect,
110 static VAStatus pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
111 const struct i965_surface *src_surface,
112 const VARectangle *src_rect,
113 struct i965_surface *dst_surface,
114 const VARectangle *dst_rect,
116 static VAStatus pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
117 const struct i965_surface *src_surface,
118 const VARectangle *src_rect,
119 struct i965_surface *dst_surface,
120 const VARectangle *dst_rect,
122 static VAStatus pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
123 const struct i965_surface *src_surface,
124 const VARectangle *src_rect,
125 struct i965_surface *dst_surface,
126 const VARectangle *dst_rect,
129 static struct pp_module pp_modules_gen5[] = {
132 "NULL module (for testing)",
135 sizeof(pp_null_gen5),
145 PP_NV12_LOAD_SAVE_N12,
146 pp_nv12_load_save_nv12_gen5,
147 sizeof(pp_nv12_load_save_nv12_gen5),
151 pp_plx_load_save_plx_initialize,
157 PP_NV12_LOAD_SAVE_PL3,
158 pp_nv12_load_save_pl3_gen5,
159 sizeof(pp_nv12_load_save_pl3_gen5),
163 pp_plx_load_save_plx_initialize,
169 PP_PL3_LOAD_SAVE_N12,
170 pp_pl3_load_save_nv12_gen5,
171 sizeof(pp_pl3_load_save_nv12_gen5),
175 pp_plx_load_save_plx_initialize,
181 PP_PL3_LOAD_SAVE_N12,
182 pp_pl3_load_save_pl3_gen5,
183 sizeof(pp_pl3_load_save_pl3_gen5),
187 pp_plx_load_save_plx_initialize
192 "NV12 Scaling module",
194 pp_nv12_scaling_gen5,
195 sizeof(pp_nv12_scaling_gen5),
199 pp_nv12_scaling_initialize,
207 sizeof(pp_nv12_avs_gen5),
211 pp_nv12_avs_initialize,
219 sizeof(pp_nv12_dndi_gen5),
223 pp_nv12_dndi_initialize,
231 sizeof(pp_nv12_dn_gen5),
235 pp_nv12_dn_initialize,
239 static const uint32_t pp_null_gen6[][4] = {
240 #include "shaders/post_processing/gen5_6/null.g6b"
243 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
244 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
247 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
248 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
251 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
252 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
255 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
256 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
259 static const uint32_t pp_nv12_scaling_gen6[][4] = {
260 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g6b"
263 static const uint32_t pp_nv12_avs_gen6[][4] = {
264 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
267 static const uint32_t pp_nv12_dndi_gen6[][4] = {
268 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
271 static const uint32_t pp_nv12_dn_gen6[][4] = {
272 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g6b"
275 static struct pp_module pp_modules_gen6[] = {
278 "NULL module (for testing)",
281 sizeof(pp_null_gen6),
291 PP_NV12_LOAD_SAVE_N12,
292 pp_nv12_load_save_nv12_gen6,
293 sizeof(pp_nv12_load_save_nv12_gen6),
297 pp_plx_load_save_plx_initialize,
303 PP_NV12_LOAD_SAVE_PL3,
304 pp_nv12_load_save_pl3_gen6,
305 sizeof(pp_nv12_load_save_pl3_gen6),
309 pp_plx_load_save_plx_initialize,
315 PP_PL3_LOAD_SAVE_N12,
316 pp_pl3_load_save_nv12_gen6,
317 sizeof(pp_pl3_load_save_nv12_gen6),
321 pp_plx_load_save_plx_initialize,
327 PP_PL3_LOAD_SAVE_N12,
328 pp_pl3_load_save_pl3_gen6,
329 sizeof(pp_pl3_load_save_pl3_gen6),
333 pp_plx_load_save_plx_initialize,
338 "NV12 Scaling module",
340 pp_nv12_scaling_gen6,
341 sizeof(pp_nv12_scaling_gen6),
345 pp_nv12_scaling_initialize,
353 sizeof(pp_nv12_avs_gen6),
357 pp_nv12_avs_initialize,
365 sizeof(pp_nv12_dndi_gen6),
369 pp_nv12_dndi_initialize,
377 sizeof(pp_nv12_dn_gen6),
381 pp_nv12_dn_initialize,
385 #define pp_static_parameter pp_context->pp_static_parameter
386 #define pp_inline_parameter pp_context->pp_inline_parameter
389 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
391 struct i965_driver_data *i965 = i965_driver_data(ctx);
394 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
395 struct object_image *obj_image = IMAGE(surface->id);
396 fourcc = obj_image->image.format.fourcc;
398 struct object_surface *obj_surface = SURFACE(surface->id);
399 fourcc = obj_surface->fourcc;
406 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
409 case I915_TILING_NONE:
410 ss->ss3.tiled_surface = 0;
411 ss->ss3.tile_walk = 0;
414 ss->ss3.tiled_surface = 1;
415 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
418 ss->ss3.tiled_surface = 1;
419 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
425 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
428 case I915_TILING_NONE:
429 ss->ss2.tiled_surface = 0;
430 ss->ss2.tile_walk = 0;
433 ss->ss2.tiled_surface = 1;
434 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
437 ss->ss2.tiled_surface = 1;
438 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
444 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
446 struct i965_interface_descriptor *desc;
448 int pp_index = pp_context->current_pp;
450 bo = pp_context->idrt.bo;
454 memset(desc, 0, sizeof(*desc));
455 desc->desc0.grf_reg_blocks = 10;
456 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
457 desc->desc1.const_urb_entry_read_offset = 0;
458 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
459 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
460 desc->desc2.sampler_count = 0;
461 desc->desc3.binding_table_entry_count = 0;
462 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
464 dri_bo_emit_reloc(bo,
465 I915_GEM_DOMAIN_INSTRUCTION, 0,
466 desc->desc0.grf_reg_blocks,
467 offsetof(struct i965_interface_descriptor, desc0),
468 pp_context->pp_modules[pp_index].kernel.bo);
470 dri_bo_emit_reloc(bo,
471 I915_GEM_DOMAIN_INSTRUCTION, 0,
472 desc->desc2.sampler_count << 2,
473 offsetof(struct i965_interface_descriptor, desc2),
474 pp_context->sampler_state_table.bo);
477 pp_context->idrt.num_interface_descriptors++;
481 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
483 struct i965_vfe_state *vfe_state;
486 bo = pp_context->vfe_state.bo;
489 vfe_state = bo->virtual;
490 memset(vfe_state, 0, sizeof(*vfe_state));
491 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
492 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
493 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
494 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
495 vfe_state->vfe1.children_present = 0;
496 vfe_state->vfe2.interface_descriptor_base =
497 pp_context->idrt.bo->offset >> 4; /* reloc */
498 dri_bo_emit_reloc(bo,
499 I915_GEM_DOMAIN_INSTRUCTION, 0,
501 offsetof(struct i965_vfe_state, vfe2),
502 pp_context->idrt.bo);
507 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
509 unsigned char *constant_buffer;
511 assert(sizeof(pp_static_parameter) == 128);
512 dri_bo_map(pp_context->curbe.bo, 1);
513 assert(pp_context->curbe.bo->virtual);
514 constant_buffer = pp_context->curbe.bo->virtual;
515 memcpy(constant_buffer, &pp_static_parameter, sizeof(pp_static_parameter));
516 dri_bo_unmap(pp_context->curbe.bo);
520 ironlake_pp_states_setup(VADriverContextP ctx,
521 struct i965_post_processing_context *pp_context)
523 ironlake_pp_interface_descriptor_table(pp_context);
524 ironlake_pp_vfe_state(pp_context);
525 ironlake_pp_upload_constants(pp_context);
529 ironlake_pp_pipeline_select(VADriverContextP ctx,
530 struct i965_post_processing_context *pp_context)
532 struct intel_batchbuffer *batch = pp_context->batch;
534 BEGIN_BATCH(batch, 1);
535 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
536 ADVANCE_BATCH(batch);
540 ironlake_pp_urb_layout(VADriverContextP ctx,
541 struct i965_post_processing_context *pp_context)
543 struct intel_batchbuffer *batch = pp_context->batch;
544 unsigned int vfe_fence, cs_fence;
546 vfe_fence = pp_context->urb.cs_start;
547 cs_fence = pp_context->urb.size;
549 BEGIN_BATCH(batch, 3);
550 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
553 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
554 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
555 ADVANCE_BATCH(batch);
559 ironlake_pp_state_base_address(VADriverContextP ctx,
560 struct i965_post_processing_context *pp_context)
562 struct intel_batchbuffer *batch = pp_context->batch;
564 BEGIN_BATCH(batch, 8);
565 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
566 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
567 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
568 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
569 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
570 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
571 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
572 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
573 ADVANCE_BATCH(batch);
577 ironlake_pp_state_pointers(VADriverContextP ctx,
578 struct i965_post_processing_context *pp_context)
580 struct intel_batchbuffer *batch = pp_context->batch;
582 BEGIN_BATCH(batch, 3);
583 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
585 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
586 ADVANCE_BATCH(batch);
590 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
591 struct i965_post_processing_context *pp_context)
593 struct intel_batchbuffer *batch = pp_context->batch;
595 BEGIN_BATCH(batch, 2);
596 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
598 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
599 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
600 ADVANCE_BATCH(batch);
604 ironlake_pp_constant_buffer(VADriverContextP ctx,
605 struct i965_post_processing_context *pp_context)
607 struct intel_batchbuffer *batch = pp_context->batch;
609 BEGIN_BATCH(batch, 2);
610 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
611 OUT_RELOC(batch, pp_context->curbe.bo,
612 I915_GEM_DOMAIN_INSTRUCTION, 0,
613 pp_context->urb.size_cs_entry - 1);
614 ADVANCE_BATCH(batch);
618 ironlake_pp_object_walker(VADriverContextP ctx,
619 struct i965_post_processing_context *pp_context)
621 struct intel_batchbuffer *batch = pp_context->batch;
622 int x, x_steps, y, y_steps;
624 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
625 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
627 for (y = 0; y < y_steps; y++) {
628 for (x = 0; x < x_steps; x++) {
629 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
630 BEGIN_BATCH(batch, 20);
631 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
633 OUT_BATCH(batch, 0); /* no indirect data */
636 /* inline data grf 5-6 */
637 assert(sizeof(pp_inline_parameter) == 64);
638 intel_batchbuffer_data(batch, &pp_inline_parameter, sizeof(pp_inline_parameter));
640 ADVANCE_BATCH(batch);
647 ironlake_pp_pipeline_setup(VADriverContextP ctx,
648 struct i965_post_processing_context *pp_context)
650 struct intel_batchbuffer *batch = pp_context->batch;
652 intel_batchbuffer_start_atomic(batch, 0x1000);
653 intel_batchbuffer_emit_mi_flush(batch);
654 ironlake_pp_pipeline_select(ctx, pp_context);
655 ironlake_pp_state_base_address(ctx, pp_context);
656 ironlake_pp_state_pointers(ctx, pp_context);
657 ironlake_pp_urb_layout(ctx, pp_context);
658 ironlake_pp_cs_urb_layout(ctx, pp_context);
659 ironlake_pp_constant_buffer(ctx, pp_context);
660 ironlake_pp_object_walker(ctx, pp_context);
661 intel_batchbuffer_end_atomic(batch);
665 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
666 dri_bo *surf_bo, unsigned long surf_bo_offset,
667 int width, int height, int pitch, int format,
668 int index, int is_target)
670 struct i965_surface_state *ss;
673 unsigned int swizzle;
675 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
676 ss_bo = pp_context->surface_state_binding_table.bo;
679 dri_bo_map(ss_bo, True);
680 assert(ss_bo->virtual);
681 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
682 memset(ss, 0, sizeof(*ss));
683 ss->ss0.surface_type = I965_SURFACE_2D;
684 ss->ss0.surface_format = format;
685 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
686 ss->ss2.width = width - 1;
687 ss->ss2.height = height - 1;
688 ss->ss3.pitch = pitch - 1;
689 pp_set_surface_tiling(ss, tiling);
690 dri_bo_emit_reloc(ss_bo,
691 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
693 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
695 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
700 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
701 dri_bo *surf_bo, unsigned long surf_bo_offset,
702 int width, int height, int wpitch,
703 int xoffset, int yoffset,
704 int format, int interleave_chroma,
707 struct i965_surface_state2 *ss2;
710 unsigned int swizzle;
712 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
713 ss2_bo = pp_context->surface_state_binding_table.bo;
716 dri_bo_map(ss2_bo, True);
717 assert(ss2_bo->virtual);
718 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
719 memset(ss2, 0, sizeof(*ss2));
720 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
721 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
722 ss2->ss1.width = width - 1;
723 ss2->ss1.height = height - 1;
724 ss2->ss2.pitch = wpitch - 1;
725 ss2->ss2.interleave_chroma = interleave_chroma;
726 ss2->ss2.surface_format = format;
727 ss2->ss3.x_offset_for_cb = xoffset;
728 ss2->ss3.y_offset_for_cb = yoffset;
729 pp_set_surface2_tiling(ss2, tiling);
730 dri_bo_emit_reloc(ss2_bo,
731 I915_GEM_DOMAIN_RENDER, 0,
733 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
735 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
736 dri_bo_unmap(ss2_bo);
740 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
741 const struct i965_surface *surface,
742 int base_index, int is_target,
743 int *width, int *height, int *pitch, int *offset)
745 struct i965_driver_data *i965 = i965_driver_data(ctx);
746 struct object_surface *obj_surface;
747 struct object_image *obj_image;
749 int fourcc = pp_get_surface_fourcc(ctx, surface);
751 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
752 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
754 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
756 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
757 obj_surface = SURFACE(surface->id);
758 bo = obj_surface->bo;
759 width[0] = obj_surface->orig_width;
760 height[0] = obj_surface->orig_height;
761 pitch[0] = obj_surface->width;
764 if (interleaved_uv) {
765 width[1] = obj_surface->orig_width;
766 height[1] = obj_surface->orig_height / 2;
767 pitch[1] = obj_surface->width;
768 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
770 width[1] = obj_surface->orig_width / 2;
771 height[1] = obj_surface->orig_height / 2;
772 pitch[1] = obj_surface->width / 2;
773 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
774 width[2] = obj_surface->orig_width / 2;
775 height[2] = obj_surface->orig_height / 2;
776 pitch[2] = obj_surface->width / 2;
777 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
780 obj_image = IMAGE(surface->id);
782 width[0] = obj_image->image.width;
783 height[0] = obj_image->image.height;
784 pitch[0] = obj_image->image.pitches[0];
785 offset[0] = obj_image->image.offsets[0];
787 if (interleaved_uv) {
788 width[1] = obj_image->image.width;
789 height[1] = obj_image->image.height / 2;
790 pitch[1] = obj_image->image.pitches[1];
791 offset[1] = obj_image->image.offsets[1];
793 width[1] = obj_image->image.width / 2;
794 height[1] = obj_image->image.height / 2;
795 pitch[1] = obj_image->image.pitches[1];
796 offset[1] = obj_image->image.offsets[1];
797 width[2] = obj_image->image.width / 2;
798 height[2] = obj_image->image.height / 2;
799 pitch[2] = obj_image->image.pitches[2];
800 offset[2] = obj_image->image.offsets[2];
805 i965_pp_set_surface_state(ctx, pp_context,
807 width[Y] / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
808 base_index, is_target);
810 if (interleaved_uv) {
811 i965_pp_set_surface_state(ctx, pp_context,
813 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
814 base_index + 1, is_target);
817 i965_pp_set_surface_state(ctx, pp_context,
819 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
820 base_index + 1, is_target);
823 i965_pp_set_surface_state(ctx, pp_context,
825 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
826 base_index + 2, is_target);
832 pp_null_x_steps(void *private_context)
838 pp_null_y_steps(void *private_context)
844 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
850 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
851 const struct i965_surface *src_surface,
852 const VARectangle *src_rect,
853 struct i965_surface *dst_surface,
854 const VARectangle *dst_rect,
857 /* private function & data */
858 pp_context->pp_x_steps = pp_null_x_steps;
859 pp_context->pp_y_steps = pp_null_y_steps;
860 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
862 dst_surface->flags = src_surface->flags;
864 return VA_STATUS_SUCCESS;
868 pp_load_save_x_steps(void *private_context)
874 pp_load_save_y_steps(void *private_context)
876 struct pp_load_save_context *pp_load_save_context = private_context;
878 return pp_load_save_context->dest_h / 8;
882 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
884 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
885 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
886 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16;
887 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8;
893 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
894 const struct i965_surface *src_surface,
895 const VARectangle *src_rect,
896 struct i965_surface *dst_surface,
897 const VARectangle *dst_rect,
900 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->private_context;
901 int width[3], height[3], pitch[3], offset[3];
905 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
906 width, height, pitch, offset);
908 /* destination surface */
909 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
910 width, height, pitch, offset);
912 /* private function & data */
913 pp_context->pp_x_steps = pp_load_save_x_steps;
914 pp_context->pp_y_steps = pp_load_save_y_steps;
915 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
916 pp_load_save_context->dest_h = ALIGN(height[Y], 16);
917 pp_load_save_context->dest_w = ALIGN(width[Y], 16);
919 pp_inline_parameter.grf5.block_count_x = ALIGN(width[Y], 16) / 16; /* 1 x N */
920 pp_inline_parameter.grf5.number_blocks = ALIGN(width[Y], 16) / 16;
922 dst_surface->flags = src_surface->flags;
924 return VA_STATUS_SUCCESS;
928 pp_scaling_x_steps(void *private_context)
934 pp_scaling_y_steps(void *private_context)
936 struct pp_scaling_context *pp_scaling_context = private_context;
938 return pp_scaling_context->dest_h / 8;
942 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
944 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
945 float src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
946 float src_y_steping = pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step;
948 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
949 pp_inline_parameter.grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
950 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
951 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
957 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
958 const struct i965_surface *src_surface,
959 const VARectangle *src_rect,
960 struct i965_surface *dst_surface,
961 const VARectangle *dst_rect,
964 struct i965_driver_data *i965 = i965_driver_data(ctx);
965 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
966 struct object_surface *obj_surface;
967 struct i965_sampler_state *sampler_state;
968 int in_w, in_h, in_wpitch, in_hpitch;
969 int out_w, out_h, out_wpitch, out_hpitch;
972 obj_surface = SURFACE(src_surface->id);
973 in_w = obj_surface->orig_width;
974 in_h = obj_surface->orig_height;
975 in_wpitch = obj_surface->width;
976 in_hpitch = obj_surface->height;
978 /* source Y surface index 1 */
979 i965_pp_set_surface_state(ctx, pp_context,
981 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
984 /* source UV surface index 2 */
985 i965_pp_set_surface_state(ctx, pp_context,
986 obj_surface->bo, in_wpitch * in_hpitch,
987 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
990 /* destination surface */
991 obj_surface = SURFACE(dst_surface->id);
992 out_w = obj_surface->orig_width;
993 out_h = obj_surface->orig_height;
994 out_wpitch = obj_surface->width;
995 out_hpitch = obj_surface->height;
997 /* destination Y surface index 7 */
998 i965_pp_set_surface_state(ctx, pp_context,
1000 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1003 /* destination UV surface index 8 */
1004 i965_pp_set_surface_state(ctx, pp_context,
1005 obj_surface->bo, out_wpitch * out_hpitch,
1006 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1010 dri_bo_map(pp_context->sampler_state_table.bo, True);
1011 assert(pp_context->sampler_state_table.bo->virtual);
1012 sampler_state = pp_context->sampler_state_table.bo->virtual;
1014 /* SIMD16 Y index 1 */
1015 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
1016 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1017 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1018 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1019 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1021 /* SIMD16 UV index 2 */
1022 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
1023 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1024 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1025 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1026 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1028 dri_bo_unmap(pp_context->sampler_state_table.bo);
1030 /* private function & data */
1031 pp_context->pp_x_steps = pp_scaling_x_steps;
1032 pp_context->pp_y_steps = pp_scaling_y_steps;
1033 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
1035 pp_scaling_context->dest_x = dst_rect->x;
1036 pp_scaling_context->dest_y = dst_rect->y;
1037 pp_scaling_context->dest_w = ALIGN(dst_rect->width, 16);
1038 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 16);
1039 pp_scaling_context->src_normalized_x = (float)src_rect->x / in_w / out_w;
1040 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h / out_h;
1042 pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / out_h;
1044 pp_inline_parameter.grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / out_w;
1045 pp_inline_parameter.grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
1046 pp_inline_parameter.grf5.number_blocks = pp_scaling_context->dest_w / 16;
1047 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1048 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1050 dst_surface->flags = src_surface->flags;
1052 return VA_STATUS_SUCCESS;
1056 pp_avs_x_steps(void *private_context)
1058 struct pp_avs_context *pp_avs_context = private_context;
1060 return pp_avs_context->dest_w / 16;
1064 pp_avs_y_steps(void *private_context)
1070 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1072 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1073 float src_x_steping, src_y_steping, video_step_delta;
1074 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
1076 if (tmp_w >= pp_avs_context->dest_w) {
1077 pp_inline_parameter.grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1078 pp_inline_parameter.grf6.video_step_delta = 0;
1081 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
1082 pp_avs_context->src_normalized_x;
1084 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1085 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1086 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1087 16 * 15 * video_step_delta / 2;
1090 int n0, n1, n2, nls_left, nls_right;
1091 int factor_a = 5, factor_b = 4;
1094 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
1095 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
1096 n2 = tmp_w / (16 * factor_a);
1098 nls_right = n1 + n2;
1099 f = (float) n2 * 16 / tmp_w;
1102 pp_inline_parameter.grf6.video_step_delta = 0.0;
1105 pp_inline_parameter.grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
1106 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1108 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1109 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1110 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1111 16 * 15 * video_step_delta / 2;
1115 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
1116 float a = f / (nls_left * 16 * factor_b);
1117 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
1119 pp_inline_parameter.grf6.video_step_delta = b;
1122 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1123 pp_inline_parameter.grf5.normalized_video_x_scaling_step = a;
1125 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1126 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1127 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1128 16 * 15 * video_step_delta / 2;
1129 pp_inline_parameter.grf5.normalized_video_x_scaling_step += 16 * b;
1131 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
1132 /* scale the center linearly */
1133 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1134 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1135 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1136 16 * 15 * video_step_delta / 2;
1137 pp_inline_parameter.grf6.video_step_delta = 0.0;
1138 pp_inline_parameter.grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1140 float a = f / (nls_right * 16 * factor_b);
1141 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
1143 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1144 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1145 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1146 16 * 15 * video_step_delta / 2;
1147 pp_inline_parameter.grf6.video_step_delta = -b;
1149 if (x == (pp_avs_context->dest_w / 16 - nls_right))
1150 pp_inline_parameter.grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
1152 pp_inline_parameter.grf5.normalized_video_x_scaling_step -= b * 16;
1157 src_y_steping = pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step;
1158 pp_inline_parameter.grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
1159 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1160 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
1166 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1167 const struct i965_surface *src_surface,
1168 const VARectangle *src_rect,
1169 struct i965_surface *dst_surface,
1170 const VARectangle *dst_rect,
1173 struct i965_driver_data *i965 = i965_driver_data(ctx);
1174 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1175 struct object_surface *obj_surface;
1176 struct i965_sampler_8x8 *sampler_8x8;
1177 struct i965_sampler_8x8_state *sampler_8x8_state;
1179 int in_w, in_h, in_wpitch, in_hpitch;
1180 int out_w, out_h, out_wpitch, out_hpitch;
1183 obj_surface = SURFACE(src_surface->id);
1184 in_w = obj_surface->orig_width;
1185 in_h = obj_surface->orig_height;
1186 in_wpitch = obj_surface->width;
1187 in_hpitch = obj_surface->height;
1189 /* source Y surface index 1 */
1190 i965_pp_set_surface2_state(ctx, pp_context,
1192 in_w, in_h, in_wpitch,
1194 SURFACE_FORMAT_Y8_UNORM, 0,
1197 /* source UV surface index 2 */
1198 i965_pp_set_surface2_state(ctx, pp_context,
1199 obj_surface->bo, in_wpitch * in_hpitch,
1200 in_w, in_h, in_wpitch,
1202 SURFACE_FORMAT_PLANAR_420_8, 1,
1205 /* destination surface */
1206 obj_surface = SURFACE(dst_surface->id);
1207 out_w = obj_surface->orig_width;
1208 out_h = obj_surface->orig_height;
1209 out_wpitch = obj_surface->width;
1210 out_hpitch = obj_surface->height;
1211 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1213 /* destination Y surface index 7 */
1214 i965_pp_set_surface_state(ctx, pp_context,
1216 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1219 /* destination UV surface index 8 */
1220 i965_pp_set_surface_state(ctx, pp_context,
1221 obj_surface->bo, out_wpitch * out_hpitch,
1222 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1225 /* sampler 8x8 state */
1226 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1227 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1228 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1229 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1230 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1231 sampler_8x8_state->dw136.default_sharpness_level = 0;
1232 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
1233 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1234 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1235 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
1238 dri_bo_map(pp_context->sampler_state_table.bo, True);
1239 assert(pp_context->sampler_state_table.bo->virtual);
1240 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
1241 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
1243 /* sample_8x8 Y index 1 */
1245 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1246 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1247 sampler_8x8[index].dw0.ief_bypass = 0;
1248 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1249 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1250 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1251 sampler_8x8[index].dw2.global_noise_estimation = 22;
1252 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1253 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1254 sampler_8x8[index].dw3.strong_edge_weight = 7;
1255 sampler_8x8[index].dw3.regular_weight = 2;
1256 sampler_8x8[index].dw3.non_edge_weight = 0;
1257 sampler_8x8[index].dw3.gain_factor = 40;
1258 sampler_8x8[index].dw4.steepness_boost = 0;
1259 sampler_8x8[index].dw4.steepness_threshold = 0;
1260 sampler_8x8[index].dw4.mr_boost = 0;
1261 sampler_8x8[index].dw4.mr_threshold = 5;
1262 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1263 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1264 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1265 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1266 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1267 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1268 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1269 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1270 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1271 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1272 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1273 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1274 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1275 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1276 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1277 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1278 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1279 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1280 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1281 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1282 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1283 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1284 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1285 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1286 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1287 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1288 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1289 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1290 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1291 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1292 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1293 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1294 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1295 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1296 sampler_8x8[index].dw13.limiter_boost = 0;
1297 sampler_8x8[index].dw13.minimum_limiter = 10;
1298 sampler_8x8[index].dw13.maximum_limiter = 11;
1299 sampler_8x8[index].dw14.clip_limiter = 130;
1300 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1301 I915_GEM_DOMAIN_RENDER,
1304 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1305 pp_context->sampler_state_table.bo_8x8);
1307 dri_bo_map(pp_context->sampler_state_table.bo_8x8_uv, True);
1308 assert(pp_context->sampler_state_table.bo_8x8_uv->virtual);
1309 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1310 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8_uv->virtual;
1311 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1312 sampler_8x8_state->dw136.default_sharpness_level = 0;
1313 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 0;
1314 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1315 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1316 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8_uv);
1318 /* sample_8x8 UV index 2 */
1320 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1321 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_NEAREST;
1322 sampler_8x8[index].dw0.ief_bypass = 0;
1323 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1324 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1325 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8_uv->offset >> 5;
1326 sampler_8x8[index].dw2.global_noise_estimation = 22;
1327 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1328 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1329 sampler_8x8[index].dw3.strong_edge_weight = 7;
1330 sampler_8x8[index].dw3.regular_weight = 2;
1331 sampler_8x8[index].dw3.non_edge_weight = 0;
1332 sampler_8x8[index].dw3.gain_factor = 40;
1333 sampler_8x8[index].dw4.steepness_boost = 0;
1334 sampler_8x8[index].dw4.steepness_threshold = 0;
1335 sampler_8x8[index].dw4.mr_boost = 0;
1336 sampler_8x8[index].dw4.mr_threshold = 5;
1337 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1338 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1339 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1340 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1341 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1342 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1343 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1344 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1345 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1346 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1347 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1348 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1349 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1350 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1351 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1352 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1353 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1354 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1355 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1356 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1357 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1358 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1359 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1360 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1361 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1362 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1363 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1364 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1365 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1366 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1367 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1368 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1369 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1370 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1371 sampler_8x8[index].dw13.limiter_boost = 0;
1372 sampler_8x8[index].dw13.minimum_limiter = 10;
1373 sampler_8x8[index].dw13.maximum_limiter = 11;
1374 sampler_8x8[index].dw14.clip_limiter = 130;
1375 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1376 I915_GEM_DOMAIN_RENDER,
1379 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1380 pp_context->sampler_state_table.bo_8x8_uv);
1382 dri_bo_unmap(pp_context->sampler_state_table.bo);
1384 /* private function & data */
1385 pp_context->pp_x_steps = pp_avs_x_steps;
1386 pp_context->pp_y_steps = pp_avs_y_steps;
1387 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
1389 pp_avs_context->dest_x = dst_rect->x;
1390 pp_avs_context->dest_y = dst_rect->y;
1391 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
1392 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
1393 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w / out_w;
1394 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h / out_h;
1395 pp_avs_context->src_w = src_rect->width;
1396 pp_avs_context->src_h = src_rect->height;
1398 pp_static_parameter.grf4.r4_2.avs.nlas = 1;
1399 pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / out_h;
1401 pp_inline_parameter.grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / out_w;
1402 pp_inline_parameter.grf5.block_count_x = 1; /* M x 1 */
1403 pp_inline_parameter.grf5.number_blocks = pp_avs_context->dest_h / 8;
1404 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1405 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1406 pp_inline_parameter.grf6.video_step_delta = 0.0;
1408 dst_surface->flags = src_surface->flags;
1410 return VA_STATUS_SUCCESS;
1414 pp_dndi_x_steps(void *private_context)
1420 pp_dndi_y_steps(void *private_context)
1422 struct pp_dndi_context *pp_dndi_context = private_context;
1424 return pp_dndi_context->dest_h / 4;
1428 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1430 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16;
1431 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 4;
1437 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1438 const struct i965_surface *src_surface,
1439 const VARectangle *src_rect,
1440 struct i965_surface *dst_surface,
1441 const VARectangle *dst_rect,
1444 struct i965_driver_data *i965 = i965_driver_data(ctx);
1445 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
1446 struct object_surface *obj_surface;
1447 struct i965_sampler_dndi *sampler_dndi;
1451 int dndi_top_first = 1;
1453 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
1454 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
1456 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
1462 obj_surface = SURFACE(src_surface->id);
1463 orig_w = obj_surface->orig_width;
1464 orig_h = obj_surface->orig_height;
1465 w = obj_surface->width;
1466 h = obj_surface->height;
1468 if (pp_context->stmm.bo == NULL) {
1469 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
1473 assert(pp_context->stmm.bo);
1476 /* source UV surface index 2 */
1477 i965_pp_set_surface_state(ctx, pp_context,
1478 obj_surface->bo, w * h,
1479 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
1482 /* source YUV surface index 4 */
1483 i965_pp_set_surface2_state(ctx, pp_context,
1487 SURFACE_FORMAT_PLANAR_420_8, 1,
1490 /* source STMM surface index 20 */
1491 i965_pp_set_surface_state(ctx, pp_context,
1492 pp_context->stmm.bo, 0,
1493 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
1496 /* destination surface */
1497 obj_surface = SURFACE(dst_surface->id);
1498 orig_w = obj_surface->orig_width;
1499 orig_h = obj_surface->orig_height;
1500 w = obj_surface->width;
1501 h = obj_surface->height;
1503 /* destination Y surface index 7 */
1504 i965_pp_set_surface_state(ctx, pp_context,
1506 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
1509 /* destination UV surface index 8 */
1510 i965_pp_set_surface_state(ctx, pp_context,
1511 obj_surface->bo, w * h,
1512 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
1515 dri_bo_map(pp_context->sampler_state_table.bo, True);
1516 assert(pp_context->sampler_state_table.bo->virtual);
1517 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
1518 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
1520 /* sample dndi index 1 */
1522 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
1523 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
1524 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
1525 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
1527 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
1528 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
1529 sampler_dndi[index].dw1.stmm_c2 = 0;
1530 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
1531 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
1533 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
1534 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
1535 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
1536 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
1538 sampler_dndi[index].dw3.maximum_stmm = 128;
1539 sampler_dndi[index].dw3.multipler_for_vecm = 2;
1540 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
1541 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
1542 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
1544 sampler_dndi[index].dw4.sdi_delta = 8;
1545 sampler_dndi[index].dw4.sdi_threshold = 128;
1546 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
1547 sampler_dndi[index].dw4.stmm_shift_up = 0;
1548 sampler_dndi[index].dw4.stmm_shift_down = 0;
1549 sampler_dndi[index].dw4.minimum_stmm = 0;
1551 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
1552 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
1553 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
1554 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
1556 sampler_dndi[index].dw6.dn_enable = 1;
1557 sampler_dndi[index].dw6.di_enable = 1;
1558 sampler_dndi[index].dw6.di_partial = 0;
1559 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
1560 sampler_dndi[index].dw6.dndi_stream_id = 1;
1561 sampler_dndi[index].dw6.dndi_first_frame = 1;
1562 sampler_dndi[index].dw6.progressive_dn = 0;
1563 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
1564 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
1565 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
1567 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
1568 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
1569 sampler_dndi[index].dw7.vdi_walker_enable = 0;
1570 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
1572 dri_bo_unmap(pp_context->sampler_state_table.bo);
1574 /* private function & data */
1575 pp_context->pp_x_steps = pp_dndi_x_steps;
1576 pp_context->pp_y_steps = pp_dndi_y_steps;
1577 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
1579 pp_static_parameter.grf1.statistics_surface_picth = w / 2;
1580 pp_static_parameter.grf1.r1_6.di.top_field_first = 0;
1581 pp_static_parameter.grf4.r4_2.di.motion_history_coefficient_m2 = 64;
1582 pp_static_parameter.grf4.r4_2.di.motion_history_coefficient_m1 = 192;
1584 pp_inline_parameter.grf5.block_count_x = w / 16; /* 1 x N */
1585 pp_inline_parameter.grf5.number_blocks = w / 16;
1586 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1587 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1589 pp_dndi_context->dest_w = w;
1590 pp_dndi_context->dest_h = h;
1592 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
1594 return VA_STATUS_SUCCESS;
1598 pp_dn_x_steps(void *private_context)
1604 pp_dn_y_steps(void *private_context)
1606 struct pp_dn_context *pp_dn_context = private_context;
1608 return pp_dn_context->dest_h / 8;
1612 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1614 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16;
1615 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8;
1621 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1622 const struct i965_surface *src_surface,
1623 const VARectangle *src_rect,
1624 struct i965_surface *dst_surface,
1625 const VARectangle *dst_rect,
1628 struct i965_driver_data *i965 = i965_driver_data(ctx);
1629 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
1630 struct object_surface *obj_surface;
1631 struct i965_sampler_dndi *sampler_dndi;
1632 VAProcFilterBaseParameterBuffer *dn_filter_param = filter_param;
1636 int dn_strength = 15;
1637 int dndi_top_first = 1;
1638 int dn_progressive = 0;
1640 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
1643 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
1651 if (dn_filter_param) {
1652 int value = dn_filter_param->value;
1660 dn_strength = (int)(value * 31.0F);
1664 obj_surface = SURFACE(src_surface->id);
1665 orig_w = obj_surface->orig_width;
1666 orig_h = obj_surface->orig_height;
1667 w = obj_surface->width;
1668 h = obj_surface->height;
1670 if (pp_context->stmm.bo == NULL) {
1671 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
1675 assert(pp_context->stmm.bo);
1678 /* source UV surface index 2 */
1679 i965_pp_set_surface_state(ctx, pp_context,
1680 obj_surface->bo, w * h,
1681 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
1684 /* source YUV surface index 4 */
1685 i965_pp_set_surface2_state(ctx, pp_context,
1689 SURFACE_FORMAT_PLANAR_420_8, 1,
1692 /* source STMM surface index 20 */
1693 i965_pp_set_surface_state(ctx, pp_context,
1694 pp_context->stmm.bo, 0,
1695 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
1698 /* destination surface */
1699 obj_surface = SURFACE(dst_surface->id);
1700 orig_w = obj_surface->orig_width;
1701 orig_h = obj_surface->orig_height;
1702 w = obj_surface->width;
1703 h = obj_surface->height;
1705 /* destination Y surface index 7 */
1706 i965_pp_set_surface_state(ctx, pp_context,
1708 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
1711 /* destination UV surface index 8 */
1712 i965_pp_set_surface_state(ctx, pp_context,
1713 obj_surface->bo, w * h,
1714 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
1717 dri_bo_map(pp_context->sampler_state_table.bo, True);
1718 assert(pp_context->sampler_state_table.bo->virtual);
1719 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
1720 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
1722 /* sample dndi index 1 */
1724 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
1725 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
1726 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
1727 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
1729 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
1730 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
1731 sampler_dndi[index].dw1.stmm_c2 = 0;
1732 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
1733 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
1735 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
1736 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
1737 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
1738 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
1740 sampler_dndi[index].dw3.maximum_stmm = 128;
1741 sampler_dndi[index].dw3.multipler_for_vecm = 2;
1742 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
1743 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
1744 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
1746 sampler_dndi[index].dw4.sdi_delta = 8;
1747 sampler_dndi[index].dw4.sdi_threshold = 128;
1748 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
1749 sampler_dndi[index].dw4.stmm_shift_up = 0;
1750 sampler_dndi[index].dw4.stmm_shift_down = 0;
1751 sampler_dndi[index].dw4.minimum_stmm = 0;
1753 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
1754 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
1755 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
1756 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
1758 sampler_dndi[index].dw6.dn_enable = 1;
1759 sampler_dndi[index].dw6.di_enable = 0;
1760 sampler_dndi[index].dw6.di_partial = 0;
1761 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
1762 sampler_dndi[index].dw6.dndi_stream_id = 1;
1763 sampler_dndi[index].dw6.dndi_first_frame = 1;
1764 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
1765 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
1766 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
1767 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
1769 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
1770 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
1771 sampler_dndi[index].dw7.vdi_walker_enable = 0;
1772 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
1774 dri_bo_unmap(pp_context->sampler_state_table.bo);
1776 /* private function & data */
1777 pp_context->pp_x_steps = pp_dn_x_steps;
1778 pp_context->pp_y_steps = pp_dn_y_steps;
1779 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
1781 pp_static_parameter.grf1.statistics_surface_picth = w / 2;
1782 pp_static_parameter.grf1.r1_6.di.top_field_first = 0;
1783 pp_static_parameter.grf4.r4_2.di.motion_history_coefficient_m2 = 64;
1784 pp_static_parameter.grf4.r4_2.di.motion_history_coefficient_m1 = 192;
1786 pp_inline_parameter.grf5.block_count_x = w / 16; /* 1 x N */
1787 pp_inline_parameter.grf5.number_blocks = w / 16;
1788 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1789 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1791 pp_dn_context->dest_w = w;
1792 pp_dn_context->dest_h = h;
1794 dst_surface->flags = src_surface->flags;
1796 return VA_STATUS_SUCCESS;
1800 ironlake_pp_initialize(
1801 VADriverContextP ctx,
1802 struct i965_post_processing_context *pp_context,
1803 const struct i965_surface *src_surface,
1804 const VARectangle *src_rect,
1805 struct i965_surface *dst_surface,
1806 const VARectangle *dst_rect,
1812 struct i965_driver_data *i965 = i965_driver_data(ctx);
1813 struct pp_module *pp_module;
1816 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
1817 bo = dri_bo_alloc(i965->intel.bufmgr,
1818 "surface state & binding table",
1819 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
1822 pp_context->surface_state_binding_table.bo = bo;
1824 dri_bo_unreference(pp_context->curbe.bo);
1825 bo = dri_bo_alloc(i965->intel.bufmgr,
1830 pp_context->curbe.bo = bo;
1832 dri_bo_unreference(pp_context->idrt.bo);
1833 bo = dri_bo_alloc(i965->intel.bufmgr,
1834 "interface discriptor",
1835 sizeof(struct i965_interface_descriptor),
1838 pp_context->idrt.bo = bo;
1839 pp_context->idrt.num_interface_descriptors = 0;
1841 dri_bo_unreference(pp_context->sampler_state_table.bo);
1842 bo = dri_bo_alloc(i965->intel.bufmgr,
1843 "sampler state table",
1847 dri_bo_map(bo, True);
1848 memset(bo->virtual, 0, bo->size);
1850 pp_context->sampler_state_table.bo = bo;
1852 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
1853 bo = dri_bo_alloc(i965->intel.bufmgr,
1854 "sampler 8x8 state ",
1858 pp_context->sampler_state_table.bo_8x8 = bo;
1860 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
1861 bo = dri_bo_alloc(i965->intel.bufmgr,
1862 "sampler 8x8 state ",
1866 pp_context->sampler_state_table.bo_8x8_uv = bo;
1868 dri_bo_unreference(pp_context->vfe_state.bo);
1869 bo = dri_bo_alloc(i965->intel.bufmgr,
1871 sizeof(struct i965_vfe_state),
1874 pp_context->vfe_state.bo = bo;
1876 memset(&pp_static_parameter, 0, sizeof(pp_static_parameter));
1877 memset(&pp_inline_parameter, 0, sizeof(pp_inline_parameter));
1878 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
1879 pp_context->current_pp = pp_index;
1880 pp_module = &pp_context->pp_modules[pp_index];
1882 if (pp_module->initialize)
1883 va_status = pp_module->initialize(ctx, pp_context,
1890 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
1896 ironlake_post_processing(
1897 VADriverContextP ctx,
1898 struct i965_post_processing_context *pp_context,
1899 const struct i965_surface *src_surface,
1900 const VARectangle *src_rect,
1901 struct i965_surface *dst_surface,
1902 const VARectangle *dst_rect,
1909 va_status = ironlake_pp_initialize(ctx, pp_context,
1917 if (va_status == VA_STATUS_SUCCESS) {
1918 ironlake_pp_states_setup(ctx, pp_context);
1919 ironlake_pp_pipeline_setup(ctx, pp_context);
1927 VADriverContextP ctx,
1928 struct i965_post_processing_context *pp_context,
1929 const struct i965_surface *src_surface,
1930 const VARectangle *src_rect,
1931 struct i965_surface *dst_surface,
1932 const VARectangle *dst_rect,
1938 struct i965_driver_data *i965 = i965_driver_data(ctx);
1939 struct pp_module *pp_module;
1942 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
1943 bo = dri_bo_alloc(i965->intel.bufmgr,
1944 "surface state & binding table",
1945 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
1948 pp_context->surface_state_binding_table.bo = bo;
1950 dri_bo_unreference(pp_context->curbe.bo);
1951 bo = dri_bo_alloc(i965->intel.bufmgr,
1956 pp_context->curbe.bo = bo;
1958 dri_bo_unreference(pp_context->idrt.bo);
1959 bo = dri_bo_alloc(i965->intel.bufmgr,
1960 "interface discriptor",
1961 sizeof(struct gen6_interface_descriptor_data),
1964 pp_context->idrt.bo = bo;
1965 pp_context->idrt.num_interface_descriptors = 0;
1967 dri_bo_unreference(pp_context->sampler_state_table.bo);
1968 bo = dri_bo_alloc(i965->intel.bufmgr,
1969 "sampler state table",
1973 dri_bo_map(bo, True);
1974 memset(bo->virtual, 0, bo->size);
1976 pp_context->sampler_state_table.bo = bo;
1978 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
1979 bo = dri_bo_alloc(i965->intel.bufmgr,
1980 "sampler 8x8 state ",
1984 pp_context->sampler_state_table.bo_8x8 = bo;
1986 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
1987 bo = dri_bo_alloc(i965->intel.bufmgr,
1988 "sampler 8x8 state ",
1992 pp_context->sampler_state_table.bo_8x8_uv = bo;
1994 dri_bo_unreference(pp_context->vfe_state.bo);
1995 bo = dri_bo_alloc(i965->intel.bufmgr,
1997 sizeof(struct i965_vfe_state),
2000 pp_context->vfe_state.bo = bo;
2002 memset(&pp_static_parameter, 0, sizeof(pp_static_parameter));
2003 memset(&pp_inline_parameter, 0, sizeof(pp_inline_parameter));
2004 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
2005 pp_context->current_pp = pp_index;
2006 pp_module = &pp_context->pp_modules[pp_index];
2008 if (pp_module->initialize)
2009 va_status = pp_module->initialize(ctx, pp_context,
2016 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
2022 gen6_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
2024 struct gen6_interface_descriptor_data *desc;
2026 int pp_index = pp_context->current_pp;
2028 bo = pp_context->idrt.bo;
2029 dri_bo_map(bo, True);
2030 assert(bo->virtual);
2032 memset(desc, 0, sizeof(*desc));
2033 desc->desc0.kernel_start_pointer =
2034 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
2035 desc->desc1.single_program_flow = 1;
2036 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
2037 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
2038 desc->desc2.sampler_state_pointer =
2039 pp_context->sampler_state_table.bo->offset >> 5;
2040 desc->desc3.binding_table_entry_count = 0;
2041 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
2042 desc->desc4.constant_urb_entry_read_offset = 0;
2043 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
2045 dri_bo_emit_reloc(bo,
2046 I915_GEM_DOMAIN_INSTRUCTION, 0,
2048 offsetof(struct gen6_interface_descriptor_data, desc0),
2049 pp_context->pp_modules[pp_index].kernel.bo);
2051 dri_bo_emit_reloc(bo,
2052 I915_GEM_DOMAIN_INSTRUCTION, 0,
2053 desc->desc2.sampler_count << 2,
2054 offsetof(struct gen6_interface_descriptor_data, desc2),
2055 pp_context->sampler_state_table.bo);
2058 pp_context->idrt.num_interface_descriptors++;
2062 gen6_pp_upload_constants(struct i965_post_processing_context *pp_context)
2064 unsigned char *constant_buffer;
2066 assert(sizeof(pp_static_parameter) == 128);
2067 dri_bo_map(pp_context->curbe.bo, 1);
2068 assert(pp_context->curbe.bo->virtual);
2069 constant_buffer = pp_context->curbe.bo->virtual;
2070 memcpy(constant_buffer, &pp_static_parameter, sizeof(pp_static_parameter));
2071 dri_bo_unmap(pp_context->curbe.bo);
2075 gen6_pp_states_setup(VADriverContextP ctx,
2076 struct i965_post_processing_context *pp_context)
2078 gen6_pp_interface_descriptor_table(pp_context);
2079 gen6_pp_upload_constants(pp_context);
2083 gen6_pp_pipeline_select(VADriverContextP ctx,
2084 struct i965_post_processing_context *pp_context)
2086 struct intel_batchbuffer *batch = pp_context->batch;
2088 BEGIN_BATCH(batch, 1);
2089 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
2090 ADVANCE_BATCH(batch);
2094 gen6_pp_state_base_address(VADriverContextP ctx,
2095 struct i965_post_processing_context *pp_context)
2097 struct intel_batchbuffer *batch = pp_context->batch;
2099 BEGIN_BATCH(batch, 10);
2100 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
2101 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2102 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
2103 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2104 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2105 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2106 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2107 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2108 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2109 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
2110 ADVANCE_BATCH(batch);
2114 gen6_pp_vfe_state(VADriverContextP ctx,
2115 struct i965_post_processing_context *pp_context)
2117 struct intel_batchbuffer *batch = pp_context->batch;
2119 BEGIN_BATCH(batch, 8);
2120 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
2121 OUT_BATCH(batch, 0);
2123 (pp_context->urb.num_vfe_entries - 1) << 16 |
2124 pp_context->urb.num_vfe_entries << 8);
2125 OUT_BATCH(batch, 0);
2127 (pp_context->urb.size_vfe_entry * 2) << 16 | /* in 256 bits unit */
2128 (pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 - 1)); /* in 256 bits unit */
2129 OUT_BATCH(batch, 0);
2130 OUT_BATCH(batch, 0);
2131 OUT_BATCH(batch, 0);
2132 ADVANCE_BATCH(batch);
2136 gen6_pp_curbe_load(VADriverContextP ctx,
2137 struct i965_post_processing_context *pp_context)
2139 struct intel_batchbuffer *batch = pp_context->batch;
2141 assert(pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 512 <= pp_context->curbe.bo->size);
2143 BEGIN_BATCH(batch, 4);
2144 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
2145 OUT_BATCH(batch, 0);
2147 pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 512);
2149 pp_context->curbe.bo,
2150 I915_GEM_DOMAIN_INSTRUCTION, 0,
2152 ADVANCE_BATCH(batch);
2156 gen6_interface_descriptor_load(VADriverContextP ctx,
2157 struct i965_post_processing_context *pp_context)
2159 struct intel_batchbuffer *batch = pp_context->batch;
2161 BEGIN_BATCH(batch, 4);
2162 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
2163 OUT_BATCH(batch, 0);
2165 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
2167 pp_context->idrt.bo,
2168 I915_GEM_DOMAIN_INSTRUCTION, 0,
2170 ADVANCE_BATCH(batch);
2174 gen6_pp_object_walker(VADriverContextP ctx,
2175 struct i965_post_processing_context *pp_context)
2177 struct intel_batchbuffer *batch = pp_context->batch;
2178 int x, x_steps, y, y_steps;
2180 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
2181 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
2183 for (y = 0; y < y_steps; y++) {
2184 for (x = 0; x < x_steps; x++) {
2185 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
2186 BEGIN_BATCH(batch, 22);
2187 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 20);
2188 OUT_BATCH(batch, 0);
2189 OUT_BATCH(batch, 0); /* no indirect data */
2190 OUT_BATCH(batch, 0);
2191 OUT_BATCH(batch, 0); /* scoreboard */
2192 OUT_BATCH(batch, 0);
2194 /* inline data grf 5-6 */
2195 assert(sizeof(pp_inline_parameter) == 64);
2196 intel_batchbuffer_data(batch, &pp_inline_parameter, sizeof(pp_inline_parameter));
2198 ADVANCE_BATCH(batch);
2205 gen6_pp_pipeline_setup(VADriverContextP ctx,
2206 struct i965_post_processing_context *pp_context)
2208 struct intel_batchbuffer *batch = pp_context->batch;
2210 intel_batchbuffer_start_atomic(batch, 0x1000);
2211 intel_batchbuffer_emit_mi_flush(batch);
2212 gen6_pp_pipeline_select(ctx, pp_context);
2213 gen6_pp_state_base_address(ctx, pp_context);
2214 gen6_pp_curbe_load(ctx, pp_context);
2215 gen6_interface_descriptor_load(ctx, pp_context);
2216 gen6_pp_vfe_state(ctx, pp_context);
2217 gen6_pp_object_walker(ctx, pp_context);
2218 intel_batchbuffer_end_atomic(batch);
2222 gen6_post_processing(
2223 VADriverContextP ctx,
2224 struct i965_post_processing_context *pp_context,
2225 const struct i965_surface *src_surface,
2226 const VARectangle *src_rect,
2227 struct i965_surface *dst_surface,
2228 const VARectangle *dst_rect,
2235 va_status = gen6_pp_initialize(ctx, pp_context,
2243 if (va_status == VA_STATUS_SUCCESS) {
2244 gen6_pp_states_setup(ctx, pp_context);
2245 gen6_pp_pipeline_setup(ctx, pp_context);
2252 i965_post_processing_internal(
2253 VADriverContextP ctx,
2254 struct i965_post_processing_context *pp_context,
2255 const struct i965_surface *src_surface,
2256 const VARectangle *src_rect,
2257 struct i965_surface *dst_surface,
2258 const VARectangle *dst_rect,
2263 struct i965_driver_data *i965 = i965_driver_data(ctx);
2266 if (IS_GEN6(i965->intel.device_id) ||
2267 IS_GEN7(i965->intel.device_id))
2268 va_status = gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
2270 va_status = ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
2276 i965_DestroySurfaces(VADriverContextP ctx,
2277 VASurfaceID *surface_list,
2280 i965_CreateSurfaces(VADriverContextP ctx,
2285 VASurfaceID *surfaces);
2287 i965_post_processing(
2288 VADriverContextP ctx,
2289 VASurfaceID surface,
2290 const VARectangle *src_rect,
2291 const VARectangle *dst_rect,
2293 int *has_done_scaling
2296 struct i965_driver_data *i965 = i965_driver_data(ctx);
2297 VASurfaceID in_surface_id = surface;
2298 VASurfaceID out_surface_id = VA_INVALID_ID;
2300 *has_done_scaling = 0;
2303 struct object_surface *obj_surface;
2305 struct i965_surface src_surface;
2306 struct i965_surface dst_surface;
2308 obj_surface = SURFACE(in_surface_id);
2310 /* Currently only support post processing for NV12 surface */
2311 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
2312 return out_surface_id;
2314 if (flags & I965_PP_FLAG_DEINTERLACING) {
2315 status = i965_CreateSurfaces(ctx,
2316 obj_surface->orig_width,
2317 obj_surface->orig_height,
2318 VA_RT_FORMAT_YUV420,
2321 assert(status == VA_STATUS_SUCCESS);
2322 obj_surface = SURFACE(out_surface_id);
2323 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2325 src_surface.id = in_surface_id;
2326 src_surface.type = I965_SURFACE_TYPE_SURFACE;
2327 src_surface.flags = (flags & I965_PP_FLAG_DEINTERLACING_TOP_FISRT) ?
2328 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
2329 dst_surface.id = out_surface_id;
2330 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
2331 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
2333 i965_post_processing_internal(ctx, i965->pp_context,
2342 if (flags & I965_PP_FLAG_AVS) {
2343 struct i965_render_state *render_state = &i965->render_state;
2344 struct intel_region *dest_region = render_state->draw_region;
2346 if (out_surface_id != VA_INVALID_ID)
2347 in_surface_id = out_surface_id;
2349 status = i965_CreateSurfaces(ctx,
2351 dest_region->height,
2352 VA_RT_FORMAT_YUV420,
2355 assert(status == VA_STATUS_SUCCESS);
2356 obj_surface = SURFACE(out_surface_id);
2357 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2359 src_surface.id = in_surface_id;
2360 src_surface.type = I965_SURFACE_TYPE_SURFACE;
2361 src_surface.flags = I965_SURFACE_FLAG_FRAME;
2362 dst_surface.id = out_surface_id;
2363 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
2364 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
2366 i965_post_processing_internal(ctx, i965->pp_context,
2374 if (in_surface_id != surface)
2375 i965_DestroySurfaces(ctx, &in_surface_id, 1);
2377 *has_done_scaling = 1;
2381 return out_surface_id;
2385 i965_image_i420_processing(VADriverContextP ctx,
2386 const struct i965_surface *src_surface,
2387 const VARectangle *src_rect,
2388 struct i965_surface *dst_surface,
2389 const VARectangle *dst_rect)
2391 struct i965_driver_data *i965 = i965_driver_data(ctx);
2392 struct i965_post_processing_context *pp_context = i965->pp_context;
2393 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
2395 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
2396 i965_post_processing_internal(ctx, i965->pp_context,
2401 PP_PL3_LOAD_SAVE_N12,
2404 i965_post_processing_internal(ctx, i965->pp_context,
2409 PP_PL3_LOAD_SAVE_PL3,
2413 intel_batchbuffer_flush(pp_context->batch);
2415 return VA_STATUS_SUCCESS;
2419 i965_image_nv12_processing(VADriverContextP ctx,
2420 const struct i965_surface *src_surface,
2421 const VARectangle *src_rect,
2422 struct i965_surface *dst_surface,
2423 const VARectangle *dst_rect)
2425 struct i965_driver_data *i965 = i965_driver_data(ctx);
2426 struct i965_post_processing_context *pp_context = i965->pp_context;
2427 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
2429 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
2430 i965_post_processing_internal(ctx, i965->pp_context,
2435 PP_NV12_LOAD_SAVE_N12,
2438 i965_post_processing_internal(ctx, i965->pp_context,
2443 PP_NV12_LOAD_SAVE_PL3,
2447 intel_batchbuffer_flush(pp_context->batch);
2449 return VA_STATUS_SUCCESS;
2453 i965_image_processing(VADriverContextP ctx,
2454 const struct i965_surface *src_surface,
2455 const VARectangle *src_rect,
2456 struct i965_surface *dst_surface,
2457 const VARectangle *dst_rect)
2459 struct i965_driver_data *i965 = i965_driver_data(ctx);
2460 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
2463 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
2466 case VA_FOURCC('Y', 'V', '1', '2'):
2467 case VA_FOURCC('I', '4', '2', '0'):
2468 status = i965_image_i420_processing(ctx,
2475 case VA_FOURCC('N', 'V', '1', '2'):
2476 status = i965_image_nv12_processing(ctx,
2484 status = VA_STATUS_ERROR_UNIMPLEMENTED;
2493 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
2497 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
2498 pp_context->surface_state_binding_table.bo = NULL;
2500 dri_bo_unreference(pp_context->curbe.bo);
2501 pp_context->curbe.bo = NULL;
2503 dri_bo_unreference(pp_context->sampler_state_table.bo);
2504 pp_context->sampler_state_table.bo = NULL;
2506 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
2507 pp_context->sampler_state_table.bo_8x8 = NULL;
2509 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
2510 pp_context->sampler_state_table.bo_8x8_uv = NULL;
2512 dri_bo_unreference(pp_context->idrt.bo);
2513 pp_context->idrt.bo = NULL;
2514 pp_context->idrt.num_interface_descriptors = 0;
2516 dri_bo_unreference(pp_context->vfe_state.bo);
2517 pp_context->vfe_state.bo = NULL;
2519 dri_bo_unreference(pp_context->stmm.bo);
2520 pp_context->stmm.bo = NULL;
2522 for (i = 0; i < NUM_PP_MODULES; i++) {
2523 struct pp_module *pp_module = &pp_context->pp_modules[i];
2525 dri_bo_unreference(pp_module->kernel.bo);
2526 pp_module->kernel.bo = NULL;
2532 i965_post_processing_terminate(VADriverContextP ctx)
2534 struct i965_driver_data *i965 = i965_driver_data(ctx);
2535 struct i965_post_processing_context *pp_context = i965->pp_context;
2538 i965_post_processing_context_finalize(pp_context);
2542 i965->pp_context = NULL;
2548 i965_post_processing_context_init(VADriverContextP ctx,
2549 struct i965_post_processing_context *pp_context,
2550 struct intel_batchbuffer *batch)
2552 struct i965_driver_data *i965 = i965_driver_data(ctx);
2555 pp_context->urb.size = URB_SIZE((&i965->intel));
2556 pp_context->urb.num_vfe_entries = 32;
2557 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
2558 pp_context->urb.num_cs_entries = 1;
2559 pp_context->urb.size_cs_entry = 2; /* in 512 bits unit */
2560 pp_context->urb.vfe_start = 0;
2561 pp_context->urb.cs_start = pp_context->urb.vfe_start +
2562 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
2563 assert(pp_context->urb.cs_start +
2564 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
2566 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
2567 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
2569 if (IS_GEN6(i965->intel.device_id) ||
2570 IS_GEN7(i965->intel.device_id))
2571 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
2572 else if (IS_IRONLAKE(i965->intel.device_id))
2573 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
2575 for (i = 0; i < NUM_PP_MODULES; i++) {
2576 struct pp_module *pp_module = &pp_context->pp_modules[i];
2577 dri_bo_unreference(pp_module->kernel.bo);
2578 if (pp_module->kernel.bin) {
2579 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
2580 pp_module->kernel.name,
2581 pp_module->kernel.size,
2583 assert(pp_module->kernel.bo);
2584 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
2586 pp_module->kernel.bo = NULL;
2590 pp_context->batch = batch;
2594 i965_post_processing_init(VADriverContextP ctx)
2596 struct i965_driver_data *i965 = i965_driver_data(ctx);
2597 struct i965_post_processing_context *pp_context = i965->pp_context;
2600 if (pp_context == NULL) {
2601 pp_context = calloc(1, sizeof(*pp_context));
2602 i965_post_processing_context_init(ctx, pp_context, i965->batch);
2603 i965->pp_context = pp_context;
2610 static const int procfilter_to_pp_flag[10] = {
2611 PP_NULL, /* VAProcFilterNone */
2612 PP_NULL, /* VAProcFilterDering */
2613 PP_NULL, /* VAProcFilterDeblocking */
2614 PP_NV12_DN, /* VAProcFilterNoiseReduction */
2615 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
2616 PP_NULL, /* VAProcFilterSharpening */
2617 PP_NULL, /* VAProcFilterColorEnhancement */
2618 PP_NULL, /* VAProcFilterProcAmp */
2619 PP_NULL, /* VAProcFilterComposition */
2620 PP_NULL, /* VAProcFilterFrameRateConversion */
2623 static const int proc_frame_to_pp_frame[3] = {
2624 I965_SURFACE_FLAG_FRAME,
2625 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
2626 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
2630 i965_proc_picture(VADriverContextP ctx,
2632 union codec_state *codec_state,
2633 struct hw_context *hw_context)
2635 struct i965_driver_data *i965 = i965_driver_data(ctx);
2636 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
2637 struct proc_state *proc_state = &codec_state->proc;
2638 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
2639 VAProcInputParameterBuffer *input_param = (VAProcInputParameterBuffer *)proc_state->input_param->buffer;
2640 struct object_surface *obj_surface;
2641 struct i965_surface src_surface, dst_surface;
2644 VASurfaceID tmp_surfaces[VA_PROC_PIPELINE_MAX_NUM_FILTERS];
2645 int num_tmp_surfaces = 0;
2647 assert(input_param->surface != VA_INVALID_ID);
2648 assert(proc_state->current_render_target != VA_INVALID_ID);
2650 obj_surface = SURFACE(proc_state->current_render_target);
2651 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2653 obj_surface = SURFACE(input_param->surface);
2654 assert(obj_surface->fourcc == VA_FOURCC('N', 'V', '1', '2'));
2656 src_surface.id = input_param->surface;
2657 src_surface.type = I965_SURFACE_TYPE_SURFACE;
2658 src_surface.flags = proc_frame_to_pp_frame[input_param->flags];
2660 for (i = 0; i < VA_PROC_PIPELINE_MAX_NUM_FILTERS; i++) {
2661 VAProcFilterType filter_type = pipeline_param->filter_pipeline[i];
2662 VASurfaceID out_surface_id = VA_INVALID_ID;
2663 void *filter_param = NULL;
2665 if (procfilter_to_pp_flag[filter_type] != PP_NULL) {
2666 if (proc_state->filter_param[filter_type])
2667 filter_param = proc_state->filter_param[filter_type]->buffer;
2669 status = i965_CreateSurfaces(ctx,
2670 obj_surface->orig_width,
2671 obj_surface->orig_height,
2672 VA_RT_FORMAT_YUV420,
2675 assert(status == VA_STATUS_SUCCESS);
2676 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
2677 obj_surface = SURFACE(out_surface_id);
2678 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2679 dst_surface.id = out_surface_id;
2680 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
2681 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
2683 &input_param->region,
2685 &input_param->region,
2686 procfilter_to_pp_flag[filter_type],
2689 if (status == VA_STATUS_SUCCESS) {
2690 src_surface.id = dst_surface.id;
2691 src_surface.type = dst_surface.type;
2692 src_surface.flags = dst_surface.flags;
2697 dst_surface.id = proc_state->current_render_target;
2698 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
2699 i965_post_processing_internal(ctx, &proc_context->pp_context,
2701 &input_param->region,
2703 &pipeline_param->output_region,
2707 if (num_tmp_surfaces)
2708 i965_DestroySurfaces(ctx,
2712 intel_batchbuffer_flush(hw_context->batch);
2716 i965_proc_context_destroy(void *hw_context)
2718 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
2720 i965_post_processing_context_finalize(&proc_context->pp_context);
2721 intel_batchbuffer_free(proc_context->base.batch);
2726 i965_proc_context_init(VADriverContextP ctx, VAProfile profile)
2728 struct intel_driver_data *intel = intel_driver_data(ctx);
2729 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
2731 proc_context->base.destroy = i965_proc_context_destroy;
2732 proc_context->base.run = i965_proc_picture;
2733 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
2734 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
2736 return (struct hw_context *)proc_context;