172 points · by oumua_don17 · 5y ago · 150 comments
Also - throwing a zip file over the fence, really? Can't you put it on GitHub?
In obj-c or swift, ARC would handle that for you, so this makes the memory management aspect of using Metal a bit more of a headache.
It doesn't break ARC right, it just won't do the automatic reference counting in C++ source. You can send it back and forth over the wall with CFBridgingRetain and CFBridgingRelease no?
Having an autorelease pool is pretty standard practice, and ARC works the same way in ObjC (and I assume Swift) apps - stuff that was autoreleased accumulates in the pool until it is drained, which tends to happen every turn of the run loop.
GitHub was not invented at Apple, sadly.
A. Metal came 2 years before Vulkan.
B. Microsoft does their own proprietary API with DirectX.
C. Metal is a high-level language, Vulkan is low-level. Apple wants you to use a high-level language so they have more flexibility in optimizing the low-level for you now and in the future, which Vulkan closes off more.
D. Metal runs on iOS, iPadOS, and tvOS as well, not just macOS. It's a graphics API for all Apple platforms.
E. Because of D, talent for Metal is much more likely to be found with mobile game developers than AAA studios.
F. Game engines actually support Metal - Unity, Unreal, LWJGL, the most common engines run on Metal fine. Don't use Metal as a scapegoat.
The problem is that historically, this is what's lead to tons of issues in games. Drivers make their own "optimizations" resulting in terrible performance for some task on one GPU, and great performance on another. Or instead of performance differences, it's outright bugs.
Then, combine that with GPUs being fairly expensive, and fast moving when it comes to new features. Most game studios aren't going to buy 20 different GPUs and test their entire game on all of them. So games often ship with terrible performance or bugs on various different GPUs. And it's often not the game's fault: are games really supposed to detect your exact GPU model, and change code paths to work around a driver bug? That's crazy.
To combat this, GPU drivers often get updates after a game launch that fix the issues with performance/bugs for specific games at the driver level, when it detects that those games are running. So now drivers become a pile of game-specific hacks, making the problem even worse.
This is the reason Vulkan is so low level. The goal is to make sure drivers don't get horribly bloated, and games aren't working around driver-specific bugs (they still happen, just hopefully less). And when games want to use specific GPU features for extra performance, instead of drivers trying to magically improve normal operations, they can make a vendor-specific extension providing the new functionality that games can opt into when the feature is detected (e.g., raytracing). That's part of why Vulkan has so many more extensions than OpenGL does.
Vulkan may be low level, but it's intended to be so. By foregoing Vulkan support, Apple rejected any attempt at making a higher level API on top of Vulkan that would work on every system. Instead, WebGPU has to try and abstract over Vulkan/Metal/DirectX12 separately, which mostly works, but leads to a whole lot of clunk and longer development time than if Vulkan was the standard everywhere.
That's not to say macOS should never have made Metal. But by not adding Vulkan support in addition later on, they're really hurting cross-platform compatibility. Sure, now Apple can optimize their platform to the best of their ability (theoretically). But that comes at a huge overall cost to the ecosystem, for instance with games having poor support for macOS.
This is mostly irrelevant for MacOS/iOS/iPadOS/tvOS. The number of people plugging in an external GPU on Macs is minuscule
> for instance with games having poor support for macOS.
Games don't have poor support on MacOS because of lack of Vulkan. They have poor support because pretty much no Mac (except maybe the newest M1 macs?) have gamer level GPUs and no market for high end games. Gamers basically know if you want to game, get a PC, and game devs know not to waste money on Mac ports.
I don't know if I had this point edited in when you wrote this, but see point F:
"F. Game engines actually support Metal - Unity, Unreal, LWJGL, the most common engines run on Metal fine. Don't use Metal as a scapegoat."
[EDIT: Actually, they do, with the OpenGL compatibility pack at https://www.microsoft.com/en-us/p/opencl-and-opengl-compatib.... It's new for Windows 10, and it only supports up to OpenGL 3.3, suspiciously around the same compatibility level as macOS...]
MacOS, well, Apple got into a huge spat with NVIDIA in ~2012. Around the same time, actually, that Apple stopped updating OpenGL (though they wouldn't formally deprecate OpenGL until 2018). Part of me wonders if NVIDIA was writing the OpenGL for Apple, but then OpenGL just got put on the shelf after the spat.
The result though is that neither Windows, nor Apple, supports OpenCL past 1.2 or OpenGL past 3.2/3.3. It's the GPU vendors that have been taking us further.
[EDIT 2: Correction, macOS supports OpenGL 4.1, Windows tops out at 3.3 without GPU drivers if you have DirectX 12]
DX12 may be proprietary and ship only with Windows, but GPU vendors are able to provide OpenGL and Vulkan support through their drivers. As a result, DirectX is an option, not a requirement. Metal is a requirement for 3D acceleration on Apple hardware.
Those same GPUs have perfectly functional Vulkan drivers on Android. I don't know what the problem is.
Having Vulkan on Windows is more like a courtesy from Nvidia, AMD and Intel that Microsoft hasn't really blocked [1]. But it can't truly be relied on on Windows - other GPU vendors don't need to build it [2]. Presumably with that excuse, Microsoft has not allowed apps on the Windows Store that targeted a 3D API other than Direct3D - that stuff just would not work on Qualcomm devices and presumably other devices as well.
[1]: If they were committed to being assholes about it they could force change as part of the WHQL problem, but it doesn't look like they are that committed. I'm not sure what they are committed to though.
[2]: I.e. what if we get Windows laptops with Mediatek chips, or Microsoft and/or Apple revive some Bootcamp mechanism for Windows on Apple Silicon?
With much pain. Have you seen the shader pipeline we have to deal with going from HLSL to Metal? And no, translating the entire body of shader work to MSL is not an option.
Vulkan has never clicked for me. I can cut and paste code to get something running but I don't really understand it. When you say Metal is high level, that's very appealing to me.
> Metal is a high-level language, Vulkan is low-level.
Wikipedia says Metal is low-level. What do you think accounts for the different description?
That said, there would be challenges, and big ones, the more you tried to make it actually Metal compatible. You'd need a C++ compiler for the shaders, and certain idioms (pointers, scalar types other than 32 bits) would be difficult to translate portably.
And as adamnemecek points out, the role of a friendly cross-platform GPU layer is largely being occupied by WebGPU (wgpu in particular in Rust-land). That'll be very comfortable for people used to Metal, as there's been lots of input from Apple folks. However, WGSL is much lower level than Metal Shading Language, and there are lots of important capabilities (subgroups, etc) missing that Metal and other advanced (>DX11) APIs can do.
An interesting discussion worth reading:
Metal has sort of been ported to other platforms, WebGPU is almost a subset of it (albeit somewhat higher level). There's even wgpu to use it outside of a browser.
Why would they do that? By the time Vulcan came out they had years of engineering effort in Metal.
I say that bearing in mind we're talking about battery powered hardware, which can not spend any extra cpu cycles on anything, period, without being berated in the press for short battery life compared to some competitor.
From the GPU compute perspective:
Vulkan has a subset of the features that Metal has.
Metal uses a device programming language that is C++ based, has pointers... and uses AIR (an LLVM IR dialect) as the bytecode.
Vulkan would be a big downgrade in feature levels from that.
While it is very much possible (and done) to have a compliant OpenCL implementation over Metal or D3D12, such a thing isn't possible at all for Vulkan.
I don't see the logic here.
Unity has a Metal target, but its not like you can just ignore it exists after you enable it. I'd much rather write to a single API than many targets, even if Unity makes it possible to do so.
And vulkan does not support some methods that e.g. metal has natively (and vice versa of course)
H. Switch main API is NVN
They don't control the API - not what is in it, the direction it is going, nor when it is updated. That means they can't integrate it tightly with their OSs. Not from a tech standpoint and not from a release standpoint.
Supporting it in MacOS would mean just having a team working for Khronos, implementing Vulkan on top of MacOS's actual graphics API, Metal, and releasing when they could.
It would seem much better if some other group -- one with an actual stake or interest in it -- would take this on. Not sure who that would be because there doesn't seem to be a good enough reason for any group to do it.
Most game engines probably want to go directly on top of Metal -- they already provide an abstraction layer and probably don't want to have an intermediate one.
GPU makers, even at the best of times, have never been interested, and, of course, they can look forward to zero Mac business in the near future, so that isn't going to change.
Not sure who else there possibly is.
I could imagine an open platform supplanting CUDA in the long term from a cost-optimization angle, especially on server workloads, but I just don't see serious work moving from one closed platform to a smaller closed platform.
i'm planning to use this to rewrite the metal backend of my rhi abstraction.