react-native-wgpu 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +59 -14
  2. package/android/CMakeLists.txt +3 -3
  3. package/cpp/jsi/{RNFEnumMapper.h → EnumMapper.h} +2 -6
  4. package/cpp/jsi/{RNFJSIConverter.h → JSIConverter.h} +27 -110
  5. package/cpp/jsi/NativeObject.h +607 -0
  6. package/cpp/jsi/{RNFPromise.cpp → Promise.cpp} +3 -6
  7. package/cpp/jsi/{RNFPromise.h → Promise.h} +2 -5
  8. package/cpp/jsi/RuntimeAwareCache.cpp +7 -0
  9. package/cpp/jsi/RuntimeAwareCache.h +100 -0
  10. package/cpp/jsi/RuntimeLifecycleMonitor.cpp +72 -0
  11. package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
  12. package/cpp/rnwgpu/ArrayBuffer.h +8 -12
  13. package/cpp/rnwgpu/RNWebGPUManager.cpp +187 -28
  14. package/cpp/rnwgpu/RNWebGPUManager.h +7 -0
  15. package/cpp/rnwgpu/api/Canvas.h +14 -12
  16. package/cpp/rnwgpu/api/GPU.cpp +4 -6
  17. package/cpp/rnwgpu/api/GPU.h +13 -11
  18. package/cpp/rnwgpu/api/GPUAdapter.cpp +9 -9
  19. package/cpp/rnwgpu/api/GPUAdapter.h +14 -11
  20. package/cpp/rnwgpu/api/GPUAdapterInfo.h +17 -15
  21. package/cpp/rnwgpu/api/GPUBindGroup.h +11 -10
  22. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +12 -11
  23. package/cpp/rnwgpu/api/GPUBuffer.h +19 -16
  24. package/cpp/rnwgpu/api/GPUCanvasContext.h +17 -13
  25. package/cpp/rnwgpu/api/GPUCommandBuffer.h +12 -10
  26. package/cpp/rnwgpu/api/GPUCommandEncoder.h +35 -32
  27. package/cpp/rnwgpu/api/GPUCompilationInfo.h +19 -19
  28. package/cpp/rnwgpu/api/GPUCompilationMessage.h +10 -7
  29. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +28 -27
  30. package/cpp/rnwgpu/api/GPUComputePipeline.h +14 -13
  31. package/cpp/rnwgpu/api/GPUDevice.cpp +111 -95
  32. package/cpp/rnwgpu/api/GPUDevice.h +51 -43
  33. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +12 -10
  34. package/cpp/rnwgpu/api/GPUError.h +19 -29
  35. package/cpp/rnwgpu/api/GPUExtent3D.h +7 -10
  36. package/cpp/rnwgpu/api/GPUExternalTexture.h +12 -11
  37. package/cpp/rnwgpu/api/GPUInternalError.h +31 -0
  38. package/cpp/rnwgpu/api/GPUOrigin2D.h +6 -10
  39. package/cpp/rnwgpu/api/GPUOrigin3D.h +6 -10
  40. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +33 -0
  41. package/cpp/rnwgpu/api/GPUPipelineLayout.h +12 -10
  42. package/cpp/rnwgpu/api/GPUQuerySet.h +14 -12
  43. package/cpp/rnwgpu/api/GPUQueue.h +18 -17
  44. package/cpp/rnwgpu/api/GPURenderBundle.h +11 -10
  45. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +36 -33
  46. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +49 -47
  47. package/cpp/rnwgpu/api/GPURenderPipeline.h +14 -12
  48. package/cpp/rnwgpu/api/GPUSampler.h +11 -10
  49. package/cpp/rnwgpu/api/GPUShaderModule.cpp +7 -8
  50. package/cpp/rnwgpu/api/GPUShaderModule.h +13 -12
  51. package/cpp/rnwgpu/api/GPUSupportedLimits.h +73 -93
  52. package/cpp/rnwgpu/api/GPUTexture.h +24 -20
  53. package/cpp/rnwgpu/api/GPUTextureView.h +11 -10
  54. package/cpp/rnwgpu/api/GPUValidationError.h +32 -0
  55. package/cpp/rnwgpu/api/ImageBitmap.h +10 -6
  56. package/cpp/rnwgpu/api/RNWebGPU.h +21 -21
  57. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +3 -7
  58. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +7 -11
  59. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +3 -7
  60. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +3 -7
  61. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +3 -8
  62. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +3 -7
  63. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +3 -7
  64. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +3 -8
  65. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +3 -8
  66. package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +28 -32
  67. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +3 -7
  68. package/cpp/rnwgpu/api/descriptors/GPUColor.h +3 -8
  69. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +3 -7
  70. package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +18 -20
  71. package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +3 -8
  72. package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +3 -8
  73. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +3 -7
  74. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +3 -7
  75. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +3 -7
  76. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +3 -7
  77. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +3 -7
  78. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +3 -8
  79. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +3 -7
  80. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +3 -7
  81. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +3 -7
  82. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +3 -7
  83. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +3 -7
  84. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +3 -7
  85. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +3 -8
  86. package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +11 -14
  87. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +3 -8
  88. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +3 -7
  89. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +3 -8
  90. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +3 -7
  91. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +3 -8
  92. package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +3 -8
  93. package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +3 -8
  94. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +3 -8
  95. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +3 -7
  96. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +3 -7
  97. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +3 -7
  98. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +3 -7
  99. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +3 -7
  100. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +3 -8
  101. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +3 -8
  102. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +3 -8
  103. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +3 -7
  104. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +3 -7
  105. package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +14 -16
  106. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +3 -8
  107. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +3 -8
  108. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +3 -8
  109. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +3 -7
  110. package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +18 -29
  111. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +3 -8
  112. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +3 -7
  113. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +3 -8
  114. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +3 -7
  115. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +3 -7
  116. package/cpp/rnwgpu/api/descriptors/Unions.h +3 -3
  117. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +10 -10
  118. package/cpp/rnwgpu/async/AsyncTaskHandle.h +2 -2
  119. package/lib/commonjs/Canvas.js +9 -14
  120. package/lib/commonjs/Canvas.js.map +1 -1
  121. package/lib/commonjs/external/ModuleProxy.js +36 -0
  122. package/lib/commonjs/external/ModuleProxy.js.map +1 -0
  123. package/lib/commonjs/external/index.js +17 -0
  124. package/lib/commonjs/external/index.js.map +1 -0
  125. package/lib/commonjs/external/reanimated/ReanimatedProxy.js +18 -0
  126. package/lib/commonjs/external/reanimated/ReanimatedProxy.js.map +1 -0
  127. package/lib/commonjs/external/reanimated/index.js +21 -0
  128. package/lib/commonjs/external/reanimated/index.js.map +1 -0
  129. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +50 -0
  130. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
  131. package/lib/commonjs/main/index.js +2 -142
  132. package/lib/commonjs/main/index.js.map +1 -1
  133. package/lib/module/Canvas.js +10 -16
  134. package/lib/module/Canvas.js.map +1 -1
  135. package/lib/module/external/ModuleProxy.js +28 -0
  136. package/lib/module/external/ModuleProxy.js.map +1 -0
  137. package/lib/module/external/index.js +2 -0
  138. package/lib/module/external/index.js.map +1 -0
  139. package/lib/module/external/reanimated/ReanimatedProxy.js +12 -0
  140. package/lib/module/external/reanimated/ReanimatedProxy.js.map +1 -0
  141. package/lib/module/external/reanimated/index.js +3 -0
  142. package/lib/module/external/reanimated/index.js.map +1 -0
  143. package/lib/module/external/reanimated/registerWebGPUForReanimated.js +43 -0
  144. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
  145. package/lib/module/main/index.js +2 -141
  146. package/lib/module/main/index.js.map +1 -1
  147. package/lib/typescript/babel.config.d.ts +1 -0
  148. package/lib/typescript/lib/commonjs/Canvas.d.ts +5 -1
  149. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  150. package/lib/typescript/lib/commonjs/external/ModuleProxy.d.ts +12 -0
  151. package/lib/typescript/lib/commonjs/external/ModuleProxy.d.ts.map +1 -0
  152. package/lib/typescript/lib/commonjs/external/index.d.ts +2 -0
  153. package/lib/typescript/lib/commonjs/external/index.d.ts.map +1 -0
  154. package/lib/typescript/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts +6 -0
  155. package/lib/typescript/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
  156. package/lib/typescript/lib/commonjs/external/reanimated/index.d.ts +4 -0
  157. package/lib/typescript/lib/commonjs/external/reanimated/index.d.ts.map +1 -0
  158. package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts +9 -0
  159. package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
  160. package/lib/typescript/lib/module/Canvas.d.ts +6 -1
  161. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  162. package/lib/typescript/lib/module/external/ModuleProxy.d.ts +7 -0
  163. package/lib/typescript/lib/module/external/ModuleProxy.d.ts.map +1 -0
  164. package/lib/typescript/lib/module/external/index.d.ts +2 -0
  165. package/lib/typescript/lib/module/external/index.d.ts.map +1 -0
  166. package/lib/typescript/lib/module/external/reanimated/ReanimatedProxy.d.ts +5 -0
  167. package/lib/typescript/lib/module/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
  168. package/lib/typescript/lib/module/external/reanimated/index.d.ts +3 -0
  169. package/lib/typescript/lib/module/external/reanimated/index.d.ts.map +1 -0
  170. package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts +2 -0
  171. package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
  172. package/lib/typescript/src/Canvas.d.ts +4 -2
  173. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  174. package/lib/typescript/src/external/ModuleProxy.d.ts +11 -0
  175. package/lib/typescript/src/external/ModuleProxy.d.ts.map +1 -0
  176. package/lib/typescript/src/external/index.d.ts +2 -0
  177. package/lib/typescript/src/external/index.d.ts.map +1 -0
  178. package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts +4 -0
  179. package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
  180. package/lib/typescript/src/external/reanimated/index.d.ts +3 -0
  181. package/lib/typescript/src/external/reanimated/index.d.ts.map +1 -0
  182. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +8 -0
  183. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
  184. package/package.json +15 -2
  185. package/src/Canvas.tsx +16 -22
  186. package/src/external/ModuleProxy.ts +30 -0
  187. package/src/external/index.ts +1 -0
  188. package/src/external/reanimated/ReanimatedProxy.ts +19 -0
  189. package/src/external/reanimated/index.ts +2 -0
  190. package/src/external/reanimated/registerWebGPUForReanimated.ts +43 -0
  191. package/src/main/index.tsx +3 -170
  192. package/cpp/jsi/RNFHybridObject.cpp +0 -150
  193. package/cpp/jsi/RNFHybridObject.h +0 -181
  194. package/cpp/jsi/RNFJSIHelper.h +0 -51
  195. package/cpp/jsi/RNFPointerHolder.h +0 -95
  196. package/cpp/jsi/RNFRuntimeState.cpp +0 -18
  197. package/cpp/jsi/RNFRuntimeState.h +0 -106
@@ -8,7 +8,7 @@
8
8
 
9
9
  #include "Unions.h"
10
10
 
11
- #include "RNFHybridObject.h"
11
+ #include "NativeObject.h"
12
12
 
13
13
  #include "webgpu/webgpu_cpp.h"
14
14
 
@@ -18,17 +18,18 @@
18
18
 
19
19
  namespace rnwgpu {
20
20
 
21
- namespace m = margelo;
21
+ namespace jsi = facebook::jsi;
22
22
 
23
- class GPUComputePassEncoder : public m::HybridObject {
23
+ class GPUComputePassEncoder : public NativeObject<GPUComputePassEncoder> {
24
24
  public:
25
+ static constexpr const char *CLASS_NAME = "GPUComputePassEncoder";
26
+
25
27
  explicit GPUComputePassEncoder(wgpu::ComputePassEncoder instance,
26
28
  std::string label)
27
- : HybridObject("GPUComputePassEncoder"), _instance(instance),
28
- _label(label) {}
29
+ : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
29
30
 
30
31
  public:
31
- std::string getBrand() { return _name; }
32
+ std::string getBrand() { return CLASS_NAME; }
32
33
 
33
34
  void setPipeline(std::shared_ptr<GPUComputePipeline> pipeline);
34
35
  void dispatchWorkgroups(uint32_t workgroupCountX,
@@ -51,27 +52,27 @@ public:
51
52
  _instance.SetLabel(_label.c_str());
52
53
  }
53
54
 
54
- void loadHybridMethods() override {
55
- registerHybridGetter("__brand", &GPUComputePassEncoder::getBrand, this);
56
- registerHybridMethod("setPipeline", &GPUComputePassEncoder::setPipeline,
57
- this);
58
- registerHybridMethod("dispatchWorkgroups",
59
- &GPUComputePassEncoder::dispatchWorkgroups, this);
60
- registerHybridMethod("dispatchWorkgroupsIndirect",
61
- &GPUComputePassEncoder::dispatchWorkgroupsIndirect,
62
- this);
63
- registerHybridMethod("end", &GPUComputePassEncoder::end, this);
64
- registerHybridMethod("pushDebugGroup",
65
- &GPUComputePassEncoder::pushDebugGroup, this);
66
- registerHybridMethod("popDebugGroup", &GPUComputePassEncoder::popDebugGroup,
67
- this);
68
- registerHybridMethod("insertDebugMarker",
69
- &GPUComputePassEncoder::insertDebugMarker, this);
70
- registerHybridMethod("setBindGroup", &GPUComputePassEncoder::setBindGroup,
71
- this);
72
-
73
- registerHybridGetter("label", &GPUComputePassEncoder::getLabel, this);
74
- registerHybridSetter("label", &GPUComputePassEncoder::setLabel, this);
55
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
56
+ installGetter(runtime, prototype, "__brand",
57
+ &GPUComputePassEncoder::getBrand);
58
+ installMethod(runtime, prototype, "setPipeline",
59
+ &GPUComputePassEncoder::setPipeline);
60
+ installMethod(runtime, prototype, "dispatchWorkgroups",
61
+ &GPUComputePassEncoder::dispatchWorkgroups);
62
+ installMethod(runtime, prototype, "dispatchWorkgroupsIndirect",
63
+ &GPUComputePassEncoder::dispatchWorkgroupsIndirect);
64
+ installMethod(runtime, prototype, "end", &GPUComputePassEncoder::end);
65
+ installMethod(runtime, prototype, "pushDebugGroup",
66
+ &GPUComputePassEncoder::pushDebugGroup);
67
+ installMethod(runtime, prototype, "popDebugGroup",
68
+ &GPUComputePassEncoder::popDebugGroup);
69
+ installMethod(runtime, prototype, "insertDebugMarker",
70
+ &GPUComputePassEncoder::insertDebugMarker);
71
+ installMethod(runtime, prototype, "setBindGroup",
72
+ &GPUComputePassEncoder::setBindGroup);
73
+ installGetterSetter(runtime, prototype, "label",
74
+ &GPUComputePassEncoder::getLabel,
75
+ &GPUComputePassEncoder::setLabel);
75
76
  }
76
77
 
77
78
  inline const wgpu::ComputePassEncoder get() { return _instance; }
@@ -5,7 +5,7 @@
5
5
 
6
6
  #include "Unions.h"
7
7
 
8
- #include "RNFHybridObject.h"
8
+ #include "NativeObject.h"
9
9
 
10
10
  #include "webgpu/webgpu_cpp.h"
11
11
 
@@ -13,16 +13,17 @@
13
13
 
14
14
  namespace rnwgpu {
15
15
 
16
- namespace m = margelo;
16
+ namespace jsi = facebook::jsi;
17
17
 
18
- class GPUComputePipeline : public m::HybridObject {
18
+ class GPUComputePipeline : public NativeObject<GPUComputePipeline> {
19
19
  public:
20
+ static constexpr const char *CLASS_NAME = "GPUComputePipeline";
21
+
20
22
  explicit GPUComputePipeline(wgpu::ComputePipeline instance, std::string label)
21
- : HybridObject("GPUComputePipeline"), _instance(instance), _label(label) {
22
- }
23
+ : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
23
24
 
24
25
  public:
25
- std::string getBrand() { return _name; }
26
+ std::string getBrand() { return CLASS_NAME; }
26
27
 
27
28
  std::shared_ptr<GPUBindGroupLayout> getBindGroupLayout(uint32_t index);
28
29
 
@@ -32,13 +33,13 @@ public:
32
33
  _instance.SetLabel(_label.c_str());
33
34
  }
34
35
 
35
- void loadHybridMethods() override {
36
- registerHybridGetter("__brand", &GPUComputePipeline::getBrand, this);
37
- registerHybridMethod("getBindGroupLayout",
38
- &GPUComputePipeline::getBindGroupLayout, this);
39
-
40
- registerHybridGetter("label", &GPUComputePipeline::getLabel, this);
41
- registerHybridSetter("label", &GPUComputePipeline::setLabel, this);
36
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
37
+ installGetter(runtime, prototype, "__brand", &GPUComputePipeline::getBrand);
38
+ installMethod(runtime, prototype, "getBindGroupLayout",
39
+ &GPUComputePipeline::getBindGroupLayout);
40
+ installGetterSetter(runtime, prototype, "label",
41
+ &GPUComputePipeline::getLabel,
42
+ &GPUComputePipeline::setLabel);
42
43
  }
43
44
 
44
45
  inline const wgpu::ComputePipeline get() { return _instance; }
@@ -7,9 +7,12 @@
7
7
  #include <vector>
8
8
 
9
9
  #include "Convertors.h"
10
- #include "RNFJSIConverter.h"
10
+ #include "JSIConverter.h"
11
11
 
12
12
  #include "GPUFeatures.h"
13
+ #include "GPUInternalError.h"
14
+ #include "GPUOutOfMemoryError.h"
15
+ #include "GPUValidationError.h"
13
16
 
14
17
  namespace rnwgpu {
15
18
 
@@ -26,8 +29,8 @@ void GPUDevice::notifyDeviceLost(wgpu::DeviceLostReason reason,
26
29
  auto resolve = std::move(*_lostResolve);
27
30
  _lostResolve.reset();
28
31
  resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
29
- return margelo::JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
30
- runtime, info);
32
+ return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime,
33
+ info);
31
34
  });
32
35
  }
33
36
 
@@ -248,31 +251,31 @@ async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
248
251
  descriptor->label.has_value() ? descriptor->label.value() : "");
249
252
  auto pipelineHolder = std::make_shared<GPUComputePipeline>(nullptr, label);
250
253
 
251
- return _async->postTask(
252
- [device = _instance, desc, descriptor,
253
- pipelineHolder](const async::AsyncTaskHandle::ResolveFunction &resolve,
254
- const async::AsyncTaskHandle::RejectFunction &reject) {
255
- (void)descriptor;
256
- device.CreateComputePipelineAsync(
257
- &desc, wgpu::CallbackMode::AllowProcessEvents,
258
- [pipelineHolder, resolve,
259
- reject](wgpu::CreatePipelineAsyncStatus status,
260
- wgpu::ComputePipeline pipeline, const char *msg) mutable {
261
- if (status == wgpu::CreatePipelineAsyncStatus::Success &&
262
- pipeline) {
263
- pipelineHolder->_instance = pipeline;
264
- resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
265
- return margelo::
266
- JSIConverter<std::shared_ptr<GPUComputePipeline>>::toJSI(
267
- runtime, pipelineHolder);
268
- });
269
- } else {
270
- std::string error = msg ? std::string(msg)
271
- : "Failed to create compute pipeline";
272
- reject(std::move(error));
273
- }
254
+ return _async->postTask([device = _instance, desc, descriptor,
255
+ pipelineHolder](
256
+ const async::AsyncTaskHandle::ResolveFunction
257
+ &resolve,
258
+ const async::AsyncTaskHandle::RejectFunction
259
+ &reject) {
260
+ (void)descriptor;
261
+ device.CreateComputePipelineAsync(
262
+ &desc, wgpu::CallbackMode::AllowProcessEvents,
263
+ [pipelineHolder, resolve,
264
+ reject](wgpu::CreatePipelineAsyncStatus status,
265
+ wgpu::ComputePipeline pipeline, const char *msg) mutable {
266
+ if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
267
+ pipelineHolder->_instance = pipeline;
268
+ resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
269
+ return JSIConverter<std::shared_ptr<GPUComputePipeline>>::toJSI(
270
+ runtime, pipelineHolder);
274
271
  });
275
- });
272
+ } else {
273
+ std::string error =
274
+ msg ? std::string(msg) : "Failed to create compute pipeline";
275
+ reject(std::move(error));
276
+ }
277
+ });
278
+ });
276
279
  }
277
280
 
278
281
  async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
@@ -289,31 +292,31 @@ async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
289
292
  descriptor->label.has_value() ? descriptor->label.value() : "");
290
293
  auto pipelineHolder = std::make_shared<GPURenderPipeline>(nullptr, label);
291
294
 
292
- return _async->postTask(
293
- [device = _instance, desc, descriptor,
294
- pipelineHolder](const async::AsyncTaskHandle::ResolveFunction &resolve,
295
- const async::AsyncTaskHandle::RejectFunction &reject) {
296
- (void)descriptor;
297
- device.CreateRenderPipelineAsync(
298
- &desc, wgpu::CallbackMode::AllowProcessEvents,
299
- [pipelineHolder, resolve,
300
- reject](wgpu::CreatePipelineAsyncStatus status,
301
- wgpu::RenderPipeline pipeline, const char *msg) mutable {
302
- if (status == wgpu::CreatePipelineAsyncStatus::Success &&
303
- pipeline) {
304
- pipelineHolder->_instance = pipeline;
305
- resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
306
- return margelo::
307
- JSIConverter<std::shared_ptr<GPURenderPipeline>>::toJSI(
308
- runtime, pipelineHolder);
309
- });
310
- } else {
311
- std::string error =
312
- msg ? std::string(msg) : "Failed to create render pipeline";
313
- reject(std::move(error));
314
- }
295
+ return _async->postTask([device = _instance, desc, descriptor,
296
+ pipelineHolder](
297
+ const async::AsyncTaskHandle::ResolveFunction
298
+ &resolve,
299
+ const async::AsyncTaskHandle::RejectFunction
300
+ &reject) {
301
+ (void)descriptor;
302
+ device.CreateRenderPipelineAsync(
303
+ &desc, wgpu::CallbackMode::AllowProcessEvents,
304
+ [pipelineHolder, resolve,
305
+ reject](wgpu::CreatePipelineAsyncStatus status,
306
+ wgpu::RenderPipeline pipeline, const char *msg) mutable {
307
+ if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
308
+ pipelineHolder->_instance = pipeline;
309
+ resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
310
+ return JSIConverter<std::shared_ptr<GPURenderPipeline>>::toJSI(
311
+ runtime, pipelineHolder);
315
312
  });
316
- });
313
+ } else {
314
+ std::string error =
315
+ msg ? std::string(msg) : "Failed to create render pipeline";
316
+ reject(std::move(error));
317
+ }
318
+ });
319
+ });
317
320
  }
318
321
 
319
322
  void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
@@ -323,47 +326,60 @@ void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
323
326
  async::AsyncTaskHandle GPUDevice::popErrorScope() {
324
327
  auto device = _instance;
325
328
 
326
- return _async->postTask(
327
- [device](const async::AsyncTaskHandle::ResolveFunction &resolve,
328
- const async::AsyncTaskHandle::RejectFunction &reject) {
329
- device.PopErrorScope(
330
- wgpu::CallbackMode::AllowProcessEvents,
331
- [resolve, reject](wgpu::PopErrorScopeStatus status,
332
- wgpu::ErrorType type, wgpu::StringView message) {
333
- if (status == wgpu::PopErrorScopeStatus::Error ||
334
- status == wgpu::PopErrorScopeStatus::CallbackCancelled) {
335
- reject("PopErrorScope failed");
336
- return;
337
- }
338
-
339
- std::variant<std::nullptr_t, std::shared_ptr<GPUError>> result =
340
- nullptr;
341
-
342
- switch (type) {
343
- case wgpu::ErrorType::NoError:
344
- break;
345
- case wgpu::ErrorType::OutOfMemory:
346
- case wgpu::ErrorType::Validation:
347
- case wgpu::ErrorType::Internal:
348
- case wgpu::ErrorType::Unknown: {
349
- std::string messageString =
350
- message.length ? std::string(message.data, message.length)
351
- : "";
352
- result = std::make_shared<GPUError>(type, messageString);
353
- break;
354
- }
355
- default:
356
- reject("Unhandled GPU error type");
357
- return;
358
- }
359
-
360
- resolve([result =
361
- std::move(result)](jsi::Runtime &runtime) mutable {
362
- return margelo::JSIConverter<decltype(result)>::toJSI(runtime,
363
- result);
364
- });
329
+ return _async->postTask([device](const async::AsyncTaskHandle::ResolveFunction
330
+ &resolve,
331
+ const async::AsyncTaskHandle::RejectFunction
332
+ &reject) {
333
+ device.PopErrorScope(
334
+ wgpu::CallbackMode::AllowProcessEvents,
335
+ [resolve, reject](wgpu::PopErrorScopeStatus status,
336
+ wgpu::ErrorType type, wgpu::StringView message) {
337
+ if (status == wgpu::PopErrorScopeStatus::Error ||
338
+ status == wgpu::PopErrorScopeStatus::CallbackCancelled) {
339
+ reject("PopErrorScope failed");
340
+ return;
341
+ }
342
+
343
+ std::string messageString =
344
+ message.length ? std::string(message.data, message.length) : "";
345
+
346
+ switch (type) {
347
+ case wgpu::ErrorType::NoError:
348
+ resolve([](jsi::Runtime &runtime) mutable {
349
+ return jsi::Value::null();
365
350
  });
366
- });
351
+ break;
352
+ case wgpu::ErrorType::Validation: {
353
+ auto error = std::make_shared<GPUValidationError>(messageString);
354
+ resolve([error](jsi::Runtime &runtime) mutable {
355
+ return JSIConverter<std::shared_ptr<GPUValidationError>>::toJSI(
356
+ runtime, error);
357
+ });
358
+ break;
359
+ }
360
+ case wgpu::ErrorType::OutOfMemory: {
361
+ auto error = std::make_shared<GPUOutOfMemoryError>(messageString);
362
+ resolve([error](jsi::Runtime &runtime) mutable {
363
+ return JSIConverter<std::shared_ptr<GPUOutOfMemoryError>>::toJSI(
364
+ runtime, error);
365
+ });
366
+ break;
367
+ }
368
+ case wgpu::ErrorType::Internal:
369
+ case wgpu::ErrorType::Unknown: {
370
+ auto error = std::make_shared<GPUInternalError>(messageString);
371
+ resolve([error](jsi::Runtime &runtime) mutable {
372
+ return JSIConverter<std::shared_ptr<GPUInternalError>>::toJSI(
373
+ runtime, error);
374
+ });
375
+ break;
376
+ }
377
+ default:
378
+ reject("Unhandled GPU error type");
379
+ return;
380
+ }
381
+ });
382
+ });
367
383
  }
368
384
 
369
385
  std::unordered_set<std::string> GPUDevice::getFeatures() {
@@ -390,8 +406,8 @@ async::AsyncTaskHandle GPUDevice::getLost() {
390
406
  const async::AsyncTaskHandle::ResolveFunction &resolve,
391
407
  const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
392
408
  resolve([info](jsi::Runtime &runtime) mutable {
393
- return margelo::JSIConverter<
394
- std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime, info);
409
+ return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
410
+ runtime, info);
395
411
  });
396
412
  },
397
413
  false);
@@ -402,8 +418,8 @@ async::AsyncTaskHandle GPUDevice::getLost() {
402
418
  const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
403
419
  if (_lostSettled && _lostInfo) {
404
420
  resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
405
- return margelo::JSIConverter<
406
- std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime, info);
421
+ return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
422
+ runtime, info);
407
423
  });
408
424
  return;
409
425
  }
@@ -9,7 +9,7 @@
9
9
 
10
10
  #include "Unions.h"
11
11
 
12
- #include "RNFHybridObject.h"
12
+ #include "NativeObject.h"
13
13
 
14
14
  #include "rnwgpu/async/AsyncRunner.h"
15
15
  #include "rnwgpu/async/AsyncTaskHandle.h"
@@ -49,18 +49,20 @@
49
49
 
50
50
  namespace rnwgpu {
51
51
 
52
- namespace m = margelo;
52
+ namespace jsi = facebook::jsi;
53
53
 
54
- class GPUDevice : public m::HybridObject {
54
+ class GPUDevice : public NativeObject<GPUDevice> {
55
55
  public:
56
+ static constexpr const char *CLASS_NAME = "GPUDevice";
57
+
56
58
  explicit GPUDevice(wgpu::Device instance,
57
59
  std::shared_ptr<async::AsyncRunner> async,
58
60
  std::string label)
59
- : HybridObject("GPUDevice"), _instance(instance), _async(async),
61
+ : NativeObject(CLASS_NAME), _instance(instance), _async(async),
60
62
  _label(label) {}
61
63
 
62
64
  public:
63
- std::string getBrand() { return _name; }
65
+ std::string getBrand() { return CLASS_NAME; }
64
66
 
65
67
  void destroy();
66
68
  std::shared_ptr<GPUBuffer>
@@ -109,44 +111,50 @@ public:
109
111
  _instance.SetLabel(_label.c_str());
110
112
  }
111
113
 
112
- void loadHybridMethods() override {
113
- registerHybridGetter("__brand", &GPUDevice::getBrand, this);
114
- registerHybridMethod("destroy", &GPUDevice::destroy, this);
115
- registerHybridMethod("createBuffer", &GPUDevice::createBuffer, this);
116
- registerHybridMethod("createTexture", &GPUDevice::createTexture, this);
117
- registerHybridMethod("createSampler", &GPUDevice::createSampler, this);
118
- registerHybridMethod("importExternalTexture",
119
- &GPUDevice::importExternalTexture, this);
120
- registerHybridMethod("createBindGroupLayout",
121
- &GPUDevice::createBindGroupLayout, this);
122
- registerHybridMethod("createPipelineLayout",
123
- &GPUDevice::createPipelineLayout, this);
124
- registerHybridMethod("createBindGroup", &GPUDevice::createBindGroup, this);
125
- registerHybridMethod("createShaderModule", &GPUDevice::createShaderModule,
126
- this);
127
- registerHybridMethod("createComputePipeline",
128
- &GPUDevice::createComputePipeline, this);
129
- registerHybridMethod("createRenderPipeline",
130
- &GPUDevice::createRenderPipeline, this);
131
- registerHybridMethod("createComputePipelineAsync",
132
- &GPUDevice::createComputePipelineAsync, this);
133
- registerHybridMethod("createRenderPipelineAsync",
134
- &GPUDevice::createRenderPipelineAsync, this);
135
- registerHybridMethod("createCommandEncoder",
136
- &GPUDevice::createCommandEncoder, this);
137
- registerHybridMethod("createRenderBundleEncoder",
138
- &GPUDevice::createRenderBundleEncoder, this);
139
- registerHybridMethod("createQuerySet", &GPUDevice::createQuerySet, this);
140
- registerHybridMethod("pushErrorScope", &GPUDevice::pushErrorScope, this);
141
- registerHybridMethod("popErrorScope", &GPUDevice::popErrorScope, this);
142
- registerHybridGetter("features", &GPUDevice::getFeatures, this);
143
- registerHybridGetter("limits", &GPUDevice::getLimits, this);
144
- registerHybridGetter("queue", &GPUDevice::getQueue, this);
145
- registerHybridGetter("lost", &GPUDevice::getLost, this);
146
- registerHybridGetter("label", &GPUDevice::getLabel, this);
147
- registerHybridSetter("label", &GPUDevice::setLabel, this);
148
- registerHybridMethod("forceLossForTesting", &GPUDevice::forceLossForTesting,
149
- this);
114
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
115
+ installGetter(runtime, prototype, "__brand", &GPUDevice::getBrand);
116
+ installMethod(runtime, prototype, "destroy", &GPUDevice::destroy);
117
+ installMethod(runtime, prototype, "createBuffer", &GPUDevice::createBuffer);
118
+ installMethod(runtime, prototype, "createTexture",
119
+ &GPUDevice::createTexture);
120
+ installMethod(runtime, prototype, "createSampler",
121
+ &GPUDevice::createSampler);
122
+ installMethod(runtime, prototype, "importExternalTexture",
123
+ &GPUDevice::importExternalTexture);
124
+ installMethod(runtime, prototype, "createBindGroupLayout",
125
+ &GPUDevice::createBindGroupLayout);
126
+ installMethod(runtime, prototype, "createPipelineLayout",
127
+ &GPUDevice::createPipelineLayout);
128
+ installMethod(runtime, prototype, "createBindGroup",
129
+ &GPUDevice::createBindGroup);
130
+ installMethod(runtime, prototype, "createShaderModule",
131
+ &GPUDevice::createShaderModule);
132
+ installMethod(runtime, prototype, "createComputePipeline",
133
+ &GPUDevice::createComputePipeline);
134
+ installMethod(runtime, prototype, "createRenderPipeline",
135
+ &GPUDevice::createRenderPipeline);
136
+ installMethod(runtime, prototype, "createComputePipelineAsync",
137
+ &GPUDevice::createComputePipelineAsync);
138
+ installMethod(runtime, prototype, "createRenderPipelineAsync",
139
+ &GPUDevice::createRenderPipelineAsync);
140
+ installMethod(runtime, prototype, "createCommandEncoder",
141
+ &GPUDevice::createCommandEncoder);
142
+ installMethod(runtime, prototype, "createRenderBundleEncoder",
143
+ &GPUDevice::createRenderBundleEncoder);
144
+ installMethod(runtime, prototype, "createQuerySet",
145
+ &GPUDevice::createQuerySet);
146
+ installMethod(runtime, prototype, "pushErrorScope",
147
+ &GPUDevice::pushErrorScope);
148
+ installMethod(runtime, prototype, "popErrorScope",
149
+ &GPUDevice::popErrorScope);
150
+ installGetter(runtime, prototype, "features", &GPUDevice::getFeatures);
151
+ installGetter(runtime, prototype, "limits", &GPUDevice::getLimits);
152
+ installGetter(runtime, prototype, "queue", &GPUDevice::getQueue);
153
+ installGetter(runtime, prototype, "lost", &GPUDevice::getLost);
154
+ installGetterSetter(runtime, prototype, "label", &GPUDevice::getLabel,
155
+ &GPUDevice::setLabel);
156
+ installMethod(runtime, prototype, "forceLossForTesting",
157
+ &GPUDevice::forceLossForTesting);
150
158
  }
151
159
 
152
160
  inline const wgpu::Device get() { return _instance; }
@@ -4,30 +4,32 @@
4
4
 
5
5
  #include "Unions.h"
6
6
 
7
- #include "RNFHybridObject.h"
7
+ #include "NativeObject.h"
8
8
 
9
9
  #include "webgpu/webgpu_cpp.h"
10
10
 
11
11
  namespace rnwgpu {
12
12
 
13
- namespace m = margelo;
13
+ namespace jsi = facebook::jsi;
14
14
 
15
- class GPUDeviceLostInfo : public m::HybridObject {
15
+ class GPUDeviceLostInfo : public NativeObject<GPUDeviceLostInfo> {
16
16
  public:
17
+ static constexpr const char *CLASS_NAME = "GPUDeviceLostInfo";
18
+
17
19
  explicit GPUDeviceLostInfo(wgpu::DeviceLostReason reason, std::string message)
18
- : HybridObject("GPUDeviceLostInfo"), _reason(reason), _message(message) {}
20
+ : NativeObject(CLASS_NAME), _reason(reason), _message(message) {}
19
21
 
20
22
  public:
21
- std::string getBrand() { return _name; }
23
+ std::string getBrand() { return CLASS_NAME; }
22
24
 
23
25
  wgpu::DeviceLostReason getReason() { return _reason; }
24
26
  std::string getMessage() { return _message; }
25
27
 
26
- void loadHybridMethods() override {
27
- registerHybridGetter("__brand", &GPUDeviceLostInfo::getBrand, this);
28
-
29
- registerHybridGetter("reason", &GPUDeviceLostInfo::getReason, this);
30
- registerHybridGetter("message", &GPUDeviceLostInfo::getMessage, this);
28
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
29
+ installGetter(runtime, prototype, "__brand", &GPUDeviceLostInfo::getBrand);
30
+ installGetter(runtime, prototype, "reason", &GPUDeviceLostInfo::getReason);
31
+ installGetter(runtime, prototype, "message",
32
+ &GPUDeviceLostInfo::getMessage);
31
33
  }
32
34
 
33
35
  private:
@@ -1,45 +1,35 @@
1
1
  #pragma once
2
2
 
3
- #include <memory>
4
3
  #include <string>
5
- #include <utility>
6
4
 
7
- #include "webgpu/webgpu_cpp.h"
8
-
9
- #include "RNFEnumMapper.h"
10
- #include "RNFJSIConverter.h"
5
+ #include "NativeObject.h"
11
6
 
12
7
  namespace rnwgpu {
13
8
 
14
- class GPUError {
9
+ namespace jsi = facebook::jsi;
15
10
 
11
+ class GPUError : public NativeObject<GPUError> {
16
12
  public:
17
- GPUError(wgpu::ErrorType aType, std::string aMessage)
18
- : type(aType), message(std::move(aMessage)) {}
13
+ static constexpr const char *CLASS_NAME = "GPUError";
19
14
 
20
- wgpu::ErrorType type;
21
- std::string message;
22
- };
15
+ explicit GPUError(std::string message)
16
+ : NativeObject(CLASS_NAME), _message(std::move(message)) {}
23
17
 
24
- } // namespace rnwgpu
18
+ public:
19
+ std::string getBrand() { return CLASS_NAME; }
20
+ std::string getMessage() { return _message; }
25
21
 
26
- namespace margelo {
22
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
23
+ installGetter(runtime, prototype, "__brand", &GPUError::getBrand);
24
+ installGetter(runtime, prototype, "message", &GPUError::getMessage);
25
+ }
27
26
 
28
- using namespace rnwgpu; // NOLINT(build/namespaces)
27
+ protected:
28
+ // Protected constructor for subclasses
29
+ GPUError(const char *className, std::string message)
30
+ : NativeObject(className), _message(std::move(message)) {}
29
31
 
30
- template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUError>> {
31
- static std::shared_ptr<rnwgpu::GPUBindGroupEntry>
32
- fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
33
- throw std::runtime_error("Invalid GPUBindGroupEntry::fromJSI()");
34
- }
35
- static jsi::Value toJSI(jsi::Runtime &runtime,
36
- std::shared_ptr<rnwgpu::GPUError> arg) {
37
- jsi::Object result(runtime);
38
- result.setProperty(
39
- runtime, "message",
40
- jsi::String::createFromUtf8(runtime, arg->message.c_str()));
41
- return result;
42
- }
32
+ std::string _message;
43
33
  };
44
34
 
45
- } // namespace margelo
35
+ } // namespace rnwgpu