gpuweb/spirv-execution-env

Are the atomics offered by SPIR-V/Vulkan compilable to Metal?

RobinMorisset opened this issue · 2 comments

The Vulkan memory model offers a lot of kind of atomic operations, including release and acquire fences and atomic stores and loads.

However, the Metal Shading Language only offers relaxed atomics, and no pure memory fences.
The only kind of synchronization it offers (as far as I can tell) is by applying mem_flags to a control-barrier. Because control-barriers have an impact on control-flow, and cannot be used in non-uniform control-flow, they cannot be used for the purpose of transpiling Vulkan atomics.

I've tried looking at how SPIRV-cross compiles SPIRV to MSL, and it appears to just drop all memory orders when compiling atomic accesses to MSL: https://github.com/KhronosGroup/SPIRV-Cross/blob/master/spirv_msl.cpp#L3088
I am currently trying to compile spirv-cross to verify that this is indeed what it does, but decided to raise an issue here in the meantime, as I think it is important to make sure that whatever shading language is picked for the web can be supported on all platforms.

We discussed this with David Neto and concluded that WebSPIRV (or whatever this eventually is called) should only have relaxed atomics to deal with this problem.

Essentially the edit is that atomic operations may only use "Relaxed" memory ordering.