react-native-wgpu 0.1.12 → 0.1.14
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/android/CMakeLists.txt +7 -0
- package/android/build.gradle +4 -4
- package/android/cpp/cpp-adapter.cpp +10 -4
- package/android/cpp/platform/ThreadUtils.cpp +41 -0
- package/apple/ApplePlatformContext.h +19 -0
- package/apple/ApplePlatformContext.mm +86 -0
- package/apple/MetalView.h +13 -0
- package/apple/MetalView.mm +58 -0
- package/apple/WebGPUModule.h +19 -0
- package/apple/WebGPUModule.mm +93 -0
- package/apple/WebGPUView.h +15 -0
- package/apple/WebGPUView.mm +68 -0
- package/apple/WebGPUViewManager.mm +23 -0
- package/apple/platform/ThreadUtils.cpp +33 -0
- package/cpp/jsi/RNFJSIConverter.h +47 -28
- package/cpp/platform/ThreadUtils.h +30 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +8 -0
- package/cpp/rnwgpu/api/Convertors.h +13 -14
- package/cpp/rnwgpu/api/GPU.cpp +4 -4
- package/cpp/rnwgpu/api/GPUAdapter.cpp +15 -14
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +25 -4
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +6 -4
- package/cpp/rnwgpu/api/GPUDevice.cpp +5 -5
- package/cpp/rnwgpu/api/GPUDevice.h +7 -1
- package/cpp/rnwgpu/api/GPUFeatures.h +4 -4
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +2 -1
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +9 -0
- package/cpp/threading/CallInvokerDispatcher.h +37 -0
- package/cpp/threading/Dispatcher.cpp +54 -0
- package/cpp/threading/Dispatcher.h +93 -0
- package/cpp/threading/ThreadPool.cpp +86 -0
- package/cpp/threading/ThreadPool.h +53 -0
- package/cpp/webgpu/webgpu.h +762 -758
- package/cpp/webgpu/webgpu_cpp.h +1827 -1626
- package/cpp/webgpu/webgpu_cpp_chained_struct.h +2 -0
- package/lib/commonjs/hooks.js +4 -2
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/module/hooks.js +4 -2
- package/lib/module/hooks.js.map +1 -1
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +1 -0
- package/lib/typescript/src/hooks.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/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +10 -10
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/dawn.json +270 -251
- package/package.json +2 -2
- package/src/__tests__/Alpha.spec.ts +28 -0
- package/src/__tests__/Device.spec.ts +31 -0
- package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
- package/src/hooks.tsx +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wgpu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"android/cpp/**",
|
|
16
16
|
"android/src/**",
|
|
17
17
|
"cpp/**/*.{h,cpp}",
|
|
18
|
-
"
|
|
18
|
+
"apple/**",
|
|
19
19
|
"libs/**",
|
|
20
20
|
"*.podspec"
|
|
21
21
|
],
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { checkImage, client, encodeImage } from "./setup";
|
|
2
|
+
|
|
3
|
+
describe("Alpha", () => {
|
|
4
|
+
it("Premultiplied Color", async () => {
|
|
5
|
+
const result = await client.eval(({ device, ctx, canvas }) => {
|
|
6
|
+
const commandEncoder = device.createCommandEncoder();
|
|
7
|
+
const textureView = ctx.getCurrentTexture().createView();
|
|
8
|
+
const alpha = 0.5;
|
|
9
|
+
const renderPassDescriptor: GPURenderPassDescriptor = {
|
|
10
|
+
colorAttachments: [
|
|
11
|
+
{
|
|
12
|
+
view: textureView,
|
|
13
|
+
clearValue: [0.3 * alpha, 0.6 * alpha, 1 * alpha, alpha],
|
|
14
|
+
loadOp: "clear",
|
|
15
|
+
storeOp: "store",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
21
|
+
passEncoder.end();
|
|
22
|
+
device.queue.submit([commandEncoder.finish()]);
|
|
23
|
+
return canvas.getImageData();
|
|
24
|
+
});
|
|
25
|
+
const image = encodeImage(result);
|
|
26
|
+
checkImage(image, "snapshots/semi-opaque-cyan.png");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -32,4 +32,35 @@ describe("Device", () => {
|
|
|
32
32
|
);
|
|
33
33
|
expect(["unknown", "destroyed"].includes(result.reason)).toBe(true);
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
it("times out device.lost if the device has not been destroyed", async () => {
|
|
37
|
+
const isDeviceLost = await client.eval(({ device }) => {
|
|
38
|
+
const timeout = new Promise((resolve) => {
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
resolve(false);
|
|
41
|
+
}, 50);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return Promise.race([device.lost.then(() => true), timeout]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(isDeviceLost).toBeFalsy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("resolves an awaited device.lost when device.destroy is called", async () => {
|
|
51
|
+
const result = await client.eval(({ adapter }) =>
|
|
52
|
+
adapter.requestDevice({ label: "myGPU2" }).then((device) => {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
device.destroy();
|
|
55
|
+
}, 50);
|
|
56
|
+
|
|
57
|
+
return device.lost.then((r) => ({
|
|
58
|
+
reason: r.reason,
|
|
59
|
+
message: r.message,
|
|
60
|
+
}));
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(["unknown", "destroyed"].includes(result.reason)).toBeTruthy();
|
|
65
|
+
});
|
|
35
66
|
});
|
|
Binary file
|
package/src/hooks.tsx
CHANGED
|
@@ -6,9 +6,10 @@ import type { RNCanvasContext, CanvasRef, NativeCanvas } from "./Canvas";
|
|
|
6
6
|
type Unsubscribe = () => void;
|
|
7
7
|
|
|
8
8
|
export const warnIfNotHardwareAccelerated = (adapter: GPUAdapter) => {
|
|
9
|
-
if (adapter.
|
|
9
|
+
if (adapter.isFallbackAdapter) {
|
|
10
10
|
console.warn(
|
|
11
|
-
|
|
11
|
+
// eslint-disable-next-line max-len
|
|
12
|
+
"GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow. Some features may be unavailable.",
|
|
12
13
|
);
|
|
13
14
|
}
|
|
14
15
|
};
|