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"
41 #include "intel_media.h"
44 vpp_surface_convert(VADriverContextP ctx,
45 struct object_surface *src_obj_surf,
46 struct object_surface *dst_obj_surf);
48 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
50 #define SURFACE_STATE_PADDED_SIZE MAX(SURFACE_STATE_PADDED_SIZE_GEN8,\
51 MAX(SURFACE_STATE_PADDED_SIZE_GEN6, SURFACE_STATE_PADDED_SIZE_GEN7))
53 #define SURFACE_STATE_OFFSET(index) (SURFACE_STATE_PADDED_SIZE * index)
54 #define BINDING_TABLE_OFFSET SURFACE_STATE_OFFSET(MAX_PP_SURFACES)
56 #define GPU_ASM_BLOCK_WIDTH 16
57 #define GPU_ASM_BLOCK_HEIGHT 8
58 #define GPU_ASM_X_OFFSET_ALIGNMENT 4
60 #define VA_STATUS_SUCCESS_1 0xFFFFFFFE
63 i965_CreateSurfaces(VADriverContextP ctx,
68 VASurfaceID *surfaces);
70 static const uint32_t pp_null_gen5[][4] = {
71 #include "shaders/post_processing/gen5_6/null.g4b.gen5"
74 static const uint32_t pp_nv12_load_save_nv12_gen5[][4] = {
75 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g4b.gen5"
78 static const uint32_t pp_nv12_load_save_pl3_gen5[][4] = {
79 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g4b.gen5"
82 static const uint32_t pp_pl3_load_save_nv12_gen5[][4] = {
83 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g4b.gen5"
86 static const uint32_t pp_pl3_load_save_pl3_gen5[][4] = {
87 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g4b.gen5"
90 static const uint32_t pp_nv12_scaling_gen5[][4] = {
91 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g4b.gen5"
94 static const uint32_t pp_nv12_avs_gen5[][4] = {
95 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g4b.gen5"
98 static const uint32_t pp_nv12_dndi_gen5[][4] = {
99 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g4b.gen5"
102 static const uint32_t pp_nv12_dn_gen5[][4] = {
103 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g4b.gen5"
106 static const uint32_t pp_nv12_load_save_pa_gen5[][4] = {
107 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g4b.gen5"
110 static const uint32_t pp_pl3_load_save_pa_gen5[][4] = {
111 #include "shaders/post_processing/gen5_6/pl3_load_save_pa.g4b.gen5"
114 static const uint32_t pp_pa_load_save_nv12_gen5[][4] = {
115 #include "shaders/post_processing/gen5_6/pa_load_save_nv12.g4b.gen5"
118 static const uint32_t pp_pa_load_save_pl3_gen5[][4] = {
119 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g4b.gen5"
122 static const uint32_t pp_pa_load_save_pa_gen5[][4] = {
123 #include "shaders/post_processing/gen5_6/pa_load_save_pa.g4b.gen5"
126 static const uint32_t pp_rgbx_load_save_nv12_gen5[][4] = {
127 #include "shaders/post_processing/gen5_6/rgbx_load_save_nv12.g4b.gen5"
130 static const uint32_t pp_nv12_load_save_rgbx_gen5[][4] = {
131 #include "shaders/post_processing/gen5_6/nv12_load_save_rgbx.g4b.gen5"
134 static VAStatus pp_null_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_avs_initialize_nlas(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_scaling_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,
152 static VAStatus gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
153 const struct i965_surface *src_surface,
154 const VARectangle *src_rect,
155 struct i965_surface *dst_surface,
156 const VARectangle *dst_rect,
158 static VAStatus pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
159 const struct i965_surface *src_surface,
160 const VARectangle *src_rect,
161 struct i965_surface *dst_surface,
162 const VARectangle *dst_rect,
164 static VAStatus pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
165 const struct i965_surface *src_surface,
166 const VARectangle *src_rect,
167 struct i965_surface *dst_surface,
168 const VARectangle *dst_rect,
170 static VAStatus pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
171 const struct i965_surface *src_surface,
172 const VARectangle *src_rect,
173 struct i965_surface *dst_surface,
174 const VARectangle *dst_rect,
177 static struct pp_module pp_modules_gen5[] = {
180 "NULL module (for testing)",
183 sizeof(pp_null_gen5),
193 PP_NV12_LOAD_SAVE_N12,
194 pp_nv12_load_save_nv12_gen5,
195 sizeof(pp_nv12_load_save_nv12_gen5),
199 pp_plx_load_save_plx_initialize,
205 PP_NV12_LOAD_SAVE_PL3,
206 pp_nv12_load_save_pl3_gen5,
207 sizeof(pp_nv12_load_save_pl3_gen5),
211 pp_plx_load_save_plx_initialize,
217 PP_PL3_LOAD_SAVE_N12,
218 pp_pl3_load_save_nv12_gen5,
219 sizeof(pp_pl3_load_save_nv12_gen5),
223 pp_plx_load_save_plx_initialize,
229 PP_PL3_LOAD_SAVE_PL3,
230 pp_pl3_load_save_pl3_gen5,
231 sizeof(pp_pl3_load_save_pl3_gen5),
235 pp_plx_load_save_plx_initialize
240 "NV12 Scaling module",
242 pp_nv12_scaling_gen5,
243 sizeof(pp_nv12_scaling_gen5),
247 pp_nv12_scaling_initialize,
255 sizeof(pp_nv12_avs_gen5),
259 pp_nv12_avs_initialize_nlas,
267 sizeof(pp_nv12_dndi_gen5),
271 pp_nv12_dndi_initialize,
279 sizeof(pp_nv12_dn_gen5),
283 pp_nv12_dn_initialize,
289 PP_NV12_LOAD_SAVE_PA,
290 pp_nv12_load_save_pa_gen5,
291 sizeof(pp_nv12_load_save_pa_gen5),
295 pp_plx_load_save_plx_initialize,
302 pp_pl3_load_save_pa_gen5,
303 sizeof(pp_pl3_load_save_pa_gen5),
307 pp_plx_load_save_plx_initialize,
313 PP_PA_LOAD_SAVE_NV12,
314 pp_pa_load_save_nv12_gen5,
315 sizeof(pp_pa_load_save_nv12_gen5),
319 pp_plx_load_save_plx_initialize,
326 pp_pa_load_save_pl3_gen5,
327 sizeof(pp_pa_load_save_pl3_gen5),
331 pp_plx_load_save_plx_initialize,
338 pp_pa_load_save_pa_gen5,
339 sizeof(pp_pa_load_save_pa_gen5),
343 pp_plx_load_save_plx_initialize,
349 PP_RGBX_LOAD_SAVE_NV12,
350 pp_rgbx_load_save_nv12_gen5,
351 sizeof(pp_rgbx_load_save_nv12_gen5),
355 pp_plx_load_save_plx_initialize,
361 PP_NV12_LOAD_SAVE_RGBX,
362 pp_nv12_load_save_rgbx_gen5,
363 sizeof(pp_nv12_load_save_rgbx_gen5),
367 pp_plx_load_save_plx_initialize,
371 static const uint32_t pp_null_gen6[][4] = {
372 #include "shaders/post_processing/gen5_6/null.g6b"
375 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
376 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
379 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
380 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
383 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
384 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
387 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
388 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
391 static const uint32_t pp_nv12_scaling_gen6[][4] = {
392 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
395 static const uint32_t pp_nv12_avs_gen6[][4] = {
396 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
399 static const uint32_t pp_nv12_dndi_gen6[][4] = {
400 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
403 static const uint32_t pp_nv12_dn_gen6[][4] = {
404 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g6b"
407 static const uint32_t pp_nv12_load_save_pa_gen6[][4] = {
408 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g6b"
411 static const uint32_t pp_pl3_load_save_pa_gen6[][4] = {
412 #include "shaders/post_processing/gen5_6/pl3_load_save_pa.g6b"
415 static const uint32_t pp_pa_load_save_nv12_gen6[][4] = {
416 #include "shaders/post_processing/gen5_6/pa_load_save_nv12.g6b"
419 static const uint32_t pp_pa_load_save_pl3_gen6[][4] = {
420 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g6b"
423 static const uint32_t pp_pa_load_save_pa_gen6[][4] = {
424 #include "shaders/post_processing/gen5_6/pa_load_save_pa.g6b"
427 static const uint32_t pp_rgbx_load_save_nv12_gen6[][4] = {
428 #include "shaders/post_processing/gen5_6/rgbx_load_save_nv12.g6b"
431 static const uint32_t pp_nv12_load_save_rgbx_gen6[][4] = {
432 #include "shaders/post_processing/gen5_6/nv12_load_save_rgbx.g6b"
435 static struct pp_module pp_modules_gen6[] = {
438 "NULL module (for testing)",
441 sizeof(pp_null_gen6),
451 PP_NV12_LOAD_SAVE_N12,
452 pp_nv12_load_save_nv12_gen6,
453 sizeof(pp_nv12_load_save_nv12_gen6),
457 pp_plx_load_save_plx_initialize,
463 PP_NV12_LOAD_SAVE_PL3,
464 pp_nv12_load_save_pl3_gen6,
465 sizeof(pp_nv12_load_save_pl3_gen6),
469 pp_plx_load_save_plx_initialize,
475 PP_PL3_LOAD_SAVE_N12,
476 pp_pl3_load_save_nv12_gen6,
477 sizeof(pp_pl3_load_save_nv12_gen6),
481 pp_plx_load_save_plx_initialize,
487 PP_PL3_LOAD_SAVE_PL3,
488 pp_pl3_load_save_pl3_gen6,
489 sizeof(pp_pl3_load_save_pl3_gen6),
493 pp_plx_load_save_plx_initialize,
498 "NV12 Scaling module",
500 pp_nv12_scaling_gen6,
501 sizeof(pp_nv12_scaling_gen6),
505 gen6_nv12_scaling_initialize,
513 sizeof(pp_nv12_avs_gen6),
517 pp_nv12_avs_initialize_nlas,
525 sizeof(pp_nv12_dndi_gen6),
529 pp_nv12_dndi_initialize,
537 sizeof(pp_nv12_dn_gen6),
541 pp_nv12_dn_initialize,
546 PP_NV12_LOAD_SAVE_PA,
547 pp_nv12_load_save_pa_gen6,
548 sizeof(pp_nv12_load_save_pa_gen6),
552 pp_plx_load_save_plx_initialize,
559 pp_pl3_load_save_pa_gen6,
560 sizeof(pp_pl3_load_save_pa_gen6),
564 pp_plx_load_save_plx_initialize,
570 PP_PA_LOAD_SAVE_NV12,
571 pp_pa_load_save_nv12_gen6,
572 sizeof(pp_pa_load_save_nv12_gen6),
576 pp_plx_load_save_plx_initialize,
583 pp_pa_load_save_pl3_gen6,
584 sizeof(pp_pa_load_save_pl3_gen6),
588 pp_plx_load_save_plx_initialize,
595 pp_pa_load_save_pa_gen6,
596 sizeof(pp_pa_load_save_pa_gen6),
600 pp_plx_load_save_plx_initialize,
606 PP_RGBX_LOAD_SAVE_NV12,
607 pp_rgbx_load_save_nv12_gen6,
608 sizeof(pp_rgbx_load_save_nv12_gen6),
612 pp_plx_load_save_plx_initialize,
618 PP_NV12_LOAD_SAVE_RGBX,
619 pp_nv12_load_save_rgbx_gen6,
620 sizeof(pp_nv12_load_save_rgbx_gen6),
624 pp_plx_load_save_plx_initialize,
628 static const uint32_t pp_null_gen7[][4] = {
631 static const uint32_t pp_nv12_load_save_nv12_gen7[][4] = {
632 #include "shaders/post_processing/gen7/pl2_to_pl2.g7b"
635 static const uint32_t pp_nv12_load_save_pl3_gen7[][4] = {
636 #include "shaders/post_processing/gen7/pl2_to_pl3.g7b"
639 static const uint32_t pp_pl3_load_save_nv12_gen7[][4] = {
640 #include "shaders/post_processing/gen7/pl3_to_pl2.g7b"
643 static const uint32_t pp_pl3_load_save_pl3_gen7[][4] = {
644 #include "shaders/post_processing/gen7/pl3_to_pl3.g7b"
647 static const uint32_t pp_nv12_scaling_gen7[][4] = {
648 #include "shaders/post_processing/gen7/avs.g7b"
651 static const uint32_t pp_nv12_avs_gen7[][4] = {
652 #include "shaders/post_processing/gen7/avs.g7b"
655 static const uint32_t pp_nv12_dndi_gen7[][4] = {
656 #include "shaders/post_processing/gen7/dndi.g7b"
659 static const uint32_t pp_nv12_dn_gen7[][4] = {
660 #include "shaders/post_processing/gen7/nv12_dn_nv12.g7b"
662 static const uint32_t pp_nv12_load_save_pa_gen7[][4] = {
663 #include "shaders/post_processing/gen7/pl2_to_pa.g7b"
665 static const uint32_t pp_pl3_load_save_pa_gen7[][4] = {
666 #include "shaders/post_processing/gen7/pl3_to_pa.g7b"
668 static const uint32_t pp_pa_load_save_nv12_gen7[][4] = {
669 #include "shaders/post_processing/gen7/pa_to_pl2.g7b"
671 static const uint32_t pp_pa_load_save_pl3_gen7[][4] = {
672 #include "shaders/post_processing/gen7/pa_to_pl3.g7b"
674 static const uint32_t pp_pa_load_save_pa_gen7[][4] = {
675 #include "shaders/post_processing/gen7/pa_to_pa.g7b"
677 static const uint32_t pp_rgbx_load_save_nv12_gen7[][4] = {
678 #include "shaders/post_processing/gen7/rgbx_to_nv12.g7b"
680 static const uint32_t pp_nv12_load_save_rgbx_gen7[][4] = {
681 #include "shaders/post_processing/gen7/pl2_to_rgbx.g7b"
684 static VAStatus gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
685 const struct i965_surface *src_surface,
686 const VARectangle *src_rect,
687 struct i965_surface *dst_surface,
688 const VARectangle *dst_rect,
690 static VAStatus gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
691 const struct i965_surface *src_surface,
692 const VARectangle *src_rect,
693 struct i965_surface *dst_surface,
694 const VARectangle *dst_rect,
696 static VAStatus gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
697 const struct i965_surface *src_surface,
698 const VARectangle *src_rect,
699 struct i965_surface *dst_surface,
700 const VARectangle *dst_rect,
703 static struct pp_module pp_modules_gen7[] = {
706 "NULL module (for testing)",
709 sizeof(pp_null_gen7),
719 PP_NV12_LOAD_SAVE_N12,
720 pp_nv12_load_save_nv12_gen7,
721 sizeof(pp_nv12_load_save_nv12_gen7),
725 gen7_pp_plx_avs_initialize,
731 PP_NV12_LOAD_SAVE_PL3,
732 pp_nv12_load_save_pl3_gen7,
733 sizeof(pp_nv12_load_save_pl3_gen7),
737 gen7_pp_plx_avs_initialize,
743 PP_PL3_LOAD_SAVE_N12,
744 pp_pl3_load_save_nv12_gen7,
745 sizeof(pp_pl3_load_save_nv12_gen7),
749 gen7_pp_plx_avs_initialize,
755 PP_PL3_LOAD_SAVE_PL3,
756 pp_pl3_load_save_pl3_gen7,
757 sizeof(pp_pl3_load_save_pl3_gen7),
761 gen7_pp_plx_avs_initialize,
766 "NV12 Scaling module",
768 pp_nv12_scaling_gen7,
769 sizeof(pp_nv12_scaling_gen7),
773 gen7_pp_plx_avs_initialize,
781 sizeof(pp_nv12_avs_gen7),
785 gen7_pp_plx_avs_initialize,
793 sizeof(pp_nv12_dndi_gen7),
797 gen7_pp_nv12_dndi_initialize,
805 sizeof(pp_nv12_dn_gen7),
809 gen7_pp_nv12_dn_initialize,
814 PP_NV12_LOAD_SAVE_PA,
815 pp_nv12_load_save_pa_gen7,
816 sizeof(pp_nv12_load_save_pa_gen7),
820 gen7_pp_plx_avs_initialize,
827 pp_pl3_load_save_pa_gen7,
828 sizeof(pp_pl3_load_save_pa_gen7),
832 gen7_pp_plx_avs_initialize,
838 PP_PA_LOAD_SAVE_NV12,
839 pp_pa_load_save_nv12_gen7,
840 sizeof(pp_pa_load_save_nv12_gen7),
844 gen7_pp_plx_avs_initialize,
851 pp_pa_load_save_pl3_gen7,
852 sizeof(pp_pa_load_save_pl3_gen7),
856 gen7_pp_plx_avs_initialize,
863 pp_pa_load_save_pa_gen7,
864 sizeof(pp_pa_load_save_pa_gen7),
868 gen7_pp_plx_avs_initialize,
874 PP_RGBX_LOAD_SAVE_NV12,
875 pp_rgbx_load_save_nv12_gen7,
876 sizeof(pp_rgbx_load_save_nv12_gen7),
880 gen7_pp_plx_avs_initialize,
886 PP_NV12_LOAD_SAVE_RGBX,
887 pp_nv12_load_save_rgbx_gen7,
888 sizeof(pp_nv12_load_save_rgbx_gen7),
892 gen7_pp_plx_avs_initialize,
897 static const uint32_t pp_null_gen75[][4] = {
900 static const uint32_t pp_nv12_load_save_nv12_gen75[][4] = {
901 #include "shaders/post_processing/gen7/pl2_to_pl2.g75b"
904 static const uint32_t pp_nv12_load_save_pl3_gen75[][4] = {
905 #include "shaders/post_processing/gen7/pl2_to_pl3.g75b"
908 static const uint32_t pp_pl3_load_save_nv12_gen75[][4] = {
909 #include "shaders/post_processing/gen7/pl3_to_pl2.g75b"
912 static const uint32_t pp_pl3_load_save_pl3_gen75[][4] = {
913 #include "shaders/post_processing/gen7/pl3_to_pl3.g75b"
916 static const uint32_t pp_nv12_scaling_gen75[][4] = {
917 #include "shaders/post_processing/gen7/avs.g75b"
920 static const uint32_t pp_nv12_avs_gen75[][4] = {
921 #include "shaders/post_processing/gen7/avs.g75b"
924 static const uint32_t pp_nv12_dndi_gen75[][4] = {
925 // #include "shaders/post_processing/gen7/dndi.g75b"
928 static const uint32_t pp_nv12_dn_gen75[][4] = {
929 // #include "shaders/post_processing/gen7/nv12_dn_nv12.g75b"
931 static const uint32_t pp_nv12_load_save_pa_gen75[][4] = {
932 #include "shaders/post_processing/gen7/pl2_to_pa.g75b"
934 static const uint32_t pp_pl3_load_save_pa_gen75[][4] = {
935 #include "shaders/post_processing/gen7/pl3_to_pa.g75b"
937 static const uint32_t pp_pa_load_save_nv12_gen75[][4] = {
938 #include "shaders/post_processing/gen7/pa_to_pl2.g75b"
940 static const uint32_t pp_pa_load_save_pl3_gen75[][4] = {
941 #include "shaders/post_processing/gen7/pa_to_pl3.g75b"
943 static const uint32_t pp_pa_load_save_pa_gen75[][4] = {
944 #include "shaders/post_processing/gen7/pa_to_pa.g75b"
946 static const uint32_t pp_rgbx_load_save_nv12_gen75[][4] = {
947 #include "shaders/post_processing/gen7/rgbx_to_nv12.g75b"
949 static const uint32_t pp_nv12_load_save_rgbx_gen75[][4] = {
950 #include "shaders/post_processing/gen7/pl2_to_rgbx.g75b"
953 static struct pp_module pp_modules_gen75[] = {
956 "NULL module (for testing)",
959 sizeof(pp_null_gen75),
969 PP_NV12_LOAD_SAVE_N12,
970 pp_nv12_load_save_nv12_gen75,
971 sizeof(pp_nv12_load_save_nv12_gen75),
975 gen7_pp_plx_avs_initialize,
981 PP_NV12_LOAD_SAVE_PL3,
982 pp_nv12_load_save_pl3_gen75,
983 sizeof(pp_nv12_load_save_pl3_gen75),
987 gen7_pp_plx_avs_initialize,
993 PP_PL3_LOAD_SAVE_N12,
994 pp_pl3_load_save_nv12_gen75,
995 sizeof(pp_pl3_load_save_nv12_gen75),
999 gen7_pp_plx_avs_initialize,
1005 PP_PL3_LOAD_SAVE_PL3,
1006 pp_pl3_load_save_pl3_gen75,
1007 sizeof(pp_pl3_load_save_pl3_gen75),
1011 gen7_pp_plx_avs_initialize,
1016 "NV12 Scaling module",
1018 pp_nv12_scaling_gen75,
1019 sizeof(pp_nv12_scaling_gen75),
1023 gen7_pp_plx_avs_initialize,
1031 sizeof(pp_nv12_avs_gen75),
1035 gen7_pp_plx_avs_initialize,
1043 sizeof(pp_nv12_dndi_gen75),
1047 gen7_pp_nv12_dn_initialize,
1055 sizeof(pp_nv12_dn_gen75),
1059 gen7_pp_nv12_dn_initialize,
1065 PP_NV12_LOAD_SAVE_PA,
1066 pp_nv12_load_save_pa_gen75,
1067 sizeof(pp_nv12_load_save_pa_gen75),
1071 gen7_pp_plx_avs_initialize,
1077 PP_PL3_LOAD_SAVE_PA,
1078 pp_pl3_load_save_pa_gen75,
1079 sizeof(pp_pl3_load_save_pa_gen75),
1083 gen7_pp_plx_avs_initialize,
1089 PP_PA_LOAD_SAVE_NV12,
1090 pp_pa_load_save_nv12_gen75,
1091 sizeof(pp_pa_load_save_nv12_gen75),
1095 gen7_pp_plx_avs_initialize,
1101 PP_PA_LOAD_SAVE_PL3,
1102 pp_pa_load_save_pl3_gen75,
1103 sizeof(pp_pa_load_save_pl3_gen75),
1107 gen7_pp_plx_avs_initialize,
1114 pp_pa_load_save_pa_gen75,
1115 sizeof(pp_pa_load_save_pa_gen75),
1119 gen7_pp_plx_avs_initialize,
1125 PP_RGBX_LOAD_SAVE_NV12,
1126 pp_rgbx_load_save_nv12_gen75,
1127 sizeof(pp_rgbx_load_save_nv12_gen75),
1131 gen7_pp_plx_avs_initialize,
1137 PP_NV12_LOAD_SAVE_RGBX,
1138 pp_nv12_load_save_rgbx_gen75,
1139 sizeof(pp_nv12_load_save_rgbx_gen75),
1143 gen7_pp_plx_avs_initialize,
1149 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
1153 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
1154 struct object_image *obj_image = (struct object_image *)surface->base;
1155 fourcc = obj_image->image.format.fourcc;
1157 struct object_surface *obj_surface = (struct object_surface *)surface->base;
1158 fourcc = obj_surface->fourcc;
1165 pp_get_surface_size(VADriverContextP ctx, const struct i965_surface *surface, int *width, int *height)
1167 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
1168 struct object_image *obj_image = (struct object_image *)surface->base;
1170 *width = obj_image->image.width;
1171 *height = obj_image->image.height;
1173 struct object_surface *obj_surface = (struct object_surface *)surface->base;
1175 *width = obj_surface->orig_width;
1176 *height = obj_surface->orig_height;
1181 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
1184 case I915_TILING_NONE:
1185 ss->ss3.tiled_surface = 0;
1186 ss->ss3.tile_walk = 0;
1189 ss->ss3.tiled_surface = 1;
1190 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
1193 ss->ss3.tiled_surface = 1;
1194 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
1200 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
1203 case I915_TILING_NONE:
1204 ss->ss2.tiled_surface = 0;
1205 ss->ss2.tile_walk = 0;
1208 ss->ss2.tiled_surface = 1;
1209 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
1212 ss->ss2.tiled_surface = 1;
1213 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
1219 gen7_pp_set_surface_tiling(struct gen7_surface_state *ss, unsigned int tiling)
1222 case I915_TILING_NONE:
1223 ss->ss0.tiled_surface = 0;
1224 ss->ss0.tile_walk = 0;
1227 ss->ss0.tiled_surface = 1;
1228 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
1231 ss->ss0.tiled_surface = 1;
1232 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
1238 gen7_pp_set_surface2_tiling(struct gen7_surface_state2 *ss, unsigned int tiling)
1241 case I915_TILING_NONE:
1242 ss->ss2.tiled_surface = 0;
1243 ss->ss2.tile_walk = 0;
1246 ss->ss2.tiled_surface = 1;
1247 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
1250 ss->ss2.tiled_surface = 1;
1251 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
1257 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
1259 struct i965_interface_descriptor *desc;
1261 int pp_index = pp_context->current_pp;
1263 bo = pp_context->idrt.bo;
1265 assert(bo->virtual);
1267 memset(desc, 0, sizeof(*desc));
1268 desc->desc0.grf_reg_blocks = 10;
1269 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
1270 desc->desc1.const_urb_entry_read_offset = 0;
1271 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
1272 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
1273 desc->desc2.sampler_count = 0;
1274 desc->desc3.binding_table_entry_count = 0;
1275 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
1277 dri_bo_emit_reloc(bo,
1278 I915_GEM_DOMAIN_INSTRUCTION, 0,
1279 desc->desc0.grf_reg_blocks,
1280 offsetof(struct i965_interface_descriptor, desc0),
1281 pp_context->pp_modules[pp_index].kernel.bo);
1283 dri_bo_emit_reloc(bo,
1284 I915_GEM_DOMAIN_INSTRUCTION, 0,
1285 desc->desc2.sampler_count << 2,
1286 offsetof(struct i965_interface_descriptor, desc2),
1287 pp_context->sampler_state_table.bo);
1290 pp_context->idrt.num_interface_descriptors++;
1294 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
1296 struct i965_vfe_state *vfe_state;
1299 bo = pp_context->vfe_state.bo;
1301 assert(bo->virtual);
1302 vfe_state = bo->virtual;
1303 memset(vfe_state, 0, sizeof(*vfe_state));
1304 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
1305 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
1306 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
1307 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
1308 vfe_state->vfe1.children_present = 0;
1309 vfe_state->vfe2.interface_descriptor_base =
1310 pp_context->idrt.bo->offset >> 4; /* reloc */
1311 dri_bo_emit_reloc(bo,
1312 I915_GEM_DOMAIN_INSTRUCTION, 0,
1314 offsetof(struct i965_vfe_state, vfe2),
1315 pp_context->idrt.bo);
1320 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
1322 unsigned char *constant_buffer;
1323 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1325 assert(sizeof(*pp_static_parameter) == 128);
1326 dri_bo_map(pp_context->curbe.bo, 1);
1327 assert(pp_context->curbe.bo->virtual);
1328 constant_buffer = pp_context->curbe.bo->virtual;
1329 memcpy(constant_buffer, pp_static_parameter, sizeof(*pp_static_parameter));
1330 dri_bo_unmap(pp_context->curbe.bo);
1334 ironlake_pp_states_setup(VADriverContextP ctx,
1335 struct i965_post_processing_context *pp_context)
1337 ironlake_pp_interface_descriptor_table(pp_context);
1338 ironlake_pp_vfe_state(pp_context);
1339 ironlake_pp_upload_constants(pp_context);
1343 ironlake_pp_pipeline_select(VADriverContextP ctx,
1344 struct i965_post_processing_context *pp_context)
1346 struct intel_batchbuffer *batch = pp_context->batch;
1348 BEGIN_BATCH(batch, 1);
1349 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
1350 ADVANCE_BATCH(batch);
1354 ironlake_pp_urb_layout(VADriverContextP ctx,
1355 struct i965_post_processing_context *pp_context)
1357 struct intel_batchbuffer *batch = pp_context->batch;
1358 unsigned int vfe_fence, cs_fence;
1360 vfe_fence = pp_context->urb.cs_start;
1361 cs_fence = pp_context->urb.size;
1363 BEGIN_BATCH(batch, 3);
1364 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
1365 OUT_BATCH(batch, 0);
1367 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
1368 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
1369 ADVANCE_BATCH(batch);
1373 ironlake_pp_state_base_address(VADriverContextP ctx,
1374 struct i965_post_processing_context *pp_context)
1376 struct intel_batchbuffer *batch = pp_context->batch;
1378 BEGIN_BATCH(batch, 8);
1379 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
1380 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1381 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
1382 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1383 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1384 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1385 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1386 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1387 ADVANCE_BATCH(batch);
1391 ironlake_pp_state_pointers(VADriverContextP ctx,
1392 struct i965_post_processing_context *pp_context)
1394 struct intel_batchbuffer *batch = pp_context->batch;
1396 BEGIN_BATCH(batch, 3);
1397 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
1398 OUT_BATCH(batch, 0);
1399 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
1400 ADVANCE_BATCH(batch);
1404 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
1405 struct i965_post_processing_context *pp_context)
1407 struct intel_batchbuffer *batch = pp_context->batch;
1409 BEGIN_BATCH(batch, 2);
1410 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
1412 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
1413 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
1414 ADVANCE_BATCH(batch);
1418 ironlake_pp_constant_buffer(VADriverContextP ctx,
1419 struct i965_post_processing_context *pp_context)
1421 struct intel_batchbuffer *batch = pp_context->batch;
1423 BEGIN_BATCH(batch, 2);
1424 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
1425 OUT_RELOC(batch, pp_context->curbe.bo,
1426 I915_GEM_DOMAIN_INSTRUCTION, 0,
1427 pp_context->urb.size_cs_entry - 1);
1428 ADVANCE_BATCH(batch);
1432 ironlake_pp_object_walker(VADriverContextP ctx,
1433 struct i965_post_processing_context *pp_context)
1435 struct intel_batchbuffer *batch = pp_context->batch;
1436 int x, x_steps, y, y_steps;
1437 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1439 x_steps = pp_context->pp_x_steps(pp_context->private_context);
1440 y_steps = pp_context->pp_y_steps(pp_context->private_context);
1442 for (y = 0; y < y_steps; y++) {
1443 for (x = 0; x < x_steps; x++) {
1444 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
1445 BEGIN_BATCH(batch, 20);
1446 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
1447 OUT_BATCH(batch, 0);
1448 OUT_BATCH(batch, 0); /* no indirect data */
1449 OUT_BATCH(batch, 0);
1451 /* inline data grf 5-6 */
1452 assert(sizeof(*pp_inline_parameter) == 64);
1453 intel_batchbuffer_data(batch, pp_inline_parameter, sizeof(*pp_inline_parameter));
1455 ADVANCE_BATCH(batch);
1462 ironlake_pp_pipeline_setup(VADriverContextP ctx,
1463 struct i965_post_processing_context *pp_context)
1465 struct intel_batchbuffer *batch = pp_context->batch;
1467 intel_batchbuffer_start_atomic(batch, 0x1000);
1468 intel_batchbuffer_emit_mi_flush(batch);
1469 ironlake_pp_pipeline_select(ctx, pp_context);
1470 ironlake_pp_state_base_address(ctx, pp_context);
1471 ironlake_pp_state_pointers(ctx, pp_context);
1472 ironlake_pp_urb_layout(ctx, pp_context);
1473 ironlake_pp_cs_urb_layout(ctx, pp_context);
1474 ironlake_pp_constant_buffer(ctx, pp_context);
1475 ironlake_pp_object_walker(ctx, pp_context);
1476 intel_batchbuffer_end_atomic(batch);
1479 // update u/v offset when the surface format are packed yuv
1480 static void i965_update_src_surface_static_parameter(
1481 VADriverContextP ctx,
1482 struct i965_post_processing_context *pp_context,
1483 const struct i965_surface *surface)
1485 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1486 int fourcc = pp_get_surface_fourcc(ctx, surface);
1489 case VA_FOURCC_YUY2:
1490 pp_static_parameter->grf1.source_packed_u_offset = 1;
1491 pp_static_parameter->grf1.source_packed_v_offset = 3;
1493 case VA_FOURCC_UYVY:
1494 pp_static_parameter->grf1.source_packed_y_offset = 1;
1495 pp_static_parameter->grf1.source_packed_v_offset = 2;
1497 case VA_FOURCC_BGRX:
1498 case VA_FOURCC_BGRA:
1499 pp_static_parameter->grf1.source_rgb_layout = 0;
1501 case VA_FOURCC_RGBX:
1502 case VA_FOURCC_RGBA:
1503 pp_static_parameter->grf1.source_rgb_layout = 1;
1511 static void i965_update_dst_surface_static_parameter(
1512 VADriverContextP ctx,
1513 struct i965_post_processing_context *pp_context,
1514 const struct i965_surface *surface)
1516 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1517 int fourcc = pp_get_surface_fourcc(ctx, surface);
1520 case VA_FOURCC_YUY2:
1521 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_u_offset = 1;
1522 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 3;
1524 case VA_FOURCC_UYVY:
1525 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_y_offset = 1;
1526 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 2;
1528 case VA_FOURCC_BGRX:
1529 case VA_FOURCC_BGRA:
1530 pp_static_parameter->grf1.r1_2.csc.destination_rgb_layout = 0;
1532 case VA_FOURCC_RGBX:
1533 case VA_FOURCC_RGBA:
1534 pp_static_parameter->grf1.r1_2.csc.destination_rgb_layout = 1;
1543 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1544 dri_bo *surf_bo, unsigned long surf_bo_offset,
1545 int width, int height, int pitch, int format,
1546 int index, int is_target)
1548 struct i965_surface_state *ss;
1550 unsigned int tiling;
1551 unsigned int swizzle;
1553 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1554 ss_bo = pp_context->surface_state_binding_table.bo;
1557 dri_bo_map(ss_bo, True);
1558 assert(ss_bo->virtual);
1559 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1560 memset(ss, 0, sizeof(*ss));
1561 ss->ss0.surface_type = I965_SURFACE_2D;
1562 ss->ss0.surface_format = format;
1563 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1564 ss->ss2.width = width - 1;
1565 ss->ss2.height = height - 1;
1566 ss->ss3.pitch = pitch - 1;
1567 pp_set_surface_tiling(ss, tiling);
1568 dri_bo_emit_reloc(ss_bo,
1569 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1571 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
1573 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1574 dri_bo_unmap(ss_bo);
1578 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1579 dri_bo *surf_bo, unsigned long surf_bo_offset,
1580 int width, int height, int wpitch,
1581 int xoffset, int yoffset,
1582 int format, int interleave_chroma,
1585 struct i965_surface_state2 *ss2;
1587 unsigned int tiling;
1588 unsigned int swizzle;
1590 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1591 ss2_bo = pp_context->surface_state_binding_table.bo;
1594 dri_bo_map(ss2_bo, True);
1595 assert(ss2_bo->virtual);
1596 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1597 memset(ss2, 0, sizeof(*ss2));
1598 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1599 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1600 ss2->ss1.width = width - 1;
1601 ss2->ss1.height = height - 1;
1602 ss2->ss2.pitch = wpitch - 1;
1603 ss2->ss2.interleave_chroma = interleave_chroma;
1604 ss2->ss2.surface_format = format;
1605 ss2->ss3.x_offset_for_cb = xoffset;
1606 ss2->ss3.y_offset_for_cb = yoffset;
1607 pp_set_surface2_tiling(ss2, tiling);
1608 dri_bo_emit_reloc(ss2_bo,
1609 I915_GEM_DOMAIN_RENDER, 0,
1611 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
1613 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1614 dri_bo_unmap(ss2_bo);
1618 gen7_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1619 dri_bo *surf_bo, unsigned long surf_bo_offset,
1620 int width, int height, int pitch, int format,
1621 int index, int is_target)
1623 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1624 struct gen7_surface_state *ss;
1626 unsigned int tiling;
1627 unsigned int swizzle;
1629 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1630 ss_bo = pp_context->surface_state_binding_table.bo;
1633 dri_bo_map(ss_bo, True);
1634 assert(ss_bo->virtual);
1635 ss = (struct gen7_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1636 memset(ss, 0, sizeof(*ss));
1637 ss->ss0.surface_type = I965_SURFACE_2D;
1638 ss->ss0.surface_format = format;
1639 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1640 ss->ss2.width = width - 1;
1641 ss->ss2.height = height - 1;
1642 ss->ss3.pitch = pitch - 1;
1643 gen7_pp_set_surface_tiling(ss, tiling);
1644 if (IS_HASWELL(i965->intel.device_info))
1645 gen7_render_set_surface_scs(ss);
1646 dri_bo_emit_reloc(ss_bo,
1647 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1649 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state, ss1),
1651 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1652 dri_bo_unmap(ss_bo);
1656 gen7_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1657 dri_bo *surf_bo, unsigned long surf_bo_offset,
1658 int width, int height, int wpitch,
1659 int xoffset, int yoffset,
1660 int format, int interleave_chroma,
1663 struct gen7_surface_state2 *ss2;
1665 unsigned int tiling;
1666 unsigned int swizzle;
1668 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1669 ss2_bo = pp_context->surface_state_binding_table.bo;
1672 dri_bo_map(ss2_bo, True);
1673 assert(ss2_bo->virtual);
1674 ss2 = (struct gen7_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1675 memset(ss2, 0, sizeof(*ss2));
1676 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1677 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1678 ss2->ss1.width = width - 1;
1679 ss2->ss1.height = height - 1;
1680 ss2->ss2.pitch = wpitch - 1;
1681 ss2->ss2.interleave_chroma = interleave_chroma;
1682 ss2->ss2.surface_format = format;
1683 ss2->ss3.x_offset_for_cb = xoffset;
1684 ss2->ss3.y_offset_for_cb = yoffset;
1685 gen7_pp_set_surface2_tiling(ss2, tiling);
1686 dri_bo_emit_reloc(ss2_bo,
1687 I915_GEM_DOMAIN_RENDER, 0,
1689 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state2, ss0),
1691 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1692 dri_bo_unmap(ss2_bo);
1696 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1697 const struct i965_surface *surface,
1698 int base_index, int is_target,
1699 int *width, int *height, int *pitch, int *offset)
1701 struct object_surface *obj_surface;
1702 struct object_image *obj_image;
1704 int fourcc = pp_get_surface_fourcc(ctx, surface);
1706 const int U = ((fourcc == VA_FOURCC_YV12) ||
1707 (fourcc == VA_FOURCC_YV16))
1709 const int V = ((fourcc == VA_FOURCC_YV12) ||
1710 (fourcc == VA_FOURCC_YV16))
1713 int interleaved_uv = fourcc == VA_FOURCC_NV12;
1714 int packed_yuv = (fourcc == VA_FOURCC_YUY2 || fourcc == VA_FOURCC_UYVY);
1715 int full_packed_format = (fourcc == VA_FOURCC_RGBA ||
1716 fourcc == VA_FOURCC_RGBX ||
1717 fourcc == VA_FOURCC_BGRA ||
1718 fourcc == VA_FOURCC_BGRX);
1719 int scale_factor_of_1st_plane_width_in_byte = 1;
1721 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1722 obj_surface = (struct object_surface *)surface->base;
1723 bo = obj_surface->bo;
1724 width[0] = obj_surface->orig_width;
1725 height[0] = obj_surface->orig_height;
1726 pitch[0] = obj_surface->width;
1729 if (full_packed_format) {
1730 scale_factor_of_1st_plane_width_in_byte = 4;
1732 else if (packed_yuv ) {
1733 scale_factor_of_1st_plane_width_in_byte = 2;
1735 else if (interleaved_uv) {
1736 width[1] = obj_surface->orig_width;
1737 height[1] = obj_surface->orig_height / 2;
1738 pitch[1] = obj_surface->width;
1739 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1741 width[1] = obj_surface->orig_width / 2;
1742 height[1] = obj_surface->orig_height / 2;
1743 pitch[1] = obj_surface->width / 2;
1744 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
1745 width[2] = obj_surface->orig_width / 2;
1746 height[2] = obj_surface->orig_height / 2;
1747 pitch[2] = obj_surface->width / 2;
1748 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
1751 obj_image = (struct object_image *)surface->base;
1753 width[0] = obj_image->image.width;
1754 height[0] = obj_image->image.height;
1755 pitch[0] = obj_image->image.pitches[0];
1756 offset[0] = obj_image->image.offsets[0];
1758 if (full_packed_format) {
1759 scale_factor_of_1st_plane_width_in_byte = 4;
1761 else if (packed_yuv ) {
1762 scale_factor_of_1st_plane_width_in_byte = 2;
1764 else if (interleaved_uv) {
1765 width[1] = obj_image->image.width;
1766 height[1] = obj_image->image.height / 2;
1767 pitch[1] = obj_image->image.pitches[1];
1768 offset[1] = obj_image->image.offsets[1];
1770 width[1] = obj_image->image.width / 2;
1771 height[1] = obj_image->image.height / 2;
1772 pitch[1] = obj_image->image.pitches[1];
1773 offset[1] = obj_image->image.offsets[1];
1774 width[2] = obj_image->image.width / 2;
1775 height[2] = obj_image->image.height / 2;
1776 pitch[2] = obj_image->image.pitches[2];
1777 offset[2] = obj_image->image.offsets[2];
1778 if (fourcc == VA_FOURCC_YV16) {
1779 width[1] = obj_image->image.width / 2;
1780 height[1] = obj_image->image.height;
1781 width[2] = obj_image->image.width / 2;
1782 height[2] = obj_image->image.height;
1788 i965_pp_set_surface_state(ctx, pp_context,
1790 width[Y] *scale_factor_of_1st_plane_width_in_byte / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
1791 base_index, is_target);
1793 if (!packed_yuv && !full_packed_format) {
1794 if (interleaved_uv) {
1795 i965_pp_set_surface_state(ctx, pp_context,
1797 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
1798 base_index + 1, is_target);
1801 i965_pp_set_surface_state(ctx, pp_context,
1803 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
1804 base_index + 1, is_target);
1807 i965_pp_set_surface_state(ctx, pp_context,
1809 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
1810 base_index + 2, is_target);
1817 gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1818 const struct i965_surface *surface,
1819 int base_index, int is_target,
1820 const VARectangle *rect,
1821 int *width, int *height, int *pitch, int *offset)
1823 struct object_surface *obj_surface;
1824 struct object_image *obj_image;
1826 int fourcc = pp_get_surface_fourcc(ctx, surface);
1827 const i965_fourcc_info *fourcc_info = get_fourcc_info(fourcc);
1829 if (fourcc_info == NULL)
1832 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1833 obj_surface = (struct object_surface *)surface->base;
1834 bo = obj_surface->bo;
1835 width[0] = MIN(rect->x + rect->width, obj_surface->orig_width);
1836 height[0] = MIN(rect->y + rect->height, obj_surface->orig_height);
1837 pitch[0] = obj_surface->width;
1840 if (fourcc_info->num_planes == 1 && is_target)
1841 width[0] = width[0] * (fourcc_info->bpp[0] / 8); /* surface format is R8 */
1843 width[1] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_surface->cb_cr_width);
1844 height[1] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_surface->cb_cr_height);
1845 pitch[1] = obj_surface->cb_cr_pitch;
1846 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
1848 width[2] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_surface->cb_cr_width);
1849 height[2] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_surface->cb_cr_height);
1850 pitch[2] = obj_surface->cb_cr_pitch;
1851 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
1855 /* FIXME: add support for ARGB/ABGR image */
1856 obj_image = (struct object_image *)surface->base;
1858 width[0] = MIN(rect->x + rect->width, obj_image->image.width);
1859 height[0] = MIN(rect->y + rect->height, obj_image->image.height);
1860 pitch[0] = obj_image->image.pitches[0];
1861 offset[0] = obj_image->image.offsets[0];
1863 if (fourcc_info->num_planes == 1) {
1865 width[0] = width[0] * (fourcc_info->bpp[0] / 8); /* surface format is R8 */
1866 } else if (fourcc_info->num_planes == 2) {
1869 assert(fourcc_info->num_components == 3);
1871 U = fourcc_info->components[1].plane;
1872 V = fourcc_info->components[2].plane;
1873 assert((U == 1 && V == 2) ||
1874 (U == 2 && V == 1));
1877 /* Always set width/height although they aren't used for fourcc_info->num_planes == 1 */
1878 width[1] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_image->image.width / fourcc_info->hfactor);
1879 height[1] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_image->image.height / fourcc_info->vfactor);
1880 pitch[1] = obj_image->image.pitches[U];
1881 offset[1] = obj_image->image.offsets[U];
1883 width[2] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_image->image.width / fourcc_info->hfactor);
1884 height[2] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_image->image.height / fourcc_info->vfactor);
1885 pitch[2] = obj_image->image.pitches[V];
1886 offset[2] = obj_image->image.offsets[V];
1890 gen7_pp_set_surface_state(ctx, pp_context,
1892 width[0] / 4, height[0], pitch[0],
1893 I965_SURFACEFORMAT_R8_UINT,
1896 if (fourcc_info->num_planes == 2) {
1897 gen7_pp_set_surface_state(ctx, pp_context,
1899 width[1] / 2, height[1], pitch[1],
1900 I965_SURFACEFORMAT_R8G8_SINT,
1902 } else if (fourcc_info->num_planes == 3) {
1903 gen7_pp_set_surface_state(ctx, pp_context,
1905 width[1] / 4, height[1], pitch[1],
1906 I965_SURFACEFORMAT_R8_SINT,
1908 gen7_pp_set_surface_state(ctx, pp_context,
1910 width[2] / 4, height[2], pitch[2],
1911 I965_SURFACEFORMAT_R8_SINT,
1915 if (fourcc_info->format == I965_COLOR_RGB) {
1916 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1917 /* the format is MSB: X-B-G-R */
1918 pp_static_parameter->grf2.save_avs_rgb_swap = 0;
1919 if ((fourcc == VA_FOURCC_BGRA) ||
1920 (fourcc == VA_FOURCC_BGRX)) {
1921 /* It is stored as MSB: X-R-G-B */
1922 pp_static_parameter->grf2.save_avs_rgb_swap = 1;
1926 int format0 = SURFACE_FORMAT_Y8_UNORM;
1929 case VA_FOURCC_YUY2:
1930 format0 = SURFACE_FORMAT_YCRCB_NORMAL;
1933 case VA_FOURCC_UYVY:
1934 format0 = SURFACE_FORMAT_YCRCB_SWAPY;
1941 if (fourcc_info->format == I965_COLOR_RGB) {
1942 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1943 /* Only R8G8B8A8_UNORM is supported for BGRX or RGBX */
1944 format0 = SURFACE_FORMAT_R8G8B8A8_UNORM;
1945 pp_static_parameter->grf2.src_avs_rgb_swap = 0;
1946 if ((fourcc == VA_FOURCC_BGRA) ||
1947 (fourcc == VA_FOURCC_BGRX)) {
1948 pp_static_parameter->grf2.src_avs_rgb_swap = 1;
1952 gen7_pp_set_surface2_state(ctx, pp_context,
1954 width[0], height[0], pitch[0],
1959 if (fourcc_info->num_planes == 2) {
1960 gen7_pp_set_surface2_state(ctx, pp_context,
1962 width[1], height[1], pitch[1],
1964 SURFACE_FORMAT_R8B8_UNORM, 0,
1966 } else if (fourcc_info->num_planes == 3) {
1967 gen7_pp_set_surface2_state(ctx, pp_context,
1969 width[1], height[1], pitch[1],
1971 SURFACE_FORMAT_R8_UNORM, 0,
1973 gen7_pp_set_surface2_state(ctx, pp_context,
1975 width[2], height[2], pitch[2],
1977 SURFACE_FORMAT_R8_UNORM, 0,
1984 pp_null_x_steps(void *private_context)
1990 pp_null_y_steps(void *private_context)
1996 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2002 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2003 const struct i965_surface *src_surface,
2004 const VARectangle *src_rect,
2005 struct i965_surface *dst_surface,
2006 const VARectangle *dst_rect,
2009 /* private function & data */
2010 pp_context->pp_x_steps = pp_null_x_steps;
2011 pp_context->pp_y_steps = pp_null_y_steps;
2012 pp_context->private_context = NULL;
2013 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
2015 dst_surface->flags = src_surface->flags;
2017 return VA_STATUS_SUCCESS;
2021 pp_load_save_x_steps(void *private_context)
2027 pp_load_save_y_steps(void *private_context)
2029 struct pp_load_save_context *pp_load_save_context = private_context;
2031 return pp_load_save_context->dest_h / 8;
2035 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2037 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2038 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)pp_context->private_context;
2040 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_load_save_context->dest_x;
2041 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_load_save_context->dest_y;
2046 static void calculate_boundary_block_mask(struct i965_post_processing_context *pp_context, const VARectangle *dst_rect)
2049 /* x offset of dest surface must be dword aligned.
2050 * so we have to extend dst surface on left edge, and mask out pixels not interested
2052 if (dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT) {
2053 pp_context->block_horizontal_mask_left = 0;
2054 for (i=dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT; i<GPU_ASM_BLOCK_WIDTH; i++)
2056 pp_context->block_horizontal_mask_left |= 1<<i;
2060 pp_context->block_horizontal_mask_left = 0xffff;
2063 int dst_width_adjust = dst_rect->width + dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;
2064 if (dst_width_adjust%GPU_ASM_BLOCK_WIDTH){
2065 pp_context->block_horizontal_mask_right = (1 << (dst_width_adjust%GPU_ASM_BLOCK_WIDTH)) - 1;
2068 pp_context->block_horizontal_mask_right = 0xffff;
2071 if (dst_rect->height%GPU_ASM_BLOCK_HEIGHT){
2072 pp_context->block_vertical_mask_bottom = (1 << (dst_rect->height%GPU_ASM_BLOCK_HEIGHT)) - 1;
2075 pp_context->block_vertical_mask_bottom = 0xff;
2080 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2081 const struct i965_surface *src_surface,
2082 const VARectangle *src_rect,
2083 struct i965_surface *dst_surface,
2084 const VARectangle *dst_rect,
2087 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->pp_load_save_context;
2088 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2089 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2090 int width[3], height[3], pitch[3], offset[3];
2092 /* source surface */
2093 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
2094 width, height, pitch, offset);
2096 /* destination surface */
2097 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
2098 width, height, pitch, offset);
2100 /* private function & data */
2101 pp_context->pp_x_steps = pp_load_save_x_steps;
2102 pp_context->pp_y_steps = pp_load_save_y_steps;
2103 pp_context->private_context = &pp_context->pp_load_save_context;
2104 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
2106 int dst_left_edge_extend = dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;;
2107 pp_load_save_context->dest_x = dst_rect->x - dst_left_edge_extend;
2108 pp_load_save_context->dest_y = dst_rect->y;
2109 pp_load_save_context->dest_h = ALIGN(dst_rect->height, 8);
2110 pp_load_save_context->dest_w = ALIGN(dst_rect->width+dst_left_edge_extend, 16);
2112 pp_inline_parameter->grf5.block_count_x = pp_load_save_context->dest_w / 16; /* 1 x N */
2113 pp_inline_parameter->grf5.number_blocks = pp_load_save_context->dest_w / 16;
2115 pp_static_parameter->grf3.horizontal_origin_offset = src_rect->x;
2116 pp_static_parameter->grf3.vertical_origin_offset = src_rect->y;
2118 // update u/v offset for packed yuv
2119 i965_update_src_surface_static_parameter (ctx, pp_context, src_surface);
2120 i965_update_dst_surface_static_parameter (ctx, pp_context, dst_surface);
2122 dst_surface->flags = src_surface->flags;
2124 return VA_STATUS_SUCCESS;
2128 pp_scaling_x_steps(void *private_context)
2134 pp_scaling_y_steps(void *private_context)
2136 struct pp_scaling_context *pp_scaling_context = private_context;
2138 return pp_scaling_context->dest_h / 8;
2142 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2144 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)pp_context->private_context;
2145 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2146 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2147 float src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2148 float src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
2150 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
2151 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
2152 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
2153 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
2159 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2160 const struct i965_surface *src_surface,
2161 const VARectangle *src_rect,
2162 struct i965_surface *dst_surface,
2163 const VARectangle *dst_rect,
2166 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->pp_scaling_context;
2167 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2168 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2169 struct object_surface *obj_surface;
2170 struct i965_sampler_state *sampler_state;
2171 int in_w, in_h, in_wpitch, in_hpitch;
2172 int out_w, out_h, out_wpitch, out_hpitch;
2174 /* source surface */
2175 obj_surface = (struct object_surface *)src_surface->base;
2176 in_w = obj_surface->orig_width;
2177 in_h = obj_surface->orig_height;
2178 in_wpitch = obj_surface->width;
2179 in_hpitch = obj_surface->height;
2181 /* source Y surface index 1 */
2182 i965_pp_set_surface_state(ctx, pp_context,
2184 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
2187 /* source UV surface index 2 */
2188 i965_pp_set_surface_state(ctx, pp_context,
2189 obj_surface->bo, in_wpitch * in_hpitch,
2190 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
2193 /* destination surface */
2194 obj_surface = (struct object_surface *)dst_surface->base;
2195 out_w = obj_surface->orig_width;
2196 out_h = obj_surface->orig_height;
2197 out_wpitch = obj_surface->width;
2198 out_hpitch = obj_surface->height;
2200 /* destination Y surface index 7 */
2201 i965_pp_set_surface_state(ctx, pp_context,
2203 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
2206 /* destination UV surface index 8 */
2207 i965_pp_set_surface_state(ctx, pp_context,
2208 obj_surface->bo, out_wpitch * out_hpitch,
2209 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
2213 dri_bo_map(pp_context->sampler_state_table.bo, True);
2214 assert(pp_context->sampler_state_table.bo->virtual);
2215 sampler_state = pp_context->sampler_state_table.bo->virtual;
2217 /* SIMD16 Y index 1 */
2218 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
2219 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
2220 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2221 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2222 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2224 /* SIMD16 UV index 2 */
2225 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
2226 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
2227 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2228 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2229 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2231 dri_bo_unmap(pp_context->sampler_state_table.bo);
2233 /* private function & data */
2234 pp_context->pp_x_steps = pp_scaling_x_steps;
2235 pp_context->pp_y_steps = pp_scaling_y_steps;
2236 pp_context->private_context = &pp_context->pp_scaling_context;
2237 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
2239 int dst_left_edge_extend = dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;
2240 float src_left_edge_extend = (float)dst_left_edge_extend*src_rect->width/dst_rect->width;
2241 pp_scaling_context->dest_x = dst_rect->x - dst_left_edge_extend;
2242 pp_scaling_context->dest_y = dst_rect->y;
2243 pp_scaling_context->dest_w = ALIGN(dst_rect->width + dst_left_edge_extend, 16);
2244 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 8);
2245 pp_scaling_context->src_normalized_x = (float)(src_rect->x - src_left_edge_extend)/ in_w;
2246 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h;
2248 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
2250 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) (src_rect->width + src_left_edge_extend)/ in_w / (dst_rect->width + dst_left_edge_extend);
2251 pp_inline_parameter->grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
2252 pp_inline_parameter->grf5.number_blocks = pp_scaling_context->dest_w / 16;
2254 dst_surface->flags = src_surface->flags;
2256 return VA_STATUS_SUCCESS;
2260 pp_avs_x_steps(void *private_context)
2262 struct pp_avs_context *pp_avs_context = private_context;
2264 return pp_avs_context->dest_w / 16;
2268 pp_avs_y_steps(void *private_context)
2274 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2276 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)pp_context->private_context;
2277 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2278 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2279 float src_x_steping, src_y_steping, video_step_delta;
2280 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
2282 if (pp_static_parameter->grf4.r4_2.avs.nlas == 0) {
2283 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2284 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_avs_context->src_normalized_x;
2285 } else if (tmp_w >= pp_avs_context->dest_w) {
2286 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
2287 pp_inline_parameter->grf6.video_step_delta = 0;
2290 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
2291 pp_avs_context->src_normalized_x;
2293 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2294 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2295 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2296 16 * 15 * video_step_delta / 2;
2299 int n0, n1, n2, nls_left, nls_right;
2300 int factor_a = 5, factor_b = 4;
2303 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
2304 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
2305 n2 = tmp_w / (16 * factor_a);
2307 nls_right = n1 + n2;
2308 f = (float) n2 * 16 / tmp_w;
2311 pp_inline_parameter->grf6.video_step_delta = 0.0;
2314 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
2315 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
2317 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2318 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2319 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2320 16 * 15 * video_step_delta / 2;
2324 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
2325 float a = f / (nls_left * 16 * factor_b);
2326 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
2328 pp_inline_parameter->grf6.video_step_delta = b;
2331 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
2332 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a;
2334 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2335 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2336 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2337 16 * 15 * video_step_delta / 2;
2338 pp_inline_parameter->grf5.normalized_video_x_scaling_step += 16 * b;
2340 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
2341 /* scale the center linearly */
2342 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2343 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2344 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2345 16 * 15 * video_step_delta / 2;
2346 pp_inline_parameter->grf6.video_step_delta = 0.0;
2347 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
2349 float a = f / (nls_right * 16 * factor_b);
2350 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
2352 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2353 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2354 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2355 16 * 15 * video_step_delta / 2;
2356 pp_inline_parameter->grf6.video_step_delta = -b;
2358 if (x == (pp_avs_context->dest_w / 16 - nls_right))
2359 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
2361 pp_inline_parameter->grf5.normalized_video_x_scaling_step -= b * 16;
2366 src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
2367 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
2368 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
2369 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
2375 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2376 const struct i965_surface *src_surface,
2377 const VARectangle *src_rect,
2378 struct i965_surface *dst_surface,
2379 const VARectangle *dst_rect,
2383 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->pp_avs_context;
2384 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2385 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2386 struct object_surface *obj_surface;
2387 struct i965_sampler_8x8 *sampler_8x8;
2388 struct i965_sampler_8x8_state *sampler_8x8_state;
2390 int in_w, in_h, in_wpitch, in_hpitch;
2391 int out_w, out_h, out_wpitch, out_hpitch;
2395 obj_surface = (struct object_surface *)src_surface->base;
2396 in_w = obj_surface->orig_width;
2397 in_h = obj_surface->orig_height;
2398 in_wpitch = obj_surface->width;
2399 in_hpitch = obj_surface->height;
2401 /* source Y surface index 1 */
2402 i965_pp_set_surface2_state(ctx, pp_context,
2404 in_w, in_h, in_wpitch,
2406 SURFACE_FORMAT_Y8_UNORM, 0,
2409 /* source UV surface index 2 */
2410 i965_pp_set_surface2_state(ctx, pp_context,
2411 obj_surface->bo, in_wpitch * in_hpitch,
2412 in_w / 2, in_h / 2, in_wpitch,
2414 SURFACE_FORMAT_R8B8_UNORM, 0,
2417 /* destination surface */
2418 obj_surface = (struct object_surface *)dst_surface->base;
2419 out_w = obj_surface->orig_width;
2420 out_h = obj_surface->orig_height;
2421 out_wpitch = obj_surface->width;
2422 out_hpitch = obj_surface->height;
2423 assert(out_w <= out_wpitch && out_h <= out_hpitch);
2425 /* destination Y surface index 7 */
2426 i965_pp_set_surface_state(ctx, pp_context,
2428 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
2431 /* destination UV surface index 8 */
2432 i965_pp_set_surface_state(ctx, pp_context,
2433 obj_surface->bo, out_wpitch * out_hpitch,
2434 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
2437 /* sampler 8x8 state */
2438 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
2439 assert(pp_context->sampler_state_table.bo_8x8->virtual);
2440 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
2441 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
2442 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
2444 for (i = 0; i < 17; i++) {
2445 /* for Y channel, currently ignore */
2446 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x00;
2447 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x00;
2448 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x08;
2449 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x18;
2450 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x18;
2451 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x08;
2452 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x00;
2453 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x00;
2454 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x00;
2455 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x00;
2456 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x10;
2457 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x10;
2458 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x10;
2459 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x10;
2460 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x00;
2461 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x00;
2462 /* for U/V channel, 0.25 */
2463 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
2464 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
2465 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
2466 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
2467 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
2468 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
2469 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
2470 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
2471 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
2472 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
2473 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
2474 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
2475 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
2476 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
2477 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
2478 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
2481 sampler_8x8_state->dw136.default_sharpness_level = 0;
2482 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
2483 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
2484 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
2485 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
2488 dri_bo_map(pp_context->sampler_state_table.bo, True);
2489 assert(pp_context->sampler_state_table.bo->virtual);
2490 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
2491 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
2493 /* sample_8x8 Y index 1 */
2495 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2496 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
2497 sampler_8x8[index].dw0.ief_bypass = 1;
2498 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
2499 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
2500 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2501 sampler_8x8[index].dw2.global_noise_estimation = 22;
2502 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2503 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2504 sampler_8x8[index].dw3.strong_edge_weight = 7;
2505 sampler_8x8[index].dw3.regular_weight = 2;
2506 sampler_8x8[index].dw3.non_edge_weight = 0;
2507 sampler_8x8[index].dw3.gain_factor = 40;
2508 sampler_8x8[index].dw4.steepness_boost = 0;
2509 sampler_8x8[index].dw4.steepness_threshold = 0;
2510 sampler_8x8[index].dw4.mr_boost = 0;
2511 sampler_8x8[index].dw4.mr_threshold = 5;
2512 sampler_8x8[index].dw5.pwl1_point_1 = 4;
2513 sampler_8x8[index].dw5.pwl1_point_2 = 12;
2514 sampler_8x8[index].dw5.pwl1_point_3 = 16;
2515 sampler_8x8[index].dw5.pwl1_point_4 = 26;
2516 sampler_8x8[index].dw6.pwl1_point_5 = 40;
2517 sampler_8x8[index].dw6.pwl1_point_6 = 160;
2518 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
2519 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
2520 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
2521 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
2522 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
2523 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
2524 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
2525 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
2526 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
2527 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
2528 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
2529 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
2530 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
2531 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
2532 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
2533 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
2534 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
2535 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
2536 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
2537 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
2538 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
2539 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
2540 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
2541 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
2542 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
2543 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
2544 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
2545 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
2546 sampler_8x8[index].dw13.limiter_boost = 0;
2547 sampler_8x8[index].dw13.minimum_limiter = 10;
2548 sampler_8x8[index].dw13.maximum_limiter = 11;
2549 sampler_8x8[index].dw14.clip_limiter = 130;
2550 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2551 I915_GEM_DOMAIN_RENDER,
2554 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2555 pp_context->sampler_state_table.bo_8x8);
2557 /* sample_8x8 UV index 2 */
2559 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2560 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
2561 sampler_8x8[index].dw0.ief_bypass = 1;
2562 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
2563 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
2564 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2565 sampler_8x8[index].dw2.global_noise_estimation = 22;
2566 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2567 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2568 sampler_8x8[index].dw3.strong_edge_weight = 7;
2569 sampler_8x8[index].dw3.regular_weight = 2;
2570 sampler_8x8[index].dw3.non_edge_weight = 0;
2571 sampler_8x8[index].dw3.gain_factor = 40;
2572 sampler_8x8[index].dw4.steepness_boost = 0;
2573 sampler_8x8[index].dw4.steepness_threshold = 0;
2574 sampler_8x8[index].dw4.mr_boost = 0;
2575 sampler_8x8[index].dw4.mr_threshold = 5;
2576 sampler_8x8[index].dw5.pwl1_point_1 = 4;
2577 sampler_8x8[index].dw5.pwl1_point_2 = 12;
2578 sampler_8x8[index].dw5.pwl1_point_3 = 16;
2579 sampler_8x8[index].dw5.pwl1_point_4 = 26;
2580 sampler_8x8[index].dw6.pwl1_point_5 = 40;
2581 sampler_8x8[index].dw6.pwl1_point_6 = 160;
2582 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
2583 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
2584 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
2585 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
2586 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
2587 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
2588 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
2589 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
2590 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
2591 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
2592 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
2593 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
2594 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
2595 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
2596 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
2597 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
2598 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
2599 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
2600 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
2601 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
2602 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
2603 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
2604 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
2605 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
2606 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
2607 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
2608 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
2609 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
2610 sampler_8x8[index].dw13.limiter_boost = 0;
2611 sampler_8x8[index].dw13.minimum_limiter = 10;
2612 sampler_8x8[index].dw13.maximum_limiter = 11;
2613 sampler_8x8[index].dw14.clip_limiter = 130;
2614 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2615 I915_GEM_DOMAIN_RENDER,
2618 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2619 pp_context->sampler_state_table.bo_8x8);
2621 dri_bo_unmap(pp_context->sampler_state_table.bo);
2623 /* private function & data */
2624 pp_context->pp_x_steps = pp_avs_x_steps;
2625 pp_context->pp_y_steps = pp_avs_y_steps;
2626 pp_context->private_context = &pp_context->pp_avs_context;
2627 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
2629 int dst_left_edge_extend = dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;
2630 float src_left_edge_extend = (float)dst_left_edge_extend*src_rect->width/dst_rect->width;
2631 pp_avs_context->dest_x = dst_rect->x - dst_left_edge_extend;
2632 pp_avs_context->dest_y = dst_rect->y;
2633 pp_avs_context->dest_w = ALIGN(dst_rect->width + dst_left_edge_extend, 16);
2634 pp_avs_context->dest_h = ALIGN(dst_rect->height, 8);
2635 pp_avs_context->src_normalized_x = (float)(src_rect->x - src_left_edge_extend)/ in_w;
2636 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h;
2637 pp_avs_context->src_w = src_rect->width + src_left_edge_extend;
2638 pp_avs_context->src_h = src_rect->height;
2640 pp_static_parameter->grf4.r4_2.avs.nlas = nlas;
2641 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
2643 pp_inline_parameter->grf5.normalized_video_x_scaling_step = (float) (src_rect->width + src_left_edge_extend)/ in_w / (dst_rect->width + dst_left_edge_extend);
2644 pp_inline_parameter->grf5.block_count_x = 1; /* M x 1 */
2645 pp_inline_parameter->grf5.number_blocks = pp_avs_context->dest_h / 8;
2646 pp_inline_parameter->grf6.video_step_delta = 0.0;
2648 dst_surface->flags = src_surface->flags;
2650 return VA_STATUS_SUCCESS;
2654 pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2655 const struct i965_surface *src_surface,
2656 const VARectangle *src_rect,
2657 struct i965_surface *dst_surface,
2658 const VARectangle *dst_rect,
2661 return pp_nv12_avs_initialize(ctx, pp_context,
2671 gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2672 const struct i965_surface *src_surface,
2673 const VARectangle *src_rect,
2674 struct i965_surface *dst_surface,
2675 const VARectangle *dst_rect,
2678 return pp_nv12_avs_initialize(ctx, pp_context,
2688 gen7_pp_avs_x_steps(void *private_context)
2690 struct pp_avs_context *pp_avs_context = private_context;
2692 return pp_avs_context->dest_w / 16;
2696 gen7_pp_avs_y_steps(void *private_context)
2698 struct pp_avs_context *pp_avs_context = private_context;
2700 return pp_avs_context->dest_h / 16;
2704 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2706 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)pp_context->private_context;
2707 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2709 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
2710 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
2711 pp_inline_parameter->grf7.constant_0 = 0xffffffff;
2712 pp_inline_parameter->grf7.sampler_load_main_video_x_scaling_step = pp_avs_context->horiz_range / pp_avs_context->src_w;
2717 static void gen7_update_src_surface_uv_offset(VADriverContextP ctx,
2718 struct i965_post_processing_context *pp_context,
2719 const struct i965_surface *surface)
2721 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2722 int fourcc = pp_get_surface_fourcc(ctx, surface);
2724 if (fourcc == VA_FOURCC_YUY2) {
2725 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
2726 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
2727 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
2728 } else if (fourcc == VA_FOURCC_UYVY) {
2729 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 1;
2730 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 0;
2731 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 2;
2736 gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2737 const struct i965_surface *src_surface,
2738 const VARectangle *src_rect,
2739 struct i965_surface *dst_surface,
2740 const VARectangle *dst_rect,
2743 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->pp_avs_context;
2744 struct i965_driver_data *i965 = i965_driver_data(ctx);
2745 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2746 struct gen7_sampler_8x8 *sampler_8x8;
2747 struct i965_sampler_8x8_state *sampler_8x8_state;
2749 int width[3], height[3], pitch[3], offset[3];
2750 int src_width, src_height;
2752 /* source surface */
2753 gen7_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
2755 width, height, pitch, offset);
2756 src_width = width[0];
2757 src_height = height[0];
2759 /* destination surface */
2760 gen7_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
2762 width, height, pitch, offset);
2764 /* sampler 8x8 state */
2765 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
2766 assert(pp_context->sampler_state_table.bo_8x8->virtual);
2767 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
2768 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
2769 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
2771 for (i = 0; i < 17; i++) {
2775 /* for Y channel, currently ignore */
2776 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
2777 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
2778 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
2779 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = intel_format_convert(1 - coff, 1, 6,0);
2780 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = intel_format_convert(coff, 1, 6, 0);
2781 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
2782 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
2783 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
2784 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
2785 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
2786 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
2787 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
2788 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = intel_format_convert(coff, 1, 6, 0);
2789 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
2790 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
2791 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
2792 /* for U/V channel, 0.25 */
2793 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
2794 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
2795 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x0;
2796 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
2797 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = intel_format_convert(coff, 1, 6, 0);
2798 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0;
2799 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
2800 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
2801 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
2802 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
2803 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x0;
2804 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
2805 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = intel_format_convert(coff, 1, 6, 0);
2806 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x0;
2807 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
2808 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
2811 sampler_8x8_state->dw136.default_sharpness_level = 0;
2812 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
2813 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
2814 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
2815 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
2818 dri_bo_map(pp_context->sampler_state_table.bo, True);
2819 assert(pp_context->sampler_state_table.bo->virtual);
2820 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
2821 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
2823 /* sample_8x8 Y index 4 */
2825 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2826 sampler_8x8[index].dw0.global_noise_estimation = 255;
2827 sampler_8x8[index].dw0.ief_bypass = 1;
2829 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2831 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2832 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2833 sampler_8x8[index].dw2.r5x_coefficient = 9;
2834 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2835 sampler_8x8[index].dw2.r5c_coefficient = 3;
2837 sampler_8x8[index].dw3.r3x_coefficient = 27;
2838 sampler_8x8[index].dw3.r3c_coefficient = 5;
2839 sampler_8x8[index].dw3.gain_factor = 40;
2840 sampler_8x8[index].dw3.non_edge_weight = 1;
2841 sampler_8x8[index].dw3.regular_weight = 2;
2842 sampler_8x8[index].dw3.strong_edge_weight = 7;
2843 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2845 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2846 I915_GEM_DOMAIN_RENDER,
2849 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2850 pp_context->sampler_state_table.bo_8x8);
2852 /* sample_8x8 UV index 8 */
2854 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2855 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2856 sampler_8x8[index].dw0.global_noise_estimation = 255;
2857 sampler_8x8[index].dw0.ief_bypass = 1;
2858 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2859 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2860 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2861 sampler_8x8[index].dw2.r5x_coefficient = 9;
2862 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2863 sampler_8x8[index].dw2.r5c_coefficient = 3;
2864 sampler_8x8[index].dw3.r3x_coefficient = 27;
2865 sampler_8x8[index].dw3.r3c_coefficient = 5;
2866 sampler_8x8[index].dw3.gain_factor = 40;
2867 sampler_8x8[index].dw3.non_edge_weight = 1;
2868 sampler_8x8[index].dw3.regular_weight = 2;
2869 sampler_8x8[index].dw3.strong_edge_weight = 7;
2870 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2872 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2873 I915_GEM_DOMAIN_RENDER,
2876 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2877 pp_context->sampler_state_table.bo_8x8);
2879 /* sampler_8x8 V, index 12 */
2881 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
2882 sampler_8x8[index].dw0.disable_8x8_filter = 0;
2883 sampler_8x8[index].dw0.global_noise_estimation = 255;
2884 sampler_8x8[index].dw0.ief_bypass = 1;
2885 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
2886 sampler_8x8[index].dw2.weak_edge_threshold = 1;
2887 sampler_8x8[index].dw2.strong_edge_threshold = 8;
2888 sampler_8x8[index].dw2.r5x_coefficient = 9;
2889 sampler_8x8[index].dw2.r5cx_coefficient = 8;
2890 sampler_8x8[index].dw2.r5c_coefficient = 3;
2891 sampler_8x8[index].dw3.r3x_coefficient = 27;
2892 sampler_8x8[index].dw3.r3c_coefficient = 5;
2893 sampler_8x8[index].dw3.gain_factor = 40;
2894 sampler_8x8[index].dw3.non_edge_weight = 1;
2895 sampler_8x8[index].dw3.regular_weight = 2;
2896 sampler_8x8[index].dw3.strong_edge_weight = 7;
2897 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
2899 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
2900 I915_GEM_DOMAIN_RENDER,
2903 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
2904 pp_context->sampler_state_table.bo_8x8);
2906 dri_bo_unmap(pp_context->sampler_state_table.bo);
2908 /* private function & data */
2909 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
2910 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
2911 pp_context->private_context = &pp_context->pp_avs_context;
2912 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
2914 pp_avs_context->dest_x = dst_rect->x;
2915 pp_avs_context->dest_y = dst_rect->y;
2916 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
2917 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
2918 pp_avs_context->src_w = src_rect->width;
2919 pp_avs_context->src_h = src_rect->height;
2920 pp_avs_context->horiz_range = (float)src_rect->width / src_width;
2922 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
2923 dw = MAX(dw, dst_rect->width);
2925 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
2926 pp_static_parameter->grf2.avs_wa_enable = 1; /* must be set for GEN7 */
2927 if (IS_HASWELL(i965->intel.device_info))
2928 pp_static_parameter->grf2.avs_wa_enable = 0; /* HSW don't use the WA */
2930 if (pp_static_parameter->grf2.avs_wa_enable) {
2931 int src_fourcc = pp_get_surface_fourcc(ctx, src_surface);
2932 if ((src_fourcc == VA_FOURCC_RGBA) ||
2933 (src_fourcc == VA_FOURCC_RGBX) ||
2934 (src_fourcc == VA_FOURCC_BGRA) ||
2935 (src_fourcc == VA_FOURCC_BGRX)) {
2936 pp_static_parameter->grf2.avs_wa_enable = 0;
2940 pp_static_parameter->grf2.avs_wa_width = src_width;
2941 pp_static_parameter->grf2.avs_wa_one_div_256_width = (float) 1.0 / (256 * src_width);
2942 pp_static_parameter->grf2.avs_wa_five_div_256_width = (float) 5.0 / (256 * src_width);
2943 pp_static_parameter->grf2.alpha = 255;
2945 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
2946 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) src_rect->height / src_height / dst_rect->height;
2947 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = (float) src_rect->y / src_height -
2948 (float) pp_avs_context->dest_y * pp_static_parameter->grf4.sampler_load_vertical_scaling_step;
2949 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = (float) src_rect->x / src_width -
2950 (float) pp_avs_context->dest_x * pp_avs_context->horiz_range / dw;
2952 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
2954 dst_surface->flags = src_surface->flags;
2956 return VA_STATUS_SUCCESS;
2960 pp_dndi_x_steps(void *private_context)
2966 pp_dndi_y_steps(void *private_context)
2968 struct pp_dndi_context *pp_dndi_context = private_context;
2970 return pp_dndi_context->dest_h / 4;
2974 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2976 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2978 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
2979 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
2985 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2986 const struct i965_surface *src_surface,
2987 const VARectangle *src_rect,
2988 struct i965_surface *dst_surface,
2989 const VARectangle *dst_rect,
2992 struct i965_driver_data *i965 = i965_driver_data(ctx);
2993 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->pp_dndi_context;
2994 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2995 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2996 struct object_surface *previous_in_obj_surface, *current_in_obj_surface, *previous_out_obj_surface, *current_out_obj_surface;
2997 struct i965_sampler_dndi *sampler_dndi;
3001 int dndi_top_first = 1;
3002 VAProcFilterParameterBufferDeinterlacing *di_filter_param = (VAProcFilterParameterBufferDeinterlacing *)filter_param;
3003 int is_first_frame = (pp_dndi_context->frame_order == -1);
3005 if (di_filter_param->flags & VA_DEINTERLACING_BOTTOM_FIELD)
3011 current_in_obj_surface = (struct object_surface *)src_surface->base;
3013 if (di_filter_param->algorithm == VAProcDeinterlacingBob) {
3014 previous_in_obj_surface = current_in_obj_surface;
3016 } else if (di_filter_param->algorithm == VAProcDeinterlacingMotionAdaptive) {
3017 if (pp_dndi_context->frame_order == 0) {
3018 VAProcPipelineParameterBuffer *pipeline_param = pp_context->pipeline_param;
3019 if (!pipeline_param ||
3020 !pipeline_param->num_forward_references ||
3021 pipeline_param->forward_references[0] == VA_INVALID_ID) {
3022 WARN_ONCE("A forward temporal reference is needed for Motion adaptive deinterlacing !!!\n");
3024 return VA_STATUS_ERROR_INVALID_PARAMETER;
3026 previous_in_obj_surface = SURFACE(pipeline_param->forward_references[0]);
3027 assert(previous_in_obj_surface && previous_in_obj_surface->bo);
3031 } else if (pp_dndi_context->frame_order == 1) {
3032 vpp_surface_convert(ctx,
3033 pp_dndi_context->current_out_obj_surface,
3034 (struct object_surface *)dst_surface->base);
3035 pp_dndi_context->frame_order = (pp_dndi_context->frame_order + 1) % 2;
3038 return VA_STATUS_SUCCESS_1;
3040 previous_in_obj_surface = current_in_obj_surface;
3044 return VA_STATUS_ERROR_UNIMPLEMENTED;
3047 /* source (temporal reference) YUV surface index 5 */
3048 orig_w = previous_in_obj_surface->orig_width;
3049 orig_h = previous_in_obj_surface->orig_height;
3050 w = previous_in_obj_surface->width;
3051 h = previous_in_obj_surface->height;
3052 i965_pp_set_surface2_state(ctx, pp_context,
3053 previous_in_obj_surface->bo, 0,
3056 SURFACE_FORMAT_PLANAR_420_8, 1,
3059 /* source surface */
3060 orig_w = current_in_obj_surface->orig_width;
3061 orig_h = current_in_obj_surface->orig_height;
3062 w = current_in_obj_surface->width;
3063 h = current_in_obj_surface->height;
3065 /* source UV surface index 2 */
3066 i965_pp_set_surface_state(ctx, pp_context,
3067 current_in_obj_surface->bo, w * h,
3068 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3071 /* source YUV surface index 4 */
3072 i965_pp_set_surface2_state(ctx, pp_context,
3073 current_in_obj_surface->bo, 0,
3076 SURFACE_FORMAT_PLANAR_420_8, 1,
3079 /* source STMM surface index 6 */
3080 if (pp_dndi_context->stmm_bo == NULL) {
3081 pp_dndi_context->stmm_bo = dri_bo_alloc(i965->intel.bufmgr,
3085 assert(pp_dndi_context->stmm_bo);
3088 i965_pp_set_surface_state(ctx, pp_context,
3089 pp_dndi_context->stmm_bo, 0,
3090 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3093 /* destination (Previous frame) */
3094 previous_out_obj_surface = (struct object_surface *)dst_surface->base;
3095 orig_w = previous_out_obj_surface->orig_width;
3096 orig_h = previous_out_obj_surface->orig_height;
3097 w = previous_out_obj_surface->width;
3098 h = previous_out_obj_surface->height;
3100 if (is_first_frame) {
3101 current_out_obj_surface = previous_out_obj_surface;
3105 if (pp_dndi_context->current_out_surface == VA_INVALID_SURFACE) {
3106 unsigned int tiling = 0, swizzle = 0;
3107 dri_bo_get_tiling(previous_out_obj_surface->bo, &tiling, &swizzle);
3109 va_status = i965_CreateSurfaces(ctx,
3112 VA_RT_FORMAT_YUV420,
3114 &pp_dndi_context->current_out_surface);
3115 assert(va_status == VA_STATUS_SUCCESS);
3116 pp_dndi_context->current_out_obj_surface = SURFACE(pp_dndi_context->current_out_surface);
3117 assert(pp_dndi_context->current_out_obj_surface);
3118 i965_check_alloc_surface_bo(ctx,
3119 pp_dndi_context->current_out_obj_surface,
3120 tiling != I915_TILING_NONE,
3125 current_out_obj_surface = pp_dndi_context->current_out_obj_surface;
3128 /* destination (Previous frame) Y surface index 7 */
3129 i965_pp_set_surface_state(ctx, pp_context,
3130 previous_out_obj_surface->bo, 0,
3131 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3134 /* destination (Previous frame) UV surface index 8 */
3135 i965_pp_set_surface_state(ctx, pp_context,
3136 previous_out_obj_surface->bo, w * h,
3137 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3140 /* destination(Current frame) */
3141 orig_w = current_out_obj_surface->orig_width;
3142 orig_h = current_out_obj_surface->orig_height;
3143 w = current_out_obj_surface->width;
3144 h = current_out_obj_surface->height;
3146 /* destination (Current frame) Y surface index xxx */
3147 i965_pp_set_surface_state(ctx, pp_context,
3148 current_out_obj_surface->bo, 0,
3149 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3152 /* destination (Current frame) UV surface index xxx */
3153 i965_pp_set_surface_state(ctx, pp_context,
3154 current_out_obj_surface->bo, w * h,
3155 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3158 /* STMM output surface, index 20 */
3159 i965_pp_set_surface_state(ctx, pp_context,
3160 pp_dndi_context->stmm_bo, 0,
3161 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3165 dri_bo_map(pp_context->sampler_state_table.bo, True);
3166 assert(pp_context->sampler_state_table.bo->virtual);
3167 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
3168 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
3170 /* sample dndi index 1 */
3172 sampler_dndi[index].dw0.denoise_asd_threshold = 38;
3173 sampler_dndi[index].dw0.denoise_history_delta = 7; // 0-15, default is 8
3174 sampler_dndi[index].dw0.denoise_maximum_history = 192; // 128-240
3175 sampler_dndi[index].dw0.denoise_stad_threshold = 140;
3177 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 38;
3178 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 1;
3179 sampler_dndi[index].dw1.stmm_c2 = 1;
3180 sampler_dndi[index].dw1.low_temporal_difference_threshold = 0;
3181 sampler_dndi[index].dw1.temporal_difference_threshold = 0;
3183 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 20; // 0-31
3184 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 1; // 0-15
3185 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
3186 sampler_dndi[index].dw2.good_neighbor_threshold = 12; // 0-63
3188 sampler_dndi[index].dw3.maximum_stmm = 150;
3189 sampler_dndi[index].dw3.multipler_for_vecm = 30;
3190 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 125;
3191 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3192 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
3194 sampler_dndi[index].dw4.sdi_delta = 5;
3195 sampler_dndi[index].dw4.sdi_threshold = 100;
3196 sampler_dndi[index].dw4.stmm_output_shift = 5; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3197 sampler_dndi[index].dw4.stmm_shift_up = 1;
3198 sampler_dndi[index].dw4.stmm_shift_down = 0;
3199 sampler_dndi[index].dw4.minimum_stmm = 118;
3201 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 175;
3202 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 37;
3203 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 100;
3204 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 50;
3206 sampler_dndi[index].dw6.dn_enable = 1;
3207 sampler_dndi[index].dw6.di_enable = 1;
3208 sampler_dndi[index].dw6.di_partial = 0;
3209 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
3210 sampler_dndi[index].dw6.dndi_stream_id = 0;
3211 sampler_dndi[index].dw6.dndi_first_frame = is_first_frame;
3212 sampler_dndi[index].dw6.progressive_dn = 0;
3213 sampler_dndi[index].dw6.fmd_tear_threshold = 2;
3214 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 100;
3215 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 16;
3217 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
3218 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
3219 sampler_dndi[index].dw7.vdi_walker_enable = 0;
3220 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
3222 dri_bo_unmap(pp_context->sampler_state_table.bo);
3224 /* private function & data */
3225 pp_context->pp_x_steps = pp_dndi_x_steps;
3226 pp_context->pp_y_steps = pp_dndi_y_steps;
3227 pp_context->private_context = &pp_context->pp_dndi_context;
3228 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
3230 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
3231 pp_static_parameter->grf1.r1_6.di.top_field_first = dndi_top_first;
3232 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 0;
3233 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 0;
3235 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
3236 pp_inline_parameter->grf5.number_blocks = w / 16;
3237 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
3238 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
3240 pp_dndi_context->dest_w = w;
3241 pp_dndi_context->dest_h = h;
3243 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
3245 pp_dndi_context->frame_order = (pp_dndi_context->frame_order + 1) % 2;
3247 return VA_STATUS_SUCCESS;
3251 pp_dn_x_steps(void *private_context)
3257 pp_dn_y_steps(void *private_context)
3259 struct pp_dn_context *pp_dn_context = private_context;
3261 return pp_dn_context->dest_h / 8;
3265 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3267 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3269 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
3270 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
3276 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3277 const struct i965_surface *src_surface,
3278 const VARectangle *src_rect,
3279 struct i965_surface *dst_surface,
3280 const VARectangle *dst_rect,
3283 struct i965_driver_data *i965 = i965_driver_data(ctx);
3284 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->pp_dn_context;
3285 struct object_surface *obj_surface;
3286 struct i965_sampler_dndi *sampler_dndi;
3287 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3288 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3289 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
3293 int dn_strength = 15;
3294 int dndi_top_first = 1;
3295 int dn_progressive = 0;
3297 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
3300 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
3308 if (dn_filter_param) {
3309 float value = dn_filter_param->value;
3317 dn_strength = (int)(value * 31.0F);
3321 obj_surface = (struct object_surface *)src_surface->base;
3322 orig_w = obj_surface->orig_width;
3323 orig_h = obj_surface->orig_height;
3324 w = obj_surface->width;
3325 h = obj_surface->height;
3327 if (pp_dn_context->stmm_bo == NULL) {
3328 pp_dn_context->stmm_bo = dri_bo_alloc(i965->intel.bufmgr,
3332 assert(pp_dn_context->stmm_bo);
3335 /* source UV surface index 2 */
3336 i965_pp_set_surface_state(ctx, pp_context,
3337 obj_surface->bo, w * h,
3338 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3341 /* source YUV surface index 4 */
3342 i965_pp_set_surface2_state(ctx, pp_context,
3346 SURFACE_FORMAT_PLANAR_420_8, 1,
3349 /* source STMM surface index 20 */
3350 i965_pp_set_surface_state(ctx, pp_context,
3351 pp_dn_context->stmm_bo, 0,
3352 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3355 /* destination surface */
3356 obj_surface = (struct object_surface *)dst_surface->base;
3357 orig_w = obj_surface->orig_width;
3358 orig_h = obj_surface->orig_height;
3359 w = obj_surface->width;
3360 h = obj_surface->height;
3362 /* destination Y surface index 7 */
3363 i965_pp_set_surface_state(ctx, pp_context,
3365 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3368 /* destination UV surface index 8 */
3369 i965_pp_set_surface_state(ctx, pp_context,
3370 obj_surface->bo, w * h,
3371 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3374 dri_bo_map(pp_context->sampler_state_table.bo, True);
3375 assert(pp_context->sampler_state_table.bo->virtual);
3376 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
3377 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
3379 /* sample dndi index 1 */
3381 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
3382 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
3383 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
3384 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
3386 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
3387 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
3388 sampler_dndi[index].dw1.stmm_c2 = 0;
3389 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
3390 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
3392 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
3393 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
3394 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
3395 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
3397 sampler_dndi[index].dw3.maximum_stmm = 128;
3398 sampler_dndi[index].dw3.multipler_for_vecm = 2;
3399 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
3400 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3401 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
3403 sampler_dndi[index].dw4.sdi_delta = 8;
3404 sampler_dndi[index].dw4.sdi_threshold = 128;
3405 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3406 sampler_dndi[index].dw4.stmm_shift_up = 0;
3407 sampler_dndi[index].dw4.stmm_shift_down = 0;
3408 sampler_dndi[index].dw4.minimum_stmm = 0;
3410 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
3411 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
3412 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
3413 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
3415 sampler_dndi[index].dw6.dn_enable = 1;
3416 sampler_dndi[index].dw6.di_enable = 0;
3417 sampler_dndi[index].dw6.di_partial = 0;
3418 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
3419 sampler_dndi[index].dw6.dndi_stream_id = 1;
3420 sampler_dndi[index].dw6.dndi_first_frame = 1;
3421 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
3422 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
3423 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
3424 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
3426 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
3427 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
3428 sampler_dndi[index].dw7.vdi_walker_enable = 0;
3429 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
3431 dri_bo_unmap(pp_context->sampler_state_table.bo);
3433 /* private function & data */
3434 pp_context->pp_x_steps = pp_dn_x_steps;
3435 pp_context->pp_y_steps = pp_dn_y_steps;
3436 pp_context->private_context = &pp_context->pp_dn_context;
3437 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
3439 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
3440 pp_static_parameter->grf1.r1_6.di.top_field_first = 0;
3441 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 64;
3442 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 192;
3444 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
3445 pp_inline_parameter->grf5.number_blocks = w / 16;
3446 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
3447 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
3449 pp_dn_context->dest_w = w;
3450 pp_dn_context->dest_h = h;
3452 dst_surface->flags = src_surface->flags;
3454 return VA_STATUS_SUCCESS;
3458 gen7_pp_dndi_x_steps(void *private_context)
3460 struct pp_dndi_context *pp_dndi_context = private_context;
3462 return pp_dndi_context->dest_w / 16;
3466 gen7_pp_dndi_y_steps(void *private_context)
3468 struct pp_dndi_context *pp_dndi_context = private_context;
3470 return pp_dndi_context->dest_h / 4;
3474 gen7_pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3476 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3478 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16;
3479 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 4;
3485 gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3486 const struct i965_surface *src_surface,
3487 const VARectangle *src_rect,
3488 struct i965_surface *dst_surface,
3489 const VARectangle *dst_rect,
3492 struct i965_driver_data *i965 = i965_driver_data(ctx);
3493 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->pp_dndi_context;
3494 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3495 struct object_surface *previous_in_obj_surface, *current_in_obj_surface, *previous_out_obj_surface, *current_out_obj_surface;
3496 struct gen7_sampler_dndi *sampler_dndi;
3500 int dndi_top_first = 1;
3501 VAProcFilterParameterBufferDeinterlacing *di_filter_param = (VAProcFilterParameterBufferDeinterlacing *)filter_param;
3502 int is_first_frame = (pp_dndi_context->frame_order == -1);
3504 if (di_filter_param->flags & VA_DEINTERLACING_BOTTOM_FIELD)
3510 current_in_obj_surface = (struct object_surface *)src_surface->base;
3512 if (di_filter_param->algorithm == VAProcDeinterlacingBob) {
3513 previous_in_obj_surface = current_in_obj_surface;
3515 } else if (di_filter_param->algorithm == VAProcDeinterlacingMotionAdaptive) {
3516 if (pp_dndi_context->frame_order == 0) {
3517 VAProcPipelineParameterBuffer *pipeline_param = pp_context->pipeline_param;
3518 if (!pipeline_param ||
3519 !pipeline_param->num_forward_references ||
3520 pipeline_param->forward_references[0] == VA_INVALID_ID) {
3521 WARN_ONCE("A forward temporal reference is needed for Motion adaptive deinterlacing !!!\n");
3523 return VA_STATUS_ERROR_INVALID_PARAMETER;
3525 previous_in_obj_surface = SURFACE(pipeline_param->forward_references[0]);
3526 assert(previous_in_obj_surface && previous_in_obj_surface->bo);
3530 } else if (pp_dndi_context->frame_order == 1) {
3531 vpp_surface_convert(ctx,
3532 pp_dndi_context->current_out_obj_surface,
3533 (struct object_surface *)dst_surface->base);
3534 pp_dndi_context->frame_order = (pp_dndi_context->frame_order + 1) % 2;
3537 return VA_STATUS_SUCCESS_1;
3539 previous_in_obj_surface = current_in_obj_surface;
3543 return VA_STATUS_ERROR_UNIMPLEMENTED;
3546 /* source (temporal reference) YUV surface index 4 */
3547 orig_w = previous_in_obj_surface->orig_width;
3548 orig_h = previous_in_obj_surface->orig_height;
3549 w = previous_in_obj_surface->width;
3550 h = previous_in_obj_surface->height;
3551 gen7_pp_set_surface2_state(ctx, pp_context,
3552 previous_in_obj_surface->bo, 0,
3555 SURFACE_FORMAT_PLANAR_420_8, 1,
3558 /* source surface */
3559 orig_w = current_in_obj_surface->orig_width;
3560 orig_h = current_in_obj_surface->orig_height;
3561 w = current_in_obj_surface->width;
3562 h = current_in_obj_surface->height;
3564 /* source UV surface index 1 */
3565 gen7_pp_set_surface_state(ctx, pp_context,
3566 current_in_obj_surface->bo, w * h,
3567 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3570 /* source YUV surface index 3 */
3571 gen7_pp_set_surface2_state(ctx, pp_context,
3572 current_in_obj_surface->bo, 0,
3575 SURFACE_FORMAT_PLANAR_420_8, 1,
3578 /* STMM / History Statistics input surface, index 5 */
3579 if (pp_dndi_context->stmm_bo == NULL) {
3580 pp_dndi_context->stmm_bo = dri_bo_alloc(i965->intel.bufmgr,
3584 assert(pp_dndi_context->stmm_bo);
3587 gen7_pp_set_surface_state(ctx, pp_context,
3588 pp_dndi_context->stmm_bo, 0,
3589 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3592 /* destination surface */
3593 previous_out_obj_surface = (struct object_surface *)dst_surface->base;
3594 orig_w = previous_out_obj_surface->orig_width;
3595 orig_h = previous_out_obj_surface->orig_height;
3596 w = previous_out_obj_surface->width;
3597 h = previous_out_obj_surface->height;
3599 if (is_first_frame) {
3600 current_out_obj_surface = previous_out_obj_surface;
3604 if (pp_dndi_context->current_out_surface == VA_INVALID_SURFACE) {
3605 unsigned int tiling = 0, swizzle = 0;
3606 dri_bo_get_tiling(previous_out_obj_surface->bo, &tiling, &swizzle);
3608 va_status = i965_CreateSurfaces(ctx,
3611 VA_RT_FORMAT_YUV420,
3613 &pp_dndi_context->current_out_surface);
3614 assert(va_status == VA_STATUS_SUCCESS);
3615 pp_dndi_context->current_out_obj_surface = SURFACE(pp_dndi_context->current_out_surface);
3616 assert(pp_dndi_context->current_out_obj_surface);
3617 i965_check_alloc_surface_bo(ctx,
3618 pp_dndi_context->current_out_obj_surface,
3619 tiling != I915_TILING_NONE,
3624 current_out_obj_surface = pp_dndi_context->current_out_obj_surface;
3627 /* destination(Previous frame) Y surface index 27 */
3628 gen7_pp_set_surface_state(ctx, pp_context,
3629 previous_out_obj_surface->bo, 0,
3630 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3633 /* destination(Previous frame) UV surface index 28 */
3634 gen7_pp_set_surface_state(ctx, pp_context,
3635 previous_out_obj_surface->bo, w * h,
3636 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3639 /* destination(Current frame) Y surface index 30 */
3640 gen7_pp_set_surface_state(ctx, pp_context,
3641 current_out_obj_surface->bo, 0,
3642 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3645 /* destination(Current frame) UV surface index 31 */
3646 orig_w = current_out_obj_surface->orig_width;
3647 orig_h = current_out_obj_surface->orig_height;
3648 w = current_out_obj_surface->width;
3649 h = current_out_obj_surface->height;
3651 gen7_pp_set_surface_state(ctx, pp_context,
3652 current_out_obj_surface->bo, w * h,
3653 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3656 /* STMM output surface, index 33 */
3657 gen7_pp_set_surface_state(ctx, pp_context,
3658 pp_dndi_context->stmm_bo, 0,
3659 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3664 dri_bo_map(pp_context->sampler_state_table.bo, True);
3665 assert(pp_context->sampler_state_table.bo->virtual);
3666 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
3667 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
3669 /* sample dndi index 0 */
3671 sampler_dndi[index].dw0.denoise_asd_threshold = 38;
3672 sampler_dndi[index].dw0.dnmh_delt = 7;
3673 sampler_dndi[index].dw0.vdi_walker_y_stride = 0;
3674 sampler_dndi[index].dw0.vdi_walker_frame_sharing_enable = 0;
3675 sampler_dndi[index].dw0.denoise_maximum_history = 192; // 128-240
3676 sampler_dndi[index].dw0.denoise_stad_threshold = 140;
3678 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 38;
3679 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 1;
3680 sampler_dndi[index].dw1.stmm_c2 = 2;
3681 sampler_dndi[index].dw1.low_temporal_difference_threshold = 0;
3682 sampler_dndi[index].dw1.temporal_difference_threshold = 0;
3684 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 20; // 0-31
3685 sampler_dndi[index].dw2.bne_edge_th = 1;
3686 sampler_dndi[index].dw2.smooth_mv_th = 0;
3687 sampler_dndi[index].dw2.sad_tight_th = 5;
3688 sampler_dndi[index].dw2.cat_slope_minus1 = 9;
3689 sampler_dndi[index].dw2.good_neighbor_th = 12;
3691 sampler_dndi[index].dw3.maximum_stmm = 150;
3692 sampler_dndi[index].dw3.multipler_for_vecm = 30;
3693 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 125;
3694 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3695 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
3697 sampler_dndi[index].dw4.sdi_delta = 5;
3698 sampler_dndi[index].dw4.sdi_threshold = 100;
3699 sampler_dndi[index].dw4.stmm_output_shift = 5; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3700 sampler_dndi[index].dw4.stmm_shift_up = 1;
3701 sampler_dndi[index].dw4.stmm_shift_down = 0;
3702 sampler_dndi[index].dw4.minimum_stmm = 118;
3704 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 175;
3705 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 37;
3706 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 100;
3707 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 50;
3708 sampler_dndi[index].dw6.dn_enable = 0;
3709 sampler_dndi[index].dw6.di_enable = 1;
3710 sampler_dndi[index].dw6.di_partial = 0;
3711 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
3712 sampler_dndi[index].dw6.dndi_stream_id = 1;
3713 sampler_dndi[index].dw6.dndi_first_frame = is_first_frame;
3714 sampler_dndi[index].dw6.progressive_dn = 0;
3715 sampler_dndi[index].dw6.mcdi_enable = 0;
3716 sampler_dndi[index].dw6.fmd_tear_threshold = 2;
3717 sampler_dndi[index].dw6.cat_th1 = 0;
3718 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 100;
3719 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 16;
3721 sampler_dndi[index].dw7.sad_tha = 5;
3722 sampler_dndi[index].dw7.sad_thb = 10;
3723 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
3724 sampler_dndi[index].dw7.mc_pixel_consistency_th = 25;
3725 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
3726 sampler_dndi[index].dw7.vdi_walker_enable = 0;
3727 sampler_dndi[index].dw7.neighborpixel_th = 10;
3728 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
3730 dri_bo_unmap(pp_context->sampler_state_table.bo);
3732 /* private function & data */
3733 pp_context->pp_x_steps = gen7_pp_dndi_x_steps;
3734 pp_context->pp_y_steps = gen7_pp_dndi_y_steps;
3735 pp_context->private_context = &pp_context->pp_dndi_context;
3736 pp_context->pp_set_block_parameter = gen7_pp_dndi_set_block_parameter;
3738 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
3739 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
3740 pp_static_parameter->grf1.di_top_field_first = 0;
3741 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3743 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3744 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3745 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3747 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
3748 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3750 pp_dndi_context->dest_w = w;
3751 pp_dndi_context->dest_h = h;
3753 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
3755 pp_dndi_context->frame_order = (pp_dndi_context->frame_order + 1) % 2;
3757 return VA_STATUS_SUCCESS;
3761 gen7_pp_dn_x_steps(void *private_context)
3763 struct pp_dn_context *pp_dn_context = private_context;
3765 return pp_dn_context->dest_w / 16;
3769 gen7_pp_dn_y_steps(void *private_context)
3771 struct pp_dn_context *pp_dn_context = private_context;
3773 return pp_dn_context->dest_h / 4;
3777 gen7_pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3779 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3781 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
3782 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
3788 gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3789 const struct i965_surface *src_surface,
3790 const VARectangle *src_rect,
3791 struct i965_surface *dst_surface,
3792 const VARectangle *dst_rect,
3795 struct i965_driver_data *i965 = i965_driver_data(ctx);
3796 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->pp_dn_context;
3797 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3798 struct object_surface *obj_surface;
3799 struct gen7_sampler_dndi *sampler_dn;
3800 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
3804 int dn_strength = 15;
3805 int dndi_top_first = 1;
3806 int dn_progressive = 0;
3808 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
3811 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
3819 if (dn_filter_param) {
3820 float value = dn_filter_param->value;
3828 dn_strength = (int)(value * 31.0F);
3832 obj_surface = (struct object_surface *)src_surface->base;
3833 orig_w = obj_surface->orig_width;
3834 orig_h = obj_surface->orig_height;
3835 w = obj_surface->width;
3836 h = obj_surface->height;
3838 if (pp_dn_context->stmm_bo == NULL) {
3839 pp_dn_context->stmm_bo= dri_bo_alloc(i965->intel.bufmgr,
3843 assert(pp_dn_context->stmm_bo);
3846 /* source UV surface index 1 */
3847 gen7_pp_set_surface_state(ctx, pp_context,
3848 obj_surface->bo, w * h,
3849 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3852 /* source YUV surface index 3 */
3853 gen7_pp_set_surface2_state(ctx, pp_context,
3857 SURFACE_FORMAT_PLANAR_420_8, 1,
3860 /* source (temporal reference) YUV surface index 4 */
3861 gen7_pp_set_surface2_state(ctx, pp_context,
3865 SURFACE_FORMAT_PLANAR_420_8, 1,
3868 /* STMM / History Statistics input surface, index 5 */
3869 gen7_pp_set_surface_state(ctx, pp_context,
3870 pp_dn_context->stmm_bo, 0,
3871 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3874 /* destination surface */
3875 obj_surface = (struct object_surface *)dst_surface->base;
3876 orig_w = obj_surface->orig_width;
3877 orig_h = obj_surface->orig_height;
3878 w = obj_surface->width;
3879 h = obj_surface->height;
3881 /* destination Y surface index 24 */
3882 gen7_pp_set_surface_state(ctx, pp_context,
3884 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
3887 /* destination UV surface index 25 */
3888 gen7_pp_set_surface_state(ctx, pp_context,
3889 obj_surface->bo, w * h,
3890 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
3894 dri_bo_map(pp_context->sampler_state_table.bo, True);
3895 assert(pp_context->sampler_state_table.bo->virtual);
3896 assert(sizeof(*sampler_dn) == sizeof(int) * 8);
3897 sampler_dn = pp_context->sampler_state_table.bo->virtual;
3899 /* sample dn index 1 */
3901 sampler_dn[index].dw0.denoise_asd_threshold = 0;
3902 sampler_dn[index].dw0.dnmh_delt = 8;
3903 sampler_dn[index].dw0.vdi_walker_y_stride = 0;
3904 sampler_dn[index].dw0.vdi_walker_frame_sharing_enable = 0;
3905 sampler_dn[index].dw0.denoise_maximum_history = 128; // 128-240
3906 sampler_dn[index].dw0.denoise_stad_threshold = 0;
3908 sampler_dn[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
3909 sampler_dn[index].dw1.denoise_moving_pixel_threshold = 0;
3910 sampler_dn[index].dw1.stmm_c2 = 0;
3911 sampler_dn[index].dw1.low_temporal_difference_threshold = 8;
3912 sampler_dn[index].dw1.temporal_difference_threshold = 16;
3914 sampler_dn[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
3915 sampler_dn[index].dw2.bne_edge_th = 1;
3916 sampler_dn[index].dw2.smooth_mv_th = 0;
3917 sampler_dn[index].dw2.sad_tight_th = 5;
3918 sampler_dn[index].dw2.cat_slope_minus1 = 9;
3919 sampler_dn[index].dw2.good_neighbor_th = 4;
3921 sampler_dn[index].dw3.maximum_stmm = 128;
3922 sampler_dn[index].dw3.multipler_for_vecm = 2;
3923 sampler_dn[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
3924 sampler_dn[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
3925 sampler_dn[index].dw3.stmm_blending_constant_select = 0;
3927 sampler_dn[index].dw4.sdi_delta = 8;
3928 sampler_dn[index].dw4.sdi_threshold = 128;
3929 sampler_dn[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
3930 sampler_dn[index].dw4.stmm_shift_up = 0;
3931 sampler_dn[index].dw4.stmm_shift_down = 0;
3932 sampler_dn[index].dw4.minimum_stmm = 0;
3934 sampler_dn[index].dw5.fmd_temporal_difference_threshold = 0;
3935 sampler_dn[index].dw5.sdi_fallback_mode_2_constant = 0;
3936 sampler_dn[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
3937 sampler_dn[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
3939 sampler_dn[index].dw6.dn_enable = 1;
3940 sampler_dn[index].dw6.di_enable = 0;
3941 sampler_dn[index].dw6.di_partial = 0;
3942 sampler_dn[index].dw6.dndi_top_first = dndi_top_first;
3943 sampler_dn[index].dw6.dndi_stream_id = 1;
3944 sampler_dn[index].dw6.dndi_first_frame = 1;
3945 sampler_dn[index].dw6.progressive_dn = dn_progressive;
3946 sampler_dn[index].dw6.mcdi_enable = 0;
3947 sampler_dn[index].dw6.fmd_tear_threshold = 32;
3948 sampler_dn[index].dw6.cat_th1 = 0;
3949 sampler_dn[index].dw6.fmd2_vertical_difference_threshold = 32;
3950 sampler_dn[index].dw6.fmd1_vertical_difference_threshold = 32;
3952 sampler_dn[index].dw7.sad_tha = 5;
3953 sampler_dn[index].dw7.sad_thb = 10;
3954 sampler_dn[index].dw7.fmd_for_1st_field_of_current_frame = 2;
3955 sampler_dn[index].dw7.mc_pixel_consistency_th = 25;
3956 sampler_dn[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
3957 sampler_dn[index].dw7.vdi_walker_enable = 0;
3958 sampler_dn[index].dw7.neighborpixel_th = 10;
3959 sampler_dn[index].dw7.column_width_minus1 = w / 16;
3961 dri_bo_unmap(pp_context->sampler_state_table.bo);
3963 /* private function & data */
3964 pp_context->pp_x_steps = gen7_pp_dn_x_steps;
3965 pp_context->pp_y_steps = gen7_pp_dn_y_steps;
3966 pp_context->private_context = &pp_context->pp_dn_context;
3967 pp_context->pp_set_block_parameter = gen7_pp_dn_set_block_parameter;
3969 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
3970 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
3971 pp_static_parameter->grf1.di_top_field_first = 0;
3972 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3974 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3975 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3976 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3978 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
3979 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
3981 pp_dn_context->dest_w = w;
3982 pp_dn_context->dest_h = h;
3984 dst_surface->flags = src_surface->flags;
3986 return VA_STATUS_SUCCESS;
3990 ironlake_pp_initialize(
3991 VADriverContextP ctx,
3992 struct i965_post_processing_context *pp_context,
3993 const struct i965_surface *src_surface,
3994 const VARectangle *src_rect,
3995 struct i965_surface *dst_surface,
3996 const VARectangle *dst_rect,
4002 struct i965_driver_data *i965 = i965_driver_data(ctx);
4003 struct pp_module *pp_module;
4005 int static_param_size, inline_param_size;
4007 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
4008 bo = dri_bo_alloc(i965->intel.bufmgr,
4009 "surface state & binding table",
4010 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
4013 pp_context->surface_state_binding_table.bo = bo;
4015 dri_bo_unreference(pp_context->curbe.bo);
4016 bo = dri_bo_alloc(i965->intel.bufmgr,
4021 pp_context->curbe.bo = bo;
4023 dri_bo_unreference(pp_context->idrt.bo);
4024 bo = dri_bo_alloc(i965->intel.bufmgr,
4025 "interface discriptor",
4026 sizeof(struct i965_interface_descriptor),
4029 pp_context->idrt.bo = bo;
4030 pp_context->idrt.num_interface_descriptors = 0;
4032 dri_bo_unreference(pp_context->sampler_state_table.bo);
4033 bo = dri_bo_alloc(i965->intel.bufmgr,
4034 "sampler state table",
4038 dri_bo_map(bo, True);
4039 memset(bo->virtual, 0, bo->size);
4041 pp_context->sampler_state_table.bo = bo;
4043 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
4044 bo = dri_bo_alloc(i965->intel.bufmgr,
4045 "sampler 8x8 state ",
4049 pp_context->sampler_state_table.bo_8x8 = bo;
4051 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
4052 bo = dri_bo_alloc(i965->intel.bufmgr,
4053 "sampler 8x8 state ",
4057 pp_context->sampler_state_table.bo_8x8_uv = bo;
4059 dri_bo_unreference(pp_context->vfe_state.bo);
4060 bo = dri_bo_alloc(i965->intel.bufmgr,
4062 sizeof(struct i965_vfe_state),
4065 pp_context->vfe_state.bo = bo;
4067 static_param_size = sizeof(struct pp_static_parameter);
4068 inline_param_size = sizeof(struct pp_inline_parameter);
4070 memset(pp_context->pp_static_parameter, 0, static_param_size);
4071 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
4073 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
4074 pp_context->current_pp = pp_index;
4075 pp_module = &pp_context->pp_modules[pp_index];
4077 if (pp_module->initialize)
4078 va_status = pp_module->initialize(ctx, pp_context,
4085 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
4091 ironlake_post_processing(
4092 VADriverContextP ctx,
4093 struct i965_post_processing_context *pp_context,
4094 const struct i965_surface *src_surface,
4095 const VARectangle *src_rect,
4096 struct i965_surface *dst_surface,
4097 const VARectangle *dst_rect,
4104 va_status = ironlake_pp_initialize(ctx, pp_context,
4112 if (va_status == VA_STATUS_SUCCESS) {
4113 ironlake_pp_states_setup(ctx, pp_context);
4114 ironlake_pp_pipeline_setup(ctx, pp_context);
4122 VADriverContextP ctx,
4123 struct i965_post_processing_context *pp_context,
4124 const struct i965_surface *src_surface,
4125 const VARectangle *src_rect,
4126 struct i965_surface *dst_surface,
4127 const VARectangle *dst_rect,
4133 struct i965_driver_data *i965 = i965_driver_data(ctx);
4134 struct pp_module *pp_module;
4136 int static_param_size, inline_param_size;
4138 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
4139 bo = dri_bo_alloc(i965->intel.bufmgr,
4140 "surface state & binding table",
4141 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
4144 pp_context->surface_state_binding_table.bo = bo;
4146 dri_bo_unreference(pp_context->curbe.bo);
4147 bo = dri_bo_alloc(i965->intel.bufmgr,
4152 pp_context->curbe.bo = bo;
4154 dri_bo_unreference(pp_context->idrt.bo);
4155 bo = dri_bo_alloc(i965->intel.bufmgr,
4156 "interface discriptor",
4157 sizeof(struct gen6_interface_descriptor_data),
4160 pp_context->idrt.bo = bo;
4161 pp_context->idrt.num_interface_descriptors = 0;
4163 dri_bo_unreference(pp_context->sampler_state_table.bo);
4164 bo = dri_bo_alloc(i965->intel.bufmgr,
4165 "sampler state table",
4169 dri_bo_map(bo, True);
4170 memset(bo->virtual, 0, bo->size);
4172 pp_context->sampler_state_table.bo = bo;
4174 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
4175 bo = dri_bo_alloc(i965->intel.bufmgr,
4176 "sampler 8x8 state ",
4180 pp_context->sampler_state_table.bo_8x8 = bo;
4182 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
4183 bo = dri_bo_alloc(i965->intel.bufmgr,
4184 "sampler 8x8 state ",
4188 pp_context->sampler_state_table.bo_8x8_uv = bo;
4190 dri_bo_unreference(pp_context->vfe_state.bo);
4191 bo = dri_bo_alloc(i965->intel.bufmgr,
4193 sizeof(struct i965_vfe_state),
4196 pp_context->vfe_state.bo = bo;
4198 if (IS_GEN7(i965->intel.device_info)) {
4199 static_param_size = sizeof(struct gen7_pp_static_parameter);
4200 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
4202 static_param_size = sizeof(struct pp_static_parameter);
4203 inline_param_size = sizeof(struct pp_inline_parameter);
4206 memset(pp_context->pp_static_parameter, 0, static_param_size);
4207 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
4209 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
4210 pp_context->current_pp = pp_index;
4211 pp_module = &pp_context->pp_modules[pp_index];
4213 if (pp_module->initialize)
4214 va_status = pp_module->initialize(ctx, pp_context,
4221 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
4223 calculate_boundary_block_mask(pp_context, dst_rect);
4230 gen6_pp_interface_descriptor_table(VADriverContextP ctx,
4231 struct i965_post_processing_context *pp_context)
4233 struct i965_driver_data *i965 = i965_driver_data(ctx);
4234 struct gen6_interface_descriptor_data *desc;
4236 int pp_index = pp_context->current_pp;
4238 bo = pp_context->idrt.bo;
4239 dri_bo_map(bo, True);
4240 assert(bo->virtual);
4242 memset(desc, 0, sizeof(*desc));
4243 desc->desc0.kernel_start_pointer =
4244 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
4245 desc->desc1.single_program_flow = 1;
4246 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
4247 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
4248 desc->desc2.sampler_state_pointer =
4249 pp_context->sampler_state_table.bo->offset >> 5;
4250 desc->desc3.binding_table_entry_count = 0;
4251 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
4252 desc->desc4.constant_urb_entry_read_offset = 0;
4254 if (IS_GEN7(i965->intel.device_info))
4255 desc->desc4.constant_urb_entry_read_length = 6; /* grf 1-6 */
4257 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
4259 dri_bo_emit_reloc(bo,
4260 I915_GEM_DOMAIN_INSTRUCTION, 0,
4262 offsetof(struct gen6_interface_descriptor_data, desc0),
4263 pp_context->pp_modules[pp_index].kernel.bo);
4265 dri_bo_emit_reloc(bo,
4266 I915_GEM_DOMAIN_INSTRUCTION, 0,
4267 desc->desc2.sampler_count << 2,
4268 offsetof(struct gen6_interface_descriptor_data, desc2),
4269 pp_context->sampler_state_table.bo);
4272 pp_context->idrt.num_interface_descriptors++;
4276 gen6_pp_upload_constants(VADriverContextP ctx,
4277 struct i965_post_processing_context *pp_context)
4279 struct i965_driver_data *i965 = i965_driver_data(ctx);
4280 unsigned char *constant_buffer;
4283 assert(sizeof(struct pp_static_parameter) == 128);
4284 assert(sizeof(struct gen7_pp_static_parameter) == 192);
4286 if (IS_GEN7(i965->intel.device_info))
4287 param_size = sizeof(struct gen7_pp_static_parameter);
4289 param_size = sizeof(struct pp_static_parameter);
4291 dri_bo_map(pp_context->curbe.bo, 1);
4292 assert(pp_context->curbe.bo->virtual);
4293 constant_buffer = pp_context->curbe.bo->virtual;
4294 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
4295 dri_bo_unmap(pp_context->curbe.bo);
4299 gen6_pp_states_setup(VADriverContextP ctx,
4300 struct i965_post_processing_context *pp_context)
4302 gen6_pp_interface_descriptor_table(ctx, pp_context);
4303 gen6_pp_upload_constants(ctx, pp_context);
4307 gen6_pp_pipeline_select(VADriverContextP ctx,
4308 struct i965_post_processing_context *pp_context)
4310 struct intel_batchbuffer *batch = pp_context->batch;
4312 BEGIN_BATCH(batch, 1);
4313 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
4314 ADVANCE_BATCH(batch);
4318 gen6_pp_state_base_address(VADriverContextP ctx,
4319 struct i965_post_processing_context *pp_context)
4321 struct intel_batchbuffer *batch = pp_context->batch;
4323 BEGIN_BATCH(batch, 10);
4324 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
4325 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4326 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
4327 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4328 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4329 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4330 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4331 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4332 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4333 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
4334 ADVANCE_BATCH(batch);
4338 gen6_pp_vfe_state(VADriverContextP ctx,
4339 struct i965_post_processing_context *pp_context)
4341 struct intel_batchbuffer *batch = pp_context->batch;
4343 BEGIN_BATCH(batch, 8);
4344 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
4345 OUT_BATCH(batch, 0);
4347 (pp_context->vfe_gpu_state.max_num_threads - 1) << 16 |
4348 pp_context->vfe_gpu_state.num_urb_entries << 8);
4349 OUT_BATCH(batch, 0);
4351 (pp_context->vfe_gpu_state.urb_entry_size) << 16 |
4352 /* URB Entry Allocation Size, in 256 bits unit */
4353 (pp_context->vfe_gpu_state.curbe_allocation_size));
4354 /* CURBE Allocation Size, in 256 bits unit */
4355 OUT_BATCH(batch, 0);
4356 OUT_BATCH(batch, 0);
4357 OUT_BATCH(batch, 0);
4358 ADVANCE_BATCH(batch);
4362 gen6_pp_curbe_load(VADriverContextP ctx,
4363 struct i965_post_processing_context *pp_context)
4365 struct intel_batchbuffer *batch = pp_context->batch;
4366 struct i965_driver_data *i965 = i965_driver_data(ctx);
4369 if (IS_GEN7(i965->intel.device_info))
4370 param_size = sizeof(struct gen7_pp_static_parameter);
4372 param_size = sizeof(struct pp_static_parameter);
4374 BEGIN_BATCH(batch, 4);
4375 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
4376 OUT_BATCH(batch, 0);
4380 pp_context->curbe.bo,
4381 I915_GEM_DOMAIN_INSTRUCTION, 0,
4383 ADVANCE_BATCH(batch);
4387 gen6_interface_descriptor_load(VADriverContextP ctx,
4388 struct i965_post_processing_context *pp_context)
4390 struct intel_batchbuffer *batch = pp_context->batch;
4392 BEGIN_BATCH(batch, 4);
4393 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
4394 OUT_BATCH(batch, 0);
4396 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
4398 pp_context->idrt.bo,
4399 I915_GEM_DOMAIN_INSTRUCTION, 0,
4401 ADVANCE_BATCH(batch);
4404 static void update_block_mask_parameter(struct i965_post_processing_context *pp_context, int x, int y, int x_steps, int y_steps)
4406 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
4408 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
4409 pp_inline_parameter->grf6.block_vertical_mask_bottom = pp_context->block_vertical_mask_bottom;
4410 // for the first block, it always on the left edge. the second block will reload horizontal_mask from grf6.block_horizontal_mask_middle
4411 pp_inline_parameter->grf5.block_horizontal_mask = pp_context->block_horizontal_mask_left;
4412 pp_inline_parameter->grf6.block_horizontal_mask_middle = 0xffff;
4413 pp_inline_parameter->grf6.block_horizontal_mask_right = pp_context->block_horizontal_mask_right;
4417 if (y == y_steps-1) {
4418 pp_inline_parameter->grf5.block_vertical_mask = pp_context->block_vertical_mask_bottom;
4421 pp_inline_parameter->grf6.block_vertical_mask_bottom = 0xff;
4427 if (x == 0) { // all blocks in this group are on the left edge
4428 pp_inline_parameter->grf6.block_horizontal_mask_middle = pp_context->block_horizontal_mask_left;
4429 pp_inline_parameter->grf6.block_horizontal_mask_right = pp_context->block_horizontal_mask_left;
4431 else if (x == x_steps-1) {
4432 pp_inline_parameter->grf5.block_horizontal_mask = pp_context->block_horizontal_mask_right;
4433 pp_inline_parameter->grf6.block_horizontal_mask_middle = pp_context->block_horizontal_mask_right;
4436 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
4437 pp_inline_parameter->grf6.block_horizontal_mask_middle = 0xffff;
4438 pp_inline_parameter->grf6.block_horizontal_mask_right = 0xffff;
4445 gen6_pp_object_walker(VADriverContextP ctx,
4446 struct i965_post_processing_context *pp_context)
4448 struct i965_driver_data *i965 = i965_driver_data(ctx);
4449 struct intel_batchbuffer *batch = pp_context->batch;
4450 int x, x_steps, y, y_steps;
4451 int param_size, command_length_in_dws;
4452 dri_bo *command_buffer;
4453 unsigned int *command_ptr;
4455 if (IS_GEN7(i965->intel.device_info))
4456 param_size = sizeof(struct gen7_pp_inline_parameter);
4458 param_size = sizeof(struct pp_inline_parameter);
4460 x_steps = pp_context->pp_x_steps(pp_context->private_context);
4461 y_steps = pp_context->pp_y_steps(pp_context->private_context);
4462 command_length_in_dws = 6 + (param_size >> 2);
4463 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
4464 "command objects buffer",
4465 command_length_in_dws * 4 * x_steps * y_steps + 8,
4468 dri_bo_map(command_buffer, 1);
4469 command_ptr = command_buffer->virtual;
4471 for (y = 0; y < y_steps; y++) {
4472 for (x = 0; x < x_steps; x++) {
4473 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
4474 // some common block parameter update goes here, apply to all pp functions
4475 if (IS_GEN6(i965->intel.device_info))
4476 update_block_mask_parameter (pp_context, x, y, x_steps, y_steps);
4478 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
4484 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
4485 command_ptr += (param_size >> 2);
4490 if (command_length_in_dws * x_steps * y_steps % 2 == 0)
4493 *command_ptr = MI_BATCH_BUFFER_END;
4495 dri_bo_unmap(command_buffer);
4497 BEGIN_BATCH(batch, 2);
4498 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (1 << 8));
4499 OUT_RELOC(batch, command_buffer,
4500 I915_GEM_DOMAIN_COMMAND, 0,
4502 ADVANCE_BATCH(batch);
4504 dri_bo_unreference(command_buffer);
4506 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
4507 * will cause control to pass back to ring buffer
4509 intel_batchbuffer_end_atomic(batch);
4510 intel_batchbuffer_flush(batch);
4511 intel_batchbuffer_start_atomic(batch, 0x1000);
4515 gen6_pp_pipeline_setup(VADriverContextP ctx,
4516 struct i965_post_processing_context *pp_context)
4518 struct intel_batchbuffer *batch = pp_context->batch;
4520 intel_batchbuffer_start_atomic(batch, 0x1000);
4521 intel_batchbuffer_emit_mi_flush(batch);
4522 gen6_pp_pipeline_select(ctx, pp_context);
4523 gen6_pp_state_base_address(ctx, pp_context);
4524 gen6_pp_vfe_state(ctx, pp_context);
4525 gen6_pp_curbe_load(ctx, pp_context);
4526 gen6_interface_descriptor_load(ctx, pp_context);
4527 gen6_pp_object_walker(ctx, pp_context);
4528 intel_batchbuffer_end_atomic(batch);
4532 gen6_post_processing(
4533 VADriverContextP ctx,
4534 struct i965_post_processing_context *pp_context,
4535 const struct i965_surface *src_surface,
4536 const VARectangle *src_rect,
4537 struct i965_surface *dst_surface,
4538 const VARectangle *dst_rect,
4545 va_status = gen6_pp_initialize(ctx, pp_context,
4553 if (va_status == VA_STATUS_SUCCESS) {
4554 gen6_pp_states_setup(ctx, pp_context);
4555 gen6_pp_pipeline_setup(ctx, pp_context);
4558 if (va_status == VA_STATUS_SUCCESS_1)
4559 va_status = VA_STATUS_SUCCESS;
4565 i965_post_processing_internal(
4566 VADriverContextP ctx,
4567 struct i965_post_processing_context *pp_context,
4568 const struct i965_surface *src_surface,
4569 const VARectangle *src_rect,
4570 struct i965_surface *dst_surface,
4571 const VARectangle *dst_rect,
4577 struct i965_driver_data *i965 = i965_driver_data(ctx);
4579 if (pp_context && pp_context->intel_post_processing) {
4580 va_status = (pp_context->intel_post_processing)(ctx, pp_context,
4581 src_surface, src_rect,
4582 dst_surface, dst_rect,
4583 pp_index, filter_param);
4585 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
4592 rgb_to_yuv(unsigned int argb,
4598 int r = ((argb >> 16) & 0xff);
4599 int g = ((argb >> 8) & 0xff);
4600 int b = ((argb >> 0) & 0xff);
4602 *y = (257 * r + 504 * g + 98 * b) / 1000 + 16;
4603 *v = (439 * r - 368 * g - 71 * b) / 1000 + 128;
4604 *u = (-148 * r - 291 * g + 439 * b) / 1000 + 128;
4605 *a = ((argb >> 24) & 0xff);
4609 i965_vpp_clear_surface(VADriverContextP ctx,
4610 struct i965_post_processing_context *pp_context,
4611 struct object_surface *obj_surface,
4614 struct i965_driver_data *i965 = i965_driver_data(ctx);
4615 struct intel_batchbuffer *batch = pp_context->batch;
4616 unsigned int blt_cmd, br13;
4617 unsigned int tiling = 0, swizzle = 0;
4619 unsigned char y, u, v, a = 0;
4620 int region_width, region_height;
4622 /* Currently only support NV12 surface */
4623 if (!obj_surface || obj_surface->fourcc != VA_FOURCC_NV12)
4626 rgb_to_yuv(color, &y, &u, &v, &a);
4631 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4632 blt_cmd = XY_COLOR_BLT_CMD;
4633 pitch = obj_surface->width;
4635 if (tiling != I915_TILING_NONE) {
4636 assert(tiling == I915_TILING_Y);
4637 // blt_cmd |= XY_COLOR_BLT_DST_TILED;
4645 if (IS_IRONLAKE(i965->intel.device_info)) {
4646 intel_batchbuffer_start_atomic(batch, 48);
4647 BEGIN_BATCH(batch, 12);
4649 /* Will double-check the command if the new chipset is added */
4650 intel_batchbuffer_start_atomic_blt(batch, 48);
4651 BEGIN_BLT_BATCH(batch, 12);
4654 region_width = obj_surface->width;
4655 region_height = obj_surface->height;
4657 OUT_BATCH(batch, blt_cmd);
4658 OUT_BATCH(batch, br13);
4663 region_height << 16 |
4665 OUT_RELOC(batch, obj_surface->bo,
4666 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
4668 OUT_BATCH(batch, y);
4674 region_width = obj_surface->width / 2;
4675 region_height = obj_surface->height / 2;
4677 if (tiling == I915_TILING_Y) {
4678 region_height = ALIGN(obj_surface->height / 2, 32);
4681 OUT_BATCH(batch, blt_cmd);
4682 OUT_BATCH(batch, br13);
4687 region_height << 16 |
4689 OUT_RELOC(batch, obj_surface->bo,
4690 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
4691 obj_surface->width * obj_surface->y_cb_offset);
4692 OUT_BATCH(batch, v << 8 | u);
4694 ADVANCE_BATCH(batch);
4695 intel_batchbuffer_end_atomic(batch);
4699 i965_scaling_processing(
4700 VADriverContextP ctx,
4701 struct object_surface *src_surface_obj,
4702 const VARectangle *src_rect,
4703 struct object_surface *dst_surface_obj,
4704 const VARectangle *dst_rect,
4707 VAStatus va_status = VA_STATUS_SUCCESS;
4708 struct i965_driver_data *i965 = i965_driver_data(ctx);
4710 assert(src_surface_obj->fourcc == VA_FOURCC_NV12);
4711 assert(dst_surface_obj->fourcc == VA_FOURCC_NV12);
4713 if (HAS_VPP(i965) && (flags & I965_PP_FLAG_AVS)) {
4714 struct i965_surface src_surface;
4715 struct i965_surface dst_surface;
4717 _i965LockMutex(&i965->pp_mutex);
4719 src_surface.base = (struct object_base *)src_surface_obj;
4720 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4721 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4722 dst_surface.base = (struct object_base *)dst_surface_obj;
4723 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4724 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4726 va_status = i965_post_processing_internal(ctx, i965->pp_context,
4734 _i965UnlockMutex(&i965->pp_mutex);
4741 i965_post_processing(
4742 VADriverContextP ctx,
4743 struct object_surface *obj_surface,
4744 const VARectangle *src_rect,
4745 const VARectangle *dst_rect,
4747 int *has_done_scaling
4750 struct i965_driver_data *i965 = i965_driver_data(ctx);
4751 VASurfaceID out_surface_id = VA_INVALID_ID;
4752 VASurfaceID tmp_id = VA_INVALID_ID;
4754 *has_done_scaling = 0;
4756 if (HAS_VPP(i965)) {
4758 struct i965_surface src_surface;
4759 struct i965_surface dst_surface;
4761 /* Currently only support post processing for NV12 surface */
4762 if (obj_surface->fourcc != VA_FOURCC_NV12)
4763 return out_surface_id;
4765 _i965LockMutex(&i965->pp_mutex);
4767 if (flags & I965_PP_FLAG_MCDI) {
4768 src_surface.base = (struct object_base *)obj_surface;
4769 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4770 src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ?
4771 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
4773 status = i965_CreateSurfaces(ctx,
4774 obj_surface->orig_width,
4775 obj_surface->orig_height,
4776 VA_RT_FORMAT_YUV420,
4779 assert(status == VA_STATUS_SUCCESS);
4780 obj_surface = SURFACE(out_surface_id);
4781 assert(obj_surface);
4782 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
4783 i965_vpp_clear_surface(ctx, i965->pp_context, obj_surface, 0);
4785 dst_surface.base = (struct object_base *)obj_surface;
4786 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4787 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4789 i965_post_processing_internal(ctx, i965->pp_context,
4798 if (flags & I965_PP_FLAG_AVS) {
4799 struct i965_render_state *render_state = &i965->render_state;
4800 struct intel_region *dest_region = render_state->draw_region;
4802 if (out_surface_id != VA_INVALID_ID)
4803 tmp_id = out_surface_id;
4805 src_surface.base = (struct object_base *)obj_surface;
4806 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4807 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4809 status = i965_CreateSurfaces(ctx,
4811 dest_region->height,
4812 VA_RT_FORMAT_YUV420,
4815 assert(status == VA_STATUS_SUCCESS);
4816 obj_surface = SURFACE(out_surface_id);
4817 assert(obj_surface);
4818 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
4819 i965_vpp_clear_surface(ctx, i965->pp_context, obj_surface, 0);
4821 dst_surface.base = (struct object_base *)obj_surface;
4822 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4823 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4825 i965_post_processing_internal(ctx, i965->pp_context,
4833 if (tmp_id != VA_INVALID_ID)
4834 i965_DestroySurfaces(ctx, &tmp_id, 1);
4836 *has_done_scaling = 1;
4839 _i965UnlockMutex(&i965->pp_mutex);
4842 return out_surface_id;
4846 i965_image_pl2_processing(VADriverContextP ctx,
4847 const struct i965_surface *src_surface,
4848 const VARectangle *src_rect,
4849 struct i965_surface *dst_surface,
4850 const VARectangle *dst_rect);
4853 i965_image_plx_nv12_plx_processing(VADriverContextP ctx,
4854 VAStatus (*i965_image_plx_nv12_processing)(
4856 const struct i965_surface *,
4857 const VARectangle *,
4858 struct i965_surface *,
4859 const VARectangle *),
4860 const struct i965_surface *src_surface,
4861 const VARectangle *src_rect,
4862 struct i965_surface *dst_surface,
4863 const VARectangle *dst_rect)
4865 struct i965_driver_data *i965 = i965_driver_data(ctx);
4867 VASurfaceID tmp_surface_id = VA_INVALID_SURFACE;
4868 struct object_surface *obj_surface = NULL;
4869 struct i965_surface tmp_surface;
4872 pp_get_surface_size(ctx, dst_surface, &width, &height);
4873 status = i965_CreateSurfaces(ctx,
4876 VA_RT_FORMAT_YUV420,
4879 assert(status == VA_STATUS_SUCCESS);
4880 obj_surface = SURFACE(tmp_surface_id);
4881 assert(obj_surface);
4882 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
4884 tmp_surface.base = (struct object_base *)obj_surface;
4885 tmp_surface.type = I965_SURFACE_TYPE_SURFACE;
4886 tmp_surface.flags = I965_SURFACE_FLAG_FRAME;
4888 status = i965_image_plx_nv12_processing(ctx,
4894 if (status == VA_STATUS_SUCCESS)
4895 status = i965_image_pl2_processing(ctx,
4901 i965_DestroySurfaces(ctx,
4910 i965_image_pl1_rgbx_processing(VADriverContextP ctx,
4911 const struct i965_surface *src_surface,
4912 const VARectangle *src_rect,
4913 struct i965_surface *dst_surface,
4914 const VARectangle *dst_rect)
4916 struct i965_driver_data *i965 = i965_driver_data(ctx);
4917 struct i965_post_processing_context *pp_context = i965->pp_context;
4918 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4922 case VA_FOURCC_NV12:
4923 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4928 PP_RGBX_LOAD_SAVE_NV12,
4930 intel_batchbuffer_flush(pp_context->batch);
4934 vaStatus = i965_image_plx_nv12_plx_processing(ctx,
4935 i965_image_pl1_rgbx_processing,
4947 i965_image_pl3_processing(VADriverContextP ctx,
4948 const struct i965_surface *src_surface,
4949 const VARectangle *src_rect,
4950 struct i965_surface *dst_surface,
4951 const VARectangle *dst_rect)
4953 struct i965_driver_data *i965 = i965_driver_data(ctx);
4954 struct i965_post_processing_context *pp_context = i965->pp_context;
4955 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
4956 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
4959 case VA_FOURCC_NV12:
4960 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4965 PP_PL3_LOAD_SAVE_N12,
4967 intel_batchbuffer_flush(pp_context->batch);
4970 case VA_FOURCC_IMC1:
4971 case VA_FOURCC_IMC3:
4972 case VA_FOURCC_YV12:
4973 case VA_FOURCC_I420:
4974 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4979 PP_PL3_LOAD_SAVE_PL3,
4981 intel_batchbuffer_flush(pp_context->batch);
4984 case VA_FOURCC_YUY2:
4985 case VA_FOURCC_UYVY:
4986 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
4991 PP_PL3_LOAD_SAVE_PA,
4993 intel_batchbuffer_flush(pp_context->batch);
4997 vaStatus = i965_image_plx_nv12_plx_processing(ctx,
4998 i965_image_pl3_processing,
5010 i965_image_pl2_processing(VADriverContextP ctx,
5011 const struct i965_surface *src_surface,
5012 const VARectangle *src_rect,
5013 struct i965_surface *dst_surface,
5014 const VARectangle *dst_rect)
5016 struct i965_driver_data *i965 = i965_driver_data(ctx);
5017 struct i965_post_processing_context *pp_context = i965->pp_context;
5018 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
5019 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
5022 case VA_FOURCC_NV12:
5023 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5028 PP_NV12_LOAD_SAVE_N12,
5032 case VA_FOURCC_IMC1:
5033 case VA_FOURCC_IMC3:
5034 case VA_FOURCC_YV12:
5035 case VA_FOURCC_I420:
5036 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5041 PP_NV12_LOAD_SAVE_PL3,
5045 case VA_FOURCC_YUY2:
5046 case VA_FOURCC_UYVY:
5047 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5052 PP_NV12_LOAD_SAVE_PA,
5056 case VA_FOURCC_BGRX:
5057 case VA_FOURCC_BGRA:
5058 case VA_FOURCC_RGBX:
5059 case VA_FOURCC_RGBA:
5060 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5065 PP_NV12_LOAD_SAVE_RGBX,
5070 return VA_STATUS_ERROR_UNIMPLEMENTED;
5073 intel_batchbuffer_flush(pp_context->batch);
5079 i965_image_pl1_processing(VADriverContextP ctx,
5080 const struct i965_surface *src_surface,
5081 const VARectangle *src_rect,
5082 struct i965_surface *dst_surface,
5083 const VARectangle *dst_rect)
5085 struct i965_driver_data *i965 = i965_driver_data(ctx);
5086 struct i965_post_processing_context *pp_context = i965->pp_context;
5087 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
5091 case VA_FOURCC_NV12:
5092 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5097 PP_PA_LOAD_SAVE_NV12,
5099 intel_batchbuffer_flush(pp_context->batch);
5102 case VA_FOURCC_YV12:
5103 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5108 PP_PA_LOAD_SAVE_PL3,
5110 intel_batchbuffer_flush(pp_context->batch);
5113 case VA_FOURCC_YUY2:
5114 case VA_FOURCC_UYVY:
5115 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
5122 intel_batchbuffer_flush(pp_context->batch);
5126 vaStatus = i965_image_plx_nv12_plx_processing(ctx,
5127 i965_image_pl1_processing,
5139 i965_image_processing(VADriverContextP ctx,
5140 const struct i965_surface *src_surface,
5141 const VARectangle *src_rect,
5142 struct i965_surface *dst_surface,
5143 const VARectangle *dst_rect)
5145 struct i965_driver_data *i965 = i965_driver_data(ctx);
5146 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
5148 if (HAS_VPP(i965)) {
5149 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
5151 _i965LockMutex(&i965->pp_mutex);
5154 case VA_FOURCC_YV12:
5155 case VA_FOURCC_I420:
5156 case VA_FOURCC_IMC1:
5157 case VA_FOURCC_IMC3:
5158 case VA_FOURCC_422H:
5159 case VA_FOURCC_422V:
5160 case VA_FOURCC_411P:
5161 case VA_FOURCC_444P:
5162 case VA_FOURCC_YV16:
5163 status = i965_image_pl3_processing(ctx,
5170 case VA_FOURCC_NV12:
5171 status = i965_image_pl2_processing(ctx,
5177 case VA_FOURCC_YUY2:
5178 case VA_FOURCC_UYVY:
5179 status = i965_image_pl1_processing(ctx,
5185 case VA_FOURCC_BGRA:
5186 case VA_FOURCC_BGRX:
5187 case VA_FOURCC_RGBA:
5188 case VA_FOURCC_RGBX:
5189 status = i965_image_pl1_rgbx_processing(ctx,
5196 status = VA_STATUS_ERROR_UNIMPLEMENTED;
5200 _i965UnlockMutex(&i965->pp_mutex);
5207 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
5211 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
5212 pp_context->surface_state_binding_table.bo = NULL;
5214 dri_bo_unreference(pp_context->curbe.bo);
5215 pp_context->curbe.bo = NULL;
5217 dri_bo_unreference(pp_context->sampler_state_table.bo);
5218 pp_context->sampler_state_table.bo = NULL;
5220 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
5221 pp_context->sampler_state_table.bo_8x8 = NULL;
5223 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
5224 pp_context->sampler_state_table.bo_8x8_uv = NULL;
5226 dri_bo_unreference(pp_context->idrt.bo);
5227 pp_context->idrt.bo = NULL;
5228 pp_context->idrt.num_interface_descriptors = 0;
5230 dri_bo_unreference(pp_context->vfe_state.bo);
5231 pp_context->vfe_state.bo = NULL;
5233 dri_bo_unreference(pp_context->pp_dndi_context.stmm_bo);
5234 pp_context->pp_dndi_context.stmm_bo = NULL;
5236 dri_bo_unreference(pp_context->pp_dn_context.stmm_bo);
5237 pp_context->pp_dn_context.stmm_bo = NULL;
5239 for (i = 0; i < NUM_PP_MODULES; i++) {
5240 struct pp_module *pp_module = &pp_context->pp_modules[i];
5242 dri_bo_unreference(pp_module->kernel.bo);
5243 pp_module->kernel.bo = NULL;
5246 free(pp_context->pp_static_parameter);
5247 free(pp_context->pp_inline_parameter);
5248 pp_context->pp_static_parameter = NULL;
5249 pp_context->pp_inline_parameter = NULL;
5253 i965_post_processing_terminate(VADriverContextP ctx)
5255 struct i965_driver_data *i965 = i965_driver_data(ctx);
5256 struct i965_post_processing_context *pp_context = i965->pp_context;
5259 pp_context->finalize(pp_context);
5263 i965->pp_context = NULL;
5266 #define VPP_CURBE_ALLOCATION_SIZE 32
5269 i965_post_processing_context_init(VADriverContextP ctx,
5271 struct intel_batchbuffer *batch)
5273 struct i965_driver_data *i965 = i965_driver_data(ctx);
5275 struct i965_post_processing_context *pp_context = data;
5277 if (IS_IRONLAKE(i965->intel.device_info)) {
5278 pp_context->urb.size = i965->intel.device_info->urb_size;
5279 pp_context->urb.num_vfe_entries = 32;
5280 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
5281 pp_context->urb.num_cs_entries = 1;
5282 pp_context->urb.size_cs_entry = 2;
5283 pp_context->urb.vfe_start = 0;
5284 pp_context->urb.cs_start = pp_context->urb.vfe_start +
5285 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
5286 assert(pp_context->urb.cs_start +
5287 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= i965->intel.device_info->urb_size);
5288 pp_context->intel_post_processing = ironlake_post_processing;
5290 pp_context->vfe_gpu_state.max_num_threads = 60;
5291 pp_context->vfe_gpu_state.num_urb_entries = 59;
5292 pp_context->vfe_gpu_state.gpgpu_mode = 0;
5293 pp_context->vfe_gpu_state.urb_entry_size = 16 - 1;
5294 pp_context->vfe_gpu_state.curbe_allocation_size = VPP_CURBE_ALLOCATION_SIZE;
5295 pp_context->intel_post_processing = gen6_post_processing;
5298 pp_context->finalize = i965_post_processing_context_finalize;
5300 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
5301 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
5302 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen7));
5303 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen75));
5305 if (IS_HASWELL(i965->intel.device_info))
5306 memcpy(pp_context->pp_modules, pp_modules_gen75, sizeof(pp_context->pp_modules));
5307 else if (IS_GEN7(i965->intel.device_info))
5308 memcpy(pp_context->pp_modules, pp_modules_gen7, sizeof(pp_context->pp_modules));
5309 else if (IS_GEN6(i965->intel.device_info))
5310 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
5311 else if (IS_IRONLAKE(i965->intel.device_info))
5312 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
5314 for (i = 0; i < NUM_PP_MODULES; i++) {
5315 struct pp_module *pp_module = &pp_context->pp_modules[i];
5316 dri_bo_unreference(pp_module->kernel.bo);
5317 if (pp_module->kernel.bin && pp_module->kernel.size) {
5318 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
5319 pp_module->kernel.name,
5320 pp_module->kernel.size,
5322 assert(pp_module->kernel.bo);
5323 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
5325 pp_module->kernel.bo = NULL;
5329 /* static & inline parameters */
5330 if (IS_GEN7(i965->intel.device_info)) {
5331 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
5332 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
5334 pp_context->pp_static_parameter = calloc(sizeof(struct pp_static_parameter), 1);
5335 pp_context->pp_inline_parameter = calloc(sizeof(struct pp_inline_parameter), 1);
5338 pp_context->pp_dndi_context.current_out_surface = VA_INVALID_SURFACE;
5339 pp_context->pp_dndi_context.current_out_obj_surface = NULL;
5340 pp_context->pp_dndi_context.frame_order = -1;
5341 pp_context->batch = batch;
5345 i965_post_processing_init(VADriverContextP ctx)
5347 struct i965_driver_data *i965 = i965_driver_data(ctx);
5348 struct i965_post_processing_context *pp_context = i965->pp_context;
5350 if (HAS_VPP(i965)) {
5351 if (pp_context == NULL) {
5352 pp_context = calloc(1, sizeof(*pp_context));
5353 i965->codec_info->post_processing_context_init(ctx, pp_context, i965->pp_batch);
5354 i965->pp_context = pp_context;
5361 static const int procfilter_to_pp_flag[VAProcFilterCount] = {
5362 PP_NULL, /* VAProcFilterNone */
5363 PP_NV12_DN, /* VAProcFilterNoiseReduction */
5364 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
5365 PP_NULL, /* VAProcFilterSharpening */
5366 PP_NULL, /* VAProcFilterColorBalance */
5369 static const int proc_frame_to_pp_frame[3] = {
5370 I965_SURFACE_FLAG_FRAME,
5371 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
5372 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
5376 i965_proc_picture(VADriverContextP ctx,
5378 union codec_state *codec_state,
5379 struct hw_context *hw_context)
5381 struct i965_driver_data *i965 = i965_driver_data(ctx);
5382 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
5383 struct proc_state *proc_state = &codec_state->proc;
5384 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
5385 struct object_surface *obj_surface;
5386 struct i965_surface src_surface, dst_surface;
5387 VARectangle src_rect, dst_rect;
5390 VASurfaceID tmp_surfaces[VAProcFilterCount + 4];
5391 int num_tmp_surfaces = 0;
5392 unsigned int tiling = 0, swizzle = 0;
5393 int in_width, in_height;
5395 if (pipeline_param->surface == VA_INVALID_ID ||
5396 proc_state->current_render_target == VA_INVALID_ID) {
5397 status = VA_STATUS_ERROR_INVALID_SURFACE;
5401 obj_surface = SURFACE(pipeline_param->surface);
5404 status = VA_STATUS_ERROR_INVALID_SURFACE;
5408 if (!obj_surface->bo) {
5409 status = VA_STATUS_ERROR_INVALID_VALUE; /* The input surface is created without valid content */
5413 if (pipeline_param->num_filters && !pipeline_param->filters) {
5414 status = VA_STATUS_ERROR_INVALID_PARAMETER;
5418 in_width = obj_surface->orig_width;
5419 in_height = obj_surface->orig_height;
5420 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5422 src_surface.base = (struct object_base *)obj_surface;
5423 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5424 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
5426 VASurfaceID out_surface_id = VA_INVALID_ID;
5427 if (obj_surface->fourcc != VA_FOURCC_NV12) {
5428 src_surface.base = (struct object_base *)obj_surface;
5429 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5430 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5433 src_rect.width = in_width;
5434 src_rect.height = in_height;
5436 status = i965_CreateSurfaces(ctx,
5439 VA_RT_FORMAT_YUV420,
5442 assert(status == VA_STATUS_SUCCESS);
5443 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
5444 obj_surface = SURFACE(out_surface_id);
5445 assert(obj_surface);
5446 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
5448 dst_surface.base = (struct object_base *)obj_surface;
5449 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5450 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5453 dst_rect.width = in_width;
5454 dst_rect.height = in_height;
5456 status = i965_image_processing(ctx,
5461 assert(status == VA_STATUS_SUCCESS);
5463 src_surface.base = (struct object_base *)obj_surface;
5464 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5465 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
5468 if (pipeline_param->surface_region) {
5469 src_rect.x = pipeline_param->surface_region->x;
5470 src_rect.y = pipeline_param->surface_region->y;
5471 src_rect.width = pipeline_param->surface_region->width;
5472 src_rect.height = pipeline_param->surface_region->height;
5476 src_rect.width = in_width;
5477 src_rect.height = in_height;
5480 if (pipeline_param->output_region) {
5481 dst_rect.x = pipeline_param->output_region->x;
5482 dst_rect.y = pipeline_param->output_region->y;
5483 dst_rect.width = pipeline_param->output_region->width;
5484 dst_rect.height = pipeline_param->output_region->height;
5488 dst_rect.width = in_width;
5489 dst_rect.height = in_height;
5492 proc_context->pp_context.pipeline_param = pipeline_param;
5494 for (i = 0; i < pipeline_param->num_filters; i++) {
5495 struct object_buffer *obj_buffer = BUFFER(pipeline_param->filters[i]);
5496 VAProcFilterParameterBufferBase *filter_param = NULL;
5497 VAProcFilterType filter_type;
5501 !obj_buffer->buffer_store ||
5502 !obj_buffer->buffer_store->buffer) {
5503 status = VA_STATUS_ERROR_INVALID_FILTER_CHAIN;
5507 out_surface_id = VA_INVALID_ID;
5508 filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
5509 filter_type = filter_param->type;
5510 kernel_index = procfilter_to_pp_flag[filter_type];
5512 if (kernel_index != PP_NULL &&
5513 proc_context->pp_context.pp_modules[kernel_index].kernel.bo != NULL) {
5514 status = i965_CreateSurfaces(ctx,
5517 VA_RT_FORMAT_YUV420,
5520 assert(status == VA_STATUS_SUCCESS);
5521 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
5522 obj_surface = SURFACE(out_surface_id);
5523 assert(obj_surface);
5524 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
5525 dst_surface.base = (struct object_base *)obj_surface;
5526 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5527 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
5535 if (status == VA_STATUS_SUCCESS) {
5536 src_surface.base = dst_surface.base;
5537 src_surface.type = dst_surface.type;
5538 src_surface.flags = dst_surface.flags;
5543 proc_context->pp_context.pipeline_param = NULL;
5544 obj_surface = SURFACE(proc_state->current_render_target);
5547 status = VA_STATUS_ERROR_INVALID_SURFACE;
5552 if (obj_surface->fourcc && obj_surface->fourcc != VA_FOURCC_NV12){
5554 out_surface_id = VA_INVALID_ID;
5555 status = i965_CreateSurfaces(ctx,
5556 obj_surface->orig_width,
5557 obj_surface->orig_height,
5558 VA_RT_FORMAT_YUV420,
5561 assert(status == VA_STATUS_SUCCESS);
5562 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
5563 struct object_surface *csc_surface = SURFACE(out_surface_id);
5564 assert(csc_surface);
5565 i965_check_alloc_surface_bo(ctx, csc_surface, !!tiling, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
5566 dst_surface.base = (struct object_base *)csc_surface;
5568 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
5569 dst_surface.base = (struct object_base *)obj_surface;
5572 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5573 i965_vpp_clear_surface(ctx, &proc_context->pp_context, obj_surface, pipeline_param->output_background_color);
5575 // load/save doesn't support different origin offset for src and dst surface
5576 if (src_rect.width == dst_rect.width &&
5577 src_rect.height == dst_rect.height &&
5578 src_rect.x == dst_rect.x &&
5579 src_rect.y == dst_rect.y) {
5580 i965_post_processing_internal(ctx, &proc_context->pp_context,
5585 PP_NV12_LOAD_SAVE_N12,
5589 i965_post_processing_internal(ctx, &proc_context->pp_context,
5594 (pipeline_param->filter_flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC ?
5595 PP_NV12_AVS : PP_NV12_SCALING,
5600 src_surface.base = dst_surface.base;
5601 src_surface.type = dst_surface.type;
5602 src_surface.flags = dst_surface.flags;
5603 dst_surface.base = (struct object_base *)obj_surface;
5604 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5605 i965_image_processing(ctx, &src_surface, &dst_rect, &dst_surface, &dst_rect);
5608 if (num_tmp_surfaces)
5609 i965_DestroySurfaces(ctx,
5613 intel_batchbuffer_flush(hw_context->batch);
5615 return VA_STATUS_SUCCESS;
5618 if (num_tmp_surfaces)
5619 i965_DestroySurfaces(ctx,
5627 i965_proc_context_destroy(void *hw_context)
5629 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
5631 i965_post_processing_context_finalize(&proc_context->pp_context);
5632 intel_batchbuffer_free(proc_context->base.batch);
5637 i965_proc_context_init(VADriverContextP ctx, struct object_config *obj_config)
5639 struct i965_driver_data *i965 = i965_driver_data(ctx);
5640 struct intel_driver_data *intel = intel_driver_data(ctx);
5641 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
5643 proc_context->base.destroy = i965_proc_context_destroy;
5644 proc_context->base.run = i965_proc_picture;
5645 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
5646 i965->codec_info->post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
5648 return (struct hw_context *)proc_context;