DirectXMath icon indicating copy to clipboard operation
DirectXMath copied to clipboard

Support for WebAssembly SIMD Intrinsics (v128) and Rust Integration

Open danielozyurt opened this issue 10 months ago • 5 comments

DirectXMath supports SIMD on architectures such as SSE2 but does not support WebAssembly SIMD intrinsics using the v128 type. As a header-only library that compiles with any standard C++20 compiler, I successfully compiled it with Clang targeting WebAssembly but found no intrinsic support for WebAssembly SIMD.

I prefer DirectXMath over other libraries (such as GLM) because it is released under the MIT License, supports major SIMD instruction sets, and offers useful functions for software rendering.

My main use case for DirectXMath is software-based rendering (rasterization and ray tracing) targeting outputs such as:

Win32 (GDI)

Direct2D

HTML Canvas via WebAssembly

BMP files

Could you consider adding support for WebAssembly SIMD intrinsics using the v128 type? Also, with Microsoft’s recent focus on Rust, are there any plans for official Rust support or bindings in DirectXMath?

Thank you for your consideration.

danielozyurt avatar May 06 '25 08:05 danielozyurt

I actually did port this to WebAssembly in my repository and this is pretty simple to do

vbsp-exe avatar May 27 '25 16:05 vbsp-exe

Can you provide a PR as to what you had to change for reference?

walbourn avatar May 27 '25 18:05 walbourn

Hi, I’m interested in working on WebAssembly SIMD support and/or Rust bindings for DirectXMath. Is anyone else working on this? Any tips before I dive in?

RohithPariki avatar May 28 '25 01:05 RohithPariki

Can you provide a PR as to what you had to change for reference?

Sure, I'd do that as soon as I can.

vbsp-exe avatar May 28 '25 11:05 vbsp-exe

It took me longer than expected to create this minimally working demo project for anyone it may help.

I built a C++ source file using DirectXMath into a WASM binary and integrated it with JavaScript. The extra time went into providing clear explanations, thorough documentation, and assembling the minimally needed components (e.g., additional dummy headers).

WASM Vector3Cross Demo Branch

I hope it is at least somewhat useful.

P.S. It may be possible to use XMFLOAT3 directly; I'm not sure about XMVECTOR.

It may also be possible to use the LLVM (Clang/LLVM) toolchain integrated with Microsoft Visual Studio 2022.

The Visual Studio compiler team may consider adding support for WebAssembly as a compilation target, similar to how LLVM does.

danielozyurt avatar May 28 '25 11:05 danielozyurt