mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[fuchsia] shader warmup fixes (flutter/engine#22439)
This change contains a couple of changes that should have been in github.com/flutter/engine/commit/4903a92b2b16e480c486965f6c102f335f1a4ecb but fell through the cracks First one lifts the initialization of the flutter::RunConfiguration so that the asset manager gets set on the persistant cache before the shader warmup happens. I'm not sure how this didnt end up in the first PR I think it got mangled during merge conflict resolution. no test coverage for that code because its in the middle of a 400 line constructor Second one fixes a race condition that the tests dont catch because the tests are single threaded. This change restructures the test that missed this bug so that it would have caught that bug and will catch comparable bugs.
This commit is contained in:
parent
c035c7f167
commit
fa9001447d
@ -201,6 +201,12 @@ Engine::Engine(Delegate& delegate,
|
||||
});
|
||||
};
|
||||
|
||||
// Launch the engine in the appropriate configuration.
|
||||
// Note: this initializes the Asset Manager on the global PersistantCache
|
||||
// so it must be called before WarmupSkps() is called below.
|
||||
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
|
||||
settings, task_runners.GetIOTaskRunner());
|
||||
|
||||
// Setup the callback that will instantiate the platform view.
|
||||
flutter::Shell::CreateCallback<flutter::PlatformView>
|
||||
on_create_platform_view = fml::MakeCopyable(
|
||||
@ -375,10 +381,6 @@ Engine::Engine(Delegate& delegate,
|
||||
};
|
||||
}
|
||||
|
||||
// Launch the engine in the appropriate configuration.
|
||||
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
|
||||
shell_->GetSettings(), shell_->GetTaskRunners().GetIOTaskRunner());
|
||||
|
||||
auto on_run_failure = [weak = weak_factory_.GetWeakPtr()]() {
|
||||
// The engine could have been killed by the caller right after the
|
||||
// constructor was called but before it could run on the UI thread.
|
||||
@ -647,7 +649,7 @@ void Engine::WarmupSkps(fml::BasicTaskRunner* concurrent_task_runner,
|
||||
|
||||
// tell concurrent task runner to deserialize all skps available from
|
||||
// the asset manager
|
||||
concurrent_task_runner->PostTask([&raster_task_runner, skp_warmup_surface,
|
||||
concurrent_task_runner->PostTask([raster_task_runner, skp_warmup_surface,
|
||||
&surface_producer]() {
|
||||
TRACE_DURATION("flutter", "DeserializeSkps");
|
||||
std::vector<std::unique_ptr<fml::Mapping>> skp_mappings =
|
||||
|
||||
@ -34,14 +34,22 @@ class MockTaskRunner : public fml::BasicTaskRunner {
|
||||
virtual ~MockTaskRunner() {}
|
||||
|
||||
void PostTask(const fml::closure& task) override {
|
||||
task_count_++;
|
||||
task();
|
||||
outstanding_tasks_.push(task);
|
||||
}
|
||||
|
||||
int GetTaskCount() { return task_count_; }
|
||||
|
||||
void Run() {
|
||||
while (!outstanding_tasks_.empty()) {
|
||||
outstanding_tasks_.front()();
|
||||
outstanding_tasks_.pop();
|
||||
task_count_++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int task_count_ = 0;
|
||||
std::queue<const fml::closure> outstanding_tasks_;
|
||||
};
|
||||
|
||||
class EngineTest : public ::testing::Test {
|
||||
@ -53,15 +61,16 @@ class EngineTest : public ::testing::Test {
|
||||
|
||||
fuchsia::ui::scenic::SessionPtr session_ptr;
|
||||
scenic::Session session(std::move(session_ptr));
|
||||
VulkanSurfaceProducer surface_producer(&session);
|
||||
surface_producer_ = std::make_unique<VulkanSurfaceProducer>(&session);
|
||||
|
||||
Engine::WarmupSkps(&concurrent_task_runner_, &raster_task_runner_,
|
||||
surface_producer);
|
||||
*surface_producer_);
|
||||
}
|
||||
|
||||
protected:
|
||||
MockTaskRunner concurrent_task_runner_;
|
||||
MockTaskRunner raster_task_runner_;
|
||||
std::unique_ptr<VulkanSurfaceProducer> surface_producer_;
|
||||
};
|
||||
|
||||
TEST_F(EngineTest, SkpWarmup) {
|
||||
@ -100,6 +109,8 @@ TEST_F(EngineTest, SkpWarmup) {
|
||||
PersistentCache::GetCacheForProcess()->SetAssetManager(asset_manager);
|
||||
|
||||
WarmupSkps();
|
||||
concurrent_task_runner_.Run();
|
||||
raster_task_runner_.Run();
|
||||
|
||||
EXPECT_EQ(concurrent_task_runner_.GetTaskCount(), 1);
|
||||
EXPECT_EQ(raster_task_runner_.GetTaskCount(), 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user