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 const uint32_t pp_nv12_load_save_pa_gen5[][4] = {
95 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g4b.gen5"
98 static VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
99 const struct i965_surface *src_surface,
100 const VARectangle *src_rect,
101 struct i965_surface *dst_surface,
102 const VARectangle *dst_rect,
104 static VAStatus pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
105 const struct i965_surface *src_surface,
106 const VARectangle *src_rect,
107 struct i965_surface *dst_surface,
108 const VARectangle *dst_rect,
110 static VAStatus pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
111 const struct i965_surface *src_surface,
112 const VARectangle *src_rect,
113 struct i965_surface *dst_surface,
114 const VARectangle *dst_rect,
116 static VAStatus gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
117 const struct i965_surface *src_surface,
118 const VARectangle *src_rect,
119 struct i965_surface *dst_surface,
120 const VARectangle *dst_rect,
122 static VAStatus pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
123 const struct i965_surface *src_surface,
124 const VARectangle *src_rect,
125 struct i965_surface *dst_surface,
126 const VARectangle *dst_rect,
128 static VAStatus pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
129 const struct i965_surface *src_surface,
130 const VARectangle *src_rect,
131 struct i965_surface *dst_surface,
132 const VARectangle *dst_rect,
134 static VAStatus pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
135 const struct i965_surface *src_surface,
136 const VARectangle *src_rect,
137 struct i965_surface *dst_surface,
138 const VARectangle *dst_rect,
141 static struct pp_module pp_modules_gen5[] = {
144 "NULL module (for testing)",
147 sizeof(pp_null_gen5),
157 PP_NV12_LOAD_SAVE_N12,
158 pp_nv12_load_save_nv12_gen5,
159 sizeof(pp_nv12_load_save_nv12_gen5),
163 pp_plx_load_save_plx_initialize,
169 PP_NV12_LOAD_SAVE_PL3,
170 pp_nv12_load_save_pl3_gen5,
171 sizeof(pp_nv12_load_save_pl3_gen5),
175 pp_plx_load_save_plx_initialize,
181 PP_PL3_LOAD_SAVE_N12,
182 pp_pl3_load_save_nv12_gen5,
183 sizeof(pp_pl3_load_save_nv12_gen5),
187 pp_plx_load_save_plx_initialize,
193 PP_PL3_LOAD_SAVE_N12,
194 pp_pl3_load_save_pl3_gen5,
195 sizeof(pp_pl3_load_save_pl3_gen5),
199 pp_plx_load_save_plx_initialize
204 "NV12 Scaling module",
206 pp_nv12_scaling_gen5,
207 sizeof(pp_nv12_scaling_gen5),
211 pp_nv12_scaling_initialize,
219 sizeof(pp_nv12_avs_gen5),
223 pp_nv12_avs_initialize_nlas,
231 sizeof(pp_nv12_dndi_gen5),
235 pp_nv12_dndi_initialize,
243 sizeof(pp_nv12_dn_gen5),
247 pp_nv12_dn_initialize,
253 PP_NV12_LOAD_SAVE_PA,
254 pp_nv12_load_save_pa_gen5,
255 sizeof(pp_nv12_load_save_pa_gen5),
259 pp_plx_load_save_plx_initialize,
264 static const uint32_t pp_null_gen6[][4] = {
265 #include "shaders/post_processing/gen5_6/null.g6b"
268 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
269 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
272 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
273 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
276 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
277 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
280 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
281 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
284 static const uint32_t pp_nv12_scaling_gen6[][4] = {
285 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
288 static const uint32_t pp_nv12_avs_gen6[][4] = {
289 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
292 static const uint32_t pp_nv12_dndi_gen6[][4] = {
293 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
296 static const uint32_t pp_nv12_dn_gen6[][4] = {
297 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g6b"
300 static const uint32_t pp_nv12_load_save_pa_gen6[][4] = {
301 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g6b"
304 static struct pp_module pp_modules_gen6[] = {
307 "NULL module (for testing)",
310 sizeof(pp_null_gen6),
320 PP_NV12_LOAD_SAVE_N12,
321 pp_nv12_load_save_nv12_gen6,
322 sizeof(pp_nv12_load_save_nv12_gen6),
326 pp_plx_load_save_plx_initialize,
332 PP_NV12_LOAD_SAVE_PL3,
333 pp_nv12_load_save_pl3_gen6,
334 sizeof(pp_nv12_load_save_pl3_gen6),
338 pp_plx_load_save_plx_initialize,
344 PP_PL3_LOAD_SAVE_N12,
345 pp_pl3_load_save_nv12_gen6,
346 sizeof(pp_pl3_load_save_nv12_gen6),
350 pp_plx_load_save_plx_initialize,
356 PP_PL3_LOAD_SAVE_N12,
357 pp_pl3_load_save_pl3_gen6,
358 sizeof(pp_pl3_load_save_pl3_gen6),
362 pp_plx_load_save_plx_initialize,
367 "NV12 Scaling module",
369 pp_nv12_scaling_gen6,
370 sizeof(pp_nv12_scaling_gen6),
374 gen6_nv12_scaling_initialize,
382 sizeof(pp_nv12_avs_gen6),
386 pp_nv12_avs_initialize_nlas,
394 sizeof(pp_nv12_dndi_gen6),
398 pp_nv12_dndi_initialize,
406 sizeof(pp_nv12_dn_gen6),
410 pp_nv12_dn_initialize,
415 PP_NV12_LOAD_SAVE_PA,
416 pp_nv12_load_save_pa_gen6,
417 sizeof(pp_nv12_load_save_pa_gen6),
421 pp_plx_load_save_plx_initialize,
427 static const uint32_t pp_null_gen7[][4] = {
430 static const uint32_t pp_nv12_load_save_nv12_gen7[][4] = {
431 #include "shaders/post_processing/gen7/pl2_to_pl2.g7b"
434 static const uint32_t pp_nv12_load_save_pl3_gen7[][4] = {
435 #include "shaders/post_processing/gen7/pl2_to_pl3.g7b"
438 static const uint32_t pp_pl3_load_save_nv12_gen7[][4] = {
439 #include "shaders/post_processing/gen7/pl3_to_pl2.g7b"
442 static const uint32_t pp_pl3_load_save_pl3_gen7[][4] = {
443 #include "shaders/post_processing/gen7/pl3_to_pl3.g7b"
446 static const uint32_t pp_nv12_scaling_gen7[][4] = {
447 #include "shaders/post_processing/gen7/avs.g7b"
450 static const uint32_t pp_nv12_avs_gen7[][4] = {
451 #include "shaders/post_processing/gen7/avs.g7b"
454 static const uint32_t pp_nv12_dndi_gen7[][4] = {
455 #include "shaders/post_processing/gen7/dndi.g7b"
458 static const uint32_t pp_nv12_dn_gen7[][4] = {
460 static const uint32_t pp_nv12_load_save_pa_gen7[][4] = {
463 static VAStatus gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
464 const struct i965_surface *src_surface,
465 const VARectangle *src_rect,
466 struct i965_surface *dst_surface,
467 const VARectangle *dst_rect,
469 static VAStatus gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
470 const struct i965_surface *src_surface,
471 const VARectangle *src_rect,
472 struct i965_surface *dst_surface,
473 const VARectangle *dst_rect,
475 static VAStatus gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
476 const struct i965_surface *src_surface,
477 const VARectangle *src_rect,
478 struct i965_surface *dst_surface,
479 const VARectangle *dst_rect,
482 static struct pp_module pp_modules_gen7[] = {
485 "NULL module (for testing)",
488 sizeof(pp_null_gen7),
498 PP_NV12_LOAD_SAVE_N12,
499 pp_nv12_load_save_nv12_gen7,
500 sizeof(pp_nv12_load_save_nv12_gen7),
504 gen7_pp_plx_avs_initialize,
510 PP_NV12_LOAD_SAVE_PL3,
511 pp_nv12_load_save_pl3_gen7,
512 sizeof(pp_nv12_load_save_pl3_gen7),
516 gen7_pp_plx_avs_initialize,
522 PP_PL3_LOAD_SAVE_N12,
523 pp_pl3_load_save_nv12_gen7,
524 sizeof(pp_pl3_load_save_nv12_gen7),
528 gen7_pp_plx_avs_initialize,
534 PP_PL3_LOAD_SAVE_N12,
535 pp_pl3_load_save_pl3_gen7,
536 sizeof(pp_pl3_load_save_pl3_gen7),
540 gen7_pp_plx_avs_initialize,
545 "NV12 Scaling module",
547 pp_nv12_scaling_gen7,
548 sizeof(pp_nv12_scaling_gen7),
552 gen7_pp_plx_avs_initialize,
560 sizeof(pp_nv12_avs_gen7),
564 gen7_pp_plx_avs_initialize,
572 sizeof(pp_nv12_dndi_gen7),
576 gen7_pp_nv12_dndi_initialize,
584 sizeof(pp_nv12_dn_gen7),
588 gen7_pp_nv12_dn_initialize,
593 PP_NV12_LOAD_SAVE_PA,
594 pp_nv12_load_save_pa_gen7,
595 sizeof(pp_nv12_load_save_pa_gen7),
599 pp_plx_load_save_plx_initialize,
605 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
607 struct i965_driver_data *i965 = i965_driver_data(ctx);
610 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
611 struct object_image *obj_image = IMAGE(surface->id);
612 fourcc = obj_image->image.format.fourcc;
614 struct object_surface *obj_surface = SURFACE(surface->id);
615 fourcc = obj_surface->fourcc;
622 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
625 case I915_TILING_NONE:
626 ss->ss3.tiled_surface = 0;
627 ss->ss3.tile_walk = 0;
630 ss->ss3.tiled_surface = 1;
631 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
634 ss->ss3.tiled_surface = 1;
635 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
641 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
644 case I915_TILING_NONE:
645 ss->ss2.tiled_surface = 0;
646 ss->ss2.tile_walk = 0;
649 ss->ss2.tiled_surface = 1;
650 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
653 ss->ss2.tiled_surface = 1;
654 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
660 gen7_pp_set_surface_tiling(struct gen7_surface_state *ss, unsigned int tiling)
663 case I915_TILING_NONE:
664 ss->ss0.tiled_surface = 0;
665 ss->ss0.tile_walk = 0;
668 ss->ss0.tiled_surface = 1;
669 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
672 ss->ss0.tiled_surface = 1;
673 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
679 gen7_pp_set_surface2_tiling(struct gen7_surface_state2 *ss, unsigned int tiling)
682 case I915_TILING_NONE:
683 ss->ss2.tiled_surface = 0;
684 ss->ss2.tile_walk = 0;
687 ss->ss2.tiled_surface = 1;
688 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
691 ss->ss2.tiled_surface = 1;
692 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
698 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
700 struct i965_interface_descriptor *desc;
702 int pp_index = pp_context->current_pp;
704 bo = pp_context->idrt.bo;
708 memset(desc, 0, sizeof(*desc));
709 desc->desc0.grf_reg_blocks = 10;
710 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
711 desc->desc1.const_urb_entry_read_offset = 0;
712 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
713 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
714 desc->desc2.sampler_count = 0;
715 desc->desc3.binding_table_entry_count = 0;
716 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
718 dri_bo_emit_reloc(bo,
719 I915_GEM_DOMAIN_INSTRUCTION, 0,
720 desc->desc0.grf_reg_blocks,
721 offsetof(struct i965_interface_descriptor, desc0),
722 pp_context->pp_modules[pp_index].kernel.bo);
724 dri_bo_emit_reloc(bo,
725 I915_GEM_DOMAIN_INSTRUCTION, 0,
726 desc->desc2.sampler_count << 2,
727 offsetof(struct i965_interface_descriptor, desc2),
728 pp_context->sampler_state_table.bo);
731 pp_context->idrt.num_interface_descriptors++;
735 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
737 struct i965_vfe_state *vfe_state;
740 bo = pp_context->vfe_state.bo;
743 vfe_state = bo->virtual;
744 memset(vfe_state, 0, sizeof(*vfe_state));
745 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
746 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
747 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
748 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
749 vfe_state->vfe1.children_present = 0;
750 vfe_state->vfe2.interface_descriptor_base =
751 pp_context->idrt.bo->offset >> 4; /* reloc */
752 dri_bo_emit_reloc(bo,
753 I915_GEM_DOMAIN_INSTRUCTION, 0,
755 offsetof(struct i965_vfe_state, vfe2),
756 pp_context->idrt.bo);
761 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
763 unsigned char *constant_buffer;
764 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
766 assert(sizeof(*pp_static_parameter) == 128);
767 dri_bo_map(pp_context->curbe.bo, 1);
768 assert(pp_context->curbe.bo->virtual);
769 constant_buffer = pp_context->curbe.bo->virtual;
770 memcpy(constant_buffer, pp_static_parameter, sizeof(*pp_static_parameter));
771 dri_bo_unmap(pp_context->curbe.bo);
775 ironlake_pp_states_setup(VADriverContextP ctx,
776 struct i965_post_processing_context *pp_context)
778 ironlake_pp_interface_descriptor_table(pp_context);
779 ironlake_pp_vfe_state(pp_context);
780 ironlake_pp_upload_constants(pp_context);
784 ironlake_pp_pipeline_select(VADriverContextP ctx,
785 struct i965_post_processing_context *pp_context)
787 struct intel_batchbuffer *batch = pp_context->batch;
789 BEGIN_BATCH(batch, 1);
790 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
791 ADVANCE_BATCH(batch);
795 ironlake_pp_urb_layout(VADriverContextP ctx,
796 struct i965_post_processing_context *pp_context)
798 struct intel_batchbuffer *batch = pp_context->batch;
799 unsigned int vfe_fence, cs_fence;
801 vfe_fence = pp_context->urb.cs_start;
802 cs_fence = pp_context->urb.size;
804 BEGIN_BATCH(batch, 3);
805 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
808 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
809 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
810 ADVANCE_BATCH(batch);
814 ironlake_pp_state_base_address(VADriverContextP ctx,
815 struct i965_post_processing_context *pp_context)
817 struct intel_batchbuffer *batch = pp_context->batch;
819 BEGIN_BATCH(batch, 8);
820 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
821 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
822 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
823 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
824 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
825 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
826 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
827 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
828 ADVANCE_BATCH(batch);
832 ironlake_pp_state_pointers(VADriverContextP ctx,
833 struct i965_post_processing_context *pp_context)
835 struct intel_batchbuffer *batch = pp_context->batch;
837 BEGIN_BATCH(batch, 3);
838 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
840 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
841 ADVANCE_BATCH(batch);
845 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
846 struct i965_post_processing_context *pp_context)
848 struct intel_batchbuffer *batch = pp_context->batch;
850 BEGIN_BATCH(batch, 2);
851 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
853 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
854 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
855 ADVANCE_BATCH(batch);
859 ironlake_pp_constant_buffer(VADriverContextP ctx,
860 struct i965_post_processing_context *pp_context)
862 struct intel_batchbuffer *batch = pp_context->batch;
864 BEGIN_BATCH(batch, 2);
865 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
866 OUT_RELOC(batch, pp_context->curbe.bo,
867 I915_GEM_DOMAIN_INSTRUCTION, 0,
868 pp_context->urb.size_cs_entry - 1);
869 ADVANCE_BATCH(batch);
873 ironlake_pp_object_walker(VADriverContextP ctx,
874 struct i965_post_processing_context *pp_context)
876 struct intel_batchbuffer *batch = pp_context->batch;
877 int x, x_steps, y, y_steps;
878 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
880 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
881 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
883 for (y = 0; y < y_steps; y++) {
884 for (x = 0; x < x_steps; x++) {
885 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
886 BEGIN_BATCH(batch, 20);
887 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
889 OUT_BATCH(batch, 0); /* no indirect data */
892 /* inline data grf 5-6 */
893 assert(sizeof(*pp_inline_parameter) == 64);
894 intel_batchbuffer_data(batch, pp_inline_parameter, sizeof(*pp_inline_parameter));
896 ADVANCE_BATCH(batch);
903 ironlake_pp_pipeline_setup(VADriverContextP ctx,
904 struct i965_post_processing_context *pp_context)
906 struct intel_batchbuffer *batch = pp_context->batch;
908 intel_batchbuffer_start_atomic(batch, 0x1000);
909 intel_batchbuffer_emit_mi_flush(batch);
910 ironlake_pp_pipeline_select(ctx, pp_context);
911 ironlake_pp_state_base_address(ctx, pp_context);
912 ironlake_pp_state_pointers(ctx, pp_context);
913 ironlake_pp_urb_layout(ctx, pp_context);
914 ironlake_pp_cs_urb_layout(ctx, pp_context);
915 ironlake_pp_constant_buffer(ctx, pp_context);
916 ironlake_pp_object_walker(ctx, pp_context);
917 intel_batchbuffer_end_atomic(batch);
921 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
922 dri_bo *surf_bo, unsigned long surf_bo_offset,
923 int width, int height, int pitch, int format,
924 int index, int is_target)
926 struct i965_surface_state *ss;
929 unsigned int swizzle;
931 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
932 ss_bo = pp_context->surface_state_binding_table.bo;
935 dri_bo_map(ss_bo, True);
936 assert(ss_bo->virtual);
937 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
938 memset(ss, 0, sizeof(*ss));
939 ss->ss0.surface_type = I965_SURFACE_2D;
940 ss->ss0.surface_format = format;
941 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
942 ss->ss2.width = width - 1;
943 ss->ss2.height = height - 1;
944 ss->ss3.pitch = pitch - 1;
945 pp_set_surface_tiling(ss, tiling);
946 dri_bo_emit_reloc(ss_bo,
947 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
949 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
951 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
956 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
957 dri_bo *surf_bo, unsigned long surf_bo_offset,
958 int width, int height, int wpitch,
959 int xoffset, int yoffset,
960 int format, int interleave_chroma,
963 struct i965_surface_state2 *ss2;
966 unsigned int swizzle;
968 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
969 ss2_bo = pp_context->surface_state_binding_table.bo;
972 dri_bo_map(ss2_bo, True);
973 assert(ss2_bo->virtual);
974 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
975 memset(ss2, 0, sizeof(*ss2));
976 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
977 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
978 ss2->ss1.width = width - 1;
979 ss2->ss1.height = height - 1;
980 ss2->ss2.pitch = wpitch - 1;
981 ss2->ss2.interleave_chroma = interleave_chroma;
982 ss2->ss2.surface_format = format;
983 ss2->ss3.x_offset_for_cb = xoffset;
984 ss2->ss3.y_offset_for_cb = yoffset;
985 pp_set_surface2_tiling(ss2, tiling);
986 dri_bo_emit_reloc(ss2_bo,
987 I915_GEM_DOMAIN_RENDER, 0,
989 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
991 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
992 dri_bo_unmap(ss2_bo);
996 gen7_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
997 dri_bo *surf_bo, unsigned long surf_bo_offset,
998 int width, int height, int pitch, int format,
999 int index, int is_target)
1001 struct gen7_surface_state *ss;
1003 unsigned int tiling;
1004 unsigned int swizzle;
1006 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1007 ss_bo = pp_context->surface_state_binding_table.bo;
1010 dri_bo_map(ss_bo, True);
1011 assert(ss_bo->virtual);
1012 ss = (struct gen7_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1013 memset(ss, 0, sizeof(*ss));
1014 ss->ss0.surface_type = I965_SURFACE_2D;
1015 ss->ss0.surface_format = format;
1016 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1017 ss->ss2.width = width - 1;
1018 ss->ss2.height = height - 1;
1019 ss->ss3.pitch = pitch - 1;
1020 gen7_pp_set_surface_tiling(ss, tiling);
1021 dri_bo_emit_reloc(ss_bo,
1022 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1024 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state, ss1),
1026 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1027 dri_bo_unmap(ss_bo);
1031 gen7_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1032 dri_bo *surf_bo, unsigned long surf_bo_offset,
1033 int width, int height, int wpitch,
1034 int xoffset, int yoffset,
1035 int format, int interleave_chroma,
1038 struct gen7_surface_state2 *ss2;
1040 unsigned int tiling;
1041 unsigned int swizzle;
1043 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1044 ss2_bo = pp_context->surface_state_binding_table.bo;
1047 dri_bo_map(ss2_bo, True);
1048 assert(ss2_bo->virtual);
1049 ss2 = (struct gen7_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1050 memset(ss2, 0, sizeof(*ss2));
1051 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1052 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1053 ss2->ss1.width = width - 1;
1054 ss2->ss1.height = height - 1;
1055 ss2->ss2.pitch = wpitch - 1;
1056 ss2->ss2.interleave_chroma = interleave_chroma;
1057 ss2->ss2.surface_format = format;
1058 ss2->ss3.x_offset_for_cb = xoffset;
1059 ss2->ss3.y_offset_for_cb = yoffset;
1060 gen7_pp_set_surface2_tiling(ss2, tiling);
1061 dri_bo_emit_reloc(ss2_bo,
1062 I915_GEM_DOMAIN_RENDER, 0,
1064 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state2, ss0),
1066 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1067 dri_bo_unmap(ss2_bo);
1071 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1072 const struct i965_surface *surface,
1073 int base_index, int is_target,
1074 int *width, int *height, int *pitch, int *offset)
1076 struct i965_driver_data *i965 = i965_driver_data(ctx);
1077 struct object_surface *obj_surface;
1078 struct object_image *obj_image;
1080 int fourcc = pp_get_surface_fourcc(ctx, surface);
1082 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
1083 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
1085 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1086 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
1088 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1089 obj_surface = SURFACE(surface->id);
1090 bo = obj_surface->bo;
1091 width[0] = obj_surface->orig_width;
1092 height[0] = obj_surface->orig_height;
1093 pitch[0] = obj_surface->width;
1097 width[0] = obj_surface->orig_width * 2;
1098 pitch[0] = obj_surface->width * 2;
1100 else if (interleaved_uv) {
1101 width[1] = obj_surface->orig_width;
1102 height[1] = obj_surface->orig_height / 2;
1103 pitch[1] = obj_surface->width;
1104 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1106 width[1] = obj_surface->orig_width / 2;
1107 height[1] = obj_surface->orig_height / 2;
1108 pitch[1] = obj_surface->width / 2;
1109 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1110 width[2] = obj_surface->orig_width / 2;
1111 height[2] = obj_surface->orig_height / 2;
1112 pitch[2] = obj_surface->width / 2;
1113 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
1116 obj_image = IMAGE(surface->id);
1118 width[0] = obj_image->image.width;
1119 height[0] = obj_image->image.height;
1120 pitch[0] = obj_image->image.pitches[0];
1121 offset[0] = obj_image->image.offsets[0];
1123 if (interleaved_uv) {
1124 width[1] = obj_image->image.width;
1125 height[1] = obj_image->image.height / 2;
1126 pitch[1] = obj_image->image.pitches[1];
1127 offset[1] = obj_image->image.offsets[1];
1129 width[1] = obj_image->image.width / 2;
1130 height[1] = obj_image->image.height / 2;
1131 pitch[1] = obj_image->image.pitches[1];
1132 offset[1] = obj_image->image.offsets[1];
1133 width[2] = obj_image->image.width / 2;
1134 height[2] = obj_image->image.height / 2;
1135 pitch[2] = obj_image->image.pitches[2];
1136 offset[2] = obj_image->image.offsets[2];
1141 i965_pp_set_surface_state(ctx, pp_context,
1143 width[Y] / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
1144 base_index, is_target);
1147 if (interleaved_uv) {
1148 i965_pp_set_surface_state(ctx, pp_context,
1150 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
1151 base_index + 1, is_target);
1154 i965_pp_set_surface_state(ctx, pp_context,
1156 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
1157 base_index + 1, is_target);
1160 i965_pp_set_surface_state(ctx, pp_context,
1162 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
1163 base_index + 2, is_target);
1170 gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1171 const struct i965_surface *surface,
1172 int base_index, int is_target,
1173 int *width, int *height, int *pitch, int *offset)
1175 struct i965_driver_data *i965 = i965_driver_data(ctx);
1176 struct object_surface *obj_surface;
1177 struct object_image *obj_image;
1179 int fourcc = pp_get_surface_fourcc(ctx, surface);
1180 const int U = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
1181 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 2 : 1;
1182 const int V = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
1183 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 1 : 2;
1184 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1186 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1187 obj_surface = SURFACE(surface->id);
1188 bo = obj_surface->bo;
1189 width[0] = obj_surface->orig_width;
1190 height[0] = obj_surface->orig_height;
1191 pitch[0] = obj_surface->width;
1194 width[1] = obj_surface->cb_cr_width;
1195 height[1] = obj_surface->cb_cr_height;
1196 pitch[1] = obj_surface->cb_cr_pitch;
1197 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
1199 width[2] = obj_surface->cb_cr_width;
1200 height[2] = obj_surface->cb_cr_height;
1201 pitch[2] = obj_surface->cb_cr_pitch;
1202 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
1204 obj_image = IMAGE(surface->id);
1206 width[0] = obj_image->image.width;
1207 height[0] = obj_image->image.height;
1208 pitch[0] = obj_image->image.pitches[0];
1209 offset[0] = obj_image->image.offsets[0];
1211 if (interleaved_uv) {
1212 width[1] = obj_image->image.width;
1213 height[1] = obj_image->image.height / 2;
1214 pitch[1] = obj_image->image.pitches[1];
1215 offset[1] = obj_image->image.offsets[1];
1217 width[1] = obj_image->image.width / 2;
1218 height[1] = obj_image->image.height / 2;
1219 pitch[1] = obj_image->image.pitches[U];
1220 offset[1] = obj_image->image.offsets[U];
1221 width[2] = obj_image->image.width / 2;
1222 height[2] = obj_image->image.height / 2;
1223 pitch[2] = obj_image->image.pitches[V];
1224 offset[2] = obj_image->image.offsets[V];
1229 gen7_pp_set_surface_state(ctx, pp_context,
1231 width[0] / 4, height[0], pitch[0],
1232 I965_SURFACEFORMAT_R8_SINT,
1235 if (interleaved_uv) {
1236 gen7_pp_set_surface_state(ctx, pp_context,
1238 width[1] / 2, height[1], pitch[1],
1239 I965_SURFACEFORMAT_R8G8_SINT,
1242 gen7_pp_set_surface_state(ctx, pp_context,
1244 width[1] / 4, height[1], pitch[1],
1245 I965_SURFACEFORMAT_R8_SINT,
1247 gen7_pp_set_surface_state(ctx, pp_context,
1249 width[2] / 4, height[2], pitch[2],
1250 I965_SURFACEFORMAT_R8_SINT,
1254 gen7_pp_set_surface2_state(ctx, pp_context,
1256 width[0], height[0], pitch[0],
1258 SURFACE_FORMAT_Y8_UNORM, 0,
1261 if (interleaved_uv) {
1262 gen7_pp_set_surface2_state(ctx, pp_context,
1264 width[1], height[1], pitch[1],
1266 SURFACE_FORMAT_R8B8_UNORM, 0,
1269 gen7_pp_set_surface2_state(ctx, pp_context,
1271 width[1], height[1], pitch[1],
1273 SURFACE_FORMAT_R8_UNORM, 0,
1275 gen7_pp_set_surface2_state(ctx, pp_context,
1277 width[2], height[2], pitch[2],
1279 SURFACE_FORMAT_R8_UNORM, 0,
1286 pp_null_x_steps(void *private_context)
1292 pp_null_y_steps(void *private_context)
1298 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1304 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1305 const struct i965_surface *src_surface,
1306 const VARectangle *src_rect,
1307 struct i965_surface *dst_surface,
1308 const VARectangle *dst_rect,
1311 /* private function & data */
1312 pp_context->pp_x_steps = pp_null_x_steps;
1313 pp_context->pp_y_steps = pp_null_y_steps;
1314 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
1316 dst_surface->flags = src_surface->flags;
1318 return VA_STATUS_SUCCESS;
1322 pp_load_save_x_steps(void *private_context)
1328 pp_load_save_y_steps(void *private_context)
1330 struct pp_load_save_context *pp_load_save_context = private_context;
1332 return pp_load_save_context->dest_h / 8;
1336 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1338 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1340 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1341 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1342 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
1343 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
1349 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1350 const struct i965_surface *src_surface,
1351 const VARectangle *src_rect,
1352 struct i965_surface *dst_surface,
1353 const VARectangle *dst_rect,
1356 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->private_context;
1357 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1358 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1359 int width[3], height[3], pitch[3], offset[3];
1362 /* source surface */
1363 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
1364 width, height, pitch, offset);
1366 /* destination surface */
1367 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
1368 width, height, pitch, offset);
1370 /* private function & data */
1371 pp_context->pp_x_steps = pp_load_save_x_steps;
1372 pp_context->pp_y_steps = pp_load_save_y_steps;
1373 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
1374 pp_load_save_context->dest_h = ALIGN(height[Y], 16);
1375 pp_load_save_context->dest_w = ALIGN(width[Y], 16);
1377 pp_inline_parameter->grf5.block_count_x = ALIGN(width[Y], 16) / 16; /* 1 x N */
1378 pp_inline_parameter->grf5.number_blocks = ALIGN(width[Y], 16) / 16;
1380 pp_static_parameter->grf3.horizontal_origin_offset = src_rect->x;
1381 pp_static_parameter->grf3.vertical_origin_offset = src_rect->y;
1383 dst_surface->flags = src_surface->flags;
1385 return VA_STATUS_SUCCESS;
1389 pp_scaling_x_steps(void *private_context)
1395 pp_scaling_y_steps(void *private_context)
1397 struct pp_scaling_context *pp_scaling_context = private_context;
1399 return pp_scaling_context->dest_h / 8;
1403 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1405 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1406 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1407 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1408 float src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1409 float src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1411 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
1412 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
1413 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
1414 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
1420 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1421 const struct i965_surface *src_surface,
1422 const VARectangle *src_rect,
1423 struct i965_surface *dst_surface,
1424 const VARectangle *dst_rect,
1427 struct i965_driver_data *i965 = i965_driver_data(ctx);
1428 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1429 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1430 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1431 struct object_surface *obj_surface;
1432 struct i965_sampler_state *sampler_state;
1433 int in_w, in_h, in_wpitch, in_hpitch;
1434 int out_w, out_h, out_wpitch, out_hpitch;
1436 /* source surface */
1437 obj_surface = SURFACE(src_surface->id);
1438 in_w = obj_surface->orig_width;
1439 in_h = obj_surface->orig_height;
1440 in_wpitch = obj_surface->width;
1441 in_hpitch = obj_surface->height;
1443 /* source Y surface index 1 */
1444 i965_pp_set_surface_state(ctx, pp_context,
1446 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1449 /* source UV surface index 2 */
1450 i965_pp_set_surface_state(ctx, pp_context,
1451 obj_surface->bo, in_wpitch * in_hpitch,
1452 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1455 /* destination surface */
1456 obj_surface = SURFACE(dst_surface->id);
1457 out_w = obj_surface->orig_width;
1458 out_h = obj_surface->orig_height;
1459 out_wpitch = obj_surface->width;
1460 out_hpitch = obj_surface->height;
1462 /* destination Y surface index 7 */
1463 i965_pp_set_surface_state(ctx, pp_context,
1465 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1468 /* destination UV surface index 8 */
1469 i965_pp_set_surface_state(ctx, pp_context,
1470 obj_surface->bo, out_wpitch * out_hpitch,
1471 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1475 dri_bo_map(pp_context->sampler_state_table.bo, True);
1476 assert(pp_context->sampler_state_table.bo->virtual);
1477 sampler_state = pp_context->sampler_state_table.bo->virtual;
1479 /* SIMD16 Y index 1 */
1480 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
1481 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1482 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1483 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1484 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1486 /* SIMD16 UV index 2 */
1487 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
1488 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1489 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1490 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1491 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1493 dri_bo_unmap(pp_context->sampler_state_table.bo);
1495 /* private function & data */
1496 pp_context->pp_x_steps = pp_scaling_x_steps;
1497 pp_context->pp_y_steps = pp_scaling_y_steps;
1498 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
1500 pp_scaling_context->dest_x = dst_rect->x;
1501 pp_scaling_context->dest_y = dst_rect->y;
1502 pp_scaling_context->dest_w = ALIGN(dst_rect->width, 16);
1503 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 16);
1504 pp_scaling_context->src_normalized_x = (float)src_rect->x / in_w;
1505 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h;
1507 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
1509 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
1510 pp_inline_parameter->grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
1511 pp_inline_parameter->grf5.number_blocks = pp_scaling_context->dest_w / 16;
1512 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1513 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1515 dst_surface->flags = src_surface->flags;
1517 return VA_STATUS_SUCCESS;
1521 pp_avs_x_steps(void *private_context)
1523 struct pp_avs_context *pp_avs_context = private_context;
1525 return pp_avs_context->dest_w / 16;
1529 pp_avs_y_steps(void *private_context)
1535 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1537 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1538 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1539 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1540 float src_x_steping, src_y_steping, video_step_delta;
1541 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
1543 if (pp_static_parameter->grf4.r4_2.avs.nlas == 0) {
1544 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1545 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_avs_context->src_normalized_x;
1546 } else if (tmp_w >= pp_avs_context->dest_w) {
1547 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1548 pp_inline_parameter->grf6.video_step_delta = 0;
1551 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
1552 pp_avs_context->src_normalized_x;
1554 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1555 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1556 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1557 16 * 15 * video_step_delta / 2;
1560 int n0, n1, n2, nls_left, nls_right;
1561 int factor_a = 5, factor_b = 4;
1564 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
1565 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
1566 n2 = tmp_w / (16 * factor_a);
1568 nls_right = n1 + n2;
1569 f = (float) n2 * 16 / tmp_w;
1572 pp_inline_parameter->grf6.video_step_delta = 0.0;
1575 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
1576 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1578 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1579 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1580 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1581 16 * 15 * video_step_delta / 2;
1585 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
1586 float a = f / (nls_left * 16 * factor_b);
1587 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
1589 pp_inline_parameter->grf6.video_step_delta = b;
1592 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1593 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a;
1595 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1596 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1597 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1598 16 * 15 * video_step_delta / 2;
1599 pp_inline_parameter->grf5.normalized_video_x_scaling_step += 16 * b;
1601 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
1602 /* scale the center linearly */
1603 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1604 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1605 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1606 16 * 15 * video_step_delta / 2;
1607 pp_inline_parameter->grf6.video_step_delta = 0.0;
1608 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1610 float a = f / (nls_right * 16 * factor_b);
1611 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
1613 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1614 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1615 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1616 16 * 15 * video_step_delta / 2;
1617 pp_inline_parameter->grf6.video_step_delta = -b;
1619 if (x == (pp_avs_context->dest_w / 16 - nls_right))
1620 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
1622 pp_inline_parameter->grf5.normalized_video_x_scaling_step -= b * 16;
1627 src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1628 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
1629 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1630 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
1636 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1637 const struct i965_surface *src_surface,
1638 const VARectangle *src_rect,
1639 struct i965_surface *dst_surface,
1640 const VARectangle *dst_rect,
1644 struct i965_driver_data *i965 = i965_driver_data(ctx);
1645 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1646 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1647 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1648 struct object_surface *obj_surface;
1649 struct i965_sampler_8x8 *sampler_8x8;
1650 struct i965_sampler_8x8_state *sampler_8x8_state;
1652 int in_w, in_h, in_wpitch, in_hpitch;
1653 int out_w, out_h, out_wpitch, out_hpitch;
1657 obj_surface = SURFACE(src_surface->id);
1658 in_w = obj_surface->orig_width;
1659 in_h = obj_surface->orig_height;
1660 in_wpitch = obj_surface->width;
1661 in_hpitch = obj_surface->height;
1663 /* source Y surface index 1 */
1664 i965_pp_set_surface2_state(ctx, pp_context,
1666 in_w, in_h, in_wpitch,
1668 SURFACE_FORMAT_Y8_UNORM, 0,
1671 /* source UV surface index 2 */
1672 i965_pp_set_surface2_state(ctx, pp_context,
1673 obj_surface->bo, in_wpitch * in_hpitch,
1674 in_w / 2, in_h / 2, in_wpitch,
1676 SURFACE_FORMAT_R8B8_UNORM, 0,
1679 /* destination surface */
1680 obj_surface = SURFACE(dst_surface->id);
1681 out_w = obj_surface->orig_width;
1682 out_h = obj_surface->orig_height;
1683 out_wpitch = obj_surface->width;
1684 out_hpitch = obj_surface->height;
1685 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1687 /* destination Y surface index 7 */
1688 i965_pp_set_surface_state(ctx, pp_context,
1690 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1693 /* destination UV surface index 8 */
1694 i965_pp_set_surface_state(ctx, pp_context,
1695 obj_surface->bo, out_wpitch * out_hpitch,
1696 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1699 /* sampler 8x8 state */
1700 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1701 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1702 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1703 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1704 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1706 for (i = 0; i < 17; i++) {
1707 /* for Y channel, currently ignore */
1708 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x00;
1709 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x00;
1710 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x08;
1711 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x18;
1712 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x18;
1713 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x08;
1714 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x00;
1715 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x00;
1716 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x00;
1717 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x00;
1718 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x10;
1719 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x10;
1720 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x10;
1721 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x10;
1722 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x00;
1723 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x00;
1724 /* for U/V channel, 0.25 */
1725 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
1726 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
1727 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
1728 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
1729 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
1730 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
1731 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
1732 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
1733 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
1734 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
1735 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
1736 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
1737 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
1738 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
1739 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
1740 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
1743 sampler_8x8_state->dw136.default_sharpness_level = 0;
1744 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
1745 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1746 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1747 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
1750 dri_bo_map(pp_context->sampler_state_table.bo, True);
1751 assert(pp_context->sampler_state_table.bo->virtual);
1752 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
1753 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
1755 /* sample_8x8 Y index 1 */
1757 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1758 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1759 sampler_8x8[index].dw0.ief_bypass = 1;
1760 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1761 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1762 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1763 sampler_8x8[index].dw2.global_noise_estimation = 22;
1764 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1765 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1766 sampler_8x8[index].dw3.strong_edge_weight = 7;
1767 sampler_8x8[index].dw3.regular_weight = 2;
1768 sampler_8x8[index].dw3.non_edge_weight = 0;
1769 sampler_8x8[index].dw3.gain_factor = 40;
1770 sampler_8x8[index].dw4.steepness_boost = 0;
1771 sampler_8x8[index].dw4.steepness_threshold = 0;
1772 sampler_8x8[index].dw4.mr_boost = 0;
1773 sampler_8x8[index].dw4.mr_threshold = 5;
1774 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1775 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1776 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1777 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1778 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1779 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1780 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1781 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1782 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1783 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1784 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1785 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1786 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1787 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1788 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1789 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1790 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1791 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1792 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1793 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1794 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1795 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1796 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1797 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1798 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1799 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1800 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1801 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1802 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1803 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1804 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1805 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1806 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1807 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1808 sampler_8x8[index].dw13.limiter_boost = 0;
1809 sampler_8x8[index].dw13.minimum_limiter = 10;
1810 sampler_8x8[index].dw13.maximum_limiter = 11;
1811 sampler_8x8[index].dw14.clip_limiter = 130;
1812 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1813 I915_GEM_DOMAIN_RENDER,
1816 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1817 pp_context->sampler_state_table.bo_8x8);
1819 /* sample_8x8 UV index 2 */
1821 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1822 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1823 sampler_8x8[index].dw0.ief_bypass = 1;
1824 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1825 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1826 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1827 sampler_8x8[index].dw2.global_noise_estimation = 22;
1828 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1829 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1830 sampler_8x8[index].dw3.strong_edge_weight = 7;
1831 sampler_8x8[index].dw3.regular_weight = 2;
1832 sampler_8x8[index].dw3.non_edge_weight = 0;
1833 sampler_8x8[index].dw3.gain_factor = 40;
1834 sampler_8x8[index].dw4.steepness_boost = 0;
1835 sampler_8x8[index].dw4.steepness_threshold = 0;
1836 sampler_8x8[index].dw4.mr_boost = 0;
1837 sampler_8x8[index].dw4.mr_threshold = 5;
1838 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1839 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1840 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1841 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1842 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1843 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1844 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1845 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1846 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1847 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1848 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1849 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1850 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1851 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1852 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1853 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1854 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1855 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1856 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1857 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1858 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1859 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1860 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1861 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1862 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1863 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1864 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1865 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1866 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1867 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1868 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1869 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1870 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1871 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1872 sampler_8x8[index].dw13.limiter_boost = 0;
1873 sampler_8x8[index].dw13.minimum_limiter = 10;
1874 sampler_8x8[index].dw13.maximum_limiter = 11;
1875 sampler_8x8[index].dw14.clip_limiter = 130;
1876 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1877 I915_GEM_DOMAIN_RENDER,
1880 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1881 pp_context->sampler_state_table.bo_8x8);
1883 dri_bo_unmap(pp_context->sampler_state_table.bo);
1885 /* private function & data */
1886 pp_context->pp_x_steps = pp_avs_x_steps;
1887 pp_context->pp_y_steps = pp_avs_y_steps;
1888 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
1890 pp_avs_context->dest_x = dst_rect->x;
1891 pp_avs_context->dest_y = dst_rect->y;
1892 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
1893 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
1894 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w;
1895 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h;
1896 pp_avs_context->src_w = src_rect->width;
1897 pp_avs_context->src_h = src_rect->height;
1899 pp_static_parameter->grf4.r4_2.avs.nlas = nlas;
1900 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
1902 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
1903 pp_inline_parameter->grf5.block_count_x = 1; /* M x 1 */
1904 pp_inline_parameter->grf5.number_blocks = pp_avs_context->dest_h / 8;
1905 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1906 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1907 pp_inline_parameter->grf6.video_step_delta = 0.0;
1909 dst_surface->flags = src_surface->flags;
1911 return VA_STATUS_SUCCESS;
1915 pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1916 const struct i965_surface *src_surface,
1917 const VARectangle *src_rect,
1918 struct i965_surface *dst_surface,
1919 const VARectangle *dst_rect,
1922 return pp_nv12_avs_initialize(ctx, pp_context,
1932 gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1933 const struct i965_surface *src_surface,
1934 const VARectangle *src_rect,
1935 struct i965_surface *dst_surface,
1936 const VARectangle *dst_rect,
1939 return pp_nv12_avs_initialize(ctx, pp_context,
1949 gen7_pp_avs_x_steps(void *private_context)
1951 struct pp_avs_context *pp_avs_context = private_context;
1953 return pp_avs_context->dest_w / 16;
1957 gen7_pp_avs_y_steps(void *private_context)
1959 struct pp_avs_context *pp_avs_context = private_context;
1961 return pp_avs_context->dest_h / 16;
1965 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1967 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1968 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1970 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1971 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
1972 pp_inline_parameter->grf7.constant_0 = 0xffffffff;
1973 pp_inline_parameter->grf7.sampler_load_main_video_x_scaling_step = 1.0 / pp_avs_context->src_w;
1979 gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1980 const struct i965_surface *src_surface,
1981 const VARectangle *src_rect,
1982 struct i965_surface *dst_surface,
1983 const VARectangle *dst_rect,
1986 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1987 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1988 struct gen7_sampler_8x8 *sampler_8x8;
1989 struct i965_sampler_8x8_state *sampler_8x8_state;
1991 int width[3], height[3], pitch[3], offset[3];
1993 /* source surface */
1994 gen7_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
1995 width, height, pitch, offset);
1997 /* destination surface */
1998 gen7_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
1999 width, height, pitch, offset);
2001 /* sampler 8x8 state */
2002 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
2003 assert(pp_context->sampler_state_table.bo_8x8->virtual);
2004 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
2005 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
2006 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
2008 for (i = 0; i < 17; i++) {
2009 /* for Y channel, currently ignore */
2010 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
2011 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
2012 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
2013 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x0;
2014 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x0;
2015 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
2016 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
2017 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
2018 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
2019 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
2020 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
2021 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x0;
2022 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x0;
2023 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
2024 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
2025 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
2026 /* for U/V channel, 0.25 */
2027 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
2028 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
2029 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
2030 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
2031 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
2032 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
2033 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
2034 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
2035 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
2036 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
2037 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
2038 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
2039 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
2040 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
2041 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
2042 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
2045 sampler_8x8_state->dw136.default_sharpness_level = 0;
2046 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
2047 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
2048 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
2049 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
2052 dri_bo_map(pp_context->sampler_state_table.bo, True);
2053 assert(pp_context->sampler_state_table.bo->virtual);
2054 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
2055 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
2057 /* sample_8x8 Y index 4 */
2059 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2060 sampler_8x8[index].dw0.global_noise_estimation = 255;
2061 sampler_8x8[index].dw0.ief_bypass = 1;
2063 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2065 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2066 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2067 sampler_8x8[index].dw2.r5x_coefficient = 9;
2068 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2069 sampler_8x8[index].dw2.r5c_coefficient = 3;
2071 sampler_8x8[index].dw3.r3x_coefficient = 27;
2072 sampler_8x8[index].dw3.r3c_coefficient = 5;
2073 sampler_8x8[index].dw3.gain_factor = 40;
2074 sampler_8x8[index].dw3.non_edge_weight = 1;
2075 sampler_8x8[index].dw3.regular_weight = 2;
2076 sampler_8x8[index].dw3.strong_edge_weight = 7;
2077 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2079 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2080 I915_GEM_DOMAIN_RENDER,
2083 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2084 pp_context->sampler_state_table.bo_8x8);
2086 /* sample_8x8 UV index 8 */
2088 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2089 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2090 sampler_8x8[index].dw0.global_noise_estimation = 255;
2091 sampler_8x8[index].dw0.ief_bypass = 1;
2092 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2093 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2094 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2095 sampler_8x8[index].dw2.r5x_coefficient = 9;
2096 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2097 sampler_8x8[index].dw2.r5c_coefficient = 3;
2098 sampler_8x8[index].dw3.r3x_coefficient = 27;
2099 sampler_8x8[index].dw3.r3c_coefficient = 5;
2100 sampler_8x8[index].dw3.gain_factor = 40;
2101 sampler_8x8[index].dw3.non_edge_weight = 1;
2102 sampler_8x8[index].dw3.regular_weight = 2;
2103 sampler_8x8[index].dw3.strong_edge_weight = 7;
2104 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2106 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2107 I915_GEM_DOMAIN_RENDER,
2110 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2111 pp_context->sampler_state_table.bo_8x8);
2113 /* sampler_8x8 V, index 12 */
2115 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2116 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2117 sampler_8x8[index].dw0.global_noise_estimation = 255;
2118 sampler_8x8[index].dw0.ief_bypass = 1;
2119 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2120 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2121 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2122 sampler_8x8[index].dw2.r5x_coefficient = 9;
2123 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2124 sampler_8x8[index].dw2.r5c_coefficient = 3;
2125 sampler_8x8[index].dw3.r3x_coefficient = 27;
2126 sampler_8x8[index].dw3.r3c_coefficient = 5;
2127 sampler_8x8[index].dw3.gain_factor = 40;
2128 sampler_8x8[index].dw3.non_edge_weight = 1;
2129 sampler_8x8[index].dw3.regular_weight = 2;
2130 sampler_8x8[index].dw3.strong_edge_weight = 7;
2131 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2133 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2134 I915_GEM_DOMAIN_RENDER,
2137 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2138 pp_context->sampler_state_table.bo_8x8);
2140 dri_bo_unmap(pp_context->sampler_state_table.bo);
2142 /* private function & data */
2143 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
2144 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
2145 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
2147 pp_avs_context->dest_x = dst_rect->x;
2148 pp_avs_context->dest_y = dst_rect->y;
2149 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
2150 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
2151 pp_avs_context->src_w = src_rect->width;
2152 pp_avs_context->src_h = src_rect->height;
2154 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
2155 dw = MAX(dw, pp_avs_context->dest_w);
2157 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2158 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
2159 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) 1.0 / pp_avs_context->dest_h;
2160 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = -(float)pp_avs_context->dest_y / pp_avs_context->dest_h;
2161 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = -(float)pp_avs_context->dest_x / dw;
2163 dst_surface->flags = src_surface->flags;
2165 return VA_STATUS_SUCCESS;
2169 pp_dndi_x_steps(void *private_context)
2175 pp_dndi_y_steps(void *private_context)
2177 struct pp_dndi_context *pp_dndi_context = private_context;
2179 return pp_dndi_context->dest_h / 4;
2183 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2185 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2187 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2188 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
2194 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2195 const struct i965_surface *src_surface,
2196 const VARectangle *src_rect,
2197 struct i965_surface *dst_surface,
2198 const VARectangle *dst_rect,
2201 struct i965_driver_data *i965 = i965_driver_data(ctx);
2202 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2203 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2204 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2205 struct object_surface *obj_surface;
2206 struct i965_sampler_dndi *sampler_dndi;
2210 int dndi_top_first = 1;
2212 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2213 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2215 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2221 obj_surface = SURFACE(src_surface->id);
2222 orig_w = obj_surface->orig_width;
2223 orig_h = obj_surface->orig_height;
2224 w = obj_surface->width;
2225 h = obj_surface->height;
2227 if (pp_context->stmm.bo == NULL) {
2228 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2232 assert(pp_context->stmm.bo);
2235 /* source UV surface index 2 */
2236 i965_pp_set_surface_state(ctx, pp_context,
2237 obj_surface->bo, w * h,
2238 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2241 /* source YUV surface index 4 */
2242 i965_pp_set_surface2_state(ctx, pp_context,
2246 SURFACE_FORMAT_PLANAR_420_8, 1,
2249 /* source STMM surface index 20 */
2250 i965_pp_set_surface_state(ctx, pp_context,
2251 pp_context->stmm.bo, 0,
2252 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2255 /* destination surface */
2256 obj_surface = SURFACE(dst_surface->id);
2257 orig_w = obj_surface->orig_width;
2258 orig_h = obj_surface->orig_height;
2259 w = obj_surface->width;
2260 h = obj_surface->height;
2262 /* destination Y surface index 7 */
2263 i965_pp_set_surface_state(ctx, pp_context,
2265 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2268 /* destination UV surface index 8 */
2269 i965_pp_set_surface_state(ctx, pp_context,
2270 obj_surface->bo, w * h,
2271 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2274 dri_bo_map(pp_context->sampler_state_table.bo, True);
2275 assert(pp_context->sampler_state_table.bo->virtual);
2276 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2277 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2279 /* sample dndi index 1 */
2281 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2282 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2283 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2284 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2286 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2287 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 4;
2288 sampler_dndi[index].dw1.stmm_c2 = 1;
2289 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2290 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2292 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2293 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2294 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2295 sampler_dndi[index].dw2.good_neighbor_threshold = 4; // 0-63
2297 sampler_dndi[index].dw3.maximum_stmm = 128;
2298 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2299 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2300 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2301 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2303 sampler_dndi[index].dw4.sdi_delta = 8;
2304 sampler_dndi[index].dw4.sdi_threshold = 128;
2305 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2306 sampler_dndi[index].dw4.stmm_shift_up = 0;
2307 sampler_dndi[index].dw4.stmm_shift_down = 0;
2308 sampler_dndi[index].dw4.minimum_stmm = 0;
2310 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 8;
2311 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 32;
2312 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 64;
2313 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 32;
2315 sampler_dndi[index].dw6.dn_enable = 1;
2316 sampler_dndi[index].dw6.di_enable = 1;
2317 sampler_dndi[index].dw6.di_partial = 0;
2318 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2319 sampler_dndi[index].dw6.dndi_stream_id = 0;
2320 sampler_dndi[index].dw6.dndi_first_frame = 1;
2321 sampler_dndi[index].dw6.progressive_dn = 0;
2322 sampler_dndi[index].dw6.fmd_tear_threshold = 63;
2323 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2324 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2326 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
2327 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
2328 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2329 sampler_dndi[index].dw7.column_width_minus1 = 0;
2331 dri_bo_unmap(pp_context->sampler_state_table.bo);
2333 /* private function & data */
2334 pp_context->pp_x_steps = pp_dndi_x_steps;
2335 pp_context->pp_y_steps = pp_dndi_y_steps;
2336 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
2338 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2339 pp_static_parameter->grf1.r1_6.di.top_field_first = dndi_top_first;
2340 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 0;
2341 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 0;
2343 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2344 pp_inline_parameter->grf5.number_blocks = w / 16;
2345 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2346 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2348 pp_dndi_context->dest_w = w;
2349 pp_dndi_context->dest_h = h;
2351 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
2353 return VA_STATUS_SUCCESS;
2357 pp_dn_x_steps(void *private_context)
2363 pp_dn_y_steps(void *private_context)
2365 struct pp_dn_context *pp_dn_context = private_context;
2367 return pp_dn_context->dest_h / 8;
2371 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2373 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2375 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2376 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
2382 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2383 const struct i965_surface *src_surface,
2384 const VARectangle *src_rect,
2385 struct i965_surface *dst_surface,
2386 const VARectangle *dst_rect,
2389 struct i965_driver_data *i965 = i965_driver_data(ctx);
2390 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
2391 struct object_surface *obj_surface;
2392 struct i965_sampler_dndi *sampler_dndi;
2393 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2394 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2395 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
2399 int dn_strength = 15;
2400 int dndi_top_first = 1;
2401 int dn_progressive = 0;
2403 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
2406 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
2414 if (dn_filter_param) {
2415 float value = dn_filter_param->value;
2423 dn_strength = (int)(value * 31.0F);
2427 obj_surface = SURFACE(src_surface->id);
2428 orig_w = obj_surface->orig_width;
2429 orig_h = obj_surface->orig_height;
2430 w = obj_surface->width;
2431 h = obj_surface->height;
2433 if (pp_context->stmm.bo == NULL) {
2434 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2438 assert(pp_context->stmm.bo);
2441 /* source UV surface index 2 */
2442 i965_pp_set_surface_state(ctx, pp_context,
2443 obj_surface->bo, w * h,
2444 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2447 /* source YUV surface index 4 */
2448 i965_pp_set_surface2_state(ctx, pp_context,
2452 SURFACE_FORMAT_PLANAR_420_8, 1,
2455 /* source STMM surface index 20 */
2456 i965_pp_set_surface_state(ctx, pp_context,
2457 pp_context->stmm.bo, 0,
2458 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2461 /* destination surface */
2462 obj_surface = SURFACE(dst_surface->id);
2463 orig_w = obj_surface->orig_width;
2464 orig_h = obj_surface->orig_height;
2465 w = obj_surface->width;
2466 h = obj_surface->height;
2468 /* destination Y surface index 7 */
2469 i965_pp_set_surface_state(ctx, pp_context,
2471 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2474 /* destination UV surface index 8 */
2475 i965_pp_set_surface_state(ctx, pp_context,
2476 obj_surface->bo, w * h,
2477 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2480 dri_bo_map(pp_context->sampler_state_table.bo, True);
2481 assert(pp_context->sampler_state_table.bo->virtual);
2482 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2483 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2485 /* sample dndi index 1 */
2487 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2488 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2489 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2490 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2492 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2493 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2494 sampler_dndi[index].dw1.stmm_c2 = 0;
2495 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2496 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2498 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
2499 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2500 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2501 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
2503 sampler_dndi[index].dw3.maximum_stmm = 128;
2504 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2505 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2506 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2507 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2509 sampler_dndi[index].dw4.sdi_delta = 8;
2510 sampler_dndi[index].dw4.sdi_threshold = 128;
2511 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2512 sampler_dndi[index].dw4.stmm_shift_up = 0;
2513 sampler_dndi[index].dw4.stmm_shift_down = 0;
2514 sampler_dndi[index].dw4.minimum_stmm = 0;
2516 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2517 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2518 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2519 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2521 sampler_dndi[index].dw6.dn_enable = 1;
2522 sampler_dndi[index].dw6.di_enable = 0;
2523 sampler_dndi[index].dw6.di_partial = 0;
2524 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2525 sampler_dndi[index].dw6.dndi_stream_id = 1;
2526 sampler_dndi[index].dw6.dndi_first_frame = 1;
2527 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
2528 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
2529 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2530 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2532 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
2533 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
2534 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2535 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
2537 dri_bo_unmap(pp_context->sampler_state_table.bo);
2539 /* private function & data */
2540 pp_context->pp_x_steps = pp_dn_x_steps;
2541 pp_context->pp_y_steps = pp_dn_y_steps;
2542 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
2544 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2545 pp_static_parameter->grf1.r1_6.di.top_field_first = 0;
2546 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 64;
2547 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 192;
2549 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2550 pp_inline_parameter->grf5.number_blocks = w / 16;
2551 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2552 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2554 pp_dn_context->dest_w = w;
2555 pp_dn_context->dest_h = h;
2557 dst_surface->flags = src_surface->flags;
2559 return VA_STATUS_SUCCESS;
2563 gen7_pp_dndi_x_steps(void *private_context)
2565 struct pp_dndi_context *pp_dndi_context = private_context;
2567 return pp_dndi_context->dest_w / 16;
2571 gen7_pp_dndi_y_steps(void *private_context)
2573 struct pp_dndi_context *pp_dndi_context = private_context;
2575 return pp_dndi_context->dest_h / 4;
2579 gen7_pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2581 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2583 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16;
2584 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 4;
2590 gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2591 const struct i965_surface *src_surface,
2592 const VARectangle *src_rect,
2593 struct i965_surface *dst_surface,
2594 const VARectangle *dst_rect,
2597 struct i965_driver_data *i965 = i965_driver_data(ctx);
2598 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2599 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2600 struct object_surface *obj_surface;
2601 struct gen7_sampler_dndi *sampler_dndi;
2605 int dndi_top_first = 1;
2607 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2608 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2610 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2616 obj_surface = SURFACE(src_surface->id);
2617 orig_w = obj_surface->orig_width;
2618 orig_h = obj_surface->orig_height;
2619 w = obj_surface->width;
2620 h = obj_surface->height;
2622 if (pp_context->stmm.bo == NULL) {
2623 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2627 assert(pp_context->stmm.bo);
2630 /* source UV surface index 1 */
2631 gen7_pp_set_surface_state(ctx, pp_context,
2632 obj_surface->bo, w * h,
2633 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2636 /* source YUV surface index 3 */
2637 gen7_pp_set_surface2_state(ctx, pp_context,
2641 SURFACE_FORMAT_PLANAR_420_8, 1,
2644 /* source (temporal reference) YUV surface index 4 */
2645 gen7_pp_set_surface2_state(ctx, pp_context,
2649 SURFACE_FORMAT_PLANAR_420_8, 1,
2652 /* STMM / History Statistics input surface, index 5 */
2653 gen7_pp_set_surface_state(ctx, pp_context,
2654 pp_context->stmm.bo, 0,
2655 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2658 /* destination surface */
2659 obj_surface = SURFACE(dst_surface->id);
2660 orig_w = obj_surface->orig_width;
2661 orig_h = obj_surface->orig_height;
2662 w = obj_surface->width;
2663 h = obj_surface->height;
2665 /* destination(Previous frame) Y surface index 27 */
2666 gen7_pp_set_surface_state(ctx, pp_context,
2668 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2671 /* destination(Previous frame) UV surface index 28 */
2672 gen7_pp_set_surface_state(ctx, pp_context,
2673 obj_surface->bo, w * h,
2674 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2677 /* destination(Current frame) Y surface index 30 */
2678 gen7_pp_set_surface_state(ctx, pp_context,
2680 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2683 /* destination(Current frame) UV surface index 31 */
2684 gen7_pp_set_surface_state(ctx, pp_context,
2685 obj_surface->bo, w * h,
2686 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2689 /* STMM output surface, index 33 */
2690 gen7_pp_set_surface_state(ctx, pp_context,
2691 pp_context->stmm.bo, 0,
2692 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2697 dri_bo_map(pp_context->sampler_state_table.bo, True);
2698 assert(pp_context->sampler_state_table.bo->virtual);
2699 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2700 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2702 /* sample dndi index 0 */
2704 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2705 sampler_dndi[index].dw0.dnmh_delt = 8;
2706 sampler_dndi[index].dw0.vdi_walker_y_stride = 0;
2707 sampler_dndi[index].dw0.vdi_walker_frame_sharing_enable = 0;
2708 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2709 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2711 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2712 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2713 sampler_dndi[index].dw1.stmm_c2 = 0;
2714 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2715 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2717 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2718 sampler_dndi[index].dw2.bne_edge_th = 1;
2719 sampler_dndi[index].dw2.smooth_mv_th = 0;
2720 sampler_dndi[index].dw2.sad_tight_th = 5;
2721 sampler_dndi[index].dw2.cat_slope_minus1 = 9;
2722 sampler_dndi[index].dw2.good_neighbor_th = 4;
2724 sampler_dndi[index].dw3.maximum_stmm = 128;
2725 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2726 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2727 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2728 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2730 sampler_dndi[index].dw4.sdi_delta = 8;
2731 sampler_dndi[index].dw4.sdi_threshold = 128;
2732 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2733 sampler_dndi[index].dw4.stmm_shift_up = 0;
2734 sampler_dndi[index].dw4.stmm_shift_down = 0;
2735 sampler_dndi[index].dw4.minimum_stmm = 0;
2737 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2738 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2739 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2740 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2742 sampler_dndi[index].dw6.dn_enable = 0;
2743 sampler_dndi[index].dw6.di_enable = 1;
2744 sampler_dndi[index].dw6.di_partial = 0;
2745 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2746 sampler_dndi[index].dw6.dndi_stream_id = 1;
2747 sampler_dndi[index].dw6.dndi_first_frame = 1;
2748 sampler_dndi[index].dw6.progressive_dn = 0;
2749 sampler_dndi[index].dw6.mcdi_enable = 0;
2750 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
2751 sampler_dndi[index].dw6.cat_th1 = 0;
2752 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2753 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2755 sampler_dndi[index].dw7.sad_tha = 5;
2756 sampler_dndi[index].dw7.sad_thb = 10;
2757 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
2758 sampler_dndi[index].dw7.mc_pixel_consistency_th = 25;
2759 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
2760 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2761 sampler_dndi[index].dw7.neighborpixel_th = 10;
2762 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
2764 dri_bo_unmap(pp_context->sampler_state_table.bo);
2766 /* private function & data */
2767 pp_context->pp_x_steps = gen7_pp_dndi_x_steps;
2768 pp_context->pp_y_steps = gen7_pp_dndi_y_steps;
2769 pp_context->pp_set_block_parameter = gen7_pp_dndi_set_block_parameter;
2771 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
2772 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
2773 pp_static_parameter->grf1.di_top_field_first = 0;
2774 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2776 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2777 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2778 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2780 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
2781 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
2783 pp_dndi_context->dest_w = w;
2784 pp_dndi_context->dest_h = h;
2786 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
2788 return VA_STATUS_SUCCESS;
2792 gen7_pp_dn_x_steps(void *private_context)
2798 gen7_pp_dn_y_steps(void *private_context)
2800 struct pp_dn_context *pp_dn_context = private_context;
2802 return pp_dn_context->dest_h / 4;
2806 gen7_pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2808 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2810 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2811 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
2817 gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2818 const struct i965_surface *src_surface,
2819 const VARectangle *src_rect,
2820 struct i965_surface *dst_surface,
2821 const VARectangle *dst_rect,
2824 struct i965_driver_data *i965 = i965_driver_data(ctx);
2825 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
2826 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2827 struct object_surface *obj_surface;
2828 struct gen7_sampler_dndi *sampler_dn;
2829 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
2833 int dn_strength = 15;
2834 int dndi_top_first = 1;
2835 int dn_progressive = 0;
2837 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
2840 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
2848 if (dn_filter_param) {
2849 float value = dn_filter_param->value;
2857 dn_strength = (int)(value * 31.0F);
2861 obj_surface = SURFACE(src_surface->id);
2862 orig_w = obj_surface->orig_width;
2863 orig_h = obj_surface->orig_height;
2864 w = obj_surface->width;
2865 h = obj_surface->height;
2867 if (pp_context->stmm.bo == NULL) {
2868 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2872 assert(pp_context->stmm.bo);
2875 /* source UV surface index 1 */
2876 gen7_pp_set_surface_state(ctx, pp_context,
2877 obj_surface->bo, w * h,
2878 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2881 /* source YUV surface index 3 */
2882 gen7_pp_set_surface2_state(ctx, pp_context,
2886 SURFACE_FORMAT_PLANAR_420_8, 1,
2889 /* source STMM surface index 5 */
2890 gen7_pp_set_surface_state(ctx, pp_context,
2891 pp_context->stmm.bo, 0,
2892 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2895 /* destination surface */
2896 obj_surface = SURFACE(dst_surface->id);
2897 orig_w = obj_surface->orig_width;
2898 orig_h = obj_surface->orig_height;
2899 w = obj_surface->width;
2900 h = obj_surface->height;
2902 /* destination Y surface index 7 */
2903 gen7_pp_set_surface_state(ctx, pp_context,
2905 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2908 /* destination UV surface index 8 */
2909 gen7_pp_set_surface_state(ctx, pp_context,
2910 obj_surface->bo, w * h,
2911 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2914 dri_bo_map(pp_context->sampler_state_table.bo, True);
2915 assert(pp_context->sampler_state_table.bo->virtual);
2916 assert(sizeof(*sampler_dn) == sizeof(int) * 8);
2917 sampler_dn = pp_context->sampler_state_table.bo->virtual;
2919 /* sample dn index 1 */
2921 sampler_dn[index].dw0.denoise_asd_threshold = 0;
2922 sampler_dn[index].dw0.dnmh_delt = 8;
2923 sampler_dn[index].dw0.vdi_walker_y_stride = 0;
2924 sampler_dn[index].dw0.vdi_walker_frame_sharing_enable = 0;
2925 sampler_dn[index].dw0.denoise_maximum_history = 128; // 128-240
2926 sampler_dn[index].dw0.denoise_stad_threshold = 0;
2928 sampler_dn[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2929 sampler_dn[index].dw1.denoise_moving_pixel_threshold = 0;
2930 sampler_dn[index].dw1.stmm_c2 = 0;
2931 sampler_dn[index].dw1.low_temporal_difference_threshold = 8;
2932 sampler_dn[index].dw1.temporal_difference_threshold = 16;
2934 sampler_dn[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
2935 sampler_dn[index].dw2.bne_edge_th = 1;
2936 sampler_dn[index].dw2.smooth_mv_th = 0;
2937 sampler_dn[index].dw2.sad_tight_th = 5;
2938 sampler_dn[index].dw2.cat_slope_minus1 = 9;
2939 sampler_dn[index].dw2.good_neighbor_th = 4;
2941 sampler_dn[index].dw3.maximum_stmm = 128;
2942 sampler_dn[index].dw3.multipler_for_vecm = 2;
2943 sampler_dn[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2944 sampler_dn[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2945 sampler_dn[index].dw3.stmm_blending_constant_select = 0;
2947 sampler_dn[index].dw4.sdi_delta = 8;
2948 sampler_dn[index].dw4.sdi_threshold = 128;
2949 sampler_dn[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2950 sampler_dn[index].dw4.stmm_shift_up = 0;
2951 sampler_dn[index].dw4.stmm_shift_down = 0;
2952 sampler_dn[index].dw4.minimum_stmm = 0;
2954 sampler_dn[index].dw5.fmd_temporal_difference_threshold = 0;
2955 sampler_dn[index].dw5.sdi_fallback_mode_2_constant = 0;
2956 sampler_dn[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2957 sampler_dn[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2959 sampler_dn[index].dw6.dn_enable = 1;
2960 sampler_dn[index].dw6.di_enable = 0;
2961 sampler_dn[index].dw6.di_partial = 0;
2962 sampler_dn[index].dw6.dndi_top_first = dndi_top_first;
2963 sampler_dn[index].dw6.dndi_stream_id = 1;
2964 sampler_dn[index].dw6.dndi_first_frame = 1;
2965 sampler_dn[index].dw6.progressive_dn = dn_progressive;
2966 sampler_dn[index].dw6.mcdi_enable = 0;
2967 sampler_dn[index].dw6.fmd_tear_threshold = 32;
2968 sampler_dn[index].dw6.cat_th1 = 0;
2969 sampler_dn[index].dw6.fmd2_vertical_difference_threshold = 32;
2970 sampler_dn[index].dw6.fmd1_vertical_difference_threshold = 32;
2972 sampler_dn[index].dw7.sad_tha = 5;
2973 sampler_dn[index].dw7.sad_thb = 10;
2974 sampler_dn[index].dw7.fmd_for_1st_field_of_current_frame = 2;
2975 sampler_dn[index].dw7.mc_pixel_consistency_th = 25;
2976 sampler_dn[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
2977 sampler_dn[index].dw7.vdi_walker_enable = 0;
2978 sampler_dn[index].dw7.neighborpixel_th = 10;
2979 sampler_dn[index].dw7.column_width_minus1 = w / 16;
2981 dri_bo_unmap(pp_context->sampler_state_table.bo);
2983 /* private function & data */
2984 pp_context->pp_x_steps = gen7_pp_dn_x_steps;
2985 pp_context->pp_y_steps = gen7_pp_dn_y_steps;
2986 pp_context->pp_set_block_parameter = gen7_pp_dn_set_block_parameter;
2988 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
2989 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
2990 pp_static_parameter->grf1.di_top_field_first = 0;
2991 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2993 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2994 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2995 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2997 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
2998 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3000 pp_dn_context->dest_w = w;
3001 pp_dn_context->dest_h = h;
3003 dst_surface->flags = src_surface->flags;
3005 return VA_STATUS_SUCCESS;
3008 // update u/v offset when the surface format are packed yuv
3009 static void i965_update_src_surface_uv_offset(
3010 VADriverContextP ctx,
3011 struct i965_post_processing_context *pp_context,
3012 const struct i965_surface *surface)
3014 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3015 int fourcc = pp_get_surface_fourcc(ctx, surface);
3017 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
3018 pp_static_parameter->grf1.source_packed_u_offset = 1;
3019 pp_static_parameter->grf1.source_packed_v_offset = 3;
3021 else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
3022 pp_static_parameter->grf1.source_packed_y_offset = 1;
3023 pp_static_parameter->grf1.source_packed_v_offset = 2;
3028 static void i965_update_dst_surface_uv_offset(
3029 VADriverContextP ctx,
3030 struct i965_post_processing_context *pp_context,
3031 const struct i965_surface *surface)
3033 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3034 int fourcc = pp_get_surface_fourcc(ctx, surface);
3036 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
3037 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_u_offset = 1;
3038 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 3;
3040 else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
3041 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_y_offset = 1;
3042 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 2;
3048 ironlake_pp_initialize(
3049 VADriverContextP ctx,
3050 struct i965_post_processing_context *pp_context,
3051 const struct i965_surface *src_surface,
3052 const VARectangle *src_rect,
3053 struct i965_surface *dst_surface,
3054 const VARectangle *dst_rect,
3060 struct i965_driver_data *i965 = i965_driver_data(ctx);
3061 struct pp_module *pp_module;
3063 int static_param_size, inline_param_size;
3065 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3066 bo = dri_bo_alloc(i965->intel.bufmgr,
3067 "surface state & binding table",
3068 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
3071 pp_context->surface_state_binding_table.bo = bo;
3073 dri_bo_unreference(pp_context->curbe.bo);
3074 bo = dri_bo_alloc(i965->intel.bufmgr,
3079 pp_context->curbe.bo = bo;
3081 dri_bo_unreference(pp_context->idrt.bo);
3082 bo = dri_bo_alloc(i965->intel.bufmgr,
3083 "interface discriptor",
3084 sizeof(struct i965_interface_descriptor),
3087 pp_context->idrt.bo = bo;
3088 pp_context->idrt.num_interface_descriptors = 0;
3090 dri_bo_unreference(pp_context->sampler_state_table.bo);
3091 bo = dri_bo_alloc(i965->intel.bufmgr,
3092 "sampler state table",
3096 dri_bo_map(bo, True);
3097 memset(bo->virtual, 0, bo->size);
3099 pp_context->sampler_state_table.bo = bo;
3101 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3102 bo = dri_bo_alloc(i965->intel.bufmgr,
3103 "sampler 8x8 state ",
3107 pp_context->sampler_state_table.bo_8x8 = bo;
3109 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3110 bo = dri_bo_alloc(i965->intel.bufmgr,
3111 "sampler 8x8 state ",
3115 pp_context->sampler_state_table.bo_8x8_uv = bo;
3117 dri_bo_unreference(pp_context->vfe_state.bo);
3118 bo = dri_bo_alloc(i965->intel.bufmgr,
3120 sizeof(struct i965_vfe_state),
3123 pp_context->vfe_state.bo = bo;
3125 if (IS_GEN7(i965->intel.device_id)) {
3126 static_param_size = sizeof(struct gen7_pp_static_parameter);
3127 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
3129 static_param_size = sizeof(struct pp_static_parameter);
3130 inline_param_size = sizeof(struct pp_inline_parameter);
3133 memset(pp_context->pp_static_parameter, 0, static_param_size);
3134 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
3136 // update u/v offset for packed yuv
3137 i965_update_src_surface_uv_offset (ctx, pp_context, src_surface);
3138 i965_update_dst_surface_uv_offset (ctx, pp_context, dst_surface);
3140 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3141 pp_context->current_pp = pp_index;
3142 pp_module = &pp_context->pp_modules[pp_index];
3144 if (pp_module->initialize)
3145 va_status = pp_module->initialize(ctx, pp_context,
3152 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3158 ironlake_post_processing(
3159 VADriverContextP ctx,
3160 struct i965_post_processing_context *pp_context,
3161 const struct i965_surface *src_surface,
3162 const VARectangle *src_rect,
3163 struct i965_surface *dst_surface,
3164 const VARectangle *dst_rect,
3171 va_status = ironlake_pp_initialize(ctx, pp_context,
3179 if (va_status == VA_STATUS_SUCCESS) {
3180 ironlake_pp_states_setup(ctx, pp_context);
3181 ironlake_pp_pipeline_setup(ctx, pp_context);
3189 VADriverContextP ctx,
3190 struct i965_post_processing_context *pp_context,
3191 const struct i965_surface *src_surface,
3192 const VARectangle *src_rect,
3193 struct i965_surface *dst_surface,
3194 const VARectangle *dst_rect,
3200 struct i965_driver_data *i965 = i965_driver_data(ctx);
3201 struct pp_module *pp_module;
3203 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3204 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3206 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3207 bo = dri_bo_alloc(i965->intel.bufmgr,
3208 "surface state & binding table",
3209 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
3212 pp_context->surface_state_binding_table.bo = bo;
3214 dri_bo_unreference(pp_context->curbe.bo);
3215 bo = dri_bo_alloc(i965->intel.bufmgr,
3220 pp_context->curbe.bo = bo;
3222 dri_bo_unreference(pp_context->idrt.bo);
3223 bo = dri_bo_alloc(i965->intel.bufmgr,
3224 "interface discriptor",
3225 sizeof(struct gen6_interface_descriptor_data),
3228 pp_context->idrt.bo = bo;
3229 pp_context->idrt.num_interface_descriptors = 0;
3231 dri_bo_unreference(pp_context->sampler_state_table.bo);
3232 bo = dri_bo_alloc(i965->intel.bufmgr,
3233 "sampler state table",
3237 dri_bo_map(bo, True);
3238 memset(bo->virtual, 0, bo->size);
3240 pp_context->sampler_state_table.bo = bo;
3242 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3243 bo = dri_bo_alloc(i965->intel.bufmgr,
3244 "sampler 8x8 state ",
3248 pp_context->sampler_state_table.bo_8x8 = bo;
3250 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3251 bo = dri_bo_alloc(i965->intel.bufmgr,
3252 "sampler 8x8 state ",
3256 pp_context->sampler_state_table.bo_8x8_uv = bo;
3258 dri_bo_unreference(pp_context->vfe_state.bo);
3259 bo = dri_bo_alloc(i965->intel.bufmgr,
3261 sizeof(struct i965_vfe_state),
3264 pp_context->vfe_state.bo = bo;
3266 memset(pp_static_parameter, 0, sizeof(*pp_static_parameter));
3267 memset(pp_inline_parameter, 0, sizeof(*pp_inline_parameter));
3269 // update u/v offset for packed yuv
3270 i965_update_src_surface_uv_offset (ctx, pp_context, src_surface);
3271 i965_update_dst_surface_uv_offset (ctx, pp_context, dst_surface);
3273 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3274 pp_context->current_pp = pp_index;
3275 pp_module = &pp_context->pp_modules[pp_index];
3277 if (pp_module->initialize)
3278 va_status = pp_module->initialize(ctx, pp_context,
3285 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3291 gen6_pp_interface_descriptor_table(VADriverContextP ctx,
3292 struct i965_post_processing_context *pp_context)
3294 struct i965_driver_data *i965 = i965_driver_data(ctx);
3295 struct gen6_interface_descriptor_data *desc;
3297 int pp_index = pp_context->current_pp;
3299 bo = pp_context->idrt.bo;
3300 dri_bo_map(bo, True);
3301 assert(bo->virtual);
3303 memset(desc, 0, sizeof(*desc));
3304 desc->desc0.kernel_start_pointer =
3305 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
3306 desc->desc1.single_program_flow = 1;
3307 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
3308 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
3309 desc->desc2.sampler_state_pointer =
3310 pp_context->sampler_state_table.bo->offset >> 5;
3311 desc->desc3.binding_table_entry_count = 0;
3312 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
3313 desc->desc4.constant_urb_entry_read_offset = 0;
3315 if (IS_GEN7(i965->intel.device_id))
3316 desc->desc4.constant_urb_entry_read_length = 6; /* grf 1-6 */
3318 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
3320 dri_bo_emit_reloc(bo,
3321 I915_GEM_DOMAIN_INSTRUCTION, 0,
3323 offsetof(struct gen6_interface_descriptor_data, desc0),
3324 pp_context->pp_modules[pp_index].kernel.bo);
3326 dri_bo_emit_reloc(bo,
3327 I915_GEM_DOMAIN_INSTRUCTION, 0,
3328 desc->desc2.sampler_count << 2,
3329 offsetof(struct gen6_interface_descriptor_data, desc2),
3330 pp_context->sampler_state_table.bo);
3333 pp_context->idrt.num_interface_descriptors++;
3337 gen6_pp_upload_constants(VADriverContextP ctx,
3338 struct i965_post_processing_context *pp_context)
3340 struct i965_driver_data *i965 = i965_driver_data(ctx);
3341 unsigned char *constant_buffer;
3344 assert(sizeof(struct pp_static_parameter) == 128);
3345 assert(sizeof(struct gen7_pp_static_parameter) == 192);
3347 if (IS_GEN7(i965->intel.device_id))
3348 param_size = sizeof(struct gen7_pp_static_parameter);
3350 param_size = sizeof(struct pp_static_parameter);
3352 dri_bo_map(pp_context->curbe.bo, 1);
3353 assert(pp_context->curbe.bo->virtual);
3354 constant_buffer = pp_context->curbe.bo->virtual;
3355 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
3356 dri_bo_unmap(pp_context->curbe.bo);
3360 gen6_pp_states_setup(VADriverContextP ctx,
3361 struct i965_post_processing_context *pp_context)
3363 gen6_pp_interface_descriptor_table(ctx, pp_context);
3364 gen6_pp_upload_constants(ctx, pp_context);
3368 gen6_pp_pipeline_select(VADriverContextP ctx,
3369 struct i965_post_processing_context *pp_context)
3371 struct intel_batchbuffer *batch = pp_context->batch;
3373 BEGIN_BATCH(batch, 1);
3374 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
3375 ADVANCE_BATCH(batch);
3379 gen6_pp_state_base_address(VADriverContextP ctx,
3380 struct i965_post_processing_context *pp_context)
3382 struct intel_batchbuffer *batch = pp_context->batch;
3384 BEGIN_BATCH(batch, 10);
3385 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
3386 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3387 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
3388 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3389 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3390 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3391 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3392 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3393 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3394 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3395 ADVANCE_BATCH(batch);
3399 gen6_pp_vfe_state(VADriverContextP ctx,
3400 struct i965_post_processing_context *pp_context)
3402 struct intel_batchbuffer *batch = pp_context->batch;
3404 BEGIN_BATCH(batch, 8);
3405 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
3406 OUT_BATCH(batch, 0);
3408 (pp_context->urb.num_vfe_entries - 1) << 16 |
3409 pp_context->urb.num_vfe_entries << 8);
3410 OUT_BATCH(batch, 0);
3412 (pp_context->urb.size_vfe_entry * 2) << 16 | /* URB Entry Allocation Size, in 256 bits unit */
3413 (pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2)); /* CURBE Allocation Size, in 256 bits unit */
3414 OUT_BATCH(batch, 0);
3415 OUT_BATCH(batch, 0);
3416 OUT_BATCH(batch, 0);
3417 ADVANCE_BATCH(batch);
3421 gen6_pp_curbe_load(VADriverContextP ctx,
3422 struct i965_post_processing_context *pp_context)
3424 struct intel_batchbuffer *batch = pp_context->batch;
3426 assert(pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32 <= pp_context->curbe.bo->size);
3428 BEGIN_BATCH(batch, 4);
3429 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
3430 OUT_BATCH(batch, 0);
3432 pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32);
3434 pp_context->curbe.bo,
3435 I915_GEM_DOMAIN_INSTRUCTION, 0,
3437 ADVANCE_BATCH(batch);
3441 gen6_interface_descriptor_load(VADriverContextP ctx,
3442 struct i965_post_processing_context *pp_context)
3444 struct intel_batchbuffer *batch = pp_context->batch;
3446 BEGIN_BATCH(batch, 4);
3447 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
3448 OUT_BATCH(batch, 0);
3450 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
3452 pp_context->idrt.bo,
3453 I915_GEM_DOMAIN_INSTRUCTION, 0,
3455 ADVANCE_BATCH(batch);
3459 gen6_pp_object_walker(VADriverContextP ctx,
3460 struct i965_post_processing_context *pp_context)
3462 struct i965_driver_data *i965 = i965_driver_data(ctx);
3463 struct intel_batchbuffer *batch = pp_context->batch;
3464 int x, x_steps, y, y_steps;
3465 int param_size, command_length_in_dws;
3466 dri_bo *command_buffer;
3467 unsigned int *command_ptr;
3469 if (IS_GEN7(i965->intel.device_id))
3470 param_size = sizeof(struct gen7_pp_inline_parameter);
3472 param_size = sizeof(struct pp_inline_parameter);
3474 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
3475 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
3476 command_length_in_dws = 6 + (param_size >> 2);
3477 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
3478 "command objects buffer",
3479 command_length_in_dws * 4 * x_steps * y_steps + 8,
3482 dri_bo_map(command_buffer, 1);
3483 command_ptr = command_buffer->virtual;
3485 for (y = 0; y < y_steps; y++) {
3486 for (x = 0; x < x_steps; x++) {
3487 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
3488 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
3494 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
3495 command_ptr += (param_size >> 2);
3500 if (command_length_in_dws * x_steps * y_steps % 2 == 0)
3503 *command_ptr = MI_BATCH_BUFFER_END;
3505 dri_bo_unmap(command_buffer);
3507 BEGIN_BATCH(batch, 2);
3508 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (2 << 6));
3509 OUT_RELOC(batch, command_buffer,
3510 I915_GEM_DOMAIN_COMMAND, 0,
3512 ADVANCE_BATCH(batch);
3514 dri_bo_unreference(command_buffer);
3516 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
3517 * will cause control to pass back to ring buffer
3519 intel_batchbuffer_end_atomic(batch);
3520 intel_batchbuffer_flush(batch);
3521 intel_batchbuffer_start_atomic(batch, 0x1000);
3525 gen6_pp_pipeline_setup(VADriverContextP ctx,
3526 struct i965_post_processing_context *pp_context)
3528 struct intel_batchbuffer *batch = pp_context->batch;
3530 intel_batchbuffer_start_atomic(batch, 0x1000);
3531 intel_batchbuffer_emit_mi_flush(batch);
3532 gen6_pp_pipeline_select(ctx, pp_context);
3533 gen6_pp_state_base_address(ctx, pp_context);
3534 gen6_pp_vfe_state(ctx, pp_context);
3535 gen6_pp_curbe_load(ctx, pp_context);
3536 gen6_interface_descriptor_load(ctx, pp_context);
3537 gen6_pp_object_walker(ctx, pp_context);
3538 intel_batchbuffer_end_atomic(batch);
3542 gen6_post_processing(
3543 VADriverContextP ctx,
3544 struct i965_post_processing_context *pp_context,
3545 const struct i965_surface *src_surface,
3546 const VARectangle *src_rect,
3547 struct i965_surface *dst_surface,
3548 const VARectangle *dst_rect,
3555 va_status = gen6_pp_initialize(ctx, pp_context,
3563 if (va_status == VA_STATUS_SUCCESS) {
3564 gen6_pp_states_setup(ctx, pp_context);
3565 gen6_pp_pipeline_setup(ctx, pp_context);
3572 i965_post_processing_internal(
3573 VADriverContextP ctx,
3574 struct i965_post_processing_context *pp_context,
3575 const struct i965_surface *src_surface,
3576 const VARectangle *src_rect,
3577 struct i965_surface *dst_surface,
3578 const VARectangle *dst_rect,
3583 struct i965_driver_data *i965 = i965_driver_data(ctx);
3586 if (IS_GEN6(i965->intel.device_id) ||
3587 IS_GEN7(i965->intel.device_id))
3588 va_status = gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3590 va_status = ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3596 i965_DestroySurfaces(VADriverContextP ctx,
3597 VASurfaceID *surface_list,
3600 i965_CreateSurfaces(VADriverContextP ctx,
3605 VASurfaceID *surfaces);
3608 rgb_to_yuv(unsigned int argb,
3614 int r = ((argb >> 16) & 0xff);
3615 int g = ((argb >> 8) & 0xff);
3616 int b = ((argb >> 0) & 0xff);
3618 *y = (257 * r + 504 * g + 98 * b) / 1000 + 16;
3619 *v = (439 * r - 368 * g - 71 * b) / 1000 + 128;
3620 *u = (-148 * r - 291 * g + 439 * b) / 1000 + 128;
3621 *a = ((argb >> 24) & 0xff);
3625 i965_vpp_clear_surface(VADriverContextP ctx,
3626 struct i965_post_processing_context *pp_context,
3627 VASurfaceID surface,
3630 struct i965_driver_data *i965 = i965_driver_data(ctx);
3631 struct intel_batchbuffer *batch = pp_context->batch;
3632 struct object_surface *obj_surface = SURFACE(surface);
3633 unsigned int blt_cmd, br13;
3634 unsigned int tiling = 0, swizzle = 0;
3636 unsigned char y, u, v, a;
3638 /* Currently only support NV12 surface */
3639 if (!obj_surface || obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3642 rgb_to_yuv(color, &y, &u, &v, &a);
3644 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3645 blt_cmd = XY_COLOR_BLT_CMD;
3646 pitch = obj_surface->width;
3648 if (tiling != I915_TILING_NONE) {
3649 blt_cmd |= XY_COLOR_BLT_DST_TILED;
3657 if (IS_GEN6(i965->intel.device_id) ||
3658 IS_GEN7(i965->intel.device_id)) {
3659 intel_batchbuffer_start_atomic_blt(batch, 48);
3660 BEGIN_BLT_BATCH(batch, 12);
3662 intel_batchbuffer_start_atomic(batch, 48);
3663 BEGIN_BATCH(batch, 12);
3666 OUT_BATCH(batch, blt_cmd);
3667 OUT_BATCH(batch, br13);
3672 obj_surface->height << 16 |
3673 obj_surface->width);
3674 OUT_RELOC(batch, obj_surface->bo,
3675 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3677 OUT_BATCH(batch, y);
3683 OUT_BATCH(batch, blt_cmd);
3684 OUT_BATCH(batch, br13);
3689 obj_surface->height / 2 << 16 |
3690 obj_surface->width / 2);
3691 OUT_RELOC(batch, obj_surface->bo,
3692 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3693 obj_surface->width * obj_surface->y_cb_offset);
3694 OUT_BATCH(batch, v << 8 | u);
3696 ADVANCE_BATCH(batch);
3697 intel_batchbuffer_end_atomic(batch);
3701 i965_post_processing(
3702 VADriverContextP ctx,
3703 VASurfaceID surface,
3704 const VARectangle *src_rect,
3705 const VARectangle *dst_rect,
3707 int *has_done_scaling
3710 struct i965_driver_data *i965 = i965_driver_data(ctx);
3711 VASurfaceID in_surface_id = surface;
3712 VASurfaceID out_surface_id = VA_INVALID_ID;
3714 *has_done_scaling = 0;
3717 struct object_surface *obj_surface;
3719 struct i965_surface src_surface;
3720 struct i965_surface dst_surface;
3722 obj_surface = SURFACE(in_surface_id);
3724 /* Currently only support post processing for NV12 surface */
3725 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3726 return out_surface_id;
3728 _i965LockMutex(&i965->pp_mutex);
3730 if (flags & I965_PP_FLAG_MCDI) {
3731 status = i965_CreateSurfaces(ctx,
3732 obj_surface->orig_width,
3733 obj_surface->orig_height,
3734 VA_RT_FORMAT_YUV420,
3737 assert(status == VA_STATUS_SUCCESS);
3738 obj_surface = SURFACE(out_surface_id);
3739 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3740 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3741 src_surface.id = in_surface_id;
3742 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3743 src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ?
3744 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
3745 dst_surface.id = out_surface_id;
3746 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3747 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3749 i965_post_processing_internal(ctx, i965->pp_context,
3758 if (flags & I965_PP_FLAG_AVS) {
3759 struct i965_render_state *render_state = &i965->render_state;
3760 struct intel_region *dest_region = render_state->draw_region;
3762 if (out_surface_id != VA_INVALID_ID)
3763 in_surface_id = out_surface_id;
3765 status = i965_CreateSurfaces(ctx,
3767 dest_region->height,
3768 VA_RT_FORMAT_YUV420,
3771 assert(status == VA_STATUS_SUCCESS);
3772 obj_surface = SURFACE(out_surface_id);
3773 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3774 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3775 src_surface.id = in_surface_id;
3776 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3777 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3778 dst_surface.id = out_surface_id;
3779 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3780 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3782 i965_post_processing_internal(ctx, i965->pp_context,
3790 if (in_surface_id != surface)
3791 i965_DestroySurfaces(ctx, &in_surface_id, 1);
3793 *has_done_scaling = 1;
3796 _i965UnlockMutex(&i965->pp_mutex);
3799 return out_surface_id;
3803 i965_image_pl3_processing(VADriverContextP ctx,
3804 const struct i965_surface *src_surface,
3805 const VARectangle *src_rect,
3806 struct i965_surface *dst_surface,
3807 const VARectangle *dst_rect)
3809 struct i965_driver_data *i965 = i965_driver_data(ctx);
3810 struct i965_post_processing_context *pp_context = i965->pp_context;
3811 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
3813 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
3814 i965_post_processing_internal(ctx, i965->pp_context,
3819 PP_PL3_LOAD_SAVE_N12,
3822 i965_post_processing_internal(ctx, i965->pp_context,
3827 PP_PL3_LOAD_SAVE_PL3,
3831 intel_batchbuffer_flush(pp_context->batch);
3833 return VA_STATUS_SUCCESS;
3837 i965_image_pl2_processing(VADriverContextP ctx,
3838 const struct i965_surface *src_surface,
3839 const VARectangle *src_rect,
3840 struct i965_surface *dst_surface,
3841 const VARectangle *dst_rect)
3843 struct i965_driver_data *i965 = i965_driver_data(ctx);
3844 struct i965_post_processing_context *pp_context = i965->pp_context;
3845 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
3847 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
3848 i965_post_processing_internal(ctx, i965->pp_context,
3853 PP_NV12_LOAD_SAVE_N12,
3855 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
3856 fourcc == VA_FOURCC('I', 'M', 'C', '3')) {
3857 i965_post_processing_internal(ctx, i965->pp_context,
3862 PP_NV12_LOAD_SAVE_PL3,
3864 } else if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
3865 i965_post_processing_internal(ctx, i965->pp_context,
3870 PP_NV12_LOAD_SAVE_PA,
3874 intel_batchbuffer_flush(pp_context->batch);
3876 return VA_STATUS_SUCCESS;
3880 i965_image_processing(VADriverContextP ctx,
3881 const struct i965_surface *src_surface,
3882 const VARectangle *src_rect,
3883 struct i965_surface *dst_surface,
3884 const VARectangle *dst_rect)
3886 struct i965_driver_data *i965 = i965_driver_data(ctx);
3887 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
3890 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
3892 _i965LockMutex(&i965->pp_mutex);
3895 case VA_FOURCC('Y', 'V', '1', '2'):
3896 case VA_FOURCC('I', '4', '2', '0'):
3897 case VA_FOURCC('I', 'M', 'C', '1'):
3898 case VA_FOURCC('I', 'M', 'C', '3'):
3899 status = i965_image_pl3_processing(ctx,
3906 case VA_FOURCC('N', 'V', '1', '2'):
3907 status = i965_image_pl2_processing(ctx,
3915 status = VA_STATUS_ERROR_UNIMPLEMENTED;
3919 _i965UnlockMutex(&i965->pp_mutex);
3926 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
3930 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3931 pp_context->surface_state_binding_table.bo = NULL;
3933 dri_bo_unreference(pp_context->curbe.bo);
3934 pp_context->curbe.bo = NULL;
3936 dri_bo_unreference(pp_context->sampler_state_table.bo);
3937 pp_context->sampler_state_table.bo = NULL;
3939 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3940 pp_context->sampler_state_table.bo_8x8 = NULL;
3942 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3943 pp_context->sampler_state_table.bo_8x8_uv = NULL;
3945 dri_bo_unreference(pp_context->idrt.bo);
3946 pp_context->idrt.bo = NULL;
3947 pp_context->idrt.num_interface_descriptors = 0;
3949 dri_bo_unreference(pp_context->vfe_state.bo);
3950 pp_context->vfe_state.bo = NULL;
3952 dri_bo_unreference(pp_context->stmm.bo);
3953 pp_context->stmm.bo = NULL;
3955 for (i = 0; i < NUM_PP_MODULES; i++) {
3956 struct pp_module *pp_module = &pp_context->pp_modules[i];
3958 dri_bo_unreference(pp_module->kernel.bo);
3959 pp_module->kernel.bo = NULL;
3962 free(pp_context->pp_static_parameter);
3963 free(pp_context->pp_inline_parameter);
3964 pp_context->pp_static_parameter = NULL;
3965 pp_context->pp_inline_parameter = NULL;
3969 i965_post_processing_terminate(VADriverContextP ctx)
3971 struct i965_driver_data *i965 = i965_driver_data(ctx);
3972 struct i965_post_processing_context *pp_context = i965->pp_context;
3975 i965_post_processing_context_finalize(pp_context);
3979 i965->pp_context = NULL;
3985 i965_post_processing_context_init(VADriverContextP ctx,
3986 struct i965_post_processing_context *pp_context,
3987 struct intel_batchbuffer *batch)
3989 struct i965_driver_data *i965 = i965_driver_data(ctx);
3992 pp_context->urb.size = URB_SIZE((&i965->intel));
3993 pp_context->urb.num_vfe_entries = 32;
3994 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
3995 pp_context->urb.num_cs_entries = 1;
3997 if (IS_GEN7(i965->intel.device_id))
3998 pp_context->urb.size_cs_entry = 4; /* in 512 bits unit */
4000 pp_context->urb.size_cs_entry = 2;
4002 pp_context->urb.vfe_start = 0;
4003 pp_context->urb.cs_start = pp_context->urb.vfe_start +
4004 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
4005 assert(pp_context->urb.cs_start +
4006 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
4008 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
4009 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
4010 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen7));
4012 if (IS_GEN7(i965->intel.device_id))
4013 memcpy(pp_context->pp_modules, pp_modules_gen7, sizeof(pp_context->pp_modules));
4014 else if (IS_GEN6(i965->intel.device_id))
4015 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
4016 else if (IS_IRONLAKE(i965->intel.device_id))
4017 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
4019 for (i = 0; i < NUM_PP_MODULES; i++) {
4020 struct pp_module *pp_module = &pp_context->pp_modules[i];
4021 dri_bo_unreference(pp_module->kernel.bo);
4022 if (pp_module->kernel.bin && pp_module->kernel.size) {
4023 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
4024 pp_module->kernel.name,
4025 pp_module->kernel.size,
4027 assert(pp_module->kernel.bo);
4028 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
4030 pp_module->kernel.bo = NULL;
4034 /* static & inline parameters */
4035 if (IS_GEN7(i965->intel.device_id)) {
4036 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
4037 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
4039 pp_context->pp_static_parameter = calloc(sizeof(struct pp_static_parameter), 1);
4040 pp_context->pp_inline_parameter = calloc(sizeof(struct pp_inline_parameter), 1);
4043 pp_context->batch = batch;
4047 i965_post_processing_init(VADriverContextP ctx)
4049 struct i965_driver_data *i965 = i965_driver_data(ctx);
4050 struct i965_post_processing_context *pp_context = i965->pp_context;
4053 if (pp_context == NULL) {
4054 pp_context = calloc(1, sizeof(*pp_context));
4055 i965_post_processing_context_init(ctx, pp_context, i965->batch);
4056 i965->pp_context = pp_context;
4063 static const int procfilter_to_pp_flag[VAProcFilterCount] = {
4064 PP_NULL, /* VAProcFilterNone */
4065 PP_NV12_DN, /* VAProcFilterNoiseReduction */
4066 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
4067 PP_NULL, /* VAProcFilterSharpening */
4068 PP_NULL, /* VAProcFilterColorBalance */
4069 PP_NULL, /* VAProcFilterColorStandard */
4072 static const int proc_frame_to_pp_frame[3] = {
4073 I965_SURFACE_FLAG_FRAME,
4074 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
4075 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
4079 i965_proc_picture(VADriverContextP ctx,
4081 union codec_state *codec_state,
4082 struct hw_context *hw_context)
4084 struct i965_driver_data *i965 = i965_driver_data(ctx);
4085 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
4086 struct proc_state *proc_state = &codec_state->proc;
4087 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
4088 struct object_surface *obj_surface;
4089 struct i965_surface src_surface, dst_surface;
4090 VARectangle src_rect, dst_rect;
4093 VASurfaceID tmp_surfaces[VAProcFilterCount + 4];
4094 int num_tmp_surfaces = 0;
4095 unsigned int tiling = 0, swizzle = 0;
4096 int in_width, in_height;
4098 assert(pipeline_param->surface != VA_INVALID_ID);
4099 assert(proc_state->current_render_target != VA_INVALID_ID);
4101 obj_surface = SURFACE(pipeline_param->surface);
4102 in_width = obj_surface->orig_width;
4103 in_height = obj_surface->orig_height;
4104 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4106 src_surface.id = pipeline_param->surface;
4107 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4108 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
4110 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
4111 VASurfaceID out_surface_id = VA_INVALID_ID;
4113 src_surface.id = pipeline_param->surface;
4114 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4115 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4118 src_rect.width = in_width;
4119 src_rect.height = in_height;
4121 status = i965_CreateSurfaces(ctx,
4124 VA_RT_FORMAT_YUV420,
4127 assert(status == VA_STATUS_SUCCESS);
4128 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
4129 obj_surface = SURFACE(out_surface_id);
4130 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
4132 dst_surface.id = out_surface_id;
4133 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4134 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4137 dst_rect.width = in_width;
4138 dst_rect.height = in_height;
4140 status = i965_image_processing(ctx,
4145 assert(status == VA_STATUS_SUCCESS);
4147 src_surface.id = out_surface_id;
4148 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4149 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
4152 if (pipeline_param->surface_region) {
4153 src_rect.x = pipeline_param->surface_region->x;
4154 src_rect.y = pipeline_param->surface_region->y;
4155 src_rect.width = pipeline_param->surface_region->width;
4156 src_rect.height = pipeline_param->surface_region->height;
4160 src_rect.width = in_width;
4161 src_rect.height = in_height;
4164 if (pipeline_param->output_region) {
4165 dst_rect.x = pipeline_param->output_region->x;
4166 dst_rect.y = pipeline_param->output_region->y;
4167 dst_rect.width = pipeline_param->output_region->width;
4168 dst_rect.height = pipeline_param->output_region->height;
4172 dst_rect.width = in_width;
4173 dst_rect.height = in_height;
4176 obj_surface = SURFACE(proc_state->current_render_target);
4177 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4178 i965_vpp_clear_surface(ctx, i965->pp_context, proc_state->current_render_target, pipeline_param->output_background_color);
4180 for (i = 0; i < pipeline_param->num_filters; i++) {
4181 struct object_buffer *obj_buffer = BUFFER(pipeline_param->filters[i]);
4182 VAProcFilterParameterBufferBase *filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4183 VAProcFilterType filter_type = filter_param->type;
4184 VASurfaceID out_surface_id = VA_INVALID_ID;
4185 int kernel_index = procfilter_to_pp_flag[filter_type];
4187 if (kernel_index != PP_NULL &&
4188 proc_context->pp_context.pp_modules[kernel_index].kernel.bo != NULL) {
4189 status = i965_CreateSurfaces(ctx,
4192 VA_RT_FORMAT_YUV420,
4195 assert(status == VA_STATUS_SUCCESS);
4196 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
4197 obj_surface = SURFACE(out_surface_id);
4198 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4199 dst_surface.id = out_surface_id;
4200 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4201 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
4209 if (status == VA_STATUS_SUCCESS) {
4210 src_surface.id = dst_surface.id;
4211 src_surface.type = dst_surface.type;
4212 src_surface.flags = dst_surface.flags;
4217 dst_surface.id = proc_state->current_render_target;
4218 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4220 if (src_rect.width == dst_rect.width &&
4221 src_rect.height == dst_rect.height) {
4222 i965_post_processing_internal(ctx, &proc_context->pp_context,
4227 PP_NV12_LOAD_SAVE_N12,
4231 i965_post_processing_internal(ctx, &proc_context->pp_context,
4236 (pipeline_param->filter_flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC ?
4237 PP_NV12_AVS : PP_NV12_SCALING,
4241 if (num_tmp_surfaces)
4242 i965_DestroySurfaces(ctx,
4246 intel_batchbuffer_flush(hw_context->batch);
4250 i965_proc_context_destroy(void *hw_context)
4252 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
4254 i965_post_processing_context_finalize(&proc_context->pp_context);
4255 intel_batchbuffer_free(proc_context->base.batch);
4260 i965_proc_context_init(VADriverContextP ctx, struct object_config *obj_config)
4262 struct intel_driver_data *intel = intel_driver_data(ctx);
4263 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
4265 proc_context->base.destroy = i965_proc_context_destroy;
4266 proc_context->base.run = i965_proc_picture;
4267 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
4268 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
4270 return (struct hw_context *)proc_context;