react-native-wgpu 0.1.11 → 0.1.13
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/{ios/IOSPlatformContext.h → apple/ApplePlatformContext.h} +4 -4
- package/{ios/IOSPlatformContext.mm → apple/ApplePlatformContext.mm} +24 -6
- package/{ios → apple}/MetalView.h +3 -0
- package/apple/MetalView.mm +58 -0
- package/{ios → apple}/WebGPUModule.mm +2 -2
- package/{ios → apple}/WebGPUView.h +0 -3
- package/apple/WebGPUView.mm +68 -0
- package/cpp/rnwgpu/api/Convertors.h +0 -9
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +6 -5
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +7 -0
- package/cpp/webgpu/webgpu.h +4182 -5
- package/cpp/webgpu/webgpu_cpp.h +9009 -5
- package/lib/commonjs/hooks.js +61 -1
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +0 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/hooks.js +57 -1
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +0 -5
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/hooks.d.ts +11 -0
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/hooks.d.ts +11 -0
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/index.d.ts +0 -1
- package/lib/typescript/lib/module/index.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +1 -0
- package/lib/typescript/src/hooks.d.ts +18 -0
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +0 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +8 -8
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/package.json +3 -3
- package/react-native-wgpu.podspec +1 -1
- package/src/__tests__/Alpha.spec.ts +28 -0
- package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
- package/src/hooks.tsx +125 -0
- package/src/index.tsx +0 -8
- package/cpp/dawn/dawn_proc_table.h +0 -308
- package/cpp/dawn/webgpu.h +0 -4210
- package/cpp/dawn/webgpu_cpp.h +0 -9037
- package/cpp/dawn/webgpu_cpp_print.h +0 -2466
- package/cpp/dawn/wire/client/webgpu.h +0 -339
- package/cpp/dawn/wire/client/webgpu_cpp.h +0 -9177
- package/ios/MetalView.mm +0 -40
- package/ios/SurfaceUtils.h +0 -15
- package/ios/SurfaceUtils.mm +0 -34
- package/ios/WebGPUView.mm +0 -86
- package/ios/WebGPUViewComponentDescriptor.h +0 -61
- package/src/hooks.ts +0 -53
- /package/{ios → apple}/WebGPUModule.h +0 -0
- /package/{ios → apple}/WebGPUViewManager.mm +0 -0
package/ios/MetalView.mm
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#import "MetalView.h"
|
|
2
|
-
#import "SurfaceUtils.h"
|
|
3
|
-
#import "webgpu_cpp.h"
|
|
4
|
-
#import <React/RCTViewManager.h>
|
|
5
|
-
|
|
6
|
-
@implementation MetalView {
|
|
7
|
-
BOOL _isConfigured;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
+ (Class)layerClass {
|
|
11
|
-
return [CAMetalLayer class];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Paper only method
|
|
15
|
-
// TODO: this method is wrong, it appears to call configureSurface instead of
|
|
16
|
-
// updateSurface sometimes
|
|
17
|
-
- (void)reactSetFrame:(CGRect)frame {
|
|
18
|
-
[super reactSetFrame:frame];
|
|
19
|
-
if (!_isConfigured) {
|
|
20
|
-
[SurfaceUtils configureSurface:self.layer
|
|
21
|
-
size:self.frame.size
|
|
22
|
-
contextId:[_contextId intValue]];
|
|
23
|
-
_isConfigured = YES;
|
|
24
|
-
} else {
|
|
25
|
-
[SurfaceUtils updateSurface:[_contextId intValue] size:self.frame.size];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
- (void)willMoveToSuperview:(UIView *)newSuperview {
|
|
30
|
-
[super willMoveToSuperview:newSuperview];
|
|
31
|
-
|
|
32
|
-
if (newSuperview == nil) {
|
|
33
|
-
// The view is being removed from its superview
|
|
34
|
-
// Add your cleanup code here
|
|
35
|
-
[SurfaceUtils cleanupSurface:[_contextId intValue]];
|
|
36
|
-
_isConfigured = NO;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@end
|
package/ios/SurfaceUtils.h
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#import <UIKit/UIKit.h>
|
|
4
|
-
|
|
5
|
-
@interface SurfaceUtils : NSObject
|
|
6
|
-
|
|
7
|
-
+ (void)configureSurface:(CALayer *)layer
|
|
8
|
-
size:(CGSize)size
|
|
9
|
-
contextId:(int)contextId;
|
|
10
|
-
|
|
11
|
-
+ (void)updateSurface:(int)contextId size:(CGSize)size;
|
|
12
|
-
|
|
13
|
-
+ (void)cleanupSurface:(int)contextId;
|
|
14
|
-
|
|
15
|
-
@end
|
package/ios/SurfaceUtils.mm
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#import "SurfaceUtils.h"
|
|
2
|
-
#import "MetalView.h"
|
|
3
|
-
#import "WebGPUModule.h"
|
|
4
|
-
#import "WebGPUView.h"
|
|
5
|
-
|
|
6
|
-
@implementation SurfaceUtils
|
|
7
|
-
|
|
8
|
-
+ (void)configureSurface:(CALayer *)layer
|
|
9
|
-
size:(CGSize)size
|
|
10
|
-
contextId:(int)contextId {
|
|
11
|
-
std::shared_ptr<rnwgpu::RNWebGPUManager> manager = [WebGPUModule getManager];
|
|
12
|
-
void *nativeSurface = (__bridge void *)layer;
|
|
13
|
-
auto ®istry = rnwgpu::SurfaceRegistry::getInstance();
|
|
14
|
-
auto gpu = manager->_gpu;
|
|
15
|
-
auto surface = manager->_platformContext->makeSurface(
|
|
16
|
-
gpu, nativeSurface, size.width, size.height);
|
|
17
|
-
registry.getSurfaceInfoOrCreate(contextId, gpu, size.width, size.height)
|
|
18
|
-
->switchToOnscreen(nativeSurface, surface);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
+ (void)updateSurface:(int)contextId size:(CGSize)size {
|
|
22
|
-
// std::shared_ptr<rnwgpu::RNWebGPUManager> manager = [WebGPUModule
|
|
23
|
-
// getManager];
|
|
24
|
-
auto ®istry = rnwgpu::SurfaceRegistry::getInstance();
|
|
25
|
-
registry.getSurfaceInfo(contextId)->resize(size.width, size.height);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
+ (void)cleanupSurface:(int)contextId {
|
|
29
|
-
auto ®istry = rnwgpu::SurfaceRegistry::getInstance();
|
|
30
|
-
// Remove the surface info from the registry
|
|
31
|
-
registry.removeSurfaceInfo(contextId);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@end
|
package/ios/WebGPUView.mm
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
-
#import "WebGPUView.h"
|
|
3
|
-
|
|
4
|
-
#import <react/renderer/components/RNWgpuViewSpec/EventEmitters.h>
|
|
5
|
-
#import <react/renderer/components/RNWgpuViewSpec/Props.h>
|
|
6
|
-
#import <react/renderer/components/RNWgpuViewSpec/RCTComponentViewHelpers.h>
|
|
7
|
-
|
|
8
|
-
#import "MetalView.h"
|
|
9
|
-
#import "RCTFabricComponentsPlugins.h"
|
|
10
|
-
#import "Utils.h"
|
|
11
|
-
#import "WebGPUModule.h"
|
|
12
|
-
#import "WebGPUViewComponentDescriptor.h"
|
|
13
|
-
|
|
14
|
-
using namespace facebook::react;
|
|
15
|
-
|
|
16
|
-
@interface WebGPUView () <RCTWebGPUViewViewProtocol>
|
|
17
|
-
|
|
18
|
-
@end
|
|
19
|
-
|
|
20
|
-
@implementation WebGPUView {
|
|
21
|
-
NSNumber *_contextId;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static NSMutableDictionary<NSNumber *, MetalView *> *metalViewRegistry =
|
|
25
|
-
[NSMutableDictionary new];
|
|
26
|
-
|
|
27
|
-
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
28
|
-
return concreteComponentDescriptorProvider<WebGPUViewComponentDescriptor>();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
+ (void)registerMetalView:(MetalView *)metalView
|
|
32
|
-
withContextId:(NSNumber *)contextId {
|
|
33
|
-
metalViewRegistry[contextId] = metalView;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
+ (bool)isContextRegisterd:(NSNumber *)contextId {
|
|
37
|
-
return metalViewRegistry[contextId] != nil;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
- (instancetype)initWithFrame:(CGRect)frame {
|
|
41
|
-
if (self = [super initWithFrame:frame]) {
|
|
42
|
-
static const auto defaultProps = std::make_shared<const WebGPUViewProps>();
|
|
43
|
-
_props = defaultProps;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return self;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
- (void)prepareForRecycle {
|
|
50
|
-
[super prepareForRecycle];
|
|
51
|
-
self.contentView = nil;
|
|
52
|
-
if ([metalViewRegistry objectForKey:_contextId] != nil) {
|
|
53
|
-
[metalViewRegistry removeObjectForKey:_contextId];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
- (void)updateProps:(const facebook::react::Props::Shared &)props
|
|
58
|
-
oldProps:(const facebook::react::Props::Shared &)oldProps {
|
|
59
|
-
const auto &oldViewProps =
|
|
60
|
-
*std::static_pointer_cast<const WebGPUViewProps>(_props);
|
|
61
|
-
const auto &newViewProps =
|
|
62
|
-
*std::static_pointer_cast<const WebGPUViewProps>(props);
|
|
63
|
-
|
|
64
|
-
if (newViewProps.contextId != oldViewProps.contextId) {
|
|
65
|
-
_contextId = [[NSNumber alloc] initWithInt:newViewProps.contextId];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
[super updateProps:props oldProps:oldProps];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
- (void)updateLayoutMetrics:
|
|
72
|
-
(const facebook::react::LayoutMetrics &)layoutMetrics
|
|
73
|
-
oldLayoutMetrics:
|
|
74
|
-
(const facebook::react::LayoutMetrics &)oldLayoutMetrics {
|
|
75
|
-
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
76
|
-
if (!self.contentView) {
|
|
77
|
-
const auto &props =
|
|
78
|
-
*std::static_pointer_cast<WebGPUViewProps const>(_props);
|
|
79
|
-
self.contentView = metalViewRegistry[@(props.contextId)];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Class<RCTComponentViewProtocol> WebGPUViewCls(void) { return WebGPUView.class; }
|
|
84
|
-
|
|
85
|
-
@end
|
|
86
|
-
#endif
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
-
|
|
3
|
-
#pragma once
|
|
4
|
-
|
|
5
|
-
#include <react/debug/react_native_assert.h>
|
|
6
|
-
#include <react/renderer/components/RNWgpuViewSpec/ShadowNodes.h>
|
|
7
|
-
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
8
|
-
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
9
|
-
#include <react/renderer/core/LayoutContext.h>
|
|
10
|
-
|
|
11
|
-
#import "MetalView.h"
|
|
12
|
-
#import "SurfaceUtils.h"
|
|
13
|
-
#import "WebGPUView.h"
|
|
14
|
-
|
|
15
|
-
namespace facebook {
|
|
16
|
-
namespace react {
|
|
17
|
-
|
|
18
|
-
class WebGPUViewCustomShadowNode final : public WebGPUViewShadowNode {
|
|
19
|
-
|
|
20
|
-
public:
|
|
21
|
-
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
22
|
-
|
|
23
|
-
void layout(LayoutContext layoutContext) override {
|
|
24
|
-
YogaLayoutableShadowNode::layout(layoutContext);
|
|
25
|
-
configureSurface();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
void configureSurface() {
|
|
29
|
-
const auto &viewProps =
|
|
30
|
-
*std::static_pointer_cast<WebGPUViewProps const>(props_);
|
|
31
|
-
if ([WebGPUView isContextRegisterd:@(viewProps.contextId)]) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
__block MetalView *metalView;
|
|
35
|
-
__block CALayer *layer;
|
|
36
|
-
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
37
|
-
metalView = [[MetalView alloc] init];
|
|
38
|
-
layer = metalView.layer;
|
|
39
|
-
});
|
|
40
|
-
[WebGPUView registerMetalView:metalView
|
|
41
|
-
withContextId:@(viewProps.contextId)];
|
|
42
|
-
|
|
43
|
-
// TODO: use physical size
|
|
44
|
-
float width = layoutMetrics_.frame.size.width;
|
|
45
|
-
float height = layoutMetrics_.frame.size.height;
|
|
46
|
-
[SurfaceUtils configureSurface:layer
|
|
47
|
-
size:CGSizeMake(width, height)
|
|
48
|
-
contextId:viewProps.contextId];
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
class WebGPUViewComponentDescriptor final
|
|
53
|
-
: public ConcreteComponentDescriptor<WebGPUViewCustomShadowNode> {
|
|
54
|
-
public:
|
|
55
|
-
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
} // namespace react
|
|
59
|
-
} // namespace facebook
|
|
60
|
-
|
|
61
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
package/src/hooks.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import type { RNCanvasContext, CanvasRef, NativeCanvas } from "./Canvas";
|
|
4
|
-
|
|
5
|
-
type Unsubscribe = () => void;
|
|
6
|
-
|
|
7
|
-
export const useSurface = () => {
|
|
8
|
-
const [surface, setSurface] = useState<NativeCanvas | null>(null);
|
|
9
|
-
const ref = useCanvasEffect(() => {
|
|
10
|
-
const sur = ref.current!.getNativeSurface();
|
|
11
|
-
setSurface(sur);
|
|
12
|
-
});
|
|
13
|
-
return { ref, surface };
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useGPUContext = () => {
|
|
17
|
-
const [context, setContext] = useState<RNCanvasContext | null>(null);
|
|
18
|
-
const ref = useCanvasEffect(() => {
|
|
19
|
-
const ctx = ref.current!.getContext("webgpu")!;
|
|
20
|
-
setContext(ctx);
|
|
21
|
-
});
|
|
22
|
-
return { ref, context };
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const useCanvasEffect = (
|
|
26
|
-
effect: () =>
|
|
27
|
-
| void
|
|
28
|
-
| Unsubscribe
|
|
29
|
-
| Promise<Unsubscribe | void>
|
|
30
|
-
| Promise<void>,
|
|
31
|
-
) => {
|
|
32
|
-
const unsub = useRef<Unsubscribe | null | Promise<Unsubscribe | void>>(null);
|
|
33
|
-
const ref = useRef<CanvasRef>(null);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
ref.current!.whenReady(async () => {
|
|
36
|
-
const sub = effect();
|
|
37
|
-
if (sub) {
|
|
38
|
-
unsub.current = sub;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return () => {
|
|
42
|
-
if (unsub.current) {
|
|
43
|
-
if (unsub.current instanceof Promise) {
|
|
44
|
-
unsub.current.then((sub) => sub && sub());
|
|
45
|
-
} else {
|
|
46
|
-
unsub.current();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
-
}, []);
|
|
52
|
-
return ref;
|
|
53
|
-
};
|
|
File without changes
|
|
File without changes
|