react-native-webgpu 0.23.0 → 0.25.0

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 (127) hide show
  1. package/Package.swift +18 -129
  2. package/android/CMakeLists.txt +1 -0
  3. package/android/cpp/AndroidPlatformContext.h +10 -9
  4. package/android/cpp/cpp-adapter.cpp +19 -96
  5. package/android/src/main/java/com/webgpu/BackingViewKind.java +5 -22
  6. package/android/src/main/java/com/webgpu/WebGPUAPI.java +0 -2
  7. package/android/src/main/java/com/webgpu/WebGPUModule.java +34 -3
  8. package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +1 -1
  9. package/android/src/main/java/com/webgpu/WebGPUView.java +17 -34
  10. package/apple/ApplePlatformContext.h +2 -1
  11. package/apple/ApplePlatformContext.mm +2 -2
  12. package/apple/WebGPUModule.mm +22 -0
  13. package/binaries.json +53 -105
  14. package/cpp/dawn/common/ExternalTextureParams.h +3 -3
  15. package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
  16. package/cpp/dawn/include/dawn/dawn_proc_table.h +329 -0
  17. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
  18. package/cpp/dawn/include/dawn/dawn_version.h +51 -0
  19. package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
  20. package/cpp/dawn/include/dawn/native/D3D12Backend.h +104 -0
  21. package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
  22. package/cpp/dawn/include/dawn/native/DawnNative.h +375 -0
  23. package/cpp/dawn/include/dawn/native/MetalBackend.h +67 -0
  24. package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
  25. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
  26. package/cpp/dawn/include/dawn/native/VulkanBackend.h +199 -0
  27. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
  28. package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
  29. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +210 -0
  30. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
  31. package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
  32. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
  33. package/cpp/dawn/include/dawn/webgpu.h +5119 -0
  34. package/cpp/dawn/include/dawn/webgpu_cpp.h +10506 -0
  35. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2897 -0
  36. package/cpp/dawn/include/webgpu/webgpu.h +33 -0
  37. package/cpp/dawn/include/webgpu/webgpu_cpp.h +33 -0
  38. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
  39. package/cpp/dawn/include/webgpu/webgpu_cpp_print.h +33 -0
  40. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +163 -0
  41. package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
  42. package/cpp/rnwgpu/GpuPurge.cpp +86 -0
  43. package/cpp/rnwgpu/GpuPurge.h +66 -0
  44. package/cpp/rnwgpu/PlatformContext.h +1 -1
  45. package/cpp/rnwgpu/SurfaceRegistry.h +2 -612
  46. package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
  47. package/cpp/rnwgpu/api/GPUDevice.cpp +59 -32
  48. package/cpp/rnwgpu/api/GPUDevice.h +49 -4
  49. package/cpp/rnwgpu/api/RNWebGPU.h +11 -4
  50. package/lib/commonjs/Canvas.js +8 -26
  51. package/lib/commonjs/Canvas.js.map +1 -1
  52. package/lib/commonjs/main/index.js +12 -0
  53. package/lib/commonjs/main/index.js.map +1 -1
  54. package/lib/commonjs/main/index.web.js +11 -0
  55. package/lib/commonjs/main/index.web.js.map +1 -1
  56. package/lib/commonjs/mock.js +4 -1
  57. package/lib/commonjs/mock.js.map +1 -1
  58. package/lib/commonjs/purgeGpuResources.js +29 -0
  59. package/lib/commonjs/purgeGpuResources.js.map +1 -0
  60. package/lib/commonjs/video.js +8 -4
  61. package/lib/commonjs/video.js.map +1 -1
  62. package/lib/module/Canvas.js +8 -26
  63. package/lib/module/Canvas.js.map +1 -1
  64. package/lib/module/main/index.js +1 -0
  65. package/lib/module/main/index.js.map +1 -1
  66. package/lib/module/main/index.web.js +1 -0
  67. package/lib/module/main/index.web.js.map +1 -1
  68. package/lib/module/mock.js +1 -0
  69. package/lib/module/mock.js.map +1 -1
  70. package/lib/module/purgeGpuResources.js +22 -0
  71. package/lib/module/purgeGpuResources.js.map +1 -0
  72. package/lib/module/video.js +6 -2
  73. package/lib/module/video.js.map +1 -1
  74. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  75. package/lib/typescript/lib/commonjs/mock.d.ts +1 -0
  76. package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
  77. package/lib/typescript/lib/commonjs/purgeGpuResources.d.ts +18 -0
  78. package/lib/typescript/lib/commonjs/purgeGpuResources.d.ts.map +1 -0
  79. package/lib/typescript/lib/commonjs/video.d.ts +6 -2
  80. package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
  81. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  82. package/lib/typescript/lib/module/main/index.d.ts +1 -0
  83. package/lib/typescript/lib/module/main/index.web.d.ts +1 -0
  84. package/lib/typescript/lib/module/mock.d.ts +1 -0
  85. package/lib/typescript/lib/module/mock.d.ts.map +1 -1
  86. package/lib/typescript/lib/module/purgeGpuResources.d.ts +2 -0
  87. package/lib/typescript/lib/module/purgeGpuResources.d.ts.map +1 -0
  88. package/lib/typescript/lib/module/video.d.ts +1 -1
  89. package/lib/typescript/lib/module/video.d.ts.map +1 -1
  90. package/lib/typescript/react-native.config.d.ts +1 -0
  91. package/lib/typescript/src/Canvas.d.ts +2 -12
  92. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  93. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +1 -1
  94. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  95. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +1 -1
  96. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  97. package/lib/typescript/src/index.d.ts +3 -2
  98. package/lib/typescript/src/index.d.ts.map +1 -1
  99. package/lib/typescript/src/main/index.d.ts +1 -0
  100. package/lib/typescript/src/main/index.d.ts.map +1 -1
  101. package/lib/typescript/src/main/index.web.d.ts +1 -0
  102. package/lib/typescript/src/main/index.web.d.ts.map +1 -1
  103. package/lib/typescript/src/mock.d.ts +2 -1
  104. package/lib/typescript/src/mock.d.ts.map +1 -1
  105. package/lib/typescript/src/purgeGpuResources.d.ts +17 -0
  106. package/lib/typescript/src/purgeGpuResources.d.ts.map +1 -0
  107. package/lib/typescript/src/types.d.ts +1 -1
  108. package/lib/typescript/src/types.d.ts.map +1 -1
  109. package/lib/typescript/src/video.d.ts +7 -3
  110. package/lib/typescript/src/video.d.ts.map +1 -1
  111. package/package.json +10 -5
  112. package/react-native-webgpu.podspec +46 -78
  113. package/react-native.config.js +9 -6
  114. package/scripts/apple-binaries-utils.sh +280 -0
  115. package/scripts/prepare-apple-binaries.sh +309 -0
  116. package/scripts/spm-plugin.js +130 -0
  117. package/src/Canvas.tsx +12 -50
  118. package/src/WebGPUViewNativeComponent.ts +1 -1
  119. package/src/WebGPUViewNativeComponent.web.ts +1 -1
  120. package/src/index.tsx +5 -4
  121. package/src/main/index.tsx +1 -0
  122. package/src/main/index.web.tsx +1 -0
  123. package/src/mock.ts +2 -1
  124. package/src/purgeGpuResources.ts +21 -0
  125. package/src/types.ts +1 -1
  126. package/src/video.ts +12 -5
  127. package/android/src/main/java/com/webgpu/WebGPUHardwareBufferView.java +0 -278
@@ -0,0 +1,33 @@
1
+ // Copyright 2022 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_WEBGPU_WEBGPU_H_
29
+ #define INCLUDE_WEBGPU_WEBGPU_H_
30
+
31
+ #include "dawn/webgpu.h"
32
+
33
+ #endif // INCLUDE_WEBGPU_WEBGPU_H_
@@ -0,0 +1,33 @@
1
+ // Copyright 2022 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_WEBGPU_WEBGPU_CPP_H_
29
+ #define INCLUDE_WEBGPU_WEBGPU_CPP_H_
30
+
31
+ #include "dawn/webgpu_cpp.h"
32
+
33
+ #endif // INCLUDE_WEBGPU_WEBGPU_CPP_H_
@@ -0,0 +1,57 @@
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
+ #ifdef __EMSCRIPTEN__
29
+ #error "Do not include this header. Use the headers provided by Emdawnwebgpu instead."
30
+ #endif
31
+
32
+ #ifndef WEBGPU_CPP_CHAINED_STRUCT_H_
33
+ #define WEBGPU_CPP_CHAINED_STRUCT_H_
34
+
35
+ #include <cstddef>
36
+ #include <cstdint>
37
+
38
+ // This header file declares the ChainedStruct structures separately from the WebGPU
39
+ // headers so that dependencies can directly extend structures without including the larger header
40
+ // which exposes capabilities that may require correctly set proc tables.
41
+ namespace wgpu {
42
+
43
+ enum class SType : uint32_t;
44
+
45
+ struct ChainedStruct {
46
+ ChainedStruct const * nextInChain = nullptr;
47
+ SType sType = SType(0u);
48
+ };
49
+
50
+ struct ChainedStructOut {
51
+ ChainedStructOut * nextInChain = nullptr;
52
+ SType sType = SType(0u);
53
+ };
54
+
55
+ } // namespace wgpu}
56
+
57
+ #endif // WEBGPU_CPP_CHAINED_STRUCT_H_
@@ -0,0 +1,33 @@
1
+ // Copyright 2025 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_WEBGPU_WEBGPU_CPP_PRINT_H_
29
+ #define INCLUDE_WEBGPU_WEBGPU_CPP_PRINT_H_
30
+
31
+ #include "dawn/webgpu_cpp_print.h"
32
+
33
+ #endif // INCLUDE_WEBGPU_WEBGPU_CPP_PRINT_H_
@@ -0,0 +1,163 @@
1
+ // Copyright 2017 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 WEBGPU_ENUM_CLASS_BITMASKS_H_
29
+ #define WEBGPU_ENUM_CLASS_BITMASKS_H_
30
+
31
+ #include <type_traits>
32
+
33
+ // The operators in wgpu:: namespace need be introduced into other namespaces with
34
+ // using-declarations for C++ Argument Dependent Lookup to work.
35
+ #define WGPU_IMPORT_BITMASK_OPERATORS \
36
+ using wgpu::operator|; \
37
+ using wgpu::operator&; \
38
+ using wgpu::operator^; \
39
+ using wgpu::operator~; \
40
+ using wgpu::operator&=; \
41
+ using wgpu::operator|=; \
42
+ using wgpu::operator^=; \
43
+ using wgpu::HasZeroOrOneBits;
44
+
45
+ namespace wgpu {
46
+
47
+ template <typename T>
48
+ struct IsWGPUBitmask {
49
+ static constexpr bool enable = false;
50
+ };
51
+
52
+ template <typename T, typename Enable = void>
53
+ struct LowerBitmask {
54
+ static constexpr bool enable = false;
55
+ };
56
+
57
+ template <typename T>
58
+ struct LowerBitmask<T, typename std::enable_if<IsWGPUBitmask<T>::enable>::type> {
59
+ static constexpr bool enable = true;
60
+ using type = T;
61
+ constexpr static T Lower(T t) { return t; }
62
+ };
63
+
64
+ template <typename T>
65
+ struct BoolConvertible {
66
+ using Integral = typename std::underlying_type<T>::type;
67
+
68
+ explicit constexpr BoolConvertible(Integral value) : value(value) {}
69
+ // NOLINTNEXTLINE(google-explicit-constructor)
70
+ constexpr operator bool() const { return value != 0; }
71
+ // NOLINTNEXTLINE(google-explicit-constructor)
72
+ constexpr operator T() const { return static_cast<T>(value); }
73
+
74
+ Integral value;
75
+ };
76
+
77
+ template <typename T>
78
+ struct LowerBitmask<BoolConvertible<T>> {
79
+ static constexpr bool enable = true;
80
+ using type = T;
81
+ static constexpr type Lower(BoolConvertible<T> t) { return t; }
82
+ };
83
+
84
+ template <
85
+ typename T1,
86
+ typename T2,
87
+ typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
88
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
89
+ using T = typename LowerBitmask<T1>::type;
90
+ using Integral = typename std::underlying_type<T>::type;
91
+ return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) |
92
+ static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
93
+ }
94
+
95
+ template <
96
+ typename T1,
97
+ typename T2,
98
+ typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
99
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
100
+ using T = typename LowerBitmask<T1>::type;
101
+ using Integral = typename std::underlying_type<T>::type;
102
+ return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) &
103
+ static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
104
+ }
105
+
106
+ template <
107
+ typename T1,
108
+ typename T2,
109
+ typename = typename std::enable_if<LowerBitmask<T1>::enable && LowerBitmask<T2>::enable>::type>
110
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
111
+ using T = typename LowerBitmask<T1>::type;
112
+ using Integral = typename std::underlying_type<T>::type;
113
+ return BoolConvertible<T>(static_cast<Integral>(LowerBitmask<T1>::Lower(left)) ^
114
+ static_cast<Integral>(LowerBitmask<T2>::Lower(right)));
115
+ }
116
+
117
+ template <typename T1>
118
+ constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
119
+ using T = typename LowerBitmask<T1>::type;
120
+ using Integral = typename std::underlying_type<T>::type;
121
+ return BoolConvertible<T>(
122
+ static_cast<Integral>(~static_cast<Integral>(LowerBitmask<T1>::Lower(t))));
123
+ }
124
+
125
+ template <
126
+ typename T,
127
+ typename T2,
128
+ typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
129
+ constexpr T& operator&=(T& l, T2 right) {
130
+ T r = LowerBitmask<T2>::Lower(right);
131
+ l = l & r;
132
+ return l;
133
+ }
134
+
135
+ template <
136
+ typename T,
137
+ typename T2,
138
+ typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
139
+ constexpr T& operator|=(T& l, T2 right) {
140
+ T r = LowerBitmask<T2>::Lower(right);
141
+ l = l | r;
142
+ return l;
143
+ }
144
+
145
+ template <
146
+ typename T,
147
+ typename T2,
148
+ typename = typename std::enable_if<IsWGPUBitmask<T>::enable && LowerBitmask<T2>::enable>::type>
149
+ constexpr T& operator^=(T& l, T2 right) {
150
+ T r = LowerBitmask<T2>::Lower(right);
151
+ l = l ^ r;
152
+ return l;
153
+ }
154
+
155
+ template <typename T>
156
+ constexpr bool HasZeroOrOneBits(T value) {
157
+ using Integral = typename std::underlying_type<T>::type;
158
+ return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
159
+ }
160
+
161
+ } // namespace wgpu
162
+
163
+ #endif // WEBGPU_ENUM_CLASS_BITMASKS_H_
@@ -0,0 +1,88 @@
1
+ // Copyright 2022 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_WEBGPU_WEBGPU_GLFW_H_
29
+ #define INCLUDE_WEBGPU_WEBGPU_GLFW_H_
30
+
31
+ #ifdef __cplusplus
32
+ #include <memory>
33
+
34
+ #include "webgpu/webgpu_cpp.h"
35
+ #else
36
+ #include "webgpu/webgpu.h"
37
+ #endif
38
+
39
+ #if defined(WGPU_GLFW_SHARED_LIBRARY)
40
+ #if defined(_WIN32)
41
+ #if defined(WGPU_GLFW_IMPLEMENTATION)
42
+ #define WGPU_GLFW_EXPORT __declspec(dllexport)
43
+ #else
44
+ #define WGPU_GLFW_EXPORT __declspec(dllimport)
45
+ #endif
46
+ #else // defined(_WIN32)
47
+ #if defined(WGPU_GLFW_IMPLEMENTATION)
48
+ #define WGPU_GLFW_EXPORT __attribute__((visibility("default")))
49
+ #else
50
+ #define WGPU_GLFW_EXPORT
51
+ #endif
52
+ #endif // defined(_WIN32)
53
+ #else // defined(WGPU_GLFW_SHARED_LIBRARY)
54
+ #define WGPU_GLFW_EXPORT
55
+ #endif // defined(WGPU_GLFW_SHARED_LIBRARY)
56
+
57
+ struct GLFWwindow;
58
+
59
+ #ifdef __cplusplus
60
+ extern "C" {
61
+ #endif
62
+
63
+ WGPU_GLFW_EXPORT WGPUSurface wgpuGlfwCreateSurfaceForWindow(const WGPUInstance instance,
64
+ struct GLFWwindow* window);
65
+
66
+ #ifdef __cplusplus
67
+ }
68
+
69
+ namespace wgpu::glfw {
70
+
71
+ // Does the necessary setup on the GLFWwindow to allow creating a wgpu::Surface with it and
72
+ // calls `instance.CreateSurface` with the correct descriptor for this window.
73
+ // Returns a null wgpu::Surface on failure.
74
+ WGPU_GLFW_EXPORT wgpu::Surface CreateSurfaceForWindow(const wgpu::Instance& instance,
75
+ GLFWwindow* window);
76
+
77
+ // Use for testing only. Does everything that CreateSurfaceForWindow does except the call to
78
+ // CreateSurface. Useful to be able to modify the descriptor for testing, or when trying to
79
+ // avoid using the global proc table.
80
+ // NOLINTNEXTLINE(build/include_what_you_use)
81
+ WGPU_GLFW_EXPORT std::unique_ptr<wgpu::ChainedStruct, void (*)(wgpu::ChainedStruct*)>
82
+ SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window);
83
+
84
+ } // namespace wgpu::glfw
85
+
86
+ #endif
87
+
88
+ #endif // INCLUDE_WEBGPU_WEBGPU_GLFW_H_
@@ -0,0 +1,86 @@
1
+ #include "GpuPurge.h"
2
+
3
+ #include <mutex>
4
+ #include <system_error>
5
+ #include <thread>
6
+
7
+ #include "GPUDevice.h"
8
+
9
+ namespace rnwgpu {
10
+
11
+ namespace {
12
+
13
+ struct State {
14
+ std::mutex mutex;
15
+ // Whether the purge thread is alive.
16
+ bool running = false;
17
+ // Whether a request came in since the thread last started a run.
18
+ bool requested = false;
19
+ };
20
+
21
+ // Never destroyed: the purge thread may still use it while the process exits.
22
+ State &getState() noexcept {
23
+ static auto *state = new State();
24
+ return *state;
25
+ }
26
+
27
+ } // namespace
28
+
29
+ void GpuPurge::request() noexcept {
30
+ auto &state = getState();
31
+ {
32
+ std::lock_guard<std::mutex> lock(state.mutex);
33
+ state.requested = true;
34
+ if (state.running) {
35
+ return;
36
+ }
37
+ state.running = true;
38
+ }
39
+ try {
40
+ std::thread([] { runRequests(); }).detach();
41
+ } catch (const std::system_error &) {
42
+ // No thread to be had: nothing is purged.
43
+ std::lock_guard<std::mutex> lock(state.mutex);
44
+ state.running = false;
45
+ }
46
+ }
47
+
48
+ void GpuPurge::onMemoryWarning() noexcept { request(); }
49
+
50
+ void GpuPurge::onLowMemory() noexcept { request(); }
51
+
52
+ void GpuPurge::onTrimMemory(int level) noexcept {
53
+ if (level >= kTrimMemoryUiHidden) {
54
+ request();
55
+ }
56
+ }
57
+
58
+ void GpuPurge::runRequests() noexcept {
59
+ auto &state = getState();
60
+ for (;;) {
61
+ {
62
+ std::lock_guard<std::mutex> lock(state.mutex);
63
+ if (!state.requested) {
64
+ state.running = false;
65
+ return;
66
+ }
67
+ state.requested = false;
68
+ }
69
+ run();
70
+ }
71
+ }
72
+
73
+ void GpuPurge::run() {
74
+ for (int pass = 0; pass < kMaxPasses; pass++) {
75
+ bool pending = GPUDevice::reduceMemoryUsage();
76
+ if (pass < kRuntimeThreadPasses) {
77
+ pending |= GPUDevice::reduceMemoryUsageOnRuntimeThreads();
78
+ }
79
+ if (!pending) {
80
+ return;
81
+ }
82
+ std::this_thread::sleep_for(kPassInterval);
83
+ }
84
+ }
85
+
86
+ } // namespace rnwgpu
@@ -0,0 +1,66 @@
1
+ #pragma once
2
+
3
+ #include <chrono>
4
+
5
+ namespace rnwgpu {
6
+
7
+ // purgeGpuResources(), which the system also brings about when it is short of
8
+ // memory and, on Android, when the app goes to the background: Dawn gives the
9
+ // GPU memory it keeps for reuse (the memory of destroyed textures and buffers,
10
+ // staging memory) back to the system, for every live device (see
11
+ // GPUDevice::reduceMemoryUsage). Nothing alive is affected.
12
+ //
13
+ // The platform modules only report what the system said (onMemoryWarning,
14
+ // onLowMemory, onTrimMemory): whether it calls for a purge is decided here.
15
+ //
16
+ // request() returns at once. The work runs on a thread of its own, started by
17
+ // a request and gone once done; a request made while it runs is served by one
18
+ // more run of the same thread, however many came in.
19
+ class GpuPurge {
20
+ public:
21
+ // purgeGpuResources() from JS. Any thread.
22
+ static void request() noexcept;
23
+
24
+ // iOS, UIApplicationDidReceiveMemoryWarningNotification: the system is short
25
+ // of memory, and ends the apps that hold the most of it first. Any thread.
26
+ static void onMemoryWarning() noexcept;
27
+
28
+ // Android, ComponentCallbacks.onLowMemory(): the whole system is short of
29
+ // memory. Any thread.
30
+ static void onLowMemory() noexcept;
31
+
32
+ // Android, ComponentCallbacks2.onTrimMemory(): purges from
33
+ // kTrimMemoryUiHidden, which is each time the app goes to the background.
34
+ // Any thread.
35
+ static void onTrimMemory(int level) noexcept;
36
+
37
+ private:
38
+ // One run asks Dawn again for as long as it says deletions wait for
39
+ // submitted work to complete, this many times at most and this far apart:
40
+ // about a second in all.
41
+ static constexpr int kMaxPasses = 10;
42
+ static constexpr std::chrono::milliseconds kPassInterval{100};
43
+
44
+ // The passes of a run that also ask the devices only the thread of their
45
+ // runtime may use (see GPUDevice::reduceMemoryUsageOnRuntimeThreads). What
46
+ // Dawn answers there is not waited for, hence a fixed number: the first lets
47
+ // the pending deletions go through, the next free what they leave.
48
+ static constexpr int kRuntimeThreadPasses = 3;
49
+
50
+ // ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN: the app is no longer visible. It
51
+ // renders nothing there, and the system ends the processes in the background
52
+ // that hold the most memory first. The system sends it each time the app
53
+ // leaves the foreground, and it may be all it sends: TRIM_MEMORY_BACKGROUND
54
+ // did not come to an app left in the background until it was cached and
55
+ // frozen (a Samsung on Android 17). The levels below this one are for an app
56
+ // in the foreground, and are no longer sent since Android 14.
57
+ static constexpr int kTrimMemoryUiHidden = 20;
58
+
59
+ // The purge thread: runs until no request is left.
60
+ static void runRequests() noexcept;
61
+
62
+ // One run: the passes over the live devices.
63
+ static void run();
64
+ };
65
+
66
+ } // namespace rnwgpu
@@ -246,7 +246,7 @@ public:
246
246
  // for a regular sampled GPUTexture; NV12 is the right shape for the
247
247
  // importExternalTexture path (zero-copy biplanar YUV).
248
248
  virtual std::unique_ptr<IVideoPlayer>
249
- createVideoPlayer(const std::string &path, VideoPixelFormat format) = 0;
249
+ createTestVideoPlayer(const std::string &path, VideoPixelFormat format) = 0;
250
250
 
251
251
  // Wrap a CVPixelBufferRef (Apple) or AHardwareBuffer* (Android) pointer
252
252
  // obtained from another library (typically VisionCamera's