WebGPU C API rewritten to match Dawn's webgpu.h
Component: WebGPU | 2eb1451
WebGPU.framework is WebKit's Metal-backed implementation of the WebGPU C API. The GPU process runs it on behalf of WebContent, which reaches it through the WebGPU IPC and proxy layers. Entry points such as wgpuBufferMapAsync, wgpuInstanceRequestAdapter, and wgpuAdapterRequestDevice were callback-based, with completion and lifetime rules that depended on the caller.
The C API (WebGPU.h and the Metal entry points) now matches the webgpu.h that Dawn/ANGLE builds with. It adopts string views, futures with callback-info structs, pointer+size arguments, status returns, _Undefined enum defaults and _BindingNotUsed, and chained structs for external textures and max draw count. The instance owns pending futures, and wgpuInstanceWaitAny drives pending work until a future completes or the wait times out. wgpuAdapterGetInfo allocates strings that wgpuAdapterInfoFreeMembers frees, and wgpuDeviceGetQueue now returns a new reference.
Before: After:
wgpuXRequest(desc, cb, userdata) wgpuXRequest(desc, CallbackInfo)
└─► work ──► cb(userdata) └─► Instance::createFuture() ──► WGPUFuture
wgpuInstanceWaitAny(futures[], n, timeout)
└─► loop: run pending instance work ──► completeFuture() ──► callback
until anyFutureCompleted() or timeout
Significance
One C header can now sit under both the Dawn and WebKit Metal backends, at the cost of changed async, string and refcount contracts across nearly every entry point.
Audit directions
Every new ownership contract here is a potential lifetime bug in a privileged process. Check future and callback-info lifetime against instance teardown, callbacks firing after a device, adapter, or buffer is destroyed, double completion, and userdata handling. wgpuInstanceWaitAny runs pending work synchronously, so look for re-entrancy, mutation of the future set during iteration, timeout edges, and invalid or already-completed futures. The manual alloc/free in wgpuAdapterGetInfo/wgpuAdapterInfoFreeMembers (toAPIAllocated, freeAllocated) invites mismatched allocators, double free, free of an uninitialized struct, and string-view length vs NUL-termination confusion, the same class as this week's EME bug. Callers of wgpuDeviceGetQueue may now leak or over-release. The rewritten wgpuBufferGetMappedRange, wgpuBufferGetConstMappedRange, wgpu*SetBindGroup, and wgpuCommandEncoderFinish conversions need bounds, size, and null/zero-count checks. Chained-struct traversal with unexpected sType values and sentinel values reaching Metal unvalidated round out the list.