Skip to content

Commit b095052

Browse files
authored
Merge pull request #20 from blazejkustra/fix/rn-webgpu-worklets-high-bugs
fix(ShaderView): Android transparency + correct worklet WebGPU setup (bump rn-webgpu 0.5.15)
2 parents f96e8bf + b660ea2 commit b095052

6 files changed

Lines changed: 21 additions & 60 deletions

File tree

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"react-native-reanimated": "4.3.1",
2525
"react-native-safe-area-context": "~5.7.0",
2626
"react-native-screens": "4.25.2",
27-
"react-native-webgpu": "0.5.14",
27+
"react-native-webgpu": "0.5.15",
2828
"react-native-worklets": "0.8.3"
2929
},
3030
"devDependencies": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"react-native-builder-bob": "^0.41.0",
9090
"react-native-gesture-handler": "2.31.1",
9191
"react-native-reanimated": "4.3.1",
92-
"react-native-webgpu": "0.5.14",
92+
"react-native-webgpu": "0.5.15",
9393
"react-native-worklets": "0.8.3",
9494
"release-it": "^20.2.0",
9595
"turbo": "^2.9.16",

src/components/ShaderView/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PixelRatio, StyleSheet } from 'react-native';
2-
import { Canvas } from 'react-native-webgpu';
2+
import { Canvas, installWebGPU } from 'react-native-webgpu';
33
import { useEffect, useRef } from 'react';
44
import { createSynchronizable, scheduleOnRuntime } from 'react-native-worklets';
55
import { colorToVec4 } from '../../utils/colors';
@@ -99,6 +99,12 @@ export default function ShaderView({
9999
scheduleOnRuntime(runtime, () => {
100100
'worklet';
101101

102+
// Worklet runtimes start without the WebGPU flag constants
103+
// (GPUBufferUsage, GPUTextureUsage, ...). installWebGPU() captures them
104+
// into this runtime so they're available below. Idempotent / safe no-op
105+
// if already installed.
106+
installWebGPU();
107+
102108
// Create pipeline once
103109
const pipeline = device.createRenderPipeline({
104110
layout: 'auto',
@@ -251,7 +257,12 @@ export default function ShaderView({
251257
]);
252258

253259
return (
254-
<Canvas ref={canvasRef} style={[styles.canvas, style]} {...viewProps} />
260+
<Canvas
261+
ref={canvasRef}
262+
transparent={transparent}
263+
style={[styles.canvas, style]}
264+
{...viewProps}
265+
/>
255266
);
256267
}
257268

src/hooks/useWGPUSetup.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
} from 'react-native-webgpu';
77
import { useEffect, useState } from 'react';
88
import type { WorkletRuntime } from 'react-native-worklets';
9-
import { initWebGPU } from '../utils/initWebGPU';
109
import { BackgroundRuntime } from '../utils/backgroundRuntime';
1110

1211
type GPUResources = {
@@ -56,8 +55,6 @@ export function useWGPUSetup(): WGPUSetupResult {
5655
alphaMode: 'premultiplied',
5756
});
5857

59-
initWebGPU(runtime);
60-
6158
if (!cancelled) {
6259
setResources({ device, context, presentationFormat });
6360
}

src/utils/initWebGPU.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10743,7 +10743,7 @@ __metadata:
1074310743
react-native-reanimated: "npm:4.3.1"
1074410744
react-native-safe-area-context: "npm:~5.7.0"
1074510745
react-native-screens: "npm:4.25.2"
10746-
react-native-webgpu: "npm:0.5.14"
10746+
react-native-webgpu: "npm:0.5.15"
1074710747
react-native-worklets: "npm:0.8.3"
1074810748
typescript: "npm:6.0.3"
1074910749
languageName: unknown
@@ -10777,7 +10777,7 @@ __metadata:
1077710777
react-native-builder-bob: "npm:^0.41.0"
1077810778
react-native-gesture-handler: "npm:2.31.1"
1077910779
react-native-reanimated: "npm:4.3.1"
10780-
react-native-webgpu: "npm:0.5.14"
10780+
react-native-webgpu: "npm:0.5.15"
1078110781
react-native-worklets: "npm:0.8.3"
1078210782
release-it: "npm:^20.2.0"
1078310783
turbo: "npm:^2.9.16"
@@ -10878,9 +10878,9 @@ __metadata:
1087810878
languageName: node
1087910879
linkType: hard
1088010880

10881-
"react-native-webgpu@npm:0.5.14":
10882-
version: 0.5.14
10883-
resolution: "react-native-webgpu@npm:0.5.14"
10881+
"react-native-webgpu@npm:0.5.15":
10882+
version: 0.5.15
10883+
resolution: "react-native-webgpu@npm:0.5.15"
1088410884
peerDependencies:
1088510885
react: "*"
1088610886
react-native: ">=0.81.0"
@@ -10891,7 +10891,7 @@ __metadata:
1089110891
optional: true
1089210892
react-native-worklets:
1089310893
optional: true
10894-
checksum: 10c0/305f81f31273275a0f13616af3b50c5418ee06d1e098a5a613446ec5ed88730a65e6e8f206628a9e080cc579684bbee7a8ef3a3d46dae748ad793e4fb22e2030
10894+
checksum: 10c0/91430eb36a5ff5f7e43519a79b384bc9648776c2b4788900e8f9154a706cc8c60c101decc3ef32631cef300f2f636e9aeb038ccf90b15dd8cbb7f8381f39fa4b
1089510895
languageName: node
1089610896
linkType: hard
1089710897

0 commit comments

Comments
 (0)