react-native-wgpu 0.3.2 → 0.4.0

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 (98) hide show
  1. package/README.md +7 -5
  2. package/lib/commonjs/Canvas.js +10 -3
  3. package/lib/commonjs/Canvas.js.map +1 -1
  4. package/lib/commonjs/WebGPUViewNativeComponent.web.js +99 -0
  5. package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -0
  6. package/lib/commonjs/WebPolyfillGPUModule.js +40 -0
  7. package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -0
  8. package/lib/commonjs/index.js +4 -208
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/main/index.js +227 -0
  11. package/lib/commonjs/main/index.js.map +1 -0
  12. package/lib/commonjs/main/index.web.js +51 -0
  13. package/lib/commonjs/main/index.web.js.map +1 -0
  14. package/lib/commonjs/types.js +2 -0
  15. package/lib/commonjs/types.js.map +1 -0
  16. package/lib/commonjs/utils.js +11 -0
  17. package/lib/commonjs/utils.js.map +1 -0
  18. package/lib/module/Canvas.js +11 -4
  19. package/lib/module/Canvas.js.map +1 -1
  20. package/lib/module/WebGPUViewNativeComponent.web.js +93 -0
  21. package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -0
  22. package/lib/module/WebPolyfillGPUModule.js +38 -0
  23. package/lib/module/WebPolyfillGPUModule.js.map +1 -0
  24. package/lib/module/index.js +3 -160
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/main/index.js +168 -0
  27. package/lib/module/main/index.js.map +1 -0
  28. package/lib/module/main/index.web.js +8 -0
  29. package/lib/module/main/index.web.js.map +1 -0
  30. package/lib/module/types.js +2 -0
  31. package/lib/module/types.js.map +1 -0
  32. package/lib/module/utils.js +5 -0
  33. package/lib/module/utils.js.map +1 -0
  34. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts +5 -0
  35. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -0
  36. package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts +2 -0
  37. package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts.map +1 -0
  38. package/lib/typescript/lib/commonjs/index.d.ts +0 -1
  39. package/lib/typescript/lib/commonjs/main/index.d.ts +3 -0
  40. package/lib/typescript/lib/commonjs/main/index.d.ts.map +1 -0
  41. package/lib/typescript/lib/commonjs/main/index.web.d.ts +2 -0
  42. package/lib/typescript/lib/commonjs/main/index.web.d.ts.map +1 -0
  43. package/lib/typescript/lib/commonjs/types.d.ts +1 -0
  44. package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
  45. package/lib/typescript/lib/commonjs/utils.d.ts +3 -0
  46. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
  47. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  48. package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts +2 -0
  49. package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -0
  50. package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts +2 -0
  51. package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts.map +1 -0
  52. package/lib/typescript/lib/module/index.d.ts +1 -5
  53. package/lib/typescript/lib/module/main/index.d.ts +6 -0
  54. package/lib/typescript/lib/module/main/index.d.ts.map +1 -0
  55. package/lib/typescript/lib/module/main/index.web.d.ts +5 -0
  56. package/lib/typescript/lib/module/main/index.web.d.ts.map +1 -0
  57. package/lib/typescript/lib/module/types.d.ts +1 -0
  58. package/lib/typescript/lib/module/types.d.ts.map +1 -0
  59. package/lib/typescript/lib/module/utils.d.ts +2 -0
  60. package/lib/typescript/lib/module/utils.d.ts.map +1 -0
  61. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  62. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +1 -1
  63. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  64. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +118 -0
  65. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -0
  66. package/lib/typescript/src/WebPolyfillGPUModule.d.ts +2 -0
  67. package/lib/typescript/src/WebPolyfillGPUModule.d.ts.map +1 -0
  68. package/lib/typescript/src/index.d.ts +16 -5
  69. package/lib/typescript/src/index.d.ts.map +1 -1
  70. package/lib/typescript/src/main/index.d.ts +6 -0
  71. package/lib/typescript/src/main/index.d.ts.map +1 -0
  72. package/lib/typescript/src/main/index.web.d.ts +6 -0
  73. package/lib/typescript/src/main/index.web.d.ts.map +1 -0
  74. package/lib/typescript/src/types.d.ts +19 -0
  75. package/lib/typescript/src/types.d.ts.map +1 -0
  76. package/lib/typescript/src/utils.d.ts +2 -0
  77. package/lib/typescript/src/utils.d.ts.map +1 -0
  78. package/package.json +2 -1
  79. package/src/Canvas.tsx +12 -4
  80. package/src/WebGPUViewNativeComponent.ts +1 -1
  81. package/src/WebGPUViewNativeComponent.web.ts +108 -0
  82. package/src/WebPolyfillGPUModule.ts +53 -0
  83. package/src/index.tsx +25 -196
  84. package/src/main/index.tsx +204 -0
  85. package/src/main/index.web.tsx +8 -0
  86. package/src/types.ts +20 -0
  87. package/src/utils.ts +4 -0
  88. package/lib/commonjs/WebGPUView.js +0 -2
  89. package/lib/commonjs/WebGPUView.js.map +0 -1
  90. package/lib/module/WebGPUView.js +0 -2
  91. package/lib/module/WebGPUView.js.map +0 -1
  92. package/lib/typescript/lib/commonjs/WebGPUView.d.ts +0 -1
  93. package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +0 -1
  94. package/lib/typescript/lib/module/WebGPUView.d.ts +0 -1
  95. package/lib/typescript/lib/module/WebGPUView.d.ts.map +0 -1
  96. package/lib/typescript/src/WebGPUView.d.ts +0 -1
  97. package/lib/typescript/src/WebGPUView.d.ts.map +0 -1
  98. package/src/WebGPUView.tsx +0 -0
@@ -0,0 +1,204 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import WebGPUModule from "../NativeWebGPUModule";
3
+
4
+ export * from "../Canvas";
5
+ export * from "../Offscreen";
6
+ export * from "../WebGPUViewNativeComponent";
7
+ export * from "../hooks";
8
+
9
+ export { default as WebGPUModule } from "../NativeWebGPUModule";
10
+
11
+ const GPU: any = {};
12
+ GPU[Symbol.hasInstance] = function (instance: object) {
13
+ return "__brand" in instance && instance.__brand === "GPU";
14
+ };
15
+
16
+ const GPUAdapter: any = {};
17
+ GPUAdapter[Symbol.hasInstance] = function (instance: object) {
18
+ return "__brand" in instance && instance.__brand === "GPUAdapter";
19
+ };
20
+
21
+ const GPUAdapterInfo: any = {};
22
+ GPUAdapterInfo[Symbol.hasInstance] = function (instance: object) {
23
+ return "__brand" in instance && instance.__brand === "GPUAdapterInfo";
24
+ };
25
+
26
+ const GPUBindGroup: any = {};
27
+ GPUBindGroup[Symbol.hasInstance] = function (instance: object) {
28
+ return "__brand" in instance && instance.__brand === "GPUBindGroup";
29
+ };
30
+
31
+ const GPUBindGroupLayout: any = {};
32
+ GPUBindGroupLayout[Symbol.hasInstance] = function (instance: object) {
33
+ return "__brand" in instance && instance.__brand === "GPUBindGroupLayout";
34
+ };
35
+
36
+ const GPUBuffer: any = {};
37
+ GPUBuffer[Symbol.hasInstance] = function (instance: object) {
38
+ return "__brand" in instance && instance.__brand === "GPUBuffer";
39
+ };
40
+
41
+ const GPUCanvasContext: any = {};
42
+ GPUCanvasContext[Symbol.hasInstance] = function (instance: object) {
43
+ return "__brand" in instance && instance.__brand === "GPUCanvasContext";
44
+ };
45
+
46
+ const GPUCommandBuffer: any = {};
47
+ GPUCommandBuffer[Symbol.hasInstance] = function (instance: object) {
48
+ return "__brand" in instance && instance.__brand === "GPUCommandBuffer";
49
+ };
50
+
51
+ const GPUCommandEncoder: any = {};
52
+ GPUCommandEncoder[Symbol.hasInstance] = function (instance: object) {
53
+ return "__brand" in instance && instance.__brand === "GPUCommandEncoder";
54
+ };
55
+
56
+ const GPUCompilationInfo: any = {};
57
+ GPUCompilationInfo[Symbol.hasInstance] = function (instance: object) {
58
+ return "__brand" in instance && instance.__brand === "GPUCompilationInfo";
59
+ };
60
+
61
+ const GPUCompilationMessage: any = {};
62
+ GPUCompilationMessage[Symbol.hasInstance] = function (instance: object) {
63
+ return "__brand" in instance && instance.__brand === "GPUCompilationMessage";
64
+ };
65
+
66
+ const GPUComputePassEncoder: any = {};
67
+ GPUComputePassEncoder[Symbol.hasInstance] = function (instance: object) {
68
+ return "__brand" in instance && instance.__brand === "GPUComputePassEncoder";
69
+ };
70
+
71
+ const GPUComputePipeline: any = {};
72
+ GPUComputePipeline[Symbol.hasInstance] = function (instance: object) {
73
+ return "__brand" in instance && instance.__brand === "GPUComputePipeline";
74
+ };
75
+
76
+ const GPUDevice: any = {};
77
+ GPUDevice[Symbol.hasInstance] = function (instance: object) {
78
+ return "__brand" in instance && instance.__brand === "GPUDevice";
79
+ };
80
+
81
+ const GPUDeviceLostInfo: any = {};
82
+ GPUDeviceLostInfo[Symbol.hasInstance] = function (instance: object) {
83
+ return "__brand" in instance && instance.__brand === "GPUDeviceLostInfo";
84
+ };
85
+
86
+ const GPUError: any = {};
87
+ GPUError[Symbol.hasInstance] = function (instance: object) {
88
+ return "__brand" in instance && instance.__brand === "GPUError";
89
+ };
90
+
91
+ const GPUExternalTexture: any = {};
92
+ GPUExternalTexture[Symbol.hasInstance] = function (instance: object) {
93
+ return "__brand" in instance && instance.__brand === "GPUExternalTexture";
94
+ };
95
+
96
+ const GPUPipelineLayout: any = {};
97
+ GPUPipelineLayout[Symbol.hasInstance] = function (instance: object) {
98
+ return "__brand" in instance && instance.__brand === "GPUPipelineLayout";
99
+ };
100
+
101
+ const GPUQuerySet: any = {};
102
+ GPUQuerySet[Symbol.hasInstance] = function (instance: object) {
103
+ return "__brand" in instance && instance.__brand === "GPUQuerySet";
104
+ };
105
+
106
+ const GPUQueue: any = {};
107
+ GPUQueue[Symbol.hasInstance] = function (instance: object) {
108
+ return "__brand" in instance && instance.__brand === "GPUQueue";
109
+ };
110
+
111
+ const GPURenderBundle: any = {};
112
+ GPURenderBundle[Symbol.hasInstance] = function (instance: object) {
113
+ return "__brand" in instance && instance.__brand === "GPURenderBundle";
114
+ };
115
+
116
+ const GPURenderBundleEncoder: any = {};
117
+ GPURenderBundleEncoder[Symbol.hasInstance] = function (instance: object) {
118
+ return "__brand" in instance && instance.__brand === "GPURenderBundleEncoder";
119
+ };
120
+
121
+ const GPURenderPassEncoder: any = {};
122
+ GPURenderPassEncoder[Symbol.hasInstance] = function (instance: object) {
123
+ return "__brand" in instance && instance.__brand === "GPURenderPassEncoder";
124
+ };
125
+
126
+ const GPURenderPipeline: any = {};
127
+ GPURenderPipeline[Symbol.hasInstance] = function (instance: object) {
128
+ return "__brand" in instance && instance.__brand === "GPURenderPipeline";
129
+ };
130
+
131
+ const GPUSampler: any = {};
132
+ GPUSampler[Symbol.hasInstance] = function (instance: object) {
133
+ return "__brand" in instance && instance.__brand === "GPUSampler";
134
+ };
135
+
136
+ const GPUShaderModule: any = {};
137
+ GPUShaderModule[Symbol.hasInstance] = function (instance: object) {
138
+ return "__brand" in instance && instance.__brand === "GPUShaderModule";
139
+ };
140
+
141
+ const GPUTexture: any = {};
142
+ GPUTexture[Symbol.hasInstance] = function (instance: object) {
143
+ return "__brand" in instance && instance.__brand === "GPUTexture";
144
+ };
145
+
146
+ const GPUTextureView: any = {};
147
+ GPUTextureView[Symbol.hasInstance] = function (instance: object) {
148
+ return "__brand" in instance && instance.__brand === "GPUTextureView";
149
+ };
150
+
151
+ global.GPU = GPU;
152
+ global.GPUAdapter = GPUAdapter;
153
+ global.GPUAdapterInfo = GPUAdapterInfo;
154
+ global.GPUBindGroup = GPUBindGroup;
155
+ global.GPUBindGroupLayout = GPUBindGroupLayout;
156
+ global.GPUBuffer = GPUBuffer;
157
+ global.GPUCanvasContext = GPUCanvasContext;
158
+ global.GPUCommandBuffer = GPUCommandBuffer;
159
+ global.GPUCommandEncoder = GPUCommandEncoder;
160
+ global.GPUCompilationInfo = GPUCompilationInfo;
161
+ global.GPUCompilationMessage = GPUCompilationMessage;
162
+ global.GPUComputePassEncoder = GPUComputePassEncoder;
163
+ global.GPUComputePipeline = GPUComputePipeline;
164
+ global.GPUDevice = GPUDevice;
165
+ global.GPUDeviceLostInfo = GPUDeviceLostInfo;
166
+ global.GPUError = GPUError;
167
+ global.GPUExternalTexture = GPUExternalTexture;
168
+ global.GPUPipelineLayout = GPUPipelineLayout;
169
+ global.GPUQuerySet = GPUQuerySet;
170
+ global.GPUQueue = GPUQueue;
171
+ global.GPURenderBundle = GPURenderBundle;
172
+ global.GPURenderBundleEncoder = GPURenderBundleEncoder;
173
+ global.GPURenderPassEncoder = GPURenderPassEncoder;
174
+ global.GPURenderPipeline = GPURenderPipeline;
175
+ global.GPUSampler = GPUSampler;
176
+ global.GPUShaderModule = GPUShaderModule;
177
+ global.GPUTexture = GPUTexture;
178
+ global.GPUTextureView = GPUTextureView;
179
+
180
+ WebGPUModule.install();
181
+
182
+ if (!navigator) {
183
+ // @ts-expect-error Navigation object is more complex than this, setting it to an empty object to add gpu property
184
+ navigator = {
185
+ gpu: RNWebGPU.gpu,
186
+ userAgent: "react-native",
187
+ };
188
+ } else {
189
+ navigator.gpu = RNWebGPU.gpu;
190
+ if (typeof navigator.userAgent !== "string") {
191
+ try {
192
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
193
+ // @ts-ignore - Hermes navigator may not include a userAgent, align with the polyfill if needed
194
+ navigator.userAgent = "react-native";
195
+ } catch {
196
+ // navigator.userAgent can be read-only; ignore if assignment fails
197
+ }
198
+ }
199
+ }
200
+
201
+ global.createImageBitmap =
202
+ global.createImageBitmap ??
203
+ ((...params: Parameters<typeof createImageBitmap>) =>
204
+ new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
@@ -0,0 +1,8 @@
1
+ import "../WebPolyfillGPUModule";
2
+
3
+ export * from "../Canvas";
4
+ export * from "../Offscreen";
5
+ export * from "../WebGPUViewNativeComponent";
6
+ export * from "../hooks";
7
+
8
+ // We don't need to set all global properties on web, webgpu is already available globally
package/src/types.ts ADDED
@@ -0,0 +1,20 @@
1
+ type SurfacePointer = bigint;
2
+
3
+ export interface NativeCanvas {
4
+ surface: SurfacePointer;
5
+ width: number;
6
+ height: number;
7
+ clientWidth: number;
8
+ clientHeight: number;
9
+ }
10
+
11
+ export type RNCanvasContext = GPUCanvasContext & {
12
+ present: () => void;
13
+ };
14
+
15
+ export interface CanvasRef {
16
+ getContextId: () => number;
17
+ getContext(contextName: "webgpu"): RNCanvasContext | null;
18
+ getNativeSurface: () => NativeCanvas;
19
+ whenReady: (callback: () => void) => void;
20
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Only used on the web
2
+ export function contextIdToId(contextId: number) {
3
+ return "rnwgpu-canvas-" + contextId;
4
+ }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=WebGPUView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["WebGPUView.tsx"],"mappings":"","ignoreList":[]}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=WebGPUView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["WebGPUView.tsx"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=WebGPUView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGPUView.d.ts","sourceRoot":"","sources":["../../../commonjs/WebGPUView.js"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=WebGPUView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGPUView.d.ts","sourceRoot":"","sources":["../../../module/WebGPUView.js"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=WebGPUView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGPUView.d.ts","sourceRoot":"","sources":["../../../src/WebGPUView.tsx"],"names":[],"mappings":""}
File without changes