software-mansion / software-mansion/TypeGPU

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

Open
#2,633 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
3.2k
Forks
122
Avg merge
3d 5h
Merged PRs (30d)
34

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing texture.write() implementation and any writeAsync entry point. Compare their current handling with the proposed exact, resize, region, crop, blob, and channel forms. Done means the agreed API behavior is implemented and each documented usage shape is covered by appropriate validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.