• 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_ADAPTER_H_
16 #define DAWNNATIVE_ADAPTER_H_
17 
18 #include "dawn_native/DawnNative.h"
19 
20 #include "dawn_native/Error.h"
21 #include "dawn_native/Features.h"
22 #include "dawn_native/Limits.h"
23 #include "dawn_native/dawn_platform.h"
24 
25 #include <string>
26 
27 namespace dawn_native {
28 
29     class DeviceBase;
30 
31     class AdapterBase {
32       public:
33         AdapterBase(InstanceBase* instance, wgpu::BackendType backend);
34         virtual ~AdapterBase() = default;
35 
36         MaybeError Initialize();
37 
38         wgpu::BackendType GetBackendType() const;
39         wgpu::AdapterType GetAdapterType() const;
40         const std::string& GetDriverDescription() const;
41         const PCIInfo& GetPCIInfo() const;
42         InstanceBase* GetInstance() const;
43 
44         DeviceBase* CreateDevice(const DawnDeviceDescriptor* descriptor = nullptr);
45 
46         void RequestDevice(const DawnDeviceDescriptor* descriptor,
47                            WGPURequestDeviceCallback callback,
48                            void* userdata);
49 
50         void ResetInternalDeviceForTesting();
51 
52         FeaturesSet GetSupportedFeatures() const;
53         bool SupportsAllRequestedFeatures(const std::vector<const char*>& requestedFeatures) const;
54         WGPUDeviceProperties GetAdapterProperties() const;
55 
56         bool GetLimits(SupportedLimits* limits) const;
57 
58         void SetUseTieredLimits(bool useTieredLimits);
59 
60         virtual bool SupportsExternalImages() const = 0;
61 
62       protected:
63         PCIInfo mPCIInfo = {};
64         wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown;
65         std::string mDriverDescription;
66         FeaturesSet mSupportedFeatures;
67 
68       private:
69         virtual ResultOrError<DeviceBase*> CreateDeviceImpl(
70             const DawnDeviceDescriptor* descriptor) = 0;
71 
72         virtual MaybeError InitializeImpl() = 0;
73 
74         // Check base WebGPU features and discover supported featurees.
75         virtual MaybeError InitializeSupportedFeaturesImpl() = 0;
76 
77         // Check base WebGPU limits and populate supported limits.
78         virtual MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) = 0;
79 
80         MaybeError CreateDeviceInternal(DeviceBase** result,
81                                         const DawnDeviceDescriptor* descriptor);
82 
83         virtual MaybeError ResetInternalDeviceForTestingImpl();
84         InstanceBase* mInstance = nullptr;
85         wgpu::BackendType mBackend;
86         CombinedLimits mLimits;
87         bool mUseTieredLimits = false;
88     };
89 
90 }  // namespace dawn_native
91 
92 #endif  // DAWNNATIVE_ADAPTER_H_
93