react-native-wgpu 0.1.0 → 0.1.3

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 (280) 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 +132 -0
  5. package/android/cpp/cpp-adapter.cpp +70 -4
  6. package/android/src/main/java/com/webgpu/WebGPUModule.java +69 -21
  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 +29 -0
  22. package/cpp/rnwgpu/RNWebGPUManager.cpp +13 -11
  23. package/cpp/rnwgpu/RNWebGPUManager.h +9 -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 +81 -23
  30. package/cpp/rnwgpu/api/GPU.h +24 -6
  31. package/cpp/rnwgpu/api/GPUAdapter.cpp +138 -24
  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 +44 -8
  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 +153 -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/ImageBitmap.h +34 -0
  81. package/cpp/rnwgpu/api/RNWebGPU.h +100 -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 +32 -31
  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 +19 -0
  139. package/ios/IOSPlatformContext.mm +68 -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 +47 -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 +183 -19
  158. package/lib/commonjs/index.js.map +1 -1
  159. package/lib/commonjs/utils.js +39 -0
  160. package/lib/commonjs/utils.js.map +1 -0
  161. package/lib/module/Canvas.js +40 -0
  162. package/lib/module/Canvas.js.map +1 -0
  163. package/lib/module/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
  164. package/lib/module/NativeWebGPUModule.js.map +1 -0
  165. package/lib/module/WebGPUView.js +2 -0
  166. package/lib/module/WebGPUView.js.map +1 -0
  167. package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
  168. package/lib/module/index.js +158 -6
  169. package/lib/module/index.js.map +1 -1
  170. package/lib/module/utils.js +31 -0
  171. package/lib/module/utils.js.map +1 -0
  172. package/lib/typescript/example/src/Triangle/triangle.d.ts +3 -0
  173. package/lib/typescript/example/src/Triangle/triangle.d.ts.map +1 -0
  174. package/lib/typescript/example/src/Wireframe/Shaders.d.ts +3 -0
  175. package/lib/typescript/example/src/Wireframe/Shaders.d.ts.map +1 -0
  176. package/lib/typescript/example/src/Wireframe/models.d.ts +29 -0
  177. package/lib/typescript/example/src/Wireframe/models.d.ts.map +1 -0
  178. package/lib/typescript/example/src/components/DrawingContext.d.ts +13 -0
  179. package/lib/typescript/example/src/components/DrawingContext.d.ts.map +1 -0
  180. package/lib/typescript/example/src/components/cube.d.ts +7 -0
  181. package/lib/typescript/example/src/components/cube.d.ts.map +1 -0
  182. package/lib/typescript/example/src/components/meshes/sphere.d.ts +12 -0
  183. package/lib/typescript/example/src/components/meshes/sphere.d.ts.map +1 -0
  184. package/lib/typescript/example/src/components/meshes/teapot.d.ts +6 -0
  185. package/lib/typescript/example/src/components/meshes/teapot.d.ts.map +1 -0
  186. package/lib/typescript/example/src/components/meshes/utils.d.ts +10 -0
  187. package/lib/typescript/example/src/components/meshes/utils.d.ts.map +1 -0
  188. package/lib/typescript/jest.config.d.ts +4 -0
  189. package/lib/typescript/lib/commonjs/Canvas.d.ts +4 -0
  190. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -0
  191. package/lib/typescript/lib/commonjs/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
  192. package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts.map +1 -0
  193. package/lib/typescript/lib/commonjs/WebGPUView.d.ts +1 -0
  194. package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +1 -0
  195. package/lib/typescript/lib/commonjs/index.d.ts +0 -2
  196. package/lib/typescript/lib/commonjs/utils.d.ts +5 -0
  197. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
  198. package/lib/typescript/lib/module/Canvas.d.ts +2 -0
  199. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -0
  200. package/lib/typescript/lib/module/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
  201. package/lib/typescript/lib/module/NativeWebGPUModule.d.ts.map +1 -0
  202. package/lib/typescript/lib/module/WebGPUView.d.ts +1 -0
  203. package/lib/typescript/lib/module/WebGPUView.d.ts.map +1 -0
  204. package/lib/typescript/lib/module/index.d.ts +3 -3
  205. package/lib/typescript/lib/module/utils.d.ts +3 -0
  206. package/lib/typescript/lib/module/utils.d.ts.map +1 -0
  207. package/lib/typescript/src/Canvas.d.ts +29 -0
  208. package/lib/typescript/src/Canvas.d.ts.map +1 -0
  209. package/lib/typescript/src/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +2 -1
  210. package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -0
  211. package/lib/typescript/src/WebGPUView.d.ts +1 -0
  212. package/lib/typescript/src/WebGPUView.d.ts.map +1 -0
  213. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -1
  214. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  215. package/lib/typescript/src/index.d.ts +3 -7
  216. package/lib/typescript/src/index.d.ts.map +1 -1
  217. package/lib/typescript/src/utils.d.ts +7 -0
  218. package/lib/typescript/src/utils.d.ts.map +1 -0
  219. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  220. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  221. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  222. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  223. package/libs/dawn.json +4597 -0
  224. package/libs/ios/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  225. package/libs/ios/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  226. package/libs/ios/libwebgpu_dawn.a +0 -0
  227. package/libs/ios/libwebgpu_dawn.xcframework/Info.plist +44 -0
  228. package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  229. package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  230. package/libs/ios/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  231. package/package.json +25 -8
  232. package/{react-native-webgpu.podspec → react-native-wgpu.podspec} +6 -9
  233. package/src/Canvas.tsx +73 -0
  234. package/src/{WebGPUNativeModule.ts → NativeWebGPUModule.ts} +1 -0
  235. package/src/WebGPUView.tsx +0 -0
  236. package/src/WebGPUViewNativeComponent.ts +2 -1
  237. package/src/index.tsx +191 -8
  238. package/src/utils.ts +40 -0
  239. package/android/src/main/AndroidManifestNew.xml +0 -2
  240. package/cpp/rnwgpu/MutableBuffer.h +0 -48
  241. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -33
  242. package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +0 -81
  243. package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +0 -76
  244. package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +0 -91
  245. package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +0 -61
  246. package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +0 -75
  247. package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +0 -71
  248. package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +0 -54
  249. package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +0 -83
  250. package/ios/RNFAppleLogger.mm +0 -22
  251. package/ios/Utils.h +0 -5
  252. package/ios/Utils.m +0 -26
  253. package/lib/module/WebGPUNativeModule.js.map +0 -1
  254. package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +0 -1
  255. package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +0 -1
  256. package/lib/typescript/scripts/build/copy-artifacts.d.ts +0 -2
  257. package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +0 -1
  258. package/lib/typescript/scripts/build/dawn.d.ts +0 -2
  259. package/lib/typescript/scripts/build/dawn.d.ts.map +0 -1
  260. package/lib/typescript/scripts/build/util.d.ts +0 -13
  261. package/lib/typescript/scripts/build/util.d.ts.map +0 -1
  262. package/lib/typescript/scripts/codegen/codegen.d.ts +0 -2
  263. package/lib/typescript/scripts/codegen/codegen.d.ts.map +0 -1
  264. package/lib/typescript/scripts/codegen/model/dawn.d.ts +0 -2
  265. package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +0 -1
  266. package/lib/typescript/scripts/codegen/model/model.d.ts +0 -8
  267. package/lib/typescript/scripts/codegen/model/model.d.ts.map +0 -1
  268. package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +0 -4
  269. package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +0 -1
  270. package/lib/typescript/scripts/codegen/templates/Enum.d.ts +0 -3
  271. package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +0 -1
  272. package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +0 -3
  273. package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +0 -1
  274. package/lib/typescript/scripts/codegen/templates/Unions.d.ts +0 -6
  275. package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +0 -1
  276. package/lib/typescript/scripts/codegen/templates/common.d.ts +0 -9
  277. package/lib/typescript/scripts/codegen/templates/common.d.ts.map +0 -1
  278. package/lib/typescript/scripts/codegen/util.d.ts +0 -2
  279. package/lib/typescript/scripts/codegen/util.d.ts.map +0 -1
  280. package/lib/typescript/src/WebGPUNativeModule.d.ts.map +0 -1
@@ -2,43 +2,79 @@
2
2
 
3
3
  #include <future>
4
4
  #include <memory>
5
+ #include <optional>
5
6
  #include <string>
7
+ #include <vector>
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
 
17
+ #include "ArrayBuffer.h"
18
+
14
19
  namespace rnwgpu {
15
20
 
16
21
  namespace m = margelo;
17
22
 
18
23
  class GPUBuffer : public m::HybridObject {
19
24
  public:
20
- explicit GPUBuffer(wgpu::Buffer instance, std::string label)
21
- : HybridObject("GPUBuffer"), _instance(instance), _label(label) {}
25
+ explicit GPUBuffer(wgpu::Buffer instance, std::shared_ptr<AsyncRunner> async,
26
+ std::string label)
27
+ : HybridObject("GPUBuffer"), _instance(instance), _async(async),
28
+ _label(label) {}
22
29
 
23
30
  public:
24
31
  std::string getBrand() { return _name; }
25
32
 
26
- std::shared_ptr<MutableJSIBuffer> getMappedRange(std::optional<size_t> offset,
27
- std::optional<size_t> size);
33
+ std::future<void> mapAsync(uint64_t modeIn, std::optional<uint64_t> offset,
34
+ std::optional<uint64_t> size);
35
+ std::shared_ptr<ArrayBuffer> getMappedRange(std::optional<size_t> offset,
36
+ std::optional<size_t> size);
28
37
  void unmap();
38
+ void destroy();
39
+
40
+ uint64_t getSize();
41
+ double getUsage();
42
+ wgpu::BufferMapState getMapState();
29
43
 
30
44
  std::string getLabel() { return _label; }
45
+ void setLabel(const std::string &label) {
46
+ _label = label;
47
+ _instance.SetLabel(_label.c_str());
48
+ }
31
49
 
32
50
  void loadHybridMethods() override {
33
51
  registerHybridGetter("__brand", &GPUBuffer::getBrand, this);
52
+ registerHybridMethod("mapAsync", &GPUBuffer::mapAsync, this);
34
53
  registerHybridMethod("getMappedRange", &GPUBuffer::getMappedRange, this);
35
54
  registerHybridMethod("unmap", &GPUBuffer::unmap, this);
36
-
55
+ registerHybridMethod("destroy", &GPUBuffer::destroy, this);
56
+ registerHybridGetter("size", &GPUBuffer::getSize, this);
57
+ registerHybridGetter("usage", &GPUBuffer::getUsage, this);
58
+ registerHybridGetter("mapState", &GPUBuffer::getMapState, this);
37
59
  registerHybridGetter("label", &GPUBuffer::getLabel, this);
60
+ registerHybridSetter("label", &GPUBuffer::setLabel, this);
38
61
  }
39
62
 
63
+ inline const wgpu::Buffer get() { return _instance; }
64
+
40
65
  private:
41
66
  wgpu::Buffer _instance;
67
+ std::shared_ptr<AsyncRunner> _async;
42
68
  std::string _label;
69
+ struct Mapping {
70
+ uint64_t start;
71
+ uint64_t end;
72
+ inline bool Intersects(uint64_t s, uint64_t e) const {
73
+ return s < end && e > start;
74
+ }
75
+ std::shared_ptr<ArrayBuffer> buffer;
76
+ };
77
+ std::vector<Mapping> mappings;
43
78
  };
44
- } // namespace rnwgpu
79
+
80
+ } // namespace rnwgpu
@@ -0,0 +1,63 @@
1
+ #include "GPUCanvasContext.h"
2
+ #include "Convertors.h"
3
+ #include "RNWebGPUManager.h"
4
+
5
+ namespace rnwgpu {
6
+
7
+ void GPUCanvasContext::configure(
8
+ std::shared_ptr<GPUCanvasConfiguration> configuration) {
9
+ Convertor conv;
10
+ wgpu::SurfaceConfiguration surfaceConfiguration;
11
+ surfaceConfiguration.device = configuration->device->get();
12
+ _device = configuration->device->get();
13
+ if (configuration->viewFormats.has_value()) {
14
+ if (!conv(surfaceConfiguration.viewFormats,
15
+ surfaceConfiguration.viewFormatCount,
16
+ configuration->viewFormats.value())) {
17
+ throw std::runtime_error("Error with SurfaceConfiguration");
18
+ }
19
+ }
20
+ if (!conv(surfaceConfiguration.format, configuration->format)) {
21
+ throw std::runtime_error("Error with SurfaceConfiguration");
22
+ }
23
+ if (!conv(surfaceConfiguration.usage, configuration->usage)) {
24
+ throw std::runtime_error("Error with SurfaceConfiguration");
25
+ }
26
+ surfaceConfiguration.width = _canvas->getWidth();
27
+ surfaceConfiguration.height = _canvas->getHeight();
28
+ _instance.Configure(&surfaceConfiguration);
29
+ _lastConfig = configuration;
30
+ _width = _canvas->getWidth();
31
+ _height = _canvas->getHeight();
32
+ }
33
+
34
+ void GPUCanvasContext::unconfigure() {
35
+ _lastConfig = nullptr;
36
+ _width = _canvas->getWidth();
37
+ _height = _canvas->getHeight();
38
+ _instance.Unconfigure();
39
+ }
40
+
41
+ std::shared_ptr<GPUTexture> GPUCanvasContext::getCurrentTexture() {
42
+ // we need to reconfigure if the size of the canvas has changed
43
+ if (_width != _canvas->getWidth() || _height != _canvas->getHeight()) {
44
+ configure(_lastConfig);
45
+ }
46
+ wgpu::SurfaceTexture surfaceTexture;
47
+ _instance.GetCurrentTexture(&surfaceTexture);
48
+ auto texture = surfaceTexture.texture;
49
+ if (texture == nullptr) {
50
+ throw std::runtime_error("Couldn't get current texture");
51
+ }
52
+ // Default canvas texture label is ""
53
+ return std::make_shared<GPUTexture>(texture, "");
54
+ }
55
+
56
+ void GPUCanvasContext::present() {
57
+ #ifdef __APPLE__
58
+ dawn::native::metal::WaitForCommandsToBeScheduled(_device.Get());
59
+ #endif
60
+ _instance.Present();
61
+ }
62
+
63
+ } // namespace rnwgpu
@@ -1,33 +1,76 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
3
  #include <memory>
5
4
  #include <string>
6
5
 
7
6
  #include "Unions.h"
8
- #include <RNFHybridObject.h>
9
-
10
- #include "MutableBuffer.h"
11
7
 
12
8
  #include "webgpu/webgpu_cpp.h"
13
9
 
10
+ #include "RNFHybridObject.h"
11
+
12
+ #include "AsyncRunner.h"
13
+
14
+ #include "Canvas.h"
15
+ #include "GPUCanvasConfiguration.h"
16
+ #include "GPUTexture.h"
17
+ #include "SurfaceRegistry.h"
18
+
19
+ #ifdef __APPLE__
20
+
21
+ namespace dawn {
22
+ namespace native {
23
+ namespace metal {
24
+
25
+ // See
26
+ // https://source.chromium.org/chromium/chromium/src/+/main:third_party/dawn/include/dawn/native/MetalBackend.h;l=41
27
+ void WaitForCommandsToBeScheduled(WGPUDevice device);
28
+
29
+ } // namespace metal
30
+ } // namespace native
31
+ } // namespace dawn
32
+
33
+ #endif
34
+
14
35
  namespace rnwgpu {
15
36
 
16
37
  namespace m = margelo;
17
38
 
18
39
  class GPUCanvasContext : public m::HybridObject {
19
40
  public:
20
- explicit GPUCanvasContext(wgpu::CanvasContext instance)
21
- : HybridObject("GPUCanvasContext"), _instance(instance) {}
41
+ explicit GPUCanvasContext(wgpu::Surface instance,
42
+ std::shared_ptr<Canvas> canvas)
43
+ : HybridObject("GPUCanvasContext"), _instance(instance), _canvas(canvas) {
44
+ }
22
45
 
23
46
  public:
24
47
  std::string getBrand() { return _name; }
25
48
 
49
+ std::shared_ptr<Canvas> getCanvas() { return _canvas; }
50
+
26
51
  void loadHybridMethods() override {
27
52
  registerHybridGetter("__brand", &GPUCanvasContext::getBrand, this);
53
+ registerHybridGetter("canvas", &GPUCanvasContext::getCanvas, this);
54
+ registerHybridMethod("configure", &GPUCanvasContext::configure, this);
55
+ registerHybridMethod("unconfigure", &GPUCanvasContext::unconfigure, this);
56
+ registerHybridMethod("getCurrentTexture",
57
+ &GPUCanvasContext::getCurrentTexture, this);
58
+ registerHybridMethod("present", &GPUCanvasContext::present, this);
28
59
  }
29
60
 
61
+ inline const wgpu::Surface get() { return _instance; }
62
+ void configure(std::shared_ptr<GPUCanvasConfiguration> configuration);
63
+ void unconfigure();
64
+ std::shared_ptr<GPUTexture> getCurrentTexture();
65
+ void present();
66
+
30
67
  private:
31
- wgpu::CanvasContext _instance;
68
+ wgpu::Surface _instance;
69
+ wgpu::Device _device;
70
+ std::shared_ptr<Canvas> _canvas;
71
+ std::shared_ptr<GPUCanvasConfiguration> _lastConfig;
72
+ float _width;
73
+ float _height;
32
74
  };
33
- } // namespace rnwgpu
75
+
76
+ } // 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", &GPUCommandBuffer::getBrand, this);
30
33
 
31
34
  registerHybridGetter("label", &GPUCommandBuffer::getLabel, this);
35
+ registerHybridSetter("label", &GPUCommandBuffer::setLabel, this);
32
36
  }
33
37
 
38
+ inline const wgpu::CommandBuffer get() { return _instance; }
39
+
34
40
  private:
35
41
  wgpu::CommandBuffer _instance;
36
42
  std::string _label;
37
43
  };
44
+
38
45
  } // namespace rnwgpu
@@ -0,0 +1,177 @@
1
+ #include "GPUCommandEncoder.h"
2
+
3
+ #include <vector>
4
+
5
+ #include "Convertors.h"
6
+
7
+ namespace rnwgpu {
8
+
9
+ void GPUCommandEncoder::copyBufferToBuffer(
10
+ std::shared_ptr<GPUBuffer> source, uint64_t sourceOffset,
11
+ std::shared_ptr<GPUBuffer> destination, uint64_t destinationOffset,
12
+ uint64_t size) {
13
+ Convertor conv;
14
+
15
+ wgpu::Buffer src{};
16
+ wgpu::Buffer dst{};
17
+ if (!conv(src, source) || //
18
+ !conv(dst, destination)) {
19
+ return;
20
+ }
21
+ _instance.CopyBufferToBuffer(src, sourceOffset, dst, destinationOffset, size);
22
+ }
23
+
24
+ std::shared_ptr<GPUCommandBuffer> GPUCommandEncoder::finish(
25
+ std::optional<std::shared_ptr<GPUCommandBufferDescriptor>> descriptor) {
26
+ wgpu::CommandBufferDescriptor desc{};
27
+ Convertor conv;
28
+ if (!conv(desc, descriptor)) {
29
+ throw std::runtime_error(
30
+ "GPUCommandEncoder::finish(): error with GPUCommandBufferDescriptor");
31
+ }
32
+ auto commandBuffer = _instance.Finish(&desc);
33
+ return std::make_shared<GPUCommandBuffer>(
34
+ commandBuffer,
35
+ descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
36
+ }
37
+
38
+ std::shared_ptr<GPURenderPassEncoder> GPUCommandEncoder::beginRenderPass(
39
+ std::shared_ptr<GPURenderPassDescriptor> descriptor) {
40
+
41
+ wgpu::RenderPassDescriptor desc{};
42
+ wgpu::RenderPassDescriptorMaxDrawCount maxDrawCountDesc{};
43
+ desc.nextInChain = &maxDrawCountDesc;
44
+ Convertor conv;
45
+
46
+ // TODO: why is this not in Converter
47
+ if (!conv(desc.colorAttachments, desc.colorAttachmentCount,
48
+ descriptor->colorAttachments) ||
49
+ !conv(desc.depthStencilAttachment, descriptor->depthStencilAttachment) ||
50
+ !conv(desc.label, descriptor->label) ||
51
+ !conv(desc.occlusionQuerySet, descriptor->occlusionQuerySet) ||
52
+ !conv(desc.timestampWrites, descriptor->timestampWrites) ||
53
+ !conv(maxDrawCountDesc.maxDrawCount, descriptor->maxDrawCount)) {
54
+ throw std::runtime_error("PUCommandEncoder::beginRenderPass(): couldn't "
55
+ "get GPURenderPassDescriptor");
56
+ }
57
+ auto renderPass = _instance.BeginRenderPass(&desc);
58
+ return std::make_shared<GPURenderPassEncoder>(renderPass,
59
+ descriptor->label.value_or(""));
60
+ }
61
+
62
+ void GPUCommandEncoder::copyTextureToBuffer(
63
+ std::shared_ptr<GPUImageCopyTexture> source,
64
+ std::shared_ptr<GPUImageCopyBuffer> destination,
65
+ std::shared_ptr<GPUExtent3D> copySize) {
66
+ Convertor conv;
67
+ wgpu::ImageCopyTexture src{};
68
+ wgpu::ImageCopyBuffer dst{};
69
+ wgpu::Extent3D size{};
70
+ if (!conv(src, source) || //
71
+ !conv(dst, destination) || //
72
+ !conv(size, copySize)) {
73
+ return;
74
+ }
75
+ _instance.CopyTextureToBuffer(&src, &dst, &size);
76
+ }
77
+
78
+ void GPUCommandEncoder::copyTextureToTexture(
79
+ std::shared_ptr<GPUImageCopyTexture> source,
80
+ std::shared_ptr<GPUImageCopyTexture> destination,
81
+ std::shared_ptr<GPUExtent3D> copySize) {
82
+ Convertor conv;
83
+
84
+ wgpu::ImageCopyTexture src{};
85
+ wgpu::ImageCopyTexture dst{};
86
+ wgpu::Extent3D size{};
87
+ if (!conv(src, source) || //
88
+ !conv(dst, destination) || //
89
+ !conv(size, copySize)) {
90
+ return;
91
+ }
92
+
93
+ _instance.CopyTextureToTexture(&src, &dst, &size);
94
+ }
95
+
96
+ std::shared_ptr<GPUComputePassEncoder> GPUCommandEncoder::beginComputePass(
97
+ std::optional<std::shared_ptr<GPUComputePassDescriptor>> descriptor) {
98
+ wgpu::ComputePassDescriptor desc;
99
+ Convertor conv;
100
+ if (!conv(desc, descriptor)) {
101
+ throw std::runtime_error("GPUCommandEncoder.beginComputePass(): couldn't "
102
+ "access GPUComputePassDescriptor.");
103
+ }
104
+ auto computePass = _instance.BeginComputePass(&desc);
105
+ return std::make_shared<GPUComputePassEncoder>(
106
+ computePass,
107
+ descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
108
+ }
109
+
110
+ void GPUCommandEncoder::resolveQuerySet(std::shared_ptr<GPUQuerySet> querySet,
111
+ uint32_t firstQuery,
112
+ uint32_t queryCount,
113
+ std::shared_ptr<GPUBuffer> destination,
114
+ uint64_t destinationOffset) {
115
+ Convertor conv;
116
+
117
+ wgpu::QuerySet q{};
118
+ uint32_t f = 0;
119
+ uint32_t c = 0;
120
+ wgpu::Buffer b{};
121
+ uint64_t o = 0;
122
+
123
+ if (!conv(q, querySet) || //
124
+ !conv(f, firstQuery) || //
125
+ !conv(c, queryCount) || //
126
+ !conv(b, destination) || //
127
+ !conv(o, destinationOffset)) {
128
+ return;
129
+ }
130
+
131
+ _instance.ResolveQuerySet(q, f, c, b, o);
132
+ }
133
+
134
+ void GPUCommandEncoder::copyBufferToTexture(
135
+ std::shared_ptr<GPUImageCopyBuffer> source,
136
+ std::shared_ptr<GPUImageCopyTexture> destination,
137
+ std::shared_ptr<GPUExtent3D> copySize) {
138
+ Convertor conv;
139
+
140
+ wgpu::ImageCopyBuffer src{};
141
+ wgpu::ImageCopyTexture dst{};
142
+ wgpu::Extent3D size{};
143
+ if (!conv(src, source) || //
144
+ !conv(dst, destination) || //
145
+ !conv(size, copySize)) {
146
+ return;
147
+ }
148
+
149
+ _instance.CopyBufferToTexture(&src, &dst, &size);
150
+ }
151
+
152
+ void GPUCommandEncoder::clearBuffer(std::shared_ptr<GPUBuffer> buffer,
153
+ std::optional<uint64_t> offset,
154
+ std::optional<uint64_t> size) {
155
+ Convertor conv;
156
+
157
+ wgpu::Buffer b{};
158
+ uint64_t s = wgpu::kWholeSize;
159
+ if (!conv(b, buffer) || //
160
+ !conv(s, size)) {
161
+ return;
162
+ }
163
+
164
+ _instance.ClearBuffer(b, offset.value_or(0), s);
165
+ }
166
+
167
+ void GPUCommandEncoder::pushDebugGroup(std::string groupLabel) {
168
+ _instance.PushDebugGroup(groupLabel.c_str());
169
+ }
170
+
171
+ void GPUCommandEncoder::popDebugGroup() { _instance.PopDebugGroup(); }
172
+
173
+ void GPUCommandEncoder::insertDebugMarker(std::string markerLabel) {
174
+ _instance.InsertDebugMarker(markerLabel.c_str());
175
+ }
176
+
177
+ } // namespace rnwgpu
@@ -1,16 +1,28 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
3
  #include <memory>
5
4
  #include <string>
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
 
14
+ #include "GPUBuffer.h"
15
+ #include "GPUCommandBuffer.h"
16
+ #include "GPUCommandBufferDescriptor.h"
17
+ #include "GPUComputePassDescriptor.h"
18
+ #include "GPUComputePassEncoder.h"
19
+ #include "GPUExtent3D.h"
20
+ #include "GPUImageCopyBuffer.h"
21
+ #include "GPUImageCopyTexture.h"
22
+ #include "GPUQuerySet.h"
23
+ #include "GPURenderPassDescriptor.h"
24
+ #include "GPURenderPassEncoder.h"
25
+
14
26
  namespace rnwgpu {
15
27
 
16
28
  namespace m = margelo;
@@ -23,16 +35,76 @@ public:
23
35
  public:
24
36
  std::string getBrand() { return _name; }
25
37
 
38
+ std::shared_ptr<GPURenderPassEncoder>
39
+ beginRenderPass(std::shared_ptr<GPURenderPassDescriptor> descriptor);
40
+ std::shared_ptr<GPUComputePassEncoder> beginComputePass(
41
+ std::optional<std::shared_ptr<GPUComputePassDescriptor>> descriptor);
42
+ void copyBufferToBuffer(std::shared_ptr<GPUBuffer> source,
43
+ uint64_t sourceOffset,
44
+ std::shared_ptr<GPUBuffer> destination,
45
+ uint64_t destinationOffset, uint64_t size);
46
+ void copyBufferToTexture(std::shared_ptr<GPUImageCopyBuffer> source,
47
+ std::shared_ptr<GPUImageCopyTexture> destination,
48
+ std::shared_ptr<GPUExtent3D> copySize);
49
+ void copyTextureToBuffer(std::shared_ptr<GPUImageCopyTexture> source,
50
+ std::shared_ptr<GPUImageCopyBuffer> destination,
51
+ std::shared_ptr<GPUExtent3D> copySize);
52
+ void copyTextureToTexture(std::shared_ptr<GPUImageCopyTexture> source,
53
+ std::shared_ptr<GPUImageCopyTexture> destination,
54
+ std::shared_ptr<GPUExtent3D> copySize);
55
+ void clearBuffer(std::shared_ptr<GPUBuffer> buffer,
56
+ std::optional<uint64_t> offset,
57
+ std::optional<uint64_t> size);
58
+ void resolveQuerySet(std::shared_ptr<GPUQuerySet> querySet,
59
+ uint32_t firstQuery, uint32_t queryCount,
60
+ std::shared_ptr<GPUBuffer> destination,
61
+ uint64_t destinationOffset);
62
+ std::shared_ptr<GPUCommandBuffer>
63
+ finish(std::optional<std::shared_ptr<GPUCommandBufferDescriptor>> descriptor);
64
+ void pushDebugGroup(std::string groupLabel);
65
+ void popDebugGroup();
66
+ void insertDebugMarker(std::string markerLabel);
67
+
26
68
  std::string getLabel() { return _label; }
69
+ void setLabel(const std::string &label) {
70
+ _label = label;
71
+ _instance.SetLabel(_label.c_str());
72
+ }
27
73
 
28
74
  void loadHybridMethods() override {
29
75
  registerHybridGetter("__brand", &GPUCommandEncoder::getBrand, this);
76
+ registerHybridMethod("beginRenderPass", &GPUCommandEncoder::beginRenderPass,
77
+ this);
78
+ registerHybridMethod("beginComputePass",
79
+ &GPUCommandEncoder::beginComputePass, this);
80
+ registerHybridMethod("copyBufferToBuffer",
81
+ &GPUCommandEncoder::copyBufferToBuffer, this);
82
+ registerHybridMethod("copyBufferToTexture",
83
+ &GPUCommandEncoder::copyBufferToTexture, this);
84
+ registerHybridMethod("copyTextureToBuffer",
85
+ &GPUCommandEncoder::copyTextureToBuffer, this);
86
+ registerHybridMethod("copyTextureToTexture",
87
+ &GPUCommandEncoder::copyTextureToTexture, this);
88
+ registerHybridMethod("clearBuffer", &GPUCommandEncoder::clearBuffer, this);
89
+ registerHybridMethod("resolveQuerySet", &GPUCommandEncoder::resolveQuerySet,
90
+ this);
91
+ registerHybridMethod("finish", &GPUCommandEncoder::finish, this);
92
+ registerHybridMethod("pushDebugGroup", &GPUCommandEncoder::pushDebugGroup,
93
+ this);
94
+ registerHybridMethod("popDebugGroup", &GPUCommandEncoder::popDebugGroup,
95
+ this);
96
+ registerHybridMethod("insertDebugMarker",
97
+ &GPUCommandEncoder::insertDebugMarker, this);
30
98
 
31
99
  registerHybridGetter("label", &GPUCommandEncoder::getLabel, this);
100
+ registerHybridSetter("label", &GPUCommandEncoder::setLabel, this);
32
101
  }
33
102
 
103
+ inline const wgpu::CommandEncoder get() { return _instance; }
104
+
34
105
  private:
35
106
  wgpu::CommandEncoder _instance;
36
107
  std::string _label;
37
108
  };
109
+
38
110
  } // namespace rnwgpu
@@ -1,13 +1,13 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
- #include <memory>
5
3
  #include <string>
4
+ #include <vector>
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
 
@@ -15,19 +15,76 @@ namespace rnwgpu {
15
15
 
16
16
  namespace m = margelo;
17
17
 
18
+ struct GPUCompilationMessage {
19
+ std::string message;
20
+ wgpu::CompilationMessageType type;
21
+ uint64_t lineNum;
22
+ uint64_t linePos;
23
+ uint64_t offset;
24
+ uint64_t length;
25
+ uint64_t utf16LinePos;
26
+ uint64_t utf16Offset;
27
+ uint64_t utf16Length;
28
+ };
29
+
18
30
  class GPUCompilationInfo : public m::HybridObject {
19
31
  public:
20
- explicit GPUCompilationInfo(wgpu::CompilationInfo instance)
21
- : HybridObject("GPUCompilationInfo"), _instance(instance) {}
32
+ GPUCompilationInfo() : HybridObject("GPUCompilationInfo") {}
22
33
 
23
34
  public:
24
35
  std::string getBrand() { return _name; }
25
36
 
37
+ std::vector<GPUCompilationMessage> getMessages() { return _messages; }
38
+
26
39
  void loadHybridMethods() override {
27
40
  registerHybridGetter("__brand", &GPUCompilationInfo::getBrand, this);
41
+ registerHybridGetter("messages", &GPUCompilationInfo::getMessages, this);
28
42
  }
29
43
 
30
44
  private:
31
- wgpu::CompilationInfo _instance;
45
+ std::vector<GPUCompilationMessage> _messages;
46
+ friend class GPUShaderModule;
47
+ };
48
+
49
+ } // namespace rnwgpu
50
+
51
+ namespace margelo {
52
+ template <> struct JSIConverter<std::vector<rnwgpu::GPUCompilationMessage>> {
53
+ static std::vector<rnwgpu::GPUCompilationMessage>
54
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
55
+ throw std::runtime_error("Invalid GPUCompilationMessage::fromJSI()");
56
+ }
57
+ static jsi::Value toJSI(jsi::Runtime &runtime,
58
+ std::vector<rnwgpu::GPUCompilationMessage> arg) {
59
+ jsi::Array result = jsi::Array(runtime, arg.size());
60
+ for (size_t i = 0; i < arg.size(); i++) {
61
+ const auto &message = arg[i];
62
+ jsi::Object messageObj(runtime);
63
+ messageObj.setProperty(
64
+ runtime, "message",
65
+ jsi::String::createFromUtf8(runtime, message.message));
66
+ std::string typeStr;
67
+ EnumMapper::convertEnumToJSUnion(message.type, &typeStr);
68
+ messageObj.setProperty(runtime, "type",
69
+ jsi::String::createFromUtf8(runtime, typeStr));
70
+ messageObj.setProperty(runtime, "lineNum",
71
+ static_cast<double>(message.lineNum));
72
+ messageObj.setProperty(runtime, "linePos",
73
+ static_cast<double>(message.linePos));
74
+ messageObj.setProperty(runtime, "offset",
75
+ static_cast<double>(message.offset));
76
+ messageObj.setProperty(runtime, "length",
77
+ static_cast<double>(message.length));
78
+ messageObj.setProperty(runtime, "utf16LinePos",
79
+ static_cast<double>(message.utf16LinePos));
80
+ messageObj.setProperty(runtime, "utf16Offset",
81
+ static_cast<double>(message.utf16Offset));
82
+ messageObj.setProperty(runtime, "utf16Length",
83
+ static_cast<double>(message.utf16Length));
84
+ result.setValueAtIndex(runtime, i, messageObj);
85
+ }
86
+ return result;
87
+ }
32
88
  };
33
- } // namespace rnwgpu
89
+
90
+ } // namespace margelo
@@ -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
 
@@ -27,7 +26,10 @@ public:
27
26
  registerHybridGetter("__brand", &GPUCompilationMessage::getBrand, this);
28
27
  }
29
28
 
29
+ inline const wgpu::CompilationMessage get() { return _instance; }
30
+
30
31
  private:
31
32
  wgpu::CompilationMessage _instance;
32
33
  };
34
+
33
35
  } // namespace rnwgpu