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.
- package/README.md +7 -5
- package/lib/commonjs/Canvas.js +10 -3
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.web.js +99 -0
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/WebPolyfillGPUModule.js +40 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -0
- package/lib/commonjs/index.js +4 -208
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/main/index.js +227 -0
- package/lib/commonjs/main/index.js.map +1 -0
- package/lib/commonjs/main/index.web.js +51 -0
- package/lib/commonjs/main/index.web.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +11 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/Canvas.js +11 -4
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +93 -0
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/module/WebPolyfillGPUModule.js +38 -0
- package/lib/module/WebPolyfillGPUModule.js.map +1 -0
- package/lib/module/index.js +3 -160
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.js +168 -0
- package/lib/module/main/index.js.map +1 -0
- package/lib/module/main/index.web.js +8 -0
- package/lib/module/main/index.web.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +5 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts +5 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/main/index.d.ts +3 -0
- package/lib/typescript/lib/commonjs/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts +2 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/utils.d.ts +3 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts +2 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +1 -5
- package/lib/typescript/lib/module/main/index.d.ts +6 -0
- package/lib/typescript/lib/module/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +5 -0
- package/lib/typescript/lib/module/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/types.d.ts +1 -0
- package/lib/typescript/lib/module/types.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils.d.ts +2 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +118 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +16 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.d.ts +6 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -0
- package/lib/typescript/src/main/index.web.d.ts +6 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +19 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/Canvas.tsx +12 -4
- package/src/WebGPUViewNativeComponent.ts +1 -1
- package/src/WebGPUViewNativeComponent.web.ts +108 -0
- package/src/WebPolyfillGPUModule.ts +53 -0
- package/src/index.tsx +25 -196
- package/src/main/index.tsx +204 -0
- package/src/main/index.web.tsx +8 -0
- package/src/types.ts +20 -0
- package/src/utils.ts +4 -0
- package/lib/commonjs/WebGPUView.js +0 -2
- package/lib/commonjs/WebGPUView.js.map +0 -1
- package/lib/module/WebGPUView.js +0 -2
- package/lib/module/WebGPUView.js.map +0 -1
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts +0 -1
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +0 -1
- package/lib/typescript/lib/module/WebGPUView.d.ts +0 -1
- package/lib/typescript/lib/module/WebGPUView.d.ts.map +0 -1
- package/lib/typescript/src/WebGPUView.d.ts +0 -1
- package/lib/typescript/src/WebGPUView.d.ts.map +0 -1
- 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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["WebGPUView.tsx"],"mappings":"","ignoreList":[]}
|
package/lib/module/WebGPUView.js
DELETED
|
@@ -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":""}
|
package/src/WebGPUView.tsx
DELETED
|
File without changes
|