Commit 5ebd469c authored by Xiang, Haihao's avatar Xiang, Haihao

i965_drv_video: fix graphics memory usage

parent 6da7b5d6
This diff is collapsed.
......@@ -29,12 +29,7 @@
#ifndef __I965_AVC_BSD_H__
#define __I965_AVC_BSD_H__
struct i965_avc_bsd_surface
{
dri_bo *direct_mv_wr_top_bo;
dri_bo *direct_mv_wr_bottom_bo;
int direct_mv_flag;
};
#define DMV_SIZE 0x88000 /* 557056 bytes for a frame */
struct i965_avc_bsd_context
{
......@@ -46,14 +41,15 @@ struct i965_avc_bsd_context
dri_bo *bo;
} mpr_row_store;
struct {
dri_bo *bo;
} avc_it_command_mb_info;
int init;
};
struct {
dri_bo *bo;
long write_offset;
} avc_it_data;
struct i965_avc_bsd_surface
{
struct i965_avc_bsd_context *ctx;
dri_bo *dmv_top;
dri_bo *dmv_bottom;
int dmv_bottom_flag;
};
void i965_avc_bsd_pipeline(VADriverContextP, struct decode_state *);
......
......@@ -176,11 +176,15 @@ i965_avc_hw_scoreboard_upload_constants(struct i965_avc_hw_scoreboard_context *a
{
unsigned char *constant_buffer;
if (avc_hw_scoreboard_context->curbe.upload)
return;
dri_bo_map(avc_hw_scoreboard_context->curbe.bo, 1);
assert(avc_hw_scoreboard_context->curbe.bo->virtual);
constant_buffer = avc_hw_scoreboard_context->curbe.bo->virtual;
memcpy(constant_buffer, avc_hw_scoreboard_constants, sizeof(avc_hw_scoreboard_constants));
dri_bo_unmap(avc_hw_scoreboard_context->curbe.bo);
avc_hw_scoreboard_context->curbe.upload = 1;
}
static void
......@@ -358,12 +362,14 @@ i965_avc_hw_scoreboard_decode_init(VADriverContextP ctx)
struct i965_avc_hw_scoreboard_context *avc_hw_scoreboard_context = &i965_h264_context->avc_hw_scoreboard_context;
dri_bo *bo;
dri_bo_unreference(avc_hw_scoreboard_context->curbe.bo);
if (avc_hw_scoreboard_context->curbe.bo == NULL) {
bo = dri_bo_alloc(i965->intel.bufmgr,
"constant buffer",
4096, 64);
assert(bo);
avc_hw_scoreboard_context->curbe.bo = bo;
avc_hw_scoreboard_context->curbe.upload = 0;
}
dri_bo_unreference(avc_hw_scoreboard_context->surface.s_bo);
avc_hw_scoreboard_context->surface.s_bo = i965_h264_context->avc_it_command_mb_info.bo;
......
......@@ -57,6 +57,7 @@ struct i965_avc_hw_scoreboard_context
struct {
dri_bo *bo;
int upload;
} curbe;
struct {
......
......@@ -367,11 +367,8 @@ i965_CreateSurfaces(VADriverContextP ctx,
obj_surface->width = ALIGN(width, 16);
obj_surface->height = ALIGN(height, 16);
obj_surface->size = SIZE_YUV420(obj_surface->width, obj_surface->height);
obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
"vaapi surface",
obj_surface->size,
64);
assert(obj_surface->bo);
obj_surface->flags = SURFACE_REFERENCED;
obj_surface->bo = NULL;
obj_surface->private_data = NULL;
obj_surface->free_private_data = NULL;
}
......@@ -1327,7 +1324,7 @@ i965_CreateImage(VADriverContextP ctx,
*out_image = *image;
return VA_STATUS_SUCCESS;
error:
error:
i965_DestroyImage(ctx, image_id);
return va_status;
}
......@@ -1439,6 +1436,13 @@ i965_PutSurface(VADriverContextP ctx,
if (dri_state->driConnectedFlag != VA_DRI2)
return VA_STATUS_ERROR_UNKNOWN;
/* Some broken sources such as H.264 conformance case FM2_SVA_C
* will get here
*/
obj_surface = SURFACE(surface);
if (obj_surface->bo == NULL)
return VA_STATUS_SUCCESS;
dri_drawable = dri_get_drawable(ctx, draw);
assert(dri_drawable);
......@@ -1480,13 +1484,24 @@ i965_PutSurface(VADriverContextP ctx,
i965_render_put_surface(ctx, surface,
srcx, srcy, srcw, srch,
destx, desty, destw, desth);
obj_surface = SURFACE(surface);
if(obj_surface->subpic != VA_INVALID_ID) {
i965_render_put_subpic(ctx, surface,
srcx, srcy, srcw, srch,
destx, desty, destw, desth);
}
dri_swap_buffer(ctx, dri_drawable);
obj_surface->flags |= SURFACE_DISPLAYED;
if (!(obj_surface->flags & SURFACE_REFERENCED)) {
dri_bo_unreference(obj_surface->bo);
obj_surface->bo = NULL;
obj_surface->flags = 0;
if (obj_surface->free_private_data)
obj_surface->free_private_data(&obj_surface->private_data);
}
return VA_STATUS_SUCCESS;
}
......
......@@ -94,6 +94,9 @@ struct object_context
struct decode_state decode_state;
};
#define SURFACE_REFERENCED (1 << 0)
#define SURFACE_DISPLAYED (1 << 1)
struct object_surface
{
struct object_base base;
......@@ -102,6 +105,7 @@ struct object_surface
int width;
int height;
int size;
int flags;
dri_bo *bo;
void (*free_private_data)(void **data);
void *private_data;
......@@ -137,8 +141,6 @@ struct object_subpic
dri_bo *bo;
};
struct i965_driver_data
{
struct intel_driver_data intel;
......
......@@ -199,7 +199,7 @@ i965_media_pipeline_setup(VADriverContextP ctx, struct decode_state *decode_stat
}
static void
i965_media_decode_init(VADriverContextP ctx, VAProfile profile)
i965_media_decode_init(VADriverContextP ctx, VAProfile profile, struct decode_state *decode_state)
{
int i;
struct i965_driver_data *i965 = i965_driver_data(ctx);
......@@ -250,13 +250,13 @@ i965_media_decode_init(VADriverContextP ctx, VAProfile profile)
switch (profile) {
case VAProfileMPEG2Simple:
case VAProfileMPEG2Main:
i965_media_mpeg2_decode_init(ctx);
i965_media_mpeg2_decode_init(ctx, decode_state);
break;
case VAProfileH264Baseline:
case VAProfileH264Main:
case VAProfileH264High:
i965_media_h264_decode_init(ctx);
i965_media_h264_decode_init(ctx, decode_state);
break;
default:
......@@ -273,7 +273,7 @@ i965_media_decode_picture(VADriverContextP ctx,
struct i965_driver_data *i965 = i965_driver_data(ctx);
struct i965_media_state *media_state = &i965->media_state;
i965_media_decode_init(ctx, profile);
i965_media_decode_init(ctx, profile, decode_state);
assert(media_state->media_states_setup);
media_state->media_states_setup(ctx, decode_state);
i965_media_pipeline_setup(ctx, decode_state);
......
......@@ -702,21 +702,9 @@ i965_media_h264_states_setup(VADriverContextP ctx, struct decode_state *decode_s
struct i965_driver_data *i965 = i965_driver_data(ctx);
struct i965_media_state *media_state = &i965->media_state;
struct i965_h264_context *i965_h264_context;
VAPictureParameterBufferH264 *pic_param;
assert(media_state->private_context);
i965_h264_context = (struct i965_h264_context *)media_state->private_context;
assert(decode_state->pic_param && decode_state->pic_param->buffer);
pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
i965_h264_context->picture.width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
i965_h264_context->picture.height_in_mbs = ((pic_param->picture_height_in_mbs_minus1 + 1) & 0xff) /
(1 + !!pic_param->pic_fields.bits.field_pic_flag); /* picture height */
i965_h264_context->picture.mbaff_frame_flag = (pic_param->seq_fields.bits.mb_adaptive_frame_field_flag &&
!pic_param->pic_fields.bits.field_pic_flag);
i965_h264_context->avc_it_command_mb_info.mbs = (i965_h264_context->picture.width_in_mbs *
i965_h264_context->picture.height_in_mbs);
i965_avc_bsd_pipeline(ctx, decode_state);
......@@ -792,13 +780,14 @@ i965_media_h264_free_private_context(void **data)
}
void
i965_media_h264_decode_init(VADriverContextP ctx)
i965_media_h264_decode_init(VADriverContextP ctx, struct decode_state *decode_state)
{
struct i965_driver_data *i965 = i965_driver_data(ctx);
struct i965_media_state *media_state = &i965->media_state;
struct i965_h264_context *i965_h264_context;
dri_bo *bo;
int i;
VAPictureParameterBufferH264 *pic_param;
i965_h264_context = media_state->private_context;
......@@ -829,7 +818,7 @@ i965_media_h264_decode_init(VADriverContextP ctx)
struct media_kernel *kernel = &h264_avc_kernels[i];
kernel->bo = dri_bo_alloc(i965->intel.bufmgr,
kernel->name,
kernel->size, 64);
kernel->size, 0x1000);
assert(kernel->bo);
dri_bo_subdata(kernel->bo, 0, kernel->size, kernel->bin);
}
......@@ -865,12 +854,20 @@ i965_media_h264_decode_init(VADriverContextP ctx)
media_state->media_objects = i965_media_h264_objects;
}
i965_h264_context->enable_avc_ildb = 0;
assert(decode_state->pic_param && decode_state->pic_param->buffer);
pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
i965_h264_context->picture.width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
i965_h264_context->picture.height_in_mbs = ((pic_param->picture_height_in_mbs_minus1 + 1) & 0xff) /
(1 + !!pic_param->pic_fields.bits.field_pic_flag); /* picture height */
i965_h264_context->picture.mbaff_frame_flag = (pic_param->seq_fields.bits.mb_adaptive_frame_field_flag &&
!pic_param->pic_fields.bits.field_pic_flag);
i965_h264_context->avc_it_command_mb_info.mbs = (i965_h264_context->picture.width_in_mbs *
i965_h264_context->picture.height_in_mbs);
dri_bo_unreference(i965_h264_context->avc_it_command_mb_info.bo);
bo = dri_bo_alloc(i965->intel.bufmgr,
"avc it command mb info",
0x80000 * (1 + i965_h264_context->use_avc_hw_scoreboard), /* at least 522240 bytes */
i965_h264_context->avc_it_command_mb_info.mbs * MB_CMD_IN_BYTES * (1 + i965_h264_context->use_avc_hw_scoreboard) + 4,
0x1000);
assert(bo);
i965_h264_context->avc_it_command_mb_info.bo = bo;
......@@ -878,8 +875,10 @@ i965_media_h264_decode_init(VADriverContextP ctx)
dri_bo_unreference(i965_h264_context->avc_it_data.bo);
bo = dri_bo_alloc(i965->intel.bufmgr,
"avc it data",
0x1000000, /* at least 16711680 bytes */
4096);
i965_h264_context->avc_it_command_mb_info.mbs *
0x800 *
(1 + !!pic_param->pic_fields.bits.field_pic_flag),
0x1000);
assert(bo);
i965_h264_context->avc_it_data.bo = bo;
i965_h264_context->avc_it_data.write_offset = 0;
......@@ -891,8 +890,8 @@ i965_media_h264_decode_init(VADriverContextP ctx)
dri_bo_unreference(i965_h264_context->avc_ildb_data.bo);
bo = dri_bo_alloc(i965->intel.bufmgr,
"AVC-ILDB Data Buffer",
0x100000, /* at least 1044480 bytes */
64);
i965_h264_context->avc_it_command_mb_info.mbs * 64 * 2,
0x1000);
assert(bo);
i965_h264_context->avc_ildb_data.bo = bo;
......
......@@ -60,6 +60,6 @@ struct i965_h264_context
} fsid_list[16];
};
void i965_media_h264_decode_init(VADriverContextP ctx);
void i965_media_h264_decode_init(VADriverContextP ctx, struct decode_state *decode_state);
#endif /* _I965_MEDIA_H264_H_ */
......@@ -518,6 +518,15 @@ 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);
}
if (picture_structure == MPEG_FRAME) {
i965_media_mpeg2_surface_state(ctx, base_index + 0, obj_surface,
0, w, h,
......@@ -897,7 +906,7 @@ i965_media_mpeg2_free_private_context(void **data)
}
void
i965_media_mpeg2_decode_init(VADriverContextP ctx)
i965_media_mpeg2_decode_init(VADriverContextP ctx, struct decode_state *decode_state)
{
struct i965_driver_data *i965 = i965_driver_data(ctx);
struct i965_media_state *media_state = &i965->media_state;
......
......@@ -39,6 +39,6 @@
struct decode_state;
void i965_media_mpeg2_decode_init(VADriverContextP ctx);
void i965_media_mpeg2_decode_init(VADriverContextP ctx, struct decode_state * decode_state);
#endif /* _I965_MEDIA_MPEG2_H_ */
......@@ -921,6 +921,9 @@ i965_render_upload_constants(VADriverContextP ctx)
struct i965_render_state *render_state = &i965->render_state;
unsigned short *constant_buffer;
if (render_state->curbe.upload)
return;
dri_bo_map(render_state->curbe.bo, 1);
assert(render_state->curbe.bo->virtual);
constant_buffer = render_state->curbe.bo->virtual;
......@@ -931,6 +934,7 @@ i965_render_upload_constants(VADriverContextP ctx)
*constant_buffer = 0;
dri_bo_unmap(render_state->curbe.bo);
render_state->curbe.upload = 1;
}
static void
......@@ -1508,7 +1512,7 @@ i965_render_init(VADriverContextP ctx)
struct render_kernel *kernel = &render_kernels[i];
kernel->bo = dri_bo_alloc(i965->intel.bufmgr,
kernel->name,
kernel->size, 64);
kernel->size, 0x1000);
assert(kernel->bo);
dri_bo_subdata(kernel->bo, 0, kernel->size, kernel->bin);
}
......@@ -1518,6 +1522,7 @@ i965_render_init(VADriverContextP ctx)
"constant buffer",
4096, 64);
assert(render_state->curbe.bo);
render_state->curbe.upload = 0;
return True;
}
......
......@@ -43,7 +43,6 @@ struct i965_render_state
struct {
dri_bo *state;
dri_bo *prog;
} sf;
struct {
......@@ -52,7 +51,6 @@ struct i965_render_state
dri_bo *surface[MAX_RENDER_SURFACES];
dri_bo *binding_table;
dri_bo *state;
dri_bo *prog;
} wm;
struct {
......@@ -62,6 +60,7 @@ struct i965_render_state
struct {
dri_bo *bo;
int upload;
} curbe;
int interleaved_uv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment