react-native-wgpu 0.3.1 → 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/apple/MetalView.mm +1 -1
- package/cpp/rnwgpu/api/GPU.h +0 -1
- package/cpp/rnwgpu/api/GPUAdapter.cpp +7 -7
- package/cpp/webgpu/webgpu.h +4827 -5
- package/cpp/webgpu/webgpu_cpp.h +10140 -5
- package/cpp/webgpu/webgpu_cpp_print.h +2687 -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/cpp/dawn/dawn_proc_table.h +0 -313
- package/cpp/dawn/native/DawnNative.h +0 -361
- package/cpp/dawn/native/NullBackend.h +0 -39
- package/cpp/dawn/native/OpenGLBackend.h +0 -82
- package/cpp/dawn/native/VulkanBackend.h +0 -183
- package/cpp/dawn/native/dawn_native_export.h +0 -49
- package/cpp/dawn/webgpu.h +0 -4855
- package/cpp/dawn/webgpu_cpp.h +0 -10168
- package/cpp/dawn/webgpu_cpp_print.h +0 -2715
- package/cpp/dawn/wire/client/webgpu.h +0 -354
- package/cpp/dawn/wire/client/webgpu_cpp.h +0 -10343
- package/cpp/dawn/wire/client/webgpu_cpp_print.h +0 -2715
- 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,53 @@
|
|
|
1
|
+
import { contextIdToId } from "./utils";
|
|
2
|
+
|
|
3
|
+
const fabric = true;
|
|
4
|
+
|
|
5
|
+
function getNativeSurface(contextId: number) {
|
|
6
|
+
const canvas = document.getElementById(
|
|
7
|
+
contextIdToId(contextId),
|
|
8
|
+
) as HTMLCanvasElement;
|
|
9
|
+
|
|
10
|
+
const { height, width } = canvas.getBoundingClientRect()!;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
surface: BigInt(contextId),
|
|
14
|
+
height,
|
|
15
|
+
width,
|
|
16
|
+
clientHeight: height,
|
|
17
|
+
clientWidth: width,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function makeWebGPUCanvasContext(
|
|
22
|
+
contextId: number,
|
|
23
|
+
width: number,
|
|
24
|
+
height: number,
|
|
25
|
+
) {
|
|
26
|
+
const canvas = document.getElementById(
|
|
27
|
+
contextIdToId(contextId),
|
|
28
|
+
) as HTMLCanvasElement;
|
|
29
|
+
|
|
30
|
+
const dpr = window.devicePixelRatio || 1;
|
|
31
|
+
const pixelWidth = (width * dpr).toString();
|
|
32
|
+
const pixelHeight = (height * dpr).toString();
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
canvas.getAttribute("width") !== pixelWidth ||
|
|
36
|
+
canvas.getAttribute("height") !== pixelHeight
|
|
37
|
+
) {
|
|
38
|
+
canvas.setAttribute("width", pixelWidth);
|
|
39
|
+
canvas.setAttribute("height", pixelHeight);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const context = canvas.getContext("webgpu")!;
|
|
43
|
+
return Object.assign(context, {
|
|
44
|
+
present: () => {},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// @ts-expect-error - polyfill for RNWebGPU native module
|
|
49
|
+
window.RNWebGPU = {
|
|
50
|
+
getNativeSurface,
|
|
51
|
+
MakeWebGPUCanvasContext: makeWebGPUCanvasContext,
|
|
52
|
+
fabric,
|
|
53
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,197 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from "./
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
GPUBindGroup[Symbol.hasInstance] = function (instance: object) {
|
|
27
|
-
return "__brand" in instance && instance.__brand === "GPUBindGroup";
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const GPUBindGroupLayout: any = {};
|
|
31
|
-
GPUBindGroupLayout[Symbol.hasInstance] = function (instance: object) {
|
|
32
|
-
return "__brand" in instance && instance.__brand === "GPUBindGroupLayout";
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const GPUBuffer: any = {};
|
|
36
|
-
GPUBuffer[Symbol.hasInstance] = function (instance: object) {
|
|
37
|
-
return "__brand" in instance && instance.__brand === "GPUBuffer";
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const GPUCanvasContext: any = {};
|
|
41
|
-
GPUCanvasContext[Symbol.hasInstance] = function (instance: object) {
|
|
42
|
-
return "__brand" in instance && instance.__brand === "GPUCanvasContext";
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const GPUCommandBuffer: any = {};
|
|
46
|
-
GPUCommandBuffer[Symbol.hasInstance] = function (instance: object) {
|
|
47
|
-
return "__brand" in instance && instance.__brand === "GPUCommandBuffer";
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const GPUCommandEncoder: any = {};
|
|
51
|
-
GPUCommandEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
52
|
-
return "__brand" in instance && instance.__brand === "GPUCommandEncoder";
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const GPUCompilationInfo: any = {};
|
|
56
|
-
GPUCompilationInfo[Symbol.hasInstance] = function (instance: object) {
|
|
57
|
-
return "__brand" in instance && instance.__brand === "GPUCompilationInfo";
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const GPUCompilationMessage: any = {};
|
|
61
|
-
GPUCompilationMessage[Symbol.hasInstance] = function (instance: object) {
|
|
62
|
-
return "__brand" in instance && instance.__brand === "GPUCompilationMessage";
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const GPUComputePassEncoder: any = {};
|
|
66
|
-
GPUComputePassEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
67
|
-
return "__brand" in instance && instance.__brand === "GPUComputePassEncoder";
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const GPUComputePipeline: any = {};
|
|
71
|
-
GPUComputePipeline[Symbol.hasInstance] = function (instance: object) {
|
|
72
|
-
return "__brand" in instance && instance.__brand === "GPUComputePipeline";
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const GPUDevice: any = {};
|
|
76
|
-
GPUDevice[Symbol.hasInstance] = function (instance: object) {
|
|
77
|
-
return "__brand" in instance && instance.__brand === "GPUDevice";
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const GPUDeviceLostInfo: any = {};
|
|
81
|
-
GPUDeviceLostInfo[Symbol.hasInstance] = function (instance: object) {
|
|
82
|
-
return "__brand" in instance && instance.__brand === "GPUDeviceLostInfo";
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const GPUError: any = {};
|
|
86
|
-
GPUError[Symbol.hasInstance] = function (instance: object) {
|
|
87
|
-
return "__brand" in instance && instance.__brand === "GPUError";
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const GPUExternalTexture: any = {};
|
|
91
|
-
GPUExternalTexture[Symbol.hasInstance] = function (instance: object) {
|
|
92
|
-
return "__brand" in instance && instance.__brand === "GPUExternalTexture";
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const GPUPipelineLayout: any = {};
|
|
96
|
-
GPUPipelineLayout[Symbol.hasInstance] = function (instance: object) {
|
|
97
|
-
return "__brand" in instance && instance.__brand === "GPUPipelineLayout";
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const GPUQuerySet: any = {};
|
|
101
|
-
GPUQuerySet[Symbol.hasInstance] = function (instance: object) {
|
|
102
|
-
return "__brand" in instance && instance.__brand === "GPUQuerySet";
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const GPUQueue: any = {};
|
|
106
|
-
GPUQueue[Symbol.hasInstance] = function (instance: object) {
|
|
107
|
-
return "__brand" in instance && instance.__brand === "GPUQueue";
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const GPURenderBundle: any = {};
|
|
111
|
-
GPURenderBundle[Symbol.hasInstance] = function (instance: object) {
|
|
112
|
-
return "__brand" in instance && instance.__brand === "GPURenderBundle";
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const GPURenderBundleEncoder: any = {};
|
|
116
|
-
GPURenderBundleEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
117
|
-
return "__brand" in instance && instance.__brand === "GPURenderBundleEncoder";
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const GPURenderPassEncoder: any = {};
|
|
121
|
-
GPURenderPassEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
122
|
-
return "__brand" in instance && instance.__brand === "GPURenderPassEncoder";
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const GPURenderPipeline: any = {};
|
|
126
|
-
GPURenderPipeline[Symbol.hasInstance] = function (instance: object) {
|
|
127
|
-
return "__brand" in instance && instance.__brand === "GPURenderPipeline";
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const GPUSampler: any = {};
|
|
131
|
-
GPUSampler[Symbol.hasInstance] = function (instance: object) {
|
|
132
|
-
return "__brand" in instance && instance.__brand === "GPUSampler";
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const GPUShaderModule: any = {};
|
|
136
|
-
GPUShaderModule[Symbol.hasInstance] = function (instance: object) {
|
|
137
|
-
return "__brand" in instance && instance.__brand === "GPUShaderModule";
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const GPUTexture: any = {};
|
|
141
|
-
GPUTexture[Symbol.hasInstance] = function (instance: object) {
|
|
142
|
-
return "__brand" in instance && instance.__brand === "GPUTexture";
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const GPUTextureView: any = {};
|
|
146
|
-
GPUTextureView[Symbol.hasInstance] = function (instance: object) {
|
|
147
|
-
return "__brand" in instance && instance.__brand === "GPUTextureView";
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
global.GPU = GPU;
|
|
151
|
-
global.GPUAdapter = GPUAdapter;
|
|
152
|
-
global.GPUAdapterInfo = GPUAdapterInfo;
|
|
153
|
-
global.GPUBindGroup = GPUBindGroup;
|
|
154
|
-
global.GPUBindGroupLayout = GPUBindGroupLayout;
|
|
155
|
-
global.GPUBuffer = GPUBuffer;
|
|
156
|
-
global.GPUCanvasContext = GPUCanvasContext;
|
|
157
|
-
global.GPUCommandBuffer = GPUCommandBuffer;
|
|
158
|
-
global.GPUCommandEncoder = GPUCommandEncoder;
|
|
159
|
-
global.GPUCompilationInfo = GPUCompilationInfo;
|
|
160
|
-
global.GPUCompilationMessage = GPUCompilationMessage;
|
|
161
|
-
global.GPUComputePassEncoder = GPUComputePassEncoder;
|
|
162
|
-
global.GPUComputePipeline = GPUComputePipeline;
|
|
163
|
-
global.GPUDevice = GPUDevice;
|
|
164
|
-
global.GPUDeviceLostInfo = GPUDeviceLostInfo;
|
|
165
|
-
global.GPUError = GPUError;
|
|
166
|
-
global.GPUExternalTexture = GPUExternalTexture;
|
|
167
|
-
global.GPUPipelineLayout = GPUPipelineLayout;
|
|
168
|
-
global.GPUQuerySet = GPUQuerySet;
|
|
169
|
-
global.GPUQueue = GPUQueue;
|
|
170
|
-
global.GPURenderBundle = GPURenderBundle;
|
|
171
|
-
global.GPURenderBundleEncoder = GPURenderBundleEncoder;
|
|
172
|
-
global.GPURenderPassEncoder = GPURenderPassEncoder;
|
|
173
|
-
global.GPURenderPipeline = GPURenderPipeline;
|
|
174
|
-
global.GPUSampler = GPUSampler;
|
|
175
|
-
global.GPUShaderModule = GPUShaderModule;
|
|
176
|
-
global.GPUTexture = GPUTexture;
|
|
177
|
-
global.GPUTextureView = GPUTextureView;
|
|
178
|
-
|
|
179
|
-
WebGPUNativeModule.install();
|
|
180
|
-
|
|
181
|
-
if (!navigator) {
|
|
182
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
183
|
-
// @ts-expect-error
|
|
184
|
-
navigator = {};
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
|
|
3
|
+
import type { NativeCanvas, RNCanvasContext } from "./types";
|
|
4
|
+
|
|
5
|
+
export * from "./main";
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Navigator {
|
|
9
|
+
gpu: GPU;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var navigator: Navigator;
|
|
13
|
+
|
|
14
|
+
var RNWebGPU: {
|
|
15
|
+
gpu: GPU;
|
|
16
|
+
fabric: boolean;
|
|
17
|
+
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
18
|
+
MakeWebGPUCanvasContext: (
|
|
19
|
+
contextId: number,
|
|
20
|
+
width: number,
|
|
21
|
+
height: number,
|
|
22
|
+
) => RNCanvasContext;
|
|
23
|
+
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
24
|
+
createImageBitmap: typeof createImageBitmap;
|
|
25
|
+
};
|
|
185
26
|
}
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
187
|
-
// @ts-expect-error
|
|
188
|
-
navigator.gpu = RNWebGPU.gpu;
|
|
189
|
-
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
navigator.userAgent = "react-native";
|
|
193
|
-
|
|
194
|
-
global.createImageBitmap =
|
|
195
|
-
global.createImageBitmap ??
|
|
196
|
-
((...params: Parameters<typeof createImageBitmap>) =>
|
|
197
|
-
new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
|
|
@@ -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