• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef skgpu_graphite_QueueManager_DEFINED
9 #define skgpu_graphite_QueueManager_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/graphite/GraphiteTypes.h"
13 #include "include/private/base/SkDeque.h"
14 #include "include/private/base/SkTArray.h"
15 #include "src/core/SkTHash.h"
16 
17 #include <memory>
18 #include <vector>
19 
20 namespace skgpu::graphite {
21 
22 class Buffer;
23 class CommandBuffer;
24 class Context;
25 class GpuWorkSubmission;
26 struct InsertRecordingInfo;
27 class ResourceProvider;
28 class SharedContext;
29 class Task;
30 class UploadBufferManager;
31 
32 class QueueManager {
33 public:
34     virtual ~QueueManager();
35 
36     // Adds the commands from the passed in Recording to the current CommandBuffer
37     [[nodiscard]] bool addRecording(const InsertRecordingInfo&, Context*);
38 
39     // Adds the commands from the passed in Task to the current CommandBuffer
40     [[nodiscard]] bool addTask(Task*, Context*);
41 
42     // Adds a proc that will be called when the current CommandBuffer is submitted and finishes
43     [[nodiscard]] bool addFinishInfo(const InsertFinishInfo&,
44                                      ResourceProvider*,
45                                      SkSpan<const sk_sp<Buffer>> buffersToAsyncMap = {});
46 
47     [[nodiscard]] bool submitToGpu();
48     [[nodiscard]] bool hasUnfinishedGpuWork();
49     void checkForFinishedWork(SyncToCpu);
50 
51 #if defined(GRAPHITE_TEST_UTILS)
startCapture()52     virtual void startCapture() {}
stopCapture()53     virtual void stopCapture() {}
54 #endif
55 
56     void returnCommandBuffer(std::unique_ptr<CommandBuffer>);
57 
tick()58     virtual void tick() const {}
59 
60     void addUploadBufferManagerRefs(UploadBufferManager*);
61 
62 protected:
63     QueueManager(const SharedContext* sharedContext);
64 
65     using OutstandingSubmission = std::unique_ptr<GpuWorkSubmission>;
66 
67     const SharedContext* fSharedContext;
68     std::unique_ptr<CommandBuffer> fCurrentCommandBuffer;
69 
70 private:
71     virtual std::unique_ptr<CommandBuffer> getNewCommandBuffer(ResourceProvider*) = 0;
72     virtual OutstandingSubmission onSubmitToGpu() = 0;
73 
74     bool setupCommandBuffer(ResourceProvider*);
75 
76     SkDeque fOutstandingSubmissions;
77 
78     std::vector<std::unique_ptr<CommandBuffer>> fAvailableCommandBuffers;
79 
80     skia_private::THashMap<uint32_t, uint32_t> fLastAddedRecordingIDs;
81 };
82 
83 } // namespace skgpu::graphite
84 
85 #endif // skgpu_graphite_QueueManager_DEFINED
86