av1: 8 threads for >720p and tiles config
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 <jianj@google.com>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40237}
diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc
index d23e2d1..28a8e5f 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 @@
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<int>(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<int>(log2(cfg_.g_threads)));
@@ -399,7 +405,9 @@
// 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;