react-native-webgpu 0.5.14 → 0.5.15

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 (79) hide show
  1. package/README.md +19 -6
  2. package/android/CMakeLists.txt +2 -2
  3. package/cpp/jsi/NativeObject.h +39 -0
  4. package/cpp/rnwgpu/RNWebGPUManager.cpp +8 -0
  5. package/cpp/rnwgpu/SurfaceRegistry.h +33 -1
  6. package/cpp/rnwgpu/api/GPU.cpp +14 -11
  7. package/cpp/rnwgpu/api/GPU.h +6 -4
  8. package/cpp/rnwgpu/api/GPUAdapter.cpp +5 -8
  9. package/cpp/rnwgpu/api/GPUAdapter.h +3 -3
  10. package/cpp/rnwgpu/api/GPUBuffer.cpp +23 -24
  11. package/cpp/rnwgpu/api/GPUBuffer.h +3 -3
  12. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +13 -16
  13. package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -0
  14. package/cpp/rnwgpu/api/GPUDevice.cpp +103 -19
  15. package/cpp/rnwgpu/api/GPUDevice.h +17 -3
  16. package/cpp/rnwgpu/api/GPUQueue.h +3 -3
  17. package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
  18. package/cpp/rnwgpu/api/GPUSharedFence.cpp +77 -0
  19. package/cpp/rnwgpu/api/GPUSharedFence.h +53 -0
  20. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +60 -11
  21. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +13 -9
  22. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +58 -0
  23. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +51 -0
  24. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +55 -23
  25. package/cpp/rnwgpu/async/AsyncTaskHandle.h +8 -5
  26. package/cpp/rnwgpu/async/RuntimeContext.cpp +193 -0
  27. package/cpp/rnwgpu/async/RuntimeContext.h +122 -0
  28. package/lib/commonjs/Canvas.js.map +1 -1
  29. package/lib/commonjs/Offscreen.js +1 -1
  30. package/lib/commonjs/WebPolyfillGPUModule.js +2 -0
  31. package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
  32. package/lib/commonjs/constants.js +40 -0
  33. package/lib/commonjs/constants.js.map +1 -0
  34. package/lib/commonjs/index.js +22 -0
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/install.js +63 -0
  37. package/lib/commonjs/install.js.map +1 -0
  38. package/lib/module/Canvas.js.map +1 -1
  39. package/lib/module/Offscreen.js +1 -1
  40. package/lib/module/WebPolyfillGPUModule.js +2 -0
  41. package/lib/module/WebPolyfillGPUModule.js.map +1 -1
  42. package/lib/module/constants.js +34 -0
  43. package/lib/module/constants.js.map +1 -0
  44. package/lib/module/index.js +2 -0
  45. package/lib/module/index.js.map +1 -1
  46. package/lib/module/install.js +57 -0
  47. package/lib/module/install.js.map +1 -0
  48. package/lib/typescript/lib/commonjs/constants.d.ts +3 -0
  49. package/lib/typescript/lib/commonjs/constants.d.ts.map +1 -0
  50. package/lib/typescript/lib/commonjs/install.d.ts +35 -0
  51. package/lib/typescript/lib/commonjs/install.d.ts.map +1 -0
  52. package/lib/typescript/lib/module/constants.d.ts +6 -0
  53. package/lib/typescript/lib/module/constants.d.ts.map +1 -0
  54. package/lib/typescript/lib/module/index.d.ts +2 -0
  55. package/lib/typescript/lib/module/install.d.ts +2 -0
  56. package/lib/typescript/lib/module/install.d.ts.map +1 -0
  57. package/lib/typescript/src/Canvas.d.ts +9 -0
  58. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  59. package/lib/typescript/src/constants.d.ts +6 -0
  60. package/lib/typescript/src/constants.d.ts.map +1 -0
  61. package/lib/typescript/src/index.d.ts +5 -2
  62. package/lib/typescript/src/index.d.ts.map +1 -1
  63. package/lib/typescript/src/install.d.ts +34 -0
  64. package/lib/typescript/src/install.d.ts.map +1 -0
  65. package/lib/typescript/src/types.d.ts +34 -2
  66. package/lib/typescript/src/types.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/src/Canvas.tsx +9 -0
  69. package/src/Offscreen.ts +1 -1
  70. package/src/WebPolyfillGPUModule.ts +3 -3
  71. package/src/constants.ts +37 -0
  72. package/src/index.tsx +13 -2
  73. package/src/install.ts +61 -0
  74. package/src/types.ts +69 -3
  75. package/cpp/rnwgpu/async/AsyncDispatcher.h +0 -28
  76. package/cpp/rnwgpu/async/AsyncRunner.cpp +0 -215
  77. package/cpp/rnwgpu/async/AsyncRunner.h +0 -53
  78. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +0 -23
  79. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +0 -22
@@ -1 +1 @@
1
- {"version":3,"names":["_main","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;AAYA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_main","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_constants","_install"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;AAcA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,UAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,UAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,UAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,QAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,QAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,QAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,QAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.installWebGPU = void 0;
7
+ var _constants = require("./constants");
8
+ // Globals that this function installs on the calling runtime. These are the
9
+ // native-derived flag constants re-exported from `./constants` (a single source
10
+ // of truth, matching the native `wgpu::*Usage` enums), so they are safe to set
11
+ // on any runtime.
12
+ const constants = {
13
+ GPUBufferUsage: _constants.GPUBufferUsage,
14
+ GPUTextureUsage: _constants.GPUTextureUsage,
15
+ GPUShaderStage: _constants.GPUShaderStage,
16
+ GPUColorWrite: _constants.GPUColorWrite,
17
+ GPUMapMode: _constants.GPUMapMode
18
+ };
19
+
20
+ /**
21
+ * Install WebGPU on the runtime that calls it.
22
+ *
23
+ * The native module installs the WebGPU flag constants (`GPUBufferUsage`,
24
+ * `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`, `GPUMapMode`) as globals
25
+ * on the main JS runtime, but worklet runtimes (Reanimated UI, dedicated worklet
26
+ * runtimes, Vision Camera frame processors) start without them, so referencing
27
+ * the bare global inside a worklet yields `undefined`.
28
+ *
29
+ * Call `installWebGPU()` once at the top of a worklet to make those globals
30
+ * available there, instead of importing each constant by hand:
31
+ *
32
+ * ```tsx
33
+ * import { installWebGPU } from "react-native-webgpu";
34
+ *
35
+ * const work = (device: GPUDevice) => {
36
+ * "worklet";
37
+ * installWebGPU();
38
+ * device.createBuffer({
39
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
40
+ * });
41
+ * };
42
+ * ```
43
+ *
44
+ * The constants are captured into the worklet by closure (the same way a shader
45
+ * string is), so they work on every runtime. Calling it on a runtime that
46
+ * already has the globals (e.g. the main JS runtime) is a safe no-op.
47
+ *
48
+ * This is the explicit entry point for runtime setup; for now it only installs
49
+ * the flag constants, but it is the place where other per-runtime WebGPU setup
50
+ * (e.g. `navigator.gpu`) can be wired in later.
51
+ */
52
+ const installWebGPU = () => {
53
+ "worklet";
54
+
55
+ const g = globalThis;
56
+ for (const [key, value] of Object.entries(constants)) {
57
+ if (g[key] === undefined) {
58
+ g[key] = value;
59
+ }
60
+ }
61
+ };
62
+ exports.installWebGPU = installWebGPU;
63
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","installWebGPU","g","globalThis","key","value","Object","entries","undefined","exports"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAQA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,SAAS,CAAC,EAAE;IACpD,IAAIO,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;AACF,CAAC;AAACI,OAAA,CAAAR,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["React","useImperativeHandle","useRef","useState","View","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","Canvas","transparent","ref","props","viewRef","contextId","_","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","_extends","collapsable","style","flex"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEpE,SAASC,IAAI,QAAQ,cAAc;AAEnC,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;A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J,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useImperativeHandle","useRef","useState","View","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","Canvas","transparent","ref","props","viewRef","contextId","_","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","_extends","collapsable","style","flex"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEpE,SAASC,IAAI,QAAQ,cAAc;AAEnC,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AAoCA,OAAO,MAAME,MAAM,GAAGA,CAAC;EAAEC,WAAW;EAAEC,GAAG;EAAE,GAAGC;AAAmB,CAAC,KAAK;EACrE,MAAMC,OAAO,GAAGV,MAAM,CAAC,IAAI,CAAC;EAC5B,MAAM,CAACW,SAAS,EAAEC,CAAC,CAAC,GAAGX,QAAQ,CAAC,MAAMI,iBAAiB,CAAC,CAAC,CAAC;EAC1DN,mBAAmB,CAACS,GAAG,EAAE,OAAO;IAC9BK,YAAY,EAAEA,CAAA,KAAMF,SAAS;IAC7BG,gBAAgB,EAAEA,CAAA,KAAM;MACtB,OAAOC,QAAQ,CAACD,gBAAgB,CAACH,SAAS,CAAC;IAC7C,CAAC;IACDK,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIC,KAAK,CAAC,iCAAiCD,WAAW,EAAE,CAAC;MACjE;MACA,IAAI,CAACP,OAAO,CAACS,OAAO,EAAE;QACpB,MAAM,IAAID,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA;MACA;MACA,MAAME,IAAI,GAAGV,OAAO,CAACS,OAAc;MACnC,MAAME,IAAI,GACR,uBAAuB,IAAID,IAAI,GAC3BA,IAAI,CAACE,qBAAqB,CAAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOR,QAAQ,CAACS,uBAAuB,CACrCb,SAAS,EACTU,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EAEH,oBACE5B,KAAA,CAAA6B,aAAA,CAACzB,IAAI,EAAA0B,QAAA;IAACC,WAAW,EAAE,KAAM;IAACrB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/CX,KAAA,CAAA6B,aAAA,CAACxB,gBAAgB;IACf2B,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBpB,SAAS,EAAEA,SAAU;IACrBJ,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
@@ -55,7 +55,7 @@ class GPUOffscreenCanvasContext {
55
55
  throw new Error("Method not implemented.");
56
56
  }
57
57
  present() {
58
- // Do nothing
58
+ // Offscreen contexts have nothing to present; readback is via getImageData.
59
59
  }
60
60
  getDevice() {
61
61
  if (!this.device) {
@@ -24,6 +24,8 @@ function makeWebGPUCanvasContext(contextId, width, height) {
24
24
  canvas.setAttribute("height", pixelHeight);
25
25
  }
26
26
  const context = canvas.getContext("webgpu");
27
+ // On web there is no manual present; expose a no-op so RNCanvasContext's
28
+ // present() (called after queue.submit() on native) is callable here too.
27
29
  return Object.assign(context, {
28
30
  present: () => {}
29
31
  });
@@ -1 +1 @@
1
- {"version":3,"names":["contextIdToId","fabric","getNativeSurface","contextId","canvas","document","getElementById","height","width","getBoundingClientRect","surface","BigInt","clientHeight","clientWidth","makeWebGPUCanvasContext","dpr","window","devicePixelRatio","pixelWidth","toString","pixelHeight","getAttribute","setAttribute","context","getContext","Object","assign","present","RNWebGPU","MakeWebGPUCanvasContext"],"sourceRoot":"../../src","sources":["WebPolyfillGPUModule.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAS;AAEvC,MAAMC,MAAM,GAAG,IAAI;AAEnB,SAASC,gBAAgBA,CAACC,SAAiB,EAAE;EAC3C,MAAMC,MAAM,GAAGC,QAAQ,CAACC,cAAc,CACpCN,aAAa,CAACG,SAAS,CACzB,CAAsB;EAEtB,MAAM;IAAEI,MAAM;IAAEC;EAAM,CAAC,GAAGJ,MAAM,CAACK,qBAAqB,CAAC,CAAE;EAEzD,OAAO;IACLC,OAAO,EAAEC,MAAM,CAACR,SAAS,CAAC;IAC1BI,MAAM;IACNC,KAAK;IACLI,YAAY,EAAEL,MAAM;IACpBM,WAAW,EAAEL;EACf,CAAC;AACH;AAEA,SAASM,uBAAuBA,CAC9BX,SAAiB,EACjBK,KAAa,EACbD,MAAc,EACd;EACA,MAAMH,MAAM,GAAGC,QAAQ,CAACC,cAAc,CACpCN,aAAa,CAACG,SAAS,CACzB,CAAsB;EAEtB,MAAMY,GAAG,GAAGC,MAAM,CAACC,gBAAgB,IAAI,CAAC;EACxC,MAAMC,UAAU,GAAG,CAACV,KAAK,GAAGO,GAAG,EAAEI,QAAQ,CAAC,CAAC;EAC3C,MAAMC,WAAW,GAAG,CAACb,MAAM,GAAGQ,GAAG,EAAEI,QAAQ,CAAC,CAAC;EAE7C,IACEf,MAAM,CAACiB,YAAY,CAAC,OAAO,CAAC,KAAKH,UAAU,IAC3Cd,MAAM,CAACiB,YAAY,CAAC,QAAQ,CAAC,KAAKD,WAAW,EAC7C;IACAhB,MAAM,CAACkB,YAAY,CAAC,OAAO,EAAEJ,UAAU,CAAC;IACxCd,MAAM,CAACkB,YAAY,CAAC,QAAQ,EAAEF,WAAW,CAAC;EAC5C;EAEA,MAAMG,OAAO,GAAGnB,MAAM,CAACoB,UAAU,CAAC,QAAQ,CAAE;EAC5C,OAAOC,MAAM,CAACC,MAAM,CAACH,OAAO,EAAE;IAC5BI,OAAO,EAAEA,CAAA,KAAM,CAAC;EAClB,CAAC,CAAC;AACJ;;AAEA;AACAX,MAAM,CAACY,QAAQ,GAAG;EAChB1B,gBAAgB;EAChB2B,uBAAuB,EAAEf,uBAAuB;EAChDb;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["contextIdToId","fabric","getNativeSurface","contextId","canvas","document","getElementById","height","width","getBoundingClientRect","surface","BigInt","clientHeight","clientWidth","makeWebGPUCanvasContext","dpr","window","devicePixelRatio","pixelWidth","toString","pixelHeight","getAttribute","setAttribute","context","getContext","Object","assign","present","RNWebGPU","MakeWebGPUCanvasContext"],"sourceRoot":"../../src","sources":["WebPolyfillGPUModule.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAS;AAEvC,MAAMC,MAAM,GAAG,IAAI;AAEnB,SAASC,gBAAgBA,CAACC,SAAiB,EAAE;EAC3C,MAAMC,MAAM,GAAGC,QAAQ,CAACC,cAAc,CACpCN,aAAa,CAACG,SAAS,CACzB,CAAsB;EAEtB,MAAM;IAAEI,MAAM;IAAEC;EAAM,CAAC,GAAGJ,MAAM,CAACK,qBAAqB,CAAC,CAAE;EAEzD,OAAO;IACLC,OAAO,EAAEC,MAAM,CAACR,SAAS,CAAC;IAC1BI,MAAM;IACNC,KAAK;IACLI,YAAY,EAAEL,MAAM;IACpBM,WAAW,EAAEL;EACf,CAAC;AACH;AAEA,SAASM,uBAAuBA,CAC9BX,SAAiB,EACjBK,KAAa,EACbD,MAAc,EACd;EACA,MAAMH,MAAM,GAAGC,QAAQ,CAACC,cAAc,CACpCN,aAAa,CAACG,SAAS,CACzB,CAAsB;EAEtB,MAAMY,GAAG,GAAGC,MAAM,CAACC,gBAAgB,IAAI,CAAC;EACxC,MAAMC,UAAU,GAAG,CAACV,KAAK,GAAGO,GAAG,EAAEI,QAAQ,CAAC,CAAC;EAC3C,MAAMC,WAAW,GAAG,CAACb,MAAM,GAAGQ,GAAG,EAAEI,QAAQ,CAAC,CAAC;EAE7C,IACEf,MAAM,CAACiB,YAAY,CAAC,OAAO,CAAC,KAAKH,UAAU,IAC3Cd,MAAM,CAACiB,YAAY,CAAC,QAAQ,CAAC,KAAKD,WAAW,EAC7C;IACAhB,MAAM,CAACkB,YAAY,CAAC,OAAO,EAAEJ,UAAU,CAAC;IACxCd,MAAM,CAACkB,YAAY,CAAC,QAAQ,EAAEF,WAAW,CAAC;EAC5C;EAEA,MAAMG,OAAO,GAAGnB,MAAM,CAACoB,UAAU,CAAC,QAAQ,CAAE;EAC5C;EACA;EACA,OAAOC,MAAM,CAACC,MAAM,CAACH,OAAO,EAAE;IAAEI,OAAO,EAAEA,CAAA,KAAM,CAAC;EAAE,CAAC,CAAC;AACtD;;AAEA;AACAX,MAAM,CAACY,QAAQ,GAAG;EAChB1B,gBAAgB;EAChB2B,uBAAuB,EAAEf,uBAAuB;EAChDb;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ /// <reference types="@webgpu/types" />
2
+
3
+ // WebGPU flag constants as importable JS values.
4
+ //
5
+ // The native module installs `GPUBufferUsage`, `GPUTextureUsage`,
6
+ // `GPUShaderStage`, `GPUColorWrite` and `GPUMapMode` as globals, but only on the
7
+ // main JS runtime. Worklet runtimes (Reanimated UI, dedicated worklet runtimes,
8
+ // Vision Camera frame processors) do not get those globals, so referencing the
9
+ // bare global inside a worklet yields `undefined`.
10
+ //
11
+ // Rather than hardcode the bit values here (which could drift from the native
12
+ // `wgpu::*Usage` enums), we re-export the globals the native module already
13
+ // installed (see `GPUBufferUsage.h` and friends, which derive their values from
14
+ // the Dawn enums with `static_assert`s). This keeps a single source of truth.
15
+ // Importing them into a worklet lets the Worklets serializer capture them by
16
+ // closure (the same way module-level shader strings are captured), making them
17
+ // available on every runtime without passing them in by hand:
18
+ //
19
+ // import { GPUBufferUsage } from "react-native-webgpu";
20
+ // const work = () => {
21
+ // "worklet";
22
+ // device.createBuffer({ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ });
23
+ // };
24
+ //
25
+ // These are read at module evaluation time. The package entry (`index.tsx`)
26
+ // re-exports `./main` before `./constants`, and `./main` installs the native
27
+ // module synchronously, so the globals always exist by the time this runs.
28
+
29
+ export const GPUBufferUsage = globalThis.GPUBufferUsage;
30
+ export const GPUTextureUsage = globalThis.GPUTextureUsage;
31
+ export const GPUShaderStage = globalThis.GPUShaderStage;
32
+ export const GPUColorWrite = globalThis.GPUColorWrite;
33
+ export const GPUMapMode = globalThis.GPUMapMode;
34
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GPUBufferUsage","globalThis","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode"],"sourceRoot":"../../src","sources":["constants.ts"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,cAAc,GAAGC,UAAU,CAACD,cAAc;AAEvD,OAAO,MAAME,eAAe,GAAGD,UAAU,CAACC,eAAe;AAEzD,OAAO,MAAMC,cAAc,GAAGF,UAAU,CAACE,cAAc;AAEvD,OAAO,MAAMC,aAAa,GAAGH,UAAU,CAACG,aAAa;AAErD,OAAO,MAAMC,UAAU,GAAGJ,UAAU,CAACI,UAAU","ignoreList":[]}
@@ -1,5 +1,7 @@
1
1
  /// <reference types="@webgpu/types" />
2
2
 
3
3
  export * from "./main";
4
+ export * from "./constants";
5
+ export * from "./install";
4
6
  export {};
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;;AAYA,cAAc,QAAQ;AAAC","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;;AAcA,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AAAC","ignoreList":[]}
@@ -0,0 +1,57 @@
1
+ import { GPUBufferUsage, GPUColorWrite, GPUMapMode, GPUShaderStage, GPUTextureUsage } from "./constants";
2
+
3
+ // Globals that this function installs on the calling runtime. These are the
4
+ // native-derived flag constants re-exported from `./constants` (a single source
5
+ // of truth, matching the native `wgpu::*Usage` enums), so they are safe to set
6
+ // on any runtime.
7
+ const constants = {
8
+ GPUBufferUsage,
9
+ GPUTextureUsage,
10
+ GPUShaderStage,
11
+ GPUColorWrite,
12
+ GPUMapMode
13
+ };
14
+
15
+ /**
16
+ * Install WebGPU on the runtime that calls it.
17
+ *
18
+ * The native module installs the WebGPU flag constants (`GPUBufferUsage`,
19
+ * `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`, `GPUMapMode`) as globals
20
+ * on the main JS runtime, but worklet runtimes (Reanimated UI, dedicated worklet
21
+ * runtimes, Vision Camera frame processors) start without them, so referencing
22
+ * the bare global inside a worklet yields `undefined`.
23
+ *
24
+ * Call `installWebGPU()` once at the top of a worklet to make those globals
25
+ * available there, instead of importing each constant by hand:
26
+ *
27
+ * ```tsx
28
+ * import { installWebGPU } from "react-native-webgpu";
29
+ *
30
+ * const work = (device: GPUDevice) => {
31
+ * "worklet";
32
+ * installWebGPU();
33
+ * device.createBuffer({
34
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
35
+ * });
36
+ * };
37
+ * ```
38
+ *
39
+ * The constants are captured into the worklet by closure (the same way a shader
40
+ * string is), so they work on every runtime. Calling it on a runtime that
41
+ * already has the globals (e.g. the main JS runtime) is a safe no-op.
42
+ *
43
+ * This is the explicit entry point for runtime setup; for now it only installs
44
+ * the flag constants, but it is the place where other per-runtime WebGPU setup
45
+ * (e.g. `navigator.gpu`) can be wired in later.
46
+ */
47
+ export const installWebGPU = () => {
48
+ "worklet";
49
+
50
+ const g = globalThis;
51
+ for (const [key, value] of Object.entries(constants)) {
52
+ if (g[key] === undefined) {
53
+ g[key] = value;
54
+ }
55
+ }
56
+ };
57
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GPUBufferUsage","GPUColorWrite","GPUMapMode","GPUShaderStage","GPUTextureUsage","constants","installWebGPU","g","globalThis","key","value","Object","entries","undefined"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":"AAAA,SACEA,cAAc,EACdC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,eAAe,QACV,aAAa;;AAEpB;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBL,cAAc;EACdI,eAAe;EACfD,cAAc;EACdF,aAAa;EACbC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACP,SAAS,CAAC,EAAE;IACpD,IAAIE,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export const __esModule: boolean;
2
+ export { GPUBufferUsage, GPUTextureUsage, GPUShaderStage, GPUColorWrite, GPUMapMode };
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../commonjs/constants.js"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ export const __esModule: boolean;
2
+ /**
3
+ * Install WebGPU on the runtime that calls it.
4
+ *
5
+ * The native module installs the WebGPU flag constants (`GPUBufferUsage`,
6
+ * `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`, `GPUMapMode`) as globals
7
+ * on the main JS runtime, but worklet runtimes (Reanimated UI, dedicated worklet
8
+ * runtimes, Vision Camera frame processors) start without them, so referencing
9
+ * the bare global inside a worklet yields `undefined`.
10
+ *
11
+ * Call `installWebGPU()` once at the top of a worklet to make those globals
12
+ * available there, instead of importing each constant by hand:
13
+ *
14
+ * ```tsx
15
+ * import { installWebGPU } from "react-native-webgpu";
16
+ *
17
+ * const work = (device: GPUDevice) => {
18
+ * "worklet";
19
+ * installWebGPU();
20
+ * device.createBuffer({
21
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
22
+ * });
23
+ * };
24
+ * ```
25
+ *
26
+ * The constants are captured into the worklet by closure (the same way a shader
27
+ * string is), so they work on every runtime. Calling it on a runtime that
28
+ * already has the globals (e.g. the main JS runtime) is a safe no-op.
29
+ *
30
+ * This is the explicit entry point for runtime setup; for now it only installs
31
+ * the flag constants, but it is the place where other per-runtime WebGPU setup
32
+ * (e.g. `navigator.gpu`) can be wired in later.
33
+ */
34
+ export function installWebGPU(): void;
35
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,sCASC"}
@@ -0,0 +1,6 @@
1
+ export const GPUBufferUsage: GPUBufferUsage;
2
+ export const GPUTextureUsage: GPUTextureUsage;
3
+ export const GPUShaderStage: GPUShaderStage;
4
+ export const GPUColorWrite: GPUColorWrite;
5
+ export const GPUMapMode: GPUMapMode;
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../module/constants.js"],"names":[],"mappings":"AA4BA,4CAAwD;AACxD,8CAA0D;AAC1D,4CAAwD;AACxD,0CAAsD;AACtD,oCAAgD"}
@@ -1,2 +1,4 @@
1
1
  export * from "./main";
2
+ export * from "./constants";
3
+ export * from "./install";
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export function installWebGPU(): void;
2
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA8CO,sCASN"}
@@ -9,6 +9,15 @@ export interface NativeCanvas {
9
9
  clientHeight: number;
10
10
  }
11
11
  export type RNCanvasContext = GPUCanvasContext & {
12
+ /**
13
+ * Present the current frame.
14
+ *
15
+ * Call this after `queue.submit()` on every runtime: the main JS runtime, the
16
+ * Reanimated UI runtime, and dedicated worklet runtimes (e.g.
17
+ * `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
18
+ * processor). It runs synchronously on the calling thread, so the frame is
19
+ * presented from whichever thread did the rendering.
20
+ */
12
21
  present: () => void;
13
22
  };
14
23
  export interface CanvasRef {
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,MAAM,GAAI,gCAAgC,WAAW,sBAuCjE,CAAC"}
1
+ {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,MAAM,GAAI,gCAAgC,WAAW,sBAuCjE,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const GPUBufferUsage: GPUBufferUsage;
2
+ export declare const GPUTextureUsage: GPUTextureUsage;
3
+ export declare const GPUShaderStage: GPUShaderStage;
4
+ export declare const GPUColorWrite: GPUColorWrite;
5
+ export declare const GPUMapMode: GPUMapMode;
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,cAAc,gBAA4B,CAAC;AAExD,eAAO,MAAM,eAAe,iBAA6B,CAAC;AAE1D,eAAO,MAAM,cAAc,gBAA4B,CAAC;AAExD,eAAO,MAAM,aAAa,eAA2B,CAAC;AAEtD,eAAO,MAAM,UAAU,YAAwB,CAAC"}
@@ -1,6 +1,8 @@
1
- import type { GPUDawnTogglesDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, NativeCanvas, RNCanvasContext, VideoPlayer, NativeVideoFrame, NativeVideoPixelFormat } from "./types";
1
+ import type { GPUSharedFence, GPUSharedFenceDescriptor, GPUDawnTogglesDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, NativeCanvas, RNCanvasContext, VideoPlayer, NativeVideoFrame, NativeVideoPixelFormat } from "./types";
2
2
  export * from "./main";
3
- export type { NativeVideoFrame, VideoPlayer, NativeVideoPixelFormat, CreateVideoPlayerOptions, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUDawnTogglesDescriptor, } from "./types";
3
+ export * from "./constants";
4
+ export * from "./install";
5
+ export type { NativeVideoFrame, VideoPlayer, GPUSharedFence, GPUSharedFenceDescriptor, GPUSharedFenceExportInfo, GPUSharedFenceState, GPUSharedFenceType, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUSharedTextureMemoryEndAccessState, NativeVideoPixelFormat, CreateVideoPlayerOptions, GPUDawnTogglesDescriptor, } from "./types";
4
6
  declare global {
5
7
  interface Navigator {
6
8
  gpu: GPU;
@@ -21,6 +23,7 @@ declare global {
21
23
  };
22
24
  interface GPUDevice {
23
25
  importSharedTextureMemory(descriptor: GPUSharedTextureMemoryDescriptor): GPUSharedTextureMemory;
26
+ importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
24
27
  }
25
28
  interface GPUDeviceDescriptor {
26
29
  dawnToggles?: GPUDawnTogglesDescriptor;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,GAAG,EAAE,GAAG,CAAC;KACV;IAED,IAAI,SAAS,EAAE,SAAS,CAAC;IAEzB,IAAI,QAAQ,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;QACtD,uBAAuB,EAAE,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,eAAe,CAAC;QACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAC;QACvE,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;QAC5C,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,CAAC;QACnD,oBAAoB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,gBAAgB,CAAC;QAI1E,gC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,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,GACnC,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Install WebGPU on the runtime that calls it.
3
+ *
4
+ * The native module installs the WebGPU flag constants (`GPUBufferUsage`,
5
+ * `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`, `GPUMapMode`) as globals
6
+ * on the main JS runtime, but worklet runtimes (Reanimated UI, dedicated worklet
7
+ * runtimes, Vision Camera frame processors) start without them, so referencing
8
+ * the bare global inside a worklet yields `undefined`.
9
+ *
10
+ * Call `installWebGPU()` once at the top of a worklet to make those globals
11
+ * available there, instead of importing each constant by hand:
12
+ *
13
+ * ```tsx
14
+ * import { installWebGPU } from "react-native-webgpu";
15
+ *
16
+ * const work = (device: GPUDevice) => {
17
+ * "worklet";
18
+ * installWebGPU();
19
+ * device.createBuffer({
20
+ * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
21
+ * });
22
+ * };
23
+ * ```
24
+ *
25
+ * The constants are captured into the worklet by closure (the same way a shader
26
+ * string is), so they work on every runtime. Calling it on a runtime that
27
+ * already has the globals (e.g. the main JS runtime) is a safe no-op.
28
+ *
29
+ * This is the explicit entry point for runtime setup; for now it only installs
30
+ * the flag constants, but it is the place where other per-runtime WebGPU setup
31
+ * (e.g. `navigator.gpu`) can be wired in later.
32
+ */
33
+ export declare const installWebGPU: () => void;
34
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,aAAa,YAQzB,CAAC"}
@@ -7,6 +7,15 @@ export interface NativeCanvas {
7
7
  clientHeight: number;
8
8
  }
9
9
  export type RNCanvasContext = GPUCanvasContext & {
10
+ /**
11
+ * Present the current frame.
12
+ *
13
+ * Call this after `queue.submit()` on every runtime: the main JS runtime, the
14
+ * Reanimated UI runtime, and dedicated worklet runtimes (e.g.
15
+ * `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
16
+ * processor). It runs synchronously on the calling thread, so the frame is
17
+ * presented from whichever thread did the rendering.
18
+ */
10
19
  present: () => void;
11
20
  };
12
21
  export interface CanvasRef {
@@ -35,6 +44,29 @@ export interface GPUSharedTextureMemoryDescriptor {
35
44
  handle: bigint;
36
45
  label?: string;
37
46
  }
47
+ export type GPUSharedFenceType = "mtl-shared-event" | "sync-fd" | "vk-semaphore-opaque-fd";
48
+ export interface GPUSharedFenceDescriptor {
49
+ type: GPUSharedFenceType;
50
+ handle: bigint;
51
+ label?: string;
52
+ }
53
+ export interface GPUSharedFenceExportInfo {
54
+ type: GPUSharedFenceType;
55
+ handle: bigint;
56
+ }
57
+ export interface GPUSharedFence {
58
+ readonly __brand: "GPUSharedFence";
59
+ label: string;
60
+ export(): GPUSharedFenceExportInfo;
61
+ }
62
+ export interface GPUSharedFenceState {
63
+ fence: GPUSharedFence;
64
+ signaledValue: bigint;
65
+ }
66
+ export interface GPUSharedTextureMemoryEndAccessState {
67
+ initialized: boolean;
68
+ fences: GPUSharedFenceState[];
69
+ }
38
70
  export interface GPUDawnTogglesDescriptor {
39
71
  enabledToggles?: string[];
40
72
  disabledToggles?: string[];
@@ -43,8 +75,8 @@ export interface GPUSharedTextureMemory {
43
75
  readonly __brand: "GPUSharedTextureMemory";
44
76
  label: string;
45
77
  createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;
46
- beginAccess(texture: GPUTexture, initialized: boolean): boolean;
47
- endAccess(texture: GPUTexture): boolean;
78
+ beginAccess(texture: GPUTexture, initialized: boolean, fences?: GPUSharedFenceState[]): void;
79
+ endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;
48
80
  }
49
81
  export {};
50
82
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","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AU,CAAC;IAM7D,WAAW,CACT,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,OAAO,EACpB,MAAM,CAAC,EAAE,mBAAmB,EAAE,GAC7B,IAAI,CAAC;IAGR,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,oCAAoC,CAAC;CACtE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webgpu",
3
- "version": "0.5.14",
3
+ "version": "0.5.15",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/Canvas.tsx CHANGED
@@ -20,6 +20,15 @@ export interface NativeCanvas {
20
20
  }
21
21
 
22
22
  export type RNCanvasContext = GPUCanvasContext & {
23
+ /**
24
+ * Present the current frame.
25
+ *
26
+ * Call this after `queue.submit()` on every runtime: the main JS runtime, the
27
+ * Reanimated UI runtime, and dedicated worklet runtimes (e.g.
28
+ * `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
29
+ * processor). It runs synchronously on the calling thread, so the frame is
30
+ * presented from whichever thread did the rendering.
31
+ */
23
32
  present: () => void;
24
33
  };
25
34
 
package/src/Offscreen.ts CHANGED
@@ -65,7 +65,7 @@ class GPUOffscreenCanvasContext implements GPUCanvasContext {
65
65
  }
66
66
 
67
67
  present() {
68
- // Do nothing
68
+ // Offscreen contexts have nothing to present; readback is via getImageData.
69
69
  }
70
70
 
71
71
  getDevice() {
@@ -40,9 +40,9 @@ function makeWebGPUCanvasContext(
40
40
  }
41
41
 
42
42
  const context = canvas.getContext("webgpu")!;
43
- return Object.assign(context, {
44
- present: () => {},
45
- });
43
+ // On web there is no manual present; expose a no-op so RNCanvasContext's
44
+ // present() (called after queue.submit() on native) is callable here too.
45
+ return Object.assign(context, { present: () => {} });
46
46
  }
47
47
 
48
48
  // @ts-expect-error - polyfill for RNWebGPU native module
@@ -0,0 +1,37 @@
1
+ /// <reference types="@webgpu/types" />
2
+
3
+ // WebGPU flag constants as importable JS values.
4
+ //
5
+ // The native module installs `GPUBufferUsage`, `GPUTextureUsage`,
6
+ // `GPUShaderStage`, `GPUColorWrite` and `GPUMapMode` as globals, but only on the
7
+ // main JS runtime. Worklet runtimes (Reanimated UI, dedicated worklet runtimes,
8
+ // Vision Camera frame processors) do not get those globals, so referencing the
9
+ // bare global inside a worklet yields `undefined`.
10
+ //
11
+ // Rather than hardcode the bit values here (which could drift from the native
12
+ // `wgpu::*Usage` enums), we re-export the globals the native module already
13
+ // installed (see `GPUBufferUsage.h` and friends, which derive their values from
14
+ // the Dawn enums with `static_assert`s). This keeps a single source of truth.
15
+ // Importing them into a worklet lets the Worklets serializer capture them by
16
+ // closure (the same way module-level shader strings are captured), making them
17
+ // available on every runtime without passing them in by hand:
18
+ //
19
+ // import { GPUBufferUsage } from "react-native-webgpu";
20
+ // const work = () => {
21
+ // "worklet";
22
+ // device.createBuffer({ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ });
23
+ // };
24
+ //
25
+ // These are read at module evaluation time. The package entry (`index.tsx`)
26
+ // re-exports `./main` before `./constants`, and `./main` installs the native
27
+ // module synchronously, so the globals always exist by the time this runs.
28
+
29
+ export const GPUBufferUsage = globalThis.GPUBufferUsage;
30
+
31
+ export const GPUTextureUsage = globalThis.GPUTextureUsage;
32
+
33
+ export const GPUShaderStage = globalThis.GPUShaderStage;
34
+
35
+ export const GPUColorWrite = globalThis.GPUColorWrite;
36
+
37
+ export const GPUMapMode = globalThis.GPUMapMode;
package/src/index.tsx CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference types="@webgpu/types" />
2
2
  import type {
3
+ GPUSharedFence,
4
+ GPUSharedFenceDescriptor,
3
5
  GPUDawnTogglesDescriptor,
4
6
  GPUSharedTextureMemory,
5
7
  GPUSharedTextureMemoryDescriptor,
@@ -11,13 +13,21 @@ import type {
11
13
  } from "./types";
12
14
 
13
15
  export * from "./main";
16
+ export * from "./constants";
17
+ export * from "./install";
14
18
  export type {
15
19
  NativeVideoFrame,
16
20
  VideoPlayer,
17
- NativeVideoPixelFormat,
18
- CreateVideoPlayerOptions,
21
+ GPUSharedFence,
22
+ GPUSharedFenceDescriptor,
23
+ GPUSharedFenceExportInfo,
24
+ GPUSharedFenceState,
25
+ GPUSharedFenceType,
19
26
  GPUSharedTextureMemory,
20
27
  GPUSharedTextureMemoryDescriptor,
28
+ GPUSharedTextureMemoryEndAccessState,
29
+ NativeVideoPixelFormat,
30
+ CreateVideoPlayerOptions,
21
31
  GPUDawnTogglesDescriptor,
22
32
  } from "./types";
23
33
 
@@ -56,6 +66,7 @@ declare global {
56
66
  importSharedTextureMemory(
57
67
  descriptor: GPUSharedTextureMemoryDescriptor,
58
68
  ): GPUSharedTextureMemory;
69
+ importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
59
70
  }
60
71
 
61
72
  // Non-standard, Dawn-only. Lets callers set Dawn device-stage toggles at