react-native-wgpu 0.1.5 → 0.1.7

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 (168) hide show
  1. package/README.md +43 -42
  2. package/android/cpp/AndroidPlatformContext.h +2 -1
  3. package/cpp/jsi/RNFJSIConverter.h +10 -0
  4. package/cpp/rnwgpu/SurfaceRegistry.h +1 -2
  5. package/cpp/rnwgpu/api/Canvas.h +3 -3
  6. package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
  7. package/ios/WebGPUView.mm +14 -1
  8. package/lib/commonjs/Canvas.js.map +1 -1
  9. package/lib/commonjs/utils.js +2 -2
  10. package/lib/commonjs/utils.js.map +1 -1
  11. package/lib/module/Canvas.js.map +1 -1
  12. package/lib/module/utils.js +2 -2
  13. package/lib/module/utils.js.map +1 -1
  14. package/lib/typescript/lib/commonjs/utils.d.ts +1 -1
  15. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -1
  16. package/lib/typescript/lib/module/utils.d.ts +1 -1
  17. package/lib/typescript/lib/module/utils.d.ts.map +1 -1
  18. package/lib/typescript/src/Canvas.d.ts +3 -2
  19. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  20. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +2 -0
  21. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +1 -0
  22. package/lib/typescript/src/__tests__/Buffer.spec.d.ts +2 -0
  23. package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +1 -0
  24. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +2 -0
  25. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +1 -0
  26. package/lib/typescript/src/__tests__/Constants.spec.d.ts +2 -0
  27. package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +1 -0
  28. package/lib/typescript/src/__tests__/Device.spec.d.ts +2 -0
  29. package/lib/typescript/src/__tests__/Device.spec.d.ts.map +1 -0
  30. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +2 -0
  31. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +1 -0
  32. package/lib/typescript/src/__tests__/GPU.spec.d.ts +2 -0
  33. package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +1 -0
  34. package/lib/typescript/src/__tests__/ImageData.spec.d.ts +2 -0
  35. package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +1 -0
  36. package/lib/typescript/src/__tests__/Shaders.spec.d.ts +2 -0
  37. package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +1 -0
  38. package/lib/typescript/src/__tests__/Texture.spec.d.ts +2 -0
  39. package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +1 -0
  40. package/lib/typescript/src/__tests__/components/DrawingContext.d.ts +12 -0
  41. package/lib/typescript/src/__tests__/components/DrawingContext.d.ts.map +1 -0
  42. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +3 -0
  43. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +1 -0
  44. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +29 -0
  45. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +1 -0
  46. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +5 -0
  47. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +1 -0
  48. package/lib/typescript/src/__tests__/components/cube.d.ts +7 -0
  49. package/lib/typescript/src/__tests__/components/cube.d.ts.map +1 -0
  50. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +22 -0
  51. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +1 -0
  52. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +12 -0
  53. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +1 -0
  54. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +7 -0
  55. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +1 -0
  56. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +6 -0
  57. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +1 -0
  58. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +6 -0
  59. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +1 -0
  60. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +10 -0
  61. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +1 -0
  62. package/lib/typescript/src/__tests__/components/triangle.d.ts +3 -0
  63. package/lib/typescript/src/__tests__/components/triangle.d.ts.map +1 -0
  64. package/lib/typescript/src/__tests__/config.d.ts +3 -0
  65. package/lib/typescript/src/__tests__/config.d.ts.map +1 -0
  66. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +2 -0
  67. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +1 -0
  68. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +2 -0
  69. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +1 -0
  70. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +2 -0
  71. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +1 -0
  72. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +2 -0
  73. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +1 -0
  74. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +2 -0
  75. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +1 -0
  76. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +2 -0
  77. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +1 -0
  78. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +2 -0
  79. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +1 -0
  80. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +2 -0
  81. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +1 -0
  82. package/lib/typescript/src/__tests__/globalSetup.d.ts +10 -0
  83. package/lib/typescript/src/__tests__/globalSetup.d.ts.map +1 -0
  84. package/lib/typescript/src/__tests__/globalTeardown.d.ts +3 -0
  85. package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +1 -0
  86. package/lib/typescript/src/__tests__/setup.d.ts +62 -0
  87. package/lib/typescript/src/__tests__/setup.d.ts.map +1 -0
  88. package/lib/typescript/src/utils.d.ts +2 -1
  89. package/lib/typescript/src/utils.d.ts.map +1 -1
  90. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  91. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  92. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  93. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  94. package/libs/{ios/libwebgpu_dawn.xcframework/ios-arm64 → apple/arm64_iphoneos}/libwebgpu_dawn.a +0 -0
  95. package/libs/{ios → apple}/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  96. package/libs/{ios → apple}/arm64_xros/libwebgpu_dawn.a +0 -0
  97. package/libs/{ios → apple}/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  98. package/libs/{ios → apple}/libwebgpu_dawn.a +0 -0
  99. package/libs/{ios/arm64_iphoneos → apple/libwebgpu_dawn.xcframework/ios-arm64}/libwebgpu_dawn.a +0 -0
  100. package/libs/{ios → apple}/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  101. package/libs/apple/libwebgpu_dawn_macosx.xcframework/Info.plist +28 -0
  102. package/libs/apple/libwebgpu_dawn_macosx.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
  103. package/libs/{ios/libwebgpu_dawn_visionos.xcframework/xros-arm64_x86_64-simulator → apple}/libwebgpu_dawn_visionos.a +0 -0
  104. package/libs/{ios → apple}/libwebgpu_dawn_visionos.xcframework/Info.plist +2 -2
  105. package/libs/{ios/arm64_xros/libwebgpu_dawn_visionos.a → apple/libwebgpu_dawn_visionos.xcframework/xros-arm64/libwebgpu_dawn.a} +0 -0
  106. package/libs/{ios → apple/libwebgpu_dawn_visionos.xcframework/xros-arm64_x86_64-simulator}/libwebgpu_dawn_visionos.a +0 -0
  107. package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
  108. package/libs/{ios → apple}/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  109. package/libs/{ios → apple}/x86_64_xrsimulator/libwebgpu_dawn.a +0 -0
  110. package/package.json +23 -22
  111. package/react-native-wgpu.podspec +2 -2
  112. package/src/Canvas.tsx +4 -2
  113. package/src/__tests__/ArrayBuffer.spec.ts +76 -0
  114. package/src/__tests__/Buffer.spec.ts +357 -0
  115. package/src/__tests__/ComputeShader.spec.ts +375 -0
  116. package/src/__tests__/Constants.spec.ts +91 -0
  117. package/src/__tests__/Device.spec.ts +35 -0
  118. package/src/__tests__/ExternalTexture.spec.ts +284 -0
  119. package/src/__tests__/GPU.spec.ts +229 -0
  120. package/src/__tests__/ImageData.spec.ts +26 -0
  121. package/src/__tests__/Shaders.spec.ts +232 -0
  122. package/src/__tests__/Texture.spec.ts +191 -0
  123. package/src/__tests__/assets/Di-3d.png +0 -0
  124. package/src/__tests__/components/DrawingContext.ts +11 -0
  125. package/src/__tests__/components/Wireframe/Shaders.ts +138 -0
  126. package/src/__tests__/components/Wireframe/models.ts +113 -0
  127. package/src/__tests__/components/Wireframe/utils.ts +22 -0
  128. package/src/__tests__/components/cube.ts +51 -0
  129. package/src/__tests__/components/meshes/mesh.ts +96 -0
  130. package/src/__tests__/components/meshes/sphere.ts +103 -0
  131. package/src/__tests__/components/meshes/stanfordDragon.ts +44 -0
  132. package/src/__tests__/components/meshes/stanfordDragonData.ts +5 -0
  133. package/src/__tests__/components/meshes/teapot.ts +13 -0
  134. package/src/__tests__/components/meshes/utils.ts +235 -0
  135. package/src/__tests__/components/triangle.ts +17 -0
  136. package/src/__tests__/config.ts +2 -0
  137. package/src/__tests__/demos/ABuffer.spec.ts +885 -0
  138. package/src/__tests__/demos/Blur.spec.ts +397 -0
  139. package/src/__tests__/demos/Cube.spec.ts +925 -0
  140. package/src/__tests__/demos/FractalCube.spec.ts +239 -0
  141. package/src/__tests__/demos/OcclusionQuery.spec.ts +376 -0
  142. package/src/__tests__/demos/RenderBundles.spec.ts +579 -0
  143. package/src/__tests__/demos/Triangle.spec.ts +248 -0
  144. package/src/__tests__/demos/Wireframe.spec.ts +190 -0
  145. package/src/__tests__/globalSetup.ts +54 -0
  146. package/src/__tests__/globalTeardown.ts +11 -0
  147. package/src/__tests__/setup.ts +409 -0
  148. package/src/__tests__/snapshots/abuffer.png +0 -0
  149. package/src/__tests__/snapshots/asteroid.png +0 -0
  150. package/src/__tests__/snapshots/blur.png +0 -0
  151. package/src/__tests__/snapshots/buffer.png +0 -0
  152. package/src/__tests__/snapshots/constant-triangle.png +0 -0
  153. package/src/__tests__/snapshots/cube.png +0 -0
  154. package/src/__tests__/snapshots/f.png +0 -0
  155. package/src/__tests__/snapshots/f2.png +0 -0
  156. package/src/__tests__/snapshots/fractal-cubes.png +0 -0
  157. package/src/__tests__/snapshots/instanced-cubes.png +0 -0
  158. package/src/__tests__/snapshots/occlusion-query.png +0 -0
  159. package/src/__tests__/snapshots/ref.png +0 -0
  160. package/src/__tests__/snapshots/texture.png +0 -0
  161. package/src/__tests__/snapshots/textured-cube.png +0 -0
  162. package/src/__tests__/snapshots/triangle-msaa.png +0 -0
  163. package/src/__tests__/snapshots/triangle.png +0 -0
  164. package/src/__tests__/snapshots/two-cube.png +0 -0
  165. package/src/utils.ts +3 -1
  166. package/android/gradle.properties +0 -5
  167. package/libs/ios/libwebgpu_dawn_visionos.xcframework/xros-arm64/libwebgpu_dawn_visionos.a +0 -0
  168. package/libs/{ios → apple}/libwebgpu_dawn.xcframework/Info.plist +5 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stanfordDragon.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/stanfordDragon.ts"],"names":[],"mappings":"AAsCA,eAAO,MAAM,IAAI;;;;;CAKhB,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ cells: number[][];
3
+ positions: number[][];
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=stanfordDragonData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stanfordDragonData.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/stanfordDragonData.ts"],"names":[],"mappings":";;;;AACA,wBAGE"}
@@ -0,0 +1,6 @@
1
+ export declare const mesh: {
2
+ positions: [number, number, number][];
3
+ triangles: [number, number, number][];
4
+ normals: [number, number, number][];
5
+ };
6
+ //# sourceMappingURL=teapot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teapot.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/teapot.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI;eACoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;eAC9B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;aAC1C,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;CAC1C,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare function computeSurfaceNormals(positions: [number, number, number][], triangles: [number, number, number][]): [number, number, number][];
2
+ export declare function generateNormals(maxAngle: number, positions: [number, number, number][], triangles: [number, number, number][]): {
3
+ positions: [number, number, number][];
4
+ normals: [number, number, number][];
5
+ triangles: [number, number, number][];
6
+ };
7
+ type ProjectedPlane = "xy" | "xz" | "yz";
8
+ export declare function computeProjectedPlaneUVs(positions: [number, number, number][], projectedPlane?: ProjectedPlane): [number, number][];
9
+ export {};
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GACpC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CA4B5B;AAsBD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;;;;EA2ItC;AAED,KAAK,cAAc,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAQzC,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,cAAc,GAAE,cAAqB,GACpC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAuBpB"}
@@ -0,0 +1,3 @@
1
+ export declare const triangleVertWGSL = "@vertex\nfn main(\n @builtin(vertex_index) VertexIndex : u32\n) -> @builtin(position) vec4f {\n var pos = array<vec2f, 3>(\n vec2(0.0, 0.5),\n vec2(-0.5, -0.5),\n vec2(0.5, -0.5)\n );\n\n return vec4f(pos[VertexIndex], 0.0, 1.0);\n}";
2
+ export declare const redFragWGSL = "@fragment\nfn main() -> @location(0) vec4f {\n return vec4(1.0, 0.0, 0.0, 1.0);\n}";
3
+ //# sourceMappingURL=triangle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triangle.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/components/triangle.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,0PAW3B,CAAC;AAEH,eAAO,MAAM,WAAW,wFAGtB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const DEBUG: boolean;
2
+ export declare const REFERENCE: boolean;
3
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,SAA+B,CAAC;AAClD,eAAO,MAAM,SAAS,SAAmC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ABuffer.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ABuffer.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/ABuffer.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Blur.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blur.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/Blur.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare const basicVert = "struct Uniforms {\n modelViewProjectionMatrix : mat4x4f,\n}\n@binding(0) @group(0) var<uniform> uniforms : Uniforms;\n\nstruct VertexOutput {\n @builtin(position) Position : vec4f,\n @location(0) fragUV : vec2f,\n @location(1) fragPosition: vec4f,\n}\n\n@vertex\nfn main(\n @location(0) position : vec4f,\n @location(1) uv : vec2f\n) -> VertexOutput {\n var output : VertexOutput;\n output.Position = uniforms.modelViewProjectionMatrix * position;\n output.fragUV = uv;\n output.fragPosition = 0.5 * (position + vec4(1.0, 1.0, 1.0, 1.0));\n return output;\n}\n";
2
+ //# sourceMappingURL=Cube.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cube.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/Cube.spec.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,gkBAsBrB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=FractalCube.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FractalCube.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/FractalCube.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
2
+ //# sourceMappingURL=OcclusionQuery.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OcclusionQuery.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/OcclusionQuery.spec.ts"],"names":[],"mappings":"AA6CA,MAAM,MAAM,qBAAqB,GAC7B,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RenderBundles.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderBundles.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/RenderBundles.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Triangle.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Triangle.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/Triangle.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Wireframe.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wireframe.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/Wireframe.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { Server, WebSocket } from "ws";
2
+ declare global {
3
+ var testServer: Server;
4
+ var testClient: WebSocket;
5
+ var testOS: "ios" | "android" | "web" | "node";
6
+ var testArch: "paper" | "fabric";
7
+ }
8
+ declare const globalSetup: () => Promise<void>;
9
+ export default globalSetup;
10
+ //# sourceMappingURL=globalSetup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/globalSetup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAK5C,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,UAAU,EAAE,MAAM,CAAC;IACvB,IAAI,UAAU,EAAE,SAAS,CAAC;IAC1B,IAAI,MAAM,EAAE,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;IAC/C,IAAI,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC;CAClC;AAUD,QAAA,MAAM,WAAW,qBA6BhB,CAAC;AAGF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const globalTeardown: () => void;
2
+ export default globalTeardown;
3
+ //# sourceMappingURL=globalTeardown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalTeardown.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/globalTeardown.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc,YAOnB,CAAC;AAGF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { PNG } from "pngjs";
2
+ import type { mat4, vec3, mat3 } from "wgpu-matrix";
3
+ import type { Server, WebSocket } from "ws";
4
+ import type { DrawingContext } from "./components/DrawingContext";
5
+ type TestOS = "ios" | "android" | "web" | "node";
6
+ declare global {
7
+ var testServer: Server;
8
+ var testClient: WebSocket;
9
+ var testOS: TestOS;
10
+ }
11
+ interface GPUContext {
12
+ gpu: GPU;
13
+ adapter: GPUAdapter;
14
+ device: GPUDevice;
15
+ shaders: {
16
+ triangleVertWGSL: string;
17
+ redFragWGSL: string;
18
+ };
19
+ urls: {
20
+ fTexture: string;
21
+ };
22
+ assets: {
23
+ cubeVertexArray: Float32Array;
24
+ di3D: ImageData;
25
+ moon: ImageData;
26
+ saturn: ImageData;
27
+ };
28
+ ctx: DrawingContext;
29
+ mat4: typeof mat4;
30
+ vec3: typeof vec3;
31
+ mat3: typeof mat3;
32
+ }
33
+ type Ctx = Record<string, unknown>;
34
+ type JSONValue = {
35
+ [key: string]: JSONValue;
36
+ } | JSONValue[] | number | string | boolean | null;
37
+ interface TestingClient {
38
+ eval<C = Ctx, R = JSONValue>(fn: (ctx: GPUContext & C) => R | Promise<R>, ctx?: C): Promise<R>;
39
+ OS: TestOS;
40
+ arch: "paper" | "fabric";
41
+ init(): Promise<void>;
42
+ dispose(): Promise<void>;
43
+ }
44
+ export declare let client: TestingClient;
45
+ interface BitmapData {
46
+ data: number[];
47
+ width: number;
48
+ height: number;
49
+ format: string;
50
+ }
51
+ export declare const encodeImage: (bitmap: BitmapData) => PNG;
52
+ interface CheckImageOptions {
53
+ maxPixelDiff?: number;
54
+ threshold?: number;
55
+ overwrite?: boolean;
56
+ mute?: boolean;
57
+ shouldFail?: boolean;
58
+ }
59
+ export declare const checkImage: (toTest: PNG, relPath: string, opts?: CheckImageOptions) => number;
60
+ export declare const decodeImage: (relPath: string) => BitmapData;
61
+ export {};
62
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/setup.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAOlE,KAAK,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,UAAU,EAAE,MAAM,CAAC;IACvB,IAAI,UAAU,EAAE,SAAS,CAAC;IAC1B,IAAI,MAAM,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,UAAU;IAClB,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,EAAE,UAAU,CAAC;IACpB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE;QACP,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,MAAM,EAAE;QACN,eAAe,EAAE,YAAY,CAAC;QAC9B,IAAI,EAAE,SAAS,CAAC;QAChB,IAAI,EAAE,SAAS,CAAC;QAChB,MAAM,EAAE,SAAS,CAAC;KACnB,CAAC;IACF,GAAG,EAAE,cAAc,CAAC;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB;AAED,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnC,KAAK,SAAS,GACV;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC5B,SAAS,EAAE,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,CAAC;AAET,UAAU,aAAa;IACrB,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,SAAS,EACzB,EAAE,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC3C,GAAG,CAAC,EAAE,CAAC,GACN,OAAO,CAAC,CAAC,CAAC,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,eAAO,IAAI,MAAM,EAAE,aAAa,CAAC;AAiOjC,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,WAAW,WAAY,UAAU,QAuB7C,CAAC;AAEF,UAAU,iBAAiB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAYD,eAAO,MAAM,UAAU,WACb,GAAG,WACF,MAAM,SACR,iBAAiB,WA2CzB,CAAC;AAEF,eAAO,MAAM,WAAW,YAAa,MAAM,KAAG,UAa7C,CAAC"}
@@ -1,6 +1,7 @@
1
+ import type { DependencyList } from "react";
1
2
  import type { CanvasRef } from "./Canvas";
2
3
  type Unsubscribe = () => void;
3
4
  export declare const warnIfNotHardwareAccelerated: (adapter: GPUAdapter) => void;
4
- export declare const useCanvasEffect: (effect: () => void | Unsubscribe | Promise<void | Unsubscribe>) => import("react").RefObject<CanvasRef>;
5
+ export declare const useCanvasEffect: (effect: () => void | Unsubscribe | Promise<void | Unsubscribe>, deps?: DependencyList) => import("react").RefObject<CanvasRef>;
5
6
  export {};
6
7
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B,eAAO,MAAM,4BAA4B,YAAa,UAAU,SAM/D,CAAC;AAEF,eAAO,MAAM,eAAe,WAClB,MAAM,IAAI,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,yCAwB/D,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B,eAAO,MAAM,4BAA4B,YAAa,UAAU,SAM/D,CAAC;AAEF,eAAO,MAAM,eAAe,WAClB,MAAM,IAAI,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,SACxD,cAAc,yCAwBrB,CAAC"}
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>libwebgpu_dawn.a</string>
10
+ <key>LibraryIdentifier</key>
11
+ <string>macos-arm64_x86_64</string>
12
+ <key>LibraryPath</key>
13
+ <string>libwebgpu_dawn.a</string>
14
+ <key>SupportedArchitectures</key>
15
+ <array>
16
+ <string>arm64</string>
17
+ <string>x86_64</string>
18
+ </array>
19
+ <key>SupportedPlatform</key>
20
+ <string>macos</string>
21
+ </dict>
22
+ </array>
23
+ <key>CFBundlePackageType</key>
24
+ <string>XFWK</string>
25
+ <key>XCFrameworkFormatVersion</key>
26
+ <string>1.0</string>
27
+ </dict>
28
+ </plist>
@@ -6,11 +6,11 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>BinaryPath</key>
9
- <string>libwebgpu_dawn_visionos.a</string>
9
+ <string>libwebgpu_dawn.a</string>
10
10
  <key>LibraryIdentifier</key>
11
11
  <string>xros-arm64</string>
12
12
  <key>LibraryPath</key>
13
- <string>libwebgpu_dawn_visionos.a</string>
13
+ <string>libwebgpu_dawn.a</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wgpu",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -8,31 +8,23 @@
8
8
  "react-native": "src/index",
9
9
  "source": "src/index",
10
10
  "files": [
11
- "src",
12
- "lib",
13
- "android",
14
- "ios",
15
- "cpp",
16
- "*.podspec",
11
+ "src/**",
12
+ "lib/**",
13
+ "android/build.gradle",
14
+ "android/CMakeLists.txt",
15
+ "android/cpp/**",
16
+ "android/src/**",
17
+ "cpp/**/*.{h,cpp}",
18
+ "ios/**",
17
19
  "libs/**",
18
- "!scripts",
19
- "!ios/build",
20
- "!android/build",
21
- "!android/gradle",
22
- "!android/gradlew",
23
- "!android/gradlew.bat",
24
- "!android/local.properties",
25
- "!**/__tests__",
26
- "!**/__fixtures__",
27
- "!**/__mocks__",
28
- "!**/.*"
20
+ "*.podspec"
29
21
  ],
30
22
  "scripts": {
31
23
  "test": "jest -i",
32
24
  "test:ref": "REFERENCE=true yarn test -i",
33
- "tsc": "tsc --noEmit",
34
25
  "lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
35
- "prepare": "bob build",
26
+ "tsc": "tsc --noEmit",
27
+ "build": "bob build",
36
28
  "build-dawn": "ts-node scripts/build/dawn.ts",
37
29
  "clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
38
30
  "clang-format": "yarn clang-format-ios && yarn clang-format-android && yarn clang-format-common",
@@ -40,6 +32,7 @@
40
32
  "clang-format-android": "find android/cpp/ -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
41
33
  "clang-format-common": "find cpp/rnwgpu -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
42
34
  "cpplint": "cpplint --linelength=230 --filter=-legal/copyright,-whitespace/indent,-whitespace/comments,-whitespace/ending_newline,-build/include_order,-runtime/references,-readability/todo,-whitespace/blank_line,-whitespace/todo,-runtime/int,-build/c++11,-whitespace/parens --exclude=example --exclude=android/.cxx --exclude=cpp/webgpu --exclude=cpp/dawn --exclude=ios --exclude=android/build --exclude=node_modules --recursive .",
35
+ "download-artifacts": "ts-node scripts/build/download-artifacts.ts && yarn copy-artifacts",
43
36
  "copy-artifacts": "ts-node scripts/build/copy-artifacts.ts",
44
37
  "codegen": "ts-node scripts/codegen/codegen.ts && yarn clang-format"
45
38
  },
@@ -70,9 +63,16 @@
70
63
  "@types/react": "^18.2.44",
71
64
  "@types/seedrandom": "^3.0.8",
72
65
  "@types/ws": "^8.5.10",
66
+ "@typescript-eslint/eslint-plugin": "^8.4.0",
67
+ "@typescript-eslint/parser": "^8.4.0",
73
68
  "@webgpu/types": "^0.1.44",
74
69
  "clang-format": "^1.8.0",
75
70
  "del-cli": "^5.1.0",
71
+ "eslint": "8",
72
+ "eslint-config-react-native-wcandillon": "^3.10.2",
73
+ "eslint-plugin-import": "2.27.5",
74
+ "eslint-plugin-jest": "^28.8.2",
75
+ "eslint-plugin-prettier": "^5.2.1",
76
76
  "jest": "^29.7.0",
77
77
  "lodash": "^4.17.21",
78
78
  "pixelmatch": "5.3.0",
@@ -87,9 +87,10 @@
87
87
  "teapot": "^1.0.0",
88
88
  "ts-morph": "^22.0.0",
89
89
  "ts-node": "^10.9.2",
90
- "turbo": "^1.10.7",
90
+ "typescript": "^5.2.2",
91
91
  "wgpu-matrix": "^3.0.2",
92
- "ws": "^8.18.0"
92
+ "ws": "^8.18.0",
93
+ "yargs": "^17.7.2"
93
94
  },
94
95
  "peerDependencies": {
95
96
  "react": "*",
@@ -20,11 +20,11 @@ Pod::Spec.new do |s|
20
20
  ]
21
21
 
22
22
  s.ios.vendored_frameworks = [
23
- 'libs/ios/libwebgpu_dawn.xcframework',
23
+ 'libs/apple/libwebgpu_dawn.xcframework',
24
24
  ]
25
25
 
26
26
  s.visionos.vendored_frameworks = [
27
- 'libs/ios/libwebgpu_dawn_visionos.xcframework',
27
+ 'libs/apple/libwebgpu_dawn_visionos.xcframework',
28
28
  ]
29
29
 
30
30
  s.pod_target_xcconfig = {
package/src/Canvas.tsx CHANGED
@@ -21,8 +21,10 @@ declare global {
21
21
  };
22
22
  }
23
23
 
24
+ type SurfacePointer = bigint;
25
+
24
26
  export interface NativeCanvas {
25
- surface: bigint;
27
+ surface: SurfacePointer;
26
28
  width: number;
27
29
  height: number;
28
30
  clientWidth: number;
@@ -34,11 +36,11 @@ const WebGPUContextRegistry = global.__WebGPUContextRegistry;
34
36
 
35
37
  type CanvasContext = GPUCanvasContext & {
36
38
  present: () => void;
37
- getNativeSurface: () => NativeCanvas;
38
39
  };
39
40
 
40
41
  export interface CanvasRef {
41
42
  getContext(contextName: "webgpu"): CanvasContext | null;
43
+ getNativeSurface: () => NativeCanvas;
42
44
  }
43
45
 
44
46
  export const Canvas = forwardRef<CanvasRef, ViewProps>((props, ref) => {
@@ -0,0 +1,76 @@
1
+ import { client } from "./setup";
2
+
3
+ describe("Buffer", () => {
4
+ it("Array Buffer (1)", async () => {
5
+ const result = await client.eval(() => {
6
+ return Array.from(new Uint8Array([1.0, 2.0, 3.0, 4.0]));
7
+ });
8
+ expect(result.slice(0, 4)).toEqual([1, 2, 3, 4]);
9
+ });
10
+ it("Array Buffer (2)", async () => {
11
+ const result = await client.eval(({ device }) => {
12
+ const data = new Float32Array([1.0, 2.0, 3.0, 4.0]);
13
+ const bufferSize = data.byteLength; // 4 32-bit floats
14
+ const sourceBuffer = device.createBuffer({
15
+ size: bufferSize,
16
+ usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
17
+ });
18
+
19
+ // Create a buffer for reading
20
+ const readBuffer = device.createBuffer({
21
+ size: bufferSize,
22
+ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
23
+ });
24
+
25
+ // Create data to upload
26
+
27
+ // Write data to the source buffer
28
+ device.queue.writeBuffer(sourceBuffer, 0, data);
29
+
30
+ // Copy data from source buffer to read buffer
31
+ const encoder = device.createCommandEncoder();
32
+ encoder.copyBufferToBuffer(sourceBuffer, 0, readBuffer, 0, bufferSize);
33
+ device.queue.submit([encoder.finish()]);
34
+ return device.queue.onSubmittedWorkDone().then(() => {
35
+ // Map the read buffer for reading
36
+ return readBuffer.mapAsync(GPUMapMode.READ).then(() => {
37
+ const readData = new Float32Array(readBuffer.getMappedRange());
38
+ return Array.from(readData);
39
+ });
40
+ });
41
+ });
42
+ expect(result).toEqual([1, 2, 3, 4]);
43
+ });
44
+ it("Array Buffer (3)", async () => {
45
+ const result = await client.eval(({ device }) => {
46
+ const data = new Float32Array([1.0, 2.0, 3.0, 4.0]);
47
+ const bufferSize = data.byteLength; // 4 32-bit floats
48
+ const sourceBuffer = device.createBuffer({
49
+ size: bufferSize,
50
+ usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
51
+ });
52
+
53
+ // Create a buffer for reading
54
+ const readBuffer = device.createBuffer({
55
+ size: bufferSize,
56
+ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
57
+ });
58
+
59
+ // Create data to upload
60
+
61
+ // Write data to the source buffer
62
+ device.queue.writeBuffer(sourceBuffer, 0, data);
63
+
64
+ // Copy data from source buffer to read buffer
65
+ const encoder = device.createCommandEncoder();
66
+ encoder.copyBufferToBuffer(sourceBuffer, 0, readBuffer, 0, bufferSize);
67
+ device.queue.submit([encoder.finish()]);
68
+ // Map the read buffer for reading
69
+ return readBuffer.mapAsync(GPUMapMode.READ).then(() => {
70
+ const readData = new Float32Array(readBuffer.getMappedRange());
71
+ return Array.from(readData);
72
+ });
73
+ });
74
+ expect(result).toEqual([1, 2, 3, 4]);
75
+ });
76
+ });