{"slug": "zig-gpu-kernel-for-macos-via-spirv", "title": "Zig gpu kernel for macOS (via spirv)", "summary": "Developer Danielkonge published a Zig example on Codeberg that runs GPU kernels on macOS by compiling through the spirv64-vulkan target and converting to Metal with spirv-cross. The developer reported the build system was straightforward, but the main difficulty was finding a clean way to use slices inside the kernel, a limitation that does not arise when compiling directly for amdgcn-amdhsa-none or nvptx64-cuda-none. The developer noted the setup should work cross-platform if spirv-cross is used only to produce .metal files without compiling them via xcrun, and pointed to spirv-cross's recent addition to allyourcodebase as a possible way to simplify the build steps.", "body_md": "I finally got some time to look at this a bit more, [see here.](https://codeberg.org/Danielkonge/mac_gpu_example.zig) (LLM disclosure: I got lazy with comments and docstrings, and some of the setup was done with LLM help, since I didn’t want to really focus on writing a proper SHA256 implementation without slices that I could use. What I was interested in was just playing with mac GPU kernels in zig code.)\n\nThe build system stuff ended up all being pretty easy, and the main annoyance was actually that I couldn’t find a nice way to use slices in the kernel. When compiling directly for `amdgcn-amdhsa-none` or `nvptx64-cuda-none` you don’t run into this, but going through `spirv64-vulkan` it is a problem.\n\nOverall I thought the setup worked pretty well, and if you only use `spirv-cross` to get `.metal` files and don’t compile them with `xcrun`, I guess everything should work well cross platform too.\n\n[As an aside, I saw recently that `spirv-cross` was added to allyourcodebase, so the build steps might be nicer with that now: [https://codeberg.org/allyourcodebase/spirv-cross](https://codeberg.org/allyourcodebase/spirv-cross)]", "url": "https://wpnews.pro/news/zig-gpu-kernel-for-macos-via-spirv", "canonical_source": "https://ziggit.dev/t/zig-gpu-kernel-for-macos-via-spirv/14458#post_7", "published_at": "2026-11-08 15:33:39+00:00", "updated_at": "2026-11-09 01:45:57.330231+00:00", "lang": "en", "topics": ["developer-tools", "ai-infrastructure"], "entities": ["Zig", "macOS", "spirv-cross", "spirv64-vulkan", "Metal", "Codeberg", "Danielkonge", "allyourcodebase"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/zig-gpu-kernel-for-macos-via-spirv", "markdown": "https://wpnews.pro/news/zig-gpu-kernel-for-macos-via-spirv.md", "text": "https://wpnews.pro/news/zig-gpu-kernel-for-macos-via-spirv.txt", "jsonld": "https://wpnews.pro/news/zig-gpu-kernel-for-macos-via-spirv.jsonld"}}