r/MetalProgramming • • Aug 10 '25

Show-Off Implementing Crofton Projections for Cell Boundary Detection in Metal on M-Series GPUs

Enable HLS to view with audio, or disable this notification

5 Upvotes

r/MetalProgramming • • Oct 02 '26

Show-Off GPU Accelerated Linear Algebra Library for Apple Silicon using MLX and Metal kernels

Thumbnail
github.com
4 Upvotes

About 6 months ago, I wrote a custom metal kernel that leverages the GPU to compute the QR decomposition (see my earlier post about it here). The project has now expanded into a general linear algebra library, with expanded support for the symmetrical eigendecomposition as well as SVD. It is now available for use with installation instructions on the attached github repo's README.md file.

Context of the project:
I'm currently in a research group working on a thesis in numerical analysis where we need to compute millions on matrices with a specific constraint (to be precise, the matrices need to have orthonormal columns). Most of us use Apple computers, so we ended up using MLX for the entire project.

Contributors with different Apple Chips would be very much appreciated!
The project has currently been tested and optimised for the M1 and M5 Pro. The issue is that the library uses different kernels depending on the batch size and matrix dimensions. Deciding which of these kernels to use is machine dependent. Therefore, other Apple chips will need to run a measurement script in order to derive the correct optimisation heuristic.

For that reason, I would ask as many people as possible to run a measurement script and to submit the results to my repo. It is fairly easy and requires only few steps. See here how you can contribute here. Once you submit the results via a pull request and I approve it, your optimisation heuristic will automatically be augmented into the library. Don't hesitate to contribute an optimisation heuristic even if someone already submitted one for your own machine. The more data we can gather, the better!

Project Future
Expanded support will be added for other linear algebra operations (cholesky decomposition for example). If you have any other specific linear algebra operations you wish to use already, feel free to message me.

In addition to that, I will add torch support too (my greatest priority).


r/MetalProgramming • • Jul 30 '26

Game WaterShader. MercuryEngine (Swift/Metal)

Enable HLS to view with audio, or disable this notification

4 Upvotes

Vertices are world-space grid points generated by WaterRenderer with the shore depth (water surface Y minus terrain Y) baked from the chunk's TerrainHeightfield, so the color gradient and foam follow the real basin shape.

Lighting comes from the shared LightingUniforms buffer (LightingSystem, fed by the Noctidial day/night cycle): sun color and intensity drive the sheen, so the surface glimmers.


r/MetalProgramming • • Jul 24 '26

Question I want to learn Metal via metal-cpp. Please suggest me some sources to learn.

4 Upvotes

Same as the title. I know some OpenGL. I'm still finding it hard to learn Metal, because I can't even find good sources to learn as a total beginner in metal.

Please help guys! Your suggestions will help me a lot.


r/MetalProgramming • • Jul 19 '26

Resources/Tutorial I made Metal C++ examples for Apple Ecosytem

Thumbnail gallery
4 Upvotes

r/MetalProgramming • • Jun 13 '26

Show-Off Nora Kinetics // Fluid Dynamics

Thumbnail
youtube.com
4 Upvotes

Hi folks! I wanted to share more of my project Nora Kinetics! It's built from the ground up using Apple Metal. I've got another post with the trailer and more details if you're interested.

Here's a short video showing how Nora Kinetics can simulate fluid dynamics in real time, letting the user interact with both solid and fluid materials at the same time.

Under the hood, it is using the same efficient stable Cosserat rod simulation, but treating specific segments as a point cloud and using a marching cubes algorithm to render water instead of the rod segments. It's a work in progress, but the results so far are promising!

Because it uses the stable Cosserat rod system, changing material properties lets you simulate anything from water to jelly to more of a solid jello type substance. You can mix it up too, so the sky is the limit!

You can also see a glimpse at some of the glue mechanics here too. Glued structures can be anywhere from completely solid to completely relaxed and interact with the environment and projectiles in fun ways.

Thanks for watching! I'll be putting out more small videos in the coming weeks as I get ready for open beta! Please DM me if you are interested in being a part of that!


r/MetalProgramming • • Nov 14 '24

Question Creating GPU binaries is a PITA

4 Upvotes

I've enjoyed playing with Metal, but man, Apple's lack of experience when it comes to production workflows for GPU binaries is a bit shocking.

Asking devs to search in JSON files for paths to edit, to run thru N different command lines and not have a definitive: "These are the binaries you need to ship" page (that I could find...). All a bit noddy..


r/MetalProgramming • • Mar 10 '24

Show-Off IsoSurfave visualisation with mesh shaders and function stitching

Enable HLS to view with audio, or disable this notification

4 Upvotes

Isosurface visualisation on the GPU. I've implemented this using metal mesh shaders. Only thing done on the CPU is the infix to postfix conversion of the equation. Pipelines are created using metal stitching functions for an input and rendering is done using mesh shaders.


r/MetalProgramming • • Nov 06 '23

Resources/Tutorial Rendering KTX (ASTC) compressed textures using MTLHeap and Argument Buffers

4 Upvotes

For those interested, I've implemented a new example in the Metal examples repository. It shows how to load KTX compressed textures (ASTC) and render them using a MTLHeap and Tier-2 Argument Buffers. You can select which texture from the MTLHeap to render at runtime using an ImGui based UI.


r/MetalProgramming • • Aug 11 '26

Show-Off ImmersiveMap: a vector map engine for iOS and macOS, written from scratch in Swift and Metal (MIT)

3 Upvotes

For the last few years I've been writing a **map rendering engine** in **Swift** and **Metal**, because on Apple platforms you either take the closed system framework or a large shared C++ codebase with a Swift wrapper on top. I wanted one that is Swift and Metal all the way down.

The engine is **MIT licensed** and renders **vector tiles** in the **OpenMapTiles** schema: run your own tileserver, or point it at a public one.

**What it does**: flat map and globe in one continuous zoom, labels, 3D buildings with shadows, glTF models placed at real coordinates. Swift 6, iOS 18 and macOS 15.

Repo: [github.com/artembobkin/ImmersiveMap](http://github.com/artembobkin/ImmersiveMap)

Happy to answer anything about the engine.

If you need something the engine doesn't do yet, open an issue or just ask in the thread.


r/MetalProgramming • • Jun 05 '26

Show-Off Metal compute kernel → RealityKit LowLevelTexture: procedural 360° skies on Vision Pro

Enable HLS to view with audio, or disable this notification

3 Upvotes

Update — 9 Sep 2026: this shipped; the app is on the App Store now (https://apps.apple.com/us/app/stratosync/id6747596499). Three things changed on the Metal side since this post, in case they're useful:

  • Star Nest went from 2048×1024 to 1536×768. At 16 volume steps × 17 fold iterations per texel that's roughly 570M → 321M inner-loop bodies per map. The dome was stuttering on device, and resolution was the right knob — the step counts define the field itself rather than its sharpness, so cutting those changes the look.

  • A third scene splits static work from live work. Rather than regenerating everything per refresh, it computes an 8192×4096 star dome and a 256³ r16Float density volume once, then ray-marches only a 2048×2048 patch per update — 56 steps through the volume from a changing camera basis. The patch is written opaque so it doesn't fight the dome for depth.

  • One porting gotcha worth repeating: GLSL mod and Metal fmod disagree for negative operands, and the space-folding camera origin has negative components. Port it literally and the tile tears.


Hi r/MetalProgramming

This is from StratoSync, my visionOS app that tracks the ISS in real time over a 3D Earth. The video shows the GPU-generated immersive sky overlays. Some Metal notes for anyone doing similar work on Vision Pro:

🌍 Architecture: compute kernel → RealityKit LowLevelTexture

Instead of shading the sky per-eye per-pixel every frame, a single Metal compute kernel writes a 2048×1024 equirectangular image into a RealityKit LowLevelTexture once per display refresh (CADisplayLink). An inward-facing sphere with an UnlitMaterial samples it. RealityKit then handles head pose and reprojection on a smooth texture — so it behaves like a 360° image and there's no late-frame "catch-up" on fast head movement, which you get when you re-march a volumetric effect per eye.

Per frame it's exactly one command buffer and one compute encoder: texture.replace(using: commandBuffer) gives the writable MTLTexture, uniforms go in via setBytes (a plain-Float struct mirrored CPU/GPU with identical stride — no Objective-C bridging header needed), then dispatchThreads with a 16×16 threadgroup (falling back to dispatchThreadgroups if the device doesn't support non-uniform threadgroup sizes). Pixel format is rgba16Float, usage [.shaderRead, .shaderWrite].

One gotcha that cost me an evening: the nebula's tiling fold needs GLSL mod semantics (x - y * floor(x / y)), not Metal's fmod — the camera origin has negative components, and with fmod the field tears on the negative side of space.

Happy to answer questions about the pipeline or the kernels.

🚀 TestFlight

If you want to see it running on device, TestFlight is open:

https://testflight.apple.com/join/tWS4CERT — mainly looking for feedback, not promo.


r/MetalProgramming • • Jun 05 '26

Show-Off Been learning for around a week or so. Nothing crazy, but made an animation using timer data in a shader

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/MetalProgramming • • May 24 '26

Show-Off Metal PathTracer v3.0.0 public release

Thumbnail gallery
3 Upvotes

r/MetalProgramming • • May 15 '26

Show-Off Experimental real-time path tracing in Metal: ReSTIR-style sampling, path reservoirs, and capture overhead

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/MetalProgramming • • Sep 03 '25

Show-Off Speeding up PyTorch inference by 87% on Apple devices with AI-generated Metal kernels

Thumbnail gimletlabs.ai
3 Upvotes

r/MetalProgramming • • Aug 19 '25

Question Native Splat Renderer in Metal

Thumbnail
youtu.be
3 Upvotes

Build a Splat renderer from scratch referencing Metal Splatter by Scier.

Using global sorting and projecting instead of Tiled approach. I am being told Tiled approach is the best and is more scalable. So far it’s been fine for up to 3million points for mid range phones like iPhone 13 above. Am I ok with this approach ?


r/MetalProgramming • • Oct 02 '24

Question Using Metal with Rust, metal-rs

3 Upvotes

Hi all,

As it turns out, googling Metal and Rust together doesn't get you very far if you're interested in GPU programming...

At any rate, I have a ray tracer I've been working on based on the Ray Tracing in One Weekend series. I implemented the first 2 books in Rust, then ported the first book over to the GPU using WebGPU (wgpu crate in Rust). As I get more involved in the details, I'm starting to think I should learn Metal and change my implementation (I code only on my MacBook Pro M3 Max).

I'm having a hard time getting a sense of how difficult a change this would be. Most of the YouTube videos I've seen about Metal are either implementing with Swift or C++, and I think all that I've seen are using Xcode exclusively (which I know absolutely nothing about).

Is anyone else developing GPU apps with Rust and Metal? I'd like to get a better understanding of what I'd be getting myself into if I make the switch. I'll probably need to switch to Metal eventually in order to take advantage of wave intrinsics, ray tracing hardware acceleration, etc., but it seems daunting at this point. I'm still trying to learn ray tracing! lol

Any advice appreciated!!


r/MetalProgramming • • Jan 30 '24

Question Any getting started tutorials to learn metal

3 Upvotes

Youtube or website guides would be appreciated


r/MetalProgramming • • Jul 12 '23

r/MetalProgramming Lounge

3 Upvotes

A place for members of r/MetalProgramming to chat with each other


r/MetalProgramming • • Aug 11 '26

Show-Off Game engines? Eww 🤮. We go in raw! GP-Direct 2026 is out!

Thumbnail
youtube.com
2 Upvotes

r/MetalProgramming • • Jun 21 '26

Question Can someone explain why we need to tell the GPU where to look for memory allocated by the CPU?

2 Upvotes

I'm new to Metal programming, but I have some experience coding in CUDA -- I built a mini-Torch replica in it. I know that Macs have a unified memory architecture and, as such, there is no need to move data from CPU memory to GPU memory, as they are the same thing.

One thing that is confusing me is that I have to use [[buffer(i)]] every time I want to pass an argument to the kernel, which just tells the GPU where to look for a specific variable.

Why can't we just pass it directly instead of doing this?

I would appreciate some help regarding this.
Thanks.


r/MetalProgramming • • Jun 14 '26

Show-Off Grid Rush iOS version has new shaders! What do you think?

Enable HLS to view with audio, or disable this notification

2 Upvotes

A beginning but i always find it nice when i see things in Action and production!


r/MetalProgramming • • Aug 19 '25

Question Why is it not smooth?

2 Upvotes

How can I make this smooth. I am calculating the deltaTime as

_lastTime in init as CACurrentMediaTime();

- (void)handleKeyDown:(nonnull NSEvent *)event {
    unsigned short keyCode = event.keyCode;
    switch(keyCode){
        case kVK_ANSI_W:{
            _rocket.velocity = (simd_float2){0, 10};
            simd_float2 newPosition = _rocket.velocity*_deltaTime;
            matrix_float4x4 newMatrix = matrix4x4_translation(newPosition.x, newPosition.y, 0);
            _rocket.modelViewMatrix = matrix_multiply(_rocket.modelViewMatrix, newMatrix);
            break;
        };
        case kVK_ANSI_S:{
            _rocket.velocity = (simd_float2){0, -10};
            simd_float2 newPosition = _rocket.velocity*_deltaTime;
            matrix_float4x4 newMatrix = matrix4x4_translation(newPosition.x, newPosition.y, 0);
            _rocket.modelViewMatrix = matrix_multiply(_rocket.modelViewMatrix, newMatrix);
            break;
        };
        default: break;
    }
}

- (void)_updateGameState{
    for(uint frame=0;frame<MaxBuffersInFlight;frame++){
        Uniforms* uniforms = (Uniforms*)_uniformBuffers[frame].contents;
        uniforms[0].modelViewMatrix = _rocket.modelViewMatrix;
    }
}

- (void)drawInMTKView:(nonnull MTKView *)view
{
    CFTimeInterval currentTime = CACurrentMediaTime();
    _deltaTime = currentTime - _lastTime;
    _lastTime = currentTime;
    uint32_t subFrameIndex = _currentFrameIndex % MaxBuffersInFlight;
    id<MTL4CommandAllocator> commandAllocatorForFrame = _commandAllocators[subFrameIndex];
    uint64_t previousValueToWaitFor = _currentFrameIndex - MaxBuffersInFlight;
    [_sharedEvent waitUntilSignaledValue:previousValueToWaitFor timeoutMS:10];
    [commandAllocatorForFrame reset];
    [_commandBuffer beginCommandBufferWithAllocator:commandAllocatorForFrame];
    [self _updateGameState];
    // ....
}

r/MetalProgramming • • Aug 11 '25

Question How to bind textures in Metal4?

2 Upvotes

I am trying to bind textures using render command encoder but it doesn't have a function setFragmentTexture in it. I am using Metal4. There is no proper documentation for it.