Commit 24ab1dd15d for aom
commit 24ab1dd15d5bca73178e1e42dd3b93bb9caa5db3
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
(cherry picked from commit 900fa7eef8505fe0a530115c67c04d956e20f48e)
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 733f2697f6..423f2f93b9 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1556,9 +1556,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 3b38c805b2..fb6a13a70c 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;
@@ -1736,9 +1737,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);
@@ -1926,9 +1926,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);
}
@@ -2004,9 +2005,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 572ff0ed2a..4436f004f3 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -1334,7 +1334,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);
}