Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: gpu/ipc/service/gpu_scheduler.h

Issue 2440093003: WIP GPU scheduler + delayed activation / tile draw
Patch Set: SignalSyncToken -> IsFenceSyncReleased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/ipc/service/gpu_command_stream.h ('k') | gpu/ipc/service/gpu_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GPU_IPC_SERVICE_GPU_SCHEDULER_H_
6 #define GPU_IPC_SERVICE_GPU_SCHEDULER_H_
7
8 #include <deque>
9 #include <set>
10 #include <vector>
11
12 #include "base/cancelable_callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "base/threading/thread_checker.h"
17 #include "base/time/time.h"
18 #include "gpu/command_buffer/common/preemption_flag.h"
19 #include "gpu/gpu_export.h"
20 #include "gpu/ipc/common/gpu_stream_constants.h"
21
22 namespace base {
23 class SingleThreadTaskRunner;
24 }
25
26 namespace gpu {
27
28 class GpuCommandStream;
29
30 struct GPU_EXPORT GpuSchedulerSettings {
31 base::TimeDelta min_time_slice;
32 base::TimeDelta max_time_slice;
33 };
34
35 class GPU_EXPORT GpuScheduler {
36 public:
37 // Create with default settings.
38 static std::unique_ptr<GpuScheduler> Create(
39 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
40
41 GpuScheduler(const GpuSchedulerSettings& settings,
42 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
43
44 virtual ~GpuScheduler();
45
46 void AddStream(GpuCommandStream* stream, GpuStreamPriority priority);
47 void RemoveStream(GpuCommandStream* stream);
48
49 // Returns true if current stream should yield. Called on the main thread.
50 bool ShouldYield();
51
52 // Called when stream becomes ready.
53 void ScheduleStream(GpuCommandStream* stream);
54
55 // Called when a stream stops being ready.
56 void DescheduleStream(GpuCommandStream* stream);
57
58 protected:
59 virtual base::TimeTicks Now(); // for testing
60
61 private:
62 struct StreamInfo {
63 GpuCommandStream* stream = nullptr;
64 GpuStreamPriority priority = GpuStreamPriority::LAST;
65 bool ready = false;
66 };
67
68 struct ScheduledStream {
69 GpuCommandStream* stream = nullptr;
70 GpuStreamPriority priority = GpuStreamPriority::LAST;
71
72 bool operator<(const ScheduledStream& other) const {
73 return std::tie(priority, stream) >
74 std::tie(other.priority, other.stream);
75 }
76 };
77
78 std::vector<StreamInfo>::iterator FindStream(GpuCommandStream* stream);
79 std::vector<ScheduledStream>::iterator FindScheduledStream(
80 GpuCommandStream* stream);
81
82 void BuildWorkQueue();
83 ScheduledStream GetNextStream();
84 void RunNextStream();
85
86 const GpuSchedulerSettings settings_;
87 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
88
89 // The following are protected by |lock_|.
90 bool running_ = false;
91 // If we need to reschedule
92 bool needs_rescheduling_ = false;
93 // List of streams and associated information.
94 std::vector<StreamInfo> streams_;
95 // Priority queue of streams that are scheduled to run.
96 std::vector<ScheduledStream> work_queue_;
97 // Protects the above variables.
98 base::Lock lock_;
99
100 // Time when current stream started running.
101 base::TimeTicks running_stream_start_time_;
102
103 // Used to ensure that methods (except ScheduleStream) are called on the main
104 // thread.
105 base::ThreadChecker thread_checker_;
106
107 base::WeakPtrFactory<GpuScheduler> weak_factory_;
108
109 DISALLOW_COPY_AND_ASSIGN(GpuScheduler);
110 };
111
112 } // namespace gpu
113
114 #endif // GPU_IPC_SERVICE_GPU_SCHEDULER_H_
OLDNEW
« no previous file with comments | « gpu/ipc/service/gpu_command_stream.h ('k') | gpu/ipc/service/gpu_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698