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_static_parameter(
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);
1071 case VA_FOURCC('Y', 'U', 'Y', '2'):
1072 pp_static_parameter->grf1.source_packed_u_offset = 1;
1073 pp_static_parameter->grf1.source_packed_v_offset = 3;
1075 case VA_FOURCC('U', 'Y', 'V', 'Y'):
1076 pp_static_parameter->grf1.source_packed_y_offset = 1;
1077 pp_static_parameter->grf1.source_packed_v_offset = 2;
1079 case VA_FOURCC('B', 'G', 'R', 'X'):
1080 case VA_FOURCC('B', 'G', 'R', 'A'):
1081 pp_static_parameter->grf1.source_rgb_layout = 0;
1083 case VA_FOURCC('R', 'G', 'B', 'X'):
1084 case VA_FOURCC('R', 'G', 'B', 'A'):
1085 pp_static_parameter->grf1.source_rgb_layout = 1;
1093 static void i965_update_dst_surface_static_parameter(
1094 VADriverContextP ctx,
1095 struct i965_post_processing_context *pp_context,
1096 const struct i965_surface *surface)
1098 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1099 int fourcc = pp_get_surface_fourcc(ctx, surface);
1102 case VA_FOURCC('Y', 'U', 'Y', '2'):
1103 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_u_offset = 1;
1104 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 3;
1106 case VA_FOURCC('U', 'Y', 'V', 'Y'):
1107 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_y_offset = 1;
1108 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 2;
1110 case VA_FOURCC('B', 'G', 'R', 'X'):
1111 case VA_FOURCC('B', 'G', 'R', 'A'):
1112 pp_static_parameter->grf1.r1_2.csc.destination_rgb_layout = 0;
1114 case VA_FOURCC('R', 'G', 'B', 'X'):
1115 case VA_FOURCC('R', 'G', 'B', 'A'):
1116 pp_static_parameter->grf1.r1_2.csc.destination_rgb_layout = 1;
1125 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1126 dri_bo *surf_bo, unsigned long surf_bo_offset,
1127 int width, int height, int pitch, int format,
1128 int index, int is_target)
1130 struct i965_surface_state *ss;
1132 unsigned int tiling;
1133 unsigned int swizzle;
1135 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1136 ss_bo = pp_context->surface_state_binding_table.bo;
1139 dri_bo_map(ss_bo, True);
1140 assert(ss_bo->virtual);
1141 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1142 memset(ss, 0, sizeof(*ss));
1143 ss->ss0.surface_type = I965_SURFACE_2D;
1144 ss->ss0.surface_format = format;
1145 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1146 ss->ss2.width = width - 1;
1147 ss->ss2.height = height - 1;
1148 ss->ss3.pitch = pitch - 1;
1149 pp_set_surface_tiling(ss, tiling);
1150 dri_bo_emit_reloc(ss_bo,
1151 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1153 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
1155 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1156 dri_bo_unmap(ss_bo);
1160 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1161 dri_bo *surf_bo, unsigned long surf_bo_offset,
1162 int width, int height, int wpitch,
1163 int xoffset, int yoffset,
1164 int format, int interleave_chroma,
1167 struct i965_surface_state2 *ss2;
1169 unsigned int tiling;
1170 unsigned int swizzle;
1172 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1173 ss2_bo = pp_context->surface_state_binding_table.bo;
1176 dri_bo_map(ss2_bo, True);
1177 assert(ss2_bo->virtual);
1178 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1179 memset(ss2, 0, sizeof(*ss2));
1180 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1181 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1182 ss2->ss1.width = width - 1;
1183 ss2->ss1.height = height - 1;
1184 ss2->ss2.pitch = wpitch - 1;
1185 ss2->ss2.interleave_chroma = interleave_chroma;
1186 ss2->ss2.surface_format = format;
1187 ss2->ss3.x_offset_for_cb = xoffset;
1188 ss2->ss3.y_offset_for_cb = yoffset;
1189 pp_set_surface2_tiling(ss2, tiling);
1190 dri_bo_emit_reloc(ss2_bo,
1191 I915_GEM_DOMAIN_RENDER, 0,
1193 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
1195 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1196 dri_bo_unmap(ss2_bo);
1200 gen7_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1201 dri_bo *surf_bo, unsigned long surf_bo_offset,
1202 int width, int height, int pitch, int format,
1203 int index, int is_target)
1205 struct gen7_surface_state *ss;
1207 unsigned int tiling;
1208 unsigned int swizzle;
1210 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1211 ss_bo = pp_context->surface_state_binding_table.bo;
1214 dri_bo_map(ss_bo, True);
1215 assert(ss_bo->virtual);
1216 ss = (struct gen7_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1217 memset(ss, 0, sizeof(*ss));
1218 ss->ss0.surface_type = I965_SURFACE_2D;
1219 ss->ss0.surface_format = format;
1220 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1221 ss->ss2.width = width - 1;
1222 ss->ss2.height = height - 1;
1223 ss->ss3.pitch = pitch - 1;
1224 gen7_pp_set_surface_tiling(ss, tiling);
1225 dri_bo_emit_reloc(ss_bo,
1226 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1228 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state, ss1),
1230 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1231 dri_bo_unmap(ss_bo);
1235 gen7_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1236 dri_bo *surf_bo, unsigned long surf_bo_offset,
1237 int width, int height, int wpitch,
1238 int xoffset, int yoffset,
1239 int format, int interleave_chroma,
1242 struct gen7_surface_state2 *ss2;
1244 unsigned int tiling;
1245 unsigned int swizzle;
1247 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1248 ss2_bo = pp_context->surface_state_binding_table.bo;
1251 dri_bo_map(ss2_bo, True);
1252 assert(ss2_bo->virtual);
1253 ss2 = (struct gen7_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1254 memset(ss2, 0, sizeof(*ss2));
1255 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1256 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1257 ss2->ss1.width = width - 1;
1258 ss2->ss1.height = height - 1;
1259 ss2->ss2.pitch = wpitch - 1;
1260 ss2->ss2.interleave_chroma = interleave_chroma;
1261 ss2->ss2.surface_format = format;
1262 ss2->ss3.x_offset_for_cb = xoffset;
1263 ss2->ss3.y_offset_for_cb = yoffset;
1264 gen7_pp_set_surface2_tiling(ss2, tiling);
1265 dri_bo_emit_reloc(ss2_bo,
1266 I915_GEM_DOMAIN_RENDER, 0,
1268 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state2, ss0),
1270 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1271 dri_bo_unmap(ss2_bo);
1275 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1276 const struct i965_surface *surface,
1277 int base_index, int is_target,
1278 int *width, int *height, int *pitch, int *offset)
1280 struct i965_driver_data *i965 = i965_driver_data(ctx);
1281 struct object_surface *obj_surface;
1282 struct object_image *obj_image;
1284 int fourcc = pp_get_surface_fourcc(ctx, surface);
1286 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
1287 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
1289 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1290 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
1291 int full_packed_format = (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
1292 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
1293 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
1294 fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
1295 int scale_factor_of_1st_plane_width_in_byte = 1;
1297 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1298 obj_surface = SURFACE(surface->id);
1299 bo = obj_surface->bo;
1300 width[0] = obj_surface->orig_width;
1301 height[0] = obj_surface->orig_height;
1302 pitch[0] = obj_surface->width;
1305 if (full_packed_format) {
1306 scale_factor_of_1st_plane_width_in_byte = 4;
1307 pitch[0] = obj_surface->width * 4;
1309 else if (packed_yuv ) {
1310 scale_factor_of_1st_plane_width_in_byte = 2;
1311 pitch[0] = obj_surface->width * 2;
1313 else if (interleaved_uv) {
1314 width[1] = obj_surface->orig_width;
1315 height[1] = obj_surface->orig_height / 2;
1316 pitch[1] = obj_surface->width;
1317 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1319 width[1] = obj_surface->orig_width / 2;
1320 height[1] = obj_surface->orig_height / 2;
1321 pitch[1] = obj_surface->width / 2;
1322 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1323 width[2] = obj_surface->orig_width / 2;
1324 height[2] = obj_surface->orig_height / 2;
1325 pitch[2] = obj_surface->width / 2;
1326 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
1329 obj_image = IMAGE(surface->id);
1331 width[0] = obj_image->image.width;
1332 height[0] = obj_image->image.height;
1333 pitch[0] = obj_image->image.pitches[0];
1334 offset[0] = obj_image->image.offsets[0];
1336 if (full_packed_format) {
1337 scale_factor_of_1st_plane_width_in_byte = 4;
1339 else if (packed_yuv ) {
1340 scale_factor_of_1st_plane_width_in_byte = 2;
1342 else if (interleaved_uv) {
1343 width[1] = obj_image->image.width;
1344 height[1] = obj_image->image.height / 2;
1345 pitch[1] = obj_image->image.pitches[1];
1346 offset[1] = obj_image->image.offsets[1];
1348 width[1] = obj_image->image.width / 2;
1349 height[1] = obj_image->image.height / 2;
1350 pitch[1] = obj_image->image.pitches[1];
1351 offset[1] = obj_image->image.offsets[1];
1352 width[2] = obj_image->image.width / 2;
1353 height[2] = obj_image->image.height / 2;
1354 pitch[2] = obj_image->image.pitches[2];
1355 offset[2] = obj_image->image.offsets[2];
1360 i965_pp_set_surface_state(ctx, pp_context,
1362 width[Y] *scale_factor_of_1st_plane_width_in_byte / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
1363 base_index, is_target);
1365 if (!packed_yuv && !full_packed_format) {
1366 if (interleaved_uv) {
1367 i965_pp_set_surface_state(ctx, pp_context,
1369 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
1370 base_index + 1, is_target);
1373 i965_pp_set_surface_state(ctx, pp_context,
1375 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
1376 base_index + 1, is_target);
1379 i965_pp_set_surface_state(ctx, pp_context,
1381 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
1382 base_index + 2, is_target);
1389 gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1390 const struct i965_surface *surface,
1391 int base_index, int is_target,
1392 int *width, int *height, int *pitch, int *offset)
1394 struct i965_driver_data *i965 = i965_driver_data(ctx);
1395 struct object_surface *obj_surface;
1396 struct object_image *obj_image;
1398 int fourcc = pp_get_surface_fourcc(ctx, surface);
1399 const int U = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
1400 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 2 : 1;
1401 const int V = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
1402 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 1 : 2;
1403 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
1404 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
1406 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1407 obj_surface = SURFACE(surface->id);
1408 bo = obj_surface->bo;
1409 width[0] = obj_surface->orig_width;
1410 height[0] = obj_surface->orig_height;
1411 pitch[0] = obj_surface->width;
1416 width[0] = obj_surface->orig_width * 2; /* surface format is R8, so double the width */
1418 width[0] = obj_surface->orig_width; /* surface foramt is YCBCR, width is specified in units of pixels */
1420 pitch[0] = obj_surface->width * 2;
1423 width[1] = obj_surface->cb_cr_width;
1424 height[1] = obj_surface->cb_cr_height;
1425 pitch[1] = obj_surface->cb_cr_pitch;
1426 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
1428 width[2] = obj_surface->cb_cr_width;
1429 height[2] = obj_surface->cb_cr_height;
1430 pitch[2] = obj_surface->cb_cr_pitch;
1431 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
1433 obj_image = IMAGE(surface->id);
1435 width[0] = obj_image->image.width;
1436 height[0] = obj_image->image.height;
1437 pitch[0] = obj_image->image.pitches[0];
1438 offset[0] = obj_image->image.offsets[0];
1442 width[0] = obj_image->image.width * 2; /* surface format is R8, so double the width */
1444 width[0] = obj_image->image.width; /* surface foramt is YCBCR, width is specified in units of pixels */
1445 } else if (interleaved_uv) {
1446 width[1] = obj_image->image.width / 2;
1447 height[1] = obj_image->image.height / 2;
1448 pitch[1] = obj_image->image.pitches[1];
1449 offset[1] = obj_image->image.offsets[1];
1451 width[1] = obj_image->image.width / 2;
1452 height[1] = obj_image->image.height / 2;
1453 pitch[1] = obj_image->image.pitches[U];
1454 offset[1] = obj_image->image.offsets[U];
1455 width[2] = obj_image->image.width / 2;
1456 height[2] = obj_image->image.height / 2;
1457 pitch[2] = obj_image->image.pitches[V];
1458 offset[2] = obj_image->image.offsets[V];
1463 gen7_pp_set_surface_state(ctx, pp_context,
1465 width[0] / 4, height[0], pitch[0],
1466 I965_SURFACEFORMAT_R8_SINT,
1470 if (interleaved_uv) {
1471 gen7_pp_set_surface_state(ctx, pp_context,
1473 width[1] / 2, height[1], pitch[1],
1474 I965_SURFACEFORMAT_R8G8_SINT,
1477 gen7_pp_set_surface_state(ctx, pp_context,
1479 width[1] / 4, height[1], pitch[1],
1480 I965_SURFACEFORMAT_R8_SINT,
1482 gen7_pp_set_surface_state(ctx, pp_context,
1484 width[2] / 4, height[2], pitch[2],
1485 I965_SURFACEFORMAT_R8_SINT,
1490 int format0 = SURFACE_FORMAT_Y8_UNORM;
1493 case VA_FOURCC('Y', 'U', 'Y', '2'):
1494 format0 = SURFACE_FORMAT_YCRCB_NORMAL;
1497 case VA_FOURCC('U', 'Y', 'V', 'Y'):
1498 format0 = SURFACE_FORMAT_YCRCB_SWAPY;
1505 gen7_pp_set_surface2_state(ctx, pp_context,
1507 width[0], height[0], pitch[0],
1513 if (interleaved_uv) {
1514 gen7_pp_set_surface2_state(ctx, pp_context,
1516 width[1], height[1], pitch[1],
1518 SURFACE_FORMAT_R8B8_UNORM, 0,
1521 gen7_pp_set_surface2_state(ctx, pp_context,
1523 width[1], height[1], pitch[1],
1525 SURFACE_FORMAT_R8_UNORM, 0,
1527 gen7_pp_set_surface2_state(ctx, pp_context,
1529 width[2], height[2], pitch[2],
1531 SURFACE_FORMAT_R8_UNORM, 0,
1539 pp_null_x_steps(void *private_context)
1545 pp_null_y_steps(void *private_context)
1551 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1557 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1558 const struct i965_surface *src_surface,
1559 const VARectangle *src_rect,
1560 struct i965_surface *dst_surface,
1561 const VARectangle *dst_rect,
1564 /* private function & data */
1565 pp_context->pp_x_steps = pp_null_x_steps;
1566 pp_context->pp_y_steps = pp_null_y_steps;
1567 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
1569 dst_surface->flags = src_surface->flags;
1571 return VA_STATUS_SUCCESS;
1575 pp_load_save_x_steps(void *private_context)
1581 pp_load_save_y_steps(void *private_context)
1583 struct pp_load_save_context *pp_load_save_context = private_context;
1585 return pp_load_save_context->dest_h / 8;
1589 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1591 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1593 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1594 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1595 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
1596 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
1602 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1603 const struct i965_surface *src_surface,
1604 const VARectangle *src_rect,
1605 struct i965_surface *dst_surface,
1606 const VARectangle *dst_rect,
1609 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->private_context;
1610 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1611 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1612 int width[3], height[3], pitch[3], offset[3];
1615 /* source surface */
1616 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
1617 width, height, pitch, offset);
1619 /* destination surface */
1620 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
1621 width, height, pitch, offset);
1623 /* private function & data */
1624 pp_context->pp_x_steps = pp_load_save_x_steps;
1625 pp_context->pp_y_steps = pp_load_save_y_steps;
1626 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
1627 pp_load_save_context->dest_h = ALIGN(height[Y], 16);
1628 pp_load_save_context->dest_w = ALIGN(width[Y], 16);
1630 pp_inline_parameter->grf5.block_count_x = ALIGN(width[Y], 16) / 16; /* 1 x N */
1631 pp_inline_parameter->grf5.number_blocks = ALIGN(width[Y], 16) / 16;
1633 pp_static_parameter->grf3.horizontal_origin_offset = src_rect->x;
1634 pp_static_parameter->grf3.vertical_origin_offset = src_rect->y;
1636 // update u/v offset for packed yuv
1637 i965_update_src_surface_static_parameter (ctx, pp_context, src_surface);
1638 i965_update_dst_surface_static_parameter (ctx, pp_context, dst_surface);
1640 dst_surface->flags = src_surface->flags;
1642 return VA_STATUS_SUCCESS;
1646 pp_scaling_x_steps(void *private_context)
1652 pp_scaling_y_steps(void *private_context)
1654 struct pp_scaling_context *pp_scaling_context = private_context;
1656 return pp_scaling_context->dest_h / 8;
1660 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1662 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1663 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1664 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1665 float src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1666 float src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1668 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
1669 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
1670 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
1671 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
1677 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1678 const struct i965_surface *src_surface,
1679 const VARectangle *src_rect,
1680 struct i965_surface *dst_surface,
1681 const VARectangle *dst_rect,
1684 struct i965_driver_data *i965 = i965_driver_data(ctx);
1685 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
1686 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1687 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1688 struct object_surface *obj_surface;
1689 struct i965_sampler_state *sampler_state;
1690 int in_w, in_h, in_wpitch, in_hpitch;
1691 int out_w, out_h, out_wpitch, out_hpitch;
1693 /* source surface */
1694 obj_surface = SURFACE(src_surface->id);
1695 in_w = obj_surface->orig_width;
1696 in_h = obj_surface->orig_height;
1697 in_wpitch = obj_surface->width;
1698 in_hpitch = obj_surface->height;
1700 /* source Y surface index 1 */
1701 i965_pp_set_surface_state(ctx, pp_context,
1703 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1706 /* source UV surface index 2 */
1707 i965_pp_set_surface_state(ctx, pp_context,
1708 obj_surface->bo, in_wpitch * in_hpitch,
1709 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1712 /* destination surface */
1713 obj_surface = SURFACE(dst_surface->id);
1714 out_w = obj_surface->orig_width;
1715 out_h = obj_surface->orig_height;
1716 out_wpitch = obj_surface->width;
1717 out_hpitch = obj_surface->height;
1719 /* destination Y surface index 7 */
1720 i965_pp_set_surface_state(ctx, pp_context,
1722 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1725 /* destination UV surface index 8 */
1726 i965_pp_set_surface_state(ctx, pp_context,
1727 obj_surface->bo, out_wpitch * out_hpitch,
1728 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1732 dri_bo_map(pp_context->sampler_state_table.bo, True);
1733 assert(pp_context->sampler_state_table.bo->virtual);
1734 sampler_state = pp_context->sampler_state_table.bo->virtual;
1736 /* SIMD16 Y index 1 */
1737 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
1738 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1739 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1740 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1741 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1743 /* SIMD16 UV index 2 */
1744 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
1745 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
1746 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1747 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1748 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1750 dri_bo_unmap(pp_context->sampler_state_table.bo);
1752 /* private function & data */
1753 pp_context->pp_x_steps = pp_scaling_x_steps;
1754 pp_context->pp_y_steps = pp_scaling_y_steps;
1755 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
1757 pp_scaling_context->dest_x = dst_rect->x;
1758 pp_scaling_context->dest_y = dst_rect->y;
1759 pp_scaling_context->dest_w = ALIGN(dst_rect->width, 16);
1760 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 16);
1761 pp_scaling_context->src_normalized_x = (float)src_rect->x / in_w;
1762 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h;
1764 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
1766 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
1767 pp_inline_parameter->grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
1768 pp_inline_parameter->grf5.number_blocks = pp_scaling_context->dest_w / 16;
1769 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
1770 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
1772 dst_surface->flags = src_surface->flags;
1774 return VA_STATUS_SUCCESS;
1778 pp_avs_x_steps(void *private_context)
1780 struct pp_avs_context *pp_avs_context = private_context;
1782 return pp_avs_context->dest_w / 16;
1786 pp_avs_y_steps(void *private_context)
1792 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1794 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1795 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1796 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1797 float src_x_steping, src_y_steping, video_step_delta;
1798 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
1800 if (pp_static_parameter->grf4.r4_2.avs.nlas == 0) {
1801 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1802 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_avs_context->src_normalized_x;
1803 } else if (tmp_w >= pp_avs_context->dest_w) {
1804 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1805 pp_inline_parameter->grf6.video_step_delta = 0;
1808 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
1809 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;
1817 int n0, n1, n2, nls_left, nls_right;
1818 int factor_a = 5, factor_b = 4;
1821 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
1822 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
1823 n2 = tmp_w / (16 * factor_a);
1825 nls_right = n1 + n2;
1826 f = (float) n2 * 16 / tmp_w;
1829 pp_inline_parameter->grf6.video_step_delta = 0.0;
1832 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
1833 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1835 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1836 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1837 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1838 16 * 15 * video_step_delta / 2;
1842 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
1843 float a = f / (nls_left * 16 * factor_b);
1844 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
1846 pp_inline_parameter->grf6.video_step_delta = b;
1849 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1850 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a;
1852 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1853 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1854 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1855 16 * 15 * video_step_delta / 2;
1856 pp_inline_parameter->grf5.normalized_video_x_scaling_step += 16 * b;
1858 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
1859 /* scale the center linearly */
1860 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1861 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1862 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1863 16 * 15 * video_step_delta / 2;
1864 pp_inline_parameter->grf6.video_step_delta = 0.0;
1865 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1867 float a = f / (nls_right * 16 * factor_b);
1868 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
1870 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
1871 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
1872 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1873 16 * 15 * video_step_delta / 2;
1874 pp_inline_parameter->grf6.video_step_delta = -b;
1876 if (x == (pp_avs_context->dest_w / 16 - nls_right))
1877 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
1879 pp_inline_parameter->grf5.normalized_video_x_scaling_step -= b * 16;
1884 src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
1885 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
1886 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1887 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
1893 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1894 const struct i965_surface *src_surface,
1895 const VARectangle *src_rect,
1896 struct i965_surface *dst_surface,
1897 const VARectangle *dst_rect,
1901 struct i965_driver_data *i965 = i965_driver_data(ctx);
1902 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1903 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1904 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1905 struct object_surface *obj_surface;
1906 struct i965_sampler_8x8 *sampler_8x8;
1907 struct i965_sampler_8x8_state *sampler_8x8_state;
1909 int in_w, in_h, in_wpitch, in_hpitch;
1910 int out_w, out_h, out_wpitch, out_hpitch;
1914 obj_surface = SURFACE(src_surface->id);
1915 in_w = obj_surface->orig_width;
1916 in_h = obj_surface->orig_height;
1917 in_wpitch = obj_surface->width;
1918 in_hpitch = obj_surface->height;
1920 /* source Y surface index 1 */
1921 i965_pp_set_surface2_state(ctx, pp_context,
1923 in_w, in_h, in_wpitch,
1925 SURFACE_FORMAT_Y8_UNORM, 0,
1928 /* source UV surface index 2 */
1929 i965_pp_set_surface2_state(ctx, pp_context,
1930 obj_surface->bo, in_wpitch * in_hpitch,
1931 in_w / 2, in_h / 2, in_wpitch,
1933 SURFACE_FORMAT_R8B8_UNORM, 0,
1936 /* destination surface */
1937 obj_surface = SURFACE(dst_surface->id);
1938 out_w = obj_surface->orig_width;
1939 out_h = obj_surface->orig_height;
1940 out_wpitch = obj_surface->width;
1941 out_hpitch = obj_surface->height;
1942 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1944 /* destination Y surface index 7 */
1945 i965_pp_set_surface_state(ctx, pp_context,
1947 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1950 /* destination UV surface index 8 */
1951 i965_pp_set_surface_state(ctx, pp_context,
1952 obj_surface->bo, out_wpitch * out_hpitch,
1953 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1956 /* sampler 8x8 state */
1957 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1958 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1959 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1960 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1961 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1963 for (i = 0; i < 17; i++) {
1964 /* for Y channel, currently ignore */
1965 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x00;
1966 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x00;
1967 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x08;
1968 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x18;
1969 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x18;
1970 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x08;
1971 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x00;
1972 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x00;
1973 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x00;
1974 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x00;
1975 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x10;
1976 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x10;
1977 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x10;
1978 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x10;
1979 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x00;
1980 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x00;
1981 /* for U/V channel, 0.25 */
1982 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
1983 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
1984 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
1985 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
1986 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
1987 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
1988 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
1989 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
1990 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
1991 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
1992 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
1993 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
1994 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
1995 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
1996 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
1997 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
2000 sampler_8x8_state->dw136.default_sharpness_level = 0;
2001 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
2002 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
2003 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
2004 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
2007 dri_bo_map(pp_context->sampler_state_table.bo, True);
2008 assert(pp_context->sampler_state_table.bo->virtual);
2009 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
2010 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
2012 /* sample_8x8 Y index 1 */
2014 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2015 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
2016 sampler_8x8[index].dw0.ief_bypass = 1;
2017 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
2018 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
2019 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2020 sampler_8x8[index].dw2.global_noise_estimation = 22;
2021 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2022 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2023 sampler_8x8[index].dw3.strong_edge_weight = 7;
2024 sampler_8x8[index].dw3.regular_weight = 2;
2025 sampler_8x8[index].dw3.non_edge_weight = 0;
2026 sampler_8x8[index].dw3.gain_factor = 40;
2027 sampler_8x8[index].dw4.steepness_boost = 0;
2028 sampler_8x8[index].dw4.steepness_threshold = 0;
2029 sampler_8x8[index].dw4.mr_boost = 0;
2030 sampler_8x8[index].dw4.mr_threshold = 5;
2031 sampler_8x8[index].dw5.pwl1_point_1 = 4;
2032 sampler_8x8[index].dw5.pwl1_point_2 = 12;
2033 sampler_8x8[index].dw5.pwl1_point_3 = 16;
2034 sampler_8x8[index].dw5.pwl1_point_4 = 26;
2035 sampler_8x8[index].dw6.pwl1_point_5 = 40;
2036 sampler_8x8[index].dw6.pwl1_point_6 = 160;
2037 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
2038 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
2039 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
2040 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
2041 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
2042 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
2043 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
2044 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
2045 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
2046 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
2047 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
2048 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
2049 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
2050 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
2051 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
2052 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
2053 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
2054 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
2055 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
2056 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
2057 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
2058 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
2059 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
2060 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
2061 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
2062 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
2063 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
2064 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
2065 sampler_8x8[index].dw13.limiter_boost = 0;
2066 sampler_8x8[index].dw13.minimum_limiter = 10;
2067 sampler_8x8[index].dw13.maximum_limiter = 11;
2068 sampler_8x8[index].dw14.clip_limiter = 130;
2069 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2070 I915_GEM_DOMAIN_RENDER,
2073 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2074 pp_context->sampler_state_table.bo_8x8);
2076 /* sample_8x8 UV index 2 */
2078 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2079 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
2080 sampler_8x8[index].dw0.ief_bypass = 1;
2081 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
2082 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
2083 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2084 sampler_8x8[index].dw2.global_noise_estimation = 22;
2085 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2086 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2087 sampler_8x8[index].dw3.strong_edge_weight = 7;
2088 sampler_8x8[index].dw3.regular_weight = 2;
2089 sampler_8x8[index].dw3.non_edge_weight = 0;
2090 sampler_8x8[index].dw3.gain_factor = 40;
2091 sampler_8x8[index].dw4.steepness_boost = 0;
2092 sampler_8x8[index].dw4.steepness_threshold = 0;
2093 sampler_8x8[index].dw4.mr_boost = 0;
2094 sampler_8x8[index].dw4.mr_threshold = 5;
2095 sampler_8x8[index].dw5.pwl1_point_1 = 4;
2096 sampler_8x8[index].dw5.pwl1_point_2 = 12;
2097 sampler_8x8[index].dw5.pwl1_point_3 = 16;
2098 sampler_8x8[index].dw5.pwl1_point_4 = 26;
2099 sampler_8x8[index].dw6.pwl1_point_5 = 40;
2100 sampler_8x8[index].dw6.pwl1_point_6 = 160;
2101 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
2102 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
2103 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
2104 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
2105 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
2106 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
2107 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
2108 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
2109 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
2110 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
2111 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
2112 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
2113 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
2114 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
2115 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
2116 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
2117 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
2118 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
2119 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
2120 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
2121 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
2122 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
2123 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
2124 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
2125 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
2126 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
2127 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
2128 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
2129 sampler_8x8[index].dw13.limiter_boost = 0;
2130 sampler_8x8[index].dw13.minimum_limiter = 10;
2131 sampler_8x8[index].dw13.maximum_limiter = 11;
2132 sampler_8x8[index].dw14.clip_limiter = 130;
2133 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2134 I915_GEM_DOMAIN_RENDER,
2137 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2138 pp_context->sampler_state_table.bo_8x8);
2140 dri_bo_unmap(pp_context->sampler_state_table.bo);
2142 /* private function & data */
2143 pp_context->pp_x_steps = pp_avs_x_steps;
2144 pp_context->pp_y_steps = pp_avs_y_steps;
2145 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
2147 pp_avs_context->dest_x = dst_rect->x;
2148 pp_avs_context->dest_y = dst_rect->y;
2149 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
2150 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
2151 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w;
2152 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h;
2153 pp_avs_context->src_w = src_rect->width;
2154 pp_avs_context->src_h = src_rect->height;
2156 pp_static_parameter->grf4.r4_2.avs.nlas = nlas;
2157 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
2159 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / dst_rect->width;
2160 pp_inline_parameter->grf5.block_count_x = 1; /* M x 1 */
2161 pp_inline_parameter->grf5.number_blocks = pp_avs_context->dest_h / 8;
2162 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2163 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2164 pp_inline_parameter->grf6.video_step_delta = 0.0;
2166 dst_surface->flags = src_surface->flags;
2168 return VA_STATUS_SUCCESS;
2172 pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2173 const struct i965_surface *src_surface,
2174 const VARectangle *src_rect,
2175 struct i965_surface *dst_surface,
2176 const VARectangle *dst_rect,
2179 return pp_nv12_avs_initialize(ctx, pp_context,
2189 gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2190 const struct i965_surface *src_surface,
2191 const VARectangle *src_rect,
2192 struct i965_surface *dst_surface,
2193 const VARectangle *dst_rect,
2196 return pp_nv12_avs_initialize(ctx, pp_context,
2206 gen7_pp_avs_x_steps(void *private_context)
2208 struct pp_avs_context *pp_avs_context = private_context;
2210 return pp_avs_context->dest_w / 16;
2214 gen7_pp_avs_y_steps(void *private_context)
2216 struct pp_avs_context *pp_avs_context = private_context;
2218 return pp_avs_context->dest_h / 16;
2222 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2224 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
2225 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2227 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
2228 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
2229 pp_inline_parameter->grf7.constant_0 = 0xffffffff;
2230 pp_inline_parameter->grf7.sampler_load_main_video_x_scaling_step = 1.0 / pp_avs_context->src_w;
2235 static void gen7_update_src_surface_uv_offset(VADriverContextP ctx,
2236 struct i965_post_processing_context *pp_context,
2237 const struct i965_surface *surface)
2239 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2240 int fourcc = pp_get_surface_fourcc(ctx, surface);
2242 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
2243 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2244 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2245 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2246 } else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
2247 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 1;
2248 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 0;
2249 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 2;
2254 gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2255 const struct i965_surface *src_surface,
2256 const VARectangle *src_rect,
2257 struct i965_surface *dst_surface,
2258 const VARectangle *dst_rect,
2261 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
2262 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2263 struct gen7_sampler_8x8 *sampler_8x8;
2264 struct i965_sampler_8x8_state *sampler_8x8_state;
2266 int width[3], height[3], pitch[3], offset[3];
2268 /* source surface */
2269 gen7_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
2270 width, height, pitch, offset);
2272 /* destination surface */
2273 gen7_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
2274 width, height, pitch, offset);
2276 /* sampler 8x8 state */
2277 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
2278 assert(pp_context->sampler_state_table.bo_8x8->virtual);
2279 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
2280 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
2281 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
2283 for (i = 0; i < 17; i++) {
2284 /* for Y channel, currently ignore */
2285 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
2286 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
2287 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
2288 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x0;
2289 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x0;
2290 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
2291 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
2292 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
2293 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
2294 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
2295 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
2296 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x0;
2297 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x0;
2298 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
2299 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
2300 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
2301 /* for U/V channel, 0.25 */
2302 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
2303 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
2304 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
2305 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
2306 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
2307 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
2308 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
2309 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
2310 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
2311 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
2312 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
2313 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
2314 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
2315 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
2316 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
2317 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
2320 sampler_8x8_state->dw136.default_sharpness_level = 0;
2321 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
2322 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
2323 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
2324 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
2327 dri_bo_map(pp_context->sampler_state_table.bo, True);
2328 assert(pp_context->sampler_state_table.bo->virtual);
2329 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
2330 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
2332 /* sample_8x8 Y index 4 */
2334 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2335 sampler_8x8[index].dw0.global_noise_estimation = 255;
2336 sampler_8x8[index].dw0.ief_bypass = 1;
2338 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2340 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2341 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2342 sampler_8x8[index].dw2.r5x_coefficient = 9;
2343 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2344 sampler_8x8[index].dw2.r5c_coefficient = 3;
2346 sampler_8x8[index].dw3.r3x_coefficient = 27;
2347 sampler_8x8[index].dw3.r3c_coefficient = 5;
2348 sampler_8x8[index].dw3.gain_factor = 40;
2349 sampler_8x8[index].dw3.non_edge_weight = 1;
2350 sampler_8x8[index].dw3.regular_weight = 2;
2351 sampler_8x8[index].dw3.strong_edge_weight = 7;
2352 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2354 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2355 I915_GEM_DOMAIN_RENDER,
2358 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2359 pp_context->sampler_state_table.bo_8x8);
2361 /* sample_8x8 UV index 8 */
2363 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2364 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2365 sampler_8x8[index].dw0.global_noise_estimation = 255;
2366 sampler_8x8[index].dw0.ief_bypass = 1;
2367 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2368 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2369 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2370 sampler_8x8[index].dw2.r5x_coefficient = 9;
2371 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2372 sampler_8x8[index].dw2.r5c_coefficient = 3;
2373 sampler_8x8[index].dw3.r3x_coefficient = 27;
2374 sampler_8x8[index].dw3.r3c_coefficient = 5;
2375 sampler_8x8[index].dw3.gain_factor = 40;
2376 sampler_8x8[index].dw3.non_edge_weight = 1;
2377 sampler_8x8[index].dw3.regular_weight = 2;
2378 sampler_8x8[index].dw3.strong_edge_weight = 7;
2379 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2381 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2382 I915_GEM_DOMAIN_RENDER,
2385 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2386 pp_context->sampler_state_table.bo_8x8);
2388 /* sampler_8x8 V, index 12 */
2390 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2391 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2392 sampler_8x8[index].dw0.global_noise_estimation = 255;
2393 sampler_8x8[index].dw0.ief_bypass = 1;
2394 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2395 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2396 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2397 sampler_8x8[index].dw2.r5x_coefficient = 9;
2398 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2399 sampler_8x8[index].dw2.r5c_coefficient = 3;
2400 sampler_8x8[index].dw3.r3x_coefficient = 27;
2401 sampler_8x8[index].dw3.r3c_coefficient = 5;
2402 sampler_8x8[index].dw3.gain_factor = 40;
2403 sampler_8x8[index].dw3.non_edge_weight = 1;
2404 sampler_8x8[index].dw3.regular_weight = 2;
2405 sampler_8x8[index].dw3.strong_edge_weight = 7;
2406 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2408 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2409 I915_GEM_DOMAIN_RENDER,
2412 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2413 pp_context->sampler_state_table.bo_8x8);
2415 dri_bo_unmap(pp_context->sampler_state_table.bo);
2417 /* private function & data */
2418 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
2419 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
2420 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
2422 pp_avs_context->dest_x = dst_rect->x;
2423 pp_avs_context->dest_y = dst_rect->y;
2424 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
2425 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
2426 pp_avs_context->src_w = src_rect->width;
2427 pp_avs_context->src_h = src_rect->height;
2429 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
2430 dw = MAX(dw, pp_avs_context->dest_w);
2432 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2433 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
2434 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) 1.0 / pp_avs_context->dest_h;
2435 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = -(float)pp_avs_context->dest_y / pp_avs_context->dest_h;
2436 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = -(float)pp_avs_context->dest_x / dw;
2438 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
2440 dst_surface->flags = src_surface->flags;
2442 return VA_STATUS_SUCCESS;
2446 pp_dndi_x_steps(void *private_context)
2452 pp_dndi_y_steps(void *private_context)
2454 struct pp_dndi_context *pp_dndi_context = private_context;
2456 return pp_dndi_context->dest_h / 4;
2460 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2462 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2464 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2465 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
2471 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2472 const struct i965_surface *src_surface,
2473 const VARectangle *src_rect,
2474 struct i965_surface *dst_surface,
2475 const VARectangle *dst_rect,
2478 struct i965_driver_data *i965 = i965_driver_data(ctx);
2479 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2480 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2481 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2482 struct object_surface *obj_surface;
2483 struct i965_sampler_dndi *sampler_dndi;
2487 int dndi_top_first = 1;
2489 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2490 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2492 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2498 obj_surface = SURFACE(src_surface->id);
2499 orig_w = obj_surface->orig_width;
2500 orig_h = obj_surface->orig_height;
2501 w = obj_surface->width;
2502 h = obj_surface->height;
2504 if (pp_context->stmm.bo == NULL) {
2505 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2509 assert(pp_context->stmm.bo);
2512 /* source UV surface index 2 */
2513 i965_pp_set_surface_state(ctx, pp_context,
2514 obj_surface->bo, w * h,
2515 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2518 /* source YUV surface index 4 */
2519 i965_pp_set_surface2_state(ctx, pp_context,
2523 SURFACE_FORMAT_PLANAR_420_8, 1,
2526 /* source STMM surface index 20 */
2527 i965_pp_set_surface_state(ctx, pp_context,
2528 pp_context->stmm.bo, 0,
2529 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2532 /* destination surface */
2533 obj_surface = SURFACE(dst_surface->id);
2534 orig_w = obj_surface->orig_width;
2535 orig_h = obj_surface->orig_height;
2536 w = obj_surface->width;
2537 h = obj_surface->height;
2539 /* destination Y surface index 7 */
2540 i965_pp_set_surface_state(ctx, pp_context,
2542 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2545 /* destination UV surface index 8 */
2546 i965_pp_set_surface_state(ctx, pp_context,
2547 obj_surface->bo, w * h,
2548 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2551 dri_bo_map(pp_context->sampler_state_table.bo, True);
2552 assert(pp_context->sampler_state_table.bo->virtual);
2553 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2554 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2556 /* sample dndi index 1 */
2558 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2559 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2560 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2561 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2563 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2564 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 4;
2565 sampler_dndi[index].dw1.stmm_c2 = 1;
2566 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2567 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2569 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2570 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2571 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2572 sampler_dndi[index].dw2.good_neighbor_threshold = 4; // 0-63
2574 sampler_dndi[index].dw3.maximum_stmm = 128;
2575 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2576 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2577 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2578 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2580 sampler_dndi[index].dw4.sdi_delta = 8;
2581 sampler_dndi[index].dw4.sdi_threshold = 128;
2582 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2583 sampler_dndi[index].dw4.stmm_shift_up = 0;
2584 sampler_dndi[index].dw4.stmm_shift_down = 0;
2585 sampler_dndi[index].dw4.minimum_stmm = 0;
2587 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 8;
2588 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 32;
2589 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 64;
2590 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 32;
2592 sampler_dndi[index].dw6.dn_enable = 1;
2593 sampler_dndi[index].dw6.di_enable = 1;
2594 sampler_dndi[index].dw6.di_partial = 0;
2595 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2596 sampler_dndi[index].dw6.dndi_stream_id = 0;
2597 sampler_dndi[index].dw6.dndi_first_frame = 1;
2598 sampler_dndi[index].dw6.progressive_dn = 0;
2599 sampler_dndi[index].dw6.fmd_tear_threshold = 63;
2600 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2601 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2603 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
2604 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
2605 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2606 sampler_dndi[index].dw7.column_width_minus1 = 0;
2608 dri_bo_unmap(pp_context->sampler_state_table.bo);
2610 /* private function & data */
2611 pp_context->pp_x_steps = pp_dndi_x_steps;
2612 pp_context->pp_y_steps = pp_dndi_y_steps;
2613 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
2615 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2616 pp_static_parameter->grf1.r1_6.di.top_field_first = dndi_top_first;
2617 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 0;
2618 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 0;
2620 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2621 pp_inline_parameter->grf5.number_blocks = w / 16;
2622 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2623 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2625 pp_dndi_context->dest_w = w;
2626 pp_dndi_context->dest_h = h;
2628 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
2630 return VA_STATUS_SUCCESS;
2634 pp_dn_x_steps(void *private_context)
2640 pp_dn_y_steps(void *private_context)
2642 struct pp_dn_context *pp_dn_context = private_context;
2644 return pp_dn_context->dest_h / 8;
2648 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2650 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2652 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2653 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
2659 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2660 const struct i965_surface *src_surface,
2661 const VARectangle *src_rect,
2662 struct i965_surface *dst_surface,
2663 const VARectangle *dst_rect,
2666 struct i965_driver_data *i965 = i965_driver_data(ctx);
2667 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
2668 struct object_surface *obj_surface;
2669 struct i965_sampler_dndi *sampler_dndi;
2670 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2671 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2672 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
2676 int dn_strength = 15;
2677 int dndi_top_first = 1;
2678 int dn_progressive = 0;
2680 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
2683 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
2691 if (dn_filter_param) {
2692 float value = dn_filter_param->value;
2700 dn_strength = (int)(value * 31.0F);
2704 obj_surface = SURFACE(src_surface->id);
2705 orig_w = obj_surface->orig_width;
2706 orig_h = obj_surface->orig_height;
2707 w = obj_surface->width;
2708 h = obj_surface->height;
2710 if (pp_context->stmm.bo == NULL) {
2711 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2715 assert(pp_context->stmm.bo);
2718 /* source UV surface index 2 */
2719 i965_pp_set_surface_state(ctx, pp_context,
2720 obj_surface->bo, w * h,
2721 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2724 /* source YUV surface index 4 */
2725 i965_pp_set_surface2_state(ctx, pp_context,
2729 SURFACE_FORMAT_PLANAR_420_8, 1,
2732 /* source STMM surface index 20 */
2733 i965_pp_set_surface_state(ctx, pp_context,
2734 pp_context->stmm.bo, 0,
2735 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2738 /* destination surface */
2739 obj_surface = SURFACE(dst_surface->id);
2740 orig_w = obj_surface->orig_width;
2741 orig_h = obj_surface->orig_height;
2742 w = obj_surface->width;
2743 h = obj_surface->height;
2745 /* destination Y surface index 7 */
2746 i965_pp_set_surface_state(ctx, pp_context,
2748 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2751 /* destination UV surface index 8 */
2752 i965_pp_set_surface_state(ctx, pp_context,
2753 obj_surface->bo, w * h,
2754 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2757 dri_bo_map(pp_context->sampler_state_table.bo, True);
2758 assert(pp_context->sampler_state_table.bo->virtual);
2759 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2760 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2762 /* sample dndi index 1 */
2764 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2765 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
2766 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2767 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2769 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2770 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2771 sampler_dndi[index].dw1.stmm_c2 = 0;
2772 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2773 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2775 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
2776 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
2777 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
2778 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
2780 sampler_dndi[index].dw3.maximum_stmm = 128;
2781 sampler_dndi[index].dw3.multipler_for_vecm = 2;
2782 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
2783 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
2784 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
2786 sampler_dndi[index].dw4.sdi_delta = 8;
2787 sampler_dndi[index].dw4.sdi_threshold = 128;
2788 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
2789 sampler_dndi[index].dw4.stmm_shift_up = 0;
2790 sampler_dndi[index].dw4.stmm_shift_down = 0;
2791 sampler_dndi[index].dw4.minimum_stmm = 0;
2793 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
2794 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
2795 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
2796 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
2798 sampler_dndi[index].dw6.dn_enable = 1;
2799 sampler_dndi[index].dw6.di_enable = 0;
2800 sampler_dndi[index].dw6.di_partial = 0;
2801 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
2802 sampler_dndi[index].dw6.dndi_stream_id = 1;
2803 sampler_dndi[index].dw6.dndi_first_frame = 1;
2804 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
2805 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
2806 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
2807 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
2809 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
2810 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
2811 sampler_dndi[index].dw7.vdi_walker_enable = 0;
2812 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
2814 dri_bo_unmap(pp_context->sampler_state_table.bo);
2816 /* private function & data */
2817 pp_context->pp_x_steps = pp_dn_x_steps;
2818 pp_context->pp_y_steps = pp_dn_y_steps;
2819 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
2821 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
2822 pp_static_parameter->grf1.r1_6.di.top_field_first = 0;
2823 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 64;
2824 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 192;
2826 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
2827 pp_inline_parameter->grf5.number_blocks = w / 16;
2828 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
2829 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
2831 pp_dn_context->dest_w = w;
2832 pp_dn_context->dest_h = h;
2834 dst_surface->flags = src_surface->flags;
2836 return VA_STATUS_SUCCESS;
2840 gen7_pp_dndi_x_steps(void *private_context)
2842 struct pp_dndi_context *pp_dndi_context = private_context;
2844 return pp_dndi_context->dest_w / 16;
2848 gen7_pp_dndi_y_steps(void *private_context)
2850 struct pp_dndi_context *pp_dndi_context = private_context;
2852 return pp_dndi_context->dest_h / 4;
2856 gen7_pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2858 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2860 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16;
2861 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 4;
2867 gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2868 const struct i965_surface *src_surface,
2869 const VARectangle *src_rect,
2870 struct i965_surface *dst_surface,
2871 const VARectangle *dst_rect,
2874 struct i965_driver_data *i965 = i965_driver_data(ctx);
2875 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
2876 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2877 struct object_surface *obj_surface;
2878 struct gen7_sampler_dndi *sampler_dndi;
2882 int dndi_top_first = 1;
2884 if (src_surface->flags == I965_SURFACE_FLAG_FRAME)
2885 return VA_STATUS_ERROR_FLAG_NOT_SUPPORTED;
2887 if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST)
2893 obj_surface = SURFACE(src_surface->id);
2894 orig_w = obj_surface->orig_width;
2895 orig_h = obj_surface->orig_height;
2896 w = obj_surface->width;
2897 h = obj_surface->height;
2899 if (pp_context->stmm.bo == NULL) {
2900 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
2904 assert(pp_context->stmm.bo);
2907 /* source UV surface index 1 */
2908 gen7_pp_set_surface_state(ctx, pp_context,
2909 obj_surface->bo, w * h,
2910 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2913 /* source YUV surface index 3 */
2914 gen7_pp_set_surface2_state(ctx, pp_context,
2918 SURFACE_FORMAT_PLANAR_420_8, 1,
2921 /* source (temporal reference) YUV surface index 4 */
2922 gen7_pp_set_surface2_state(ctx, pp_context,
2926 SURFACE_FORMAT_PLANAR_420_8, 1,
2929 /* STMM / History Statistics input surface, index 5 */
2930 gen7_pp_set_surface_state(ctx, pp_context,
2931 pp_context->stmm.bo, 0,
2932 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2935 /* destination surface */
2936 obj_surface = SURFACE(dst_surface->id);
2937 orig_w = obj_surface->orig_width;
2938 orig_h = obj_surface->orig_height;
2939 w = obj_surface->width;
2940 h = obj_surface->height;
2942 /* destination(Previous frame) Y surface index 27 */
2943 gen7_pp_set_surface_state(ctx, pp_context,
2945 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2948 /* destination(Previous frame) UV surface index 28 */
2949 gen7_pp_set_surface_state(ctx, pp_context,
2950 obj_surface->bo, w * h,
2951 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2954 /* destination(Current frame) Y surface index 30 */
2955 gen7_pp_set_surface_state(ctx, pp_context,
2957 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2960 /* destination(Current frame) UV surface index 31 */
2961 gen7_pp_set_surface_state(ctx, pp_context,
2962 obj_surface->bo, w * h,
2963 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
2966 /* STMM output surface, index 33 */
2967 gen7_pp_set_surface_state(ctx, pp_context,
2968 pp_context->stmm.bo, 0,
2969 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
2974 dri_bo_map(pp_context->sampler_state_table.bo, True);
2975 assert(pp_context->sampler_state_table.bo->virtual);
2976 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
2977 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
2979 /* sample dndi index 0 */
2981 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
2982 sampler_dndi[index].dw0.dnmh_delt = 8;
2983 sampler_dndi[index].dw0.vdi_walker_y_stride = 0;
2984 sampler_dndi[index].dw0.vdi_walker_frame_sharing_enable = 0;
2985 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
2986 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
2988 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
2989 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
2990 sampler_dndi[index].dw1.stmm_c2 = 0;
2991 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
2992 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
2994 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
2995 sampler_dndi[index].dw2.bne_edge_th = 1;
2996 sampler_dndi[index].dw2.smooth_mv_th = 0;
2997 sampler_dndi[index].dw2.sad_tight_th = 5;
2998 sampler_dndi[index].dw2.cat_slope_minus1 = 9;
2999 sampler_dndi[index].dw2.good_neighbor_th = 4;
3001 sampler_dndi[index].dw3.maximum_stmm = 128;
3002 sampler_dndi[index].dw3.multipler_for_vecm = 2;
3003 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
3004 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3005 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
3007 sampler_dndi[index].dw4.sdi_delta = 8;
3008 sampler_dndi[index].dw4.sdi_threshold = 128;
3009 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3010 sampler_dndi[index].dw4.stmm_shift_up = 0;
3011 sampler_dndi[index].dw4.stmm_shift_down = 0;
3012 sampler_dndi[index].dw4.minimum_stmm = 0;
3014 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
3015 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
3016 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
3017 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
3019 sampler_dndi[index].dw6.dn_enable = 0;
3020 sampler_dndi[index].dw6.di_enable = 1;
3021 sampler_dndi[index].dw6.di_partial = 0;
3022 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
3023 sampler_dndi[index].dw6.dndi_stream_id = 1;
3024 sampler_dndi[index].dw6.dndi_first_frame = 1;
3025 sampler_dndi[index].dw6.progressive_dn = 0;
3026 sampler_dndi[index].dw6.mcdi_enable = 0;
3027 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
3028 sampler_dndi[index].dw6.cat_th1 = 0;
3029 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
3030 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
3032 sampler_dndi[index].dw7.sad_tha = 5;
3033 sampler_dndi[index].dw7.sad_thb = 10;
3034 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
3035 sampler_dndi[index].dw7.mc_pixel_consistency_th = 25;
3036 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
3037 sampler_dndi[index].dw7.vdi_walker_enable = 0;
3038 sampler_dndi[index].dw7.neighborpixel_th = 10;
3039 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
3041 dri_bo_unmap(pp_context->sampler_state_table.bo);
3043 /* private function & data */
3044 pp_context->pp_x_steps = gen7_pp_dndi_x_steps;
3045 pp_context->pp_y_steps = gen7_pp_dndi_y_steps;
3046 pp_context->pp_set_block_parameter = gen7_pp_dndi_set_block_parameter;
3048 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
3049 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
3050 pp_static_parameter->grf1.di_top_field_first = 0;
3051 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3053 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3054 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3055 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3057 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
3058 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3060 pp_dndi_context->dest_w = w;
3061 pp_dndi_context->dest_h = h;
3063 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
3065 return VA_STATUS_SUCCESS;
3069 gen7_pp_dn_x_steps(void *private_context)
3075 gen7_pp_dn_y_steps(void *private_context)
3077 struct pp_dn_context *pp_dn_context = private_context;
3079 return pp_dn_context->dest_h / 4;
3083 gen7_pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3085 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3087 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
3088 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
3094 gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3095 const struct i965_surface *src_surface,
3096 const VARectangle *src_rect,
3097 struct i965_surface *dst_surface,
3098 const VARectangle *dst_rect,
3101 struct i965_driver_data *i965 = i965_driver_data(ctx);
3102 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->private_context;
3103 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3104 struct object_surface *obj_surface;
3105 struct gen7_sampler_dndi *sampler_dn;
3106 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
3110 int dn_strength = 15;
3111 int dndi_top_first = 1;
3112 int dn_progressive = 0;
3114 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
3117 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
3125 if (dn_filter_param) {
3126 float value = dn_filter_param->value;
3134 dn_strength = (int)(value * 31.0F);
3138 obj_surface = SURFACE(src_surface->id);
3139 orig_w = obj_surface->orig_width;
3140 orig_h = obj_surface->orig_height;
3141 w = obj_surface->width;
3142 h = obj_surface->height;
3144 if (pp_context->stmm.bo == NULL) {
3145 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
3149 assert(pp_context->stmm.bo);
3152 /* source UV surface index 1 */
3153 gen7_pp_set_surface_state(ctx, pp_context,
3154 obj_surface->bo, w * h,
3155 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3158 /* source YUV surface index 3 */
3159 gen7_pp_set_surface2_state(ctx, pp_context,
3163 SURFACE_FORMAT_PLANAR_420_8, 1,
3166 /* source STMM surface index 5 */
3167 gen7_pp_set_surface_state(ctx, pp_context,
3168 pp_context->stmm.bo, 0,
3169 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3172 /* destination surface */
3173 obj_surface = SURFACE(dst_surface->id);
3174 orig_w = obj_surface->orig_width;
3175 orig_h = obj_surface->orig_height;
3176 w = obj_surface->width;
3177 h = obj_surface->height;
3179 /* destination Y surface index 7 */
3180 gen7_pp_set_surface_state(ctx, pp_context,
3182 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3185 /* destination UV surface index 8 */
3186 gen7_pp_set_surface_state(ctx, pp_context,
3187 obj_surface->bo, w * h,
3188 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3191 dri_bo_map(pp_context->sampler_state_table.bo, True);
3192 assert(pp_context->sampler_state_table.bo->virtual);
3193 assert(sizeof(*sampler_dn) == sizeof(int) * 8);
3194 sampler_dn = pp_context->sampler_state_table.bo->virtual;
3196 /* sample dn index 1 */
3198 sampler_dn[index].dw0.denoise_asd_threshold = 0;
3199 sampler_dn[index].dw0.dnmh_delt = 8;
3200 sampler_dn[index].dw0.vdi_walker_y_stride = 0;
3201 sampler_dn[index].dw0.vdi_walker_frame_sharing_enable = 0;
3202 sampler_dn[index].dw0.denoise_maximum_history = 128; // 128-240
3203 sampler_dn[index].dw0.denoise_stad_threshold = 0;
3205 sampler_dn[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
3206 sampler_dn[index].dw1.denoise_moving_pixel_threshold = 0;
3207 sampler_dn[index].dw1.stmm_c2 = 0;
3208 sampler_dn[index].dw1.low_temporal_difference_threshold = 8;
3209 sampler_dn[index].dw1.temporal_difference_threshold = 16;
3211 sampler_dn[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
3212 sampler_dn[index].dw2.bne_edge_th = 1;
3213 sampler_dn[index].dw2.smooth_mv_th = 0;
3214 sampler_dn[index].dw2.sad_tight_th = 5;
3215 sampler_dn[index].dw2.cat_slope_minus1 = 9;
3216 sampler_dn[index].dw2.good_neighbor_th = 4;
3218 sampler_dn[index].dw3.maximum_stmm = 128;
3219 sampler_dn[index].dw3.multipler_for_vecm = 2;
3220 sampler_dn[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
3221 sampler_dn[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3222 sampler_dn[index].dw3.stmm_blending_constant_select = 0;
3224 sampler_dn[index].dw4.sdi_delta = 8;
3225 sampler_dn[index].dw4.sdi_threshold = 128;
3226 sampler_dn[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3227 sampler_dn[index].dw4.stmm_shift_up = 0;
3228 sampler_dn[index].dw4.stmm_shift_down = 0;
3229 sampler_dn[index].dw4.minimum_stmm = 0;
3231 sampler_dn[index].dw5.fmd_temporal_difference_threshold = 0;
3232 sampler_dn[index].dw5.sdi_fallback_mode_2_constant = 0;
3233 sampler_dn[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
3234 sampler_dn[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
3236 sampler_dn[index].dw6.dn_enable = 1;
3237 sampler_dn[index].dw6.di_enable = 0;
3238 sampler_dn[index].dw6.di_partial = 0;
3239 sampler_dn[index].dw6.dndi_top_first = dndi_top_first;
3240 sampler_dn[index].dw6.dndi_stream_id = 1;
3241 sampler_dn[index].dw6.dndi_first_frame = 1;
3242 sampler_dn[index].dw6.progressive_dn = dn_progressive;
3243 sampler_dn[index].dw6.mcdi_enable = 0;
3244 sampler_dn[index].dw6.fmd_tear_threshold = 32;
3245 sampler_dn[index].dw6.cat_th1 = 0;
3246 sampler_dn[index].dw6.fmd2_vertical_difference_threshold = 32;
3247 sampler_dn[index].dw6.fmd1_vertical_difference_threshold = 32;
3249 sampler_dn[index].dw7.sad_tha = 5;
3250 sampler_dn[index].dw7.sad_thb = 10;
3251 sampler_dn[index].dw7.fmd_for_1st_field_of_current_frame = 2;
3252 sampler_dn[index].dw7.mc_pixel_consistency_th = 25;
3253 sampler_dn[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
3254 sampler_dn[index].dw7.vdi_walker_enable = 0;
3255 sampler_dn[index].dw7.neighborpixel_th = 10;
3256 sampler_dn[index].dw7.column_width_minus1 = w / 16;
3258 dri_bo_unmap(pp_context->sampler_state_table.bo);
3260 /* private function & data */
3261 pp_context->pp_x_steps = gen7_pp_dn_x_steps;
3262 pp_context->pp_y_steps = gen7_pp_dn_y_steps;
3263 pp_context->pp_set_block_parameter = gen7_pp_dn_set_block_parameter;
3265 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
3266 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
3267 pp_static_parameter->grf1.di_top_field_first = 0;
3268 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3270 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3271 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3272 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3274 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
3275 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3277 pp_dn_context->dest_w = w;
3278 pp_dn_context->dest_h = h;
3280 dst_surface->flags = src_surface->flags;
3282 return VA_STATUS_SUCCESS;
3286 ironlake_pp_initialize(
3287 VADriverContextP ctx,
3288 struct i965_post_processing_context *pp_context,
3289 const struct i965_surface *src_surface,
3290 const VARectangle *src_rect,
3291 struct i965_surface *dst_surface,
3292 const VARectangle *dst_rect,
3298 struct i965_driver_data *i965 = i965_driver_data(ctx);
3299 struct pp_module *pp_module;
3301 int static_param_size, inline_param_size;
3303 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3304 bo = dri_bo_alloc(i965->intel.bufmgr,
3305 "surface state & binding table",
3306 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
3309 pp_context->surface_state_binding_table.bo = bo;
3311 dri_bo_unreference(pp_context->curbe.bo);
3312 bo = dri_bo_alloc(i965->intel.bufmgr,
3317 pp_context->curbe.bo = bo;
3319 dri_bo_unreference(pp_context->idrt.bo);
3320 bo = dri_bo_alloc(i965->intel.bufmgr,
3321 "interface discriptor",
3322 sizeof(struct i965_interface_descriptor),
3325 pp_context->idrt.bo = bo;
3326 pp_context->idrt.num_interface_descriptors = 0;
3328 dri_bo_unreference(pp_context->sampler_state_table.bo);
3329 bo = dri_bo_alloc(i965->intel.bufmgr,
3330 "sampler state table",
3334 dri_bo_map(bo, True);
3335 memset(bo->virtual, 0, bo->size);
3337 pp_context->sampler_state_table.bo = bo;
3339 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3340 bo = dri_bo_alloc(i965->intel.bufmgr,
3341 "sampler 8x8 state ",
3345 pp_context->sampler_state_table.bo_8x8 = bo;
3347 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3348 bo = dri_bo_alloc(i965->intel.bufmgr,
3349 "sampler 8x8 state ",
3353 pp_context->sampler_state_table.bo_8x8_uv = bo;
3355 dri_bo_unreference(pp_context->vfe_state.bo);
3356 bo = dri_bo_alloc(i965->intel.bufmgr,
3358 sizeof(struct i965_vfe_state),
3361 pp_context->vfe_state.bo = bo;
3363 static_param_size = sizeof(struct pp_static_parameter);
3364 inline_param_size = sizeof(struct pp_inline_parameter);
3366 memset(pp_context->pp_static_parameter, 0, static_param_size);
3367 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
3369 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3370 pp_context->current_pp = pp_index;
3371 pp_module = &pp_context->pp_modules[pp_index];
3373 if (pp_module->initialize)
3374 va_status = pp_module->initialize(ctx, pp_context,
3381 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3387 ironlake_post_processing(
3388 VADriverContextP ctx,
3389 struct i965_post_processing_context *pp_context,
3390 const struct i965_surface *src_surface,
3391 const VARectangle *src_rect,
3392 struct i965_surface *dst_surface,
3393 const VARectangle *dst_rect,
3400 va_status = ironlake_pp_initialize(ctx, pp_context,
3408 if (va_status == VA_STATUS_SUCCESS) {
3409 ironlake_pp_states_setup(ctx, pp_context);
3410 ironlake_pp_pipeline_setup(ctx, pp_context);
3418 VADriverContextP ctx,
3419 struct i965_post_processing_context *pp_context,
3420 const struct i965_surface *src_surface,
3421 const VARectangle *src_rect,
3422 struct i965_surface *dst_surface,
3423 const VARectangle *dst_rect,
3429 struct i965_driver_data *i965 = i965_driver_data(ctx);
3430 struct pp_module *pp_module;
3432 int static_param_size, inline_param_size;
3434 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
3435 bo = dri_bo_alloc(i965->intel.bufmgr,
3436 "surface state & binding table",
3437 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
3440 pp_context->surface_state_binding_table.bo = bo;
3442 dri_bo_unreference(pp_context->curbe.bo);
3443 bo = dri_bo_alloc(i965->intel.bufmgr,
3448 pp_context->curbe.bo = bo;
3450 dri_bo_unreference(pp_context->idrt.bo);
3451 bo = dri_bo_alloc(i965->intel.bufmgr,
3452 "interface discriptor",
3453 sizeof(struct gen6_interface_descriptor_data),
3456 pp_context->idrt.bo = bo;
3457 pp_context->idrt.num_interface_descriptors = 0;
3459 dri_bo_unreference(pp_context->sampler_state_table.bo);
3460 bo = dri_bo_alloc(i965->intel.bufmgr,
3461 "sampler state table",
3465 dri_bo_map(bo, True);
3466 memset(bo->virtual, 0, bo->size);
3468 pp_context->sampler_state_table.bo = bo;
3470 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
3471 bo = dri_bo_alloc(i965->intel.bufmgr,
3472 "sampler 8x8 state ",
3476 pp_context->sampler_state_table.bo_8x8 = bo;
3478 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
3479 bo = dri_bo_alloc(i965->intel.bufmgr,
3480 "sampler 8x8 state ",
3484 pp_context->sampler_state_table.bo_8x8_uv = bo;
3486 dri_bo_unreference(pp_context->vfe_state.bo);
3487 bo = dri_bo_alloc(i965->intel.bufmgr,
3489 sizeof(struct i965_vfe_state),
3492 pp_context->vfe_state.bo = bo;
3494 if (IS_GEN7(i965->intel.device_id)) {
3495 static_param_size = sizeof(struct gen7_pp_static_parameter);
3496 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
3498 static_param_size = sizeof(struct pp_static_parameter);
3499 inline_param_size = sizeof(struct pp_inline_parameter);
3502 memset(pp_context->pp_static_parameter, 0, static_param_size);
3503 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
3505 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
3506 pp_context->current_pp = pp_index;
3507 pp_module = &pp_context->pp_modules[pp_index];
3509 if (pp_module->initialize)
3510 va_status = pp_module->initialize(ctx, pp_context,
3517 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
3523 gen6_pp_interface_descriptor_table(VADriverContextP ctx,
3524 struct i965_post_processing_context *pp_context)
3526 struct i965_driver_data *i965 = i965_driver_data(ctx);
3527 struct gen6_interface_descriptor_data *desc;
3529 int pp_index = pp_context->current_pp;
3531 bo = pp_context->idrt.bo;
3532 dri_bo_map(bo, True);
3533 assert(bo->virtual);
3535 memset(desc, 0, sizeof(*desc));
3536 desc->desc0.kernel_start_pointer =
3537 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
3538 desc->desc1.single_program_flow = 1;
3539 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
3540 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
3541 desc->desc2.sampler_state_pointer =
3542 pp_context->sampler_state_table.bo->offset >> 5;
3543 desc->desc3.binding_table_entry_count = 0;
3544 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
3545 desc->desc4.constant_urb_entry_read_offset = 0;
3547 if (IS_GEN7(i965->intel.device_id))
3548 desc->desc4.constant_urb_entry_read_length = 6; /* grf 1-6 */
3550 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
3552 dri_bo_emit_reloc(bo,
3553 I915_GEM_DOMAIN_INSTRUCTION, 0,
3555 offsetof(struct gen6_interface_descriptor_data, desc0),
3556 pp_context->pp_modules[pp_index].kernel.bo);
3558 dri_bo_emit_reloc(bo,
3559 I915_GEM_DOMAIN_INSTRUCTION, 0,
3560 desc->desc2.sampler_count << 2,
3561 offsetof(struct gen6_interface_descriptor_data, desc2),
3562 pp_context->sampler_state_table.bo);
3565 pp_context->idrt.num_interface_descriptors++;
3569 gen6_pp_upload_constants(VADriverContextP ctx,
3570 struct i965_post_processing_context *pp_context)
3572 struct i965_driver_data *i965 = i965_driver_data(ctx);
3573 unsigned char *constant_buffer;
3576 assert(sizeof(struct pp_static_parameter) == 128);
3577 assert(sizeof(struct gen7_pp_static_parameter) == 192);
3579 if (IS_GEN7(i965->intel.device_id))
3580 param_size = sizeof(struct gen7_pp_static_parameter);
3582 param_size = sizeof(struct pp_static_parameter);
3584 dri_bo_map(pp_context->curbe.bo, 1);
3585 assert(pp_context->curbe.bo->virtual);
3586 constant_buffer = pp_context->curbe.bo->virtual;
3587 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
3588 dri_bo_unmap(pp_context->curbe.bo);
3592 gen6_pp_states_setup(VADriverContextP ctx,
3593 struct i965_post_processing_context *pp_context)
3595 gen6_pp_interface_descriptor_table(ctx, pp_context);
3596 gen6_pp_upload_constants(ctx, pp_context);
3600 gen6_pp_pipeline_select(VADriverContextP ctx,
3601 struct i965_post_processing_context *pp_context)
3603 struct intel_batchbuffer *batch = pp_context->batch;
3605 BEGIN_BATCH(batch, 1);
3606 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
3607 ADVANCE_BATCH(batch);
3611 gen6_pp_state_base_address(VADriverContextP ctx,
3612 struct i965_post_processing_context *pp_context)
3614 struct intel_batchbuffer *batch = pp_context->batch;
3616 BEGIN_BATCH(batch, 10);
3617 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
3618 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3619 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
3620 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3621 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3622 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3623 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3624 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3625 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3626 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
3627 ADVANCE_BATCH(batch);
3631 gen6_pp_vfe_state(VADriverContextP ctx,
3632 struct i965_post_processing_context *pp_context)
3634 struct intel_batchbuffer *batch = pp_context->batch;
3636 BEGIN_BATCH(batch, 8);
3637 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
3638 OUT_BATCH(batch, 0);
3640 (pp_context->urb.num_vfe_entries - 1) << 16 |
3641 pp_context->urb.num_vfe_entries << 8);
3642 OUT_BATCH(batch, 0);
3644 (pp_context->urb.size_vfe_entry * 2) << 16 | /* URB Entry Allocation Size, in 256 bits unit */
3645 (pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2)); /* CURBE Allocation Size, in 256 bits unit */
3646 OUT_BATCH(batch, 0);
3647 OUT_BATCH(batch, 0);
3648 OUT_BATCH(batch, 0);
3649 ADVANCE_BATCH(batch);
3653 gen6_pp_curbe_load(VADriverContextP ctx,
3654 struct i965_post_processing_context *pp_context)
3656 struct intel_batchbuffer *batch = pp_context->batch;
3658 assert(pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32 <= pp_context->curbe.bo->size);
3660 BEGIN_BATCH(batch, 4);
3661 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
3662 OUT_BATCH(batch, 0);
3664 pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 * 32);
3666 pp_context->curbe.bo,
3667 I915_GEM_DOMAIN_INSTRUCTION, 0,
3669 ADVANCE_BATCH(batch);
3673 gen6_interface_descriptor_load(VADriverContextP ctx,
3674 struct i965_post_processing_context *pp_context)
3676 struct intel_batchbuffer *batch = pp_context->batch;
3678 BEGIN_BATCH(batch, 4);
3679 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
3680 OUT_BATCH(batch, 0);
3682 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
3684 pp_context->idrt.bo,
3685 I915_GEM_DOMAIN_INSTRUCTION, 0,
3687 ADVANCE_BATCH(batch);
3691 gen6_pp_object_walker(VADriverContextP ctx,
3692 struct i965_post_processing_context *pp_context)
3694 struct i965_driver_data *i965 = i965_driver_data(ctx);
3695 struct intel_batchbuffer *batch = pp_context->batch;
3696 int x, x_steps, y, y_steps;
3697 int param_size, command_length_in_dws;
3698 dri_bo *command_buffer;
3699 unsigned int *command_ptr;
3701 if (IS_GEN7(i965->intel.device_id))
3702 param_size = sizeof(struct gen7_pp_inline_parameter);
3704 param_size = sizeof(struct pp_inline_parameter);
3706 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
3707 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
3708 command_length_in_dws = 6 + (param_size >> 2);
3709 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
3710 "command objects buffer",
3711 command_length_in_dws * 4 * x_steps * y_steps + 8,
3714 dri_bo_map(command_buffer, 1);
3715 command_ptr = command_buffer->virtual;
3717 for (y = 0; y < y_steps; y++) {
3718 for (x = 0; x < x_steps; x++) {
3719 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
3720 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
3726 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
3727 command_ptr += (param_size >> 2);
3732 if (command_length_in_dws * x_steps * y_steps % 2 == 0)
3735 *command_ptr = MI_BATCH_BUFFER_END;
3737 dri_bo_unmap(command_buffer);
3739 BEGIN_BATCH(batch, 2);
3740 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (2 << 6));
3741 OUT_RELOC(batch, command_buffer,
3742 I915_GEM_DOMAIN_COMMAND, 0,
3744 ADVANCE_BATCH(batch);
3746 dri_bo_unreference(command_buffer);
3748 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
3749 * will cause control to pass back to ring buffer
3751 intel_batchbuffer_end_atomic(batch);
3752 intel_batchbuffer_flush(batch);
3753 intel_batchbuffer_start_atomic(batch, 0x1000);
3757 gen6_pp_pipeline_setup(VADriverContextP ctx,
3758 struct i965_post_processing_context *pp_context)
3760 struct intel_batchbuffer *batch = pp_context->batch;
3762 intel_batchbuffer_start_atomic(batch, 0x1000);
3763 intel_batchbuffer_emit_mi_flush(batch);
3764 gen6_pp_pipeline_select(ctx, pp_context);
3765 gen6_pp_state_base_address(ctx, pp_context);
3766 gen6_pp_vfe_state(ctx, pp_context);
3767 gen6_pp_curbe_load(ctx, pp_context);
3768 gen6_interface_descriptor_load(ctx, pp_context);
3769 gen6_pp_object_walker(ctx, pp_context);
3770 intel_batchbuffer_end_atomic(batch);
3774 gen6_post_processing(
3775 VADriverContextP ctx,
3776 struct i965_post_processing_context *pp_context,
3777 const struct i965_surface *src_surface,
3778 const VARectangle *src_rect,
3779 struct i965_surface *dst_surface,
3780 const VARectangle *dst_rect,
3787 va_status = gen6_pp_initialize(ctx, pp_context,
3795 if (va_status == VA_STATUS_SUCCESS) {
3796 gen6_pp_states_setup(ctx, pp_context);
3797 gen6_pp_pipeline_setup(ctx, pp_context);
3804 i965_post_processing_internal(
3805 VADriverContextP ctx,
3806 struct i965_post_processing_context *pp_context,
3807 const struct i965_surface *src_surface,
3808 const VARectangle *src_rect,
3809 struct i965_surface *dst_surface,
3810 const VARectangle *dst_rect,
3815 struct i965_driver_data *i965 = i965_driver_data(ctx);
3818 if (IS_GEN6(i965->intel.device_id) ||
3819 IS_GEN7(i965->intel.device_id))
3820 va_status = gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3822 va_status = ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
3828 i965_DestroySurfaces(VADriverContextP ctx,
3829 VASurfaceID *surface_list,
3832 i965_CreateSurfaces(VADriverContextP ctx,
3837 VASurfaceID *surfaces);
3840 rgb_to_yuv(unsigned int argb,
3846 int r = ((argb >> 16) & 0xff);
3847 int g = ((argb >> 8) & 0xff);
3848 int b = ((argb >> 0) & 0xff);
3850 *y = (257 * r + 504 * g + 98 * b) / 1000 + 16;
3851 *v = (439 * r - 368 * g - 71 * b) / 1000 + 128;
3852 *u = (-148 * r - 291 * g + 439 * b) / 1000 + 128;
3853 *a = ((argb >> 24) & 0xff);
3857 i965_vpp_clear_surface(VADriverContextP ctx,
3858 struct i965_post_processing_context *pp_context,
3859 VASurfaceID surface,
3862 struct i965_driver_data *i965 = i965_driver_data(ctx);
3863 struct intel_batchbuffer *batch = pp_context->batch;
3864 struct object_surface *obj_surface = SURFACE(surface);
3865 unsigned int blt_cmd, br13;
3866 unsigned int tiling = 0, swizzle = 0;
3868 unsigned char y, u, v, a = 0;
3870 /* Currently only support NV12 surface */
3871 if (!obj_surface || obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3874 rgb_to_yuv(color, &y, &u, &v, &a);
3879 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3880 blt_cmd = XY_COLOR_BLT_CMD;
3881 pitch = obj_surface->width;
3883 if (tiling != I915_TILING_NONE) {
3884 blt_cmd |= XY_COLOR_BLT_DST_TILED;
3892 if (IS_GEN6(i965->intel.device_id) ||
3893 IS_GEN7(i965->intel.device_id)) {
3894 intel_batchbuffer_start_atomic_blt(batch, 48);
3895 BEGIN_BLT_BATCH(batch, 12);
3897 intel_batchbuffer_start_atomic(batch, 48);
3898 BEGIN_BATCH(batch, 12);
3901 OUT_BATCH(batch, blt_cmd);
3902 OUT_BATCH(batch, br13);
3907 obj_surface->height << 16 |
3908 obj_surface->width);
3909 OUT_RELOC(batch, obj_surface->bo,
3910 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3912 OUT_BATCH(batch, y);
3918 OUT_BATCH(batch, blt_cmd);
3919 OUT_BATCH(batch, br13);
3924 obj_surface->height / 2 << 16 |
3925 obj_surface->width / 2);
3926 OUT_RELOC(batch, obj_surface->bo,
3927 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
3928 obj_surface->width * obj_surface->y_cb_offset);
3929 OUT_BATCH(batch, v << 8 | u);
3931 ADVANCE_BATCH(batch);
3932 intel_batchbuffer_end_atomic(batch);
3936 i965_post_processing(
3937 VADriverContextP ctx,
3938 VASurfaceID surface,
3939 const VARectangle *src_rect,
3940 const VARectangle *dst_rect,
3942 int *has_done_scaling
3945 struct i965_driver_data *i965 = i965_driver_data(ctx);
3946 VASurfaceID in_surface_id = surface;
3947 VASurfaceID out_surface_id = VA_INVALID_ID;
3949 *has_done_scaling = 0;
3952 struct object_surface *obj_surface;
3954 struct i965_surface src_surface;
3955 struct i965_surface dst_surface;
3957 obj_surface = SURFACE(in_surface_id);
3959 /* Currently only support post processing for NV12 surface */
3960 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
3961 return out_surface_id;
3963 _i965LockMutex(&i965->pp_mutex);
3965 if (flags & I965_PP_FLAG_MCDI) {
3966 status = i965_CreateSurfaces(ctx,
3967 obj_surface->orig_width,
3968 obj_surface->orig_height,
3969 VA_RT_FORMAT_YUV420,
3972 assert(status == VA_STATUS_SUCCESS);
3973 obj_surface = SURFACE(out_surface_id);
3974 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
3975 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
3976 src_surface.id = in_surface_id;
3977 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3978 src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ?
3979 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
3980 dst_surface.id = out_surface_id;
3981 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3982 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3984 i965_post_processing_internal(ctx, i965->pp_context,
3993 if (flags & I965_PP_FLAG_AVS) {
3994 struct i965_render_state *render_state = &i965->render_state;
3995 struct intel_region *dest_region = render_state->draw_region;
3997 if (out_surface_id != VA_INVALID_ID)
3998 in_surface_id = out_surface_id;
4000 status = i965_CreateSurfaces(ctx,
4002 dest_region->height,
4003 VA_RT_FORMAT_YUV420,
4006 assert(status == VA_STATUS_SUCCESS);
4007 obj_surface = SURFACE(out_surface_id);
4008 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4009 i965_vpp_clear_surface(ctx, i965->pp_context, out_surface_id, 0);
4010 src_surface.id = in_surface_id;
4011 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4012 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4013 dst_surface.id = out_surface_id;
4014 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4015 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4017 i965_post_processing_internal(ctx, i965->pp_context,
4025 if (in_surface_id != surface)
4026 i965_DestroySurfaces(ctx, &in_surface_id, 1);
4028 *has_done_scaling = 1;
4031 _i965UnlockMutex(&i965->pp_mutex);
4034 return out_surface_id;
4038 i965_image_pl3_processing(VADriverContextP ctx,
4039 const struct i965_surface *src_surface,
4040 const VARectangle *src_rect,
4041 struct i965_surface *dst_surface,
4042 const VARectangle *dst_rect)
4044 struct i965_driver_data *i965 = i965_driver_data(ctx);
4045 struct i965_post_processing_context *pp_context = i965->pp_context;
4046 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4047 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
4049 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
4050 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4055 PP_PL3_LOAD_SAVE_N12,
4057 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
4058 fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
4059 fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
4060 fourcc == VA_FOURCC('I', '4', '2', '0')) {
4061 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4066 PP_PL3_LOAD_SAVE_PL3,
4068 } else if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') ||
4069 fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
4070 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4075 PP_PL3_LOAD_SAVE_PA,
4082 intel_batchbuffer_flush(pp_context->batch);
4088 i965_image_pl2_processing(VADriverContextP ctx,
4089 const struct i965_surface *src_surface,
4090 const VARectangle *src_rect,
4091 struct i965_surface *dst_surface,
4092 const VARectangle *dst_rect)
4094 struct i965_driver_data *i965 = i965_driver_data(ctx);
4095 struct i965_post_processing_context *pp_context = i965->pp_context;
4096 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4097 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
4099 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
4100 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4105 PP_NV12_LOAD_SAVE_N12,
4107 } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
4108 fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
4109 fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
4110 fourcc == VA_FOURCC('I', '4', '2', '0') ) {
4111 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4116 PP_NV12_LOAD_SAVE_PL3,
4118 } else if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') ||
4119 fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
4120 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4125 PP_NV12_LOAD_SAVE_PA,
4129 intel_batchbuffer_flush(pp_context->batch);
4135 i965_image_pl1_processing(VADriverContextP ctx,
4136 const struct i965_surface *src_surface,
4137 const VARectangle *src_rect,
4138 struct i965_surface *dst_surface,
4139 const VARectangle *dst_rect)
4141 struct i965_driver_data *i965 = i965_driver_data(ctx);
4142 struct i965_post_processing_context *pp_context = i965->pp_context;
4143 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4145 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
4146 i965_post_processing_internal(ctx, i965->pp_context,
4151 PP_PA_LOAD_SAVE_NV12,
4154 else if (fourcc == VA_FOURCC_YV12) {
4155 i965_post_processing_internal(ctx, i965->pp_context,
4160 PP_PA_LOAD_SAVE_PL3,
4165 return VA_STATUS_ERROR_UNKNOWN;
4168 intel_batchbuffer_flush(pp_context->batch);
4170 return VA_STATUS_SUCCESS;
4174 i965_image_processing(VADriverContextP ctx,
4175 const struct i965_surface *src_surface,
4176 const VARectangle *src_rect,
4177 struct i965_surface *dst_surface,
4178 const VARectangle *dst_rect)
4180 struct i965_driver_data *i965 = i965_driver_data(ctx);
4181 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
4184 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
4186 _i965LockMutex(&i965->pp_mutex);
4189 case VA_FOURCC('Y', 'V', '1', '2'):
4190 case VA_FOURCC('I', '4', '2', '0'):
4191 case VA_FOURCC('I', 'M', 'C', '1'):
4192 case VA_FOURCC('I', 'M', 'C', '3'):
4193 status = i965_image_pl3_processing(ctx,
4200 case VA_FOURCC('N', 'V', '1', '2'):
4201 status = i965_image_pl2_processing(ctx,
4207 case VA_FOURCC('Y', 'U', 'Y', '2'):
4208 case VA_FOURCC('U', 'Y', 'V', 'Y'):
4209 status = i965_image_pl1_processing(ctx,
4217 status = VA_STATUS_ERROR_UNIMPLEMENTED;
4221 _i965UnlockMutex(&i965->pp_mutex);
4228 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
4232 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
4233 pp_context->surface_state_binding_table.bo = NULL;
4235 dri_bo_unreference(pp_context->curbe.bo);
4236 pp_context->curbe.bo = NULL;
4238 dri_bo_unreference(pp_context->sampler_state_table.bo);
4239 pp_context->sampler_state_table.bo = NULL;
4241 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
4242 pp_context->sampler_state_table.bo_8x8 = NULL;
4244 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
4245 pp_context->sampler_state_table.bo_8x8_uv = NULL;
4247 dri_bo_unreference(pp_context->idrt.bo);
4248 pp_context->idrt.bo = NULL;
4249 pp_context->idrt.num_interface_descriptors = 0;
4251 dri_bo_unreference(pp_context->vfe_state.bo);
4252 pp_context->vfe_state.bo = NULL;
4254 dri_bo_unreference(pp_context->stmm.bo);
4255 pp_context->stmm.bo = NULL;
4257 for (i = 0; i < NUM_PP_MODULES; i++) {
4258 struct pp_module *pp_module = &pp_context->pp_modules[i];
4260 dri_bo_unreference(pp_module->kernel.bo);
4261 pp_module->kernel.bo = NULL;
4264 free(pp_context->pp_static_parameter);
4265 free(pp_context->pp_inline_parameter);
4266 pp_context->pp_static_parameter = NULL;
4267 pp_context->pp_inline_parameter = NULL;
4271 i965_post_processing_terminate(VADriverContextP ctx)
4273 struct i965_driver_data *i965 = i965_driver_data(ctx);
4274 struct i965_post_processing_context *pp_context = i965->pp_context;
4277 i965_post_processing_context_finalize(pp_context);
4281 i965->pp_context = NULL;
4287 i965_post_processing_context_init(VADriverContextP ctx,
4288 struct i965_post_processing_context *pp_context,
4289 struct intel_batchbuffer *batch)
4291 struct i965_driver_data *i965 = i965_driver_data(ctx);
4294 pp_context->urb.size = URB_SIZE((&i965->intel));
4295 pp_context->urb.num_vfe_entries = 32;
4296 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
4297 pp_context->urb.num_cs_entries = 1;
4299 if (IS_GEN7(i965->intel.device_id))
4300 pp_context->urb.size_cs_entry = 4; /* in 512 bits unit */
4302 pp_context->urb.size_cs_entry = 2;
4304 pp_context->urb.vfe_start = 0;
4305 pp_context->urb.cs_start = pp_context->urb.vfe_start +
4306 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
4307 assert(pp_context->urb.cs_start +
4308 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
4310 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
4311 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
4312 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen7));
4314 if (IS_GEN7(i965->intel.device_id))
4315 memcpy(pp_context->pp_modules, pp_modules_gen7, sizeof(pp_context->pp_modules));
4316 else if (IS_GEN6(i965->intel.device_id))
4317 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
4318 else if (IS_IRONLAKE(i965->intel.device_id))
4319 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
4321 for (i = 0; i < NUM_PP_MODULES; i++) {
4322 struct pp_module *pp_module = &pp_context->pp_modules[i];
4323 dri_bo_unreference(pp_module->kernel.bo);
4324 if (pp_module->kernel.bin && pp_module->kernel.size) {
4325 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
4326 pp_module->kernel.name,
4327 pp_module->kernel.size,
4329 assert(pp_module->kernel.bo);
4330 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
4332 pp_module->kernel.bo = NULL;
4336 /* static & inline parameters */
4337 if (IS_GEN7(i965->intel.device_id)) {
4338 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
4339 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
4341 pp_context->pp_static_parameter = calloc(sizeof(struct pp_static_parameter), 1);
4342 pp_context->pp_inline_parameter = calloc(sizeof(struct pp_inline_parameter), 1);
4345 pp_context->batch = batch;
4349 i965_post_processing_init(VADriverContextP ctx)
4351 struct i965_driver_data *i965 = i965_driver_data(ctx);
4352 struct i965_post_processing_context *pp_context = i965->pp_context;
4355 if (pp_context == NULL) {
4356 pp_context = calloc(1, sizeof(*pp_context));
4357 i965_post_processing_context_init(ctx, pp_context, i965->batch);
4358 i965->pp_context = pp_context;
4365 static const int procfilter_to_pp_flag[VAProcFilterCount] = {
4366 PP_NULL, /* VAProcFilterNone */
4367 PP_NV12_DN, /* VAProcFilterNoiseReduction */
4368 PP_NULL, /* VAProcFilterDeblocking */
4369 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
4370 PP_NULL, /* VAProcFilterSharpening */
4371 PP_NULL, /* VAProcFilterColorBalance */
4372 PP_NULL, /* VAProcFilterColorStandard */
4373 PP_NULL, /* VAProcFilterFrameRateConversion */
4376 static const int proc_frame_to_pp_frame[3] = {
4377 I965_SURFACE_FLAG_FRAME,
4378 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
4379 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
4383 i965_proc_picture(VADriverContextP ctx,
4385 union codec_state *codec_state,
4386 struct hw_context *hw_context)
4388 struct i965_driver_data *i965 = i965_driver_data(ctx);
4389 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
4390 struct proc_state *proc_state = &codec_state->proc;
4391 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
4392 struct object_surface *obj_surface;
4393 struct i965_surface src_surface, dst_surface;
4394 VARectangle src_rect, dst_rect;
4397 VASurfaceID tmp_surfaces[VAProcFilterCount + 4];
4398 int num_tmp_surfaces = 0;
4399 unsigned int tiling = 0, swizzle = 0;
4400 int in_width, in_height;
4402 assert(pipeline_param->surface != VA_INVALID_ID);
4403 assert(proc_state->current_render_target != VA_INVALID_ID);
4405 obj_surface = SURFACE(pipeline_param->surface);
4406 in_width = obj_surface->orig_width;
4407 in_height = obj_surface->orig_height;
4408 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4410 src_surface.id = pipeline_param->surface;
4411 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4412 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
4414 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
4415 VASurfaceID out_surface_id = VA_INVALID_ID;
4417 src_surface.id = pipeline_param->surface;
4418 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4419 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4422 src_rect.width = in_width;
4423 src_rect.height = in_height;
4425 status = i965_CreateSurfaces(ctx,
4428 VA_RT_FORMAT_YUV420,
4431 assert(status == VA_STATUS_SUCCESS);
4432 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
4433 obj_surface = SURFACE(out_surface_id);
4434 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
4436 dst_surface.id = out_surface_id;
4437 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4438 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4441 dst_rect.width = in_width;
4442 dst_rect.height = in_height;
4444 status = i965_image_processing(ctx,
4449 assert(status == VA_STATUS_SUCCESS);
4451 src_surface.id = out_surface_id;
4452 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4453 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
4456 if (pipeline_param->surface_region) {
4457 src_rect.x = pipeline_param->surface_region->x;
4458 src_rect.y = pipeline_param->surface_region->y;
4459 src_rect.width = pipeline_param->surface_region->width;
4460 src_rect.height = pipeline_param->surface_region->height;
4464 src_rect.width = in_width;
4465 src_rect.height = in_height;
4468 if (pipeline_param->output_region) {
4469 dst_rect.x = pipeline_param->output_region->x;
4470 dst_rect.y = pipeline_param->output_region->y;
4471 dst_rect.width = pipeline_param->output_region->width;
4472 dst_rect.height = pipeline_param->output_region->height;
4476 dst_rect.width = in_width;
4477 dst_rect.height = in_height;
4480 obj_surface = SURFACE(proc_state->current_render_target);
4481 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4482 i965_vpp_clear_surface(ctx, &proc_context->pp_context, proc_state->current_render_target, pipeline_param->output_background_color);
4484 for (i = 0; i < pipeline_param->num_filters; i++) {
4485 struct object_buffer *obj_buffer = BUFFER(pipeline_param->filters[i]);
4486 VAProcFilterParameterBufferBase *filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4487 VAProcFilterType filter_type = filter_param->type;
4488 VASurfaceID out_surface_id = VA_INVALID_ID;
4489 int kernel_index = procfilter_to_pp_flag[filter_type];
4491 if (kernel_index != PP_NULL &&
4492 proc_context->pp_context.pp_modules[kernel_index].kernel.bo != NULL) {
4493 status = i965_CreateSurfaces(ctx,
4496 VA_RT_FORMAT_YUV420,
4499 assert(status == VA_STATUS_SUCCESS);
4500 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
4501 obj_surface = SURFACE(out_surface_id);
4502 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
4503 dst_surface.id = out_surface_id;
4504 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4505 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
4513 if (status == VA_STATUS_SUCCESS) {
4514 src_surface.id = dst_surface.id;
4515 src_surface.type = dst_surface.type;
4516 src_surface.flags = dst_surface.flags;
4521 dst_surface.id = proc_state->current_render_target;
4522 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4524 if (src_rect.width == dst_rect.width &&
4525 src_rect.height == dst_rect.height) {
4526 i965_post_processing_internal(ctx, &proc_context->pp_context,
4531 PP_NV12_LOAD_SAVE_N12,
4535 i965_post_processing_internal(ctx, &proc_context->pp_context,
4540 (pipeline_param->filter_flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC ?
4541 PP_NV12_AVS : PP_NV12_SCALING,
4545 if (num_tmp_surfaces)
4546 i965_DestroySurfaces(ctx,
4550 intel_batchbuffer_flush(hw_context->batch);
4554 i965_proc_context_destroy(void *hw_context)
4556 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
4558 i965_post_processing_context_finalize(&proc_context->pp_context);
4559 intel_batchbuffer_free(proc_context->base.batch);
4564 i965_proc_context_init(VADriverContextP ctx, struct object_config *obj_config)
4566 struct intel_driver_data *intel = intel_driver_data(ctx);
4567 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
4569 proc_context->base.destroy = i965_proc_context_destroy;
4570 proc_context->base.run = i965_proc_picture;
4571 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
4572 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
4574 return (struct hw_context *)proc_context;