summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang, Haihao <haihao.xiang@intel.com>2011-05-25 14:14:42 +0800
committerXiang, Haihao <haihao.xiang@intel.com>2011-05-25 14:38:44 +0800
commite0e4c6b8931cc3c658330d65257e5f766c1c376c (patch)
tree410c6e1653164546321e72a9e1f50d1b602b4d93
parent1854f7cbe1727d3ad1a3d547f1b2739790a08e53 (diff)
i965_drv_video: clean up codes
Check and allocate surface BO in a same function Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
-rw-r--r--i965_drv_video/gen6_mfc.c18
-rw-r--r--i965_drv_video/gen6_mfd.c71
-rw-r--r--i965_drv_video/gen7_mfd.c71
-rw-r--r--i965_drv_video/i965_avc_bsd.c20
-rw-r--r--i965_drv_video/i965_drv_video.c61
-rw-r--r--i965_drv_video/i965_drv_video.h5
-rw-r--r--i965_drv_video/i965_media_mpeg2.c9
7 files changed, 55 insertions, 200 deletions
diff --git a/i965_drv_video/gen6_mfc.c b/i965_drv_video/gen6_mfc.c
index 06315c5..45e10fe 100644
--- a/i965_drv_video/gen6_mfc.c
+++ b/i965_drv_video/gen6_mfc.c
@@ -615,23 +615,7 @@ static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx,
/*Setup all the input&output object*/
obj_surface = SURFACE(pPicParameter->reconstructed_picture);
assert(obj_surface);
-
- if (!obj_surface->bo) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
mfc_context->post_deblocking_output.bo = obj_surface->bo;
dri_bo_reference(mfc_context->post_deblocking_output.bo);
diff --git a/i965_drv_video/gen6_mfd.c b/i965_drv_video/gen6_mfd.c
index ceed0db..bd92e99 100644
--- a/i965_drv_video/gen6_mfd.c
+++ b/i965_drv_video/gen6_mfd.c
@@ -120,22 +120,8 @@ gen6_mfd_avc_frame_store_index(VADriverContextP ctx,
int frame_idx;
struct object_surface *obj_surface = SURFACE(ref_pic->picture_id);
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ assert(obj_surface);
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
for (frame_idx = 0; frame_idx < ARRAY_ELEMS(gen6_mfd_context->reference_surface); frame_idx++) {
for (j = 0; j < ARRAY_ELEMS(gen6_mfd_context->reference_surface); j++) {
@@ -1056,24 +1042,8 @@ gen6_mfd_avc_decode_init(VADriverContextP ctx,
obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
obj_surface->flags |= (pic_param->pic_fields.bits.reference_pic_flag ? SURFACE_REFERENCED : 0);
gen6_mfd_init_avc_surface(ctx, pic_param, obj_surface);
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
-
dri_bo_unreference(gen6_mfd_context->post_deblocking_output.bo);
gen6_mfd_context->post_deblocking_output.bo = obj_surface->bo;
dri_bo_reference(gen6_mfd_context->post_deblocking_output.bo);
@@ -1221,22 +1191,7 @@ gen6_mfd_mpeg2_decode_init(VADriverContextP ctx,
/* Current decoded picture */
obj_surface = SURFACE(decode_state->current_render_target);
assert(obj_surface);
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
dri_bo_unreference(gen6_mfd_context->pre_deblocking_output.bo);
gen6_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
@@ -1547,23 +1502,7 @@ gen6_mfd_vc1_decode_init(VADriverContextP ctx,
obj_surface = SURFACE(decode_state->current_render_target);
assert(obj_surface);
gen6_mfd_init_vc1_surface(ctx, pic_param, obj_surface);
-
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
dri_bo_unreference(gen6_mfd_context->post_deblocking_output.bo);
gen6_mfd_context->post_deblocking_output.bo = obj_surface->bo;
diff --git a/i965_drv_video/gen7_mfd.c b/i965_drv_video/gen7_mfd.c
index 3c9d581..55321d0 100644
--- a/i965_drv_video/gen7_mfd.c
+++ b/i965_drv_video/gen7_mfd.c
@@ -120,22 +120,8 @@ gen7_mfd_avc_frame_store_index(VADriverContextP ctx,
int frame_idx;
struct object_surface *obj_surface = SURFACE(ref_pic->picture_id);
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ assert(obj_surface);
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
for (frame_idx = 0; frame_idx < ARRAY_ELEMS(gen7_mfd_context->reference_surface); frame_idx++) {
for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
@@ -1003,24 +989,8 @@ gen7_mfd_avc_decode_init(VADriverContextP ctx,
obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
obj_surface->flags |= (pic_param->pic_fields.bits.reference_pic_flag ? SURFACE_REFERENCED : 0);
gen7_mfd_init_avc_surface(ctx, pic_param, obj_surface);
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
-
dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
gen7_mfd_context->post_deblocking_output.bo = obj_surface->bo;
dri_bo_reference(gen7_mfd_context->post_deblocking_output.bo);
@@ -1167,22 +1137,7 @@ gen7_mfd_mpeg2_decode_init(VADriverContextP ctx,
/* Current decoded picture */
obj_surface = SURFACE(decode_state->current_render_target);
assert(obj_surface);
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
@@ -1502,23 +1457,7 @@ gen7_mfd_vc1_decode_init(VADriverContextP ctx,
obj_surface = SURFACE(decode_state->current_render_target);
assert(obj_surface);
gen7_mfd_init_vc1_surface(ctx, pic_param, obj_surface);
-
- if (obj_surface->bo == NULL) {
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 1);
dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
gen7_mfd_context->post_deblocking_output.bo = obj_surface->bo;
diff --git a/i965_drv_video/i965_avc_bsd.c b/i965_drv_video/i965_avc_bsd.c
index 84b8fa4..99bfff0 100644
--- a/i965_drv_video/i965_avc_bsd.c
+++ b/i965_drv_video/i965_avc_bsd.c
@@ -516,13 +516,7 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx,
obj_surface->flags |= (pic_param->pic_fields.bits.reference_pic_flag ? SURFACE_REFERENCED : 0);
i965_avc_bsd_init_avc_bsd_surface(ctx, obj_surface, pic_param, i965_h264_context);
avc_bsd_surface = obj_surface->private_data;
-
- if (obj_surface->bo == NULL) {
- obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->size,
- 0x1000);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 0);
OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top,
I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
@@ -964,17 +958,9 @@ i965_avc_bsd_frame_store_index(VADriverContextP ctx,
if (!found) {
int frame_idx;
struct object_surface *obj_surface = SURFACE(ref_pic->picture_id);
+ assert(obj_surface);
+ i965_check_alloc_surface_bo(ctx, obj_surface, 0);
- if (obj_surface->bo == NULL) {
- /* Some broken sources such as conformance case FM2_SVA_C
- * will get here !!!. Allocating a BO for it to avoid SEGMENT FAULT
- */
- obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->size,
- 0x1000);
- }
-
for (frame_idx = 0; frame_idx < ARRAY_ELEMS(i965_h264_context->fsid_list); frame_idx++) {
for (j = 0; j < ARRAY_ELEMS(i965_h264_context->fsid_list); j++) {
if (i965_h264_context->fsid_list[j].surface_id == VA_INVALID_ID)
diff --git a/i965_drv_video/i965_drv_video.c b/i965_drv_video/i965_drv_video.c
index f31fff4..f6ae6a4 100644
--- a/i965_drv_video/i965_drv_video.c
+++ b/i965_drv_video/i965_drv_video.c
@@ -1815,6 +1815,40 @@ i965_CreateImage(VADriverContextP ctx,
return va_status;
}
+void
+i965_check_alloc_surface_bo(VADriverContextP ctx,
+ struct object_surface *obj_surface,
+ int tiled)
+{
+ struct i965_driver_data *i965 = i965_driver_data(ctx);
+
+ if (obj_surface->bo)
+ return;
+
+ if (tiled) {
+ uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
+ unsigned long pitch;
+
+ obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
+ "vaapi surface",
+ obj_surface->width,
+ obj_surface->height + obj_surface->height / 2,
+ 1,
+ &tiling_mode,
+ &pitch,
+ 0);
+ assert(tiling_mode == I915_TILING_Y);
+ assert(pitch == obj_surface->width);
+ } else {
+ obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
+ "vaapi surface",
+ obj_surface->size,
+ 0x1000);
+ }
+
+ assert(obj_surface->bo);
+}
+
VAStatus i965_DeriveImage(VADriverContextP ctx,
VASurfaceID surface,
VAImage *out_image) /* out */
@@ -1899,32 +1933,7 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
}
}
- if (obj_surface->bo == NULL) {
- if (HAS_TILED_SURFACE(i965)) {
-
- uint32_t tiling_mode = I915_TILING_Y;
- unsigned long pitch;
-
- obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->width,
- obj_surface->height + obj_surface->height / 2,
- 1,
- &tiling_mode,
- &pitch,
- 0);
- assert(obj_surface->bo);
- assert(tiling_mode == I915_TILING_Y);
- assert(pitch == obj_surface->width);
- } else {
- obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->size,
- 0x1000);
- }
- }
-
- assert(obj_surface->bo);
+ i965_check_alloc_surface_bo(ctx, obj_surface, HAS_TILED_SURFACE(i965));
va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
if (va_status != VA_STATUS_SUCCESS)
diff --git a/i965_drv_video/i965_drv_video.h b/i965_drv_video/i965_drv_video.h
index c0ff3d4..6a68b34 100644
--- a/i965_drv_video/i965_drv_video.h
+++ b/i965_drv_video/i965_drv_video.h
@@ -249,4 +249,9 @@ i965_driver_data(VADriverContextP ctx)
return (struct i965_driver_data *)(ctx->pDriverData);
}
+void
+i965_check_alloc_surface_bo(VADriverContextP ctx,
+ struct object_surface *obj_surface,
+ int tiled);
+
#endif /* _I965_DRV_VIDEO_H_ */
diff --git a/i965_drv_video/i965_media_mpeg2.c b/i965_drv_video/i965_media_mpeg2.c
index 612fc0e..e920c63 100644
--- a/i965_drv_video/i965_media_mpeg2.c
+++ b/i965_drv_video/i965_media_mpeg2.c
@@ -516,14 +516,7 @@ i965_media_mpeg2_surface_setup(VADriverContextP ctx,
int w = obj_surface->width;
int h = obj_surface->height;
- if (obj_surface->bo == NULL) {
- struct i965_driver_data *i965 = i965_driver_data(ctx);
-
- obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
- "vaapi surface",
- obj_surface->size,
- 0x1000);
- }
+ i965_check_alloc_surface_bo(ctx, obj_surface, 0);
if (picture_structure == MPEG_FRAME) {
i965_media_mpeg2_surface_state(ctx, base_index + 0, obj_surface,