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 <va/va_backend.h>
36 #include "intel_batchbuffer.h"
37 #include "intel_driver.h"
38 #include "i965_defines.h"
39 #include "i965_structs.h"
40 #include "i965_drv_video.h"
41 #include "i965_post_processing.h"
42 #include "i965_render.h"
44 #define HAS_PP(ctx) (IS_IRONLAKE((ctx)->intel.device_id) || \
45 IS_GEN6((ctx)->intel.device_id) || \
46 IS_GEN7((ctx)->intel.device_id))
48 #define SURFACE_STATE_PADDED_SIZE_0_I965 ALIGN(sizeof(struct i965_surface_state), 32)
49 #define SURFACE_STATE_PADDED_SIZE_1_I965 ALIGN(sizeof(struct i965_surface_state2), 32)
50 #define SURFACE_STATE_PADDED_SIZE_I965 MAX(SURFACE_STATE_PADDED_SIZE_0_I965, SURFACE_STATE_PADDED_SIZE_1_I965)
52 #define SURFACE_STATE_PADDED_SIZE SURFACE_STATE_PADDED_SIZE_I965
53 #define SURFACE_STATE_OFFSET(index) (SURFACE_STATE_PADDED_SIZE * index)
54 #define BINDING_TABLE_OFFSET SURFACE_STATE_OFFSET(MAX_PP_SURFACES)
56 static const uint32_t pp_null_gen5[][4] = {
57 #include "shaders/post_processing/gen5_6/null.g4b.gen5"
60 static const uint32_t pp_nv12_load_save_nv12_gen5[][4] = {
61 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g4b.gen5"
64 static const uint32_t pp_nv12_load_save_pl3_gen5[][4] = {
65 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g4b.gen5"
68 static const uint32_t pp_pl3_load_save_nv12_gen5[][4] = {
69 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g4b.gen5"
72 static const uint32_t pp_pl3_load_save_pl3_gen5[][4] = {
73 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g4b.gen5"
76 static const uint32_t pp_nv12_scaling_gen5[][4] = {
77 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g4b.gen5"
80 static const uint32_t pp_nv12_avs_gen5[][4] = {
81 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g4b.gen5"
84 static const uint32_t pp_nv12_dndi_gen5[][4] = {
85 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g4b.gen5"
88 static void pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
89 const struct i965_surface *src_surface,
90 const VARectangle *src_rect,
91 const struct i965_surface *dst_surface,
92 const VARectangle *dst_rect,
94 static void pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
95 const struct i965_surface *src_surface,
96 const VARectangle *src_rect,
97 const struct i965_surface *dst_surface,
98 const VARectangle *dst_rect,
100 static void pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
101 const struct i965_surface *src_surface,
102 const VARectangle *src_rect,
103 const struct i965_surface *dst_surface,
104 const VARectangle *dst_rect,
106 static void pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
107 const struct i965_surface *src_surface,
108 const VARectangle *src_rect,
109 const struct i965_surface *dst_surface,
110 const VARectangle *dst_rect,
112 static void pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
113 const struct i965_surface *src_surface,
114 const VARectangle *src_rect,
115 const struct i965_surface *dst_surface,
116 const VARectangle *dst_rect,
119 static struct pp_module pp_modules_gen5[] = {
122 "NULL module (for testing)",
125 sizeof(pp_null_gen5),
135 PP_NV12_LOAD_SAVE_N12,
136 pp_nv12_load_save_nv12_gen5,
137 sizeof(pp_nv12_load_save_nv12_gen5),
141 pp_plx_load_save_plx_initialize,
147 PP_NV12_LOAD_SAVE_PL3,
148 pp_nv12_load_save_pl3_gen5,
149 sizeof(pp_nv12_load_save_pl3_gen5),
153 pp_plx_load_save_plx_initialize,
159 PP_PL3_LOAD_SAVE_N12,
160 pp_pl3_load_save_nv12_gen5,
161 sizeof(pp_pl3_load_save_nv12_gen5),
165 pp_plx_load_save_plx_initialize,
171 PP_PL3_LOAD_SAVE_N12,
172 pp_pl3_load_save_pl3_gen5,
173 sizeof(pp_pl3_load_save_pl3_gen5),
177 pp_plx_load_save_plx_initialize
182 "NV12 Scaling module",
184 pp_nv12_scaling_gen5,
185 sizeof(pp_nv12_scaling_gen5),
189 pp_nv12_scaling_initialize,
197 sizeof(pp_nv12_avs_gen5),
201 pp_nv12_avs_initialize,
209 sizeof(pp_nv12_dndi_gen5),
213 pp_nv12_dndi_initialize,
217 static const uint32_t pp_null_gen6[][4] = {
218 #include "shaders/post_processing/gen5_6/null.g6b"
221 static const uint32_t pp_nv12_load_save_nv12_gen6[][4] = {
222 #include "shaders/post_processing/gen5_6/nv12_load_save_nv12.g6b"
225 static const uint32_t pp_nv12_load_save_pl3_gen6[][4] = {
226 #include "shaders/post_processing/gen5_6/nv12_load_save_pl3.g6b"
229 static const uint32_t pp_pl3_load_save_nv12_gen6[][4] = {
230 #include "shaders/post_processing/gen5_6/pl3_load_save_nv12.g6b"
233 static const uint32_t pp_pl3_load_save_pl3_gen6[][4] = {
234 #include "shaders/post_processing/gen5_6/pl3_load_save_pl3.g6b"
237 static const uint32_t pp_nv12_scaling_gen6[][4] = {
238 #include "shaders/post_processing/gen5_6/nv12_scaling_nv12.g6b"
241 static const uint32_t pp_nv12_avs_gen6[][4] = {
242 #include "shaders/post_processing/gen5_6/nv12_avs_nv12.g6b"
245 static const uint32_t pp_nv12_dndi_gen6[][4] = {
246 #include "shaders/post_processing/gen5_6/nv12_dndi_nv12.g6b"
249 static struct pp_module pp_modules_gen6[] = {
252 "NULL module (for testing)",
255 sizeof(pp_null_gen6),
265 PP_NV12_LOAD_SAVE_N12,
266 pp_nv12_load_save_nv12_gen6,
267 sizeof(pp_nv12_load_save_nv12_gen6),
271 pp_plx_load_save_plx_initialize,
277 PP_NV12_LOAD_SAVE_PL3,
278 pp_nv12_load_save_pl3_gen6,
279 sizeof(pp_nv12_load_save_pl3_gen6),
283 pp_plx_load_save_plx_initialize,
289 PP_PL3_LOAD_SAVE_N12,
290 pp_pl3_load_save_nv12_gen6,
291 sizeof(pp_pl3_load_save_nv12_gen6),
295 pp_plx_load_save_plx_initialize,
301 PP_PL3_LOAD_SAVE_N12,
302 pp_pl3_load_save_pl3_gen6,
303 sizeof(pp_pl3_load_save_pl3_gen6),
307 pp_plx_load_save_plx_initialize,
312 "NV12 Scaling module",
314 pp_nv12_scaling_gen6,
315 sizeof(pp_nv12_scaling_gen6),
319 pp_nv12_scaling_initialize,
327 sizeof(pp_nv12_avs_gen6),
331 pp_nv12_avs_initialize,
339 sizeof(pp_nv12_dndi_gen6),
343 pp_nv12_dndi_initialize,
347 #define pp_static_parameter pp_context->pp_static_parameter
348 #define pp_inline_parameter pp_context->pp_inline_parameter
351 pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
353 struct i965_driver_data *i965 = i965_driver_data(ctx);
356 if (surface->flag == I965_SURFACE_IMAGE) {
357 struct object_image *obj_image = IMAGE(surface->id);
358 fourcc = obj_image->image.format.fourcc;
360 struct object_surface *obj_surface = SURFACE(surface->id);
361 fourcc = obj_surface->fourcc;
368 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
371 case I915_TILING_NONE:
372 ss->ss3.tiled_surface = 0;
373 ss->ss3.tile_walk = 0;
376 ss->ss3.tiled_surface = 1;
377 ss->ss3.tile_walk = I965_TILEWALK_XMAJOR;
380 ss->ss3.tiled_surface = 1;
381 ss->ss3.tile_walk = I965_TILEWALK_YMAJOR;
387 pp_set_surface2_tiling(struct i965_surface_state2 *ss, unsigned int tiling)
390 case I915_TILING_NONE:
391 ss->ss2.tiled_surface = 0;
392 ss->ss2.tile_walk = 0;
395 ss->ss2.tiled_surface = 1;
396 ss->ss2.tile_walk = I965_TILEWALK_XMAJOR;
399 ss->ss2.tiled_surface = 1;
400 ss->ss2.tile_walk = I965_TILEWALK_YMAJOR;
406 ironlake_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
408 struct i965_interface_descriptor *desc;
410 int pp_index = pp_context->current_pp;
412 bo = pp_context->idrt.bo;
416 memset(desc, 0, sizeof(*desc));
417 desc->desc0.grf_reg_blocks = 10;
418 desc->desc0.kernel_start_pointer = pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
419 desc->desc1.const_urb_entry_read_offset = 0;
420 desc->desc1.const_urb_entry_read_len = 4; /* grf 1-4 */
421 desc->desc2.sampler_state_pointer = pp_context->sampler_state_table.bo->offset >> 5;
422 desc->desc2.sampler_count = 0;
423 desc->desc3.binding_table_entry_count = 0;
424 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
426 dri_bo_emit_reloc(bo,
427 I915_GEM_DOMAIN_INSTRUCTION, 0,
428 desc->desc0.grf_reg_blocks,
429 offsetof(struct i965_interface_descriptor, desc0),
430 pp_context->pp_modules[pp_index].kernel.bo);
432 dri_bo_emit_reloc(bo,
433 I915_GEM_DOMAIN_INSTRUCTION, 0,
434 desc->desc2.sampler_count << 2,
435 offsetof(struct i965_interface_descriptor, desc2),
436 pp_context->sampler_state_table.bo);
439 pp_context->idrt.num_interface_descriptors++;
443 ironlake_pp_vfe_state(struct i965_post_processing_context *pp_context)
445 struct i965_vfe_state *vfe_state;
448 bo = pp_context->vfe_state.bo;
451 vfe_state = bo->virtual;
452 memset(vfe_state, 0, sizeof(*vfe_state));
453 vfe_state->vfe1.max_threads = pp_context->urb.num_vfe_entries - 1;
454 vfe_state->vfe1.urb_entry_alloc_size = pp_context->urb.size_vfe_entry - 1;
455 vfe_state->vfe1.num_urb_entries = pp_context->urb.num_vfe_entries;
456 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
457 vfe_state->vfe1.children_present = 0;
458 vfe_state->vfe2.interface_descriptor_base =
459 pp_context->idrt.bo->offset >> 4; /* reloc */
460 dri_bo_emit_reloc(bo,
461 I915_GEM_DOMAIN_INSTRUCTION, 0,
463 offsetof(struct i965_vfe_state, vfe2),
464 pp_context->idrt.bo);
469 ironlake_pp_upload_constants(struct i965_post_processing_context *pp_context)
471 unsigned char *constant_buffer;
473 assert(sizeof(pp_static_parameter) == 128);
474 dri_bo_map(pp_context->curbe.bo, 1);
475 assert(pp_context->curbe.bo->virtual);
476 constant_buffer = pp_context->curbe.bo->virtual;
477 memcpy(constant_buffer, &pp_static_parameter, sizeof(pp_static_parameter));
478 dri_bo_unmap(pp_context->curbe.bo);
482 ironlake_pp_states_setup(VADriverContextP ctx,
483 struct i965_post_processing_context *pp_context)
485 ironlake_pp_interface_descriptor_table(pp_context);
486 ironlake_pp_vfe_state(pp_context);
487 ironlake_pp_upload_constants(pp_context);
491 ironlake_pp_pipeline_select(VADriverContextP ctx,
492 struct i965_post_processing_context *pp_context)
494 struct intel_batchbuffer *batch = pp_context->batch;
496 BEGIN_BATCH(batch, 1);
497 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
498 ADVANCE_BATCH(batch);
502 ironlake_pp_urb_layout(VADriverContextP ctx,
503 struct i965_post_processing_context *pp_context)
505 struct intel_batchbuffer *batch = pp_context->batch;
506 unsigned int vfe_fence, cs_fence;
508 vfe_fence = pp_context->urb.cs_start;
509 cs_fence = pp_context->urb.size;
511 BEGIN_BATCH(batch, 3);
512 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
515 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
516 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
517 ADVANCE_BATCH(batch);
521 ironlake_pp_state_base_address(VADriverContextP ctx,
522 struct i965_post_processing_context *pp_context)
524 struct intel_batchbuffer *batch = pp_context->batch;
526 BEGIN_BATCH(batch, 8);
527 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
528 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
529 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
530 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
531 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
532 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
533 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
534 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
535 ADVANCE_BATCH(batch);
539 ironlake_pp_state_pointers(VADriverContextP ctx,
540 struct i965_post_processing_context *pp_context)
542 struct intel_batchbuffer *batch = pp_context->batch;
544 BEGIN_BATCH(batch, 3);
545 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
547 OUT_RELOC(batch, pp_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
548 ADVANCE_BATCH(batch);
552 ironlake_pp_cs_urb_layout(VADriverContextP ctx,
553 struct i965_post_processing_context *pp_context)
555 struct intel_batchbuffer *batch = pp_context->batch;
557 BEGIN_BATCH(batch, 2);
558 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
560 ((pp_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
561 (pp_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
562 ADVANCE_BATCH(batch);
566 ironlake_pp_constant_buffer(VADriverContextP ctx,
567 struct i965_post_processing_context *pp_context)
569 struct intel_batchbuffer *batch = pp_context->batch;
571 BEGIN_BATCH(batch, 2);
572 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
573 OUT_RELOC(batch, pp_context->curbe.bo,
574 I915_GEM_DOMAIN_INSTRUCTION, 0,
575 pp_context->urb.size_cs_entry - 1);
576 ADVANCE_BATCH(batch);
580 ironlake_pp_object_walker(VADriverContextP ctx,
581 struct i965_post_processing_context *pp_context)
583 struct intel_batchbuffer *batch = pp_context->batch;
584 int x, x_steps, y, y_steps;
586 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
587 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
589 for (y = 0; y < y_steps; y++) {
590 for (x = 0; x < x_steps; x++) {
591 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
592 BEGIN_BATCH(batch, 20);
593 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 18);
595 OUT_BATCH(batch, 0); /* no indirect data */
598 /* inline data grf 5-6 */
599 assert(sizeof(pp_inline_parameter) == 64);
600 intel_batchbuffer_data(batch, &pp_inline_parameter, sizeof(pp_inline_parameter));
602 ADVANCE_BATCH(batch);
609 ironlake_pp_pipeline_setup(VADriverContextP ctx,
610 struct i965_post_processing_context *pp_context)
612 struct intel_batchbuffer *batch = pp_context->batch;
614 intel_batchbuffer_start_atomic(batch, 0x1000);
615 intel_batchbuffer_emit_mi_flush(batch);
616 ironlake_pp_pipeline_select(ctx, pp_context);
617 ironlake_pp_state_base_address(ctx, pp_context);
618 ironlake_pp_state_pointers(ctx, pp_context);
619 ironlake_pp_urb_layout(ctx, pp_context);
620 ironlake_pp_cs_urb_layout(ctx, pp_context);
621 ironlake_pp_constant_buffer(ctx, pp_context);
622 ironlake_pp_object_walker(ctx, pp_context);
623 intel_batchbuffer_end_atomic(batch);
627 i965_pp_set_surface_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
628 dri_bo *surf_bo, unsigned long surf_bo_offset,
629 int width, int height, int pitch, int format,
630 int index, int is_target)
632 struct i965_surface_state *ss;
635 unsigned int swizzle;
637 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
638 ss_bo = pp_context->surface_state_binding_table.bo;
641 dri_bo_map(ss_bo, True);
642 assert(ss_bo->virtual);
643 ss = (struct i965_surface_state *)((char *)ss_bo->virtual + SURFACE_STATE_OFFSET(index));
644 memset(ss, 0, sizeof(*ss));
645 ss->ss0.surface_type = I965_SURFACE_2D;
646 ss->ss0.surface_format = format;
647 ss->ss1.base_addr = surf_bo->offset + surf_bo_offset;
648 ss->ss2.width = width - 1;
649 ss->ss2.height = height - 1;
650 ss->ss3.pitch = pitch - 1;
651 pp_set_surface_tiling(ss, tiling);
652 dri_bo_emit_reloc(ss_bo,
653 I915_GEM_DOMAIN_RENDER, is_target ? I915_GEM_DOMAIN_RENDER : 0,
655 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state, ss1),
657 ((unsigned int *)((char *)ss_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
662 i965_pp_set_surface2_state(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
663 dri_bo *surf_bo, unsigned long surf_bo_offset,
664 int width, int height, int wpitch,
665 int xoffset, int yoffset,
666 int format, int interleave_chroma,
669 struct i965_surface_state2 *ss2;
672 unsigned int swizzle;
674 dri_bo_get_tiling(surf_bo, &tiling, &swizzle);
675 ss2_bo = pp_context->surface_state_binding_table.bo;
678 dri_bo_map(ss2_bo, True);
679 assert(ss2_bo->virtual);
680 ss2 = (struct i965_surface_state2 *)((char *)ss2_bo->virtual + SURFACE_STATE_OFFSET(index));
681 memset(ss2, 0, sizeof(*ss2));
682 ss2->ss0.surface_base_address = surf_bo->offset + surf_bo_offset;
683 ss2->ss1.cbcr_pixel_offset_v_direction = 0;
684 ss2->ss1.width = width - 1;
685 ss2->ss1.height = height - 1;
686 ss2->ss2.pitch = wpitch - 1;
687 ss2->ss2.interleave_chroma = interleave_chroma;
688 ss2->ss2.surface_format = format;
689 ss2->ss3.x_offset_for_cb = xoffset;
690 ss2->ss3.y_offset_for_cb = yoffset;
691 pp_set_surface2_tiling(ss2, tiling);
692 dri_bo_emit_reloc(ss2_bo,
693 I915_GEM_DOMAIN_RENDER, 0,
695 SURFACE_STATE_OFFSET(index) + offsetof(struct i965_surface_state2, ss0),
697 ((unsigned int *)((char *)ss2_bo->virtual + BINDING_TABLE_OFFSET))[index] = SURFACE_STATE_OFFSET(index);
698 dri_bo_unmap(ss2_bo);
702 pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
703 const struct i965_surface *surface,
704 int base_index, int is_target,
705 int *width, int *height, int *pitch, int *offset)
707 struct i965_driver_data *i965 = i965_driver_data(ctx);
708 struct object_surface *obj_surface;
709 struct object_image *obj_image;
711 int fourcc = pp_get_surface_fourcc(ctx, surface);
713 const int U = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 2 : 1;
714 const int V = fourcc == VA_FOURCC('Y', 'V', '1', '2') ? 1 : 2;
716 int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
718 if (surface->flag == I965_SURFACE_SURFACE) {
719 obj_surface = SURFACE(surface->id);
720 bo = obj_surface->bo;
721 width[0] = obj_surface->orig_width;
722 height[0] = obj_surface->orig_height;
723 pitch[0] = obj_surface->width;
726 if (interleaved_uv) {
727 width[1] = obj_surface->orig_width;
728 height[1] = obj_surface->orig_height / 2;
729 pitch[1] = obj_surface->width;
730 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
732 width[1] = obj_surface->orig_width / 2;
733 height[1] = obj_surface->orig_height / 2;
734 pitch[1] = obj_surface->width / 2;
735 offset[1] = offset[0] + obj_surface->width * obj_surface->height;
736 width[2] = obj_surface->orig_width / 2;
737 height[2] = obj_surface->orig_height / 2;
738 pitch[2] = obj_surface->width / 2;
739 offset[2] = offset[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
742 obj_image = IMAGE(surface->id);
744 width[0] = obj_image->image.width;
745 height[0] = obj_image->image.height;
746 pitch[0] = obj_image->image.pitches[0];
747 offset[0] = obj_image->image.offsets[0];
749 if (interleaved_uv) {
750 width[1] = obj_image->image.width;
751 height[1] = obj_image->image.height / 2;
752 pitch[1] = obj_image->image.pitches[1];
753 offset[1] = obj_image->image.offsets[1];
755 width[1] = obj_image->image.width / 2;
756 height[1] = obj_image->image.height / 2;
757 pitch[1] = obj_image->image.pitches[1];
758 offset[1] = obj_image->image.offsets[1];
759 width[2] = obj_image->image.width / 2;
760 height[2] = obj_image->image.height / 2;
761 pitch[2] = obj_image->image.pitches[2];
762 offset[2] = obj_image->image.offsets[2];
767 i965_pp_set_surface_state(ctx, pp_context,
769 width[Y] / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
770 base_index, is_target);
772 if (interleaved_uv) {
773 i965_pp_set_surface_state(ctx, pp_context,
775 width[UV] / 4, height[UV], pitch[UV], I965_SURFACEFORMAT_R8_UNORM,
776 base_index + 1, is_target);
779 i965_pp_set_surface_state(ctx, pp_context,
781 width[U] / 4, height[U], pitch[U], I965_SURFACEFORMAT_R8_UNORM,
782 base_index + 1, is_target);
785 i965_pp_set_surface_state(ctx, pp_context,
787 width[V] / 4, height[V], pitch[V], I965_SURFACEFORMAT_R8_UNORM,
788 base_index + 2, is_target);
794 pp_null_x_steps(void *private_context)
800 pp_null_y_steps(void *private_context)
806 pp_null_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
812 pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
813 const struct i965_surface *src_surface,
814 const VARectangle *src_rect,
815 const struct i965_surface *dst_surface,
816 const VARectangle *dst_rect,
819 /* private function & data */
820 pp_context->pp_x_steps = pp_null_x_steps;
821 pp_context->pp_y_steps = pp_null_y_steps;
822 pp_context->pp_set_block_parameter = pp_null_set_block_parameter;
826 pp_load_save_x_steps(void *private_context)
832 pp_load_save_y_steps(void *private_context)
834 struct pp_load_save_context *pp_load_save_context = private_context;
836 return pp_load_save_context->dest_h / 8;
840 pp_load_save_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
842 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
843 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
844 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16;
845 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8;
851 pp_plx_load_save_plx_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
852 const struct i965_surface *src_surface,
853 const VARectangle *src_rect,
854 const struct i965_surface *dst_surface,
855 const VARectangle *dst_rect,
858 struct pp_load_save_context *pp_load_save_context = (struct pp_load_save_context *)&pp_context->private_context;
859 int width[3], height[3], pitch[3], offset[3];
863 pp_set_media_rw_message_surface(ctx, pp_context, src_surface, 1, 0,
864 width, height, pitch, offset);
866 /* destination surface */
867 pp_set_media_rw_message_surface(ctx, pp_context, dst_surface, 7, 1,
868 width, height, pitch, offset);
870 /* private function & data */
871 pp_context->pp_x_steps = pp_load_save_x_steps;
872 pp_context->pp_y_steps = pp_load_save_y_steps;
873 pp_context->pp_set_block_parameter = pp_load_save_set_block_parameter;
874 pp_load_save_context->dest_h = ALIGN(height[Y], 16);
875 pp_load_save_context->dest_w = ALIGN(width[Y], 16);
877 pp_inline_parameter.grf5.block_count_x = ALIGN(width[Y], 16) / 16; /* 1 x N */
878 pp_inline_parameter.grf5.number_blocks = ALIGN(width[Y], 16) / 16;
882 pp_scaling_x_steps(void *private_context)
888 pp_scaling_y_steps(void *private_context)
890 struct pp_scaling_context *pp_scaling_context = private_context;
892 return pp_scaling_context->dest_h / 8;
896 pp_scaling_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
898 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
899 float src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
900 float src_y_steping = pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step;
902 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = src_x_steping * x * 16 + pp_scaling_context->src_normalized_x;
903 pp_inline_parameter.grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_scaling_context->src_normalized_y;
904 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16 + pp_scaling_context->dest_x;
905 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8 + pp_scaling_context->dest_y;
911 pp_nv12_scaling_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
912 const struct i965_surface *src_surface,
913 const VARectangle *src_rect,
914 const struct i965_surface *dst_surface,
915 const VARectangle *dst_rect,
918 struct i965_driver_data *i965 = i965_driver_data(ctx);
919 struct pp_scaling_context *pp_scaling_context = (struct pp_scaling_context *)&pp_context->private_context;
920 struct object_surface *obj_surface;
921 struct i965_sampler_state *sampler_state;
922 int in_w, in_h, in_wpitch, in_hpitch;
923 int out_w, out_h, out_wpitch, out_hpitch;
926 obj_surface = SURFACE(src_surface->id);
927 in_w = obj_surface->orig_width;
928 in_h = obj_surface->orig_height;
929 in_wpitch = obj_surface->width;
930 in_hpitch = obj_surface->height;
932 /* source Y surface index 1 */
933 i965_pp_set_surface_state(ctx, pp_context,
935 in_w, in_h, in_wpitch, I965_SURFACEFORMAT_R8_UNORM,
938 /* source UV surface index 2 */
939 i965_pp_set_surface_state(ctx, pp_context,
940 obj_surface->bo, in_wpitch * in_hpitch,
941 in_w / 2, in_h / 2, in_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
944 /* destination surface */
945 obj_surface = SURFACE(dst_surface->id);
946 out_w = obj_surface->orig_width;
947 out_h = obj_surface->orig_height;
948 out_wpitch = obj_surface->width;
949 out_hpitch = obj_surface->height;
951 /* destination Y surface index 7 */
952 i965_pp_set_surface_state(ctx, pp_context,
954 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
957 /* destination UV surface index 8 */
958 i965_pp_set_surface_state(ctx, pp_context,
959 obj_surface->bo, out_wpitch * out_hpitch,
960 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
964 dri_bo_map(pp_context->sampler_state_table.bo, True);
965 assert(pp_context->sampler_state_table.bo->virtual);
966 sampler_state = pp_context->sampler_state_table.bo->virtual;
968 /* SIMD16 Y index 1 */
969 sampler_state[1].ss0.min_filter = I965_MAPFILTER_LINEAR;
970 sampler_state[1].ss0.mag_filter = I965_MAPFILTER_LINEAR;
971 sampler_state[1].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
972 sampler_state[1].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
973 sampler_state[1].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
975 /* SIMD16 UV index 2 */
976 sampler_state[2].ss0.min_filter = I965_MAPFILTER_LINEAR;
977 sampler_state[2].ss0.mag_filter = I965_MAPFILTER_LINEAR;
978 sampler_state[2].ss1.r_wrap_mode = I965_TEXCOORDMODE_CLAMP;
979 sampler_state[2].ss1.s_wrap_mode = I965_TEXCOORDMODE_CLAMP;
980 sampler_state[2].ss1.t_wrap_mode = I965_TEXCOORDMODE_CLAMP;
982 dri_bo_unmap(pp_context->sampler_state_table.bo);
984 /* private function & data */
985 pp_context->pp_x_steps = pp_scaling_x_steps;
986 pp_context->pp_y_steps = pp_scaling_y_steps;
987 pp_context->pp_set_block_parameter = pp_scaling_set_block_parameter;
989 pp_scaling_context->dest_x = dst_rect->x;
990 pp_scaling_context->dest_y = dst_rect->y;
991 pp_scaling_context->dest_w = ALIGN(dst_rect->width, 16);
992 pp_scaling_context->dest_h = ALIGN(dst_rect->height, 16);
993 pp_scaling_context->src_normalized_x = (float)src_rect->x / in_w / out_w;
994 pp_scaling_context->src_normalized_y = (float)src_rect->y / in_h / out_h;
996 pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / out_h;
998 pp_inline_parameter.grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / out_w;
999 pp_inline_parameter.grf5.block_count_x = pp_scaling_context->dest_w / 16; /* 1 x N */
1000 pp_inline_parameter.grf5.number_blocks = pp_scaling_context->dest_w / 16;
1001 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1002 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1006 pp_avs_x_steps(void *private_context)
1008 struct pp_avs_context *pp_avs_context = private_context;
1010 return pp_avs_context->dest_w / 16;
1014 pp_avs_y_steps(void *private_context)
1020 pp_avs_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1022 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1023 float src_x_steping, src_y_steping, video_step_delta;
1024 int tmp_w = ALIGN(pp_avs_context->dest_h * pp_avs_context->src_w / pp_avs_context->src_h, 16);
1026 if (tmp_w >= pp_avs_context->dest_w) {
1027 pp_inline_parameter.grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1028 pp_inline_parameter.grf6.video_step_delta = 0;
1031 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = (float)(tmp_w - pp_avs_context->dest_w) / tmp_w / 2 +
1032 pp_avs_context->src_normalized_x;
1034 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1035 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1036 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1037 16 * 15 * video_step_delta / 2;
1040 int n0, n1, n2, nls_left, nls_right;
1041 int factor_a = 5, factor_b = 4;
1044 n0 = (pp_avs_context->dest_w - tmp_w) / (16 * 2);
1045 n1 = (pp_avs_context->dest_w - tmp_w) / 16 - n0;
1046 n2 = tmp_w / (16 * factor_a);
1048 nls_right = n1 + n2;
1049 f = (float) n2 * 16 / tmp_w;
1052 pp_inline_parameter.grf6.video_step_delta = 0.0;
1055 pp_inline_parameter.grf5.normalized_video_x_scaling_step = 1.0 / pp_avs_context->dest_w;
1056 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1058 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1059 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1060 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1061 16 * 15 * video_step_delta / 2;
1065 /* f = a * nls_left * 16 + b * nls_left * 16 * (nls_left * 16 - 1) / 2 */
1066 float a = f / (nls_left * 16 * factor_b);
1067 float b = (f - nls_left * 16 * a) * 2 / (nls_left * 16 * (nls_left * 16 - 1));
1069 pp_inline_parameter.grf6.video_step_delta = b;
1072 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin = pp_avs_context->src_normalized_x;
1073 pp_inline_parameter.grf5.normalized_video_x_scaling_step = a;
1075 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1076 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1077 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1078 16 * 15 * video_step_delta / 2;
1079 pp_inline_parameter.grf5.normalized_video_x_scaling_step += 16 * b;
1081 } else if (x < (pp_avs_context->dest_w / 16 - nls_right)) {
1082 /* scale the center linearly */
1083 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1084 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1085 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1086 16 * 15 * video_step_delta / 2;
1087 pp_inline_parameter.grf6.video_step_delta = 0.0;
1088 pp_inline_parameter.grf5.normalized_video_x_scaling_step = 1.0 / tmp_w;
1090 float a = f / (nls_right * 16 * factor_b);
1091 float b = (f - nls_right * 16 * a) * 2 / (nls_right * 16 * (nls_right * 16 - 1));
1093 src_x_steping = pp_inline_parameter.grf5.normalized_video_x_scaling_step;
1094 video_step_delta = pp_inline_parameter.grf6.video_step_delta;
1095 pp_inline_parameter.grf5.r5_1.source_surface_block_normalized_horizontal_origin += src_x_steping * 16 +
1096 16 * 15 * video_step_delta / 2;
1097 pp_inline_parameter.grf6.video_step_delta = -b;
1099 if (x == (pp_avs_context->dest_w / 16 - nls_right))
1100 pp_inline_parameter.grf5.normalized_video_x_scaling_step = a + (nls_right * 16 - 1) * b;
1102 pp_inline_parameter.grf5.normalized_video_x_scaling_step -= b * 16;
1107 src_y_steping = pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step;
1108 pp_inline_parameter.grf5.source_surface_block_normalized_vertical_origin = src_y_steping * y * 8 + pp_avs_context->src_normalized_y;
1109 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16 + pp_avs_context->dest_x;
1110 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 8 + pp_avs_context->dest_y;
1116 pp_nv12_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1117 const struct i965_surface *src_surface,
1118 const VARectangle *src_rect,
1119 const struct i965_surface *dst_surface,
1120 const VARectangle *dst_rect,
1123 struct i965_driver_data *i965 = i965_driver_data(ctx);
1124 struct pp_avs_context *pp_avs_context = (struct pp_avs_context *)&pp_context->private_context;
1125 struct object_surface *obj_surface;
1126 struct i965_sampler_8x8 *sampler_8x8;
1127 struct i965_sampler_8x8_state *sampler_8x8_state;
1129 int in_w, in_h, in_wpitch, in_hpitch;
1130 int out_w, out_h, out_wpitch, out_hpitch;
1133 obj_surface = SURFACE(src_surface->id);
1134 in_w = obj_surface->orig_width;
1135 in_h = obj_surface->orig_height;
1136 in_wpitch = obj_surface->width;
1137 in_hpitch = obj_surface->height;
1139 /* source Y surface index 1 */
1140 i965_pp_set_surface2_state(ctx, pp_context,
1142 in_w, in_h, in_wpitch,
1144 SURFACE_FORMAT_Y8_UNORM, 0,
1147 /* source UV surface index 2 */
1148 i965_pp_set_surface2_state(ctx, pp_context,
1149 obj_surface->bo, in_wpitch * in_hpitch,
1150 in_w, in_h, in_wpitch,
1152 SURFACE_FORMAT_PLANAR_420_8, 1,
1155 /* destination surface */
1156 obj_surface = SURFACE(dst_surface->id);
1157 out_w = obj_surface->orig_width;
1158 out_h = obj_surface->orig_height;
1159 out_wpitch = obj_surface->width;
1160 out_hpitch = obj_surface->height;
1161 assert(out_w <= out_wpitch && out_h <= out_hpitch);
1163 /* destination Y surface index 7 */
1164 i965_pp_set_surface_state(ctx, pp_context,
1166 out_w / 4, out_h, out_wpitch, I965_SURFACEFORMAT_R8_UNORM,
1169 /* destination UV surface index 8 */
1170 i965_pp_set_surface_state(ctx, pp_context,
1171 obj_surface->bo, out_wpitch * out_hpitch,
1172 out_w / 4, out_h / 2, out_wpitch, I965_SURFACEFORMAT_R8G8_UNORM,
1175 /* sampler 8x8 state */
1176 dri_bo_map(pp_context->sampler_state_table.bo_8x8, True);
1177 assert(pp_context->sampler_state_table.bo_8x8->virtual);
1178 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1179 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8->virtual;
1180 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1181 sampler_8x8_state->dw136.default_sharpness_level = 0;
1182 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 1;
1183 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1184 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1185 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8);
1188 dri_bo_map(pp_context->sampler_state_table.bo, True);
1189 assert(pp_context->sampler_state_table.bo->virtual);
1190 assert(sizeof(*sampler_8x8) == sizeof(int) * 16);
1191 sampler_8x8 = pp_context->sampler_state_table.bo->virtual;
1193 /* sample_8x8 Y index 1 */
1195 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1196 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_ADAPTIVE_8_TAP;
1197 sampler_8x8[index].dw0.ief_bypass = 0;
1198 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1199 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1200 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8->offset >> 5;
1201 sampler_8x8[index].dw2.global_noise_estimation = 22;
1202 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1203 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1204 sampler_8x8[index].dw3.strong_edge_weight = 7;
1205 sampler_8x8[index].dw3.regular_weight = 2;
1206 sampler_8x8[index].dw3.non_edge_weight = 0;
1207 sampler_8x8[index].dw3.gain_factor = 40;
1208 sampler_8x8[index].dw4.steepness_boost = 0;
1209 sampler_8x8[index].dw4.steepness_threshold = 0;
1210 sampler_8x8[index].dw4.mr_boost = 0;
1211 sampler_8x8[index].dw4.mr_threshold = 5;
1212 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1213 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1214 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1215 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1216 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1217 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1218 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1219 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1220 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1221 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1222 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1223 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1224 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1225 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1226 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1227 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1228 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1229 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1230 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1231 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1232 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1233 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1234 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1235 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1236 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1237 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1238 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1239 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1240 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1241 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1242 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1243 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1244 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1245 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1246 sampler_8x8[index].dw13.limiter_boost = 0;
1247 sampler_8x8[index].dw13.minimum_limiter = 10;
1248 sampler_8x8[index].dw13.maximum_limiter = 11;
1249 sampler_8x8[index].dw14.clip_limiter = 130;
1250 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1251 I915_GEM_DOMAIN_RENDER,
1254 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1255 pp_context->sampler_state_table.bo_8x8);
1257 dri_bo_map(pp_context->sampler_state_table.bo_8x8_uv, True);
1258 assert(pp_context->sampler_state_table.bo_8x8_uv->virtual);
1259 assert(sizeof(*sampler_8x8_state) == sizeof(int) * 138);
1260 sampler_8x8_state = pp_context->sampler_state_table.bo_8x8_uv->virtual;
1261 memset(sampler_8x8_state, 0, sizeof(*sampler_8x8_state));
1262 sampler_8x8_state->dw136.default_sharpness_level = 0;
1263 sampler_8x8_state->dw137.adaptive_filter_for_all_channel = 0;
1264 sampler_8x8_state->dw137.bypass_y_adaptive_filtering = 1;
1265 sampler_8x8_state->dw137.bypass_x_adaptive_filtering = 1;
1266 dri_bo_unmap(pp_context->sampler_state_table.bo_8x8_uv);
1268 /* sample_8x8 UV index 2 */
1270 memset(&sampler_8x8[index], 0, sizeof(*sampler_8x8));
1271 sampler_8x8[index].dw0.avs_filter_type = AVS_FILTER_NEAREST;
1272 sampler_8x8[index].dw0.ief_bypass = 0;
1273 sampler_8x8[index].dw0.ief_filter_type = IEF_FILTER_DETAIL;
1274 sampler_8x8[index].dw0.ief_filter_size = IEF_FILTER_SIZE_5X5;
1275 sampler_8x8[index].dw1.sampler_8x8_state_pointer = pp_context->sampler_state_table.bo_8x8_uv->offset >> 5;
1276 sampler_8x8[index].dw2.global_noise_estimation = 22;
1277 sampler_8x8[index].dw2.strong_edge_threshold = 8;
1278 sampler_8x8[index].dw2.weak_edge_threshold = 1;
1279 sampler_8x8[index].dw3.strong_edge_weight = 7;
1280 sampler_8x8[index].dw3.regular_weight = 2;
1281 sampler_8x8[index].dw3.non_edge_weight = 0;
1282 sampler_8x8[index].dw3.gain_factor = 40;
1283 sampler_8x8[index].dw4.steepness_boost = 0;
1284 sampler_8x8[index].dw4.steepness_threshold = 0;
1285 sampler_8x8[index].dw4.mr_boost = 0;
1286 sampler_8x8[index].dw4.mr_threshold = 5;
1287 sampler_8x8[index].dw5.pwl1_point_1 = 4;
1288 sampler_8x8[index].dw5.pwl1_point_2 = 12;
1289 sampler_8x8[index].dw5.pwl1_point_3 = 16;
1290 sampler_8x8[index].dw5.pwl1_point_4 = 26;
1291 sampler_8x8[index].dw6.pwl1_point_5 = 40;
1292 sampler_8x8[index].dw6.pwl1_point_6 = 160;
1293 sampler_8x8[index].dw6.pwl1_r3_bias_0 = 127;
1294 sampler_8x8[index].dw6.pwl1_r3_bias_1 = 98;
1295 sampler_8x8[index].dw7.pwl1_r3_bias_2 = 88;
1296 sampler_8x8[index].dw7.pwl1_r3_bias_3 = 64;
1297 sampler_8x8[index].dw7.pwl1_r3_bias_4 = 44;
1298 sampler_8x8[index].dw7.pwl1_r3_bias_5 = 0;
1299 sampler_8x8[index].dw8.pwl1_r3_bias_6 = 0;
1300 sampler_8x8[index].dw8.pwl1_r5_bias_0 = 3;
1301 sampler_8x8[index].dw8.pwl1_r5_bias_1 = 32;
1302 sampler_8x8[index].dw8.pwl1_r5_bias_2 = 32;
1303 sampler_8x8[index].dw9.pwl1_r5_bias_3 = 58;
1304 sampler_8x8[index].dw9.pwl1_r5_bias_4 = 100;
1305 sampler_8x8[index].dw9.pwl1_r5_bias_5 = 108;
1306 sampler_8x8[index].dw9.pwl1_r5_bias_6 = 88;
1307 sampler_8x8[index].dw10.pwl1_r3_slope_0 = -116;
1308 sampler_8x8[index].dw10.pwl1_r3_slope_1 = -20;
1309 sampler_8x8[index].dw10.pwl1_r3_slope_2 = -96;
1310 sampler_8x8[index].dw10.pwl1_r3_slope_3 = -32;
1311 sampler_8x8[index].dw11.pwl1_r3_slope_4 = -50;
1312 sampler_8x8[index].dw11.pwl1_r3_slope_5 = 0;
1313 sampler_8x8[index].dw11.pwl1_r3_slope_6 = 0;
1314 sampler_8x8[index].dw11.pwl1_r5_slope_0 = 116;
1315 sampler_8x8[index].dw12.pwl1_r5_slope_1 = 0;
1316 sampler_8x8[index].dw12.pwl1_r5_slope_2 = 114;
1317 sampler_8x8[index].dw12.pwl1_r5_slope_3 = 67;
1318 sampler_8x8[index].dw12.pwl1_r5_slope_4 = 9;
1319 sampler_8x8[index].dw13.pwl1_r5_slope_5 = -3;
1320 sampler_8x8[index].dw13.pwl1_r5_slope_6 = -15;
1321 sampler_8x8[index].dw13.limiter_boost = 0;
1322 sampler_8x8[index].dw13.minimum_limiter = 10;
1323 sampler_8x8[index].dw13.maximum_limiter = 11;
1324 sampler_8x8[index].dw14.clip_limiter = 130;
1325 dri_bo_emit_reloc(pp_context->sampler_state_table.bo,
1326 I915_GEM_DOMAIN_RENDER,
1329 sizeof(*sampler_8x8) * index + offsetof(struct i965_sampler_8x8, dw1),
1330 pp_context->sampler_state_table.bo_8x8_uv);
1332 dri_bo_unmap(pp_context->sampler_state_table.bo);
1334 /* private function & data */
1335 pp_context->pp_x_steps = pp_avs_x_steps;
1336 pp_context->pp_y_steps = pp_avs_y_steps;
1337 pp_context->pp_set_block_parameter = pp_avs_set_block_parameter;
1339 pp_avs_context->dest_x = dst_rect->x;
1340 pp_avs_context->dest_y = dst_rect->y;
1341 pp_avs_context->dest_w = ALIGN(dst_rect->width, 16);
1342 pp_avs_context->dest_h = ALIGN(dst_rect->height, 16);
1343 pp_avs_context->src_normalized_x = (float)src_rect->x / in_w / out_w;
1344 pp_avs_context->src_normalized_y = (float)src_rect->y / in_h / out_h;
1345 pp_avs_context->src_w = src_rect->width;
1346 pp_avs_context->src_h = src_rect->height;
1348 pp_static_parameter.grf4.r4_2.avs.nlas = 1;
1349 pp_static_parameter.grf1.r1_6.normalized_video_y_scaling_step = (float) src_rect->height / in_h / out_h;
1351 pp_inline_parameter.grf5.normalized_video_x_scaling_step = (float) src_rect->width / in_w / out_w;
1352 pp_inline_parameter.grf5.block_count_x = 1; /* M x 1 */
1353 pp_inline_parameter.grf5.number_blocks = pp_avs_context->dest_h / 8;
1354 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1355 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1356 pp_inline_parameter.grf6.video_step_delta = 0.0;
1360 pp_dndi_x_steps(void *private_context)
1366 pp_dndi_y_steps(void *private_context)
1368 struct pp_dndi_context *pp_dndi_context = private_context;
1370 return pp_dndi_context->dest_h / 4;
1374 pp_dndi_set_block_parameter(struct i965_post_processing_context *pp_context, int x, int y)
1376 pp_inline_parameter.grf5.destination_block_horizontal_origin = x * 16;
1377 pp_inline_parameter.grf5.destination_block_vertical_origin = y * 4;
1383 void pp_nv12_dndi_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
1384 const struct i965_surface *src_surface,
1385 const VARectangle *src_rect,
1386 const struct i965_surface *dst_surface,
1387 const VARectangle *dst_rect,
1390 struct i965_driver_data *i965 = i965_driver_data(ctx);
1391 struct pp_dndi_context *pp_dndi_context = (struct pp_dndi_context *)&pp_context->private_context;
1392 struct object_surface *obj_surface;
1393 struct i965_sampler_dndi *sampler_dndi;
1399 obj_surface = SURFACE(src_surface->id);
1400 orig_w = obj_surface->orig_width;
1401 orig_h = obj_surface->orig_height;
1402 w = obj_surface->width;
1403 h = obj_surface->height;
1405 if (pp_context->stmm.bo == NULL) {
1406 pp_context->stmm.bo = dri_bo_alloc(i965->intel.bufmgr,
1410 assert(pp_context->stmm.bo);
1413 /* source UV surface index 2 */
1414 i965_pp_set_surface_state(ctx, pp_context,
1415 obj_surface->bo, w * h,
1416 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
1419 /* source YUV surface index 4 */
1420 i965_pp_set_surface2_state(ctx, pp_context,
1424 SURFACE_FORMAT_PLANAR_420_8, 1,
1427 /* source STMM surface index 20 */
1428 i965_pp_set_surface_state(ctx, pp_context,
1429 pp_context->stmm.bo, 0,
1430 orig_w, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
1433 /* destination surface */
1434 obj_surface = SURFACE(dst_surface->id);
1435 orig_w = obj_surface->orig_width;
1436 orig_h = obj_surface->orig_height;
1437 w = obj_surface->width;
1438 h = obj_surface->height;
1440 /* destination Y surface index 7 */
1441 i965_pp_set_surface_state(ctx, pp_context,
1443 orig_w / 4, orig_h, w, I965_SURFACEFORMAT_R8_UNORM,
1446 /* destination UV surface index 8 */
1447 i965_pp_set_surface_state(ctx, pp_context,
1448 obj_surface->bo, w * h,
1449 orig_w / 4, orig_h / 2, w, I965_SURFACEFORMAT_R8G8_UNORM,
1452 dri_bo_map(pp_context->sampler_state_table.bo, True);
1453 assert(pp_context->sampler_state_table.bo->virtual);
1454 assert(sizeof(*sampler_dndi) == sizeof(int) * 8);
1455 sampler_dndi = pp_context->sampler_state_table.bo->virtual;
1457 /* sample dndi index 1 */
1459 sampler_dndi[index].dw0.denoise_asd_threshold = 0;
1460 sampler_dndi[index].dw0.denoise_history_delta = 8; // 0-15, default is 8
1461 sampler_dndi[index].dw0.denoise_maximum_history = 128; // 128-240
1462 sampler_dndi[index].dw0.denoise_stad_threshold = 0;
1464 sampler_dndi[index].dw1.denoise_threshold_for_sum_of_complexity_measure = 64;
1465 sampler_dndi[index].dw1.denoise_moving_pixel_threshold = 0;
1466 sampler_dndi[index].dw1.stmm_c2 = 0;
1467 sampler_dndi[index].dw1.low_temporal_difference_threshold = 8;
1468 sampler_dndi[index].dw1.temporal_difference_threshold = 16;
1470 sampler_dndi[index].dw2.block_noise_estimate_noise_threshold = 15; // 0-31
1471 sampler_dndi[index].dw2.block_noise_estimate_edge_threshold = 7; // 0-15
1472 sampler_dndi[index].dw2.denoise_edge_threshold = 7; // 0-15
1473 sampler_dndi[index].dw2.good_neighbor_threshold = 7; // 0-63
1475 sampler_dndi[index].dw3.maximum_stmm = 128;
1476 sampler_dndi[index].dw3.multipler_for_vecm = 2;
1477 sampler_dndi[index].dw3.blending_constant_across_time_for_small_values_of_stmm = 0;
1478 sampler_dndi[index].dw3.blending_constant_across_time_for_large_values_of_stmm = 64;
1479 sampler_dndi[index].dw3.stmm_blending_constant_select = 0;
1481 sampler_dndi[index].dw4.sdi_delta = 8;
1482 sampler_dndi[index].dw4.sdi_threshold = 128;
1483 sampler_dndi[index].dw4.stmm_output_shift = 7; // stmm_max - stmm_min = 2 ^ stmm_output_shift
1484 sampler_dndi[index].dw4.stmm_shift_up = 0;
1485 sampler_dndi[index].dw4.stmm_shift_down = 0;
1486 sampler_dndi[index].dw4.minimum_stmm = 0;
1488 sampler_dndi[index].dw5.fmd_temporal_difference_threshold = 0;
1489 sampler_dndi[index].dw5.sdi_fallback_mode_2_constant = 0;
1490 sampler_dndi[index].dw5.sdi_fallback_mode_1_t2_constant = 0;
1491 sampler_dndi[index].dw5.sdi_fallback_mode_1_t1_constant = 0;
1493 sampler_dndi[index].dw6.dn_enable = 1;
1494 sampler_dndi[index].dw6.di_enable = 1;
1495 sampler_dndi[index].dw6.di_partial = 0;
1496 sampler_dndi[index].dw6.dndi_top_first = 1;
1497 sampler_dndi[index].dw6.dndi_stream_id = 1;
1498 sampler_dndi[index].dw6.dndi_first_frame = 1;
1499 sampler_dndi[index].dw6.progressive_dn = 0;
1500 sampler_dndi[index].dw6.fmd_tear_threshold = 32;
1501 sampler_dndi[index].dw6.fmd2_vertical_difference_threshold = 32;
1502 sampler_dndi[index].dw6.fmd1_vertical_difference_threshold = 32;
1504 sampler_dndi[index].dw7.fmd_for_1st_field_of_current_frame = 2;
1505 sampler_dndi[index].dw7.fmd_for_2nd_field_of_previous_frame = 1;
1506 sampler_dndi[index].dw7.vdi_walker_enable = 0;
1507 sampler_dndi[index].dw7.column_width_minus1 = w / 16;
1509 dri_bo_unmap(pp_context->sampler_state_table.bo);
1511 /* private function & data */
1512 pp_context->pp_x_steps = pp_dndi_x_steps;
1513 pp_context->pp_y_steps = pp_dndi_y_steps;
1514 pp_context->pp_set_block_parameter = pp_dndi_set_block_parameter;
1516 pp_static_parameter.grf1.statistics_surface_picth = w / 2;
1517 pp_static_parameter.grf1.r1_6.di.top_field_first = 0;
1518 pp_static_parameter.grf4.r4_2.di.motion_history_coefficient_m2 = 64;
1519 pp_static_parameter.grf4.r4_2.di.motion_history_coefficient_m1 = 192;
1521 pp_inline_parameter.grf5.block_count_x = w / 16; /* 1 x N */
1522 pp_inline_parameter.grf5.number_blocks = w / 16;
1523 pp_inline_parameter.grf5.block_vertical_mask = 0xff;
1524 pp_inline_parameter.grf5.block_horizontal_mask = 0xffff;
1526 pp_dndi_context->dest_w = w;
1527 pp_dndi_context->dest_h = h;
1531 ironlake_pp_initialize(
1532 VADriverContextP ctx,
1533 struct i965_post_processing_context *pp_context,
1534 const struct i965_surface *src_surface,
1535 const VARectangle *src_rect,
1536 const struct i965_surface *dst_surface,
1537 const VARectangle *dst_rect,
1542 struct i965_driver_data *i965 = i965_driver_data(ctx);
1543 struct pp_module *pp_module;
1546 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
1547 bo = dri_bo_alloc(i965->intel.bufmgr,
1548 "surface state & binding table",
1549 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
1552 pp_context->surface_state_binding_table.bo = bo;
1554 dri_bo_unreference(pp_context->curbe.bo);
1555 bo = dri_bo_alloc(i965->intel.bufmgr,
1560 pp_context->curbe.bo = bo;
1562 dri_bo_unreference(pp_context->idrt.bo);
1563 bo = dri_bo_alloc(i965->intel.bufmgr,
1564 "interface discriptor",
1565 sizeof(struct i965_interface_descriptor),
1568 pp_context->idrt.bo = bo;
1569 pp_context->idrt.num_interface_descriptors = 0;
1571 dri_bo_unreference(pp_context->sampler_state_table.bo);
1572 bo = dri_bo_alloc(i965->intel.bufmgr,
1573 "sampler state table",
1577 dri_bo_map(bo, True);
1578 memset(bo->virtual, 0, bo->size);
1580 pp_context->sampler_state_table.bo = bo;
1582 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
1583 bo = dri_bo_alloc(i965->intel.bufmgr,
1584 "sampler 8x8 state ",
1588 pp_context->sampler_state_table.bo_8x8 = bo;
1590 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
1591 bo = dri_bo_alloc(i965->intel.bufmgr,
1592 "sampler 8x8 state ",
1596 pp_context->sampler_state_table.bo_8x8_uv = bo;
1598 dri_bo_unreference(pp_context->vfe_state.bo);
1599 bo = dri_bo_alloc(i965->intel.bufmgr,
1601 sizeof(struct i965_vfe_state),
1604 pp_context->vfe_state.bo = bo;
1606 memset(&pp_static_parameter, 0, sizeof(pp_static_parameter));
1607 memset(&pp_inline_parameter, 0, sizeof(pp_inline_parameter));
1608 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
1609 pp_context->current_pp = pp_index;
1610 pp_module = &pp_context->pp_modules[pp_index];
1612 if (pp_module->initialize)
1613 pp_module->initialize(ctx, pp_context,
1622 ironlake_post_processing(
1623 VADriverContextP ctx,
1624 struct i965_post_processing_context *pp_context,
1625 const struct i965_surface *src_surface,
1626 const VARectangle *src_rect,
1627 const struct i965_surface *dst_surface,
1628 const VARectangle *dst_rect,
1633 ironlake_pp_initialize(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
1634 ironlake_pp_states_setup(ctx, pp_context);
1635 ironlake_pp_pipeline_setup(ctx, pp_context);
1640 VADriverContextP ctx,
1641 struct i965_post_processing_context *pp_context,
1642 const struct i965_surface *src_surface,
1643 const VARectangle *src_rect,
1644 const struct i965_surface *dst_surface,
1645 const VARectangle *dst_rect,
1650 struct i965_driver_data *i965 = i965_driver_data(ctx);
1651 struct pp_module *pp_module;
1654 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
1655 bo = dri_bo_alloc(i965->intel.bufmgr,
1656 "surface state & binding table",
1657 (SURFACE_STATE_PADDED_SIZE + sizeof(unsigned int)) * MAX_PP_SURFACES,
1660 pp_context->surface_state_binding_table.bo = bo;
1662 dri_bo_unreference(pp_context->curbe.bo);
1663 bo = dri_bo_alloc(i965->intel.bufmgr,
1668 pp_context->curbe.bo = bo;
1670 dri_bo_unreference(pp_context->idrt.bo);
1671 bo = dri_bo_alloc(i965->intel.bufmgr,
1672 "interface discriptor",
1673 sizeof(struct gen6_interface_descriptor_data),
1676 pp_context->idrt.bo = bo;
1677 pp_context->idrt.num_interface_descriptors = 0;
1679 dri_bo_unreference(pp_context->sampler_state_table.bo);
1680 bo = dri_bo_alloc(i965->intel.bufmgr,
1681 "sampler state table",
1685 dri_bo_map(bo, True);
1686 memset(bo->virtual, 0, bo->size);
1688 pp_context->sampler_state_table.bo = bo;
1690 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
1691 bo = dri_bo_alloc(i965->intel.bufmgr,
1692 "sampler 8x8 state ",
1696 pp_context->sampler_state_table.bo_8x8 = bo;
1698 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
1699 bo = dri_bo_alloc(i965->intel.bufmgr,
1700 "sampler 8x8 state ",
1704 pp_context->sampler_state_table.bo_8x8_uv = bo;
1706 dri_bo_unreference(pp_context->vfe_state.bo);
1707 bo = dri_bo_alloc(i965->intel.bufmgr,
1709 sizeof(struct i965_vfe_state),
1712 pp_context->vfe_state.bo = bo;
1714 memset(&pp_static_parameter, 0, sizeof(pp_static_parameter));
1715 memset(&pp_inline_parameter, 0, sizeof(pp_inline_parameter));
1716 assert(pp_index >= PP_NULL && pp_index < NUM_PP_MODULES);
1717 pp_context->current_pp = pp_index;
1718 pp_module = &pp_context->pp_modules[pp_index];
1720 if (pp_module->initialize)
1721 pp_module->initialize(ctx, pp_context,
1730 gen6_pp_interface_descriptor_table(struct i965_post_processing_context *pp_context)
1732 struct gen6_interface_descriptor_data *desc;
1734 int pp_index = pp_context->current_pp;
1736 bo = pp_context->idrt.bo;
1737 dri_bo_map(bo, True);
1738 assert(bo->virtual);
1740 memset(desc, 0, sizeof(*desc));
1741 desc->desc0.kernel_start_pointer =
1742 pp_context->pp_modules[pp_index].kernel.bo->offset >> 6; /* reloc */
1743 desc->desc1.single_program_flow = 1;
1744 desc->desc1.floating_point_mode = FLOATING_POINT_IEEE_754;
1745 desc->desc2.sampler_count = 1; /* 1 - 4 samplers used */
1746 desc->desc2.sampler_state_pointer =
1747 pp_context->sampler_state_table.bo->offset >> 5;
1748 desc->desc3.binding_table_entry_count = 0;
1749 desc->desc3.binding_table_pointer = (BINDING_TABLE_OFFSET >> 5);
1750 desc->desc4.constant_urb_entry_read_offset = 0;
1751 desc->desc4.constant_urb_entry_read_length = 4; /* grf 1-4 */
1753 dri_bo_emit_reloc(bo,
1754 I915_GEM_DOMAIN_INSTRUCTION, 0,
1756 offsetof(struct gen6_interface_descriptor_data, desc0),
1757 pp_context->pp_modules[pp_index].kernel.bo);
1759 dri_bo_emit_reloc(bo,
1760 I915_GEM_DOMAIN_INSTRUCTION, 0,
1761 desc->desc2.sampler_count << 2,
1762 offsetof(struct gen6_interface_descriptor_data, desc2),
1763 pp_context->sampler_state_table.bo);
1766 pp_context->idrt.num_interface_descriptors++;
1770 gen6_pp_upload_constants(struct i965_post_processing_context *pp_context)
1772 unsigned char *constant_buffer;
1774 assert(sizeof(pp_static_parameter) == 128);
1775 dri_bo_map(pp_context->curbe.bo, 1);
1776 assert(pp_context->curbe.bo->virtual);
1777 constant_buffer = pp_context->curbe.bo->virtual;
1778 memcpy(constant_buffer, &pp_static_parameter, sizeof(pp_static_parameter));
1779 dri_bo_unmap(pp_context->curbe.bo);
1783 gen6_pp_states_setup(VADriverContextP ctx,
1784 struct i965_post_processing_context *pp_context)
1786 gen6_pp_interface_descriptor_table(pp_context);
1787 gen6_pp_upload_constants(pp_context);
1791 gen6_pp_pipeline_select(VADriverContextP ctx,
1792 struct i965_post_processing_context *pp_context)
1794 struct intel_batchbuffer *batch = pp_context->batch;
1796 BEGIN_BATCH(batch, 1);
1797 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
1798 ADVANCE_BATCH(batch);
1802 gen6_pp_state_base_address(VADriverContextP ctx,
1803 struct i965_post_processing_context *pp_context)
1805 struct intel_batchbuffer *batch = pp_context->batch;
1807 BEGIN_BATCH(batch, 10);
1808 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | (10 - 2));
1809 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1810 OUT_RELOC(batch, pp_context->surface_state_binding_table.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY); /* Surface state base address */
1811 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1812 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1813 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1814 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1815 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1816 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1817 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
1818 ADVANCE_BATCH(batch);
1822 gen6_pp_vfe_state(VADriverContextP ctx,
1823 struct i965_post_processing_context *pp_context)
1825 struct intel_batchbuffer *batch = pp_context->batch;
1827 BEGIN_BATCH(batch, 8);
1828 OUT_BATCH(batch, CMD_MEDIA_VFE_STATE | (8 - 2));
1829 OUT_BATCH(batch, 0);
1831 (pp_context->urb.num_vfe_entries - 1) << 16 |
1832 pp_context->urb.num_vfe_entries << 8);
1833 OUT_BATCH(batch, 0);
1835 (pp_context->urb.size_vfe_entry * 2) << 16 | /* in 256 bits unit */
1836 (pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 2 - 1)); /* in 256 bits unit */
1837 OUT_BATCH(batch, 0);
1838 OUT_BATCH(batch, 0);
1839 OUT_BATCH(batch, 0);
1840 ADVANCE_BATCH(batch);
1844 gen6_pp_curbe_load(VADriverContextP ctx,
1845 struct i965_post_processing_context *pp_context)
1847 struct intel_batchbuffer *batch = pp_context->batch;
1849 assert(pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 512 <= pp_context->curbe.bo->size);
1851 BEGIN_BATCH(batch, 4);
1852 OUT_BATCH(batch, CMD_MEDIA_CURBE_LOAD | (4 - 2));
1853 OUT_BATCH(batch, 0);
1855 pp_context->urb.size_cs_entry * pp_context->urb.num_cs_entries * 512);
1857 pp_context->curbe.bo,
1858 I915_GEM_DOMAIN_INSTRUCTION, 0,
1860 ADVANCE_BATCH(batch);
1864 gen6_interface_descriptor_load(VADriverContextP ctx,
1865 struct i965_post_processing_context *pp_context)
1867 struct intel_batchbuffer *batch = pp_context->batch;
1869 BEGIN_BATCH(batch, 4);
1870 OUT_BATCH(batch, CMD_MEDIA_INTERFACE_DESCRIPTOR_LOAD | (4 - 2));
1871 OUT_BATCH(batch, 0);
1873 pp_context->idrt.num_interface_descriptors * sizeof(struct gen6_interface_descriptor_data));
1875 pp_context->idrt.bo,
1876 I915_GEM_DOMAIN_INSTRUCTION, 0,
1878 ADVANCE_BATCH(batch);
1882 gen6_pp_object_walker(VADriverContextP ctx,
1883 struct i965_post_processing_context *pp_context)
1885 struct intel_batchbuffer *batch = pp_context->batch;
1886 int x, x_steps, y, y_steps;
1888 x_steps = pp_context->pp_x_steps(&pp_context->private_context);
1889 y_steps = pp_context->pp_y_steps(&pp_context->private_context);
1891 for (y = 0; y < y_steps; y++) {
1892 for (x = 0; x < x_steps; x++) {
1893 if (!pp_context->pp_set_block_parameter(pp_context, x, y)) {
1894 BEGIN_BATCH(batch, 22);
1895 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 20);
1896 OUT_BATCH(batch, 0);
1897 OUT_BATCH(batch, 0); /* no indirect data */
1898 OUT_BATCH(batch, 0);
1899 OUT_BATCH(batch, 0); /* scoreboard */
1900 OUT_BATCH(batch, 0);
1902 /* inline data grf 5-6 */
1903 assert(sizeof(pp_inline_parameter) == 64);
1904 intel_batchbuffer_data(batch, &pp_inline_parameter, sizeof(pp_inline_parameter));
1906 ADVANCE_BATCH(batch);
1913 gen6_pp_pipeline_setup(VADriverContextP ctx,
1914 struct i965_post_processing_context *pp_context)
1916 struct intel_batchbuffer *batch = pp_context->batch;
1918 intel_batchbuffer_start_atomic(batch, 0x1000);
1919 intel_batchbuffer_emit_mi_flush(batch);
1920 gen6_pp_pipeline_select(ctx, pp_context);
1921 gen6_pp_state_base_address(ctx, pp_context);
1922 gen6_pp_curbe_load(ctx, pp_context);
1923 gen6_interface_descriptor_load(ctx, pp_context);
1924 gen6_pp_vfe_state(ctx, pp_context);
1925 gen6_pp_object_walker(ctx, pp_context);
1926 intel_batchbuffer_end_atomic(batch);
1930 gen6_post_processing(
1931 VADriverContextP ctx,
1932 struct i965_post_processing_context *pp_context,
1933 const struct i965_surface *src_surface,
1934 const VARectangle *src_rect,
1935 const struct i965_surface *dst_surface,
1936 const VARectangle *dst_rect,
1941 gen6_pp_initialize(ctx, pp_context,
1948 gen6_pp_states_setup(ctx, pp_context);
1949 gen6_pp_pipeline_setup(ctx, pp_context);
1953 i965_post_processing_internal(
1954 VADriverContextP ctx,
1955 struct i965_post_processing_context *pp_context,
1956 const struct i965_surface *src_surface,
1957 const VARectangle *src_rect,
1958 const struct i965_surface *dst_surface,
1959 const VARectangle *dst_rect,
1964 struct i965_driver_data *i965 = i965_driver_data(ctx);
1966 if (IS_GEN6(i965->intel.device_id) ||
1967 IS_GEN7(i965->intel.device_id))
1968 gen6_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
1970 ironlake_post_processing(ctx, pp_context, src_surface, src_rect, dst_surface, dst_rect, pp_index, filter_param);
1974 i965_DestroySurfaces(VADriverContextP ctx,
1975 VASurfaceID *surface_list,
1978 i965_CreateSurfaces(VADriverContextP ctx,
1983 VASurfaceID *surfaces);
1985 i965_post_processing(
1986 VADriverContextP ctx,
1987 VASurfaceID surface,
1988 const VARectangle *src_rect,
1989 const VARectangle *dst_rect,
1991 int *has_done_scaling
1994 struct i965_driver_data *i965 = i965_driver_data(ctx);
1995 VASurfaceID in_surface_id = surface;
1996 VASurfaceID out_surface_id = VA_INVALID_ID;
1998 *has_done_scaling = 0;
2001 struct object_surface *obj_surface;
2003 struct i965_surface src_surface;
2004 struct i965_surface dst_surface;
2006 obj_surface = SURFACE(in_surface_id);
2008 /* Currently only support post processing for NV12 surface */
2009 if (obj_surface->fourcc != VA_FOURCC('N', 'V', '1', '2'))
2010 return out_surface_id;
2012 if (flags & I965_PP_FLAG_DEINTERLACING) {
2013 status = i965_CreateSurfaces(ctx,
2014 obj_surface->orig_width,
2015 obj_surface->orig_height,
2016 VA_RT_FORMAT_YUV420,
2019 assert(status == VA_STATUS_SUCCESS);
2020 obj_surface = SURFACE(out_surface_id);
2021 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2023 src_surface.id = in_surface_id;
2024 src_surface.flag = I965_SURFACE_SURFACE;
2025 dst_surface.id = out_surface_id;
2026 dst_surface.flag = I965_SURFACE_SURFACE;
2028 i965_post_processing_internal(ctx, i965->pp_context,
2037 if (flags & I965_PP_FLAG_AVS) {
2038 struct i965_render_state *render_state = &i965->render_state;
2039 struct intel_region *dest_region = render_state->draw_region;
2041 if (out_surface_id != VA_INVALID_ID)
2042 in_surface_id = out_surface_id;
2044 status = i965_CreateSurfaces(ctx,
2046 dest_region->height,
2047 VA_RT_FORMAT_YUV420,
2050 assert(status == VA_STATUS_SUCCESS);
2051 obj_surface = SURFACE(out_surface_id);
2052 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2054 src_surface.id = in_surface_id;
2055 src_surface.flag = I965_SURFACE_SURFACE;
2056 dst_surface.id = out_surface_id;
2057 dst_surface.flag = I965_SURFACE_SURFACE;
2059 i965_post_processing_internal(ctx, i965->pp_context,
2067 if (in_surface_id != surface)
2068 i965_DestroySurfaces(ctx, &in_surface_id, 1);
2070 *has_done_scaling = 1;
2074 return out_surface_id;
2078 i965_image_i420_processing(VADriverContextP ctx,
2079 const struct i965_surface *src_surface,
2080 const VARectangle *src_rect,
2081 const struct i965_surface *dst_surface,
2082 const VARectangle *dst_rect)
2084 struct i965_driver_data *i965 = i965_driver_data(ctx);
2085 struct i965_post_processing_context *pp_context = i965->pp_context;
2086 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
2088 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
2089 i965_post_processing_internal(ctx, i965->pp_context,
2094 PP_PL3_LOAD_SAVE_N12,
2097 i965_post_processing_internal(ctx, i965->pp_context,
2102 PP_PL3_LOAD_SAVE_PL3,
2106 intel_batchbuffer_flush(pp_context->batch);
2108 return VA_STATUS_SUCCESS;
2112 i965_image_nv12_processing(VADriverContextP ctx,
2113 const struct i965_surface *src_surface,
2114 const VARectangle *src_rect,
2115 const struct i965_surface *dst_surface,
2116 const VARectangle *dst_rect)
2118 struct i965_driver_data *i965 = i965_driver_data(ctx);
2119 struct i965_post_processing_context *pp_context = i965->pp_context;
2120 int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
2122 if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
2123 i965_post_processing_internal(ctx, i965->pp_context,
2128 PP_NV12_LOAD_SAVE_N12,
2131 i965_post_processing_internal(ctx, i965->pp_context,
2136 PP_NV12_LOAD_SAVE_PL3,
2140 intel_batchbuffer_flush(pp_context->batch);
2142 return VA_STATUS_SUCCESS;
2146 i965_image_processing(VADriverContextP ctx,
2147 const struct i965_surface *src_surface,
2148 const VARectangle *src_rect,
2149 const struct i965_surface *dst_surface,
2150 const VARectangle *dst_rect)
2152 struct i965_driver_data *i965 = i965_driver_data(ctx);
2153 VAStatus status = VA_STATUS_ERROR_UNIMPLEMENTED;
2156 int fourcc = pp_get_surface_fourcc(ctx, src_surface);
2159 case VA_FOURCC('Y', 'V', '1', '2'):
2160 case VA_FOURCC('I', '4', '2', '0'):
2161 status = i965_image_i420_processing(ctx,
2168 case VA_FOURCC('N', 'V', '1', '2'):
2169 status = i965_image_nv12_processing(ctx,
2177 status = VA_STATUS_ERROR_UNIMPLEMENTED;
2186 i965_post_processing_context_finalize(struct i965_post_processing_context *pp_context)
2190 dri_bo_unreference(pp_context->surface_state_binding_table.bo);
2191 pp_context->surface_state_binding_table.bo = NULL;
2193 dri_bo_unreference(pp_context->curbe.bo);
2194 pp_context->curbe.bo = NULL;
2196 dri_bo_unreference(pp_context->sampler_state_table.bo);
2197 pp_context->sampler_state_table.bo = NULL;
2199 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8);
2200 pp_context->sampler_state_table.bo_8x8 = NULL;
2202 dri_bo_unreference(pp_context->sampler_state_table.bo_8x8_uv);
2203 pp_context->sampler_state_table.bo_8x8_uv = NULL;
2205 dri_bo_unreference(pp_context->idrt.bo);
2206 pp_context->idrt.bo = NULL;
2207 pp_context->idrt.num_interface_descriptors = 0;
2209 dri_bo_unreference(pp_context->vfe_state.bo);
2210 pp_context->vfe_state.bo = NULL;
2212 dri_bo_unreference(pp_context->stmm.bo);
2213 pp_context->stmm.bo = NULL;
2215 for (i = 0; i < NUM_PP_MODULES; i++) {
2216 struct pp_module *pp_module = &pp_context->pp_modules[i];
2218 dri_bo_unreference(pp_module->kernel.bo);
2219 pp_module->kernel.bo = NULL;
2225 i965_post_processing_terminate(VADriverContextP ctx)
2227 struct i965_driver_data *i965 = i965_driver_data(ctx);
2228 struct i965_post_processing_context *pp_context = i965->pp_context;
2231 i965_post_processing_context_finalize(pp_context);
2235 i965->pp_context = NULL;
2241 i965_post_processing_context_init(VADriverContextP ctx,
2242 struct i965_post_processing_context *pp_context,
2243 struct intel_batchbuffer *batch)
2245 struct i965_driver_data *i965 = i965_driver_data(ctx);
2248 pp_context->urb.size = URB_SIZE((&i965->intel));
2249 pp_context->urb.num_vfe_entries = 32;
2250 pp_context->urb.size_vfe_entry = 1; /* in 512 bits unit */
2251 pp_context->urb.num_cs_entries = 1;
2252 pp_context->urb.size_cs_entry = 2; /* in 512 bits unit */
2253 pp_context->urb.vfe_start = 0;
2254 pp_context->urb.cs_start = pp_context->urb.vfe_start +
2255 pp_context->urb.num_vfe_entries * pp_context->urb.size_vfe_entry;
2256 assert(pp_context->urb.cs_start +
2257 pp_context->urb.num_cs_entries * pp_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
2259 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen5));
2260 assert(NUM_PP_MODULES == ARRAY_ELEMS(pp_modules_gen6));
2262 if (IS_GEN6(i965->intel.device_id) ||
2263 IS_GEN7(i965->intel.device_id))
2264 memcpy(pp_context->pp_modules, pp_modules_gen6, sizeof(pp_context->pp_modules));
2265 else if (IS_IRONLAKE(i965->intel.device_id))
2266 memcpy(pp_context->pp_modules, pp_modules_gen5, sizeof(pp_context->pp_modules));
2268 for (i = 0; i < NUM_PP_MODULES; i++) {
2269 struct pp_module *pp_module = &pp_context->pp_modules[i];
2270 dri_bo_unreference(pp_module->kernel.bo);
2271 if (pp_module->kernel.bin) {
2272 pp_module->kernel.bo = dri_bo_alloc(i965->intel.bufmgr,
2273 pp_module->kernel.name,
2274 pp_module->kernel.size,
2276 assert(pp_module->kernel.bo);
2277 dri_bo_subdata(pp_module->kernel.bo, 0, pp_module->kernel.size, pp_module->kernel.bin);
2279 pp_module->kernel.bo = NULL;
2283 pp_context->batch = batch;
2287 i965_post_processing_init(VADriverContextP ctx)
2289 struct i965_driver_data *i965 = i965_driver_data(ctx);
2290 struct i965_post_processing_context *pp_context = i965->pp_context;
2293 if (pp_context == NULL) {
2294 pp_context = calloc(1, sizeof(*pp_context));
2295 i965_post_processing_context_init(ctx, pp_context, i965->batch);
2296 i965->pp_context = pp_context;
2303 static const int procfilter_to_pp_flag[10] = {
2304 PP_NULL, /* VAProcFilterNone */
2305 PP_NULL, /* VAProcFilterDering */
2306 PP_NULL, /* VAProcFilterDeblocking */
2307 PP_NV12_DNDI, /* VAProcFilterNoiseReduction */
2308 PP_NV12_DNDI, /* VAProcFilterDeinterlacing */
2309 PP_NULL, /* VAProcFilterSharpening */
2310 PP_NULL, /* VAProcFilterColorEnhancement */
2311 PP_NULL, /* VAProcFilterProcAmp */
2312 PP_NULL, /* VAProcFilterComposition */
2313 PP_NULL, /* VAProcFilterFrameRateConversion */
2317 i965_proc_picture(VADriverContextP ctx,
2319 union codec_state *codec_state,
2320 struct hw_context *hw_context)
2322 struct i965_driver_data *i965 = i965_driver_data(ctx);
2323 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
2324 struct proc_state *proc_state = &codec_state->proc;
2325 VAProcPipelineParameterBuffer *pipeline_param = (VAProcPipelineParameterBuffer *)proc_state->pipeline_param->buffer;
2326 VAProcInputParameterBuffer *input_param = (VAProcInputParameterBuffer *)proc_state->input_param->buffer;
2327 struct object_surface *obj_surface;
2328 struct i965_surface src_surface, dst_surface;
2331 VASurfaceID tmp_surfaces[VA_PROC_PIPELINE_MAX_NUM_FILTERS];
2332 int num_tmp_surfaces = 0;
2334 assert(input_param->surface != VA_INVALID_ID);
2335 assert(proc_state->current_render_target != VA_INVALID_ID);
2337 obj_surface = SURFACE(proc_state->current_render_target);
2338 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2340 obj_surface = SURFACE(input_param->surface);
2341 assert(obj_surface->fourcc == VA_FOURCC('N', 'V', '1', '2'));
2343 src_surface.id = input_param->surface;
2344 src_surface.flag = I965_SURFACE_SURFACE;
2346 for (i = 0; i < VA_PROC_PIPELINE_MAX_NUM_FILTERS; i++) {
2347 VAProcFilterType filter_type = pipeline_param->filter_pipeline[i];
2348 VASurfaceID out_surface_id = VA_INVALID_ID;
2349 void *filter_param = NULL;
2351 if (procfilter_to_pp_flag[filter_type] != PP_NULL) {
2352 if (proc_state->filter_param[filter_type])
2353 filter_param = proc_state->filter_param[filter_type]->buffer;
2355 status = i965_CreateSurfaces(ctx,
2356 obj_surface->orig_width,
2357 obj_surface->orig_height,
2358 VA_RT_FORMAT_YUV420,
2361 assert(status == VA_STATUS_SUCCESS);
2362 tmp_surfaces[num_tmp_surfaces++] = out_surface_id;
2363 obj_surface = SURFACE(out_surface_id);
2364 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N','V','1','2'));
2365 dst_surface.id = out_surface_id;
2366 dst_surface.flag = I965_SURFACE_SURFACE;
2367 i965_post_processing_internal(ctx, &proc_context->pp_context,
2369 &input_param->region,
2371 &input_param->region,
2372 procfilter_to_pp_flag[filter_type],
2374 src_surface.id = dst_surface.id;
2378 dst_surface.id = proc_state->current_render_target;
2379 dst_surface.flag = I965_SURFACE_SURFACE;
2380 i965_post_processing_internal(ctx, &proc_context->pp_context,
2382 &input_param->region,
2384 &pipeline_param->output_region,
2388 if (num_tmp_surfaces)
2389 i965_DestroySurfaces(ctx,
2393 intel_batchbuffer_flush(hw_context->batch);
2397 i965_proc_context_destroy(void *hw_context)
2399 struct i965_proc_context *proc_context = (struct i965_proc_context *)hw_context;
2401 i965_post_processing_context_finalize(&proc_context->pp_context);
2402 intel_batchbuffer_free(proc_context->base.batch);
2407 i965_proc_context_init(VADriverContextP ctx, VAProfile profile)
2409 struct intel_driver_data *intel = intel_driver_data(ctx);
2410 struct i965_proc_context *proc_context = calloc(1, sizeof(struct i965_proc_context));
2412 proc_context->base.destroy = i965_proc_context_destroy;
2413 proc_context->base.run = i965_proc_picture;
2414 proc_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
2415 i965_post_processing_context_init(ctx, &proc_context->pp_context, proc_context->base.batch);
2417 return (struct hw_context *)proc_context;