-
Re: Possibility of using C++ directly with Metal API
tijmen Sep 20, 2015 5:56 AM (in response to komires)Yes I would like that as well. I was initially suprised that the Metal API was in Objective-C, but I think they did that so the API could be transpiled to Swift. At least Objective-C++ works rather well and so Metal was easy to integrate in our C++ engine.
-
Re: Possibility of using C++ directly with Metal API
Jessy Sep 20, 2015 9:40 AM (in response to komires)I think persuing this would be counterproductive for the human race.
C++ is old and not as suitable for human use as Swift is. The solution is to stop using fake-C++ for writing shaders, as Swift becomes able to fully replace what we have now. Although Metal SL is a decent step up from GLSL and Cg, it's not Swift. Not embracing Swift for all programming tasks, and improving that dog food via the eating and getting back to the chef, keeps us from programming well.
-
Re: Possibility of using C++ directly with Metal API
rocket99 Feb 10, 2018 6:57 PM (in response to Jessy)which language can take interaction with hardwares directly?
Only c/c++ until now, I think that's why shader languanges(GLSL, HLSL, MetalShader) are writen in c++ syntax
-
-
Re: Possibility of using C++ directly with Metal API
sbrodhead Sep 22, 2015 9:42 PM (in response to komires)You can intermix C++ and Objective-C in Object-C++.
So if you have an Objective-C file called foo.m just change the file extension to .mm (foo.mm)
Then the compiler can handle C++ along with Objective-C.
Works like a charm.
-
Re: Possibility of using C++ directly with Metal API
komires Sep 29, 2015 1:08 PM (in response to sbrodhead)I was thinking of something along the lines of NativeActivity for Android. Solution intended mainly for games and multimedia apps. The current intermix C++ and Objective-C in Object-C++ gives additional overhead that could be eliminated.
-
Re: Possibility of using C++ directly with Metal API
slime Sep 29, 2015 2:22 PM (in response to komires)According to an Apple GPU driver developer, they did prototype a non-Objective C API but the overhead of Objective-C method calls in Metal was about the same or slightly better than the alternative.
Having the external Metal APIs be in another language wouldn't magically give better real-world performance, and it's trivial to call Objective-C APIs from C or C++ code by making it compile as Objective-C or Objective-C++.
-
Re: Possibility of using C++ directly with Metal API
jrb Sep 30, 2015 11:40 PM (in response to slime)"it's trivial to call Objective-C APIs from C or C++ code"
Agreed. But there are non-trivial performance costs. Just profile your app and see how much time objc_msgSend() eats. You realize method calls in Obj-c are dynamic dispatch, right? Same with properties. Just compiling obj-c with c/c++ is completely not the issue.
"in another language wouldn't magically give better real-world performance"
Yes, it can. Obj-C and C++ have some fundamentally different internals. People are asking this for real reasons, not for language religion. My desire is based on our own real on-device profiling data.
In our engine, we've resorted to making C++ shadow versions of some Metal api classes just to reduce costs on hot paths. I'll add another vote for a real native compiled API, but not expecting it to happen.
-
Re: Possibility of using C++ directly with Metal API
slime Oct 1, 2015 1:29 AM (in response to jrb)As I said, Apple already prototyped what you're suggesting and did not find any worthwhile performance benefit. Calling C++ (virtual) methods has its own overhead as well, and objc_msgSend has become very optimized over the years for what it does.
Look into this function if you want the absolute maximum performance at all costs: https://developer.apple.com/library/ios/documentation/Metal/Reference/MTLCommandQueue_Ref/index.html#//apple_ref/occ/intfm/MTLCommandQueue/commandBufferWithUnretainedReferences
-
-
-
-
Level 1
Level 3
Level 2