react-native-wgpu 0.1.0 → 0.1.2

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 (269) hide show
  1. package/README.md +221 -13
  2. package/android/CMakeLists.txt +15 -1
  3. package/android/build.gradle +0 -18
  4. package/android/cpp/AndroidPlatformContext.h +26 -0
  5. package/android/cpp/cpp-adapter.cpp +66 -3
  6. package/android/src/main/java/com/webgpu/WebGPUModule.java +64 -22
  7. package/android/src/main/java/com/webgpu/WebGPUView.java +63 -8
  8. package/android/src/main/java/com/webgpu/WebGPUViewManager.java +5 -6
  9. package/android/src/newarch/{WgpuViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +5 -5
  10. package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +23 -0
  11. package/android/src/oldarch/{WebGPUViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +1 -1
  12. package/cpp/{Logger.h → WGPULogger.h} +13 -6
  13. package/cpp/dawn/webgpu.h +9 -0
  14. package/cpp/dawn/webgpu_cpp.h +95 -43
  15. package/cpp/dawn/webgpu_cpp_print.h +6 -0
  16. package/cpp/dawn/wire/client/webgpu_cpp.h +80 -43
  17. package/cpp/jsi/RNFHybridObject.cpp +1 -1
  18. package/cpp/jsi/RNFHybridObject.h +4 -4
  19. package/cpp/jsi/RNFJSIConverter.h +204 -17
  20. package/cpp/rnwgpu/ArrayBuffer.h +72 -0
  21. package/cpp/rnwgpu/PlatformContext.h +16 -0
  22. package/cpp/rnwgpu/RNWebGPUManager.cpp +14 -9
  23. package/cpp/rnwgpu/RNWebGPUManager.h +12 -1
  24. package/cpp/rnwgpu/SurfaceRegistry.h +36 -0
  25. package/cpp/rnwgpu/api/AsyncRunner.h +30 -0
  26. package/cpp/rnwgpu/api/Canvas.h +55 -0
  27. package/cpp/rnwgpu/api/Convertors.h +765 -0
  28. package/cpp/rnwgpu/api/External.h +12 -0
  29. package/cpp/rnwgpu/api/GPU.cpp +100 -23
  30. package/cpp/rnwgpu/api/GPU.h +24 -6
  31. package/cpp/rnwgpu/api/GPUAdapter.cpp +122 -8
  32. package/cpp/rnwgpu/api/GPUAdapter.h +24 -5
  33. package/cpp/rnwgpu/api/GPUAdapterInfo.h +19 -7
  34. package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
  35. package/cpp/rnwgpu/api/GPUBindGroup.h +11 -4
  36. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +11 -4
  37. package/cpp/rnwgpu/api/GPUBuffer.cpp +82 -7
  38. package/cpp/rnwgpu/api/GPUBuffer.h +43 -7
  39. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +63 -0
  40. package/cpp/rnwgpu/api/GPUCanvasContext.h +51 -8
  41. package/cpp/rnwgpu/api/GPUCommandBuffer.h +11 -4
  42. package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +177 -0
  43. package/cpp/rnwgpu/api/GPUCommandEncoder.h +75 -3
  44. package/cpp/rnwgpu/api/GPUCompilationInfo.h +65 -8
  45. package/cpp/rnwgpu/api/GPUCompilationMessage.h +6 -4
  46. package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +58 -0
  47. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +49 -3
  48. package/cpp/rnwgpu/api/GPUComputePipeline.cpp +11 -0
  49. package/cpp/rnwgpu/api/GPUComputePipeline.h +18 -3
  50. package/cpp/rnwgpu/api/GPUDevice.cpp +330 -3
  51. package/cpp/rnwgpu/api/GPUDevice.h +119 -5
  52. package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +6 -0
  53. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +14 -7
  54. package/cpp/rnwgpu/api/GPUError.h +42 -0
  55. package/cpp/rnwgpu/api/GPUExtent3D.h +69 -0
  56. package/cpp/rnwgpu/api/GPUExternalTexture.h +11 -4
  57. package/cpp/rnwgpu/api/GPUFeatures.h +221 -0
  58. package/cpp/rnwgpu/api/GPUOrigin2D.h +59 -0
  59. package/cpp/rnwgpu/api/GPUOrigin3D.h +66 -0
  60. package/cpp/rnwgpu/api/GPUPipelineLayout.h +11 -4
  61. package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
  62. package/cpp/rnwgpu/api/GPUQuerySet.h +19 -5
  63. package/cpp/rnwgpu/api/GPUQueue.cpp +110 -0
  64. package/cpp/rnwgpu/api/GPUQueue.h +45 -4
  65. package/cpp/rnwgpu/api/GPURenderBundle.h +11 -4
  66. package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +128 -0
  67. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +72 -3
  68. package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +161 -0
  69. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +93 -3
  70. package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
  71. package/cpp/rnwgpu/api/GPURenderPipeline.h +18 -3
  72. package/cpp/rnwgpu/api/GPUSampler.h +11 -4
  73. package/cpp/rnwgpu/api/GPUShaderModule.cpp +39 -0
  74. package/cpp/rnwgpu/api/GPUShaderModule.h +23 -4
  75. package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +133 -0
  76. package/cpp/rnwgpu/api/GPUSupportedLimits.h +128 -4
  77. package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
  78. package/cpp/rnwgpu/api/GPUTexture.h +38 -4
  79. package/cpp/rnwgpu/api/GPUTextureView.h +11 -4
  80. package/cpp/rnwgpu/api/ImageData.h +50 -0
  81. package/cpp/rnwgpu/api/Navigator.h +46 -0
  82. package/cpp/rnwgpu/api/WebGPUCanvasContextFactory.h +59 -0
  83. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +31 -43
  84. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +40 -31
  85. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +24 -32
  86. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +56 -49
  87. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +27 -20
  88. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +23 -31
  89. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +25 -36
  90. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +25 -25
  91. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +26 -46
  92. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +31 -53
  93. package/cpp/rnwgpu/api/descriptors/GPUColor.h +72 -0
  94. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +27 -33
  95. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +51 -0
  96. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +51 -0
  97. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +24 -25
  98. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +25 -42
  99. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +32 -42
  100. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +58 -76
  101. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +38 -30
  102. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +11 -11
  103. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +43 -34
  104. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +39 -46
  105. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +29 -45
  106. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +25 -34
  107. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +32 -36
  108. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +42 -44
  109. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +24 -34
  110. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +24 -32
  111. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +25 -35
  112. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +35 -26
  113. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +29 -35
  114. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +23 -43
  115. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +49 -0
  116. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +51 -0
  117. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +41 -57
  118. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +42 -61
  119. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +54 -66
  120. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +52 -55
  121. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +25 -42
  122. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +60 -56
  123. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +21 -20
  124. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +17 -14
  125. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +63 -63
  126. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +28 -27
  127. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +28 -49
  128. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +32 -23
  129. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +27 -29
  130. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +27 -20
  131. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +49 -76
  132. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +48 -64
  133. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +29 -31
  134. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +23 -44
  135. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +30 -36
  136. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +39 -38
  137. package/cpp/rnwgpu/api/descriptors/Unions.h +57 -2
  138. package/ios/IOSPlatformContext.h +16 -0
  139. package/ios/IOSPlatformContext.mm +18 -0
  140. package/ios/MetalView.h +10 -0
  141. package/ios/MetalView.mm +27 -0
  142. package/ios/SurfaceUtils.h +13 -0
  143. package/ios/SurfaceUtils.mm +24 -0
  144. package/ios/WebGPUModule.h +8 -7
  145. package/ios/WebGPUModule.mm +47 -14
  146. package/ios/WebGPUView.h +6 -3
  147. package/ios/WebGPUView.mm +36 -24
  148. package/ios/WebGPUViewComponentDescriptor.h +61 -0
  149. package/ios/WebGPUViewManager.mm +6 -4
  150. package/lib/commonjs/Canvas.js +49 -0
  151. package/lib/commonjs/Canvas.js.map +1 -0
  152. package/lib/commonjs/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
  153. package/lib/commonjs/{WebGPUNativeModule.js.map → NativeWebGPUModule.js.map} +1 -1
  154. package/lib/commonjs/WebGPUView.js +2 -0
  155. package/lib/commonjs/WebGPUView.js.map +1 -0
  156. package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
  157. package/lib/commonjs/index.js +158 -19
  158. package/lib/commonjs/index.js.map +1 -1
  159. package/lib/module/Canvas.js +42 -0
  160. package/lib/module/Canvas.js.map +1 -0
  161. package/lib/module/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
  162. package/lib/module/NativeWebGPUModule.js.map +1 -0
  163. package/lib/module/WebGPUView.js +2 -0
  164. package/lib/module/WebGPUView.js.map +1 -0
  165. package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
  166. package/lib/module/index.js +144 -6
  167. package/lib/module/index.js.map +1 -1
  168. package/lib/typescript/example/src/Triangle/triangle.d.ts +3 -0
  169. package/lib/typescript/example/src/Triangle/triangle.d.ts.map +1 -0
  170. package/lib/typescript/example/src/Wireframe/Shaders.d.ts +3 -0
  171. package/lib/typescript/example/src/Wireframe/Shaders.d.ts.map +1 -0
  172. package/lib/typescript/example/src/Wireframe/models.d.ts +29 -0
  173. package/lib/typescript/example/src/Wireframe/models.d.ts.map +1 -0
  174. package/lib/typescript/example/src/components/DrawingContext.d.ts +13 -0
  175. package/lib/typescript/example/src/components/DrawingContext.d.ts.map +1 -0
  176. package/lib/typescript/example/src/components/cube.d.ts +7 -0
  177. package/lib/typescript/example/src/components/cube.d.ts.map +1 -0
  178. package/lib/typescript/example/src/components/meshes/sphere.d.ts +12 -0
  179. package/lib/typescript/example/src/components/meshes/sphere.d.ts.map +1 -0
  180. package/lib/typescript/example/src/components/meshes/teapot.d.ts +6 -0
  181. package/lib/typescript/example/src/components/meshes/teapot.d.ts.map +1 -0
  182. package/lib/typescript/example/src/components/meshes/utils.d.ts +10 -0
  183. package/lib/typescript/example/src/components/meshes/utils.d.ts.map +1 -0
  184. package/lib/typescript/jest.config.d.ts +4 -0
  185. package/lib/typescript/lib/commonjs/Canvas.d.ts +4 -0
  186. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -0
  187. package/lib/typescript/lib/commonjs/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
  188. package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts.map +1 -0
  189. package/lib/typescript/lib/commonjs/WebGPUView.d.ts +1 -0
  190. package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +1 -0
  191. package/lib/typescript/lib/commonjs/index.d.ts +0 -2
  192. package/lib/typescript/lib/module/Canvas.d.ts +2 -0
  193. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -0
  194. package/lib/typescript/lib/module/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
  195. package/lib/typescript/lib/module/NativeWebGPUModule.d.ts.map +1 -0
  196. package/lib/typescript/lib/module/WebGPUView.d.ts +1 -0
  197. package/lib/typescript/lib/module/WebGPUView.d.ts.map +1 -0
  198. package/lib/typescript/lib/module/index.d.ts +2 -3
  199. package/lib/typescript/src/Canvas.d.ts +22 -0
  200. package/lib/typescript/src/Canvas.d.ts.map +1 -0
  201. package/lib/typescript/src/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +2 -1
  202. package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -0
  203. package/lib/typescript/src/WebGPUView.d.ts +1 -0
  204. package/lib/typescript/src/WebGPUView.d.ts.map +1 -0
  205. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -1
  206. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  207. package/lib/typescript/src/index.d.ts +2 -7
  208. package/lib/typescript/src/index.d.ts.map +1 -1
  209. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  210. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  211. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  212. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  213. package/libs/dawn.json +4597 -0
  214. package/libs/ios/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  215. package/libs/ios/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  216. package/libs/ios/libwebgpu_dawn.a +0 -0
  217. package/libs/ios/libwebgpu_dawn.xcframework/Info.plist +44 -0
  218. package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  219. package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  220. package/libs/ios/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  221. package/package.json +25 -8
  222. package/{react-native-webgpu.podspec → react-native-wgpu.podspec} +6 -9
  223. package/src/Canvas.tsx +68 -0
  224. package/src/{WebGPUNativeModule.ts → NativeWebGPUModule.ts} +1 -0
  225. package/src/WebGPUView.tsx +0 -0
  226. package/src/WebGPUViewNativeComponent.ts +2 -1
  227. package/src/index.tsx +172 -8
  228. package/android/src/main/AndroidManifestNew.xml +0 -2
  229. package/cpp/rnwgpu/MutableBuffer.h +0 -48
  230. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -33
  231. package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +0 -81
  232. package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +0 -76
  233. package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +0 -91
  234. package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +0 -61
  235. package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +0 -75
  236. package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +0 -71
  237. package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +0 -54
  238. package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +0 -83
  239. package/ios/RNFAppleLogger.mm +0 -22
  240. package/ios/Utils.h +0 -5
  241. package/ios/Utils.m +0 -26
  242. package/lib/module/WebGPUNativeModule.js.map +0 -1
  243. package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +0 -1
  244. package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +0 -1
  245. package/lib/typescript/scripts/build/copy-artifacts.d.ts +0 -2
  246. package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +0 -1
  247. package/lib/typescript/scripts/build/dawn.d.ts +0 -2
  248. package/lib/typescript/scripts/build/dawn.d.ts.map +0 -1
  249. package/lib/typescript/scripts/build/util.d.ts +0 -13
  250. package/lib/typescript/scripts/build/util.d.ts.map +0 -1
  251. package/lib/typescript/scripts/codegen/codegen.d.ts +0 -2
  252. package/lib/typescript/scripts/codegen/codegen.d.ts.map +0 -1
  253. package/lib/typescript/scripts/codegen/model/dawn.d.ts +0 -2
  254. package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +0 -1
  255. package/lib/typescript/scripts/codegen/model/model.d.ts +0 -8
  256. package/lib/typescript/scripts/codegen/model/model.d.ts.map +0 -1
  257. package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +0 -4
  258. package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +0 -1
  259. package/lib/typescript/scripts/codegen/templates/Enum.d.ts +0 -3
  260. package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +0 -1
  261. package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +0 -3
  262. package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +0 -1
  263. package/lib/typescript/scripts/codegen/templates/Unions.d.ts +0 -6
  264. package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +0 -1
  265. package/lib/typescript/scripts/codegen/templates/common.d.ts +0 -9
  266. package/lib/typescript/scripts/codegen/templates/common.d.ts.map +0 -1
  267. package/lib/typescript/scripts/codegen/util.d.ts +0 -2
  268. package/lib/typescript/scripts/codegen/util.d.ts.map +0 -1
  269. package/lib/typescript/src/WebGPUNativeModule.d.ts.map +0 -1
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include "webgpu/webgpu_cpp.h"
4
+
5
+ namespace rnwgpu {
6
+ enum class PredefinedColorSpace : uint32_t {
7
+ DisplayP3 = 0,
8
+ Srgb = 1,
9
+ };
10
+
11
+ enum class PremultiplyAlpha : uint32_t { Default = 0, None = 1, Premultiply };
12
+ } // namespace rnwgpu
@@ -1,32 +1,109 @@
1
1
  #include "GPU.h"
2
+
2
3
  #include <utility>
4
+ #include <vector>
5
+
6
+ #include "Convertors.h"
3
7
 
4
8
  namespace rnwgpu {
5
9
 
6
- std::future<std::shared_ptr<GPUAdapter>>
7
- GPU::requestAdapter(std::shared_ptr<GPURequestAdapterOptions> options) {
8
- return std::async(std::launch::async, [this, options]() {
9
- auto aOptions = options->getInstance();
10
- wgpu::Adapter adapter = nullptr;
11
- _instance.RequestAdapter(
12
- aOptions,
13
- [](WGPURequestAdapterStatus, WGPUAdapter cAdapter, const char *message,
14
- void *userdata) {
15
- if (message != nullptr) {
16
- fprintf(stderr, "%s", message);
17
- return;
18
- }
19
- *static_cast<wgpu::Adapter *>(userdata) =
20
- wgpu::Adapter::Acquire(cAdapter);
21
- },
22
- &adapter);
23
- // TODO: implement returning null jsi value
24
- if (!adapter) {
25
- throw std::runtime_error("Failed to request adapter");
26
- }
10
+ std::future<std::variant<std::nullptr_t, std::shared_ptr<GPUAdapter>>>
11
+ GPU::requestAdapter(
12
+ std::optional<std::shared_ptr<GPURequestAdapterOptions>> options) {
13
+ return std::async(
14
+ std::launch::async,
15
+ [this,
16
+ options]() -> std::variant<std::nullptr_t, std::shared_ptr<GPUAdapter>> {
17
+ wgpu::RequestAdapterOptions aOptions;
18
+ Convertor conv;
19
+ if (!conv(aOptions, options)) {
20
+ throw std::runtime_error("Failed to convert GPUDeviceDescriptor");
21
+ }
22
+ wgpu::Adapter adapter = nullptr;
23
+ _instance.RequestAdapter(
24
+ &aOptions,
25
+ [](WGPURequestAdapterStatus, WGPUAdapter cAdapter,
26
+ const char *message, void *userdata) {
27
+ if (message != nullptr) {
28
+ fprintf(stderr, "%s", message);
29
+ return;
30
+ }
31
+ *static_cast<wgpu::Adapter *>(userdata) =
32
+ wgpu::Adapter::Acquire(cAdapter);
33
+ },
34
+ &adapter);
35
+ if (!adapter) {
36
+ return nullptr;
37
+ }
27
38
 
28
- return std::make_shared<GPUAdapter>(std::move(adapter));
29
- });
39
+ return std::make_shared<GPUAdapter>(std::move(adapter), _async);
40
+ });
41
+ }
42
+
43
+ // Async impl keeping here as a reference
44
+ // std::future<std::shared_ptr<GPUAdapter>>
45
+ // GPU::requestAdapter(std::shared_ptr<GPURequestAdapterOptions> options) {
46
+ // return _async->runAsync([=](wgpu::Instance *instance) {
47
+ // auto aOptions = options->getInstance();
48
+ // wgpu::Adapter adapter = nullptr;
49
+ // auto result = std::make_shared<GPUAdapter>(adapter, _async);
50
+ // wgpu::RequestAdapterCallbackInfo callback;
51
+ // callback.callback = [](WGPURequestAdapterStatus, WGPUAdapter cAdapter,
52
+ // const char *message, void *userdata) {
53
+ // if (message != nullptr) {
54
+ // fprintf(stderr, "%s", message);
55
+ // return;
56
+ // }
57
+ // *static_cast<wgpu::Adapter *>(userdata) =
58
+ // wgpu::Adapter::Acquire(cAdapter);
59
+ // };
60
+ // callback.mode = wgpu::CallbackMode::WaitAnyOnly;
61
+ // callback.userdata = &(result->_instance);
62
+ // auto future = _instance.RequestAdapter(aOptions, callback);
63
+ // instance->WaitAny(future, UINT64_MAX);
64
+ // return result;
65
+ // });
66
+ // }
67
+
68
+ std::unordered_set<std::string> GPU::getWgslLanguageFeatures() {
69
+ auto count = _instance.EnumerateWGSLLanguageFeatures(nullptr);
70
+ std::vector<wgpu::WGSLFeatureName> features(count);
71
+ _instance.EnumerateWGSLLanguageFeatures(features.data());
72
+ std::unordered_set<std::string> result;
73
+ for (auto feature : features) {
74
+ std::string name;
75
+ switch (feature) {
76
+ case wgpu::WGSLFeatureName::ReadonlyAndReadwriteStorageTextures:
77
+ name = "readonly_and_readwrite_storage_textures";
78
+ break;
79
+ case wgpu::WGSLFeatureName::Packed4x8IntegerDotProduct:
80
+ name = "packed_4x8_integer_dot_product";
81
+ break;
82
+ case wgpu::WGSLFeatureName::UnrestrictedPointerParameters:
83
+ name = "unrestricted_pointer_parameters";
84
+ break;
85
+ case wgpu::WGSLFeatureName::PointerCompositeAccess:
86
+ name = "pointer_composite_access";
87
+ break;
88
+ case wgpu::WGSLFeatureName::ChromiumTestingUnimplemented:
89
+ name = "chromium_testing_unimplemented";
90
+ break;
91
+ case wgpu::WGSLFeatureName::ChromiumTestingUnsafeExperimental:
92
+ name = "chromium_testing_unsafe_experimental";
93
+ break;
94
+ case wgpu::WGSLFeatureName::ChromiumTestingExperimental:
95
+ name = "chromium_testing_experimental";
96
+ break;
97
+ case wgpu::WGSLFeatureName::ChromiumTestingShippedWithKillswitch:
98
+ name = "chromium_testing_shipped_with_killswitch";
99
+ break;
100
+ case wgpu::WGSLFeatureName::ChromiumTestingShipped:
101
+ name = "chromium_testing_shipped";
102
+ break;
103
+ }
104
+ result.insert(name);
105
+ }
106
+ return result;
30
107
  }
31
108
 
32
109
  wgpu::TextureFormat GPU::getPreferredCanvasFormat() {
@@ -3,11 +3,14 @@
3
3
  #include <future>
4
4
  #include <memory>
5
5
  #include <string>
6
+ #include <unordered_set>
7
+ #include <variant>
6
8
 
7
9
  #include "Unions.h"
8
- #include <RNFHybridObject.h>
9
10
 
10
- #include "MutableBuffer.h"
11
+ #include "RNFHybridObject.h"
12
+
13
+ #include "AsyncRunner.h"
11
14
 
12
15
  #include "webgpu/webgpu_cpp.h"
13
16
 
@@ -20,24 +23,39 @@ namespace m = margelo;
20
23
 
21
24
  class GPU : public m::HybridObject {
22
25
  public:
23
- explicit GPU(wgpu::Instance instance)
24
- : HybridObject("GPU"), _instance(instance) {}
26
+ GPU() : HybridObject("GPU") {
27
+ wgpu::InstanceDescriptor instanceDesc;
28
+ instanceDesc.features.timedWaitAnyEnable = true;
29
+ instanceDesc.features.timedWaitAnyMaxCount = 64;
30
+ _instance = wgpu::CreateInstance(&instanceDesc);
31
+ auto instance = &_instance;
32
+ _async = std::make_shared<AsyncRunner>(instance);
33
+ }
25
34
 
26
35
  public:
27
36
  std::string getBrand() { return _name; }
28
37
 
29
- std::future<std::shared_ptr<GPUAdapter>>
30
- requestAdapter(std::shared_ptr<GPURequestAdapterOptions> options);
38
+ std::future<std::variant<std::nullptr_t, std::shared_ptr<GPUAdapter>>>
39
+ requestAdapter(
40
+ std::optional<std::shared_ptr<GPURequestAdapterOptions>> options);
31
41
  wgpu::TextureFormat getPreferredCanvasFormat();
32
42
 
43
+ std::unordered_set<std::string> getWgslLanguageFeatures();
44
+
33
45
  void loadHybridMethods() override {
34
46
  registerHybridGetter("__brand", &GPU::getBrand, this);
35
47
  registerHybridMethod("requestAdapter", &GPU::requestAdapter, this);
36
48
  registerHybridMethod("getPreferredCanvasFormat",
37
49
  &GPU::getPreferredCanvasFormat, this);
50
+ registerHybridGetter("wgslLanguageFeatures", &GPU::getWgslLanguageFeatures,
51
+ this);
38
52
  }
39
53
 
54
+ inline const wgpu::Instance get() { return _instance; }
55
+
40
56
  private:
41
57
  wgpu::Instance _instance;
58
+ std::shared_ptr<AsyncRunner> _async;
42
59
  };
60
+
43
61
  } // namespace rnwgpu
@@ -1,17 +1,71 @@
1
- // GPUAdapter.cpp
2
-
3
1
  #include "GPUAdapter.h"
2
+
3
+ #include <string>
4
4
  #include <utility>
5
+ #include <vector>
6
+
7
+ #include "Convertors.h"
8
+
9
+ #include "GPUFeatures.h"
10
+ #include "WGPULogger.h"
5
11
 
6
12
  namespace rnwgpu {
7
13
 
8
- std::future<std::shared_ptr<GPUDevice>>
9
- GPUAdapter::requestDevice(std::shared_ptr<GPUDeviceDescriptor> descriptor) {
10
- return std::async(std::launch::async, [this, descriptor]() {
14
+ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
15
+ std::optional<std::shared_ptr<GPUDeviceDescriptor>> descriptor) {
16
+ return std::async(std::launch::async, [this,
17
+ descriptor = std::move(descriptor)]() {
11
18
  wgpu::Device device = nullptr;
12
- auto aDescriptor = descriptor->getInstance();
19
+ wgpu::DeviceDescriptor aDescriptor;
20
+ Convertor conv;
21
+ if (!conv(aDescriptor, descriptor)) {
22
+ throw std::runtime_error("Failed to convert GPUDeviceDescriptor");
23
+ }
24
+ wgpu::DeviceLostCallbackInfo info = {
25
+ .callback = [](WGPUDevice const *device, WGPUDeviceLostReason reason,
26
+ char const *message, void *userdata) {
27
+ const char *lostReason = "";
28
+ switch (reason) {
29
+ case WGPUDeviceLostReason_Destroyed:
30
+ lostReason = "Destroyed";
31
+ break;
32
+ case WGPUDeviceLostReason_Unknown:
33
+ lostReason = "Unknown";
34
+ break;
35
+ default:
36
+ lostReason = "Unknown";
37
+ }
38
+ Logger::logToConsole("GPU Device Lost (%s): %s", lostReason, message);
39
+ }};
40
+ aDescriptor.deviceLostCallbackInfo = info;
41
+ wgpu::UncapturedErrorCallbackInfo errorInfo;
42
+ errorInfo.userdata = static_cast<void *>(_creationRuntime);
43
+ errorInfo.callback = [](WGPUErrorType type, const char *message,
44
+ void *userdata) {
45
+ auto creationRuntime = static_cast<jsi::Runtime *>(userdata);
46
+ const char *errorType = "";
47
+ switch (type) {
48
+ case WGPUErrorType_Validation:
49
+ errorType = "Validation";
50
+ break;
51
+ case WGPUErrorType_OutOfMemory:
52
+ errorType = "Out of Memory";
53
+ break;
54
+ case WGPUErrorType_Internal:
55
+ errorType = "Internal";
56
+ break;
57
+ case WGPUErrorType_Unknown:
58
+ errorType = "Unknown";
59
+ break;
60
+ default:
61
+ errorType = "Unknown";
62
+ }
63
+ std::string fullMessage = std::string(errorType) + ": " + message;
64
+ Logger::errorToJavascriptConsole(*creationRuntime, fullMessage.c_str());
65
+ };
66
+ aDescriptor.uncapturedErrorCallbackInfo = errorInfo;
13
67
  _instance.RequestDevice(
14
- aDescriptor,
68
+ &aDescriptor,
15
69
  [](WGPURequestDeviceStatus status, WGPUDevice cDevice,
16
70
  const char *message, void *userdata) {
17
71
  if (message != nullptr) {
@@ -26,8 +80,68 @@ GPUAdapter::requestDevice(std::shared_ptr<GPUDeviceDescriptor> descriptor) {
26
80
  if (!device) {
27
81
  throw std::runtime_error("Failed to request device");
28
82
  }
29
- return std::make_shared<GPUDevice>(std::move(device), descriptor->label);
83
+ device.SetLoggingCallback(
84
+ [](WGPULoggingType type, const char *message, void *userdata) {
85
+ auto creationRuntime = static_cast<jsi::Runtime *>(userdata);
86
+ const char *logLevel = "";
87
+ switch (type) {
88
+ case WGPULoggingType_Warning:
89
+ logLevel = "Warning";
90
+ Logger::warnToJavascriptConsole(*creationRuntime, message);
91
+ break;
92
+ case WGPULoggingType_Error:
93
+ logLevel = "Error";
94
+ Logger::errorToJavascriptConsole(*creationRuntime, message);
95
+ break;
96
+ case WGPULoggingType_Verbose:
97
+ logLevel = "Verbose";
98
+ case WGPULoggingType_Info:
99
+ logLevel = "Info";
100
+ default:
101
+ logLevel = "Unknown";
102
+ Logger::logToConsole("%s: %s", logLevel, message);
103
+ }
104
+ },
105
+ _creationRuntime);
106
+ std::string label =
107
+ descriptor.has_value() ? descriptor.value()->label.value_or("") : "";
108
+ return std::make_shared<GPUDevice>(std::move(device), _async, label);
30
109
  });
31
110
  }
32
111
 
112
+ std::unordered_set<std::string> GPUAdapter::getFeatures() {
113
+ size_t count = _instance.EnumerateFeatures(nullptr);
114
+ std::vector<wgpu::FeatureName> features(count);
115
+ _instance.EnumerateFeatures(features.data());
116
+ std::unordered_set<std::string> result;
117
+ for (auto feature : features) {
118
+ std::string name;
119
+ convertEnumToJSUnion(feature, &name);
120
+ if (name != "") {
121
+ result.insert(name);
122
+ }
123
+ }
124
+ return result;
125
+ }
126
+
127
+ std::shared_ptr<GPUSupportedLimits> GPUAdapter::getLimits() {
128
+ wgpu::SupportedLimits limits{};
129
+ if (!_instance.GetLimits(&limits)) {
130
+ throw std::runtime_error("Failed to get limits");
131
+ }
132
+ return std::make_shared<GPUSupportedLimits>(limits);
133
+ }
134
+
135
+ std::shared_ptr<GPUAdapterInfo> GPUAdapter::getInfo() {
136
+ wgpu::AdapterInfo info = {};
137
+ _instance.GetInfo(&info);
138
+ return std::make_shared<GPUAdapterInfo>(info);
139
+ }
140
+
141
+ bool GPUAdapter::getIsFallbackAdapter() {
142
+ wgpu::AdapterProperties adapterProperties = {};
143
+ _instance.GetProperties(&adapterProperties);
144
+ return adapterProperties.adapterType == wgpu::AdapterType::DiscreteGPU;
145
+ }
146
+
33
147
  } // namespace rnwgpu
@@ -3,16 +3,20 @@
3
3
  #include <future>
4
4
  #include <memory>
5
5
  #include <string>
6
+ #include <unordered_set>
6
7
 
7
8
  #include "Unions.h"
8
- #include <RNFHybridObject.h>
9
9
 
10
- #include "MutableBuffer.h"
10
+ #include "RNFHybridObject.h"
11
+
12
+ #include "AsyncRunner.h"
11
13
 
12
14
  #include "webgpu/webgpu_cpp.h"
13
15
 
16
+ #include "GPUAdapterInfo.h"
14
17
  #include "GPUDevice.h"
15
18
  #include "GPUDeviceDescriptor.h"
19
+ #include "GPUSupportedLimits.h"
16
20
 
17
21
  namespace rnwgpu {
18
22
 
@@ -20,21 +24,36 @@ namespace m = margelo;
20
24
 
21
25
  class GPUAdapter : public m::HybridObject {
22
26
  public:
23
- explicit GPUAdapter(wgpu::Adapter instance)
24
- : HybridObject("GPUAdapter"), _instance(instance) {}
27
+ explicit GPUAdapter(wgpu::Adapter instance,
28
+ std::shared_ptr<AsyncRunner> async)
29
+ : HybridObject("GPUAdapter"), _instance(instance), _async(async) {}
25
30
 
26
31
  public:
27
32
  std::string getBrand() { return _name; }
28
33
 
29
34
  std::future<std::shared_ptr<GPUDevice>>
30
- requestDevice(std::shared_ptr<GPUDeviceDescriptor> options);
35
+ requestDevice(std::optional<std::shared_ptr<GPUDeviceDescriptor>> descriptor);
36
+
37
+ std::unordered_set<std::string> getFeatures();
38
+ std::shared_ptr<GPUSupportedLimits> getLimits();
39
+ std::shared_ptr<GPUAdapterInfo> getInfo();
40
+ bool getIsFallbackAdapter();
31
41
 
32
42
  void loadHybridMethods() override {
33
43
  registerHybridGetter("__brand", &GPUAdapter::getBrand, this);
34
44
  registerHybridMethod("requestDevice", &GPUAdapter::requestDevice, this);
45
+ registerHybridGetter("features", &GPUAdapter::getFeatures, this);
46
+ registerHybridGetter("limits", &GPUAdapter::getLimits, this);
47
+ registerHybridGetter("info", &GPUAdapter::getInfo, this);
48
+ registerHybridGetter("isFallbackAdapter", &GPUAdapter::getIsFallbackAdapter,
49
+ this);
35
50
  }
36
51
 
52
+ inline const wgpu::Adapter get() { return _instance; }
53
+
37
54
  private:
38
55
  wgpu::Adapter _instance;
56
+ std::shared_ptr<AsyncRunner> _async;
39
57
  };
58
+
40
59
  } // namespace rnwgpu
@@ -1,13 +1,13 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
- #include <memory>
5
3
  #include <string>
4
+ #include <utility>
6
5
 
7
6
  #include "Unions.h"
8
- #include <RNFHybridObject.h>
9
7
 
10
- #include "MutableBuffer.h"
8
+ #include "RNFHybridObject.h"
9
+
10
+ #include "AsyncRunner.h"
11
11
 
12
12
  #include "webgpu/webgpu_cpp.h"
13
13
 
@@ -17,17 +17,29 @@ namespace m = margelo;
17
17
 
18
18
  class GPUAdapterInfo : public m::HybridObject {
19
19
  public:
20
- explicit GPUAdapterInfo(wgpu::AdapterInfo instance)
21
- : HybridObject("GPUAdapterInfo"), _instance(instance) {}
20
+ explicit GPUAdapterInfo(wgpu::AdapterInfo &instance)
21
+ : HybridObject("GPUAdapterInfo"), _instance(std::move(instance)) {}
22
22
 
23
23
  public:
24
24
  std::string getBrand() { return _name; }
25
25
 
26
+ std::string getVendor() { return _instance.vendor; }
27
+ std::string getArchitecture() { return _instance.architecture; }
28
+ std::string getDevice() { return _instance.device; }
29
+ std::string getDescription() { return _instance.description; }
30
+
26
31
  void loadHybridMethods() override {
27
32
  registerHybridGetter("__brand", &GPUAdapterInfo::getBrand, this);
33
+
34
+ registerHybridGetter("vendor", &GPUAdapterInfo::getVendor, this);
35
+ registerHybridGetter("architecture", &GPUAdapterInfo::getArchitecture,
36
+ this);
37
+ registerHybridGetter("device", &GPUAdapterInfo::getDevice, this);
38
+ registerHybridGetter("description", &GPUAdapterInfo::getDescription, this);
28
39
  }
29
40
 
30
41
  private:
31
42
  wgpu::AdapterInfo _instance;
32
43
  };
33
- } // namespace rnwgpu
44
+
45
+ } // namespace rnwgpu
@@ -0,0 +1,3 @@
1
+ #include "GPUBindGroup.h"
2
+
3
+ namespace rnwgpu {} // namespace rnwgpu
@@ -1,13 +1,12 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
- #include <memory>
5
3
  #include <string>
6
4
 
7
5
  #include "Unions.h"
8
- #include <RNFHybridObject.h>
9
6
 
10
- #include "MutableBuffer.h"
7
+ #include "RNFHybridObject.h"
8
+
9
+ #include "AsyncRunner.h"
11
10
 
12
11
  #include "webgpu/webgpu_cpp.h"
13
12
 
@@ -24,15 +23,23 @@ public:
24
23
  std::string getBrand() { return _name; }
25
24
 
26
25
  std::string getLabel() { return _label; }
26
+ void setLabel(const std::string &label) {
27
+ _label = label;
28
+ _instance.SetLabel(_label.c_str());
29
+ }
27
30
 
28
31
  void loadHybridMethods() override {
29
32
  registerHybridGetter("__brand", &GPUBindGroup::getBrand, this);
30
33
 
31
34
  registerHybridGetter("label", &GPUBindGroup::getLabel, this);
35
+ registerHybridSetter("label", &GPUBindGroup::setLabel, this);
32
36
  }
33
37
 
38
+ inline const wgpu::BindGroup get() { return _instance; }
39
+
34
40
  private:
35
41
  wgpu::BindGroup _instance;
36
42
  std::string _label;
37
43
  };
44
+
38
45
  } // namespace rnwgpu
@@ -1,13 +1,12 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
- #include <memory>
5
3
  #include <string>
6
4
 
7
5
  #include "Unions.h"
8
- #include <RNFHybridObject.h>
9
6
 
10
- #include "MutableBuffer.h"
7
+ #include "RNFHybridObject.h"
8
+
9
+ #include "AsyncRunner.h"
11
10
 
12
11
  #include "webgpu/webgpu_cpp.h"
13
12
 
@@ -25,15 +24,23 @@ public:
25
24
  std::string getBrand() { return _name; }
26
25
 
27
26
  std::string getLabel() { return _label; }
27
+ void setLabel(const std::string &label) {
28
+ _label = label;
29
+ _instance.SetLabel(_label.c_str());
30
+ }
28
31
 
29
32
  void loadHybridMethods() override {
30
33
  registerHybridGetter("__brand", &GPUBindGroupLayout::getBrand, this);
31
34
 
32
35
  registerHybridGetter("label", &GPUBindGroupLayout::getLabel, this);
36
+ registerHybridSetter("label", &GPUBindGroupLayout::setLabel, this);
33
37
  }
34
38
 
39
+ inline const wgpu::BindGroupLayout get() { return _instance; }
40
+
35
41
  private:
36
42
  wgpu::BindGroupLayout _instance;
37
43
  std::string _label;
38
44
  };
45
+
39
46
  } // namespace rnwgpu
@@ -1,16 +1,91 @@
1
1
  #include "GPUBuffer.h"
2
2
 
3
+ #include <utility>
4
+
5
+ #include "Convertors.h"
6
+
3
7
  namespace rnwgpu {
4
8
 
5
- std::shared_ptr<MutableJSIBuffer>
6
- GPUBuffer::getMappedRange(std::optional<size_t> offset,
7
- std::optional<size_t> size) {
8
- auto aOffset = offset.value_or(0);
9
- auto aSize = size.value_or(WGPU_WHOLE_MAP_SIZE);
10
- auto result = _instance.GetMappedRange(aOffset, aSize);
11
- return std::make_shared<MutableJSIBuffer>(result, _instance.GetSize());
9
+ std::shared_ptr<ArrayBuffer>
10
+ GPUBuffer::getMappedRange(std::optional<size_t> o, std::optional<size_t> size) {
11
+ auto offset = o.value_or(0);
12
+ uint64_t s = size.has_value() ? size.value() : (_instance.GetSize() - offset);
13
+
14
+ uint64_t start = offset;
15
+ uint64_t end = offset + s;
16
+ // for (auto& mapping : mappings_) {
17
+ // if (mapping.Intersects(start, end)) {
18
+ // Errors::OperationError(env).ThrowAsJavaScriptException();
19
+ // return {};
20
+ // }
21
+ // }
22
+
23
+ auto *ptr =
24
+ (_instance.GetUsage() & wgpu::BufferUsage::MapWrite)
25
+ ? _instance.GetMappedRange(offset, s)
26
+ : const_cast<void *>(_instance.GetConstMappedRange(offset, s));
27
+ if (!ptr) {
28
+ throw std::runtime_error("Failed to get getMappedRange");
29
+ }
30
+ auto array_buffer = std::make_shared<ArrayBuffer>(ptr, s, 1);
31
+ // TODO(crbug.com/dawn/1135): Ownership here is the wrong way around.
32
+ // mappings_.emplace_back(Mapping{start, end,
33
+ // Napi::Persistent(array_buffer)});
34
+ return array_buffer;
35
+ }
36
+
37
+ void GPUBuffer::destroy() { _instance.Destroy(); }
38
+
39
+ std::future<void> GPUBuffer::mapAsync(uint64_t modeIn,
40
+ std::optional<uint64_t> offset,
41
+ std::optional<uint64_t> size) {
42
+ Convertor conv;
43
+ wgpu::MapMode mode;
44
+ if (!conv(mode, modeIn)) {
45
+ throw std::runtime_error("Couldn't get MapMode");
46
+ }
47
+ uint64_t rangeSize = size.has_value()
48
+ ? size.value()
49
+ : (_instance.GetSize() - offset.value_or(0));
50
+ return _async->runAsync([=] {
51
+ // for (auto& mapping : mappings) {
52
+ // if (mapping.Intersects(start, end)) {
53
+ // promise.set_exception(std::make_exception_ptr(std::runtime_error("Buffer
54
+ // is already mapped"))); return future;
55
+ // }
56
+ // }
57
+ wgpu::BufferMapCallbackInfo callback;
58
+ callback.mode = wgpu::CallbackMode::WaitAnyOnly;
59
+ callback.callback = [](WGPUBufferMapAsyncStatus status, void *userdata) {
60
+ switch (status) {
61
+ case WGPUBufferMapAsyncStatus_Success:
62
+ break;
63
+ case WGPUBufferMapAsyncStatus_InstanceDropped:
64
+ throw std::runtime_error("WGPUBufferMapAsyncStatus_InstanceDropped");
65
+ break;
66
+ case WGPUBufferMapAsyncStatus_ValidationError:
67
+ throw std::runtime_error("WGPUBufferMapAsyncStatus_ValidationError");
68
+ break;
69
+ default:
70
+ throw std::runtime_error("WGPUBufferMapAsyncStatus: " +
71
+ std::to_string(status));
72
+ break;
73
+ }
74
+ };
75
+ return _instance.MapAsync(mode, offset.value_or(0), rangeSize, callback);
76
+ });
12
77
  }
13
78
 
14
79
  void GPUBuffer::unmap() { _instance.Unmap(); }
15
80
 
81
+ uint64_t GPUBuffer::getSize() { return _instance.GetSize(); }
82
+
83
+ double GPUBuffer::getUsage() {
84
+ return static_cast<double>(_instance.GetUsage());
85
+ }
86
+
87
+ wgpu::BufferMapState GPUBuffer::getMapState() {
88
+ return _instance.GetMapState();
89
+ }
90
+
16
91
  } // namespace rnwgpu