r/MetalProgramming • u/dariopagliaricci • 2d ago
r/MetalProgramming • u/MardyBum0401 • 6d ago
Show-Off Metal ASCII rendering on iPhone: turning animated 3D characters into a screen-space glyph grid
I shipped Project: NULL, a small iPhone sword-fighting game, and wanted to share the Metal trick behind the characters in this clip. Rather than sticking letters to the mesh, I render the animated characters to an offscreen texture. The composite pass samples the center of each screen-space cell, then uses luminance and coverage to pick a glyph from an atlas. It samples the glyph itself at the position within the cell, so the grid stays anchored to the screen while the character animates underneath it.
One detail that helped: picking a glyph from brightness alone loses information at thin edges. I let coverage make partially covered cells both sparser and fainter. The trade-off is that a blade can still get lost at that resolution. I kept the blade trail separate and used a thin depth-tested line on solid scenery edges, so you can tell what stopped the swing without making the glyph grid finer everywhere. The touch controls stay outside the ASCII pass.
If you’ve built a similar post-process, I’d love to know how you handled thin moving silhouettes without losing the coarse grid. The clip is captured gameplay; the game is free on iPhone: https://apps.apple.com/app/project-null/id6837462134
r/MetalProgramming • u/CuriousDevv • 10d ago
Question Apple Metal C++ Bindings Memory Leak in Hello World Program
Here's my SO post: https://stackoverflow.com/questions/80017096/apple-metal-c-bindings-memory-leak-in-hello-world-program
I am trying to write an Apple Metal application in C++ using the metal-cpp binding. However, in a simple hello, world program I get a memory leak from simply importing the libraries. I followed the setup on Apple's official "Get started with Metal-cpp".
In order to compile with memory leak checking, the official metal-cpp repository states.
"Use the Environment Variable OBJC_DEBUG_MISSING_POOLS=YES to print a runtime warning when an autoreleased object is leaked because no enclosing AutoreleasePool is available for its thread."
Below is the Hello, World program that is causing memory leaks on my machine.
#define NS_PRIVATE_IMPLEMENTATION
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include <Foundation/Foundation.hpp>
#include <Metal/Metal.hpp>
#include <QuartzCore/QuartzCore.hpp>
#include <iostream>
#include <thread>
#include <chrono>
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Checking for metal-cpp memory leaks..." << std::endl;
while (true)
{
std::cout << "Sleeping for 10 seconds" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(10));
}
return EXIT_SUCCESS;
} With the above program, I get continuous memory leaks. If you remove the while loop portion I get a singular memory leak. There should be no memory leaks because I'm not creating any metal objects. Even so, I have tried to add auto release pools in the following way:
#define NS_PRIVATE_IMPLEMENTATION
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include <Foundation/Foundation.hpp>
#include <Metal/Metal.hpp>
#include <QuartzCore/QuartzCore.hpp>
#include <iostream>
#include <thread>
#include <chrono>
int main(int argc, const char * argv[])
{
NS::AutoreleasePool* pool = NS::AutoreleasePool::alloc()->init();
// insert code here...
std::cout << "Checking for metal-cpp memory leaks..." << std::endl;
pool->release();
return EXIT_SUCCESS;
} But I still get a memory leak. I feel like I'm going crazy. Not sure if anyone has any ideas.
r/MetalProgramming • u/mikebmx1 • 15d ago
Show-Off mlxVS: CuVS for your Mac GPU vector search on Apple Silicon
r/MetalProgramming • u/foosekis4j • 29d ago
Show-Off A Java to Metal open-source compiler writen in Java
tornadovm.orgr/MetalProgramming • u/_Geolm_ • 29d ago
Show-Off tile-caching rendering
Hi,
inspired by the post https://blickeditor.com/blog/caching-an-immediate-mode-ui I've added tile cache rendering to my onedraw renderer, a gpu-driven sdf renderer for metal api. On the screenshot you can see :
- green tiles are copied from previous frame as the hash of the commands affecting this tile didn't change
- red tiles have different hash so had to be recomputed
- elsewehere, it's just clear color, the bining rejected all commands
You can have a look at the library and the release. Tile caching gives good results with mostly static scene obviously, it's an option in my renderer.
https://github.com/Geolm/onedraw
Cheers,
Geolm
r/MetalProgramming • u/Icy-Dinner4579 • Oct 25 '26
Question My C++23 engine where the UI is a GPU-drawn MVVM tree — shader graph, own title bar, DX12/Vulkan/Metal
r/MetalProgramming • u/Intrepid_Bee_9194 • Oct 12 '26
Show-Off Scheduled versus completed texture delivery in a Metal image pipeline (Harbeth, MIT)
I maintain Harbeth, an MIT-licensed Apple GPU image/frame engine. Here's a delivery distinction in its Metal API: a command buffer being scheduled and a texture being ready for CPU readback are different states.
The opt-in transmitOutputRealTimeCommit path can deliver a texture after command-buffer scheduling, before GPU completion:
var io = HarbethIO(element: inputTexture, filters: filters)
io.transmitOutputRealTimeCommit = true
let texture = try await io.transmitOutput()That result needs a compatible GPU dependency chain for subsequent use. CPU code must not immediately read it back. With the default switch value, asynchronous delivery follows GPU completion and can report command-buffer failure.
Image, pixel-buffer and sample-buffer results wait for GPU completion before CPU materialization. Synchronous output() also waits for the GPU work required by its output and is unaffected by this switch.
The source documents the consumer responsibilities, including keeping resources alive and avoiding writes while the GPU still uses them.
Implementation: https://github.com/yangKJ/Harbeth/blob/master/Sources/Basic/IO/HarbethIO.swift
Project: https://github.com/yangKJ/Harbeth
How do you express scheduled versus completed delivery in your Metal wrappers: distinct result types, an explicit synchronization operation, or a dependency contract owned by the host? I'm interested in implementation tradeoffs.
r/MetalProgramming • u/_Geolm_ • Oct 09 '26
Show-Off I made a lossless BC1 texture compressor designed for GPU decompression, 1.47:1 average ratio
r/MetalProgramming • u/Sorry-Peace-296 • Oct 02 '26
Show-Off GPU Accelerated Linear Algebra Library for Apple Silicon using MLX and Metal kernels
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 • u/Natural_Childhood731 • Sep 24 '26
Show-Off I got tired of flat iOS chats, so I built a pixel-art one in Metal
Hey everyone! This whole thing started because I got tired of the standard iOS UI. As a developer, I felt like the existing framework was limiting my vision. Fair warning: that's just my opinion, and maybe you don't care about any of this, which is totally fine. But I thought: why not make something fun using new tools? So I built a pixel-art chat controller in Metal. There's a video up top if you want to see it in action.
Two things pushed me to do it.
Problem #1 is the design. Standard iOS chats are flat, and I wanted a pixel-art interface, so I built one with Metal.
Problem #2 is lag. I wanted to get rid of stutters and dropped frames when scrolling a big chat. Real numbers are coming in a second, but the headline is this: by rendering the geometry straight on the GPU, I cut the main-thread CPU load during scrolling by more than 2x.
I began with profiling in Xcode. Scrolling itself isn't what lags. The stutters come from UIKit overhead: heavy Auto Layout calculations and UIView recycling that clog up the main thread.
So I took a regular UIKit chat with text messages and scrolled it while watching the main thread. Under active scrolling it sat at around 30% CPU.
Then I made the same chat in Metal, going around all that heavy UIKit machinery. Main thread load dropped to 9–13%.
And that's when I decided I could spend the freed-up performance on custom animations. What's stopping us from stepping outside the templates, experimenting, taking risks? Isn't that the whole point of building cool stuff? When you control the look and the whole render pipeline of a chat, a huge playground opens up.
The pixel-art controller is part of a full chat app. The standard UI runs on MessageKit, and the Metal controller plugs in as a fully independent module, so you can switch between the two. Behind the app there's a custom backend (WebSockets + HTTPS). So far the app has registration, the main message types, group chats, my own video and photo compressor, audio and video calls, and viewing files in the cloud.
The Metal controller already handles text and photo messages. Here's my TODO list for the pixel chat room:
- Video messages
- Audio messages
- Geolocation
- Showing files sent in the chat
- Message dates
- Camera support
- Typing indicator
- Maybe avatars
I don't want to just show you dry code. I want to show how this works in a real example. So I started a YouTube playlist, and the first video is already up: testing the chat in near-real conditions. I'll keep updating it: https://youtube.com/playlist?list=PLOe0Yi7UOxgg&si=xGlA8cOFkqjxyLij
If you're curious, follow along. Questions about the Metal side, or just general thoughts? Drop them in the comments. Thanks for reading!
r/MetalProgramming • u/Sad_Reputation7874 • Aug 31 '26
Question Metal for Directed Graphs
I have no interest in AI, but I read some oblique references to matrix multiplication used in AI.
I want to do research into some properties of directed graphs, which can be represented as matrices, but I don't necessarily need to do multiplications - maybe I will, maybe I'll need to write my own procedures depending on what I find.
Can anyone say whether there is much support for directed graphs or matrix operations in Metal? I'm deciding on buying a Macbook Pro to use the GPU for research. Any notable support for general matrix operations or Directed Graph APIs would be of interest.
But if the only Metal support is narrowly tailored to AI-only uses, it's perhaps not so interesting. I don't want to reverse-engineer an AI API just to fake some general matrix operations.
Thanks in advance.
r/MetalProgramming • u/Lithalean • Aug 20 '26
Show-Off Mercury to Metal Logo SplashScreen
An animated liquid-mercury orb rendered entirely with a Metal fragment shader, with the Metal "M" logo outlined in its center. Monochromatic silver / chrome aesthetic for the Mercury game engine.
r/MetalProgramming • u/devslacker • Aug 11 '26
Show-Off ImmersiveMap: a vector map engine for iOS and macOS, written from scratch in Swift and Metal (MIT)
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 • u/BlackGoku36 • Aug 11 '26
Show-Off Game engines? Eww 🤮. We go in raw! GP-Direct 2026 is out!
r/MetalProgramming • u/Lithalean • Jul 30 '26
Game WaterShader. MercuryEngine (Swift/Metal)
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 • u/AccountantOverall703 • Jul 28 '26
Show-Off Ray Tracing in One Weekend in Metal
Hi! I recently implemented Ray Tracing in One Weekend in Metal using metal-cpp. Resources for metal-cpp specifically are pretty sparse, so I figured I'd share in case it helps anyone getting started with it or with graphics programming in general. Hope it helps!
r/MetalProgramming • u/Xccelerate_ • Jul 24 '26
Question I want to learn Metal via metal-cpp. Please suggest me some sources to learn.
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 • u/Different-Meat-8418 • Jul 19 '26
Resources/Tutorial I made Metal C++ examples for Apple Ecosytem
galleryr/MetalProgramming • u/BPEvilelement • Jul 11 '26
Show-Off Hey
Finally, I feel I have a home lol.
I am a senior iOS engineer who has branched out into Metal development over the past few years. I have spent a good bit of time training myself in both 2D and 3D Metal development. Though I am still very much a beginner with the technology, it definitely opens a whole new world of possibilities for what you can offer users for apps and games.
Though I am working on my own game project utilizing the Metal framework, with the goal of launching at some point in 2026.
r/MetalProgramming • u/prof_mistake • Jun 21 '26
Question Can someone explain why we need to tell the GPU where to look for memory allocated by the CPU?
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 • u/sariug • Jun 14 '26
Show-Off Grid Rush iOS version has new shaders! What do you think?
A beginning but i always find it nice when i see things in Action and production!