www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Objective-C D metal binding

reply Hipreme <msnmancini hotmail.com> writes:
Hello guys. I have been working for some time into binding Metal 
to D.
This has been quite an interesting journey and today I've reached 
a point where it is usable.
It is far from complete, but I included a lot of comments from 
Apple's documentation, and also have tested and got an entire 
Metal hello world working in D.

The API I worked on is really nice, I manually put the opIndex, 
opIndexAssign, wrapped Objective C Runtime Arrays to a strongly 
typed array in D. The main point into this binding is getting 
Metal to run on Hipreme Engine, so, I don't plan into supporting 
what I don't use. That said, I still welcome any contribution to 
make this a standard way to program using Apple's Metal.

I'll put an example folder the moment I get a dub fix for macOS.

![Metal MacOS D Hello 
World](https://user-images.githubusercontent.com/10136262/224425800-e417414e-b6be-4e92-93b4-9087b1b281a2.png)

https://code.dlang.org/packages/d-metal-binding
Mar 10 2023
next sibling parent Hipreme <msnmancini hotmail.com> writes:
On Friday, 10 March 2023 at 20:53:23 UTC, Hipreme wrote:

 https://code.dlang.org/packages/d-metal-binding
Sorry Guys. I also forgot one important thing to say: I really want to get iOS support. Though this is not possible right now since `extern(Objective-C)` is not implemented for LDC. If someone could help Martin get this work done I would be really happy :)
Mar 10 2023
prev sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Friday, 10 March 2023 at 20:53:23 UTC, Hipreme wrote:
 Hello guys. I have been working for some time into binding 
 Metal to D.
 This has been quite an interesting journey and today I've 
 reached a point where it is usable.
 It is far from complete, but I included a lot of comments from 
 Apple's documentation, and also have tested and got an entire 
 Metal hello world working in D.

 The API I worked on is really nice, I manually put the opIndex, 
 opIndexAssign, wrapped Objective C Runtime Arrays to a strongly 
 typed array in D. The main point into this binding is getting 
 Metal to run on Hipreme Engine, so, I don't plan into 
 supporting what I don't use. That said, I still welcome any 
 contribution to make this a standard way to program using 
 Apple's Metal.

 I'll put an example folder the moment I get a dub fix for macOS.

 ![Metal MacOS D Hello 
 World](https://user-images.githubusercontent.com/10136262/224425800-e417414e-b6be-4e92-93b4-9087b1b281a2.png)

 https://code.dlang.org/packages/d-metal-binding
Congrats! But metal obj-c? do you mean DMD support only? so no Apple Silicon (intel only)? I don't think Intel stuff on mac ecosystem will be a thing for too long, PPC era already vanished from history There is the official C++ headers that you can use to make things easier https://developer.apple.com/metal/cpp/
Mar 10 2023
next sibling parent reply Hipreme <msnmancini hotmail.com> writes:
On Friday, 10 March 2023 at 21:10:50 UTC, ryuukk_ wrote:
 Congrats!

 But metal obj-c? do you mean DMD support only? so no Apple 
 Silicon (intel only)?

 I don't think Intel stuff on mac ecosystem will be a thing for 
 too long, PPC era already vanished from history

 There is the official C++ headers that you can use to make 
 things easier

 https://developer.apple.com/metal/cpp/
As said in the post above, I do intend to get `extern(Objective-C)` into LDC even if I have to do it myself. Which is also why I'm looking if someone could help Martin get this on LDC. Binding to the main API is better than the secondary one, and this is an advantage that D has over other languages. This is not only about Silicon, it is also about getting iOS. iOS market share is as big as Android and any game developer would be interested in entering in this market.
Mar 10 2023
parent ryuukk_ <ryuukk.dev gmail.com> writes:
On Friday, 10 March 2023 at 21:14:38 UTC, Hipreme wrote:
 On Friday, 10 March 2023 at 21:10:50 UTC, ryuukk_ wrote:
 Congrats!

 But metal obj-c? do you mean DMD support only? so no Apple 
 Silicon (intel only)?

 I don't think Intel stuff on mac ecosystem will be a thing for 
 too long, PPC era already vanished from history

 There is the official C++ headers that you can use to make 
 things easier

 https://developer.apple.com/metal/cpp/
As said in the post above, I do intend to get `extern(Objective-C)` into LDC even if I have to do it myself. Which is also why I'm looking if someone could help Martin get this on LDC. Binding to the main API is better than the secondary one, and this is an advantage that D has over other languages. This is not only about Silicon, it is also about getting iOS. iOS market share is as big as Android and any game developer would be interested in entering in this market.
That's exactly what i'm saying, Intel is dead on that platform, it's only just ARM, therefore this metal-cpp comes handy
Mar 10 2023
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 3/10/23 4:10 PM, ryuukk_ wrote:
 On Friday, 10 March 2023 at 20:53:23 UTC, Hipreme wrote:
 Hello guys. I have been working for some time into binding Metal to D.
 This has been quite an interesting journey and today I've reached a 
 point where it is usable.
 It is far from complete, but I included a lot of comments from Apple's 
 documentation, and also have tested and got an entire Metal hello 
 world working in D.

 The API I worked on is really nice, I manually put the opIndex, 
 opIndexAssign, wrapped Objective C Runtime Arrays to a strongly typed 
 array in D. The main point into this binding is getting Metal to run 
 on Hipreme Engine, so, I don't plan into supporting what I don't use. 
 That said, I still welcome any contribution to make this a standard 
 way to program using Apple's Metal.

 I'll put an example folder the moment I get a dub fix for macOS.

 ![Metal MacOS D Hello 
 World](https://user-images.githubusercontent.com/10136262/224425800-e417414e-b6be-4e92-93b4-9087b1b281a2.png)

 https://code.dlang.org/packages/d-metal-binding
Congrats! But metal obj-c? do you mean DMD support only? so no Apple Silicon (intel only)? I don't think Intel stuff on mac ecosystem will be a thing for too long, PPC era already vanished from history There is the official C++ headers that you can use to make things easier https://developer.apple.com/metal/cpp/
From that page: No measurable overhead compared to calling Metal Objective-C headers, due to inlining of C++ function calls. D will not inline C++ function calls. So there will be overhead. Objective-C support is better. Getting Obj-C support into LDC is the right path. And I'm with you too -- we need ARM support for Metal. Looking forward to it! -Steve
Mar 11 2023
parent max haughton <maxhaton gmail.com> writes:
On Saturday, 11 March 2023 at 13:08:49 UTC, Steven Schveighoffer 
wrote:
 On 3/10/23 4:10 PM, ryuukk_ wrote:
 On Friday, 10 March 2023 at 20:53:23 UTC, Hipreme wrote:
 Hello guys. I have been working for some time into binding 
 Metal to D.
 This has been quite an interesting journey and today I've 
 reached a point where it is usable.
 It is far from complete, but I included a lot of comments 
 from Apple's documentation, and also have tested and got an 
 entire Metal hello world working in D.

 The API I worked on is really nice, I manually put the 
 opIndex, opIndexAssign, wrapped Objective C Runtime Arrays to 
 a strongly typed array in D. The main point into this binding 
 is getting Metal to run on Hipreme Engine, so, I don't plan 
 into supporting what I don't use. That said, I still welcome 
 any contribution to make this a standard way to program using 
 Apple's Metal.

 I'll put an example folder the moment I get a dub fix for 
 macOS.

 ![Metal MacOS D Hello 
 World](https://user-images.githubusercontent.com/10136262/224425800-e417414e-b6be-4e92-93b4-9087b1b281a2.png)

 https://code.dlang.org/packages/d-metal-binding
Congrats! But metal obj-c? do you mean DMD support only? so no Apple Silicon (intel only)? I don't think Intel stuff on mac ecosystem will be a thing for too long, PPC era already vanished from history There is the official C++ headers that you can use to make things easier https://developer.apple.com/metal/cpp/
From that page: No measurable overhead compared to calling Metal Objective-C headers, due to inlining of C++ function calls. D will not inline C++ function calls. So there will be overhead.
If you are able to use LTO then they'll be inlined. This may be slightly easier said that done for some build targets because apple's "clang" is actually a closed source fork so it's not impossible that there is LLVM incompatibility in there somewhere. In the absence of evidence suggesting otherwise, the overhead of an additional function call is probably quite small relative to the metal part of the function call (especially if that Metal call ends up waiting on the GPU for something). I'm now curious if there are I$ optimizations specifically for chasing function calls like this.
Mar 11 2023