Repository navigation
Description
With Wasm memory64 proposal, Wasm pointer size becomes 64-bit.
In this build mode, in Wasm->JS boundary, 64-bit numbers are marshalled using BigInts.
This has an effect to WebGPU API in places where a TypedArray + offset + size are passed. Currently it looks like there are only two such places in the WebGPU API:
GPUQueue.writeBuffer(
GPUBuffer buffer,
GPUSize64 bufferOffset,
[AllowShared] BufferSource data,
optional GPUSize64 dataOffset = 0,
optional GPUSize64 size);
GPUQueue.writeTexture(
GPUImageCopyTexture destination,
[AllowShared] BufferSource data,
dataLayout: {
GPUSize64 offset,
GPUSize32 bytesPerRow,
GPUSize32 rowsPerImage
},
GPUExtent3D size);To be able to express the full 64-bit address space, the GPUSize64 fields bufferOffset, dataOffset, size and offset would need to be able to pass in BigInts.
GPUSize64 is currently marked as
typedef [EnforceRange] unsigned long long GPUSize64;does that already register as BigInt-capable to JS? Or how does unsigned long long in the IDL interact with JS today? (currently in practice one can pass Numbers in such places at least)
Should that simply change to
typedef (unsigned long long or BigInt) GPUSize64;?
Alternatively if BigInts are not so hot here, the WebGPU API could make a deliberate choice to restrict to enabling only 53-bit address spaces by restricting to the safe integer range of a double Number. Though that would have an adverse effect to restrict Wasm memory64-enabled builds to instead be "memory53" builds. (iiuc the current Wasm64 proposal is for a full 64-bit address space, not for a restricted 53 bits address space)
CC @kripken , @binji, @rossberg, @aardappel .
Activity
juj commentedon Nov 4, 2021
This scenario affects WebGL API even wider since it has more of these kinds of entry points, though before opening an issue there, it is probably good to discuss what WebGPU will do on this front. CC @kenrussell
aardappel commentedon Nov 4, 2021
If
unsigned long longmeans it currently supports 53-bits, then that is sufficient for the foreseeable future. The bigger issue is that the Wasm boundary will always produce BigInt, so that will need to be supported regardless.juj commentedon Nov 4, 2021
Are address space techniques pushed out of scope for Wasm memory64? There is this ticket WebAssembly/memory64#4 that requests this support. I think specs like WebGPU that are likely to leverage wasm memory64 would be good to coordinate early towards memory64's intended end state, to avoid needing to do a second "patch-up" iteration of the spec after the fact?
aardappel commentedon Nov 4, 2021
I'd love to have some of these features in the linked issue obviously, but getting them in Wasm will not be a trivial process.
And there's a difference between "Wasm Memory64" and "Memory64 JS bindings".. the latter does not have to be as powerful as the former for the whole to still be useful. Or at least not complicate matters on a first iteration. There will be many applications where the latter does not even exist.
kainino0x commentedon Nov 9, 2021
AFAICT WebIDL does not handle bigints specially. The IDL
ConvertToIntconverts its input toNumber(i.e. double) first.juj commentedon Sep 8, 2024
Closing this issue, as in other API areas the convention is to avoid BigInts, and handle BigInt -> Number conversion at Wasm->JS boundary. Wasm64 allows up to 16GB (or in prototype, up to 32GB) of contiguous linear memory, i.e. there are no virtual memory facilities - so there is no possibility even in Wasm64 to reserve address space at > 53bits pointer area like one might expect to occur in native program code; such extension mechanisms are left for other proposals beyond Wasm memory64.