• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_FENCE_H_
16 #define DAWNNATIVE_FENCE_H_
17 
18 #include "common/SerialMap.h"
19 #include "dawn_native/Error.h"
20 #include "dawn_native/Forward.h"
21 #include "dawn_native/ObjectBase.h"
22 
23 #include "dawn_native/dawn_platform.h"
24 
25 #include <map>
26 
27 namespace dawn_native {
28 
29     MaybeError ValidateFenceDescriptor(const FenceDescriptor* descriptor);
30 
31     class FenceBase : public ObjectBase {
32       public:
33         FenceBase(QueueBase* queue, const FenceDescriptor* descriptor);
34         ~FenceBase();
35 
36         static FenceBase* MakeError(DeviceBase* device);
37 
38         uint64_t GetSignaledValue() const;
39         const QueueBase* GetQueue() const;
40 
41         // Dawn API
42         uint64_t GetCompletedValue() const;
43         void OnCompletion(uint64_t value, dawn::FenceOnCompletionCallback callback, void* userdata);
44 
45       protected:
46         friend class QueueBase;
47         friend class FenceSignalTracker;
48         void SetSignaledValue(uint64_t signalValue);
49         void SetCompletedValue(uint64_t completedValue);
50 
51       private:
52         FenceBase(DeviceBase* device, ObjectBase::ErrorTag tag);
53 
54         MaybeError ValidateOnCompletion(uint64_t value) const;
55 
56         struct OnCompletionData {
57             dawn::FenceOnCompletionCallback completionCallback = nullptr;
58             void* userdata = nullptr;
59         };
60 
61         uint64_t mSignalValue;
62         uint64_t mCompletedValue;
63         Ref<QueueBase> mQueue;
64         SerialMap<OnCompletionData> mRequests;
65     };
66 
67 }  // namespace dawn_native
68 
69 #endif  // DAWNNATIVE_FENCE_H_
70