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
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include "Unions.h"
8
8
 
9
- #include "RNFHybridObject.h"
9
+ #include "NativeObject.h"
10
10
 
11
11
  #include "rnwgpu/async/AsyncRunner.h"
12
12
  #include "rnwgpu/async/AsyncTaskHandle.h"
@@ -20,16 +20,18 @@
20
20
 
21
21
  namespace rnwgpu {
22
22
 
23
- namespace m = margelo;
23
+ namespace jsi = facebook::jsi;
24
24
 
25
- class GPUAdapter : public m::HybridObject {
25
+ class GPUAdapter : public NativeObject<GPUAdapter> {
26
26
  public:
27
+ static constexpr const char *CLASS_NAME = "GPUAdapter";
28
+
27
29
  explicit GPUAdapter(wgpu::Adapter instance,
28
30
  std::shared_ptr<async::AsyncRunner> async)
29
- : HybridObject("GPUAdapter"), _instance(instance), _async(async) {}
31
+ : NativeObject(CLASS_NAME), _instance(instance), _async(async) {}
30
32
 
31
33
  public:
32
- std::string getBrand() { return _name; }
34
+ std::string getBrand() { return CLASS_NAME; }
33
35
 
34
36
  async::AsyncTaskHandle
35
37
  requestDevice(std::optional<std::shared_ptr<GPUDeviceDescriptor>> descriptor);
@@ -38,12 +40,13 @@ public:
38
40
  std::shared_ptr<GPUSupportedLimits> getLimits();
39
41
  std::shared_ptr<GPUAdapterInfo> getInfo();
40
42
 
41
- void loadHybridMethods() override {
42
- registerHybridGetter("__brand", &GPUAdapter::getBrand, this);
43
- registerHybridMethod("requestDevice", &GPUAdapter::requestDevice, this);
44
- registerHybridGetter("features", &GPUAdapter::getFeatures, this);
45
- registerHybridGetter("limits", &GPUAdapter::getLimits, this);
46
- registerHybridGetter("info", &GPUAdapter::getInfo, this);
43
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
44
+ installGetter(runtime, prototype, "__brand", &GPUAdapter::getBrand);
45
+ installMethod(runtime, prototype, "requestDevice",
46
+ &GPUAdapter::requestDevice);
47
+ installGetter(runtime, prototype, "features", &GPUAdapter::getFeatures);
48
+ installGetter(runtime, prototype, "limits", &GPUAdapter::getLimits);
49
+ installGetter(runtime, prototype, "info", &GPUAdapter::getInfo);
47
50
  }
48
51
 
49
52
  inline const wgpu::Adapter 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 "Convertors.h"
11
11
 
@@ -13,18 +13,20 @@
13
13
 
14
14
  namespace rnwgpu {
15
15
 
16
- namespace m = margelo;
16
+ namespace jsi = facebook::jsi;
17
17
 
18
- class GPUAdapterInfo : public m::HybridObject {
18
+ class GPUAdapterInfo : public NativeObject<GPUAdapterInfo> {
19
19
  public:
20
+ static constexpr const char *CLASS_NAME = "GPUAdapterInfo";
21
+
20
22
  explicit GPUAdapterInfo(wgpu::AdapterInfo &info)
21
- : HybridObject("GPUAdapterInfo"), _vendor(info.vendor),
23
+ : NativeObject(CLASS_NAME), _vendor(info.vendor),
22
24
  _architecture(info.architecture), _device(info.device),
23
25
  _description(info.description),
24
26
  _isFallbackAdapter(info.adapterType == wgpu::AdapterType::CPU) {}
25
27
 
26
28
  public:
27
- std::string getBrand() { return _name; }
29
+ std::string getBrand() { return CLASS_NAME; }
28
30
 
29
31
  std::string getVendor() { return _vendor; }
30
32
  std::string getArchitecture() { return _architecture; }
@@ -32,16 +34,16 @@ public:
32
34
  std::string getDescription() { return _description; }
33
35
  bool getIsFallbackAdapter() { return _isFallbackAdapter; }
34
36
 
35
- void loadHybridMethods() override {
36
- registerHybridGetter("__brand", &GPUAdapterInfo::getBrand, this);
37
-
38
- registerHybridGetter("vendor", &GPUAdapterInfo::getVendor, this);
39
- registerHybridGetter("architecture", &GPUAdapterInfo::getArchitecture,
40
- this);
41
- registerHybridGetter("device", &GPUAdapterInfo::getDevice, this);
42
- registerHybridGetter("description", &GPUAdapterInfo::getDescription, this);
43
- registerHybridGetter("isFallbackAdapter",
44
- &GPUAdapterInfo::getIsFallbackAdapter, this);
37
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
38
+ installGetter(runtime, prototype, "__brand", &GPUAdapterInfo::getBrand);
39
+ installGetter(runtime, prototype, "vendor", &GPUAdapterInfo::getVendor);
40
+ installGetter(runtime, prototype, "architecture",
41
+ &GPUAdapterInfo::getArchitecture);
42
+ installGetter(runtime, prototype, "device", &GPUAdapterInfo::getDevice);
43
+ installGetter(runtime, prototype, "description",
44
+ &GPUAdapterInfo::getDescription);
45
+ installGetter(runtime, prototype, "isFallbackAdapter",
46
+ &GPUAdapterInfo::getIsFallbackAdapter);
45
47
  }
46
48
 
47
49
  private:
@@ -4,21 +4,23 @@
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 GPUBindGroup : public m::HybridObject {
15
+ class GPUBindGroup : public NativeObject<GPUBindGroup> {
16
16
  public:
17
+ static constexpr const char *CLASS_NAME = "GPUBindGroup";
18
+
17
19
  explicit GPUBindGroup(wgpu::BindGroup instance, std::string label)
18
- : HybridObject("GPUBindGroup"), _instance(instance), _label(label) {}
20
+ : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
19
21
 
20
22
  public:
21
- std::string getBrand() { return _name; }
23
+ std::string getBrand() { return CLASS_NAME; }
22
24
 
23
25
  std::string getLabel() { return _label; }
24
26
  void setLabel(const std::string &label) {
@@ -26,11 +28,10 @@ public:
26
28
  _instance.SetLabel(_label.c_str());
27
29
  }
28
30
 
29
- void loadHybridMethods() override {
30
- registerHybridGetter("__brand", &GPUBindGroup::getBrand, this);
31
-
32
- registerHybridGetter("label", &GPUBindGroup::getLabel, this);
33
- registerHybridSetter("label", &GPUBindGroup::setLabel, this);
31
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
32
+ installGetter(runtime, prototype, "__brand", &GPUBindGroup::getBrand);
33
+ installGetterSetter(runtime, prototype, "label", &GPUBindGroup::getLabel,
34
+ &GPUBindGroup::setLabel);
34
35
  }
35
36
 
36
37
  inline const wgpu::BindGroup get() { return _instance; }
@@ -4,22 +4,23 @@
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 GPUBindGroupLayout : public m::HybridObject {
15
+ class GPUBindGroupLayout : public NativeObject<GPUBindGroupLayout> {
16
16
  public:
17
+ static constexpr const char *CLASS_NAME = "GPUBindGroupLayout";
18
+
17
19
  explicit GPUBindGroupLayout(wgpu::BindGroupLayout instance, std::string label)
18
- : HybridObject("GPUBindGroupLayout"), _instance(instance), _label(label) {
19
- }
20
+ : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
20
21
 
21
22
  public:
22
- std::string getBrand() { return _name; }
23
+ std::string getBrand() { return CLASS_NAME; }
23
24
 
24
25
  std::string getLabel() { return _label; }
25
26
  void setLabel(const std::string &label) {
@@ -27,11 +28,11 @@ public:
27
28
  _instance.SetLabel(_label.c_str());
28
29
  }
29
30
 
30
- void loadHybridMethods() override {
31
- registerHybridGetter("__brand", &GPUBindGroupLayout::getBrand, this);
32
-
33
- registerHybridGetter("label", &GPUBindGroupLayout::getLabel, this);
34
- registerHybridSetter("label", &GPUBindGroupLayout::setLabel, this);
31
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
32
+ installGetter(runtime, prototype, "__brand", &GPUBindGroupLayout::getBrand);
33
+ installGetterSetter(runtime, prototype, "label",
34
+ &GPUBindGroupLayout::getLabel,
35
+ &GPUBindGroupLayout::setLabel);
35
36
  }
36
37
 
37
38
  inline const wgpu::BindGroupLayout get() { return _instance; }
@@ -7,7 +7,7 @@
7
7
 
8
8
  #include "Unions.h"
9
9
 
10
- #include "RNFHybridObject.h"
10
+ #include "NativeObject.h"
11
11
 
12
12
  #include "rnwgpu/async/AsyncRunner.h"
13
13
  #include "rnwgpu/async/AsyncTaskHandle.h"
@@ -18,18 +18,20 @@
18
18
 
19
19
  namespace rnwgpu {
20
20
 
21
- namespace m = margelo;
21
+ namespace jsi = facebook::jsi;
22
22
 
23
- class GPUBuffer : public m::HybridObject {
23
+ class GPUBuffer : public NativeObject<GPUBuffer> {
24
24
  public:
25
+ static constexpr const char *CLASS_NAME = "GPUBuffer";
26
+
25
27
  explicit GPUBuffer(wgpu::Buffer instance,
26
28
  std::shared_ptr<async::AsyncRunner> async,
27
29
  std::string label)
28
- : HybridObject("GPUBuffer"), _instance(instance), _async(async),
30
+ : NativeObject(CLASS_NAME), _instance(instance), _async(async),
29
31
  _label(label) {}
30
32
 
31
33
  public:
32
- std::string getBrand() { return _name; }
34
+ std::string getBrand() { return CLASS_NAME; }
33
35
 
34
36
  async::AsyncTaskHandle mapAsync(uint64_t modeIn,
35
37
  std::optional<uint64_t> offset,
@@ -49,17 +51,18 @@ public:
49
51
  _instance.SetLabel(_label.c_str());
50
52
  }
51
53
 
52
- void loadHybridMethods() override {
53
- registerHybridGetter("__brand", &GPUBuffer::getBrand, this);
54
- registerHybridMethod("mapAsync", &GPUBuffer::mapAsync, this);
55
- registerHybridMethod("getMappedRange", &GPUBuffer::getMappedRange, this);
56
- registerHybridMethod("unmap", &GPUBuffer::unmap, this);
57
- registerHybridMethod("destroy", &GPUBuffer::destroy, this);
58
- registerHybridGetter("size", &GPUBuffer::getSize, this);
59
- registerHybridGetter("usage", &GPUBuffer::getUsage, this);
60
- registerHybridGetter("mapState", &GPUBuffer::getMapState, this);
61
- registerHybridGetter("label", &GPUBuffer::getLabel, this);
62
- registerHybridSetter("label", &GPUBuffer::setLabel, this);
54
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
55
+ installGetter(runtime, prototype, "__brand", &GPUBuffer::getBrand);
56
+ installMethod(runtime, prototype, "mapAsync", &GPUBuffer::mapAsync);
57
+ installMethod(runtime, prototype, "getMappedRange",
58
+ &GPUBuffer::getMappedRange);
59
+ installMethod(runtime, prototype, "unmap", &GPUBuffer::unmap);
60
+ installMethod(runtime, prototype, "destroy", &GPUBuffer::destroy);
61
+ installGetter(runtime, prototype, "size", &GPUBuffer::getSize);
62
+ installGetter(runtime, prototype, "usage", &GPUBuffer::getUsage);
63
+ installGetter(runtime, prototype, "mapState", &GPUBuffer::getMapState);
64
+ installGetterSetter(runtime, prototype, "label", &GPUBuffer::getLabel,
65
+ &GPUBuffer::setLabel);
63
66
  }
64
67
 
65
68
  inline const wgpu::Buffer get() { return _instance; }
@@ -8,7 +8,7 @@
8
8
 
9
9
  #include "webgpu/webgpu_cpp.h"
10
10
 
11
- #include "RNFHybridObject.h"
11
+ #include "NativeObject.h"
12
12
 
13
13
  #include "Canvas.h"
14
14
  #include "GPU.h"
@@ -18,13 +18,15 @@
18
18
 
19
19
  namespace rnwgpu {
20
20
 
21
- namespace m = margelo;
21
+ namespace jsi = facebook::jsi;
22
22
 
23
- class GPUCanvasContext : public m::HybridObject {
23
+ class GPUCanvasContext : public NativeObject<GPUCanvasContext> {
24
24
  public:
25
+ static constexpr const char *CLASS_NAME = "GPUCanvasContext";
26
+
25
27
  GPUCanvasContext(std::shared_ptr<GPU> gpu, int contextId, int width,
26
28
  int height)
27
- : HybridObject("GPUCanvasContext"), _gpu(std::move(gpu)) {
29
+ : NativeObject(CLASS_NAME), _gpu(std::move(gpu)) {
28
30
  _canvas = std::make_shared<Canvas>(nullptr, width, height);
29
31
  auto &registry = rnwgpu::SurfaceRegistry::getInstance();
30
32
  _surfaceInfo =
@@ -32,18 +34,20 @@ public:
32
34
  }
33
35
 
34
36
  public:
35
- std::string getBrand() { return _name; }
37
+ std::string getBrand() { return CLASS_NAME; }
36
38
 
37
39
  std::shared_ptr<Canvas> getCanvas() { return _canvas; }
38
40
 
39
- void loadHybridMethods() override {
40
- registerHybridGetter("__brand", &GPUCanvasContext::getBrand, this);
41
- registerHybridGetter("canvas", &GPUCanvasContext::getCanvas, this);
42
- registerHybridMethod("configure", &GPUCanvasContext::configure, this);
43
- registerHybridMethod("unconfigure", &GPUCanvasContext::unconfigure, this);
44
- registerHybridMethod("getCurrentTexture",
45
- &GPUCanvasContext::getCurrentTexture, this);
46
- registerHybridMethod("present", &GPUCanvasContext::present, this);
41
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
42
+ installGetter(runtime, prototype, "__brand", &GPUCanvasContext::getBrand);
43
+ installGetter(runtime, prototype, "canvas", &GPUCanvasContext::getCanvas);
44
+ installMethod(runtime, prototype, "configure",
45
+ &GPUCanvasContext::configure);
46
+ installMethod(runtime, prototype, "unconfigure",
47
+ &GPUCanvasContext::unconfigure);
48
+ installMethod(runtime, prototype, "getCurrentTexture",
49
+ &GPUCanvasContext::getCurrentTexture);
50
+ installMethod(runtime, prototype, "present", &GPUCanvasContext::present);
47
51
  }
48
52
 
49
53
  // TODO: is this ok?
@@ -4,21 +4,23 @@
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 GPUCommandBuffer : public m::HybridObject {
15
+ class GPUCommandBuffer : public NativeObject<GPUCommandBuffer> {
16
16
  public:
17
+ static constexpr const char *CLASS_NAME = "GPUCommandBuffer";
18
+
17
19
  explicit GPUCommandBuffer(wgpu::CommandBuffer instance, std::string label)
18
- : HybridObject("GPUCommandBuffer"), _instance(instance), _label(label) {}
20
+ : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
19
21
 
20
22
  public:
21
- std::string getBrand() { return _name; }
23
+ std::string getBrand() { return CLASS_NAME; }
22
24
 
23
25
  std::string getLabel() { return _label; }
24
26
  void setLabel(const std::string &label) {
@@ -26,11 +28,11 @@ public:
26
28
  _instance.SetLabel(_label.c_str());
27
29
  }
28
30
 
29
- void loadHybridMethods() override {
30
- registerHybridGetter("__brand", &GPUCommandBuffer::getBrand, this);
31
-
32
- registerHybridGetter("label", &GPUCommandBuffer::getLabel, this);
33
- registerHybridSetter("label", &GPUCommandBuffer::setLabel, this);
31
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
32
+ installGetter(runtime, prototype, "__brand", &GPUCommandBuffer::getBrand);
33
+ installGetterSetter(runtime, prototype, "label",
34
+ &GPUCommandBuffer::getLabel,
35
+ &GPUCommandBuffer::setLabel);
34
36
  }
35
37
 
36
38
  inline const wgpu::CommandBuffer 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
 
@@ -23,15 +23,17 @@
23
23
 
24
24
  namespace rnwgpu {
25
25
 
26
- namespace m = margelo;
26
+ namespace jsi = facebook::jsi;
27
27
 
28
- class GPUCommandEncoder : public m::HybridObject {
28
+ class GPUCommandEncoder : public NativeObject<GPUCommandEncoder> {
29
29
  public:
30
+ static constexpr const char *CLASS_NAME = "GPUCommandEncoder";
31
+
30
32
  explicit GPUCommandEncoder(wgpu::CommandEncoder instance, std::string label)
31
- : HybridObject("GPUCommandEncoder"), _instance(instance), _label(label) {}
33
+ : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
32
34
 
33
35
  public:
34
- std::string getBrand() { return _name; }
36
+ std::string getBrand() { return CLASS_NAME; }
35
37
 
36
38
  std::shared_ptr<GPURenderPassEncoder>
37
39
  beginRenderPass(std::shared_ptr<GPURenderPassDescriptor> descriptor);
@@ -69,33 +71,34 @@ public:
69
71
  _instance.SetLabel(_label.c_str());
70
72
  }
71
73
 
72
- void loadHybridMethods() override {
73
- registerHybridGetter("__brand", &GPUCommandEncoder::getBrand, this);
74
- registerHybridMethod("beginRenderPass", &GPUCommandEncoder::beginRenderPass,
75
- this);
76
- registerHybridMethod("beginComputePass",
77
- &GPUCommandEncoder::beginComputePass, this);
78
- registerHybridMethod("copyBufferToBuffer",
79
- &GPUCommandEncoder::copyBufferToBuffer, this);
80
- registerHybridMethod("copyBufferToTexture",
81
- &GPUCommandEncoder::copyBufferToTexture, this);
82
- registerHybridMethod("copyTextureToBuffer",
83
- &GPUCommandEncoder::copyTextureToBuffer, this);
84
- registerHybridMethod("copyTextureToTexture",
85
- &GPUCommandEncoder::copyTextureToTexture, this);
86
- registerHybridMethod("clearBuffer", &GPUCommandEncoder::clearBuffer, this);
87
- registerHybridMethod("resolveQuerySet", &GPUCommandEncoder::resolveQuerySet,
88
- this);
89
- registerHybridMethod("finish", &GPUCommandEncoder::finish, this);
90
- registerHybridMethod("pushDebugGroup", &GPUCommandEncoder::pushDebugGroup,
91
- this);
92
- registerHybridMethod("popDebugGroup", &GPUCommandEncoder::popDebugGroup,
93
- this);
94
- registerHybridMethod("insertDebugMarker",
95
- &GPUCommandEncoder::insertDebugMarker, this);
96
-
97
- registerHybridGetter("label", &GPUCommandEncoder::getLabel, this);
98
- registerHybridSetter("label", &GPUCommandEncoder::setLabel, this);
74
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
75
+ installGetter(runtime, prototype, "__brand", &GPUCommandEncoder::getBrand);
76
+ installMethod(runtime, prototype, "beginRenderPass",
77
+ &GPUCommandEncoder::beginRenderPass);
78
+ installMethod(runtime, prototype, "beginComputePass",
79
+ &GPUCommandEncoder::beginComputePass);
80
+ installMethod(runtime, prototype, "copyBufferToBuffer",
81
+ &GPUCommandEncoder::copyBufferToBuffer);
82
+ installMethod(runtime, prototype, "copyBufferToTexture",
83
+ &GPUCommandEncoder::copyBufferToTexture);
84
+ installMethod(runtime, prototype, "copyTextureToBuffer",
85
+ &GPUCommandEncoder::copyTextureToBuffer);
86
+ installMethod(runtime, prototype, "copyTextureToTexture",
87
+ &GPUCommandEncoder::copyTextureToTexture);
88
+ installMethod(runtime, prototype, "clearBuffer",
89
+ &GPUCommandEncoder::clearBuffer);
90
+ installMethod(runtime, prototype, "resolveQuerySet",
91
+ &GPUCommandEncoder::resolveQuerySet);
92
+ installMethod(runtime, prototype, "finish", &GPUCommandEncoder::finish);
93
+ installMethod(runtime, prototype, "pushDebugGroup",
94
+ &GPUCommandEncoder::pushDebugGroup);
95
+ installMethod(runtime, prototype, "popDebugGroup",
96
+ &GPUCommandEncoder::popDebugGroup);
97
+ installMethod(runtime, prototype, "insertDebugMarker",
98
+ &GPUCommandEncoder::insertDebugMarker);
99
+ installGetterSetter(runtime, prototype, "label",
100
+ &GPUCommandEncoder::getLabel,
101
+ &GPUCommandEncoder::setLabel);
99
102
  }
100
103
 
101
104
  inline const wgpu::CommandEncoder get() { return _instance; }
@@ -5,15 +5,15 @@
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
 
12
12
  namespace rnwgpu {
13
13
 
14
- namespace m = margelo;
14
+ namespace jsi = facebook::jsi;
15
15
 
16
- struct GPUCompilationMessage {
16
+ struct GPUCompilationMessageData {
17
17
  std::string message;
18
18
  wgpu::CompilationMessageType type;
19
19
  uint64_t lineNum;
@@ -22,35 +22,35 @@ struct GPUCompilationMessage {
22
22
  uint64_t length;
23
23
  };
24
24
 
25
- class GPUCompilationInfo : public m::HybridObject {
25
+ class GPUCompilationInfo : public NativeObject<GPUCompilationInfo> {
26
26
  public:
27
- GPUCompilationInfo() : HybridObject("GPUCompilationInfo") {}
27
+ static constexpr const char *CLASS_NAME = "GPUCompilationInfo";
28
+
29
+ GPUCompilationInfo() : NativeObject(CLASS_NAME) {}
28
30
 
29
31
  public:
30
- std::string getBrand() { return _name; }
32
+ std::string getBrand() { return CLASS_NAME; }
31
33
 
32
- std::vector<GPUCompilationMessage> getMessages() { return _messages; }
34
+ std::vector<GPUCompilationMessageData> getMessages() { return _messages; }
33
35
 
34
- void loadHybridMethods() override {
35
- registerHybridGetter("__brand", &GPUCompilationInfo::getBrand, this);
36
- registerHybridGetter("messages", &GPUCompilationInfo::getMessages, this);
36
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
37
+ installGetter(runtime, prototype, "__brand", &GPUCompilationInfo::getBrand);
38
+ installGetter(runtime, prototype, "messages",
39
+ &GPUCompilationInfo::getMessages);
37
40
  }
38
41
 
39
42
  private:
40
- std::vector<GPUCompilationMessage> _messages;
43
+ std::vector<GPUCompilationMessageData> _messages;
41
44
  friend class GPUShaderModule;
42
45
  };
43
46
 
44
- } // namespace rnwgpu
45
-
46
- namespace margelo {
47
- template <> struct JSIConverter<std::vector<rnwgpu::GPUCompilationMessage>> {
48
- static std::vector<rnwgpu::GPUCompilationMessage>
47
+ template <> struct JSIConverter<std::vector<GPUCompilationMessageData>> {
48
+ static std::vector<GPUCompilationMessageData>
49
49
  fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
50
- throw std::runtime_error("Invalid GPUCompilationMessage::fromJSI()");
50
+ throw std::runtime_error("Invalid GPUCompilationMessageData::fromJSI()");
51
51
  }
52
52
  static jsi::Value toJSI(jsi::Runtime &runtime,
53
- std::vector<rnwgpu::GPUCompilationMessage> arg) {
53
+ std::vector<GPUCompilationMessageData> arg) {
54
54
  jsi::Array result = jsi::Array(runtime, arg.size());
55
55
  for (size_t i = 0; i < arg.size(); i++) {
56
56
  const auto &message = arg[i];
@@ -76,4 +76,4 @@ template <> struct JSIConverter<std::vector<rnwgpu::GPUCompilationMessage>> {
76
76
  }
77
77
  };
78
78
 
79
- } // namespace margelo
79
+ } // namespace rnwgpu
@@ -4,24 +4,27 @@
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 GPUCompilationMessage : public m::HybridObject {
15
+ class GPUCompilationMessage : public NativeObject<GPUCompilationMessage> {
16
16
  public:
17
+ static constexpr const char *CLASS_NAME = "GPUCompilationMessage";
18
+
17
19
  explicit GPUCompilationMessage(wgpu::CompilationMessage instance)
18
- : HybridObject("GPUCompilationMessage"), _instance(instance) {}
20
+ : NativeObject(CLASS_NAME), _instance(instance) {}
19
21
 
20
22
  public:
21
- std::string getBrand() { return _name; }
23
+ std::string getBrand() { return CLASS_NAME; }
22
24
 
23
- void loadHybridMethods() override {
24
- registerHybridGetter("__brand", &GPUCompilationMessage::getBrand, this);
25
+ static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
26
+ installGetter(runtime, prototype, "__brand",
27
+ &GPUCompilationMessage::getBrand);
25
28
  }
26
29
 
27
30
  inline const wgpu::CompilationMessage get() { return _instance; }