react-native-wgpu 0.1.5 → 0.1.6
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.
- package/README.md +43 -42
- package/android/cpp/AndroidPlatformContext.h +2 -1
- package/cpp/jsi/RNFJSIConverter.h +10 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +1 -2
- package/cpp/rnwgpu/api/Canvas.h +3 -3
- package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
- package/ios/WebGPUView.mm +14 -1
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/utils.js +2 -2
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/utils.js +2 -2
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/lib/commonjs/utils.d.ts +1 -1
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -1
- package/lib/typescript/lib/module/utils.d.ts +1 -1
- package/lib/typescript/lib/module/utils.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +3 -2
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Constants.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Device.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Device.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/GPU.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Texture.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/DrawingContext.d.ts +12 -0
- package/lib/typescript/src/__tests__/components/DrawingContext.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +3 -0
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +29 -0
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +5 -0
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/cube.d.ts +7 -0
- package/lib/typescript/src/__tests__/components/cube.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +22 -0
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +12 -0
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +7 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +6 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +6 -0
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +10 -0
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/triangle.d.ts +3 -0
- package/lib/typescript/src/__tests__/components/triangle.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/config.d.ts +3 -0
- package/lib/typescript/src/__tests__/config.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/globalSetup.d.ts +10 -0
- package/lib/typescript/src/__tests__/globalSetup.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/globalTeardown.d.ts +3 -0
- package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/setup.d.ts +62 -0
- package/lib/typescript/src/__tests__/setup.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -1
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/{ios/libwebgpu_dawn.xcframework/ios-arm64 → apple/arm64_iphoneos}/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/{ios/arm64_xros/libwebgpu_dawn_visionos.a → apple/arm64_xros/libwebgpu_dawn.a} +0 -0
- package/libs/{ios → apple}/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn.a +0 -0
- package/libs/{ios/arm64_iphoneos → apple/libwebgpu_dawn.xcframework/ios-arm64}/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn_macosx.xcframework/Info.plist +28 -0
- package/libs/apple/libwebgpu_dawn_macosx.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/libs/{ios/libwebgpu_dawn_visionos.xcframework/xros-arm64_x86_64-simulator → apple}/libwebgpu_dawn_visionos.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn_visionos.xcframework/Info.plist +7 -7
- package/libs/{ios/libwebgpu_dawn_visionos.xcframework/xros-arm64/libwebgpu_dawn_visionos.a → apple/libwebgpu_dawn_visionos.xcframework/xros-arm64/libwebgpu_dawn.a} +0 -0
- package/libs/{ios → apple/libwebgpu_dawn_visionos.xcframework/xros-arm64_x86_64-simulator}/libwebgpu_dawn_visionos.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/x86_64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/package.json +23 -23
- package/src/Canvas.tsx +4 -2
- package/src/__tests__/ArrayBuffer.spec.ts +76 -0
- package/src/__tests__/Buffer.spec.ts +357 -0
- package/src/__tests__/ComputeShader.spec.ts +375 -0
- package/src/__tests__/Constants.spec.ts +91 -0
- package/src/__tests__/Device.spec.ts +35 -0
- package/src/__tests__/ExternalTexture.spec.ts +284 -0
- package/src/__tests__/GPU.spec.ts +229 -0
- package/src/__tests__/ImageData.spec.ts +26 -0
- package/src/__tests__/Shaders.spec.ts +232 -0
- package/src/__tests__/Texture.spec.ts +191 -0
- package/src/__tests__/assets/Di-3d.png +0 -0
- package/src/__tests__/components/DrawingContext.ts +11 -0
- package/src/__tests__/components/Wireframe/Shaders.ts +138 -0
- package/src/__tests__/components/Wireframe/models.ts +113 -0
- package/src/__tests__/components/Wireframe/utils.ts +22 -0
- package/src/__tests__/components/cube.ts +51 -0
- package/src/__tests__/components/meshes/mesh.ts +96 -0
- package/src/__tests__/components/meshes/sphere.ts +103 -0
- package/src/__tests__/components/meshes/stanfordDragon.ts +44 -0
- package/src/__tests__/components/meshes/stanfordDragonData.ts +5 -0
- package/src/__tests__/components/meshes/teapot.ts +13 -0
- package/src/__tests__/components/meshes/utils.ts +235 -0
- package/src/__tests__/components/triangle.ts +17 -0
- package/src/__tests__/config.ts +2 -0
- package/src/__tests__/demos/ABuffer.spec.ts +885 -0
- package/src/__tests__/demos/Blur.spec.ts +397 -0
- package/src/__tests__/demos/Cube.spec.ts +925 -0
- package/src/__tests__/demos/FractalCube.spec.ts +239 -0
- package/src/__tests__/demos/OcclusionQuery.spec.ts +376 -0
- package/src/__tests__/demos/RenderBundles.spec.ts +579 -0
- package/src/__tests__/demos/Triangle.spec.ts +248 -0
- package/src/__tests__/demos/Wireframe.spec.ts +190 -0
- package/src/__tests__/globalSetup.ts +54 -0
- package/src/__tests__/globalTeardown.ts +11 -0
- package/src/__tests__/setup.ts +409 -0
- package/src/__tests__/snapshots/abuffer.png +0 -0
- package/src/__tests__/snapshots/asteroid.png +0 -0
- package/src/__tests__/snapshots/blur.png +0 -0
- package/src/__tests__/snapshots/buffer.png +0 -0
- package/src/__tests__/snapshots/constant-triangle.png +0 -0
- package/src/__tests__/snapshots/cube.png +0 -0
- package/src/__tests__/snapshots/f.png +0 -0
- package/src/__tests__/snapshots/f2.png +0 -0
- package/src/__tests__/snapshots/fractal-cubes.png +0 -0
- package/src/__tests__/snapshots/instanced-cubes.png +0 -0
- package/src/__tests__/snapshots/occlusion-query.png +0 -0
- package/src/__tests__/snapshots/ref.png +0 -0
- package/src/__tests__/snapshots/texture.png +0 -0
- package/src/__tests__/snapshots/textured-cube.png +0 -0
- package/src/__tests__/snapshots/triangle-msaa.png +0 -0
- package/src/__tests__/snapshots/triangle.png +0 -0
- package/src/__tests__/snapshots/two-cube.png +0 -0
- package/src/utils.ts +3 -1
- package/android/gradle.properties +0 -5
- package/libs/ios/arm64_xros/libwebgpu_dawn.a +0 -0
- package/react-native-wgpu.podspec +0 -57
- 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 @@
|
|
|
1
|
+
{"version":3,"file":"stanfordDragonData.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/stanfordDragonData.ts"],"names":[],"mappings":";;;;AACA,wBAGE"}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"ABuffer.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/ABuffer.spec.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"RenderBundles.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/RenderBundles.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Triangle.spec.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/demos/Triangle.spec.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
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
|
|
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":"
|
|
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"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/libs/{ios/libwebgpu_dawn.xcframework/ios-arm64 → apple/arm64_iphoneos}/libwebgpu_dawn.a
RENAMED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/libs/{ios/arm64_iphoneos → apple/libwebgpu_dawn.xcframework/ios-arm64}/libwebgpu_dawn.a
RENAMED
|
Binary file
|
package/libs/{ios → apple}/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a
RENAMED
|
Binary file
|
|
@@ -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>
|
|
Binary file
|
|
Binary file
|
|
@@ -8,32 +8,32 @@
|
|
|
8
8
|
<key>BinaryPath</key>
|
|
9
9
|
<string>libwebgpu_dawn_visionos.a</string>
|
|
10
10
|
<key>LibraryIdentifier</key>
|
|
11
|
-
<string>xros-
|
|
11
|
+
<string>xros-arm64_x86_64-simulator</string>
|
|
12
12
|
<key>LibraryPath</key>
|
|
13
13
|
<string>libwebgpu_dawn_visionos.a</string>
|
|
14
14
|
<key>SupportedArchitectures</key>
|
|
15
15
|
<array>
|
|
16
16
|
<string>arm64</string>
|
|
17
|
+
<string>x86_64</string>
|
|
17
18
|
</array>
|
|
18
19
|
<key>SupportedPlatform</key>
|
|
19
20
|
<string>xros</string>
|
|
21
|
+
<key>SupportedPlatformVariant</key>
|
|
22
|
+
<string>simulator</string>
|
|
20
23
|
</dict>
|
|
21
24
|
<dict>
|
|
22
25
|
<key>BinaryPath</key>
|
|
23
|
-
<string>
|
|
26
|
+
<string>libwebgpu_dawn.a</string>
|
|
24
27
|
<key>LibraryIdentifier</key>
|
|
25
|
-
<string>xros-
|
|
28
|
+
<string>xros-arm64</string>
|
|
26
29
|
<key>LibraryPath</key>
|
|
27
|
-
<string>
|
|
30
|
+
<string>libwebgpu_dawn.a</string>
|
|
28
31
|
<key>SupportedArchitectures</key>
|
|
29
32
|
<array>
|
|
30
33
|
<string>arm64</string>
|
|
31
|
-
<string>x86_64</string>
|
|
32
34
|
</array>
|
|
33
35
|
<key>SupportedPlatform</key>
|
|
34
36
|
<string>xros</string>
|
|
35
|
-
<key>SupportedPlatformVariant</key>
|
|
36
|
-
<string>simulator</string>
|
|
37
37
|
</dict>
|
|
38
38
|
</array>
|
|
39
39
|
<key>CFBundlePackageType</key>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wgpu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -8,31 +8,22 @@
|
|
|
8
8
|
"react-native": "src/index",
|
|
9
9
|
"source": "src/index",
|
|
10
10
|
"files": [
|
|
11
|
-
"src",
|
|
12
|
-
"lib",
|
|
13
|
-
"android",
|
|
14
|
-
"
|
|
15
|
-
"cpp",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"!android/build",
|
|
21
|
-
"!android/gradle",
|
|
22
|
-
"!android/gradlew",
|
|
23
|
-
"!android/gradlew.bat",
|
|
24
|
-
"!android/local.properties",
|
|
25
|
-
"!**/__tests__",
|
|
26
|
-
"!**/__fixtures__",
|
|
27
|
-
"!**/__mocks__",
|
|
28
|
-
"!**/.*"
|
|
11
|
+
"src/**",
|
|
12
|
+
"lib/**",
|
|
13
|
+
"android/build.gradle",
|
|
14
|
+
"android/CMakeLists.txt",
|
|
15
|
+
"android/cpp/**",
|
|
16
|
+
"android/src/**",
|
|
17
|
+
"cpp/**/*.{h,cpp}",
|
|
18
|
+
"ios/**",
|
|
19
|
+
"libs/**"
|
|
29
20
|
],
|
|
30
21
|
"scripts": {
|
|
31
22
|
"test": "jest -i",
|
|
32
23
|
"test:ref": "REFERENCE=true yarn test -i",
|
|
33
|
-
"tsc": "tsc --noEmit",
|
|
34
24
|
"lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
|
|
35
|
-
"
|
|
25
|
+
"tsc": "tsc --noEmit",
|
|
26
|
+
"build": "bob build",
|
|
36
27
|
"build-dawn": "ts-node scripts/build/dawn.ts",
|
|
37
28
|
"clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
|
|
38
29
|
"clang-format": "yarn clang-format-ios && yarn clang-format-android && yarn clang-format-common",
|
|
@@ -40,6 +31,7 @@
|
|
|
40
31
|
"clang-format-android": "find android/cpp/ -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
|
|
41
32
|
"clang-format-common": "find cpp/rnwgpu -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
|
|
42
33
|
"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 .",
|
|
34
|
+
"download-artifacts": "ts-node scripts/build/download-artifacts.ts && yarn copy-artifacts",
|
|
43
35
|
"copy-artifacts": "ts-node scripts/build/copy-artifacts.ts",
|
|
44
36
|
"codegen": "ts-node scripts/codegen/codegen.ts && yarn clang-format"
|
|
45
37
|
},
|
|
@@ -70,9 +62,16 @@
|
|
|
70
62
|
"@types/react": "^18.2.44",
|
|
71
63
|
"@types/seedrandom": "^3.0.8",
|
|
72
64
|
"@types/ws": "^8.5.10",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
66
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
73
67
|
"@webgpu/types": "^0.1.44",
|
|
74
68
|
"clang-format": "^1.8.0",
|
|
75
69
|
"del-cli": "^5.1.0",
|
|
70
|
+
"eslint": "8",
|
|
71
|
+
"eslint-config-react-native-wcandillon": "^3.10.2",
|
|
72
|
+
"eslint-plugin-import": "2.27.5",
|
|
73
|
+
"eslint-plugin-jest": "^28.8.2",
|
|
74
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
76
75
|
"jest": "^29.7.0",
|
|
77
76
|
"lodash": "^4.17.21",
|
|
78
77
|
"pixelmatch": "5.3.0",
|
|
@@ -87,9 +86,10 @@
|
|
|
87
86
|
"teapot": "^1.0.0",
|
|
88
87
|
"ts-morph": "^22.0.0",
|
|
89
88
|
"ts-node": "^10.9.2",
|
|
90
|
-
"
|
|
89
|
+
"typescript": "^5.2.2",
|
|
91
90
|
"wgpu-matrix": "^3.0.2",
|
|
92
|
-
"ws": "^8.18.0"
|
|
91
|
+
"ws": "^8.18.0",
|
|
92
|
+
"yargs": "^17.7.2"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"react": "*",
|
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:
|
|
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
|
+
});
|