This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Allow jumpstarts to pipeline readiness. #54355
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "impeller/base/job_queue.h" | ||
|
|
||
| #include "flutter/fml/trace_event.h" | ||
| #include "impeller/base/validation.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| JobQueue::JobQueue(std::shared_ptr<fml::ConcurrentTaskRunner> task_runner) | ||
| : task_runner_(std::move(task_runner)) {} | ||
|
|
||
| JobQueue::~JobQueue() = default; | ||
|
|
||
| std::shared_ptr<JobQueue> JobQueue::Make( | ||
| std::shared_ptr<fml::ConcurrentTaskRunner> task_runner) { | ||
| return std::shared_ptr<JobQueue>(new JobQueue(std::move(task_runner))); | ||
| } | ||
|
|
||
| UniqueID JobQueue::AddJob(fml::closure job) { | ||
| auto id = UniqueID{}; | ||
| { | ||
| Lock lock(jobs_mutex_); | ||
| jobs_[id] = job; | ||
| } | ||
| ScheduleAndRunJob(id); | ||
| return id; | ||
| } | ||
|
|
||
| void JobQueue::ScheduleAndRunJob(UniqueID id) { | ||
| task_runner_->PostTask([weak = weak_from_this(), id]() { | ||
| if (auto thiz = weak.lock()) { | ||
| thiz->RunJobNow(id); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| void JobQueue::PrioritizeJob(UniqueID id) { | ||
| Lock lock(jobs_mutex_); | ||
| high_priority_job_ids_.push_back(id); | ||
| } | ||
|
|
||
| void JobQueue::RunJobNow(UniqueID id) { | ||
| while (RunHighPriorityJob()) { | ||
| } | ||
| fml::closure job; | ||
| { | ||
| Lock lock(jobs_mutex_); | ||
| job = TakeJob(id); | ||
| } | ||
| if (job) { | ||
| TRACE_EVENT0("impeller", "RegularJob"); | ||
| job(); | ||
| } | ||
| } | ||
|
|
||
| bool JobQueue::RunHighPriorityJob() { | ||
| fml::closure job; | ||
| { | ||
| Lock lock(jobs_mutex_); | ||
| if (high_priority_job_ids_.empty()) { | ||
| return false; | ||
| } | ||
| auto job_id = high_priority_job_ids_.front(); | ||
| high_priority_job_ids_.pop_front(); | ||
| job = TakeJob(job_id); | ||
| } | ||
| if (job) { | ||
| TRACE_EVENT0("impeller", "HighPriorityJob"); | ||
| job(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| void JobQueue::DoJobNow(UniqueID id) { | ||
| fml::closure job; | ||
| { | ||
| Lock lock(jobs_mutex_); | ||
| job = TakeJob(id); | ||
| } | ||
| if (job) { | ||
| TRACE_EVENT0("impeller", "EagerJob"); | ||
| job(); | ||
| } | ||
| } | ||
|
|
||
| fml::closure JobQueue::TakeJob(UniqueID id) { | ||
| auto found = jobs_.find(id); | ||
| if (found == jobs_.end()) { | ||
| return nullptr; | ||
| } | ||
| auto job = found->second; | ||
| jobs_.erase(found); | ||
| return job; | ||
| } | ||
|
|
||
| const std::shared_ptr<fml::ConcurrentTaskRunner>& JobQueue::GetTaskRunner() | ||
| const { | ||
| return task_runner_; | ||
| } | ||
|
|
||
| } // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_IMPELLER_BASE_JOB_QUEUE_H_ | ||
| #define FLUTTER_IMPELLER_BASE_JOB_QUEUE_H_ | ||
|
|
||
| #include <deque> | ||
| #include <map> | ||
| #include <memory> | ||
|
|
||
| #include "flutter/fml/closure.h" | ||
| #include "flutter/fml/concurrent_message_loop.h" | ||
| #include "impeller/base/comparable.h" | ||
| #include "impeller/base/thread.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| /// @brief Manages a queue of jobs that execute on a concurrent task | ||
| /// runner. Jobs execute as soon as resources are available. Callers | ||
| /// have the ability to re-prioritize jobs or perform jobs eagerly | ||
| /// on their own threads if needed. | ||
| /// | ||
| /// The job queue and all its methods are thread-safe. | ||
| /// | ||
| class JobQueue final : public std::enable_shared_from_this<JobQueue> { | ||
| public: | ||
| //---------------------------------------------------------------------------- | ||
| /// @brief Creates a job queue which schedules tasks on the given | ||
| /// concurrent task runner. | ||
| /// | ||
| /// @param[in] task_runner The task runner | ||
| /// | ||
| /// @return A job queue if one can be created. | ||
| /// | ||
| static std::shared_ptr<JobQueue> Make( | ||
| std::shared_ptr<fml::ConcurrentTaskRunner> task_runner); | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Destroys the job queue. | ||
| /// | ||
| ~JobQueue(); | ||
|
|
||
| JobQueue(const JobQueue&) = delete; | ||
|
|
||
| JobQueue& operator=(const JobQueue&) = delete; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Adds a job to the job queue and schedules it for execution at | ||
| /// a later point in time. The job ID obtained may be used to | ||
| /// re-prioritize the job within the queue at a later point. | ||
| /// | ||
| /// @param[in] job The job | ||
| /// | ||
| /// @return The unique id for the job. | ||
| /// | ||
| UniqueID AddJob(fml::closure job); | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Prioritize a previously added job for immediate execution on | ||
| /// the concurrent task runner. | ||
| /// | ||
| /// @param[in] id The job identifier. | ||
| /// | ||
| void PrioritizeJob(UniqueID id); | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief If the job has not already been completed, executes the job | ||
| /// immediately on the callers thread. | ||
| /// | ||
| /// This is useful if the current thread is going to idle anyway | ||
| /// and wants to participate in performing the job of the | ||
| /// concurrent task runner. | ||
| /// | ||
| /// @param[in] id The job identifier. | ||
| /// | ||
| void DoJobNow(UniqueID id); | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Gets the task runner for the queue. | ||
| /// | ||
| /// @return The task runner. | ||
| /// | ||
| const std::shared_ptr<fml::ConcurrentTaskRunner>& GetTaskRunner() const; | ||
|
|
||
| private: | ||
| std::shared_ptr<fml::ConcurrentTaskRunner> task_runner_; | ||
| Mutex jobs_mutex_; | ||
| std::map<UniqueID, fml::closure> jobs_ IPLR_GUARDED_BY(jobs_mutex_); | ||
| std::deque<UniqueID> high_priority_job_ids_ IPLR_GUARDED_BY(jobs_mutex_); | ||
|
|
||
| JobQueue(std::shared_ptr<fml::ConcurrentTaskRunner> task_runner); | ||
|
|
||
| void ScheduleAndRunJob(UniqueID id); | ||
|
|
||
| void RunJobNow(UniqueID id); | ||
|
|
||
| bool RunHighPriorityJob(); | ||
|
|
||
| [[nodiscard]] | ||
| fml::closure TakeJob(UniqueID id) IPLR_REQUIRES(jobs_mutex_); | ||
| }; | ||
|
|
||
| } // namespace impeller | ||
|
|
||
| #endif // FLUTTER_IMPELLER_BASE_JOB_QUEUE_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be used somewhere? My understanding is that every pipeline would be scheduled to be created, then there is a mechanism to boost the priority when the pipeline is requested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I was going to add this the spot where the glyph atlas pipeline was being setup. Still WIP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every pipeline will be scheduled eventually in the order in which the jobs were added. Jobs can skip to the front of the queue as necessary (this call). Jobs can be performed eagerly on anything too to avoid a context switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to re-prioritize the glyph atlas shader? Can we simply move it to the front of the queue in ContentContext?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think thats what I mean? Just call PrioritizeJob on it immediately after?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger, will re-arrange the pipeline and remove PrioritizeJob. Keep the jobqueue still or pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stall is completely gone (at least in this app) after the rearrange.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we'll need the job queue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think so too. Hopefully. Just checking the gallery and if I can suppress the regression on the mokey, that should be it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing in favor of #54373