React Native WebGPU

Offscreen Canvas

Headless GPU renderings with CPU readbacks

GPUOffscreenCanvas is a helper shim that mimics the Web OffscreenCanvas API. It is offered as a convenience to quickly produce offscreen renderings with CPU readback.

Basic usage

import {  } from "react-native-webgpu";

const  = new (256, 256);
const  = .("webgpu")!;

const  = await .();
.({ , : "rgba8unorm" });

// encode render passes into the offscreen target…
..([.()]);

const  = await .(); // CPU readback

getImageData() copies the canvas texture into a buffer, maps it, and resolves with { data, width, height, format }, where data holds 4 bytes per pixel, row by row. Because WebGPU copies rows in multiples of 256 bytes, the canvas width must be a multiple of 64.

It is meant for tests, snapshots and one-off exports; to read pixels repeatedly, copy the texture into a reusable GPUBuffer of your own with copyTextureToBuffer.

On this page