react-native-webgpu 0.23.0 → 0.25.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/android/CMakeLists.txt +1 -0
- package/android/cpp/AndroidPlatformContext.h +10 -9
- package/android/cpp/cpp-adapter.cpp +19 -96
- package/android/src/main/java/com/webgpu/BackingViewKind.java +5 -22
- package/android/src/main/java/com/webgpu/WebGPUAPI.java +0 -2
- package/android/src/main/java/com/webgpu/WebGPUModule.java +34 -3
- package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +1 -1
- package/android/src/main/java/com/webgpu/WebGPUView.java +17 -34
- package/apple/ApplePlatformContext.h +2 -1
- package/apple/ApplePlatformContext.mm +2 -2
- package/apple/WebGPUModule.mm +22 -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/GpuPurge.cpp +86 -0
- package/cpp/rnwgpu/GpuPurge.h +66 -0
- package/cpp/rnwgpu/PlatformContext.h +1 -1
- package/cpp/rnwgpu/SurfaceRegistry.h +2 -612
- package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +59 -32
- package/cpp/rnwgpu/api/GPUDevice.h +49 -4
- package/cpp/rnwgpu/api/RNWebGPU.h +11 -4
- package/lib/commonjs/Canvas.js +8 -26
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/main/index.js +12 -0
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/commonjs/main/index.web.js +11 -0
- package/lib/commonjs/main/index.web.js.map +1 -1
- package/lib/commonjs/mock.js +4 -1
- package/lib/commonjs/mock.js.map +1 -1
- package/lib/commonjs/purgeGpuResources.js +29 -0
- package/lib/commonjs/purgeGpuResources.js.map +1 -0
- package/lib/commonjs/video.js +8 -4
- package/lib/commonjs/video.js.map +1 -1
- package/lib/module/Canvas.js +8 -26
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/main/index.js +1 -0
- package/lib/module/main/index.js.map +1 -1
- package/lib/module/main/index.web.js +1 -0
- package/lib/module/main/index.web.js.map +1 -1
- package/lib/module/mock.js +1 -0
- package/lib/module/mock.js.map +1 -1
- package/lib/module/purgeGpuResources.js +22 -0
- package/lib/module/purgeGpuResources.js.map +1 -0
- package/lib/module/video.js +6 -2
- package/lib/module/video.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/mock.d.ts +1 -0
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/purgeGpuResources.d.ts +18 -0
- package/lib/typescript/lib/commonjs/purgeGpuResources.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/video.d.ts +6 -2
- package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/main/index.d.ts +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +1 -0
- package/lib/typescript/lib/module/mock.d.ts +1 -0
- package/lib/typescript/lib/module/mock.d.ts.map +1 -1
- package/lib/typescript/lib/module/purgeGpuResources.d.ts +2 -0
- package/lib/typescript/lib/module/purgeGpuResources.d.ts.map +1 -0
- package/lib/typescript/lib/module/video.d.ts +1 -1
- 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/Canvas.d.ts +2 -12
- 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 +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -2
- 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/main/index.web.d.ts +1 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -1
- package/lib/typescript/src/mock.d.ts +2 -1
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/lib/typescript/src/purgeGpuResources.d.ts +17 -0
- package/lib/typescript/src/purgeGpuResources.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +1 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/video.d.ts +7 -3
- package/lib/typescript/src/video.d.ts.map +1 -1
- package/package.json +10 -5
- package/react-native-webgpu.podspec +46 -78
- 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/Canvas.tsx +12 -50
- package/src/WebGPUViewNativeComponent.ts +1 -1
- package/src/WebGPUViewNativeComponent.web.ts +1 -1
- package/src/index.tsx +5 -4
- package/src/main/index.tsx +1 -0
- package/src/main/index.web.tsx +1 -0
- package/src/mock.ts +2 -1
- package/src/purgeGpuResources.ts +21 -0
- package/src/types.ts +1 -1
- package/src/video.ts +12 -5
- package/android/src/main/java/com/webgpu/WebGPUHardwareBufferView.java +0 -278
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# CocoaPods and RN SwiftPM share this Node-free preparation phase.
|
|
4
|
+
# SDK archives contain static libraries; headers already ship in react-native-webgpu.
|
|
5
|
+
# Nothing compiles here: resolve libraries, update XCFramework slices, then copy
|
|
6
|
+
# the selected SDK's archives into Xcode's library search path.
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# /bin/bash prepare-apple-binaries.sh --config
|
|
10
|
+
# /bin/bash prepare-apple-binaries.sh --config --spm-package <generated-package>
|
|
11
|
+
# /bin/bash prepare-apple-binaries.sh --output <build-products> --assembly-root <build-intermediates>
|
|
12
|
+
#
|
|
13
|
+
# Xcode environment:
|
|
14
|
+
# PLATFORM_NAME, EFFECTIVE_PLATFORM_NAME, SDK_VARIANT select the SDK/variant.
|
|
15
|
+
# ARCHS, EXCLUDED_ARCHS, ONLY_ACTIVE_ARCH, CURRENT_ARCH, NATIVE_ARCH_ACTUAL
|
|
16
|
+
# select required architectures; metadata may contain additional ones.
|
|
17
|
+
# IPHONEOS_DEPLOYMENT_TARGET, TVOS_DEPLOYMENT_TARGET, MACOSX_DEPLOYMENT_TARGET
|
|
18
|
+
# must meet the selected archive's deployment floor.
|
|
19
|
+
# BUILT_PRODUCTS_DIR and OBJROOT supply default output/assembly directories.
|
|
20
|
+
# ENABLE_USER_SCRIPT_SANDBOXING must be NO on the target running this phase.
|
|
21
|
+
#
|
|
22
|
+
# Overrides:
|
|
23
|
+
# RNSKIA_CACHE_DIR changes the shared download cache (default:
|
|
24
|
+
# ~/Library/Caches/react-native-skia). Version/checksum subdirectories remain.
|
|
25
|
+
# REACT_NATIVE_SKIA_BINARIES_URL changes the release base URL; the installed
|
|
26
|
+
# binaries.json still pins the tag and checksums, including for mirrors.
|
|
27
|
+
# libs/apple, when present, is a read-only local Dawn override.
|
|
28
|
+
set -Eeuo pipefail
|
|
29
|
+
|
|
30
|
+
# MARK: Package paths and shared constants
|
|
31
|
+
|
|
32
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
33
|
+
PACKAGE_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
34
|
+
source "$SCRIPT_DIR/apple-binaries-utils.sh"
|
|
35
|
+
|
|
36
|
+
# MARK: Failure reporting and cleanup
|
|
37
|
+
|
|
38
|
+
# Report the actual command failure before Xcode's generic PhaseScriptExecution error.
|
|
39
|
+
report_failure() {
|
|
40
|
+
local status="$1" line="$2" command="$3"
|
|
41
|
+
if [[ ! -f "$WORK_DIR/failed" ]]; then
|
|
42
|
+
printf 'error: [react-native-webgpu] Preparation failed at line %s (exit %s): %s. Check the diagnostic above, permissions, and free disk space.\n' "$line" "$status" "$command" >&2
|
|
43
|
+
: > "$WORK_DIR/failed"
|
|
44
|
+
fi
|
|
45
|
+
exit "$status"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Release only locks still owned by this process, never a later cache writer.
|
|
49
|
+
cleanup() {
|
|
50
|
+
# Missing pid files are expected for locks released before EXIT. Bash 3.2
|
|
51
|
+
# otherwise inherits ERR into their reads and reports a successful run as failed.
|
|
52
|
+
trap - ERR
|
|
53
|
+
local directory owner entry
|
|
54
|
+
for directory in ${LOCKS[@]+"${LOCKS[@]}"}; do
|
|
55
|
+
owner=$(cat "$directory/pid" 2>/dev/null) || owner=''
|
|
56
|
+
if [[ "$owner" == "$$" ]]; then rm -rf "$directory"; fi
|
|
57
|
+
done
|
|
58
|
+
# Interrupted downloads/copies are temporary. Keep verified cache entries,
|
|
59
|
+
# local overrides, and complete XCFramework slices from earlier builds.
|
|
60
|
+
for entry in ${TEMP_PATHS[@]+"${TEMP_PATHS[@]}"}; do rm -rf "$entry"; done
|
|
61
|
+
rm -rf "$WORK_DIR"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# MARK: Xcode target selection
|
|
65
|
+
|
|
66
|
+
# Sets SDK and REQUESTED_ARCHS from Xcode's expanded architecture settings.
|
|
67
|
+
# Catalyst uses the macOS SDK, but must select iOS/macabi libraries. Exclusions
|
|
68
|
+
# apply before ONLY_ACTIVE_ARCH reduces the request to the current architecture.
|
|
69
|
+
detect_target() {
|
|
70
|
+
SDK="${PLATFORM_NAME:-}"
|
|
71
|
+
if [[ "$SDK" == macosx ]]; then
|
|
72
|
+
SDK=macos
|
|
73
|
+
if [[ "${EFFECTIVE_PLATFORM_NAME:-}" == -maccatalyst || "${SDK_VARIANT:-}" == maccatalyst || "${SDK_VARIANT:-}" == iosmac ]]; then
|
|
74
|
+
SDK=maccatalyst
|
|
75
|
+
fi
|
|
76
|
+
fi
|
|
77
|
+
sdk_descriptor "$SDK" >/dev/null ||
|
|
78
|
+
fail "Unsupported Apple platform '${PLATFORM_NAME:-unset}' (EFFECTIVE_PLATFORM_NAME='${EFFECTIVE_PLATFORM_NAME:-}'). Supported SDKs: ${RNWGPU_SDKS[*]}. Build an Apple target in Xcode."
|
|
79
|
+
local arch excluded skip seen='' active="${CURRENT_ARCH:-}"
|
|
80
|
+
if [[ -z "$active" || "$active" == undefined_arch ]]; then active="${NATIVE_ARCH_ACTUAL:-}"; fi
|
|
81
|
+
REQUESTED_ARCHS=()
|
|
82
|
+
for arch in ${ARCHS:-}; do
|
|
83
|
+
[[ "$arch" =~ ^[A-Za-z0-9_]+$ ]] || fail "Invalid architecture in ARCHS: $arch"
|
|
84
|
+
skip=false
|
|
85
|
+
for excluded in ${EXCLUDED_ARCHS:-}; do
|
|
86
|
+
if [[ "$arch" == "$excluded" ]]; then skip=true; fi
|
|
87
|
+
done
|
|
88
|
+
if [[ "$skip" == false && " $seen " != *" $arch "* ]]; then
|
|
89
|
+
REQUESTED_ARCHS+=("$arch")
|
|
90
|
+
seen="$seen $arch"
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
((${#REQUESTED_ARCHS[@]} > 0)) || fail "Cannot determine Apple architectures from ARCHS='${ARCHS:-}'. Run preparation from an Xcode target."
|
|
94
|
+
if [[ "${ONLY_ACTIVE_ARCH:-NO}" == YES && -n "$active" && " $seen " == *" $active "* ]]; then
|
|
95
|
+
REQUESTED_ARCHS=("$active")
|
|
96
|
+
fi
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# MARK: CocoaPods and SwiftPM configuration
|
|
100
|
+
|
|
101
|
+
# Plain JSON is consumed by the podspec and the mandatory RN JavaScript adapter.
|
|
102
|
+
# Names are prefixed at staging so they cannot collide with another dependency's
|
|
103
|
+
# libwebgpu_dawn.a in the shared build-products directory.
|
|
104
|
+
print_configuration() {
|
|
105
|
+
local name="${RNWGPU_DAWN_LIBRARY#lib}"
|
|
106
|
+
printf '{"linkNames":["rnwgpu_%s"]}\n' "${name%.a}"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Keep generated files stable across repeated SwiftPM autolinking synchronizations.
|
|
110
|
+
write_if_changed() {
|
|
111
|
+
local source="$1" destination="$2"
|
|
112
|
+
if ! cmp -s "$source" "$destination"; then
|
|
113
|
+
mkdir -p "$(dirname "$destination")"
|
|
114
|
+
cp "$source" "$destination"
|
|
115
|
+
fi
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# write_spm_package DIRECTORY: generate a link-settings target, not binaryTargets.
|
|
119
|
+
# SwiftPM resolves this small local package before Xcode knows the selected SDK;
|
|
120
|
+
# the build phase provides its libraries later. Headers stay in react-native-webgpu.
|
|
121
|
+
# Only the RN hook is JavaScript. Package generation and the native phase use shell.
|
|
122
|
+
write_spm_package() {
|
|
123
|
+
local directory="$1" library name
|
|
124
|
+
printf '// Link settings only; Dawn headers ship in react-native-webgpu.\n' > "$WORK_DIR/ReactNativeWebGPUBinaries.h"
|
|
125
|
+
printf '// Propagates static binary link settings to the app.\n' > "$WORK_DIR/link.c"
|
|
126
|
+
cat > "$WORK_DIR/Package.swift" <<'SWIFT'
|
|
127
|
+
// swift-tools-version: 6.0
|
|
128
|
+
// Generated by react-native-webgpu; SDK binaries are prepared by its Xcode phase.
|
|
129
|
+
import PackageDescription
|
|
130
|
+
|
|
131
|
+
let package = Package(
|
|
132
|
+
name: "ReactNativeWebGPUBinaries",
|
|
133
|
+
platforms: [.iOS(.v15), .tvOS(.v15), .macOS(.v14)],
|
|
134
|
+
products: [.library(name: "ReactNativeWebGPUBinaries", targets: ["ReactNativeWebGPUBinaries"])],
|
|
135
|
+
targets: [
|
|
136
|
+
.target(
|
|
137
|
+
name: "ReactNativeWebGPUBinaries",
|
|
138
|
+
path: ".",
|
|
139
|
+
sources: ["link.c"],
|
|
140
|
+
publicHeadersPath: "include",
|
|
141
|
+
linkerSettings: [
|
|
142
|
+
SWIFT
|
|
143
|
+
for library in "${ALL_LIBRARIES[@]}"; do
|
|
144
|
+
name="${library#lib}"
|
|
145
|
+
printf ' .linkedLibrary("rnwgpu_%s"),\n' "${name%.a}" >> "$WORK_DIR/Package.swift"
|
|
146
|
+
done
|
|
147
|
+
cat >> "$WORK_DIR/Package.swift" <<'SWIFT'
|
|
148
|
+
]
|
|
149
|
+
)
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
SWIFT
|
|
153
|
+
write_if_changed "$WORK_DIR/Package.swift" "$directory/Package.swift"
|
|
154
|
+
write_if_changed "$WORK_DIR/link.c" "$directory/link.c"
|
|
155
|
+
write_if_changed "$WORK_DIR/ReactNativeWebGPUBinaries.h" "$directory/include/ReactNativeWebGPUBinaries.h"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
# MARK: Incremental XCFramework assembly
|
|
159
|
+
|
|
160
|
+
# write_xcframework_plist CONTAINER LIBRARY METADATA_ROOT: describe only SDKs
|
|
161
|
+
# already prepared in this build folder. A later SDK appends its own slice.
|
|
162
|
+
# All values written to XML are fixed library/platform names or validated archs.
|
|
163
|
+
# The descriptors come from saved SDK metadata, rather than hardcoded slice names.
|
|
164
|
+
write_xcframework_plist() {
|
|
165
|
+
local container="$1" library="$2" metadata_root="$3" sdk file identifier archs arch
|
|
166
|
+
local ignored platform variant deployment
|
|
167
|
+
{
|
|
168
|
+
cat <<'PLIST'
|
|
169
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
170
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
171
|
+
<plist version="1.0"><dict>
|
|
172
|
+
<key>CFBundlePackageType</key><string>XFWK</string>
|
|
173
|
+
<key>XCFrameworkFormatVersion</key><string>1.0</string>
|
|
174
|
+
<key>AvailableLibraries</key><array>
|
|
175
|
+
PLIST
|
|
176
|
+
for sdk in "${RNWGPU_SDKS[@]}"; do
|
|
177
|
+
file="$metadata_root/$sdk.json"
|
|
178
|
+
[[ -f "$file" ]] || continue
|
|
179
|
+
IFS='|' read -r ignored platform variant deployment <<< "$(sdk_descriptor "$sdk")"
|
|
180
|
+
archs=$(json_strings "$file" architectures)
|
|
181
|
+
identifier="$platform-$(printf '%s\n' "$archs" | LC_ALL=C sort | paste -sd _ -)${variant:+-$variant}"
|
|
182
|
+
printf '<dict><key>LibraryIdentifier</key><string>%s</string>\n' "$identifier"
|
|
183
|
+
printf '<key>LibraryPath</key><string>%s</string>\n' "$library"
|
|
184
|
+
printf '<key>SupportedPlatform</key><string>%s</string>\n' "$platform"
|
|
185
|
+
if [[ -n "$variant" ]]; then printf '<key>SupportedPlatformVariant</key><string>%s</string>\n' "$variant"; fi
|
|
186
|
+
printf '<key>SupportedArchitectures</key><array>\n'
|
|
187
|
+
while IFS= read -r arch; do printf '<string>%s</string>\n' "$arch"; done <<< "$archs"
|
|
188
|
+
printf '</array></dict>\n'
|
|
189
|
+
done
|
|
190
|
+
printf '</array></dict></plist>\n'
|
|
191
|
+
} > "$container/Info.plist"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
# Clone on APFS where possible; fall back to an ordinary copy on other volumes.
|
|
195
|
+
copy_library() {
|
|
196
|
+
cp -c "$1" "$2" 2>/dev/null || cp -p "$1" "$2"
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
# Update one SDK atomically and retain other SDKs already prepared in this build.
|
|
200
|
+
# Returns the module's CONTAINER_ROOT for the linker staging step.
|
|
201
|
+
# The caller holds the assembly lock across both assembly and linker staging.
|
|
202
|
+
assemble_module() {
|
|
203
|
+
local root="$CONTAINERS/$MODULE" library existing=true temporary previous='' old_archs platform variant ignored deployment
|
|
204
|
+
local signature_file="$CONTAINERS/$MODULE/.slices/$SDK.signature"
|
|
205
|
+
CONTAINER_ROOT="$root"
|
|
206
|
+
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
207
|
+
if [[ ! -f "$root/${library%.a}.xcframework/$META_IDENTIFIER/$library" || ! -f "$root/${library%.a}.xcframework/Info.plist" ]]; then existing=false; fi
|
|
208
|
+
done
|
|
209
|
+
if [[ -f "$signature_file" && "$(cat "$signature_file")" == "$SOURCE_SIGNATURE" && "$existing" == true ]]; then return; fi
|
|
210
|
+
temporary="$root.$$.assemble"
|
|
211
|
+
TEMP_PATHS+=("$temporary")
|
|
212
|
+
mkdir -p "$temporary"
|
|
213
|
+
if [[ -d "$root" ]]; then ditto "$root" "$temporary"; fi
|
|
214
|
+
if [[ -f "$temporary/.slices/$SDK.json" ]]; then
|
|
215
|
+
old_archs=$(json_strings "$temporary/.slices/$SDK.json" architectures)
|
|
216
|
+
IFS='|' read -r ignored platform variant deployment <<< "$(sdk_descriptor "$SDK")"
|
|
217
|
+
previous="$platform-$(printf '%s\n' "$old_archs" | LC_ALL=C sort | paste -sd _ -)${variant:+-$variant}"
|
|
218
|
+
fi
|
|
219
|
+
mkdir -p "$temporary/.slices"
|
|
220
|
+
cp "$SOURCE_DIRECTORY/metadata.json" "$temporary/.slices/$SDK.json"
|
|
221
|
+
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
222
|
+
local container="$temporary/${library%.a}.xcframework"
|
|
223
|
+
if [[ -n "$previous" && "$previous" != "$META_IDENTIFIER" ]]; then rm -rf "$container/$previous"; fi
|
|
224
|
+
mkdir -p "$container/$META_IDENTIFIER"
|
|
225
|
+
copy_library "$SOURCE_DIRECTORY/$library" "$container/$META_IDENTIFIER/$library"
|
|
226
|
+
write_xcframework_plist "$container" "$library" "$temporary/.slices"
|
|
227
|
+
done
|
|
228
|
+
printf '%s\n' "$SOURCE_SIGNATURE" > "$temporary/.slices/$SDK.signature"
|
|
229
|
+
replace_directory "$temporary" "$root"
|
|
230
|
+
note "Prepared $SDK XCFramework slices ($(printf '%s' "$META_ARCHS" | tr '\n' ' '))"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# MARK: Linker inputs
|
|
234
|
+
|
|
235
|
+
# stage_module: expose the selected slice as librnwgpu_<name>.a in OUTPUT.
|
|
236
|
+
# Static libraries link into the app; XCFramework containers are build inputs,
|
|
237
|
+
# rather than dynamic frameworks copied into the app's Frameworks directory.
|
|
238
|
+
# Build-product stamps include SDK/version/source identity, avoiding equal-size
|
|
239
|
+
# archives from another platform and unnecessary copies on incremental builds.
|
|
240
|
+
stage_module() {
|
|
241
|
+
local library destination temporary stamp="$OUTPUT/.rnwgpu-$MODULE.signature"
|
|
242
|
+
local signature="$SDK:$VERSION:$SOURCE_SIGNATURE" name
|
|
243
|
+
mkdir -p "$OUTPUT"
|
|
244
|
+
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
245
|
+
name="${library#lib}"
|
|
246
|
+
destination="$OUTPUT/librnwgpu_$name"
|
|
247
|
+
if [[ -f "$stamp" && "$(cat "$stamp")" == "$signature" && -f "$destination" ]]; then continue; fi
|
|
248
|
+
temporary="$destination.$$.tmp"
|
|
249
|
+
TEMP_PATHS+=("$temporary")
|
|
250
|
+
copy_library "$CONTAINER_ROOT/${library%.a}.xcframework/$META_IDENTIFIER/$library" "$temporary"
|
|
251
|
+
mv "$temporary" "$destination"
|
|
252
|
+
done
|
|
253
|
+
printf '%s\n' "$signature" > "$stamp"
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
# MARK: Entry point
|
|
257
|
+
|
|
258
|
+
# Configuration mode performs no downloads; native mode requires Xcode settings.
|
|
259
|
+
# Global state is shared with helpers; initialize cleanup ownership before any
|
|
260
|
+
# operation that may fail. CLI arguments override the Xcode directory defaults.
|
|
261
|
+
main() {
|
|
262
|
+
WORK_DIR=$(mktemp -d "${TMPDIR:-/tmp}/rnwgpu-apple.XXXXXX")
|
|
263
|
+
LOCKS=()
|
|
264
|
+
TEMP_PATHS=()
|
|
265
|
+
trap 'report_failure "$?" "$LINENO" "$BASH_COMMAND"' ERR
|
|
266
|
+
trap cleanup EXIT
|
|
267
|
+
trap 'exit 130' INT
|
|
268
|
+
trap 'exit 143' TERM
|
|
269
|
+
local config=false spm_package='' manifest_hash
|
|
270
|
+
OUTPUT="${BUILT_PRODUCTS_DIR:-}"
|
|
271
|
+
ASSEMBLY_ROOT="${OBJROOT:+$OBJROOT/ReactNativeWebGPUBinaries}"
|
|
272
|
+
while (($# > 0)); do
|
|
273
|
+
case "$1" in
|
|
274
|
+
--config) config=true; shift ;;
|
|
275
|
+
--output|--assembly-root|--spm-package)
|
|
276
|
+
(($# > 1)) && [[ -n "$2" ]] || fail "Missing value for $1."
|
|
277
|
+
case "$1" in
|
|
278
|
+
--output) OUTPUT="$2" ;;
|
|
279
|
+
--assembly-root) ASSEMBLY_ROOT="$2" ;;
|
|
280
|
+
--spm-package) spm_package="$2" ;;
|
|
281
|
+
esac
|
|
282
|
+
shift 2 ;;
|
|
283
|
+
*) fail "Unknown preparation option '$1'." ;;
|
|
284
|
+
esac
|
|
285
|
+
done
|
|
286
|
+
if [[ "$config" != true ]]; then detect_target; fi
|
|
287
|
+
load_release
|
|
288
|
+
ALL_LIBRARIES=("$RNWGPU_DAWN_LIBRARY")
|
|
289
|
+
if [[ -n "$spm_package" ]]; then write_spm_package "$spm_package"; fi
|
|
290
|
+
if [[ "$config" == true ]]; then print_configuration; return; fi
|
|
291
|
+
[[ "$OUTPUT" == /* && "$ASSEMBLY_ROOT" == /* ]] || fail 'Missing absolute binary output/build directory. Run preparation from the installed Xcode phase.'
|
|
292
|
+
[[ "${ENABLE_USER_SCRIPT_SANDBOXING:-NO}" != YES ]] || fail 'Binary preparation needs release-cache/build-product access. Set User Script Sandboxing to No on this app target.'
|
|
293
|
+
[[ -f "$PACKAGE_ROOT/cpp/dawn/include/webgpu/webgpu.h" ]] ||
|
|
294
|
+
fail 'Dawn headers are missing from react-native-webgpu. Reinstall it; contributors must run yarn copy-dawn-headers.'
|
|
295
|
+
# Isolate assembly by manifest while retaining other SDKs of the same release.
|
|
296
|
+
manifest_hash=$(hash_file "$MANIFEST")
|
|
297
|
+
CONTAINERS="$ASSEMBLY_ROOT/$VERSION-${manifest_hash:0:16}"
|
|
298
|
+
MODULE=dawn
|
|
299
|
+
MODULE_LIBRARIES=("$RNWGPU_DAWN_LIBRARY")
|
|
300
|
+
resolve_libraries "$SDK"
|
|
301
|
+
acquire_lock "$ASSEMBLY_ROOT.lock"
|
|
302
|
+
assemble_module
|
|
303
|
+
stage_module
|
|
304
|
+
release_lock "$ASSEMBLY_ROOT.lock"
|
|
305
|
+
note "Ready: $SDK (${REQUESTED_ARCHS[*]}); Dawn own"
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
# Sourcing exposes helpers for verification; direct execution prepares binaries.
|
|
309
|
+
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then main "$@"; fi
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// MARK: Autolinking helpers
|
|
4
|
+
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { execFileSync } = require("child_process");
|
|
8
|
+
|
|
9
|
+
/** Quote a generated path as one shell argument, including spaces/apostrophes. */
|
|
10
|
+
const shellQuote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RN requires a JavaScript autolinking entry point. It delegates configuration
|
|
14
|
+
* and package generation to Bash; the installed Xcode phase never invokes Node.
|
|
15
|
+
* RN invokes this hook again when it regenerates the autolinked package graph.
|
|
16
|
+
* Configuration reads the installed release pin; binary downloads wait for Xcode
|
|
17
|
+
* to supply the SDK and architecture build settings.
|
|
18
|
+
*/
|
|
19
|
+
module.exports = function webgpuSwiftPM(context) {
|
|
20
|
+
const packageRoot = path.join(__dirname, "..");
|
|
21
|
+
const scriptPath = path.join(__dirname, "prepare-apple-binaries.sh");
|
|
22
|
+
|
|
23
|
+
// MARK: RN hook compatibility
|
|
24
|
+
|
|
25
|
+
// Check the installed hook's capability, rather than assuming a semver string
|
|
26
|
+
// describes it: local RN checkouts and prereleases may carry different tooling.
|
|
27
|
+
// Without scriptPhases, libraries would be linked before they were prepared.
|
|
28
|
+
const contract = path.join(
|
|
29
|
+
context.reactNativeRoot,
|
|
30
|
+
"scripts/spm/autolinking-plugins.js"
|
|
31
|
+
);
|
|
32
|
+
if (
|
|
33
|
+
!fs.existsSync(contract) ||
|
|
34
|
+
!fs.readFileSync(contract, "utf8").includes("scriptPhases")
|
|
35
|
+
) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"react-native-webgpu: automatic SwiftPM binary preparation requires React Native 0.87.1 or newer. Upgrade React Native or use CocoaPods."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// MARK: Generated Dawn link settings
|
|
42
|
+
|
|
43
|
+
// WebGPU always supplies Dawn. Skia's integration opts out of its own copy
|
|
44
|
+
// when this native module is linked; both packages validate the same pin.
|
|
45
|
+
// Configuration writes a local link-settings package, without downloading SDKs.
|
|
46
|
+
execFileSync(
|
|
47
|
+
"/bin/bash",
|
|
48
|
+
[
|
|
49
|
+
scriptPath,
|
|
50
|
+
"--config",
|
|
51
|
+
"--spm-package",
|
|
52
|
+
path.join(context.outputDir, "ReactNativeWebGPUBinaries"),
|
|
53
|
+
],
|
|
54
|
+
{ encoding: "utf8" }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// MARK: Xcode preparation phase
|
|
58
|
+
|
|
59
|
+
// RN already resolved the package during autolinking. A project-relative path
|
|
60
|
+
// handles hoisting/pnpm and relocation without Node lookups inside Xcode.
|
|
61
|
+
// Resolve symlinks on both sides before computing the path so workspace package
|
|
62
|
+
// aliases do not produce a different path after Xcode expands SRCROOT.
|
|
63
|
+
const relativeScript = shellQuote(
|
|
64
|
+
path.relative(fs.realpathSync(context.appRoot), fs.realpathSync(scriptPath))
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Xcode expands SDK/architecture variables when this phase runs. Cache and
|
|
68
|
+
// assembly logic stays in the shared shell scripts used by CocoaPods too.
|
|
69
|
+
// exec preserves their exit status and error diagnostics in Xcode's build log.
|
|
70
|
+
const script = `set -eo pipefail
|
|
71
|
+
# Check before reading package files, which script sandboxing may already deny.
|
|
72
|
+
if [ "\${ENABLE_USER_SCRIPT_SANDBOXING:-NO}" = YES ]; then
|
|
73
|
+
echo "error: [react-native-webgpu] Set User Script Sandboxing to No on this app target; preparation needs release-cache and build-product access." >&2
|
|
74
|
+
exit 1
|
|
75
|
+
fi
|
|
76
|
+
PREPARE_SCRIPT="$SRCROOT"/${relativeScript}
|
|
77
|
+
if [ ! -f "$PREPARE_SCRIPT" ]; then
|
|
78
|
+
echo "error: [react-native-webgpu] Binary preparation script is missing. Reinstall dependencies and rerun react-native spm update." >&2
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
exec /bin/bash "$PREPARE_SCRIPT" --output "$BUILT_PRODUCTS_DIR" --assembly-root "$OBJROOT/ReactNativeWebGPUBinaries"
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
// MARK: Native package registration
|
|
85
|
+
|
|
86
|
+
// RN delegates the plugin host's native contribution entirely to this hook.
|
|
87
|
+
// Recreate its usual libs/<name> alias so Package.swift's relative React and
|
|
88
|
+
// generated-code dependencies resolve within this app's autolinking tree.
|
|
89
|
+
const packageAlias = path.join(
|
|
90
|
+
context.outputDir,
|
|
91
|
+
"libs",
|
|
92
|
+
"ReactNativeWebGPU"
|
|
93
|
+
);
|
|
94
|
+
fs.mkdirSync(path.dirname(packageAlias), { recursive: true });
|
|
95
|
+
if (!fs.existsSync(packageAlias)) {
|
|
96
|
+
fs.symlinkSync(packageRoot, packageAlias, "dir");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// MARK: RN phase reconciliation and synchronization
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
packageDependencies: [{ name: "ReactNativeWebGPU", path: packageAlias }],
|
|
103
|
+
productDependencies: [
|
|
104
|
+
{ name: "ReactNativeWebGPU", package: "ReactNativeWebGPU" },
|
|
105
|
+
],
|
|
106
|
+
scriptPhases: [
|
|
107
|
+
{
|
|
108
|
+
// RN uses this stable id to update the phase instead of adding duplicates.
|
|
109
|
+
id: "react-native-webgpu.prepare-binaries",
|
|
110
|
+
name: "Prepare React Native WebGPU binaries",
|
|
111
|
+
script,
|
|
112
|
+
// Bundled headers allow package compilation without downloading binaries;
|
|
113
|
+
// prepare libraries before the app's compile/link steps consume them.
|
|
114
|
+
position: "beforeCompile",
|
|
115
|
+
// SDK selection and local overrides are not fixed Xcode input files.
|
|
116
|
+
// Run every build; shell signatures skip unchanged assembly and copies.
|
|
117
|
+
alwaysOutOfDate: true,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
// These trigger RN autolinking regeneration when the pin or adapter changes.
|
|
121
|
+
// They are separate from the preparation phase's own binary/cache checks.
|
|
122
|
+
watchPaths: [
|
|
123
|
+
path.join(packageRoot, "binaries.json"),
|
|
124
|
+
path.join(packageRoot, "Package.swift"),
|
|
125
|
+
__filename,
|
|
126
|
+
scriptPath,
|
|
127
|
+
path.join(__dirname, "apple-binaries-utils.sh"),
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
};
|
package/src/Canvas.tsx
CHANGED
|
@@ -12,8 +12,7 @@ export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./types";
|
|
|
12
12
|
const generateContextId = () => RNWebGPU.allocateContextId();
|
|
13
13
|
|
|
14
14
|
/** The Android view a canvas draws into, see {@link AndroidCanvasProps}. */
|
|
15
|
-
export type AndroidBackingView =
|
|
16
|
-
"TextureView" | "SurfaceView" | "HardwareBufferView";
|
|
15
|
+
export type AndroidBackingView = "TextureView" | "SurfaceView";
|
|
17
16
|
|
|
18
17
|
/** The options of a canvas backed by a `TextureView`, the default. */
|
|
19
18
|
export interface AndroidTextureViewProps {
|
|
@@ -62,17 +61,6 @@ export interface AndroidSurfaceViewProps {
|
|
|
62
61
|
zOrderMediaOverlay?: boolean;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
/** The options of a canvas backed by a `HardwareBufferView`. */
|
|
66
|
-
export interface AndroidHardwareBufferViewProps {
|
|
67
|
-
/**
|
|
68
|
-
* A plain view drawing each frame's `AHardwareBuffer` inline: composited
|
|
69
|
-
* like a `TextureView`, without its extra copy. Opt-in and experimental,
|
|
70
|
-
* on Android 10 and later; below that the canvas uses a `TextureView`,
|
|
71
|
-
* with a warning in development. Always composites with alpha.
|
|
72
|
-
*/
|
|
73
|
-
backingView: "HardwareBufferView";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
64
|
/**
|
|
77
65
|
* Android-only rendering options: the native view behind the canvas and its
|
|
78
66
|
* options. The view is created when the canvas mounts and kept: a change of
|
|
@@ -81,9 +69,7 @@ export interface AndroidHardwareBufferViewProps {
|
|
|
81
69
|
* z-order options on Android 11 and later. Ignored on iOS and web.
|
|
82
70
|
*/
|
|
83
71
|
export type AndroidCanvasProps =
|
|
84
|
-
|
|
|
85
|
-
| AndroidSurfaceViewProps
|
|
86
|
-
| AndroidHardwareBufferViewProps;
|
|
72
|
+
AndroidTextureViewProps | AndroidSurfaceViewProps;
|
|
87
73
|
|
|
88
74
|
export interface CanvasProps extends ViewProps {
|
|
89
75
|
/**
|
|
@@ -128,25 +114,16 @@ const resolveBackingView = (
|
|
|
128
114
|
android?: AndroidCanvasProps,
|
|
129
115
|
): AndroidBackingView => {
|
|
130
116
|
const { backingView } = options(android);
|
|
131
|
-
return backingView === "SurfaceView"
|
|
132
|
-
? backingView
|
|
133
|
-
: "TextureView";
|
|
117
|
+
return backingView === "SurfaceView" ? backingView : "TextureView";
|
|
134
118
|
};
|
|
135
119
|
|
|
136
|
-
// Whether the canvas composites as opaque
|
|
137
|
-
//
|
|
138
|
-
// unless asked otherwise, and a HardwareBufferView always composites with
|
|
139
|
-
// alpha.
|
|
120
|
+
// Whether the canvas composites as opaque: a SurfaceView is opaque unless
|
|
121
|
+
// asked otherwise, a TextureView is translucent unless asked otherwise.
|
|
140
122
|
const resolveOpaque = (android?: AndroidCanvasProps): boolean => {
|
|
141
123
|
const { opaque } = options(android);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
case "TextureView":
|
|
146
|
-
return opaque === true;
|
|
147
|
-
case "HardwareBufferView":
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
124
|
+
return resolveBackingView(android) === "SurfaceView"
|
|
125
|
+
? opaque !== false
|
|
126
|
+
: opaque === true;
|
|
150
127
|
};
|
|
151
128
|
|
|
152
129
|
// The native props the `android` prop resolves to.
|
|
@@ -169,28 +146,13 @@ const warnIgnoredChange = (prop: string) =>
|
|
|
169
146
|
"to change it.",
|
|
170
147
|
);
|
|
171
148
|
|
|
172
|
-
// Warns, in development on Android, about
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
// The native side only says so in logcat, which is not where a JS developer
|
|
177
|
-
// looks.
|
|
149
|
+
// Warns, in development on Android, about a change of these props that the
|
|
150
|
+
// native view ignores: the backing view is created from them when the canvas
|
|
151
|
+
// mounts (see WebGPUView.java, whose setters these rules mirror). The native
|
|
152
|
+
// side only says so in logcat, which is not where a JS developer looks.
|
|
178
153
|
const useBackingViewWarning = (android?: AndroidCanvasProps) => {
|
|
179
154
|
const mount = useRef(android);
|
|
180
155
|
const prev = useRef(android);
|
|
181
|
-
useEffect(() => {
|
|
182
|
-
if (
|
|
183
|
-
__DEV__ &&
|
|
184
|
-
Platform.OS === "android" &&
|
|
185
|
-
resolveBackingView(mount.current) === "HardwareBufferView" &&
|
|
186
|
-
Number(Platform.Version) < 29
|
|
187
|
-
) {
|
|
188
|
-
console.warn(
|
|
189
|
-
"android.backingView: HardwareBufferView needs Android 10, the " +
|
|
190
|
-
"canvas uses a TextureView.",
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
}, []);
|
|
194
156
|
useEffect(() => {
|
|
195
157
|
if (__DEV__ && Platform.OS === "android") {
|
|
196
158
|
const { current: before } = prev;
|
|
@@ -5,7 +5,7 @@ export interface NativeProps extends ViewProps {
|
|
|
5
5
|
contextId: CodegenTypes.Int32;
|
|
6
6
|
// The `android` prop, resolved (see Canvas.tsx)
|
|
7
7
|
androidBackingView?: CodegenTypes.WithDefault<
|
|
8
|
-
"TextureView" | "SurfaceView"
|
|
8
|
+
"TextureView" | "SurfaceView",
|
|
9
9
|
"TextureView"
|
|
10
10
|
>;
|
|
11
11
|
androidOpaque?: CodegenTypes.WithDefault<boolean, false>;
|
|
@@ -7,7 +7,7 @@ import { contextIdToId } from "./utils";
|
|
|
7
7
|
export interface NativeProps extends ViewProps {
|
|
8
8
|
contextId: CodegenTypes.Int32;
|
|
9
9
|
// The `android` prop, resolved: Android-only, never reaches the DOM
|
|
10
|
-
androidBackingView?: "TextureView" | "SurfaceView"
|
|
10
|
+
androidBackingView?: "TextureView" | "SurfaceView";
|
|
11
11
|
androidOpaque?: boolean;
|
|
12
12
|
androidZOrderOnTop?: boolean;
|
|
13
13
|
androidZOrderMediaOverlay?: boolean;
|
package/src/index.tsx
CHANGED
|
@@ -43,7 +43,7 @@ export type {
|
|
|
43
43
|
GPUSharedTextureMemoryDescriptor,
|
|
44
44
|
GPUSharedTextureMemoryEndAccessState,
|
|
45
45
|
NativeBufferPixelFormat,
|
|
46
|
-
|
|
46
|
+
CreateTestVideoPlayerOptions,
|
|
47
47
|
GPUCopyExternalNativeFrameSourceInfo,
|
|
48
48
|
GPUDawnTogglesDescriptor,
|
|
49
49
|
GPUNativeExternalTextureDescriptor,
|
|
@@ -113,12 +113,13 @@ declare global {
|
|
|
113
113
|
// device from Skia.getNativeDevice()) into a GPUDevice. Requires the
|
|
114
114
|
// exporter to link this process's single Dawn copy.
|
|
115
115
|
importDevice: (pointer: bigint) => GPUDevice;
|
|
116
|
+
purgeGpuResources: () => void;
|
|
116
117
|
// Wrap an externally created WGPUTexture pointer into a GPUTexture,
|
|
117
118
|
// taking ownership of one reference (pair with producers that return a
|
|
118
119
|
// +1 pointer, e.g. Skia.Image.MakeGPUTextureFromImage()).
|
|
119
120
|
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
120
|
-
// Prefer the
|
|
121
|
-
|
|
121
|
+
// Prefer the createTestVideoPlayer() export, which takes an options object.
|
|
122
|
+
createTestVideoPlayer: (
|
|
122
123
|
source: string,
|
|
123
124
|
pixelFormat?: NativeBufferPixelFormat,
|
|
124
125
|
) => VideoPlayer;
|
|
@@ -185,7 +186,7 @@ declare global {
|
|
|
185
186
|
source: GPUDrawElementImageSource,
|
|
186
187
|
destination: GPUDrawElementImageDestination,
|
|
187
188
|
): Promise<void>;
|
|
188
|
-
// Non-spec extension: a NativeBuffer (from
|
|
189
|
+
// Non-spec extension: a NativeBuffer (from createTestVideoPlayer,
|
|
189
190
|
// createNativeBufferFromPointer or createTestVideoFrame) as the copy
|
|
190
191
|
// source. The frame is rendered into the destination on the GPU through
|
|
191
192
|
// an external texture, which converts YUV to RGB and applies `rotation`
|
package/src/main/index.tsx
CHANGED
package/src/main/index.web.tsx
CHANGED
|
@@ -6,6 +6,7 @@ export * from "../WebGPUViewNativeComponent";
|
|
|
6
6
|
export * from "../hooks";
|
|
7
7
|
export * from "../GPUDeviceProvider";
|
|
8
8
|
export * from "../formats";
|
|
9
|
+
export * from "../purgeGpuResources";
|
|
9
10
|
export * from "../video";
|
|
10
11
|
|
|
11
12
|
// We don't need to set all global properties on web, webgpu is already available globally
|
package/src/mock.ts
CHANGED
|
@@ -85,7 +85,6 @@ const NOT_AVAILABLE_UNDER_JEST =
|
|
|
85
85
|
export type {
|
|
86
86
|
AndroidBackingView,
|
|
87
87
|
AndroidCanvasProps,
|
|
88
|
-
AndroidHardwareBufferViewProps,
|
|
89
88
|
AndroidSurfaceViewProps,
|
|
90
89
|
AndroidTextureViewProps,
|
|
91
90
|
CanvasProps,
|
|
@@ -147,6 +146,8 @@ export const useMainDevice = (): never => {
|
|
|
147
146
|
throw new Error(`useMainDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
|
|
148
147
|
};
|
|
149
148
|
|
|
149
|
+
export const purgeGpuResources = () => undefined;
|
|
150
|
+
|
|
150
151
|
export const importDevice = (_pointer: bigint): GPUDevice => {
|
|
151
152
|
throw new Error(`importDevice() ${NOT_AVAILABLE_UNDER_JEST}`);
|
|
152
153
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the GPU memory nothing uses to the system. Most apps should never
|
|
3
|
+
* call it: `destroy()` lets Dawn reuse the memory, and react-native-webgpu
|
|
4
|
+
* purges on its own when the system is short of memory and, on Android, each
|
|
5
|
+
* time the app goes to the background.
|
|
6
|
+
*
|
|
7
|
+
* It is meant for a one-off peak (a video export) followed by a long stretch
|
|
8
|
+
* that needs far less GPU memory. Not for a render loop, not after each
|
|
9
|
+
* `destroy()`, not on unmount: memory Dawn would have reused has to be
|
|
10
|
+
* requested from the system again. It does not free what was not destroyed.
|
|
11
|
+
*
|
|
12
|
+
* It returns right away and works in the background. It covers every device
|
|
13
|
+
* created through react-native-webgpu; an imported device is purged by its
|
|
14
|
+
* owner. Not part of the WebGPU spec, and does nothing on the Web.
|
|
15
|
+
*/
|
|
16
|
+
export const purgeGpuResources = (): void => {
|
|
17
|
+
if (typeof RNWebGPU === "undefined") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
RNWebGPU.purgeGpuResources();
|
|
21
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -171,7 +171,7 @@ export interface GPUCopyExternalNativeFrameSourceInfo {
|
|
|
171
171
|
mirrored?: boolean;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
export interface
|
|
174
|
+
export interface CreateTestVideoPlayerOptions {
|
|
175
175
|
// The layout of the frames on Apple platforms:
|
|
176
176
|
// 'bgra8' (default): single-plane BGRA surfaces, for importSharedTextureMemory
|
|
177
177
|
// and a regular sampled GPUTexture.
|