Commit 917d6c06 authored by Dominic Symes's avatar Dominic Symes

max-tile: Fix issues discovered when testing max-tile

max-tile remains off by default until more testing is performed but I would
like to check in the fixes that are known so far to prevent this patch getting too big

max_tile was provisionally adopted at the working group meeting 2017-Oct-10

This patch fixes the following issues:
- max_tile is fixed to suport superblock size 64x64 as well as 128x128 (ext_partition support)
- max_tile is fixed in combination with loop_restoration
- max_tile is fixed in combination with ext_tile (Bug: 1013)
- max_tile is fixed in combination with lv_map and 64x64 subperblock (lv_map memory allocation
  fixed for 64x64 superblock)
- max_tile reports the size of the first tile for inspection.c used by the analyzer

Change-Id: Ib83ff613e5d66563c81452a085c7984d3b4813e4
parent 8ac4557b
......@@ -135,8 +135,9 @@ void av1_alloc_restoration_buffers(AV1_COMMON *cm) {
int num_stripes = 0;
for (int i = 0; i < cm->tile_rows; ++i) {
#if CONFIG_MAX_TILE
const int sb_h = cm->tile_row_start_sb[i + 1] - cm->tile_row_start_sb[i];
const int mi_h = sb_h << MAX_MIB_SIZE_LOG2;
TileInfo tile_info;
av1_tile_set_row(&tile_info, cm, i);
const int mi_h = tile_info.mi_row_end - tile_info.mi_row_start;
#else
const int mi_h = ((i + 1) < cm->tile_rows)
? cm->tile_height
......
......@@ -480,6 +480,9 @@ typedef struct AV1Common {
#if CONFIG_DEPENDENT_HORZTILES
int tile_row_independent[MAX_TILE_ROWS]; // valid for 0 <= i < tile_rows
#endif
#if CONFIG_EXT_TILE
int tile_width, tile_height; // In MI units
#endif
#else
int log2_tile_cols, log2_tile_rows; // Used in non-large_scale_tile_coding.
int tile_width, tile_height; // In MI units
......
......@@ -41,26 +41,6 @@ const sgr_params_type sgr_params[SGRPROJ_PARAMS] = {
#endif // MAX_RADIUS == 2
};
#if CONFIG_MAX_TILE
static void tile_width_and_height(const AV1_COMMON *cm, int is_uv, int sb_w,
int sb_h, int *px_w, int *px_h) {
const int scaled_sb_w = sb_w << MAX_MIB_SIZE_LOG2;
const int scaled_sb_h = sb_h << MAX_MIB_SIZE_LOG2;
const int ss_x = is_uv && cm->subsampling_x;
const int ss_y = is_uv && cm->subsampling_y;
*px_w = (scaled_sb_w + ss_x) >> ss_x;
*px_h = (scaled_sb_h + ss_y) >> ss_y;
#if CONFIG_FRAME_SUPERRES
if (!av1_superres_unscaled(cm)) {
av1_calculate_unscaled_superres_size(px_w, px_h,
cm->superres_scale_denominator);
}
#endif // CONFIG_FRAME_SUPERRES
}
#endif // CONFIG_MAX_TILE
// Similar to av1_get_tile_rect(), except that we extend the bottommost tile in
// each frame to a multiple of 8 luma pixels.
// This is done to help simplify the implementation of striped-loop-restoration,
......@@ -93,30 +73,37 @@ void av1_alloc_restoration_struct(AV1_COMMON *cm, RestorationInfo *rsi,
// top-left and we can use get_ext_tile_rect(). With CONFIG_MAX_TILE, we have
// to do the computation ourselves, iterating over the tiles and keeping
// track of the largest width and height, then upscaling.
int max_sb_w = 0;
int max_sb_h = 0;
TileInfo tile;
int max_mi_w = 0;
int max_mi_h = 0;
int tile_col = 0;
int tile_row = 0;
for (int i = 0; i < cm->tile_cols; ++i) {
const int sb_w = cm->tile_col_start_sb[i + 1] - cm->tile_col_start_sb[i];
max_sb_w = AOMMAX(max_sb_w, sb_w);
av1_tile_set_col(&tile, cm, i);
if (tile.mi_col_end - tile.mi_col_start > max_mi_w) {
max_mi_w = tile.mi_col_end - tile.mi_col_start;
tile_col = i;
}
}
for (int i = 0; i < cm->tile_rows; ++i) {
const int sb_h = cm->tile_row_start_sb[i + 1] - cm->tile_row_start_sb[i];
max_sb_h = AOMMAX(max_sb_h, sb_h);
av1_tile_set_row(&tile, cm, i);
if (tile.mi_row_end - tile.mi_row_start > max_mi_h) {
max_mi_h = tile.mi_row_end - tile.mi_row_start;
tile_row = i;
}
}
int max_tile_w, max_tile_h;
tile_width_and_height(cm, is_uv, max_sb_w, max_sb_h, &max_tile_w,
&max_tile_h);
TileInfo tile_info;
av1_tile_init(&tile_info, cm, tile_row, tile_col);
#else
TileInfo tile_info;
av1_tile_init(&tile_info, cm, 0, 0);
#endif // CONFIG_MAX_TILE
const AV1PixelRect tile_rect = get_ext_tile_rect(&tile_info, cm, is_uv);
assert(tile_rect.left == 0 && tile_rect.top == 0);
const int max_tile_w = tile_rect.right;
const int max_tile_h = tile_rect.bottom;
#endif // CONFIG_MAX_TILE
// To calculate hpertile and vpertile (horizontal and vertical units per
// tile), we basically want to divide the largest tile width or height by the
......@@ -1562,8 +1549,8 @@ void av1_foreach_rest_unit_in_frame(const struct AV1Common *cm, int plane,
// For a vertical index, mi_x should be the block's top row and tile_x_start_sb
// should be cm->tile_row_start_sb. The return value will be "tile_row" for the
// tile containing the block.
static int get_tile_idx(const int *tile_x_start_sb, int mi_x) {
int sb_x = mi_x << MAX_MIB_SIZE_LOG2;
static int get_tile_idx(const int *tile_x_start_sb, int mi_x, int mib_log2) {
int sb_x = mi_x >> mib_log2;
for (int i = 0; i < MAX_TILE_COLS; ++i) {
if (tile_x_start_sb[i + 1] > sb_x) return i;
......@@ -1590,22 +1577,13 @@ int av1_loop_restoration_corners_in_sb(const struct AV1Common *cm, int plane,
// Which tile contains the superblock? Find that tile's top-left in mi-units,
// together with the tile's size in pixels.
#if CONFIG_MAX_TILE
const int tile_row = get_tile_idx(cm->tile_row_start_sb, mi_row);
const int tile_col = get_tile_idx(cm->tile_col_start_sb, mi_col);
const int sb_t = cm->tile_row_start_sb[tile_row];
const int sb_l = cm->tile_col_start_sb[tile_col];
const int sb_b = cm->tile_row_start_sb[tile_row + 1];
const int sb_r = cm->tile_col_start_sb[tile_col + 1];
int tile_w, tile_h;
tile_width_and_height(cm, is_uv, sb_r - sb_l, sb_t - sb_b, &tile_w, &tile_h);
const int mi_top = sb_t << MAX_MIB_SIZE_LOG2;
const int mi_left = sb_l << MAX_MIB_SIZE_LOG2;
const int mib_log2 = cm->mib_size_log2;
const int tile_row = get_tile_idx(cm->tile_row_start_sb, mi_row, mib_log2);
const int tile_col = get_tile_idx(cm->tile_col_start_sb, mi_col, mib_log2);
#else
const int tile_row = mi_row / cm->tile_height;
const int tile_col = mi_col / cm->tile_width;
#endif // CONFIG_MAX_TILE
TileInfo tile_info;
av1_tile_init(&tile_info, cm, tile_row, tile_col);
......@@ -1616,7 +1594,6 @@ int av1_loop_restoration_corners_in_sb(const struct AV1Common *cm, int plane,
const int mi_top = tile_info.mi_row_start;
const int mi_left = tile_info.mi_col_start;
#endif // CONFIG_MAX_TILE
// Compute the mi-unit corners of the superblock relative to the top-left of
// the tile
......
......@@ -49,10 +49,10 @@ static int tile_log2(int blk_size, int target) {
}
void av1_get_tile_limits(AV1_COMMON *const cm) {
int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2);
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2);
int sb_cols = mi_cols >> MAX_MIB_SIZE_LOG2;
int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2;
int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->mib_size_log2);
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2);
int sb_cols = mi_cols >> cm->mib_size_log2;
int sb_rows = mi_rows >> cm->mib_size_log2;
cm->min_log2_tile_cols = tile_log2(MAX_TILE_WIDTH_SB, sb_cols);
cm->max_log2_tile_cols = tile_log2(1, AOMMIN(sb_cols, MAX_TILE_COLS));
......@@ -64,10 +64,10 @@ void av1_get_tile_limits(AV1_COMMON *const cm) {
}
void av1_calculate_tile_cols(AV1_COMMON *const cm) {
int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2);
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2);
int sb_cols = mi_cols >> MAX_MIB_SIZE_LOG2;
int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2;
int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->mib_size_log2);
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2);
int sb_cols = mi_cols >> cm->mib_size_log2;
int sb_rows = mi_rows >> cm->mib_size_log2;
int i;
if (cm->uniform_tile_spacing_flag) {
......@@ -85,7 +85,7 @@ void av1_calculate_tile_cols(AV1_COMMON *const cm) {
cm->max_tile_height_sb = sb_rows >> cm->min_log2_tile_rows;
} else {
int max_tile_area_sb = (sb_rows * sb_cols);
int max_tile_width_sb = 0;
int max_tile_width_sb = 1;
cm->log2_tile_cols = tile_log2(1, cm->tile_cols);
for (i = 0; i < cm->tile_cols; i++) {
int size_sb = cm->tile_col_start_sb[i + 1] - cm->tile_col_start_sb[i];
......@@ -99,8 +99,8 @@ void av1_calculate_tile_cols(AV1_COMMON *const cm) {
}
void av1_calculate_tile_rows(AV1_COMMON *const cm) {
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2);
int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2;
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2);
int sb_rows = mi_rows >> cm->mib_size_log2;
int start_sb, size_sb, i;
if (cm->uniform_tile_spacing_flag) {
......@@ -131,18 +131,20 @@ void av1_calculate_tile_rows(AV1_COMMON *const cm) {
void av1_tile_set_row(TileInfo *tile, const AV1_COMMON *cm, int row) {
assert(row < cm->tile_rows);
int mi_row_start = cm->tile_row_start_sb[row] << MAX_MIB_SIZE_LOG2;
int mi_row_end = cm->tile_row_start_sb[row + 1] << MAX_MIB_SIZE_LOG2;
int mi_row_start = cm->tile_row_start_sb[row] << cm->mib_size_log2;
int mi_row_end = cm->tile_row_start_sb[row + 1] << cm->mib_size_log2;
tile->mi_row_start = mi_row_start;
tile->mi_row_end = AOMMIN(mi_row_end, cm->mi_rows);
assert(tile->mi_row_end > tile->mi_row_start);
}
void av1_tile_set_col(TileInfo *tile, const AV1_COMMON *cm, int col) {
assert(col < cm->tile_cols);
int mi_col_start = cm->tile_col_start_sb[col] << MAX_MIB_SIZE_LOG2;
int mi_col_end = cm->tile_col_start_sb[col + 1] << MAX_MIB_SIZE_LOG2;
int mi_col_start = cm->tile_col_start_sb[col] << cm->mib_size_log2;
int mi_col_end = cm->tile_col_start_sb[col + 1] << cm->mib_size_log2;
tile->mi_col_start = mi_col_start;
tile->mi_col_end = AOMMIN(mi_col_end, cm->mi_cols);
assert(tile->mi_col_end > tile->mi_col_start);
}
#else
......
......@@ -1611,10 +1611,10 @@ static int rb_read_uniform(struct aom_read_bit_buffer *const rb, int n) {
static void read_tile_info_max_tile(AV1_COMMON *const cm,
struct aom_read_bit_buffer *const rb) {
int width_mi = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2);
int height_mi = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2);
int width_sb = width_mi >> MAX_MIB_SIZE_LOG2;
int height_sb = height_mi >> MAX_MIB_SIZE_LOG2;
int width_mi = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->mib_size_log2);
int height_mi = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2);
int width_sb = width_mi >> cm->mib_size_log2;
int height_sb = height_mi >> cm->mib_size_log2;
av1_get_tile_limits(cm);
cm->uniform_tile_spacing_flag = aom_rb_read_bit(rb);
......@@ -1737,6 +1737,17 @@ static void read_tile_info(AV1Decoder *const pbi,
pbi->tile_col_size_bytes = aom_rb_read_literal(rb, 2) + 1;
pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1;
}
#if CONFIG_MAX_TILE
int i;
for (i = 0; i <= cm->tile_cols; i++) {
cm->tile_col_start_sb[i] =
((i * cm->tile_width - 1) >> cm->mib_size_log2) + 1;
}
for (i = 0; i <= cm->tile_rows; i++) {
cm->tile_row_start_sb[i] =
((i * cm->tile_height - 1) >> cm->mib_size_log2) + 1;
}
#endif // CONFIG_MAX_TILE
} else {
#endif // CONFIG_EXT_TILE
......
......@@ -43,8 +43,17 @@ int ifd_inspect(insp_frame_data *fd, void *decoder) {
fd->show_frame = cm->show_frame;
fd->frame_type = cm->frame_type;
fd->base_qindex = cm->base_qindex;
#if CONFIG_MAX_TILE
// Set width and height of the first tile until generic support can be added
TileInfo tile_info;
av1_tile_set_row(&tile_info, cm, 0);
av1_tile_set_col(&tile_info, cm, 0);
fd->tile_mi_cols = tile_info.mi_col_end - tile_info.mi_col_start;
fd->tile_mi_rows = tile_info.mi_row_end - tile_info.mi_row_start;
#else
fd->tile_mi_cols = cm->tile_width;
fd->tile_mi_rows = cm->tile_height;
#endif
fd->delta_q_present_flag = cm->delta_q_present_flag;
fd->delta_q_res = cm->delta_q_res;
#if CONFIG_ACCOUNTING
......
......@@ -2767,10 +2767,10 @@ static void wb_write_uniform(struct aom_write_bit_buffer *wb, int n, int v) {
static void write_tile_info_max_tile(const AV1_COMMON *const cm,
struct aom_write_bit_buffer *wb) {
int width_mi = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2);
int height_mi = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2);
int width_sb = width_mi >> MAX_MIB_SIZE_LOG2;
int height_sb = height_mi >> MAX_MIB_SIZE_LOG2;
int width_mi = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->mib_size_log2);
int height_mi = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2);
int width_sb = width_mi >> cm->mib_size_log2;
int height_sb = height_mi >> cm->mib_size_log2;
int size_sb, i;
aom_wb_write_bit(wb, cm->uniform_tile_spacing_flag);
......
......@@ -301,10 +301,14 @@ static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) {
assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC);
#if !CONFIG_MAX_TILE
// for the max_tile experiment there is no common tile_width, tile_height
// max_tile assumes tile dimensions are in superblocks (not 64x64 units)
assert(IMPLIES(cpi->common.tile_cols > 1,
cpi->common.tile_width % MAX_MIB_SIZE == 0));
assert(IMPLIES(cpi->common.tile_rows > 1,
cpi->common.tile_height % MAX_MIB_SIZE == 0));
#endif
// TODO(any): Possibly could improve this with a heuristic.
return BLOCK_128X128;
......@@ -872,8 +876,8 @@ static void set_tile_info_max_tile(AV1_COMP *cpi) {
cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols);
cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols);
} else {
int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2);
int sb_cols = mi_cols >> MAX_MIB_SIZE_LOG2;
int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->mib_size_log2);
int sb_cols = mi_cols >> cm->mib_size_log2;
int size_sb, j = 0;
cm->uniform_tile_spacing_flag = 0;
for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) {
......@@ -892,8 +896,8 @@ static void set_tile_info_max_tile(AV1_COMP *cpi) {
cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows);
cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows);
} else {
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2);
int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2;
int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2);
int sb_rows = mi_rows >> cm->mib_size_log2;
int size_sb, j = 0;
for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) {
cm->tile_row_start_sb[i] = start_sb;
......@@ -949,6 +953,17 @@ static void set_tile_info(AV1_COMP *cpi) {
cm->tile_rows = 1;
while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows;
#if CONFIG_MAX_TILE
int i;
for (i = 0; i <= cm->tile_cols; i++) {
cm->tile_col_start_sb[i] =
((i * cm->tile_width - 1) >> cm->mib_size_log2) + 1;
}
for (i = 0; i <= cm->tile_rows; i++) {
cm->tile_row_start_sb[i] =
((i * cm->tile_height - 1) >> cm->mib_size_log2) + 1;
}
#endif // CONFIG_MAX_TILE
} else {
#endif // CONFIG_EXT_TILE
......@@ -1070,6 +1085,7 @@ static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) {
cm->width = oxcf->width;
cm->height = oxcf->height;
set_sb_size(cm, select_sb_size(cpi)); // set sb size before allocations
alloc_compressor_data(cpi);
// Single thread case: use counts in common.
......@@ -2499,8 +2515,12 @@ void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
cm->width = cpi->oxcf.width;
cm->height = cpi->oxcf.height;
if (cpi->initial_width) {
if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) {
int sb_size = cm->sb_size;
set_sb_size(cm, select_sb_size(cpi));
if (cpi->initial_width || sb_size != cm->sb_size) {
if (cm->width > cpi->initial_width || cm->height > cpi->initial_height ||
cm->sb_size != sb_size) {
av1_free_context_buffers(cm);
av1_free_pc_tree(&cpi->td);
alloc_compressor_data(cpi);
......
......@@ -58,8 +58,8 @@ void av1_alloc_txb_buf(AV1_COMP *cpi) {
}
#else
AV1_COMMON *cm = &cpi->common;
int size = ((cm->mi_rows >> MAX_MIB_SIZE_LOG2) + 1) *
((cm->mi_cols >> MAX_MIB_SIZE_LOG2) + 1);
int size = ((cm->mi_rows >> cm->mib_size_log2) + 1) *
((cm->mi_cols >> cm->mib_size_log2) + 1);
av1_free_txb_buf(cpi);
// TODO(jingning): This should be further reduced.
......@@ -81,9 +81,9 @@ void av1_free_txb_buf(AV1_COMP *cpi) {
void av1_set_coeff_buffer(const AV1_COMP *const cpi, MACROBLOCK *const x,
int mi_row, int mi_col) {
int stride = (cpi->common.mi_cols >> MAX_MIB_SIZE_LOG2) + 1;
int offset =
(mi_row >> MAX_MIB_SIZE_LOG2) * stride + (mi_col >> MAX_MIB_SIZE_LOG2);
int mib_size_log2 = cpi->common.mib_size_log2;
int stride = (cpi->common.mi_cols >> mib_size_log2) + 1;
int offset = (mi_row >> mib_size_log2) * stride + (mi_col >> mib_size_log2);
CB_COEFF_BUFFER *coeff_buf = &cpi->coeff_buffer_base[offset];
const int txb_offset = x->cb_offset / (TX_SIZE_W_MIN * TX_SIZE_H_MIN);
for (int plane = 0; plane < MAX_MB_PLANE; ++plane) {
......
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