├── examples └── Example │ ├── .watchmanconfig │ ├── app.json │ ├── jest.config.js │ ├── .bundle │ └── config │ ├── .prettierignore │ ├── .yarnrc.yml │ ├── android │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ │ ├── ic_launcher_round.webp │ │ │ │ │ │ └── ic_launcher_foreground.webp │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ │ ├── ic_launcher_round.webp │ │ │ │ │ │ └── ic_launcher_foreground.webp │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ │ ├── ic_launcher_round.webp │ │ │ │ │ │ └── ic_launcher_foreground.webp │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ │ ├── ic_launcher_round.webp │ │ │ │ │ │ └── ic_launcher_foreground.webp │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ │ ├── ic_launcher_round.webp │ │ │ │ │ │ └── ic_launcher_foreground.webp │ │ │ │ │ └── mipmap-anydpi-v26 │ │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── ic_launcher-playstore.png │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── MainActivity.kt │ │ │ │ └── AndroidManifest.xml │ │ │ └── debug │ │ │ │ └── AndroidManifest.xml │ │ ├── debug.keystore │ │ └── proguard-rules.pro │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ └── build.gradle │ ├── .eslintignore │ ├── ios │ ├── Example │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ ├── dark_60@2x.png │ │ │ │ ├── dark_60@3x.png │ │ │ │ ├── icon_60@2x.png │ │ │ │ ├── icon_60@3x.png │ │ │ │ ├── tinted_60@2x.png │ │ │ │ └── tinted_60@3x.png │ │ ├── PrivacyInfo.xcprivacy │ │ └── AppDelegate.swift │ ├── Example.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── .xcode.env │ └── Podfile │ ├── src │ ├── WebGPUSamples │ │ ├── shaders │ │ │ ├── red.frag.wgsl │ │ │ ├── vertexPositionColor.frag.wgsl │ │ │ ├── triangle.vert.wgsl │ │ │ ├── basic.vert.wgsl │ │ │ └── fullscreenTexturedQuad.wgsl │ │ ├── assets │ │ │ └── img │ │ │ │ ├── moon.jpg │ │ │ │ ├── Di-3d.png │ │ │ │ ├── saturn.jpg │ │ │ │ ├── webgpu.png │ │ │ │ ├── wood_albedo.png │ │ │ │ ├── cubemap │ │ │ │ ├── negx.jpg │ │ │ │ ├── negy.jpg │ │ │ │ ├── negz.jpg │ │ │ │ ├── posx.jpg │ │ │ │ ├── posy.jpg │ │ │ │ └── posz.jpg │ │ │ │ ├── spiral_height.png │ │ │ │ ├── spiral_normal.png │ │ │ │ ├── toybox_height.png │ │ │ │ ├── toybox_normal.png │ │ │ │ ├── brickwall_albedo.jpg │ │ │ │ ├── brickwall_height.jpg │ │ │ │ └── brickwall_normal.jpg │ │ ├── GPGPU │ │ │ ├── GameOfLife │ │ │ │ ├── frag.wgsl │ │ │ │ ├── vert.wgsl │ │ │ │ └── compute.wgsl │ │ │ ├── BitonicSort │ │ │ │ └── atomicToZero.wgsl │ │ │ └── ComputeBoids │ │ │ │ └── sprite.wgsl │ │ ├── WebGPUFeatures │ │ │ ├── ReversedZ │ │ │ │ ├── fragment.wgsl │ │ │ │ ├── fragmentTextureQuad.wgsl │ │ │ │ ├── vertexTextureQuad.wgsl │ │ │ │ ├── fragmentPrecisionErrorPass.wgsl │ │ │ │ ├── vertexDepthPrePass.wgsl │ │ │ │ ├── vertexPrecisionErrorPass.wgsl │ │ │ │ └── vertex.wgsl │ │ │ ├── OcclusionQueries │ │ │ │ └── solidColorLit.wgsl │ │ │ └── SamplerParameters │ │ │ │ └── showTexture.wgsl │ │ ├── GraphicsTechniques │ │ │ ├── DeferredRendering │ │ │ │ ├── vertexTextureQuad.wgsl │ │ │ │ ├── fragmentWriteGBuffers.wgsl │ │ │ │ ├── vertexWriteGBuffers.wgsl │ │ │ │ ├── lightUpdate.wgsl │ │ │ │ └── fragmentGBuffersDebugView.wgsl │ │ │ ├── ShadowMapping │ │ │ │ ├── vertexShadow.wgsl │ │ │ │ └── vertex.wgsl │ │ │ ├── Wireframe │ │ │ │ ├── utils.ts │ │ │ │ └── solidColorLit.wgsl │ │ │ ├── Cameras │ │ │ │ └── cube.wgsl │ │ │ └── Cornell │ │ │ │ ├── tonemapper.wgsl │ │ │ │ └── rasterizer.wgsl │ │ ├── BasicGraphics │ │ │ ├── TexturedCube │ │ │ │ └── sampleTextureMixColor.frag.wgsl │ │ │ ├── FractalCube │ │ │ │ └── sampleSelf.frag.wgsl │ │ │ ├── InstancedCube │ │ │ │ └── instanced.vert.wgsl │ │ │ └── CubeMap │ │ │ │ └── sampleCubemap.frag.wgsl │ │ └── meshes │ │ │ ├── teapot.ts │ │ │ └── stanfordDragon.ts │ ├── InHouse │ │ ├── Portal │ │ │ ├── portal.jpg │ │ │ └── portal.wgsl │ │ ├── Thread.tsx │ │ ├── ResizeCanvas │ │ │ ├── triangle.wgsl │ │ │ └── ResizeCanvas.tsx │ │ ├── AnimateCanvas │ │ │ ├── triangle.wgsl │ │ │ └── AnimateCanvas.tsx │ │ ├── CWTriangle │ │ │ └── cw-triangle.wgsl │ │ └── Outlines │ │ │ └── outlines.wgsl │ ├── assets │ │ └── images │ │ │ └── cropImage.png │ ├── types │ │ ├── gltf.d.ts │ │ ├── navigationTypes.ts │ │ └── TextDecoder.d.ts │ ├── utils │ │ ├── constants.ts │ │ ├── launchArguments.ts │ │ ├── examplesCallback.ts │ │ └── shaders │ │ │ ├── quad.wgsl │ │ │ ├── videoQuad.wgsl │ │ │ └── flakesTexture.wgsl │ └── Components │ │ ├── stats │ │ ├── HudLabel.tsx │ │ ├── HudContainer.tsx │ │ ├── hudStyles.ts │ │ ├── HudText.tsx │ │ ├── useHudText.tsx │ │ └── useStats.tsx │ │ ├── controls │ │ ├── dat.gui │ │ │ ├── incrementingId.ts │ │ │ ├── incrementingId.test.ts │ │ │ ├── StringController.ts │ │ │ ├── SwitchController.ts │ │ │ ├── FunctionController.ts │ │ │ ├── NumberController.ts │ │ │ ├── SliderController.ts │ │ │ └── OptionsController.ts │ │ ├── react │ │ │ ├── ControlLabel.tsx │ │ │ ├── ControlInput.tsx │ │ │ ├── ControlButton.tsx │ │ │ ├── ControlBackground.tsx │ │ │ ├── controlsStyles.ts │ │ │ ├── ControlsContainer.tsx │ │ │ ├── ControlSwitch.tsx │ │ │ └── ControlFolder.tsx │ │ └── sliderUtils.ts │ │ ├── globalStyles.ts │ │ ├── Square.tsx │ │ └── Root.tsx │ ├── .prettierrc.js │ ├── babel.config.js │ ├── .eslintrc.js │ ├── tsconfig.json │ ├── babel │ └── gltf-babel-transformer.js │ ├── Gemfile │ ├── index.js │ ├── metro.config.js │ ├── README.md │ └── .gitignore ├── packages ├── react-native-webgpu-tests │ ├── .gitignore │ ├── .prettierignore │ ├── bin │ │ ├── test-examples │ │ └── test-package │ ├── .prettierrc.cjs │ ├── src │ │ ├── index.js │ │ ├── utils │ │ │ ├── queue.js │ │ │ └── log.js │ │ ├── examples │ │ │ └── examples-to-test.js │ │ └── package │ │ │ ├── pack.js │ │ │ └── build-android.js │ └── package.json ├── react-native-webgpu-three │ ├── .prettierignore │ ├── babel │ │ ├── index.js │ │ └── package.json │ ├── metro │ │ ├── package.json │ │ └── index.js │ ├── .prettierrc.js │ ├── src │ │ ├── constNodePatch.js │ │ ├── rendererPatch.js │ │ ├── Image.js │ │ ├── nodeBuilderPatch.js │ │ ├── index.js │ │ └── debugLogging.js │ ├── types │ │ └── index.d.ts │ ├── LICENSE │ └── package.json ├── react-native-webgpu │ ├── babel.config.js │ ├── metro │ │ ├── index.js │ │ └── package.json │ ├── types │ │ └── wgsl.d.ts │ ├── cxx │ │ ├── JSIInstance.cpp │ │ ├── WGPUContext.cpp │ │ ├── android │ │ │ ├── Thread.cpp │ │ │ ├── WGPULog.h │ │ │ ├── WGPUJsi.h │ │ │ ├── JNIExceptionHandler.h │ │ │ ├── WGPUAndroidInstance.h │ │ │ └── WGPUAndroidInstance.cpp │ │ ├── ios │ │ │ ├── Thread.mm │ │ │ ├── WGPULog.h │ │ │ ├── UIImage+Bitmap.h │ │ │ ├── WGPUObjCInstance.h │ │ │ ├── WGPUJsi.h │ │ │ ├── WGPUWebGPUViewManager.mm │ │ │ ├── WGPUWebGPUView.h │ │ │ ├── WGPUObjCInstance.m │ │ │ └── UIImage+Bitmap.mm │ │ ├── InstallRootJSI.h │ │ ├── CreateImageBitmap.h │ │ ├── Thread.h │ │ ├── JSIInstance.h │ │ ├── SurfacesManager.h │ │ ├── SamplerHostObject.cpp │ │ ├── BindGroupHostObject.cpp │ │ ├── TextureViewHostObject.cpp │ │ ├── QueueHostObject.h │ │ ├── RenderBundleHostObject.cpp │ │ ├── CommandBufferHostObject.cpp │ │ ├── PipelineLayoutHostObject.cpp │ │ ├── BindGroupLayoutHostObject.cpp │ │ ├── ExampleHostObject.cpp │ │ ├── AutoReleasePool.h │ │ ├── AdapterHostObject.h │ │ ├── ExampleHostObject.h │ │ ├── SurfacesManager.cpp │ │ ├── BufferHostObject.h │ │ ├── CommandEncoderHostObject.h │ │ ├── WGPUDefaults.h │ │ ├── SamplerHostObject.h │ │ ├── QuerySetHostObject.h │ │ ├── ImageBitmapHostObject.h │ │ ├── BindGroupHostObject.h │ │ ├── TextureViewHostObject.h │ │ ├── ContextHostObject.h │ │ ├── ShaderModuleHostObject.h │ │ ├── WGPUWrappers.h │ │ ├── CommandBufferHostObject.h │ │ ├── PipelineLayoutHostObject.h │ │ ├── RenderPipelineHostObject.h │ │ ├── BindGroupLayoutHostObject.h │ │ ├── ComputePipelineHostObject.h │ │ ├── RenderBundleHostObject.h │ │ ├── DeviceHostObject.h │ │ ├── ImageBitmapHostObject.cpp │ │ ├── RenderBundleEncoderHostObject.h │ │ ├── RenderPassEncoderHostObject.h │ │ ├── ComputePassEncoderHostObject.h │ │ ├── ErrorHandler.h │ │ ├── TextureHostObject.h │ │ ├── WGPUContext.h │ │ ├── QuerySetHostObject.cpp │ │ ├── RenderPipelineHostObject.cpp │ │ └── ComputePipelineHostObject.cpp │ ├── android │ │ ├── src │ │ │ ├── main │ │ │ │ ├── AndroidManifestNew.xml │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── webgpu │ │ │ │ │ ├── ExceptionHandler.kt │ │ │ │ │ ├── WebGPUViewManagerImpl.kt │ │ │ │ │ ├── WebgpuPackage.kt │ │ │ │ │ ├── BitmapLoaderFactory.kt │ │ │ │ │ ├── CxxBridge.kt │ │ │ │ │ ├── BlobBitmapLoader.kt │ │ │ │ │ └── HTTPBitmapLoader.kt │ │ │ ├── newarch │ │ │ │ └── com │ │ │ │ │ └── webgpu │ │ │ │ │ └── WebgpuModule.kt │ │ │ └── oldarch │ │ │ │ └── com │ │ │ │ └── webgpu │ │ │ │ └── WebGPUViewManager.kt │ │ └── gradle.properties │ ├── wgsl-babel-transformer │ │ ├── package.json │ │ └── index.js │ ├── src │ │ ├── styles.ts │ │ ├── index.ts │ │ ├── specs │ │ │ ├── index.ts │ │ │ ├── NativeWebgpuModule.ts │ │ │ └── WebgpuNativeComponent.ts │ │ ├── constants.ts │ │ └── native.ts │ ├── .prettierrc.js │ ├── .clang-format │ ├── tsconfig.json │ └── react-native.config.js └── react-native-webgpu-experimental │ ├── babel.config.js │ ├── android │ ├── src │ │ ├── main │ │ │ ├── AndroidManifestNew.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── webgpu │ │ │ │ └── experimental │ │ │ │ ├── CxxBridge.kt │ │ │ │ └── WebgpuExperimentalPackage.kt │ │ └── newarch │ │ │ └── java │ │ │ └── com │ │ │ └── webgpu │ │ │ └── experimental │ │ │ └── WebgpuExperimentalModule.kt │ └── gradle.properties │ ├── src │ ├── index.ts │ ├── specs │ │ ├── index.ts │ │ └── NativeWebgpuExperimentalModule.ts │ └── native.ts │ ├── cxx │ ├── Compression.h │ ├── SocketCallback.h │ ├── InstallExperimentalJSI.h │ ├── ios │ │ └── WGPUExperimentalJsi.h │ ├── android │ │ └── WGPUExperimentalJsi.h │ ├── InstallExperimentalJSI.cpp │ └── VideoPlayer.h │ ├── .prettierrc.js │ ├── .clang-format │ ├── tsconfig.json │ ├── react-native.config.js │ └── types │ └── globals.d.ts ├── .yarnrc.yml ├── .gitmodules ├── scripts ├── zip-libs.sh ├── copy-types.sh ├── copy-headers.sh ├── codegen.sh ├── format-cxx.sh └── build-ios.sh ├── .gitignore ├── README.md ├── turbo.json └── LICENSE /examples/Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /.test* 3 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/.prettierignore: -------------------------------------------------------------------------------- 1 | /.test 2 | /node_modules 3 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | yarnPath: .yarn/releases/yarn-3.6.4.cjs 4 | -------------------------------------------------------------------------------- /examples/Example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "displayName": "Example" 4 | } 5 | -------------------------------------------------------------------------------- /examples/Example/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'react-native', 3 | }; 4 | -------------------------------------------------------------------------------- /examples/Example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-three/.prettierignore: -------------------------------------------------------------------------------- 1 | src/examples/jsm/capabilities/WebGPU.js 2 | -------------------------------------------------------------------------------- /examples/Example/.prettierignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | /.yarn 3 | /android 4 | /ios 5 | /node_modules 6 | /vendor 7 | -------------------------------------------------------------------------------- /examples/Example/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | yarnPath: .yarn/releases/yarn-3.6.4.cjs 4 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:@react-native/babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/metro/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | resolver: { 3 | sourceExts: ['wgsl'], 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/types/wgsl.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.wgsl' { 2 | var value: string; 3 | export default value; 4 | } 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "submodules/wgpu-native"] 2 | path = submodules/wgpu-native 3 | url = https://github.com/gfx-rs/wgpu-native.git 4 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Example 3 | 4 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:@react-native/babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/JSIInstance.cpp: -------------------------------------------------------------------------------- 1 | #include "JSIInstance.h" 2 | 3 | using namespace facebook::jsi; 4 | using namespace wgpu; 5 | -------------------------------------------------------------------------------- /examples/Example/.eslintignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | /.yarn 3 | /android 4 | /ios 5 | /node_modules 6 | /vendor 7 | /babel.config.js 8 | /metro.config.js 9 | -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-three/babel/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: ['@babel/plugin-transform-export-namespace-from'], 3 | }; 4 | -------------------------------------------------------------------------------- /scripts/zip-libs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pushd packages/react-native-webgpu 4 | 5 | zip Bin+Headers.zip -r bin include 6 | 7 | popd 8 | -------------------------------------------------------------------------------- /examples/Example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/debug.keystore -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/shaders/red.frag.wgsl: -------------------------------------------------------------------------------- 1 | @fragment 2 | fn main() -> @location(0) vec4f { 3 | return vec4(1.0, 0.0, 0.0, 1.0); 4 | } 5 | -------------------------------------------------------------------------------- /examples/Example/src/InHouse/Portal/portal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/InHouse/Portal/portal.jpg -------------------------------------------------------------------------------- /packages/react-native-webgpu/android/src/main/AndroidManifestNew.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/Example/src/assets/images/cropImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/assets/images/cropImage.png -------------------------------------------------------------------------------- /scripts/copy-types.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | mkdir -p lib/typescript 4 | cat types/wgsl.d.ts types/webGpuTypes.d.ts > lib/typescript/react-native-webgpu.d.ts 5 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/moon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/moon.jpg -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/android/src/main/AndroidManifestNew.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ThreadWebGpuView'; 2 | export { ENABLE_THREADS, install, installWithThreadId } from './native'; 3 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/src/specs/index.ts: -------------------------------------------------------------------------------- 1 | export const NativeWebgpuExperimentalModule = 2 | require('./NativeWebgpuExperimentalModule').default; 3 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/metro/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-webgpu-metro", 3 | "version": "1.0.0", 4 | "private": true, 5 | "main": "index" 6 | } 7 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/Di-3d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/Di-3d.png -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/saturn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/saturn.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/webgpu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/webgpu.png -------------------------------------------------------------------------------- /examples/Example/src/types/gltf.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.gltf' { 2 | import {GLTF} from '@gltf-transform/core'; 3 | var value: GLTF.IGLTF; 4 | export default value; 5 | } 6 | -------------------------------------------------------------------------------- /examples/Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/GPGPU/GameOfLife/frag.wgsl: -------------------------------------------------------------------------------- 1 | @fragment 2 | fn main(@location(0) cell: f32) -> @location(0) vec4f { 3 | return vec4f(cell, cell, cell, 1.); 4 | } 5 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/wood_albedo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/wood_albedo.png -------------------------------------------------------------------------------- /packages/react-native-webgpu-three/babel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-webgpu-three-babel", 3 | "version": "1.0.0", 4 | "private": true, 5 | "main": "index" 6 | } 7 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-three/metro/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-webgpu-three-metro", 3 | "version": "1.0.0", 4 | "private": true, 5 | "main": "index" 6 | } 7 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/wgsl-babel-transformer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wgsl-babel-transformer", 3 | "version": "1.0.0", 4 | "private": true, 5 | "main": "index" 6 | } 7 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/cubemap/negx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/cubemap/negx.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/cubemap/negy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/cubemap/negy.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/cubemap/negz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/cubemap/negz.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/cubemap/posx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/cubemap/posx.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/cubemap/posy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/cubemap/posy.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/cubemap/posz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/cubemap/posz.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/spiral_height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/spiral_height.png -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/spiral_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/spiral_normal.png -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/toybox_height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/toybox_height.png -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/toybox_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/toybox_normal.png -------------------------------------------------------------------------------- /packages/react-native-webgpu/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/WebGPUFeatures/ReversedZ/fragment.wgsl: -------------------------------------------------------------------------------- 1 | @fragment 2 | fn main( 3 | @location(0) fragColor: vec4f 4 | ) -> @location(0) vec4f { 5 | return fragColor; 6 | } 7 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/brickwall_albedo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/brickwall_albedo.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/brickwall_height.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/brickwall_height.jpg -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/assets/img/brickwall_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/src/WebGPUSamples/assets/img/brickwall_normal.jpg -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /examples/Example/src/utils/constants.ts: -------------------------------------------------------------------------------- 1 | export const THREE_EXAMPLES_BASE_URL = 'https://threejs.org/examples'; 2 | export const WEB_GPU_SAMPLES_BASE_URL = 3 | 'https://webgpu.github.io/webgpu-samples'; 4 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /packages/react-native-webgpu/android/gradle.properties: -------------------------------------------------------------------------------- 1 | Webgpu_kotlinVersion=1.7.0 2 | Webgpu_minSdkVersion=27 3 | Webgpu_targetSdkVersion=31 4 | Webgpu_compileSdkVersion=31 5 | Webgpu_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /examples/Example/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | semi: true, 8 | }; 9 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/WGPUContext.cpp: -------------------------------------------------------------------------------- 1 | #import "WGPUContext.h" 2 | 3 | #import "wgpu.h" 4 | 5 | bool wgpu::WGPUContext::poll(bool wait) { return wgpuDevicePoll(_device->_device, (WGPUBool)wait, NULL); } 6 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/src/styles.ts: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from 'react-native'; 2 | 3 | export const styles = StyleSheet.create({ 4 | fill: { 5 | width: '100%', 6 | height: '100%', 7 | }, 8 | }); 9 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/dark_60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/dark_60@2x.png -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/dark_60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/dark_60@3x.png -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/icon_60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/icon_60@2x.png -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/icon_60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/icon_60@3x.png -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/bin/test-examples: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | cd "$SCRIPT_DIR/.." 5 | node src/index.js examples 6 | -------------------------------------------------------------------------------- /scripts/copy-headers.sh: -------------------------------------------------------------------------------- 1 | OUT_DIR="packages/react-native-webgpu/include" 2 | mkdir -p "$OUT_DIR" 3 | cp submodules/wgpu-native/ffi/wgpu.h \ 4 | submodules/wgpu-native/ffi/webgpu-headers/webgpu.h \ 5 | "$OUT_DIR" 6 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/tinted_60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/tinted_60@2x.png -------------------------------------------------------------------------------- /examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/tinted_60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/ios/Example/Images.xcassets/AppIcon.appiconset/tinted_60@3x.png -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/cxx/Compression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace facebook::jsi; 6 | 7 | namespace wgpu { 8 | Value inflate(Runtime &runtime); 9 | } 10 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanhenry/react-native-webgpu/HEAD/examples/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp -------------------------------------------------------------------------------- /packages/react-native-webgpu/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | semi: true, 8 | }; 9 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/shaders/vertexPositionColor.frag.wgsl: -------------------------------------------------------------------------------- 1 | @fragment 2 | fn main( 3 | @location(0) fragUV: vec2f, 4 | @location(1) fragPosition: vec4f 5 | ) -> @location(0) vec4f { 6 | return fragPosition; 7 | } 8 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/cxx/SocketCallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace facebook::jsi; 6 | 7 | namespace wgpu { 8 | Value socketCallback(Runtime &runtime); 9 | } 10 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | semi: true, 8 | }; 9 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-three/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | semi: true, 8 | }; 9 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | semi: true, 8 | }; 9 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/src/index.js: -------------------------------------------------------------------------------- 1 | if (process.argv.includes('package')) { 2 | await import('./package/package.js'); 3 | } else if (process.argv.includes('examples')) { 4 | await import('./examples/examples.js'); 5 | } 6 | -------------------------------------------------------------------------------- /examples/Example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:@react-native/babel-preset'], 3 | plugins: [ 4 | ...require('react-native-webgpu-three/babel').plugins, 5 | 'react-native-reanimated/plugin', 6 | ], 7 | }; 8 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/android/Thread.cpp: -------------------------------------------------------------------------------- 1 | #include "Thread.h" 2 | 3 | #include 4 | 5 | using namespace wgpu; 6 | 7 | void Thread::run(std::function &&fn) { _invoker->invokeAsync(std::move(fn)); } 8 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/ios/Thread.mm: -------------------------------------------------------------------------------- 1 | #include "Thread.h" 2 | #import "React-callinvoker/ReactCommon/CallInvoker.h" 3 | 4 | using namespace wgpu; 5 | 6 | void Thread::run(std::function &&fn) { _invoker->invokeAsync(std::move(fn)); } 7 | -------------------------------------------------------------------------------- /examples/Example/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native', 4 | rules: { 5 | 'react/react-in-jsx-scope': 'off', 6 | 'no-bitwise': 'off', 7 | 'no-dupe-class-members': 'off', 8 | semi: 'off', 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/android/gradle.properties: -------------------------------------------------------------------------------- 1 | WebgpuExperimental_kotlinVersion=1.7.0 2 | WebgpuExperimental_minSdkVersion=27 3 | WebgpuExperimental_targetSdkVersion=31 4 | WebgpuExperimental_compileSdkVersion=31 5 | WebgpuExperimental_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /examples/Example/src/types/navigationTypes.ts: -------------------------------------------------------------------------------- 1 | import type {Examples, Example} from '../Components/ExampleScreen'; 2 | 3 | export type Routes = { 4 | root: undefined; 5 | examples: { 6 | name: Examples; 7 | }; 8 | example: { 9 | name: Example; 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/ios/WGPULog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define WGPU_LOG_INFO(...) os_log_with_type(OS_LOG_DEFAULT, OS_LOG_TYPE_INFO, __VA_ARGS__) 6 | #define WGPU_LOG_ERROR(...) os_log_with_type(OS_LOG_DEFAULT, OS_LOG_TYPE_ERROR, __VA_ARGS__) 7 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/InstallRootJSI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "Surface.h" 5 | 6 | using namespace facebook::jsi; 7 | 8 | namespace wgpu { 9 | 10 | void installRootJSI(Runtime& runtime, std::shared_ptr jsiInstance); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/GPGPU/BitonicSort/atomicToZero.wgsl: -------------------------------------------------------------------------------- 1 | @group(0) @binding(3) var counter: atomic; 2 | 3 | @compute @workgroup_size(1, 1, 1) 4 | fn atomicToZero() { 5 | let counterValue = atomicLoad(&counter); 6 | atomicSub(&counter, counterValue); 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # MacOS 2 | __MACOSX 3 | .DS_Store 4 | *.pem 5 | 6 | # Yarn 7 | .yarn/* 8 | !.yarn/patches 9 | !.yarn/plugins 10 | !.yarn/releases 11 | !.yarn/sdks 12 | !.yarn/versions 13 | 14 | # VSCode 15 | /.vscode 16 | 17 | /.idea 18 | /node_modules 19 | **/react-native-webgpu-*.tgz 20 | /.test* 21 | -------------------------------------------------------------------------------- /examples/Example/src/utils/launchArguments.ts: -------------------------------------------------------------------------------- 1 | import {LaunchArguments as RNLaunchArguments} from 'react-native-launch-arguments'; 2 | 3 | interface LaunchArguments { 4 | example?: string; 5 | callbackid?: string; 6 | } 7 | 8 | export const launchArguments = RNLaunchArguments.value(); 9 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/bin/test-package: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | cd "$SCRIPT_DIR/.." 5 | [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 6 | rvm use 3.3.5 7 | node src/index.js package 8 | -------------------------------------------------------------------------------- /examples/Example/src/Components/stats/HudLabel.tsx: -------------------------------------------------------------------------------- 1 | import {Text} from 'react-native'; 2 | import {hudStyles} from './hudStyles'; 3 | 4 | type HudLabelProps = { 5 | text: string; 6 | }; 7 | 8 | export const HudLabel = ({text}: HudLabelProps) => ( 9 | {text} 10 | ); 11 | -------------------------------------------------------------------------------- /examples/Example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@react-native/typescript-config/tsconfig.json", 3 | "include": [ 4 | "**/*", 5 | "../../node_modules/react-native-webgpu/lib/typescript/react-native-webgpu.d.ts", 6 | "../../node_modules/react-native-webgpu-experimental/types/globals.d.ts" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/CreateImageBitmap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "JSIInstance.h" 6 | 7 | using namespace facebook::jsi; 8 | 9 | namespace wgpu { 10 | 11 | Function createImageBitmap(Runtime &runtime, std::shared_ptr jsiInstance); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /scripts/codegen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 6 | 7 | pushd examples/Example 8 | 9 | yarn pod:install 10 | 11 | pushd android 12 | ./gradlew react-native-webgpu:generateCodegenArtifactsFromSchema 13 | popd 14 | 15 | popd 16 | -------------------------------------------------------------------------------- /examples/Example/src/Components/controls/dat.gui/incrementingId.ts: -------------------------------------------------------------------------------- 1 | let ids: Record = {}; 2 | 3 | export const __resetIds = () => { 4 | ids = {}; 5 | }; 6 | 7 | export const getId = (key: string) => { 8 | ids[key] ??= 0; 9 | const id = ids[key]; 10 | ids[key] += 1; 11 | return id; 12 | }; 13 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/cxx/InstallExperimentalJSI.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "JSIInstance.h" 6 | 7 | using namespace facebook::jsi; 8 | 9 | namespace wgpu { 10 | void installExperimentalJSI(Runtime& runtime, std::shared_ptr jsiInstance); 11 | } 12 | -------------------------------------------------------------------------------- /examples/Example/ios/Example.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/android/WGPULog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define WGPU_LOG_INFO(...) __android_log_buf_print(LOG_ID_DEFAULT, ANDROID_LOG_INFO, "WebGPU_JNI", __VA_ARGS__) 6 | #define WGPU_LOG_ERROR(...) __android_log_buf_print(LOG_ID_DEFAULT, ANDROID_LOG_ERROR, "WebGPU_JNI", __VA_ARGS__) 7 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/src/index.ts: -------------------------------------------------------------------------------- 1 | import './constants'; 2 | import './native'; 3 | 4 | export * from './WebGpuView'; 5 | export * from './types'; 6 | export { install, installWithThreadId } from './native'; 7 | export type { OnCreateSurfaceEvent } from './specs'; 8 | export { WebgpuNativeComponent, Backends } from './specs'; 9 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/src/specs/index.ts: -------------------------------------------------------------------------------- 1 | export type { OnCreateSurfaceEvent } from './WebgpuNativeComponent'; 2 | export { Backends } from './WebgpuNativeComponent'; 3 | export const NativeWebgpuModule = require('./NativeWebgpuModule').default; 4 | export const WebgpuNativeComponent = require('./WebgpuNativeComponent').default; 5 | -------------------------------------------------------------------------------- /examples/Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /examples/Example/ios/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/shaders/triangle.vert.wgsl: -------------------------------------------------------------------------------- 1 | @vertex 2 | fn main( 3 | @builtin(vertex_index) VertexIndex : u32 4 | ) -> @builtin(position) vec4f { 5 | var pos = array( 6 | vec2(0.0, 0.5), 7 | vec2(-0.5, -0.5), 8 | vec2(0.5, -0.5) 9 | ); 10 | 11 | return vec4f(pos[VertexIndex], 0.0, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /examples/Example/src/Components/controls/react/ControlLabel.tsx: -------------------------------------------------------------------------------- 1 | import {Text} from 'react-native'; 2 | import {controlsStyles} from './controlsStyles'; 3 | 4 | type ControlLabelProps = { 5 | text: string; 6 | }; 7 | 8 | export const ControlLabel = ({text}: ControlLabelProps) => { 9 | return {text}; 10 | }; 11 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/src/specs/NativeWebgpuModule.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import type { TurboModule } from 'react-native'; 3 | import { TurboModuleRegistry } from 'react-native'; 4 | 5 | interface Spec extends TurboModule { 6 | installWithThreadId(threadId: string): boolean; 7 | } 8 | 9 | export default TurboModuleRegistry.get('WGPUJsi'); 10 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-tests/src/utils/queue.js: -------------------------------------------------------------------------------- 1 | export class Queue { 2 | _tasks = []; 3 | push(task) { 4 | this._tasks.push(task); 5 | } 6 | 7 | async execute() { 8 | while (true) { 9 | const [task] = this._tasks.splice(0, 1); 10 | if (!task) { 11 | break; 12 | } 13 | await task(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/Example/src/Components/globalStyles.ts: -------------------------------------------------------------------------------- 1 | import {StyleSheet} from 'react-native'; 2 | 3 | export const globalStyles = StyleSheet.create({ 4 | fill: { 5 | width: '100%', 6 | height: '100%', 7 | }, 8 | pressed: { 9 | opacity: 0.6, 10 | }, 11 | centerContents: { 12 | justifyContent: 'center', 13 | alignItems: 'center', 14 | }, 15 | }); 16 | -------------------------------------------------------------------------------- /examples/Example/src/Components/stats/HudContainer.tsx: -------------------------------------------------------------------------------- 1 | import {PropsWithChildren} from 'react'; 2 | import {View} from 'react-native'; 3 | import {hudStyles} from './hudStyles'; 4 | 5 | type HudContainerProps = PropsWithChildren; 6 | 7 | export const HudContainer = ({children}: HudContainerProps) => { 8 | return {children}; 9 | }; 10 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/WebGPUFeatures/ReversedZ/fragmentTextureQuad.wgsl: -------------------------------------------------------------------------------- 1 | @group(0) @binding(0) var depthTexture: texture_depth_2d; 2 | 3 | @fragment 4 | fn main( 5 | @builtin(position) coord : vec4f 6 | ) -> @location(0) vec4f { 7 | let depthValue = textureLoad(depthTexture, vec2i(floor(coord.xy)), 0); 8 | return vec4f(depthValue, depthValue, depthValue, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /examples/Example/src/Components/controls/react/ControlInput.tsx: -------------------------------------------------------------------------------- 1 | import {PropsWithChildren} from 'react'; 2 | import {View} from 'react-native'; 3 | import {controlsStyles} from './controlsStyles'; 4 | 5 | type ControlInputProps = PropsWithChildren; 6 | 7 | export const ControlInput = ({children}: ControlInputProps) => { 8 | return {children}; 9 | }; 10 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/WebGPUFeatures/ReversedZ/vertexTextureQuad.wgsl: -------------------------------------------------------------------------------- 1 | @vertex 2 | fn main( 3 | @builtin(vertex_index) VertexIndex : u32 4 | ) -> @builtin(position) vec4f { 5 | var pos = array( 6 | vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0), 7 | vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0) 8 | ); 9 | 10 | return vec4(pos[VertexIndex], 0.0, 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/cxx/ios/WGPUExperimentalJsi.h: -------------------------------------------------------------------------------- 1 | #ifdef RCT_NEW_ARCH_ENABLED 2 | 3 | #import 4 | 5 | @interface WGPUExperimentalJsi : NSObject 6 | #else 7 | #import 8 | 9 | @interface WGPUExperimentalJsi : NSObject 10 | #endif 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /examples/Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { includeBuild("../../../node_modules/@react-native/gradle-plugin") } 2 | plugins { id("com.facebook.react.settings") } 3 | extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } 4 | rootProject.name = 'Example' 5 | include ':app' 6 | includeBuild('../../../node_modules/@react-native/gradle-plugin') 7 | -------------------------------------------------------------------------------- /examples/Example/src/InHouse/Thread.tsx: -------------------------------------------------------------------------------- 1 | import {ThreadWebGpuView} from 'react-native-webgpu-experimental'; 2 | import {globalStyles} from '../Components/globalStyles'; 3 | import {Square} from '../Components/Square'; 4 | 5 | export const Thread = () => { 6 | return ( 7 | 8 | 9 | 10 | ); 11 | }; 12 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/GraphicsTechniques/DeferredRendering/vertexTextureQuad.wgsl: -------------------------------------------------------------------------------- 1 | @vertex 2 | fn main( 3 | @builtin(vertex_index) VertexIndex : u32 4 | ) -> @builtin(position) vec4f { 5 | var pos = array( 6 | vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0), 7 | vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0), 8 | ); 9 | 10 | return vec4f(pos[VertexIndex], 0.0, 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /examples/Example/src/Components/controls/dat.gui/incrementingId.test.ts: -------------------------------------------------------------------------------- 1 | import {__resetIds, getId} from './incrementingId'; 2 | 3 | describe('getId', () => { 4 | beforeEach(() => { 5 | __resetIds(); 6 | }); 7 | 8 | it('gets id', () => { 9 | expect(getId('test')).toBe(0); 10 | expect(getId('test')).toBe(1); 11 | __resetIds(); 12 | expect(getId('test')).toBe(0); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/BasicGraphics/TexturedCube/sampleTextureMixColor.frag.wgsl: -------------------------------------------------------------------------------- 1 | @group(0) @binding(1) var mySampler: sampler; 2 | @group(0) @binding(2) var myTexture: texture_2d; 3 | 4 | @fragment 5 | fn main( 6 | @location(0) fragUV: vec2f, 7 | @location(1) fragPosition: vec4f 8 | ) -> @location(0) vec4f { 9 | return textureSample(myTexture, mySampler, fragUV) * fragPosition; 10 | } 11 | -------------------------------------------------------------------------------- /examples/Example/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/Example/src/InHouse/ResizeCanvas/triangle.wgsl: -------------------------------------------------------------------------------- 1 | struct Uniforms { 2 | ortho: mat4x4f, 3 | } 4 | 5 | @group(0) @binding(0) var uniforms: Uniforms; 6 | 7 | @vertex 8 | fn v_main( 9 | @location(0) position: vec4f, 10 | ) -> @builtin(position) vec4f { 11 | return uniforms.ortho * position; 12 | } 13 | 14 | @fragment 15 | fn f_main() -> @location(0) vec4f { 16 | return vec4f(0.0, 1.0, 0.0, 1.0); 17 | } 18 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/android/WGPUJsi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace facebook::jsi; 6 | 7 | namespace facebook::react { 8 | 9 | class WGPUJsi : public NativeWebgpuModuleCxxSpec { 10 | public: 11 | WGPUJsi(std::shared_ptr jsInvoker); 12 | 13 | bool installWithThreadId(Runtime &rt, String threadId); 14 | }; 15 | } // namespace facebook::react 16 | -------------------------------------------------------------------------------- /examples/Example/babel/gltf-babel-transformer.js: -------------------------------------------------------------------------------- 1 | const babelTransformer = require('react-native-webgpu/wgsl-babel-transformer'); 2 | 3 | module.exports = {...babelTransformer}; 4 | module.exports.transform = function (options) { 5 | if (options.filename.endsWith('.gltf')) { 6 | options.src = `const contents = ${options.src}; 7 | export default contents;`; 8 | } 9 | return babelTransformer.transform(options); 10 | }; 11 | -------------------------------------------------------------------------------- /examples/Example/src/InHouse/AnimateCanvas/triangle.wgsl: -------------------------------------------------------------------------------- 1 | struct Uniforms { 2 | ortho: mat4x4f, 3 | } 4 | 5 | @group(0) @binding(0) var uniforms: Uniforms; 6 | 7 | @vertex 8 | fn v_main( 9 | @location(0) position: vec4f, 10 | ) -> @builtin(position) vec4f { 11 | return uniforms.ortho * position; 12 | } 13 | 14 | @fragment 15 | fn f_main() -> @location(0) vec4f { 16 | return vec4f(0.0, 1.0, 0.0, 1.0); 17 | } 18 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 2 3 | ContinuationIndentWidth: 2 4 | ObjCBlockIndentWidth: 2 5 | BracedInitializerIndentWidth: 2 6 | ConstructorInitializerIndentWidth: 2 7 | PPIndentWidth: 2 8 | UseTab: Never 9 | ColumnLimit: 120 10 | LambdaBodyIndentation: OuterScope 11 | Macros: 12 | - WGPU_FUNC_FROM_HOST_FUNC(x, y, z)=fn([]() 13 | - RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(x, y)=- (x)y 14 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 2 3 | ContinuationIndentWidth: 2 4 | ObjCBlockIndentWidth: 2 5 | BracedInitializerIndentWidth: 2 6 | ConstructorInitializerIndentWidth: 2 7 | PPIndentWidth: 2 8 | UseTab: Never 9 | ColumnLimit: 120 10 | LambdaBodyIndentation: OuterScope 11 | Macros: 12 | - WGPU_FUNC_FROM_HOST_FUNC(x, y, z)=fn([]() 13 | - RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(x, y)=- (x)y 14 | -------------------------------------------------------------------------------- /examples/Example/src/Components/Square.tsx: -------------------------------------------------------------------------------- 1 | import {Keyboard, StyleSheet, View} from 'react-native'; 2 | import type {ReactNode} from 'react'; 3 | 4 | export const Square = ({children}: {children: ReactNode}) => ( 5 | 6 | {children} 7 | 8 | ); 9 | 10 | const styles = StyleSheet.create({ 11 | container: { 12 | width: '100%', 13 | aspectRatio: 1, 14 | }, 15 | }); 16 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/src/specs/NativeWebgpuExperimentalModule.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | import type { TurboModule } from 'react-native'; 3 | import { TurboModuleRegistry } from 'react-native'; 4 | 5 | interface Spec extends TurboModule { 6 | readonly getConstants: () => { ENABLE_THREADS: boolean }; 7 | 8 | installWithThreadId(threadId: string): boolean; 9 | } 10 | 11 | export default TurboModuleRegistry.get('WGPUExperimentalJsi'); 12 | -------------------------------------------------------------------------------- /examples/Example/src/Components/stats/hudStyles.ts: -------------------------------------------------------------------------------- 1 | import {StyleSheet} from 'react-native'; 2 | 3 | export const hudStyles = StyleSheet.create({ 4 | container: { 5 | ...StyleSheet.absoluteFillObject, 6 | bottom: undefined, 7 | backgroundColor: '#00000080', 8 | paddingVertical: 2, 9 | paddingHorizontal: 4, 10 | gap: 2, 11 | }, 12 | text: { 13 | padding: 0, 14 | margin: 0, 15 | color: '#FFF', 16 | flex: 1, 17 | }, 18 | }); 19 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-three/src/constNodePatch.js: -------------------------------------------------------------------------------- 1 | import ConstNode from 'three/examples/jsm/nodes/core/ConstNode'; 2 | 3 | ConstNode.prototype.generate = function (builder, output) { 4 | const type = this.getNodeType(builder); 5 | 6 | if (type === 'float' && ['int', 'uint'].includes(output)) { 7 | return `${Math.round(parseFloat(this.generateConst(builder)))}`; 8 | } 9 | 10 | return builder.format(this.generateConst(builder), type, output); 11 | }; 12 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/WebGPUFeatures/ReversedZ/fragmentPrecisionErrorPass.wgsl: -------------------------------------------------------------------------------- 1 | @group(1) @binding(0) var depthTexture: texture_depth_2d; 2 | 3 | @fragment 4 | fn main( 5 | @builtin(position) coord: vec4f, 6 | @location(0) clipPos: vec4f 7 | ) -> @location(0) vec4f { 8 | let depthValue = textureLoad(depthTexture, vec2i(floor(coord.xy)), 0); 9 | let v : f32 = abs(clipPos.z / clipPos.w - depthValue) * 2000000.0; 10 | return vec4f(v, v, v, 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /examples/Example/src/InHouse/CWTriangle/cw-triangle.wgsl: -------------------------------------------------------------------------------- 1 | @vertex 2 | fn v_main( 3 | @builtin(vertex_index) VertexIndex : u32 4 | ) -> @builtin(position) vec4f { 5 | var pos = array( // triangle is drawn clockwise 6 | vec2(0.0, 0.5), 7 | vec2(0.5, -0.5), 8 | vec2(-0.5, -0.5) 9 | ); 10 | 11 | return vec4f(pos[VertexIndex], 0.0, 1.0); 12 | } 13 | 14 | @fragment 15 | fn f_main() -> @location(0) vec4f { 16 | return vec4f(1.0, 1.0, 0.0, 1.0); 17 | } 18 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/ios/UIImage+Bitmap.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | using namespace facebook::jsi; 5 | 6 | typedef struct BitmapImage { 7 | uint8_t* _Nonnull data; 8 | size_t size; 9 | uint32_t width; 10 | uint32_t height; 11 | } BitmapImage; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface UIImage (Bitmap) 16 | 17 | - (BOOL)createBitmapImage:(BitmapImage*)bitmapImage; 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/ios/WGPUObjCInstance.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | 5 | NS_ASSUME_NONNULL_BEGIN 6 | 7 | @interface WGPUObjCInstance : NSObject 8 | 9 | + (WGPUObjCInstance *)shared; 10 | 11 | @property(nonatomic, weak) RCTBlobManager *blobManager; 12 | 13 | - (void)loadModules:(RCTModuleRegistry *)moduleRegistry; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/android/src/main/java/com/webgpu/experimental/CxxBridge.kt: -------------------------------------------------------------------------------- 1 | package com.webgpu.experimental 2 | 3 | import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder 4 | 5 | class CxxBridge { 6 | companion object { 7 | init { 8 | System.loadLibrary("react-native-webgpu-experimental") 9 | } 10 | 11 | external fun installJsi(threadId: String, jsiRuntimeRef: Long, jsCallInvokerHolder: CallInvokerHolder): Boolean 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/android/src/main/java/com/webgpu/ExceptionHandler.kt: -------------------------------------------------------------------------------- 1 | package com.webgpu 2 | 3 | import com.facebook.proguard.annotations.DoNotStrip 4 | import com.facebook.react.bridge.ReactApplicationContext 5 | import com.facebook.react.common.JavascriptException 6 | 7 | @DoNotStrip 8 | class ExceptionHandler(val context: ReactApplicationContext) { 9 | @DoNotStrip 10 | fun handleException(message: String) { 11 | context.handleException(JavascriptException(message)) 12 | } 13 | } -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/Thread.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace facebook::react { 7 | class CallInvoker; 8 | } 9 | 10 | namespace wgpu { 11 | 12 | class Thread { 13 | public: 14 | explicit Thread(std::shared_ptr invoker) : _invoker(invoker) {} 15 | void run(std::function&&); 16 | 17 | private: 18 | std::shared_ptr _invoker; 19 | }; 20 | 21 | } // namespace wgpu 22 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/ios/WGPUJsi.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import "ContextHostObject.h" 5 | #import "WGPUContext.h" 6 | #import "webgpu.h" 7 | #import "wgpu.h" 8 | 9 | #ifdef RCT_NEW_ARCH_ENABLED 10 | 11 | #import 12 | 13 | @interface WGPUJsi : NSObject 14 | #else 15 | #import 16 | 17 | @interface WGPUJsi : NSObject 18 | #endif 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /examples/Example/src/Components/stats/HudText.tsx: -------------------------------------------------------------------------------- 1 | import {forwardRef} from 'react'; 2 | import {TextInput, TextInputProps} from 'react-native'; 3 | import {hudStyles} from './hudStyles'; 4 | 5 | export const HudText = forwardRef( 6 | ({style, ...props}, ref) => ( 7 | 14 | ), 15 | ); 16 | HudText.displayName = 'HudText'; 17 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/JSIInstance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "Thread.h" 8 | 9 | using namespace facebook::jsi; 10 | using namespace wgpu; 11 | 12 | namespace wgpu { 13 | 14 | class JSIInstance { 15 | public: 16 | explicit JSIInstance(Runtime &rt, std::shared_ptr thread) : runtime(rt), jsThread(std::move(thread)) {} 17 | Runtime &runtime; 18 | std::shared_ptr jsThread; 19 | }; 20 | 21 | } // namespace wgpu 22 | -------------------------------------------------------------------------------- /examples/Example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/meshes/teapot.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error implicit any, missing declaration file 2 | import teapotData from 'teapot'; 3 | import {computeSurfaceNormals} from './utils'; 4 | 5 | export const mesh = { 6 | positions: teapotData.positions as [number, number, number][], 7 | triangles: teapotData.cells as [number, number, number][], 8 | normals: [] as [number, number, number][], 9 | }; 10 | 11 | // Compute surface normals 12 | mesh.normals = computeSurfaceNormals(mesh.positions, mesh.triangles); 13 | -------------------------------------------------------------------------------- /examples/Example/src/WebGPUSamples/BasicGraphics/FractalCube/sampleSelf.frag.wgsl: -------------------------------------------------------------------------------- 1 | @binding(1) @group(0) var mySampler: sampler; 2 | @binding(2) @group(0) var myTexture: texture_2d; 3 | 4 | @fragment 5 | fn main( 6 | @location(0) fragUV: vec2f, 7 | @location(1) fragPosition: vec4f 8 | ) -> @location(0) vec4f { 9 | let texColor = textureSample(myTexture, mySampler, fragUV * 0.8 + vec2(0.1)); 10 | let f = select(1.0, 0.0, length(texColor.rgb - vec3(0.5)) < 0.01); 11 | return f * texColor + (1.0 - f) * fragPosition; 12 | } 13 | -------------------------------------------------------------------------------- /examples/Example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /packages/react-native-webgpu-experimental/cxx/android/WGPUExperimentalJsi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace facebook::jsi; 6 | 7 | namespace facebook::react { 8 | 9 | class WGPUExperimentalJsi : public NativeWebgpuExperimentalModuleCxxSpec { 10 | public: 11 | WGPUExperimentalJsi(std::shared_ptr jsInvoker); 12 | 13 | Object getConstants(Runtime &rt); 14 | bool installWithThreadId(Runtime &rt, String threadId); 15 | }; 16 | } // namespace facebook::react 17 | -------------------------------------------------------------------------------- /packages/react-native-webgpu/cxx/ios/WGPUWebGPUViewManager.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "WGPUWebGPUView.h" 4 | 5 | @interface WGPUWebGPUViewManager : RCTViewManager 6 | @end 7 | 8 | @implementation WGPUWebGPUViewManager 9 | 10 | RCT_EXPORT_MODULE(WGPUWebGPUView) 11 | RCT_EXPORT_VIEW_PROPERTY(onCreateSurface, RCTBubblingEventBlock) 12 | RCT_EXPORT_VIEW_PROPERTY(pollSize, BOOL) 13 | 14 | - (UIView*)view { 15 | WGPUWebGPUView* view = [[WGPUWebGPUView alloc] init]; 16 | return view; 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /examples/Example/src/Components/controls/react/ControlButton.tsx: -------------------------------------------------------------------------------- 1 | import {Button, ButtonProps} from 'react-native'; 2 | import {controlForegroundColor} from './controlsStyles'; 3 | 4 | type ControlButtonProps = Pick; 5 | 6 | export const ControlButton = ({ 7 | title, 8 | onPress, 9 | disabled, 10 | }: ControlButtonProps) => { 11 | return ( 12 |