• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_QUEUE_H_
16 #define DAWNNATIVE_QUEUE_H_
17 
18 #include "common/SerialQueue.h"
19 #include "dawn_native/Error.h"
20 #include "dawn_native/Forward.h"
21 #include "dawn_native/IntegerTypes.h"
22 #include "dawn_native/ObjectBase.h"
23 
24 #include "dawn_native/dawn_platform.h"
25 
26 namespace dawn_native {
27 
28     class QueueBase : public ApiObjectBase {
29       public:
30         struct TaskInFlight {
31             virtual ~TaskInFlight();
32             virtual void Finish() = 0;
33             virtual void HandleDeviceLoss() = 0;
34         };
35 
36         ~QueueBase() override;
37 
38         static QueueBase* MakeError(DeviceBase* device);
39 
40         ObjectType GetType() const override;
41 
42         // Dawn API
43         void APISubmit(uint32_t commandCount, CommandBufferBase* const* commands);
44         void APIOnSubmittedWorkDone(uint64_t signalValue,
45                                     WGPUQueueWorkDoneCallback callback,
46                                     void* userdata);
47         void APIWriteBuffer(BufferBase* buffer,
48                             uint64_t bufferOffset,
49                             const void* data,
50                             size_t size);
51         void APIWriteTexture(const ImageCopyTexture* destination,
52                              const void* data,
53                              size_t dataSize,
54                              const TextureDataLayout* dataLayout,
55                              const Extent3D* writeSize);
56         void APICopyTextureForBrowser(const ImageCopyTexture* source,
57                                       const ImageCopyTexture* destination,
58                                       const Extent3D* copySize,
59                                       const CopyTextureForBrowserOptions* options);
60 
61         MaybeError WriteBuffer(BufferBase* buffer,
62                                uint64_t bufferOffset,
63                                const void* data,
64                                size_t size);
65         void TrackTask(std::unique_ptr<TaskInFlight> task, ExecutionSerial serial);
66         void Tick(ExecutionSerial finishedSerial);
67         void HandleDeviceLoss();
68 
69       protected:
70         QueueBase(DeviceBase* device);
71         QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag);
72         void DestroyImpl() override;
73 
74       private:
75         MaybeError WriteTextureInternal(const ImageCopyTexture* destination,
76                                         const void* data,
77                                         size_t dataSize,
78                                         const TextureDataLayout& dataLayout,
79                                         const Extent3D* writeSize);
80         MaybeError CopyTextureForBrowserInternal(const ImageCopyTexture* source,
81                                                  const ImageCopyTexture* destination,
82                                                  const Extent3D* copySize,
83                                                  const CopyTextureForBrowserOptions* options);
84 
85         virtual MaybeError SubmitImpl(uint32_t commandCount,
86                                       CommandBufferBase* const* commands) = 0;
87         virtual MaybeError WriteBufferImpl(BufferBase* buffer,
88                                            uint64_t bufferOffset,
89                                            const void* data,
90                                            size_t size);
91         virtual MaybeError WriteTextureImpl(const ImageCopyTexture& destination,
92                                             const void* data,
93                                             const TextureDataLayout& dataLayout,
94                                             const Extent3D& writeSize);
95 
96         MaybeError ValidateSubmit(uint32_t commandCount, CommandBufferBase* const* commands) const;
97         MaybeError ValidateOnSubmittedWorkDone(uint64_t signalValue,
98                                                WGPUQueueWorkDoneStatus* status) const;
99         MaybeError ValidateWriteTexture(const ImageCopyTexture* destination,
100                                         size_t dataSize,
101                                         const TextureDataLayout& dataLayout,
102                                         const Extent3D* writeSize) const;
103 
104         void SubmitInternal(uint32_t commandCount, CommandBufferBase* const* commands);
105 
106         SerialQueue<ExecutionSerial, std::unique_ptr<TaskInFlight>> mTasksInFlight;
107     };
108 
109 }  // namespace dawn_native
110 
111 #endif  // DAWNNATIVE_QUEUE_H_
112