Commit 900fa7eef8 for aom
commit 900fa7eef8505fe0a530115c67c04d956e20f48e
Author: James Zern <jzern@google.com>
Date: Thu Mar 5 11:02:08 2026 -0800
enc: always alloc tile data w/tile count change
Previously the code would retain an earlier allocation if the number of
tiles was less than or equal to the current count. This change always
reallocates tile data when the tile count changes. It avoids holding on
to extra memory unnecessarily. This is an uncommon condition, so there's
no need to optimize this.
Note this may be unnecessary after
c2daa0f13c Use enc_row_mt->allocated_tile_cols/rows correctly
but given the complex logic around this code, forcing the allocation may
be safest.
Bug: 487259772
Change-Id: I6acd5febcd79dce89b59869bf65386df2c993dc8
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 6cc6770967..6f3bbc21aa 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1564,9 +1564,8 @@ static inline void encode_tiles(AV1_COMP *cpi) {
int tile_col, tile_row;
MACROBLOCK *const mb = &cpi->td.mb;
- assert(IMPLIES(cpi->tile_data == NULL,
- cpi->allocated_tiles < tile_cols * tile_rows));
- if (cpi->allocated_tiles < tile_cols * tile_rows) av1_alloc_tile_data(cpi);
+ assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
+ if (cpi->allocated_tiles != tile_cols * tile_rows) av1_alloc_tile_data(cpi);
av1_init_tile_data(cpi);
av1_alloc_mb_data(cpi, mb);
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 1c8d1bdffc..4f5fe5d5f9 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -249,6 +249,7 @@ static void row_mt_mem_alloc(AV1_COMP *cpi, int max_rows, int max_cols,
av1_row_mt_mem_dealloc(cpi);
// Allocate memory for row based multi-threading
+ assert(cpi->allocated_tiles == tile_cols * tile_rows);
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
for (tile_col = 0; tile_col < tile_cols; tile_col++) {
int tile_index = tile_row * tile_cols + tile_col;
@@ -1745,9 +1746,8 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) {
const int tile_rows = cm->tiles.rows;
int num_workers = mt_info->num_mod_workers[MOD_ENC];
- assert(IMPLIES(cpi->tile_data == NULL,
- cpi->allocated_tiles < tile_cols * tile_rows));
- if (cpi->allocated_tiles < tile_cols * tile_rows) av1_alloc_tile_data(cpi);
+ assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
+ if (cpi->allocated_tiles != tile_cols * tile_rows) av1_alloc_tile_data(cpi);
av1_init_tile_data(cpi);
num_workers = AOMMIN(num_workers, mt_info->num_workers);
@@ -1935,9 +1935,10 @@ void av1_encode_tiles_row_mt(AV1_COMP *cpi) {
enc_row_mt->allocated_rows != max_sb_rows_in_tile ||
enc_row_mt->allocated_cols != (max_sb_cols_in_tile - 1) ||
enc_row_mt->allocated_sb_rows != sb_rows_in_frame);
- const bool alloc_tile_data = cpi->allocated_tiles < tile_cols * tile_rows;
+ const bool alloc_tile_data = cpi->allocated_tiles != tile_cols * tile_rows;
assert(IMPLIES(cpi->tile_data == NULL, alloc_tile_data));
+ assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
if (alloc_tile_data) {
av1_alloc_tile_data(cpi);
}
@@ -2013,9 +2014,10 @@ void av1_fp_encode_tiles_row_mt(AV1_COMP *cpi) {
const bool alloc_row_mt_mem = enc_row_mt->allocated_tile_cols != tile_cols ||
enc_row_mt->allocated_tile_rows != tile_rows ||
enc_row_mt->allocated_rows != max_mb_rows;
- const bool alloc_tile_data = cpi->allocated_tiles < tile_cols * tile_rows;
+ const bool alloc_tile_data = cpi->allocated_tiles != tile_cols * tile_rows;
assert(IMPLIES(cpi->tile_data == NULL, alloc_tile_data));
+ assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
if (alloc_tile_data) {
av1_alloc_tile_data(cpi);
}
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 0c66d7febe..07a9d3b206 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -1361,7 +1361,7 @@ void av1_first_pass(AV1_COMP *cpi, const int64_t ts_duration) {
const int tile_cols = cm->tiles.cols;
const int tile_rows = cm->tiles.rows;
- if (cpi->allocated_tiles < tile_cols * tile_rows) {
+ if (cpi->allocated_tiles != tile_cols * tile_rows) {
av1_alloc_tile_data(cpi);
}