gpuweb icon indicating copy to clipboard operation
gpuweb copied to clipboard

Extend WGSL to Support Additional Integer Types

Open MichealReed opened this issue 11 months ago • 3 comments

Currently, WGSL supports only 32-bit integer types (i32 and u32). Many applications could greatly benefit from native support for additional integer types, such as i8, i16, i64, u8, u16, and u64.

  • Supporting smaller integer sizes (i8, i16, u8, u16) would enable more compact data representations, reducing memory usage and potentially improving cache performance.
  • Larger integer types (i64, u64) allow handling of larger numbers natively, which is useful for high-precision computations and applications requiring extended numerical ranges.
  • Enhanced integer support can benefit many things but primarily AI and video work where 8 and 16 bit buffers are common.

MichealReed avatar Apr 11 '25 00:04 MichealReed

64-bit integer math is not supported by Mac2 Metal feature sets - https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf but it seems like an extension would be reasonable.

mwyrzykowski avatar May 13 '25 17:05 mwyrzykowski

I developed a WebGPU-based BLAKE2b implementation, and it performs approximately 20-30% slower than an equivalent OpenCL-based implementation primarily due to the extra operations required for arithmetic on 32-bit integer pairs to represent the 64-bit values defined by the algorithm. Extending WGSL to support u64 could bring it up to par with OpenCL for my project.

Zosoled avatar Jun 02 '25 13:06 Zosoled

There is also a preceding issue for integers other than 32-bit: https://github.com/gpuweb/gpuweb/issues/273

mehmetoguzderin avatar Jun 02 '25 13:06 mehmetoguzderin

Enhanced integer support can benefit many things but primarily AI and video work where 8 and 16 bit buffers are common.

When the buffer is a large array of small ints, the use case may be covered by storage texel buffers. See #162

dneto0 avatar Sep 15 '25 16:09 dneto0

Closing as duplicate of #273

dneto0 avatar Sep 15 '25 16:09 dneto0