Chromium Code Reviews| Index: gpu/command_buffer/service/scheduler.h |
| diff --git a/gpu/command_buffer/service/scheduler.h b/gpu/command_buffer/service/scheduler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..01791d2d062b46e78f90452c09ca66f88581c48d |
| --- /dev/null |
| +++ b/gpu/command_buffer/service/scheduler.h |
| @@ -0,0 +1,134 @@ |
| +// Copyright (c) 2017 The Chromium 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 GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_ |
| +#define GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_ |
| + |
| +#include <map> |
| +#include <queue> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "gpu/command_buffer/common/gpu_stream_constants.h" |
| +#include "gpu/command_buffer/common/sync_token.h" |
| +#include "gpu/command_buffer/service/sequence_id.h" |
| +#include "gpu/gpu_export.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +namespace trace_event { |
| +class ConvertableToTraceFormat; |
| +} |
| +} |
| + |
| +namespace gpu { |
| +class SyncPointManager; |
| + |
| +class GPU_EXPORT Scheduler { |
| + public: |
| + Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + SyncPointManager* sync_point_manager); |
| + |
| + virtual ~Scheduler(); |
| + |
| + // Create a sequence with given priority. Returns an identifier for the |
| + // sequence that can be used with SyncPonintManager for creating sync point |
| + // release clients. Sequences start off as enabled (see |EnableSequence|). |
| + SequenceId CreateSequence(GpuStreamPriority priority); |
| + |
| + // Destroy the sequence and run any scheduled tasks immediately. |
| + void DestroySequence(SequenceId sequence_id); |
| + |
| + // Enables the sequence so that its tasks may be scheduled. |
| + void EnableSequence(SequenceId sequence_id); |
| + |
| + // Disables the sequence. |
| + void DisableSequence(SequenceId sequence_id); |
| + |
| + // Schedules task (closure) to run on the sequence. The task is blocked until |
| + // the sync token fences are released or determined to be invalid. Tasks are |
| + // run in the order in which they are submitted. |
| + void ScheduleTask(SequenceId sequence_id, |
| + base::OnceClosure closure, |
| + const std::vector<SyncToken>& sync_token_fences); |
| + |
| + // Continue running task on the sequence with the closure. This must be called |
| + // while running a previously scheduled task. |
| + void ContinueTask(SequenceId sequence_id, base::OnceClosure closure); |
| + |
| + // If the sequence should yield so that a higher priority sequence may run. |
| + bool ShouldYield(SequenceId sequence_id); |
| + |
| + private: |
| + class Sequence; |
| + |
| + struct SchedulingState { |
| + SequenceId sequence_id; |
| + GpuStreamPriority priority = GpuStreamPriority::LAST; |
| + uint32_t order_num = 0; |
| + |
| + SchedulingState(); |
| + SchedulingState(const SchedulingState& other); |
| + ~SchedulingState(); |
| + |
| + bool operator<(const SchedulingState& other) const { |
| + return std::tie(priority, order_num) > |
| + std::tie(other.priority, other.order_num); |
| + } |
| + |
| + std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() |
| + const; |
| + }; |
| + |
| + using SchedulingQueue = std::priority_queue<SchedulingState>; |
| + |
| + void SyncTokenFenceReleased(const SyncToken& sync_token, |
| + uint32_t order_num, |
| + SequenceId release_sequence_id, |
| + SequenceId waiting_sequence_id); |
| + |
| + void TryScheduleSequence(Sequence* sequence); |
| + |
| + void RebuildSchedulingQueue(); |
| + |
| + Sequence* GetSequence(SequenceId sequence_id); |
| + |
| + void RunNextTask(); |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + |
| + SyncPointManager* const sync_point_manager_; |
| + |
| + // The following are protected by |lock_|. |
| + bool running_ = false; |
| + |
| + std::map<SequenceId, std::unique_ptr<Sequence>> sequences_; |
|
piman
2017/05/10 00:38:50
nit: flat_map may work well here.
sunnyps
2017/05/10 23:15:15
Done.
|
| + |
| + SchedulingQueue scheduling_queue_; |
| + |
| + // If the running sequence should yield so that a higher priority sequence can |
| + // run. |
| + bool should_yield_ = false; |
| + |
| + // If the scheduling queue needs to be rebuild because a sequence changed |
| + // priority. |
| + bool rebuild_scheduling_queue_ = false; |
| + |
| + // Protects the above variables. |
| + mutable base::Lock lock_; |
|
vmiura
2017/05/04 21:27:37
The lock should be declared before the variables i
sunnyps
2017/05/10 23:15:15
Done.
|
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + base::WeakPtrFactory<Scheduler> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| +}; |
| + |
| +} // namespace gpu |
| + |
| +#endif // GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_ |