react-native-wgpu 0.1.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 (208) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +31 -0
  3. package/android/CMakeLists.txt +74 -0
  4. package/android/build.gradle +166 -0
  5. package/android/cpp/cpp-adapter.cpp +12 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +3 -0
  8. package/android/src/main/AndroidManifestNew.xml +2 -0
  9. package/android/src/main/java/com/webgpu/WebGPUModule.java +39 -0
  10. package/android/src/main/java/com/webgpu/WebGPUView.java +24 -0
  11. package/android/src/main/java/com/webgpu/WebGPUViewManager.java +31 -0
  12. package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +26 -0
  13. package/android/src/newarch/WgpuViewManagerSpec.java +24 -0
  14. package/android/src/oldarch/WebGPUViewManagerSpec.java +11 -0
  15. package/cpp/Logger.h +82 -0
  16. package/cpp/dawn/dawn_proc_table.h +308 -0
  17. package/cpp/dawn/webgpu.h +4201 -0
  18. package/cpp/dawn/webgpu_cpp.h +8985 -0
  19. package/cpp/dawn/webgpu_cpp_print.h +2460 -0
  20. package/cpp/dawn/wire/client/webgpu.h +339 -0
  21. package/cpp/dawn/wire/client/webgpu_cpp.h +9140 -0
  22. package/cpp/jsi/RNFEnumMapper.h +49 -0
  23. package/cpp/jsi/RNFHybridObject.cpp +145 -0
  24. package/cpp/jsi/RNFHybridObject.h +162 -0
  25. package/cpp/jsi/RNFJSIConverter.h +412 -0
  26. package/cpp/jsi/RNFJSIHelper.h +49 -0
  27. package/cpp/jsi/RNFPointerHolder.h +95 -0
  28. package/cpp/jsi/RNFPromise.cpp +45 -0
  29. package/cpp/jsi/RNFPromise.h +38 -0
  30. package/cpp/jsi/RNFRuntimeCache.cpp +57 -0
  31. package/cpp/jsi/RNFRuntimeCache.h +79 -0
  32. package/cpp/jsi/RNFWorkletRuntimeCollector.h +43 -0
  33. package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +11 -0
  34. package/cpp/jsi/RNFWorkletRuntimeRegistry.h +44 -0
  35. package/cpp/rnwgpu/MutableBuffer.h +48 -0
  36. package/cpp/rnwgpu/RNWebGPUManager.cpp +60 -0
  37. package/cpp/rnwgpu/RNWebGPUManager.h +30 -0
  38. package/cpp/rnwgpu/api/GPU.cpp +40 -0
  39. package/cpp/rnwgpu/api/GPU.h +43 -0
  40. package/cpp/rnwgpu/api/GPUAdapter.cpp +33 -0
  41. package/cpp/rnwgpu/api/GPUAdapter.h +40 -0
  42. package/cpp/rnwgpu/api/GPUAdapterInfo.h +33 -0
  43. package/cpp/rnwgpu/api/GPUBindGroup.h +38 -0
  44. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +39 -0
  45. package/cpp/rnwgpu/api/GPUBuffer.cpp +16 -0
  46. package/cpp/rnwgpu/api/GPUBuffer.h +44 -0
  47. package/cpp/rnwgpu/api/GPUCanvasContext.h +33 -0
  48. package/cpp/rnwgpu/api/GPUCommandBuffer.h +38 -0
  49. package/cpp/rnwgpu/api/GPUCommandEncoder.h +38 -0
  50. package/cpp/rnwgpu/api/GPUCompilationInfo.h +33 -0
  51. package/cpp/rnwgpu/api/GPUCompilationMessage.h +33 -0
  52. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +40 -0
  53. package/cpp/rnwgpu/api/GPUComputePipeline.h +39 -0
  54. package/cpp/rnwgpu/api/GPUDevice.cpp +12 -0
  55. package/cpp/rnwgpu/api/GPUDevice.h +45 -0
  56. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +33 -0
  57. package/cpp/rnwgpu/api/GPUExternalTexture.h +39 -0
  58. package/cpp/rnwgpu/api/GPUPipelineLayout.h +38 -0
  59. package/cpp/rnwgpu/api/GPUQuerySet.h +38 -0
  60. package/cpp/rnwgpu/api/GPUQueue.h +38 -0
  61. package/cpp/rnwgpu/api/GPURenderBundle.h +38 -0
  62. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +40 -0
  63. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +40 -0
  64. package/cpp/rnwgpu/api/GPURenderPipeline.h +38 -0
  65. package/cpp/rnwgpu/api/GPUSampler.h +38 -0
  66. package/cpp/rnwgpu/api/GPUShaderModule.h +38 -0
  67. package/cpp/rnwgpu/api/GPUSupportedLimits.h +33 -0
  68. package/cpp/rnwgpu/api/GPUTexture.h +38 -0
  69. package/cpp/rnwgpu/api/GPUTextureView.h +38 -0
  70. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +33 -0
  71. package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +81 -0
  72. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +67 -0
  73. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +69 -0
  74. package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +95 -0
  75. package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +56 -0
  76. package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +65 -0
  77. package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +72 -0
  78. package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +62 -0
  79. package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +85 -0
  80. package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +43 -0
  81. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +93 -0
  82. package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +81 -0
  83. package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +69 -0
  84. package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +31 -0
  85. package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +62 -0
  86. package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +80 -0
  87. package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +82 -0
  88. package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +126 -0
  89. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +69 -0
  90. package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +76 -0
  91. package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +91 -0
  92. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +44 -0
  93. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +75 -0
  94. package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +85 -0
  95. package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +83 -0
  96. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +66 -0
  97. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +74 -0
  98. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +88 -0
  99. package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +70 -0
  100. package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +25 -0
  101. package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +68 -0
  102. package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +61 -0
  103. package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +75 -0
  104. package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +71 -0
  105. package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +54 -0
  106. package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +72 -0
  107. package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +66 -0
  108. package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +72 -0
  109. package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +81 -0
  110. package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +102 -0
  111. package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +105 -0
  112. package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +118 -0
  113. package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +100 -0
  114. package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +83 -0
  115. package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +80 -0
  116. package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +104 -0
  117. package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +56 -0
  118. package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +48 -0
  119. package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +116 -0
  120. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +64 -0
  121. package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +88 -0
  122. package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +27 -0
  123. package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +61 -0
  124. package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +67 -0
  125. package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +58 -0
  126. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +123 -0
  127. package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +40 -0
  128. package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +113 -0
  129. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +71 -0
  130. package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +80 -0
  131. package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +73 -0
  132. package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +77 -0
  133. package/cpp/rnwgpu/api/descriptors/Unions.h +1645 -0
  134. package/cpp/webgpu/webgpu.h +33 -0
  135. package/cpp/webgpu/webgpu_cpp.h +33 -0
  136. package/cpp/webgpu/webgpu_cpp_chained_struct.h +55 -0
  137. package/cpp/webgpu/webgpu_enum_class_bitmasks.h +161 -0
  138. package/ios/RNFAppleLogger.mm +22 -0
  139. package/ios/Utils.h +5 -0
  140. package/ios/Utils.m +26 -0
  141. package/ios/WebGPUModule.h +18 -0
  142. package/ios/WebGPUModule.mm +77 -0
  143. package/ios/WebGPUView.h +15 -0
  144. package/ios/WebGPUView.mm +58 -0
  145. package/ios/WebGPUViewManager.mm +21 -0
  146. package/lib/commonjs/WebGPUNativeModule.js +10 -0
  147. package/lib/commonjs/WebGPUNativeModule.js.map +1 -0
  148. package/lib/commonjs/WebGPUViewNativeComponent.js +11 -0
  149. package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -0
  150. package/lib/commonjs/index.js +45 -0
  151. package/lib/commonjs/index.js.map +1 -0
  152. package/lib/module/WebGPUNativeModule.js +4 -0
  153. package/lib/module/WebGPUNativeModule.js.map +1 -0
  154. package/lib/module/WebGPUViewNativeComponent.js +4 -0
  155. package/lib/module/WebGPUViewNativeComponent.js.map +1 -0
  156. package/lib/module/index.js +9 -0
  157. package/lib/module/index.js.map +1 -0
  158. package/lib/typescript/babel.config.d.ts +2 -0
  159. package/lib/typescript/babel.config.d.ts.map +1 -0
  160. package/lib/typescript/jest.config.d.ts +5 -0
  161. package/lib/typescript/jest.config.d.ts.map +1 -0
  162. package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts +5 -0
  163. package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +1 -0
  164. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.d.ts +4 -0
  165. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.d.ts.map +1 -0
  166. package/lib/typescript/lib/commonjs/index.d.ts +5 -0
  167. package/lib/typescript/lib/commonjs/index.d.ts.map +1 -0
  168. package/lib/typescript/lib/module/WebGPUNativeModule.d.ts +3 -0
  169. package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +1 -0
  170. package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts +4 -0
  171. package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts.map +1 -0
  172. package/lib/typescript/lib/module/index.d.ts +5 -0
  173. package/lib/typescript/lib/module/index.d.ts.map +1 -0
  174. package/lib/typescript/scripts/build/copy-artifacts.d.ts +2 -0
  175. package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +1 -0
  176. package/lib/typescript/scripts/build/dawn.d.ts +2 -0
  177. package/lib/typescript/scripts/build/dawn.d.ts.map +1 -0
  178. package/lib/typescript/scripts/build/util.d.ts +13 -0
  179. package/lib/typescript/scripts/build/util.d.ts.map +1 -0
  180. package/lib/typescript/scripts/codegen/codegen.d.ts +2 -0
  181. package/lib/typescript/scripts/codegen/codegen.d.ts.map +1 -0
  182. package/lib/typescript/scripts/codegen/model/dawn.d.ts +2 -0
  183. package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +1 -0
  184. package/lib/typescript/scripts/codegen/model/model.d.ts +8 -0
  185. package/lib/typescript/scripts/codegen/model/model.d.ts.map +1 -0
  186. package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +4 -0
  187. package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +1 -0
  188. package/lib/typescript/scripts/codegen/templates/Enum.d.ts +3 -0
  189. package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +1 -0
  190. package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +3 -0
  191. package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +1 -0
  192. package/lib/typescript/scripts/codegen/templates/Unions.d.ts +6 -0
  193. package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +1 -0
  194. package/lib/typescript/scripts/codegen/templates/common.d.ts +9 -0
  195. package/lib/typescript/scripts/codegen/templates/common.d.ts.map +1 -0
  196. package/lib/typescript/scripts/codegen/util.d.ts +2 -0
  197. package/lib/typescript/scripts/codegen/util.d.ts.map +1 -0
  198. package/lib/typescript/src/WebGPUNativeModule.d.ts +7 -0
  199. package/lib/typescript/src/WebGPUNativeModule.d.ts.map +1 -0
  200. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +8 -0
  201. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -0
  202. package/lib/typescript/src/index.d.ts +9 -0
  203. package/lib/typescript/src/index.d.ts.map +1 -0
  204. package/package.json +120 -0
  205. package/react-native-webgpu.podspec +56 -0
  206. package/src/WebGPUNativeModule.ts +9 -0
  207. package/src/WebGPUViewNativeComponent.ts +9 -0
  208. package/src/index.tsx +13 -0
@@ -0,0 +1,72 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUBufferBinding {
17
+ public:
18
+ wgpu::BufferBinding *getInstance() { return &_instance; }
19
+
20
+ wgpu::BufferBinding _instance;
21
+ };
22
+ } // namespace rnwgpu
23
+
24
+ namespace margelo {
25
+
26
+ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUBufferBinding>> {
27
+ static std::shared_ptr<rnwgpu::GPUBufferBinding>
28
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
29
+ auto result = std::make_unique<rnwgpu::GPUBufferBinding>();
30
+ if (!outOfBounds && arg.isObject()) {
31
+ auto value = arg.getObject(runtime);
32
+ if (value.hasProperty(runtime, "buffer")) {
33
+ auto buffer = value.getProperty(runtime, "buffer");
34
+
35
+ if (buffer.isUndefined()) {
36
+ throw std::runtime_error(
37
+ "Property GPUBufferBinding::buffer is required");
38
+ }
39
+ } else {
40
+ throw std::runtime_error(
41
+ "Property GPUBufferBinding::buffer is not defined");
42
+ }
43
+ if (value.hasProperty(runtime, "offset")) {
44
+ auto offset = value.getProperty(runtime, "offset");
45
+
46
+ if (offset.isNumber()) {
47
+ result->_instance.offset = offset.getNumber();
48
+ }
49
+ }
50
+ if (value.hasProperty(runtime, "size")) {
51
+ auto size = value.getProperty(runtime, "size");
52
+
53
+ if (size.isNumber()) {
54
+ result->_instance.size = size.getNumber();
55
+ }
56
+ }
57
+ }
58
+ rnwgpu::Logger::logToConsole("GPUBufferBinding::buffer = %f",
59
+ result->_instance.buffer);
60
+ rnwgpu::Logger::logToConsole("GPUBufferBinding::offset = %f",
61
+ result->_instance.offset);
62
+ rnwgpu::Logger::logToConsole("GPUBufferBinding::size = %f",
63
+ result->_instance.size);
64
+ return result;
65
+ }
66
+ static jsi::Value toJSI(jsi::Runtime &runtime,
67
+ std::shared_ptr<rnwgpu::GPUBufferBinding> arg) {
68
+ // No conversions here
69
+ return jsi::Value::null();
70
+ }
71
+ };
72
+ } // namespace margelo
@@ -0,0 +1,62 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUBufferBindingLayout {
17
+ public:
18
+ wgpu::BufferBindingLayout *getInstance() { return &_instance; }
19
+
20
+ wgpu::BufferBindingLayout _instance;
21
+ };
22
+ } // namespace rnwgpu
23
+
24
+ namespace margelo {
25
+
26
+ template <>
27
+ struct JSIConverter<std::shared_ptr<rnwgpu::GPUBufferBindingLayout>> {
28
+ static std::shared_ptr<rnwgpu::GPUBufferBindingLayout>
29
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
30
+ auto result = std::make_unique<rnwgpu::GPUBufferBindingLayout>();
31
+ if (!outOfBounds && arg.isObject()) {
32
+ auto value = arg.getObject(runtime);
33
+ if (value.hasProperty(runtime, "type")) {
34
+ auto type = value.getProperty(runtime, "type");
35
+ }
36
+ if (value.hasProperty(runtime, "hasDynamicOffset")) {
37
+ auto hasDynamicOffset = value.getProperty(runtime, "hasDynamicOffset");
38
+ }
39
+ if (value.hasProperty(runtime, "minBindingSize")) {
40
+ auto minBindingSize = value.getProperty(runtime, "minBindingSize");
41
+
42
+ if (minBindingSize.isNumber()) {
43
+ result->_instance.minBindingSize = minBindingSize.getNumber();
44
+ }
45
+ }
46
+ }
47
+ rnwgpu::Logger::logToConsole("GPUBufferBindingLayout::type = %f",
48
+ result->_instance.type);
49
+ rnwgpu::Logger::logToConsole(
50
+ "GPUBufferBindingLayout::hasDynamicOffset = %f",
51
+ result->_instance.hasDynamicOffset);
52
+ rnwgpu::Logger::logToConsole("GPUBufferBindingLayout::minBindingSize = %f",
53
+ result->_instance.minBindingSize);
54
+ return result;
55
+ }
56
+ static jsi::Value toJSI(jsi::Runtime &runtime,
57
+ std::shared_ptr<rnwgpu::GPUBufferBindingLayout> arg) {
58
+ // No conversions here
59
+ return jsi::Value::null();
60
+ }
61
+ };
62
+ } // namespace margelo
@@ -0,0 +1,85 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUBufferDescriptor {
17
+ public:
18
+ wgpu::BufferDescriptor *getInstance() { return &_instance; }
19
+
20
+ wgpu::BufferDescriptor _instance;
21
+
22
+ std::string label;
23
+ };
24
+ } // namespace rnwgpu
25
+
26
+ namespace margelo {
27
+
28
+ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUBufferDescriptor>> {
29
+ static std::shared_ptr<rnwgpu::GPUBufferDescriptor>
30
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
31
+ auto result = std::make_unique<rnwgpu::GPUBufferDescriptor>();
32
+ if (!outOfBounds && arg.isObject()) {
33
+ auto value = arg.getObject(runtime);
34
+ if (value.hasProperty(runtime, "size")) {
35
+ auto size = value.getProperty(runtime, "size");
36
+
37
+ if (size.isUndefined()) {
38
+ throw std::runtime_error(
39
+ "Property GPUBufferDescriptor::size is required");
40
+ }
41
+ } else {
42
+ throw std::runtime_error(
43
+ "Property GPUBufferDescriptor::size is not defined");
44
+ }
45
+ if (value.hasProperty(runtime, "usage")) {
46
+ auto usage = value.getProperty(runtime, "usage");
47
+
48
+ if (usage.isUndefined()) {
49
+ throw std::runtime_error(
50
+ "Property GPUBufferDescriptor::usage is required");
51
+ }
52
+ } else {
53
+ throw std::runtime_error(
54
+ "Property GPUBufferDescriptor::usage is not defined");
55
+ }
56
+ if (value.hasProperty(runtime, "mappedAtCreation")) {
57
+ auto mappedAtCreation = value.getProperty(runtime, "mappedAtCreation");
58
+ }
59
+ if (value.hasProperty(runtime, "label")) {
60
+ auto label = value.getProperty(runtime, "label");
61
+
62
+ if (label.isString()) {
63
+ auto str = label.asString(runtime).utf8(runtime);
64
+ result->label = str;
65
+ result->_instance.label = result->label.c_str();
66
+ }
67
+ }
68
+ }
69
+ rnwgpu::Logger::logToConsole("GPUBufferDescriptor::size = %f",
70
+ result->_instance.size);
71
+ rnwgpu::Logger::logToConsole("GPUBufferDescriptor::usage = %f",
72
+ result->_instance.usage);
73
+ rnwgpu::Logger::logToConsole("GPUBufferDescriptor::mappedAtCreation = %f",
74
+ result->_instance.mappedAtCreation);
75
+ rnwgpu::Logger::logToConsole("GPUBufferDescriptor::label = %f",
76
+ result->_instance.label);
77
+ return result;
78
+ }
79
+ static jsi::Value toJSI(jsi::Runtime &runtime,
80
+ std::shared_ptr<rnwgpu::GPUBufferDescriptor> arg) {
81
+ // No conversions here
82
+ return jsi::Value::null();
83
+ }
84
+ };
85
+ } // namespace margelo
@@ -0,0 +1,43 @@
1
+ #pragma once
2
+ #include <string>
3
+
4
+ #include <RNFHybridObject.h>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ namespace rnwgpu {
9
+
10
+ namespace m = margelo;
11
+
12
+ class GPUBufferUsage : public m::HybridObject {
13
+ public:
14
+ GPUBufferUsage() : HybridObject("GPUBufferUsage") {}
15
+
16
+ public:
17
+ double MapRead() { return static_cast<double>(wgpu::BufferUsage::MapRead); }
18
+ double MapWrite() { return static_cast<double>(wgpu::BufferUsage::MapWrite); }
19
+ double CopySrc() { return static_cast<double>(wgpu::BufferUsage::CopySrc); }
20
+ double CopyDst() { return static_cast<double>(wgpu::BufferUsage::CopyDst); }
21
+ double Index() { return static_cast<double>(wgpu::BufferUsage::Index); }
22
+ double Vertex() { return static_cast<double>(wgpu::BufferUsage::Vertex); }
23
+ double Uniform() { return static_cast<double>(wgpu::BufferUsage::Uniform); }
24
+ double Storage() { return static_cast<double>(wgpu::BufferUsage::Storage); }
25
+ double Indirect() { return static_cast<double>(wgpu::BufferUsage::Indirect); }
26
+ double QueryResolve() {
27
+ return static_cast<double>(wgpu::BufferUsage::QueryResolve);
28
+ }
29
+
30
+ void loadHybridMethods() override {
31
+ registerHybridGetter("MAP_READ", &GPUBufferUsage::MapRead, this);
32
+ registerHybridGetter("MAP_WRITE", &GPUBufferUsage::MapWrite, this);
33
+ registerHybridGetter("COPY_SRC", &GPUBufferUsage::CopySrc, this);
34
+ registerHybridGetter("COPY_DST", &GPUBufferUsage::CopyDst, this);
35
+ registerHybridGetter("INDEX", &GPUBufferUsage::Index, this);
36
+ registerHybridGetter("VERTEX", &GPUBufferUsage::Vertex, this);
37
+ registerHybridGetter("UNIFORM", &GPUBufferUsage::Uniform, this);
38
+ registerHybridGetter("STORAGE", &GPUBufferUsage::Storage, this);
39
+ registerHybridGetter("INDIRECT", &GPUBufferUsage::Indirect, this);
40
+ registerHybridGetter("QUERY_RESOLVE", &GPUBufferUsage::QueryResolve, this);
41
+ }
42
+ };
43
+ } // namespace rnwgpu
@@ -0,0 +1,93 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUCanvasConfiguration {
17
+ public:
18
+ wgpu::CanvasConfiguration *getInstance() { return &_instance; }
19
+
20
+ wgpu::CanvasConfiguration _instance;
21
+ };
22
+ } // namespace rnwgpu
23
+
24
+ namespace margelo {
25
+
26
+ template <>
27
+ struct JSIConverter<std::shared_ptr<rnwgpu::GPUCanvasConfiguration>> {
28
+ static std::shared_ptr<rnwgpu::GPUCanvasConfiguration>
29
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
30
+ auto result = std::make_unique<rnwgpu::GPUCanvasConfiguration>();
31
+ if (!outOfBounds && arg.isObject()) {
32
+ auto value = arg.getObject(runtime);
33
+ if (value.hasProperty(runtime, "device")) {
34
+ auto device = value.getProperty(runtime, "device");
35
+
36
+ if (device.isUndefined()) {
37
+ throw std::runtime_error(
38
+ "Property GPUCanvasConfiguration::device is required");
39
+ }
40
+ } else {
41
+ throw std::runtime_error(
42
+ "Property GPUCanvasConfiguration::device is not defined");
43
+ }
44
+ if (value.hasProperty(runtime, "format")) {
45
+ auto format = value.getProperty(runtime, "format");
46
+
47
+ if (format.isUndefined()) {
48
+ throw std::runtime_error(
49
+ "Property GPUCanvasConfiguration::format is required");
50
+ }
51
+ } else {
52
+ throw std::runtime_error(
53
+ "Property GPUCanvasConfiguration::format is not defined");
54
+ }
55
+ if (value.hasProperty(runtime, "usage")) {
56
+ auto usage = value.getProperty(runtime, "usage");
57
+
58
+ if (usage.isNumber()) {
59
+ result->_instance.usage =
60
+ static_cast<wgpu::TextureUsageFlags>(usage.getNumber());
61
+ }
62
+ }
63
+ if (value.hasProperty(runtime, "viewFormats")) {
64
+ auto viewFormats = value.getProperty(runtime, "viewFormats");
65
+ }
66
+ if (value.hasProperty(runtime, "colorSpace")) {
67
+ auto colorSpace = value.getProperty(runtime, "colorSpace");
68
+ }
69
+ if (value.hasProperty(runtime, "alphaMode")) {
70
+ auto alphaMode = value.getProperty(runtime, "alphaMode");
71
+ }
72
+ }
73
+ rnwgpu::Logger::logToConsole("GPUCanvasConfiguration::device = %f",
74
+ result->_instance.device);
75
+ rnwgpu::Logger::logToConsole("GPUCanvasConfiguration::format = %f",
76
+ result->_instance.format);
77
+ rnwgpu::Logger::logToConsole("GPUCanvasConfiguration::usage = %f",
78
+ result->_instance.usage);
79
+ rnwgpu::Logger::logToConsole("GPUCanvasConfiguration::viewFormats = %f",
80
+ result->_instance.viewFormats);
81
+ rnwgpu::Logger::logToConsole("GPUCanvasConfiguration::colorSpace = %f",
82
+ result->_instance.colorSpace);
83
+ rnwgpu::Logger::logToConsole("GPUCanvasConfiguration::alphaMode = %f",
84
+ result->_instance.alphaMode);
85
+ return result;
86
+ }
87
+ static jsi::Value toJSI(jsi::Runtime &runtime,
88
+ std::shared_ptr<rnwgpu::GPUCanvasConfiguration> arg) {
89
+ // No conversions here
90
+ return jsi::Value::null();
91
+ }
92
+ };
93
+ } // namespace margelo
@@ -0,0 +1,81 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUColorDict {
17
+ public:
18
+ wgpu::ColorDict *getInstance() { return &_instance; }
19
+
20
+ wgpu::ColorDict _instance;
21
+ };
22
+ } // namespace rnwgpu
23
+
24
+ namespace margelo {
25
+
26
+ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUColorDict>> {
27
+ static std::shared_ptr<rnwgpu::GPUColorDict>
28
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
29
+ auto result = std::make_unique<rnwgpu::GPUColorDict>();
30
+ if (!outOfBounds && arg.isObject()) {
31
+ auto value = arg.getObject(runtime);
32
+ if (value.hasProperty(runtime, "r")) {
33
+ auto r = value.getProperty(runtime, "r");
34
+
35
+ if (r.isUndefined()) {
36
+ throw std::runtime_error("Property GPUColorDict::r is required");
37
+ }
38
+ } else {
39
+ throw std::runtime_error("Property GPUColorDict::r is not defined");
40
+ }
41
+ if (value.hasProperty(runtime, "g")) {
42
+ auto g = value.getProperty(runtime, "g");
43
+
44
+ if (g.isUndefined()) {
45
+ throw std::runtime_error("Property GPUColorDict::g is required");
46
+ }
47
+ } else {
48
+ throw std::runtime_error("Property GPUColorDict::g is not defined");
49
+ }
50
+ if (value.hasProperty(runtime, "b")) {
51
+ auto b = value.getProperty(runtime, "b");
52
+
53
+ if (b.isUndefined()) {
54
+ throw std::runtime_error("Property GPUColorDict::b is required");
55
+ }
56
+ } else {
57
+ throw std::runtime_error("Property GPUColorDict::b is not defined");
58
+ }
59
+ if (value.hasProperty(runtime, "a")) {
60
+ auto a = value.getProperty(runtime, "a");
61
+
62
+ if (a.isUndefined()) {
63
+ throw std::runtime_error("Property GPUColorDict::a is required");
64
+ }
65
+ } else {
66
+ throw std::runtime_error("Property GPUColorDict::a is not defined");
67
+ }
68
+ }
69
+ rnwgpu::Logger::logToConsole("GPUColorDict::r = %f", result->_instance.r);
70
+ rnwgpu::Logger::logToConsole("GPUColorDict::g = %f", result->_instance.g);
71
+ rnwgpu::Logger::logToConsole("GPUColorDict::b = %f", result->_instance.b);
72
+ rnwgpu::Logger::logToConsole("GPUColorDict::a = %f", result->_instance.a);
73
+ return result;
74
+ }
75
+ static jsi::Value toJSI(jsi::Runtime &runtime,
76
+ std::shared_ptr<rnwgpu::GPUColorDict> arg) {
77
+ // No conversions here
78
+ return jsi::Value::null();
79
+ }
80
+ };
81
+ } // namespace margelo
@@ -0,0 +1,69 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUColorTargetState {
17
+ public:
18
+ wgpu::ColorTargetState *getInstance() { return &_instance; }
19
+
20
+ wgpu::ColorTargetState _instance;
21
+ };
22
+ } // namespace rnwgpu
23
+
24
+ namespace margelo {
25
+
26
+ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUColorTargetState>> {
27
+ static std::shared_ptr<rnwgpu::GPUColorTargetState>
28
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
29
+ auto result = std::make_unique<rnwgpu::GPUColorTargetState>();
30
+ if (!outOfBounds && arg.isObject()) {
31
+ auto value = arg.getObject(runtime);
32
+ if (value.hasProperty(runtime, "format")) {
33
+ auto format = value.getProperty(runtime, "format");
34
+
35
+ if (format.isUndefined()) {
36
+ throw std::runtime_error(
37
+ "Property GPUColorTargetState::format is required");
38
+ }
39
+ } else {
40
+ throw std::runtime_error(
41
+ "Property GPUColorTargetState::format is not defined");
42
+ }
43
+ if (value.hasProperty(runtime, "blend")) {
44
+ auto blend = value.getProperty(runtime, "blend");
45
+ }
46
+ if (value.hasProperty(runtime, "writeMask")) {
47
+ auto writeMask = value.getProperty(runtime, "writeMask");
48
+
49
+ if (writeMask.isNumber()) {
50
+ result->_instance.writeMask =
51
+ static_cast<wgpu::ColorWriteFlags>(writeMask.getNumber());
52
+ }
53
+ }
54
+ }
55
+ rnwgpu::Logger::logToConsole("GPUColorTargetState::format = %f",
56
+ result->_instance.format);
57
+ rnwgpu::Logger::logToConsole("GPUColorTargetState::blend = %f",
58
+ result->_instance.blend);
59
+ rnwgpu::Logger::logToConsole("GPUColorTargetState::writeMask = %f",
60
+ result->_instance.writeMask);
61
+ return result;
62
+ }
63
+ static jsi::Value toJSI(jsi::Runtime &runtime,
64
+ std::shared_ptr<rnwgpu::GPUColorTargetState> arg) {
65
+ // No conversions here
66
+ return jsi::Value::null();
67
+ }
68
+ };
69
+ } // namespace margelo
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+ #include <string>
3
+
4
+ #include <RNFHybridObject.h>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ namespace rnwgpu {
9
+
10
+ namespace m = margelo;
11
+
12
+ class GPUColorWrite : public m::HybridObject {
13
+ public:
14
+ GPUColorWrite() : HybridObject("GPUColorWrite") {}
15
+
16
+ public:
17
+ double Red() { return static_cast<double>(wgpu::ColorWriteMask::Red); }
18
+ double Green() { return static_cast<double>(wgpu::ColorWriteMask::Green); }
19
+ double Blue() { return static_cast<double>(wgpu::ColorWriteMask::Blue); }
20
+ double Alpha() { return static_cast<double>(wgpu::ColorWriteMask::Alpha); }
21
+ double All() { return static_cast<double>(wgpu::ColorWriteMask::All); }
22
+
23
+ void loadHybridMethods() override {
24
+ registerHybridGetter("RED", &GPUColorWrite::Red, this);
25
+ registerHybridGetter("GREEN", &GPUColorWrite::Green, this);
26
+ registerHybridGetter("BLUE", &GPUColorWrite::Blue, this);
27
+ registerHybridGetter("ALPHA", &GPUColorWrite::Alpha, this);
28
+ registerHybridGetter("ALL", &GPUColorWrite::All, this);
29
+ }
30
+ };
31
+ } // namespace rnwgpu
@@ -0,0 +1,62 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUComputePassDescriptor {
17
+ public:
18
+ wgpu::ComputePassDescriptor *getInstance() { return &_instance; }
19
+
20
+ wgpu::ComputePassDescriptor _instance;
21
+
22
+ std::string label;
23
+ };
24
+ } // namespace rnwgpu
25
+
26
+ namespace margelo {
27
+
28
+ template <>
29
+ struct JSIConverter<std::shared_ptr<rnwgpu::GPUComputePassDescriptor>> {
30
+ static std::shared_ptr<rnwgpu::GPUComputePassDescriptor>
31
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
32
+ auto result = std::make_unique<rnwgpu::GPUComputePassDescriptor>();
33
+ if (!outOfBounds && arg.isObject()) {
34
+ auto value = arg.getObject(runtime);
35
+ if (value.hasProperty(runtime, "timestampWrites")) {
36
+ auto timestampWrites = value.getProperty(runtime, "timestampWrites");
37
+ }
38
+ if (value.hasProperty(runtime, "label")) {
39
+ auto label = value.getProperty(runtime, "label");
40
+
41
+ if (label.isString()) {
42
+ auto str = label.asString(runtime).utf8(runtime);
43
+ result->label = str;
44
+ result->_instance.label = result->label.c_str();
45
+ }
46
+ }
47
+ }
48
+ rnwgpu::Logger::logToConsole(
49
+ "GPUComputePassDescriptor::timestampWrites = %f",
50
+ result->_instance.timestampWrites);
51
+ rnwgpu::Logger::logToConsole("GPUComputePassDescriptor::label = %f",
52
+ result->_instance.label);
53
+ return result;
54
+ }
55
+ static jsi::Value
56
+ toJSI(jsi::Runtime &runtime,
57
+ std::shared_ptr<rnwgpu::GPUComputePassDescriptor> arg) {
58
+ // No conversions here
59
+ return jsi::Value::null();
60
+ }
61
+ };
62
+ } // namespace margelo
@@ -0,0 +1,80 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "Logger.h"
9
+ #include "RNFJSIConverter.h"
10
+ #include <RNFHybridObject.h>
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ class GPUComputePassTimestampWrites {
17
+ public:
18
+ wgpu::ComputePassTimestampWrites *getInstance() { return &_instance; }
19
+
20
+ wgpu::ComputePassTimestampWrites _instance;
21
+ };
22
+ } // namespace rnwgpu
23
+
24
+ namespace margelo {
25
+
26
+ template <>
27
+ struct JSIConverter<std::shared_ptr<rnwgpu::GPUComputePassTimestampWrites>> {
28
+ static std::shared_ptr<rnwgpu::GPUComputePassTimestampWrites>
29
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
30
+ auto result = std::make_unique<rnwgpu::GPUComputePassTimestampWrites>();
31
+ if (!outOfBounds && arg.isObject()) {
32
+ auto value = arg.getObject(runtime);
33
+ if (value.hasProperty(runtime, "querySet")) {
34
+ auto querySet = value.getProperty(runtime, "querySet");
35
+
36
+ if (querySet.isUndefined()) {
37
+ throw std::runtime_error(
38
+ "Property GPUComputePassTimestampWrites::querySet is required");
39
+ }
40
+ } else {
41
+ throw std::runtime_error(
42
+ "Property GPUComputePassTimestampWrites::querySet is not defined");
43
+ }
44
+ if (value.hasProperty(runtime, "beginningOfPassWriteIndex")) {
45
+ auto beginningOfPassWriteIndex =
46
+ value.getProperty(runtime, "beginningOfPassWriteIndex");
47
+
48
+ if (beginningOfPassWriteIndex.isNumber()) {
49
+ result->_instance.beginningOfPassWriteIndex =
50
+ static_cast<wgpu::Size32>(beginningOfPassWriteIndex.getNumber());
51
+ }
52
+ }
53
+ if (value.hasProperty(runtime, "endOfPassWriteIndex")) {
54
+ auto endOfPassWriteIndex =
55
+ value.getProperty(runtime, "endOfPassWriteIndex");
56
+
57
+ if (endOfPassWriteIndex.isNumber()) {
58
+ result->_instance.endOfPassWriteIndex =
59
+ static_cast<wgpu::Size32>(endOfPassWriteIndex.getNumber());
60
+ }
61
+ }
62
+ }
63
+ rnwgpu::Logger::logToConsole("GPUComputePassTimestampWrites::querySet = %f",
64
+ result->_instance.querySet);
65
+ rnwgpu::Logger::logToConsole(
66
+ "GPUComputePassTimestampWrites::beginningOfPassWriteIndex = %f",
67
+ result->_instance.beginningOfPassWriteIndex);
68
+ rnwgpu::Logger::logToConsole(
69
+ "GPUComputePassTimestampWrites::endOfPassWriteIndex = %f",
70
+ result->_instance.endOfPassWriteIndex);
71
+ return result;
72
+ }
73
+ static jsi::Value
74
+ toJSI(jsi::Runtime &runtime,
75
+ std::shared_ptr<rnwgpu::GPUComputePassTimestampWrites> arg) {
76
+ // No conversions here
77
+ return jsi::Value::null();
78
+ }
79
+ };
80
+ } // namespace margelo