WebAssembly / WebAssembly/wasi-webgpu

Open question: Should we use the wit type system to enforce webgpu rules?

Open
#43 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
220
Forks
15
PR merge metrics
No merged PRs in 30d

Description

WebGPU is written for JS, and is constraint by JS limitations, while wit has a type-system.
Should we use this type-system to enforce WebGPU rules, or should we rather keep the API as close as possible to the official WebGPU API?

Here are a couple of cases where we could enforce rules with the type system:
Take ownership in end/finish method calls

WebGPU has some methods that are meant to be called at the end
GPURenderPassEncoder and GPUComputePassEncoder have .end() methods, and GPUCommandEncoder has the .finish() method, and they're not supposed to be used after calling .end()/.finish().
We could change these to static methods that take ownership, and therefore enforce the rule with the type system.
This would change the way you'd call this method from encoder.end() to GPURenderPassEncoder.end(encoder). A bit clunkier, but enforces the ownership rule.
See also #9

#### Take ownership in requestDevice
requestDevice cnd only be called once per GPUAdapter (see This is a one-time action...)
Similar to the previous point, we could make requestDevice take ownership of GPUAdapter

See https://github.com/WebAssembly/wasi-gfx/issues/43#issuecomment-2678994855 why this is not applicable

BindGroupLayoutEntry entry as variant

The entry in createBindGroupLayout's descriptor, has to have exactly one of the following: buffer/sampler/texture/storageTexture(or externalTexture).
In JS this is a dictionary and the user has to set exactly one of them, but in wit we can simply change it to a variant. That would enforce that exactly one is set.
See also webgpu-native/webgpu-headers/issues/438

Contributor guide

No contributing guide indexed for this repository

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 comparing the WebGPU API references linked in the issue with the proposed WIT ownership and variant designs, then read #9 and the linked webgpu-native/webgpu-headers issue. Done means reaching and documenting a project decision on whether WIT should enforce these rules or preserve the official WebGPU API shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.