2 * Copyright © 2014 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>
26 * Zhao Yakui <yakui.zhao@intel.com>
35 #include "intel_batchbuffer.h"
36 #include "intel_driver.h"
37 #include "i965_defines.h"
38 #include "i965_structs.h"
39 #include "i965_drv_video.h"
40 #include "i965_post_processing.h"
41 #include "i965_render.h"
42 #include "i965_yuv_coefs.h"
43 #include "intel_media.h"
45 #include "gen75_picture_process.h"
46 #include "intel_common_vpp_internal.h"
48 #define SURFACE_STATE_PADDED_SIZE SURFACE_STATE_PADDED_SIZE_GEN8
50 #define SURFACE_STATE_OFFSET(index) (SURFACE_STATE_PADDED_SIZE * index)
51 #define BINDING_TABLE_OFFSET SURFACE_STATE_OFFSET(MAX_PP_SURFACES)
53 #define GPU_ASM_BLOCK_WIDTH 16
54 #define GPU_ASM_BLOCK_HEIGHT 8
55 #define GPU_ASM_X_OFFSET_ALIGNMENT 4
57 #define VA_STATUS_SUCCESS_1 0xFFFFFFFE
59 VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
60 const struct i965_surface *src_surface,
61 const VARectangle *src_rect,
62 struct i965_surface *dst_surface,
63 const VARectangle *dst_rect,
66 VAStatus gen8_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
67 const struct i965_surface *src_surface,
68 const VARectangle *src_rect,
69 struct i965_surface *dst_surface,
70 const VARectangle *dst_rect,
73 /* TODO: Modify the shader and then compile it again.
74 * Currently it is derived from Haswell*/
75 static const uint32_t pp_null_gen8[][4] = {
78 static const uint32_t pp_nv12_load_save_nv12_gen8[][4] = {
79 #include "shaders/post_processing/gen8/pl2_to_pl2.g8b"
82 static const uint32_t pp_nv12_load_save_pl3_gen8[][4] = {
83 #include "shaders/post_processing/gen8/pl2_to_pl3.g8b"
86 static const uint32_t pp_pl3_load_save_nv12_gen8[][4] = {
87 #include "shaders/post_processing/gen8/pl3_to_pl2.g8b"
90 static const uint32_t pp_pl3_load_save_pl3_gen8[][4] = {
91 #include "shaders/post_processing/gen8/pl3_to_pl3.g8b"
94 static const uint32_t pp_nv12_scaling_gen8[][4] = {
95 #include "shaders/post_processing/gen8/pl2_to_pl2.g8b"
98 static const uint32_t pp_nv12_avs_gen8[][4] = {
99 #include "shaders/post_processing/gen8/pl2_to_pl2.g8b"
102 static const uint32_t pp_nv12_dndi_gen8[][4] = {
103 // #include "shaders/post_processing/gen7/dndi.g75b"
106 static const uint32_t pp_nv12_dn_gen8[][4] = {
107 // #include "shaders/post_processing/gen7/nv12_dn_nv12.g75b"
109 static const uint32_t pp_nv12_load_save_pa_gen8[][4] = {
110 #include "shaders/post_processing/gen8/pl2_to_pa.g8b"
112 static const uint32_t pp_pl3_load_save_pa_gen8[][4] = {
113 #include "shaders/post_processing/gen8/pl3_to_pa.g8b"
115 static const uint32_t pp_pa_load_save_nv12_gen8[][4] = {
116 #include "shaders/post_processing/gen8/pa_to_pl2.g8b"
118 static const uint32_t pp_pa_load_save_pl3_gen8[][4] = {
119 #include "shaders/post_processing/gen8/pa_to_pl3.g8b"
121 static const uint32_t pp_pa_load_save_pa_gen8[][4] = {
122 #include "shaders/post_processing/gen8/pa_to_pa.g8b"
124 static const uint32_t pp_rgbx_load_save_nv12_gen8[][4] = {
125 #include "shaders/post_processing/gen8/rgbx_to_nv12.g8b"
127 static const uint32_t pp_nv12_load_save_rgbx_gen8[][4] = {
128 #include "shaders/post_processing/gen8/pl2_to_rgbx.g8b"
131 static struct pp_module pp_modules_gen8[] = {
134 "NULL module (for testing)",
137 sizeof(pp_null_gen8),
147 PP_NV12_LOAD_SAVE_N12,
148 pp_nv12_load_save_nv12_gen8,
149 sizeof(pp_nv12_load_save_nv12_gen8),
153 gen8_pp_plx_avs_initialize,
159 PP_NV12_LOAD_SAVE_PL3,
160 pp_nv12_load_save_pl3_gen8,
161 sizeof(pp_nv12_load_save_pl3_gen8),
164 gen8_pp_plx_avs_initialize,
170 PP_PL3_LOAD_SAVE_N12,
171 pp_pl3_load_save_nv12_gen8,
172 sizeof(pp_pl3_load_save_nv12_gen8),
176 gen8_pp_plx_avs_initialize,
182 PP_PL3_LOAD_SAVE_PL3,
183 pp_pl3_load_save_pl3_gen8,
184 sizeof(pp_pl3_load_save_pl3_gen8),
188 gen8_pp_plx_avs_initialize,
193 "NV12 Scaling module",
195 pp_nv12_scaling_gen8,
196 sizeof(pp_nv12_scaling_gen8),
200 gen8_pp_plx_avs_initialize,
208 sizeof(pp_nv12_avs_gen8),
212 gen8_pp_plx_avs_initialize,
220 sizeof(pp_nv12_dndi_gen8),
232 sizeof(pp_nv12_dn_gen8),
241 PP_NV12_LOAD_SAVE_PA,
242 pp_nv12_load_save_pa_gen8,
243 sizeof(pp_nv12_load_save_pa_gen8),
247 gen8_pp_plx_avs_initialize,
254 pp_pl3_load_save_pa_gen8,
255 sizeof(pp_pl3_load_save_pa_gen8),
259 gen8_pp_plx_avs_initialize,
265 PP_PA_LOAD_SAVE_NV12,
266 pp_pa_load_save_nv12_gen8,
267 sizeof(pp_pa_load_save_nv12_gen8),
271 gen8_pp_plx_avs_initialize,
278 pp_pa_load_save_pl3_gen8,
279 sizeof(pp_pa_load_save_pl3_gen8),
283 gen8_pp_plx_avs_initialize,
290 pp_pa_load_save_pa_gen8,
291 sizeof(pp_pa_load_save_pa_gen8),
295 gen8_pp_plx_avs_initialize,
301 PP_RGBX_LOAD_SAVE_NV12,
302 pp_rgbx_load_save_nv12_gen8,
303 sizeof(pp_rgbx_load_save_nv12_gen8),
307 gen8_pp_plx_avs_initialize,
313 PP_NV12_LOAD_SAVE_RGBX,
314 pp_nv12_load_save_rgbx_gen8,
315 sizeof(pp_nv12_load_save_rgbx_gen8),
319 gen8_pp_plx_avs_initialize,
323 #define MAX_SCALING_SURFACES 16
325 #define DEFAULT_MOCS 0
327 static const uint32_t pp_yuv420p8_scaling_gen8[][4] = {
328 #include "shaders/post_processing/gen8/conv_nv12.g8b"
332 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
336 if (surface->type == I965_SURFACE_TYPE_IMAGE) {
337 struct object_image *obj_image = (struct object_image *)surface->base;
338 fourcc = obj_image->image.format.fourcc;
340 struct object_surface *obj_surface = (struct object_surface *)surface->base;
341 fourcc = obj_surface->fourcc;
348 gen8_pp_set_surface_tiling(struct gen8_surface_state *ss, unsigned int tiling)
351 case I915_TILING_NONE:
352 ss->ss0.tiled_surface = 0;
353 ss->ss0.tile_walk = 0;
356 ss->ss0.tiled_surface = 1;
357 ss->ss0.tile_walk = I965_TILEWALK_XMAJOR;
360 ss->ss0.tiled_surface = 1;
361 ss->ss0.tile_walk = I965_TILEWALK_YMAJOR;
367 gen8_pp_set_surface2_tiling(struct gen8_surface_state2 *ss, unsigned int tiling)
370 case I915_TILING_NONE:
371 ss->ss2.tiled_surface = 0;
372 ss->ss2.tile_walk = 0;
375 ss->ss2.tiled_surface = 1;
376 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
379 ss->ss2.tiled_surface = 1;
380 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
387 gen8_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
388 dri_bo *surf_bo, unsigned long surf_bo_offset,
389 int width, int height, int pitch, int format,
390 int index, int is_target)
392 struct i965_driver_data *i965 = i965_driver_data(ctx);
393 struct gen8_surface_state *ss;
396 unsigned int swizzle;
398 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
399 ss_bo = pp_context->surface_state_binding_table.bo;
402 dri_bo_map(ss_bo, True);
403 assert(ss_bo->virtual);
404 ss = (struct gen8_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
405 memset(ss, 0, sizeof(*ss));
407 if (IS_GEN9(i965->intel.device_info))
408 ss->ss1.surface_mocs = GEN9_CACHE_PTE;
410 ss->ss0.surface_type = I965_SURFACE_2D;
411 ss->ss0.surface_format = format;
412 ss->ss8.base_addr = surf_bo->offset + surf_bo_offset;
413 ss->ss2.width = width - 1;
414 ss->ss2.height = height - 1;
415 ss->ss3.pitch = pitch - 1;
417 /* Always set 1(align 4 mode) per B-spec */
418 ss->ss0.vertical_alignment = 1;
419 ss->ss0.horizontal_alignment = 1;
421 gen8_pp_set_surface_tiling(ss, tiling);
422 gen8_render_set_surface_scs(ss);
423 dri_bo_emit_reloc(ss_bo,
424 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
426 SURFACE_STATE_OFFSET(index) + offsetof(struct gen8_surface_state, ss8),
428 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
434 gen8_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
435 dri_bo *surf_bo, unsigned long surf_bo_offset,
436 int width, int height, int wpitch,
437 int xoffset, int yoffset,
438 int format, int interleave_chroma,
441 struct i965_driver_data *i965 = i965_driver_data(ctx);
442 struct gen8_surface_state2 *ss2;
445 unsigned int swizzle;
447 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
448 ss2_bo = pp_context->surface_state_binding_table.bo;
451 dri_bo_map(ss2_bo, True);
452 assert(ss2_bo->virtual);
453 ss2 = (struct gen8_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
454 memset(ss2, 0, sizeof(*ss2));
456 if (IS_GEN9(i965->intel.device_info))
457 ss2->ss5.surface_object_mocs = GEN9_CACHE_PTE;
459 ss2->ss6.base_addr = surf_bo->offset + surf_bo_offset;
460 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
461 ss2->ss1.width = width - 1;
462 ss2->ss1.height = height - 1;
463 ss2->ss2.pitch = wpitch - 1;
464 ss2->ss2.interleave_chroma = interleave_chroma;
465 ss2->ss2.surface_format = format;
466 ss2->ss3.x_offset_for_cb = xoffset;
467 ss2->ss3.y_offset_for_cb = yoffset;
468 gen8_pp_set_surface2_tiling(ss2, tiling);
469 dri_bo_emit_reloc(ss2_bo,
470 I915_GEM_DOMAIN_RENDER, 0,
472 SURFACE_STATE_OFFSET(index) + offsetof(struct gen8_surface_state2, ss6),
474 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
475 dri_bo_unmap(ss2_bo);
479 gen8_pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
480 const struct i965_surface *surface,
481 int base_index, int is_target,
482 const VARectangle *rect,
483 int *width, int *height, int *pitch, int *offset)
485 struct object_surface *obj_surface;
486 struct object_image *obj_image;
488 int fourcc = pp_get_surface_fourcc(ctx, surface);
489 const i965_fourcc_info *fourcc_info = get_fourcc_info(fourcc);
491 if (fourcc_info == NULL)
494 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
495 obj_surface = (struct object_surface *)surface->base;
496 bo = obj_surface->bo;
497 width[0] = MIN(rect->x + rect->width, obj_surface->orig_width);
498 height[0] = MIN(rect->y + rect->height, obj_surface->orig_height);
499 pitch[0] = obj_surface->width;
502 if (fourcc_info->num_planes == 1 && is_target)
503 width[0] = width[0] * (fourcc_info->bpp[0] / 8); /* surface format is R8 */
505 width[1] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_surface->cb_cr_width);
506 height[1] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_surface->cb_cr_height);
507 pitch[1] = obj_surface->cb_cr_pitch;
508 offset[1] = obj_surface->y_cb_offset * obj_surface->width;
510 width[2] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_surface->cb_cr_width);
511 height[2] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_surface->cb_cr_height);
512 pitch[2] = obj_surface->cb_cr_pitch;
513 offset[2] = obj_surface->y_cr_offset * obj_surface->width;
517 /* FIXME: add support for ARGB/ABGR image */
518 obj_image = (struct object_image *)surface->base;
520 width[0] = MIN(rect->x + rect->width, obj_image->image.width);
521 height[0] = MIN(rect->y + rect->height, obj_image->image.height);
522 pitch[0] = obj_image->image.pitches[0];
523 offset[0] = obj_image->image.offsets[0];
525 if (fourcc_info->num_planes == 1) {
527 width[0] = width[0] * (fourcc_info->bpp[0] / 8); /* surface format is R8 */
528 } else if (fourcc_info->num_planes == 2) {
531 assert(fourcc_info->num_components == 3);
533 U = fourcc_info->components[1].plane;
534 V = fourcc_info->components[2].plane;
535 assert((U == 1 && V == 2) ||
539 /* Always set width/height although they aren't used for fourcc_info->num_planes == 1 */
540 width[1] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_image->image.width / fourcc_info->hfactor);
541 height[1] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_image->image.height / fourcc_info->vfactor);
542 pitch[1] = obj_image->image.pitches[U];
543 offset[1] = obj_image->image.offsets[U];
545 width[2] = MIN(rect->x / fourcc_info->hfactor + rect->width / fourcc_info->hfactor, obj_image->image.width / fourcc_info->hfactor);
546 height[2] = MIN(rect->y / fourcc_info->vfactor + rect->height / fourcc_info->vfactor, obj_image->image.height / fourcc_info->vfactor);
547 pitch[2] = obj_image->image.pitches[V];
548 offset[2] = obj_image->image.offsets[V];
552 gen8_pp_set_surface_state(ctx, pp_context,
554 ALIGN(width[0], 4) / 4, height[0], pitch[0],
555 I965_SURFACEFORMAT_R8_UINT,
558 if (fourcc_info->num_planes == 2) {
559 gen8_pp_set_surface_state(ctx, pp_context,
561 ALIGN(width[1], 2) / 2, height[1], pitch[1],
562 I965_SURFACEFORMAT_R8G8_SINT,
564 } else if (fourcc_info->num_planes == 3) {
565 gen8_pp_set_surface_state(ctx, pp_context,
567 ALIGN(width[1], 4) / 4, height[1], pitch[1],
568 I965_SURFACEFORMAT_R8_SINT,
570 gen8_pp_set_surface_state(ctx, pp_context,
572 ALIGN(width[2], 4) / 4, height[2], pitch[2],
573 I965_SURFACEFORMAT_R8_SINT,
577 if (fourcc_info->format == I965_COLOR_RGB) {
578 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
579 /* the format is MSB: X-B-G-R */
580 pp_static_parameter->grf2.save_avs_rgb_swap = 0;
581 if ((fourcc == VA_FOURCC_BGRA) ||
582 (fourcc == VA_FOURCC_BGRX)) {
583 /* It is stored as MSB: X-R-G-B */
584 pp_static_parameter->grf2.save_avs_rgb_swap = 1;
588 int format0 = SURFACE_FORMAT_Y8_UNORM;
592 format0 = SURFACE_FORMAT_YCRCB_NORMAL;
596 format0 = SURFACE_FORMAT_YCRCB_SWAPY;
603 if (fourcc_info->format == I965_COLOR_RGB) {
604 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
605 /* Only R8G8B8A8_UNORM is supported for BGRX or RGBX */
606 format0 = SURFACE_FORMAT_R8G8B8A8_UNORM;
607 pp_static_parameter->grf2.src_avs_rgb_swap = 0;
608 if ((fourcc == VA_FOURCC_BGRA) ||
609 (fourcc == VA_FOURCC_BGRX)) {
610 pp_static_parameter->grf2.src_avs_rgb_swap = 1;
614 gen8_pp_set_surface2_state(ctx, pp_context,
616 width[0], height[0], pitch[0],
621 if (fourcc_info->num_planes == 2) {
622 gen8_pp_set_surface2_state(ctx, pp_context,
624 width[1], height[1], pitch[1],
626 SURFACE_FORMAT_R8B8_UNORM, 0,
628 } else if (fourcc_info->num_planes == 3) {
629 gen8_pp_set_surface2_state(ctx, pp_context,
631 width[1], height[1], pitch[1],
633 SURFACE_FORMAT_R8_UNORM, 0,
635 gen8_pp_set_surface2_state(ctx, pp_context,
637 width[2], height[2], pitch[2],
639 SURFACE_FORMAT_R8_UNORM, 0,
643 gen8_pp_set_surface_state(ctx, pp_context,
645 ALIGN(width[0], 4) / 4, height[0], pitch[0],
646 I965_SURFACEFORMAT_R8_UINT,
649 if (fourcc_info->num_planes == 2) {
650 gen8_pp_set_surface_state(ctx, pp_context,
652 ALIGN(width[1], 2) / 2, height[1], pitch[1],
653 I965_SURFACEFORMAT_R8G8_SINT,
655 } else if (fourcc_info->num_planes == 3) {
656 gen8_pp_set_surface_state(ctx, pp_context,
658 ALIGN(width[1], 4) / 4, height[1], pitch[1],
659 I965_SURFACEFORMAT_R8_SINT,
661 gen8_pp_set_surface_state(ctx, pp_context,
663 ALIGN(width[2], 4) / 4, height[2], pitch[2],
664 I965_SURFACEFORMAT_R8_SINT,
671 pp_null_x_steps(void *private_context)
677 pp_null_y_steps(void *private_context)
683 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
689 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
690 const struct i965_surface *src_surface,
691 const VARectangle *src_rect,
692 struct i965_surface *dst_surface,
693 const VARectangle *dst_rect,
696 /* private function & data */
697 pp_context->pp_x_steps = pp_null_x_steps;
698 pp_context->pp_y_steps = pp_null_y_steps;
699 pp_context->private_context = NULL;
700 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
702 dst_surface->flags = src_surface->flags;
704 return VA_STATUS_SUCCESS;
707 static void calculate_boundary_block_mask(struct i965_post_processing_context *pp_context, const VARectangle *dst_rect)
709 int i, dst_width_adjust;
710 /* x offset of dest surface must be dword aligned.
711 * so we have to extend dst surface on left edge, and mask out pixels not interested
713 if (dst_rect->x % GPU_ASM_X_OFFSET_ALIGNMENT) {
714 pp_context->block_horizontal_mask_left = 0;
715 for (i = dst_rect->x % GPU_ASM_X_OFFSET_ALIGNMENT; i < GPU_ASM_BLOCK_WIDTH; i++) {
716 pp_context->block_horizontal_mask_left |= 1 << i;
719 pp_context->block_horizontal_mask_left = 0xffff;
722 dst_width_adjust = dst_rect->width + dst_rect->x % GPU_ASM_X_OFFSET_ALIGNMENT;
723 if (dst_width_adjust % GPU_ASM_BLOCK_WIDTH) {
724 pp_context->block_horizontal_mask_right = (1 << (dst_width_adjust % GPU_ASM_BLOCK_WIDTH)) - 1;
726 pp_context->block_horizontal_mask_right = 0xffff;
729 if (dst_rect->height % GPU_ASM_BLOCK_HEIGHT) {
730 pp_context->block_vertical_mask_bottom = (1 << (dst_rect->height % GPU_ASM_BLOCK_HEIGHT)) - 1;
732 pp_context->block_vertical_mask_bottom = 0xff;
738 gen7_pp_avs_x_steps(void *private_context)
740 struct pp_avs_context *pp_avs_context = private_context;
742 return pp_avs_context->dest_w / 16;
746 gen7_pp_avs_y_steps(void *private_context)
748 struct pp_avs_context *pp_avs_context = private_context;
750 return pp_avs_context->dest_h / 16;
754 gen7_pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
756 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)pp_context->private_context;
757 struct gen7_pp_inline_parameter *pp_inline_parameter = pp_context->pp_inline_parameter;
759 pp_inline_parameter->grf9.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
760 pp_inline_parameter->grf9.destination_block_vertical_origin = y * 16 + pp_avs_context->dest_y;
761 pp_inline_parameter->grf9.constant_0 = 0xffffffff;
762 pp_inline_parameter->grf9.sampler_load_main_video_x_scaling_step = pp_avs_context->horiz_range / pp_avs_context->src_w;
767 static void gen7_update_src_surface_uv_offset(VADriverContextP ctx,
768 struct i965_post_processing_context *pp_context,
769 const struct i965_surface *surface)
771 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
772 int fourcc = pp_get_surface_fourcc(ctx, surface);
774 if (fourcc == VA_FOURCC_YUY2) {
775 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 0;
776 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 1;
777 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 3;
778 } else if (fourcc == VA_FOURCC_UYVY) {
779 pp_static_parameter->grf2.di_destination_packed_y_component_offset = 1;
780 pp_static_parameter->grf2.di_destination_packed_u_component_offset = 0;
781 pp_static_parameter->grf2.di_destination_packed_v_component_offset = 2;
785 static const AVSConfig gen8_avs_config = {
786 .coeff_frac_bits = 6,
787 .coeff_epsilon = 1.0f / (1U << 6),
789 .num_luma_coeffs = 8,
790 .num_chroma_coeffs = 4,
794 .y_k_h = { -2, -2, -2, -2, -2, -2, -2, -2 },
795 .y_k_v = { -2, -2, -2, -2, -2, -2, -2, -2 },
796 .uv_k_h = { -1, -2, -2, -1 },
797 .uv_k_v = { -1, -2, -2, -1 },
800 .y_k_h = { 2, 2, 2, 2, 2, 2, 2, 2 },
801 .y_k_v = { 2, 2, 2, 2, 2, 2, 2, 2 },
802 .uv_k_h = { 1, 2, 2, 1 },
803 .uv_k_v = { 1, 2, 2, 1 },
809 gen8_pp_get_8tap_filter_mode(VADriverContextP ctx,
810 const struct i965_surface *surface)
812 int fourcc = pp_get_surface_fourcc(ctx, surface);
814 if (fourcc == VA_FOURCC_YUY2 ||
815 fourcc == VA_FOURCC_UYVY)
822 gen8_pp_kernel_use_media_read_msg(VADriverContextP ctx,
823 const struct i965_surface *src_surface,
824 const VARectangle *src_rect,
825 const struct i965_surface *dst_surface,
826 const VARectangle *dst_rect)
828 int src_fourcc = pp_get_surface_fourcc(ctx, src_surface);
829 int dst_fourcc = pp_get_surface_fourcc(ctx, dst_surface);
830 const i965_fourcc_info *src_fourcc_info = get_fourcc_info(src_fourcc);
831 const i965_fourcc_info *dst_fourcc_info = get_fourcc_info(dst_fourcc);
833 if (!src_fourcc_info ||
834 src_fourcc_info->subsampling != SUBSAMPLE_YUV420 ||
836 dst_fourcc_info->subsampling != SUBSAMPLE_YUV420)
839 if (src_rect->x == dst_rect->x &&
840 src_rect->y == dst_rect->y &&
841 src_rect->width == dst_rect->width &&
842 src_rect->height == dst_rect->height)
849 gen8_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
850 const struct i965_surface *src_surface,
851 const VARectangle *src_rect,
852 struct i965_surface *dst_surface,
853 const VARectangle *dst_rect,
856 /* TODO: Add the sampler_8x8 state */
857 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->pp_avs_context;
858 struct gen7_pp_static_parameter *pp_static_parameter = pp_context->pp_static_parameter;
859 struct gen8_sampler_8x8_avs *sampler_8x8;
861 int width[3], height[3], pitch[3], offset[3];
862 int src_width, src_height;
863 unsigned char *cc_ptr;
864 AVSState * const avs = &pp_avs_context->state;
866 const float * yuv_to_rgb_coefs;
867 size_t yuv_to_rgb_coefs_size;
869 memset(pp_static_parameter, 0, sizeof(struct gen7_pp_static_parameter));
872 gen8_pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 0, 0,
874 width, height, pitch, offset);
875 src_height = height[0];
876 src_width = width[0];
878 /* destination surface */
879 gen8_pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 24, 1,
881 width, height, pitch, offset);
883 /* sampler 8x8 state */
884 dri_bo_map(pp_context->dynamic_state.bo, True);
885 assert(pp_context->dynamic_state.bo->virtual);
887 cc_ptr = (unsigned char *) pp_context->dynamic_state.bo->virtual +
888 pp_context->sampler_offset;
889 /* Currently only one gen8 sampler_8x8 is initialized */
890 sampler_8x8 = (struct gen8_sampler_8x8_avs *) cc_ptr;
891 memset(sampler_8x8, 0, sizeof(*sampler_8x8));
893 sampler_8x8->dw0.gain_factor = 44;
894 sampler_8x8->dw0.weak_edge_threshold = 1;
895 sampler_8x8->dw0.strong_edge_threshold = 8;
896 /* Use the value like that on Ivy instead of default
897 * sampler_8x8->dw0.r3x_coefficient = 5;
899 sampler_8x8->dw0.r3x_coefficient = 27;
900 sampler_8x8->dw0.r3c_coefficient = 5;
902 sampler_8x8->dw2.global_noise_estimation = 255;
903 sampler_8x8->dw2.non_edge_weight = 1;
904 sampler_8x8->dw2.regular_weight = 2;
905 sampler_8x8->dw2.strong_edge_weight = 7;
906 /* Use the value like that on Ivy instead of default
907 * sampler_8x8->dw2.r5x_coefficient = 7;
908 * sampler_8x8->dw2.r5cx_coefficient = 7;
909 * sampler_8x8->dw2.r5c_coefficient = 7;
911 sampler_8x8->dw2.r5x_coefficient = 9;
912 sampler_8x8->dw2.r5cx_coefficient = 8;
913 sampler_8x8->dw2.r5c_coefficient = 3;
915 sampler_8x8->dw3.sin_alpha = 101; /* sin_alpha = 0 */
916 sampler_8x8->dw3.cos_alpha = 79; /* cos_alpha = 0 */
917 sampler_8x8->dw3.sat_max = 0x1f;
918 sampler_8x8->dw3.hue_max = 14;
919 /* The 8tap filter will determine whether the adaptive Filter is
920 * applied for all channels(dw153).
921 * If the 8tap filter is disabled, the adaptive filter should be disabled.
922 * Only when 8tap filter is enabled, it can be enabled or not.
924 sampler_8x8->dw3.enable_8tap_filter = gen8_pp_get_8tap_filter_mode(ctx, src_surface);
925 sampler_8x8->dw3.ief4_smooth_enable = 0;
927 sampler_8x8->dw4.s3u = 0;
928 sampler_8x8->dw4.diamond_margin = 4;
929 sampler_8x8->dw4.vy_std_enable = 0;
930 sampler_8x8->dw4.umid = 110;
931 sampler_8x8->dw4.vmid = 154;
933 sampler_8x8->dw5.diamond_dv = 0;
934 sampler_8x8->dw5.diamond_th = 35;
935 sampler_8x8->dw5.diamond_alpha = 100; /* diamond_alpha = 0 */
936 sampler_8x8->dw5.hs_margin = 3;
937 sampler_8x8->dw5.diamond_du = 2;
939 sampler_8x8->dw6.y_point1 = 46;
940 sampler_8x8->dw6.y_point2 = 47;
941 sampler_8x8->dw6.y_point3 = 254;
942 sampler_8x8->dw6.y_point4 = 255;
944 sampler_8x8->dw7.inv_margin_vyl = 3300; /* inv_margin_vyl = 0 */
946 sampler_8x8->dw8.inv_margin_vyu = 1600; /* inv_margin_vyu = 0 */
947 sampler_8x8->dw8.p0l = 46;
948 sampler_8x8->dw8.p1l = 216;
950 sampler_8x8->dw9.p2l = 236;
951 sampler_8x8->dw9.p3l = 236;
952 sampler_8x8->dw9.b0l = 133;
953 sampler_8x8->dw9.b1l = 130;
955 sampler_8x8->dw10.b2l = 130;
956 sampler_8x8->dw10.b3l = 130;
957 /* s0l = -5 / 256. s2.8 */
958 sampler_8x8->dw10.s0l = 1029; /* s0l = 0 */
959 sampler_8x8->dw10.y_slope2 = 31; /* y_slop2 = 0 */
961 sampler_8x8->dw11.s1l = 0;
962 sampler_8x8->dw11.s2l = 0;
964 sampler_8x8->dw12.s3l = 0;
965 sampler_8x8->dw12.p0u = 46;
966 sampler_8x8->dw12.p1u = 66;
967 sampler_8x8->dw12.y_slope1 = 31; /* y_slope1 = 0 */
969 sampler_8x8->dw13.p2u = 130;
970 sampler_8x8->dw13.p3u = 236;
971 sampler_8x8->dw13.b0u = 143;
972 sampler_8x8->dw13.b1u = 163;
974 sampler_8x8->dw14.b2u = 200;
975 sampler_8x8->dw14.b3u = 140;
976 sampler_8x8->dw14.s0u = 256; /* s0u = 0 */
978 sampler_8x8->dw15.s1u = 113; /* s1u = 0 */
979 sampler_8x8->dw15.s2u = 1203; /* s2u = 0 */
981 sx = (float)dst_rect->width / src_rect->width;
982 sy = (float)dst_rect->height / src_rect->height;
983 avs_update_coefficients(avs, sx, sy, pp_context->filter_flags);
985 assert(avs->config->num_phases >= 16);
986 for (i = 0; i <= 16; i++) {
987 struct gen8_sampler_8x8_avs_coefficients * const sampler_8x8_state =
988 &sampler_8x8->coefficients[i];
989 const AVSCoeffs * const coeffs = &avs->coeffs[i];
991 sampler_8x8_state->dw0.table_0x_filter_c0 =
992 intel_format_convert(coeffs->y_k_h[0], 1, 6, 1);
993 sampler_8x8_state->dw0.table_0y_filter_c0 =
994 intel_format_convert(coeffs->y_k_v[0], 1, 6, 1);
995 sampler_8x8_state->dw0.table_0x_filter_c1 =
996 intel_format_convert(coeffs->y_k_h[1], 1, 6, 1);
997 sampler_8x8_state->dw0.table_0y_filter_c1 =
998 intel_format_convert(coeffs->y_k_v[1], 1, 6, 1);
1000 sampler_8x8_state->dw1.table_0x_filter_c2 =
1001 intel_format_convert(coeffs->y_k_h[2], 1, 6, 1);
1002 sampler_8x8_state->dw1.table_0y_filter_c2 =
1003 intel_format_convert(coeffs->y_k_v[2], 1, 6, 1);
1004 sampler_8x8_state->dw1.table_0x_filter_c3 =
1005 intel_format_convert(coeffs->y_k_h[3], 1, 6, 1);
1006 sampler_8x8_state->dw1.table_0y_filter_c3 =
1007 intel_format_convert(coeffs->y_k_v[3], 1, 6, 1);
1009 sampler_8x8_state->dw2.table_0x_filter_c4 =
1010 intel_format_convert(coeffs->y_k_h[4], 1, 6, 1);
1011 sampler_8x8_state->dw2.table_0y_filter_c4 =
1012 intel_format_convert(coeffs->y_k_v[4], 1, 6, 1);
1013 sampler_8x8_state->dw2.table_0x_filter_c5 =
1014 intel_format_convert(coeffs->y_k_h[5], 1, 6, 1);
1015 sampler_8x8_state->dw2.table_0y_filter_c5 =
1016 intel_format_convert(coeffs->y_k_v[5], 1, 6, 1);
1018 sampler_8x8_state->dw3.table_0x_filter_c6 =
1019 intel_format_convert(coeffs->y_k_h[6], 1, 6, 1);
1020 sampler_8x8_state->dw3.table_0y_filter_c6 =
1021 intel_format_convert(coeffs->y_k_v[6], 1, 6, 1);
1022 sampler_8x8_state->dw3.table_0x_filter_c7 =
1023 intel_format_convert(coeffs->y_k_h[7], 1, 6, 1);
1024 sampler_8x8_state->dw3.table_0y_filter_c7 =
1025 intel_format_convert(coeffs->y_k_v[7], 1, 6, 1);
1027 sampler_8x8_state->dw4.pad0 = 0;
1028 sampler_8x8_state->dw5.pad0 = 0;
1029 sampler_8x8_state->dw4.table_1x_filter_c2 =
1030 intel_format_convert(coeffs->uv_k_h[0], 1, 6, 1);
1031 sampler_8x8_state->dw4.table_1x_filter_c3 =
1032 intel_format_convert(coeffs->uv_k_h[1], 1, 6, 1);
1033 sampler_8x8_state->dw5.table_1x_filter_c4 =
1034 intel_format_convert(coeffs->uv_k_h[2], 1, 6, 1);
1035 sampler_8x8_state->dw5.table_1x_filter_c5 =
1036 intel_format_convert(coeffs->uv_k_h[3], 1, 6, 1);
1038 sampler_8x8_state->dw6.pad0 =
1039 sampler_8x8_state->dw7.pad0 =
1040 sampler_8x8_state->dw6.table_1y_filter_c2 =
1041 intel_format_convert(coeffs->uv_k_v[0], 1, 6, 1);
1042 sampler_8x8_state->dw6.table_1y_filter_c3 =
1043 intel_format_convert(coeffs->uv_k_v[1], 1, 6, 1);
1044 sampler_8x8_state->dw7.table_1y_filter_c4 =
1045 intel_format_convert(coeffs->uv_k_v[2], 1, 6, 1);
1046 sampler_8x8_state->dw7.table_1y_filter_c5 =
1047 intel_format_convert(coeffs->uv_k_v[3], 1, 6, 1);
1050 sampler_8x8->dw152.default_sharpness_level =
1051 -avs_is_needed(pp_context->filter_flags);
1052 sampler_8x8->dw153.adaptive_filter_for_all_channel = 1;
1053 sampler_8x8->dw153.bypass_y_adaptive_filtering = 1;
1054 sampler_8x8->dw153.bypass_x_adaptive_filtering = 1;
1056 for (; i <= avs->config->num_phases; i++) {
1057 struct gen8_sampler_8x8_avs_coefficients * const sampler_8x8_state =
1058 &sampler_8x8->coefficients1[i - 17];
1059 const AVSCoeffs * const coeffs = &avs->coeffs[i];
1061 sampler_8x8_state->dw0.table_0x_filter_c0 =
1062 intel_format_convert(coeffs->y_k_h[0], 1, 6, 1);
1063 sampler_8x8_state->dw0.table_0y_filter_c0 =
1064 intel_format_convert(coeffs->y_k_v[0], 1, 6, 1);
1065 sampler_8x8_state->dw0.table_0x_filter_c1 =
1066 intel_format_convert(coeffs->y_k_h[1], 1, 6, 1);
1067 sampler_8x8_state->dw0.table_0y_filter_c1 =
1068 intel_format_convert(coeffs->y_k_v[1], 1, 6, 1);
1070 sampler_8x8_state->dw1.table_0x_filter_c2 =
1071 intel_format_convert(coeffs->y_k_h[2], 1, 6, 1);
1072 sampler_8x8_state->dw1.table_0y_filter_c2 =
1073 intel_format_convert(coeffs->y_k_v[2], 1, 6, 1);
1074 sampler_8x8_state->dw1.table_0x_filter_c3 =
1075 intel_format_convert(coeffs->y_k_h[3], 1, 6, 1);
1076 sampler_8x8_state->dw1.table_0y_filter_c3 =
1077 intel_format_convert(coeffs->y_k_v[3], 1, 6, 1);
1079 sampler_8x8_state->dw2.table_0x_filter_c4 =
1080 intel_format_convert(coeffs->y_k_h[4], 1, 6, 1);
1081 sampler_8x8_state->dw2.table_0y_filter_c4 =
1082 intel_format_convert(coeffs->y_k_v[4], 1, 6, 1);
1083 sampler_8x8_state->dw2.table_0x_filter_c5 =
1084 intel_format_convert(coeffs->y_k_h[5], 1, 6, 1);
1085 sampler_8x8_state->dw2.table_0y_filter_c5 =
1086 intel_format_convert(coeffs->y_k_v[5], 1, 6, 1);
1088 sampler_8x8_state->dw3.table_0x_filter_c6 =
1089 intel_format_convert(coeffs->y_k_h[6], 1, 6, 1);
1090 sampler_8x8_state->dw3.table_0y_filter_c6 =
1091 intel_format_convert(coeffs->y_k_v[6], 1, 6, 1);
1092 sampler_8x8_state->dw3.table_0x_filter_c7 =
1093 intel_format_convert(coeffs->y_k_h[7], 1, 6, 1);
1094 sampler_8x8_state->dw3.table_0y_filter_c7 =
1095 intel_format_convert(coeffs->y_k_v[7], 1, 6, 1);
1097 sampler_8x8_state->dw4.pad0 = 0;
1098 sampler_8x8_state->dw5.pad0 = 0;
1099 sampler_8x8_state->dw4.table_1x_filter_c2 =
1100 intel_format_convert(coeffs->uv_k_h[0], 1, 6, 1);
1101 sampler_8x8_state->dw4.table_1x_filter_c3 =
1102 intel_format_convert(coeffs->uv_k_h[1], 1, 6, 1);
1103 sampler_8x8_state->dw5.table_1x_filter_c4 =
1104 intel_format_convert(coeffs->uv_k_h[2], 1, 6, 1);
1105 sampler_8x8_state->dw5.table_1x_filter_c5 =
1106 intel_format_convert(coeffs->uv_k_h[3], 1, 6, 1);
1108 sampler_8x8_state->dw6.pad0 =
1109 sampler_8x8_state->dw7.pad0 =
1110 sampler_8x8_state->dw6.table_1y_filter_c2 =
1111 intel_format_convert(coeffs->uv_k_v[0], 1, 6, 1);
1112 sampler_8x8_state->dw6.table_1y_filter_c3 =
1113 intel_format_convert(coeffs->uv_k_v[1], 1, 6, 1);
1114 sampler_8x8_state->dw7.table_1y_filter_c4 =
1115 intel_format_convert(coeffs->uv_k_v[2], 1, 6, 1);
1116 sampler_8x8_state->dw7.table_1y_filter_c5 =
1117 intel_format_convert(coeffs->uv_k_v[3], 1, 6, 1);
1120 dri_bo_unmap(pp_context->dynamic_state.bo);
1123 /* private function & data */
1124 pp_context->pp_x_steps = gen7_pp_avs_x_steps;
1125 pp_context->pp_y_steps = gen7_pp_avs_y_steps;
1126 pp_context->private_context = &pp_context->pp_avs_context;
1127 pp_context->pp_set_block_parameter = gen7_pp_avs_set_block_parameter;
1129 int dst_left_edge_extend = dst_rect->x % GPU_ASM_X_OFFSET_ALIGNMENT;
1130 pp_avs_context->dest_x = dst_rect->x - dst_left_edge_extend;
1131 pp_avs_context->dest_y = dst_rect->y;
1132 pp_avs_context->dest_w = ALIGN(dst_rect->width + dst_left_edge_extend, 16);
1133 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
1134 pp_avs_context->src_w = src_rect->width;
1135 pp_avs_context->src_h = src_rect->height;
1136 pp_avs_context->horiz_range = (float)src_rect->width / src_width;
1138 int dw = (pp_avs_context->src_w - 1) / 16 + 1;
1139 dw = MAX(dw, dst_rect->width + dst_left_edge_extend);
1141 pp_static_parameter->grf1.pointer_to_inline_parameter = 7;
1142 pp_static_parameter->grf2.avs_wa_enable = gen8_pp_kernel_use_media_read_msg(ctx,
1143 src_surface, src_rect,
1144 dst_surface, dst_rect); /* reuse this flag for media block reading on gen8+ */
1145 pp_static_parameter->grf2.alpha = 255;
1147 pp_static_parameter->grf3.sampler_load_horizontal_scaling_step_ratio = (float) pp_avs_context->src_w / dw;
1148 pp_static_parameter->grf4.sampler_load_vertical_scaling_step = (float) src_rect->height / src_height / dst_rect->height;
1149 pp_static_parameter->grf5.sampler_load_vertical_frame_origin = (float) src_rect->y / src_height -
1150 (float) pp_avs_context->dest_y * pp_static_parameter->grf4.sampler_load_vertical_scaling_step;
1151 pp_static_parameter->grf6.sampler_load_horizontal_frame_origin = (float) src_rect->x / src_width -
1152 (float) pp_avs_context->dest_x * pp_avs_context->horiz_range / dw;
1154 gen7_update_src_surface_uv_offset(ctx, pp_context, dst_surface);
1156 yuv_to_rgb_coefs = i915_color_standard_to_coefs(i915_filter_to_color_standard(src_surface->flags &
1158 &yuv_to_rgb_coefs_size);
1159 memcpy(&pp_static_parameter->grf7, yuv_to_rgb_coefs, yuv_to_rgb_coefs_size);
1161 dst_surface->flags = src_surface->flags;
1163 return VA_STATUS_SUCCESS;
1168 VADriverContextP ctx,
1169 struct i965_post_processing_context *pp_context,
1170 const struct i965_surface *src_surface,
1171 const VARectangle *src_rect,
1172 struct i965_surface *dst_surface,
1173 const VARectangle *dst_rect,
1179 struct i965_driver_data *i965 = i965_driver_data(ctx);
1182 unsigned int end_offset;
1183 struct pp_module *pp_module;
1184 int static_param_size, inline_param_size;
1186 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
1187 bo = dri_bo_alloc(i965->intel.bufmgr,
1188 "surface state & binding table",
1189 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
1192 pp_context->surface_state_binding_table.bo = bo;
1194 pp_context->idrt.num_interface_descriptors = 0;
1196 pp_context->sampler_size = 4 * 4096;
1198 bo_size = 4096 + pp_context->curbe_size + pp_context->sampler_size
1199 + pp_context->idrt_size;
1201 dri_bo_unreference(pp_context->dynamic_state.bo);
1202 bo = dri_bo_alloc(i965->intel.bufmgr,
1208 pp_context->dynamic_state.bo = bo;
1209 pp_context->dynamic_state.bo_size = bo_size;
1212 pp_context->dynamic_state.end_offset = 0;
1214 /* Constant buffer offset */
1215 pp_context->curbe_offset = ALIGN(end_offset, 64);
1216 end_offset = pp_context->curbe_offset + pp_context->curbe_size;
1218 /* Interface descriptor offset */
1219 pp_context->idrt_offset = ALIGN(end_offset, 64);
1220 end_offset = pp_context->idrt_offset + pp_context->idrt_size;
1222 /* Sampler state offset */
1223 pp_context->sampler_offset = ALIGN(end_offset, 64);
1224 end_offset = pp_context->sampler_offset + pp_context->sampler_size;
1226 /* update the end offset of dynamic_state */
1227 pp_context->dynamic_state.end_offset = ALIGN(end_offset, 64);
1229 static_param_size = sizeof(struct gen7_pp_static_parameter);
1230 inline_param_size = sizeof(struct gen7_pp_inline_parameter);
1232 memset(pp_context->pp_static_parameter, 0, static_param_size);
1233 memset(pp_context->pp_inline_parameter, 0, inline_param_size);
1235 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
1236 pp_context->current_pp = pp_index;
1237 pp_module = &pp_context->pp_modules[pp_index];
1239 if (pp_module->initialize)
1240 va_status = pp_module->initialize(ctx, pp_context,
1247 va_status = VA_STATUS_ERROR_UNIMPLEMENTED;
1249 calculate_boundary_block_mask(pp_context, dst_rect);
1255 gen8_pp_interface_descriptor_table(VADriverContextP ctx,
1256 struct i965_post_processing_context *pp_context)
1258 struct gen8_interface_descriptor_data *desc;
1260 int pp_index = pp_context->current_pp;
1261 unsigned char *cc_ptr;
1263 bo = pp_context->dynamic_state.bo;
1266 assert(bo->virtual);
1267 cc_ptr = (unsigned char *)bo->virtual + pp_context->idrt_offset;
1269 desc = (struct gen8_interface_descriptor_data *) cc_ptr +
1270 pp_context->idrt.num_interface_descriptors;
1272 memset(desc, 0, sizeof(*desc));
1273 desc->desc0.kernel_start_pointer =
1274 pp_context->pp_modules[pp_index].kernel.kernel_offset >> 6; /* reloc */
1275 desc->desc2.single_program_flow = 1;
1276 desc->desc2.floating_point_mode = FLOATING_POINT_IEEE_754;
1277 desc->desc3.sampler_count = 0; /* 1 - 4 samplers used */
1278 desc->desc3.sampler_state_pointer = pp_context->sampler_offset >> 5;
1279 desc->desc4.binding_table_entry_count = 0;
1280 desc->desc4.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
1281 desc->desc5.constant_urb_entry_read_offset = 0;
1283 desc->desc5.constant_urb_entry_read_length = 8; /* grf 1-8 */
1286 pp_context->idrt.num_interface_descriptors++;
1291 gen8_pp_upload_constants(VADriverContextP ctx,
1292 struct i965_post_processing_context *pp_context)
1294 unsigned char *constant_buffer;
1297 assert(sizeof(struct gen7_pp_static_parameter) == 256);
1299 param_size = sizeof(struct gen7_pp_static_parameter);
1301 dri_bo_map(pp_context->dynamic_state.bo, 1);
1302 assert(pp_context->dynamic_state.bo->virtual);
1303 constant_buffer = (unsigned char *) pp_context->dynamic_state.bo->virtual +
1304 pp_context->curbe_offset;
1306 memcpy(constant_buffer, pp_context->pp_static_parameter, param_size);
1307 dri_bo_unmap(pp_context->dynamic_state.bo);
1312 gen8_pp_states_setup(VADriverContextP ctx,
1313 struct i965_post_processing_context *pp_context)
1315 gen8_pp_interface_descriptor_table(ctx, pp_context);
1316 gen8_pp_upload_constants(ctx, pp_context);
1320 gen6_pp_pipeline_select(VADriverContextP ctx,
1321 struct i965_post_processing_context *pp_context)
1323 struct intel_batchbuffer *batch = pp_context->batch;
1325 BEGIN_BATCH(batch, 1);
1326 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
1327 ADVANCE_BATCH(batch);
1331 gen8_pp_state_base_address(VADriverContextP ctx,
1332 struct i965_post_processing_context *pp_context)
1334 struct intel_batchbuffer *batch = pp_context->batch;
1336 BEGIN_BATCH(batch, 16);
1337 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (16 - 2));
1338 /* DW1 Generate state address */
1339 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1340 OUT_BATCH(batch, 0);
1341 OUT_BATCH(batch, 0);
1343 /* DW4-5. Surface state address */
1344 OUT_RELOC64(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
1346 /* DW6-7. Dynamic state address */
1347 OUT_RELOC64(batch, pp_context->dynamic_state.bo, I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_SAMPLER,
1348 0, 0 | BASE_ADDRESS_MODIFY);
1350 /* DW8. Indirect object address */
1351 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1352 OUT_BATCH(batch, 0);
1354 /* DW10-11. Instruction base address */
1355 OUT_RELOC64(batch, pp_context->instruction_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
1357 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
1358 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
1359 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
1360 OUT_BATCH(batch, 0xFFFF0000 | BASE_ADDRESS_MODIFY);
1361 ADVANCE_BATCH(batch);
1365 gen8_pp_vfe_state(VADriverContextP ctx,
1366 struct i965_post_processing_context *pp_context)
1368 struct intel_batchbuffer *batch = pp_context->batch;
1370 BEGIN_BATCH(batch, 9);
1371 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (9 - 2));
1372 OUT_BATCH(batch, 0);
1373 OUT_BATCH(batch, 0);
1375 (pp_context->vfe_gpu_state.max_num_threads - 1) << 16 |
1376 pp_context->vfe_gpu_state.num_urb_entries << 8);
1377 OUT_BATCH(batch, 0);
1379 (pp_context->vfe_gpu_state.urb_entry_size) << 16 |
1380 /* URB Entry Allocation Size, in 256 bits unit */
1381 (pp_context->vfe_gpu_state.curbe_allocation_size));
1382 /* CURBE Allocation Size, in 256 bits unit */
1383 OUT_BATCH(batch, 0);
1384 OUT_BATCH(batch, 0);
1385 OUT_BATCH(batch, 0);
1386 ADVANCE_BATCH(batch);
1390 gen8_interface_descriptor_load(VADriverContextP ctx,
1391 struct i965_post_processing_context *pp_context)
1393 struct intel_batchbuffer *batch = pp_context->batch;
1395 BEGIN_BATCH(batch, 6);
1397 OUT_BATCH(batch, CMD_MEDIA_STATE_FLUSH);
1398 OUT_BATCH(batch, 0);
1400 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
1401 OUT_BATCH(batch, 0);
1403 pp_context->idrt.num_interface_descriptors * sizeof(struct gen8_interface_descriptor_data));
1404 OUT_BATCH(batch, pp_context->idrt_offset);
1405 ADVANCE_BATCH(batch);
1409 gen8_pp_curbe_load(VADriverContextP ctx,
1410 struct i965_post_processing_context *pp_context)
1412 struct intel_batchbuffer *batch = pp_context->batch;
1413 int param_size = 64;
1415 param_size = sizeof(struct gen7_pp_static_parameter);
1417 BEGIN_BATCH(batch, 4);
1418 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
1419 OUT_BATCH(batch, 0);
1422 OUT_BATCH(batch, pp_context->curbe_offset);
1423 ADVANCE_BATCH(batch);
1427 gen8_pp_object_walker(VADriverContextP ctx,
1428 struct i965_post_processing_context *pp_context)
1430 struct i965_driver_data *i965 = i965_driver_data(ctx);
1431 struct intel_batchbuffer *batch = pp_context->batch;
1432 int x, x_steps, y, y_steps;
1433 int param_size, command_length_in_dws, extra_cmd_in_dws;
1434 dri_bo *command_buffer;
1435 unsigned int *command_ptr;
1437 param_size = sizeof(struct gen7_pp_inline_parameter);
1439 x_steps = pp_context->pp_x_steps(pp_context->private_context);
1440 y_steps = pp_context->pp_y_steps(pp_context->private_context);
1441 command_length_in_dws = 6 + (param_size >> 2);
1442 extra_cmd_in_dws = 2;
1443 command_buffer = dri_bo_alloc(i965->intel.bufmgr,
1444 "command objects buffer",
1445 (command_length_in_dws + extra_cmd_in_dws) * 4 * x_steps * y_steps + 64,
1448 dri_bo_map(command_buffer, 1);
1449 command_ptr = command_buffer->virtual;
1451 for (y = 0; y < y_steps; y++) {
1452 for (x = 0; x < x_steps; x++) {
1453 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
1455 *command_ptr++ = (CMD_MEDIA_OBJECT | (command_length_in_dws - 2));
1461 memcpy(command_ptr, pp_context->pp_inline_parameter, param_size);
1462 command_ptr += (param_size >> 2);
1464 *command_ptr++ = CMD_MEDIA_STATE_FLUSH;
1470 if ((command_length_in_dws + extra_cmd_in_dws) * x_steps * y_steps % 2 == 0)
1473 *command_ptr++ = MI_BATCH_BUFFER_END;
1476 dri_bo_unmap(command_buffer);
1478 BEGIN_BATCH(batch, 3);
1479 OUT_BATCH(batch, MI_BATCH_BUFFER_START | (1 << 8) | (1 << 0));
1480 OUT_RELOC64(batch, command_buffer,
1481 I915_GEM_DOMAIN_COMMAND, 0, 0);
1482 ADVANCE_BATCH(batch);
1484 dri_bo_unreference(command_buffer);
1486 /* Have to execute the batch buffer here becuase MI_BATCH_BUFFER_END
1487 * will cause control to pass back to ring buffer
1489 intel_batchbuffer_end_atomic(batch);
1490 intel_batchbuffer_flush(batch);
1491 intel_batchbuffer_start_atomic(batch, 0x1000);
1495 gen8_pp_pipeline_setup(VADriverContextP ctx,
1496 struct i965_post_processing_context *pp_context)
1498 struct intel_batchbuffer *batch = pp_context->batch;
1500 intel_batchbuffer_start_atomic(batch, 0x1000);
1501 intel_batchbuffer_emit_mi_flush(batch);
1502 gen6_pp_pipeline_select(ctx, pp_context);
1503 gen8_pp_state_base_address(ctx, pp_context);
1504 gen8_pp_vfe_state(ctx, pp_context);
1505 gen8_pp_curbe_load(ctx, pp_context);
1506 gen8_interface_descriptor_load(ctx, pp_context);
1507 gen8_pp_vfe_state(ctx, pp_context);
1508 gen8_pp_object_walker(ctx, pp_context);
1509 intel_batchbuffer_end_atomic(batch);
1513 gen8_post_processing(
1514 VADriverContextP ctx,
1515 struct i965_post_processing_context *pp_context,
1516 const struct i965_surface *src_surface,
1517 const VARectangle *src_rect,
1518 struct i965_surface *dst_surface,
1519 const VARectangle *dst_rect,
1526 va_status = gen8_pp_initialize(ctx, pp_context,
1534 if (va_status == VA_STATUS_SUCCESS) {
1535 gen8_pp_states_setup(ctx, pp_context);
1536 gen8_pp_pipeline_setup(ctx, pp_context);
1543 gen8_post_processing_context_finalize(VADriverContextP ctx,
1544 struct i965_post_processing_context *pp_context)
1546 if (pp_context->scaling_context_initialized) {
1547 gen8_gpe_context_destroy(&pp_context->scaling_10bit_context);
1548 pp_context->scaling_context_initialized = 0;
1551 if (pp_context->scaling_8bit_initialized & VPPGPE_8BIT_420) {
1552 gen8_gpe_context_destroy(&pp_context->scaling_yuv420p8_context);
1553 pp_context->scaling_8bit_initialized &= ~(VPPGPE_8BIT_420);
1556 if (pp_context->vebox_proc_ctx) {
1557 gen75_vebox_context_destroy(ctx, pp_context->vebox_proc_ctx);
1558 pp_context->vebox_proc_ctx = NULL;
1561 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
1562 pp_context->surface_state_binding_table.bo = NULL;
1564 dri_bo_unreference(pp_context->pp_dn_context.stmm_bo);
1565 pp_context->pp_dn_context.stmm_bo = NULL;
1567 if (pp_context->instruction_state.bo) {
1568 dri_bo_unreference(pp_context->instruction_state.bo);
1569 pp_context->instruction_state.bo = NULL;
1572 if (pp_context->indirect_state.bo) {
1573 dri_bo_unreference(pp_context->indirect_state.bo);
1574 pp_context->indirect_state.bo = NULL;
1577 if (pp_context->dynamic_state.bo) {
1578 dri_bo_unreference(pp_context->dynamic_state.bo);
1579 pp_context->dynamic_state.bo = NULL;
1582 free(pp_context->pp_static_parameter);
1583 free(pp_context->pp_inline_parameter);
1584 pp_context->pp_static_parameter = NULL;
1585 pp_context->pp_inline_parameter = NULL;
1588 #define VPP_CURBE_ALLOCATION_SIZE 32
1591 gen8_post_processing_context_common_init(VADriverContextP ctx,
1593 struct pp_module *pp_modules,
1595 struct intel_batchbuffer *batch)
1597 struct i965_driver_data *i965 = i965_driver_data(ctx);
1599 unsigned int kernel_offset, end_offset;
1600 unsigned char *kernel_ptr;
1601 struct pp_module *pp_module;
1602 struct i965_post_processing_context *pp_context = data;
1604 if (i965->intel.eu_total > 0)
1605 pp_context->vfe_gpu_state.max_num_threads = 6 * i965->intel.eu_total;
1607 pp_context->vfe_gpu_state.max_num_threads = 60;
1608 pp_context->vfe_gpu_state.num_urb_entries = 59;
1609 pp_context->vfe_gpu_state.gpgpu_mode = 0;
1610 pp_context->vfe_gpu_state.urb_entry_size = 16 - 1;
1611 pp_context->vfe_gpu_state.curbe_allocation_size = VPP_CURBE_ALLOCATION_SIZE;
1613 pp_context->intel_post_processing = gen8_post_processing;
1614 pp_context->finalize = gen8_post_processing_context_finalize;
1616 assert(ARRAY_ELEMS(pp_context->pp_modules) == num_pp_modules);
1618 memcpy(pp_context->pp_modules, pp_modules, sizeof(pp_context->pp_modules));
1620 kernel_size = 4096 ;
1622 for (i = 0; i < NUM_PP_MODULES; i++) {
1623 pp_module = &pp_context->pp_modules[i];
1625 if (pp_module->kernel.bin && pp_module->kernel.size) {
1626 kernel_size += pp_module->kernel.size;
1630 pp_context->instruction_state.bo = dri_bo_alloc(i965->intel.bufmgr,
1634 if (pp_context->instruction_state.bo == NULL) {
1635 WARN_ONCE("failure to allocate the buffer space for kernel shader in VPP\n");
1639 assert(pp_context->instruction_state.bo);
1642 pp_context->instruction_state.bo_size = kernel_size;
1643 pp_context->instruction_state.end_offset = 0;
1646 dri_bo_map(pp_context->instruction_state.bo, 1);
1647 kernel_ptr = (unsigned char *)(pp_context->instruction_state.bo->virtual);
1649 for (i = 0; i < NUM_PP_MODULES; i++) {
1650 pp_module = &pp_context->pp_modules[i];
1652 kernel_offset = ALIGN(end_offset, 64);
1653 pp_module->kernel.kernel_offset = kernel_offset;
1655 if (pp_module->kernel.bin && pp_module->kernel.size) {
1657 memcpy(kernel_ptr + kernel_offset, pp_module->kernel.bin, pp_module->kernel.size);
1658 end_offset = kernel_offset + pp_module->kernel.size;
1662 pp_context->instruction_state.end_offset = ALIGN(end_offset, 64);
1664 dri_bo_unmap(pp_context->instruction_state.bo);
1666 /* static & inline parameters */
1667 pp_context->pp_static_parameter = calloc(sizeof(struct gen7_pp_static_parameter), 1);
1668 pp_context->pp_inline_parameter = calloc(sizeof(struct gen7_pp_inline_parameter), 1);
1670 pp_context->batch = batch;
1672 pp_context->idrt_size = 5 * sizeof(struct gen8_interface_descriptor_data);
1673 pp_context->curbe_size = 256;
1678 gen8_post_processing_context_init(VADriverContextP ctx,
1680 struct intel_batchbuffer *batch)
1682 struct i965_driver_data *i965 = i965_driver_data(ctx);
1683 struct i965_post_processing_context *pp_context = data;
1684 struct i965_gpe_context *gpe_context;
1685 struct i965_kernel scaling_kernel;
1687 gen8_post_processing_context_common_init(ctx, data, pp_modules_gen8, ARRAY_ELEMS(pp_modules_gen8), batch);
1688 avs_init_state(&pp_context->pp_avs_context.state, &gen8_avs_config);
1690 /* initialize the YUV420 8-Bit scaling context. The below is supported.
1696 gpe_context = &pp_context->scaling_yuv420p8_context;
1697 memset(&scaling_kernel, 0, sizeof(scaling_kernel));
1698 scaling_kernel.bin = pp_yuv420p8_scaling_gen8;
1699 scaling_kernel.size = sizeof(pp_yuv420p8_scaling_gen8);
1700 gen8_gpe_load_kernels(ctx, gpe_context, &scaling_kernel, 1);
1701 gpe_context->idrt.entry_size = ALIGN(sizeof(struct gen8_interface_descriptor_data), 64);
1702 gpe_context->idrt.max_entries = 1;
1703 gpe_context->sampler.entry_size = ALIGN(sizeof(struct gen8_sampler_state), 64);
1704 gpe_context->sampler.max_entries = 1;
1705 gpe_context->curbe.length = ALIGN(sizeof(struct scaling_input_parameter), 32);
1707 gpe_context->surface_state_binding_table.max_entries = MAX_SCALING_SURFACES;
1708 gpe_context->surface_state_binding_table.binding_table_offset = 0;
1709 gpe_context->surface_state_binding_table.surface_state_offset = ALIGN(MAX_SCALING_SURFACES * 4, 64);
1710 gpe_context->surface_state_binding_table.length = ALIGN(MAX_SCALING_SURFACES * 4, 64) + ALIGN(MAX_SCALING_SURFACES * SURFACE_STATE_PADDED_SIZE_GEN8, 64);
1712 if (i965->intel.eu_total > 0) {
1713 gpe_context->vfe_state.max_num_threads = i965->intel.eu_total * 6;
1715 if (i965->intel.has_bsd2)
1716 gpe_context->vfe_state.max_num_threads = 300;
1718 gpe_context->vfe_state.max_num_threads = 60;
1721 gpe_context->vfe_state.curbe_allocation_size = 37;
1722 gpe_context->vfe_state.urb_entry_size = 16;
1723 if (i965->intel.has_bsd2)
1724 gpe_context->vfe_state.num_urb_entries = 127;
1726 gpe_context->vfe_state.num_urb_entries = 64;
1728 gpe_context->vfe_state.gpgpu_mode = 0;
1730 gen8_gpe_context_init(ctx, gpe_context);
1731 pp_context->scaling_8bit_initialized = VPPGPE_8BIT_420;
1736 gen8_run_kernel_media_object_walker(VADriverContextP ctx,
1737 struct intel_batchbuffer *batch,
1738 struct i965_gpe_context *gpe_context,
1739 struct gpe_media_object_walker_parameter *param)
1741 if (!batch || !gpe_context || !param)
1744 intel_batchbuffer_start_atomic(batch, 0x1000);
1746 intel_batchbuffer_emit_mi_flush(batch);
1748 gen8_gpe_pipeline_setup(ctx, gpe_context, batch);
1749 gen8_gpe_media_object_walker(ctx, gpe_context, batch, param);
1750 gen8_gpe_media_state_flush(ctx, gpe_context, batch);
1753 intel_batchbuffer_end_atomic(batch);
1755 intel_batchbuffer_flush(batch);
1760 gen8_add_dri_buffer_2d_gpe_surface(VADriverContextP ctx,
1761 struct i965_gpe_context *gpe_context,
1763 unsigned int bo_offset,
1765 unsigned int height,
1767 int is_media_block_rw,
1768 unsigned int format,
1772 struct i965_gpe_resource gpe_resource;
1773 struct i965_gpe_surface gpe_surface;
1775 i965_dri_object_to_2d_gpe_resource(&gpe_resource, bo, width, height, pitch);
1776 memset(&gpe_surface, 0, sizeof(gpe_surface));
1777 gpe_surface.gpe_resource = &gpe_resource;
1778 gpe_surface.is_2d_surface = 1;
1779 gpe_surface.is_media_block_rw = !!is_media_block_rw;
1780 gpe_surface.cacheability_control = DEFAULT_MOCS;
1781 gpe_surface.format = format;
1782 gpe_surface.is_override_offset = 1;
1783 gpe_surface.offset = bo_offset;
1784 gpe_surface.is_16bpp = is_10bit;
1786 gen9_gpe_context_add_surface(gpe_context, &gpe_surface, index);
1788 i965_free_gpe_resource(&gpe_resource);
1792 gen8_vpp_scaling_sample_state(VADriverContextP ctx,
1793 struct i965_gpe_context *gpe_context,
1794 VARectangle *src_rect,
1795 VARectangle *dst_rect)
1797 struct gen8_sampler_state *sampler_state;
1799 if (gpe_context == NULL || !src_rect || !dst_rect)
1801 dri_bo_map(gpe_context->sampler.bo, 1);
1803 if (gpe_context->sampler.bo->virtual == NULL)
1806 assert(gpe_context->sampler.bo->virtual);
1808 sampler_state = (struct gen8_sampler_state *)
1809 (gpe_context->sampler.bo->virtual + gpe_context->sampler.offset);
1811 memset(sampler_state, 0, sizeof(*sampler_state));
1813 if ((src_rect->width == dst_rect->width) &&
1814 (src_rect->height == dst_rect->height)) {
1815 sampler_state->ss0.min_filter = I965_MAPFILTER_NEAREST;
1816 sampler_state->ss0.mag_filter = I965_MAPFILTER_NEAREST;
1818 sampler_state->ss0.min_filter = I965_MAPFILTER_LINEAR;
1819 sampler_state->ss0.mag_filter = I965_MAPFILTER_LINEAR;
1822 sampler_state->ss3.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1823 sampler_state->ss3.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1824 sampler_state->ss3.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
1826 dri_bo_unmap(gpe_context->sampler.bo);
1830 gen8_gpe_context_yuv420p8_scaling_curbe(VADriverContextP ctx,
1831 struct i965_gpe_context *gpe_context,
1832 VARectangle *src_rect,
1833 struct i965_surface *src_surface,
1834 VARectangle *dst_rect,
1835 struct i965_surface *dst_surface)
1837 struct scaling_input_parameter *scaling_curbe;
1838 float src_width, src_height;
1840 unsigned int fourcc;
1842 if ((gpe_context == NULL) ||
1843 (src_rect == NULL) || (src_surface == NULL) ||
1844 (dst_rect == NULL) || (dst_surface == NULL))
1847 scaling_curbe = i965_gpe_context_map_curbe(gpe_context);
1852 memset(scaling_curbe, 0, sizeof(struct scaling_input_parameter));
1854 scaling_curbe->bti_input = BTI_SCALING_INPUT_Y;
1855 scaling_curbe->bti_output = BTI_SCALING_OUTPUT_Y;
1857 /* As the src_rect/dst_rect is already checked, it is skipped.*/
1858 scaling_curbe->x_dst = dst_rect->x;
1859 scaling_curbe->y_dst = dst_rect->y;
1861 src_width = src_rect->x + src_rect->width;
1862 src_height = src_rect->y + src_rect->height;
1864 scaling_curbe->inv_width = 1 / src_width;
1865 scaling_curbe->inv_height = 1 / src_height;
1867 coeff = (float)(src_rect->width) / dst_rect->width;
1868 scaling_curbe->x_factor = coeff / src_width;
1869 scaling_curbe->x_orig = (float)(src_rect->x) / src_width;
1871 coeff = (float)(src_rect->height) / dst_rect->height;
1872 scaling_curbe->y_factor = coeff / src_height;
1873 scaling_curbe->y_orig = (float)(src_rect->y) / src_height;
1875 fourcc = pp_get_surface_fourcc(ctx, src_surface);
1876 if (fourcc == VA_FOURCC_NV12) {
1877 scaling_curbe->dw7.src_packed = 1;
1880 fourcc = pp_get_surface_fourcc(ctx, dst_surface);
1882 if (fourcc == VA_FOURCC_NV12) {
1883 scaling_curbe->dw7.dst_packed = 1;
1886 i965_gpe_context_unmap_curbe(gpe_context);
1890 gen8_pp_context_get_surface_conf(VADriverContextP ctx,
1891 struct i965_surface *surface,
1898 unsigned int fourcc;
1899 if (!rect || !surface || !width || !height || !pitch || !bo_offset)
1902 if (surface->base == NULL)
1905 fourcc = pp_get_surface_fourcc(ctx, surface);
1906 if (surface->type == I965_SURFACE_TYPE_SURFACE) {
1907 struct object_surface *obj_surface;
1909 obj_surface = (struct object_surface *)surface->base;
1910 width[0] = MIN(rect->x + rect->width, obj_surface->orig_width);
1911 height[0] = MIN(rect->y + rect->height, obj_surface->orig_height);
1912 pitch[0] = obj_surface->width;
1915 if (fourcc == VA_FOURCC_P010 || fourcc == VA_FOURCC_NV12) {
1916 width[1] = width[0] / 2;
1917 height[1] = height[0] / 2;
1918 pitch[1] = obj_surface->cb_cr_pitch;
1919 bo_offset[1] = obj_surface->width * obj_surface->y_cb_offset;
1921 /* I010/I420 format */
1922 width[1] = width[0] / 2;
1923 height[1] = height[0] / 2;
1924 pitch[1] = obj_surface->cb_cr_pitch;
1925 bo_offset[1] = obj_surface->width * obj_surface->y_cb_offset;
1926 width[2] = width[0] / 2;
1927 height[2] = height[0] / 2;
1928 pitch[2] = obj_surface->cb_cr_pitch;
1929 bo_offset[2] = obj_surface->width * obj_surface->y_cr_offset;
1933 struct object_image *obj_image;
1935 obj_image = (struct object_image *)surface->base;
1937 width[0] = MIN(rect->x + rect->width, obj_image->image.width);
1938 height[0] = MIN(rect->y + rect->height, obj_image->image.height);
1939 pitch[0] = obj_image->image.pitches[0];
1940 bo_offset[0] = obj_image->image.offsets[0];
1942 if (fourcc == VA_FOURCC_P010 || fourcc == VA_FOURCC_NV12) {
1943 width[1] = width[0] / 2;
1944 height[1] = height[0] / 2;
1945 pitch[1] = obj_image->image.pitches[1];
1946 bo_offset[1] = obj_image->image.offsets[1];
1948 /* I010/I420 format */
1950 width[1] = width[0] / 2;
1951 height[1] = height[0] / 2;
1952 pitch[1] = obj_image->image.pitches[1];
1953 bo_offset[1] = obj_image->image.offsets[1];
1954 width[2] = width[0] / 2;
1955 height[2] = height[0] / 2;
1956 pitch[2] = obj_image->image.pitches[2];
1957 bo_offset[2] = obj_image->image.offsets[2];
1965 gen8_gpe_context_yuv420p8_scaling_surfaces(VADriverContextP ctx,
1966 struct i965_gpe_context *gpe_context,
1967 VARectangle *src_rect,
1968 struct i965_surface *src_surface,
1969 VARectangle *dst_rect,
1970 struct i965_surface *dst_surface)
1972 unsigned int fourcc;
1973 int width[3], height[3], pitch[3], bo_offset[3];
1975 struct object_surface *obj_surface;
1976 struct object_image *obj_image;
1979 if ((gpe_context == NULL) ||
1980 (src_rect == NULL) || (src_surface == NULL) ||
1981 (dst_rect == NULL) || (dst_surface == NULL))
1984 if (src_surface->base == NULL || dst_surface->base == NULL)
1987 fourcc = pp_get_surface_fourcc(ctx, src_surface);
1989 if (src_surface->type == I965_SURFACE_TYPE_SURFACE) {
1990 obj_surface = (struct object_surface *)src_surface->base;
1991 bo = obj_surface->bo;
1993 obj_image = (struct object_image *)src_surface->base;
1998 if (gen8_pp_context_get_surface_conf(ctx, src_surface, src_rect,
1999 width, height, pitch,
2001 bti = BTI_SCALING_INPUT_Y;
2003 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2005 width[0], height[0],
2007 I965_SURFACEFORMAT_R8_UNORM,
2009 if (fourcc == VA_FOURCC_NV12) {
2010 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2012 width[1], height[1],
2014 I965_SURFACEFORMAT_R8G8_UNORM,
2017 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2019 width[1], height[1],
2021 I965_SURFACEFORMAT_R8_UNORM,
2024 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2026 width[2], height[2],
2028 I965_SURFACEFORMAT_R8_UNORM,
2033 fourcc = pp_get_surface_fourcc(ctx, dst_surface);
2035 if (dst_surface->type == I965_SURFACE_TYPE_SURFACE) {
2036 obj_surface = (struct object_surface *)dst_surface->base;
2037 bo = obj_surface->bo;
2039 obj_image = (struct object_image *)dst_surface->base;
2043 if (gen8_pp_context_get_surface_conf(ctx, dst_surface, dst_rect,
2044 width, height, pitch,
2046 bti = BTI_SCALING_OUTPUT_Y;
2048 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2050 width[0], height[0],
2052 I965_SURFACEFORMAT_R8_UINT,
2054 if (fourcc == VA_FOURCC_NV12) {
2055 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2057 width[1] * 2, height[1],
2059 I965_SURFACEFORMAT_R16_UINT,
2062 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2064 width[1], height[1],
2066 I965_SURFACEFORMAT_R8_UINT,
2069 gen8_add_dri_buffer_2d_gpe_surface(ctx, gpe_context, bo,
2071 width[2], height[2],
2073 I965_SURFACEFORMAT_R8_UINT,
2082 gen8_yuv420p8_scaling_post_processing(
2083 VADriverContextP ctx,
2084 struct i965_post_processing_context *pp_context,
2085 struct i965_surface *src_surface,
2086 VARectangle *src_rect,
2087 struct i965_surface *dst_surface,
2088 VARectangle *dst_rect)
2090 struct i965_gpe_context *gpe_context;
2091 struct gpe_media_object_walker_parameter media_object_walker_param;
2092 struct intel_vpp_kernel_walker_parameter kernel_walker_param;
2094 if (!pp_context || !src_surface || !src_rect || !dst_surface || !dst_rect)
2095 return VA_STATUS_ERROR_INVALID_PARAMETER;
2097 if (!(pp_context->scaling_8bit_initialized & VPPGPE_8BIT_420))
2098 return VA_STATUS_ERROR_UNIMPLEMENTED;
2100 gpe_context = &pp_context->scaling_yuv420p8_context;
2102 gen8_gpe_context_init(ctx, gpe_context);
2103 gen8_vpp_scaling_sample_state(ctx, gpe_context, src_rect, dst_rect);
2104 gen8_gpe_reset_binding_table(ctx, gpe_context);
2105 gen8_gpe_context_yuv420p8_scaling_curbe(ctx, gpe_context,
2106 src_rect, src_surface,
2107 dst_rect, dst_surface);
2109 gen8_gpe_context_yuv420p8_scaling_surfaces(ctx, gpe_context,
2110 src_rect, src_surface,
2111 dst_rect, dst_surface);
2113 gen8_gpe_setup_interface_data(ctx, gpe_context);
2115 memset(&kernel_walker_param, 0, sizeof(kernel_walker_param));
2116 kernel_walker_param.resolution_x = ALIGN(dst_rect->width, 16) >> 4;
2117 kernel_walker_param.resolution_y = ALIGN(dst_rect->height, 16) >> 4;
2118 kernel_walker_param.no_dependency = 1;
2120 intel_vpp_init_media_object_walker_parameter(&kernel_walker_param, &media_object_walker_param);
2122 gen8_run_kernel_media_object_walker(ctx, pp_context->batch,
2124 &media_object_walker_param);
2126 return VA_STATUS_SUCCESS;