Next, add three frameworks to the project: Foundation, QuartzCore, and Metal. Then, you need to set C++17 or higher as the C++ language dialect. Here, I put metal-cpp under the current project. After downloading metal-cpp, you should tell Xcode where to find it. Let me show you the steps you will need to take. Here's the webpage where you can find the downloads and instructions. So now that you know a little bit about metal-cpp, how do you actually use it? We published metal-cpp last year. I'm also excited to introduce a series of incremental C++ samples that introduces the Metal API and shows you how to accomplish different tasks with it. We hope this can help you learn how to code with metal-cpp in practice. We now provide a new version of this deferred lighting sample which uses metal-cpp. You may have already played with this deferred lighting sample before. You don't need to worry about language syntax now with metal-cpp, you can directly look into the Metal documentation to learn the concepts and usage of Metal. Obviously, metal-cpp and Objective-C Metal are almost the same. This tells the GPU that it can begin executing my commands. I present the drawable, so the triangle is displayed onscreen. Then I indicate that I've finished encoding render commands. Then I encode my draw call to render a single triangle. I then set a render pipeline state object which contains the vertex and fragment shaders and various other rendering states. The only differences are the name conventions of the languages. The C++ function renderCommandEncoder and the Objective-C method renderCommandEncoder WithDescriptor are the same. I can create a render command encoder and write render commands with a command buffer. I can simply use the raw pointer in C++ as a mapping to ID in Objective-C. First, I create a command buffer, which I will fill with commands for the GPU to execute. I am going to demonstrate how easy it is to use metal-cpp. If you've already used Metal with Objective-C, in terms of function calls, there's very little difference between the Objective-C interface of Metal and metal-cpp. If you are familiar with C++, it's a good time to learn Metal, because you don't need to worry about language syntax. These are the series of calls necessary to draw a triangle with metal-cpp. This one-to-one mapping also allows all of the developer tools to work seamlessly, including GPU Frame Capture and the Xcode debugger. I will discuss this in more detail later. Since metal-cpp implements a one-to-one mapping of C++ to Objective-C calls, it follows the same Cocoa memory-management rules. So this wrapper introduces little overhead. This is the exact same mechanism that the Objective-C compiler uses to execute Objective-C methods. metal-cpp uses C to call directly into the Objective-C runtime. It's open source under Apache 2 License, so you can modify the library and include it to your applications, easily. To do this, metal-cpp wraps parts of the Foundation and CoreAnimation frameworks. It provides 100 percent coverage of the Metal API by implementing a one-to-one mapping of C++ calls to Objective-C APIs. I say it's lightweight, because it's implemented as a header-only library with inline function calls. metal-cpp is a lightweight Metal C++ wrapper. With metal-cpp in your application, you can use Metal classes and functions in C++, and metal-cpp can help you call Objective-C functions in runtime. Introducing metal-cpp! It serves as a hub between your C++ application and Objective-C Metal. But if your code base is in C++, you may need something to bridge between your code and Metal's Objective-C code. It was originally designed using the powerful features and the conventions offered by Objective-C. Metal is the foundation for accelerated graphics and compute on Apple platforms, enabling your apps and games to tap into the incredible power of the GPU. So here's a look at metal-cpp and how it works. And finally, I'll show you how to integrate C++ code with Objective-C classes. Xcode and metal-cpp have some great utilities that can help you manage the object lifecycles in your apps. C++ and Objective-C handle lifecycles a bit differently, and I'll show you how to handle those differences. First, I'll start with an overview of what metal-cpp is and how it works, and then I'll cover some details about the lifecycles for Objective-C objects. Metal-cpp is a low-overhead library that connects your C++ applications to Metal. We created metal-cpp for anyone who uses C++ and wants to build Metal applications for Apple platforms. Today, it's my pleasure to introduce metal-cpp. ♪ Mellow instrumental hip-hop music ♪ ♪ Hi, my name is Keyi Yu, and I'm an engineer from the Metal Ecosystem team.
0 Comments
Leave a Reply. |