From 3403acb3c64cbe4e060871c77d0a83d3af75f3b9 Mon Sep 17 00:00:00 2001 From: Jerome Jiang Date: Wed, 7 Jun 2023 10:17:41 -0400 Subject: [PATCH] av1: 8 threads for >720p and tiles config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use 8 threads for > 720p Use 4 tile columns and 2 tile rows for 8 threads Use 2 tile columns and 2 tile rows for 4 threads For VGA, 2 tile_col x 2 tile_row configuration has - ~9% speedup over 4 tile_col x 1 tile_row - ~5% speedup over 1 tile_col x 4 tile_row Bug: None Change-Id: I3c1ea948437aece7c6734ce25351158cbdf0a15b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/307880 Commit-Queue: Jerome Jiang Reviewed-by: Erik Språng Cr-Commit-Position: refs/heads/main@{#40237} --- .../codecs/av1/libaom_av1_encoder.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc index d23e2d14d8..28a8e5f846 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc @@ -292,10 +292,16 @@ int LibaomAv1Encoder::InitEncode(const VideoCodec* codec_settings, SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_ENABLE_PALETTE, 0); } - if (cfg_.g_threads == 4 && cfg_.g_w == 640 && - (cfg_.g_h == 360 || cfg_.g_h == 480)) { - SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_TILE_ROWS, - static_cast(log2(cfg_.g_threads))); + if (cfg_.g_threads == 8) { + // Values passed to AV1E_SET_TILE_ROWS and AV1E_SET_TILE_COLUMNS are log2() + // based. + // Use 4 tile columns x 2 tile rows for 8 threads. + SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_TILE_ROWS, 1); + SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_TILE_COLUMNS, 2); + } else if (cfg_.g_threads == 4) { + // Use 2 tile columns x 2 tile rows for 4 threads. + SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_TILE_ROWS, 1); + SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_TILE_COLUMNS, 1); } else { SET_ENCODER_PARAM_OR_RETURN_ERROR(AV1E_SET_TILE_COLUMNS, static_cast(log2(cfg_.g_threads))); @@ -399,7 +405,9 @@ int LibaomAv1Encoder::NumberOfThreads(int width, // Keep the number of encoder threads equal to the possible number of // column/row tiles, which is (1, 2, 4, 8). See comments below for // AV1E_SET_TILE_COLUMNS/ROWS. - if (width * height >= 640 * 360 && number_of_cores > 4) { + if (width * height > 1280 * 720 && number_of_cores > 8) { + return 8; + } else if (width * height >= 640 * 360 && number_of_cores > 4) { return 4; } else if (width * height >= 320 * 180 && number_of_cores > 2) { return 2;