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
@@ -0,0 +1,66 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+
5
+ #include "RNFJSIConverter.h"
6
+
7
+ #include "webgpu/webgpu_cpp.h"
8
+
9
+ namespace rnwgpu {
10
+
11
+ struct GPUOrigin3D {
12
+ double x = 0;
13
+ double y = 0;
14
+ double z = 0;
15
+ };
16
+
17
+ } // namespace rnwgpu
18
+
19
+ namespace margelo {
20
+
21
+ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUOrigin3D>> {
22
+ static std::shared_ptr<rnwgpu::GPUOrigin3D>
23
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
24
+ auto result = std::make_unique<rnwgpu::GPUOrigin3D>();
25
+ if (!outOfBounds && arg.isObject()) {
26
+ if (arg.getObject(runtime).isArray(runtime)) {
27
+ auto array = arg.getObject(runtime).asArray(runtime);
28
+ auto size = array.size(runtime);
29
+ if (size == 0) {
30
+ throw std::runtime_error(
31
+ "Expected an array of size >1 for GPUTExtent3D");
32
+ }
33
+ if (size > 0) {
34
+ result->x = array.getValueAtIndex(runtime, 0).asNumber();
35
+ }
36
+ if (size > 1) {
37
+ result->y = array.getValueAtIndex(runtime, 1).asNumber();
38
+ }
39
+ if (size > 2) {
40
+ result->z = array.getValueAtIndex(runtime, 2).asNumber();
41
+ }
42
+ } else {
43
+ auto object = arg.getObject(runtime);
44
+ if (object.hasProperty(runtime, "x")) {
45
+ result->x = object.getProperty(runtime, "x").asNumber();
46
+ }
47
+ if (object.hasProperty(runtime, "y")) {
48
+ result->y = object.getProperty(runtime, "y").asNumber();
49
+ }
50
+ if (object.hasProperty(runtime, "z")) {
51
+ result->z = object.getProperty(runtime, "z").asNumber();
52
+ }
53
+ }
54
+ } else {
55
+ throw std::runtime_error("Expected an object for GPUOrigin3D");
56
+ }
57
+ return result;
58
+ }
59
+ static jsi::Value toJSI(jsi::Runtime &runtime,
60
+ std::shared_ptr<rnwgpu::GPUOrigin3D> arg) {
61
+ // No conversions here
62
+ return jsi::Value::null();
63
+ }
64
+ };
65
+
66
+ } // 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
 
@@ -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", &GPUPipelineLayout::getBrand, this);
30
33
 
31
34
  registerHybridGetter("label", &GPUPipelineLayout::getLabel, this);
35
+ registerHybridSetter("label", &GPUPipelineLayout::setLabel, this);
32
36
  }
33
37
 
38
+ inline const wgpu::PipelineLayout get() { return _instance; }
39
+
34
40
  private:
35
41
  wgpu::PipelineLayout _instance;
36
42
  std::string _label;
37
43
  };
44
+
38
45
  } // namespace rnwgpu
@@ -0,0 +1,11 @@
1
+ #include "GPUQuerySet.h"
2
+
3
+ namespace rnwgpu {
4
+
5
+ void GPUQuerySet::destroy() { _instance.Destroy(); }
6
+
7
+ wgpu::QueryType GPUQuerySet::getType() { return _instance.GetType(); }
8
+
9
+ uint32_t GPUQuerySet::getCount() { return _instance.GetCount(); }
10
+
11
+ } // 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
 
@@ -23,16 +22,31 @@ public:
23
22
  public:
24
23
  std::string getBrand() { return _name; }
25
24
 
25
+ void destroy();
26
+
27
+ wgpu::QueryType getType();
28
+ uint32_t getCount();
29
+
26
30
  std::string getLabel() { return _label; }
31
+ void setLabel(const std::string &label) {
32
+ _label = label;
33
+ _instance.SetLabel(_label.c_str());
34
+ }
27
35
 
28
36
  void loadHybridMethods() override {
29
37
  registerHybridGetter("__brand", &GPUQuerySet::getBrand, this);
30
-
38
+ registerHybridMethod("destroy", &GPUQuerySet::destroy, this);
39
+ registerHybridGetter("type", &GPUQuerySet::getType, this);
40
+ registerHybridGetter("count", &GPUQuerySet::getCount, this);
31
41
  registerHybridGetter("label", &GPUQuerySet::getLabel, this);
42
+ registerHybridSetter("label", &GPUQuerySet::setLabel, this);
32
43
  }
33
44
 
45
+ inline const wgpu::QuerySet get() { return _instance; }
46
+
34
47
  private:
35
48
  wgpu::QuerySet _instance;
36
49
  std::string _label;
37
50
  };
51
+
38
52
  } // namespace rnwgpu
@@ -0,0 +1,153 @@
1
+ #include "GPUQueue.h"
2
+
3
+ #include <limits>
4
+
5
+ #include "Convertors.h"
6
+
7
+ namespace rnwgpu {
8
+
9
+ struct BufferSource {
10
+ void *data;
11
+ size_t size; // in bytes
12
+ size_t bytesPerElement; // 1 for ArrayBuffers
13
+ };
14
+
15
+ void GPUQueue::submit(
16
+ std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers) {
17
+ std::vector<wgpu::CommandBuffer> bufs(commandBuffers.size());
18
+ for (size_t i = 0; i < commandBuffers.size(); i++) {
19
+ bufs[i] = commandBuffers[i]->get();
20
+ }
21
+ Convertor conv;
22
+ uint32_t bufs_size;
23
+ if (!conv(bufs_size, bufs.size())) {
24
+ return;
25
+ }
26
+ _instance.Submit(bufs_size, bufs.data());
27
+ }
28
+
29
+ void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
30
+ uint64_t bufferOffset,
31
+ std::shared_ptr<ArrayBuffer> data,
32
+ std::optional<uint64_t> dataOffsetElements,
33
+ std::optional<size_t> sizeElements) {
34
+ wgpu::Buffer buf = buffer->get();
35
+ BufferSource src{.data = data->_data,
36
+ .size = data->_size,
37
+ .bytesPerElement = data->_bytesPerElement};
38
+
39
+ // Note that in the JS semantics of WebGPU, writeBuffer works in number of
40
+ // elements of the typed arrays.
41
+ if (dataOffsetElements > uint64_t(src.size / src.bytesPerElement)) {
42
+ throw std::runtime_error("dataOffset is larger than data's size.");
43
+ return;
44
+ }
45
+ uint64_t dataOffset = dataOffsetElements.value_or(0) * src.bytesPerElement;
46
+ src.data = reinterpret_cast<uint8_t *>(src.data) + dataOffset;
47
+ src.size -= dataOffset;
48
+
49
+ // Size defaults to dataSize - dataOffset. Instead of computing in elements,
50
+ // we directly use it in bytes, and convert the provided value, if any, in
51
+ // bytes.
52
+ uint64_t size64 = uint64_t(src.size);
53
+ if (sizeElements.has_value()) {
54
+ if (sizeElements.value() >
55
+ std::numeric_limits<uint64_t>::max() / src.bytesPerElement) {
56
+ throw std::runtime_error("size overflows.");
57
+ return;
58
+ }
59
+ size64 = sizeElements.value() * src.bytesPerElement;
60
+ }
61
+
62
+ if (size64 > uint64_t(src.size)) {
63
+ throw std::runtime_error("size + dataOffset is larger than data's size.");
64
+ return;
65
+ }
66
+
67
+ if (size64 % 4 != 0) {
68
+ throw std::runtime_error("size is not a multiple of 4 bytes.");
69
+
70
+ return;
71
+ }
72
+
73
+ assert(size64 <= std::numeric_limits<size_t>::max());
74
+ _instance.WriteBuffer(buf, bufferOffset, src.data,
75
+ static_cast<size_t>(size64));
76
+ }
77
+
78
+ std::future<void> GPUQueue::onSubmittedWorkDone() {
79
+ return _async->runAsync([=] {
80
+ return _instance.OnSubmittedWorkDone(
81
+ wgpu::CallbackMode::WaitAnyOnly,
82
+ [](wgpu::QueueWorkDoneStatus status) {});
83
+ });
84
+ }
85
+
86
+ void GPUQueue::copyExternalImageToTexture(
87
+ std::shared_ptr<GPUImageCopyExternalImage> source,
88
+ std::shared_ptr<GPUImageCopyTextureTagged> destination,
89
+ std::shared_ptr<GPUExtent3D> size) {
90
+ wgpu::ImageCopyTexture dst{};
91
+ wgpu::TextureDataLayout layout{};
92
+ wgpu::Extent3D sz{};
93
+ Convertor conv;
94
+ uint32_t bytesPerPixel =
95
+ source->source->getSize() /
96
+ (source->source->getWidth() * source->source->getHeight());
97
+ auto dataLayout = std::make_shared<GPUImageDataLayout>(GPUImageDataLayout{
98
+ std::optional<double>{0.0},
99
+ std::optional<double>{
100
+ static_cast<double>(bytesPerPixel * source->source->getWidth())},
101
+ std::optional<double>{static_cast<double>(source->source->getHeight())}});
102
+ if (!conv(dst.aspect, destination->aspect) ||
103
+ !conv(dst.mipLevel, destination->mipLevel) ||
104
+ !conv(dst.origin, destination->origin) ||
105
+ !conv(dst.texture, destination->texture) ||
106
+ !conv(layout, dataLayout) || //
107
+ !conv(sz, size)) {
108
+ throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
109
+ }
110
+
111
+ if (source->flipY) {
112
+ // Calculate the row size and total size
113
+ uint32_t rowSize = bytesPerPixel * source->source->getWidth();
114
+ uint32_t totalSize = source->source->getSize();
115
+
116
+ // Create a new buffer for the flipped data
117
+ std::vector<uint8_t> flippedData(totalSize);
118
+
119
+ // Flip the data vertically
120
+ for (uint32_t row = 0; row < source->source->getHeight(); ++row) {
121
+ std::memcpy(flippedData.data() +
122
+ (source->source->getHeight() - 1 - row) * rowSize,
123
+ static_cast<const uint8_t *>(source->source->getData()) +
124
+ row * rowSize,
125
+ rowSize);
126
+ }
127
+ // Use the flipped data for writing to texture
128
+ _instance.WriteTexture(&dst, flippedData.data(), totalSize, &layout, &sz);
129
+ } else {
130
+
131
+ _instance.WriteTexture(&dst, source->source->getData(),
132
+ source->source->getSize(), &layout, &sz);
133
+ }
134
+ }
135
+
136
+ void GPUQueue::writeTexture(std::shared_ptr<GPUImageCopyTexture> destination,
137
+ std::shared_ptr<ArrayBuffer> data,
138
+ std::shared_ptr<GPUImageDataLayout> dataLayout,
139
+ std::shared_ptr<GPUExtent3D> size) {
140
+ wgpu::ImageCopyTexture dst{};
141
+ wgpu::TextureDataLayout layout{};
142
+ wgpu::Extent3D sz{};
143
+ Convertor conv;
144
+ if (!conv(dst, destination) || //
145
+ !conv(layout, dataLayout) || //
146
+ !conv(sz, size)) {
147
+ throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
148
+ }
149
+
150
+ _instance.WriteTexture(&dst, data->_data, data->_size, &layout, &sz);
151
+ }
152
+
153
+ } // namespace rnwgpu
@@ -3,36 +3,77 @@
3
3
  #include <future>
4
4
  #include <memory>
5
5
  #include <string>
6
+ #include <vector>
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 "ArrayBuffer.h"
17
+ #include "GPUBuffer.h"
18
+ #include "GPUCommandBuffer.h"
19
+ #include "GPUImageCopyExternalImage.h"
20
+ #include "GPUImageCopyTextureTagged.h"
21
+
14
22
  namespace rnwgpu {
15
23
 
16
24
  namespace m = margelo;
17
25
 
18
26
  class GPUQueue : public m::HybridObject {
19
27
  public:
20
- explicit GPUQueue(wgpu::Queue instance, std::string label)
21
- : HybridObject("GPUQueue"), _instance(instance), _label(label) {}
28
+ explicit GPUQueue(wgpu::Queue instance, std::shared_ptr<AsyncRunner> async,
29
+ std::string label)
30
+ : HybridObject("GPUQueue"), _instance(instance), _async(async),
31
+ _label(label) {}
22
32
 
23
33
  public:
24
34
  std::string getBrand() { return _name; }
25
35
 
36
+ void submit(std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers);
37
+ std::future<void> onSubmittedWorkDone();
38
+ void writeBuffer(std::shared_ptr<GPUBuffer> buffer, uint64_t bufferOffset,
39
+ std::shared_ptr<ArrayBuffer> data,
40
+ std::optional<uint64_t> dataOffsetElements,
41
+ std::optional<size_t> sizeElements);
42
+ void writeTexture(std::shared_ptr<GPUImageCopyTexture> destination,
43
+ std::shared_ptr<ArrayBuffer> data,
44
+ std::shared_ptr<GPUImageDataLayout> dataLayout,
45
+ std::shared_ptr<GPUExtent3D> size);
46
+ void copyExternalImageToTexture(
47
+ std::shared_ptr<GPUImageCopyExternalImage> source,
48
+ std::shared_ptr<GPUImageCopyTextureTagged> destination,
49
+ std::shared_ptr<GPUExtent3D> copySize);
50
+
26
51
  std::string getLabel() { return _label; }
52
+ void setLabel(const std::string &label) {
53
+ _label = label;
54
+ _instance.SetLabel(_label.c_str());
55
+ }
27
56
 
28
57
  void loadHybridMethods() override {
29
58
  registerHybridGetter("__brand", &GPUQueue::getBrand, this);
59
+ registerHybridMethod("submit", &GPUQueue::submit, this);
60
+ registerHybridMethod("onSubmittedWorkDone", &GPUQueue::onSubmittedWorkDone,
61
+ this);
62
+ registerHybridMethod("writeBuffer", &GPUQueue::writeBuffer, this);
63
+ registerHybridMethod("writeTexture", &GPUQueue::writeTexture, this);
64
+ registerHybridMethod("copyExternalImageToTexture",
65
+ &GPUQueue::copyExternalImageToTexture, this);
30
66
 
31
67
  registerHybridGetter("label", &GPUQueue::getLabel, this);
68
+ registerHybridSetter("label", &GPUQueue::setLabel, this);
32
69
  }
33
70
 
71
+ inline const wgpu::Queue get() { return _instance; }
72
+
34
73
  private:
35
74
  wgpu::Queue _instance;
75
+ std::shared_ptr<AsyncRunner> _async;
36
76
  std::string _label;
37
77
  };
78
+
38
79
  } // 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", &GPURenderBundle::getBrand, this);
30
33
 
31
34
  registerHybridGetter("label", &GPURenderBundle::getLabel, this);
35
+ registerHybridSetter("label", &GPURenderBundle::setLabel, this);
32
36
  }
33
37
 
38
+ inline const wgpu::RenderBundle get() { return _instance; }
39
+
34
40
  private:
35
41
  wgpu::RenderBundle _instance;
36
42
  std::string _label;
37
43
  };
44
+
38
45
  } // namespace rnwgpu
@@ -0,0 +1,128 @@
1
+ #include "GPURenderBundleEncoder.h"
2
+
3
+ #include "Convertors.h"
4
+
5
+ namespace rnwgpu {
6
+
7
+ std::shared_ptr<GPURenderBundle> GPURenderBundleEncoder::finish(
8
+ std::optional<std::shared_ptr<GPURenderBundleDescriptor>> descriptor) {
9
+ wgpu::RenderBundleDescriptor desc;
10
+ Convertor conv;
11
+ if (!conv(desc, descriptor)) {
12
+ throw std::runtime_error("GPURenderBundleEncoder.finish(): couldn't get "
13
+ "GPURenderBundleDescriptor");
14
+ }
15
+ auto bundle = _instance.Finish(&desc);
16
+ return std::make_shared<GPURenderBundle>(
17
+ bundle,
18
+ descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
19
+ }
20
+
21
+ void GPURenderBundleEncoder::setPipeline(
22
+ std::shared_ptr<GPURenderPipeline> pipeline) {
23
+ _instance.SetPipeline(pipeline->get());
24
+ }
25
+
26
+ void GPURenderBundleEncoder::draw(uint32_t vertexCount,
27
+ std::optional<uint32_t> instanceCount,
28
+ std::optional<uint32_t> firstVertex,
29
+ std::optional<uint32_t> firstInstance) {
30
+ _instance.Draw(vertexCount, instanceCount.value_or(1),
31
+ firstVertex.value_or(0), firstInstance.value_or(0));
32
+ }
33
+
34
+ void GPURenderBundleEncoder::setVertexBuffer(
35
+ uint32_t slot,
36
+ std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
37
+ std::optional<uint64_t> offset, std::optional<uint64_t> size) {
38
+ Convertor conv;
39
+
40
+ wgpu::Buffer b{};
41
+ uint64_t s = wgpu::kWholeSize;
42
+ if (!conv(b, buffer) || !conv(s, size)) {
43
+ return;
44
+ }
45
+ _instance.SetVertexBuffer(slot, b, offset.value_or(0), s);
46
+ }
47
+
48
+ void GPURenderBundleEncoder::setBindGroup(
49
+ uint32_t groupIndex,
50
+ std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
51
+ std::optional<std::vector<uint32_t>> dynamicOffsets) {
52
+ auto dynOffsets = dynamicOffsets.value_or(std::vector<uint32_t>());
53
+ if (dynOffsets.size() == 0) {
54
+ if (std::holds_alternative<std::nullptr_t>(bindGroup)) {
55
+ _instance.SetBindGroup(groupIndex, nullptr, 0, nullptr);
56
+ } else {
57
+ auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
58
+ _instance.SetBindGroup(groupIndex, group->get(), 0, nullptr);
59
+ }
60
+ } else {
61
+ if (std::holds_alternative<std::nullptr_t>(bindGroup)) {
62
+ _instance.SetBindGroup(groupIndex, nullptr, dynOffsets.size(),
63
+ dynamicOffsets->data());
64
+ } else {
65
+ auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
66
+ _instance.SetBindGroup(groupIndex, group->get(), dynOffsets.size(),
67
+ dynamicOffsets->data());
68
+ }
69
+ }
70
+ }
71
+
72
+ void GPURenderBundleEncoder::setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
73
+ wgpu::IndexFormat indexFormat,
74
+ std::optional<uint64_t> offset,
75
+ std::optional<uint64_t> size) {
76
+ Convertor conv;
77
+
78
+ wgpu::Buffer b{};
79
+ wgpu::IndexFormat f{};
80
+ uint64_t o = 0;
81
+ uint64_t s = wgpu::kWholeSize;
82
+ if (!conv(b, buffer) || //
83
+ !conv(f, indexFormat) || //
84
+ !conv(o, offset) || //
85
+ !conv(s, size)) {
86
+ return;
87
+ }
88
+
89
+ _instance.SetIndexBuffer(b, f, o, s);
90
+ }
91
+
92
+ void GPURenderBundleEncoder::drawIndexed(
93
+ uint32_t indexCount, std::optional<uint32_t> instanceCount,
94
+ std::optional<uint32_t> firstIndex, std::optional<double> baseVertex,
95
+ std::optional<uint32_t> firstInstance) {
96
+ _instance.DrawIndexed(indexCount, instanceCount.value_or(1),
97
+ firstIndex.value_or(0), baseVertex.value_or(0),
98
+ firstInstance.value_or(0));
99
+ }
100
+
101
+ void GPURenderBundleEncoder::pushDebugGroup(std::string groupLabel) {
102
+ _instance.PushDebugGroup(groupLabel.c_str());
103
+ }
104
+
105
+ void GPURenderBundleEncoder::popDebugGroup() { _instance.PopDebugGroup(); }
106
+
107
+ void GPURenderBundleEncoder::insertDebugMarker(std::string markerLabel) {
108
+ _instance.InsertDebugMarker(markerLabel.c_str());
109
+ }
110
+ void GPURenderBundleEncoder::drawIndirect(
111
+ std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
112
+ Convertor conv;
113
+ wgpu::Buffer b{};
114
+ if (!conv(b, indirectBuffer)) {
115
+ return;
116
+ }
117
+ _instance.DrawIndirect(b, indirectOffset);
118
+ }
119
+ void GPURenderBundleEncoder::drawIndexedIndirect(
120
+ std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
121
+ Convertor conv;
122
+ wgpu::Buffer b{};
123
+ if (!conv(b, indirectBuffer)) {
124
+ return;
125
+ }
126
+ _instance.DrawIndexedIndirect(b, indirectOffset);
127
+ }
128
+ } // namespace rnwgpu
@@ -1,16 +1,25 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
3
  #include <memory>
4
+ #include <optional>
5
5
  #include <string>
6
+ #include <variant>
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 "GPUBindGroup.h"
18
+ #include "GPUBuffer.h"
19
+ #include "GPURenderBundle.h"
20
+ #include "GPURenderBundleDescriptor.h"
21
+ #include "GPURenderPipeline.h"
22
+
14
23
  namespace rnwgpu {
15
24
 
16
25
  namespace m = margelo;
@@ -25,16 +34,76 @@ public:
25
34
  public:
26
35
  std::string getBrand() { return _name; }
27
36
 
37
+ std::shared_ptr<GPURenderBundle>
38
+ finish(std::optional<std::shared_ptr<GPURenderBundleDescriptor>> descriptor);
39
+ void pushDebugGroup(std::string groupLabel);
40
+ void popDebugGroup();
41
+ void insertDebugMarker(std::string markerLabel);
42
+ void setBindGroup(
43
+ uint32_t index,
44
+ std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
45
+ std::optional<std::vector<uint32_t>> dynamicOffsets);
46
+ void setPipeline(std::shared_ptr<GPURenderPipeline> pipeline);
47
+ void setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
48
+ wgpu::IndexFormat indexFormat,
49
+ std::optional<uint64_t> offset,
50
+ std::optional<uint64_t> size);
51
+ void setVertexBuffer(
52
+ uint32_t slot,
53
+ std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
54
+ std::optional<uint64_t> offset, std::optional<uint64_t> size);
55
+ void draw(uint32_t vertexCount, std::optional<uint32_t> instanceCount,
56
+ std::optional<uint32_t> firstVertex,
57
+ std::optional<uint32_t> firstInstance);
58
+ void drawIndexed(uint32_t indexCount, std::optional<uint32_t> instanceCount,
59
+ std::optional<uint32_t> firstIndex,
60
+ std::optional<double> baseVertex,
61
+ std::optional<uint32_t> firstInstance);
62
+ void drawIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
63
+ uint64_t indirectOffset);
64
+ void drawIndexedIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
65
+ uint64_t indirectOffset);
66
+
28
67
  std::string getLabel() { return _label; }
68
+ void setLabel(const std::string &label) {
69
+ _label = label;
70
+ _instance.SetLabel(_label.c_str());
71
+ }
29
72
 
30
73
  void loadHybridMethods() override {
31
74
  registerHybridGetter("__brand", &GPURenderBundleEncoder::getBrand, this);
75
+ registerHybridMethod("finish", &GPURenderBundleEncoder::finish, this);
76
+ registerHybridMethod("pushDebugGroup",
77
+ &GPURenderBundleEncoder::pushDebugGroup, this);
78
+ registerHybridMethod("popDebugGroup",
79
+ &GPURenderBundleEncoder::popDebugGroup, this);
80
+ registerHybridMethod("insertDebugMarker",
81
+ &GPURenderBundleEncoder::insertDebugMarker, this);
82
+ registerHybridMethod("setBindGroup", &GPURenderBundleEncoder::setBindGroup,
83
+ this);
84
+ registerHybridMethod("setPipeline", &GPURenderBundleEncoder::setPipeline,
85
+ this);
86
+ registerHybridMethod("setIndexBuffer",
87
+ &GPURenderBundleEncoder::setIndexBuffer, this);
88
+ registerHybridMethod("setVertexBuffer",
89
+ &GPURenderBundleEncoder::setVertexBuffer, this);
90
+ registerHybridMethod("draw", &GPURenderBundleEncoder::draw, this);
91
+ registerHybridMethod("drawIndexed", &GPURenderBundleEncoder::drawIndexed,
92
+ this);
93
+ registerHybridMethod("drawIndirect", &GPURenderBundleEncoder::drawIndirect,
94
+ this);
95
+ registerHybridMethod("drawIndexedIndirect",
96
+ &GPURenderBundleEncoder::drawIndexedIndirect, this);
32
97
 
33
98
  registerHybridGetter("label", &GPURenderBundleEncoder::getLabel, this);
99
+ registerHybridSetter("label", &GPURenderBundleEncoder::setLabel, this);
34
100
  }
35
101
 
102
+ inline const wgpu::RenderBundleEncoder get() { return _instance; }
103
+
36
104
  private:
37
105
  wgpu::RenderBundleEncoder _instance;
38
106
  std::string _label;
39
107
  };
108
+
40
109
  } // namespace rnwgpu