Skip to content

[RFC] impr: Extend texture.write() capabilities #2633

Description

@reczkok

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

texture.write(image);

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],
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions