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 "intel_batchbuffer.h"
35 #include "intel_driver.h"
36 #include "i965_defines.h"
37 #include "i965_structs.h"
38 #include "i965_drv_video.h"
39 #include "i965_post_processing.h"
40 #include "i965_render.h"
42 #define HAS_PP(ctx) (IS_IRONLAKE((ctx)->intel.device_id) || \
43 IS_GEN6((ctx)->intel.device_id) || \
44 IS_GEN7((ctx)->intel.device_id))
46 #define SURFACE_STATE_PADDED_SIZE_0_I965 ALIGN(sizeof(struct i965_surface_state), 32)
47 #define SURFACE_STATE_PADDED_SIZE_1_I965 ALIGN(sizeof(struct i965_surface_state2), 32)
48 #define SURFACE_STATE_PADDED_SIZE_I965 MAX(SURFACE_STATE_PADDED_SIZE_0_I965, SURFACE_STATE_PADDED_SIZE_1_I965)
50 #define SURFACE_STATE_PADDED_SIZE_0_GEN7 ALIGN(sizeof(struct gen7_surface_state), 32)
51 #define SURFACE_STATE_PADDED_SIZE_1_GEN7 ALIGN(sizeof(struct gen7_surface_state2), 32)
52 #define SURFACE_STATE_PADDED_SIZE_GEN7 MAX(SURFACE_STATE_PADDED_SIZE_0_GEN7, SURFACE_STATE_PADDED_SIZE_1_GEN7)
54 #define SURFACE_STATE_PADDED_SIZE MAX(SURFACE_STATE_PADDED_SIZE_I965, SURFACE_STATE_PADDED_SIZE_GEN7)
55 #define SURFACE_STATE_OFFSET(index) (SURFACE_STATE_PADDED_SIZE * index)
56 #define BINDING_TABLE_OFFSET SURFACE_STATE_OFFSET(MAX_PP_SURFACES)
58 static const uint32_t pp_null_gen5[][4] = {
59 #include "shaders/post_processing/gen5_6/null.g4b.gen5"
62 static const uint32_t pp_nv12_load_save_nv12_gen5[][4] = {
63 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g4b.gen5"
66 static const uint32_t pp_nv12_load_save_pl3_gen5[][4] = {
67 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g4b.gen5"
70 static const uint32_t pp_pl3_load_save_nv12_gen5[][4] = {
71 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g4b.gen5"
74 static const uint32_t pp_pl3_load_save_pl3_gen5[][4] = {
75 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g4b.gen5"
78 static const uint32_t pp_nv12_scaling_gen5[][4] = {
79 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g4b.gen5"
82 static const uint32_t pp_nv12_avs_gen5[][4] = {
83 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g4b.gen5"
86 static const uint32_t pp_nv12_dndi_gen5[][4] = {
87 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g4b.gen5"
90 static const uint32_t pp_nv12_dn_gen5[][4] = {
91 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g4b.gen5"
94 static VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
95 const struct i965_surface *src_surface,
96 const VARectangle *src_rect,
97 struct i965_surface *dst_surface,
98 const VARectangle *dst_rect,
100 static VAStatus pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
101 const struct i965_surface *src_surface,
102 const VARectangle *src_rect,
103 struct i965_surface *dst_surface,
104 const VARectangle *dst_rect,
106 static VAStatus pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
107 const struct i965_surface *src_surface,
108 const VARectangle *src_rect,
109 struct i965_surface *dst_surface,
110 const VARectangle *dst_rect,
112 static VAStatus pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
113 const struct i965_surface *src_surface,
114 const VARectangle *src_rect,
115 struct i965_surface *dst_surface,
116 const VARectangle *dst_rect,
118 static VAStatus pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
119 const struct i965_surface *src_surface,
120 const VARectangle *src_rect,
121 struct i965_surface *dst_surface,
122 const VARectangle *dst_rect,
124 static VAStatus pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
125 const struct i965_surface *src_surface,
126 const VARectangle *src_rect,
127 struct i965_surface *dst_surface,
128 const VARectangle *dst_rect,
131 static struct pp_module pp_modules_gen5[] = {
134 "NULL module (for testing)",
137 sizeof(pp_null_gen5),
147 PP_NV12_LOAD_SAVE_N12,
148 pp_nv12_load_save_nv12_gen5,
149 sizeof(pp_nv12_load_save_nv12_gen5),
153 pp_plx_load_save_plx_initialize,
159 PP_NV12_LOAD_SAVE_PL3,
160 pp_nv12_load_save_pl3_gen5,
161 sizeof(pp_nv12_load_save_pl3_gen5),
165 pp_plx_load_save_plx_initialize,
171 PP_PL3_LOAD_SAVE_N12,
172 pp_pl3_load_save_nv12_gen5,
173 sizeof(pp_pl3_load_save_nv12_gen5),
177 pp_plx_load_save_plx_initialize,
183 PP_PL3_LOAD_SAVE_N12,
184 pp_pl3_load_save_pl3_gen5,
185 sizeof(pp_pl3_load_save_pl3_gen5),
189 pp_plx_load_save_plx_initialize
194 "NV12 Scaling module",
196 pp_nv12_scaling_gen5,
197 sizeof(pp_nv12_scaling_gen5),
201 pp_nv12_scaling_initialize,
209 sizeof(pp_nv12_avs_gen5),
213 pp_nv12_avs_initialize,
221 sizeof(pp_nv12_dndi_gen5),
225 pp_nv12_dndi_initialize,
233 sizeof(pp_nv12_dn_gen5),
237 pp_nv12_dn_initialize,
241 static const uint32_t pp_null_gen6[][4] = {
242 #include "shaders/post_processing/gen5_6/null.g6b"
245 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
246 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
249 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
250 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
253 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
254 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
257 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
258 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
261 static const uint32_t pp_nv12_scaling_gen6[][4] = {
262 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g6b"
265 static const uint32_t pp_nv12_avs_gen6[][4] = {
266 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
269 static const uint32_t pp_nv12_dndi_gen6[][4] = {
270 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
273 static const uint32_t pp_nv12_dn_gen6[][4] = {
274 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g6b"
277 static struct pp_module pp_modules_gen6[] = {
280 "NULL module (for testing)",
283 sizeof(pp_null_gen6),
293 PP_NV12_LOAD_SAVE_N12,
294 pp_nv12_load_save_nv12_gen6,
295 sizeof(pp_nv12_load_save_nv12_gen6),
299 pp_plx_load_save_plx_initialize,
305 PP_NV12_LOAD_SAVE_PL3,
306 pp_nv12_load_save_pl3_gen6,
307 sizeof(pp_nv12_load_save_pl3_gen6),
311 pp_plx_load_save_plx_initialize,
317 PP_PL3_LOAD_SAVE_N12,
318 pp_pl3_load_save_nv12_gen6,
319 sizeof(pp_pl3_load_save_nv12_gen6),
323 pp_plx_load_save_plx_initialize,
329 PP_PL3_LOAD_SAVE_N12,
330 pp_pl3_load_save_pl3_gen6,
331 sizeof(pp_pl3_load_save_pl3_gen6),
335 pp_plx_load_save_plx_initialize,
340 "NV12 Scaling module",
342 pp_nv12_scaling_gen6,
343 sizeof(pp_nv12_scaling_gen6),
347 pp_nv12_scaling_initialize,
355 sizeof(pp_nv12_avs_gen6),
359 pp_nv12_avs_initialize,
367 sizeof(pp_nv12_dndi_gen6),
371 pp_nv12_dndi_initialize,
379 sizeof(pp_nv12_dn_gen6),
383 pp_nv12_dn_initialize,
387 static const uint32_t pp_null_gen7[][4] = {
390 static const uint32_t pp_nv12_load_save_nv12_gen7[][4] = {
393 static const uint32_t pp_nv12_load_save_pl3_gen7[][4] = {
396 static const uint32_t pp_pl3_load_save_nv12_gen7[][4] = {
399 static const uint32_t pp_pl3_load_save_pl3_gen7[][4] = {
402 static const uint32_t pp_nv12_scaling_gen7[][4] = {
403 #include "shaders/post_processing/gen7/avs.g7b"
406 static const uint32_t pp_nv12_avs_gen7[][4] = {
407 #include "shaders/post_processing/gen7/avs.g7b"
410 static const uint32_t pp_nv12_dndi_gen7[][4] = {
411 #include "shaders/post_processing/gen7/dndi.g7b"
414 static const uint32_t pp_nv12_dn_gen7[][4] = {
417 static VAStatus gen7_pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
418 const struct i965_surface *src_surface,
419 const VARectangle *src_rect,
420 struct i965_surface *dst_surface,
421 const VARectangle *dst_rect,
423 static VAStatus gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
424 const struct i965_surface *src_surface,
425 const VARectangle *src_rect,
426 struct i965_surface *dst_surface,
427 const VARectangle *dst_rect,
429 static VAStatus gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
430 const struct i965_surface *src_surface,
431 const VARectangle *src_rect,
432 struct i965_surface *dst_surface,
433 const VARectangle *dst_rect,
436 static struct pp_module pp_modules_gen7[] = {
439 "NULL module (for testing)",
442 sizeof(pp_null_gen7),
452 PP_NV12_LOAD_SAVE_N12,
453 pp_nv12_load_save_nv12_gen7,
454 sizeof(pp_nv12_load_save_nv12_gen7),
458 pp_plx_load_save_plx_initialize,
464 PP_NV12_LOAD_SAVE_PL3,
465 pp_nv12_load_save_pl3_gen7,
466 sizeof(pp_nv12_load_save_pl3_gen7),
470 pp_plx_load_save_plx_initialize,
476 PP_PL3_LOAD_SAVE_N12,
477 pp_pl3_load_save_nv12_gen7,
478 sizeof(pp_pl3_load_save_nv12_gen7),
482 pp_plx_load_save_plx_initialize,
488 PP_PL3_LOAD_SAVE_N12,
489 pp_pl3_load_save_pl3_gen7,
490 sizeof(pp_pl3_load_save_pl3_gen7),
494 pp_plx_load_save_plx_initialize,
499 "NV12 Scaling module",
501 pp_nv12_scaling_gen7,
502 sizeof(pp_nv12_scaling_gen7),
506 gen7_pp_nv12_avs_initialize,
514 sizeof(pp_nv12_avs_gen7),
518 gen7_pp_nv12_avs_initialize,
526 sizeof(pp_nv12_dndi_gen7),
530 gen7_pp_nv12_dndi_initialize,
538 sizeof(pp_nv12_dn_gen7),
542 gen7_pp_nv12_dn_initialize,
547 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
549 struct i965_driver_data *i965 = i965_driver_data(ctx);
552 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
553 struct object_image *obj_image = IMAGE(surface->id);
554 fourcc = obj_image->image.format.fourcc;
556 struct object_surface *obj_surface = SURFACE(surface->id);
557 fourcc = obj_surface->fourcc;
564 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
567 case I915_TILING_NONE:
568 ss->ss3.tiled_surface = 0;
569 ss->ss3.tile_walk = 0;
572 ss->ss3.tiled_surface = 1;
573 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
576 ss->ss3.tiled_surface = 1;
577 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
583 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
586 case I915_TILING_NONE:
587 ss->ss2.tiled_surface = 0;
588 ss->ss2.tile_walk = 0;
591 ss->ss2.tiled_surface = 1;
592 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
595 ss->ss2.tiled_surface = 1;
596 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
602 gen7_pp_set_surface_tiling(struct gen7_surface_state *ss, unsigned int tiling)
605 case I915_TILING_NONE:
606 ss->ss0.tiled_surface = 0;
607 ss->ss0.tile_walk = 0;
610 ss->ss0.tiled_surface = 1;
611 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
614 ss->ss0.tiled_surface = 1;
615 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
621 gen7_pp_set_surface2_tiling(struct gen7_surface_state2 *ss, unsigned int tiling)
624 case I915_TILING_NONE:
625 ss->ss2.tiled_surface = 0;
626 ss->ss2.tile_walk = 0;
629 ss->ss2.tiled_surface = 1;
630 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
633 ss->ss2.tiled_surface = 1;
634 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
640 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
642 struct i965_interface_descriptor *desc;
644 int pp_index = pp_context->current_pp;
646 bo = pp_context->idrt.bo;
650 memset(desc, 0, sizeof(*desc));
651 desc->desc0.grf_reg_blocks = 10;
652 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
653 desc->desc1.const_urb_entry_read_offset = 0;
654 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
655 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
656 desc->desc2.sampler_count = 0;
657 desc->desc3.binding_table_entry_count = 0;
658 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
660 dri_bo_emit_reloc(bo,
661 I915_GEM_DOMAIN_INSTRUCTION, 0,
662 desc->desc0.grf_reg_blocks,
663 offsetof(struct i965_interface_descriptor, desc0),
664 pp_context->pp_modules[pp_index].kernel.bo);
666 dri_bo_emit_reloc(bo,
667 I915_GEM_DOMAIN_INSTRUCTION, 0,
668 desc->desc2.sampler_count << 2,
669 offsetof(struct i965_interface_descriptor, desc2),
670 pp_context->sampler_state_table.bo);
673 pp_context->idrt.num_interface_descriptors++;
677 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
679 struct i965_vfe_state *vfe_state;
682 bo = pp_context->vfe_state.bo;
685 vfe_state = bo->virtual;
686 memset(vfe_state, 0, sizeof(*vfe_state));
687 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
688 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
689 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
690 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
691 vfe_state->vfe1.children_present = 0;
692 vfe_state->vfe2.interface_descriptor_base =
693 pp_context->idrt.bo->offset >> 4; /* reloc */
694 dri_bo_emit_reloc(bo,
695 I915_GEM_DOMAIN_INSTRUCTION, 0,
697 offsetof(struct i965_vfe_state, vfe2),
698 pp_context->idrt.bo);
703 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
705 unsigned char *constant_buffer;
706 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
708 assert(sizeof(*pp_static_parameter) == 128);
709 dri_bo_map(pp_context->curbe.bo, 1);
710 assert(pp_context->curbe.bo->virtual);
711 constant_buffer = pp_context->curbe.bo->virtual;
712 memcpy(constant_buffer, pp_static_parameter, sizeof(*pp_static_parameter));
713 dri_bo_unmap(pp_context->curbe.bo);
717 ironlake_pp_states_setup(VADriverContextP ctx,
718 struct i965_post_processing_context *pp_context)
720 ironlake_pp_interface_descriptor_table(pp_context);
721 ironlake_pp_vfe_state(pp_context);
722 ironlake_pp_upload_constants(pp_context);
726 ironlake_pp_pipeline_select(VADriverContextP ctx,
727 struct i965_post_processing_context *pp_context)
729 struct intel_batchbuffer *batch = pp_context->batch;
731 BEGIN_BATCH(batch, 1);
732 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
733 ADVANCE_BATCH(batch);
737 ironlake_pp_urb_layout(VADriverContextP ctx,
738 struct i965_post_processing_context *pp_context)
740 struct intel_batchbuffer *batch = pp_context->batch;
741 unsigned int vfe_fence, cs_fence;
743 vfe_fence = pp_context->urb.cs_start;
744 cs_fence = pp_context->urb.size;
746 BEGIN_BATCH(batch, 3);
747 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
750 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
751 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
752 ADVANCE_BATCH(batch);
756 ironlake_pp_state_base_address(VADriverContextP ctx,
757 struct i965_post_processing_context *pp_context)
759 struct intel_batchbuffer *batch = pp_context->batch;
761 BEGIN_BATCH(batch, 8);
762 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
763 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
764 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
765 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
766 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
767 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
768 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
769 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
770 ADVANCE_BATCH(batch);
774 ironlake_pp_state_pointers(VADriverContextP ctx,
775 struct i965_post_processing_context *pp_context)
777 struct intel_batchbuffer *batch = pp_context->batch;
779 BEGIN_BATCH(batch, 3);
780 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
782 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
783 ADVANCE_BATCH(batch);
787 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
788 struct i965_post_processing_context *pp_context)
790 struct intel_batchbuffer *batch = pp_context->batch;
792 BEGIN_BATCH(batch, 2);
793 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
795 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
796 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
797 ADVANCE_BATCH(batch);
801 ironlake_pp_constant_buffer(VADriverContextP ctx,
802 struct i965_post_processing_context *pp_context)
804 struct intel_batchbuffer *batch = pp_context->batch;
806 BEGIN_BATCH(batch, 2);
807 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
808 OUT_RELOC(batch, pp_context->curbe.bo,
809 I915_GEM_DOMAIN_INSTRUCTION, 0,
810 pp_context->urb.size_cs_entry - 1);
811 ADVANCE_BATCH(batch);
815 ironlake_pp_object_walker(VADriverContextP ctx,
816 struct i965_post_processing_context *pp_context)
818 struct intel_batchbuffer *batch = pp_context->batch;
819 int x, x_steps, y, y_steps;
820 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
822 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
823 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
825 for (y = 0; y < y_steps; y++) {
826 for (x = 0; x < x_steps; x++) {
827 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
828 BEGIN_BATCH(batch, 20);
829 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
831 OUT_BATCH(batch, 0); /* no indirect data */
834 /* inline data grf 5-6 */
835 assert(sizeof(*pp_inline_parameter) == 64);
836 intel_batchbuffer_data(batch, pp_inline_parameter, sizeof(*pp_inline_parameter));
838 ADVANCE_BATCH(batch);
845 ironlake_pp_pipeline_setup(VADriverContextP ctx,
846 struct i965_post_processing_context *pp_context)
848 struct intel_batchbuffer *batch = pp_context->batch;
850 intel_batchbuffer_start_atomic(batch, 0x1000);
851 intel_batchbuffer_emit_mi_flush(batch);
852 ironlake_pp_pipeline_select(ctx, pp_context);
853 ironlake_pp_state_base_address(ctx, pp_context);
854 ironlake_pp_state_pointers(ctx, pp_context);
855 ironlake_pp_urb_layout(ctx, pp_context);
856 ironlake_pp_cs_urb_layout(ctx, pp_context);
857 ironlake_pp_constant_buffer(ctx, pp_context);
858 ironlake_pp_object_walker(ctx, pp_context);
859 intel_batchbuffer_end_atomic(batch);
863 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
864 dri_bo *surf_bo, unsigned long surf_bo_offset,
865 int width, int height, int pitch, int format,
866 int index, int is_target)
868 struct i965_surface_state *ss;
871 unsigned int swizzle;
873 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
874 ss_bo = pp_context->surface_state_binding_table.bo;
877 dri_bo_map(ss_bo, True);
878 assert(ss_bo->virtual);
879 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
880 memset(ss, 0, sizeof(*ss));
881 ss->ss0.surface_type = I965_SURFACE_2D;
882 ss->ss0.surface_format = format;
883 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
884 ss->ss2.width = width - 1;
885 ss->ss2.height = height - 1;
886 ss->ss3.pitch = pitch - 1;
887 pp_set_surface_tiling(ss, tiling);
888 dri_bo_emit_reloc(ss_bo,
889 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
891 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
893 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
898 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
899 dri_bo *surf_bo, unsigned long surf_bo_offset,
900 int width, int height, int wpitch,
901 int xoffset, int yoffset,
902 int format, int interleave_chroma,
905 struct i965_surface_state2 *ss2;
908 unsigned int swizzle;
910 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
911 ss2_bo = pp_context->surface_state_binding_table.bo;
914 dri_bo_map(ss2_bo, True);
915 assert(ss2_bo->virtual);
916 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
917 memset(ss2, 0, sizeof(*ss2));
918 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
919 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
920 ss2->ss1.width = width - 1;
921 ss2->ss1.height = height - 1;
922 ss2->ss2.pitch = wpitch - 1;
923 ss2->ss2.interleave_chroma = interleave_chroma;
924 ss2->ss2.surface_format = format;
925 ss2->ss3.x_offset_for_cb = xoffset;
926 ss2->ss3.y_offset_for_cb = yoffset;
927 pp_set_surface2_tiling(ss2, tiling);
928 dri_bo_emit_reloc(ss2_bo,
929 I915_GEM_DOMAIN_RENDER, 0,
931 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
933 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
934 dri_bo_unmap(ss2_bo);
938 gen7_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
939 dri_bo *surf_bo, unsigned long surf_bo_offset,
940 int width, int height, int pitch, int format,
941 int index, int is_target)
943 struct gen7_surface_state *ss;
946 unsigned int swizzle;
948 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
949 ss_bo = pp_context->surface_state_binding_table.bo;
952 dri_bo_map(ss_bo, True);
953 assert(ss_bo->virtual);
954 ss = (struct gen7_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
955 memset(ss, 0, sizeof(*ss));
956 ss->ss0.surface_type = I965_SURFACE_2D;
957 ss->ss0.surface_format = format;
958 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
959 ss->ss2.width = width - 1;
960 ss->ss2.height = height - 1;
961 ss->ss3.pitch = pitch - 1;
962 gen7_pp_set_surface_tiling(ss, tiling);
963 dri_bo_emit_reloc(ss_bo,
964 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
966 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state, ss1),
968 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
973 gen7_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
974 dri_bo *surf_bo, unsigned long surf_bo_offset,
975 int width, int height, int wpitch,
976 int xoffset, int yoffset,
977 int format, int interleave_chroma,
980 struct gen7_surface_state2 *ss2;
983 unsigned int swizzle;
985 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
986 ss2_bo = pp_context->surface_state_binding_table.bo;
989 dri_bo_map(ss2_bo, True);
990 assert(ss2_bo->virtual);
991 ss2 = (struct gen7_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
992 memset(ss2, 0, sizeof(*ss2));
993 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
994 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
995 ss2->ss1.width = width - 1;
996 ss2->ss1.height = height - 1;
997 ss2->ss2.pitch = wpitch - 1;
998 ss2->ss2.interleave_chroma = interleave_chroma;
999 ss2->ss2.surface_format = format;
1000 ss2->ss3.x_offset_for_cb = xoffset;
1001 ss2->ss3.y_offset_for_cb = yoffset;
1002 gen7_pp_set_surface2_tiling(ss2, tiling);
1003 dri_bo_emit_reloc(ss2_bo,
1004 I915_GEM_DOMAIN_RENDER, 0,
1006 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state2, ss0),
1008 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1009 dri_bo_unmap(ss2_bo);
1013 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1014 const struct i965_surface *surface,
1015 int base_index, int is_target,
1016 int *width, int *height, int *pitch, int *offset)
1018 struct i965_driver_data *i965 = i965_driver_data(ctx);
1019 struct object_surface *obj_surface;
1020 struct object_image *obj_image;
1022 int fourcc = pp_get_surface_fourcc(ctx, surface);
1024 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
1025 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
1027 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1029 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1030 obj_surface = SURFACE(surface->id);
1031 bo = obj_surface->bo;
1032 width[0] = obj_surface->orig_width;
1033 height[0] = obj_surface->orig_height;
1034 pitch[0] = obj_surface->width;
1037 if (interleaved_uv) {
1038 width[1] = obj_surface->orig_width;
1039 height[1] = obj_surface->orig_height / 2;
1040 pitch[1] = obj_surface->width;
1041 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1043 width[1] = obj_surface->orig_width / 2;
1044 height[1] = obj_surface->orig_height / 2;
1045 pitch[1] = obj_surface->width / 2;
1046 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1047 width[2] = obj_surface->orig_width / 2;
1048 height[2] = obj_surface->orig_height / 2;
1049 pitch[2] = obj_surface->width / 2;
1050 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
1053 obj_image = IMAGE(surface->id);
1055 width[0] = obj_image->image.width;
1056 height[0] = obj_image->image.height;
1057 pitch[0] = obj_image->image.pitches[0];
1058 offset[0] = obj_image->image.offsets[0];
1060 if (interleaved_uv) {
1061 width[1] = obj_image->image.width;
1062 height[1] = obj_image->image.height / 2;
1063 pitch[1] = obj_image->image.pitches[1];
1064 offset[1] = obj_image->image.offsets[1];
1066 width[1] = obj_image->image.width / 2;
1067 height[1] = obj_image->image.height / 2;
1068 pitch[1] = obj_image->image.pitches[1];
1069 offset[1] = obj_image->image.offsets[1];
1070 width[2] = obj_image->image.width / 2;
1071 height[2] = obj_image->image.height / 2;
1072 pitch[2] = obj_image->image.pitches[2];
1073 offset[2] = obj_image->image.offsets[2];
1078 i965_pp_set_surface_state(ctx, pp_context,
1080 width[Y] / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
1081 base_index, is_target);
1083 if (interleaved_uv) {
1084 i965_pp_set_surface_state(ctx, pp_context,
1086 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
1087 base_index + 1, is_target);
1090 i965_pp_set_surface_state(ctx, pp_context,
1092 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
1093 base_index + 1, is_target);
1096 i965_pp_set_surface_state(ctx, pp_context,
1098 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
1099 base_index + 2, is_target);
1105 pp_null_x_steps(void *private_context)
1111 pp_null_y_steps(void *private_context)
1117 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1123 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1124 const struct i965_surface *src_surface,
1125 const VARectangle *src_rect,
1126 struct i965_surface *dst_surface,
1127 const VARectangle *dst_rect,
1130 /* private function & data */
1131 pp_context->pp_x_steps = pp_null_x_steps;
1132 pp_context->pp_y_steps = pp_null_y_steps;
1133 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
1135 dst_surface->flags = src_surface->flags;
1137 return VA_STATUS_SUCCESS;
1141 pp_load_save_x_steps(void *private_context)
1147 pp_load_save_y_steps(void *private_context)
1149 struct pp_load_save_context *pp_load_save_context = private_context;
1151 return pp_load_save_context->dest_h / 8;
1155 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1157 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1159 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1160 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1161 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
1162 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
1168 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1169 const struct i965_surface *src_surface,
1170 const VARectangle *src_rect,
1171 struct i965_surface *dst_surface,
1172 const VARectangle *dst_rect,
1175 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->private_context;
1176 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1177 int width[3], height[3], pitch[3], offset[3];
1180 /* source surface */
1181 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
1182 width, height, pitch, offset);
1184 /* destination surface */
1185 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
1186 width, height, pitch, offset);
1188 /* private function & data */
1189 pp_context->pp_x_steps = pp_load_save_x_steps;
1190 pp_context->pp_y_steps = pp_load_save_y_steps;
1191 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
1192 pp_load_save_context->dest_h = ALIGN(height[Y], 16);
1193 pp_load_save_context->dest_w = ALIGN(width[Y], 16);
1195 pp_inline_parameter->grf5.block_count_x = ALIGN(width[Y], 16) / 16; /* 1 x N */
1196 pp_inline_parameter->grf5.number_blocks = ALIGN(width[Y], 16) / 16;
1198 dst_surface->flags = src_surface->flags;
1200 return VA_STATUS_SUCCESS;
1204 pp_scaling_x_steps(void *private_context)
1210 pp_scaling_y_steps(void *private_context)
1212 struct pp_scaling_context *pp_scaling_context = private_context;
1214 return pp_scaling_context->dest_h / 8;
1218 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1220 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1221 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1222 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1223 float src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1224 float src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1226 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
1227 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
1228 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
1229 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
1235 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1236 const struct i965_surface *src_surface,
1237 const VARectangle *src_rect,
1238 struct i965_surface *dst_surface,
1239 const VARectangle *dst_rect,
1242 struct i965_driver_data *i965 = i965_driver_data(ctx);
1243 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1244 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1245 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1246 struct object_surface *obj_surface;
1247 struct i965_sampler_state *sampler_state;
1248 int in_w, in_h, in_wpitch, in_hpitch;
1249 int out_w, out_h, out_wpitch, out_hpitch;
1251 /* source surface */
1252 obj_surface = SURFACE(src_surface->id);
1253 in_w = obj_surface->orig_width;
1254 in_h = obj_surface->orig_height;
1255 in_wpitch = obj_surface->width;
1256 in_hpitch = obj_surface->height;
1258 /* source Y surface index 1 */
1259 i965_pp_set_surface_state(ctx, pp_context,
1261 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1264 /* source UV surface index 2 */
1265 i965_pp_set_surface_state(ctx, pp_context,
1266 obj_surface->bo, in_wpitch * in_hpitch,
1267 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1270 /* destination surface */
1271 obj_surface = SURFACE(dst_surface->id);
1272 out_w = obj_surface->orig_width;
1273 out_h = obj_surface->orig_height;
1274 out_wpitch = obj_surface->width;
1275 out_hpitch = obj_surface->height;
1277 /* destination Y surface index 7 */
1278 i965_pp_set_surface_state(ctx, pp_context,
1280 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1283 /* destination UV surface index 8 */
1284 i965_pp_set_surface_state(ctx, pp_context,
1285 obj_surface->bo, out_wpitch * out_hpitch,
1286 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1290 dri_bo_map(pp_context->sampler_state_table.bo, True);
1291 assert(pp_context->sampler_state_table.bo->virtual);
1292 sampler_state = pp_context->sampler_state_table.bo->virtual;
1294 /* SIMD16 Y index 1 */
1295 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
1296 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1297 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1298 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1299 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1301 /* SIMD16 UV index 2 */
1302 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
1303 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1304 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1305 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1306 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1308 dri_bo_unmap(pp_context->sampler_state_table.bo);
1310 /* private function & data */
1311 pp_context->pp_x_steps = pp_scaling_x_steps;
1312 pp_context->pp_y_steps = pp_scaling_y_steps;
1313 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
1315 pp_scaling_context->dest_x = dst_rect->x;
1316 pp_scaling_context->dest_y = dst_rect->y;
1317 pp_scaling_context->dest_w = ALIGN(dst_rect->width, 16);
1318 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 16);
1319 pp_scaling_context->src_normalized_x = (float)src_rect->x / in_w;
1320 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h;
1322 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
1324 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
1325 pp_inline_parameter->grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
1326 pp_inline_parameter->grf5.number_blocks = pp_scaling_context->dest_w / 16;
1327 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1328 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1330 dst_surface->flags = src_surface->flags;
1332 return VA_STATUS_SUCCESS;
1336 pp_avs_x_steps(void *private_context)
1338 struct pp_avs_context *pp_avs_context = private_context;
1340 return pp_avs_context->dest_w / 16;
1344 pp_avs_y_steps(void *private_context)
1350 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1352 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1353 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1354 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1355 float src_x_steping, src_y_steping, video_step_delta;
1356 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
1358 if (tmp_w >= pp_avs_context->dest_w) {
1359 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1360 pp_inline_parameter->grf6.video_step_delta = 0;
1363 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
1364 pp_avs_context->src_normalized_x;
1366 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1367 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1368 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1369 16 * 15 * video_step_delta / 2;
1372 int n0, n1, n2, nls_left, nls_right;
1373 int factor_a = 5, factor_b = 4;
1376 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
1377 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
1378 n2 = tmp_w / (16 * factor_a);
1380 nls_right = n1 + n2;
1381 f = (float) n2 * 16 / tmp_w;
1384 pp_inline_parameter->grf6.video_step_delta = 0.0;
1387 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
1388 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1390 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1391 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1392 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1393 16 * 15 * video_step_delta / 2;
1397 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
1398 float a = f / (nls_left * 16 * factor_b);
1399 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
1401 pp_inline_parameter->grf6.video_step_delta = b;
1404 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1405 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a;
1407 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1408 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1409 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1410 16 * 15 * video_step_delta / 2;
1411 pp_inline_parameter->grf5.normalized_video_x_scaling_step += 16 * b;
1413 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
1414 /* scale the center linearly */
1415 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1416 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1417 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1418 16 * 15 * video_step_delta / 2;
1419 pp_inline_parameter->grf6.video_step_delta = 0.0;
1420 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1422 float a = f / (nls_right * 16 * factor_b);
1423 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
1425 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1426 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1427 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1428 16 * 15 * video_step_delta / 2;
1429 pp_inline_parameter->grf6.video_step_delta = -b;
1431 if (x == (pp_avs_context->dest_w / 16 - nls_right))
1432 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
1434 pp_inline_parameter->grf5.normalized_video_x_scaling_step -= b * 16;
1439 src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1440 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
1441 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1442 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
1448 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1449 const struct i965_surface *src_surface,
1450 const VARectangle *src_rect,
1451 struct i965_surface *dst_surface,
1452 const VARectangle *dst_rect,
1455 struct i965_driver_data *i965 = i965_driver_data(ctx);
1456 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1457 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1458 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1459 struct object_surface *obj_surface;
1460 struct i965_sampler_8x8 *sampler_8x8;
1461 struct i965_sampler_8x8_state *sampler_8x8_state;
1463 int in_w, in_h, in_wpitch, in_hpitch;
1464 int out_w, out_h, out_wpitch, out_hpitch;
1468 obj_surface = SURFACE(src_surface->id);
1469 in_w = obj_surface->orig_width;
1470 in_h = obj_surface->orig_height;
1471 in_wpitch = obj_surface->width;
1472 in_hpitch = obj_surface->height;
1474 /* source Y surface index 1 */
1475 i965_pp_set_surface2_state(ctx, pp_context,
1477 in_w, in_h, in_wpitch,
1479 SURFACE_FORMAT_Y8_UNORM, 0,
1482 /* source UV surface index 2 */
1483 i965_pp_set_surface2_state(ctx, pp_context,
1484 obj_surface->bo, in_wpitch * in_hpitch,
1485 in_w / 2, in_h / 2, in_wpitch,
1487 SURFACE_FORMAT_R8B8_UNORM, 0,
1490 /* destination surface */
1491 obj_surface = SURFACE(dst_surface->id);
1492 out_w = obj_surface->orig_width;
1493 out_h = obj_surface->orig_height;
1494 out_wpitch = obj_surface->width;
1495 out_hpitch = obj_surface->height;
1496 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1498 /* destination Y surface index 7 */
1499 i965_pp_set_surface_state(ctx, pp_context,
1501 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1504 /* destination UV surface index 8 */
1505 i965_pp_set_surface_state(ctx, pp_context,
1506 obj_surface->bo, out_wpitch * out_hpitch,
1507 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1510 /* sampler 8x8 state */
1511 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1512 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1513 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1514 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1515 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1517 for (i = 0; i < 17; i++) {
1518 /* for Y channel, currently ignore */
1519 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x00;
1520 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x00;
1521 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x08;
1522 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x18;
1523 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x18;
1524 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x08;
1525 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x00;
1526 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x00;
1527 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x00;
1528 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x00;
1529 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x10;
1530 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x10;
1531 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x10;
1532 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x10;
1533 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x00;
1534 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x00;
1535 /* for U/V channel, 0.25 */
1536 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
1537 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
1538 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
1539 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
1540 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
1541 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
1542 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
1543 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
1544 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
1545 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
1546 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
1547 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
1548 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
1549 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
1550 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
1551 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
1554 sampler_8x8_state->dw136.default_sharpness_level = 0;
1555 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
1556 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1557 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1558 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
1561 dri_bo_map(pp_context->sampler_state_table.bo, True);
1562 assert(pp_context->sampler_state_table.bo->virtual);
1563 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
1564 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
1566 /* sample_8x8 Y index 1 */
1568 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1569 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1570 sampler_8x8[index].dw0.ief_bypass = 1;
1571 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1572 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1573 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1574 sampler_8x8[index].dw2.global_noise_estimation = 22;
1575 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1576 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1577 sampler_8x8[index].dw3.strong_edge_weight = 7;
1578 sampler_8x8[index].dw3.regular_weight = 2;
1579 sampler_8x8[index].dw3.non_edge_weight = 0;
1580 sampler_8x8[index].dw3.gain_factor = 40;
1581 sampler_8x8[index].dw4.steepness_boost = 0;
1582 sampler_8x8[index].dw4.steepness_threshold = 0;
1583 sampler_8x8[index].dw4.mr_boost = 0;
1584 sampler_8x8[index].dw4.mr_threshold = 5;
1585 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1586 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1587 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1588 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1589 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1590 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1591 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1592 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1593 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1594 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1595 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1596 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1597 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1598 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1599 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1600 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1601 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1602 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1603 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1604 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1605 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1606 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1607 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1608 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1609 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1610 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1611 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1612 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1613 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1614 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1615 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1616 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1617 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1618 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1619 sampler_8x8[index].dw13.limiter_boost = 0;
1620 sampler_8x8[index].dw13.minimum_limiter = 10;
1621 sampler_8x8[index].dw13.maximum_limiter = 11;
1622 sampler_8x8[index].dw14.clip_limiter = 130;
1623 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1624 I915_GEM_DOMAIN_RENDER,
1627 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1628 pp_context->sampler_state_table.bo_8x8);
1630 /* sample_8x8 UV index 2 */
1632 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1633 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1634 sampler_8x8[index].dw0.ief_bypass = 1;
1635 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1636 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1637 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1638 sampler_8x8[index].dw2.global_noise_estimation = 22;
1639 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1640 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1641 sampler_8x8[index].dw3.strong_edge_weight = 7;
1642 sampler_8x8[index].dw3.regular_weight = 2;
1643 sampler_8x8[index].dw3.non_edge_weight = 0;
1644 sampler_8x8[index].dw3.gain_factor = 40;
1645 sampler_8x8[index].dw4.steepness_boost = 0;
1646 sampler_8x8[index].dw4.steepness_threshold = 0;
1647 sampler_8x8[index].dw4.mr_boost = 0;
1648 sampler_8x8[index].dw4.mr_threshold = 5;
1649 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1650 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1651 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1652 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1653 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1654 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1655 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1656 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1657 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1658 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1659 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1660 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1661 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1662 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1663 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1664 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1665 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1666 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1667 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1668 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1669 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1670 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1671 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1672 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1673 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1674 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1675 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1676 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1677 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1678 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1679 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1680 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1681 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1682 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1683 sampler_8x8[index].dw13.limiter_boost = 0;
1684 sampler_8x8[index].dw13.minimum_limiter = 10;
1685 sampler_8x8[index].dw13.maximum_limiter = 11;
1686 sampler_8x8[index].dw14.clip_limiter = 130;
1687 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1688 I915_GEM_DOMAIN_RENDER,
1691 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1692 pp_context->sampler_state_table.bo_8x8);
1694 dri_bo_unmap(pp_context->sampler_state_table.bo);
1696 /* private function & data */
1697 pp_context->pp_x_steps = pp_avs_x_steps;
1698 pp_context->pp_y_steps = pp_avs_y_steps;
1699 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
1701 pp_avs_context->dest_x = dst_rect->x;
1702 pp_avs_context->dest_y = dst_rect->y;
1703 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
1704 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
1705 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w;
1706 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h;
1707 pp_avs_context->src_w = src_rect->width;
1708 pp_avs_context->src_h = src_rect->height;
1710 pp_static_parameter->grf4.r4_2.avs.nlas = 1;
1711 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
1713 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
1714 pp_inline_parameter->grf5.block_count_x = 1; /* M x 1 */
1715 pp_inline_parameter->grf5.number_blocks = pp_avs_context->dest_h / 8;
1716 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1717 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1718 pp_inline_parameter->grf6.video_step_delta = 0.0;
1720 dst_surface->flags = src_surface->flags;
1722 return VA_STATUS_SUCCESS;
1726 gen7_pp_avs_x_steps(void *private_context)
1728 struct pp_avs_context *pp_avs_context = private_context;
1730 return pp_avs_context->dest_w / 16;
1734 gen7_pp_avs_y_steps(void *private_context)
1736 struct pp_avs_context *pp_avs_context = private_context;
1738 return pp_avs_context->dest_h / 16;
1742 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1744 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1745 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1747 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1748 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
1749 pp_inline_parameter->grf7.constant_0 = 0xffffffff;
1750 pp_inline_parameter->grf7.sampler_load_main_video_x_scaling_step = 1.0 / pp_avs_context->src_w;
1756 gen7_pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1757 const struct i965_surface *src_surface,
1758 const VARectangle *src_rect,
1759 struct i965_surface *dst_surface,
1760 const VARectangle *dst_rect,
1763 struct i965_driver_data *i965 = i965_driver_data(ctx);
1764 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1765 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1766 struct object_surface *obj_surface;
1767 struct gen7_sampler_8x8 *sampler_8x8;
1768 struct i965_sampler_8x8_state *sampler_8x8_state;
1770 int in_w, in_h, in_wpitch, in_hpitch;
1771 int out_w, out_h, out_wpitch, out_hpitch;
1774 obj_surface = SURFACE(src_surface->id);
1775 in_w = obj_surface->orig_width;
1776 in_h = obj_surface->orig_height;
1777 in_wpitch = obj_surface->width;
1778 in_hpitch = obj_surface->height;
1780 /* source Y surface index 0 */
1781 gen7_pp_set_surface2_state(ctx, pp_context,
1783 in_w, in_h, in_wpitch,
1785 SURFACE_FORMAT_Y8_UNORM, 0,
1788 /* source UV surface index 1 */
1789 gen7_pp_set_surface2_state(ctx, pp_context,
1790 obj_surface->bo, in_wpitch * in_hpitch,
1791 in_w / 2, in_h / 2, in_wpitch,
1793 SURFACE_FORMAT_R8B8_UNORM, 0,
1796 /* destination surface */
1797 obj_surface = SURFACE(dst_surface->id);
1798 out_w = obj_surface->orig_width;
1799 out_h = obj_surface->orig_height;
1800 out_wpitch = obj_surface->width;
1801 out_hpitch = obj_surface->height;
1802 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1804 /* destination Y surface index 24 */
1805 gen7_pp_set_surface_state(ctx, pp_context,
1807 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_SINT,
1810 /* destination UV surface index 25 */
1811 gen7_pp_set_surface_state(ctx, pp_context,
1812 obj_surface->bo, out_wpitch * out_hpitch,
1813 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_SINT,
1816 /* sampler 8x8 state */
1817 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1818 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1819 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1820 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1821 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1823 for (i = 0; i < 17; i++) {
1824 /* for Y channel, currently ignore */
1825 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
1826 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
1827 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
1828 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x0;
1829 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x0;
1830 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
1831 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
1832 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
1833 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
1834 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
1835 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
1836 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x0;
1837 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x0;
1838 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
1839 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
1840 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
1841 /* for U/V channel, 0.25 */
1842 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
1843 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
1844 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
1845 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
1846 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
1847 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
1848 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
1849 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
1850 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
1851 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
1852 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
1853 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
1854 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
1855 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
1856 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
1857 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
1860 sampler_8x8_state->dw136.default_sharpness_level = 0;
1861 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
1862 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1863 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1864 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
1867 dri_bo_map(pp_context->sampler_state_table.bo, True);
1868 assert(pp_context->sampler_state_table.bo->virtual);
1869 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
1870 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
1872 /* sample_8x8 Y index 4 */
1874 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1875 sampler_8x8[index].dw0.global_noise_estimation = 255;
1876 sampler_8x8[index].dw0.ief_bypass = 1;
1878 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1880 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1881 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1882 sampler_8x8[index].dw2.r5x_coefficient = 9;
1883 sampler_8x8[index].dw2.r5cx_coefficient = 8;
1884 sampler_8x8[index].dw2.r5c_coefficient = 3;
1886 sampler_8x8[index].dw3.r3x_coefficient = 27;
1887 sampler_8x8[index].dw3.r3c_coefficient = 5;
1888 sampler_8x8[index].dw3.gain_factor = 40;
1889 sampler_8x8[index].dw3.non_edge_weight = 1;
1890 sampler_8x8[index].dw3.regular_weight = 2;
1891 sampler_8x8[index].dw3.strong_edge_weight = 7;
1892 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
1894 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1895 I915_GEM_DOMAIN_RENDER,
1898 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1899 pp_context->sampler_state_table.bo_8x8);
1901 /* sample_8x8 UV index 8 */
1903 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1904 sampler_8x8[index].dw0.disable_8x8_filter = 0;
1905 sampler_8x8[index].dw0.global_noise_estimation = 255;
1906 sampler_8x8[index].dw0.ief_bypass = 1;
1907 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1908 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1909 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1910 sampler_8x8[index].dw2.r5x_coefficient = 9;
1911 sampler_8x8[index].dw2.r5cx_coefficient = 8;
1912 sampler_8x8[index].dw2.r5c_coefficient = 3;
1913 sampler_8x8[index].dw3.r3x_coefficient = 27;
1914 sampler_8x8[index].dw3.r3c_coefficient = 5;
1915 sampler_8x8[index].dw3.gain_factor = 40;
1916 sampler_8x8[index].dw3.non_edge_weight = 1;
1917 sampler_8x8[index].dw3.regular_weight = 2;
1918 sampler_8x8[index].dw3.strong_edge_weight = 7;
1919 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
1921 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1922 I915_GEM_DOMAIN_RENDER,
1925 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1926 pp_context->sampler_state_table.bo_8x8);
1928 dri_bo_unmap(pp_context->sampler_state_table.bo);
1930 /* private function & data */
1931 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
1932 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
1933 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
1935 pp_avs_context->dest_x = dst_rect->x;
1936 pp_avs_context->dest_y = dst_rect->y;
1937 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
1938 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
1939 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w / out_w;
1940 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h / out_h;
1941 pp_avs_context->src_w = src_rect->width;
1942 pp_avs_context->src_h = src_rect->height;
1944 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
1945 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / pp_avs_context->dest_w;
1946 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) 1.0 / pp_avs_context->dest_h;
1947 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = -(float)pp_avs_context->dest_y / pp_avs_context->dest_h;
1948 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = -(float)pp_avs_context->dest_x / pp_avs_context->dest_w;
1950 dst_surface->flags = src_surface->flags;
1952 return VA_STATUS_SUCCESS;
1956 pp_dndi_x_steps(void *private_context)
1962 pp_dndi_y_steps(void *private_context)
1964 struct pp_dndi_context *pp_dndi_context = private_context;
1966 return pp_dndi_context->dest_h / 4;
1970 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1972 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1974 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
1975 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
1981 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1982 const struct i965_surface *src_surface,
1983 const VARectangle *src_rect,
1984 struct i965_surface *dst_surface,
1985 const VARectangle *dst_rect,
1988 struct i965_driver_data *i965 = i965_driver_data(ctx);
1989 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
1990 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1991 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1992 struct object_surface *obj_surface;
1993 struct i965_sampler_dndi *sampler_dndi;
1997 int dndi_top_first = 1;
1999 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2000 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2002 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2008 obj_surface = SURFACE(src_surface->id);
2009 orig_w = obj_surface->orig_width;
2010 orig_h = obj_surface->orig_height;
2011 w = obj_surface->width;
2012 h = obj_surface->height;
2014 if (pp_context->stmm.bo == NULL) {
2015 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2019 assert(pp_context->stmm.bo);
2022 /* source UV surface index 2 */
2023 i965_pp_set_surface_state(ctx, pp_context,
2024 obj_surface->bo, w * h,
2025 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2028 /* source YUV surface index 4 */
2029 i965_pp_set_surface2_state(ctx, pp_context,
2033 SURFACE_FORMAT_PLANAR_420_8, 1,
2036 /* source STMM surface index 20 */
2037 i965_pp_set_surface_state(ctx, pp_context,
2038 pp_context->stmm.bo, 0,
2039 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2042 /* destination surface */
2043 obj_surface = SURFACE(dst_surface->id);
2044 orig_w = obj_surface->orig_width;
2045 orig_h = obj_surface->orig_height;
2046 w = obj_surface->width;
2047 h = obj_surface->height;
2049 /* destination Y surface index 7 */
2050 i965_pp_set_surface_state(ctx, pp_context,
2052 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2055 /* destination UV surface index 8 */
2056 i965_pp_set_surface_state(ctx, pp_context,
2057 obj_surface->bo, w * h,
2058 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2061 dri_bo_map(pp_context->sampler_state_table.bo, True);
2062 assert(pp_context->sampler_state_table.bo->virtual);
2063 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2064 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2066 /* sample dndi index 1 */
2068 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2069 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2070 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2071 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2073 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2074 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 4;
2075 sampler_dndi[index].dw1.stmm_c2 = 1;
2076 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2077 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2079 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2080 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2081 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2082 sampler_dndi[index].dw2.good_neighbor_threshold = 4; // 0-63
2084 sampler_dndi[index].dw3.maximum_stmm = 128;
2085 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2086 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2087 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2088 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2090 sampler_dndi[index].dw4.sdi_delta = 8;
2091 sampler_dndi[index].dw4.sdi_threshold = 128;
2092 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2093 sampler_dndi[index].dw4.stmm_shift_up = 0;
2094 sampler_dndi[index].dw4.stmm_shift_down = 0;
2095 sampler_dndi[index].dw4.minimum_stmm = 0;
2097 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 8;
2098 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 32;
2099 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 64;
2100 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 32;
2102 sampler_dndi[index].dw6.dn_enable = 1;
2103 sampler_dndi[index].dw6.di_enable = 1;
2104 sampler_dndi[index].dw6.di_partial = 0;
2105 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2106 sampler_dndi[index].dw6.dndi_stream_id = 0;
2107 sampler_dndi[index].dw6.dndi_first_frame = 1;
2108 sampler_dndi[index].dw6.progressive_dn = 0;
2109 sampler_dndi[index].dw6.fmd_tear_threshold = 63;
2110 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2111 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2113 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
2114 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
2115 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2116 sampler_dndi[index].dw7.column_width_minus1 = 0;
2118 dri_bo_unmap(pp_context->sampler_state_table.bo);
2120 /* private function & data */
2121 pp_context->pp_x_steps = pp_dndi_x_steps;
2122 pp_context->pp_y_steps = pp_dndi_y_steps;
2123 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
2125 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2126 pp_static_parameter->grf1.r1_6.di.top_field_first = dndi_top_first;
2127 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 0;
2128 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 0;
2130 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2131 pp_inline_parameter->grf5.number_blocks = w / 16;
2132 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2133 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2135 pp_dndi_context->dest_w = w;
2136 pp_dndi_context->dest_h = h;
2138 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
2140 return VA_STATUS_SUCCESS;
2144 pp_dn_x_steps(void *private_context)
2150 pp_dn_y_steps(void *private_context)
2152 struct pp_dn_context *pp_dn_context = private_context;
2154 return pp_dn_context->dest_h / 8;
2158 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2160 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2162 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2163 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
2169 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2170 const struct i965_surface *src_surface,
2171 const VARectangle *src_rect,
2172 struct i965_surface *dst_surface,
2173 const VARectangle *dst_rect,
2176 struct i965_driver_data *i965 = i965_driver_data(ctx);
2177 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
2178 struct object_surface *obj_surface;
2179 struct i965_sampler_dndi *sampler_dndi;
2180 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2181 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2182 VAProcFilterBaseParameterBuffer *dn_filter_param = filter_param;
2186 int dn_strength = 15;
2187 int dndi_top_first = 1;
2188 int dn_progressive = 0;
2190 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
2193 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
2201 if (dn_filter_param) {
2202 int value = dn_filter_param->value;
2210 dn_strength = (int)(value * 31.0F);
2214 obj_surface = SURFACE(src_surface->id);
2215 orig_w = obj_surface->orig_width;
2216 orig_h = obj_surface->orig_height;
2217 w = obj_surface->width;
2218 h = obj_surface->height;
2220 if (pp_context->stmm.bo == NULL) {
2221 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2225 assert(pp_context->stmm.bo);
2228 /* source UV surface index 2 */
2229 i965_pp_set_surface_state(ctx, pp_context,
2230 obj_surface->bo, w * h,
2231 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2234 /* source YUV surface index 4 */
2235 i965_pp_set_surface2_state(ctx, pp_context,
2239 SURFACE_FORMAT_PLANAR_420_8, 1,
2242 /* source STMM surface index 20 */
2243 i965_pp_set_surface_state(ctx, pp_context,
2244 pp_context->stmm.bo, 0,
2245 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2248 /* destination surface */
2249 obj_surface = SURFACE(dst_surface->id);
2250 orig_w = obj_surface->orig_width;
2251 orig_h = obj_surface->orig_height;
2252 w = obj_surface->width;
2253 h = obj_surface->height;
2255 /* destination Y surface index 7 */
2256 i965_pp_set_surface_state(ctx, pp_context,
2258 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2261 /* destination UV surface index 8 */
2262 i965_pp_set_surface_state(ctx, pp_context,
2263 obj_surface->bo, w * h,
2264 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2267 dri_bo_map(pp_context->sampler_state_table.bo, True);
2268 assert(pp_context->sampler_state_table.bo->virtual);
2269 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2270 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2272 /* sample dndi index 1 */
2274 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2275 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2276 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2277 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2279 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2280 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2281 sampler_dndi[index].dw1.stmm_c2 = 0;
2282 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2283 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2285 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
2286 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2287 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2288 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
2290 sampler_dndi[index].dw3.maximum_stmm = 128;
2291 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2292 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2293 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2294 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2296 sampler_dndi[index].dw4.sdi_delta = 8;
2297 sampler_dndi[index].dw4.sdi_threshold = 128;
2298 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2299 sampler_dndi[index].dw4.stmm_shift_up = 0;
2300 sampler_dndi[index].dw4.stmm_shift_down = 0;
2301 sampler_dndi[index].dw4.minimum_stmm = 0;
2303 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2304 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2305 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2306 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2308 sampler_dndi[index].dw6.dn_enable = 1;
2309 sampler_dndi[index].dw6.di_enable = 0;
2310 sampler_dndi[index].dw6.di_partial = 0;
2311 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2312 sampler_dndi[index].dw6.dndi_stream_id = 1;
2313 sampler_dndi[index].dw6.dndi_first_frame = 1;
2314 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
2315 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
2316 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2317 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2319 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
2320 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
2321 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2322 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
2324 dri_bo_unmap(pp_context->sampler_state_table.bo);
2326 /* private function & data */
2327 pp_context->pp_x_steps = pp_dn_x_steps;
2328 pp_context->pp_y_steps = pp_dn_y_steps;
2329 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
2331 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2332 pp_static_parameter->grf1.r1_6.di.top_field_first = 0;
2333 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 64;
2334 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 192;
2336 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2337 pp_inline_parameter->grf5.number_blocks = w / 16;
2338 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2339 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2341 pp_dn_context->dest_w = w;
2342 pp_dn_context->dest_h = h;
2344 dst_surface->flags = src_surface->flags;
2346 return VA_STATUS_SUCCESS;
2350 gen7_pp_dndi_x_steps(void *private_context)
2352 struct pp_dndi_context *pp_dndi_context = private_context;
2354 return pp_dndi_context->dest_w / 16;
2358 gen7_pp_dndi_y_steps(void *private_context)
2360 struct pp_dndi_context *pp_dndi_context = private_context;
2362 return pp_dndi_context->dest_h / 4;
2366 gen7_pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2368 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2370 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16;
2371 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 4;
2377 gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2378 const struct i965_surface *src_surface,
2379 const VARectangle *src_rect,
2380 struct i965_surface *dst_surface,
2381 const VARectangle *dst_rect,
2384 struct i965_driver_data *i965 = i965_driver_data(ctx);
2385 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2386 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2387 struct object_surface *obj_surface;
2388 struct gen7_sampler_dndi *sampler_dndi;
2392 int dndi_top_first = 1;
2394 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2395 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2397 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2403 obj_surface = SURFACE(src_surface->id);
2404 orig_w = obj_surface->orig_width;
2405 orig_h = obj_surface->orig_height;
2406 w = obj_surface->width;
2407 h = obj_surface->height;
2409 if (pp_context->stmm.bo == NULL) {
2410 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2414 assert(pp_context->stmm.bo);
2417 /* source UV surface index 1 */
2418 gen7_pp_set_surface_state(ctx, pp_context,
2419 obj_surface->bo, w * h,
2420 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2423 /* source YUV surface index 3 */
2424 gen7_pp_set_surface2_state(ctx, pp_context,
2428 SURFACE_FORMAT_PLANAR_420_8, 1,
2431 /* source (temporal reference) YUV surface index 4 */
2432 gen7_pp_set_surface2_state(ctx, pp_context,
2436 SURFACE_FORMAT_PLANAR_420_8, 1,
2439 /* STMM / History Statistics input surface, index 5 */
2440 gen7_pp_set_surface_state(ctx, pp_context,
2441 pp_context->stmm.bo, 0,
2442 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2445 /* destination surface */
2446 obj_surface = SURFACE(dst_surface->id);
2447 orig_w = obj_surface->orig_width;
2448 orig_h = obj_surface->orig_height;
2449 w = obj_surface->width;
2450 h = obj_surface->height;
2452 /* destination(Previous frame) Y surface index 27 */
2453 gen7_pp_set_surface_state(ctx, pp_context,
2455 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2458 /* destination(Previous frame) UV surface index 28 */
2459 gen7_pp_set_surface_state(ctx, pp_context,
2460 obj_surface->bo, w * h,
2461 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2464 /* destination(Current frame) Y surface index 30 */
2465 gen7_pp_set_surface_state(ctx, pp_context,
2467 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2470 /* destination(Current frame) UV surface index 31 */
2471 gen7_pp_set_surface_state(ctx, pp_context,
2472 obj_surface->bo, w * h,
2473 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2476 /* STMM output surface, index 33 */
2477 gen7_pp_set_surface_state(ctx, pp_context,
2478 pp_context->stmm.bo, 0,
2479 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2484 dri_bo_map(pp_context->sampler_state_table.bo, True);
2485 assert(pp_context->sampler_state_table.bo->virtual);
2486 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2487 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2489 /* sample dndi index 0 */
2491 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2492 sampler_dndi[index].dw0.dnmh_delt = 8;
2493 sampler_dndi[index].dw0.vdi_walker_y_stride = 0;
2494 sampler_dndi[index].dw0.vdi_walker_frame_sharing_enable = 0;
2495 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2496 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2498 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2499 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2500 sampler_dndi[index].dw1.stmm_c2 = 0;
2501 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2502 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2504 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2505 sampler_dndi[index].dw2.bne_edge_th = 1;
2506 sampler_dndi[index].dw2.smooth_mv_th = 0;
2507 sampler_dndi[index].dw2.sad_tight_th = 5;
2508 sampler_dndi[index].dw2.cat_slope_minus1 = 9;
2509 sampler_dndi[index].dw2.good_neighbor_th = 4;
2511 sampler_dndi[index].dw3.maximum_stmm = 128;
2512 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2513 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2514 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2515 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2517 sampler_dndi[index].dw4.sdi_delta = 8;
2518 sampler_dndi[index].dw4.sdi_threshold = 128;
2519 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2520 sampler_dndi[index].dw4.stmm_shift_up = 0;
2521 sampler_dndi[index].dw4.stmm_shift_down = 0;
2522 sampler_dndi[index].dw4.minimum_stmm = 0;
2524 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2525 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2526 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2527 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2529 sampler_dndi[index].dw6.dn_enable = 0;
2530 sampler_dndi[index].dw6.di_enable = 1;
2531 sampler_dndi[index].dw6.di_partial = 0;
2532 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2533 sampler_dndi[index].dw6.dndi_stream_id = 1;
2534 sampler_dndi[index].dw6.dndi_first_frame = 1;
2535 sampler_dndi[index].dw6.progressive_dn = 0;
2536 sampler_dndi[index].dw6.mcdi_enable = 0;
2537 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
2538 sampler_dndi[index].dw6.cat_th1 = 0;
2539 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2540 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2542 sampler_dndi[index].dw7.sad_tha = 5;
2543 sampler_dndi[index].dw7.sad_thb = 10;
2544 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
2545 sampler_dndi[index].dw7.mc_pixel_consistency_th = 25;
2546 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
2547 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2548 sampler_dndi[index].dw7.neighborpixel_th = 10;
2549 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
2551 dri_bo_unmap(pp_context->sampler_state_table.bo);
2553 /* private function & data */
2554 pp_context->pp_x_steps = gen7_pp_dndi_x_steps;
2555 pp_context->pp_y_steps = gen7_pp_dndi_y_steps;
2556 pp_context->pp_set_block_parameter = gen7_pp_dndi_set_block_parameter;
2558 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
2559 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
2560 pp_static_parameter->grf1.di_top_field_first = 0;
2561 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2563 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2564 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2565 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2567 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
2568 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
2570 pp_dndi_context->dest_w = w;
2571 pp_dndi_context->dest_h = h;
2573 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
2575 return VA_STATUS_SUCCESS;
2579 gen7_pp_dn_x_steps(void *private_context)
2585 gen7_pp_dn_y_steps(void *private_context)
2587 struct pp_dn_context *pp_dn_context = private_context;
2589 return pp_dn_context->dest_h / 4;
2593 gen7_pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2595 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2597 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2598 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
2604 gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2605 const struct i965_surface *src_surface,
2606 const VARectangle *src_rect,
2607 struct i965_surface *dst_surface,
2608 const VARectangle *dst_rect,
2611 struct i965_driver_data *i965 = i965_driver_data(ctx);
2612 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
2613 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2614 struct object_surface *obj_surface;
2615 struct gen7_sampler_dndi *sampler_dn;
2616 VAProcFilterBaseParameterBuffer *dn_filter_param = filter_param;
2620 int dn_strength = 15;
2621 int dndi_top_first = 1;
2622 int dn_progressive = 0;
2624 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
2627 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
2635 if (dn_filter_param) {
2636 int value = dn_filter_param->value;
2644 dn_strength = (int)(value * 31.0F);
2648 obj_surface = SURFACE(src_surface->id);
2649 orig_w = obj_surface->orig_width;
2650 orig_h = obj_surface->orig_height;
2651 w = obj_surface->width;
2652 h = obj_surface->height;
2654 if (pp_context->stmm.bo == NULL) {
2655 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2659 assert(pp_context->stmm.bo);
2662 /* source UV surface index 1 */
2663 gen7_pp_set_surface_state(ctx, pp_context,
2664 obj_surface->bo, w * h,
2665 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2668 /* source YUV surface index 3 */
2669 gen7_pp_set_surface2_state(ctx, pp_context,
2673 SURFACE_FORMAT_PLANAR_420_8, 1,
2676 /* source STMM surface index 5 */
2677 gen7_pp_set_surface_state(ctx, pp_context,
2678 pp_context->stmm.bo, 0,
2679 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2682 /* destination surface */
2683 obj_surface = SURFACE(dst_surface->id);
2684 orig_w = obj_surface->orig_width;
2685 orig_h = obj_surface->orig_height;
2686 w = obj_surface->width;
2687 h = obj_surface->height;
2689 /* destination Y surface index 7 */
2690 gen7_pp_set_surface_state(ctx, pp_context,
2692 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2695 /* destination UV surface index 8 */
2696 gen7_pp_set_surface_state(ctx, pp_context,
2697 obj_surface->bo, w * h,
2698 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2701 dri_bo_map(pp_context->sampler_state_table.bo, True);
2702 assert(pp_context->sampler_state_table.bo->virtual);
2703 assert(sizeof(*sampler_dn) == sizeof(int) * 8);
2704 sampler_dn = pp_context->sampler_state_table.bo->virtual;
2706 /* sample dn index 1 */
2708 sampler_dn[index].dw0.denoise_asd_threshold = 0;
2709 sampler_dn[index].dw0.dnmh_delt = 8;
2710 sampler_dn[index].dw0.vdi_walker_y_stride = 0;
2711 sampler_dn[index].dw0.vdi_walker_frame_sharing_enable = 0;
2712 sampler_dn[index].dw0.denoise_maximum_history = 128; // 128-240
2713 sampler_dn[index].dw0.denoise_stad_threshold = 0;
2715 sampler_dn[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2716 sampler_dn[index].dw1.denoise_moving_pixel_threshold = 0;
2717 sampler_dn[index].dw1.stmm_c2 = 0;
2718 sampler_dn[index].dw1.low_temporal_difference_threshold = 8;
2719 sampler_dn[index].dw1.temporal_difference_threshold = 16;
2721 sampler_dn[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
2722 sampler_dn[index].dw2.bne_edge_th = 1;
2723 sampler_dn[index].dw2.smooth_mv_th = 0;
2724 sampler_dn[index].dw2.sad_tight_th = 5;
2725 sampler_dn[index].dw2.cat_slope_minus1 = 9;
2726 sampler_dn[index].dw2.good_neighbor_th = 4;
2728 sampler_dn[index].dw3.maximum_stmm = 128;
2729 sampler_dn[index].dw3.multipler_for_vecm = 2;
2730 sampler_dn[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2731 sampler_dn[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2732 sampler_dn[index].dw3.stmm_blending_constant_select = 0;
2734 sampler_dn[index].dw4.sdi_delta = 8;
2735 sampler_dn[index].dw4.sdi_threshold = 128;
2736 sampler_dn[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2737 sampler_dn[index].dw4.stmm_shift_up = 0;
2738 sampler_dn[index].dw4.stmm_shift_down = 0;
2739 sampler_dn[index].dw4.minimum_stmm = 0;
2741 sampler_dn[index].dw5.fmd_temporal_difference_threshold = 0;
2742 sampler_dn[index].dw5.sdi_fallback_mode_2_constant = 0;
2743 sampler_dn[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2744 sampler_dn[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2746 sampler_dn[index].dw6.dn_enable = 1;
2747 sampler_dn[index].dw6.di_enable = 0;
2748 sampler_dn[index].dw6.di_partial = 0;
2749 sampler_dn[index].dw6.dndi_top_first = dndi_top_first;
2750 sampler_dn[index].dw6.dndi_stream_id = 1;
2751 sampler_dn[index].dw6.dndi_first_frame = 1;
2752 sampler_dn[index].dw6.progressive_dn = dn_progressive;
2753 sampler_dn[index].dw6.mcdi_enable = 0;
2754 sampler_dn[index].dw6.fmd_tear_threshold = 32;
2755 sampler_dn[index].dw6.cat_th1 = 0;
2756 sampler_dn[index].dw6.fmd2_vertical_difference_threshold = 32;
2757 sampler_dn[index].dw6.fmd1_vertical_difference_threshold = 32;
2759 sampler_dn[index].dw7.sad_tha = 5;
2760 sampler_dn[index].dw7.sad_thb = 10;
2761 sampler_dn[index].dw7.fmd_for_1st_field_of_current_frame = 2;
2762 sampler_dn[index].dw7.mc_pixel_consistency_th = 25;
2763 sampler_dn[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
2764 sampler_dn[index].dw7.vdi_walker_enable = 0;
2765 sampler_dn[index].dw7.neighborpixel_th = 10;
2766 sampler_dn[index].dw7.column_width_minus1 = w / 16;
2768 dri_bo_unmap(pp_context->sampler_state_table.bo);
2770 /* private function & data */
2771 pp_context->pp_x_steps = gen7_pp_dn_x_steps;
2772 pp_context->pp_y_steps = gen7_pp_dn_y_steps;
2773 pp_context->pp_set_block_parameter = gen7_pp_dn_set_block_parameter;
2775 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
2776 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
2777 pp_static_parameter->grf1.di_top_field_first = 0;
2778 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2780 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2781 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2782 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2784 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
2785 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
2787 pp_dn_context->dest_w = w;
2788 pp_dn_context->dest_h = h;
2790 dst_surface->flags = src_surface->flags;
2792 return VA_STATUS_SUCCESS;
2796 ironlake_pp_initialize(
2797 VADriverContextP ctx,
2798 struct i965_post_processing_context *pp_context,
2799 const struct i965_surface *src_surface,
2800 const VARectangle *src_rect,
2801 struct i965_surface *dst_surface,
2802 const VARectangle *dst_rect,
2808 struct i965_driver_data *i965 = i965_driver_data(ctx);
2809 struct pp_module *pp_module;
2811 int static_param_size, inline_param_size;
2813 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
2814 bo = dri_bo_alloc(i965->intel.bufmgr,
2815 "surface state & binding table",
2816 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
2819 pp_context->surface_state_binding_table.bo = bo;
2821 dri_bo_unreference(pp_context->curbe.bo);
2822 bo = dri_bo_alloc(i965->intel.bufmgr,
2827 pp_context->curbe.bo = bo;
2829 dri_bo_unreference(pp_context->idrt.bo);
2830 bo = dri_bo_alloc(i965->intel.bufmgr,
2831 "interface discriptor",
2832 sizeof(struct i965_interface_descriptor),
2835 pp_context->idrt.bo = bo;
2836 pp_context->idrt.num_interface_descriptors = 0;
2838 dri_bo_unreference(pp_context->sampler_state_table.bo);
2839 bo = dri_bo_alloc(i965->intel.bufmgr,
2840 "sampler state table",
2844 dri_bo_map(bo, True);
2845 memset(bo->virtual, 0, bo->size);
2847 pp_context->sampler_state_table.bo = bo;
2849 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
2850 bo = dri_bo_alloc(i965->intel.bufmgr,
2851 "sampler 8x8 state ",
2855 pp_context->sampler_state_table.bo_8x8 = bo;
2857 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
2858 bo = dri_bo_alloc(i965->intel.bufmgr,
2859 "sampler 8x8 state ",
2863 pp_context->sampler_state_table.bo_8x8_uv = bo;
2865 dri_bo_unreference(pp_context->vfe_state.bo);
2866 bo = dri_bo_alloc(i965->intel.bufmgr,
2868 sizeof(struct i965_vfe_state),
2871 pp_context->vfe_state.bo = bo;
2873 if (IS_GEN7(i965->intel.device_id)) {
2874 static_param_size = sizeof(struct gen7_pp_static_parameter);
2875 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
2877 static_param_size = sizeof(struct pp_static_parameter);
2878 inline_param_size = sizeof(struct pp_inline_parameter);
2881 memset(pp_context->pp_static_parameter, 0, static_param_size);
2882 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
2883 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
2884 pp_context->current_pp = pp_index;
2885 pp_module = &pp_context->pp_modules[pp_index];
2887 if (pp_module->initialize)
2888 va_status = pp_module->initialize(ctx, pp_context,
2895 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
2901 ironlake_post_processing(
2902 VADriverContextP ctx,
2903 struct i965_post_processing_context *pp_context,
2904 const struct i965_surface *src_surface,
2905 const VARectangle *src_rect,
2906 struct i965_surface *dst_surface,
2907 const VARectangle *dst_rect,
2914 va_status = ironlake_pp_initialize(ctx, pp_context,
2922 if (va_status == VA_STATUS_SUCCESS) {
2923 ironlake_pp_states_setup(ctx, pp_context);
2924 ironlake_pp_pipeline_setup(ctx, pp_context);
2932 VADriverContextP ctx,
2933 struct i965_post_processing_context *pp_context,
2934 const struct i965_surface *src_surface,
2935 const VARectangle *src_rect,
2936 struct i965_surface *dst_surface,
2937 const VARectangle *dst_rect,
2943 struct i965_driver_data *i965 = i965_driver_data(ctx);
2944 struct pp_module *pp_module;
2946 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2947 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2949 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
2950 bo = dri_bo_alloc(i965->intel.bufmgr,
2951 "surface state & binding table",
2952 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
2955 pp_context->surface_state_binding_table.bo = bo;
2957 dri_bo_unreference(pp_context->curbe.bo);
2958 bo = dri_bo_alloc(i965->intel.bufmgr,
2963 pp_context->curbe.bo = bo;
2965 dri_bo_unreference(pp_context->idrt.bo);
2966 bo = dri_bo_alloc(i965->intel.bufmgr,
2967 "interface discriptor",
2968 sizeof(struct gen6_interface_descriptor_data),
2971 pp_context->idrt.bo = bo;
2972 pp_context->idrt.num_interface_descriptors = 0;
2974 dri_bo_unreference(pp_context->sampler_state_table.bo);
2975 bo = dri_bo_alloc(i965->intel.bufmgr,
2976 "sampler state table",
2980 dri_bo_map(bo, True);
2981 memset(bo->virtual, 0, bo->size);
2983 pp_context->sampler_state_table.bo = bo;
2985 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
2986 bo = dri_bo_alloc(i965->intel.bufmgr,
2987 "sampler 8x8 state ",
2991 pp_context->sampler_state_table.bo_8x8 = bo;
2993 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
2994 bo = dri_bo_alloc(i965->intel.bufmgr,
2995 "sampler 8x8 state ",
2999 pp_context->sampler_state_table.bo_8x8_uv = bo;
3001 dri_bo_unreference(pp_context->vfe_state.bo);
3002 bo = dri_bo_alloc(i965->intel.bufmgr,
3004 sizeof(struct i965_vfe_state),
3007 pp_context->vfe_state.bo = bo;
3009 memset(pp_static_parameter, 0, sizeof(*pp_static_parameter));
3010 memset(pp_inline_parameter, 0, sizeof(*pp_inline_parameter));
3011 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3012 pp_context->current_pp = pp_index;
3013 pp_module = &pp_context->pp_modules[pp_index];
3015 if (pp_module->initialize)
3016 va_status = pp_module->initialize(ctx, pp_context,
3023 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3029 gen6_pp_interface_descriptor_table(VADriverContextP ctx,
3030 struct i965_post_processing_context *pp_context)
3032 struct i965_driver_data *i965 = i965_driver_data(ctx);
3033 struct gen6_interface_descriptor_data *desc;
3035 int pp_index = pp_context->current_pp;
3037 bo = pp_context->idrt.bo;
3038 dri_bo_map(bo, True);
3039 assert(bo->virtual);
3041 memset(desc, 0, sizeof(*desc));
3042 desc->desc0.kernel_start_pointer =
3043 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
3044 desc->desc1.single_program_flow = 1;
3045 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
3046 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
3047 desc->desc2.sampler_state_pointer =
3048 pp_context->sampler_state_table.bo->offset >> 5;
3049 desc->desc3.binding_table_entry_count = 0;
3050 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
3051 desc->desc4.constant_urb_entry_read_offset = 0;
3053 if (IS_GEN7(i965->intel.device_id))
3054 desc->desc4.constant_urb_entry_read_length = 6; /* grf 1-6 */
3056 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
3058 dri_bo_emit_reloc(bo,
3059 I915_GEM_DOMAIN_INSTRUCTION, 0,
3061 offsetof(struct gen6_interface_descriptor_data, desc0),
3062 pp_context->pp_modules[pp_index].kernel.bo);
3064 dri_bo_emit_reloc(bo,
3065 I915_GEM_DOMAIN_INSTRUCTION, 0,
3066 desc->desc2.sampler_count << 2,
3067 offsetof(struct gen6_interface_descriptor_data, desc2),
3068 pp_context->sampler_state_table.bo);
3071 pp_context->idrt.num_interface_descriptors++;
3075 gen6_pp_upload_constants(VADriverContextP ctx,
3076 struct i965_post_processing_context *pp_context)
3078 struct i965_driver_data *i965 = i965_driver_data(ctx);
3079 unsigned char *constant_buffer;
3082 assert(sizeof(struct pp_static_parameter) == 128);
3083 assert(sizeof(struct gen7_pp_static_parameter) == 192);
3085 if (IS_GEN7(i965->intel.device_id))
3086 param_size = sizeof(struct gen7_pp_static_parameter);
3088 param_size = sizeof(struct pp_static_parameter);
3090 dri_bo_map(pp_context->curbe.bo, 1);
3091 assert(pp_context->curbe.bo->virtual);
3092 constant_buffer = pp_context->curbe.bo->virtual;
3093 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
3094 dri_bo_unmap(pp_context->curbe.bo);
3098 gen6_pp_states_setup(VADriverContextP ctx,
3099 struct i965_post_processing_context *pp_context)
3101 gen6_pp_interface_descriptor_table(ctx, pp_context);
3102 gen6_pp_upload_constants(ctx, pp_context);
3106 gen6_pp_pipeline_select(VADriverContextP ctx,
3107 struct i965_post_processing_context *pp_context)
3109 struct intel_batchbuffer *batch = pp_context->batch;
3111 BEGIN_BATCH(batch, 1);
3112 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
3113 ADVANCE_BATCH(batch);
3117 gen6_pp_state_base_address(VADriverContextP ctx,
3118 struct i965_post_processing_context *pp_context)
3120 struct intel_batchbuffer *batch = pp_context->batch;
3122 BEGIN_BATCH(batch, 10);
3123 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
3124 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3125 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
3126 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3127 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3128 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3129 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3130 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3131 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3132 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3133 ADVANCE_BATCH(batch);
3137 gen6_pp_vfe_state(VADriverContextP ctx,
3138 struct i965_post_processing_context *pp_context)
3140 struct intel_batchbuffer *batch = pp_context->batch;
3142 BEGIN_BATCH(batch, 8);
3143 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
3144 OUT_BATCH(batch, 0);
3146 (pp_context->urb.num_vfe_entries - 1) << 16 |
3147 pp_context->urb.num_vfe_entries << 8);
3148 OUT_BATCH(batch, 0);
3150 (pp_context->urb.size_vfe_entry * 2) << 16 | /* URB Entry Allocation Size, in 256 bits unit */
3151 (pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2)); /* CURBE Allocation Size, in 256 bits unit */
3152 OUT_BATCH(batch, 0);
3153 OUT_BATCH(batch, 0);
3154 OUT_BATCH(batch, 0);
3155 ADVANCE_BATCH(batch);
3159 gen6_pp_curbe_load(VADriverContextP ctx,
3160 struct i965_post_processing_context *pp_context)
3162 struct intel_batchbuffer *batch = pp_context->batch;
3164 assert(pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32 <= pp_context->curbe.bo->size);
3166 BEGIN_BATCH(batch, 4);
3167 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
3168 OUT_BATCH(batch, 0);
3170 pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32);
3172 pp_context->curbe.bo,
3173 I915_GEM_DOMAIN_INSTRUCTION, 0,
3175 ADVANCE_BATCH(batch);
3179 gen6_interface_descriptor_load(VADriverContextP ctx,
3180 struct i965_post_processing_context *pp_context)
3182 struct intel_batchbuffer *batch = pp_context->batch;
3184 BEGIN_BATCH(batch, 4);
3185 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
3186 OUT_BATCH(batch, 0);
3188 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
3190 pp_context->idrt.bo,
3191 I915_GEM_DOMAIN_INSTRUCTION, 0,
3193 ADVANCE_BATCH(batch);
3197 gen6_pp_object_walker(VADriverContextP ctx,
3198 struct i965_post_processing_context *pp_context)
3200 struct i965_driver_data *i965 = i965_driver_data(ctx);
3201 struct intel_batchbuffer *batch = pp_context->batch;
3202 int x, x_steps, y, y_steps;
3203 int param_size, command_length_in_dws;
3204 dri_bo *command_buffer;
3205 unsigned int *command_ptr;
3207 if (IS_GEN7(i965->intel.device_id))
3208 param_size = sizeof(struct gen7_pp_inline_parameter);
3210 param_size = sizeof(struct pp_inline_parameter);
3212 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
3213 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
3214 command_length_in_dws = 6 + (param_size >> 2);
3215 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
3216 "command objects buffer",
3217 command_length_in_dws * 4 * x_steps * y_steps + 8,
3220 dri_bo_map(command_buffer, 1);
3221 command_ptr = command_buffer->virtual;
3223 for (y = 0; y < y_steps; y++) {
3224 for (x = 0; x < x_steps; x++) {
3225 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
3226 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
3232 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
3233 command_ptr += (param_size >> 2);
3238 if (command_length_in_dws * x_steps * y_steps % 2 == 0)
3241 *command_ptr = MI_BATCH_BUFFER_END;
3243 dri_bo_unmap(command_buffer);
3245 BEGIN_BATCH(batch, 2);
3246 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (2 << 6));
3247 OUT_RELOC(batch, command_buffer,
3248 I915_GEM_DOMAIN_COMMAND, 0,
3250 ADVANCE_BATCH(batch);
3252 dri_bo_unreference(command_buffer);
3254 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
3255 * will cause control to pass back to ring buffer
3257 intel_batchbuffer_end_atomic(batch);
3258 intel_batchbuffer_flush(batch);
3259 intel_batchbuffer_start_atomic(batch, 0x1000);
3263 gen6_pp_pipeline_setup(VADriverContextP ctx,
3264 struct i965_post_processing_context *pp_context)
3266 struct intel_batchbuffer *batch = pp_context->batch;
3268 intel_batchbuffer_start_atomic(batch, 0x1000);
3269 intel_batchbuffer_emit_mi_flush(batch);
3270 gen6_pp_pipeline_select(ctx, pp_context);
3271 gen6_pp_state_base_address(ctx, pp_context);
3272 gen6_pp_vfe_state(ctx, pp_context);
3273 gen6_pp_curbe_load(ctx, pp_context);
3274 gen6_interface_descriptor_load(ctx, pp_context);
3275 gen6_pp_object_walker(ctx, pp_context);
3276 intel_batchbuffer_end_atomic(batch);
3280 gen6_post_processing(
3281 VADriverContextP ctx,
3282 struct i965_post_processing_context *pp_context,
3283 const struct i965_surface *src_surface,
3284 const VARectangle *src_rect,
3285 struct i965_surface *dst_surface,
3286 const VARectangle *dst_rect,
3293 va_status = gen6_pp_initialize(ctx, pp_context,
3301 if (va_status == VA_STATUS_SUCCESS) {
3302 gen6_pp_states_setup(ctx, pp_context);
3303 gen6_pp_pipeline_setup(ctx, pp_context);
3310 i965_post_processing_internal(
3311 VADriverContextP ctx,
3312 struct i965_post_processing_context *pp_context,
3313 const struct i965_surface *src_surface,
3314 const VARectangle *src_rect,
3315 struct i965_surface *dst_surface,
3316 const VARectangle *dst_rect,
3321 struct i965_driver_data *i965 = i965_driver_data(ctx);
3324 if (IS_GEN6(i965->intel.device_id) ||
3325 IS_GEN7(i965->intel.device_id))
3326 va_status = gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3328 va_status = ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3334 i965_DestroySurfaces(VADriverContextP ctx,
3335 VASurfaceID *surface_list,
3338 i965_CreateSurfaces(VADriverContextP ctx,
3343 VASurfaceID *surfaces);
3346 i965_vpp_clear_surface(VADriverContextP ctx,
3347 struct i965_post_processing_context *pp_context,
3348 VASurfaceID surface,
3351 struct i965_driver_data *i965 = i965_driver_data(ctx);
3352 struct intel_batchbuffer *batch = pp_context->batch;
3353 struct object_surface *obj_surface = SURFACE(surface);
3354 unsigned int blt_cmd, br13;
3355 unsigned int tiling = 0, swizzle = 0;
3358 /* Currently only support NV12 surface */
3359 if (!obj_surface || obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3362 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3363 blt_cmd = XY_COLOR_BLT_CMD;
3364 pitch = obj_surface->width;
3366 if (tiling != I915_TILING_NONE) {
3367 blt_cmd |= XY_COLOR_BLT_DST_TILED;
3375 if (IS_GEN6(i965->intel.device_id) ||
3376 IS_GEN7(i965->intel.device_id)) {
3377 intel_batchbuffer_start_atomic_blt(batch, 48);
3378 BEGIN_BLT_BATCH(batch, 12);
3380 intel_batchbuffer_start_atomic(batch, 48);
3381 BEGIN_BATCH(batch, 12);
3384 OUT_BATCH(batch, blt_cmd);
3385 OUT_BATCH(batch, br13);
3390 obj_surface->height << 16 |
3391 obj_surface->width);
3392 OUT_RELOC(batch, obj_surface->bo,
3393 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3395 OUT_BATCH(batch, 0x10);
3397 OUT_BATCH(batch, blt_cmd);
3398 OUT_BATCH(batch, br13);
3403 obj_surface->height / 2 << 16 |
3404 obj_surface->width);
3405 OUT_RELOC(batch, obj_surface->bo,
3406 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3407 obj_surface->width * obj_surface->y_cb_offset);
3408 OUT_BATCH(batch, 0x80);
3410 ADVANCE_BATCH(batch);
3411 intel_batchbuffer_end_atomic(batch);
3415 i965_post_processing(
3416 VADriverContextP ctx,
3417 VASurfaceID surface,
3418 const VARectangle *src_rect,
3419 const VARectangle *dst_rect,
3421 int *has_done_scaling
3424 struct i965_driver_data *i965 = i965_driver_data(ctx);
3425 VASurfaceID in_surface_id = surface;
3426 VASurfaceID out_surface_id = VA_INVALID_ID;
3428 *has_done_scaling = 0;
3431 struct object_surface *obj_surface;
3433 struct i965_surface src_surface;
3434 struct i965_surface dst_surface;
3436 obj_surface = SURFACE(in_surface_id);
3438 /* Currently only support post processing for NV12 surface */
3439 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3440 return out_surface_id;
3442 if (flags & I965_PP_FLAG_DEINTERLACING) {
3443 status = i965_CreateSurfaces(ctx,
3444 obj_surface->orig_width,
3445 obj_surface->orig_height,
3446 VA_RT_FORMAT_YUV420,
3449 assert(status == VA_STATUS_SUCCESS);
3450 obj_surface = SURFACE(out_surface_id);
3451 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3452 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3453 src_surface.id = in_surface_id;
3454 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3455 src_surface.flags = (flags & I965_PP_FLAG_DEINTERLACING_TOP_FISRT) ?
3456 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
3457 dst_surface.id = out_surface_id;
3458 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3459 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3461 i965_post_processing_internal(ctx, i965->pp_context,
3470 if (flags & I965_PP_FLAG_AVS) {
3471 struct i965_render_state *render_state = &i965->render_state;
3472 struct intel_region *dest_region = render_state->draw_region;
3474 if (out_surface_id != VA_INVALID_ID)
3475 in_surface_id = out_surface_id;
3477 status = i965_CreateSurfaces(ctx,
3479 dest_region->height,
3480 VA_RT_FORMAT_YUV420,
3483 assert(status == VA_STATUS_SUCCESS);
3484 obj_surface = SURFACE(out_surface_id);
3485 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3486 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3487 src_surface.id = in_surface_id;
3488 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3489 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3490 dst_surface.id = out_surface_id;
3491 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3492 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3494 i965_post_processing_internal(ctx, i965->pp_context,
3502 if (in_surface_id != surface)
3503 i965_DestroySurfaces(ctx, &in_surface_id, 1);
3505 *has_done_scaling = 1;
3509 return out_surface_id;
3513 i965_image_i420_processing(VADriverContextP ctx,
3514 const struct i965_surface *src_surface,
3515 const VARectangle *src_rect,
3516 struct i965_surface *dst_surface,
3517 const VARectangle *dst_rect)
3519 struct i965_driver_data *i965 = i965_driver_data(ctx);
3520 struct i965_post_processing_context *pp_context = i965->pp_context;
3521 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
3523 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
3524 i965_post_processing_internal(ctx, i965->pp_context,
3529 PP_PL3_LOAD_SAVE_N12,
3532 i965_post_processing_internal(ctx, i965->pp_context,
3537 PP_PL3_LOAD_SAVE_PL3,
3541 intel_batchbuffer_flush(pp_context->batch);
3543 return VA_STATUS_SUCCESS;
3547 i965_image_nv12_processing(VADriverContextP ctx,
3548 const struct i965_surface *src_surface,
3549 const VARectangle *src_rect,
3550 struct i965_surface *dst_surface,
3551 const VARectangle *dst_rect)
3553 struct i965_driver_data *i965 = i965_driver_data(ctx);
3554 struct i965_post_processing_context *pp_context = i965->pp_context;
3555 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
3557 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
3558 i965_post_processing_internal(ctx, i965->pp_context,
3563 PP_NV12_LOAD_SAVE_N12,
3566 i965_post_processing_internal(ctx, i965->pp_context,
3571 PP_NV12_LOAD_SAVE_PL3,
3575 intel_batchbuffer_flush(pp_context->batch);
3577 return VA_STATUS_SUCCESS;
3581 i965_image_processing(VADriverContextP ctx,
3582 const struct i965_surface *src_surface,
3583 const VARectangle *src_rect,
3584 struct i965_surface *dst_surface,
3585 const VARectangle *dst_rect)
3587 struct i965_driver_data *i965 = i965_driver_data(ctx);
3588 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
3591 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
3594 case VA_FOURCC('Y', 'V', '1', '2'):
3595 case VA_FOURCC('I', '4', '2', '0'):
3596 status = i965_image_i420_processing(ctx,
3603 case VA_FOURCC('N', 'V', '1', '2'):
3604 status = i965_image_nv12_processing(ctx,
3612 status = VA_STATUS_ERROR_UNIMPLEMENTED;
3621 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
3625 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3626 pp_context->surface_state_binding_table.bo = NULL;
3628 dri_bo_unreference(pp_context->curbe.bo);
3629 pp_context->curbe.bo = NULL;
3631 dri_bo_unreference(pp_context->sampler_state_table.bo);
3632 pp_context->sampler_state_table.bo = NULL;
3634 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3635 pp_context->sampler_state_table.bo_8x8 = NULL;
3637 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3638 pp_context->sampler_state_table.bo_8x8_uv = NULL;
3640 dri_bo_unreference(pp_context->idrt.bo);
3641 pp_context->idrt.bo = NULL;
3642 pp_context->idrt.num_interface_descriptors = 0;
3644 dri_bo_unreference(pp_context->vfe_state.bo);
3645 pp_context->vfe_state.bo = NULL;
3647 dri_bo_unreference(pp_context->stmm.bo);
3648 pp_context->stmm.bo = NULL;
3650 for (i = 0; i < NUM_PP_MODULES; i++) {
3651 struct pp_module *pp_module = &pp_context->pp_modules[i];
3653 dri_bo_unreference(pp_module->kernel.bo);
3654 pp_module->kernel.bo = NULL;
3657 free(pp_context->pp_static_parameter);
3658 free(pp_context->pp_inline_parameter);
3659 pp_context->pp_static_parameter = NULL;
3660 pp_context->pp_inline_parameter = NULL;
3664 i965_post_processing_terminate(VADriverContextP ctx)
3666 struct i965_driver_data *i965 = i965_driver_data(ctx);
3667 struct i965_post_processing_context *pp_context = i965->pp_context;
3670 i965_post_processing_context_finalize(pp_context);
3674 i965->pp_context = NULL;
3680 i965_post_processing_context_init(VADriverContextP ctx,
3681 struct i965_post_processing_context *pp_context,
3682 struct intel_batchbuffer *batch)
3684 struct i965_driver_data *i965 = i965_driver_data(ctx);
3687 pp_context->urb.size = URB_SIZE((&i965->intel));
3688 pp_context->urb.num_vfe_entries = 32;
3689 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
3690 pp_context->urb.num_cs_entries = 1;
3692 if (IS_GEN7(i965->intel.device_id))
3693 pp_context->urb.size_cs_entry = 4; /* in 512 bits unit */
3695 pp_context->urb.size_cs_entry = 2;
3697 pp_context->urb.vfe_start = 0;
3698 pp_context->urb.cs_start = pp_context->urb.vfe_start +
3699 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
3700 assert(pp_context->urb.cs_start +
3701 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
3703 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
3704 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
3705 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen7));
3707 if (IS_GEN7(i965->intel.device_id))
3708 memcpy(pp_context->pp_modules, pp_modules_gen7, sizeof(pp_context->pp_modules));
3709 else if (IS_GEN6(i965->intel.device_id))
3710 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
3711 else if (IS_IRONLAKE(i965->intel.device_id))
3712 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
3714 for (i = 0; i < NUM_PP_MODULES; i++) {
3715 struct pp_module *pp_module = &pp_context->pp_modules[i];
3716 dri_bo_unreference(pp_module->kernel.bo);
3717 if (pp_module->kernel.bin && pp_module->kernel.size) {
3718 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
3719 pp_module->kernel.name,
3720 pp_module->kernel.size,
3722 assert(pp_module->kernel.bo);
3723 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
3725 pp_module->kernel.bo = NULL;
3729 /* static & inline parameters */
3730 if (IS_GEN7(i965->intel.device_id)) {
3731 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
3732 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
3734 pp_context->pp_static_parameter = calloc(sizeof(struct pp_static_parameter), 1);
3735 pp_context->pp_inline_parameter = calloc(sizeof(struct pp_inline_parameter), 1);
3738 pp_context->batch = batch;
3742 i965_post_processing_init(VADriverContextP ctx)
3744 struct i965_driver_data *i965 = i965_driver_data(ctx);
3745 struct i965_post_processing_context *pp_context = i965->pp_context;
3748 if (pp_context == NULL) {
3749 pp_context = calloc(1, sizeof(*pp_context));
3750 i965_post_processing_context_init(ctx, pp_context, i965->batch);
3751 i965->pp_context = pp_context;
3758 static const int procfilter_to_pp_flag[10] = {
3759 PP_NULL, /* VAProcFilterNone */
3760 PP_NULL, /* VAProcFilterDering */
3761 PP_NULL, /* VAProcFilterDeblocking */
3762 PP_NV12_DN, /* VAProcFilterNoiseReduction */
3763 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
3764 PP_NULL, /* VAProcFilterSharpening */
3765 PP_NULL, /* VAProcFilterColorEnhancement */
3766 PP_NULL, /* VAProcFilterProcAmp */
3767 PP_NULL, /* VAProcFilterComposition */
3768 PP_NULL, /* VAProcFilterFrameRateConversion */
3771 static const int proc_frame_to_pp_frame[3] = {
3772 I965_SURFACE_FLAG_FRAME,
3773 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
3774 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
3778 i965_proc_picture(VADriverContextP ctx,
3780 union codec_state *codec_state,
3781 struct hw_context *hw_context)
3783 struct i965_driver_data *i965 = i965_driver_data(ctx);
3784 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
3785 struct proc_state *proc_state = &codec_state->proc;
3786 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
3787 VAProcInputParameterBuffer *input_param = (VAProcInputParameterBuffer *)proc_state->input_param->buffer;
3788 struct object_surface *obj_surface;
3789 struct i965_surface src_surface, dst_surface;
3792 VASurfaceID tmp_surfaces[VA_PROC_PIPELINE_MAX_NUM_FILTERS + 4];
3793 int num_tmp_surfaces = 0;
3794 unsigned int tiling = 0, swizzle = 0;
3795 int in_width, in_height;
3797 assert(input_param->surface != VA_INVALID_ID);
3798 assert(proc_state->current_render_target != VA_INVALID_ID);
3800 obj_surface = SURFACE(input_param->surface);
3801 in_width = obj_surface->orig_width;
3802 in_height = obj_surface->orig_height;
3803 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3805 src_surface.id = input_param->surface;
3806 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3807 src_surface.flags = proc_frame_to_pp_frame[input_param->flags];
3809 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
3810 struct i965_surface src_surface, dst_surface;
3811 VARectangle src_rect, dst_rect;
3812 VASurfaceID out_surface_id = VA_INVALID_ID;
3814 src_surface.id = input_param->surface;
3815 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3816 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3819 src_rect.width = in_width;
3820 src_rect.height = in_height;
3822 status = i965_CreateSurfaces(ctx,
3825 VA_RT_FORMAT_YUV420,
3828 assert(status == VA_STATUS_SUCCESS);
3829 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
3830 obj_surface = SURFACE(out_surface_id);
3831 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
3833 dst_surface.id = out_surface_id;
3834 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3835 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3838 dst_rect.width = in_width;
3839 dst_rect.height = in_height;
3841 status = i965_image_processing(ctx,
3846 assert(status == VA_STATUS_SUCCESS);
3848 src_surface.id = out_surface_id;
3849 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3850 src_surface.flags = proc_frame_to_pp_frame[input_param->flags];
3853 obj_surface = SURFACE(proc_state->current_render_target);
3854 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3856 for (i = 0; i < VA_PROC_PIPELINE_MAX_NUM_FILTERS; i++) {
3857 VAProcFilterType filter_type = pipeline_param->filter_pipeline[i];
3858 VASurfaceID out_surface_id = VA_INVALID_ID;
3859 void *filter_param = NULL;
3861 if (procfilter_to_pp_flag[filter_type] != PP_NULL) {
3862 if (proc_state->filter_param[filter_type])
3863 filter_param = proc_state->filter_param[filter_type]->buffer;
3865 status = i965_CreateSurfaces(ctx,
3868 VA_RT_FORMAT_YUV420,
3871 assert(status == VA_STATUS_SUCCESS);
3872 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
3873 obj_surface = SURFACE(out_surface_id);
3874 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3875 dst_surface.id = out_surface_id;
3876 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3877 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
3879 &input_param->region,
3881 &input_param->region,
3882 procfilter_to_pp_flag[filter_type],
3885 if (status == VA_STATUS_SUCCESS) {
3886 src_surface.id = dst_surface.id;
3887 src_surface.type = dst_surface.type;
3888 src_surface.flags = dst_surface.flags;
3893 dst_surface.id = proc_state->current_render_target;
3894 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3895 i965_post_processing_internal(ctx, &proc_context->pp_context,
3897 &input_param->region,
3899 &pipeline_param->output_region,
3900 (pipeline_param->flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC ?
3901 PP_NV12_AVS : PP_NV12_SCALING,
3904 if (num_tmp_surfaces)
3905 i965_DestroySurfaces(ctx,
3909 intel_batchbuffer_flush(hw_context->batch);
3913 i965_proc_context_destroy(void *hw_context)
3915 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
3917 i965_post_processing_context_finalize(&proc_context->pp_context);
3918 intel_batchbuffer_free(proc_context->base.batch);
3923 i965_proc_context_init(VADriverContextP ctx, VAProfile profile)
3925 struct intel_driver_data *intel = intel_driver_data(ctx);
3926 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
3928 proc_context->base.destroy = i965_proc_context_destroy;
3929 proc_context->base.run = i965_proc_picture;
3930 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
3931 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
3933 return (struct hw_context *)proc_context;