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 const uint32_t pp_pl3_load_save_pa_gen5[][4] = {
99 #include "shaders/post_processing/gen5_6/pl3_load_save_pa.g4b.gen5"
102 static const uint32_t pp_pa_load_save_nv12_gen5[][4] = {
103 #include "shaders/post_processing/gen5_6/pa_load_save_nv12.g4b.gen5"
106 static const uint32_t pp_pa_load_save_pl3_gen5[][4] = {
107 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g4b.gen5"
110 static VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
111 const struct i965_surface *src_surface,
112 const VARectangle *src_rect,
113 struct i965_surface *dst_surface,
114 const VARectangle *dst_rect,
116 static VAStatus pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
117 const struct i965_surface *src_surface,
118 const VARectangle *src_rect,
119 struct i965_surface *dst_surface,
120 const VARectangle *dst_rect,
122 static VAStatus pp_nv12_scaling_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 gen6_nv12_scaling_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_plx_load_save_plx_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,
140 static VAStatus pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
141 const struct i965_surface *src_surface,
142 const VARectangle *src_rect,
143 struct i965_surface *dst_surface,
144 const VARectangle *dst_rect,
146 static VAStatus pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
147 const struct i965_surface *src_surface,
148 const VARectangle *src_rect,
149 struct i965_surface *dst_surface,
150 const VARectangle *dst_rect,
153 static struct pp_module pp_modules_gen5[] = {
156 "NULL module (for testing)",
159 sizeof(pp_null_gen5),
169 PP_NV12_LOAD_SAVE_N12,
170 pp_nv12_load_save_nv12_gen5,
171 sizeof(pp_nv12_load_save_nv12_gen5),
175 pp_plx_load_save_plx_initialize,
181 PP_NV12_LOAD_SAVE_PL3,
182 pp_nv12_load_save_pl3_gen5,
183 sizeof(pp_nv12_load_save_pl3_gen5),
187 pp_plx_load_save_plx_initialize,
193 PP_PL3_LOAD_SAVE_N12,
194 pp_pl3_load_save_nv12_gen5,
195 sizeof(pp_pl3_load_save_nv12_gen5),
199 pp_plx_load_save_plx_initialize,
205 PP_PL3_LOAD_SAVE_N12,
206 pp_pl3_load_save_pl3_gen5,
207 sizeof(pp_pl3_load_save_pl3_gen5),
211 pp_plx_load_save_plx_initialize
216 "NV12 Scaling module",
218 pp_nv12_scaling_gen5,
219 sizeof(pp_nv12_scaling_gen5),
223 pp_nv12_scaling_initialize,
231 sizeof(pp_nv12_avs_gen5),
235 pp_nv12_avs_initialize_nlas,
243 sizeof(pp_nv12_dndi_gen5),
247 pp_nv12_dndi_initialize,
255 sizeof(pp_nv12_dn_gen5),
259 pp_nv12_dn_initialize,
265 PP_NV12_LOAD_SAVE_PA,
266 pp_nv12_load_save_pa_gen5,
267 sizeof(pp_nv12_load_save_pa_gen5),
271 pp_plx_load_save_plx_initialize,
278 pp_pl3_load_save_pa_gen5,
279 sizeof(pp_pl3_load_save_pa_gen5),
283 pp_plx_load_save_plx_initialize,
289 PP_PA_LOAD_SAVE_NV12,
290 pp_pa_load_save_nv12_gen5,
291 sizeof(pp_pa_load_save_nv12_gen5),
295 pp_plx_load_save_plx_initialize,
302 pp_pa_load_save_pl3_gen5,
303 sizeof(pp_pa_load_save_pl3_gen5),
307 pp_plx_load_save_plx_initialize,
312 static const uint32_t pp_null_gen6[][4] = {
313 #include "shaders/post_processing/gen5_6/null.g6b"
316 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
317 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
320 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
321 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
324 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
325 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
328 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
329 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
332 static const uint32_t pp_nv12_scaling_gen6[][4] = {
333 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
336 static const uint32_t pp_nv12_avs_gen6[][4] = {
337 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
340 static const uint32_t pp_nv12_dndi_gen6[][4] = {
341 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
344 static const uint32_t pp_nv12_dn_gen6[][4] = {
345 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g6b"
348 static const uint32_t pp_nv12_load_save_pa_gen6[][4] = {
349 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g6b"
352 static const uint32_t pp_pl3_load_save_pa_gen6[][4] = {
353 #include "shaders/post_processing/gen5_6/pl3_load_save_pa.g6b"
356 static const uint32_t pp_pa_load_save_nv12_gen6[][4] = {
357 #include "shaders/post_processing/gen5_6/pa_load_save_nv12.g6b"
360 static const uint32_t pp_pa_load_save_pl3_gen6[][4] = {
361 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g6b"
364 static struct pp_module pp_modules_gen6[] = {
367 "NULL module (for testing)",
370 sizeof(pp_null_gen6),
380 PP_NV12_LOAD_SAVE_N12,
381 pp_nv12_load_save_nv12_gen6,
382 sizeof(pp_nv12_load_save_nv12_gen6),
386 pp_plx_load_save_plx_initialize,
392 PP_NV12_LOAD_SAVE_PL3,
393 pp_nv12_load_save_pl3_gen6,
394 sizeof(pp_nv12_load_save_pl3_gen6),
398 pp_plx_load_save_plx_initialize,
404 PP_PL3_LOAD_SAVE_N12,
405 pp_pl3_load_save_nv12_gen6,
406 sizeof(pp_pl3_load_save_nv12_gen6),
410 pp_plx_load_save_plx_initialize,
416 PP_PL3_LOAD_SAVE_N12,
417 pp_pl3_load_save_pl3_gen6,
418 sizeof(pp_pl3_load_save_pl3_gen6),
422 pp_plx_load_save_plx_initialize,
427 "NV12 Scaling module",
429 pp_nv12_scaling_gen6,
430 sizeof(pp_nv12_scaling_gen6),
434 gen6_nv12_scaling_initialize,
442 sizeof(pp_nv12_avs_gen6),
446 pp_nv12_avs_initialize_nlas,
454 sizeof(pp_nv12_dndi_gen6),
458 pp_nv12_dndi_initialize,
466 sizeof(pp_nv12_dn_gen6),
470 pp_nv12_dn_initialize,
475 PP_NV12_LOAD_SAVE_PA,
476 pp_nv12_load_save_pa_gen6,
477 sizeof(pp_nv12_load_save_pa_gen6),
481 pp_plx_load_save_plx_initialize,
488 pp_pl3_load_save_pa_gen6,
489 sizeof(pp_pl3_load_save_pa_gen6),
493 pp_plx_load_save_plx_initialize,
499 PP_PA_LOAD_SAVE_NV12,
500 pp_pa_load_save_nv12_gen6,
501 sizeof(pp_pa_load_save_nv12_gen6),
505 pp_plx_load_save_plx_initialize,
512 pp_pa_load_save_pl3_gen6,
513 sizeof(pp_pa_load_save_pl3_gen6),
517 pp_plx_load_save_plx_initialize,
522 static const uint32_t pp_null_gen7[][4] = {
525 static const uint32_t pp_nv12_load_save_nv12_gen7[][4] = {
526 #include "shaders/post_processing/gen7/pl2_to_pl2.g7b"
529 static const uint32_t pp_nv12_load_save_pl3_gen7[][4] = {
530 #include "shaders/post_processing/gen7/pl2_to_pl3.g7b"
533 static const uint32_t pp_pl3_load_save_nv12_gen7[][4] = {
534 #include "shaders/post_processing/gen7/pl3_to_pl2.g7b"
537 static const uint32_t pp_pl3_load_save_pl3_gen7[][4] = {
538 #include "shaders/post_processing/gen7/pl3_to_pl3.g7b"
541 static const uint32_t pp_nv12_scaling_gen7[][4] = {
542 #include "shaders/post_processing/gen7/avs.g7b"
545 static const uint32_t pp_nv12_avs_gen7[][4] = {
546 #include "shaders/post_processing/gen7/avs.g7b"
549 static const uint32_t pp_nv12_dndi_gen7[][4] = {
550 // #include "shaders/post_processing/gen7/dndi.g7b"
553 static const uint32_t pp_nv12_dn_gen7[][4] = {
555 static const uint32_t pp_nv12_load_save_pa_gen7[][4] = {
556 #include "shaders/post_processing/gen7/pl2_to_pa.g7b"
558 static const uint32_t pp_pl3_load_save_pa_gen7[][4] = {
559 #include "shaders/post_processing/gen7/pl3_to_pa.g7b"
561 static const uint32_t pp_pa_load_save_nv12_gen7[][4] = {
562 #include "shaders/post_processing/gen7/pa_to_pl2.g7b"
564 static const uint32_t pp_pa_load_save_pl3_gen7[][4] = {
565 #include "shaders/post_processing/gen7/pa_to_pl3.g7b"
568 static VAStatus gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
569 const struct i965_surface *src_surface,
570 const VARectangle *src_rect,
571 struct i965_surface *dst_surface,
572 const VARectangle *dst_rect,
574 static VAStatus gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
575 const struct i965_surface *src_surface,
576 const VARectangle *src_rect,
577 struct i965_surface *dst_surface,
578 const VARectangle *dst_rect,
580 static VAStatus gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
581 const struct i965_surface *src_surface,
582 const VARectangle *src_rect,
583 struct i965_surface *dst_surface,
584 const VARectangle *dst_rect,
587 static struct pp_module pp_modules_gen7[] = {
590 "NULL module (for testing)",
593 sizeof(pp_null_gen7),
603 PP_NV12_LOAD_SAVE_N12,
604 pp_nv12_load_save_nv12_gen7,
605 sizeof(pp_nv12_load_save_nv12_gen7),
609 gen7_pp_plx_avs_initialize,
615 PP_NV12_LOAD_SAVE_PL3,
616 pp_nv12_load_save_pl3_gen7,
617 sizeof(pp_nv12_load_save_pl3_gen7),
621 gen7_pp_plx_avs_initialize,
627 PP_PL3_LOAD_SAVE_N12,
628 pp_pl3_load_save_nv12_gen7,
629 sizeof(pp_pl3_load_save_nv12_gen7),
633 gen7_pp_plx_avs_initialize,
639 PP_PL3_LOAD_SAVE_N12,
640 pp_pl3_load_save_pl3_gen7,
641 sizeof(pp_pl3_load_save_pl3_gen7),
645 gen7_pp_plx_avs_initialize,
650 "NV12 Scaling module",
652 pp_nv12_scaling_gen7,
653 sizeof(pp_nv12_scaling_gen7),
657 gen7_pp_plx_avs_initialize,
665 sizeof(pp_nv12_avs_gen7),
669 gen7_pp_plx_avs_initialize,
677 sizeof(pp_nv12_dndi_gen7),
681 gen7_pp_nv12_dndi_initialize,
689 sizeof(pp_nv12_dn_gen7),
693 gen7_pp_nv12_dn_initialize,
698 PP_NV12_LOAD_SAVE_PA,
699 pp_nv12_load_save_pa_gen7,
700 sizeof(pp_nv12_load_save_pa_gen7),
704 gen7_pp_plx_avs_initialize,
711 pp_pl3_load_save_pa_gen7,
712 sizeof(pp_pl3_load_save_pa_gen7),
716 gen7_pp_plx_avs_initialize,
722 PP_PA_LOAD_SAVE_NV12,
723 pp_pa_load_save_nv12_gen7,
724 sizeof(pp_pa_load_save_nv12_gen7),
728 gen7_pp_plx_avs_initialize,
735 pp_pa_load_save_pl3_gen7,
736 sizeof(pp_pa_load_save_pl3_gen7),
740 gen7_pp_plx_avs_initialize,
746 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
748 struct i965_driver_data *i965 = i965_driver_data(ctx);
751 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
752 struct object_image *obj_image = IMAGE(surface->id);
753 fourcc = obj_image->image.format.fourcc;
755 struct object_surface *obj_surface = SURFACE(surface->id);
756 fourcc = obj_surface->fourcc;
763 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
766 case I915_TILING_NONE:
767 ss->ss3.tiled_surface = 0;
768 ss->ss3.tile_walk = 0;
771 ss->ss3.tiled_surface = 1;
772 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
775 ss->ss3.tiled_surface = 1;
776 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
782 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
785 case I915_TILING_NONE:
786 ss->ss2.tiled_surface = 0;
787 ss->ss2.tile_walk = 0;
790 ss->ss2.tiled_surface = 1;
791 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
794 ss->ss2.tiled_surface = 1;
795 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
801 gen7_pp_set_surface_tiling(struct gen7_surface_state *ss, unsigned int tiling)
804 case I915_TILING_NONE:
805 ss->ss0.tiled_surface = 0;
806 ss->ss0.tile_walk = 0;
809 ss->ss0.tiled_surface = 1;
810 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
813 ss->ss0.tiled_surface = 1;
814 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
820 gen7_pp_set_surface2_tiling(struct gen7_surface_state2 *ss, unsigned int tiling)
823 case I915_TILING_NONE:
824 ss->ss2.tiled_surface = 0;
825 ss->ss2.tile_walk = 0;
828 ss->ss2.tiled_surface = 1;
829 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
832 ss->ss2.tiled_surface = 1;
833 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
839 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
841 struct i965_interface_descriptor *desc;
843 int pp_index = pp_context->current_pp;
845 bo = pp_context->idrt.bo;
849 memset(desc, 0, sizeof(*desc));
850 desc->desc0.grf_reg_blocks = 10;
851 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
852 desc->desc1.const_urb_entry_read_offset = 0;
853 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
854 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
855 desc->desc2.sampler_count = 0;
856 desc->desc3.binding_table_entry_count = 0;
857 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
859 dri_bo_emit_reloc(bo,
860 I915_GEM_DOMAIN_INSTRUCTION, 0,
861 desc->desc0.grf_reg_blocks,
862 offsetof(struct i965_interface_descriptor, desc0),
863 pp_context->pp_modules[pp_index].kernel.bo);
865 dri_bo_emit_reloc(bo,
866 I915_GEM_DOMAIN_INSTRUCTION, 0,
867 desc->desc2.sampler_count << 2,
868 offsetof(struct i965_interface_descriptor, desc2),
869 pp_context->sampler_state_table.bo);
872 pp_context->idrt.num_interface_descriptors++;
876 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
878 struct i965_vfe_state *vfe_state;
881 bo = pp_context->vfe_state.bo;
884 vfe_state = bo->virtual;
885 memset(vfe_state, 0, sizeof(*vfe_state));
886 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
887 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
888 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
889 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
890 vfe_state->vfe1.children_present = 0;
891 vfe_state->vfe2.interface_descriptor_base =
892 pp_context->idrt.bo->offset >> 4; /* reloc */
893 dri_bo_emit_reloc(bo,
894 I915_GEM_DOMAIN_INSTRUCTION, 0,
896 offsetof(struct i965_vfe_state, vfe2),
897 pp_context->idrt.bo);
902 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
904 unsigned char *constant_buffer;
905 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
907 assert(sizeof(*pp_static_parameter) == 128);
908 dri_bo_map(pp_context->curbe.bo, 1);
909 assert(pp_context->curbe.bo->virtual);
910 constant_buffer = pp_context->curbe.bo->virtual;
911 memcpy(constant_buffer, pp_static_parameter, sizeof(*pp_static_parameter));
912 dri_bo_unmap(pp_context->curbe.bo);
916 ironlake_pp_states_setup(VADriverContextP ctx,
917 struct i965_post_processing_context *pp_context)
919 ironlake_pp_interface_descriptor_table(pp_context);
920 ironlake_pp_vfe_state(pp_context);
921 ironlake_pp_upload_constants(pp_context);
925 ironlake_pp_pipeline_select(VADriverContextP ctx,
926 struct i965_post_processing_context *pp_context)
928 struct intel_batchbuffer *batch = pp_context->batch;
930 BEGIN_BATCH(batch, 1);
931 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
932 ADVANCE_BATCH(batch);
936 ironlake_pp_urb_layout(VADriverContextP ctx,
937 struct i965_post_processing_context *pp_context)
939 struct intel_batchbuffer *batch = pp_context->batch;
940 unsigned int vfe_fence, cs_fence;
942 vfe_fence = pp_context->urb.cs_start;
943 cs_fence = pp_context->urb.size;
945 BEGIN_BATCH(batch, 3);
946 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
949 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
950 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
951 ADVANCE_BATCH(batch);
955 ironlake_pp_state_base_address(VADriverContextP ctx,
956 struct i965_post_processing_context *pp_context)
958 struct intel_batchbuffer *batch = pp_context->batch;
960 BEGIN_BATCH(batch, 8);
961 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
962 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
963 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
964 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
965 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
966 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
967 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
968 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
969 ADVANCE_BATCH(batch);
973 ironlake_pp_state_pointers(VADriverContextP ctx,
974 struct i965_post_processing_context *pp_context)
976 struct intel_batchbuffer *batch = pp_context->batch;
978 BEGIN_BATCH(batch, 3);
979 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
981 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
982 ADVANCE_BATCH(batch);
986 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
987 struct i965_post_processing_context *pp_context)
989 struct intel_batchbuffer *batch = pp_context->batch;
991 BEGIN_BATCH(batch, 2);
992 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
994 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
995 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
996 ADVANCE_BATCH(batch);
1000 ironlake_pp_constant_buffer(VADriverContextP ctx,
1001 struct i965_post_processing_context *pp_context)
1003 struct intel_batchbuffer *batch = pp_context->batch;
1005 BEGIN_BATCH(batch, 2);
1006 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
1007 OUT_RELOC(batch, pp_context->curbe.bo,
1008 I915_GEM_DOMAIN_INSTRUCTION, 0,
1009 pp_context->urb.size_cs_entry - 1);
1010 ADVANCE_BATCH(batch);
1014 ironlake_pp_object_walker(VADriverContextP ctx,
1015 struct i965_post_processing_context *pp_context)
1017 struct intel_batchbuffer *batch = pp_context->batch;
1018 int x, x_steps, y, y_steps;
1019 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1021 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
1022 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
1024 for (y = 0; y < y_steps; y++) {
1025 for (x = 0; x < x_steps; x++) {
1026 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
1027 BEGIN_BATCH(batch, 20);
1028 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
1029 OUT_BATCH(batch, 0);
1030 OUT_BATCH(batch, 0); /* no indirect data */
1031 OUT_BATCH(batch, 0);
1033 /* inline data grf 5-6 */
1034 assert(sizeof(*pp_inline_parameter) == 64);
1035 intel_batchbuffer_data(batch, pp_inline_parameter, sizeof(*pp_inline_parameter));
1037 ADVANCE_BATCH(batch);
1044 ironlake_pp_pipeline_setup(VADriverContextP ctx,
1045 struct i965_post_processing_context *pp_context)
1047 struct intel_batchbuffer *batch = pp_context->batch;
1049 intel_batchbuffer_start_atomic(batch, 0x1000);
1050 intel_batchbuffer_emit_mi_flush(batch);
1051 ironlake_pp_pipeline_select(ctx, pp_context);
1052 ironlake_pp_state_base_address(ctx, pp_context);
1053 ironlake_pp_state_pointers(ctx, pp_context);
1054 ironlake_pp_urb_layout(ctx, pp_context);
1055 ironlake_pp_cs_urb_layout(ctx, pp_context);
1056 ironlake_pp_constant_buffer(ctx, pp_context);
1057 ironlake_pp_object_walker(ctx, pp_context);
1058 intel_batchbuffer_end_atomic(batch);
1061 // update u/v offset when the surface format are packed yuv
1062 static void i965_update_src_surface_uv_offset(
1063 VADriverContextP ctx,
1064 struct i965_post_processing_context *pp_context,
1065 const struct i965_surface *surface)
1067 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1068 int fourcc = pp_get_surface_fourcc(ctx, surface);
1070 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
1071 pp_static_parameter->grf1.source_packed_u_offset = 1;
1072 pp_static_parameter->grf1.source_packed_v_offset = 3;
1074 else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
1075 pp_static_parameter->grf1.source_packed_y_offset = 1;
1076 pp_static_parameter->grf1.source_packed_v_offset = 2;
1081 static void i965_update_dst_surface_uv_offset(
1082 VADriverContextP ctx,
1083 struct i965_post_processing_context *pp_context,
1084 const struct i965_surface *surface)
1086 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1087 int fourcc = pp_get_surface_fourcc(ctx, surface);
1089 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
1090 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_u_offset = 1;
1091 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 3;
1093 else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
1094 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_y_offset = 1;
1095 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 2;
1101 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1102 dri_bo *surf_bo, unsigned long surf_bo_offset,
1103 int width, int height, int pitch, int format,
1104 int index, int is_target)
1106 struct i965_surface_state *ss;
1108 unsigned int tiling;
1109 unsigned int swizzle;
1111 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1112 ss_bo = pp_context->surface_state_binding_table.bo;
1115 dri_bo_map(ss_bo, True);
1116 assert(ss_bo->virtual);
1117 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1118 memset(ss, 0, sizeof(*ss));
1119 ss->ss0.surface_type = I965_SURFACE_2D;
1120 ss->ss0.surface_format = format;
1121 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1122 ss->ss2.width = width - 1;
1123 ss->ss2.height = height - 1;
1124 ss->ss3.pitch = pitch - 1;
1125 pp_set_surface_tiling(ss, tiling);
1126 dri_bo_emit_reloc(ss_bo,
1127 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1129 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
1131 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1132 dri_bo_unmap(ss_bo);
1136 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1137 dri_bo *surf_bo, unsigned long surf_bo_offset,
1138 int width, int height, int wpitch,
1139 int xoffset, int yoffset,
1140 int format, int interleave_chroma,
1143 struct i965_surface_state2 *ss2;
1145 unsigned int tiling;
1146 unsigned int swizzle;
1148 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1149 ss2_bo = pp_context->surface_state_binding_table.bo;
1152 dri_bo_map(ss2_bo, True);
1153 assert(ss2_bo->virtual);
1154 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1155 memset(ss2, 0, sizeof(*ss2));
1156 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1157 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1158 ss2->ss1.width = width - 1;
1159 ss2->ss1.height = height - 1;
1160 ss2->ss2.pitch = wpitch - 1;
1161 ss2->ss2.interleave_chroma = interleave_chroma;
1162 ss2->ss2.surface_format = format;
1163 ss2->ss3.x_offset_for_cb = xoffset;
1164 ss2->ss3.y_offset_for_cb = yoffset;
1165 pp_set_surface2_tiling(ss2, tiling);
1166 dri_bo_emit_reloc(ss2_bo,
1167 I915_GEM_DOMAIN_RENDER, 0,
1169 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
1171 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1172 dri_bo_unmap(ss2_bo);
1176 gen7_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1177 dri_bo *surf_bo, unsigned long surf_bo_offset,
1178 int width, int height, int pitch, int format,
1179 int index, int is_target)
1181 struct gen7_surface_state *ss;
1183 unsigned int tiling;
1184 unsigned int swizzle;
1186 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1187 ss_bo = pp_context->surface_state_binding_table.bo;
1190 dri_bo_map(ss_bo, True);
1191 assert(ss_bo->virtual);
1192 ss = (struct gen7_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1193 memset(ss, 0, sizeof(*ss));
1194 ss->ss0.surface_type = I965_SURFACE_2D;
1195 ss->ss0.surface_format = format;
1196 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1197 ss->ss2.width = width - 1;
1198 ss->ss2.height = height - 1;
1199 ss->ss3.pitch = pitch - 1;
1200 gen7_pp_set_surface_tiling(ss, tiling);
1201 dri_bo_emit_reloc(ss_bo,
1202 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1204 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state, ss1),
1206 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1207 dri_bo_unmap(ss_bo);
1211 gen7_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1212 dri_bo *surf_bo, unsigned long surf_bo_offset,
1213 int width, int height, int wpitch,
1214 int xoffset, int yoffset,
1215 int format, int interleave_chroma,
1218 struct gen7_surface_state2 *ss2;
1220 unsigned int tiling;
1221 unsigned int swizzle;
1223 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1224 ss2_bo = pp_context->surface_state_binding_table.bo;
1227 dri_bo_map(ss2_bo, True);
1228 assert(ss2_bo->virtual);
1229 ss2 = (struct gen7_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1230 memset(ss2, 0, sizeof(*ss2));
1231 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1232 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1233 ss2->ss1.width = width - 1;
1234 ss2->ss1.height = height - 1;
1235 ss2->ss2.pitch = wpitch - 1;
1236 ss2->ss2.interleave_chroma = interleave_chroma;
1237 ss2->ss2.surface_format = format;
1238 ss2->ss3.x_offset_for_cb = xoffset;
1239 ss2->ss3.y_offset_for_cb = yoffset;
1240 gen7_pp_set_surface2_tiling(ss2, tiling);
1241 dri_bo_emit_reloc(ss2_bo,
1242 I915_GEM_DOMAIN_RENDER, 0,
1244 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state2, ss0),
1246 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1247 dri_bo_unmap(ss2_bo);
1251 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1252 const struct i965_surface *surface,
1253 int base_index, int is_target,
1254 int *width, int *height, int *pitch, int *offset)
1256 struct i965_driver_data *i965 = i965_driver_data(ctx);
1257 struct object_surface *obj_surface;
1258 struct object_image *obj_image;
1260 int fourcc = pp_get_surface_fourcc(ctx, surface);
1262 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
1263 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
1265 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1266 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
1267 int full_packed_format = (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
1268 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
1269 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
1270 fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
1271 int scale_factor_of_1st_plane_width_in_byte = 1;
1273 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1274 obj_surface = SURFACE(surface->id);
1275 bo = obj_surface->bo;
1276 width[0] = obj_surface->orig_width;
1277 height[0] = obj_surface->orig_height;
1278 pitch[0] = obj_surface->width;
1281 if (full_packed_format) {
1282 scale_factor_of_1st_plane_width_in_byte = 4;
1283 pitch[0] = obj_surface->width * 4;
1285 else if (packed_yuv ) {
1286 scale_factor_of_1st_plane_width_in_byte = 2;
1287 pitch[0] = obj_surface->width * 2;
1289 else if (interleaved_uv) {
1290 width[1] = obj_surface->orig_width;
1291 height[1] = obj_surface->orig_height / 2;
1292 pitch[1] = obj_surface->width;
1293 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1295 width[1] = obj_surface->orig_width / 2;
1296 height[1] = obj_surface->orig_height / 2;
1297 pitch[1] = obj_surface->width / 2;
1298 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1299 width[2] = obj_surface->orig_width / 2;
1300 height[2] = obj_surface->orig_height / 2;
1301 pitch[2] = obj_surface->width / 2;
1302 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
1305 obj_image = IMAGE(surface->id);
1307 width[0] = obj_image->image.width;
1308 height[0] = obj_image->image.height;
1309 pitch[0] = obj_image->image.pitches[0];
1310 offset[0] = obj_image->image.offsets[0];
1312 if (full_packed_format) {
1313 scale_factor_of_1st_plane_width_in_byte = 4;
1315 else if (packed_yuv ) {
1316 scale_factor_of_1st_plane_width_in_byte = 2;
1318 else if (interleaved_uv) {
1319 width[1] = obj_image->image.width;
1320 height[1] = obj_image->image.height / 2;
1321 pitch[1] = obj_image->image.pitches[1];
1322 offset[1] = obj_image->image.offsets[1];
1324 width[1] = obj_image->image.width / 2;
1325 height[1] = obj_image->image.height / 2;
1326 pitch[1] = obj_image->image.pitches[1];
1327 offset[1] = obj_image->image.offsets[1];
1328 width[2] = obj_image->image.width / 2;
1329 height[2] = obj_image->image.height / 2;
1330 pitch[2] = obj_image->image.pitches[2];
1331 offset[2] = obj_image->image.offsets[2];
1336 i965_pp_set_surface_state(ctx, pp_context,
1338 width[Y] *scale_factor_of_1st_plane_width_in_byte / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
1339 base_index, is_target);
1341 if (!packed_yuv && !full_packed_format) {
1342 if (interleaved_uv) {
1343 i965_pp_set_surface_state(ctx, pp_context,
1345 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
1346 base_index + 1, is_target);
1349 i965_pp_set_surface_state(ctx, pp_context,
1351 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
1352 base_index + 1, is_target);
1355 i965_pp_set_surface_state(ctx, pp_context,
1357 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
1358 base_index + 2, is_target);
1365 gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1366 const struct i965_surface *surface,
1367 int base_index, int is_target,
1368 int *width, int *height, int *pitch, int *offset)
1370 struct i965_driver_data *i965 = i965_driver_data(ctx);
1371 struct object_surface *obj_surface;
1372 struct object_image *obj_image;
1374 int fourcc = pp_get_surface_fourcc(ctx, surface);
1375 const int U = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
1376 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 2 : 1;
1377 const int V = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
1378 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 1 : 2;
1379 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1380 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
1382 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1383 obj_surface = SURFACE(surface->id);
1384 bo = obj_surface->bo;
1385 width[0] = obj_surface->orig_width;
1386 height[0] = obj_surface->orig_height;
1387 pitch[0] = obj_surface->width;
1392 width[0] = obj_surface->orig_width * 2; /* surface format is R8, so double the width */
1394 width[0] = obj_surface->orig_width; /* surface foramt is YCBCR, width is specified in units of pixels */
1396 pitch[0] = obj_surface->width * 2;
1399 width[1] = obj_surface->cb_cr_width;
1400 height[1] = obj_surface->cb_cr_height;
1401 pitch[1] = obj_surface->cb_cr_pitch;
1402 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
1404 width[2] = obj_surface->cb_cr_width;
1405 height[2] = obj_surface->cb_cr_height;
1406 pitch[2] = obj_surface->cb_cr_pitch;
1407 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
1409 obj_image = IMAGE(surface->id);
1411 width[0] = obj_image->image.width;
1412 height[0] = obj_image->image.height;
1413 pitch[0] = obj_image->image.pitches[0];
1414 offset[0] = obj_image->image.offsets[0];
1418 width[0] = obj_image->image.width * 2; /* surface format is R8, so double the width */
1420 width[0] = obj_image->image.width; /* surface foramt is YCBCR, width is specified in units of pixels */
1421 } else if (interleaved_uv) {
1422 width[1] = obj_image->image.width / 2;
1423 height[1] = obj_image->image.height / 2;
1424 pitch[1] = obj_image->image.pitches[1];
1425 offset[1] = obj_image->image.offsets[1];
1427 width[1] = obj_image->image.width / 2;
1428 height[1] = obj_image->image.height / 2;
1429 pitch[1] = obj_image->image.pitches[U];
1430 offset[1] = obj_image->image.offsets[U];
1431 width[2] = obj_image->image.width / 2;
1432 height[2] = obj_image->image.height / 2;
1433 pitch[2] = obj_image->image.pitches[V];
1434 offset[2] = obj_image->image.offsets[V];
1439 gen7_pp_set_surface_state(ctx, pp_context,
1441 width[0] / 4, height[0], pitch[0],
1442 I965_SURFACEFORMAT_R8_SINT,
1446 if (interleaved_uv) {
1447 gen7_pp_set_surface_state(ctx, pp_context,
1449 width[1] / 2, height[1], pitch[1],
1450 I965_SURFACEFORMAT_R8G8_SINT,
1453 gen7_pp_set_surface_state(ctx, pp_context,
1455 width[1] / 4, height[1], pitch[1],
1456 I965_SURFACEFORMAT_R8_SINT,
1458 gen7_pp_set_surface_state(ctx, pp_context,
1460 width[2] / 4, height[2], pitch[2],
1461 I965_SURFACEFORMAT_R8_SINT,
1466 int format0 = SURFACE_FORMAT_Y8_UNORM;
1469 case VA_FOURCC('Y', 'U', 'Y', '2'):
1470 format0 = SURFACE_FORMAT_YCRCB_NORMAL;
1473 case VA_FOURCC('U', 'Y', 'V', 'Y'):
1474 format0 = SURFACE_FORMAT_YCRCB_SWAPY;
1481 gen7_pp_set_surface2_state(ctx, pp_context,
1483 width[0], height[0], pitch[0],
1489 if (interleaved_uv) {
1490 gen7_pp_set_surface2_state(ctx, pp_context,
1492 width[1], height[1], pitch[1],
1494 SURFACE_FORMAT_R8B8_UNORM, 0,
1497 gen7_pp_set_surface2_state(ctx, pp_context,
1499 width[1], height[1], pitch[1],
1501 SURFACE_FORMAT_R8_UNORM, 0,
1503 gen7_pp_set_surface2_state(ctx, pp_context,
1505 width[2], height[2], pitch[2],
1507 SURFACE_FORMAT_R8_UNORM, 0,
1515 pp_null_x_steps(void *private_context)
1521 pp_null_y_steps(void *private_context)
1527 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1533 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1534 const struct i965_surface *src_surface,
1535 const VARectangle *src_rect,
1536 struct i965_surface *dst_surface,
1537 const VARectangle *dst_rect,
1540 /* private function & data */
1541 pp_context->pp_x_steps = pp_null_x_steps;
1542 pp_context->pp_y_steps = pp_null_y_steps;
1543 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
1545 dst_surface->flags = src_surface->flags;
1547 return VA_STATUS_SUCCESS;
1551 pp_load_save_x_steps(void *private_context)
1557 pp_load_save_y_steps(void *private_context)
1559 struct pp_load_save_context *pp_load_save_context = private_context;
1561 return pp_load_save_context->dest_h / 8;
1565 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1567 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1569 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1570 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1571 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
1572 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
1578 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1579 const struct i965_surface *src_surface,
1580 const VARectangle *src_rect,
1581 struct i965_surface *dst_surface,
1582 const VARectangle *dst_rect,
1585 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->private_context;
1586 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1587 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1588 int width[3], height[3], pitch[3], offset[3];
1591 /* source surface */
1592 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
1593 width, height, pitch, offset);
1595 /* destination surface */
1596 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
1597 width, height, pitch, offset);
1599 /* private function & data */
1600 pp_context->pp_x_steps = pp_load_save_x_steps;
1601 pp_context->pp_y_steps = pp_load_save_y_steps;
1602 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
1603 pp_load_save_context->dest_h = ALIGN(height[Y], 16);
1604 pp_load_save_context->dest_w = ALIGN(width[Y], 16);
1606 pp_inline_parameter->grf5.block_count_x = ALIGN(width[Y], 16) / 16; /* 1 x N */
1607 pp_inline_parameter->grf5.number_blocks = ALIGN(width[Y], 16) / 16;
1609 pp_static_parameter->grf3.horizontal_origin_offset = src_rect->x;
1610 pp_static_parameter->grf3.vertical_origin_offset = src_rect->y;
1612 // update u/v offset for packed yuv
1613 i965_update_src_surface_uv_offset (ctx, pp_context, src_surface);
1614 i965_update_dst_surface_uv_offset (ctx, pp_context, dst_surface);
1616 dst_surface->flags = src_surface->flags;
1618 return VA_STATUS_SUCCESS;
1622 pp_scaling_x_steps(void *private_context)
1628 pp_scaling_y_steps(void *private_context)
1630 struct pp_scaling_context *pp_scaling_context = private_context;
1632 return pp_scaling_context->dest_h / 8;
1636 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1638 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1639 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1640 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1641 float src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1642 float src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1644 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
1645 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
1646 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
1647 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
1653 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1654 const struct i965_surface *src_surface,
1655 const VARectangle *src_rect,
1656 struct i965_surface *dst_surface,
1657 const VARectangle *dst_rect,
1660 struct i965_driver_data *i965 = i965_driver_data(ctx);
1661 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1662 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1663 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1664 struct object_surface *obj_surface;
1665 struct i965_sampler_state *sampler_state;
1666 int in_w, in_h, in_wpitch, in_hpitch;
1667 int out_w, out_h, out_wpitch, out_hpitch;
1669 /* source surface */
1670 obj_surface = SURFACE(src_surface->id);
1671 in_w = obj_surface->orig_width;
1672 in_h = obj_surface->orig_height;
1673 in_wpitch = obj_surface->width;
1674 in_hpitch = obj_surface->height;
1676 /* source Y surface index 1 */
1677 i965_pp_set_surface_state(ctx, pp_context,
1679 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1682 /* source UV surface index 2 */
1683 i965_pp_set_surface_state(ctx, pp_context,
1684 obj_surface->bo, in_wpitch * in_hpitch,
1685 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1688 /* destination surface */
1689 obj_surface = SURFACE(dst_surface->id);
1690 out_w = obj_surface->orig_width;
1691 out_h = obj_surface->orig_height;
1692 out_wpitch = obj_surface->width;
1693 out_hpitch = obj_surface->height;
1695 /* destination Y surface index 7 */
1696 i965_pp_set_surface_state(ctx, pp_context,
1698 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1701 /* destination UV surface index 8 */
1702 i965_pp_set_surface_state(ctx, pp_context,
1703 obj_surface->bo, out_wpitch * out_hpitch,
1704 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1708 dri_bo_map(pp_context->sampler_state_table.bo, True);
1709 assert(pp_context->sampler_state_table.bo->virtual);
1710 sampler_state = pp_context->sampler_state_table.bo->virtual;
1712 /* SIMD16 Y index 1 */
1713 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
1714 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1715 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1716 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1717 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1719 /* SIMD16 UV index 2 */
1720 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
1721 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1722 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1723 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1724 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1726 dri_bo_unmap(pp_context->sampler_state_table.bo);
1728 /* private function & data */
1729 pp_context->pp_x_steps = pp_scaling_x_steps;
1730 pp_context->pp_y_steps = pp_scaling_y_steps;
1731 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
1733 pp_scaling_context->dest_x = dst_rect->x;
1734 pp_scaling_context->dest_y = dst_rect->y;
1735 pp_scaling_context->dest_w = ALIGN(dst_rect->width, 16);
1736 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 16);
1737 pp_scaling_context->src_normalized_x = (float)src_rect->x / in_w;
1738 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h;
1740 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
1742 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
1743 pp_inline_parameter->grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
1744 pp_inline_parameter->grf5.number_blocks = pp_scaling_context->dest_w / 16;
1745 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1746 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1748 dst_surface->flags = src_surface->flags;
1750 return VA_STATUS_SUCCESS;
1754 pp_avs_x_steps(void *private_context)
1756 struct pp_avs_context *pp_avs_context = private_context;
1758 return pp_avs_context->dest_w / 16;
1762 pp_avs_y_steps(void *private_context)
1768 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1770 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1771 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1772 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1773 float src_x_steping, src_y_steping, video_step_delta;
1774 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
1776 if (pp_static_parameter->grf4.r4_2.avs.nlas == 0) {
1777 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1778 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_avs_context->src_normalized_x;
1779 } else if (tmp_w >= pp_avs_context->dest_w) {
1780 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1781 pp_inline_parameter->grf6.video_step_delta = 0;
1784 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
1785 pp_avs_context->src_normalized_x;
1787 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1788 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1789 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1790 16 * 15 * video_step_delta / 2;
1793 int n0, n1, n2, nls_left, nls_right;
1794 int factor_a = 5, factor_b = 4;
1797 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
1798 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
1799 n2 = tmp_w / (16 * factor_a);
1801 nls_right = n1 + n2;
1802 f = (float) n2 * 16 / tmp_w;
1805 pp_inline_parameter->grf6.video_step_delta = 0.0;
1808 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
1809 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1811 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1812 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1813 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1814 16 * 15 * video_step_delta / 2;
1818 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
1819 float a = f / (nls_left * 16 * factor_b);
1820 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
1822 pp_inline_parameter->grf6.video_step_delta = b;
1825 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1826 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a;
1828 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1829 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1830 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1831 16 * 15 * video_step_delta / 2;
1832 pp_inline_parameter->grf5.normalized_video_x_scaling_step += 16 * b;
1834 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
1835 /* scale the center linearly */
1836 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1837 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1838 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1839 16 * 15 * video_step_delta / 2;
1840 pp_inline_parameter->grf6.video_step_delta = 0.0;
1841 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1843 float a = f / (nls_right * 16 * factor_b);
1844 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
1846 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1847 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1848 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1849 16 * 15 * video_step_delta / 2;
1850 pp_inline_parameter->grf6.video_step_delta = -b;
1852 if (x == (pp_avs_context->dest_w / 16 - nls_right))
1853 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
1855 pp_inline_parameter->grf5.normalized_video_x_scaling_step -= b * 16;
1860 src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1861 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
1862 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1863 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
1869 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1870 const struct i965_surface *src_surface,
1871 const VARectangle *src_rect,
1872 struct i965_surface *dst_surface,
1873 const VARectangle *dst_rect,
1877 struct i965_driver_data *i965 = i965_driver_data(ctx);
1878 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1879 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1880 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1881 struct object_surface *obj_surface;
1882 struct i965_sampler_8x8 *sampler_8x8;
1883 struct i965_sampler_8x8_state *sampler_8x8_state;
1885 int in_w, in_h, in_wpitch, in_hpitch;
1886 int out_w, out_h, out_wpitch, out_hpitch;
1890 obj_surface = SURFACE(src_surface->id);
1891 in_w = obj_surface->orig_width;
1892 in_h = obj_surface->orig_height;
1893 in_wpitch = obj_surface->width;
1894 in_hpitch = obj_surface->height;
1896 /* source Y surface index 1 */
1897 i965_pp_set_surface2_state(ctx, pp_context,
1899 in_w, in_h, in_wpitch,
1901 SURFACE_FORMAT_Y8_UNORM, 0,
1904 /* source UV surface index 2 */
1905 i965_pp_set_surface2_state(ctx, pp_context,
1906 obj_surface->bo, in_wpitch * in_hpitch,
1907 in_w / 2, in_h / 2, in_wpitch,
1909 SURFACE_FORMAT_R8B8_UNORM, 0,
1912 /* destination surface */
1913 obj_surface = SURFACE(dst_surface->id);
1914 out_w = obj_surface->orig_width;
1915 out_h = obj_surface->orig_height;
1916 out_wpitch = obj_surface->width;
1917 out_hpitch = obj_surface->height;
1918 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1920 /* destination Y surface index 7 */
1921 i965_pp_set_surface_state(ctx, pp_context,
1923 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1926 /* destination UV surface index 8 */
1927 i965_pp_set_surface_state(ctx, pp_context,
1928 obj_surface->bo, out_wpitch * out_hpitch,
1929 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1932 /* sampler 8x8 state */
1933 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1934 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1935 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1936 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1937 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1939 for (i = 0; i < 17; i++) {
1940 /* for Y channel, currently ignore */
1941 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x00;
1942 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x00;
1943 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x08;
1944 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x18;
1945 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x18;
1946 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x08;
1947 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x00;
1948 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x00;
1949 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x00;
1950 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x00;
1951 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x10;
1952 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x10;
1953 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x10;
1954 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x10;
1955 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x00;
1956 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x00;
1957 /* for U/V channel, 0.25 */
1958 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
1959 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
1960 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
1961 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
1962 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
1963 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
1964 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
1965 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
1966 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
1967 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
1968 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
1969 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
1970 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
1971 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
1972 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
1973 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
1976 sampler_8x8_state->dw136.default_sharpness_level = 0;
1977 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
1978 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1979 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1980 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
1983 dri_bo_map(pp_context->sampler_state_table.bo, True);
1984 assert(pp_context->sampler_state_table.bo->virtual);
1985 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
1986 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
1988 /* sample_8x8 Y index 1 */
1990 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1991 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1992 sampler_8x8[index].dw0.ief_bypass = 1;
1993 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1994 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1995 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1996 sampler_8x8[index].dw2.global_noise_estimation = 22;
1997 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1998 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1999 sampler_8x8[index].dw3.strong_edge_weight = 7;
2000 sampler_8x8[index].dw3.regular_weight = 2;
2001 sampler_8x8[index].dw3.non_edge_weight = 0;
2002 sampler_8x8[index].dw3.gain_factor = 40;
2003 sampler_8x8[index].dw4.steepness_boost = 0;
2004 sampler_8x8[index].dw4.steepness_threshold = 0;
2005 sampler_8x8[index].dw4.mr_boost = 0;
2006 sampler_8x8[index].dw4.mr_threshold = 5;
2007 sampler_8x8[index].dw5.pwl1_point_1 = 4;
2008 sampler_8x8[index].dw5.pwl1_point_2 = 12;
2009 sampler_8x8[index].dw5.pwl1_point_3 = 16;
2010 sampler_8x8[index].dw5.pwl1_point_4 = 26;
2011 sampler_8x8[index].dw6.pwl1_point_5 = 40;
2012 sampler_8x8[index].dw6.pwl1_point_6 = 160;
2013 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
2014 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
2015 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
2016 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
2017 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
2018 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
2019 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
2020 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
2021 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
2022 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
2023 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
2024 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
2025 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
2026 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
2027 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
2028 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
2029 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
2030 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
2031 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
2032 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
2033 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
2034 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
2035 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
2036 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
2037 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
2038 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
2039 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
2040 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
2041 sampler_8x8[index].dw13.limiter_boost = 0;
2042 sampler_8x8[index].dw13.minimum_limiter = 10;
2043 sampler_8x8[index].dw13.maximum_limiter = 11;
2044 sampler_8x8[index].dw14.clip_limiter = 130;
2045 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2046 I915_GEM_DOMAIN_RENDER,
2049 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2050 pp_context->sampler_state_table.bo_8x8);
2052 /* sample_8x8 UV index 2 */
2054 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2055 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
2056 sampler_8x8[index].dw0.ief_bypass = 1;
2057 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
2058 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
2059 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2060 sampler_8x8[index].dw2.global_noise_estimation = 22;
2061 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2062 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2063 sampler_8x8[index].dw3.strong_edge_weight = 7;
2064 sampler_8x8[index].dw3.regular_weight = 2;
2065 sampler_8x8[index].dw3.non_edge_weight = 0;
2066 sampler_8x8[index].dw3.gain_factor = 40;
2067 sampler_8x8[index].dw4.steepness_boost = 0;
2068 sampler_8x8[index].dw4.steepness_threshold = 0;
2069 sampler_8x8[index].dw4.mr_boost = 0;
2070 sampler_8x8[index].dw4.mr_threshold = 5;
2071 sampler_8x8[index].dw5.pwl1_point_1 = 4;
2072 sampler_8x8[index].dw5.pwl1_point_2 = 12;
2073 sampler_8x8[index].dw5.pwl1_point_3 = 16;
2074 sampler_8x8[index].dw5.pwl1_point_4 = 26;
2075 sampler_8x8[index].dw6.pwl1_point_5 = 40;
2076 sampler_8x8[index].dw6.pwl1_point_6 = 160;
2077 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
2078 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
2079 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
2080 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
2081 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
2082 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
2083 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
2084 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
2085 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
2086 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
2087 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
2088 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
2089 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
2090 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
2091 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
2092 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
2093 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
2094 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
2095 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
2096 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
2097 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
2098 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
2099 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
2100 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
2101 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
2102 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
2103 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
2104 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
2105 sampler_8x8[index].dw13.limiter_boost = 0;
2106 sampler_8x8[index].dw13.minimum_limiter = 10;
2107 sampler_8x8[index].dw13.maximum_limiter = 11;
2108 sampler_8x8[index].dw14.clip_limiter = 130;
2109 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2110 I915_GEM_DOMAIN_RENDER,
2113 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2114 pp_context->sampler_state_table.bo_8x8);
2116 dri_bo_unmap(pp_context->sampler_state_table.bo);
2118 /* private function & data */
2119 pp_context->pp_x_steps = pp_avs_x_steps;
2120 pp_context->pp_y_steps = pp_avs_y_steps;
2121 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
2123 pp_avs_context->dest_x = dst_rect->x;
2124 pp_avs_context->dest_y = dst_rect->y;
2125 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
2126 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
2127 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w;
2128 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h;
2129 pp_avs_context->src_w = src_rect->width;
2130 pp_avs_context->src_h = src_rect->height;
2132 pp_static_parameter->grf4.r4_2.avs.nlas = nlas;
2133 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
2135 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
2136 pp_inline_parameter->grf5.block_count_x = 1; /* M x 1 */
2137 pp_inline_parameter->grf5.number_blocks = pp_avs_context->dest_h / 8;
2138 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2139 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2140 pp_inline_parameter->grf6.video_step_delta = 0.0;
2142 dst_surface->flags = src_surface->flags;
2144 return VA_STATUS_SUCCESS;
2148 pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2149 const struct i965_surface *src_surface,
2150 const VARectangle *src_rect,
2151 struct i965_surface *dst_surface,
2152 const VARectangle *dst_rect,
2155 return pp_nv12_avs_initialize(ctx, pp_context,
2165 gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2166 const struct i965_surface *src_surface,
2167 const VARectangle *src_rect,
2168 struct i965_surface *dst_surface,
2169 const VARectangle *dst_rect,
2172 return pp_nv12_avs_initialize(ctx, pp_context,
2182 gen7_pp_avs_x_steps(void *private_context)
2184 struct pp_avs_context *pp_avs_context = private_context;
2186 return pp_avs_context->dest_w / 16;
2190 gen7_pp_avs_y_steps(void *private_context)
2192 struct pp_avs_context *pp_avs_context = private_context;
2194 return pp_avs_context->dest_h / 16;
2198 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2200 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
2201 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2203 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
2204 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
2205 pp_inline_parameter->grf7.constant_0 = 0xffffffff;
2206 pp_inline_parameter->grf7.sampler_load_main_video_x_scaling_step = 1.0 / pp_avs_context->src_w;
2211 static void gen7_update_src_surface_uv_offset(VADriverContextP ctx,
2212 struct i965_post_processing_context *pp_context,
2213 const struct i965_surface *surface)
2215 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2216 int fourcc = pp_get_surface_fourcc(ctx, surface);
2218 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
2219 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2220 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2221 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2222 } else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
2223 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 1;
2224 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 0;
2225 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 2;
2230 gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2231 const struct i965_surface *src_surface,
2232 const VARectangle *src_rect,
2233 struct i965_surface *dst_surface,
2234 const VARectangle *dst_rect,
2237 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
2238 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2239 struct gen7_sampler_8x8 *sampler_8x8;
2240 struct i965_sampler_8x8_state *sampler_8x8_state;
2242 int width[3], height[3], pitch[3], offset[3];
2244 /* source surface */
2245 gen7_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
2246 width, height, pitch, offset);
2248 /* destination surface */
2249 gen7_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
2250 width, height, pitch, offset);
2252 /* sampler 8x8 state */
2253 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
2254 assert(pp_context->sampler_state_table.bo_8x8->virtual);
2255 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
2256 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
2257 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
2259 for (i = 0; i < 17; i++) {
2260 /* for Y channel, currently ignore */
2261 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
2262 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
2263 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
2264 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x0;
2265 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x0;
2266 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
2267 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
2268 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
2269 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
2270 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
2271 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
2272 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x0;
2273 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x0;
2274 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
2275 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
2276 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
2277 /* for U/V channel, 0.25 */
2278 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
2279 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
2280 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
2281 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
2282 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
2283 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
2284 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
2285 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
2286 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
2287 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
2288 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
2289 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
2290 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
2291 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
2292 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
2293 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
2296 sampler_8x8_state->dw136.default_sharpness_level = 0;
2297 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
2298 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
2299 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
2300 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
2303 dri_bo_map(pp_context->sampler_state_table.bo, True);
2304 assert(pp_context->sampler_state_table.bo->virtual);
2305 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
2306 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
2308 /* sample_8x8 Y index 4 */
2310 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2311 sampler_8x8[index].dw0.global_noise_estimation = 255;
2312 sampler_8x8[index].dw0.ief_bypass = 1;
2314 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2316 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2317 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2318 sampler_8x8[index].dw2.r5x_coefficient = 9;
2319 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2320 sampler_8x8[index].dw2.r5c_coefficient = 3;
2322 sampler_8x8[index].dw3.r3x_coefficient = 27;
2323 sampler_8x8[index].dw3.r3c_coefficient = 5;
2324 sampler_8x8[index].dw3.gain_factor = 40;
2325 sampler_8x8[index].dw3.non_edge_weight = 1;
2326 sampler_8x8[index].dw3.regular_weight = 2;
2327 sampler_8x8[index].dw3.strong_edge_weight = 7;
2328 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2330 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2331 I915_GEM_DOMAIN_RENDER,
2334 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2335 pp_context->sampler_state_table.bo_8x8);
2337 /* sample_8x8 UV index 8 */
2339 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2340 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2341 sampler_8x8[index].dw0.global_noise_estimation = 255;
2342 sampler_8x8[index].dw0.ief_bypass = 1;
2343 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2344 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2345 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2346 sampler_8x8[index].dw2.r5x_coefficient = 9;
2347 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2348 sampler_8x8[index].dw2.r5c_coefficient = 3;
2349 sampler_8x8[index].dw3.r3x_coefficient = 27;
2350 sampler_8x8[index].dw3.r3c_coefficient = 5;
2351 sampler_8x8[index].dw3.gain_factor = 40;
2352 sampler_8x8[index].dw3.non_edge_weight = 1;
2353 sampler_8x8[index].dw3.regular_weight = 2;
2354 sampler_8x8[index].dw3.strong_edge_weight = 7;
2355 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2357 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2358 I915_GEM_DOMAIN_RENDER,
2361 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2362 pp_context->sampler_state_table.bo_8x8);
2364 /* sampler_8x8 V, index 12 */
2366 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2367 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2368 sampler_8x8[index].dw0.global_noise_estimation = 255;
2369 sampler_8x8[index].dw0.ief_bypass = 1;
2370 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2371 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2372 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2373 sampler_8x8[index].dw2.r5x_coefficient = 9;
2374 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2375 sampler_8x8[index].dw2.r5c_coefficient = 3;
2376 sampler_8x8[index].dw3.r3x_coefficient = 27;
2377 sampler_8x8[index].dw3.r3c_coefficient = 5;
2378 sampler_8x8[index].dw3.gain_factor = 40;
2379 sampler_8x8[index].dw3.non_edge_weight = 1;
2380 sampler_8x8[index].dw3.regular_weight = 2;
2381 sampler_8x8[index].dw3.strong_edge_weight = 7;
2382 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2384 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2385 I915_GEM_DOMAIN_RENDER,
2388 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2389 pp_context->sampler_state_table.bo_8x8);
2391 dri_bo_unmap(pp_context->sampler_state_table.bo);
2393 /* private function & data */
2394 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
2395 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
2396 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
2398 pp_avs_context->dest_x = dst_rect->x;
2399 pp_avs_context->dest_y = dst_rect->y;
2400 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
2401 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
2402 pp_avs_context->src_w = src_rect->width;
2403 pp_avs_context->src_h = src_rect->height;
2405 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
2406 dw = MAX(dw, pp_avs_context->dest_w);
2408 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2409 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
2410 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) 1.0 / pp_avs_context->dest_h;
2411 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = -(float)pp_avs_context->dest_y / pp_avs_context->dest_h;
2412 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = -(float)pp_avs_context->dest_x / dw;
2414 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
2416 dst_surface->flags = src_surface->flags;
2418 return VA_STATUS_SUCCESS;
2422 pp_dndi_x_steps(void *private_context)
2428 pp_dndi_y_steps(void *private_context)
2430 struct pp_dndi_context *pp_dndi_context = private_context;
2432 return pp_dndi_context->dest_h / 4;
2436 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2438 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2440 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2441 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
2447 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2448 const struct i965_surface *src_surface,
2449 const VARectangle *src_rect,
2450 struct i965_surface *dst_surface,
2451 const VARectangle *dst_rect,
2454 struct i965_driver_data *i965 = i965_driver_data(ctx);
2455 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2456 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2457 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2458 struct object_surface *obj_surface;
2459 struct i965_sampler_dndi *sampler_dndi;
2463 int dndi_top_first = 1;
2465 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2466 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2468 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2474 obj_surface = SURFACE(src_surface->id);
2475 orig_w = obj_surface->orig_width;
2476 orig_h = obj_surface->orig_height;
2477 w = obj_surface->width;
2478 h = obj_surface->height;
2480 if (pp_context->stmm.bo == NULL) {
2481 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2485 assert(pp_context->stmm.bo);
2488 /* source UV surface index 2 */
2489 i965_pp_set_surface_state(ctx, pp_context,
2490 obj_surface->bo, w * h,
2491 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2494 /* source YUV surface index 4 */
2495 i965_pp_set_surface2_state(ctx, pp_context,
2499 SURFACE_FORMAT_PLANAR_420_8, 1,
2502 /* source STMM surface index 20 */
2503 i965_pp_set_surface_state(ctx, pp_context,
2504 pp_context->stmm.bo, 0,
2505 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2508 /* destination surface */
2509 obj_surface = SURFACE(dst_surface->id);
2510 orig_w = obj_surface->orig_width;
2511 orig_h = obj_surface->orig_height;
2512 w = obj_surface->width;
2513 h = obj_surface->height;
2515 /* destination Y surface index 7 */
2516 i965_pp_set_surface_state(ctx, pp_context,
2518 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2521 /* destination UV surface index 8 */
2522 i965_pp_set_surface_state(ctx, pp_context,
2523 obj_surface->bo, w * h,
2524 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2527 dri_bo_map(pp_context->sampler_state_table.bo, True);
2528 assert(pp_context->sampler_state_table.bo->virtual);
2529 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2530 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2532 /* sample dndi index 1 */
2534 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2535 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2536 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2537 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2539 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2540 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 4;
2541 sampler_dndi[index].dw1.stmm_c2 = 1;
2542 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2543 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2545 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2546 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2547 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2548 sampler_dndi[index].dw2.good_neighbor_threshold = 4; // 0-63
2550 sampler_dndi[index].dw3.maximum_stmm = 128;
2551 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2552 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2553 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2554 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2556 sampler_dndi[index].dw4.sdi_delta = 8;
2557 sampler_dndi[index].dw4.sdi_threshold = 128;
2558 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2559 sampler_dndi[index].dw4.stmm_shift_up = 0;
2560 sampler_dndi[index].dw4.stmm_shift_down = 0;
2561 sampler_dndi[index].dw4.minimum_stmm = 0;
2563 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 8;
2564 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 32;
2565 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 64;
2566 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 32;
2568 sampler_dndi[index].dw6.dn_enable = 1;
2569 sampler_dndi[index].dw6.di_enable = 1;
2570 sampler_dndi[index].dw6.di_partial = 0;
2571 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2572 sampler_dndi[index].dw6.dndi_stream_id = 0;
2573 sampler_dndi[index].dw6.dndi_first_frame = 1;
2574 sampler_dndi[index].dw6.progressive_dn = 0;
2575 sampler_dndi[index].dw6.fmd_tear_threshold = 63;
2576 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2577 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2579 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
2580 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
2581 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2582 sampler_dndi[index].dw7.column_width_minus1 = 0;
2584 dri_bo_unmap(pp_context->sampler_state_table.bo);
2586 /* private function & data */
2587 pp_context->pp_x_steps = pp_dndi_x_steps;
2588 pp_context->pp_y_steps = pp_dndi_y_steps;
2589 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
2591 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2592 pp_static_parameter->grf1.r1_6.di.top_field_first = dndi_top_first;
2593 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 0;
2594 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 0;
2596 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2597 pp_inline_parameter->grf5.number_blocks = w / 16;
2598 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2599 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2601 pp_dndi_context->dest_w = w;
2602 pp_dndi_context->dest_h = h;
2604 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
2606 return VA_STATUS_SUCCESS;
2610 pp_dn_x_steps(void *private_context)
2616 pp_dn_y_steps(void *private_context)
2618 struct pp_dn_context *pp_dn_context = private_context;
2620 return pp_dn_context->dest_h / 8;
2624 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2626 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2628 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2629 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
2635 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2636 const struct i965_surface *src_surface,
2637 const VARectangle *src_rect,
2638 struct i965_surface *dst_surface,
2639 const VARectangle *dst_rect,
2642 struct i965_driver_data *i965 = i965_driver_data(ctx);
2643 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
2644 struct object_surface *obj_surface;
2645 struct i965_sampler_dndi *sampler_dndi;
2646 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2647 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2648 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
2652 int dn_strength = 15;
2653 int dndi_top_first = 1;
2654 int dn_progressive = 0;
2656 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
2659 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
2667 if (dn_filter_param) {
2668 float value = dn_filter_param->value;
2676 dn_strength = (int)(value * 31.0F);
2680 obj_surface = SURFACE(src_surface->id);
2681 orig_w = obj_surface->orig_width;
2682 orig_h = obj_surface->orig_height;
2683 w = obj_surface->width;
2684 h = obj_surface->height;
2686 if (pp_context->stmm.bo == NULL) {
2687 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2691 assert(pp_context->stmm.bo);
2694 /* source UV surface index 2 */
2695 i965_pp_set_surface_state(ctx, pp_context,
2696 obj_surface->bo, w * h,
2697 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2700 /* source YUV surface index 4 */
2701 i965_pp_set_surface2_state(ctx, pp_context,
2705 SURFACE_FORMAT_PLANAR_420_8, 1,
2708 /* source STMM surface index 20 */
2709 i965_pp_set_surface_state(ctx, pp_context,
2710 pp_context->stmm.bo, 0,
2711 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2714 /* destination surface */
2715 obj_surface = SURFACE(dst_surface->id);
2716 orig_w = obj_surface->orig_width;
2717 orig_h = obj_surface->orig_height;
2718 w = obj_surface->width;
2719 h = obj_surface->height;
2721 /* destination Y surface index 7 */
2722 i965_pp_set_surface_state(ctx, pp_context,
2724 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2727 /* destination UV surface index 8 */
2728 i965_pp_set_surface_state(ctx, pp_context,
2729 obj_surface->bo, w * h,
2730 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2733 dri_bo_map(pp_context->sampler_state_table.bo, True);
2734 assert(pp_context->sampler_state_table.bo->virtual);
2735 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2736 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2738 /* sample dndi index 1 */
2740 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2741 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2742 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2743 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2745 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2746 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2747 sampler_dndi[index].dw1.stmm_c2 = 0;
2748 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2749 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2751 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
2752 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2753 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2754 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
2756 sampler_dndi[index].dw3.maximum_stmm = 128;
2757 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2758 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2759 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2760 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2762 sampler_dndi[index].dw4.sdi_delta = 8;
2763 sampler_dndi[index].dw4.sdi_threshold = 128;
2764 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2765 sampler_dndi[index].dw4.stmm_shift_up = 0;
2766 sampler_dndi[index].dw4.stmm_shift_down = 0;
2767 sampler_dndi[index].dw4.minimum_stmm = 0;
2769 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2770 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2771 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2772 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2774 sampler_dndi[index].dw6.dn_enable = 1;
2775 sampler_dndi[index].dw6.di_enable = 0;
2776 sampler_dndi[index].dw6.di_partial = 0;
2777 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2778 sampler_dndi[index].dw6.dndi_stream_id = 1;
2779 sampler_dndi[index].dw6.dndi_first_frame = 1;
2780 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
2781 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
2782 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2783 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2785 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
2786 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
2787 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2788 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
2790 dri_bo_unmap(pp_context->sampler_state_table.bo);
2792 /* private function & data */
2793 pp_context->pp_x_steps = pp_dn_x_steps;
2794 pp_context->pp_y_steps = pp_dn_y_steps;
2795 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
2797 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2798 pp_static_parameter->grf1.r1_6.di.top_field_first = 0;
2799 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 64;
2800 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 192;
2802 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2803 pp_inline_parameter->grf5.number_blocks = w / 16;
2804 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2805 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2807 pp_dn_context->dest_w = w;
2808 pp_dn_context->dest_h = h;
2810 dst_surface->flags = src_surface->flags;
2812 return VA_STATUS_SUCCESS;
2816 gen7_pp_dndi_x_steps(void *private_context)
2818 struct pp_dndi_context *pp_dndi_context = private_context;
2820 return pp_dndi_context->dest_w / 16;
2824 gen7_pp_dndi_y_steps(void *private_context)
2826 struct pp_dndi_context *pp_dndi_context = private_context;
2828 return pp_dndi_context->dest_h / 4;
2832 gen7_pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2834 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2836 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16;
2837 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 4;
2843 gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2844 const struct i965_surface *src_surface,
2845 const VARectangle *src_rect,
2846 struct i965_surface *dst_surface,
2847 const VARectangle *dst_rect,
2850 struct i965_driver_data *i965 = i965_driver_data(ctx);
2851 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2852 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2853 struct object_surface *obj_surface;
2854 struct gen7_sampler_dndi *sampler_dndi;
2858 int dndi_top_first = 1;
2860 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2861 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2863 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2869 obj_surface = SURFACE(src_surface->id);
2870 orig_w = obj_surface->orig_width;
2871 orig_h = obj_surface->orig_height;
2872 w = obj_surface->width;
2873 h = obj_surface->height;
2875 if (pp_context->stmm.bo == NULL) {
2876 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2880 assert(pp_context->stmm.bo);
2883 /* source UV surface index 1 */
2884 gen7_pp_set_surface_state(ctx, pp_context,
2885 obj_surface->bo, w * h,
2886 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2889 /* source YUV surface index 3 */
2890 gen7_pp_set_surface2_state(ctx, pp_context,
2894 SURFACE_FORMAT_PLANAR_420_8, 1,
2897 /* source (temporal reference) YUV surface index 4 */
2898 gen7_pp_set_surface2_state(ctx, pp_context,
2902 SURFACE_FORMAT_PLANAR_420_8, 1,
2905 /* STMM / History Statistics input surface, index 5 */
2906 gen7_pp_set_surface_state(ctx, pp_context,
2907 pp_context->stmm.bo, 0,
2908 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2911 /* destination surface */
2912 obj_surface = SURFACE(dst_surface->id);
2913 orig_w = obj_surface->orig_width;
2914 orig_h = obj_surface->orig_height;
2915 w = obj_surface->width;
2916 h = obj_surface->height;
2918 /* destination(Previous frame) Y surface index 27 */
2919 gen7_pp_set_surface_state(ctx, pp_context,
2921 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2924 /* destination(Previous frame) UV surface index 28 */
2925 gen7_pp_set_surface_state(ctx, pp_context,
2926 obj_surface->bo, w * h,
2927 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2930 /* destination(Current frame) Y surface index 30 */
2931 gen7_pp_set_surface_state(ctx, pp_context,
2933 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2936 /* destination(Current frame) UV surface index 31 */
2937 gen7_pp_set_surface_state(ctx, pp_context,
2938 obj_surface->bo, w * h,
2939 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2942 /* STMM output surface, index 33 */
2943 gen7_pp_set_surface_state(ctx, pp_context,
2944 pp_context->stmm.bo, 0,
2945 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2950 dri_bo_map(pp_context->sampler_state_table.bo, True);
2951 assert(pp_context->sampler_state_table.bo->virtual);
2952 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2953 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2955 /* sample dndi index 0 */
2957 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2958 sampler_dndi[index].dw0.dnmh_delt = 8;
2959 sampler_dndi[index].dw0.vdi_walker_y_stride = 0;
2960 sampler_dndi[index].dw0.vdi_walker_frame_sharing_enable = 0;
2961 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2962 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2964 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2965 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2966 sampler_dndi[index].dw1.stmm_c2 = 0;
2967 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2968 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2970 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2971 sampler_dndi[index].dw2.bne_edge_th = 1;
2972 sampler_dndi[index].dw2.smooth_mv_th = 0;
2973 sampler_dndi[index].dw2.sad_tight_th = 5;
2974 sampler_dndi[index].dw2.cat_slope_minus1 = 9;
2975 sampler_dndi[index].dw2.good_neighbor_th = 4;
2977 sampler_dndi[index].dw3.maximum_stmm = 128;
2978 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2979 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2980 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2981 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2983 sampler_dndi[index].dw4.sdi_delta = 8;
2984 sampler_dndi[index].dw4.sdi_threshold = 128;
2985 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2986 sampler_dndi[index].dw4.stmm_shift_up = 0;
2987 sampler_dndi[index].dw4.stmm_shift_down = 0;
2988 sampler_dndi[index].dw4.minimum_stmm = 0;
2990 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2991 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2992 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2993 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2995 sampler_dndi[index].dw6.dn_enable = 0;
2996 sampler_dndi[index].dw6.di_enable = 1;
2997 sampler_dndi[index].dw6.di_partial = 0;
2998 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2999 sampler_dndi[index].dw6.dndi_stream_id = 1;
3000 sampler_dndi[index].dw6.dndi_first_frame = 1;
3001 sampler_dndi[index].dw6.progressive_dn = 0;
3002 sampler_dndi[index].dw6.mcdi_enable = 0;
3003 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
3004 sampler_dndi[index].dw6.cat_th1 = 0;
3005 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
3006 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
3008 sampler_dndi[index].dw7.sad_tha = 5;
3009 sampler_dndi[index].dw7.sad_thb = 10;
3010 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
3011 sampler_dndi[index].dw7.mc_pixel_consistency_th = 25;
3012 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
3013 sampler_dndi[index].dw7.vdi_walker_enable = 0;
3014 sampler_dndi[index].dw7.neighborpixel_th = 10;
3015 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
3017 dri_bo_unmap(pp_context->sampler_state_table.bo);
3019 /* private function & data */
3020 pp_context->pp_x_steps = gen7_pp_dndi_x_steps;
3021 pp_context->pp_y_steps = gen7_pp_dndi_y_steps;
3022 pp_context->pp_set_block_parameter = gen7_pp_dndi_set_block_parameter;
3024 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
3025 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
3026 pp_static_parameter->grf1.di_top_field_first = 0;
3027 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3029 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3030 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3031 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3033 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
3034 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3036 pp_dndi_context->dest_w = w;
3037 pp_dndi_context->dest_h = h;
3039 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
3041 return VA_STATUS_SUCCESS;
3045 gen7_pp_dn_x_steps(void *private_context)
3051 gen7_pp_dn_y_steps(void *private_context)
3053 struct pp_dn_context *pp_dn_context = private_context;
3055 return pp_dn_context->dest_h / 4;
3059 gen7_pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3061 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3063 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
3064 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
3070 gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3071 const struct i965_surface *src_surface,
3072 const VARectangle *src_rect,
3073 struct i965_surface *dst_surface,
3074 const VARectangle *dst_rect,
3077 struct i965_driver_data *i965 = i965_driver_data(ctx);
3078 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
3079 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3080 struct object_surface *obj_surface;
3081 struct gen7_sampler_dndi *sampler_dn;
3082 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
3086 int dn_strength = 15;
3087 int dndi_top_first = 1;
3088 int dn_progressive = 0;
3090 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
3093 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
3101 if (dn_filter_param) {
3102 float value = dn_filter_param->value;
3110 dn_strength = (int)(value * 31.0F);
3114 obj_surface = SURFACE(src_surface->id);
3115 orig_w = obj_surface->orig_width;
3116 orig_h = obj_surface->orig_height;
3117 w = obj_surface->width;
3118 h = obj_surface->height;
3120 if (pp_context->stmm.bo == NULL) {
3121 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
3125 assert(pp_context->stmm.bo);
3128 /* source UV surface index 1 */
3129 gen7_pp_set_surface_state(ctx, pp_context,
3130 obj_surface->bo, w * h,
3131 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3134 /* source YUV surface index 3 */
3135 gen7_pp_set_surface2_state(ctx, pp_context,
3139 SURFACE_FORMAT_PLANAR_420_8, 1,
3142 /* source STMM surface index 5 */
3143 gen7_pp_set_surface_state(ctx, pp_context,
3144 pp_context->stmm.bo, 0,
3145 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3148 /* destination surface */
3149 obj_surface = SURFACE(dst_surface->id);
3150 orig_w = obj_surface->orig_width;
3151 orig_h = obj_surface->orig_height;
3152 w = obj_surface->width;
3153 h = obj_surface->height;
3155 /* destination Y surface index 7 */
3156 gen7_pp_set_surface_state(ctx, pp_context,
3158 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3161 /* destination UV surface index 8 */
3162 gen7_pp_set_surface_state(ctx, pp_context,
3163 obj_surface->bo, w * h,
3164 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3167 dri_bo_map(pp_context->sampler_state_table.bo, True);
3168 assert(pp_context->sampler_state_table.bo->virtual);
3169 assert(sizeof(*sampler_dn) == sizeof(int) * 8);
3170 sampler_dn = pp_context->sampler_state_table.bo->virtual;
3172 /* sample dn index 1 */
3174 sampler_dn[index].dw0.denoise_asd_threshold = 0;
3175 sampler_dn[index].dw0.dnmh_delt = 8;
3176 sampler_dn[index].dw0.vdi_walker_y_stride = 0;
3177 sampler_dn[index].dw0.vdi_walker_frame_sharing_enable = 0;
3178 sampler_dn[index].dw0.denoise_maximum_history = 128; // 128-240
3179 sampler_dn[index].dw0.denoise_stad_threshold = 0;
3181 sampler_dn[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
3182 sampler_dn[index].dw1.denoise_moving_pixel_threshold = 0;
3183 sampler_dn[index].dw1.stmm_c2 = 0;
3184 sampler_dn[index].dw1.low_temporal_difference_threshold = 8;
3185 sampler_dn[index].dw1.temporal_difference_threshold = 16;
3187 sampler_dn[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
3188 sampler_dn[index].dw2.bne_edge_th = 1;
3189 sampler_dn[index].dw2.smooth_mv_th = 0;
3190 sampler_dn[index].dw2.sad_tight_th = 5;
3191 sampler_dn[index].dw2.cat_slope_minus1 = 9;
3192 sampler_dn[index].dw2.good_neighbor_th = 4;
3194 sampler_dn[index].dw3.maximum_stmm = 128;
3195 sampler_dn[index].dw3.multipler_for_vecm = 2;
3196 sampler_dn[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
3197 sampler_dn[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3198 sampler_dn[index].dw3.stmm_blending_constant_select = 0;
3200 sampler_dn[index].dw4.sdi_delta = 8;
3201 sampler_dn[index].dw4.sdi_threshold = 128;
3202 sampler_dn[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3203 sampler_dn[index].dw4.stmm_shift_up = 0;
3204 sampler_dn[index].dw4.stmm_shift_down = 0;
3205 sampler_dn[index].dw4.minimum_stmm = 0;
3207 sampler_dn[index].dw5.fmd_temporal_difference_threshold = 0;
3208 sampler_dn[index].dw5.sdi_fallback_mode_2_constant = 0;
3209 sampler_dn[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
3210 sampler_dn[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
3212 sampler_dn[index].dw6.dn_enable = 1;
3213 sampler_dn[index].dw6.di_enable = 0;
3214 sampler_dn[index].dw6.di_partial = 0;
3215 sampler_dn[index].dw6.dndi_top_first = dndi_top_first;
3216 sampler_dn[index].dw6.dndi_stream_id = 1;
3217 sampler_dn[index].dw6.dndi_first_frame = 1;
3218 sampler_dn[index].dw6.progressive_dn = dn_progressive;
3219 sampler_dn[index].dw6.mcdi_enable = 0;
3220 sampler_dn[index].dw6.fmd_tear_threshold = 32;
3221 sampler_dn[index].dw6.cat_th1 = 0;
3222 sampler_dn[index].dw6.fmd2_vertical_difference_threshold = 32;
3223 sampler_dn[index].dw6.fmd1_vertical_difference_threshold = 32;
3225 sampler_dn[index].dw7.sad_tha = 5;
3226 sampler_dn[index].dw7.sad_thb = 10;
3227 sampler_dn[index].dw7.fmd_for_1st_field_of_current_frame = 2;
3228 sampler_dn[index].dw7.mc_pixel_consistency_th = 25;
3229 sampler_dn[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
3230 sampler_dn[index].dw7.vdi_walker_enable = 0;
3231 sampler_dn[index].dw7.neighborpixel_th = 10;
3232 sampler_dn[index].dw7.column_width_minus1 = w / 16;
3234 dri_bo_unmap(pp_context->sampler_state_table.bo);
3236 /* private function & data */
3237 pp_context->pp_x_steps = gen7_pp_dn_x_steps;
3238 pp_context->pp_y_steps = gen7_pp_dn_y_steps;
3239 pp_context->pp_set_block_parameter = gen7_pp_dn_set_block_parameter;
3241 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
3242 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
3243 pp_static_parameter->grf1.di_top_field_first = 0;
3244 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3246 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3247 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3248 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3250 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
3251 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3253 pp_dn_context->dest_w = w;
3254 pp_dn_context->dest_h = h;
3256 dst_surface->flags = src_surface->flags;
3258 return VA_STATUS_SUCCESS;
3262 ironlake_pp_initialize(
3263 VADriverContextP ctx,
3264 struct i965_post_processing_context *pp_context,
3265 const struct i965_surface *src_surface,
3266 const VARectangle *src_rect,
3267 struct i965_surface *dst_surface,
3268 const VARectangle *dst_rect,
3274 struct i965_driver_data *i965 = i965_driver_data(ctx);
3275 struct pp_module *pp_module;
3277 int static_param_size, inline_param_size;
3279 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3280 bo = dri_bo_alloc(i965->intel.bufmgr,
3281 "surface state & binding table",
3282 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
3285 pp_context->surface_state_binding_table.bo = bo;
3287 dri_bo_unreference(pp_context->curbe.bo);
3288 bo = dri_bo_alloc(i965->intel.bufmgr,
3293 pp_context->curbe.bo = bo;
3295 dri_bo_unreference(pp_context->idrt.bo);
3296 bo = dri_bo_alloc(i965->intel.bufmgr,
3297 "interface discriptor",
3298 sizeof(struct i965_interface_descriptor),
3301 pp_context->idrt.bo = bo;
3302 pp_context->idrt.num_interface_descriptors = 0;
3304 dri_bo_unreference(pp_context->sampler_state_table.bo);
3305 bo = dri_bo_alloc(i965->intel.bufmgr,
3306 "sampler state table",
3310 dri_bo_map(bo, True);
3311 memset(bo->virtual, 0, bo->size);
3313 pp_context->sampler_state_table.bo = bo;
3315 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3316 bo = dri_bo_alloc(i965->intel.bufmgr,
3317 "sampler 8x8 state ",
3321 pp_context->sampler_state_table.bo_8x8 = bo;
3323 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3324 bo = dri_bo_alloc(i965->intel.bufmgr,
3325 "sampler 8x8 state ",
3329 pp_context->sampler_state_table.bo_8x8_uv = bo;
3331 dri_bo_unreference(pp_context->vfe_state.bo);
3332 bo = dri_bo_alloc(i965->intel.bufmgr,
3334 sizeof(struct i965_vfe_state),
3337 pp_context->vfe_state.bo = bo;
3339 static_param_size = sizeof(struct pp_static_parameter);
3340 inline_param_size = sizeof(struct pp_inline_parameter);
3342 memset(pp_context->pp_static_parameter, 0, static_param_size);
3343 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
3345 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3346 pp_context->current_pp = pp_index;
3347 pp_module = &pp_context->pp_modules[pp_index];
3349 if (pp_module->initialize)
3350 va_status = pp_module->initialize(ctx, pp_context,
3357 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3363 ironlake_post_processing(
3364 VADriverContextP ctx,
3365 struct i965_post_processing_context *pp_context,
3366 const struct i965_surface *src_surface,
3367 const VARectangle *src_rect,
3368 struct i965_surface *dst_surface,
3369 const VARectangle *dst_rect,
3376 va_status = ironlake_pp_initialize(ctx, pp_context,
3384 if (va_status == VA_STATUS_SUCCESS) {
3385 ironlake_pp_states_setup(ctx, pp_context);
3386 ironlake_pp_pipeline_setup(ctx, pp_context);
3394 VADriverContextP ctx,
3395 struct i965_post_processing_context *pp_context,
3396 const struct i965_surface *src_surface,
3397 const VARectangle *src_rect,
3398 struct i965_surface *dst_surface,
3399 const VARectangle *dst_rect,
3405 struct i965_driver_data *i965 = i965_driver_data(ctx);
3406 struct pp_module *pp_module;
3408 int static_param_size, inline_param_size;
3410 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3411 bo = dri_bo_alloc(i965->intel.bufmgr,
3412 "surface state & binding table",
3413 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
3416 pp_context->surface_state_binding_table.bo = bo;
3418 dri_bo_unreference(pp_context->curbe.bo);
3419 bo = dri_bo_alloc(i965->intel.bufmgr,
3424 pp_context->curbe.bo = bo;
3426 dri_bo_unreference(pp_context->idrt.bo);
3427 bo = dri_bo_alloc(i965->intel.bufmgr,
3428 "interface discriptor",
3429 sizeof(struct gen6_interface_descriptor_data),
3432 pp_context->idrt.bo = bo;
3433 pp_context->idrt.num_interface_descriptors = 0;
3435 dri_bo_unreference(pp_context->sampler_state_table.bo);
3436 bo = dri_bo_alloc(i965->intel.bufmgr,
3437 "sampler state table",
3441 dri_bo_map(bo, True);
3442 memset(bo->virtual, 0, bo->size);
3444 pp_context->sampler_state_table.bo = bo;
3446 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3447 bo = dri_bo_alloc(i965->intel.bufmgr,
3448 "sampler 8x8 state ",
3452 pp_context->sampler_state_table.bo_8x8 = bo;
3454 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3455 bo = dri_bo_alloc(i965->intel.bufmgr,
3456 "sampler 8x8 state ",
3460 pp_context->sampler_state_table.bo_8x8_uv = bo;
3462 dri_bo_unreference(pp_context->vfe_state.bo);
3463 bo = dri_bo_alloc(i965->intel.bufmgr,
3465 sizeof(struct i965_vfe_state),
3468 pp_context->vfe_state.bo = bo;
3470 if (IS_GEN7(i965->intel.device_id)) {
3471 static_param_size = sizeof(struct gen7_pp_static_parameter);
3472 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
3474 static_param_size = sizeof(struct pp_static_parameter);
3475 inline_param_size = sizeof(struct pp_inline_parameter);
3478 memset(pp_context->pp_static_parameter, 0, static_param_size);
3479 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
3481 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3482 pp_context->current_pp = pp_index;
3483 pp_module = &pp_context->pp_modules[pp_index];
3485 if (pp_module->initialize)
3486 va_status = pp_module->initialize(ctx, pp_context,
3493 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3499 gen6_pp_interface_descriptor_table(VADriverContextP ctx,
3500 struct i965_post_processing_context *pp_context)
3502 struct i965_driver_data *i965 = i965_driver_data(ctx);
3503 struct gen6_interface_descriptor_data *desc;
3505 int pp_index = pp_context->current_pp;
3507 bo = pp_context->idrt.bo;
3508 dri_bo_map(bo, True);
3509 assert(bo->virtual);
3511 memset(desc, 0, sizeof(*desc));
3512 desc->desc0.kernel_start_pointer =
3513 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
3514 desc->desc1.single_program_flow = 1;
3515 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
3516 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
3517 desc->desc2.sampler_state_pointer =
3518 pp_context->sampler_state_table.bo->offset >> 5;
3519 desc->desc3.binding_table_entry_count = 0;
3520 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
3521 desc->desc4.constant_urb_entry_read_offset = 0;
3523 if (IS_GEN7(i965->intel.device_id))
3524 desc->desc4.constant_urb_entry_read_length = 6; /* grf 1-6 */
3526 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
3528 dri_bo_emit_reloc(bo,
3529 I915_GEM_DOMAIN_INSTRUCTION, 0,
3531 offsetof(struct gen6_interface_descriptor_data, desc0),
3532 pp_context->pp_modules[pp_index].kernel.bo);
3534 dri_bo_emit_reloc(bo,
3535 I915_GEM_DOMAIN_INSTRUCTION, 0,
3536 desc->desc2.sampler_count << 2,
3537 offsetof(struct gen6_interface_descriptor_data, desc2),
3538 pp_context->sampler_state_table.bo);
3541 pp_context->idrt.num_interface_descriptors++;
3545 gen6_pp_upload_constants(VADriverContextP ctx,
3546 struct i965_post_processing_context *pp_context)
3548 struct i965_driver_data *i965 = i965_driver_data(ctx);
3549 unsigned char *constant_buffer;
3552 assert(sizeof(struct pp_static_parameter) == 128);
3553 assert(sizeof(struct gen7_pp_static_parameter) == 192);
3555 if (IS_GEN7(i965->intel.device_id))
3556 param_size = sizeof(struct gen7_pp_static_parameter);
3558 param_size = sizeof(struct pp_static_parameter);
3560 dri_bo_map(pp_context->curbe.bo, 1);
3561 assert(pp_context->curbe.bo->virtual);
3562 constant_buffer = pp_context->curbe.bo->virtual;
3563 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
3564 dri_bo_unmap(pp_context->curbe.bo);
3568 gen6_pp_states_setup(VADriverContextP ctx,
3569 struct i965_post_processing_context *pp_context)
3571 gen6_pp_interface_descriptor_table(ctx, pp_context);
3572 gen6_pp_upload_constants(ctx, pp_context);
3576 gen6_pp_pipeline_select(VADriverContextP ctx,
3577 struct i965_post_processing_context *pp_context)
3579 struct intel_batchbuffer *batch = pp_context->batch;
3581 BEGIN_BATCH(batch, 1);
3582 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
3583 ADVANCE_BATCH(batch);
3587 gen6_pp_state_base_address(VADriverContextP ctx,
3588 struct i965_post_processing_context *pp_context)
3590 struct intel_batchbuffer *batch = pp_context->batch;
3592 BEGIN_BATCH(batch, 10);
3593 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
3594 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3595 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
3596 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3597 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3598 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3599 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3600 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3601 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3602 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3603 ADVANCE_BATCH(batch);
3607 gen6_pp_vfe_state(VADriverContextP ctx,
3608 struct i965_post_processing_context *pp_context)
3610 struct intel_batchbuffer *batch = pp_context->batch;
3612 BEGIN_BATCH(batch, 8);
3613 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
3614 OUT_BATCH(batch, 0);
3616 (pp_context->urb.num_vfe_entries - 1) << 16 |
3617 pp_context->urb.num_vfe_entries << 8);
3618 OUT_BATCH(batch, 0);
3620 (pp_context->urb.size_vfe_entry * 2) << 16 | /* URB Entry Allocation Size, in 256 bits unit */
3621 (pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2)); /* CURBE Allocation Size, in 256 bits unit */
3622 OUT_BATCH(batch, 0);
3623 OUT_BATCH(batch, 0);
3624 OUT_BATCH(batch, 0);
3625 ADVANCE_BATCH(batch);
3629 gen6_pp_curbe_load(VADriverContextP ctx,
3630 struct i965_post_processing_context *pp_context)
3632 struct intel_batchbuffer *batch = pp_context->batch;
3634 assert(pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32 <= pp_context->curbe.bo->size);
3636 BEGIN_BATCH(batch, 4);
3637 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
3638 OUT_BATCH(batch, 0);
3640 pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32);
3642 pp_context->curbe.bo,
3643 I915_GEM_DOMAIN_INSTRUCTION, 0,
3645 ADVANCE_BATCH(batch);
3649 gen6_interface_descriptor_load(VADriverContextP ctx,
3650 struct i965_post_processing_context *pp_context)
3652 struct intel_batchbuffer *batch = pp_context->batch;
3654 BEGIN_BATCH(batch, 4);
3655 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
3656 OUT_BATCH(batch, 0);
3658 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
3660 pp_context->idrt.bo,
3661 I915_GEM_DOMAIN_INSTRUCTION, 0,
3663 ADVANCE_BATCH(batch);
3667 gen6_pp_object_walker(VADriverContextP ctx,
3668 struct i965_post_processing_context *pp_context)
3670 struct i965_driver_data *i965 = i965_driver_data(ctx);
3671 struct intel_batchbuffer *batch = pp_context->batch;
3672 int x, x_steps, y, y_steps;
3673 int param_size, command_length_in_dws;
3674 dri_bo *command_buffer;
3675 unsigned int *command_ptr;
3677 if (IS_GEN7(i965->intel.device_id))
3678 param_size = sizeof(struct gen7_pp_inline_parameter);
3680 param_size = sizeof(struct pp_inline_parameter);
3682 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
3683 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
3684 command_length_in_dws = 6 + (param_size >> 2);
3685 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
3686 "command objects buffer",
3687 command_length_in_dws * 4 * x_steps * y_steps + 8,
3690 dri_bo_map(command_buffer, 1);
3691 command_ptr = command_buffer->virtual;
3693 for (y = 0; y < y_steps; y++) {
3694 for (x = 0; x < x_steps; x++) {
3695 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
3696 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
3702 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
3703 command_ptr += (param_size >> 2);
3708 if (command_length_in_dws * x_steps * y_steps % 2 == 0)
3711 *command_ptr = MI_BATCH_BUFFER_END;
3713 dri_bo_unmap(command_buffer);
3715 BEGIN_BATCH(batch, 2);
3716 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (2 << 6));
3717 OUT_RELOC(batch, command_buffer,
3718 I915_GEM_DOMAIN_COMMAND, 0,
3720 ADVANCE_BATCH(batch);
3722 dri_bo_unreference(command_buffer);
3724 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
3725 * will cause control to pass back to ring buffer
3727 intel_batchbuffer_end_atomic(batch);
3728 intel_batchbuffer_flush(batch);
3729 intel_batchbuffer_start_atomic(batch, 0x1000);
3733 gen6_pp_pipeline_setup(VADriverContextP ctx,
3734 struct i965_post_processing_context *pp_context)
3736 struct intel_batchbuffer *batch = pp_context->batch;
3738 intel_batchbuffer_start_atomic(batch, 0x1000);
3739 intel_batchbuffer_emit_mi_flush(batch);
3740 gen6_pp_pipeline_select(ctx, pp_context);
3741 gen6_pp_state_base_address(ctx, pp_context);
3742 gen6_pp_vfe_state(ctx, pp_context);
3743 gen6_pp_curbe_load(ctx, pp_context);
3744 gen6_interface_descriptor_load(ctx, pp_context);
3745 gen6_pp_object_walker(ctx, pp_context);
3746 intel_batchbuffer_end_atomic(batch);
3750 gen6_post_processing(
3751 VADriverContextP ctx,
3752 struct i965_post_processing_context *pp_context,
3753 const struct i965_surface *src_surface,
3754 const VARectangle *src_rect,
3755 struct i965_surface *dst_surface,
3756 const VARectangle *dst_rect,
3763 va_status = gen6_pp_initialize(ctx, pp_context,
3771 if (va_status == VA_STATUS_SUCCESS) {
3772 gen6_pp_states_setup(ctx, pp_context);
3773 gen6_pp_pipeline_setup(ctx, pp_context);
3780 i965_post_processing_internal(
3781 VADriverContextP ctx,
3782 struct i965_post_processing_context *pp_context,
3783 const struct i965_surface *src_surface,
3784 const VARectangle *src_rect,
3785 struct i965_surface *dst_surface,
3786 const VARectangle *dst_rect,
3791 struct i965_driver_data *i965 = i965_driver_data(ctx);
3794 if (IS_GEN6(i965->intel.device_id) ||
3795 IS_GEN7(i965->intel.device_id))
3796 va_status = gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3798 va_status = ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3804 i965_DestroySurfaces(VADriverContextP ctx,
3805 VASurfaceID *surface_list,
3808 i965_CreateSurfaces(VADriverContextP ctx,
3813 VASurfaceID *surfaces);
3816 rgb_to_yuv(unsigned int argb,
3822 int r = ((argb >> 16) & 0xff);
3823 int g = ((argb >> 8) & 0xff);
3824 int b = ((argb >> 0) & 0xff);
3826 *y = (257 * r + 504 * g + 98 * b) / 1000 + 16;
3827 *v = (439 * r - 368 * g - 71 * b) / 1000 + 128;
3828 *u = (-148 * r - 291 * g + 439 * b) / 1000 + 128;
3829 *a = ((argb >> 24) & 0xff);
3833 i965_vpp_clear_surface(VADriverContextP ctx,
3834 struct i965_post_processing_context *pp_context,
3835 VASurfaceID surface,
3838 struct i965_driver_data *i965 = i965_driver_data(ctx);
3839 struct intel_batchbuffer *batch = pp_context->batch;
3840 struct object_surface *obj_surface = SURFACE(surface);
3841 unsigned int blt_cmd, br13;
3842 unsigned int tiling = 0, swizzle = 0;
3844 unsigned char y, u, v, a = 0;
3846 /* Currently only support NV12 surface */
3847 if (!obj_surface || obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3850 rgb_to_yuv(color, &y, &u, &v, &a);
3855 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3856 blt_cmd = XY_COLOR_BLT_CMD;
3857 pitch = obj_surface->width;
3859 if (tiling != I915_TILING_NONE) {
3860 blt_cmd |= XY_COLOR_BLT_DST_TILED;
3868 if (IS_GEN6(i965->intel.device_id) ||
3869 IS_GEN7(i965->intel.device_id)) {
3870 intel_batchbuffer_start_atomic_blt(batch, 48);
3871 BEGIN_BLT_BATCH(batch, 12);
3873 intel_batchbuffer_start_atomic(batch, 48);
3874 BEGIN_BATCH(batch, 12);
3877 OUT_BATCH(batch, blt_cmd);
3878 OUT_BATCH(batch, br13);
3883 obj_surface->height << 16 |
3884 obj_surface->width);
3885 OUT_RELOC(batch, obj_surface->bo,
3886 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3888 OUT_BATCH(batch, y);
3894 OUT_BATCH(batch, blt_cmd);
3895 OUT_BATCH(batch, br13);
3900 obj_surface->height / 2 << 16 |
3901 obj_surface->width / 2);
3902 OUT_RELOC(batch, obj_surface->bo,
3903 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3904 obj_surface->width * obj_surface->y_cb_offset);
3905 OUT_BATCH(batch, v << 8 | u);
3907 ADVANCE_BATCH(batch);
3908 intel_batchbuffer_end_atomic(batch);
3912 i965_post_processing(
3913 VADriverContextP ctx,
3914 VASurfaceID surface,
3915 const VARectangle *src_rect,
3916 const VARectangle *dst_rect,
3918 int *has_done_scaling
3921 struct i965_driver_data *i965 = i965_driver_data(ctx);
3922 VASurfaceID in_surface_id = surface;
3923 VASurfaceID out_surface_id = VA_INVALID_ID;
3925 *has_done_scaling = 0;
3928 struct object_surface *obj_surface;
3930 struct i965_surface src_surface;
3931 struct i965_surface dst_surface;
3933 obj_surface = SURFACE(in_surface_id);
3935 /* Currently only support post processing for NV12 surface */
3936 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3937 return out_surface_id;
3939 _i965LockMutex(&i965->pp_mutex);
3941 if (flags & I965_PP_FLAG_MCDI) {
3942 status = i965_CreateSurfaces(ctx,
3943 obj_surface->orig_width,
3944 obj_surface->orig_height,
3945 VA_RT_FORMAT_YUV420,
3948 assert(status == VA_STATUS_SUCCESS);
3949 obj_surface = SURFACE(out_surface_id);
3950 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3951 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3952 src_surface.id = in_surface_id;
3953 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3954 src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ?
3955 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
3956 dst_surface.id = out_surface_id;
3957 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3958 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3960 i965_post_processing_internal(ctx, i965->pp_context,
3969 if (flags & I965_PP_FLAG_AVS) {
3970 struct i965_render_state *render_state = &i965->render_state;
3971 struct intel_region *dest_region = render_state->draw_region;
3973 if (out_surface_id != VA_INVALID_ID)
3974 in_surface_id = out_surface_id;
3976 status = i965_CreateSurfaces(ctx,
3978 dest_region->height,
3979 VA_RT_FORMAT_YUV420,
3982 assert(status == VA_STATUS_SUCCESS);
3983 obj_surface = SURFACE(out_surface_id);
3984 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3985 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3986 src_surface.id = in_surface_id;
3987 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3988 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3989 dst_surface.id = out_surface_id;
3990 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3991 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3993 i965_post_processing_internal(ctx, i965->pp_context,
4001 if (in_surface_id != surface)
4002 i965_DestroySurfaces(ctx, &in_surface_id, 1);
4004 *has_done_scaling = 1;
4007 _i965UnlockMutex(&i965->pp_mutex);
4010 return out_surface_id;
4014 i965_image_pl3_processing(VADriverContextP ctx,
4015 const struct i965_surface *src_surface,
4016 const VARectangle *src_rect,
4017 struct i965_surface *dst_surface,
4018 const VARectangle *dst_rect)
4020 struct i965_driver_data *i965 = i965_driver_data(ctx);
4021 struct i965_post_processing_context *pp_context = i965->pp_context;
4022 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4023 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
4025 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
4026 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4031 PP_PL3_LOAD_SAVE_N12,
4033 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
4034 fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
4035 fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
4036 fourcc == VA_FOURCC('I', '4', '2', '0')) {
4037 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4042 PP_PL3_LOAD_SAVE_PL3,
4044 } else if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') ||
4045 fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
4046 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4051 PP_PL3_LOAD_SAVE_PA,
4058 intel_batchbuffer_flush(pp_context->batch);
4064 i965_image_pl2_processing(VADriverContextP ctx,
4065 const struct i965_surface *src_surface,
4066 const VARectangle *src_rect,
4067 struct i965_surface *dst_surface,
4068 const VARectangle *dst_rect)
4070 struct i965_driver_data *i965 = i965_driver_data(ctx);
4071 struct i965_post_processing_context *pp_context = i965->pp_context;
4072 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4073 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
4075 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
4076 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4081 PP_NV12_LOAD_SAVE_N12,
4083 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
4084 fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
4085 fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
4086 fourcc == VA_FOURCC('I', '4', '2', '0') ) {
4087 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4092 PP_NV12_LOAD_SAVE_PL3,
4094 } else if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') ||
4095 fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
4096 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4101 PP_NV12_LOAD_SAVE_PA,
4105 intel_batchbuffer_flush(pp_context->batch);
4111 i965_image_pl1_processing(VADriverContextP ctx,
4112 const struct i965_surface *src_surface,
4113 const VARectangle *src_rect,
4114 struct i965_surface *dst_surface,
4115 const VARectangle *dst_rect)
4117 struct i965_driver_data *i965 = i965_driver_data(ctx);
4118 struct i965_post_processing_context *pp_context = i965->pp_context;
4119 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4121 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
4122 i965_post_processing_internal(ctx, i965->pp_context,
4127 PP_PA_LOAD_SAVE_NV12,
4130 else if (fourcc == VA_FOURCC_YV12) {
4131 i965_post_processing_internal(ctx, i965->pp_context,
4136 PP_PA_LOAD_SAVE_PL3,
4141 return VA_STATUS_ERROR_UNKNOWN;
4144 intel_batchbuffer_flush(pp_context->batch);
4146 return VA_STATUS_SUCCESS;
4150 i965_image_processing(VADriverContextP ctx,
4151 const struct i965_surface *src_surface,
4152 const VARectangle *src_rect,
4153 struct i965_surface *dst_surface,
4154 const VARectangle *dst_rect)
4156 struct i965_driver_data *i965 = i965_driver_data(ctx);
4157 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
4160 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
4162 _i965LockMutex(&i965->pp_mutex);
4165 case VA_FOURCC('Y', 'V', '1', '2'):
4166 case VA_FOURCC('I', '4', '2', '0'):
4167 case VA_FOURCC('I', 'M', 'C', '1'):
4168 case VA_FOURCC('I', 'M', 'C', '3'):
4169 status = i965_image_pl3_processing(ctx,
4176 case VA_FOURCC('N', 'V', '1', '2'):
4177 status = i965_image_pl2_processing(ctx,
4183 case VA_FOURCC('Y', 'U', 'Y', '2'):
4184 case VA_FOURCC('U', 'Y', 'V', 'Y'):
4185 status = i965_image_pl1_processing(ctx,
4193 status = VA_STATUS_ERROR_UNIMPLEMENTED;
4197 _i965UnlockMutex(&i965->pp_mutex);
4204 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
4208 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
4209 pp_context->surface_state_binding_table.bo = NULL;
4211 dri_bo_unreference(pp_context->curbe.bo);
4212 pp_context->curbe.bo = NULL;
4214 dri_bo_unreference(pp_context->sampler_state_table.bo);
4215 pp_context->sampler_state_table.bo = NULL;
4217 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
4218 pp_context->sampler_state_table.bo_8x8 = NULL;
4220 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
4221 pp_context->sampler_state_table.bo_8x8_uv = NULL;
4223 dri_bo_unreference(pp_context->idrt.bo);
4224 pp_context->idrt.bo = NULL;
4225 pp_context->idrt.num_interface_descriptors = 0;
4227 dri_bo_unreference(pp_context->vfe_state.bo);
4228 pp_context->vfe_state.bo = NULL;
4230 dri_bo_unreference(pp_context->stmm.bo);
4231 pp_context->stmm.bo = NULL;
4233 for (i = 0; i < NUM_PP_MODULES; i++) {
4234 struct pp_module *pp_module = &pp_context->pp_modules[i];
4236 dri_bo_unreference(pp_module->kernel.bo);
4237 pp_module->kernel.bo = NULL;
4240 free(pp_context->pp_static_parameter);
4241 free(pp_context->pp_inline_parameter);
4242 pp_context->pp_static_parameter = NULL;
4243 pp_context->pp_inline_parameter = NULL;
4247 i965_post_processing_terminate(VADriverContextP ctx)
4249 struct i965_driver_data *i965 = i965_driver_data(ctx);
4250 struct i965_post_processing_context *pp_context = i965->pp_context;
4253 i965_post_processing_context_finalize(pp_context);
4257 i965->pp_context = NULL;
4263 i965_post_processing_context_init(VADriverContextP ctx,
4264 struct i965_post_processing_context *pp_context,
4265 struct intel_batchbuffer *batch)
4267 struct i965_driver_data *i965 = i965_driver_data(ctx);
4270 pp_context->urb.size = URB_SIZE((&i965->intel));
4271 pp_context->urb.num_vfe_entries = 32;
4272 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
4273 pp_context->urb.num_cs_entries = 1;
4275 if (IS_GEN7(i965->intel.device_id))
4276 pp_context->urb.size_cs_entry = 4; /* in 512 bits unit */
4278 pp_context->urb.size_cs_entry = 2;
4280 pp_context->urb.vfe_start = 0;
4281 pp_context->urb.cs_start = pp_context->urb.vfe_start +
4282 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
4283 assert(pp_context->urb.cs_start +
4284 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
4286 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
4287 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
4288 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen7));
4290 if (IS_GEN7(i965->intel.device_id))
4291 memcpy(pp_context->pp_modules, pp_modules_gen7, sizeof(pp_context->pp_modules));
4292 else if (IS_GEN6(i965->intel.device_id))
4293 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
4294 else if (IS_IRONLAKE(i965->intel.device_id))
4295 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
4297 for (i = 0; i < NUM_PP_MODULES; i++) {
4298 struct pp_module *pp_module = &pp_context->pp_modules[i];
4299 dri_bo_unreference(pp_module->kernel.bo);
4300 if (pp_module->kernel.bin && pp_module->kernel.size) {
4301 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
4302 pp_module->kernel.name,
4303 pp_module->kernel.size,
4305 assert(pp_module->kernel.bo);
4306 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
4308 pp_module->kernel.bo = NULL;
4312 /* static & inline parameters */
4313 if (IS_GEN7(i965->intel.device_id)) {
4314 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
4315 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
4317 pp_context->pp_static_parameter = calloc(sizeof(struct pp_static_parameter), 1);
4318 pp_context->pp_inline_parameter = calloc(sizeof(struct pp_inline_parameter), 1);
4321 pp_context->batch = batch;
4325 i965_post_processing_init(VADriverContextP ctx)
4327 struct i965_driver_data *i965 = i965_driver_data(ctx);
4328 struct i965_post_processing_context *pp_context = i965->pp_context;
4331 if (pp_context == NULL) {
4332 pp_context = calloc(1, sizeof(*pp_context));
4333 i965_post_processing_context_init(ctx, pp_context, i965->batch);
4334 i965->pp_context = pp_context;
4341 static const int procfilter_to_pp_flag[VAProcFilterCount] = {
4342 PP_NULL, /* VAProcFilterNone */
4343 PP_NV12_DN, /* VAProcFilterNoiseReduction */
4344 PP_NULL, /* VAProcFilterDeblocking */
4345 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
4346 PP_NULL, /* VAProcFilterSharpening */
4347 PP_NULL, /* VAProcFilterColorBalance */
4348 PP_NULL, /* VAProcFilterColorStandard */
4349 PP_NULL, /* VAProcFilterFrameRateConversion */
4352 static const int proc_frame_to_pp_frame[3] = {
4353 I965_SURFACE_FLAG_FRAME,
4354 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
4355 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
4359 i965_proc_picture(VADriverContextP ctx,
4361 union codec_state *codec_state,
4362 struct hw_context *hw_context)
4364 struct i965_driver_data *i965 = i965_driver_data(ctx);
4365 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
4366 struct proc_state *proc_state = &codec_state->proc;
4367 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
4368 struct object_surface *obj_surface;
4369 struct i965_surface src_surface, dst_surface;
4370 VARectangle src_rect, dst_rect;
4373 VASurfaceID tmp_surfaces[VAProcFilterCount + 4];
4374 int num_tmp_surfaces = 0;
4375 unsigned int tiling = 0, swizzle = 0;
4376 int in_width, in_height;
4378 assert(pipeline_param->surface != VA_INVALID_ID);
4379 assert(proc_state->current_render_target != VA_INVALID_ID);
4381 obj_surface = SURFACE(pipeline_param->surface);
4382 in_width = obj_surface->orig_width;
4383 in_height = obj_surface->orig_height;
4384 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4386 src_surface.id = pipeline_param->surface;
4387 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4388 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
4390 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
4391 VASurfaceID out_surface_id = VA_INVALID_ID;
4393 src_surface.id = pipeline_param->surface;
4394 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4395 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4398 src_rect.width = in_width;
4399 src_rect.height = in_height;
4401 status = i965_CreateSurfaces(ctx,
4404 VA_RT_FORMAT_YUV420,
4407 assert(status == VA_STATUS_SUCCESS);
4408 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
4409 obj_surface = SURFACE(out_surface_id);
4410 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
4412 dst_surface.id = out_surface_id;
4413 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4414 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4417 dst_rect.width = in_width;
4418 dst_rect.height = in_height;
4420 status = i965_image_processing(ctx,
4425 assert(status == VA_STATUS_SUCCESS);
4427 src_surface.id = out_surface_id;
4428 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4429 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
4432 if (pipeline_param->surface_region) {
4433 src_rect.x = pipeline_param->surface_region->x;
4434 src_rect.y = pipeline_param->surface_region->y;
4435 src_rect.width = pipeline_param->surface_region->width;
4436 src_rect.height = pipeline_param->surface_region->height;
4440 src_rect.width = in_width;
4441 src_rect.height = in_height;
4444 if (pipeline_param->output_region) {
4445 dst_rect.x = pipeline_param->output_region->x;
4446 dst_rect.y = pipeline_param->output_region->y;
4447 dst_rect.width = pipeline_param->output_region->width;
4448 dst_rect.height = pipeline_param->output_region->height;
4452 dst_rect.width = in_width;
4453 dst_rect.height = in_height;
4456 obj_surface = SURFACE(proc_state->current_render_target);
4457 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4458 i965_vpp_clear_surface(ctx, &proc_context->pp_context, proc_state->current_render_target, pipeline_param->output_background_color);
4460 for (i = 0; i < pipeline_param->num_filters; i++) {
4461 struct object_buffer *obj_buffer = BUFFER(pipeline_param->filters[i]);
4462 VAProcFilterParameterBufferBase *filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4463 VAProcFilterType filter_type = filter_param->type;
4464 VASurfaceID out_surface_id = VA_INVALID_ID;
4465 int kernel_index = procfilter_to_pp_flag[filter_type];
4467 if (kernel_index != PP_NULL &&
4468 proc_context->pp_context.pp_modules[kernel_index].kernel.bo != NULL) {
4469 status = i965_CreateSurfaces(ctx,
4472 VA_RT_FORMAT_YUV420,
4475 assert(status == VA_STATUS_SUCCESS);
4476 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
4477 obj_surface = SURFACE(out_surface_id);
4478 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4479 dst_surface.id = out_surface_id;
4480 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4481 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
4489 if (status == VA_STATUS_SUCCESS) {
4490 src_surface.id = dst_surface.id;
4491 src_surface.type = dst_surface.type;
4492 src_surface.flags = dst_surface.flags;
4497 dst_surface.id = proc_state->current_render_target;
4498 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4500 if (src_rect.width == dst_rect.width &&
4501 src_rect.height == dst_rect.height) {
4502 i965_post_processing_internal(ctx, &proc_context->pp_context,
4507 PP_NV12_LOAD_SAVE_N12,
4511 i965_post_processing_internal(ctx, &proc_context->pp_context,
4516 (pipeline_param->filter_flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC ?
4517 PP_NV12_AVS : PP_NV12_SCALING,
4521 if (num_tmp_surfaces)
4522 i965_DestroySurfaces(ctx,
4526 intel_batchbuffer_flush(hw_context->batch);
4530 i965_proc_context_destroy(void *hw_context)
4532 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
4534 i965_post_processing_context_finalize(&proc_context->pp_context);
4535 intel_batchbuffer_free(proc_context->base.batch);
4540 i965_proc_context_init(VADriverContextP ctx, struct object_config *obj_config)
4542 struct intel_driver_data *intel = intel_driver_data(ctx);
4543 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
4545 proc_context->base.destroy = i965_proc_context_destroy;
4546 proc_context->base.run = i965_proc_picture;
4547 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
4548 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
4550 return (struct hw_context *)proc_context;