Current API
texture.write(image);
texture.write([layer0, layer1, layer2]);
texture.write(rawBytes, mipLevel);
Useful for whole-texture writes, but limited when it comes to capabilities.
Proposed API Shape
Exact Image Writes
Writes as-is. If the image size does not match the target write area, throw.
Explicit Resize
texture.write(image, { resize: true });
Resize is opt-in (since it involves running an entire resample pipeline).
Region Writes
texture.write({
source: image,
origin: [32, 16],
size: [128, 128],
});
Writes into a destination rectangle.
Source Crop
texture.write({
source: image,
sourceOrigin: [8, 8],
sourceSize: [64, 64],
origin: [128, 32],
});
Crops source pixels before writing.
Blob Resize Path
await texture.writeAsync({
source: blob,
resize: true,
});
A resize path that does not involve running WebGPU pipelines but is asynchronous.
So conceptually:
const bitmap = await createImageBitmap(blob, { resizeWidth, resizeHeight });
texture.write({ source: bitmap, size, resize: false });
Single-Channel Writes
texture.write({
channels: {
r: roughnessMap,
g: metalnessMap,
b: aoMap,
a: maskMap,
},
});
Single-Channel With Region
texture.write({
channels: {
r: roughnessMap,
},
origin: [32, 16],
size: [128, 128],
});
Current API
Useful for whole-texture writes, but limited when it comes to capabilities.
Proposed API Shape
Exact Image Writes
Writes as-is. If the image size does not match the target write area, throw.
Explicit Resize
Resize is opt-in (since it involves running an entire resample pipeline).
Region Writes
Writes into a destination rectangle.
Source Crop
Crops source pixels before writing.
Blob Resize Path
A resize path that does not involve running WebGPU pipelines but is asynchronous.
So conceptually:
Single-Channel Writes
Single-Channel With Region