Bug 1855550 - VP8: disallow thread count changes. r=jesup
authorRyan VanderMeulen <ryanvm@gmail.com>
Wed, 27 Sep 2023 23:12:23 +0000 (21 months ago)
changeset 679511 c53f5ef77b62b79af86951a7f9130e1896b695d2
parent 679510 90445136a15d059a272041ef3c4a277732b346b6
child 679512 39eca5660ff2d818124991131dd408dd17a01671
push id41223
push userctuns@mozilla.com
push dateThu, 28 Sep 2023 03:53:26 +0000 (21 months ago)
treeherdermozilla-central@d2acd6e78b18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1855550
milestone120.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1855550 - VP8: disallow thread count changes. r=jesup Cherry-pick of upstream libvpx commits: https://chromium.googlesource.com/webm/libvpx/+/af6dedd715f4307669366944cca6e0417b290282 https://chromium.googlesource.com/webm/libvpx/+/3fbd1dca6a4d2dad332a2110d646e4ffef36d590 Differential Revision: https://phabricator.services.mozilla.com/D189428
media/libvpx/libvpx/test/encode_api_test.cc
media/libvpx/libvpx/vp8/encoder/onyx_if.c
--- a/media/libvpx/libvpx/test/encode_api_test.cc
+++ b/media/libvpx/libvpx/test/encode_api_test.cc
@@ -302,17 +302,16 @@ TEST(EncodeAPI, SetRoi) {
     }
 
     EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK);
   }
 }
 
 void InitCodec(const vpx_codec_iface_t &iface, int width, int height,
                vpx_codec_ctx_t *enc, vpx_codec_enc_cfg_t *cfg) {
-  ASSERT_EQ(vpx_codec_enc_config_default(&iface, cfg, 0), VPX_CODEC_OK);
   cfg->g_w = width;
   cfg->g_h = height;
   cfg->g_lag_in_frames = 0;
   cfg->g_pass = VPX_RC_ONE_PASS;
   ASSERT_EQ(vpx_codec_enc_init(enc, &iface, cfg, 0), VPX_CODEC_OK);
 
   ASSERT_EQ(vpx_codec_control_(enc, VP8E_SET_CPUUSED, 2), VPX_CODEC_OK);
 }
@@ -340,16 +339,17 @@ TEST(EncodeAPI, ConfigChangeThreadCount)
     SCOPED_TRACE(vpx_codec_iface_name(iface));
     for (int i = 0; i < (IsVP9(iface) ? 2 : 1); ++i) {
       vpx_codec_enc_cfg_t cfg = {};
       struct Encoder {
         ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); }
         vpx_codec_ctx_t ctx = {};
       } enc;
 
+      ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK);
       EXPECT_NO_FATAL_FAILURE(
           InitCodec(*iface, kWidth, kHeight, &enc.ctx, &cfg));
       if (IsVP9(iface)) {
         EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_TILE_COLUMNS, 6),
                   VPX_CODEC_OK);
         EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_ROW_MT, i),
                   VPX_CODEC_OK);
       }
@@ -358,16 +358,60 @@ TEST(EncodeAPI, ConfigChangeThreadCount)
         cfg.g_threads = threads;
         EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc.ctx))
             << "iteration: " << i << " threads: " << threads;
       }
     }
   }
 }
 
+TEST(EncodeAPI, ConfigResizeChangeThreadCount) {
+  constexpr int kInitWidth = 1024;
+  constexpr int kInitHeight = 1024;
+
+  for (const auto *iface : kCodecIfaces) {
+    SCOPED_TRACE(vpx_codec_iface_name(iface));
+    for (int i = 0; i < (IsVP9(iface) ? 2 : 1); ++i) {
+      vpx_codec_enc_cfg_t cfg = {};
+      struct Encoder {
+        ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); }
+        vpx_codec_ctx_t ctx = {};
+      } enc;
+
+      ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK);
+      // Start in threaded mode to ensure resolution and thread related
+      // allocations are updated correctly across changes in resolution and
+      // thread counts. See https://crbug.com/1486441.
+      cfg.g_threads = 4;
+      EXPECT_NO_FATAL_FAILURE(
+          InitCodec(*iface, kInitWidth, kInitHeight, &enc.ctx, &cfg));
+      if (IsVP9(iface)) {
+        EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_TILE_COLUMNS, 6),
+                  VPX_CODEC_OK);
+        EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_ROW_MT, i),
+                  VPX_CODEC_OK);
+      }
+
+      cfg.g_w = 1000;
+      cfg.g_h = 608;
+      EXPECT_EQ(vpx_codec_enc_config_set(&enc.ctx, &cfg), VPX_CODEC_OK)
+          << vpx_codec_error_detail(&enc.ctx);
+
+      cfg.g_w = 16;
+      cfg.g_h = 720;
+
+      for (const auto threads : { 1, 4, 8, 6, 2, 1 }) {
+        cfg.g_threads = threads;
+        EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc.ctx))
+            << "iteration: " << i << " threads: " << threads;
+      }
+    }
+  }
+}
+
 #if CONFIG_VP9_ENCODER
 class EncodeApiGetTplStatsTest
     : public ::libvpx_test::EncoderTest,
       public ::testing::TestWithParam<const libvpx_test::CodecFactory *> {
  public:
   EncodeApiGetTplStatsTest() : EncoderTest(GetParam()) {}
   ~EncodeApiGetTplStatsTest() override {}
 
--- a/media/libvpx/libvpx/vp8/encoder/onyx_if.c
+++ b/media/libvpx/libvpx/vp8/encoder/onyx_if.c
@@ -1442,16 +1442,22 @@ void vp8_change_config(VP8_COMP *cpi, VP
     cm->version = oxcf->Version;
     vp8_setup_version(cm);
   }
 
   last_w = cpi->oxcf.Width;
   last_h = cpi->oxcf.Height;
   prev_number_of_layers = cpi->oxcf.number_of_layers;
 
+  if (cpi->initial_width) {
+    // TODO(https://crbug.com/1486441): Allow changing thread counts; the
+    // allocation is done once in vp8_create_compressor().
+    oxcf->multi_threaded = cpi->oxcf.multi_threaded;
+  }
+
   cpi->oxcf = *oxcf;
 
   switch (cpi->oxcf.Mode) {
     case MODE_REALTIME:
       cpi->pass = 0;
       cpi->compressor_speed = 2;
 
       if (cpi->oxcf.cpu_used < -16) {