react-native-webgpu 0.22.0 → 0.24.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/Package.swift +18 -129
- package/README.md +15 -2
- package/android/CMakeLists.txt +2 -1
- package/android/cpp/AndroidAnimationFrameSource.h +136 -0
- package/android/cpp/AndroidPlatformContext.h +65 -9
- package/android/cpp/cpp-adapter.cpp +148 -2
- package/android/src/main/java/com/webgpu/WebGPUModule.java +24 -7
- package/android/src/main/java/com/webgpu/WebGPUNativeBufferView.java +370 -0
- package/android/src/main/java/com/webgpu/WebGPUNativeBufferViewManager.java +56 -0
- package/android/src/main/java/com/webgpu/WebGPUTextureView.java +21 -0
- package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +2 -2
- package/android/src/main/java/com/webgpu/WebGPUView.java +19 -3
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +2 -2
- package/android/src/newarch/com/webgpu/WebGPUNativeBufferViewManagerSpec.java +24 -0
- package/apple/AppleAnimationFrameSource.mm +208 -0
- package/apple/ApplePlatformContext.h +8 -1
- package/apple/ApplePlatformContext.mm +75 -2
- package/apple/NativeBufferFenceWait.mm +88 -0
- package/apple/WebGPUNativeBufferView.h +15 -0
- package/apple/WebGPUNativeBufferView.mm +200 -0
- package/binaries.json +53 -105
- package/cpp/dawn/common/ExternalTextureParams.h +3 -3
- package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
- package/cpp/dawn/include/dawn/dawn_proc_table.h +329 -0
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
- package/cpp/dawn/include/dawn/dawn_version.h +51 -0
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +104 -0
- package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/DawnNative.h +375 -0
- package/cpp/dawn/include/dawn/native/MetalBackend.h +67 -0
- package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +199 -0
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +210 -0
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
- package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
- package/cpp/dawn/include/dawn/webgpu.h +5119 -0
- package/cpp/dawn/include/dawn/webgpu_cpp.h +10506 -0
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2897 -0
- package/cpp/dawn/include/webgpu/webgpu.h +33 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +33 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_print.h +33 -0
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +163 -0
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
- package/cpp/rnwgpu/AnimationFrames.cpp +576 -0
- package/cpp/rnwgpu/AnimationFrames.h +233 -0
- package/cpp/rnwgpu/NativeBufferViewRegistry.cpp +396 -0
- package/cpp/rnwgpu/NativeBufferViewRegistry.h +163 -0
- package/cpp/rnwgpu/PlatformContext.h +21 -1
- package/cpp/rnwgpu/RNWebGPUManager.cpp +17 -4
- package/cpp/rnwgpu/SurfaceRegistry.h +2 -2
- package/cpp/rnwgpu/api/GPUAdapter.cpp +2 -2
- package/cpp/rnwgpu/api/GPUDevice.cpp +16 -131
- package/cpp/rnwgpu/api/GPUDevice.h +0 -18
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +35 -3
- package/cpp/rnwgpu/api/GPUExternalTexture.h +4 -4
- package/cpp/rnwgpu/api/GPUQueue.cpp +1 -1
- package/cpp/rnwgpu/api/GPUQueue.h +1 -1
- package/cpp/rnwgpu/api/GPUSharedFence.h +1 -0
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +11 -5
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +21 -2
- package/cpp/rnwgpu/api/GPUTexture.h +18 -0
- package/cpp/rnwgpu/api/NativeFrameFeatures.h +1 -1
- package/cpp/rnwgpu/api/NativeFrameImport.cpp +20 -17
- package/cpp/rnwgpu/api/NativeFrameImport.h +31 -20
- package/cpp/rnwgpu/api/RNWebGPU.h +206 -7
- package/cpp/rnwgpu/api/VideoFrame.h +5 -4
- package/cpp/rnwgpu/api/VideoFrameBlit.h +2 -2
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +21 -14
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +17 -9
- package/cpp/rnwgpu/async/RuntimeContext.cpp +21 -4
- package/cpp/rnwgpu/async/RuntimeContext.h +8 -0
- package/lib/commonjs/NativeBufferView.js +131 -0
- package/lib/commonjs/NativeBufferView.js.map +1 -0
- package/lib/commonjs/NativeBufferViewNativeComponent.js +10 -0
- package/lib/commonjs/NativeBufferViewNativeComponent.js.map +1 -0
- package/lib/commonjs/animationFrame.js +91 -0
- package/lib/commonjs/animationFrame.js.map +1 -0
- package/lib/commonjs/index.js +16 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/main/index.js +12 -0
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/commonjs/mock.js +30 -1
- package/lib/commonjs/mock.js.map +1 -1
- package/lib/commonjs/video.js +21 -7
- package/lib/commonjs/video.js.map +1 -1
- package/lib/module/NativeBufferView.js +122 -0
- package/lib/module/NativeBufferView.js.map +1 -0
- package/lib/module/NativeBufferViewNativeComponent.js +4 -0
- package/lib/module/NativeBufferViewNativeComponent.js.map +1 -0
- package/lib/module/animationFrame.js +83 -0
- package/lib/module/animationFrame.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.js +1 -0
- package/lib/module/main/index.js.map +1 -1
- package/lib/module/mock.js +21 -0
- package/lib/module/mock.js.map +1 -1
- package/lib/module/video.js +17 -4
- package/lib/module/video.js.map +1 -1
- package/lib/typescript/lib/commonjs/NativeBufferView.d.ts +48 -0
- package/lib/typescript/lib/commonjs/NativeBufferView.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.d.ts +5 -0
- package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/animationFrame.d.ts +54 -0
- package/lib/typescript/lib/commonjs/animationFrame.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +2 -0
- package/lib/typescript/lib/commonjs/mock.d.ts +12 -0
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/video.d.ts +9 -4
- package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
- package/lib/typescript/lib/module/NativeBufferView.d.ts +14 -0
- package/lib/typescript/lib/module/NativeBufferView.d.ts.map +1 -0
- package/lib/typescript/lib/module/NativeBufferViewNativeComponent.d.ts +3 -0
- package/lib/typescript/lib/module/NativeBufferViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/module/animationFrame.d.ts +3 -0
- package/lib/typescript/lib/module/animationFrame.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +1 -0
- package/lib/typescript/lib/module/main/index.d.ts +1 -0
- package/lib/typescript/lib/module/mock.d.ts +14 -0
- package/lib/typescript/lib/module/mock.d.ts.map +1 -1
- package/lib/typescript/lib/module/video.d.ts +4 -3
- package/lib/typescript/lib/module/video.d.ts.map +1 -1
- package/lib/typescript/react-native.config.d.ts +1 -0
- package/lib/typescript/src/NativeBufferView.d.ts +99 -0
- package/lib/typescript/src/NativeBufferView.d.ts.map +1 -0
- package/lib/typescript/src/NativeBufferViewNativeComponent.d.ts +13 -0
- package/lib/typescript/src/NativeBufferViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/animationFrame.d.ts +59 -0
- package/lib/typescript/src/animationFrame.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +18 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.d.ts +1 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -1
- package/lib/typescript/src/mock.d.ts +11 -0
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +33 -32
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/video.d.ts +18 -6
- package/lib/typescript/src/video.d.ts.map +1 -1
- package/package.json +16 -6
- package/react-native-webgpu.podspec +47 -79
- package/react-native.config.js +9 -6
- package/scripts/apple-binaries-utils.sh +280 -0
- package/scripts/prepare-apple-binaries.sh +309 -0
- package/scripts/spm-plugin.js +130 -0
- package/src/NativeBufferView.tsx +199 -0
- package/src/NativeBufferViewNativeComponent.ts +20 -0
- package/src/animationFrame.ts +82 -0
- package/src/index.tsx +48 -42
- package/src/main/index.tsx +1 -0
- package/src/mock.ts +35 -0
- package/src/types.ts +62 -88
- package/src/video.ts +32 -12
- package/cpp/rnwgpu/api/GPUNativeBufferExternalTexture.h +0 -60
- package/cpp/rnwgpu/api/GPUNativeBufferTexture.h +0 -52
- package/cpp/rnwgpu/api/GPUNativeBufferWrapper.cpp +0 -144
- package/cpp/rnwgpu/api/GPUNativeBufferWrapper.h +0 -143
- package/cpp/rnwgpu/api/descriptors/GPUNativeBufferTextureDescriptor.h +0 -55
package/Package.swift
CHANGED
|
@@ -1,134 +1,21 @@
|
|
|
1
1
|
// swift-tools-version: 6.0
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// React Native 0.87+ references a library that ships its own Package.swift
|
|
7
|
-
// through a symlink at <app>/ios/build/generated/autolinking/libs/<name>, and
|
|
8
|
-
// resolves the relative paths below against that symlink. They are the same
|
|
9
|
-
// for every standard app, because the symlink location is. Earlier React
|
|
10
|
-
// Native releases have no SwiftPM autolinking: keep CocoaPods there.
|
|
11
|
-
|
|
2
|
+
// Optional RN 0.87.1+ SwiftPM integration; CocoaPods remains the default.
|
|
3
|
+
// The autolinking plugin registers this manifest through libs/ReactNativeWebGPU
|
|
4
|
+
// and creates a neighboring link-settings package. Headers ship in npm; an
|
|
5
|
+
// Xcode phase prepares only the selected SDK's Dawn archive before app linking.
|
|
12
6
|
import Foundation
|
|
13
7
|
import PackageDescription
|
|
14
8
|
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
// A node package next to this one: a sibling in the consumer's node_modules,
|
|
23
|
-
// or under this monorepo's root.
|
|
24
|
-
let nodePackage = { (name: String) -> String? in
|
|
25
|
-
["../\(name)", "../../node_modules/\(name)"]
|
|
26
|
-
.map(sibling)
|
|
27
|
-
.first { FileManager.default.fileExists(atPath: "\($0)/package.json") }
|
|
28
|
-
}
|
|
29
|
-
let readJSON = { (path: String) -> [String: Any]? in
|
|
30
|
-
guard let data = FileManager.default.contents(atPath: path) else { return nil }
|
|
31
|
-
return try? JSONSerialization.jsonObject(with: data) as? [String: Any]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Dawn, the WebGPU implementation, comes from the react-native-webgpu-dawn npm
|
|
35
|
-
// package this package depends on: an xcframework with the `webgpu/` and
|
|
36
|
-
// `dawn/` headers embedded in every slice, which SwiftPM exposes to dependents
|
|
37
|
-
// without any search path. react-native-skia's Graphite backend links the
|
|
38
|
-
// same package, so an app installing both contains exactly one Dawn.
|
|
39
|
-
guard let dawnPath = nodePackage("react-native-webgpu-dawn") else {
|
|
40
|
-
// Reached when the dependency was skipped at install time, which SwiftPM
|
|
41
|
-
// would otherwise report as an unresolvable dependency path.
|
|
42
|
-
fatalError(
|
|
43
|
-
"""
|
|
44
|
-
react-native-webgpu-dawn was not found next to react-native-webgpu. It ships \
|
|
45
|
-
the Dawn binaries this package links against. Reinstall dependencies.
|
|
46
|
-
""")
|
|
47
|
-
}
|
|
48
|
-
let ownPackage = readJSON("\(packageRoot)/package.json") ?? [:]
|
|
49
|
-
let dawnVersion =
|
|
50
|
-
(readJSON("\(dawnPath)/package.json")?["version"] as? String) ?? "unknown"
|
|
51
|
-
|
|
52
|
-
// Skia Graphite and WebGPU must link the exact same Dawn, or the pair links
|
|
53
|
-
// fine and crashes at runtime. react-native-skia's podspec enforces this at
|
|
54
|
-
// `pod install` time; a Swift package has no install hook, so the same check
|
|
55
|
-
// runs here, at manifest evaluation. SwiftPM caches evaluations, so after
|
|
56
|
-
// changing either package's Dawn reset the package caches (File > Packages >
|
|
57
|
-
// Reset Package Caches) if this does not re-run.
|
|
58
|
-
//
|
|
59
|
-
// A react-native-skia that depends on react-native-webgpu-dawn itself must
|
|
60
|
-
// resolve the same version as this package: the copy nested under it when the
|
|
61
|
-
// package manager could not hoist it, else the one next to it (Node's
|
|
62
|
-
// resolution, which react-native-skia's podspec compares too). A workspace
|
|
63
|
-
// that resolves the package to one version for both (yarn `resolutions`, npm
|
|
64
|
-
// `overrides`) passes while react-native-skia's own pin lags behind a Dawn
|
|
65
|
-
// bump: the app then contains that one Dawn. Older Graphite builds
|
|
66
|
-
// (react-native-skia 3.0.x) vendor their own Dawn and record its release tag
|
|
67
|
-
// at libs/.dawn-version in their binary packages; this package's `dawn` field
|
|
68
|
-
// names the release that Dawn is interchangeable with.
|
|
69
|
-
if let skiaPath = nodePackage("react-native-skia"),
|
|
70
|
-
let skiaPackage = readJSON("\(skiaPath)/package.json"),
|
|
71
|
-
let skiaDawnPin = (skiaPackage["dependencies"] as? [String: String])?["react-native-webgpu-dawn"]
|
|
72
|
-
{
|
|
73
|
-
let skiaDawnPath = [
|
|
74
|
-
"\(skiaPath)/node_modules/react-native-webgpu-dawn",
|
|
75
|
-
"\(skiaPath)/../react-native-webgpu-dawn",
|
|
76
|
-
].first { FileManager.default.fileExists(atPath: "\($0)/package.json") }
|
|
77
|
-
let skiaDawn =
|
|
78
|
-
skiaDawnPath.flatMap { readJSON("\($0)/package.json")?["version"] as? String } ?? skiaDawnPin
|
|
79
|
-
if skiaDawn != dawnVersion {
|
|
80
|
-
fatalError(
|
|
81
|
-
"""
|
|
82
|
-
react-native-webgpu: Dawn version mismatch. This package links \
|
|
83
|
-
react-native-webgpu-dawn \(dawnVersion) but react-native-skia resolves \
|
|
84
|
-
\(skiaDawn) (it depends on \(skiaDawnPin)). Align the two packages so the \
|
|
85
|
-
app contains exactly one Dawn.
|
|
86
|
-
""")
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
let dawnReleaseTag =
|
|
90
|
-
"dawn-\((ownPackage["dawn"] as? String ?? "").replacingOccurrences(of: "/", with: "-"))"
|
|
91
|
-
// The graphite packages are normally hoisted next to this package, but may
|
|
92
|
-
// be nested under react-native-skia when the package manager cannot hoist
|
|
93
|
-
// them. The v2 Graphite previews (e.g. @shopify/react-native-skia@2.12.0-next.1)
|
|
94
|
-
// keep the marker in their own libs/. Every marker found is checked.
|
|
95
|
-
let skiaDawnMarkers = [
|
|
96
|
-
"react-native-skia-graphite-apple-ios/libs/.dawn-version",
|
|
97
|
-
"react-native-skia-graphite-apple-macos/libs/.dawn-version",
|
|
98
|
-
"react-native-skia/node_modules/react-native-skia-graphite-apple-ios/libs/.dawn-version",
|
|
99
|
-
"react-native-skia/node_modules/react-native-skia-graphite-apple-macos/libs/.dawn-version",
|
|
100
|
-
"@shopify/react-native-skia/libs/.dawn-version",
|
|
101
|
-
].flatMap { marker in
|
|
102
|
-
[
|
|
103
|
-
sibling("../\(marker)"), // consumer: sibling in node_modules
|
|
104
|
-
sibling("../../node_modules/\(marker)"), // this monorepo
|
|
105
|
-
]
|
|
106
|
-
}
|
|
107
|
-
for marker in skiaDawnMarkers {
|
|
108
|
-
guard let data = FileManager.default.contents(atPath: marker),
|
|
109
|
-
let skiaDawn = String(data: data, encoding: .utf8)?
|
|
110
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
111
|
-
else { continue }
|
|
112
|
-
if skiaDawn != dawnReleaseTag {
|
|
113
|
-
fatalError(
|
|
114
|
-
"""
|
|
115
|
-
react-native-webgpu: Dawn version mismatch. This package links \
|
|
116
|
-
react-native-webgpu-dawn \(dawnVersion) (\(dawnReleaseTag)) but the \
|
|
117
|
-
react-native-skia Graphite binaries (\(marker)) link \(skiaDawn). Align \
|
|
118
|
-
the two packages so the app contains exactly one Dawn.
|
|
119
|
-
""")
|
|
120
|
-
}
|
|
121
|
-
}
|
|
9
|
+
// SwiftPM discovers resources even with explicit sources. Limit discovery to
|
|
10
|
+
// native directories, excluding JS dependencies and build products automatically.
|
|
11
|
+
let packageDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
|
|
12
|
+
let nativeDirectories: Set<String> = ["apple", "cpp"]
|
|
13
|
+
let excludedPaths = try FileManager.default.contentsOfDirectory(atPath: packageDirectory.path).filter {
|
|
14
|
+
!nativeDirectories.contains($0)
|
|
122
15
|
}
|
|
123
16
|
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
// including file's own directory. The sources use bare cross-directory
|
|
127
|
-
// includes (e.g. apple/WebGPUModule.h includes "RNWebGPUManager.h" from
|
|
128
|
-
// cpp/rnwgpu), so every directory that's the target of one of those bare
|
|
129
|
-
// includes has to be listed explicitly here. The "webgpu/..." and "dawn/..."
|
|
130
|
-
// includes resolve through the Dawn xcframework's embedded headers.
|
|
131
|
-
// Keep in sync with header_dirs in react-native-webgpu.podspec.
|
|
17
|
+
// Bare includes need each internal directory explicitly, including the bundled
|
|
18
|
+
// source/generated Dawn headers. Keep this catalog aligned with the podspec.
|
|
132
19
|
let internalHeaderDirs = [
|
|
133
20
|
"apple",
|
|
134
21
|
"cpp",
|
|
@@ -137,6 +24,7 @@ let internalHeaderDirs = [
|
|
|
137
24
|
"cpp/rnwgpu/api",
|
|
138
25
|
"cpp/rnwgpu/api/descriptors",
|
|
139
26
|
"cpp/rnwgpu/async",
|
|
27
|
+
"cpp/dawn/include",
|
|
140
28
|
]
|
|
141
29
|
|
|
142
30
|
let package = Package(
|
|
@@ -145,7 +33,7 @@ let package = Package(
|
|
|
145
33
|
// target's. React Native's generated Autolinked aggregate hardcodes iOS 15.0
|
|
146
34
|
// (react-native#58379 derives it from the app instead), so this must not
|
|
147
35
|
// exceed 15.0; a lower floor is always accepted.
|
|
148
|
-
platforms: [.iOS(.v15)],
|
|
36
|
+
platforms: [.iOS(.v15), .tvOS(.v15), .macOS(.v14)],
|
|
149
37
|
products: [
|
|
150
38
|
// Autolinking looks this name up verbatim; react-native.config.js pins it.
|
|
151
39
|
.library(name: "ReactNativeWebGPU", targets: ["ReactNativeWebGPU"])
|
|
@@ -153,7 +41,7 @@ let package = Package(
|
|
|
153
41
|
dependencies: [
|
|
154
42
|
.package(name: "React-GeneratedCode", path: "../../../ios"),
|
|
155
43
|
.package(name: "ReactNative", path: "../../../../xcframeworks"),
|
|
156
|
-
.package(path:
|
|
44
|
+
.package(name: "ReactNativeWebGPUBinaries", path: "../../ReactNativeWebGPUBinaries"),
|
|
157
45
|
],
|
|
158
46
|
targets: [
|
|
159
47
|
.target(
|
|
@@ -164,12 +52,13 @@ let package = Package(
|
|
|
164
52
|
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
|
|
165
53
|
// RNWgpuViewSpec, generated by the app's codegen run.
|
|
166
54
|
.product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
|
|
167
|
-
.product(name: "
|
|
55
|
+
.product(name: "ReactNativeWebGPUBinaries", package: "ReactNativeWebGPUBinaries"),
|
|
168
56
|
],
|
|
169
57
|
// apple/ and cpp/ have no common ancestor below the package root, and
|
|
170
58
|
// .headerSearchPath cannot escape the target path.
|
|
171
59
|
path: ".",
|
|
172
|
-
|
|
60
|
+
exclude: excludedPaths,
|
|
61
|
+
// Compile only native implementations; Dawn itself is already prebuilt.
|
|
173
62
|
sources: ["apple", "cpp/jsi", "cpp/rnwgpu"],
|
|
174
63
|
// SwiftPM requires a public headers directory inside the target and
|
|
175
64
|
// defaults to "include", which this package does not have.
|
package/README.md
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
# React Native WebGPU
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/wcandillon/react-native-webgpu/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/react-native-webgpu)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
<div align="center">
|
|
7
|
+
<img alt="React Native WebGPU Logo" src="https://firebasestorage.googleapis.com/v0/b/start-react-native.appspot.com/o/webgpu.png?alt=media&token=98a41d89-3915-468c-8c8d-9f41c8110f94" width="450">
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
WebGPU for React Native, powered by Dawn. See [Documentation](https://wcandillon.github.io/react-native-webgpu/).
|
|
11
|
+
|
|
12
|
+
## Platinum Sponsors
|
|
13
|
+
|
|
14
|
+
<div align="center">
|
|
15
|
+
<a href="https://expo.dev/" target="_blank" rel="sponsored">
|
|
16
|
+
<img width="80" height="80" alt="Expo" src="https://github.com/user-attachments/assets/33f7d710-2bcc-444e-b1dd-d1288c2a0bc4" />
|
|
17
|
+
</a>
|
|
18
|
+
</div>
|
|
6
19
|
|
|
7
20
|
## Getting Started
|
|
8
21
|
|
package/android/CMakeLists.txt
CHANGED
|
@@ -47,7 +47,6 @@ add_library(${PACKAGE_NAME} SHARED
|
|
|
47
47
|
../cpp/rnwgpu/api/GPUSharedFence.cpp
|
|
48
48
|
../cpp/rnwgpu/api/GPUSharedTextureMemory.cpp
|
|
49
49
|
../cpp/rnwgpu/api/GPUExternalTexture.cpp
|
|
50
|
-
../cpp/rnwgpu/api/GPUNativeBufferWrapper.cpp
|
|
51
50
|
../cpp/rnwgpu/api/NativeFrameImport.cpp
|
|
52
51
|
../cpp/rnwgpu/api/GPURenderBundleEncoder.cpp
|
|
53
52
|
../cpp/rnwgpu/api/GPURenderPassEncoder.cpp
|
|
@@ -57,6 +56,8 @@ add_library(${PACKAGE_NAME} SHARED
|
|
|
57
56
|
../cpp/rnwgpu/api/GPUComputePipeline.cpp
|
|
58
57
|
../cpp/rnwgpu/api/GPUCanvasContext.cpp
|
|
59
58
|
../cpp/rnwgpu/DawnBlobCache.cpp
|
|
59
|
+
../cpp/rnwgpu/NativeBufferViewRegistry.cpp
|
|
60
|
+
../cpp/rnwgpu/AnimationFrames.cpp
|
|
60
61
|
../cpp/rnwgpu/RNWebGPUManager.cpp
|
|
61
62
|
../cpp/rnwgpu/WebGPURuntime.cpp
|
|
62
63
|
../cpp/jsi/Promise.cpp
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <android/choreographer.h>
|
|
4
|
+
#include <android/log.h>
|
|
5
|
+
#include <android/looper.h>
|
|
6
|
+
#include <dlfcn.h>
|
|
7
|
+
#include <pthread.h>
|
|
8
|
+
|
|
9
|
+
#include <atomic>
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <future>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <thread>
|
|
14
|
+
|
|
15
|
+
#include "AnimationFrames.h"
|
|
16
|
+
|
|
17
|
+
namespace rnwgpu {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The display's frames on Android: an AChoreographer on a looper thread of its
|
|
21
|
+
* own, so that a busy main thread or JS thread never delays them. A request
|
|
22
|
+
* from any thread sets a flag and wakes the looper, which posts one frame
|
|
23
|
+
* callback; the frame time is the choreographer's, on CLOCK_MONOTONIC (the
|
|
24
|
+
* clock of std::chrono::steady_clock). The thread lives as long as the
|
|
25
|
+
* process.
|
|
26
|
+
*/
|
|
27
|
+
class AndroidAnimationFrameSource : public AnimationFrameSource {
|
|
28
|
+
public:
|
|
29
|
+
// The process's source, made on first use (its thread then runs for the
|
|
30
|
+
// life of the process); null when the thread gets no choreographer. A
|
|
31
|
+
// reload asks again and gets the same one.
|
|
32
|
+
static std::shared_ptr<AndroidAnimationFrameSource> shared() {
|
|
33
|
+
static std::shared_ptr<AndroidAnimationFrameSource> source = create();
|
|
34
|
+
return source;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void requestFrame() override {
|
|
38
|
+
_wanted.store(true, std::memory_order_release);
|
|
39
|
+
ALooper_wake(_looper);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private:
|
|
43
|
+
AndroidAnimationFrameSource() = default;
|
|
44
|
+
|
|
45
|
+
static std::shared_ptr<AndroidAnimationFrameSource> create() {
|
|
46
|
+
auto source = std::shared_ptr<AndroidAnimationFrameSource>(
|
|
47
|
+
new AndroidAnimationFrameSource());
|
|
48
|
+
// Shared with the thread, which may still be inside set_value() when
|
|
49
|
+
// get() returns here.
|
|
50
|
+
auto ready = std::make_shared<std::promise<ALooper *>>();
|
|
51
|
+
auto looperFuture = ready->get_future();
|
|
52
|
+
// The thread borrows the source, which shared() keeps for the life of the
|
|
53
|
+
// process (when the thread fails, it returns before this returns).
|
|
54
|
+
auto *raw = source.get();
|
|
55
|
+
std::thread([raw, ready]() { raw->run(*ready); }).detach();
|
|
56
|
+
source->_looper = looperFuture.get();
|
|
57
|
+
if (source->_looper == nullptr) {
|
|
58
|
+
return nullptr;
|
|
59
|
+
}
|
|
60
|
+
return source;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
using FrameCallback64 = void (*)(int64_t, void *);
|
|
64
|
+
using PostFrameCallback64 = void (*)(AChoreographer *, FrameCallback64,
|
|
65
|
+
void *);
|
|
66
|
+
|
|
67
|
+
void run(std::promise<ALooper *> &ready) {
|
|
68
|
+
pthread_setname_np(pthread_self(), "RNWebGPU Frames");
|
|
69
|
+
ALooper *looper = ALooper_prepare(0);
|
|
70
|
+
_choreographer = AChoreographer_getInstance();
|
|
71
|
+
if (looper == nullptr || _choreographer == nullptr) {
|
|
72
|
+
__android_log_print(ANDROID_LOG_WARN, "RNWebGPU",
|
|
73
|
+
"No choreographer on the animation frame thread: "
|
|
74
|
+
"requestAnimationFrame falls back to the runtime's.");
|
|
75
|
+
ready.set_value(nullptr);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
ALooper_acquire(looper);
|
|
79
|
+
// API 29; the library builds for API 26.
|
|
80
|
+
_postFrameCallback64 = reinterpret_cast<PostFrameCallback64>(
|
|
81
|
+
dlsym(RTLD_DEFAULT, "AChoreographer_postFrameCallback64"));
|
|
82
|
+
ready.set_value(looper);
|
|
83
|
+
for (;;) {
|
|
84
|
+
ALooper_pollOnce(-1, nullptr, nullptr, nullptr);
|
|
85
|
+
if (_wanted.exchange(false, std::memory_order_acq_rel) && !_posted) {
|
|
86
|
+
post();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Looper thread.
|
|
92
|
+
void post() {
|
|
93
|
+
_posted = true;
|
|
94
|
+
if (_postFrameCallback64 != nullptr) {
|
|
95
|
+
_postFrameCallback64(
|
|
96
|
+
_choreographer,
|
|
97
|
+
[](int64_t frameTimeNanos, void *data) {
|
|
98
|
+
static_cast<AndroidAnimationFrameSource *>(data)->onFrame(
|
|
99
|
+
frameTimeNanos);
|
|
100
|
+
},
|
|
101
|
+
this);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
#pragma clang diagnostic push
|
|
105
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
106
|
+
// The entry point of API 24: its frame time is a long, 32 bits on a
|
|
107
|
+
// 32-bit device, so the clock is read instead there.
|
|
108
|
+
AChoreographer_postFrameCallback(
|
|
109
|
+
_choreographer,
|
|
110
|
+
[](long frameTimeNanos, void *data) {
|
|
111
|
+
static_cast<AndroidAnimationFrameSource *>(data)->onFrame(
|
|
112
|
+
sizeof(long) >= sizeof(int64_t)
|
|
113
|
+
? static_cast<int64_t>(frameTimeNanos)
|
|
114
|
+
: AnimationFrameDispatcher::nowNanos());
|
|
115
|
+
},
|
|
116
|
+
this);
|
|
117
|
+
#pragma clang diagnostic pop
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Looper thread.
|
|
121
|
+
void onFrame(int64_t frameTimeNanos) {
|
|
122
|
+
_posted = false;
|
|
123
|
+
deliverFrame(frameTimeNanos);
|
|
124
|
+
// A request made while the frame was delivered (on this thread, or
|
|
125
|
+
// another) is in _wanted, and its wake is pending: the loop posts it.
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
ALooper *_looper = nullptr;
|
|
129
|
+
AChoreographer *_choreographer = nullptr;
|
|
130
|
+
PostFrameCallback64 _postFrameCallback64 = nullptr;
|
|
131
|
+
std::atomic<bool> _wanted{false};
|
|
132
|
+
// Looper thread only.
|
|
133
|
+
bool _posted = false;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
} // namespace rnwgpu
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <android/api-level.h>
|
|
3
4
|
#include <android/bitmap.h>
|
|
4
5
|
#include <android/data_space.h>
|
|
5
6
|
#include <android/hardware_buffer.h>
|
|
@@ -17,6 +18,7 @@
|
|
|
17
18
|
|
|
18
19
|
#include "webgpu/webgpu_cpp.h"
|
|
19
20
|
|
|
21
|
+
#include "AndroidAnimationFrameSource.h"
|
|
20
22
|
#include "AndroidColorSpace.h"
|
|
21
23
|
#include "AndroidVideoPlayer.h"
|
|
22
24
|
#include "PlatformContext.h"
|
|
@@ -424,46 +426,100 @@ public:
|
|
|
424
426
|
return handle;
|
|
425
427
|
}
|
|
426
428
|
|
|
429
|
+
// A buffer Dawn imports as a render target (GPU_COLOR_OUTPUT) and HWUI
|
|
430
|
+
// samples (GPU_SAMPLED_IMAGE, Bitmap.wrapHardwareBuffer). Below API 29,
|
|
431
|
+
// where a NativeBufferView reads the pixels back instead, it is CPU
|
|
432
|
+
// readable too; only there, as CPU usage can force a linear layout on some
|
|
433
|
+
// drivers.
|
|
434
|
+
VideoFrameHandle createNativeBuffer(uint32_t width, uint32_t height,
|
|
435
|
+
wgpu::TextureFormat format,
|
|
436
|
+
bool displayP3) override {
|
|
437
|
+
uint32_t ahbFormat;
|
|
438
|
+
switch (format) {
|
|
439
|
+
case wgpu::TextureFormat::RGBA8Unorm:
|
|
440
|
+
ahbFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
|
|
441
|
+
break;
|
|
442
|
+
case wgpu::TextureFormat::RGBA16Float:
|
|
443
|
+
ahbFormat = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
|
|
444
|
+
break;
|
|
445
|
+
default:
|
|
446
|
+
throw std::runtime_error(
|
|
447
|
+
"createNativeBuffer: unsupported format on Android (expected "
|
|
448
|
+
"'rgba8unorm' or 'rgba16float')");
|
|
449
|
+
}
|
|
450
|
+
AHardwareBuffer_Desc desc = {};
|
|
451
|
+
desc.width = width;
|
|
452
|
+
desc.height = height;
|
|
453
|
+
desc.layers = 1;
|
|
454
|
+
desc.format = ahbFormat;
|
|
455
|
+
desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
|
|
456
|
+
AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
|
|
457
|
+
if (android_get_device_api_level() < 29) {
|
|
458
|
+
desc.usage |= AHARDWAREBUFFER_USAGE_CPU_READ_RARELY;
|
|
459
|
+
}
|
|
460
|
+
AHardwareBuffer *buffer = nullptr;
|
|
461
|
+
int err = AHardwareBuffer_allocate(&desc, &buffer);
|
|
462
|
+
if (err != 0 || !buffer) {
|
|
463
|
+
throw std::runtime_error(
|
|
464
|
+
"createNativeBuffer: AHardwareBuffer_allocate failed (" +
|
|
465
|
+
std::to_string(err) + ")");
|
|
466
|
+
}
|
|
467
|
+
VideoFrameHandle handle;
|
|
468
|
+
handle.handle = static_cast<void *>(buffer);
|
|
469
|
+
handle.width = width;
|
|
470
|
+
handle.height = height;
|
|
471
|
+
handle.colorSpace.primaries = displayP3
|
|
472
|
+
? wgpu::ColorSpacePrimariesDawn::DisplayP3
|
|
473
|
+
: wgpu::ColorSpacePrimariesDawn::SRGB;
|
|
474
|
+
handle.deleter = [buffer]() { AHardwareBuffer_release(buffer); };
|
|
475
|
+
return handle;
|
|
476
|
+
}
|
|
477
|
+
|
|
427
478
|
// The decoder writes its native YUV layout whatever format is requested:
|
|
428
479
|
// the frames are sampled through importExternalTexture (see
|
|
429
480
|
// WebGPUVideoPlayer.java).
|
|
430
481
|
std::unique_ptr<IVideoPlayer>
|
|
431
|
-
|
|
432
|
-
|
|
482
|
+
createTestVideoPlayer(const std::string &path,
|
|
483
|
+
VideoPixelFormat /*format*/) override {
|
|
433
484
|
if (!_module) {
|
|
434
|
-
throw std::runtime_error(
|
|
485
|
+
throw std::runtime_error(
|
|
486
|
+
"createTestVideoPlayer: the WebGPU module is gone");
|
|
435
487
|
}
|
|
436
488
|
jni::Environment::ensureCurrentThreadIsAttached();
|
|
437
489
|
JNIEnv *env = facebook::jni::Environment::current();
|
|
438
490
|
if (!env) {
|
|
439
491
|
throw std::runtime_error(
|
|
440
|
-
"
|
|
492
|
+
"createTestVideoPlayer: couldn't get the JNI environment");
|
|
441
493
|
}
|
|
442
494
|
jclass moduleClass = env->GetObjectClass(_module);
|
|
443
495
|
jmethodID method =
|
|
444
|
-
env->GetMethodID(moduleClass, "
|
|
496
|
+
env->GetMethodID(moduleClass, "createTestVideoPlayer",
|
|
445
497
|
"(Ljava/lang/String;)Lcom/webgpu/WebGPUVideoPlayer;");
|
|
446
498
|
env->DeleteLocalRef(moduleClass);
|
|
447
499
|
if (!method) {
|
|
448
500
|
env->ExceptionClear();
|
|
449
|
-
throw std::runtime_error(
|
|
450
|
-
|
|
501
|
+
throw std::runtime_error("createTestVideoPlayer: "
|
|
502
|
+
"WebGPUModule.createTestVideoPlayer not found");
|
|
451
503
|
}
|
|
452
504
|
jstring jPath = env->NewStringUTF(path.c_str());
|
|
453
505
|
jobject player = env->CallObjectMethod(_module, method, jPath);
|
|
454
506
|
env->DeleteLocalRef(jPath);
|
|
455
507
|
if (env->ExceptionCheck()) {
|
|
456
|
-
throw std::runtime_error("
|
|
508
|
+
throw std::runtime_error("createTestVideoPlayer: " +
|
|
457
509
|
describeAndClearJavaException(env));
|
|
458
510
|
}
|
|
459
511
|
if (player == nullptr) {
|
|
460
|
-
throw std::runtime_error("
|
|
512
|
+
throw std::runtime_error("createTestVideoPlayer: no player was created");
|
|
461
513
|
}
|
|
462
514
|
auto result = std::make_unique<AndroidVideoPlayer>(env, player);
|
|
463
515
|
env->DeleteLocalRef(player);
|
|
464
516
|
return result;
|
|
465
517
|
}
|
|
466
518
|
|
|
519
|
+
std::shared_ptr<AnimationFrameSource> makeAnimationFrameSource() override {
|
|
520
|
+
return AndroidAnimationFrameSource::shared();
|
|
521
|
+
}
|
|
522
|
+
|
|
467
523
|
std::string writeTestVideoFile() override {
|
|
468
524
|
// TODO: implement using MediaCodec (H.264 encoder) or MediaMuxer.
|
|
469
525
|
throw std::runtime_error(
|