react-native-wgpu 0.1.20 → 0.1.22
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 +9 -63
- package/android/CMakeLists.txt +15 -1
- package/apple/ApplePlatformContext.mm +6 -2
- package/apple/MetalView.h +1 -1
- package/apple/MetalView.mm +8 -9
- package/cpp/rnwgpu/SurfaceRegistry.h +1 -3
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +12 -27
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +28 -1
- package/lib/commonjs/NativeWebGPUModule.js.map +1 -1
- package/lib/commonjs/Offscreen.js +6 -27
- package/lib/commonjs/Offscreen.js.map +1 -1
- package/lib/module/NativeWebGPUModule.js.map +1 -1
- package/lib/module/Offscreen.js +6 -27
- package/lib/module/Offscreen.js.map +1 -1
- package/lib/typescript/lib/commonjs/Offscreen.d.ts +2 -8
- package/lib/typescript/lib/commonjs/Offscreen.d.ts.map +1 -1
- package/lib/typescript/lib/module/Offscreen.d.ts +2 -8
- package/lib/typescript/lib/module/Offscreen.d.ts.map +1 -1
- package/lib/typescript/src/NativeWebGPUModule.d.ts +0 -1
- package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -1
- package/lib/typescript/src/Offscreen.d.ts +4 -15
- package/lib/typescript/src/Offscreen.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +10 -10
- package/lib/typescript/src/__tests__/components/cube.d.ts +1 -1
- package/lib/typescript/src/__tests__/components/cube.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +3 -3
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/NativeWebGPUModule.ts +0 -1
- package/src/Offscreen.ts +7 -58
- package/src/__tests__/GPU.spec.ts +70 -39
package/README.md
CHANGED
|
@@ -11,15 +11,21 @@ Please note that the package name is `react-native-wgpu`.
|
|
|
11
11
|
npm install react-native-wgpu
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Below are some examples from the [example app](/
|
|
14
|
+
Below are some examples from the [example app](/apps/example/).
|
|
15
15
|
|
|
16
16
|
https://github.com/user-attachments/assets/116a41b2-2cf8-49f1-9f16-a5c83637c198
|
|
17
17
|
|
|
18
18
|
Starting from `r168`, Three.js runs out of the box with React Native WebGPU.
|
|
19
|
-
You need to have a slight modification of [the metro config](/
|
|
19
|
+
You need to have a slight modification of [the metro config](/apps/example/metro.config.js) to resolve Three.js to the WebGPU build.
|
|
20
|
+
We also support [three-fiber](/apps/example/src/ThreeJS/Fiber.tsx).
|
|
21
|
+
For model loading, we also need [the following polyfill](/apps/example/src/App.tsx#29).
|
|
20
22
|
|
|
21
23
|
https://github.com/user-attachments/assets/5b49ef63-0a3c-4679-aeb5-e4b4dddfcc1d
|
|
22
24
|
|
|
25
|
+
We also provide prebuilt binaries for visionOS and macOS.
|
|
26
|
+
|
|
27
|
+
https://github.com/user-attachments/assets/2d5c618e-5b15-4cef-8558-d4ddf8c70667
|
|
28
|
+
|
|
23
29
|
## Usage
|
|
24
30
|
|
|
25
31
|
Currently we recommend to use the `useCanvasEffect` to access the WebGPU context.
|
|
@@ -123,13 +129,7 @@ const style = StyleSheet.create({
|
|
|
123
129
|
|
|
124
130
|
## Example App
|
|
125
131
|
|
|
126
|
-
To run the example app you first need to build Dawn.
|
|
127
|
-
|
|
128
|
-
```sh
|
|
129
|
-
$ git submodule update --init
|
|
130
|
-
$ cd package && yarn
|
|
131
|
-
$ yarn build-dawn
|
|
132
|
-
```
|
|
132
|
+
To run the example app you first need to [build Dawn or download the prebuilt binaries](#building-dawn).
|
|
133
133
|
|
|
134
134
|
From there you will be able to run the example app properly.
|
|
135
135
|
|
|
@@ -184,57 +184,3 @@ device.queue.copyExternalImageToTexture(
|
|
|
184
184
|
[imageBitmap.width, imageBitmap.height],
|
|
185
185
|
);
|
|
186
186
|
```
|
|
187
|
-
|
|
188
|
-
## Troubleshooting
|
|
189
|
-
|
|
190
|
-
### iOS
|
|
191
|
-
|
|
192
|
-
To run the React Native WebGPU project on the iOS simulator, you need to disable the Metal validation API.
|
|
193
|
-
In "Edit Scheme," uncheck "Metal Validation."
|
|
194
|
-
|
|
195
|
-
<img width="1052" alt="Uncheck 'Metal Validation'" src="https://github.com/user-attachments/assets/2676e5cc-e351-4a97-bdc8-22cbd7df2ef2">
|
|
196
|
-
|
|
197
|
-
### Android
|
|
198
|
-
|
|
199
|
-
On an Android simulator, a CPU emulation layer is used which may result in very slow performance.
|
|
200
|
-
|
|
201
|
-
## Library Development
|
|
202
|
-
|
|
203
|
-
Make sure to check out the submodules:
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
git submodule update --init
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Make sure you have all the tools required for building the Skia libraries (Android Studio, XCode, Ninja, CMake, Android NDK/build tools).
|
|
210
|
-
|
|
211
|
-
### Building
|
|
212
|
-
|
|
213
|
-
* `cd packages/webgpu && yarn`
|
|
214
|
-
* `yarn build-dawn`
|
|
215
|
-
|
|
216
|
-
### Upgrading
|
|
217
|
-
|
|
218
|
-
1. `git submodule update --remote`
|
|
219
|
-
2. `yarn clean-dawn`
|
|
220
|
-
3. `yarn build-dawn`
|
|
221
|
-
|
|
222
|
-
### Codegen
|
|
223
|
-
|
|
224
|
-
* `cd packages/webgpu && yarn codegen`
|
|
225
|
-
|
|
226
|
-
### Testing
|
|
227
|
-
|
|
228
|
-
In the `package` folder, to run the test against Chrome for reference:
|
|
229
|
-
|
|
230
|
-
```
|
|
231
|
-
yarn test:ref
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
To run the e2e test, open the example app on the e2e screen.
|
|
235
|
-
By default, it will try to connect to a localhost test server.
|
|
236
|
-
If you want to run the test suite on a physical device, you can modify the address [here](/package/example/src/useClient.ts#L4).
|
|
237
|
-
|
|
238
|
-
```
|
|
239
|
-
yarn test
|
|
240
|
-
```
|
package/android/CMakeLists.txt
CHANGED
|
@@ -82,7 +82,20 @@ add_library(webgpu_dawn SHARED IMPORTED)
|
|
|
82
82
|
set_property(TARGET webgpu_dawn PROPERTY IMPORTED_LOCATION "${WEBGPU_LIBS_PATH}/libwebgpu_dawn.so")
|
|
83
83
|
|
|
84
84
|
# Link
|
|
85
|
-
|
|
85
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
86
|
+
target_link_libraries(
|
|
87
|
+
${PACKAGE_NAME}
|
|
88
|
+
${FBJNI_LIBRARY}
|
|
89
|
+
log
|
|
90
|
+
jnigraphics
|
|
91
|
+
android
|
|
92
|
+
fbjni::fbjni
|
|
93
|
+
ReactAndroid::jsi
|
|
94
|
+
ReactAndroid::reactnative
|
|
95
|
+
webgpu_dawn
|
|
96
|
+
)
|
|
97
|
+
else()
|
|
98
|
+
target_link_libraries(
|
|
86
99
|
${PACKAGE_NAME}
|
|
87
100
|
${FBJNI_LIBRARY}
|
|
88
101
|
log
|
|
@@ -93,3 +106,4 @@ target_link_libraries(
|
|
|
93
106
|
ReactAndroid::reactnativejni
|
|
94
107
|
webgpu_dawn
|
|
95
108
|
)
|
|
109
|
+
endif()
|
|
@@ -25,7 +25,9 @@ void checkIfUsingSimulatorWithAPIValidation() {
|
|
|
25
25
|
#endif
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
ApplePlatformContext::ApplePlatformContext() {
|
|
28
|
+
ApplePlatformContext::ApplePlatformContext() {
|
|
29
|
+
checkIfUsingSimulatorWithAPIValidation();
|
|
30
|
+
}
|
|
29
31
|
|
|
30
32
|
wgpu::Surface ApplePlatformContext::makeSurface(wgpu::Instance instance,
|
|
31
33
|
void *surface, int width,
|
|
@@ -62,7 +64,9 @@ ImageData ApplePlatformContext::createImageBitmap(std::string blobId,
|
|
|
62
64
|
#if !TARGET_OS_OSX
|
|
63
65
|
CGImageRef cgImage = image.CGImage;
|
|
64
66
|
#else
|
|
65
|
-
CGImageRef cgImage = [image CGImageForProposedRect:NULL
|
|
67
|
+
CGImageRef cgImage = [image CGImageForProposedRect:NULL
|
|
68
|
+
context:NULL
|
|
69
|
+
hints:NULL];
|
|
66
70
|
#endif
|
|
67
71
|
size_t width = CGImageGetWidth(cgImage);
|
|
68
72
|
size_t height = CGImageGetHeight(cgImage);
|
package/apple/MetalView.h
CHANGED
package/apple/MetalView.mm
CHANGED
|
@@ -13,15 +13,14 @@
|
|
|
13
13
|
+ (Class)layerClass {
|
|
14
14
|
return [CAMetalLayer class];
|
|
15
15
|
}
|
|
16
|
-
#else
|
|
17
|
-
- (instancetype)init
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return self;
|
|
16
|
+
#else // !TARGET_OS_OSX
|
|
17
|
+
- (instancetype)init {
|
|
18
|
+
self = [super init];
|
|
19
|
+
if (self) {
|
|
20
|
+
self.wantsLayer = true;
|
|
21
|
+
self.layer = [CAMetalLayer layer];
|
|
22
|
+
}
|
|
23
|
+
return self;
|
|
25
24
|
}
|
|
26
25
|
#endif // !TARGET_OS_OSX
|
|
27
26
|
|
|
@@ -24,9 +24,7 @@ public:
|
|
|
24
24
|
SurfaceInfo(wgpu::Instance gpu, int width, int height)
|
|
25
25
|
: gpu(std::move(gpu)), width(width), height(height) {}
|
|
26
26
|
|
|
27
|
-
~SurfaceInfo() {
|
|
28
|
-
surface = nullptr;
|
|
29
|
-
}
|
|
27
|
+
~SurfaceInfo() { surface = nullptr; }
|
|
30
28
|
|
|
31
29
|
void reconfigure(int newWidth, int newHeight) {
|
|
32
30
|
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
@@ -18,36 +18,18 @@ namespace m = margelo;
|
|
|
18
18
|
|
|
19
19
|
class GPUAdapterInfo : public m::HybridObject {
|
|
20
20
|
public:
|
|
21
|
-
explicit GPUAdapterInfo(wgpu::AdapterInfo &
|
|
22
|
-
: HybridObject("GPUAdapterInfo"),
|
|
21
|
+
explicit GPUAdapterInfo(wgpu::AdapterInfo &info)
|
|
22
|
+
: HybridObject("GPUAdapterInfo"), _vendor(info.vendor),
|
|
23
|
+
_architecture(info.architecture), _device(info.device),
|
|
24
|
+
_description(info.description) {}
|
|
23
25
|
|
|
24
26
|
public:
|
|
25
27
|
std::string getBrand() { return _name; }
|
|
26
28
|
|
|
27
|
-
std::string getVendor() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return "";
|
|
32
|
-
}
|
|
33
|
-
std::string getArchitecture() {
|
|
34
|
-
if (_instance.architecture.length) {
|
|
35
|
-
return _instance.architecture.data;
|
|
36
|
-
}
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
std::string getDevice() {
|
|
40
|
-
if (_instance.device.length) {
|
|
41
|
-
return _instance.device.data;
|
|
42
|
-
}
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
std::string getDescription() {
|
|
46
|
-
if (_instance.device.length) {
|
|
47
|
-
return _instance.device.data;
|
|
48
|
-
}
|
|
49
|
-
return "";
|
|
50
|
-
}
|
|
29
|
+
std::string getVendor() { return _vendor; }
|
|
30
|
+
std::string getArchitecture() { return _architecture; }
|
|
31
|
+
std::string getDevice() { return _device; }
|
|
32
|
+
std::string getDescription() { return _description; }
|
|
51
33
|
|
|
52
34
|
void loadHybridMethods() override {
|
|
53
35
|
registerHybridGetter("__brand", &GPUAdapterInfo::getBrand, this);
|
|
@@ -60,7 +42,10 @@ public:
|
|
|
60
42
|
}
|
|
61
43
|
|
|
62
44
|
private:
|
|
63
|
-
|
|
45
|
+
std::string _vendor;
|
|
46
|
+
std::string _architecture;
|
|
47
|
+
std::string _device;
|
|
48
|
+
std::string _description;
|
|
64
49
|
};
|
|
65
50
|
|
|
66
51
|
} // namespace rnwgpu
|
|
@@ -34,6 +34,33 @@ namespace margelo {
|
|
|
34
34
|
|
|
35
35
|
using namespace rnwgpu; // NOLINT(build/namespaces)
|
|
36
36
|
|
|
37
|
+
// We add this extra convertor because we found so library that are sending
|
|
38
|
+
// invalid feature elements
|
|
39
|
+
template <> struct JSIConverter<std::vector<wgpu::FeatureName>> {
|
|
40
|
+
|
|
41
|
+
static std::vector<wgpu::FeatureName>
|
|
42
|
+
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
|
|
43
|
+
jsi::Array array = arg.asObject(runtime).asArray(runtime);
|
|
44
|
+
size_t length = array.size(runtime);
|
|
45
|
+
|
|
46
|
+
std::vector<wgpu::FeatureName> vector;
|
|
47
|
+
vector.reserve(length);
|
|
48
|
+
for (size_t i = 0; i < length; ++i) {
|
|
49
|
+
jsi::Value elementValue = array.getValueAtIndex(runtime, i);
|
|
50
|
+
if (elementValue.isString()) {
|
|
51
|
+
vector.emplace_back(JSIConverter<wgpu::FeatureName>::fromJSI(
|
|
52
|
+
runtime, elementValue, outOfBounds));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return vector;
|
|
56
|
+
}
|
|
57
|
+
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
58
|
+
std::shared_ptr<rnwgpu::GPUDeviceDescriptor> arg) {
|
|
59
|
+
throw std::runtime_error(
|
|
60
|
+
"Invalid JSIConverter<std::vector<wgpu::FeatureName>>::toJSI()");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
37
64
|
template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUDeviceDescriptor>> {
|
|
38
65
|
static std::shared_ptr<rnwgpu::GPUDeviceDescriptor>
|
|
39
66
|
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
|
|
@@ -74,4 +101,4 @@ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUDeviceDescriptor>> {
|
|
|
74
101
|
}
|
|
75
102
|
};
|
|
76
103
|
|
|
77
|
-
} // namespace margelo
|
|
104
|
+
} // namespace margelo
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeWebGPUModule.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeWebGPUModule.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAMA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACeC,gCAAmB,CAACC,YAAY,CAAO,cAAc,CAAC","ignoreList":[]}
|
|
@@ -4,45 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.GPUOffscreenCanvas = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
7
|
class GPUOffscreenCanvas {
|
|
9
|
-
oncontextlost = null;
|
|
10
|
-
oncontextrestored = null;
|
|
11
8
|
constructor(width, height) {
|
|
12
9
|
this.width = width;
|
|
13
10
|
this.height = height;
|
|
14
11
|
this.context = new GPUOffscreenCanvasContext(this);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
// Implementation for converting the canvas content to a Blob
|
|
18
|
-
throw new Error("Method not implemented.");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Overloaded method signatures
|
|
22
|
-
|
|
23
|
-
getContext(contextId, _options) {
|
|
13
|
+
getContext(contextId) {
|
|
24
14
|
if (contextId === "webgpu") {
|
|
25
15
|
return this.context;
|
|
26
16
|
}
|
|
27
17
|
// Implement other context types if necessary
|
|
28
18
|
return null;
|
|
29
19
|
}
|
|
30
|
-
transferToImageBitmap() {
|
|
31
|
-
// Implementation for transferring the canvas content to an ImageBitmap
|
|
32
|
-
throw new Error("Method not implemented.");
|
|
33
|
-
}
|
|
34
|
-
addEventListener(_type, _listener, _options) {
|
|
35
|
-
// Event listener implementation
|
|
36
|
-
throw new Error("Method not implemented.");
|
|
37
|
-
}
|
|
38
|
-
removeEventListener(_type, _listener, _options) {
|
|
39
|
-
// Remove event listener implementation
|
|
40
|
-
throw new Error("Method not implemented.");
|
|
41
|
-
}
|
|
42
|
-
dispatchEvent(_event) {
|
|
43
|
-
// Event dispatch implementation
|
|
44
|
-
throw new Error("Method not implemented.");
|
|
45
|
-
}
|
|
46
20
|
getImageData() {
|
|
47
21
|
const device = this.context.getDevice();
|
|
48
22
|
const texture = this.context.getTexture();
|
|
@@ -78,10 +52,15 @@ class GPUOffscreenCanvasContext {
|
|
|
78
52
|
__brand = "GPUCanvasContext";
|
|
79
53
|
texture = null;
|
|
80
54
|
device = null;
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
57
|
constructor(canvas) {
|
|
82
58
|
this.canvas = canvas;
|
|
83
59
|
this.textureFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
84
60
|
}
|
|
61
|
+
getConfiguration() {
|
|
62
|
+
throw new Error("Method not implemented.");
|
|
63
|
+
}
|
|
85
64
|
present() {
|
|
86
65
|
// Do nothing
|
|
87
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GPUOffscreenCanvas","
|
|
1
|
+
{"version":3,"names":["GPUOffscreenCanvas","constructor","width","height","context","GPUOffscreenCanvasContext","getContext","contextId","getImageData","device","getDevice","texture","getTexture","commandEncoder","createCommandEncoder","bytesPerRow","buffer","createBuffer","size","usage","GPUBufferUsage","COPY_DST","MAP_READ","copyTextureToBuffer","queue","submit","finish","mapAsync","GPUMapMode","READ","then","arrayBuffer","getMappedRange","uint8Array","Uint8Array","data","Array","from","unmap","format","navigator","gpu","getPreferredCanvasFormat","exports","__brand","canvas","textureFormat","getConfiguration","Error","present","configure","config","createTexture","GPUTextureUsage","RENDER_ATTACHMENT","COPY_SRC","TEXTURE_BINDING","undefined","unconfigure","destroy","getCurrentTexture"],"sourceRoot":"../../src","sources":["Offscreen.ts"],"mappings":";;;;;;AAAO,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GwC,MAAM,CAAC1C,MAAM,CAAC2C,aAAa,CAAC;MACzClC,IAAI,EAAE,CAAC,IAAI,CAAC2B,MAAM,CAAC3C,KAAK,EAAE,IAAI,CAAC2C,MAAM,CAAC1C,MAAM,CAAC;MAC7CoC,MAAM,EAAE,IAAI,CAACO,aAAa;MAC1B3B,KAAK,EACHkC,eAAe,CAACC,iBAAiB,GACjCD,eAAe,CAACE,QAAQ,GACxBF,eAAe,CAACG;IACpB,CAAC,CAAC;IACF,OAAOC,SAAS;EAClB;EAEAC,WAAWA,CAAA,EAAG;IACZ;IACA,IAAI,IAAI,CAAC/C,OAAO,EAAE;MAChB,IAAI,CAACA,OAAO,CAACgD,OAAO,CAAC,CAAC;IACxB;IACA,OAAOF,SAAS;EAClB;EAEAG,iBAAiBA,CAAA,EAAe;IAC9B,IAAI,CAAC,IAAI,CAACjD,OAAO,EAAE;MACjB,MAAM,IAAIqC,KAAK,CAAC,2BAA2B,CAAC;IAC9C;IACA,OAAO,IAAI,CAACrC,OAAO;EACrB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeWebGPUModule.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeWebGPUModule.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAMlD;AACA,eAAeA,mBAAmB,CAACC,YAAY,CAAO,cAAc,CAAC","ignoreList":[]}
|
package/lib/module/Offscreen.js
CHANGED
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
export class GPUOffscreenCanvas {
|
|
3
|
-
oncontextlost = null;
|
|
4
|
-
oncontextrestored = null;
|
|
5
2
|
constructor(width, height) {
|
|
6
3
|
this.width = width;
|
|
7
4
|
this.height = height;
|
|
8
5
|
this.context = new GPUOffscreenCanvasContext(this);
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
// Implementation for converting the canvas content to a Blob
|
|
12
|
-
throw new Error("Method not implemented.");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Overloaded method signatures
|
|
16
|
-
|
|
17
|
-
getContext(contextId, _options) {
|
|
7
|
+
getContext(contextId) {
|
|
18
8
|
if (contextId === "webgpu") {
|
|
19
9
|
return this.context;
|
|
20
10
|
}
|
|
21
11
|
// Implement other context types if necessary
|
|
22
12
|
return null;
|
|
23
13
|
}
|
|
24
|
-
transferToImageBitmap() {
|
|
25
|
-
// Implementation for transferring the canvas content to an ImageBitmap
|
|
26
|
-
throw new Error("Method not implemented.");
|
|
27
|
-
}
|
|
28
|
-
addEventListener(_type, _listener, _options) {
|
|
29
|
-
// Event listener implementation
|
|
30
|
-
throw new Error("Method not implemented.");
|
|
31
|
-
}
|
|
32
|
-
removeEventListener(_type, _listener, _options) {
|
|
33
|
-
// Remove event listener implementation
|
|
34
|
-
throw new Error("Method not implemented.");
|
|
35
|
-
}
|
|
36
|
-
dispatchEvent(_event) {
|
|
37
|
-
// Event dispatch implementation
|
|
38
|
-
throw new Error("Method not implemented.");
|
|
39
|
-
}
|
|
40
14
|
getImageData() {
|
|
41
15
|
const device = this.context.getDevice();
|
|
42
16
|
const texture = this.context.getTexture();
|
|
@@ -71,10 +45,15 @@ class GPUOffscreenCanvasContext {
|
|
|
71
45
|
__brand = "GPUCanvasContext";
|
|
72
46
|
texture = null;
|
|
73
47
|
device = null;
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
50
|
constructor(canvas) {
|
|
75
51
|
this.canvas = canvas;
|
|
76
52
|
this.textureFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
77
53
|
}
|
|
54
|
+
getConfiguration() {
|
|
55
|
+
throw new Error("Method not implemented.");
|
|
56
|
+
}
|
|
78
57
|
present() {
|
|
79
58
|
// Do nothing
|
|
80
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GPUOffscreenCanvas","
|
|
1
|
+
{"version":3,"names":["GPUOffscreenCanvas","constructor","width","height","context","GPUOffscreenCanvasContext","getContext","contextId","getImageData","device","getDevice","texture","getTexture","commandEncoder","createCommandEncoder","bytesPerRow","buffer","createBuffer","size","usage","GPUBufferUsage","COPY_DST","MAP_READ","copyTextureToBuffer","queue","submit","finish","mapAsync","GPUMapMode","READ","then","arrayBuffer","getMappedRange","uint8Array","Uint8Array","data","Array","from","unmap","format","navigator","gpu","getPreferredCanvasFormat","__brand","canvas","textureFormat","getConfiguration","Error","present","configure","config","createTexture","GPUTextureUsage","RENDER_ATTACHMENT","COPY_SRC","TEXTURE_BINDING","undefined","unconfigure","destroy","getCurrentTexture"],"sourceRoot":"../../src","sources":["Offscreen.ts"],"mappings":"AAAA,OAAO,MAAMA,kBAAkB,CAAC;EAM9BC,WAAWA,CAACC,KAAa,EAAEC,MAAc,EAAE;IACzC,IAAI,CAACD,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAG,IAAIC,yBAAyB,CAAC,IAAI,CAAC;EACpD;EAEAC,UAAUA,CAACC,SAAmB,EAAoC;IAChE,IAAIA,SAAS,KAAK,QAAQ,EAAE;MAC1B,OAAO,IAAI,CAACH,OAAO;IACrB;IACA;IACA,OAAO,IAAI;EACb;EAEAI,YAAYA,CAAA,EAAG;IACb,MAAMC,MAAM,GAAG,IAAI,CAACL,OAAO,CAACM,SAAS,CAAC,CAAC;IACvC,MAAMC,OAAO,GAAG,IAAI,CAACP,OAAO,CAACQ,UAAU,CAAC,CAAC;IACzC,MAAMC,cAAc,GAAGJ,MAAM,CAACK,oBAAoB,CAAC,CAAC;IACpD,MAAMC,WAAW,GAAG,IAAI,CAACb,KAAK,GAAG,CAAC;IAClC,MAAMc,MAAM,GAAGP,MA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ule: boolean;
|
|
2
2
|
export class GPUOffscreenCanvas {
|
|
3
3
|
constructor(width: any, height: any);
|
|
4
|
-
oncontextlost: null;
|
|
5
|
-
oncontextrestored: null;
|
|
6
4
|
width: any;
|
|
7
5
|
height: any;
|
|
8
6
|
context: GPUOffscreenCanvasContext;
|
|
9
|
-
|
|
10
|
-
getContext(contextId: any, _options: any): GPUOffscreenCanvasContext | null;
|
|
11
|
-
transferToImageBitmap(): void;
|
|
12
|
-
addEventListener(_type: any, _listener: any, _options: any): void;
|
|
13
|
-
removeEventListener(_type: any, _listener: any, _options: any): void;
|
|
14
|
-
dispatchEvent(_event: any): void;
|
|
7
|
+
getContext(contextId: any): GPUOffscreenCanvasContext | null;
|
|
15
8
|
getImageData(): any;
|
|
16
9
|
}
|
|
17
10
|
declare class GPUOffscreenCanvasContext {
|
|
@@ -21,6 +14,7 @@ declare class GPUOffscreenCanvasContext {
|
|
|
21
14
|
device: null;
|
|
22
15
|
canvas: any;
|
|
23
16
|
textureFormat: GPUTextureFormat;
|
|
17
|
+
getConfiguration(): void;
|
|
24
18
|
present(): void;
|
|
25
19
|
getDevice(): never;
|
|
26
20
|
getTexture(): never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Offscreen.d.ts","sourceRoot":"","sources":["../../../commonjs/Offscreen.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Offscreen.d.ts","sourceRoot":"","sources":["../../../commonjs/Offscreen.js"],"names":[],"mappings":";AAMA;IACE,qCAIC;IAHC,WAAkB;IAClB,YAAoB;IACpB,mCAAkD;IAEpD,6DAMC;IACD,oBA4BC;CACF;AAED;IAME,yBAGC;IARD,gBAA6B;IAC7B,cAAe;IACf,aAAc;IAIZ,YAAoB;IACpB,gCAA6D;IAE/D,yBAEC;IACD,gBAEC;IACD,mBAKC;IACD,oBAKC;IACD,kCASC;IACD,yBAMC;IACD,2BAKC;CACF"}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
export class GPUOffscreenCanvas {
|
|
2
2
|
constructor(width: any, height: any);
|
|
3
|
-
oncontextlost: null;
|
|
4
|
-
oncontextrestored: null;
|
|
5
3
|
width: any;
|
|
6
4
|
height: any;
|
|
7
5
|
context: GPUOffscreenCanvasContext;
|
|
8
|
-
|
|
9
|
-
getContext(contextId: any, _options: any): GPUOffscreenCanvasContext | null;
|
|
10
|
-
transferToImageBitmap(): void;
|
|
11
|
-
addEventListener(_type: any, _listener: any, _options: any): void;
|
|
12
|
-
removeEventListener(_type: any, _listener: any, _options: any): void;
|
|
13
|
-
dispatchEvent(_event: any): void;
|
|
6
|
+
getContext(contextId: any): GPUOffscreenCanvasContext | null;
|
|
14
7
|
getImageData(): any;
|
|
15
8
|
}
|
|
16
9
|
declare class GPUOffscreenCanvasContext {
|
|
@@ -20,6 +13,7 @@ declare class GPUOffscreenCanvasContext {
|
|
|
20
13
|
device: null;
|
|
21
14
|
canvas: any;
|
|
22
15
|
textureFormat: GPUTextureFormat;
|
|
16
|
+
getConfiguration(): void;
|
|
23
17
|
present(): void;
|
|
24
18
|
getDevice(): never;
|
|
25
19
|
getTexture(): never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Offscreen.d.ts","sourceRoot":"","sources":["../../../module/Offscreen.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Offscreen.d.ts","sourceRoot":"","sources":["../../../module/Offscreen.js"],"names":[],"mappings":"AAAA;IACE,qCAIC;IAHC,WAAkB;IAClB,YAAoB;IACpB,mCAAkD;IAEpD,6DAMC;IACD,oBA4BC;CACF;AACD;IAME,yBAGC;IARD,gBAA6B;IAC7B,cAAe;IACf,aAAc;IAIZ,YAAoB;IACpB,gCAA6D;IAE/D,yBAEC;IACD,gBAEC;IACD,mBAKC;IACD,oBAKC;IACD,kCASC;IACD,yBAMC;IACD,2BAKC;CACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
|
|
2
2
|
export interface Spec extends TurboModule {
|
|
3
3
|
install: () => boolean;
|
|
4
|
-
createSurfaceContext: (contextId: number) => boolean;
|
|
5
4
|
}
|
|
6
5
|
declare const _default: Spec;
|
|
7
6
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeWebGPUModule.d.ts","sourceRoot":"","sources":["../../../src/NativeWebGPUModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAGhF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeWebGPUModule.d.ts","sourceRoot":"","sources":["../../../src/NativeWebGPUModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAGhF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,OAAO,EAAE,MAAM,OAAO,CAAC;CACxB;;AAGD,wBAAsE"}
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
export declare class GPUOffscreenCanvas
|
|
1
|
+
export declare class GPUOffscreenCanvas {
|
|
2
2
|
width: number;
|
|
3
3
|
height: number;
|
|
4
|
-
oncontextlost: ((this: OffscreenCanvas, ev: Event) => any) | null;
|
|
5
|
-
oncontextrestored: ((this: OffscreenCanvas, ev: Event) => any) | null;
|
|
6
4
|
private context;
|
|
7
5
|
constructor(width: number, height: number);
|
|
8
|
-
convertToBlob(_options?: ImageEncodeOptions): Promise<Blob>;
|
|
9
|
-
getContext(contextId: "2d", options?: any): OffscreenCanvasRenderingContext2D | null;
|
|
10
|
-
getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null;
|
|
11
|
-
getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null;
|
|
12
|
-
getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null;
|
|
13
|
-
getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null;
|
|
14
6
|
getContext(contextId: "webgpu"): GPUOffscreenCanvasContext | null;
|
|
15
|
-
transferToImageBitmap(): ImageBitmap;
|
|
16
|
-
addEventListener<K extends keyof OffscreenCanvasEventMap>(_type: K, _listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any, _options?: boolean | AddEventListenerOptions): void;
|
|
17
|
-
removeEventListener<K extends keyof OffscreenCanvasEventMap>(_type: K, _listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any, _options?: boolean | EventListenerOptions): void;
|
|
18
|
-
dispatchEvent(_event: Event): boolean;
|
|
19
7
|
getImageData(): Promise<{
|
|
20
8
|
data: number[];
|
|
21
9
|
width: number;
|
|
@@ -24,12 +12,13 @@ export declare class GPUOffscreenCanvas implements OffscreenCanvas {
|
|
|
24
12
|
}>;
|
|
25
13
|
}
|
|
26
14
|
declare class GPUOffscreenCanvasContext implements GPUCanvasContext {
|
|
27
|
-
readonly canvas:
|
|
15
|
+
readonly canvas: any;
|
|
28
16
|
__brand: "GPUCanvasContext";
|
|
29
17
|
private textureFormat;
|
|
30
18
|
private texture;
|
|
31
19
|
private device;
|
|
32
|
-
constructor(canvas:
|
|
20
|
+
constructor(canvas: any);
|
|
21
|
+
getConfiguration(): GPUCanvasConfigurationOut | null;
|
|
33
22
|
present(): void;
|
|
34
23
|
getDevice(): GPUDevice;
|
|
35
24
|
getTexture(): GPUTexture;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Offscreen.d.ts","sourceRoot":"","sources":["../../../src/Offscreen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Offscreen.d.ts","sourceRoot":"","sources":["../../../src/Offscreen.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,OAAO,CAA4B;gBAE/B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMzC,UAAU,CAAC,SAAS,EAAE,QAAQ,GAAG,yBAAyB,GAAG,IAAI;IAQjE,YAAY;;;;;;CA6Bb;AAED,cAAM,yBAA0B,YAAW,gBAAgB;aAQ7B,MAAM,EAAE,GAAG;IAPvC,OAAO,EAAG,kBAAkB,CAAU;IAEtC,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,MAAM,CAA0B;gBAGZ,MAAM,EAAE,GAAG;IAGvC,gBAAgB,IAAI,yBAAyB,GAAG,IAAI;IAIpD,OAAO;IAIP,SAAS;IAOT,UAAU;IAOV,SAAS,CAAC,MAAM,EAAE,sBAAsB;IAcxC,WAAW;IAQX,iBAAiB,IAAI,UAAU;CAMhC"}
|
|
@@ -4,25 +4,25 @@ type Mesh = {
|
|
|
4
4
|
normals: [number, number, number][];
|
|
5
5
|
};
|
|
6
6
|
export declare function convertMeshToTypedArrays(mesh: Mesh, scale: number, offset?: number[]): {
|
|
7
|
-
vertices: Float32Array
|
|
8
|
-
indices: Uint32Array
|
|
7
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
8
|
+
indices: Uint32Array<ArrayBuffer>;
|
|
9
9
|
};
|
|
10
10
|
export declare const modelData: {
|
|
11
11
|
teapot: {
|
|
12
|
-
vertices: Float32Array
|
|
13
|
-
indices: Uint32Array
|
|
12
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
13
|
+
indices: Uint32Array<ArrayBuffer>;
|
|
14
14
|
};
|
|
15
15
|
sphere: {
|
|
16
|
-
vertices: Float32Array
|
|
17
|
-
indices: Uint32Array
|
|
16
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
17
|
+
indices: Uint32Array<ArrayBuffer>;
|
|
18
18
|
};
|
|
19
19
|
jewel: {
|
|
20
|
-
vertices: Float32Array
|
|
21
|
-
indices: Uint32Array
|
|
20
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
21
|
+
indices: Uint32Array<ArrayBuffer>;
|
|
22
22
|
};
|
|
23
23
|
rock: {
|
|
24
|
-
vertices: Float32Array
|
|
25
|
-
indices: Uint32Array
|
|
24
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
25
|
+
indices: Uint32Array<ArrayBuffer>;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
export {};
|
|
@@ -3,5 +3,5 @@ export declare const cubePositionOffset = 0;
|
|
|
3
3
|
export declare const cubeColorOffset: number;
|
|
4
4
|
export declare const cubeUVOffset: number;
|
|
5
5
|
export declare const cubeVertexCount = 36;
|
|
6
|
-
export declare const cubeVertexArray: Float32Array
|
|
6
|
+
export declare const cubeVertexArray: Float32Array<ArrayBuffer>;
|
|
7
7
|
//# sourceMappingURL=cube.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cube.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/components/cube.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,eAAe,QAAQ,CAAC;AACrC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,KAAK,CAAC;AAGlC,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"cube.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/components/cube.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,eAAe,QAAQ,CAAC;AACrC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,KAAK,CAAC;AAGlC,eAAO,MAAM,eAAe,2BA2C1B,CAAC"}
|
|
@@ -16,7 +16,7 @@ export interface Mesh {
|
|
|
16
16
|
* @returns {boolean} An object containing an array of bindGroups and the bindGroupLayout they implement.
|
|
17
17
|
*/
|
|
18
18
|
export declare const createMeshRenderable: (device: GPUDevice, mesh: Mesh, storeVertices?: boolean, storeIndices?: boolean) => Renderable;
|
|
19
|
-
export declare const getMeshPosAtIndex: (mesh: Mesh, index: number) => Float32Array
|
|
20
|
-
export declare const getMeshNormalAtIndex: (mesh: Mesh, index: number) => Float32Array
|
|
21
|
-
export declare const getMeshUVAtIndex: (mesh: Mesh, index: number) => Float32Array
|
|
19
|
+
export declare const getMeshPosAtIndex: (mesh: Mesh, index: number) => Float32Array<ArrayBufferLike>;
|
|
20
|
+
export declare const getMeshNormalAtIndex: (mesh: Mesh, index: number) => Float32Array<ArrayBufferLike>;
|
|
21
|
+
export declare const getMeshUVAtIndex: (mesh: Mesh, index: number) => Float32Array<ArrayBufferLike>;
|
|
22
22
|
//# sourceMappingURL=mesh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/mesh.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,SAAS,CAAC;IACxB,WAAW,EAAE,SAAS,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,WAAW,GAAG,WAAW,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,WACvB,SAAS,QACX,IAAI,sDAGT,UAyCF,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAU,IAAI,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/mesh.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,SAAS,CAAC;IACxB,WAAW,EAAE,SAAS,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,WAAW,GAAG,WAAW,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,WACvB,SAAS,QACX,IAAI,sDAGT,UAyCF,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAU,IAAI,SAAS,MAAM,kCAO1D,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,IAAI,SAAS,MAAM,kCAO7D,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,IAAI,SAAS,MAAM,kCAOzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wgpu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"tsc": "tsc --noEmit",
|
|
27
27
|
"build": "bob build",
|
|
28
28
|
"build-dawn": "ts-node scripts/build/dawn.ts",
|
|
29
|
-
"copy-headers": "ts-node scripts/build/copy-headers.ts",
|
|
30
29
|
"clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
|
|
31
30
|
"clang-format": "yarn clang-format-ios && yarn clang-format-android && yarn clang-format-common",
|
|
32
31
|
"clang-format-ios": "find apple/ -iname \"*.h\" -o -iname \"*.mm\" -o -iname \"*.cpp\" | xargs clang-format -i",
|
|
@@ -66,7 +65,7 @@
|
|
|
66
65
|
"@types/ws": "^8.5.10",
|
|
67
66
|
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
68
67
|
"@typescript-eslint/parser": "^8.4.0",
|
|
69
|
-
"@webgpu/types": "0.1.
|
|
68
|
+
"@webgpu/types": "0.1.51",
|
|
70
69
|
"clang-format": "^1.8.0",
|
|
71
70
|
"del-cli": "^5.1.0",
|
|
72
71
|
"eslint": "8",
|
package/src/Offscreen.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export class GPUOffscreenCanvas implements OffscreenCanvas {
|
|
1
|
+
export class GPUOffscreenCanvas {
|
|
3
2
|
width: number;
|
|
4
3
|
height: number;
|
|
5
|
-
oncontextlost: ((this: OffscreenCanvas, ev: Event) => any) | null = null;
|
|
6
|
-
oncontextrestored: ((this: OffscreenCanvas, ev: Event) => any) | null = null;
|
|
7
4
|
|
|
8
5
|
private context: GPUOffscreenCanvasContext;
|
|
9
6
|
|
|
@@ -13,31 +10,7 @@ export class GPUOffscreenCanvas implements OffscreenCanvas {
|
|
|
13
10
|
this.context = new GPUOffscreenCanvasContext(this);
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
// Implementation for converting the canvas content to a Blob
|
|
18
|
-
throw new Error("Method not implemented.");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Overloaded method signatures
|
|
22
|
-
getContext(
|
|
23
|
-
contextId: "2d",
|
|
24
|
-
options?: any,
|
|
25
|
-
): OffscreenCanvasRenderingContext2D | null;
|
|
26
|
-
getContext(
|
|
27
|
-
contextId: "bitmaprenderer",
|
|
28
|
-
options?: any,
|
|
29
|
-
): ImageBitmapRenderingContext | null;
|
|
30
|
-
getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null;
|
|
31
|
-
getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null;
|
|
32
|
-
getContext(
|
|
33
|
-
contextId: OffscreenRenderingContextId,
|
|
34
|
-
options?: any,
|
|
35
|
-
): OffscreenRenderingContext | null;
|
|
36
|
-
getContext(contextId: "webgpu"): GPUOffscreenCanvasContext | null;
|
|
37
|
-
getContext(
|
|
38
|
-
contextId: unknown,
|
|
39
|
-
_options?: any,
|
|
40
|
-
): OffscreenRenderingContext | GPUOffscreenCanvasContext | null {
|
|
13
|
+
getContext(contextId: "webgpu"): GPUOffscreenCanvasContext | null {
|
|
41
14
|
if (contextId === "webgpu") {
|
|
42
15
|
return this.context;
|
|
43
16
|
}
|
|
@@ -45,34 +18,6 @@ export class GPUOffscreenCanvas implements OffscreenCanvas {
|
|
|
45
18
|
return null;
|
|
46
19
|
}
|
|
47
20
|
|
|
48
|
-
transferToImageBitmap(): ImageBitmap {
|
|
49
|
-
// Implementation for transferring the canvas content to an ImageBitmap
|
|
50
|
-
throw new Error("Method not implemented.");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
addEventListener<K extends keyof OffscreenCanvasEventMap>(
|
|
54
|
-
_type: K,
|
|
55
|
-
_listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
|
|
56
|
-
_options?: boolean | AddEventListenerOptions,
|
|
57
|
-
): void {
|
|
58
|
-
// Event listener implementation
|
|
59
|
-
throw new Error("Method not implemented.");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
removeEventListener<K extends keyof OffscreenCanvasEventMap>(
|
|
63
|
-
_type: K,
|
|
64
|
-
_listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
|
|
65
|
-
_options?: boolean | EventListenerOptions,
|
|
66
|
-
): void {
|
|
67
|
-
// Remove event listener implementation
|
|
68
|
-
throw new Error("Method not implemented.");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
dispatchEvent(_event: Event): boolean {
|
|
72
|
-
// Event dispatch implementation
|
|
73
|
-
throw new Error("Method not implemented.");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
21
|
getImageData() {
|
|
77
22
|
const device = this.context.getDevice();
|
|
78
23
|
const texture = this.context.getTexture();
|
|
@@ -111,9 +56,13 @@ class GPUOffscreenCanvasContext implements GPUCanvasContext {
|
|
|
111
56
|
private texture: GPUTexture | null = null;
|
|
112
57
|
private device: GPUDevice | null = null;
|
|
113
58
|
|
|
114
|
-
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
constructor(public readonly canvas: any) {
|
|
115
61
|
this.textureFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
116
62
|
}
|
|
63
|
+
getConfiguration(): GPUCanvasConfigurationOut | null {
|
|
64
|
+
throw new Error("Method not implemented.");
|
|
65
|
+
}
|
|
117
66
|
|
|
118
67
|
present() {
|
|
119
68
|
// Do nothing
|
|
@@ -52,6 +52,26 @@ describe("Adapter", () => {
|
|
|
52
52
|
});
|
|
53
53
|
expect(result).toBe(true);
|
|
54
54
|
});
|
|
55
|
+
it("requestAdapter (6)", async () => {
|
|
56
|
+
const result = await client.eval(({ gpu }) => {
|
|
57
|
+
return gpu.requestAdapter().then((adapter) => {
|
|
58
|
+
if (!adapter) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
vendor: adapter.info.vendor,
|
|
63
|
+
architecture: adapter.info.architecture,
|
|
64
|
+
device: adapter.info.device,
|
|
65
|
+
description: adapter.info.description,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
expect(result).toBeDefined();
|
|
70
|
+
expect(result!.vendor).toBeDefined();
|
|
71
|
+
expect(result!.architecture).toBeDefined();
|
|
72
|
+
expect(result!.device).toBeDefined();
|
|
73
|
+
expect(result!.description).toBeDefined();
|
|
74
|
+
});
|
|
55
75
|
it("isFallback", async () => {
|
|
56
76
|
const result = await client.eval(({ adapter }) => {
|
|
57
77
|
return adapter.isFallbackAdapter;
|
|
@@ -66,32 +86,60 @@ describe("Adapter", () => {
|
|
|
66
86
|
expect(result.includes("rg11b10ufloat-renderable")).toBe(true);
|
|
67
87
|
expect(result.includes("texture-compression-etc2")).toBe(true);
|
|
68
88
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
it("requiredLimits", async () => {
|
|
90
|
+
const result = await client.eval(({ adapter }) => {
|
|
91
|
+
return adapter
|
|
92
|
+
.requestDevice({
|
|
93
|
+
requiredLimits: {
|
|
94
|
+
maxBufferSize: 1024 * 1024 * 4,
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
.then((device) => !!device);
|
|
98
|
+
});
|
|
99
|
+
expect(result).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
it("request device with timestamp queries", async () => {
|
|
102
|
+
const result = await client.eval(({ adapter }) => {
|
|
103
|
+
if (adapter.features.has("timestamp-query")) {
|
|
104
|
+
return adapter
|
|
105
|
+
.requestDevice({
|
|
106
|
+
requiredFeatures: ["timestamp-query"],
|
|
107
|
+
})
|
|
108
|
+
.then((device) => device.features.has("timestamp-query"));
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
});
|
|
112
|
+
expect(result).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
it("request device faulty input", async () => {
|
|
115
|
+
const result = await client.eval(({ adapter }) => {
|
|
116
|
+
return adapter
|
|
117
|
+
.requestDevice({
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
119
|
+
// @ts-expect-error
|
|
120
|
+
requiredFeatures: [["bgra8unorm-storage"]],
|
|
121
|
+
requiredLimits: {
|
|
122
|
+
maxComputeWorkgroupStorageSize: 16352,
|
|
123
|
+
maxComputeWorkgroupsPerDimension: 65535,
|
|
124
|
+
maxStorageBufferBindingSize: 268435456,
|
|
125
|
+
maxBufferSize: 268435456,
|
|
126
|
+
maxComputeWorkgroupSizeX: 512,
|
|
127
|
+
maxComputeInvocationsPerWorkgroup: 512,
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.then((device) => !!device);
|
|
131
|
+
});
|
|
132
|
+
expect(result).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
// it("request device with unknown feature", async () => {
|
|
89
135
|
// const result = await client.eval(({ adapter }) => {
|
|
90
136
|
// return adapter
|
|
91
137
|
// .requestDevice({
|
|
92
|
-
//
|
|
138
|
+
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
139
|
+
// // @ts-expect-error
|
|
140
|
+
// requiredFeatures: ["foobar"],
|
|
93
141
|
// })
|
|
94
|
-
// .
|
|
142
|
+
// .catch(() => true);
|
|
95
143
|
// });
|
|
96
144
|
// expect(result).toBe(true);
|
|
97
145
|
// });
|
|
@@ -120,7 +168,6 @@ describe("Adapter", () => {
|
|
|
120
168
|
maxBufferSize,
|
|
121
169
|
maxVertexAttributes,
|
|
122
170
|
maxVertexBufferArrayStride,
|
|
123
|
-
maxInterStageShaderComponents,
|
|
124
171
|
maxInterStageShaderVariables,
|
|
125
172
|
maxColorAttachments,
|
|
126
173
|
maxColorAttachmentBytesPerSample,
|
|
@@ -155,7 +202,6 @@ describe("Adapter", () => {
|
|
|
155
202
|
maxBufferSize,
|
|
156
203
|
maxVertexAttributes,
|
|
157
204
|
maxVertexBufferArrayStride,
|
|
158
|
-
maxInterStageShaderComponents,
|
|
159
205
|
maxInterStageShaderVariables,
|
|
160
206
|
maxColorAttachments,
|
|
161
207
|
maxColorAttachmentBytesPerSample,
|
|
@@ -194,21 +240,6 @@ describe("Adapter", () => {
|
|
|
194
240
|
expect(result.maxTextureDimension2D).toBeGreaterThanOrEqual(2048);
|
|
195
241
|
expect(result.maxTextureDimension3D).toBeGreaterThanOrEqual(256);
|
|
196
242
|
});
|
|
197
|
-
// it("adapter info", async () => {
|
|
198
|
-
// const result = await client.eval(({ adapter }) => {
|
|
199
|
-
// return {
|
|
200
|
-
// __brand: adapter.info.__brand,
|
|
201
|
-
// description: adapter.info.description,
|
|
202
|
-
// architecture: adapter.info.architecture,
|
|
203
|
-
// device: adapter.info.device,
|
|
204
|
-
// vendor: adapter.info.vendor,
|
|
205
|
-
// };
|
|
206
|
-
// });
|
|
207
|
-
// expect(result.description).toBeTruthy();
|
|
208
|
-
// expect(result.architecture).toBeTruthy();
|
|
209
|
-
// expect(result.device).toBeTruthy();
|
|
210
|
-
// expect(result.vendor).toBeTruthy();
|
|
211
|
-
// });
|
|
212
243
|
it("getPreferredCanvasFormat", async () => {
|
|
213
244
|
const result = await client.eval(({ gpu }) => {
|
|
214
245
|
return gpu.getPreferredCanvasFormat();
|