Skip to content

Support for Wasm memory64? #2252

Closed
Closed

Description

@juj

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

  1. juj commented on Nov 4, 2021

    @juj
    Author

    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

  2. aardappel commented on Nov 4, 2021

    @aardappel

    If unsigned long long means 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.

  3. juj commented on Nov 4, 2021

    @juj
    Author

    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?

  4. aardappel commented on Nov 4, 2021

    @aardappel

    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.

  5. kainino0x commented on Nov 9, 2021

    @kainino0x
    Contributor

    does that already register as BigInt-capable to JS? Or how does unsigned long long in the IDL interact with JS today?

    AFAICT WebIDL does not handle bigints specially. The IDL ConvertToInt converts its input to Number (i.e. double) first.

  6. added this to the post-V1 milestone on Jan 26, 2022
  7. juj commented on Sep 8, 2024

    @juj
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions