|
1 | 1 | import React, { useEffect, useRef } from "react"; |
2 | 2 | import { StyleSheet, View } from "react-native"; |
3 | 3 | import type { CanvasRef, RNCanvasContext } from "react-native-wgpu"; |
4 | | -import { Canvas } from "react-native-wgpu"; |
| 4 | +import { Canvas, registerWebGPUSerializable } from "react-native-wgpu"; |
5 | 5 | import type { SharedValue } from "react-native-reanimated"; |
6 | 6 | import { runOnUI, useSharedValue } from "react-native-reanimated"; |
7 | | -import { registerCustomSerializable } from "react-native-worklets"; |
8 | 7 |
|
9 | 8 | import { redFragWGSL, triangleVertWGSL } from "../Triangle/triangle"; |
10 | 9 |
|
11 | | -// Declare global WebGPU worklet helper functions (installed on main runtime) |
12 | | -declare function __webgpuIsWebGPUObject(obj: unknown): boolean; |
13 | | -declare function __webgpuBox( |
14 | | - obj: object, |
15 | | -): { unbox: () => object; __boxedWebGPU: true }; |
16 | | - |
17 | 10 | // Register WebGPU objects for Worklets serialization at module load time |
18 | 11 | // This allows GPUDevice, GPUCanvasContext, etc. to be passed to worklets |
19 | | -// The unbox() method automatically installs the prototype on the UI runtime if needed |
20 | | -registerCustomSerializable({ |
21 | | - name: "WebGPU", |
22 | | - determine: (value: object): value is object => { |
23 | | - "worklet"; |
24 | | - return __webgpuIsWebGPUObject(value); |
25 | | - }, |
26 | | - pack: (value: object) => { |
27 | | - "worklet"; |
28 | | - return __webgpuBox(value); |
29 | | - }, |
30 | | - unpack: (boxed: { unbox: () => object }) => { |
31 | | - "worklet"; |
32 | | - return boxed.unbox(); |
33 | | - }, |
34 | | -}); |
| 12 | +registerWebGPUSerializable(); |
35 | 13 |
|
36 | 14 | const webGPUDemo = ( |
37 | 15 | runAnimation: SharedValue<boolean>, |
|
0 commit comments