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"
43 #define HAS_PP(ctx) (IS_IRONLAKE((ctx)->intel.device_id) || \
44 IS_GEN6((ctx)->intel.device_id) || \
45 IS_GEN7((ctx)->intel.device_id) || \
46 IS_GEN8((ctx)->intel.device_id))
49 #define SURFACE_STATE_PADDED_SIZE MAX(SURFACE_STATE_PADDED_SIZE_GEN8,\
50 MAX(SURFACE_STATE_PADDED_SIZE_GEN6, SURFACE_STATE_PADDED_SIZE_GEN7))
52 #define SURFACE_STATE_OFFSET(index) (SURFACE_STATE_PADDED_SIZE * index)
53 #define BINDING_TABLE_OFFSET SURFACE_STATE_OFFSET(MAX_PP_SURFACES)
55 #define GPU_ASM_BLOCK_WIDTH 16
56 #define GPU_ASM_BLOCK_HEIGHT 8
57 #define GPU_ASM_X_OFFSET_ALIGNMENT 4
59 #define VA_STATUS_SUCCESS_1 0xFFFFFFFE
62 i965_DestroySurfaces(VADriverContextP ctx,
63 VASurfaceID *surface_list,
66 i965_CreateSurfaces(VADriverContextP ctx,
71 VASurfaceID *surfaces);
73 static const uint32_t pp_null_gen5[][4] = {
74 #include "shaders/post_processing/gen5_6/null.g4b.gen5"
77 static const uint32_t pp_nv12_load_save_nv12_gen5[][4] = {
78 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g4b.gen5"
81 static const uint32_t pp_nv12_load_save_pl3_gen5[][4] = {
82 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g4b.gen5"
85 static const uint32_t pp_pl3_load_save_nv12_gen5[][4] = {
86 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g4b.gen5"
89 static const uint32_t pp_pl3_load_save_pl3_gen5[][4] = {
90 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g4b.gen5"
93 static const uint32_t pp_nv12_scaling_gen5[][4] = {
94 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g4b.gen5"
97 static const uint32_t pp_nv12_avs_gen5[][4] = {
98 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g4b.gen5"
101 static const uint32_t pp_nv12_dndi_gen5[][4] = {
102 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g4b.gen5"
105 static const uint32_t pp_nv12_dn_gen5[][4] = {
106 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g4b.gen5"
109 static const uint32_t pp_nv12_load_save_pa_gen5[][4] = {
110 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g4b.gen5"
113 static const uint32_t pp_pl3_load_save_pa_gen5[][4] = {
114 #include "shaders/post_processing/gen5_6/pl3_load_save_pa.g4b.gen5"
117 static const uint32_t pp_pa_load_save_nv12_gen5[][4] = {
118 #include "shaders/post_processing/gen5_6/pa_load_save_nv12.g4b.gen5"
121 static const uint32_t pp_pa_load_save_pl3_gen5[][4] = {
122 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g4b.gen5"
125 static const uint32_t pp_pa_load_save_pa_gen5[][4] = {
126 #include "shaders/post_processing/gen5_6/pa_load_save_pa.g4b.gen5"
129 static const uint32_t pp_rgbx_load_save_nv12_gen5[][4] = {
130 #include "shaders/post_processing/gen5_6/rgbx_load_save_nv12.g4b.gen5"
133 static const uint32_t pp_nv12_load_save_rgbx_gen5[][4] = {
134 #include "shaders/post_processing/gen5_6/nv12_load_save_rgbx.g4b.gen5"
137 static VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
138 const struct i965_surface *src_surface,
139 const VARectangle *src_rect,
140 struct i965_surface *dst_surface,
141 const VARectangle *dst_rect,
143 static VAStatus pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
144 const struct i965_surface *src_surface,
145 const VARectangle *src_rect,
146 struct i965_surface *dst_surface,
147 const VARectangle *dst_rect,
149 static VAStatus pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
150 const struct i965_surface *src_surface,
151 const VARectangle *src_rect,
152 struct i965_surface *dst_surface,
153 const VARectangle *dst_rect,
155 static VAStatus gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
156 const struct i965_surface *src_surface,
157 const VARectangle *src_rect,
158 struct i965_surface *dst_surface,
159 const VARectangle *dst_rect,
161 static VAStatus pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
162 const struct i965_surface *src_surface,
163 const VARectangle *src_rect,
164 struct i965_surface *dst_surface,
165 const VARectangle *dst_rect,
167 static VAStatus pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
168 const struct i965_surface *src_surface,
169 const VARectangle *src_rect,
170 struct i965_surface *dst_surface,
171 const VARectangle *dst_rect,
173 static VAStatus pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
174 const struct i965_surface *src_surface,
175 const VARectangle *src_rect,
176 struct i965_surface *dst_surface,
177 const VARectangle *dst_rect,
180 static struct pp_module pp_modules_gen5[] = {
183 "NULL module (for testing)",
186 sizeof(pp_null_gen5),
196 PP_NV12_LOAD_SAVE_N12,
197 pp_nv12_load_save_nv12_gen5,
198 sizeof(pp_nv12_load_save_nv12_gen5),
202 pp_plx_load_save_plx_initialize,
208 PP_NV12_LOAD_SAVE_PL3,
209 pp_nv12_load_save_pl3_gen5,
210 sizeof(pp_nv12_load_save_pl3_gen5),
214 pp_plx_load_save_plx_initialize,
220 PP_PL3_LOAD_SAVE_N12,
221 pp_pl3_load_save_nv12_gen5,
222 sizeof(pp_pl3_load_save_nv12_gen5),
226 pp_plx_load_save_plx_initialize,
232 PP_PL3_LOAD_SAVE_PL3,
233 pp_pl3_load_save_pl3_gen5,
234 sizeof(pp_pl3_load_save_pl3_gen5),
238 pp_plx_load_save_plx_initialize
243 "NV12 Scaling module",
245 pp_nv12_scaling_gen5,
246 sizeof(pp_nv12_scaling_gen5),
250 pp_nv12_scaling_initialize,
258 sizeof(pp_nv12_avs_gen5),
262 pp_nv12_avs_initialize_nlas,
270 sizeof(pp_nv12_dndi_gen5),
274 pp_nv12_dndi_initialize,
282 sizeof(pp_nv12_dn_gen5),
286 pp_nv12_dn_initialize,
292 PP_NV12_LOAD_SAVE_PA,
293 pp_nv12_load_save_pa_gen5,
294 sizeof(pp_nv12_load_save_pa_gen5),
298 pp_plx_load_save_plx_initialize,
305 pp_pl3_load_save_pa_gen5,
306 sizeof(pp_pl3_load_save_pa_gen5),
310 pp_plx_load_save_plx_initialize,
316 PP_PA_LOAD_SAVE_NV12,
317 pp_pa_load_save_nv12_gen5,
318 sizeof(pp_pa_load_save_nv12_gen5),
322 pp_plx_load_save_plx_initialize,
329 pp_pa_load_save_pl3_gen5,
330 sizeof(pp_pa_load_save_pl3_gen5),
334 pp_plx_load_save_plx_initialize,
341 pp_pa_load_save_pa_gen5,
342 sizeof(pp_pa_load_save_pa_gen5),
346 pp_plx_load_save_plx_initialize,
352 PP_RGBX_LOAD_SAVE_NV12,
353 pp_rgbx_load_save_nv12_gen5,
354 sizeof(pp_rgbx_load_save_nv12_gen5),
358 pp_plx_load_save_plx_initialize,
364 PP_NV12_LOAD_SAVE_RGBX,
365 pp_nv12_load_save_rgbx_gen5,
366 sizeof(pp_nv12_load_save_rgbx_gen5),
370 pp_plx_load_save_plx_initialize,
374 static const uint32_t pp_null_gen6[][4] = {
375 #include "shaders/post_processing/gen5_6/null.g6b"
378 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
379 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
382 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
383 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
386 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
387 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
390 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
391 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
394 static const uint32_t pp_nv12_scaling_gen6[][4] = {
395 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
398 static const uint32_t pp_nv12_avs_gen6[][4] = {
399 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
402 static const uint32_t pp_nv12_dndi_gen6[][4] = {
403 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
406 static const uint32_t pp_nv12_dn_gen6[][4] = {
407 #include "shaders/post_processing/gen5_6/nv12_dn_nv12.g6b"
410 static const uint32_t pp_nv12_load_save_pa_gen6[][4] = {
411 #include "shaders/post_processing/gen5_6/nv12_load_save_pa.g6b"
414 static const uint32_t pp_pl3_load_save_pa_gen6[][4] = {
415 #include "shaders/post_processing/gen5_6/pl3_load_save_pa.g6b"
418 static const uint32_t pp_pa_load_save_nv12_gen6[][4] = {
419 #include "shaders/post_processing/gen5_6/pa_load_save_nv12.g6b"
422 static const uint32_t pp_pa_load_save_pl3_gen6[][4] = {
423 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g6b"
426 static const uint32_t pp_pa_load_save_pa_gen6[][4] = {
427 #include "shaders/post_processing/gen5_6/pa_load_save_pa.g6b"
430 static const uint32_t pp_rgbx_load_save_nv12_gen6[][4] = {
431 #include "shaders/post_processing/gen5_6/rgbx_load_save_nv12.g6b"
434 static const uint32_t pp_nv12_load_save_rgbx_gen6[][4] = {
435 #include "shaders/post_processing/gen5_6/nv12_load_save_rgbx.g6b"
438 static struct pp_module pp_modules_gen6[] = {
441 "NULL module (for testing)",
444 sizeof(pp_null_gen6),
454 PP_NV12_LOAD_SAVE_N12,
455 pp_nv12_load_save_nv12_gen6,
456 sizeof(pp_nv12_load_save_nv12_gen6),
460 pp_plx_load_save_plx_initialize,
466 PP_NV12_LOAD_SAVE_PL3,
467 pp_nv12_load_save_pl3_gen6,
468 sizeof(pp_nv12_load_save_pl3_gen6),
472 pp_plx_load_save_plx_initialize,
478 PP_PL3_LOAD_SAVE_N12,
479 pp_pl3_load_save_nv12_gen6,
480 sizeof(pp_pl3_load_save_nv12_gen6),
484 pp_plx_load_save_plx_initialize,
490 PP_PL3_LOAD_SAVE_PL3,
491 pp_pl3_load_save_pl3_gen6,
492 sizeof(pp_pl3_load_save_pl3_gen6),
496 pp_plx_load_save_plx_initialize,
501 "NV12 Scaling module",
503 pp_nv12_scaling_gen6,
504 sizeof(pp_nv12_scaling_gen6),
508 gen6_nv12_scaling_initialize,
516 sizeof(pp_nv12_avs_gen6),
520 pp_nv12_avs_initialize_nlas,
528 sizeof(pp_nv12_dndi_gen6),
532 pp_nv12_dndi_initialize,
540 sizeof(pp_nv12_dn_gen6),
544 pp_nv12_dn_initialize,
549 PP_NV12_LOAD_SAVE_PA,
550 pp_nv12_load_save_pa_gen6,
551 sizeof(pp_nv12_load_save_pa_gen6),
555 pp_plx_load_save_plx_initialize,
562 pp_pl3_load_save_pa_gen6,
563 sizeof(pp_pl3_load_save_pa_gen6),
567 pp_plx_load_save_plx_initialize,
573 PP_PA_LOAD_SAVE_NV12,
574 pp_pa_load_save_nv12_gen6,
575 sizeof(pp_pa_load_save_nv12_gen6),
579 pp_plx_load_save_plx_initialize,
586 pp_pa_load_save_pl3_gen6,
587 sizeof(pp_pa_load_save_pl3_gen6),
591 pp_plx_load_save_plx_initialize,
598 pp_pa_load_save_pa_gen6,
599 sizeof(pp_pa_load_save_pa_gen6),
603 pp_plx_load_save_plx_initialize,
609 PP_RGBX_LOAD_SAVE_NV12,
610 pp_rgbx_load_save_nv12_gen6,
611 sizeof(pp_rgbx_load_save_nv12_gen6),
615 pp_plx_load_save_plx_initialize,
621 PP_NV12_LOAD_SAVE_RGBX,
622 pp_nv12_load_save_rgbx_gen6,
623 sizeof(pp_nv12_load_save_rgbx_gen6),
627 pp_plx_load_save_plx_initialize,
631 static const uint32_t pp_null_gen7[][4] = {
634 static const uint32_t pp_nv12_load_save_nv12_gen7[][4] = {
635 #include "shaders/post_processing/gen7/pl2_to_pl2.g7b"
638 static const uint32_t pp_nv12_load_save_pl3_gen7[][4] = {
639 #include "shaders/post_processing/gen7/pl2_to_pl3.g7b"
642 static const uint32_t pp_pl3_load_save_nv12_gen7[][4] = {
643 #include "shaders/post_processing/gen7/pl3_to_pl2.g7b"
646 static const uint32_t pp_pl3_load_save_pl3_gen7[][4] = {
647 #include "shaders/post_processing/gen7/pl3_to_pl3.g7b"
650 static const uint32_t pp_nv12_scaling_gen7[][4] = {
651 #include "shaders/post_processing/gen7/avs.g7b"
654 static const uint32_t pp_nv12_avs_gen7[][4] = {
655 #include "shaders/post_processing/gen7/avs.g7b"
658 static const uint32_t pp_nv12_dndi_gen7[][4] = {
659 #include "shaders/post_processing/gen7/dndi.g7b"
662 static const uint32_t pp_nv12_dn_gen7[][4] = {
663 #include "shaders/post_processing/gen7/nv12_dn_nv12.g7b"
665 static const uint32_t pp_nv12_load_save_pa_gen7[][4] = {
666 #include "shaders/post_processing/gen7/pl2_to_pa.g7b"
668 static const uint32_t pp_pl3_load_save_pa_gen7[][4] = {
669 #include "shaders/post_processing/gen7/pl3_to_pa.g7b"
671 static const uint32_t pp_pa_load_save_nv12_gen7[][4] = {
672 #include "shaders/post_processing/gen7/pa_to_pl2.g7b"
674 static const uint32_t pp_pa_load_save_pl3_gen7[][4] = {
675 #include "shaders/post_processing/gen7/pa_to_pl3.g7b"
677 static const uint32_t pp_pa_load_save_pa_gen7[][4] = {
678 #include "shaders/post_processing/gen7/pa_to_pa.g7b"
680 static const uint32_t pp_rgbx_load_save_nv12_gen7[][4] = {
681 #include "shaders/post_processing/gen7/rgbx_to_nv12.g7b"
683 static const uint32_t pp_nv12_load_save_rgbx_gen7[][4] = {
684 #include "shaders/post_processing/gen7/pl2_to_rgbx.g7b"
687 static VAStatus gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
688 const struct i965_surface *src_surface,
689 const VARectangle *src_rect,
690 struct i965_surface *dst_surface,
691 const VARectangle *dst_rect,
693 static VAStatus gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
694 const struct i965_surface *src_surface,
695 const VARectangle *src_rect,
696 struct i965_surface *dst_surface,
697 const VARectangle *dst_rect,
699 static VAStatus gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
700 const struct i965_surface *src_surface,
701 const VARectangle *src_rect,
702 struct i965_surface *dst_surface,
703 const VARectangle *dst_rect,
706 static VAStatus gen7_pp_rgbx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
707 const struct i965_surface *src_surface,
708 const VARectangle *src_rect,
709 struct i965_surface *dst_surface,
710 const VARectangle *dst_rect,
713 static VAStatus gen8_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
714 const struct i965_surface *src_surface,
715 const VARectangle *src_rect,
716 struct i965_surface *dst_surface,
717 const VARectangle *dst_rect,
720 static struct pp_module pp_modules_gen7[] = {
723 "NULL module (for testing)",
726 sizeof(pp_null_gen7),
736 PP_NV12_LOAD_SAVE_N12,
737 pp_nv12_load_save_nv12_gen7,
738 sizeof(pp_nv12_load_save_nv12_gen7),
742 gen7_pp_plx_avs_initialize,
748 PP_NV12_LOAD_SAVE_PL3,
749 pp_nv12_load_save_pl3_gen7,
750 sizeof(pp_nv12_load_save_pl3_gen7),
754 gen7_pp_plx_avs_initialize,
760 PP_PL3_LOAD_SAVE_N12,
761 pp_pl3_load_save_nv12_gen7,
762 sizeof(pp_pl3_load_save_nv12_gen7),
766 gen7_pp_plx_avs_initialize,
772 PP_PL3_LOAD_SAVE_PL3,
773 pp_pl3_load_save_pl3_gen7,
774 sizeof(pp_pl3_load_save_pl3_gen7),
778 gen7_pp_plx_avs_initialize,
783 "NV12 Scaling module",
785 pp_nv12_scaling_gen7,
786 sizeof(pp_nv12_scaling_gen7),
790 gen7_pp_plx_avs_initialize,
798 sizeof(pp_nv12_avs_gen7),
802 gen7_pp_plx_avs_initialize,
810 sizeof(pp_nv12_dndi_gen7),
814 gen7_pp_nv12_dndi_initialize,
822 sizeof(pp_nv12_dn_gen7),
826 gen7_pp_nv12_dn_initialize,
831 PP_NV12_LOAD_SAVE_PA,
832 pp_nv12_load_save_pa_gen7,
833 sizeof(pp_nv12_load_save_pa_gen7),
837 gen7_pp_plx_avs_initialize,
844 pp_pl3_load_save_pa_gen7,
845 sizeof(pp_pl3_load_save_pa_gen7),
849 gen7_pp_plx_avs_initialize,
855 PP_PA_LOAD_SAVE_NV12,
856 pp_pa_load_save_nv12_gen7,
857 sizeof(pp_pa_load_save_nv12_gen7),
861 gen7_pp_plx_avs_initialize,
868 pp_pa_load_save_pl3_gen7,
869 sizeof(pp_pa_load_save_pl3_gen7),
873 gen7_pp_plx_avs_initialize,
880 pp_pa_load_save_pa_gen7,
881 sizeof(pp_pa_load_save_pa_gen7),
885 gen7_pp_plx_avs_initialize,
891 PP_RGBX_LOAD_SAVE_NV12,
892 pp_rgbx_load_save_nv12_gen7,
893 sizeof(pp_rgbx_load_save_nv12_gen7),
897 gen7_pp_rgbx_avs_initialize,
903 PP_NV12_LOAD_SAVE_RGBX,
904 pp_nv12_load_save_rgbx_gen7,
905 sizeof(pp_nv12_load_save_rgbx_gen7),
909 gen7_pp_plx_avs_initialize,
914 static const uint32_t pp_null_gen75[][4] = {
917 static const uint32_t pp_nv12_load_save_nv12_gen75[][4] = {
918 #include "shaders/post_processing/gen7/pl2_to_pl2.g75b"
921 static const uint32_t pp_nv12_load_save_pl3_gen75[][4] = {
922 #include "shaders/post_processing/gen7/pl2_to_pl3.g75b"
925 static const uint32_t pp_pl3_load_save_nv12_gen75[][4] = {
926 #include "shaders/post_processing/gen7/pl3_to_pl2.g75b"
929 static const uint32_t pp_pl3_load_save_pl3_gen75[][4] = {
930 #include "shaders/post_processing/gen7/pl3_to_pl3.g75b"
933 static const uint32_t pp_nv12_scaling_gen75[][4] = {
934 #include "shaders/post_processing/gen7/avs.g75b"
937 static const uint32_t pp_nv12_avs_gen75[][4] = {
938 #include "shaders/post_processing/gen7/avs.g75b"
941 static const uint32_t pp_nv12_dndi_gen75[][4] = {
942 // #include "shaders/post_processing/gen7/dndi.g75b"
945 static const uint32_t pp_nv12_dn_gen75[][4] = {
946 // #include "shaders/post_processing/gen7/nv12_dn_nv12.g75b"
948 static const uint32_t pp_nv12_load_save_pa_gen75[][4] = {
949 #include "shaders/post_processing/gen7/pl2_to_pa.g75b"
951 static const uint32_t pp_pl3_load_save_pa_gen75[][4] = {
952 #include "shaders/post_processing/gen7/pl3_to_pa.g75b"
954 static const uint32_t pp_pa_load_save_nv12_gen75[][4] = {
955 #include "shaders/post_processing/gen7/pa_to_pl2.g75b"
957 static const uint32_t pp_pa_load_save_pl3_gen75[][4] = {
958 #include "shaders/post_processing/gen7/pa_to_pl3.g75b"
960 static const uint32_t pp_pa_load_save_pa_gen75[][4] = {
961 #include "shaders/post_processing/gen7/pa_to_pa.g75b"
963 static const uint32_t pp_rgbx_load_save_nv12_gen75[][4] = {
964 #include "shaders/post_processing/gen7/rgbx_to_nv12.g75b"
966 static const uint32_t pp_nv12_load_save_rgbx_gen75[][4] = {
967 #include "shaders/post_processing/gen7/pl2_to_rgbx.g75b"
970 static struct pp_module pp_modules_gen75[] = {
973 "NULL module (for testing)",
976 sizeof(pp_null_gen75),
986 PP_NV12_LOAD_SAVE_N12,
987 pp_nv12_load_save_nv12_gen75,
988 sizeof(pp_nv12_load_save_nv12_gen75),
992 gen7_pp_plx_avs_initialize,
998 PP_NV12_LOAD_SAVE_PL3,
999 pp_nv12_load_save_pl3_gen75,
1000 sizeof(pp_nv12_load_save_pl3_gen75),
1004 gen7_pp_plx_avs_initialize,
1010 PP_PL3_LOAD_SAVE_N12,
1011 pp_pl3_load_save_nv12_gen75,
1012 sizeof(pp_pl3_load_save_nv12_gen75),
1016 gen7_pp_plx_avs_initialize,
1022 PP_PL3_LOAD_SAVE_PL3,
1023 pp_pl3_load_save_pl3_gen75,
1024 sizeof(pp_pl3_load_save_pl3_gen75),
1028 gen7_pp_plx_avs_initialize,
1033 "NV12 Scaling module",
1035 pp_nv12_scaling_gen75,
1036 sizeof(pp_nv12_scaling_gen75),
1040 gen7_pp_plx_avs_initialize,
1048 sizeof(pp_nv12_avs_gen75),
1052 gen7_pp_plx_avs_initialize,
1060 sizeof(pp_nv12_dndi_gen75),
1064 gen7_pp_nv12_dndi_initialize,
1072 sizeof(pp_nv12_dn_gen75),
1076 gen7_pp_nv12_dn_initialize,
1082 PP_NV12_LOAD_SAVE_PA,
1083 pp_nv12_load_save_pa_gen75,
1084 sizeof(pp_nv12_load_save_pa_gen75),
1088 gen7_pp_plx_avs_initialize,
1094 PP_PL3_LOAD_SAVE_PA,
1095 pp_pl3_load_save_pa_gen75,
1096 sizeof(pp_pl3_load_save_pa_gen75),
1100 gen7_pp_plx_avs_initialize,
1106 PP_PA_LOAD_SAVE_NV12,
1107 pp_pa_load_save_nv12_gen75,
1108 sizeof(pp_pa_load_save_nv12_gen75),
1112 gen7_pp_plx_avs_initialize,
1118 PP_PA_LOAD_SAVE_PL3,
1119 pp_pa_load_save_pl3_gen75,
1120 sizeof(pp_pa_load_save_pl3_gen75),
1124 gen7_pp_plx_avs_initialize,
1131 pp_pa_load_save_pa_gen75,
1132 sizeof(pp_pa_load_save_pa_gen75),
1136 gen7_pp_plx_avs_initialize,
1142 PP_RGBX_LOAD_SAVE_NV12,
1143 pp_rgbx_load_save_nv12_gen75,
1144 sizeof(pp_rgbx_load_save_nv12_gen75),
1148 gen7_pp_rgbx_avs_initialize,
1154 PP_NV12_LOAD_SAVE_RGBX,
1155 pp_nv12_load_save_rgbx_gen75,
1156 sizeof(pp_nv12_load_save_rgbx_gen75),
1160 gen7_pp_plx_avs_initialize,
1165 /* TODO: Modify the shader and then compile it again.
1166 * Currently it is derived from Haswell*/
1167 static const uint32_t pp_null_gen8[][4] = {
1170 static const uint32_t pp_nv12_load_save_nv12_gen8[][4] = {
1171 #include "shaders/post_processing/gen8/pl2_to_pl2.g8b"
1174 static const uint32_t pp_nv12_load_save_pl3_gen8[][4] = {
1175 #include "shaders/post_processing/gen8/pl2_to_pl3.g8b"
1178 static const uint32_t pp_pl3_load_save_nv12_gen8[][4] = {
1179 #include "shaders/post_processing/gen8/pl3_to_pl2.g8b"
1182 static const uint32_t pp_pl3_load_save_pl3_gen8[][4] = {
1183 #include "shaders/post_processing/gen8/pl3_to_pl3.g8b"
1186 static const uint32_t pp_nv12_scaling_gen8[][4] = {
1187 #include "shaders/post_processing/gen8/pl2_to_pl2.g8b"
1190 static const uint32_t pp_nv12_avs_gen8[][4] = {
1191 #include "shaders/post_processing/gen8/pl2_to_pl2.g8b"
1194 static const uint32_t pp_nv12_dndi_gen8[][4] = {
1195 // #include "shaders/post_processing/gen7/dndi.g75b"
1198 static const uint32_t pp_nv12_dn_gen8[][4] = {
1199 // #include "shaders/post_processing/gen7/nv12_dn_nv12.g75b"
1201 static const uint32_t pp_nv12_load_save_pa_gen8[][4] = {
1202 #include "shaders/post_processing/gen8/pl2_to_pa.g8b"
1204 static const uint32_t pp_pl3_load_save_pa_gen8[][4] = {
1205 #include "shaders/post_processing/gen8/pl3_to_pa.g8b"
1207 static const uint32_t pp_pa_load_save_nv12_gen8[][4] = {
1208 #include "shaders/post_processing/gen8/pa_to_pl2.g8b"
1210 static const uint32_t pp_pa_load_save_pl3_gen8[][4] = {
1211 #include "shaders/post_processing/gen8/pa_to_pl3.g8b"
1213 static const uint32_t pp_pa_load_save_pa_gen8[][4] = {
1215 static const uint32_t pp_rgbx_load_save_nv12_gen8[][4] = {
1216 #include "shaders/post_processing/gen8/rgbx_to_nv12.g8b"
1218 static const uint32_t pp_nv12_load_save_rgbx_gen8[][4] = {
1219 #include "shaders/post_processing/gen8/pl2_to_rgbx.g8b"
1223 static struct pp_module pp_modules_gen8[] = {
1226 "NULL module (for testing)",
1229 sizeof(pp_null_gen8),
1239 PP_NV12_LOAD_SAVE_N12,
1240 pp_nv12_load_save_nv12_gen8,
1241 sizeof(pp_nv12_load_save_nv12_gen8),
1245 gen8_pp_plx_avs_initialize,
1251 PP_NV12_LOAD_SAVE_PL3,
1252 pp_nv12_load_save_pl3_gen8,
1253 sizeof(pp_nv12_load_save_pl3_gen8),
1257 gen8_pp_plx_avs_initialize,
1263 PP_PL3_LOAD_SAVE_N12,
1264 pp_pl3_load_save_nv12_gen8,
1265 sizeof(pp_pl3_load_save_nv12_gen8),
1269 gen8_pp_plx_avs_initialize,
1275 PP_PL3_LOAD_SAVE_N12,
1276 pp_pl3_load_save_pl3_gen8,
1277 sizeof(pp_pl3_load_save_pl3_gen8),
1281 gen8_pp_plx_avs_initialize,
1286 "NV12 Scaling module",
1288 pp_nv12_scaling_gen8,
1289 sizeof(pp_nv12_scaling_gen8),
1293 gen8_pp_plx_avs_initialize,
1301 sizeof(pp_nv12_avs_gen8),
1305 gen8_pp_plx_avs_initialize,
1313 sizeof(pp_nv12_dndi_gen8),
1317 gen7_pp_nv12_dndi_initialize,
1325 sizeof(pp_nv12_dn_gen8),
1329 gen7_pp_nv12_dn_initialize,
1334 PP_NV12_LOAD_SAVE_PA,
1335 pp_nv12_load_save_pa_gen8,
1336 sizeof(pp_nv12_load_save_pa_gen8),
1340 gen8_pp_plx_avs_initialize,
1346 PP_PL3_LOAD_SAVE_PA,
1347 pp_pl3_load_save_pa_gen8,
1348 sizeof(pp_pl3_load_save_pa_gen8),
1352 gen8_pp_plx_avs_initialize,
1358 PP_PA_LOAD_SAVE_NV12,
1359 pp_pa_load_save_nv12_gen8,
1360 sizeof(pp_pa_load_save_nv12_gen8),
1364 gen8_pp_plx_avs_initialize,
1370 PP_PA_LOAD_SAVE_PL3,
1371 pp_pa_load_save_pl3_gen8,
1372 sizeof(pp_pa_load_save_pl3_gen8),
1376 gen8_pp_plx_avs_initialize,
1383 pp_pa_load_save_pa_gen8,
1384 sizeof(pp_pa_load_save_pa_gen8),
1388 gen8_pp_plx_avs_initialize,
1394 PP_RGBX_LOAD_SAVE_NV12,
1395 pp_rgbx_load_save_nv12_gen8,
1396 sizeof(pp_rgbx_load_save_nv12_gen8),
1400 gen8_pp_plx_avs_initialize,
1406 PP_NV12_LOAD_SAVE_RGBX,
1407 pp_nv12_load_save_rgbx_gen8,
1408 sizeof(pp_nv12_load_save_rgbx_gen8),
1412 gen8_pp_plx_avs_initialize,
1419 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
1423 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
1424 struct object_image *obj_image = (struct object_image *)surface->base;
1425 fourcc = obj_image->image.format.fourcc;
1427 struct object_surface *obj_surface = (struct object_surface *)surface->base;
1428 fourcc = obj_surface->fourcc;
1435 pp_get_surface_size(VADriverContextP ctx, const struct i965_surface *surface, int *width, int *height)
1437 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
1438 struct object_image *obj_image = (struct object_image *)surface->base;
1440 *width = obj_image->image.width;
1441 *height = obj_image->image.height;
1443 struct object_surface *obj_surface = (struct object_surface *)surface->base;
1445 *width = obj_surface->orig_width;
1446 *height = obj_surface->orig_height;
1451 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
1454 case I915_TILING_NONE:
1455 ss->ss3.tiled_surface = 0;
1456 ss->ss3.tile_walk = 0;
1459 ss->ss3.tiled_surface = 1;
1460 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
1463 ss->ss3.tiled_surface = 1;
1464 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
1470 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
1473 case I915_TILING_NONE:
1474 ss->ss2.tiled_surface = 0;
1475 ss->ss2.tile_walk = 0;
1478 ss->ss2.tiled_surface = 1;
1479 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
1482 ss->ss2.tiled_surface = 1;
1483 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
1489 gen7_pp_set_surface_tiling(struct gen7_surface_state *ss, unsigned int tiling)
1492 case I915_TILING_NONE:
1493 ss->ss0.tiled_surface = 0;
1494 ss->ss0.tile_walk = 0;
1497 ss->ss0.tiled_surface = 1;
1498 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
1501 ss->ss0.tiled_surface = 1;
1502 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
1508 gen8_pp_set_surface_tiling(struct gen8_surface_state *ss, unsigned int tiling)
1511 case I915_TILING_NONE:
1512 ss->ss0.tiled_surface = 0;
1513 ss->ss0.tile_walk = 0;
1516 ss->ss0.tiled_surface = 1;
1517 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
1520 ss->ss0.tiled_surface = 1;
1521 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
1527 gen7_pp_set_surface2_tiling(struct gen7_surface_state2 *ss, unsigned int tiling)
1530 case I915_TILING_NONE:
1531 ss->ss2.tiled_surface = 0;
1532 ss->ss2.tile_walk = 0;
1535 ss->ss2.tiled_surface = 1;
1536 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
1539 ss->ss2.tiled_surface = 1;
1540 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
1546 gen8_pp_set_surface2_tiling(struct gen8_surface_state2 *ss, unsigned int tiling)
1549 case I915_TILING_NONE:
1550 ss->ss2.tiled_surface = 0;
1551 ss->ss2.tile_walk = 0;
1554 ss->ss2.tiled_surface = 1;
1555 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
1558 ss->ss2.tiled_surface = 1;
1559 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
1565 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
1567 struct i965_interface_descriptor *desc;
1569 int pp_index = pp_context->current_pp;
1571 bo = pp_context->idrt.bo;
1573 assert(bo->virtual);
1575 memset(desc, 0, sizeof(*desc));
1576 desc->desc0.grf_reg_blocks = 10;
1577 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
1578 desc->desc1.const_urb_entry_read_offset = 0;
1579 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
1580 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
1581 desc->desc2.sampler_count = 0;
1582 desc->desc3.binding_table_entry_count = 0;
1583 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
1585 dri_bo_emit_reloc(bo,
1586 I915_GEM_DOMAIN_INSTRUCTION, 0,
1587 desc->desc0.grf_reg_blocks,
1588 offsetof(struct i965_interface_descriptor, desc0),
1589 pp_context->pp_modules[pp_index].kernel.bo);
1591 dri_bo_emit_reloc(bo,
1592 I915_GEM_DOMAIN_INSTRUCTION, 0,
1593 desc->desc2.sampler_count << 2,
1594 offsetof(struct i965_interface_descriptor, desc2),
1595 pp_context->sampler_state_table.bo);
1598 pp_context->idrt.num_interface_descriptors++;
1602 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
1604 struct i965_vfe_state *vfe_state;
1607 bo = pp_context->vfe_state.bo;
1609 assert(bo->virtual);
1610 vfe_state = bo->virtual;
1611 memset(vfe_state, 0, sizeof(*vfe_state));
1612 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
1613 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
1614 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
1615 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
1616 vfe_state->vfe1.children_present = 0;
1617 vfe_state->vfe2.interface_descriptor_base =
1618 pp_context->idrt.bo->offset >> 4; /* reloc */
1619 dri_bo_emit_reloc(bo,
1620 I915_GEM_DOMAIN_INSTRUCTION, 0,
1622 offsetof(struct i965_vfe_state, vfe2),
1623 pp_context->idrt.bo);
1628 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
1630 unsigned char *constant_buffer;
1631 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1633 assert(sizeof(*pp_static_parameter) == 128);
1634 dri_bo_map(pp_context->curbe.bo, 1);
1635 assert(pp_context->curbe.bo->virtual);
1636 constant_buffer = pp_context->curbe.bo->virtual;
1637 memcpy(constant_buffer, pp_static_parameter, sizeof(*pp_static_parameter));
1638 dri_bo_unmap(pp_context->curbe.bo);
1642 ironlake_pp_states_setup(VADriverContextP ctx,
1643 struct i965_post_processing_context *pp_context)
1645 ironlake_pp_interface_descriptor_table(pp_context);
1646 ironlake_pp_vfe_state(pp_context);
1647 ironlake_pp_upload_constants(pp_context);
1651 ironlake_pp_pipeline_select(VADriverContextP ctx,
1652 struct i965_post_processing_context *pp_context)
1654 struct intel_batchbuffer *batch = pp_context->batch;
1656 BEGIN_BATCH(batch, 1);
1657 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
1658 ADVANCE_BATCH(batch);
1662 ironlake_pp_urb_layout(VADriverContextP ctx,
1663 struct i965_post_processing_context *pp_context)
1665 struct intel_batchbuffer *batch = pp_context->batch;
1666 unsigned int vfe_fence, cs_fence;
1668 vfe_fence = pp_context->urb.cs_start;
1669 cs_fence = pp_context->urb.size;
1671 BEGIN_BATCH(batch, 3);
1672 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
1673 OUT_BATCH(batch, 0);
1675 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
1676 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
1677 ADVANCE_BATCH(batch);
1681 ironlake_pp_state_base_address(VADriverContextP ctx,
1682 struct i965_post_processing_context *pp_context)
1684 struct intel_batchbuffer *batch = pp_context->batch;
1686 BEGIN_BATCH(batch, 8);
1687 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
1688 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1689 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
1690 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1691 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1692 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1693 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1694 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1695 ADVANCE_BATCH(batch);
1699 ironlake_pp_state_pointers(VADriverContextP ctx,
1700 struct i965_post_processing_context *pp_context)
1702 struct intel_batchbuffer *batch = pp_context->batch;
1704 BEGIN_BATCH(batch, 3);
1705 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
1706 OUT_BATCH(batch, 0);
1707 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
1708 ADVANCE_BATCH(batch);
1712 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
1713 struct i965_post_processing_context *pp_context)
1715 struct intel_batchbuffer *batch = pp_context->batch;
1717 BEGIN_BATCH(batch, 2);
1718 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
1720 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
1721 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
1722 ADVANCE_BATCH(batch);
1726 ironlake_pp_constant_buffer(VADriverContextP ctx,
1727 struct i965_post_processing_context *pp_context)
1729 struct intel_batchbuffer *batch = pp_context->batch;
1731 BEGIN_BATCH(batch, 2);
1732 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
1733 OUT_RELOC(batch, pp_context->curbe.bo,
1734 I915_GEM_DOMAIN_INSTRUCTION, 0,
1735 pp_context->urb.size_cs_entry - 1);
1736 ADVANCE_BATCH(batch);
1740 ironlake_pp_object_walker(VADriverContextP ctx,
1741 struct i965_post_processing_context *pp_context)
1743 struct intel_batchbuffer *batch = pp_context->batch;
1744 int x, x_steps, y, y_steps;
1745 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
1747 x_steps = pp_context->pp_x_steps(pp_context->private_context);
1748 y_steps = pp_context->pp_y_steps(pp_context->private_context);
1750 for (y = 0; y < y_steps; y++) {
1751 for (x = 0; x < x_steps; x++) {
1752 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
1753 BEGIN_BATCH(batch, 20);
1754 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
1755 OUT_BATCH(batch, 0);
1756 OUT_BATCH(batch, 0); /* no indirect data */
1757 OUT_BATCH(batch, 0);
1759 /* inline data grf 5-6 */
1760 assert(sizeof(*pp_inline_parameter) == 64);
1761 intel_batchbuffer_data(batch, pp_inline_parameter, sizeof(*pp_inline_parameter));
1763 ADVANCE_BATCH(batch);
1770 ironlake_pp_pipeline_setup(VADriverContextP ctx,
1771 struct i965_post_processing_context *pp_context)
1773 struct intel_batchbuffer *batch = pp_context->batch;
1775 intel_batchbuffer_start_atomic(batch, 0x1000);
1776 intel_batchbuffer_emit_mi_flush(batch);
1777 ironlake_pp_pipeline_select(ctx, pp_context);
1778 ironlake_pp_state_base_address(ctx, pp_context);
1779 ironlake_pp_state_pointers(ctx, pp_context);
1780 ironlake_pp_urb_layout(ctx, pp_context);
1781 ironlake_pp_cs_urb_layout(ctx, pp_context);
1782 ironlake_pp_constant_buffer(ctx, pp_context);
1783 ironlake_pp_object_walker(ctx, pp_context);
1784 intel_batchbuffer_end_atomic(batch);
1787 // update u/v offset when the surface format are packed yuv
1788 static void i965_update_src_surface_static_parameter(
1789 VADriverContextP ctx,
1790 struct i965_post_processing_context *pp_context,
1791 const struct i965_surface *surface)
1793 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1794 int fourcc = pp_get_surface_fourcc(ctx, surface);
1797 case VA_FOURCC('Y', 'U', 'Y', '2'):
1798 pp_static_parameter->grf1.source_packed_u_offset = 1;
1799 pp_static_parameter->grf1.source_packed_v_offset = 3;
1801 case VA_FOURCC('U', 'Y', 'V', 'Y'):
1802 pp_static_parameter->grf1.source_packed_y_offset = 1;
1803 pp_static_parameter->grf1.source_packed_v_offset = 2;
1805 case VA_FOURCC('B', 'G', 'R', 'X'):
1806 case VA_FOURCC('B', 'G', 'R', 'A'):
1807 pp_static_parameter->grf1.source_rgb_layout = 0;
1809 case VA_FOURCC('R', 'G', 'B', 'X'):
1810 case VA_FOURCC('R', 'G', 'B', 'A'):
1811 pp_static_parameter->grf1.source_rgb_layout = 1;
1819 static void i965_update_dst_surface_static_parameter(
1820 VADriverContextP ctx,
1821 struct i965_post_processing_context *pp_context,
1822 const struct i965_surface *surface)
1824 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
1825 int fourcc = pp_get_surface_fourcc(ctx, surface);
1828 case VA_FOURCC('Y', 'U', 'Y', '2'):
1829 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_u_offset = 1;
1830 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 3;
1832 case VA_FOURCC('U', 'Y', 'V', 'Y'):
1833 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_y_offset = 1;
1834 pp_static_parameter->grf1.r1_2.load_and_save.destination_packed_v_offset = 2;
1836 case VA_FOURCC('B', 'G', 'R', 'X'):
1837 case VA_FOURCC('B', 'G', 'R', 'A'):
1838 pp_static_parameter->grf1.r1_2.csc.destination_rgb_layout = 0;
1840 case VA_FOURCC('R', 'G', 'B', 'X'):
1841 case VA_FOURCC('R', 'G', 'B', 'A'):
1842 pp_static_parameter->grf1.r1_2.csc.destination_rgb_layout = 1;
1851 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1852 dri_bo *surf_bo, unsigned long surf_bo_offset,
1853 int width, int height, int pitch, int format,
1854 int index, int is_target)
1856 struct i965_surface_state *ss;
1858 unsigned int tiling;
1859 unsigned int swizzle;
1861 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1862 ss_bo = pp_context->surface_state_binding_table.bo;
1865 dri_bo_map(ss_bo, True);
1866 assert(ss_bo->virtual);
1867 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1868 memset(ss, 0, sizeof(*ss));
1869 ss->ss0.surface_type = I965_SURFACE_2D;
1870 ss->ss0.surface_format = format;
1871 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1872 ss->ss2.width = width - 1;
1873 ss->ss2.height = height - 1;
1874 ss->ss3.pitch = pitch - 1;
1875 pp_set_surface_tiling(ss, tiling);
1876 dri_bo_emit_reloc(ss_bo,
1877 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1879 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
1881 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1882 dri_bo_unmap(ss_bo);
1886 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1887 dri_bo *surf_bo, unsigned long surf_bo_offset,
1888 int width, int height, int wpitch,
1889 int xoffset, int yoffset,
1890 int format, int interleave_chroma,
1893 struct i965_surface_state2 *ss2;
1895 unsigned int tiling;
1896 unsigned int swizzle;
1898 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1899 ss2_bo = pp_context->surface_state_binding_table.bo;
1902 dri_bo_map(ss2_bo, True);
1903 assert(ss2_bo->virtual);
1904 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1905 memset(ss2, 0, sizeof(*ss2));
1906 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1907 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1908 ss2->ss1.width = width - 1;
1909 ss2->ss1.height = height - 1;
1910 ss2->ss2.pitch = wpitch - 1;
1911 ss2->ss2.interleave_chroma = interleave_chroma;
1912 ss2->ss2.surface_format = format;
1913 ss2->ss3.x_offset_for_cb = xoffset;
1914 ss2->ss3.y_offset_for_cb = yoffset;
1915 pp_set_surface2_tiling(ss2, tiling);
1916 dri_bo_emit_reloc(ss2_bo,
1917 I915_GEM_DOMAIN_RENDER, 0,
1919 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
1921 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1922 dri_bo_unmap(ss2_bo);
1926 gen7_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1927 dri_bo *surf_bo, unsigned long surf_bo_offset,
1928 int width, int height, int pitch, int format,
1929 int index, int is_target)
1931 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1932 struct gen7_surface_state *ss;
1934 unsigned int tiling;
1935 unsigned int swizzle;
1937 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1938 ss_bo = pp_context->surface_state_binding_table.bo;
1941 dri_bo_map(ss_bo, True);
1942 assert(ss_bo->virtual);
1943 ss = (struct gen7_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
1944 memset(ss, 0, sizeof(*ss));
1945 ss->ss0.surface_type = I965_SURFACE_2D;
1946 ss->ss0.surface_format = format;
1947 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
1948 ss->ss2.width = width - 1;
1949 ss->ss2.height = height - 1;
1950 ss->ss3.pitch = pitch - 1;
1951 gen7_pp_set_surface_tiling(ss, tiling);
1952 if (IS_HASWELL(i965->intel.device_id))
1953 gen7_render_set_surface_scs(ss);
1954 dri_bo_emit_reloc(ss_bo,
1955 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
1957 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state, ss1),
1959 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
1960 dri_bo_unmap(ss_bo);
1964 gen7_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1965 dri_bo *surf_bo, unsigned long surf_bo_offset,
1966 int width, int height, int wpitch,
1967 int xoffset, int yoffset,
1968 int format, int interleave_chroma,
1971 struct gen7_surface_state2 *ss2;
1973 unsigned int tiling;
1974 unsigned int swizzle;
1976 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
1977 ss2_bo = pp_context->surface_state_binding_table.bo;
1980 dri_bo_map(ss2_bo, True);
1981 assert(ss2_bo->virtual);
1982 ss2 = (struct gen7_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
1983 memset(ss2, 0, sizeof(*ss2));
1984 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
1985 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
1986 ss2->ss1.width = width - 1;
1987 ss2->ss1.height = height - 1;
1988 ss2->ss2.pitch = wpitch - 1;
1989 ss2->ss2.interleave_chroma = interleave_chroma;
1990 ss2->ss2.surface_format = format;
1991 ss2->ss3.x_offset_for_cb = xoffset;
1992 ss2->ss3.y_offset_for_cb = yoffset;
1993 gen7_pp_set_surface2_tiling(ss2, tiling);
1994 dri_bo_emit_reloc(ss2_bo,
1995 I915_GEM_DOMAIN_RENDER, 0,
1997 SURFACE_STATE_OFFSET(index) + offsetof(struct gen7_surface_state2, ss0),
1999 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
2000 dri_bo_unmap(ss2_bo);
2004 gen8_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2005 dri_bo *surf_bo, unsigned long surf_bo_offset,
2006 int width, int height, int pitch, int format,
2007 int index, int is_target)
2009 struct gen8_surface_state *ss;
2011 unsigned int tiling;
2012 unsigned int swizzle;
2014 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
2015 ss_bo = pp_context->surface_state_binding_table.bo;
2018 dri_bo_map(ss_bo, True);
2019 assert(ss_bo->virtual);
2020 ss = (struct gen8_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
2021 memset(ss, 0, sizeof(*ss));
2022 ss->ss0.surface_type = I965_SURFACE_2D;
2023 ss->ss0.surface_format = format;
2024 ss->ss8.base_addr = surf_bo->offset + surf_bo_offset;
2025 ss->ss2.width = width - 1;
2026 ss->ss2.height = height - 1;
2027 ss->ss3.pitch = pitch - 1;
2029 /* Always set 1(align 4 mode) per B-spec */
2030 ss->ss0.vertical_alignment = 1;
2031 ss->ss0.horizontal_alignment = 1;
2033 gen8_pp_set_surface_tiling(ss, tiling);
2034 gen8_render_set_surface_scs(ss);
2035 dri_bo_emit_reloc(ss_bo,
2036 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
2038 SURFACE_STATE_OFFSET(index) + offsetof(struct gen8_surface_state, ss8),
2040 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
2041 dri_bo_unmap(ss_bo);
2046 gen8_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2047 dri_bo *surf_bo, unsigned long surf_bo_offset,
2048 int width, int height, int wpitch,
2049 int xoffset, int yoffset,
2050 int format, int interleave_chroma,
2053 struct gen8_surface_state2 *ss2;
2055 unsigned int tiling;
2056 unsigned int swizzle;
2058 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
2059 ss2_bo = pp_context->surface_state_binding_table.bo;
2062 dri_bo_map(ss2_bo, True);
2063 assert(ss2_bo->virtual);
2064 ss2 = (struct gen8_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
2065 memset(ss2, 0, sizeof(*ss2));
2066 ss2->ss6.base_addr = surf_bo->offset + surf_bo_offset;
2067 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
2068 ss2->ss1.width = width - 1;
2069 ss2->ss1.height = height - 1;
2070 ss2->ss2.pitch = wpitch - 1;
2071 ss2->ss2.interleave_chroma = interleave_chroma;
2072 ss2->ss2.surface_format = format;
2073 ss2->ss3.x_offset_for_cb = xoffset;
2074 ss2->ss3.y_offset_for_cb = yoffset;
2075 gen8_pp_set_surface2_tiling(ss2, tiling);
2076 dri_bo_emit_reloc(ss2_bo,
2077 I915_GEM_DOMAIN_RENDER, 0,
2079 SURFACE_STATE_OFFSET(index) + offsetof(struct gen8_surface_state2, ss6),
2081 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
2082 dri_bo_unmap(ss2_bo);
2086 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2087 const struct i965_surface *surface,
2088 int base_index, int is_target,
2089 int *width, int *height, int *pitch, int *offset)
2091 struct object_surface *obj_surface;
2092 struct object_image *obj_image;
2094 int fourcc = pp_get_surface_fourcc(ctx, surface);
2096 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
2097 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
2099 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
2100 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
2101 int full_packed_format = (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2102 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2103 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2104 fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
2105 int scale_factor_of_1st_plane_width_in_byte = 1;
2107 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
2108 obj_surface = (struct object_surface *)surface->base;
2109 bo = obj_surface->bo;
2110 width[0] = obj_surface->orig_width;
2111 height[0] = obj_surface->orig_height;
2112 pitch[0] = obj_surface->width;
2115 if (full_packed_format) {
2116 scale_factor_of_1st_plane_width_in_byte = 4;
2118 else if (packed_yuv ) {
2119 scale_factor_of_1st_plane_width_in_byte = 2;
2121 else if (interleaved_uv) {
2122 width[1] = obj_surface->orig_width;
2123 height[1] = obj_surface->orig_height / 2;
2124 pitch[1] = obj_surface->width;
2125 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
2127 width[1] = obj_surface->orig_width / 2;
2128 height[1] = obj_surface->orig_height / 2;
2129 pitch[1] = obj_surface->width / 2;
2130 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
2131 width[2] = obj_surface->orig_width / 2;
2132 height[2] = obj_surface->orig_height / 2;
2133 pitch[2] = obj_surface->width / 2;
2134 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
2137 obj_image = (struct object_image *)surface->base;
2139 width[0] = obj_image->image.width;
2140 height[0] = obj_image->image.height;
2141 pitch[0] = obj_image->image.pitches[0];
2142 offset[0] = obj_image->image.offsets[0];
2144 if (full_packed_format) {
2145 scale_factor_of_1st_plane_width_in_byte = 4;
2147 else if (packed_yuv ) {
2148 scale_factor_of_1st_plane_width_in_byte = 2;
2150 else if (interleaved_uv) {
2151 width[1] = obj_image->image.width;
2152 height[1] = obj_image->image.height / 2;
2153 pitch[1] = obj_image->image.pitches[1];
2154 offset[1] = obj_image->image.offsets[1];
2156 width[1] = obj_image->image.width / 2;
2157 height[1] = obj_image->image.height / 2;
2158 pitch[1] = obj_image->image.pitches[1];
2159 offset[1] = obj_image->image.offsets[1];
2160 width[2] = obj_image->image.width / 2;
2161 height[2] = obj_image->image.height / 2;
2162 pitch[2] = obj_image->image.pitches[2];
2163 offset[2] = obj_image->image.offsets[2];
2168 i965_pp_set_surface_state(ctx, pp_context,
2170 width[Y] *scale_factor_of_1st_plane_width_in_byte / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
2171 base_index, is_target);
2173 if (!packed_yuv && !full_packed_format) {
2174 if (interleaved_uv) {
2175 i965_pp_set_surface_state(ctx, pp_context,
2177 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
2178 base_index + 1, is_target);
2181 i965_pp_set_surface_state(ctx, pp_context,
2183 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
2184 base_index + 1, is_target);
2187 i965_pp_set_surface_state(ctx, pp_context,
2189 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
2190 base_index + 2, is_target);
2197 gen7_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2198 const struct i965_surface *surface,
2199 int base_index, int is_target,
2200 int *width, int *height, int *pitch, int *offset)
2202 struct object_surface *obj_surface;
2203 struct object_image *obj_image;
2205 int fourcc = pp_get_surface_fourcc(ctx, surface);
2206 const int U = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
2207 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 2 : 1;
2208 const int V = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
2209 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 1 : 2;
2210 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
2211 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
2212 int rgbx_format = (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2213 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2214 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2215 fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
2217 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
2218 obj_surface = (struct object_surface *)surface->base;
2219 bo = obj_surface->bo;
2220 width[0] = obj_surface->orig_width;
2221 height[0] = obj_surface->orig_height;
2222 pitch[0] = obj_surface->width;
2227 width[0] = obj_surface->orig_width * 2; /* surface format is R8, so double the width */
2229 width[0] = obj_surface->orig_width; /* surface foramt is YCBCR, width is specified in units of pixels */
2230 } else if (rgbx_format) {
2232 width[0] = obj_surface->orig_width * 4; /* surface format is R8, so quad the width */
2235 width[1] = obj_surface->cb_cr_width;
2236 height[1] = obj_surface->cb_cr_height;
2237 pitch[1] = obj_surface->cb_cr_pitch;
2238 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
2240 width[2] = obj_surface->cb_cr_width;
2241 height[2] = obj_surface->cb_cr_height;
2242 pitch[2] = obj_surface->cb_cr_pitch;
2243 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
2245 obj_image = (struct object_image *)surface->base;
2247 width[0] = obj_image->image.width;
2248 height[0] = obj_image->image.height;
2249 pitch[0] = obj_image->image.pitches[0];
2250 offset[0] = obj_image->image.offsets[0];
2254 width[0] = obj_image->image.width * 4; /* surface format is R8, so quad the width */
2255 } else if (packed_yuv) {
2257 width[0] = obj_image->image.width * 2; /* surface format is R8, so double the width */
2259 width[0] = obj_image->image.width; /* surface foramt is YCBCR, width is specified in units of pixels */
2260 } else if (interleaved_uv) {
2261 width[1] = obj_image->image.width / 2;
2262 height[1] = obj_image->image.height / 2;
2263 pitch[1] = obj_image->image.pitches[1];
2264 offset[1] = obj_image->image.offsets[1];
2266 width[1] = obj_image->image.width / 2;
2267 height[1] = obj_image->image.height / 2;
2268 pitch[1] = obj_image->image.pitches[U];
2269 offset[1] = obj_image->image.offsets[U];
2270 width[2] = obj_image->image.width / 2;
2271 height[2] = obj_image->image.height / 2;
2272 pitch[2] = obj_image->image.pitches[V];
2273 offset[2] = obj_image->image.offsets[V];
2278 gen7_pp_set_surface_state(ctx, pp_context,
2280 width[0] / 4, height[0], pitch[0],
2281 I965_SURFACEFORMAT_R8_UINT,
2284 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2285 /* the format is MSB: X-B-G-R */
2286 pp_static_parameter->grf2.save_avs_rgb_swap = 0;
2287 if ((fourcc == VA_FOURCC('B', 'G', 'R', 'A')) ||
2288 (fourcc == VA_FOURCC('B', 'G', 'R', 'X'))) {
2289 /* It is stored as MSB: X-R-G-B */
2290 pp_static_parameter->grf2.save_avs_rgb_swap = 1;
2293 if (!packed_yuv && !rgbx_format) {
2294 if (interleaved_uv) {
2295 gen7_pp_set_surface_state(ctx, pp_context,
2297 width[1] / 2, height[1], pitch[1],
2298 I965_SURFACEFORMAT_R8G8_SINT,
2301 gen7_pp_set_surface_state(ctx, pp_context,
2303 width[1] / 4, height[1], pitch[1],
2304 I965_SURFACEFORMAT_R8_SINT,
2306 gen7_pp_set_surface_state(ctx, pp_context,
2308 width[2] / 4, height[2], pitch[2],
2309 I965_SURFACEFORMAT_R8_SINT,
2314 int format0 = SURFACE_FORMAT_Y8_UNORM;
2317 case VA_FOURCC('Y', 'U', 'Y', '2'):
2318 format0 = SURFACE_FORMAT_YCRCB_NORMAL;
2321 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2322 format0 = SURFACE_FORMAT_YCRCB_SWAPY;
2329 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2330 /* Only R8G8B8A8_UNORM is supported for BGRX or RGBX */
2331 format0 = SURFACE_FORMAT_R8G8B8A8_UNORM;
2332 pp_static_parameter->grf2.src_avs_rgb_swap = 0;
2333 if ((fourcc == VA_FOURCC('B', 'G', 'R', 'A')) ||
2334 (fourcc == VA_FOURCC('B', 'G', 'R', 'X'))) {
2335 pp_static_parameter->grf2.src_avs_rgb_swap = 1;
2338 gen7_pp_set_surface2_state(ctx, pp_context,
2340 width[0], height[0], pitch[0],
2345 if (!packed_yuv && !rgbx_format) {
2346 if (interleaved_uv) {
2347 gen7_pp_set_surface2_state(ctx, pp_context,
2349 width[1], height[1], pitch[1],
2351 SURFACE_FORMAT_R8B8_UNORM, 0,
2354 gen7_pp_set_surface2_state(ctx, pp_context,
2356 width[1], height[1], pitch[1],
2358 SURFACE_FORMAT_R8_UNORM, 0,
2360 gen7_pp_set_surface2_state(ctx, pp_context,
2362 width[2], height[2], pitch[2],
2364 SURFACE_FORMAT_R8_UNORM, 0,
2372 gen8_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2373 const struct i965_surface *surface,
2374 int base_index, int is_target,
2375 int *width, int *height, int *pitch, int *offset)
2377 struct object_surface *obj_surface;
2378 struct object_image *obj_image;
2380 int fourcc = pp_get_surface_fourcc(ctx, surface);
2381 const int U = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
2382 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 2 : 1;
2383 const int V = (fourcc == VA_FOURCC('Y', 'V', '1', '2') ||
2384 fourcc == VA_FOURCC('I', 'M', 'C', '1')) ? 1 : 2;
2385 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
2386 int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y'));
2387 int rgbx_format = (fourcc == VA_FOURCC('R', 'G', 'B', 'A') ||
2388 fourcc == VA_FOURCC('R', 'G', 'B', 'X') ||
2389 fourcc == VA_FOURCC('B', 'G', 'R', 'A') ||
2390 fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
2392 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
2393 obj_surface = (struct object_surface *)surface->base;
2394 bo = obj_surface->bo;
2395 width[0] = obj_surface->orig_width;
2396 height[0] = obj_surface->orig_height;
2397 pitch[0] = obj_surface->width;
2402 width[0] = obj_surface->orig_width * 2; /* surface format is R8, so double the width */
2404 width[0] = obj_surface->orig_width; /* surface foramt is YCBCR, width is specified in units of pixels */
2406 pitch[0] = obj_surface->width * 2;
2407 } else if (rgbx_format) {
2409 width[0] = obj_surface->orig_width * 4; /* surface format is R8, so quad the width */
2410 pitch[0] = obj_surface->width * 4;
2413 width[1] = obj_surface->cb_cr_width;
2414 height[1] = obj_surface->cb_cr_height;
2415 pitch[1] = obj_surface->cb_cr_pitch;
2416 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
2418 width[2] = obj_surface->cb_cr_width;
2419 height[2] = obj_surface->cb_cr_height;
2420 pitch[2] = obj_surface->cb_cr_pitch;
2421 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
2423 obj_image = (struct object_image *)surface->base;
2425 width[0] = obj_image->image.width;
2426 height[0] = obj_image->image.height;
2427 pitch[0] = obj_image->image.pitches[0];
2428 offset[0] = obj_image->image.offsets[0];
2432 width[0] = obj_image->image.width * 4; /* surface format is R8, so quad the width */
2433 } else if (packed_yuv) {
2435 width[0] = obj_image->image.width * 2; /* surface format is R8, so double the width */
2437 width[0] = obj_image->image.width; /* surface foramt is YCBCR, width is specified in units of pixels */
2438 } else if (interleaved_uv) {
2439 width[1] = obj_image->image.width / 2;
2440 height[1] = obj_image->image.height / 2;
2441 pitch[1] = obj_image->image.pitches[1];
2442 offset[1] = obj_image->image.offsets[1];
2444 width[1] = obj_image->image.width / 2;
2445 height[1] = obj_image->image.height / 2;
2446 pitch[1] = obj_image->image.pitches[U];
2447 offset[1] = obj_image->image.offsets[U];
2448 width[2] = obj_image->image.width / 2;
2449 height[2] = obj_image->image.height / 2;
2450 pitch[2] = obj_image->image.pitches[V];
2451 offset[2] = obj_image->image.offsets[V];
2456 gen8_pp_set_surface_state(ctx, pp_context,
2458 width[0] / 4, height[0], pitch[0],
2459 I965_SURFACEFORMAT_R8_UINT,
2462 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2463 /* the format is MSB: X-B-G-R */
2464 pp_static_parameter->grf2.save_avs_rgb_swap = 0;
2465 if ((fourcc == VA_FOURCC('B', 'G', 'R', 'A')) ||
2466 (fourcc == VA_FOURCC('B', 'G', 'R', 'X'))) {
2467 /* It is stored as MSB: X-R-G-B */
2468 pp_static_parameter->grf2.save_avs_rgb_swap = 1;
2471 if (!packed_yuv && !rgbx_format) {
2472 if (interleaved_uv) {
2473 gen8_pp_set_surface_state(ctx, pp_context,
2475 width[1] / 2, height[1], pitch[1],
2476 I965_SURFACEFORMAT_R8G8_SINT,
2479 gen8_pp_set_surface_state(ctx, pp_context,
2481 width[1] / 4, height[1], pitch[1],
2482 I965_SURFACEFORMAT_R8_SINT,
2484 gen8_pp_set_surface_state(ctx, pp_context,
2486 width[2] / 4, height[2], pitch[2],
2487 I965_SURFACEFORMAT_R8_SINT,
2492 int format0 = SURFACE_FORMAT_Y8_UNORM;
2495 case VA_FOURCC('Y', 'U', 'Y', '2'):
2496 format0 = SURFACE_FORMAT_YCRCB_NORMAL;
2499 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2500 format0 = SURFACE_FORMAT_YCRCB_SWAPY;
2507 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2508 /* Only R8G8B8A8_UNORM is supported for BGRX or RGBX */
2509 format0 = SURFACE_FORMAT_R8G8B8A8_UNORM;
2510 pp_static_parameter->grf2.src_avs_rgb_swap = 0;
2511 if ((fourcc == VA_FOURCC('B', 'G', 'R', 'A')) ||
2512 (fourcc == VA_FOURCC('B', 'G', 'R', 'X'))) {
2513 pp_static_parameter->grf2.src_avs_rgb_swap = 1;
2516 gen8_pp_set_surface2_state(ctx, pp_context,
2518 width[0], height[0], pitch[0],
2523 if (!packed_yuv && !rgbx_format) {
2524 if (interleaved_uv) {
2525 gen8_pp_set_surface2_state(ctx, pp_context,
2527 width[1], height[1], pitch[1],
2529 SURFACE_FORMAT_R8B8_UNORM, 0,
2532 gen8_pp_set_surface2_state(ctx, pp_context,
2534 width[1], height[1], pitch[1],
2536 SURFACE_FORMAT_R8_UNORM, 0,
2538 gen8_pp_set_surface2_state(ctx, pp_context,
2540 width[2], height[2], pitch[2],
2542 SURFACE_FORMAT_R8_UNORM, 0,
2550 pp_null_x_steps(void *private_context)
2556 pp_null_y_steps(void *private_context)
2562 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2568 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2569 const struct i965_surface *src_surface,
2570 const VARectangle *src_rect,
2571 struct i965_surface *dst_surface,
2572 const VARectangle *dst_rect,
2575 /* private function & data */
2576 pp_context->pp_x_steps = pp_null_x_steps;
2577 pp_context->pp_y_steps = pp_null_y_steps;
2578 pp_context->private_context = NULL;
2579 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
2581 dst_surface->flags = src_surface->flags;
2583 return VA_STATUS_SUCCESS;
2587 pp_load_save_x_steps(void *private_context)
2593 pp_load_save_y_steps(void *private_context)
2595 struct pp_load_save_context *pp_load_save_context = private_context;
2597 return pp_load_save_context->dest_h / 8;
2601 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2603 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2604 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)pp_context->private_context;
2606 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_load_save_context->dest_x;
2607 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_load_save_context->dest_y;
2612 static void calculate_boundary_block_mask(struct i965_post_processing_context *pp_context, const VARectangle *dst_rect)
2615 /* x offset of dest surface must be dword aligned.
2616 * so we have to extend dst surface on left edge, and mask out pixels not interested
2618 if (dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT) {
2619 pp_context->block_horizontal_mask_left = 0;
2620 for (i=dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT; i<GPU_ASM_BLOCK_WIDTH; i++)
2622 pp_context->block_horizontal_mask_left |= 1<<i;
2626 pp_context->block_horizontal_mask_left = 0xffff;
2629 int dst_width_adjust = dst_rect->width + dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;
2630 if (dst_width_adjust%GPU_ASM_BLOCK_WIDTH){
2631 pp_context->block_horizontal_mask_right = (1 << (dst_width_adjust%GPU_ASM_BLOCK_WIDTH)) - 1;
2634 pp_context->block_horizontal_mask_right = 0xffff;
2637 if (dst_rect->height%GPU_ASM_BLOCK_HEIGHT){
2638 pp_context->block_vertical_mask_bottom = (1 << (dst_rect->height%GPU_ASM_BLOCK_HEIGHT)) - 1;
2641 pp_context->block_vertical_mask_bottom = 0xff;
2646 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2647 const struct i965_surface *src_surface,
2648 const VARectangle *src_rect,
2649 struct i965_surface *dst_surface,
2650 const VARectangle *dst_rect,
2653 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->pp_load_save_context;
2654 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2655 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2656 int width[3], height[3], pitch[3], offset[3];
2658 /* source surface */
2659 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
2660 width, height, pitch, offset);
2662 /* destination surface */
2663 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
2664 width, height, pitch, offset);
2666 /* private function & data */
2667 pp_context->pp_x_steps = pp_load_save_x_steps;
2668 pp_context->pp_y_steps = pp_load_save_y_steps;
2669 pp_context->private_context = &pp_context->pp_load_save_context;
2670 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
2672 int dst_left_edge_extend = dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;;
2673 pp_load_save_context->dest_x = dst_rect->x - dst_left_edge_extend;
2674 pp_load_save_context->dest_y = dst_rect->y;
2675 pp_load_save_context->dest_h = ALIGN(dst_rect->height, 8);
2676 pp_load_save_context->dest_w = ALIGN(dst_rect->width+dst_left_edge_extend, 16);
2678 pp_inline_parameter->grf5.block_count_x = pp_load_save_context->dest_w / 16; /* 1 x N */
2679 pp_inline_parameter->grf5.number_blocks = pp_load_save_context->dest_w / 16;
2681 pp_static_parameter->grf3.horizontal_origin_offset = src_rect->x;
2682 pp_static_parameter->grf3.vertical_origin_offset = src_rect->y;
2684 // update u/v offset for packed yuv
2685 i965_update_src_surface_static_parameter (ctx, pp_context, src_surface);
2686 i965_update_dst_surface_static_parameter (ctx, pp_context, dst_surface);
2688 dst_surface->flags = src_surface->flags;
2690 return VA_STATUS_SUCCESS;
2694 pp_scaling_x_steps(void *private_context)
2700 pp_scaling_y_steps(void *private_context)
2702 struct pp_scaling_context *pp_scaling_context = private_context;
2704 return pp_scaling_context->dest_h / 8;
2708 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2710 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)pp_context->private_context;
2711 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2712 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2713 float src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2714 float src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
2716 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
2717 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
2718 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
2719 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
2725 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2726 const struct i965_surface *src_surface,
2727 const VARectangle *src_rect,
2728 struct i965_surface *dst_surface,
2729 const VARectangle *dst_rect,
2732 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->pp_scaling_context;
2733 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2734 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2735 struct object_surface *obj_surface;
2736 struct i965_sampler_state *sampler_state;
2737 int in_w, in_h, in_wpitch, in_hpitch;
2738 int out_w, out_h, out_wpitch, out_hpitch;
2740 /* source surface */
2741 obj_surface = (struct object_surface *)src_surface->base;
2742 in_w = obj_surface->orig_width;
2743 in_h = obj_surface->orig_height;
2744 in_wpitch = obj_surface->width;
2745 in_hpitch = obj_surface->height;
2747 /* source Y surface index 1 */
2748 i965_pp_set_surface_state(ctx, pp_context,
2750 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
2753 /* source UV surface index 2 */
2754 i965_pp_set_surface_state(ctx, pp_context,
2755 obj_surface->bo, in_wpitch * in_hpitch,
2756 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
2759 /* destination surface */
2760 obj_surface = (struct object_surface *)dst_surface->base;
2761 out_w = obj_surface->orig_width;
2762 out_h = obj_surface->orig_height;
2763 out_wpitch = obj_surface->width;
2764 out_hpitch = obj_surface->height;
2766 /* destination Y surface index 7 */
2767 i965_pp_set_surface_state(ctx, pp_context,
2769 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
2772 /* destination UV surface index 8 */
2773 i965_pp_set_surface_state(ctx, pp_context,
2774 obj_surface->bo, out_wpitch * out_hpitch,
2775 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
2779 dri_bo_map(pp_context->sampler_state_table.bo, True);
2780 assert(pp_context->sampler_state_table.bo->virtual);
2781 sampler_state = pp_context->sampler_state_table.bo->virtual;
2783 /* SIMD16 Y index 1 */
2784 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
2785 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
2786 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2787 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2788 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2790 /* SIMD16 UV index 2 */
2791 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
2792 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
2793 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2794 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2795 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
2797 dri_bo_unmap(pp_context->sampler_state_table.bo);
2799 /* private function & data */
2800 pp_context->pp_x_steps = pp_scaling_x_steps;
2801 pp_context->pp_y_steps = pp_scaling_y_steps;
2802 pp_context->private_context = &pp_context->pp_scaling_context;
2803 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
2805 int dst_left_edge_extend = dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;
2806 float src_left_edge_extend = (float)dst_left_edge_extend*src_rect->width/dst_rect->width;
2807 pp_scaling_context->dest_x = dst_rect->x - dst_left_edge_extend;
2808 pp_scaling_context->dest_y = dst_rect->y;
2809 pp_scaling_context->dest_w = ALIGN(dst_rect->width + dst_left_edge_extend, 16);
2810 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 8);
2811 pp_scaling_context->src_normalized_x = (float)(src_rect->x - src_left_edge_extend)/ in_w;
2812 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h;
2814 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
2816 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);
2817 pp_inline_parameter->grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
2818 pp_inline_parameter->grf5.number_blocks = pp_scaling_context->dest_w / 16;
2820 dst_surface->flags = src_surface->flags;
2822 return VA_STATUS_SUCCESS;
2826 pp_avs_x_steps(void *private_context)
2828 struct pp_avs_context *pp_avs_context = private_context;
2830 return pp_avs_context->dest_w / 16;
2834 pp_avs_y_steps(void *private_context)
2840 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
2842 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)pp_context->private_context;
2843 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2844 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2845 float src_x_steping, src_y_steping, video_step_delta;
2846 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
2848 if (pp_static_parameter->grf4.r4_2.avs.nlas == 0) {
2849 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2850 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_avs_context->src_normalized_x;
2851 } else if (tmp_w >= pp_avs_context->dest_w) {
2852 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
2853 pp_inline_parameter->grf6.video_step_delta = 0;
2856 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
2857 pp_avs_context->src_normalized_x;
2859 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2860 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2861 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2862 16 * 15 * video_step_delta / 2;
2865 int n0, n1, n2, nls_left, nls_right;
2866 int factor_a = 5, factor_b = 4;
2869 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
2870 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
2871 n2 = tmp_w / (16 * factor_a);
2873 nls_right = n1 + n2;
2874 f = (float) n2 * 16 / tmp_w;
2877 pp_inline_parameter->grf6.video_step_delta = 0.0;
2880 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
2881 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
2883 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2884 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2885 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2886 16 * 15 * video_step_delta / 2;
2890 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
2891 float a = f / (nls_left * 16 * factor_b);
2892 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
2894 pp_inline_parameter->grf6.video_step_delta = b;
2897 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
2898 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a;
2900 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2901 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2902 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2903 16 * 15 * video_step_delta / 2;
2904 pp_inline_parameter->grf5.normalized_video_x_scaling_step += 16 * b;
2906 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
2907 /* scale the center linearly */
2908 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2909 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2910 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2911 16 * 15 * video_step_delta / 2;
2912 pp_inline_parameter->grf6.video_step_delta = 0.0;
2913 pp_inline_parameter->grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
2915 float a = f / (nls_right * 16 * factor_b);
2916 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
2918 src_x_steping = pp_inline_parameter->grf5.normalized_video_x_scaling_step;
2919 video_step_delta = pp_inline_parameter->grf6.video_step_delta;
2920 pp_inline_parameter->grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
2921 16 * 15 * video_step_delta / 2;
2922 pp_inline_parameter->grf6.video_step_delta = -b;
2924 if (x == (pp_avs_context->dest_w / 16 - nls_right))
2925 pp_inline_parameter->grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
2927 pp_inline_parameter->grf5.normalized_video_x_scaling_step -= b * 16;
2932 src_y_steping = pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step;
2933 pp_inline_parameter->grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
2934 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
2935 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
2941 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
2942 const struct i965_surface *src_surface,
2943 const VARectangle *src_rect,
2944 struct i965_surface *dst_surface,
2945 const VARectangle *dst_rect,
2949 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->pp_avs_context;
2950 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
2951 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
2952 struct object_surface *obj_surface;
2953 struct i965_sampler_8x8 *sampler_8x8;
2954 struct i965_sampler_8x8_state *sampler_8x8_state;
2956 int in_w, in_h, in_wpitch, in_hpitch;
2957 int out_w, out_h, out_wpitch, out_hpitch;
2961 obj_surface = (struct object_surface *)src_surface->base;
2962 in_w = obj_surface->orig_width;
2963 in_h = obj_surface->orig_height;
2964 in_wpitch = obj_surface->width;
2965 in_hpitch = obj_surface->height;
2967 /* source Y surface index 1 */
2968 i965_pp_set_surface2_state(ctx, pp_context,
2970 in_w, in_h, in_wpitch,
2972 SURFACE_FORMAT_Y8_UNORM, 0,
2975 /* source UV surface index 2 */
2976 i965_pp_set_surface2_state(ctx, pp_context,
2977 obj_surface->bo, in_wpitch * in_hpitch,
2978 in_w / 2, in_h / 2, in_wpitch,
2980 SURFACE_FORMAT_R8B8_UNORM, 0,
2983 /* destination surface */
2984 obj_surface = (struct object_surface *)dst_surface->base;
2985 out_w = obj_surface->orig_width;
2986 out_h = obj_surface->orig_height;
2987 out_wpitch = obj_surface->width;
2988 out_hpitch = obj_surface->height;
2989 assert(out_w <= out_wpitch && out_h <= out_hpitch);
2991 /* destination Y surface index 7 */
2992 i965_pp_set_surface_state(ctx, pp_context,
2994 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
2997 /* destination UV surface index 8 */
2998 i965_pp_set_surface_state(ctx, pp_context,
2999 obj_surface->bo, out_wpitch * out_hpitch,
3000 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
3003 /* sampler 8x8 state */
3004 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
3005 assert(pp_context->sampler_state_table.bo_8x8->virtual);
3006 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
3007 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
3008 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
3010 for (i = 0; i < 17; i++) {
3011 /* for Y channel, currently ignore */
3012 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x00;
3013 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x00;
3014 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x08;
3015 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = 0x18;
3016 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = 0x18;
3017 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x08;
3018 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x00;
3019 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x00;
3020 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x00;
3021 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x00;
3022 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x10;
3023 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = 0x10;
3024 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = 0x10;
3025 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x10;
3026 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x00;
3027 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x00;
3028 /* for U/V channel, 0.25 */
3029 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
3030 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
3031 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x10;
3032 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = 0x10;
3033 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = 0x10;
3034 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x10;
3035 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
3036 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
3037 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
3038 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
3039 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x10;
3040 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = 0x10;
3041 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = 0x10;
3042 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x10;
3043 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
3044 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
3047 sampler_8x8_state->dw136.default_sharpness_level = 0;
3048 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
3049 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
3050 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
3051 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
3054 dri_bo_map(pp_context->sampler_state_table.bo, True);
3055 assert(pp_context->sampler_state_table.bo->virtual);
3056 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
3057 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
3059 /* sample_8x8 Y index 1 */
3061 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3062 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
3063 sampler_8x8[index].dw0.ief_bypass = 1;
3064 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
3065 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
3066 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3067 sampler_8x8[index].dw2.global_noise_estimation = 22;
3068 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3069 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3070 sampler_8x8[index].dw3.strong_edge_weight = 7;
3071 sampler_8x8[index].dw3.regular_weight = 2;
3072 sampler_8x8[index].dw3.non_edge_weight = 0;
3073 sampler_8x8[index].dw3.gain_factor = 40;
3074 sampler_8x8[index].dw4.steepness_boost = 0;
3075 sampler_8x8[index].dw4.steepness_threshold = 0;
3076 sampler_8x8[index].dw4.mr_boost = 0;
3077 sampler_8x8[index].dw4.mr_threshold = 5;
3078 sampler_8x8[index].dw5.pwl1_point_1 = 4;
3079 sampler_8x8[index].dw5.pwl1_point_2 = 12;
3080 sampler_8x8[index].dw5.pwl1_point_3 = 16;
3081 sampler_8x8[index].dw5.pwl1_point_4 = 26;
3082 sampler_8x8[index].dw6.pwl1_point_5 = 40;
3083 sampler_8x8[index].dw6.pwl1_point_6 = 160;
3084 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
3085 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
3086 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
3087 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
3088 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
3089 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
3090 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
3091 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
3092 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
3093 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
3094 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
3095 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
3096 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
3097 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
3098 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
3099 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
3100 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
3101 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
3102 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
3103 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
3104 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
3105 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
3106 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
3107 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
3108 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
3109 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
3110 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
3111 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
3112 sampler_8x8[index].dw13.limiter_boost = 0;
3113 sampler_8x8[index].dw13.minimum_limiter = 10;
3114 sampler_8x8[index].dw13.maximum_limiter = 11;
3115 sampler_8x8[index].dw14.clip_limiter = 130;
3116 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3117 I915_GEM_DOMAIN_RENDER,
3120 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3121 pp_context->sampler_state_table.bo_8x8);
3123 /* sample_8x8 UV index 2 */
3125 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3126 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
3127 sampler_8x8[index].dw0.ief_bypass = 1;
3128 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
3129 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
3130 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3131 sampler_8x8[index].dw2.global_noise_estimation = 22;
3132 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3133 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3134 sampler_8x8[index].dw3.strong_edge_weight = 7;
3135 sampler_8x8[index].dw3.regular_weight = 2;
3136 sampler_8x8[index].dw3.non_edge_weight = 0;
3137 sampler_8x8[index].dw3.gain_factor = 40;
3138 sampler_8x8[index].dw4.steepness_boost = 0;
3139 sampler_8x8[index].dw4.steepness_threshold = 0;
3140 sampler_8x8[index].dw4.mr_boost = 0;
3141 sampler_8x8[index].dw4.mr_threshold = 5;
3142 sampler_8x8[index].dw5.pwl1_point_1 = 4;
3143 sampler_8x8[index].dw5.pwl1_point_2 = 12;
3144 sampler_8x8[index].dw5.pwl1_point_3 = 16;
3145 sampler_8x8[index].dw5.pwl1_point_4 = 26;
3146 sampler_8x8[index].dw6.pwl1_point_5 = 40;
3147 sampler_8x8[index].dw6.pwl1_point_6 = 160;
3148 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
3149 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
3150 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
3151 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
3152 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
3153 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
3154 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
3155 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
3156 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
3157 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
3158 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
3159 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
3160 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
3161 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
3162 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
3163 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
3164 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
3165 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
3166 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
3167 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
3168 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
3169 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
3170 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
3171 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
3172 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
3173 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
3174 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
3175 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
3176 sampler_8x8[index].dw13.limiter_boost = 0;
3177 sampler_8x8[index].dw13.minimum_limiter = 10;
3178 sampler_8x8[index].dw13.maximum_limiter = 11;
3179 sampler_8x8[index].dw14.clip_limiter = 130;
3180 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3181 I915_GEM_DOMAIN_RENDER,
3184 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3185 pp_context->sampler_state_table.bo_8x8);
3187 dri_bo_unmap(pp_context->sampler_state_table.bo);
3189 /* private function & data */
3190 pp_context->pp_x_steps = pp_avs_x_steps;
3191 pp_context->pp_y_steps = pp_avs_y_steps;
3192 pp_context->private_context = &pp_context->pp_avs_context;
3193 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
3195 int dst_left_edge_extend = dst_rect->x%GPU_ASM_X_OFFSET_ALIGNMENT;
3196 float src_left_edge_extend = (float)dst_left_edge_extend*src_rect->width/dst_rect->width;
3197 pp_avs_context->dest_x = dst_rect->x - dst_left_edge_extend;
3198 pp_avs_context->dest_y = dst_rect->y;
3199 pp_avs_context->dest_w = ALIGN(dst_rect->width + dst_left_edge_extend, 16);
3200 pp_avs_context->dest_h = ALIGN(dst_rect->height, 8);
3201 pp_avs_context->src_normalized_x = (float)(src_rect->x - src_left_edge_extend)/ in_w;
3202 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h;
3203 pp_avs_context->src_w = src_rect->width + src_left_edge_extend;
3204 pp_avs_context->src_h = src_rect->height;
3206 pp_static_parameter->grf4.r4_2.avs.nlas = nlas;
3207 pp_static_parameter->grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / dst_rect->height;
3209 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);
3210 pp_inline_parameter->grf5.block_count_x = 1; /* M x 1 */
3211 pp_inline_parameter->grf5.number_blocks = pp_avs_context->dest_h / 8;
3212 pp_inline_parameter->grf6.video_step_delta = 0.0;
3214 dst_surface->flags = src_surface->flags;
3216 return VA_STATUS_SUCCESS;
3220 pp_nv12_avs_initialize_nlas(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3221 const struct i965_surface *src_surface,
3222 const VARectangle *src_rect,
3223 struct i965_surface *dst_surface,
3224 const VARectangle *dst_rect,
3227 return pp_nv12_avs_initialize(ctx, pp_context,
3237 gen6_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3238 const struct i965_surface *src_surface,
3239 const VARectangle *src_rect,
3240 struct i965_surface *dst_surface,
3241 const VARectangle *dst_rect,
3244 return pp_nv12_avs_initialize(ctx, pp_context,
3254 gen7_pp_avs_x_steps(void *private_context)
3256 struct pp_avs_context *pp_avs_context = private_context;
3258 return pp_avs_context->dest_w / 16;
3262 gen7_pp_avs_y_steps(void *private_context)
3264 struct pp_avs_context *pp_avs_context = private_context;
3266 return pp_avs_context->dest_h / 16;
3270 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3272 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)pp_context->private_context;
3273 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3275 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
3276 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
3277 pp_inline_parameter->grf7.constant_0 = 0xffffffff;
3278 pp_inline_parameter->grf7.sampler_load_main_video_x_scaling_step = pp_avs_context->horiz_range / pp_avs_context->src_w;
3283 static void gen7_update_src_surface_uv_offset(VADriverContextP ctx,
3284 struct i965_post_processing_context *pp_context,
3285 const struct i965_surface *surface)
3287 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3288 int fourcc = pp_get_surface_fourcc(ctx, surface);
3290 if (fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
3291 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
3292 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
3293 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
3294 } else if (fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')) {
3295 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 1;
3296 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 0;
3297 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 2;
3302 gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3303 const struct i965_surface *src_surface,
3304 const VARectangle *src_rect,
3305 struct i965_surface *dst_surface,
3306 const VARectangle *dst_rect,
3309 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->pp_avs_context;
3310 struct i965_driver_data *i965 = i965_driver_data(ctx);
3311 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3312 struct gen7_sampler_8x8 *sampler_8x8;
3313 struct i965_sampler_8x8_state *sampler_8x8_state;
3315 int width[3], height[3], pitch[3], offset[3];
3316 int src_width, src_height;
3318 /* source surface */
3319 gen7_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
3320 width, height, pitch, offset);
3321 src_width = width[0];
3322 src_height = height[0];
3324 /* destination surface */
3325 gen7_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
3326 width, height, pitch, offset);
3328 /* sampler 8x8 state */
3329 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
3330 assert(pp_context->sampler_state_table.bo_8x8->virtual);
3331 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
3332 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
3333 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
3335 for (i = 0; i < 17; i++) {
3339 /* for Y channel, currently ignore */
3340 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
3341 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
3342 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
3343 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = intel_format_convert(1 - coff, 1, 6,0);
3344 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3345 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
3346 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
3347 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
3348 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
3349 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
3350 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
3351 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3352 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3353 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
3354 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
3355 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
3356 /* for U/V channel, 0.25 */
3357 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
3358 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
3359 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x0;
3360 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3361 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3362 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0;
3363 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
3364 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
3365 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
3366 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
3367 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x0;
3368 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3369 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3370 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x0;
3371 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
3372 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
3375 sampler_8x8_state->dw136.default_sharpness_level = 0;
3376 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
3377 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
3378 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
3379 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
3382 dri_bo_map(pp_context->sampler_state_table.bo, True);
3383 assert(pp_context->sampler_state_table.bo->virtual);
3384 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
3385 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
3387 /* sample_8x8 Y index 4 */
3389 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3390 sampler_8x8[index].dw0.global_noise_estimation = 255;
3391 sampler_8x8[index].dw0.ief_bypass = 1;
3393 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3395 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3396 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3397 sampler_8x8[index].dw2.r5x_coefficient = 9;
3398 sampler_8x8[index].dw2.r5cx_coefficient = 8;
3399 sampler_8x8[index].dw2.r5c_coefficient = 3;
3401 sampler_8x8[index].dw3.r3x_coefficient = 27;
3402 sampler_8x8[index].dw3.r3c_coefficient = 5;
3403 sampler_8x8[index].dw3.gain_factor = 40;
3404 sampler_8x8[index].dw3.non_edge_weight = 1;
3405 sampler_8x8[index].dw3.regular_weight = 2;
3406 sampler_8x8[index].dw3.strong_edge_weight = 7;
3407 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
3409 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3410 I915_GEM_DOMAIN_RENDER,
3413 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3414 pp_context->sampler_state_table.bo_8x8);
3416 /* sample_8x8 UV index 8 */
3418 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3419 sampler_8x8[index].dw0.disable_8x8_filter = 0;
3420 sampler_8x8[index].dw0.global_noise_estimation = 255;
3421 sampler_8x8[index].dw0.ief_bypass = 1;
3422 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3423 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3424 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3425 sampler_8x8[index].dw2.r5x_coefficient = 9;
3426 sampler_8x8[index].dw2.r5cx_coefficient = 8;
3427 sampler_8x8[index].dw2.r5c_coefficient = 3;
3428 sampler_8x8[index].dw3.r3x_coefficient = 27;
3429 sampler_8x8[index].dw3.r3c_coefficient = 5;
3430 sampler_8x8[index].dw3.gain_factor = 40;
3431 sampler_8x8[index].dw3.non_edge_weight = 1;
3432 sampler_8x8[index].dw3.regular_weight = 2;
3433 sampler_8x8[index].dw3.strong_edge_weight = 7;
3434 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
3436 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3437 I915_GEM_DOMAIN_RENDER,
3440 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3441 pp_context->sampler_state_table.bo_8x8);
3443 /* sampler_8x8 V, index 12 */
3445 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3446 sampler_8x8[index].dw0.disable_8x8_filter = 0;
3447 sampler_8x8[index].dw0.global_noise_estimation = 255;
3448 sampler_8x8[index].dw0.ief_bypass = 1;
3449 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3450 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3451 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3452 sampler_8x8[index].dw2.r5x_coefficient = 9;
3453 sampler_8x8[index].dw2.r5cx_coefficient = 8;
3454 sampler_8x8[index].dw2.r5c_coefficient = 3;
3455 sampler_8x8[index].dw3.r3x_coefficient = 27;
3456 sampler_8x8[index].dw3.r3c_coefficient = 5;
3457 sampler_8x8[index].dw3.gain_factor = 40;
3458 sampler_8x8[index].dw3.non_edge_weight = 1;
3459 sampler_8x8[index].dw3.regular_weight = 2;
3460 sampler_8x8[index].dw3.strong_edge_weight = 7;
3461 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
3463 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3464 I915_GEM_DOMAIN_RENDER,
3467 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3468 pp_context->sampler_state_table.bo_8x8);
3470 dri_bo_unmap(pp_context->sampler_state_table.bo);
3472 /* private function & data */
3473 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
3474 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
3475 pp_context->private_context = &pp_context->pp_avs_context;
3476 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
3478 pp_avs_context->dest_x = dst_rect->x;
3479 pp_avs_context->dest_y = dst_rect->y;
3480 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
3481 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
3482 pp_avs_context->src_w = src_rect->width;
3483 pp_avs_context->src_h = src_rect->height;
3484 pp_avs_context->horiz_range = (float)src_rect->width / src_width;
3486 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
3487 dw = MAX(dw, dst_rect->width);
3489 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3490 pp_static_parameter->grf2.avs_wa_enable = 1; /* must be set for GEN7 */
3491 if (IS_HASWELL(i965->intel.device_id))
3492 pp_static_parameter->grf2.avs_wa_enable = 0; /* HSW don't use the WA */
3494 pp_static_parameter->grf2.avs_wa_width = dw;
3495 pp_static_parameter->grf2.avs_wa_one_div_256_width = (float) 1.0 / (256 * dw);
3496 pp_static_parameter->grf2.avs_wa_five_div_256_width = (float) 5.0 / (256 * dw);
3498 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
3499 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) src_rect->height / src_height / dst_rect->height;
3500 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = (float) src_rect->y / src_height -
3501 (float) pp_avs_context->dest_y * pp_static_parameter->grf4.sampler_load_vertical_scaling_step;
3502 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = (float) src_rect->x / src_width -
3503 (float) pp_avs_context->dest_x * pp_avs_context->horiz_range / dw;
3505 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
3507 dst_surface->flags = src_surface->flags;
3509 return VA_STATUS_SUCCESS;
3513 gen8_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3514 const struct i965_surface *src_surface,
3515 const VARectangle *src_rect,
3516 struct i965_surface *dst_surface,
3517 const VARectangle *dst_rect,
3520 /* TODO: Add the sampler_8x8 state */
3521 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
3522 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3523 struct gen8_sampler_8x8_avs *sampler_8x8;
3524 struct i965_sampler_8x8_coefficient *sampler_8x8_state;
3526 int width[3], height[3], pitch[3], offset[3];
3527 int src_width, src_height;
3529 memset(pp_static_parameter, 0, sizeof(struct gen7_pp_static_parameter));
3531 /* source surface */
3532 gen8_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
3533 width, height, pitch, offset);
3534 src_height = height[0];
3535 src_width = width[0];
3537 /* destination surface */
3538 gen8_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
3539 width, height, pitch, offset);
3541 /* sampler 8x8 state */
3542 dri_bo_map(pp_context->sampler_state_table.bo, True);
3543 assert(pp_context->sampler_state_table.bo->virtual);
3545 /* Currently only one gen8 sampler_8x8 is initialized */
3546 sampler_8x8 = (struct gen8_sampler_8x8_avs *)
3547 pp_context->sampler_state_table.bo->virtual;
3548 memset(sampler_8x8, 0, sizeof(*sampler_8x8));
3550 sampler_8x8->dw0.gain_factor = 44;
3551 sampler_8x8->dw0.weak_edge_threshold = 1;
3552 sampler_8x8->dw0.strong_edge_threshold = 8;
3553 /* Use the value like that on Ivy instead of default
3554 * sampler_8x8->dw0.r3x_coefficient = 5;
3556 sampler_8x8->dw0.r3x_coefficient = 27;
3557 sampler_8x8->dw0.r3c_coefficient = 5;
3559 sampler_8x8->dw2.global_noise_estimation = 255;
3560 sampler_8x8->dw2.non_edge_weight = 1;
3561 sampler_8x8->dw2.regular_weight = 2;
3562 sampler_8x8->dw2.strong_edge_weight = 7;
3563 /* Use the value like that on Ivy instead of default
3564 * sampler_8x8->dw2.r5x_coefficient = 7;
3565 * sampler_8x8->dw2.r5cx_coefficient = 7;
3566 * sampler_8x8->dw2.r5c_coefficient = 7;
3568 sampler_8x8->dw2.r5x_coefficient = 9;
3569 sampler_8x8->dw2.r5cx_coefficient = 8;
3570 sampler_8x8->dw2.r5c_coefficient = 3;
3572 sampler_8x8->dw3.sin_alpha = 101; /* sin_alpha = 0 */
3573 sampler_8x8->dw3.cos_alpha = 79; /* cos_alpha = 0 */
3574 sampler_8x8->dw3.sat_max = 0x1f;
3575 sampler_8x8->dw3.hue_max = 14;
3576 /* The 8tap filter will determine whether the adaptive Filter is
3577 * applied for all channels(dw153).
3578 * If the 8tap filter is disabled, the adaptive filter should be disabled.
3579 * Only when 8tap filter is enabled, it can be enabled or not
3581 sampler_8x8->dw3.enable_8tap_filter = 3;
3582 sampler_8x8->dw3.ief4_smooth_enable = 0;
3584 sampler_8x8->dw4.s3u = 0;
3585 sampler_8x8->dw4.diamond_margin = 4;
3586 sampler_8x8->dw4.vy_std_enable = 0;
3587 sampler_8x8->dw4.umid = 110;
3588 sampler_8x8->dw4.vmid = 154;
3590 sampler_8x8->dw5.diamond_dv = 0;
3591 sampler_8x8->dw5.diamond_th = 35;
3592 sampler_8x8->dw5.diamond_alpha = 100; /* diamond_alpha = 0 */
3593 sampler_8x8->dw5.hs_margin = 3;
3594 sampler_8x8->dw5.diamond_du = 2;
3596 sampler_8x8->dw6.y_point1 = 46;
3597 sampler_8x8->dw6.y_point2 = 47;
3598 sampler_8x8->dw6.y_point3 = 254;
3599 sampler_8x8->dw6.y_point4 = 255;
3601 sampler_8x8->dw7.inv_margin_vyl = 3300; /* inv_margin_vyl = 0 */
3603 sampler_8x8->dw8.inv_margin_vyu = 1600; /* inv_margin_vyu = 0 */
3604 sampler_8x8->dw8.p0l = 46;
3605 sampler_8x8->dw8.p1l = 216;
3607 sampler_8x8->dw9.p2l = 236;
3608 sampler_8x8->dw9.p3l = 236;
3609 sampler_8x8->dw9.b0l = 133;
3610 sampler_8x8->dw9.b1l = 130;
3612 sampler_8x8->dw10.b2l = 130;
3613 sampler_8x8->dw10.b3l = 130;
3614 /* s0l = -5 / 256. s2.8 */
3615 sampler_8x8->dw10.s0l = 1029; /* s0l = 0 */
3616 sampler_8x8->dw10.y_slope2 = 31; /* y_slop2 = 0 */
3618 sampler_8x8->dw11.s1l = 0;
3619 sampler_8x8->dw11.s2l = 0;
3621 sampler_8x8->dw12.s3l = 0;
3622 sampler_8x8->dw12.p0u = 46;
3623 sampler_8x8->dw12.p1u = 66;
3624 sampler_8x8->dw12.y_slope1 = 31; /* y_slope1 = 0 */
3626 sampler_8x8->dw13.p2u = 130;
3627 sampler_8x8->dw13.p3u = 236;
3628 sampler_8x8->dw13.b0u = 143;
3629 sampler_8x8->dw13.b1u = 163;
3631 sampler_8x8->dw14.b2u = 200;
3632 sampler_8x8->dw14.b3u = 140;
3633 sampler_8x8->dw14.s0u = 256; /* s0u = 0 */
3635 sampler_8x8->dw15.s1u = 113; /* s1u = 0 */
3636 sampler_8x8->dw15.s2u = 1203; /* s2u = 0 */
3638 sampler_8x8_state = sampler_8x8->coefficients;
3640 for (i = 0; i < 17; i++) {
3645 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
3646 /* for Y channel, currently ignore */
3647 sampler_8x8_state->dw0.table_0x_filter_c0 = 0x0;
3648 sampler_8x8_state->dw0.table_0x_filter_c1 = 0x0;
3649 sampler_8x8_state->dw0.table_0x_filter_c2 = 0x0;
3650 sampler_8x8_state->dw0.table_0x_filter_c3 =
3651 intel_format_convert(1 - coff, 1, 6, 0);
3652 sampler_8x8_state->dw1.table_0x_filter_c4 =
3653 intel_format_convert(coff, 1, 6, 0);
3654 sampler_8x8_state->dw1.table_0x_filter_c5 = 0x0;
3655 sampler_8x8_state->dw1.table_0x_filter_c6 = 0x0;
3656 sampler_8x8_state->dw1.table_0x_filter_c7 = 0x0;
3657 sampler_8x8_state->dw2.table_0y_filter_c0 = 0x0;
3658 sampler_8x8_state->dw2.table_0y_filter_c1 = 0x0;
3659 sampler_8x8_state->dw2.table_0y_filter_c2 = 0x0;
3660 sampler_8x8_state->dw2.table_0y_filter_c3 =
3661 intel_format_convert(1 - coff, 1, 6, 0);
3662 sampler_8x8_state->dw3.table_0y_filter_c4 =
3663 intel_format_convert(coff, 1, 6, 0);
3664 sampler_8x8_state->dw3.table_0y_filter_c5 = 0x0;
3665 sampler_8x8_state->dw3.table_0y_filter_c6 = 0x0;
3666 sampler_8x8_state->dw3.table_0y_filter_c7 = 0x0;
3667 /* for U/V channel, 0.25 */
3668 sampler_8x8_state->dw4.table_1x_filter_c0 = 0x0;
3669 sampler_8x8_state->dw4.table_1x_filter_c1 = 0x0;
3670 sampler_8x8_state->dw4.table_1x_filter_c2 = 0x0;
3671 sampler_8x8_state->dw4.table_1x_filter_c3 =
3672 intel_format_convert(1 - coff, 1, 6, 0);
3673 sampler_8x8_state->dw5.table_1x_filter_c4 =
3674 intel_format_convert(coff, 1, 6, 0);
3675 sampler_8x8_state->dw5.table_1x_filter_c5 = 0x00;
3676 sampler_8x8_state->dw5.table_1x_filter_c6 = 0x0;
3677 sampler_8x8_state->dw5.table_1x_filter_c7 = 0x0;
3678 sampler_8x8_state->dw6.table_1y_filter_c0 = 0x0;
3679 sampler_8x8_state->dw6.table_1y_filter_c1 = 0x0;
3680 sampler_8x8_state->dw6.table_1y_filter_c2 = 0x0;
3681 sampler_8x8_state->dw6.table_1y_filter_c3 =
3682 intel_format_convert(1 - coff, 1, 6, 0);
3683 sampler_8x8_state->dw7.table_1y_filter_c4 =
3684 intel_format_convert(coff, 1, 6,0);
3685 sampler_8x8_state->dw7.table_1y_filter_c5 = 0x0;
3686 sampler_8x8_state->dw7.table_1y_filter_c6 = 0x0;
3687 sampler_8x8_state->dw7.table_1y_filter_c7 = 0x0;
3688 sampler_8x8_state++;
3691 sampler_8x8->dw152.default_sharpness_level = 0;
3692 sampler_8x8->dw153.adaptive_filter_for_all_channel = 1;
3693 sampler_8x8->dw153.bypass_y_adaptive_filtering = 1;
3694 sampler_8x8->dw153.bypass_x_adaptive_filtering = 1;
3696 dri_bo_unmap(pp_context->sampler_state_table.bo);
3699 /* private function & data */
3700 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
3701 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
3702 pp_context->private_context = &pp_context->pp_avs_context;
3703 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
3705 pp_avs_context->dest_x = dst_rect->x;
3706 pp_avs_context->dest_y = dst_rect->y;
3707 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
3708 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
3709 pp_avs_context->src_w = src_rect->width;
3710 pp_avs_context->src_h = src_rect->height;
3711 pp_avs_context->horiz_range = (float)src_rect->width / src_width;
3713 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
3714 dw = MAX(dw, dst_rect->width);
3716 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3717 pp_static_parameter->grf2.avs_wa_enable = 0; /* It is not required on GEN8+ */
3718 pp_static_parameter->grf2.avs_wa_width = src_width;
3719 pp_static_parameter->grf2.avs_wa_one_div_256_width = (float) 1.0 / (256 * src_width);
3720 pp_static_parameter->grf2.avs_wa_five_div_256_width = (float) 5.0 / (256 * src_width);
3722 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
3723 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) src_rect->height / src_height / dst_rect->height;
3724 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = (float) src_rect->y / src_height -
3725 (float) pp_avs_context->dest_y * pp_static_parameter->grf4.sampler_load_vertical_scaling_step;
3726 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = (float) src_rect->x / src_width -
3727 (float) pp_avs_context->dest_x * pp_avs_context->horiz_range / dw;
3729 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
3731 dst_surface->flags = src_surface->flags;
3733 return VA_STATUS_SUCCESS;
3737 gen7_pp_rgbx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3738 const struct i965_surface *src_surface,
3739 const VARectangle *src_rect,
3740 struct i965_surface *dst_surface,
3741 const VARectangle *dst_rect,
3744 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->pp_avs_context;
3745 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3746 struct gen7_sampler_8x8 *sampler_8x8;
3747 struct i965_sampler_8x8_state *sampler_8x8_state;
3749 int width[3], height[3], pitch[3], offset[3];
3750 int src_width, src_height;
3752 /* source surface */
3753 gen7_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
3754 width, height, pitch, offset);
3755 src_width = width[0];
3756 src_height = height[0];
3758 /* destination surface */
3759 gen7_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
3760 width, height, pitch, offset);
3762 /* sampler 8x8 state */
3763 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
3764 assert(pp_context->sampler_state_table.bo_8x8->virtual);
3765 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
3766 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
3767 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
3769 /* The sampler_state setting of RGBX surface will be different with
3770 * that for NV12/I420 surface.
3772 for (i = 0; i < 17; i++) {
3776 /* for Y channel, currently ignore */
3777 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c0 = 0x0;
3778 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c1 = 0x0;
3779 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c2 = 0x0;
3780 sampler_8x8_state->coefficients[i].dw0.table_0x_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3781 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3782 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c5 = 0x0;
3783 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c6 = 0x0;
3784 sampler_8x8_state->coefficients[i].dw1.table_0x_filter_c7 = 0x0;
3785 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c0 = 0x0;
3786 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c1 = 0x0;
3787 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c2 = 0x0;
3788 sampler_8x8_state->coefficients[i].dw2.table_0y_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3789 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3790 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c5 = 0x0;
3791 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c6 = 0x0;
3792 sampler_8x8_state->coefficients[i].dw3.table_0y_filter_c7 = 0x0;
3793 /* for U/V channel, 0.25 */
3794 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c0 = 0x0;
3795 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c1 = 0x0;
3796 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c2 = 0x00;
3797 sampler_8x8_state->coefficients[i].dw4.table_1x_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3798 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3799 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c5 = 0x00;
3800 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c6 = 0x0;
3801 sampler_8x8_state->coefficients[i].dw5.table_1x_filter_c7 = 0x0;
3802 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c0 = 0x0;
3803 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c1 = 0x0;
3804 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c2 = 0x00;
3805 sampler_8x8_state->coefficients[i].dw6.table_1y_filter_c3 = intel_format_convert(1 - coff, 1, 6, 0);
3806 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c4 = intel_format_convert(coff, 1, 6, 0);
3807 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c5 = 0x00;
3808 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c6 = 0x0;
3809 sampler_8x8_state->coefficients[i].dw7.table_1y_filter_c7 = 0x0;
3812 sampler_8x8_state->dw136.default_sharpness_level = 0;
3813 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 0;
3814 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
3815 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
3816 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
3819 dri_bo_map(pp_context->sampler_state_table.bo, True);
3820 assert(pp_context->sampler_state_table.bo->virtual);
3821 assert(sizeof(*sampler_8x8) == sizeof(int) * 4);
3822 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
3824 /* sample_8x8 Y index 4 */
3826 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3827 sampler_8x8[index].dw0.global_noise_estimation = 255;
3828 sampler_8x8[index].dw0.ief_bypass = 1;
3830 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3832 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3833 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3834 sampler_8x8[index].dw2.r5x_coefficient = 9;
3835 sampler_8x8[index].dw2.r5cx_coefficient = 8;
3836 sampler_8x8[index].dw2.r5c_coefficient = 3;
3838 sampler_8x8[index].dw3.r3x_coefficient = 27;
3839 sampler_8x8[index].dw3.r3c_coefficient = 5;
3840 sampler_8x8[index].dw3.gain_factor = 40;
3841 sampler_8x8[index].dw3.non_edge_weight = 1;
3842 sampler_8x8[index].dw3.regular_weight = 2;
3843 sampler_8x8[index].dw3.strong_edge_weight = 7;
3844 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
3846 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3847 I915_GEM_DOMAIN_RENDER,
3850 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3851 pp_context->sampler_state_table.bo_8x8);
3853 /* sample_8x8 UV index 8 */
3855 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3856 sampler_8x8[index].dw0.disable_8x8_filter = 0;
3857 sampler_8x8[index].dw0.global_noise_estimation = 255;
3858 sampler_8x8[index].dw0.ief_bypass = 1;
3859 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3860 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3861 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3862 sampler_8x8[index].dw2.r5x_coefficient = 9;
3863 sampler_8x8[index].dw2.r5cx_coefficient = 8;
3864 sampler_8x8[index].dw2.r5c_coefficient = 3;
3865 sampler_8x8[index].dw3.r3x_coefficient = 27;
3866 sampler_8x8[index].dw3.r3c_coefficient = 5;
3867 sampler_8x8[index].dw3.gain_factor = 40;
3868 sampler_8x8[index].dw3.non_edge_weight = 1;
3869 sampler_8x8[index].dw3.regular_weight = 2;
3870 sampler_8x8[index].dw3.strong_edge_weight = 7;
3871 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
3873 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3874 I915_GEM_DOMAIN_RENDER,
3877 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3878 pp_context->sampler_state_table.bo_8x8);
3880 /* sampler_8x8 V, index 12 */
3882 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
3883 sampler_8x8[index].dw0.disable_8x8_filter = 0;
3884 sampler_8x8[index].dw0.global_noise_estimation = 255;
3885 sampler_8x8[index].dw0.ief_bypass = 1;
3886 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
3887 sampler_8x8[index].dw2.weak_edge_threshold = 1;
3888 sampler_8x8[index].dw2.strong_edge_threshold = 8;
3889 sampler_8x8[index].dw2.r5x_coefficient = 9;
3890 sampler_8x8[index].dw2.r5cx_coefficient = 8;
3891 sampler_8x8[index].dw2.r5c_coefficient = 3;
3892 sampler_8x8[index].dw3.r3x_coefficient = 27;
3893 sampler_8x8[index].dw3.r3c_coefficient = 5;
3894 sampler_8x8[index].dw3.gain_factor = 40;
3895 sampler_8x8[index].dw3.non_edge_weight = 1;
3896 sampler_8x8[index].dw3.regular_weight = 2;
3897 sampler_8x8[index].dw3.strong_edge_weight = 7;
3898 sampler_8x8[index].dw3.ief4_smooth_enable = 0;
3900 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
3901 I915_GEM_DOMAIN_RENDER,
3904 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
3905 pp_context->sampler_state_table.bo_8x8);
3907 dri_bo_unmap(pp_context->sampler_state_table.bo);
3909 /* private function & data */
3910 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
3911 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
3912 pp_context->private_context = &pp_context->pp_avs_context;
3913 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
3915 pp_avs_context->dest_x = dst_rect->x;
3916 pp_avs_context->dest_y = dst_rect->y;
3917 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
3918 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
3919 pp_avs_context->src_w = src_rect->width;
3920 pp_avs_context->src_h = src_rect->height;
3921 pp_avs_context->horiz_range = (float)src_rect->width / src_width;
3923 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
3924 dw = MAX(dw, dst_rect->width);
3926 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
3927 pp_static_parameter->grf2.avs_wa_enable = 0; /* It is unnecessary to use WA for RGBX surface */
3928 pp_static_parameter->grf2.avs_wa_width = dw;
3929 pp_static_parameter->grf2.avs_wa_one_div_256_width = (float) 1.0 / (256 * dw);
3930 pp_static_parameter->grf2.avs_wa_five_div_256_width = (float) 5.0 / (256 * dw);
3932 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
3933 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) src_rect->height / src_height / dst_rect->height;
3934 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = (float) src_rect->y / src_height -
3935 (float) pp_avs_context->dest_y * pp_static_parameter->grf4.sampler_load_vertical_scaling_step;
3936 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = (float) src_rect->x / src_width -
3937 (float) pp_avs_context->dest_x * pp_avs_context->horiz_range / dw;
3938 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
3940 dst_surface->flags = src_surface->flags;
3942 return VA_STATUS_SUCCESS;
3946 pp_dndi_x_steps(void *private_context)
3952 pp_dndi_y_steps(void *private_context)
3954 struct pp_dndi_context *pp_dndi_context = private_context;
3956 return pp_dndi_context->dest_h / 4;
3960 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
3962 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3964 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
3965 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
3971 pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
3972 const struct i965_surface *src_surface,
3973 const VARectangle *src_rect,
3974 struct i965_surface *dst_surface,
3975 const VARectangle *dst_rect,
3978 struct i965_driver_data *i965 = i965_driver_data(ctx);
3979 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->pp_dndi_context;
3980 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
3981 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
3982 struct object_surface *obj_surface;
3983 struct i965_sampler_dndi *sampler_dndi;
3987 int dndi_top_first = 1;
3988 VAProcFilterParameterBufferDeinterlacing *di_filter_param = (VAProcFilterParameterBufferDeinterlacing *)filter_param;
3990 if (di_filter_param->flags & VA_DEINTERLACING_BOTTOM_FIELD)
3996 obj_surface = (struct object_surface *)src_surface->base;
3997 orig_w = obj_surface->orig_width;
3998 orig_h = obj_surface->orig_height;
3999 w = obj_surface->width;
4000 h = obj_surface->height;
4002 if (pp_dndi_context->stmm_bo == NULL) {
4003 pp_dndi_context->stmm_bo = dri_bo_alloc(i965->intel.bufmgr,
4007 assert(pp_dndi_context->stmm_bo);
4010 /* source UV surface index 2 */
4011 i965_pp_set_surface_state(ctx, pp_context,
4012 obj_surface->bo, w * h,
4013 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4016 /* source YUV surface index 4 */
4017 i965_pp_set_surface2_state(ctx, pp_context,
4021 SURFACE_FORMAT_PLANAR_420_8, 1,
4024 /* source STMM surface index 20 */
4025 i965_pp_set_surface_state(ctx, pp_context,
4026 pp_dndi_context->stmm_bo, 0,
4027 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4030 /* destination surface */
4031 obj_surface = (struct object_surface *)dst_surface->base;
4032 orig_w = obj_surface->orig_width;
4033 orig_h = obj_surface->orig_height;
4034 w = obj_surface->width;
4035 h = obj_surface->height;
4037 /* destination Y surface index 7 */
4038 i965_pp_set_surface_state(ctx, pp_context,
4040 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4043 /* destination UV surface index 8 */
4044 i965_pp_set_surface_state(ctx, pp_context,
4045 obj_surface->bo, w * h,
4046 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4049 dri_bo_map(pp_context->sampler_state_table.bo, True);
4050 assert(pp_context->sampler_state_table.bo->virtual);
4051 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
4052 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
4054 /* sample dndi index 1 */
4056 sampler_dndi[index].dw0.denoise_asd_threshold = 38;
4057 sampler_dndi[index].dw0.denoise_history_delta = 7; // 0-15, default is 8
4058 sampler_dndi[index].dw0.denoise_maximum_history = 192; // 128-240
4059 sampler_dndi[index].dw0.denoise_stad_threshold = 140;
4061 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 38;
4062 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 1;
4063 sampler_dndi[index].dw1.stmm_c2 = 1;
4064 sampler_dndi[index].dw1.low_temporal_difference_threshold = 0;
4065 sampler_dndi[index].dw1.temporal_difference_threshold = 0;
4067 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 20; // 0-31
4068 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 1; // 0-15
4069 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
4070 sampler_dndi[index].dw2.good_neighbor_threshold = 12; // 0-63
4072 sampler_dndi[index].dw3.maximum_stmm = 150;
4073 sampler_dndi[index].dw3.multipler_for_vecm = 30;
4074 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 125;
4075 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
4076 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
4078 sampler_dndi[index].dw4.sdi_delta = 5;
4079 sampler_dndi[index].dw4.sdi_threshold = 100;
4080 sampler_dndi[index].dw4.stmm_output_shift = 5; // stmm_max - stmm_min = 2 ^ stmm_output_shift
4081 sampler_dndi[index].dw4.stmm_shift_up = 1;
4082 sampler_dndi[index].dw4.stmm_shift_down = 0;
4083 sampler_dndi[index].dw4.minimum_stmm = 118;
4085 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 175;
4086 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 37;
4087 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 100;
4088 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 50;
4090 sampler_dndi[index].dw6.dn_enable = 1;
4091 sampler_dndi[index].dw6.di_enable = 1;
4092 sampler_dndi[index].dw6.di_partial = 0;
4093 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
4094 sampler_dndi[index].dw6.dndi_stream_id = 0;
4095 sampler_dndi[index].dw6.dndi_first_frame = 1;
4096 sampler_dndi[index].dw6.progressive_dn = 0;
4097 sampler_dndi[index].dw6.fmd_tear_threshold = 2;
4098 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 100;
4099 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 16;
4101 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
4102 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
4103 sampler_dndi[index].dw7.vdi_walker_enable = 0;
4104 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
4106 dri_bo_unmap(pp_context->sampler_state_table.bo);
4108 /* private function & data */
4109 pp_context->pp_x_steps = pp_dndi_x_steps;
4110 pp_context->pp_y_steps = pp_dndi_y_steps;
4111 pp_context->private_context = &pp_context->pp_dndi_context;
4112 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
4114 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
4115 pp_static_parameter->grf1.r1_6.di.top_field_first = dndi_top_first;
4116 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 0;
4117 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 0;
4119 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
4120 pp_inline_parameter->grf5.number_blocks = w / 16;
4121 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
4122 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
4124 pp_dndi_context->dest_w = w;
4125 pp_dndi_context->dest_h = h;
4127 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
4129 return VA_STATUS_SUCCESS;
4133 pp_dn_x_steps(void *private_context)
4139 pp_dn_y_steps(void *private_context)
4141 struct pp_dn_context *pp_dn_context = private_context;
4143 return pp_dn_context->dest_h / 8;
4147 pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
4149 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
4151 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
4152 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 8;
4158 pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
4159 const struct i965_surface *src_surface,
4160 const VARectangle *src_rect,
4161 struct i965_surface *dst_surface,
4162 const VARectangle *dst_rect,
4165 struct i965_driver_data *i965 = i965_driver_data(ctx);
4166 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->pp_dn_context;
4167 struct object_surface *obj_surface;
4168 struct i965_sampler_dndi *sampler_dndi;
4169 struct pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
4170 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
4171 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
4175 int dn_strength = 15;
4176 int dndi_top_first = 1;
4177 int dn_progressive = 0;
4179 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
4182 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
4190 if (dn_filter_param) {
4191 float value = dn_filter_param->value;
4199 dn_strength = (int)(value * 31.0F);
4203 obj_surface = (struct object_surface *)src_surface->base;
4204 orig_w = obj_surface->orig_width;
4205 orig_h = obj_surface->orig_height;
4206 w = obj_surface->width;
4207 h = obj_surface->height;
4209 if (pp_dn_context->stmm_bo == NULL) {
4210 pp_dn_context->stmm_bo = dri_bo_alloc(i965->intel.bufmgr,
4214 assert(pp_dn_context->stmm_bo);
4217 /* source UV surface index 2 */
4218 i965_pp_set_surface_state(ctx, pp_context,
4219 obj_surface->bo, w * h,
4220 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4223 /* source YUV surface index 4 */
4224 i965_pp_set_surface2_state(ctx, pp_context,
4228 SURFACE_FORMAT_PLANAR_420_8, 1,
4231 /* source STMM surface index 20 */
4232 i965_pp_set_surface_state(ctx, pp_context,
4233 pp_dn_context->stmm_bo, 0,
4234 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4237 /* destination surface */
4238 obj_surface = (struct object_surface *)dst_surface->base;
4239 orig_w = obj_surface->orig_width;
4240 orig_h = obj_surface->orig_height;
4241 w = obj_surface->width;
4242 h = obj_surface->height;
4244 /* destination Y surface index 7 */
4245 i965_pp_set_surface_state(ctx, pp_context,
4247 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4250 /* destination UV surface index 8 */
4251 i965_pp_set_surface_state(ctx, pp_context,
4252 obj_surface->bo, w * h,
4253 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4256 dri_bo_map(pp_context->sampler_state_table.bo, True);
4257 assert(pp_context->sampler_state_table.bo->virtual);
4258 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
4259 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
4261 /* sample dndi index 1 */
4263 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
4264 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
4265 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
4266 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
4268 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
4269 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
4270 sampler_dndi[index].dw1.stmm_c2 = 0;
4271 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
4272 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
4274 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
4275 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
4276 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
4277 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
4279 sampler_dndi[index].dw3.maximum_stmm = 128;
4280 sampler_dndi[index].dw3.multipler_for_vecm = 2;
4281 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
4282 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
4283 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
4285 sampler_dndi[index].dw4.sdi_delta = 8;
4286 sampler_dndi[index].dw4.sdi_threshold = 128;
4287 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
4288 sampler_dndi[index].dw4.stmm_shift_up = 0;
4289 sampler_dndi[index].dw4.stmm_shift_down = 0;
4290 sampler_dndi[index].dw4.minimum_stmm = 0;
4292 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
4293 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
4294 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
4295 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
4297 sampler_dndi[index].dw6.dn_enable = 1;
4298 sampler_dndi[index].dw6.di_enable = 0;
4299 sampler_dndi[index].dw6.di_partial = 0;
4300 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
4301 sampler_dndi[index].dw6.dndi_stream_id = 1;
4302 sampler_dndi[index].dw6.dndi_first_frame = 1;
4303 sampler_dndi[index].dw6.progressive_dn = dn_progressive;
4304 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
4305 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
4306 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
4308 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
4309 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
4310 sampler_dndi[index].dw7.vdi_walker_enable = 0;
4311 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
4313 dri_bo_unmap(pp_context->sampler_state_table.bo);
4315 /* private function & data */
4316 pp_context->pp_x_steps = pp_dn_x_steps;
4317 pp_context->pp_y_steps = pp_dn_y_steps;
4318 pp_context->private_context = &pp_context->pp_dn_context;
4319 pp_context->pp_set_block_parameter = pp_dn_set_block_parameter;
4321 pp_static_parameter->grf1.statistics_surface_picth = w / 2;
4322 pp_static_parameter->grf1.r1_6.di.top_field_first = 0;
4323 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m2 = 64;
4324 pp_static_parameter->grf4.r4_2.di.motion_history_coefficient_m1 = 192;
4326 pp_inline_parameter->grf5.block_count_x = w / 16; /* 1 x N */
4327 pp_inline_parameter->grf5.number_blocks = w / 16;
4328 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
4329 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
4331 pp_dn_context->dest_w = w;
4332 pp_dn_context->dest_h = h;
4334 dst_surface->flags = src_surface->flags;
4336 return VA_STATUS_SUCCESS;
4340 gen7_pp_dndi_x_steps(void *private_context)
4342 struct pp_dndi_context *pp_dndi_context = private_context;
4344 return pp_dndi_context->dest_w / 16;
4348 gen7_pp_dndi_y_steps(void *private_context)
4350 struct pp_dndi_context *pp_dndi_context = private_context;
4352 return pp_dndi_context->dest_h / 4;
4356 gen7_pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
4358 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
4360 pp_inline_parameter->grf7.destination_block_horizontal_origin = x * 16;
4361 pp_inline_parameter->grf7.destination_block_vertical_origin = y * 4;
4368 vpp_surface_convert(VADriverContextP ctx,
4369 struct object_surface *src_obj_surf,
4370 struct object_surface *dst_obj_surf);
4373 gen7_pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
4374 const struct i965_surface *src_surface,
4375 const VARectangle *src_rect,
4376 struct i965_surface *dst_surface,
4377 const VARectangle *dst_rect,
4380 struct i965_driver_data *i965 = i965_driver_data(ctx);
4381 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->pp_dndi_context;
4382 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
4383 struct object_surface *previous_in_obj_surface, *current_in_obj_surface, *previous_out_obj_surface, *current_out_obj_surface;
4384 struct gen7_sampler_dndi *sampler_dndi;
4388 int dndi_top_first = 1;
4389 VAProcFilterParameterBufferDeinterlacing *di_filter_param = (VAProcFilterParameterBufferDeinterlacing *)filter_param;
4390 int is_first_frame = (pp_dndi_context->frame_order == -1);
4392 if (di_filter_param->flags & VA_DEINTERLACING_BOTTOM_FIELD)
4398 current_in_obj_surface = (struct object_surface *)src_surface->base;
4400 if (di_filter_param->algorithm == VAProcDeinterlacingBob) {
4401 previous_in_obj_surface = current_in_obj_surface;
4403 } else if (di_filter_param->algorithm == VAProcDeinterlacingMotionAdaptive) {
4404 if (pp_dndi_context->frame_order == 0) {
4405 VAProcPipelineParameterBuffer *pipeline_param = pp_context->pipeline_param;
4406 if (!pipeline_param ||
4407 !pipeline_param->num_forward_references ||
4408 pipeline_param->forward_references[0] == VA_INVALID_ID) {
4409 WARN_ONCE("A forward temporal reference is needed for Motion adaptive deinterlacing !!!\n");
4411 return VA_STATUS_ERROR_INVALID_PARAMETER;
4413 previous_in_obj_surface = SURFACE(pipeline_param->forward_references[0]);
4414 assert(previous_in_obj_surface && previous_in_obj_surface->bo);
4418 } else if (pp_dndi_context->frame_order == 1) {
4419 vpp_surface_convert(ctx,
4420 pp_dndi_context->current_out_obj_surface,
4421 (struct object_surface *)dst_surface->base);
4422 pp_dndi_context->frame_order = (pp_dndi_context->frame_order + 1) % 2;
4425 return VA_STATUS_SUCCESS_1;
4427 previous_in_obj_surface = current_in_obj_surface;
4431 return VA_STATUS_ERROR_UNIMPLEMENTED;
4434 /* source (temporal reference) YUV surface index 4 */
4435 orig_w = previous_in_obj_surface->orig_width;
4436 orig_h = previous_in_obj_surface->orig_height;
4437 w = previous_in_obj_surface->width;
4438 h = previous_in_obj_surface->height;
4439 gen7_pp_set_surface2_state(ctx, pp_context,
4440 previous_in_obj_surface->bo, 0,
4443 SURFACE_FORMAT_PLANAR_420_8, 1,
4446 /* source surface */
4447 orig_w = current_in_obj_surface->orig_width;
4448 orig_h = current_in_obj_surface->orig_height;
4449 w = current_in_obj_surface->width;
4450 h = current_in_obj_surface->height;
4452 /* source UV surface index 1 */
4453 gen7_pp_set_surface_state(ctx, pp_context,
4454 current_in_obj_surface->bo, w * h,
4455 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4458 /* source YUV surface index 3 */
4459 gen7_pp_set_surface2_state(ctx, pp_context,
4460 current_in_obj_surface->bo, 0,
4463 SURFACE_FORMAT_PLANAR_420_8, 1,
4466 /* STMM / History Statistics input surface, index 5 */
4467 if (pp_dndi_context->stmm_bo == NULL) {
4468 pp_dndi_context->stmm_bo = dri_bo_alloc(i965->intel.bufmgr,
4472 assert(pp_dndi_context->stmm_bo);
4475 gen7_pp_set_surface_state(ctx, pp_context,
4476 pp_dndi_context->stmm_bo, 0,
4477 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4480 /* destination surface */
4481 previous_out_obj_surface = (struct object_surface *)dst_surface->base;
4482 orig_w = previous_out_obj_surface->orig_width;
4483 orig_h = previous_out_obj_surface->orig_height;
4484 w = previous_out_obj_surface->width;
4485 h = previous_out_obj_surface->height;
4487 if (is_first_frame) {
4488 current_out_obj_surface = previous_out_obj_surface;
4492 if (pp_dndi_context->current_out_surface == VA_INVALID_SURFACE) {
4493 unsigned int tiling = 0, swizzle = 0;
4494 dri_bo_get_tiling(previous_out_obj_surface->bo, &tiling, &swizzle);
4496 va_status = i965_CreateSurfaces(ctx,
4499 VA_RT_FORMAT_YUV420,
4501 &pp_dndi_context->current_out_surface);
4502 assert(va_status == VA_STATUS_SUCCESS);
4503 pp_dndi_context->current_out_obj_surface = SURFACE(pp_dndi_context->current_out_surface);
4504 assert(pp_dndi_context->current_out_obj_surface);
4505 i965_check_alloc_surface_bo(ctx,
4506 pp_dndi_context->current_out_obj_surface,
4507 tiling != I915_TILING_NONE,
4508 VA_FOURCC('N','V','1','2'),
4512 current_out_obj_surface = pp_dndi_context->current_out_obj_surface;
4515 /* destination(Previous frame) Y surface index 27 */
4516 gen7_pp_set_surface_state(ctx, pp_context,
4517 previous_out_obj_surface->bo, 0,
4518 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4521 /* destination(Previous frame) UV surface index 28 */
4522 gen7_pp_set_surface_state(ctx, pp_context,
4523 previous_out_obj_surface->bo, w * h,
4524 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4527 /* destination(Current frame) Y surface index 30 */
4528 gen7_pp_set_surface_state(ctx, pp_context,
4529 current_out_obj_surface->bo, 0,
4530 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4533 /* destination(Current frame) UV surface index 31 */
4534 orig_w = current_out_obj_surface->orig_width;
4535 orig_h = current_out_obj_surface->orig_height;
4536 w = current_out_obj_surface->width;
4537 h = current_out_obj_surface->height;
4539 gen7_pp_set_surface_state(ctx, pp_context,
4540 current_out_obj_surface->bo, w * h,
4541 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4544 /* STMM output surface, index 33 */
4545 gen7_pp_set_surface_state(ctx, pp_context,
4546 pp_dndi_context->stmm_bo, 0,
4547 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4552 dri_bo_map(pp_context->sampler_state_table.bo, True);
4553 assert(pp_context->sampler_state_table.bo->virtual);
4554 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
4555 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
4557 /* sample dndi index 0 */
4559 sampler_dndi[index].dw0.denoise_asd_threshold = 38;
4560 sampler_dndi[index].dw0.dnmh_delt = 7;
4561 sampler_dndi[index].dw0.vdi_walker_y_stride = 0;
4562 sampler_dndi[index].dw0.vdi_walker_frame_sharing_enable = 0;
4563 sampler_dndi[index].dw0.denoise_maximum_history = 192; // 128-240
4564 sampler_dndi[index].dw0.denoise_stad_threshold = 140;
4566 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 38;
4567 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 1;
4568 sampler_dndi[index].dw1.stmm_c2 = 2;
4569 sampler_dndi[index].dw1.low_temporal_difference_threshold = 0;
4570 sampler_dndi[index].dw1.temporal_difference_threshold = 0;
4572 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 20; // 0-31
4573 sampler_dndi[index].dw2.bne_edge_th = 1;
4574 sampler_dndi[index].dw2.smooth_mv_th = 0;
4575 sampler_dndi[index].dw2.sad_tight_th = 5;
4576 sampler_dndi[index].dw2.cat_slope_minus1 = 9;
4577 sampler_dndi[index].dw2.good_neighbor_th = 12;
4579 sampler_dndi[index].dw3.maximum_stmm = 150;
4580 sampler_dndi[index].dw3.multipler_for_vecm = 30;
4581 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 125;
4582 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
4583 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
4585 sampler_dndi[index].dw4.sdi_delta = 5;
4586 sampler_dndi[index].dw4.sdi_threshold = 100;
4587 sampler_dndi[index].dw4.stmm_output_shift = 5; // stmm_max - stmm_min = 2 ^ stmm_output_shift
4588 sampler_dndi[index].dw4.stmm_shift_up = 1;
4589 sampler_dndi[index].dw4.stmm_shift_down = 0;
4590 sampler_dndi[index].dw4.minimum_stmm = 118;
4592 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 175;
4593 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 37;
4594 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 100;
4595 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 50;
4596 sampler_dndi[index].dw6.dn_enable = 0;
4597 sampler_dndi[index].dw6.di_enable = 1;
4598 sampler_dndi[index].dw6.di_partial = 0;
4599 sampler_dndi[index].dw6.dndi_top_first = dndi_top_first;
4600 sampler_dndi[index].dw6.dndi_stream_id = 1;
4601 sampler_dndi[index].dw6.dndi_first_frame = is_first_frame;
4602 sampler_dndi[index].dw6.progressive_dn = 0;
4603 sampler_dndi[index].dw6.mcdi_enable = 0;
4604 sampler_dndi[index].dw6.fmd_tear_threshold = 2;
4605 sampler_dndi[index].dw6.cat_th1 = 0;
4606 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 100;
4607 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 16;
4609 sampler_dndi[index].dw7.sad_tha = 5;
4610 sampler_dndi[index].dw7.sad_thb = 10;
4611 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 0;
4612 sampler_dndi[index].dw7.mc_pixel_consistency_th = 25;
4613 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 0;
4614 sampler_dndi[index].dw7.vdi_walker_enable = 0;
4615 sampler_dndi[index].dw7.neighborpixel_th = 10;
4616 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
4618 dri_bo_unmap(pp_context->sampler_state_table.bo);
4620 /* private function & data */
4621 pp_context->pp_x_steps = gen7_pp_dndi_x_steps;
4622 pp_context->pp_y_steps = gen7_pp_dndi_y_steps;
4623 pp_context->private_context = &pp_context->pp_dndi_context;
4624 pp_context->pp_set_block_parameter = gen7_pp_dndi_set_block_parameter;
4626 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
4627 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
4628 pp_static_parameter->grf1.di_top_field_first = 0;
4629 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
4631 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
4632 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
4633 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
4635 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
4636 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
4638 pp_dndi_context->dest_w = w;
4639 pp_dndi_context->dest_h = h;
4641 dst_surface->flags = I965_SURFACE_FLAG_FRAME;
4643 pp_dndi_context->frame_order = (pp_dndi_context->frame_order + 1) % 2;
4645 return VA_STATUS_SUCCESS;
4649 gen7_pp_dn_x_steps(void *private_context)
4651 struct pp_dn_context *pp_dn_context = private_context;
4653 return pp_dn_context->dest_w / 16;
4657 gen7_pp_dn_y_steps(void *private_context)
4659 struct pp_dn_context *pp_dn_context = private_context;
4661 return pp_dn_context->dest_h / 4;
4665 gen7_pp_dn_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
4667 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
4669 pp_inline_parameter->grf5.destination_block_horizontal_origin = x * 16;
4670 pp_inline_parameter->grf5.destination_block_vertical_origin = y * 4;
4676 gen7_pp_nv12_dn_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
4677 const struct i965_surface *src_surface,
4678 const VARectangle *src_rect,
4679 struct i965_surface *dst_surface,
4680 const VARectangle *dst_rect,
4683 struct i965_driver_data *i965 = i965_driver_data(ctx);
4684 struct pp_dn_context *pp_dn_context = (struct pp_dn_context *)&pp_context->pp_dn_context;
4685 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
4686 struct object_surface *obj_surface;
4687 struct gen7_sampler_dndi *sampler_dn;
4688 VAProcFilterParameterBuffer *dn_filter_param = filter_param; /* FIXME: parameter */
4692 int dn_strength = 15;
4693 int dndi_top_first = 1;
4694 int dn_progressive = 0;
4696 if (src_surface->flags == I965_SURFACE_FLAG_FRAME) {
4699 } else if (src_surface->flags == I965_SURFACE_FLAG_TOP_FIELD_FIRST) {
4707 if (dn_filter_param) {
4708 float value = dn_filter_param->value;
4716 dn_strength = (int)(value * 31.0F);
4720 obj_surface = (struct object_surface *)src_surface->base;
4721 orig_w = obj_surface->orig_width;
4722 orig_h = obj_surface->orig_height;
4723 w = obj_surface->width;
4724 h = obj_surface->height;
4726 if (pp_dn_context->stmm_bo == NULL) {
4727 pp_dn_context->stmm_bo= dri_bo_alloc(i965->intel.bufmgr,
4731 assert(pp_dn_context->stmm_bo);
4734 /* source UV surface index 1 */
4735 gen7_pp_set_surface_state(ctx, pp_context,
4736 obj_surface->bo, w * h,
4737 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4740 /* source YUV surface index 3 */
4741 gen7_pp_set_surface2_state(ctx, pp_context,
4745 SURFACE_FORMAT_PLANAR_420_8, 1,
4748 /* source (temporal reference) YUV surface index 4 */
4749 gen7_pp_set_surface2_state(ctx, pp_context,
4753 SURFACE_FORMAT_PLANAR_420_8, 1,
4756 /* STMM / History Statistics input surface, index 5 */
4757 gen7_pp_set_surface_state(ctx, pp_context,
4758 pp_dn_context->stmm_bo, 0,
4759 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4762 /* destination surface */
4763 obj_surface = (struct object_surface *)dst_surface->base;
4764 orig_w = obj_surface->orig_width;
4765 orig_h = obj_surface->orig_height;
4766 w = obj_surface->width;
4767 h = obj_surface->height;
4769 /* destination Y surface index 24 */
4770 gen7_pp_set_surface_state(ctx, pp_context,
4772 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
4775 /* destination UV surface index 25 */
4776 gen7_pp_set_surface_state(ctx, pp_context,
4777 obj_surface->bo, w * h,
4778 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
4782 dri_bo_map(pp_context->sampler_state_table.bo, True);
4783 assert(pp_context->sampler_state_table.bo->virtual);
4784 assert(sizeof(*sampler_dn) == sizeof(int) * 8);
4785 sampler_dn = pp_context->sampler_state_table.bo->virtual;
4787 /* sample dn index 1 */
4789 sampler_dn[index].dw0.denoise_asd_threshold = 0;
4790 sampler_dn[index].dw0.dnmh_delt = 8;
4791 sampler_dn[index].dw0.vdi_walker_y_stride = 0;
4792 sampler_dn[index].dw0.vdi_walker_frame_sharing_enable = 0;
4793 sampler_dn[index].dw0.denoise_maximum_history = 128; // 128-240
4794 sampler_dn[index].dw0.denoise_stad_threshold = 0;
4796 sampler_dn[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
4797 sampler_dn[index].dw1.denoise_moving_pixel_threshold = 0;
4798 sampler_dn[index].dw1.stmm_c2 = 0;
4799 sampler_dn[index].dw1.low_temporal_difference_threshold = 8;
4800 sampler_dn[index].dw1.temporal_difference_threshold = 16;
4802 sampler_dn[index].dw2.block_noise_estimate_noise_threshold = dn_strength; // 0-31
4803 sampler_dn[index].dw2.bne_edge_th = 1;
4804 sampler_dn[index].dw2.smooth_mv_th = 0;
4805 sampler_dn[index].dw2.sad_tight_th = 5;
4806 sampler_dn[index].dw2.cat_slope_minus1 = 9;
4807 sampler_dn[index].dw2.good_neighbor_th = 4;
4809 sampler_dn[index].dw3.maximum_stmm = 128;
4810 sampler_dn[index].dw3.multipler_for_vecm = 2;
4811 sampler_dn[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
4812 sampler_dn[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
4813 sampler_dn[index].dw3.stmm_blending_constant_select = 0;
4815 sampler_dn[index].dw4.sdi_delta = 8;
4816 sampler_dn[index].dw4.sdi_threshold = 128;
4817 sampler_dn[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
4818 sampler_dn[index].dw4.stmm_shift_up = 0;
4819 sampler_dn[index].dw4.stmm_shift_down = 0;
4820 sampler_dn[index].dw4.minimum_stmm = 0;
4822 sampler_dn[index].dw5.fmd_temporal_difference_threshold = 0;
4823 sampler_dn[index].dw5.sdi_fallback_mode_2_constant = 0;
4824 sampler_dn[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
4825 sampler_dn[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
4827 sampler_dn[index].dw6.dn_enable = 1;
4828 sampler_dn[index].dw6.di_enable = 0;
4829 sampler_dn[index].dw6.di_partial = 0;
4830 sampler_dn[index].dw6.dndi_top_first = dndi_top_first;
4831 sampler_dn[index].dw6.dndi_stream_id = 1;
4832 sampler_dn[index].dw6.dndi_first_frame = 1;
4833 sampler_dn[index].dw6.progressive_dn = dn_progressive;
4834 sampler_dn[index].dw6.mcdi_enable = 0;
4835 sampler_dn[index].dw6.fmd_tear_threshold = 32;
4836 sampler_dn[index].dw6.cat_th1 = 0;
4837 sampler_dn[index].dw6.fmd2_vertical_difference_threshold = 32;
4838 sampler_dn[index].dw6.fmd1_vertical_difference_threshold = 32;
4840 sampler_dn[index].dw7.sad_tha = 5;
4841 sampler_dn[index].dw7.sad_thb = 10;
4842 sampler_dn[index].dw7.fmd_for_1st_field_of_current_frame = 2;
4843 sampler_dn[index].dw7.mc_pixel_consistency_th = 25;
4844 sampler_dn[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
4845 sampler_dn[index].dw7.vdi_walker_enable = 0;
4846 sampler_dn[index].dw7.neighborpixel_th = 10;
4847 sampler_dn[index].dw7.column_width_minus1 = w / 16;
4849 dri_bo_unmap(pp_context->sampler_state_table.bo);
4851 /* private function & data */
4852 pp_context->pp_x_steps = gen7_pp_dn_x_steps;
4853 pp_context->pp_y_steps = gen7_pp_dn_y_steps;
4854 pp_context->private_context = &pp_context->pp_dn_context;
4855 pp_context->pp_set_block_parameter = gen7_pp_dn_set_block_parameter;
4857 pp_static_parameter->grf1.di_statistics_surface_pitch_div2 = w / 2;
4858 pp_static_parameter->grf1.di_statistics_surface_height_div4 = h / 4;
4859 pp_static_parameter->grf1.di_top_field_first = 0;
4860 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
4862 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
4863 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
4864 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
4866 pp_static_parameter->grf4.di_hoffset_svf_from_dvf = 0;
4867 pp_static_parameter->grf4.di_voffset_svf_from_dvf = 0;
4869 pp_dn_context->dest_w = w;
4870 pp_dn_context->dest_h = h;
4872 dst_surface->flags = src_surface->flags;
4874 return VA_STATUS_SUCCESS;
4878 ironlake_pp_initialize(
4879 VADriverContextP ctx,
4880 struct i965_post_processing_context *pp_context,
4881 const struct i965_surface *src_surface,
4882 const VARectangle *src_rect,
4883 struct i965_surface *dst_surface,
4884 const VARectangle *dst_rect,
4890 struct i965_driver_data *i965 = i965_driver_data(ctx);
4891 struct pp_module *pp_module;
4893 int static_param_size, inline_param_size;
4895 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
4896 bo = dri_bo_alloc(i965->intel.bufmgr,
4897 "surface state & binding table",
4898 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
4901 pp_context->surface_state_binding_table.bo = bo;
4903 dri_bo_unreference(pp_context->curbe.bo);
4904 bo = dri_bo_alloc(i965->intel.bufmgr,
4909 pp_context->curbe.bo = bo;
4911 dri_bo_unreference(pp_context->idrt.bo);
4912 bo = dri_bo_alloc(i965->intel.bufmgr,
4913 "interface discriptor",
4914 sizeof(struct i965_interface_descriptor),
4917 pp_context->idrt.bo = bo;
4918 pp_context->idrt.num_interface_descriptors = 0;
4920 dri_bo_unreference(pp_context->sampler_state_table.bo);
4921 bo = dri_bo_alloc(i965->intel.bufmgr,
4922 "sampler state table",
4926 dri_bo_map(bo, True);
4927 memset(bo->virtual, 0, bo->size);
4929 pp_context->sampler_state_table.bo = bo;
4931 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
4932 bo = dri_bo_alloc(i965->intel.bufmgr,
4933 "sampler 8x8 state ",
4937 pp_context->sampler_state_table.bo_8x8 = bo;
4939 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
4940 bo = dri_bo_alloc(i965->intel.bufmgr,
4941 "sampler 8x8 state ",
4945 pp_context->sampler_state_table.bo_8x8_uv = bo;
4947 dri_bo_unreference(pp_context->vfe_state.bo);
4948 bo = dri_bo_alloc(i965->intel.bufmgr,
4950 sizeof(struct i965_vfe_state),
4953 pp_context->vfe_state.bo = bo;
4955 static_param_size = sizeof(struct pp_static_parameter);
4956 inline_param_size = sizeof(struct pp_inline_parameter);
4958 memset(pp_context->pp_static_parameter, 0, static_param_size);
4959 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
4961 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
4962 pp_context->current_pp = pp_index;
4963 pp_module = &pp_context->pp_modules[pp_index];
4965 if (pp_module->initialize)
4966 va_status = pp_module->initialize(ctx, pp_context,
4973 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
4979 ironlake_post_processing(
4980 VADriverContextP ctx,
4981 struct i965_post_processing_context *pp_context,
4982 const struct i965_surface *src_surface,
4983 const VARectangle *src_rect,
4984 struct i965_surface *dst_surface,
4985 const VARectangle *dst_rect,
4992 va_status = ironlake_pp_initialize(ctx, pp_context,
5000 if (va_status == VA_STATUS_SUCCESS) {
5001 ironlake_pp_states_setup(ctx, pp_context);
5002 ironlake_pp_pipeline_setup(ctx, pp_context);
5010 VADriverContextP ctx,
5011 struct i965_post_processing_context *pp_context,
5012 const struct i965_surface *src_surface,
5013 const VARectangle *src_rect,
5014 struct i965_surface *dst_surface,
5015 const VARectangle *dst_rect,
5021 struct i965_driver_data *i965 = i965_driver_data(ctx);
5022 struct pp_module *pp_module;
5024 int static_param_size, inline_param_size;
5026 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
5027 bo = dri_bo_alloc(i965->intel.bufmgr,
5028 "surface state & binding table",
5029 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
5032 pp_context->surface_state_binding_table.bo = bo;
5034 dri_bo_unreference(pp_context->curbe.bo);
5035 bo = dri_bo_alloc(i965->intel.bufmgr,
5040 pp_context->curbe.bo = bo;
5042 dri_bo_unreference(pp_context->idrt.bo);
5043 bo = dri_bo_alloc(i965->intel.bufmgr,
5044 "interface discriptor",
5045 sizeof(struct gen6_interface_descriptor_data),
5048 pp_context->idrt.bo = bo;
5049 pp_context->idrt.num_interface_descriptors = 0;
5051 dri_bo_unreference(pp_context->sampler_state_table.bo);
5052 bo = dri_bo_alloc(i965->intel.bufmgr,
5053 "sampler state table",
5057 dri_bo_map(bo, True);
5058 memset(bo->virtual, 0, bo->size);
5060 pp_context->sampler_state_table.bo = bo;
5062 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
5063 bo = dri_bo_alloc(i965->intel.bufmgr,
5064 "sampler 8x8 state ",
5068 pp_context->sampler_state_table.bo_8x8 = bo;
5070 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
5071 bo = dri_bo_alloc(i965->intel.bufmgr,
5072 "sampler 8x8 state ",
5076 pp_context->sampler_state_table.bo_8x8_uv = bo;
5078 dri_bo_unreference(pp_context->vfe_state.bo);
5079 bo = dri_bo_alloc(i965->intel.bufmgr,
5081 sizeof(struct i965_vfe_state),
5084 pp_context->vfe_state.bo = bo;
5086 if (IS_GEN7(i965->intel.device_id)) {
5087 static_param_size = sizeof(struct gen7_pp_static_parameter);
5088 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
5090 static_param_size = sizeof(struct pp_static_parameter);
5091 inline_param_size = sizeof(struct pp_inline_parameter);
5094 memset(pp_context->pp_static_parameter, 0, static_param_size);
5095 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
5097 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
5098 pp_context->current_pp = pp_index;
5099 pp_module = &pp_context->pp_modules[pp_index];
5101 if (pp_module->initialize)
5102 va_status = pp_module->initialize(ctx, pp_context,
5109 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
5111 calculate_boundary_block_mask(pp_context, dst_rect);
5119 VADriverContextP ctx,
5120 struct i965_post_processing_context *pp_context,
5121 const struct i965_surface *src_surface,
5122 const VARectangle *src_rect,
5123 struct i965_surface *dst_surface,
5124 const VARectangle *dst_rect,
5130 struct i965_driver_data *i965 = i965_driver_data(ctx);
5131 struct pp_module *pp_module;
5133 int static_param_size, inline_param_size;
5135 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
5136 bo = dri_bo_alloc(i965->intel.bufmgr,
5137 "surface state & binding table",
5138 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
5141 pp_context->surface_state_binding_table.bo = bo;
5143 dri_bo_unreference(pp_context->curbe.bo);
5144 bo = dri_bo_alloc(i965->intel.bufmgr,
5149 pp_context->curbe.bo = bo;
5151 dri_bo_unreference(pp_context->idrt.bo);
5152 bo = dri_bo_alloc(i965->intel.bufmgr,
5153 "interface discriptor",
5154 sizeof(struct gen8_interface_descriptor_data),
5157 pp_context->idrt.bo = bo;
5158 pp_context->idrt.num_interface_descriptors = 0;
5160 dri_bo_unreference(pp_context->sampler_state_table.bo);
5161 bo = dri_bo_alloc(i965->intel.bufmgr,
5162 "sampler 8x8 state ",
5166 pp_context->sampler_state_table.bo = bo;
5169 dri_bo_unreference(pp_context->vfe_state.bo);
5170 bo = dri_bo_alloc(i965->intel.bufmgr,
5172 sizeof(struct i965_vfe_state),
5175 pp_context->vfe_state.bo = bo;
5177 static_param_size = sizeof(struct gen7_pp_static_parameter);
5178 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
5180 memset(pp_context->pp_static_parameter, 0, static_param_size);
5181 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
5183 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
5184 pp_context->current_pp = pp_index;
5185 pp_module = &pp_context->pp_modules[pp_index];
5187 if (pp_module->initialize)
5188 va_status = pp_module->initialize(ctx, pp_context,
5195 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
5197 calculate_boundary_block_mask(pp_context, dst_rect);
5203 gen6_pp_interface_descriptor_table(VADriverContextP ctx,
5204 struct i965_post_processing_context *pp_context)
5206 struct i965_driver_data *i965 = i965_driver_data(ctx);
5207 struct gen6_interface_descriptor_data *desc;
5209 int pp_index = pp_context->current_pp;
5211 bo = pp_context->idrt.bo;
5212 dri_bo_map(bo, True);
5213 assert(bo->virtual);
5215 memset(desc, 0, sizeof(*desc));
5216 desc->desc0.kernel_start_pointer =
5217 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
5218 desc->desc1.single_program_flow = 1;
5219 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
5220 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
5221 desc->desc2.sampler_state_pointer =
5222 pp_context->sampler_state_table.bo->offset >> 5;
5223 desc->desc3.binding_table_entry_count = 0;
5224 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
5225 desc->desc4.constant_urb_entry_read_offset = 0;
5227 if (IS_GEN7(i965->intel.device_id))
5228 desc->desc4.constant_urb_entry_read_length = 6; /* grf 1-6 */
5230 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
5232 dri_bo_emit_reloc(bo,
5233 I915_GEM_DOMAIN_INSTRUCTION, 0,
5235 offsetof(struct gen6_interface_descriptor_data, desc0),
5236 pp_context->pp_modules[pp_index].kernel.bo);
5238 dri_bo_emit_reloc(bo,
5239 I915_GEM_DOMAIN_INSTRUCTION, 0,
5240 desc->desc2.sampler_count << 2,
5241 offsetof(struct gen6_interface_descriptor_data, desc2),
5242 pp_context->sampler_state_table.bo);
5245 pp_context->idrt.num_interface_descriptors++;
5249 gen8_pp_interface_descriptor_table(VADriverContextP ctx,
5250 struct i965_post_processing_context *pp_context)
5252 struct gen8_interface_descriptor_data *desc;
5254 int pp_index = pp_context->current_pp;
5256 bo = pp_context->idrt.bo;
5257 dri_bo_map(bo, True);
5258 assert(bo->virtual);
5260 memset(desc, 0, sizeof(*desc));
5261 desc->desc0.kernel_start_pointer =
5262 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
5263 desc->desc2.single_program_flow = 1;
5264 desc->desc2.floating_point_mode = FLOATING_POINT_IEEE_754;
5265 desc->desc3.sampler_count = 1; /* 1 - 4 samplers used */
5266 desc->desc3.sampler_state_pointer =
5267 pp_context->sampler_state_table.bo->offset >> 5;
5268 desc->desc4.binding_table_entry_count = 0;
5269 desc->desc4.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
5270 desc->desc5.constant_urb_entry_read_offset = 0;
5272 desc->desc5.constant_urb_entry_read_length = 6; /* grf 1-6 */
5274 dri_bo_emit_reloc(bo,
5275 I915_GEM_DOMAIN_INSTRUCTION, 0,
5277 offsetof(struct gen8_interface_descriptor_data, desc0),
5278 pp_context->pp_modules[pp_index].kernel.bo);
5280 dri_bo_emit_reloc(bo,
5281 I915_GEM_DOMAIN_INSTRUCTION, 0,
5282 desc->desc3.sampler_count << 2,
5283 offsetof(struct gen8_interface_descriptor_data, desc3),
5284 pp_context->sampler_state_table.bo);
5287 pp_context->idrt.num_interface_descriptors++;
5291 gen6_pp_upload_constants(VADriverContextP ctx,
5292 struct i965_post_processing_context *pp_context)
5294 struct i965_driver_data *i965 = i965_driver_data(ctx);
5295 unsigned char *constant_buffer;
5298 assert(sizeof(struct pp_static_parameter) == 128);
5299 assert(sizeof(struct gen7_pp_static_parameter) == 192);
5301 if (IS_GEN7(i965->intel.device_id) ||
5302 IS_GEN8(i965->intel.device_id))
5303 param_size = sizeof(struct gen7_pp_static_parameter);
5305 param_size = sizeof(struct pp_static_parameter);
5307 dri_bo_map(pp_context->curbe.bo, 1);
5308 assert(pp_context->curbe.bo->virtual);
5309 constant_buffer = pp_context->curbe.bo->virtual;
5310 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
5311 dri_bo_unmap(pp_context->curbe.bo);
5315 gen6_pp_states_setup(VADriverContextP ctx,
5316 struct i965_post_processing_context *pp_context)
5318 gen6_pp_interface_descriptor_table(ctx, pp_context);
5319 gen6_pp_upload_constants(ctx, pp_context);
5323 gen8_pp_states_setup(VADriverContextP ctx,
5324 struct i965_post_processing_context *pp_context)
5326 gen8_pp_interface_descriptor_table(ctx, pp_context);
5327 gen6_pp_upload_constants(ctx, pp_context);
5331 gen6_pp_pipeline_select(VADriverContextP ctx,
5332 struct i965_post_processing_context *pp_context)
5334 struct intel_batchbuffer *batch = pp_context->batch;
5336 BEGIN_BATCH(batch, 1);
5337 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
5338 ADVANCE_BATCH(batch);
5342 gen6_pp_state_base_address(VADriverContextP ctx,
5343 struct i965_post_processing_context *pp_context)
5345 struct intel_batchbuffer *batch = pp_context->batch;
5347 BEGIN_BATCH(batch, 10);
5348 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
5349 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5350 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
5351 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5352 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5353 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5354 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5355 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5356 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5357 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5358 ADVANCE_BATCH(batch);
5362 gen8_pp_state_base_address(VADriverContextP ctx,
5363 struct i965_post_processing_context *pp_context)
5365 struct intel_batchbuffer *batch = pp_context->batch;
5367 BEGIN_BATCH(batch, 16);
5368 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (16 - 2));
5369 /* DW1 Generate state address */
5370 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5371 OUT_BATCH(batch, 0);
5372 OUT_BATCH(batch, 0);
5373 /* DW4. Surface state address */
5374 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
5375 OUT_BATCH(batch, 0);
5376 /* DW6. Dynamic state address */
5377 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5378 OUT_BATCH(batch, 0);
5380 /* DW8. Indirect object address */
5381 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5382 OUT_BATCH(batch, 0);
5384 /* DW10. Instruction base address */
5385 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
5386 OUT_BATCH(batch, 0);
5388 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
5389 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
5390 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
5391 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
5392 ADVANCE_BATCH(batch);
5396 gen6_pp_vfe_state(VADriverContextP ctx,
5397 struct i965_post_processing_context *pp_context)
5399 struct intel_batchbuffer *batch = pp_context->batch;
5401 BEGIN_BATCH(batch, 8);
5402 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
5403 OUT_BATCH(batch, 0);
5405 (pp_context->vfe_gpu_state.max_num_threads - 1) << 16 |
5406 pp_context->vfe_gpu_state.num_urb_entries << 8);
5407 OUT_BATCH(batch, 0);
5409 (pp_context->vfe_gpu_state.urb_entry_size) << 16 |
5410 /* URB Entry Allocation Size, in 256 bits unit */
5411 (pp_context->vfe_gpu_state.curbe_allocation_size));
5412 /* CURBE Allocation Size, in 256 bits unit */
5413 OUT_BATCH(batch, 0);
5414 OUT_BATCH(batch, 0);
5415 OUT_BATCH(batch, 0);
5416 ADVANCE_BATCH(batch);
5420 gen8_pp_vfe_state(VADriverContextP ctx,
5421 struct i965_post_processing_context *pp_context)
5423 struct intel_batchbuffer *batch = pp_context->batch;
5425 BEGIN_BATCH(batch, 9);
5426 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (9 - 2));
5427 OUT_BATCH(batch, 0);
5428 OUT_BATCH(batch, 0);
5430 (pp_context->vfe_gpu_state.max_num_threads - 1) << 16 |
5431 pp_context->vfe_gpu_state.num_urb_entries << 8);
5432 OUT_BATCH(batch, 0);
5434 (pp_context->vfe_gpu_state.urb_entry_size) << 16 |
5435 /* URB Entry Allocation Size, in 256 bits unit */
5436 (pp_context->vfe_gpu_state.curbe_allocation_size));
5437 /* CURBE Allocation Size, in 256 bits unit */
5438 OUT_BATCH(batch, 0);
5439 OUT_BATCH(batch, 0);
5440 OUT_BATCH(batch, 0);
5441 ADVANCE_BATCH(batch);
5445 gen6_pp_curbe_load(VADriverContextP ctx,
5446 struct i965_post_processing_context *pp_context)
5448 struct intel_batchbuffer *batch = pp_context->batch;
5449 struct i965_driver_data *i965 = i965_driver_data(ctx);
5452 if (IS_GEN7(i965->intel.device_id) ||
5453 IS_GEN8(i965->intel.device_id))
5454 param_size = sizeof(struct gen7_pp_static_parameter);
5456 param_size = sizeof(struct pp_static_parameter);
5458 BEGIN_BATCH(batch, 4);
5459 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
5460 OUT_BATCH(batch, 0);
5464 pp_context->curbe.bo,
5465 I915_GEM_DOMAIN_INSTRUCTION, 0,
5467 ADVANCE_BATCH(batch);
5471 gen6_interface_descriptor_load(VADriverContextP ctx,
5472 struct i965_post_processing_context *pp_context)
5474 struct intel_batchbuffer *batch = pp_context->batch;
5476 BEGIN_BATCH(batch, 4);
5477 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
5478 OUT_BATCH(batch, 0);
5480 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
5482 pp_context->idrt.bo,
5483 I915_GEM_DOMAIN_INSTRUCTION, 0,
5485 ADVANCE_BATCH(batch);
5489 gen8_interface_descriptor_load(VADriverContextP ctx,
5490 struct i965_post_processing_context *pp_context)
5492 struct intel_batchbuffer *batch = pp_context->batch;
5494 BEGIN_BATCH(batch, 4);
5495 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
5496 OUT_BATCH(batch, 0);
5498 pp_context->idrt.num_interface_descriptors * sizeof(struct gen8_interface_descriptor_data));
5500 pp_context->idrt.bo,
5501 I915_GEM_DOMAIN_INSTRUCTION, 0,
5503 ADVANCE_BATCH(batch);
5506 static void update_block_mask_parameter(struct i965_post_processing_context *pp_context, int x, int y, int x_steps, int y_steps)
5508 struct pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
5510 pp_inline_parameter->grf5.block_vertical_mask = 0xff;
5511 pp_inline_parameter->grf6.block_vertical_mask_bottom = pp_context->block_vertical_mask_bottom;
5512 // for the first block, it always on the left edge. the second block will reload horizontal_mask from grf6.block_horizontal_mask_middle
5513 pp_inline_parameter->grf5.block_horizontal_mask = pp_context->block_horizontal_mask_left;
5514 pp_inline_parameter->grf6.block_horizontal_mask_middle = 0xffff;
5515 pp_inline_parameter->grf6.block_horizontal_mask_right = pp_context->block_horizontal_mask_right;
5519 if (y == y_steps-1) {
5520 pp_inline_parameter->grf5.block_vertical_mask = pp_context->block_vertical_mask_bottom;
5523 pp_inline_parameter->grf6.block_vertical_mask_bottom = 0xff;
5529 if (x == 0) { // all blocks in this group are on the left edge
5530 pp_inline_parameter->grf6.block_horizontal_mask_middle = pp_context->block_horizontal_mask_left;
5531 pp_inline_parameter->grf6.block_horizontal_mask_right = pp_context->block_horizontal_mask_left;
5533 else if (x == x_steps-1) {
5534 pp_inline_parameter->grf5.block_horizontal_mask = pp_context->block_horizontal_mask_right;
5535 pp_inline_parameter->grf6.block_horizontal_mask_middle = pp_context->block_horizontal_mask_right;
5538 pp_inline_parameter->grf5.block_horizontal_mask = 0xffff;
5539 pp_inline_parameter->grf6.block_horizontal_mask_middle = 0xffff;
5540 pp_inline_parameter->grf6.block_horizontal_mask_right = 0xffff;
5547 gen6_pp_object_walker(VADriverContextP ctx,
5548 struct i965_post_processing_context *pp_context)
5550 struct i965_driver_data *i965 = i965_driver_data(ctx);
5551 struct intel_batchbuffer *batch = pp_context->batch;
5552 int x, x_steps, y, y_steps;
5553 int param_size, command_length_in_dws;
5554 dri_bo *command_buffer;
5555 unsigned int *command_ptr;
5557 if (IS_GEN7(i965->intel.device_id) ||
5558 IS_GEN8(i965->intel.device_id))
5559 param_size = sizeof(struct gen7_pp_inline_parameter);
5561 param_size = sizeof(struct pp_inline_parameter);
5563 x_steps = pp_context->pp_x_steps(pp_context->private_context);
5564 y_steps = pp_context->pp_y_steps(pp_context->private_context);
5565 command_length_in_dws = 6 + (param_size >> 2);
5566 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
5567 "command objects buffer",
5568 command_length_in_dws * 4 * x_steps * y_steps + 8,
5571 dri_bo_map(command_buffer, 1);
5572 command_ptr = command_buffer->virtual;
5574 for (y = 0; y < y_steps; y++) {
5575 for (x = 0; x < x_steps; x++) {
5576 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
5577 // some common block parameter update goes here, apply to all pp functions
5578 if (IS_GEN6(i965->intel.device_id))
5579 update_block_mask_parameter (pp_context, x, y, x_steps, y_steps);
5581 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
5587 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
5588 command_ptr += (param_size >> 2);
5593 if (command_length_in_dws * x_steps * y_steps % 2 == 0)
5596 *command_ptr = MI_BATCH_BUFFER_END;
5598 dri_bo_unmap(command_buffer);
5600 if (IS_GEN8(i965->intel.device_id)) {
5601 BEGIN_BATCH(batch, 3);
5602 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (1 << 8) | (1 << 0));
5603 OUT_RELOC(batch, command_buffer,
5604 I915_GEM_DOMAIN_COMMAND, 0,
5606 OUT_BATCH(batch, 0);
5607 ADVANCE_BATCH(batch);
5609 BEGIN_BATCH(batch, 2);
5610 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (2 << 6));
5611 OUT_RELOC(batch, command_buffer,
5612 I915_GEM_DOMAIN_COMMAND, 0,
5614 ADVANCE_BATCH(batch);
5617 dri_bo_unreference(command_buffer);
5619 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
5620 * will cause control to pass back to ring buffer
5622 intel_batchbuffer_end_atomic(batch);
5623 intel_batchbuffer_flush(batch);
5624 intel_batchbuffer_start_atomic(batch, 0x1000);
5628 gen6_pp_pipeline_setup(VADriverContextP ctx,
5629 struct i965_post_processing_context *pp_context)
5631 struct intel_batchbuffer *batch = pp_context->batch;
5633 intel_batchbuffer_start_atomic(batch, 0x1000);
5634 intel_batchbuffer_emit_mi_flush(batch);
5635 gen6_pp_pipeline_select(ctx, pp_context);
5636 gen6_pp_state_base_address(ctx, pp_context);
5637 gen6_pp_vfe_state(ctx, pp_context);
5638 gen6_pp_curbe_load(ctx, pp_context);
5639 gen6_interface_descriptor_load(ctx, pp_context);
5640 gen6_pp_object_walker(ctx, pp_context);
5641 intel_batchbuffer_end_atomic(batch);
5645 gen8_pp_pipeline_setup(VADriverContextP ctx,
5646 struct i965_post_processing_context *pp_context)
5648 struct intel_batchbuffer *batch = pp_context->batch;
5650 intel_batchbuffer_start_atomic(batch, 0x1000);
5651 intel_batchbuffer_emit_mi_flush(batch);
5652 gen6_pp_pipeline_select(ctx, pp_context);
5653 gen8_pp_state_base_address(ctx, pp_context);
5654 gen8_pp_vfe_state(ctx, pp_context);
5655 gen6_pp_curbe_load(ctx, pp_context);
5656 gen8_interface_descriptor_load(ctx, pp_context);
5657 gen8_pp_vfe_state(ctx, pp_context);
5658 gen6_pp_object_walker(ctx, pp_context);
5659 intel_batchbuffer_end_atomic(batch);
5663 gen6_post_processing(
5664 VADriverContextP ctx,
5665 struct i965_post_processing_context *pp_context,
5666 const struct i965_surface *src_surface,
5667 const VARectangle *src_rect,
5668 struct i965_surface *dst_surface,
5669 const VARectangle *dst_rect,
5676 va_status = gen6_pp_initialize(ctx, pp_context,
5684 if (va_status == VA_STATUS_SUCCESS) {
5685 gen6_pp_states_setup(ctx, pp_context);
5686 gen6_pp_pipeline_setup(ctx, pp_context);
5689 if (va_status == VA_STATUS_SUCCESS_1)
5690 va_status = VA_STATUS_SUCCESS;
5696 gen8_post_processing(
5697 VADriverContextP ctx,
5698 struct i965_post_processing_context *pp_context,
5699 const struct i965_surface *src_surface,
5700 const VARectangle *src_rect,
5701 struct i965_surface *dst_surface,
5702 const VARectangle *dst_rect,
5709 va_status = gen8_pp_initialize(ctx, pp_context,
5717 if (va_status == VA_STATUS_SUCCESS) {
5718 gen8_pp_states_setup(ctx, pp_context);
5719 gen8_pp_pipeline_setup(ctx, pp_context);
5726 i965_post_processing_internal(
5727 VADriverContextP ctx,
5728 struct i965_post_processing_context *pp_context,
5729 const struct i965_surface *src_surface,
5730 const VARectangle *src_rect,
5731 struct i965_surface *dst_surface,
5732 const VARectangle *dst_rect,
5738 struct i965_driver_data *i965 = i965_driver_data(ctx);
5740 if (IS_GEN8(i965->intel.device_id))
5741 va_status = gen8_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
5742 else if (IS_GEN6(i965->intel.device_id) ||
5743 IS_GEN7(i965->intel.device_id))
5744 va_status = gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
5746 va_status = ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
5752 rgb_to_yuv(unsigned int argb,
5758 int r = ((argb >> 16) & 0xff);
5759 int g = ((argb >> 8) & 0xff);
5760 int b = ((argb >> 0) & 0xff);
5762 *y = (257 * r + 504 * g + 98 * b) / 1000 + 16;
5763 *v = (439 * r - 368 * g - 71 * b) / 1000 + 128;
5764 *u = (-148 * r - 291 * g + 439 * b) / 1000 + 128;
5765 *a = ((argb >> 24) & 0xff);
5769 i965_vpp_clear_surface(VADriverContextP ctx,
5770 struct i965_post_processing_context *pp_context,
5771 struct object_surface *obj_surface,
5774 struct i965_driver_data *i965 = i965_driver_data(ctx);
5775 struct intel_batchbuffer *batch = pp_context->batch;
5776 unsigned int blt_cmd, br13;
5777 unsigned int tiling = 0, swizzle = 0;
5779 unsigned char y, u, v, a = 0;
5780 int region_width, region_height;
5782 /* Currently only support NV12 surface */
5783 if (!obj_surface || obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
5786 rgb_to_yuv(color, &y, &u, &v, &a);
5791 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5792 blt_cmd = XY_COLOR_BLT_CMD;
5793 pitch = obj_surface->width;
5795 if (tiling != I915_TILING_NONE) {
5796 assert(tiling == I915_TILING_Y);
5797 // blt_cmd |= XY_COLOR_BLT_DST_TILED;
5805 if (IS_GEN6(i965->intel.device_id) ||
5806 IS_GEN7(i965->intel.device_id) ||
5807 IS_GEN8(i965->intel.device_id)) {
5808 intel_batchbuffer_start_atomic_blt(batch, 48);
5809 BEGIN_BLT_BATCH(batch, 12);
5811 intel_batchbuffer_start_atomic(batch, 48);
5812 BEGIN_BATCH(batch, 12);
5815 region_width = obj_surface->width;
5816 region_height = obj_surface->height;
5818 OUT_BATCH(batch, blt_cmd);
5819 OUT_BATCH(batch, br13);
5824 region_height << 16 |
5826 OUT_RELOC(batch, obj_surface->bo,
5827 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
5829 OUT_BATCH(batch, y);
5835 region_width = obj_surface->width / 2;
5836 region_height = obj_surface->height / 2;
5838 if (tiling == I915_TILING_Y) {
5839 region_height = ALIGN(obj_surface->height / 2, 32);
5842 OUT_BATCH(batch, blt_cmd);
5843 OUT_BATCH(batch, br13);
5848 region_height << 16 |
5850 OUT_RELOC(batch, obj_surface->bo,
5851 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
5852 obj_surface->width * obj_surface->y_cb_offset);
5853 OUT_BATCH(batch, v << 8 | u);
5855 ADVANCE_BATCH(batch);
5856 intel_batchbuffer_end_atomic(batch);
5860 i965_scaling_processing(
5861 VADriverContextP ctx,
5862 struct object_surface *src_surface_obj,
5863 const VARectangle *src_rect,
5864 struct object_surface *dst_surface_obj,
5865 const VARectangle *dst_rect,
5868 VAStatus va_status = VA_STATUS_SUCCESS;
5869 struct i965_driver_data *i965 = i965_driver_data(ctx);
5871 assert(src_surface_obj->fourcc == VA_FOURCC('N', 'V', '1', '2'));
5872 assert(dst_surface_obj->fourcc == VA_FOURCC('N', 'V', '1', '2'));
5874 if (HAS_PP(i965) && (flags & I965_PP_FLAG_AVS)) {
5875 struct i965_surface src_surface;
5876 struct i965_surface dst_surface;
5878 _i965LockMutex(&i965->pp_mutex);
5880 src_surface.base = (struct object_base *)src_surface_obj;
5881 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5882 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5883 dst_surface.base = (struct object_base *)dst_surface_obj;
5884 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5885 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5887 va_status = i965_post_processing_internal(ctx, i965->pp_context,
5895 _i965UnlockMutex(&i965->pp_mutex);
5902 i965_post_processing(
5903 VADriverContextP ctx,
5904 struct object_surface *obj_surface,
5905 const VARectangle *src_rect,
5906 const VARectangle *dst_rect,
5908 int *has_done_scaling
5911 struct i965_driver_data *i965 = i965_driver_data(ctx);
5912 VASurfaceID out_surface_id = VA_INVALID_ID;
5913 VASurfaceID tmp_id = VA_INVALID_ID;
5915 *has_done_scaling = 0;
5919 struct i965_surface src_surface;
5920 struct i965_surface dst_surface;
5922 /* Currently only support post processing for NV12 surface */
5923 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
5924 return out_surface_id;
5926 _i965LockMutex(&i965->pp_mutex);
5928 if (flags & I965_PP_FLAG_MCDI) {
5929 src_surface.base = (struct object_base *)obj_surface;
5930 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5931 src_surface.flags = (flags & I965_PP_FLAG_TOP_FIELD) ?
5932 I965_SURFACE_FLAG_TOP_FIELD_FIRST : I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST;
5934 status = i965_CreateSurfaces(ctx,
5935 obj_surface->orig_width,
5936 obj_surface->orig_height,
5937 VA_RT_FORMAT_YUV420,
5940 assert(status == VA_STATUS_SUCCESS);
5941 obj_surface = SURFACE(out_surface_id);
5942 assert(obj_surface);
5943 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
5944 i965_vpp_clear_surface(ctx, i965->pp_context, obj_surface, 0);
5946 dst_surface.base = (struct object_base *)obj_surface;
5947 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5948 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5950 i965_post_processing_internal(ctx, i965->pp_context,
5959 if (flags & I965_PP_FLAG_AVS) {
5960 struct i965_render_state *render_state = &i965->render_state;
5961 struct intel_region *dest_region = render_state->draw_region;
5963 if (out_surface_id != VA_INVALID_ID)
5964 tmp_id = out_surface_id;
5966 src_surface.base = (struct object_base *)obj_surface;
5967 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5968 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5970 status = i965_CreateSurfaces(ctx,
5972 dest_region->height,
5973 VA_RT_FORMAT_YUV420,
5976 assert(status == VA_STATUS_SUCCESS);
5977 obj_surface = SURFACE(out_surface_id);
5978 assert(obj_surface);
5979 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
5980 i965_vpp_clear_surface(ctx, i965->pp_context, obj_surface, 0);
5982 dst_surface.base = (struct object_base *)obj_surface;
5983 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5984 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5986 i965_post_processing_internal(ctx, i965->pp_context,
5994 if (tmp_id != VA_INVALID_ID)
5995 i965_DestroySurfaces(ctx, &tmp_id, 1);
5997 *has_done_scaling = 1;
6000 _i965UnlockMutex(&i965->pp_mutex);
6003 return out_surface_id;
6007 i965_image_pl2_processing(VADriverContextP ctx,
6008 const struct i965_surface *src_surface,
6009 const VARectangle *src_rect,
6010 struct i965_surface *dst_surface,
6011 const VARectangle *dst_rect);
6014 i965_image_plx_nv12_plx_processing(VADriverContextP ctx,
6015 VAStatus (*i965_image_plx_nv12_processing)(
6017 const struct i965_surface *,
6018 const VARectangle *,
6019 struct i965_surface *,
6020 const VARectangle *),
6021 const struct i965_surface *src_surface,
6022 const VARectangle *src_rect,
6023 struct i965_surface *dst_surface,
6024 const VARectangle *dst_rect)
6026 struct i965_driver_data *i965 = i965_driver_data(ctx);
6028 VASurfaceID tmp_surface_id = VA_INVALID_SURFACE;
6029 struct object_surface *obj_surface = NULL;
6030 struct i965_surface tmp_surface;
6033 pp_get_surface_size(ctx, dst_surface, &width, &height);
6034 status = i965_CreateSurfaces(ctx,
6037 VA_RT_FORMAT_YUV420,
6040 assert(status == VA_STATUS_SUCCESS);
6041 obj_surface = SURFACE(tmp_surface_id);
6042 assert(obj_surface);
6043 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
6045 tmp_surface.base = (struct object_base *)obj_surface;
6046 tmp_surface.type = I965_SURFACE_TYPE_SURFACE;
6047 tmp_surface.flags = I965_SURFACE_FLAG_FRAME;
6049 status = i965_image_plx_nv12_processing(ctx,
6055 if (status == VA_STATUS_SUCCESS)
6056 status = i965_image_pl2_processing(ctx,
6062 i965_DestroySurfaces(ctx,
6071 i965_image_pl1_rgbx_processing(VADriverContextP ctx,
6072 const struct i965_surface *src_surface,
6073 const VARectangle *src_rect,
6074 struct i965_surface *dst_surface,
6075 const VARectangle *dst_rect)
6077 struct i965_driver_data *i965 = i965_driver_data(ctx);
6078 struct i965_post_processing_context *pp_context = i965->pp_context;
6079 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
6083 case VA_FOURCC('N', 'V', '1', '2'):
6084 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6089 PP_RGBX_LOAD_SAVE_NV12,
6091 intel_batchbuffer_flush(pp_context->batch);
6095 vaStatus = i965_image_plx_nv12_plx_processing(ctx,
6096 i965_image_pl1_rgbx_processing,
6108 i965_image_pl3_processing(VADriverContextP ctx,
6109 const struct i965_surface *src_surface,
6110 const VARectangle *src_rect,
6111 struct i965_surface *dst_surface,
6112 const VARectangle *dst_rect)
6114 struct i965_driver_data *i965 = i965_driver_data(ctx);
6115 struct i965_post_processing_context *pp_context = i965->pp_context;
6116 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
6117 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
6120 case VA_FOURCC('N', 'V', '1', '2'):
6121 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6126 PP_PL3_LOAD_SAVE_N12,
6128 intel_batchbuffer_flush(pp_context->batch);
6131 case VA_FOURCC('I', 'M', 'C', '1'):
6132 case VA_FOURCC('I', 'M', 'C', '3'):
6133 case VA_FOURCC('Y', 'V', '1', '2'):
6134 case VA_FOURCC('I', '4', '2', '0'):
6135 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6140 PP_PL3_LOAD_SAVE_PL3,
6142 intel_batchbuffer_flush(pp_context->batch);
6145 case VA_FOURCC('Y', 'U', 'Y', '2'):
6146 case VA_FOURCC('U', 'Y', 'V', 'Y'):
6147 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6152 PP_PL3_LOAD_SAVE_PA,
6154 intel_batchbuffer_flush(pp_context->batch);
6158 vaStatus = i965_image_plx_nv12_plx_processing(ctx,
6159 i965_image_pl3_processing,
6171 i965_image_pl2_processing(VADriverContextP ctx,
6172 const struct i965_surface *src_surface,
6173 const VARectangle *src_rect,
6174 struct i965_surface *dst_surface,
6175 const VARectangle *dst_rect)
6177 struct i965_driver_data *i965 = i965_driver_data(ctx);
6178 struct i965_post_processing_context *pp_context = i965->pp_context;
6179 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
6180 VAStatus vaStatus = VA_STATUS_ERROR_UNIMPLEMENTED;
6183 case VA_FOURCC('N', 'V', '1', '2'):
6184 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6189 PP_NV12_LOAD_SAVE_N12,
6193 case VA_FOURCC('I', 'M', 'C', '1'):
6194 case VA_FOURCC('I', 'M', 'C', '3'):
6195 case VA_FOURCC('Y', 'V', '1', '2'):
6196 case VA_FOURCC('I', '4', '2', '0'):
6197 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6202 PP_NV12_LOAD_SAVE_PL3,
6206 case VA_FOURCC('Y', 'U', 'Y', '2'):
6207 case VA_FOURCC('U', 'Y', 'V', 'Y'):
6208 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6213 PP_NV12_LOAD_SAVE_PA,
6217 case VA_FOURCC('B', 'G', 'R', 'X'):
6218 case VA_FOURCC('B', 'G', 'R', 'A'):
6219 case VA_FOURCC('R', 'G', 'B', 'X'):
6220 case VA_FOURCC('R', 'G', 'B', 'A'):
6221 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6226 PP_NV12_LOAD_SAVE_RGBX,
6231 return VA_STATUS_ERROR_UNIMPLEMENTED;
6234 intel_batchbuffer_flush(pp_context->batch);
6240 i965_image_pl1_processing(VADriverContextP ctx,
6241 const struct i965_surface *src_surface,
6242 const VARectangle *src_rect,
6243 struct i965_surface *dst_surface,
6244 const VARectangle *dst_rect)
6246 struct i965_driver_data *i965 = i965_driver_data(ctx);
6247 struct i965_post_processing_context *pp_context = i965->pp_context;
6248 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
6252 case VA_FOURCC('N', 'V', '1', '2'):
6253 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6258 PP_PA_LOAD_SAVE_NV12,
6260 intel_batchbuffer_flush(pp_context->batch);
6263 case VA_FOURCC('Y', 'V', '1', '2'):
6264 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6269 PP_PA_LOAD_SAVE_PL3,
6271 intel_batchbuffer_flush(pp_context->batch);
6274 case VA_FOURCC('Y', 'U', 'Y', '2'):
6275 case VA_FOURCC('U', 'Y', 'V', 'Y'):
6276 vaStatus = i965_post_processing_internal(ctx, i965->pp_context,
6283 intel_batchbuffer_flush(pp_context->batch);
6287 vaStatus = i965_image_plx_nv12_plx_processing(ctx,
6288 i965_image_pl1_processing,
6300 i965_image_processing(VADriverContextP ctx,
6301 const struct i965_surface *src_surface,
6302 const VARectangle *src_rect,
6303 struct i965_surface *dst_surface,
6304 const VARectangle *dst_rect)
6306 struct i965_driver_data *i965 = i965_driver_data(ctx);
6307 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
6310 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
6312 _i965LockMutex(&i965->pp_mutex);
6315 case VA_FOURCC('Y', 'V', '1', '2'):
6316 case VA_FOURCC('I', '4', '2', '0'):
6317 case VA_FOURCC('I', 'M', 'C', '1'):
6318 case VA_FOURCC('I', 'M', 'C', '3'):
6319 case VA_FOURCC('4', '2', '2', 'H'):
6320 case VA_FOURCC('4', '2', '2', 'V'):
6321 case VA_FOURCC('4', '1', '1', 'P'):
6322 case VA_FOURCC('4', '4', '4', 'P'):
6323 status = i965_image_pl3_processing(ctx,
6330 case VA_FOURCC('N', 'V', '1', '2'):
6331 status = i965_image_pl2_processing(ctx,
6337 case VA_FOURCC('Y', 'U', 'Y', '2'):
6338 case VA_FOURCC('U', 'Y', 'V', 'Y'):
6339 status = i965_image_pl1_processing(ctx,
6345 case VA_FOURCC('B', 'G', 'R', 'A'):
6346 case VA_FOURCC('B', 'G', 'R', 'X'):
6347 case VA_FOURCC('R', 'G', 'B', 'A'):
6348 case VA_FOURCC('R', 'G', 'B', 'X'):
6349 status = i965_image_pl1_rgbx_processing(ctx,
6356 status = VA_STATUS_ERROR_UNIMPLEMENTED;
6360 _i965UnlockMutex(&i965->pp_mutex);
6367 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
6371 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
6372 pp_context->surface_state_binding_table.bo = NULL;
6374 dri_bo_unreference(pp_context->curbe.bo);
6375 pp_context->curbe.bo = NULL;
6377 dri_bo_unreference(pp_context->sampler_state_table.bo);
6378 pp_context->sampler_state_table.bo = NULL;
6380 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
6381 pp_context->sampler_state_table.bo_8x8 = NULL;
6383 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
6384 pp_context->sampler_state_table.bo_8x8_uv = NULL;
6386 dri_bo_unreference(pp_context->idrt.bo);
6387 pp_context->idrt.bo = NULL;
6388 pp_context->idrt.num_interface_descriptors = 0;
6390 dri_bo_unreference(pp_context->vfe_state.bo);
6391 pp_context->vfe_state.bo = NULL;
6393 dri_bo_unreference(pp_context->pp_dndi_context.stmm_bo);
6394 pp_context->pp_dndi_context.stmm_bo = NULL;
6396 dri_bo_unreference(pp_context->pp_dn_context.stmm_bo);
6397 pp_context->pp_dn_context.stmm_bo = NULL;
6399 for (i = 0; i < NUM_PP_MODULES; i++) {
6400 struct pp_module *pp_module = &pp_context->pp_modules[i];
6402 dri_bo_unreference(pp_module->kernel.bo);
6403 pp_module->kernel.bo = NULL;
6406 free(pp_context->pp_static_parameter);
6407 free(pp_context->pp_inline_parameter);
6408 pp_context->pp_static_parameter = NULL;
6409 pp_context->pp_inline_parameter = NULL;
6413 i965_post_processing_terminate(VADriverContextP ctx)
6415 struct i965_driver_data *i965 = i965_driver_data(ctx);
6416 struct i965_post_processing_context *pp_context = i965->pp_context;
6419 i965_post_processing_context_finalize(pp_context);
6423 i965->pp_context = NULL;
6426 #define VPP_CURBE_ALLOCATION_SIZE 32
6429 i965_post_processing_context_init(VADriverContextP ctx,
6430 struct i965_post_processing_context *pp_context,
6431 struct intel_batchbuffer *batch)
6433 struct i965_driver_data *i965 = i965_driver_data(ctx);
6436 if (IS_IRONLAKE(i965->intel.device_id)) {
6437 pp_context->urb.size = URB_SIZE((&i965->intel));
6438 pp_context->urb.num_vfe_entries = 32;
6439 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
6440 pp_context->urb.num_cs_entries = 1;
6441 pp_context->urb.size_cs_entry = 2;
6442 pp_context->urb.vfe_start = 0;
6443 pp_context->urb.cs_start = pp_context->urb.vfe_start +
6444 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
6445 assert(pp_context->urb.cs_start +
6446 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
6448 pp_context->vfe_gpu_state.max_num_threads = 60;
6449 pp_context->vfe_gpu_state.num_urb_entries = 59;
6450 pp_context->vfe_gpu_state.gpgpu_mode = 0;
6451 pp_context->vfe_gpu_state.urb_entry_size = 16 - 1;
6452 pp_context->vfe_gpu_state.curbe_allocation_size = VPP_CURBE_ALLOCATION_SIZE;
6456 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
6457 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
6458 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen7));
6459 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen75));
6460 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen8));
6462 if (IS_GEN8(i965->intel.device_id))
6463 memcpy(pp_context->pp_modules, pp_modules_gen8, sizeof(pp_context->pp_modules));
6464 else if (IS_HASWELL(i965->intel.device_id))
6465 memcpy(pp_context->pp_modules, pp_modules_gen75, sizeof(pp_context->pp_modules));
6466 else if (IS_GEN7(i965->intel.device_id))
6467 memcpy(pp_context->pp_modules, pp_modules_gen7, sizeof(pp_context->pp_modules));
6468 else if (IS_GEN6(i965->intel.device_id))
6469 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
6470 else if (IS_IRONLAKE(i965->intel.device_id))
6471 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
6473 for (i = 0; i < NUM_PP_MODULES; i++) {
6474 struct pp_module *pp_module = &pp_context->pp_modules[i];
6475 dri_bo_unreference(pp_module->kernel.bo);
6476 if (pp_module->kernel.bin && pp_module->kernel.size) {
6477 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
6478 pp_module->kernel.name,
6479 pp_module->kernel.size,
6481 assert(pp_module->kernel.bo);
6482 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
6484 pp_module->kernel.bo = NULL;
6488 /* static & inline parameters */
6489 if (IS_GEN7(i965->intel.device_id) ||
6490 IS_GEN8(i965->intel.device_id)) {
6491 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
6492 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
6494 pp_context->pp_static_parameter = calloc(sizeof(struct pp_static_parameter), 1);
6495 pp_context->pp_inline_parameter = calloc(sizeof(struct pp_inline_parameter), 1);
6498 pp_context->pp_dndi_context.current_out_surface = VA_INVALID_SURFACE;
6499 pp_context->pp_dndi_context.current_out_obj_surface = NULL;
6500 pp_context->pp_dndi_context.frame_order = -1;
6501 pp_context->batch = batch;
6505 i965_post_processing_init(VADriverContextP ctx)
6507 struct i965_driver_data *i965 = i965_driver_data(ctx);
6508 struct i965_post_processing_context *pp_context = i965->pp_context;
6511 if (pp_context == NULL) {
6512 pp_context = calloc(1, sizeof(*pp_context));
6513 i965_post_processing_context_init(ctx, pp_context, i965->pp_batch);
6514 i965->pp_context = pp_context;
6521 static const int procfilter_to_pp_flag[VAProcFilterCount] = {
6522 PP_NULL, /* VAProcFilterNone */
6523 PP_NV12_DN, /* VAProcFilterNoiseReduction */
6524 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
6525 PP_NULL, /* VAProcFilterSharpening */
6526 PP_NULL, /* VAProcFilterColorBalance */
6529 static const int proc_frame_to_pp_frame[3] = {
6530 I965_SURFACE_FLAG_FRAME,
6531 I965_SURFACE_FLAG_TOP_FIELD_FIRST,
6532 I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST
6535 #define VA_STATUS_SUCCESS_1 0xFFFFFFFE
6538 i965_proc_picture(VADriverContextP ctx,
6540 union codec_state *codec_state,
6541 struct hw_context *hw_context)
6543 struct i965_driver_data *i965 = i965_driver_data(ctx);
6544 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
6545 struct proc_state *proc_state = &codec_state->proc;
6546 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
6547 struct object_surface *obj_surface;
6548 struct i965_surface src_surface, dst_surface;
6549 VARectangle src_rect, dst_rect;
6552 VASurfaceID tmp_surfaces[VAProcFilterCount + 4];
6553 int num_tmp_surfaces = 0;
6554 unsigned int tiling = 0, swizzle = 0;
6555 int in_width, in_height;
6557 if (pipeline_param->surface == VA_INVALID_ID ||
6558 proc_state->current_render_target == VA_INVALID_ID) {
6559 status = VA_STATUS_ERROR_INVALID_SURFACE;
6563 obj_surface = SURFACE(pipeline_param->surface);
6566 status = VA_STATUS_ERROR_INVALID_SURFACE;
6570 if (!obj_surface->bo) {
6571 status = VA_STATUS_ERROR_INVALID_VALUE; /* The input surface is created without valid content */
6575 if (pipeline_param->num_filters && !pipeline_param->filters) {
6576 status = VA_STATUS_ERROR_INVALID_PARAMETER;
6580 in_width = obj_surface->orig_width;
6581 in_height = obj_surface->orig_height;
6582 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
6584 src_surface.base = (struct object_base *)obj_surface;
6585 src_surface.type = I965_SURFACE_TYPE_SURFACE;
6586 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
6588 VASurfaceID out_surface_id = VA_INVALID_ID;
6589 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2')) {
6590 src_surface.base = (struct object_base *)obj_surface;
6591 src_surface.type = I965_SURFACE_TYPE_SURFACE;
6592 src_surface.flags = I965_SURFACE_FLAG_FRAME;
6595 src_rect.width = in_width;
6596 src_rect.height = in_height;
6598 status = i965_CreateSurfaces(ctx,
6601 VA_RT_FORMAT_YUV420,
6604 assert(status == VA_STATUS_SUCCESS);
6605 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
6606 obj_surface = SURFACE(out_surface_id);
6607 assert(obj_surface);
6608 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
6610 dst_surface.base = (struct object_base *)obj_surface;
6611 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
6612 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
6615 dst_rect.width = in_width;
6616 dst_rect.height = in_height;
6618 status = i965_image_processing(ctx,
6623 assert(status == VA_STATUS_SUCCESS);
6625 src_surface.base = (struct object_base *)obj_surface;
6626 src_surface.type = I965_SURFACE_TYPE_SURFACE;
6627 src_surface.flags = proc_frame_to_pp_frame[pipeline_param->filter_flags & 0x3];
6630 if (pipeline_param->surface_region) {
6631 src_rect.x = pipeline_param->surface_region->x;
6632 src_rect.y = pipeline_param->surface_region->y;
6633 src_rect.width = pipeline_param->surface_region->width;
6634 src_rect.height = pipeline_param->surface_region->height;
6638 src_rect.width = in_width;
6639 src_rect.height = in_height;
6642 if (pipeline_param->output_region) {
6643 dst_rect.x = pipeline_param->output_region->x;
6644 dst_rect.y = pipeline_param->output_region->y;
6645 dst_rect.width = pipeline_param->output_region->width;
6646 dst_rect.height = pipeline_param->output_region->height;
6650 dst_rect.width = in_width;
6651 dst_rect.height = in_height;
6654 proc_context->pp_context.pipeline_param = pipeline_param;
6656 for (i = 0; i < pipeline_param->num_filters; i++) {
6657 struct object_buffer *obj_buffer = BUFFER(pipeline_param->filters[i]);
6658 VAProcFilterParameterBufferBase *filter_param = NULL;
6659 VAProcFilterType filter_type;
6663 !obj_buffer->buffer_store ||
6664 !obj_buffer->buffer_store->buffer) {
6665 status = VA_STATUS_ERROR_INVALID_FILTER_CHAIN;
6669 out_surface_id = VA_INVALID_ID;
6670 filter_param = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6671 filter_type = filter_param->type;
6672 kernel_index = procfilter_to_pp_flag[filter_type];
6674 if (kernel_index != PP_NULL &&
6675 proc_context->pp_context.pp_modules[kernel_index].kernel.bo != NULL) {
6676 status = i965_CreateSurfaces(ctx,
6679 VA_RT_FORMAT_YUV420,
6682 assert(status == VA_STATUS_SUCCESS);
6683 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
6684 obj_surface = SURFACE(out_surface_id);
6685 assert(obj_surface);
6686 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
6687 dst_surface.base = (struct object_base *)obj_surface;
6688 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
6689 status = i965_post_processing_internal(ctx, &proc_context->pp_context,
6697 if (status == VA_STATUS_SUCCESS) {
6698 src_surface.base = dst_surface.base;
6699 src_surface.type = dst_surface.type;
6700 src_surface.flags = dst_surface.flags;
6705 proc_context->pp_context.pipeline_param = NULL;
6706 obj_surface = SURFACE(proc_state->current_render_target);
6709 status = VA_STATUS_ERROR_INVALID_SURFACE;
6714 if (obj_surface->fourcc && obj_surface->fourcc != VA_FOURCC('N','V','1','2')){
6716 out_surface_id = VA_INVALID_ID;
6717 status = i965_CreateSurfaces(ctx,
6718 obj_surface->orig_width,
6719 obj_surface->orig_height,
6720 VA_RT_FORMAT_YUV420,
6723 assert(status == VA_STATUS_SUCCESS);
6724 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
6725 struct object_surface *csc_surface = SURFACE(out_surface_id);
6726 assert(csc_surface);
6727 i965_check_alloc_surface_bo(ctx, csc_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
6728 dst_surface.base = (struct object_base *)csc_surface;
6730 i965_check_alloc_surface_bo(ctx, obj_surface, !!tiling, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
6731 dst_surface.base = (struct object_base *)obj_surface;
6734 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
6735 i965_vpp_clear_surface(ctx, &proc_context->pp_context, obj_surface, pipeline_param->output_background_color);
6737 // load/save doesn't support different origin offset for src and dst surface
6738 if (src_rect.width == dst_rect.width &&
6739 src_rect.height == dst_rect.height &&
6740 src_rect.x == dst_rect.x &&
6741 src_rect.y == dst_rect.y) {
6742 i965_post_processing_internal(ctx, &proc_context->pp_context,
6747 PP_NV12_LOAD_SAVE_N12,
6751 i965_post_processing_internal(ctx, &proc_context->pp_context,
6756 (pipeline_param->filter_flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC ?
6757 PP_NV12_AVS : PP_NV12_SCALING,
6762 src_surface.base = dst_surface.base;
6763 src_surface.type = dst_surface.type;
6764 src_surface.flags = dst_surface.flags;
6765 dst_surface.base = (struct object_base *)obj_surface;
6766 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
6767 i965_image_processing(ctx, &src_surface, &dst_rect, &dst_surface, &dst_rect);
6770 if (num_tmp_surfaces)
6771 i965_DestroySurfaces(ctx,
6775 intel_batchbuffer_flush(hw_context->batch);
6777 return VA_STATUS_SUCCESS;
6780 if (num_tmp_surfaces)
6781 i965_DestroySurfaces(ctx,
6789 i965_proc_context_destroy(void *hw_context)
6791 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
6793 i965_post_processing_context_finalize(&proc_context->pp_context);
6794 intel_batchbuffer_free(proc_context->base.batch);
6799 i965_proc_context_init(VADriverContextP ctx, struct object_config *obj_config)
6801 struct intel_driver_data *intel = intel_driver_data(ctx);
6802 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
6804 proc_context->base.destroy = i965_proc_context_destroy;
6805 proc_context->base.run = i965_proc_picture;
6806 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
6807 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
6809 return (struct hw_context *)proc_context;