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
@@ -25,7 +25,7 @@
25
25
  // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  #ifdef __EMSCRIPTEN__
28
- #error "Do not include this header. Emscripten already provides headers needed for WebGPU."
28
+ #error "This header is for native Dawn. Use Dawn's or Emscripten's Emscripten bindings instead."
29
29
  #endif
30
30
  #ifndef DAWN_WIRE_CLIENT_WEBGPU_CPP_H_
31
31
  #define DAWN_WIRE_CLIENT_WEBGPU_CPP_H_
@@ -303,6 +303,8 @@ enum class FeatureName : uint32_t {
303
303
  RG11B10UfloatRenderable = WGPUFeatureName_RG11B10UfloatRenderable,
304
304
  BGRA8UnormStorage = WGPUFeatureName_BGRA8UnormStorage,
305
305
  Float32Filterable = WGPUFeatureName_Float32Filterable,
306
+ Subgroups = WGPUFeatureName_Subgroups,
307
+ SubgroupsF16 = WGPUFeatureName_SubgroupsF16,
306
308
  DawnInternalUsages = WGPUFeatureName_DawnInternalUsages,
307
309
  DawnMultiPlanarFormats = WGPUFeatureName_DawnMultiPlanarFormats,
308
310
  DawnNative = WGPUFeatureName_DawnNative,
@@ -1887,6 +1889,7 @@ struct AdapterInfo {
1887
1889
  Bool const compatibilityMode = false;
1888
1890
 
1889
1891
  private:
1892
+ inline void FreeMembers();
1890
1893
  static inline void Reset(AdapterInfo& value);
1891
1894
  };
1892
1895
 
@@ -1911,6 +1914,7 @@ struct AdapterProperties {
1911
1914
  Bool const compatibilityMode = false;
1912
1915
 
1913
1916
  private:
1917
+ inline void FreeMembers();
1914
1918
  static inline void Reset(AdapterProperties& value);
1915
1919
  };
1916
1920
 
@@ -2677,6 +2681,7 @@ struct SharedBufferMemoryEndAccessState {
2677
2681
  uint64_t const * const signaledValues = {};
2678
2682
 
2679
2683
  private:
2684
+ inline void FreeMembers();
2680
2685
  static inline void Reset(SharedBufferMemoryEndAccessState& value);
2681
2686
  };
2682
2687
 
@@ -2926,6 +2931,7 @@ struct SharedTextureMemoryEndAccessState {
2926
2931
  uint64_t const * const signaledValues = {};
2927
2932
 
2928
2933
  private:
2934
+ inline void FreeMembers();
2929
2935
  static inline void Reset(SharedTextureMemoryEndAccessState& value);
2930
2936
  };
2931
2937
 
@@ -3045,6 +3051,7 @@ struct SurfaceCapabilities {
3045
3051
  CompositeAlphaMode const * const alphaModes = {};
3046
3052
 
3047
3053
  private:
3054
+ inline void FreeMembers();
3048
3055
  static inline void Reset(SurfaceCapabilities& value);
3049
3056
  };
3050
3057
 
@@ -3299,6 +3306,7 @@ struct AdapterPropertiesMemoryHeaps : ChainedStructOut {
3299
3306
  MemoryHeapInfo const * const heapInfo = {};
3300
3307
 
3301
3308
  private:
3309
+ inline void FreeMembers();
3302
3310
  static inline void Reset(AdapterPropertiesMemoryHeaps& value);
3303
3311
  };
3304
3312
 
@@ -3381,6 +3389,7 @@ struct DrmFormatCapabilities : ChainedStructOut {
3381
3389
  DrmFormatProperties const * const properties = {};
3382
3390
 
3383
3391
  private:
3392
+ inline void FreeMembers();
3384
3393
  static inline void Reset(DrmFormatCapabilities& value);
3385
3394
  };
3386
3395
 
@@ -3716,10 +3725,7 @@ struct DeviceDescriptor : protected detail::DeviceDescriptor {
3716
3725
  // AdapterInfo implementation
3717
3726
  AdapterInfo::AdapterInfo() = default;
3718
3727
  AdapterInfo::~AdapterInfo() {
3719
- if (this->vendor != nullptr || this->architecture != nullptr || this->device != nullptr || this->description != nullptr) {
3720
- wgpuDawnWireClientAdapterInfoFreeMembers(
3721
- *reinterpret_cast<WGPUAdapterInfo*>(this));
3722
- }
3728
+ FreeMembers();
3723
3729
  }
3724
3730
 
3725
3731
  AdapterInfo::AdapterInfo(AdapterInfo&& rhs)
@@ -3739,7 +3745,7 @@ AdapterInfo& AdapterInfo::operator=(AdapterInfo&& rhs) {
3739
3745
  if (&rhs == this) {
3740
3746
  return *this;
3741
3747
  }
3742
- this->~AdapterInfo();
3748
+ FreeMembers();
3743
3749
  ::wgpu::detail::AsNonConstReference(this->vendor) = std::move(rhs.vendor);
3744
3750
  ::wgpu::detail::AsNonConstReference(this->architecture) = std::move(rhs.architecture);
3745
3751
  ::wgpu::detail::AsNonConstReference(this->device) = std::move(rhs.device);
@@ -3753,7 +3759,14 @@ AdapterInfo& AdapterInfo::operator=(AdapterInfo&& rhs) {
3753
3759
  return *this;
3754
3760
  }
3755
3761
 
3756
- // static
3762
+ void AdapterInfo::FreeMembers() {
3763
+ if (this->vendor != nullptr || this->architecture != nullptr || this->device != nullptr || this->description != nullptr) {
3764
+ wgpuDawnWireClientAdapterInfoFreeMembers(
3765
+ *reinterpret_cast<WGPUAdapterInfo*>(this));
3766
+ }
3767
+ }
3768
+
3769
+ // static
3757
3770
  void AdapterInfo::Reset(AdapterInfo& value) {
3758
3771
  AdapterInfo defaultValue{};
3759
3772
  ::wgpu::detail::AsNonConstReference(value.vendor) = defaultValue.vendor;
@@ -3797,10 +3810,7 @@ static_assert(offsetof(AdapterInfo, compatibilityMode) == offsetof(WGPUAdapterIn
3797
3810
  // AdapterProperties implementation
3798
3811
  AdapterProperties::AdapterProperties() = default;
3799
3812
  AdapterProperties::~AdapterProperties() {
3800
- if (this->vendorName != nullptr || this->architecture != nullptr || this->name != nullptr || this->driverDescription != nullptr) {
3801
- wgpuDawnWireClientAdapterPropertiesFreeMembers(
3802
- *reinterpret_cast<WGPUAdapterProperties*>(this));
3803
- }
3813
+ FreeMembers();
3804
3814
  }
3805
3815
 
3806
3816
  AdapterProperties::AdapterProperties(AdapterProperties&& rhs)
@@ -3820,7 +3830,7 @@ AdapterProperties& AdapterProperties::operator=(AdapterProperties&& rhs) {
3820
3830
  if (&rhs == this) {
3821
3831
  return *this;
3822
3832
  }
3823
- this->~AdapterProperties();
3833
+ FreeMembers();
3824
3834
  ::wgpu::detail::AsNonConstReference(this->vendorID) = std::move(rhs.vendorID);
3825
3835
  ::wgpu::detail::AsNonConstReference(this->vendorName) = std::move(rhs.vendorName);
3826
3836
  ::wgpu::detail::AsNonConstReference(this->architecture) = std::move(rhs.architecture);
@@ -3834,7 +3844,14 @@ AdapterProperties& AdapterProperties::operator=(AdapterProperties&& rhs) {
3834
3844
  return *this;
3835
3845
  }
3836
3846
 
3837
- // static
3847
+ void AdapterProperties::FreeMembers() {
3848
+ if (this->vendorName != nullptr || this->architecture != nullptr || this->name != nullptr || this->driverDescription != nullptr) {
3849
+ wgpuDawnWireClientAdapterPropertiesFreeMembers(
3850
+ *reinterpret_cast<WGPUAdapterProperties*>(this));
3851
+ }
3852
+ }
3853
+
3854
+ // static
3838
3855
  void AdapterProperties::Reset(AdapterProperties& value) {
3839
3856
  AdapterProperties defaultValue{};
3840
3857
  ::wgpu::detail::AsNonConstReference(value.vendorID) = defaultValue.vendorID;
@@ -5246,10 +5263,7 @@ static_assert(offsetof(SharedBufferMemoryDescriptor, label) == offsetof(WGPUShar
5246
5263
  // SharedBufferMemoryEndAccessState implementation
5247
5264
  SharedBufferMemoryEndAccessState::SharedBufferMemoryEndAccessState() = default;
5248
5265
  SharedBufferMemoryEndAccessState::~SharedBufferMemoryEndAccessState() {
5249
- if (this->fences != nullptr || this->signaledValues != nullptr) {
5250
- wgpuDawnWireClientSharedBufferMemoryEndAccessStateFreeMembers(
5251
- *reinterpret_cast<WGPUSharedBufferMemoryEndAccessState*>(this));
5252
- }
5266
+ FreeMembers();
5253
5267
  }
5254
5268
 
5255
5269
  SharedBufferMemoryEndAccessState::SharedBufferMemoryEndAccessState(SharedBufferMemoryEndAccessState&& rhs)
@@ -5264,7 +5278,7 @@ SharedBufferMemoryEndAccessState& SharedBufferMemoryEndAccessState::operator=(Sh
5264
5278
  if (&rhs == this) {
5265
5279
  return *this;
5266
5280
  }
5267
- this->~SharedBufferMemoryEndAccessState();
5281
+ FreeMembers();
5268
5282
  ::wgpu::detail::AsNonConstReference(this->initialized) = std::move(rhs.initialized);
5269
5283
  ::wgpu::detail::AsNonConstReference(this->fenceCount) = std::move(rhs.fenceCount);
5270
5284
  ::wgpu::detail::AsNonConstReference(this->fences) = std::move(rhs.fences);
@@ -5273,7 +5287,14 @@ SharedBufferMemoryEndAccessState& SharedBufferMemoryEndAccessState::operator=(Sh
5273
5287
  return *this;
5274
5288
  }
5275
5289
 
5276
- // static
5290
+ void SharedBufferMemoryEndAccessState::FreeMembers() {
5291
+ if (this->fences != nullptr || this->signaledValues != nullptr) {
5292
+ wgpuDawnWireClientSharedBufferMemoryEndAccessStateFreeMembers(
5293
+ *reinterpret_cast<WGPUSharedBufferMemoryEndAccessState*>(this));
5294
+ }
5295
+ }
5296
+
5297
+ // static
5277
5298
  void SharedBufferMemoryEndAccessState::Reset(SharedBufferMemoryEndAccessState& value) {
5278
5299
  SharedBufferMemoryEndAccessState defaultValue{};
5279
5300
  ::wgpu::detail::AsNonConstReference(value.initialized) = defaultValue.initialized;
@@ -5700,10 +5721,7 @@ static_assert(offsetof(SharedTextureMemoryDmaBufPlane, stride) == offsetof(WGPUS
5700
5721
  // SharedTextureMemoryEndAccessState implementation
5701
5722
  SharedTextureMemoryEndAccessState::SharedTextureMemoryEndAccessState() = default;
5702
5723
  SharedTextureMemoryEndAccessState::~SharedTextureMemoryEndAccessState() {
5703
- if (this->fences != nullptr || this->signaledValues != nullptr) {
5704
- wgpuDawnWireClientSharedTextureMemoryEndAccessStateFreeMembers(
5705
- *reinterpret_cast<WGPUSharedTextureMemoryEndAccessState*>(this));
5706
- }
5724
+ FreeMembers();
5707
5725
  }
5708
5726
 
5709
5727
  SharedTextureMemoryEndAccessState::SharedTextureMemoryEndAccessState(SharedTextureMemoryEndAccessState&& rhs)
@@ -5718,7 +5736,7 @@ SharedTextureMemoryEndAccessState& SharedTextureMemoryEndAccessState::operator=(
5718
5736
  if (&rhs == this) {
5719
5737
  return *this;
5720
5738
  }
5721
- this->~SharedTextureMemoryEndAccessState();
5739
+ FreeMembers();
5722
5740
  ::wgpu::detail::AsNonConstReference(this->initialized) = std::move(rhs.initialized);
5723
5741
  ::wgpu::detail::AsNonConstReference(this->fenceCount) = std::move(rhs.fenceCount);
5724
5742
  ::wgpu::detail::AsNonConstReference(this->fences) = std::move(rhs.fences);
@@ -5727,7 +5745,14 @@ SharedTextureMemoryEndAccessState& SharedTextureMemoryEndAccessState::operator=(
5727
5745
  return *this;
5728
5746
  }
5729
5747
 
5730
- // static
5748
+ void SharedTextureMemoryEndAccessState::FreeMembers() {
5749
+ if (this->fences != nullptr || this->signaledValues != nullptr) {
5750
+ wgpuDawnWireClientSharedTextureMemoryEndAccessStateFreeMembers(
5751
+ *reinterpret_cast<WGPUSharedTextureMemoryEndAccessState*>(this));
5752
+ }
5753
+ }
5754
+
5755
+ // static
5731
5756
  void SharedTextureMemoryEndAccessState::Reset(SharedTextureMemoryEndAccessState& value) {
5732
5757
  SharedTextureMemoryEndAccessState defaultValue{};
5733
5758
  ::wgpu::detail::AsNonConstReference(value.initialized) = defaultValue.initialized;
@@ -5938,10 +5963,7 @@ static_assert(offsetof(StorageTextureBindingLayout, viewDimension) == offsetof(W
5938
5963
  // SurfaceCapabilities implementation
5939
5964
  SurfaceCapabilities::SurfaceCapabilities() = default;
5940
5965
  SurfaceCapabilities::~SurfaceCapabilities() {
5941
- if (this->formats != nullptr || this->presentModes != nullptr || this->alphaModes != nullptr) {
5942
- wgpuDawnWireClientSurfaceCapabilitiesFreeMembers(
5943
- *reinterpret_cast<WGPUSurfaceCapabilities*>(this));
5944
- }
5966
+ FreeMembers();
5945
5967
  }
5946
5968
 
5947
5969
  SurfaceCapabilities::SurfaceCapabilities(SurfaceCapabilities&& rhs)
@@ -5959,7 +5981,7 @@ SurfaceCapabilities& SurfaceCapabilities::operator=(SurfaceCapabilities&& rhs) {
5959
5981
  if (&rhs == this) {
5960
5982
  return *this;
5961
5983
  }
5962
- this->~SurfaceCapabilities();
5984
+ FreeMembers();
5963
5985
  ::wgpu::detail::AsNonConstReference(this->usages) = std::move(rhs.usages);
5964
5986
  ::wgpu::detail::AsNonConstReference(this->formatCount) = std::move(rhs.formatCount);
5965
5987
  ::wgpu::detail::AsNonConstReference(this->formats) = std::move(rhs.formats);
@@ -5971,7 +5993,14 @@ SurfaceCapabilities& SurfaceCapabilities::operator=(SurfaceCapabilities&& rhs) {
5971
5993
  return *this;
5972
5994
  }
5973
5995
 
5974
- // static
5996
+ void SurfaceCapabilities::FreeMembers() {
5997
+ if (this->formats != nullptr || this->presentModes != nullptr || this->alphaModes != nullptr) {
5998
+ wgpuDawnWireClientSurfaceCapabilitiesFreeMembers(
5999
+ *reinterpret_cast<WGPUSurfaceCapabilities*>(this));
6000
+ }
6001
+ }
6002
+
6003
+ // static
5975
6004
  void SurfaceCapabilities::Reset(SurfaceCapabilities& value) {
5976
6005
  SurfaceCapabilities defaultValue{};
5977
6006
  ::wgpu::detail::AsNonConstReference(value.usages) = defaultValue.usages;
@@ -6461,10 +6490,7 @@ AdapterPropertiesMemoryHeaps::AdapterPropertiesMemoryHeaps(AdapterPropertiesMemo
6461
6490
  heapCount(std::move(init.heapCount)),
6462
6491
  heapInfo(std::move(init.heapInfo)){}
6463
6492
  AdapterPropertiesMemoryHeaps::~AdapterPropertiesMemoryHeaps() {
6464
- if (this->heapInfo != nullptr) {
6465
- wgpuDawnWireClientAdapterPropertiesMemoryHeapsFreeMembers(
6466
- *reinterpret_cast<WGPUAdapterPropertiesMemoryHeaps*>(this));
6467
- }
6493
+ FreeMembers();
6468
6494
  }
6469
6495
 
6470
6496
  AdapterPropertiesMemoryHeaps::AdapterPropertiesMemoryHeaps(AdapterPropertiesMemoryHeaps&& rhs)
@@ -6477,14 +6503,21 @@ AdapterPropertiesMemoryHeaps& AdapterPropertiesMemoryHeaps::operator=(AdapterPro
6477
6503
  if (&rhs == this) {
6478
6504
  return *this;
6479
6505
  }
6480
- this->~AdapterPropertiesMemoryHeaps();
6506
+ FreeMembers();
6481
6507
  ::wgpu::detail::AsNonConstReference(this->heapCount) = std::move(rhs.heapCount);
6482
6508
  ::wgpu::detail::AsNonConstReference(this->heapInfo) = std::move(rhs.heapInfo);
6483
6509
  Reset(rhs);
6484
6510
  return *this;
6485
6511
  }
6486
6512
 
6487
- // static
6513
+ void AdapterPropertiesMemoryHeaps::FreeMembers() {
6514
+ if (this->heapInfo != nullptr) {
6515
+ wgpuDawnWireClientAdapterPropertiesMemoryHeapsFreeMembers(
6516
+ *reinterpret_cast<WGPUAdapterPropertiesMemoryHeaps*>(this));
6517
+ }
6518
+ }
6519
+
6520
+ // static
6488
6521
  void AdapterPropertiesMemoryHeaps::Reset(AdapterPropertiesMemoryHeaps& value) {
6489
6522
  AdapterPropertiesMemoryHeaps defaultValue{};
6490
6523
  ::wgpu::detail::AsNonConstReference(value.heapCount) = defaultValue.heapCount;
@@ -6631,10 +6664,7 @@ DrmFormatCapabilities::DrmFormatCapabilities(DrmFormatCapabilities::Init&& init)
6631
6664
  propertiesCount(std::move(init.propertiesCount)),
6632
6665
  properties(std::move(init.properties)){}
6633
6666
  DrmFormatCapabilities::~DrmFormatCapabilities() {
6634
- if (this->properties != nullptr) {
6635
- wgpuDawnWireClientDrmFormatCapabilitiesFreeMembers(
6636
- *reinterpret_cast<WGPUDrmFormatCapabilities*>(this));
6637
- }
6667
+ FreeMembers();
6638
6668
  }
6639
6669
 
6640
6670
  DrmFormatCapabilities::DrmFormatCapabilities(DrmFormatCapabilities&& rhs)
@@ -6647,14 +6677,21 @@ DrmFormatCapabilities& DrmFormatCapabilities::operator=(DrmFormatCapabilities&&
6647
6677
  if (&rhs == this) {
6648
6678
  return *this;
6649
6679
  }
6650
- this->~DrmFormatCapabilities();
6680
+ FreeMembers();
6651
6681
  ::wgpu::detail::AsNonConstReference(this->propertiesCount) = std::move(rhs.propertiesCount);
6652
6682
  ::wgpu::detail::AsNonConstReference(this->properties) = std::move(rhs.properties);
6653
6683
  Reset(rhs);
6654
6684
  return *this;
6655
6685
  }
6656
6686
 
6657
- // static
6687
+ void DrmFormatCapabilities::FreeMembers() {
6688
+ if (this->properties != nullptr) {
6689
+ wgpuDawnWireClientDrmFormatCapabilitiesFreeMembers(
6690
+ *reinterpret_cast<WGPUDrmFormatCapabilities*>(this));
6691
+ }
6692
+ }
6693
+
6694
+ // static
6658
6695
  void DrmFormatCapabilities::Reset(DrmFormatCapabilities& value) {
6659
6696
  DrmFormatCapabilities defaultValue{};
6660
6697
  ::wgpu::detail::AsNonConstReference(value.propertiesCount) = defaultValue.propertiesCount;
@@ -3,7 +3,7 @@
3
3
  //
4
4
  #include "RNFHybridObject.h"
5
5
  #include "RNFJSIConverter.h"
6
- #include "Logger.h"
6
+ #include "WGPULogger.h"
7
7
 
8
8
  #include <vector>
9
9
  #include <utility>
@@ -5,7 +5,7 @@
5
5
  #pragma once
6
6
 
7
7
  #include "RNFJSIConverter.h"
8
- #include "Logger.h"
8
+ #include "WGPULogger.h"
9
9
  #include "RNFWorkletRuntimeRegistry.h"
10
10
  #include <functional>
11
11
  #include <jsi/jsi.h>
@@ -74,11 +74,11 @@ private:
74
74
  std::unordered_map<std::string, jsi::HostFunctionType> _getters;
75
75
  std::unordered_map<std::string, jsi::HostFunctionType> _setters;
76
76
  std::unordered_map<jsi::Runtime*, std::unordered_map<std::string, std::shared_ptr<jsi::Function>>> _functionCache;
77
- // Store a pointer to the runtime. Needed for checking if the runtime is still active, see WorkletRuntimeRegistry.
78
- jsi::Runtime* _creationRuntime = nullptr;
79
77
 
80
78
  protected:
81
79
  const char* _name = TAG;
80
+ // Store a pointer to the runtime. Needed for checking if the runtime is still active, see WorkletRuntimeRegistry.
81
+ jsi::Runtime* _creationRuntime = nullptr;
82
82
 
83
83
  private:
84
84
  inline void ensureInitialized(facebook::jsi::Runtime& runtime);
@@ -89,7 +89,7 @@ private:
89
89
  std::index_sequence<Is...>, size_t count) {
90
90
  if constexpr (std::is_same_v<ReturnType, void>) {
91
91
  // It's a void method.
92
- (obj->*method)(JSIConverter<std::decay_t<Args>>::fromJSI(runtime, args[Is])...);
92
+ (obj->*method)(JSIConverter<std::decay_t<Args>>::fromJSI(runtime, args[Is], Is >= count)...);
93
93
  return jsi::Value::undefined();
94
94
  } else {
95
95
  // It's returning some C++ type, we need to convert that to a JSI value now.
@@ -4,12 +4,6 @@
4
4
 
5
5
  #pragma once
6
6
 
7
- #include "RNFEnumMapper.h"
8
- #include "RNFHybridObject.h"
9
- #include "RNFJSIHelper.h"
10
- #include "RNFPromise.h"
11
- #include "RNFWorkletRuntimeRegistry.h"
12
- #include <jsi/jsi.h>
13
7
  #include <memory>
14
8
  #include <array>
15
9
  #include <future>
@@ -18,6 +12,18 @@
18
12
  #include <utility>
19
13
  #include <type_traits>
20
14
  #include <unordered_map>
15
+ #include <limits>
16
+ #include <variant>
17
+ #include <map>
18
+ #include <unordered_set>
19
+
20
+ #include <jsi/jsi.h>
21
+
22
+ #include "RNFEnumMapper.h"
23
+ #include "RNFHybridObject.h"
24
+ #include "RNFJSIHelper.h"
25
+ #include "RNFPromise.h"
26
+ #include "RNFWorkletRuntimeRegistry.h"
21
27
 
22
28
  #if __has_include(<cxxabi.h>)
23
29
  #include <cxxabi.h>
@@ -72,26 +78,64 @@ template <> struct JSIConverter<float> {
72
78
  }
73
79
  };
74
80
 
75
- // uint64_t <> BigInt
76
- template <> struct JSIConverter<uint64_t> {
77
- static double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
78
- return arg.asBigInt(runtime).asUint64(runtime);
81
+ template <> struct JSIConverter<std::nullptr_t> {
82
+ static std::nullptr_t fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
83
+ return nullptr;
79
84
  }
80
- static jsi::Value toJSI(jsi::Runtime& runtime, uint64_t arg) {
81
- return jsi::BigInt::fromUint64(runtime, arg);
85
+ static jsi::Value toJSI(jsi::Runtime&, std::nullptr_t arg) {
86
+ return jsi::Value::null();
87
+ }
88
+ };
89
+
90
+ template <typename T>
91
+ struct JSIConverter<T, std::enable_if_t<!std::is_same_v<T, uint64_t> && std::is_same_v<T, size_t>>> {
92
+ static size_t fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
93
+ if (arg.isNumber()) {
94
+ double value = arg.asNumber();
95
+ return static_cast<size_t>(value);
96
+ } else {
97
+ return arg.asBigInt(runtime).asInt64(runtime);
98
+ }
99
+ }
100
+
101
+ static jsi::Value toJSI(jsi::Runtime& runtime, size_t arg) {
102
+ return jsi::Value(static_cast<double>(arg));
82
103
  }
83
104
  };
84
105
 
85
- // int64_t <> BigInt
86
- template <> struct JSIConverter<int64_t> {
106
+ // uint32_t <> double
107
+ template <> struct JSIConverter<uint32_t> {
87
108
  static double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
88
- return arg.asBigInt(runtime).asInt64(runtime);
109
+ double value = arg.asNumber();
110
+ return static_cast<uint32_t>(value);
89
111
  }
90
- static jsi::Value toJSI(jsi::Runtime& runtime, int64_t arg) {
91
- return jsi::BigInt::fromInt64(runtime, arg);
112
+ static jsi::Value toJSI(jsi::Runtime& runtime, uint32_t arg) {
113
+ return jsi::Value(static_cast<double>(arg));
92
114
  }
93
115
  };
94
116
 
117
+ // uint64_t <> BigInt
118
+ template <> struct JSIConverter<uint64_t> {
119
+ static uint64_t fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
120
+ if (arg.isNumber()) {
121
+ double value = arg.asNumber();
122
+ if (value < 0 || value > static_cast<double>(std::numeric_limits<uint64_t>::max())) {
123
+ throw jsi::JSError(runtime, "Number out of range for uint64_t");
124
+ }
125
+ return static_cast<uint64_t>(value);
126
+ } else {
127
+ return arg.asBigInt(runtime).getUint64(runtime);
128
+ }
129
+ }
130
+
131
+ static jsi::Value toJSI(jsi::Runtime& runtime, uint64_t arg) {
132
+ if (arg <= static_cast<uint64_t>(std::numeric_limits<double>::max())) {
133
+ return jsi::Value(static_cast<double>(arg));
134
+ } else {
135
+ throw jsi::JSError(runtime, "Number too large to be represented as a double");
136
+ }
137
+ }
138
+ };
95
139
 
96
140
  // bool <> boolean
97
141
  template <> struct JSIConverter<bool> {
@@ -236,6 +280,33 @@ template <typename ReturnType, typename... Args> struct JSIConverter<std::functi
236
280
  }
237
281
  };
238
282
 
283
+ // std::map<std::string, T> <> Record<string, T>
284
+ template <typename ValueType> struct JSIConverter<std::map<std::string, ValueType>> {
285
+ static std::map<std::string, ValueType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
286
+ jsi::Object object = arg.asObject(runtime);
287
+ jsi::Array propertyNames = object.getPropertyNames(runtime);
288
+ size_t length = propertyNames.size(runtime);
289
+
290
+ std::map<std::string, ValueType> map;
291
+ for (size_t i = 0; i < length; ++i) {
292
+ std::string key = propertyNames.getValueAtIndex(runtime, i).asString(runtime).utf8(runtime);
293
+ jsi::Value value = object.getProperty(runtime, key.c_str());
294
+ map.emplace(key, JSIConverter<ValueType>::fromJSI(runtime, value, outOfBound));
295
+ }
296
+ return map;
297
+ }
298
+ static jsi::Value toJSI(jsi::Runtime& runtime, const std::map<std::string, ValueType>& map) {
299
+ jsi::Object object(runtime);
300
+ for (const auto& pair : map) {
301
+ jsi::Value value = JSIConverter<ValueType>::toJSI(runtime, pair.second);
302
+ jsi::String key = jsi::String::createFromUtf8(runtime, pair.first);
303
+ object.setProperty(runtime, key, std::move(value));
304
+ }
305
+ return object;
306
+ }
307
+ };
308
+
309
+
239
310
  // std::vector<T> <> T[]
240
311
  template <typename ElementType> struct JSIConverter<std::vector<ElementType>> {
241
312
  static std::vector<ElementType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
@@ -409,4 +480,120 @@ template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_n
409
480
  }
410
481
  };
411
482
 
483
+
484
+ template <typename O, typename T>
485
+ struct JSIConverter<std::variant<std::vector<T>, std::shared_ptr<O>>> {
486
+ using Target = std::variant<std::vector<T>, std::shared_ptr<O>>;
487
+
488
+ static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
489
+ bool outOfBound) {
490
+ if (arg.isObject()) {
491
+ auto object = arg.getObject(runtime);
492
+ if (object.isArray(runtime)) {
493
+ return Target(
494
+ JSIConverter<std::vector<T>>::fromJSI(runtime, arg, outOfBound));
495
+ }
496
+ throw std::runtime_error("Invalid variant type expected array");
497
+ }
498
+ return Target(
499
+ JSIConverter<std::shared_ptr<O>>::fromJSI(runtime, arg, outOfBound));
500
+ }
501
+
502
+ static jsi::Value toJSI(jsi::Runtime &, Target arg) {
503
+ return jsi::Value::null();
504
+ }
505
+ };
506
+
507
+ template <typename O>
508
+ struct JSIConverter<std::variant<std::nullptr_t, std::shared_ptr<O>>> {
509
+ using Target = std::variant<std::nullptr_t, std::shared_ptr<O>>;
510
+
511
+ static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
512
+ bool outOfBound) {
513
+ if (arg.isNull()) {
514
+ return Target(nullptr);
515
+ }
516
+ return Target(
517
+ JSIConverter<std::shared_ptr<O>>::fromJSI(runtime, arg, outOfBound));
518
+ }
519
+
520
+ static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
521
+ if (std::holds_alternative<std::nullptr_t>(arg)) {
522
+ return jsi::Value::null();
523
+ }
524
+ return JSIConverter<std::shared_ptr<O>>::toJSI(
525
+ runtime, std::get<std::shared_ptr<O>>(arg));
526
+ }
527
+ };
528
+
529
+ template <typename O>
530
+ struct JSIConverter<std::variant<std::nullptr_t, O>,
531
+ std::enable_if_t<std::is_enum_v<O>>> {
532
+ using Target = std::variant<std::nullptr_t, O>;
533
+
534
+ static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
535
+ bool outOfBound) {
536
+ if (arg.isNull()) {
537
+ return Target(nullptr);
538
+ } else if (arg.isNumber()) {
539
+ return Target(static_cast<O>(arg.asNumber()));
540
+ }
541
+ return Target(JSIConverter<O>::fromJSI(runtime, arg, outOfBound));
542
+ }
543
+
544
+ static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
545
+ if (std::holds_alternative<std::nullptr_t>(arg)) {
546
+ return jsi::Value::null();
547
+ }
548
+ return JSIConverter<O>::toJSI(runtime, std::get<O>(arg));
549
+ }
550
+ };
551
+
552
+ // TODO: careful std::variant<O, std::nullptr_t> doesn't overload
553
+ // std::variant<std::nullptr_t, 0> (order's matter)
554
+ // variant<nullptr_t, numeric>
555
+ template <typename O>
556
+ struct JSIConverter<
557
+ std::variant<O, std::nullptr_t>,
558
+ std::enable_if_t<std::is_arithmetic_v<O> || std::is_enum_v<O>>> {
559
+ using Target = std::variant<O, std::nullptr_t>;
560
+ static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
561
+ bool outOfBound) {
562
+ if (arg.isNull()) {
563
+ return Target(nullptr);
564
+ }
565
+ if (arg.isNumber()) {
566
+ return Target(static_cast<O>(arg.asNumber()));
567
+ }
568
+ throw jsi::JSError(runtime, "Expected null or number");
569
+ }
570
+
571
+ static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
572
+ if (std::holds_alternative<std::nullptr_t>(arg)) {
573
+ return jsi::Value::null();
574
+ }
575
+ return jsi::Value(static_cast<double>(std::get<O>(arg)));
576
+ }
577
+ };
578
+
579
+ template <>
580
+ struct JSIConverter<std::unordered_set<std::string>> {
581
+ using Target = std::unordered_set<std::string>;
582
+ static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
583
+ bool outOfBound) {
584
+ throw jsi::JSError(runtime, "JSIConverter<std::unordered_set<std::string>>::fromJSI not implemented");
585
+ }
586
+
587
+ static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
588
+ auto setConstructor = runtime.global().getPropertyAsFunction(runtime, "Set");
589
+ auto set = setConstructor.callAsConstructor(runtime).asObject(runtime);
590
+ auto add = set.getPropertyAsFunction(runtime, "add");
591
+ for (const auto& value : arg) {
592
+ jsi::Value jsiValue = JSIConverter<std::string>::toJSI(runtime, value);
593
+ add.callWithThis(runtime, set, jsiValue);
594
+ }
595
+ return std::move(set);
596
+ }
597
+ };
598
+
412
599
  } // namespace margelo