react-native-wgpu 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +9 -63
  2. package/android/CMakeLists.txt +15 -1
  3. package/android/build.gradle +1 -1
  4. package/android/cpp/AndroidPlatformContext.h +1 -1
  5. package/apple/ApplePlatformContext.mm +11 -3
  6. package/apple/MetalView.h +2 -2
  7. package/apple/MetalView.mm +12 -0
  8. package/apple/RNWGUIKit.h +11 -0
  9. package/apple/WebGPUModule.mm +3 -12
  10. package/apple/WebGPUViewManager.mm +3 -2
  11. package/cpp/dawn/dawn_proc.h +50 -0
  12. package/cpp/dawn/dawn_proc_table.h +300 -0
  13. package/cpp/dawn/dawn_thread_dispatch_proc.h +47 -0
  14. package/cpp/dawn/native/D3D11Backend.h +64 -0
  15. package/cpp/dawn/native/D3D12Backend.h +68 -0
  16. package/cpp/dawn/native/D3DBackend.h +59 -0
  17. package/cpp/dawn/native/DawnNative.h +313 -0
  18. package/cpp/dawn/native/MetalBackend.h +55 -0
  19. package/cpp/dawn/native/NullBackend.h +39 -0
  20. package/cpp/dawn/native/OpenGLBackend.h +82 -0
  21. package/cpp/dawn/native/VulkanBackend.h +183 -0
  22. package/cpp/dawn/native/dawn_native_export.h +49 -0
  23. package/cpp/dawn/platform/DawnPlatform.h +165 -0
  24. package/cpp/dawn/platform/dawn_platform_export.h +49 -0
  25. package/cpp/dawn/webgpu_cpp_print.h +2484 -0
  26. package/cpp/rnwgpu/api/GPU.h +1 -1
  27. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +4 -0
  28. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -16
  29. package/cpp/webgpu/webgpu_glfw.h +71 -0
  30. package/lib/commonjs/NativeWebGPUModule.js.map +1 -1
  31. package/lib/module/NativeWebGPUModule.js.map +1 -1
  32. package/lib/typescript/src/NativeWebGPUModule.d.ts +0 -1
  33. package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -1
  34. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  35. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  36. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  37. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  38. package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  39. package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  40. package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
  41. package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  42. package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
  43. package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +10 -10
  44. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  45. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  46. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
  47. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
  48. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
  49. package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
  50. package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  51. package/package.json +1 -1
  52. package/react-native-wgpu.podspec +1 -1
  53. package/src/NativeWebGPUModule.ts +0 -1
  54. package/cpp/rnwgpu/api/WebGPUCanvasContextFactory.h +0 -59
@@ -0,0 +1,47 @@
1
+ // Copyright 2020 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_DAWN_THREAD_DISPATCH_PROC_H_
29
+ #define INCLUDE_DAWN_DAWN_THREAD_DISPATCH_PROC_H_
30
+
31
+ #include "dawn/dawn_proc.h"
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ // Call dawnProcSetProcs(&dawnThreadDispatchProcTable) and then use dawnProcSetPerThreadProcs
38
+ // to set per-thread procs.
39
+ WGPU_EXPORT extern DawnProcTable dawnThreadDispatchProcTable;
40
+ WGPU_EXPORT void dawnProcSetDefaultThreadProcs(const DawnProcTable* procs);
41
+ WGPU_EXPORT void dawnProcSetPerThreadProcs(const DawnProcTable* procs);
42
+
43
+ #ifdef __cplusplus
44
+ } // extern "C"
45
+ #endif
46
+
47
+ #endif // INCLUDE_DAWN_DAWN_THREAD_DISPATCH_PROC_H_
@@ -0,0 +1,64 @@
1
+ // Copyright 2023 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_NATIVE_D3D11BACKEND_H_
29
+ #define INCLUDE_DAWN_NATIVE_D3D11BACKEND_H_
30
+
31
+ #include <d3d11_1.h>
32
+ #include <wrl/client.h>
33
+
34
+ #include <memory>
35
+
36
+ #include "dawn/native/D3DBackend.h"
37
+
38
+ namespace dawn::native::d3d11 {
39
+
40
+ DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D11Device> GetD3D11Device(WGPUDevice device);
41
+
42
+ // May be chained on RequestAdapterOptions
43
+ struct DAWN_NATIVE_EXPORT RequestAdapterOptionsD3D11Device : wgpu::ChainedStruct {
44
+ RequestAdapterOptionsD3D11Device() {
45
+ sType = static_cast<wgpu::SType>(WGPUSType_RequestAdapterOptionsD3D11Device);
46
+ }
47
+
48
+ Microsoft::WRL::ComPtr<ID3D11Device> device;
49
+ };
50
+
51
+ // May be chained on SharedTextureMemoryDescriptor
52
+ struct DAWN_NATIVE_EXPORT SharedTextureMemoryD3D11Texture2DDescriptor : wgpu::ChainedStruct {
53
+ SharedTextureMemoryD3D11Texture2DDescriptor() {
54
+ sType = static_cast<wgpu::SType>(WGPUSType_SharedTextureMemoryD3D11Texture2DDescriptor);
55
+ }
56
+
57
+ // This ID3D11Texture2D object must be created from the same ID3D11Device used in the
58
+ // WGPUDevice.
59
+ Microsoft::WRL::ComPtr<ID3D11Texture2D> texture;
60
+ };
61
+
62
+ } // namespace dawn::native::d3d11
63
+
64
+ #endif // INCLUDE_DAWN_NATIVE_D3D11BACKEND_H_
@@ -0,0 +1,68 @@
1
+ // Copyright 2018 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
29
+ #define INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
30
+
31
+ #include <d3d12.h>
32
+ #include <dxgi1_4.h>
33
+ #include <wrl/client.h>
34
+
35
+ #include "dawn/native/D3DBackend.h"
36
+
37
+ struct ID3D12Device;
38
+ struct ID3D12Resource;
39
+
40
+ namespace dawn::native::d3d12 {
41
+
42
+ class Device;
43
+
44
+ enum MemorySegment {
45
+ Local,
46
+ NonLocal,
47
+ };
48
+
49
+ DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device);
50
+
51
+ DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
52
+ uint64_t requestedReservationSize,
53
+ MemorySegment memorySegment);
54
+
55
+ // May be chained on SharedBufferMemoryDescriptor
56
+ struct DAWN_NATIVE_EXPORT SharedBufferMemoryD3D12ResourceDescriptor : wgpu::ChainedStruct {
57
+ SharedBufferMemoryD3D12ResourceDescriptor() {
58
+ sType = static_cast<wgpu::SType>(WGPUSType_SharedBufferMemoryD3D12ResourceDescriptor);
59
+ }
60
+
61
+ // This ID3D12Resource object must be created from the same ID3D12Device used in the
62
+ // WGPUDevice.
63
+ Microsoft::WRL::ComPtr<ID3D12Resource> resource;
64
+ };
65
+
66
+ } // namespace dawn::native::d3d12
67
+
68
+ #endif // INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
@@ -0,0 +1,59 @@
1
+ // Copyright 2023 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
29
+ #define INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
30
+
31
+ #include <dxgi1_4.h>
32
+ #include <webgpu/webgpu_cpp_chained_struct.h>
33
+ #include <windows.h>
34
+ #include <wrl/client.h>
35
+
36
+ #include <memory>
37
+ #include <vector>
38
+
39
+ #include "dawn/native/DawnNative.h"
40
+
41
+ namespace dawn::native::d3d {
42
+
43
+ class ExternalImageDXGIImpl;
44
+
45
+ DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter);
46
+
47
+ // Can be chained in WGPURequestAdapterOptions
48
+ struct DAWN_NATIVE_EXPORT RequestAdapterOptionsLUID : wgpu::ChainedStruct {
49
+ RequestAdapterOptionsLUID();
50
+
51
+ ::LUID adapterLUID;
52
+ };
53
+
54
+ // Chrome uses 0 as acquire key.
55
+ static constexpr uint64_t kDXGIKeyedMutexAcquireKey = 0;
56
+
57
+ } // namespace dawn::native::d3d
58
+
59
+ #endif // INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
@@ -0,0 +1,313 @@
1
+ // Copyright 2018 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_NATIVE_DAWNNATIVE_H_
29
+ #define INCLUDE_DAWN_NATIVE_DAWNNATIVE_H_
30
+
31
+ #include <webgpu/webgpu_cpp.h>
32
+
33
+ #include <string>
34
+ #include <string_view>
35
+ #include <vector>
36
+
37
+ #include "dawn/dawn_proc_table.h"
38
+ #include "dawn/native/dawn_native_export.h"
39
+
40
+ namespace dawn::platform {
41
+ class Platform;
42
+ } // namespace dawn::platform
43
+
44
+ namespace dawn::native {
45
+
46
+ class InstanceBase;
47
+ class AdapterBase;
48
+
49
+ // Each toggle is assigned with a TogglesStage, indicating the validation and earliest usage
50
+ // time of the toggle.
51
+ enum class ToggleStage { Instance, Adapter, Device };
52
+
53
+ // A struct to record the information of a toggle. A toggle is a code path in Dawn device that
54
+ // can be manually configured to run or not outside Dawn, including workarounds, special
55
+ // features and optimizations.
56
+ struct ToggleInfo {
57
+ const char* name;
58
+ const char* description;
59
+ const char* url;
60
+ ToggleStage stage;
61
+ };
62
+
63
+ // A struct to record the information of a feature. A feature is a GPU feature that is not
64
+ // required to be supported by all Dawn backends and can only be used when it is enabled on the
65
+ // creation of device.
66
+ struct FeatureInfo {
67
+ const char* name;
68
+ const char* description;
69
+ const char* url;
70
+ // The enum of feature state, could be stable or experimental. Using an experimental feature
71
+ // requires the AllowUnsafeAPIs toggle to be enabled.
72
+ enum class FeatureState { Stable = 0, Experimental };
73
+ FeatureState featureState;
74
+ };
75
+
76
+ // An adapter is an object that represent on possibility of creating devices in the system.
77
+ // Most of the time it will represent a combination of a physical GPU and an API. Not that the
78
+ // same GPU can be represented by multiple adapters but on different APIs.
79
+ //
80
+ // The underlying Dawn adapter is owned by the Dawn instance so this class is not RAII but just
81
+ // a reference to an underlying adapter.
82
+ class DAWN_NATIVE_EXPORT Adapter {
83
+ public:
84
+ Adapter();
85
+ // NOLINTNEXTLINE(runtime/explicit)
86
+ Adapter(AdapterBase* impl);
87
+ ~Adapter();
88
+
89
+ Adapter(const Adapter& other);
90
+ Adapter& operator=(const Adapter& other);
91
+
92
+ // TODO(crbug.com/347047627): These methods are historical duplicates of
93
+ // those in webgpu_cpp.h. Update uses of these methods and remove them.
94
+ wgpu::Status GetInfo(wgpu::AdapterInfo* info) const;
95
+ wgpu::Status GetInfo(WGPUAdapterInfo* info) const;
96
+ std::vector<const char*> GetSupportedFeatures() const;
97
+ wgpu::ConvertibleStatus GetLimits(WGPUSupportedLimits* limits) const;
98
+
99
+ void SetUseTieredLimits(bool useTieredLimits);
100
+
101
+ // Check that the Adapter is able to support importing external images. This is necessary
102
+ // to implement the swapchain and interop APIs in Chromium.
103
+ bool SupportsExternalImages() const;
104
+
105
+ explicit operator bool() const;
106
+
107
+ // Create a device on this adapter. On an error, nullptr is returned.
108
+ WGPUDevice CreateDevice(const wgpu::DeviceDescriptor* deviceDescriptor);
109
+ WGPUDevice CreateDevice(const WGPUDeviceDescriptor* deviceDescriptor = nullptr);
110
+
111
+ void RequestDevice(const wgpu::DeviceDescriptor* descriptor,
112
+ WGPURequestDeviceCallback callback,
113
+ void* userdata);
114
+ void RequestDevice(const WGPUDeviceDescriptor* descriptor,
115
+ WGPURequestDeviceCallback callback,
116
+ void* userdata);
117
+ void RequestDevice(std::nullptr_t descriptor,
118
+ WGPURequestDeviceCallback callback,
119
+ void* userdata) {
120
+ RequestDevice(static_cast<const wgpu::DeviceDescriptor*>(descriptor), callback, userdata);
121
+ }
122
+
123
+ // Returns the underlying WGPUAdapter object.
124
+ WGPUAdapter Get() const;
125
+
126
+ // Reset the backend device object for testing purposes.
127
+ void ResetInternalDeviceForTesting();
128
+
129
+ private:
130
+ AdapterBase* mImpl = nullptr;
131
+ };
132
+
133
+ enum BackendValidationLevel { Full, Partial, Disabled };
134
+
135
+ // Can be chained in InstanceDescriptor
136
+ struct DAWN_NATIVE_EXPORT DawnInstanceDescriptor : wgpu::ChainedStruct {
137
+ DawnInstanceDescriptor();
138
+ uint32_t additionalRuntimeSearchPathsCount = 0;
139
+ const char* const* additionalRuntimeSearchPaths;
140
+ dawn::platform::Platform* platform = nullptr;
141
+
142
+ BackendValidationLevel backendValidationLevel = BackendValidationLevel::Disabled;
143
+ bool beginCaptureOnStartup = false;
144
+
145
+ WGPULoggingCallback loggingCallback = nullptr;
146
+ void* loggingCallbackUserdata = nullptr;
147
+
148
+ // Equality operators, mostly for testing. Note that this tests
149
+ // strict pointer-pointer equality if the struct contains member pointers.
150
+ bool operator==(const DawnInstanceDescriptor& rhs) const;
151
+ };
152
+
153
+ // Represents a connection to dawn_native and is used for dependency injection, discovering
154
+ // system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter).
155
+ //
156
+ // This is an RAII class for Dawn instances and also controls the lifetime of all adapters
157
+ // for this instance.
158
+ class DAWN_NATIVE_EXPORT Instance {
159
+ public:
160
+ explicit Instance(const WGPUInstanceDescriptor* desc = nullptr);
161
+ explicit Instance(InstanceBase* impl);
162
+ ~Instance();
163
+
164
+ Instance(const Instance& other) = delete;
165
+ Instance& operator=(const Instance& other) = delete;
166
+
167
+ // Discovers and returns a vector of adapters.
168
+ // All systems adapters that can be found are returned if no options are passed.
169
+ // Otherwise, returns adapters based on the `options`. Adapter toggles descriptor can chained
170
+ // after options.
171
+ std::vector<Adapter> EnumerateAdapters(const WGPURequestAdapterOptions* options) const;
172
+ std::vector<Adapter> EnumerateAdapters(
173
+ const wgpu::RequestAdapterOptions* options = nullptr) const;
174
+
175
+ const ToggleInfo* GetToggleInfo(const char* toggleName);
176
+
177
+ // Enables backend validation layers
178
+ void SetBackendValidationLevel(BackendValidationLevel validationLevel);
179
+
180
+ uint64_t GetDeviceCountForTesting() const;
181
+ // Backdoor to get the number of deprecation warnings for testing
182
+ uint64_t GetDeprecationWarningCountForTesting() const;
183
+
184
+ // Returns the underlying WGPUInstance object.
185
+ WGPUInstance Get() const;
186
+
187
+ // Make mImpl->mPlatform point to an object inside Dawn in case it becomes a dangling pointer
188
+ void DisconnectDawnPlatform();
189
+
190
+ private:
191
+ InstanceBase* mImpl = nullptr;
192
+ };
193
+
194
+ // Backend-agnostic API for dawn_native
195
+ DAWN_NATIVE_EXPORT const DawnProcTable& GetProcs();
196
+
197
+ // Query the names of all the toggles that are enabled in device
198
+ DAWN_NATIVE_EXPORT std::vector<const char*> GetTogglesUsed(WGPUDevice device);
199
+
200
+ // Backdoor to get the number of lazy clears for testing
201
+ DAWN_NATIVE_EXPORT size_t GetLazyClearCountForTesting(WGPUDevice device);
202
+
203
+ // Query if texture has been initialized
204
+ DAWN_NATIVE_EXPORT bool IsTextureSubresourceInitialized(
205
+ WGPUTexture texture,
206
+ uint32_t baseMipLevel,
207
+ uint32_t levelCount,
208
+ uint32_t baseArrayLayer,
209
+ uint32_t layerCount,
210
+ WGPUTextureAspect aspect = WGPUTextureAspect_All);
211
+
212
+ // Backdoor to get the order of the ProcMap for testing
213
+ DAWN_NATIVE_EXPORT std::vector<std::string_view> GetProcMapNamesForTesting();
214
+
215
+ DAWN_NATIVE_EXPORT bool DeviceTick(WGPUDevice device);
216
+
217
+ DAWN_NATIVE_EXPORT bool InstanceProcessEvents(WGPUInstance instance);
218
+
219
+ // ErrorInjector functions used for testing only. Defined in dawn_native/ErrorInjector.cpp
220
+ DAWN_NATIVE_EXPORT void EnableErrorInjector();
221
+ DAWN_NATIVE_EXPORT void DisableErrorInjector();
222
+ DAWN_NATIVE_EXPORT void ClearErrorInjector();
223
+ DAWN_NATIVE_EXPORT uint64_t AcquireErrorInjectorCallCount();
224
+ DAWN_NATIVE_EXPORT void InjectErrorAt(uint64_t index);
225
+
226
+ // The different types of external images
227
+ enum ExternalImageType {
228
+ OpaqueFD,
229
+ DmaBuf,
230
+ IOSurface,
231
+ EGLImage,
232
+ GLTexture,
233
+ AHardwareBuffer,
234
+ Last = AHardwareBuffer,
235
+ };
236
+
237
+ // Common properties of external images
238
+ struct DAWN_NATIVE_EXPORT ExternalImageDescriptor {
239
+ public:
240
+ const WGPUTextureDescriptor* cTextureDescriptor; // Must match image creation params
241
+ bool isInitialized; // Whether the texture is initialized on import
242
+ ExternalImageType GetType() const;
243
+
244
+ protected:
245
+ explicit ExternalImageDescriptor(ExternalImageType type);
246
+
247
+ private:
248
+ ExternalImageType mType;
249
+ };
250
+
251
+ struct DAWN_NATIVE_EXPORT ExternalImageExportInfo {
252
+ public:
253
+ bool isInitialized = false; // Whether the texture is initialized after export
254
+ ExternalImageType GetType() const;
255
+
256
+ protected:
257
+ explicit ExternalImageExportInfo(ExternalImageType type);
258
+
259
+ private:
260
+ ExternalImageType mType;
261
+ };
262
+
263
+ DAWN_NATIVE_EXPORT bool CheckIsErrorForTesting(void* objectHandle);
264
+
265
+ DAWN_NATIVE_EXPORT const char* GetObjectLabelForTesting(void* objectHandle);
266
+
267
+ DAWN_NATIVE_EXPORT uint64_t GetAllocatedSizeForTesting(WGPUBuffer buffer);
268
+
269
+ DAWN_NATIVE_EXPORT std::vector<const ToggleInfo*> AllToggleInfos();
270
+
271
+ // Used to query the details of an feature. Return nullptr if featureName is not a valid
272
+ // name of an feature supported in Dawn.
273
+ DAWN_NATIVE_EXPORT const FeatureInfo* GetFeatureInfo(wgpu::FeatureName feature);
274
+
275
+ class DAWN_NATIVE_EXPORT MemoryDump {
276
+ public:
277
+ // Standard attribute |name|s for the AddScalar() and AddString() methods.
278
+ // These match the expected names in Chromium memory-infra instrumentation.
279
+ static const char kNameSize[]; // To represent allocated space.
280
+ static const char kNameObjectCount[]; // To represent number of objects.
281
+
282
+ // Standard attribute |unit|s for the AddScalar() and AddString() methods.
283
+ // These match the expected names in Chromium memory-infra instrumentation.
284
+ static const char kUnitsBytes[]; // Unit name to represent bytes.
285
+ static const char kUnitsObjects[]; // Unit name to represent #objects.
286
+
287
+ MemoryDump() = default;
288
+
289
+ virtual void AddScalar(const char* name,
290
+ const char* key,
291
+ const char* units,
292
+ uint64_t value) = 0;
293
+
294
+ virtual void AddString(const char* name, const char* key, const std::string& value) = 0;
295
+
296
+ MemoryDump(const MemoryDump&) = delete;
297
+ MemoryDump& operator=(const MemoryDump&) = delete;
298
+
299
+ protected:
300
+ virtual ~MemoryDump() = default;
301
+ };
302
+ DAWN_NATIVE_EXPORT void DumpMemoryStatistics(WGPUDevice device, MemoryDump* dump);
303
+
304
+ // Unlike memory dumps which include detailed information about allocations, this only returns the
305
+ // total estimated memory usage, and is intended for background tracing for UMA.
306
+ DAWN_NATIVE_EXPORT uint64_t ComputeEstimatedMemoryUsage(WGPUDevice device);
307
+
308
+ // Free any unused GPU memory like staging buffers, cached resources, etc.
309
+ DAWN_NATIVE_EXPORT void ReduceMemoryUsage(WGPUDevice device);
310
+
311
+ } // namespace dawn::native
312
+
313
+ #endif // INCLUDE_DAWN_NATIVE_DAWNNATIVE_H_
@@ -0,0 +1,55 @@
1
+ // Copyright 2018 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_NATIVE_METALBACKEND_H_
29
+ #define INCLUDE_DAWN_NATIVE_METALBACKEND_H_
30
+
31
+ #include <webgpu/webgpu.h>
32
+
33
+ #include "dawn/native/dawn_native_export.h"
34
+
35
+ #if defined(__OBJC__)
36
+ #import <Metal/Metal.h>
37
+ #endif
38
+
39
+ namespace dawn::native::metal {
40
+
41
+ // When making Metal interop with other APIs, we need to be careful that QueueSubmit doesn't
42
+ // mean that the operations will be visible to other APIs/Metal devices right away. macOS
43
+ // does have a global queue of graphics operations, but the command buffers are inserted there
44
+ // when they are "scheduled". Submitting other operations before the command buffer is
45
+ // scheduled could lead to races in who gets scheduled first and incorrect rendering.
46
+ DAWN_NATIVE_EXPORT void WaitForCommandsToBeScheduled(WGPUDevice device);
47
+
48
+ #if defined(__OBJC__)
49
+ // Return the MTLDevice corresponding to the WGPUDevice.
50
+ DAWN_NATIVE_EXPORT id<MTLDevice> GetMTLDevice(WGPUDevice device);
51
+ #endif
52
+
53
+ } // namespace dawn::native::metal
54
+
55
+ #endif // INCLUDE_DAWN_NATIVE_METALBACKEND_H_
@@ -0,0 +1,39 @@
1
+ // Copyright 2018 The Dawn & Tint Authors
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are met:
5
+ //
6
+ // 1. Redistributions of source code must retain the above copyright notice, this
7
+ // list of conditions and the following disclaimer.
8
+ //
9
+ // 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ // this list of conditions and the following disclaimer in the documentation
11
+ // and/or other materials provided with the distribution.
12
+ //
13
+ // 3. Neither the name of the copyright holder nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef INCLUDE_DAWN_NATIVE_NULLBACKEND_H_
29
+ #define INCLUDE_DAWN_NATIVE_NULLBACKEND_H_
30
+
31
+ #include "dawn/native/DawnNative.h"
32
+
33
+ namespace dawn::native::null {
34
+
35
+ // Nothing for now \o/
36
+
37
+ } // namespace dawn::native::null
38
+
39
+ #endif // INCLUDE_DAWN_NATIVE_NULLBACKEND_H_