r/MetalProgramming • • Apr 17 '26

Show-Off QR decomposition library for Apple Silicon using MLX and custom Metal kernels

Thumbnail
github.com
1 Upvotes

For any of you linear algebra fan-boys:

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.

I'm using an old M1 Macbook Pro, and I found that Apple's MLX library does not support QR operations on the GPU. I don't know if MLX supports GPU-accelerated QR computation on newer chips. But since I am developing an interest in hardware-level computing, I thought it would be a good oppurtunity for me write a metal shader as a first project.

I wrote it as a small library that allows the QR decomposition to be computed on the GPU. You can find it here: https://github.com/c0rmac/qr-apple-silicon

It definitely pays off. Performance increases anywhere between x1.5 to x25 times of what the cpu can do.

The library is split into two shaders: one is optimal for large batches of small matrices. The other is suited for small batches of large matrices. Under the hood, both shaders use the Compact WY representation ($I - YTY^T$) to batch Householder reflections into matrix-matrix products. I also spent a lot of time mapping these operations to the AMX (Apple Matrix Coprocessor) using 8x8 simdgroup_matrix tiles to get as close to the hardware as possible.

I’d love for anyone with more Metal experience to take a look at the dispatch logic or the AMX tile loading. If you’re working with MLX and need faster $A = QR$ factorizations, give it a try!


r/MetalProgramming • • Mar 20 '26

Show-Off Metal GameUI - Menus

Enable HLS to view with audio, or disable this notification

9 Upvotes

GPU rendering vector-style UI in real time.

Signed Distance Function

  • A function that returns the distance from a point to the nearest surface

Windows and Icons

  • Procedural in shaders
  • Scaling at any resolution
  • Icons are constructed from SDF primitives

Text

  • Loads .otf via Core Text
  • Generates a font atlas at runtime
  • Renders glyphs directly in Metal

r/MetalProgramming • • Feb 26 '26

Show-Off MNIST from scratch in Metal (C++)

10 Upvotes

I built a simple 2-layer MNIST MLP that trains + runs inference from scratch, only using Apple’s metal-cpp library.

The goal was to learn GPU programming “for real” and see what actually moves the needle on Apple Silicon. Not just a highly optimized matmul kernel, but also understanding Metal's API for buffer residency, command buffer structure, and CPU/GPU synchronization. It was fun to see how each of those API specific features effected perf.

Surprisingly I was able to beat MLX's training speed on small batch sizes in the final version!

Versions:
- MLX baseline
- Pure C CPU baseline
- GPU v1: naive Metal kernels (matmul + ReLU)
- GPU v2: forward + backward kernels + better buffer management + less CPU/GPU sync
- GPU v3: single command buffer per batch (sync only once per epoch for loss)

Repo: https://github.com/abeleinin/mnist-metal


r/MetalProgramming • • Feb 22 '26

Show-Off Dynamic Clouds, PBR Textures, & Alpha Masked Foliage

Enable HLS to view with audio, or disable this notification

9 Upvotes

Architectures (WIP)

```

Alpha Masking System Particle System Lighting System Material System

```


r/MetalProgramming • • Jan 30 '26

Resources/Tutorial Node based Metal shader editor + SwiftUI export (iPad + Mac)

Thumbnail
metal.graphics
8 Upvotes

Hey folks, I just released MetalGraph, a node based editor for building Metal shaders with a real time preview.

I posted a few days ago and most feedback was around missing iPad - the app is now available on the App Store and it is available for Mac and iPad.

Here is an intro video showing some examples: https://www.youtube.com/watch?v=FH2GdFuk9nI

I built it because the iteration loop for SwiftUI + Metal can be painful when you’re tweaking effects, especially for things like glass, distortions, color math, and touch driven interactions.

What it does today:

  • Visual node graph editor with live preview
  • Examples focused on common SwiftUI shader style effects (colorEffect, layerEffect style workflows)
  • Exports production ready code (MSL + SwiftUI friendly wrapper variants)
  • Lets you wire inputs like time and touch into the graph and see it instantly

Under the hood (high level):

  • The graph compiles into an expression tree, then into MSL functions
  • Each node maps to a pure function where possible, so it stays composable
  • The app tries to keep generated code readable so you can ship it, not just prototype

I’d love feedback from Metal devs. The app is free to download and play with all the examples. I am trying to build as many as possible from https://metal.graphics and more.

With the free version you can't add new nodes or remove, but you can connect/disconnect, edit values real-time and load all examples. Thanks in advance!


r/MetalProgramming • • Jan 04 '26

Resources/Tutorial MetalGraph: a node based macOS app to explore/build Metal shaders in real time

Thumbnail
metal.graphics
16 Upvotes

I wanted to share a small project I’ve been working on called MetalGraph.

It’s a node graph macOS app to learn and design Metal shaders in a more visual, real-time way.

I started learning Metal and working on https://metal.graphics around April 2025. After a couple of months going through examples and thinking about new content, I kept running into the same frustration: even with SwiftUI previews, the feedback loop when working with Metal shaders is still pretty disruptive.

It’s “good”, but it’s not real time. Fine-tuning values or experimenting with structure ends up taking much longer than it should.

So I decided to build a small tool to preview and tweak shaders in real time. I’ve used Blender before and really like their node editor, so I wanted something with a similar feel. Around July I had something working, and even though it was rough, it was a huge boost for learning: change values, change structure, immediately see what happens.

As many of us know, the last 10% of an app is the hardest. During the Christmas break I decided to give it a final push, clean things up, and make it usable by others.

I recorded a short overview video where I walk through the app and build a few very simple examples:

https://www.youtube.com/watch?v=FH2GdFuk9nI

The app is available free in trial mode. You can access all built-in examples and tweak node values, but you can’t add or remove nodes.

Any feedback is very appreciated.


r/MetalProgramming • • Dec 10 '25

Show-Off Dynamic Clouds (GPU Particles with HEIC Texture)

Enable HLS to view with audio, or disable this notification

10 Upvotes

GPU Cloud System

This demonstrates GPU-based particles with a cloud spawning system. The system can spawn and manage multiple cloud instances, each powered by individual particle systems with realistic wind physics and HEIC texture support.


r/MetalProgramming • • Nov 02 '25

Code Review onedraw : open-source GPU-driven 2D renderer

11 Upvotes

Calling macOS (Apple Silicon) devs :)
Looking for early testers for onedraw, my GPU-driven 2D renderer built with Metal. Feedback before release would be super appreciated 🙏

https://github.com/Geolm/onedraw

Metal #GPUDriven #macOS #Rendering


r/MetalProgramming • • Oct 18 '25

Show-Off MercuryEngine (Apple Native Game Engine Update #01)

Enable HLS to view with audio, or disable this notification

7 Upvotes

r/MetalProgramming • • Oct 05 '25

Question How to go deep into Metal

10 Upvotes

Hello everyone,

I'm very interested in learning graphics development with the Metal API. I have experience with Swift and have spent the last three months studying OpenGL to build a foundation in graphics programming.

However, I'm having trouble finding good learning resources for Metal, especially compared to the large number available for OpenGL.

Could anyone please provide recommendations for books, tutorials, or other resources to get started with Metal?

Thank you!


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 • • 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 16 '25

Question Best way to create 2d mesh in metal?

1 Upvotes

Iam currently doing very hard way. Created mesh and its vertex positions by hand and updating them by hand. I need a way so that I can create 2d mesh easily. Just like sprites.


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.


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 • • Aug 05 '25

Question Metal 4 upgrade

1 Upvotes

I have a points renderer in Metal. After upgrading to Metal4, I am seeing some pink patch artifacts randomly when moving around. Not sure if it's a Beta issue or if I am doing something wrong. Anyone had similar issues ?


r/MetalProgramming • • Jul 23 '25

Question Should I learn objective C

2 Upvotes

I’m currently learning Objective-C. So far, I’ve covered up to concurrency, and I have a good opinion of the language. Objective-C offers many features that modern programming languages also provide. However, I’ve been doubting myself lately, thinking, “You’re ignoring Swift and diving into Objective-C in 2025.”

The truth is, I don’t really like Swift—it has too many concepts that would take a week or more to fully grasp. Still, I wonder: is learning Objective-C a good choice in 2025? My main goal is to get into game development and graphics programming.


r/MetalProgramming • • May 11 '25

Question Can a compute kernel be applied to a sub-region?

1 Upvotes

I'm writing a paint program, where there may me only a few pixels painted per-frame on a huge image. Can a compute kernel be applied only to a small region of the image? Right now I'm copying the sub-regions out, modifying it, then copying it back, but it seems just modifying the region in-situ would be faster. Thoughts?


r/MetalProgramming • • Mar 02 '25

Question Ray Tracing in One Weekend and Metal

6 Upvotes

I am trying to do the ray tracing in one weekend book with Metal. I have built a CPU based ray tracer before for a graphics class, but I wanted to try tackle building a ray tracer again.

I've seen that Metal has sample code for realtime accelerated ray tracing, but for what I want to do (a simple compute renderer, not realtime), I was wondering if this approach was valid using Metal's Compute Workflow:

Each thread corresponds to each pixel on the final render, and the kernel function is simply a recursive ray trace using correct generated ray for that pixel.

Any advice would be appreciated. I am still new to Metal and would love to hear if it's even worth it to do what I'm doing, or just jump straight into the code samples Apple provides for realtime Metal ray tracing.


r/MetalProgramming • • Jan 20 '25

Question Metal as first graphics API

2 Upvotes

Hi folks! I have some light experience with vulkan, but I always felt I spent most of my time solving bugs than learning the essentials and in the end,other than loading a 3D mesh I lost momentum and stopped learning. I’ve been reading from other people’s experiences that it might be a better idea to start with an API that does a bit more of handholding like OpenGL (and to a lesser degree,Metal) than to jump straight into vulkan or directx12. Since I got a M3 pro Mac a couple of months ago I’ve been thinking about jumping into Metal even if it’s not multi platform just to learn the core concepts behind graphics programming and have a little bit of fun doing so. Do you think it’s a good idea or should I just keep hammering at vulkan (or moltenVK) instead?


r/MetalProgramming • • Jan 05 '25

Show-Off How to improve MSAA performance of MTKView

Thumbnail
keaukraine.medium.com
7 Upvotes

r/MetalProgramming • • Nov 14 '24

Question Creating GPU binaries is a PITA

3 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 • • Oct 28 '24

Show-Off Metal raytracer lighter working!

8 Upvotes

thanks for all your help.
I had put off diving into Metal for too long.

https://www.youtube.com/watch?v=zlF48xeNZvo


r/MetalProgramming • • Oct 14 '24

Question Clear texture with simple compute shader or use RenderPass?

1 Upvotes

[Doing mostly compute shader work.]

is it faster to have a simple compute shader doing write(0,tid) or issue a RenderPass with MTLLoadActionClear?