Commit a8703156 authored by Yunqing Wang's avatar Yunqing Wang Committed by Code Review

Merge "Improved encoder threading"

parents a5ecaca6 385c2a76
...@@ -487,6 +487,16 @@ void encode_mb_row(VP8_COMP *cpi, ...@@ -487,6 +487,16 @@ void encode_mb_row(VP8_COMP *cpi,
int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride; int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
int seg_map_index = (mb_row * cpi->common.mb_cols); int seg_map_index = (mb_row * cpi->common.mb_cols);
#if CONFIG_MULTITHREAD
const int nsync = cpi->mt_sync_range;
const int rightmost_col = cm->mb_cols - 1;
volatile const int *last_row_current_mb_col;
if ((cpi->b_multi_threaded != 0) && (mb_row != 0))
last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1];
else
last_row_current_mb_col = &rightmost_col;
#endif
// reset above block coeffs // reset above block coeffs
xd->above_context = cm->above_context; xd->above_context = cm->above_context;
...@@ -532,6 +542,21 @@ void encode_mb_row(VP8_COMP *cpi, ...@@ -532,6 +542,21 @@ void encode_mb_row(VP8_COMP *cpi,
x->rddiv = cpi->RDDIV; x->rddiv = cpi->RDDIV;
x->rdmult = cpi->RDMULT; x->rdmult = cpi->RDMULT;
#if CONFIG_MULTITHREAD
if ((cpi->b_multi_threaded != 0) && (mb_row != 0))
{
if ((mb_col & (nsync - 1)) == 0)
{
while (mb_col > (*last_row_current_mb_col - nsync)
&& (*last_row_current_mb_col) != (cm->mb_cols - 1))
{
x86_pause_hint();
thread_sleep(0);
}
}
}
#endif
if(cpi->oxcf.tuning == VP8_TUNE_SSIM) if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
activity_sum += vp8_activity_masking(cpi, x); activity_sum += vp8_activity_masking(cpi, x);
...@@ -628,7 +653,12 @@ void encode_mb_row(VP8_COMP *cpi, ...@@ -628,7 +653,12 @@ void encode_mb_row(VP8_COMP *cpi,
x->partition_info++; x->partition_info++;
xd->above_context++; xd->above_context++;
cpi->current_mb_col_main = mb_col; #if CONFIG_MULTITHREAD
if (cpi->b_multi_threaded != 0)
{
cpi->mt_current_mb_col[mb_row] = mb_col;
}
#endif
} }
//extend the recon for intra prediction //extend the recon for intra prediction
...@@ -642,11 +672,14 @@ void encode_mb_row(VP8_COMP *cpi, ...@@ -642,11 +672,14 @@ void encode_mb_row(VP8_COMP *cpi,
xd->mode_info_context++; xd->mode_info_context++;
x->partition_info++; x->partition_info++;
x->activity_sum += activity_sum; x->activity_sum += activity_sum;
}
#if CONFIG_MULTITHREAD
if ((cpi->b_multi_threaded != 0) && (mb_row == cm->mb_rows - 1))
{
sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
}
#endif
}
void vp8_encode_frame(VP8_COMP *cpi) void vp8_encode_frame(VP8_COMP *cpi)
{ {
...@@ -800,22 +833,16 @@ void vp8_encode_frame(VP8_COMP *cpi) ...@@ -800,22 +833,16 @@ void vp8_encode_frame(VP8_COMP *cpi)
vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei, 1, cpi->encoding_thread_count); vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei, 1, cpi->encoding_thread_count);
for (mb_row = 0; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1)) for (i = 0; i < cm->mb_rows; i++)
{ cpi->mt_current_mb_col[i] = 0;
cpi->current_mb_col_main = -1;
for (i = 0; i < cpi->encoding_thread_count; i++) for (i = 0; i < cpi->encoding_thread_count; i++)
{ {
if ((mb_row + i + 1) >= cm->mb_rows) sem_post(&cpi->h_event_start_encoding[i]);
break; }
cpi->mb_row_ei[i].mb_row = mb_row + i + 1;
cpi->mb_row_ei[i].tp = cpi->tok + (mb_row + i + 1) * (cm->mb_cols * 16 * 24);
cpi->mb_row_ei[i].current_mb_col = -1;
//SetEvent(cpi->h_event_mbrencoding[i]);
sem_post(&cpi->h_event_mbrencoding[i]);
}
for (mb_row = 0; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1))
{
vp8_zero(cm->left_context) vp8_zero(cm->left_context)
tp = cpi->tok + mb_row * (cm->mb_cols * 16 * 24); tp = cpi->tok + mb_row * (cm->mb_cols * 16 * 24);
...@@ -830,26 +857,10 @@ void vp8_encode_frame(VP8_COMP *cpi) ...@@ -830,26 +857,10 @@ void vp8_encode_frame(VP8_COMP *cpi)
xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count; xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count; x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
if (mb_row < cm->mb_rows - 1)
//WaitForSingleObject(cpi->h_event_main, INFINITE);
sem_wait(&cpi->h_event_main);
} }
/* sem_wait(&cpi->h_event_end_encoding); /* wait for other threads to finish */
for( ;mb_row<cm->mb_rows; mb_row ++)
{
vp8_zero( cm->left_context)
tp = cpi->tok + mb_row * (cm->mb_cols * 16 * 24);
encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);
// adjust to the next row of mbs
x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
x->src.u_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
x->src.v_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
}
*/
cpi->tok_count = 0; cpi->tok_count = 0;
for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++) for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
...@@ -859,7 +870,6 @@ void vp8_encode_frame(VP8_COMP *cpi) ...@@ -859,7 +870,6 @@ void vp8_encode_frame(VP8_COMP *cpi)
if (xd->segmentation_enabled) if (xd->segmentation_enabled)
{ {
int i, j; int i, j;
if (xd->segmentation_enabled) if (xd->segmentation_enabled)
...@@ -871,7 +881,6 @@ void vp8_encode_frame(VP8_COMP *cpi) ...@@ -871,7 +881,6 @@ void vp8_encode_frame(VP8_COMP *cpi)
segment_counts[j] += cpi->mb_row_ei[i].segment_counts[j]; segment_counts[j] += cpi->mb_row_ei[i].segment_counts[j];
} }
} }
} }
for (i = 0; i < cpi->encoding_thread_count; i++) for (i = 0; i < cpi->encoding_thread_count; i++)
......
This diff is collapsed.
...@@ -1465,6 +1465,17 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi) ...@@ -1465,6 +1465,17 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
"Failed to allocate firstpass stats"); "Failed to allocate firstpass stats");
#endif #endif
#if CONFIG_MULTITHREAD
if (width < 640)
cpi->mt_sync_range = 1;
else if (width <= 1280)
cpi->mt_sync_range = 4;
else if (width <= 2560)
cpi->mt_sync_range = 8;
else
cpi->mt_sync_range = 16;
#endif
} }
...@@ -4413,7 +4424,7 @@ static void encode_frame_to_data_rate ...@@ -4413,7 +4424,7 @@ static void encode_frame_to_data_rate
} }
// Update the GF useage maps. // Update the GF useage maps.
// Update the GF useage maps. // This is done after completing the compression of a frame when all modes etc. are finalized but before loop filter
// This is done after completing the compression of a frame when all modes etc. are finalized but before loop filter // This is done after completing the compression of a frame when all modes etc. are finalized but before loop filter
vp8_update_gf_useage_maps(cpi, cm, &cpi->mb); vp8_update_gf_useage_maps(cpi, cm, &cpi->mb);
......
...@@ -191,11 +191,8 @@ typedef struct ...@@ -191,11 +191,8 @@ typedef struct
typedef struct typedef struct
{ {
MACROBLOCK mb; MACROBLOCK mb;
int mb_row;
TOKENEXTRA *tp;
int segment_counts[MAX_MB_SEGMENTS]; int segment_counts[MAX_MB_SEGMENTS];
int totalrate; int totalrate;
int current_mb_col;
} MB_ROW_COMP; } MB_ROW_COMP;
typedef struct typedef struct
...@@ -593,7 +590,8 @@ typedef struct ...@@ -593,7 +590,8 @@ typedef struct
signed char *cyclic_refresh_map; signed char *cyclic_refresh_map;
// multithread data // multithread data
int current_mb_col_main; int * mt_current_mb_col;
int mt_sync_range;
int processor_core_count; int processor_core_count;
int b_multi_threaded; int b_multi_threaded;
int encoding_thread_count; int encoding_thread_count;
...@@ -606,8 +604,8 @@ typedef struct ...@@ -606,8 +604,8 @@ typedef struct
#if CONFIG_MULTITHREAD #if CONFIG_MULTITHREAD
//events //events
sem_t *h_event_mbrencoding; sem_t *h_event_start_encoding;
sem_t h_event_main; sem_t h_event_end_encoding;
#endif #endif
TOKENLIST *tplist; TOKENLIST *tplist;
......
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