You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 02_Development_environment.md
+41-35Lines changed: 41 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
In this chapter we'll set up your environment for developing Vulkan applications
2
2
and install some useful libraries. All of the tools we'll use, with the
3
-
exception of the compiler, are compatible with both Windowsand Linux, but the
3
+
exception of the compiler, are compatible with Windows, Linux and MacOS, but the
4
4
steps for installing them differ a bit, which is why they're described
5
5
separately here.
6
6
@@ -492,26 +492,33 @@ You are now all set for [the real adventure](!Drawing_a_triangle/Setup/Base_code
492
492
493
493
These instructions will assume you are using Xcode and the [Homebrew package manager](https://brew.sh/). Also, keep in mind that you will need at least MacOS version 10.11, and your device needs to support the [Metal API](https://en.wikipedia.org/wiki/Metal_(API)#Supported_GPUs).
494
494
495
-
### MoltenVK
495
+
### Vulkan SDK
496
+
497
+
The most important component you'll need for developing Vulkan applications is the SDK. It includes the headers, standard validation layers, debugging tools and a loader for the Vulkan functions. The loader looks up the functions in the driver at runtime, similarly to GLEW for OpenGL - if you're familiar with that.
498
+
499
+
The SDK can be downloaded from [the LunarG website](https://vulkan.lunarg.com/) using the buttons at the bottom of the page. You don't have to create an account, but it will give you access to some additional documentation that may be useful to you.
500
+
501
+

496
502
497
-
For MacOS what we will be using to develop Vulkan application is [MoltenVK](https://moltengl.com/). This is a library that maps Vulkan to Apple's Metal graphics framework, with this you can take advantage of debugging and performance benefits of Apple's Metal framework.
503
+
The SDK version for MacOS internally uses [MoltenVK](https://moltengl.com/). There is no native support for Vulkan on MacOS, so what MoltenVK does is actually act as a layer that translate Vulkan API calls to Apple's Metal graphics framework. With this you can take advantage of debugging and performance benefits of Apple's Metal framework.
498
504
499
-
To install and build MoltenVK go the the project's [github repository](https://github.com/KhronosGroup/MoltenVK) and follow the instructions. By the end you should have built one of the runtime distribution packages, either the Release or the Debug configuration. To make sure everything was done successfully, we will run one of the examples from the repository. Go to the folder where you cloned the repository, find and open the file `../MoltenVK/Demos/Demos.xcworkspace`. Now all the projects should open on Xcode, select the application `Cube-macOS`, build and run it. You should see the following:
505
+
After downloading it, simply extract the contents to a folder of your choice (keep in mind you will need to reference it when creating your projects on Xcode). Inside the extracted folder, in the `Applications` folder you should have some executable files that will run a few demos using the SDK. Run the `cube` executable and you will see the following:
500
506
501
-

507
+
[](/images/cube_demo_mac.png)
502
508
503
509
### GLFW
504
510
505
-
As mentioned before, Vulkan by itself is a platform agnostic API and does not include tools for creation a window to display the rendered results. To benefit from the cross-platform advantages of Vulkan and to avoid the horrors of X11, we'll use the [GLFW library](http://www.glfw.org/) to create a window, which supports Windows, Linux and MacOS. There are other libraries available for this purpose, like [SDL](https://www.libsdl.org/), but the advantage of GLFW is that it also abstracts away some of the other platform-specific things in Vulkan besides just window creation.
511
+
As mentioned before, Vulkan by itself is a platform agnostic API and does not include tools for creation a window to display the rendered results. We'll use the [GLFW library](http://www.glfw.org/) to create a window, which supports Windows, Linux and MacOS. There are other libraries available for this purpose, like [SDL](https://www.libsdl.org/), but the advantage of GLFW is that it also abstracts away some of the other platform-specific things in Vulkan besides just window creation.
506
512
507
-
To install GLFW on MacOS you can follow the same instructions to install it on Linux, so please refer to that topic on this chapter.
513
+
To install GLFW on MacOS we will use the Homebrew package manager. Vulkan support is still not available on the current (at the time of this writing) stable version 3.2.1. Therefore we will install the latest version of the `glfw3` package using:
514
+
515
+
```bash
516
+
brew install glfw3 --HEAD
517
+
```
508
518
509
519
### GLM
510
520
511
-
Unlike DirectX 12, Vulkan does not include a library for linear algebra
512
-
operations, so we'll have to download one. [GLM](http://glm.g-truc.net/) is a
513
-
nice library that is designed for use with graphics APIs and is also commonly
514
-
used with OpenGL.
521
+
Vulkan does not include a library for linear algebra operations, so we'll have to download one. [GLM](http://glm.g-truc.net/) is a nice library that is designed for use with graphics APIs and is also commonly used with OpenGL.
515
522
516
523
It is a header-only library that can be installed from the `glm` package:
517
524
@@ -521,7 +528,7 @@ brew install glm
521
528
522
529
### Setting up Xcode
523
530
524
-
Now that all the dependencies are installed we can set up a basic Xcode project for Vulkan. Most of the instructions here are essentially a lot of "plumbing" so we can get all the dependencies linked to the project.
531
+
Now that all the dependencies are installed we can set up a basic Xcode project for Vulkan. Most of the instructions here are essentially a lot of "plumbing" so we can get all the dependencies linked to the project. Also, keep in mind that during the following instructions whenever we mention the folder `vulkansdk` we are refering to the folder where you extracted the Vulkan SDK.
525
532
526
533
Start Xcode and create a new Xcode project. On the window that will open select Application > Command Line Tool.
527
534
@@ -531,10 +538,10 @@ Select `Next`, write a name for the project and for `Language` select `C++`.
531
538
532
539

533
540
534
-
Press `Next` and the project should have been created. Now, let's change the code on the generated `main.cpp` file to the following code:
541
+
Press `Next` and the project should have been created. Now, let's change the code in the generated `main.cpp` file to the following code:
535
542
536
543
```c++
537
-
#include<vulkan/vulkan.h>
544
+
#defineGLFW_INCLUDE_VULKAN
538
545
#include<GLFW/glfw3.h>
539
546
540
547
#defineGLM_FORCE_RADIANS
@@ -571,43 +578,42 @@ int main() {
571
578
}
572
579
```
573
580
574
-
Xcode should already be complaining of errors such as libraries it cannot find. We will now start configuring the project to get rid of those errors. On the *Project Navigator* panel select your project. Open the *Build Settings* tab and then:
581
+
Keep in mind you are not required to understand all this code is doing yet, we are just setting up some API calls to make sure everything is working.
575
582
576
-
* Find the **Framework Search Paths** field and add a link to the `../MoltenVK/macOS` folder (which should be in the folder you clonned the MoltenVK project).
577
-
* Find the **Header Search Paths** field and add a link to `/usr/local/include` (this is where Homebrew install libraries, so the glm header files should be there), a link to `../glfw-3.2.1/include` for the glfw headers, and finally a link to `../MoltenVK/Package/Release/MoltenVK/include` for the Vulkan headers (in this example I built the framework for the Release configuration).
578
-
* Find the **Library Search Paths** field and add a link to `../glfw-3.2.1/src`.
583
+
Xcode should already be showing some errors such as libraries it cannot find. We will now start configuring the project to get rid of those errors. On the *Project Navigator* panel select your project. Open the *Build Settings* tab and then:
584
+
585
+
* Find the **Header Search Paths** field and add a link to `/usr/local/include` (this is where Homebrew install headers, so the glm and glfw3 header files should be there) and a link to `vulkansdk/macOS/include` for the Vulkan headers.
586
+
* Find the **Library Search Paths** field and add a link to `/usr/local/lib` (again, this is where Homebrew install libraries, so the glm and glfw3 lib files should be there) and a link to `vulkansdk/macOS/lib`.
579
587
580
588
It should look like so (obviously, paths will be different depending on where you placed on your files):
581
589
582
590

583
591
584
-
Above I have added the values for the Release configurations because it's the one I'm using, you just need to add the paths on the configuration that you picked.
592
+
Now, in the *Build Phases* tab, on **Link Binary With Libraries** we will add both the `glfw3` and the `vulkan` frameworks. To make things easier we will be adding he dynamic libraries in the project (you can check the documentation of these libraries if you want to use the static frameworks).
593
+
594
+
For glfw open the folder `/usr/local/lib` and there you will find a file name like `libglfw.3.x.dylib` ("x" is the library's version number, it might be different depending on when you downloaded the package from Homebrew). Simply drag that file to the Linked Frameworks and Libraries tab on Xcode.
585
595
586
-
Now, on the *General* tab, on **Linked Frameworks and Libraries** you will need to add the following frameworks:
596
+
For vulkan, go to `vulkansdk/macOS/lib`. Do the same for the file both files `libvulkan.1.dylib`and `libvulkan.1.x.xx.dylib` (where "x" will be the version number of the the SDK you downloaded).
587
597
588
-
* libc++.tbd
589
-
* libglfw3.a
590
-
* Should be at `../glfw-3.2.1/src/libglfw3.a`.
591
-
* MoltenVK.framework
592
-
* Should be at `../MoltenVK/Package/Release/MoltenVK/macOS/MoltenVK.framework`.
593
-
* Metal.framework
594
-
* IOSurface.framework
595
-
* QuartzCore.framework
596
-
* IOKit.framework
597
-
* Foundation.framework
598
-
* Cocoa.framework
599
-
* CoreVideo.framework
598
+
After adding those libraries, in the same tab on **Copy Files** change `Destination` to "Frameworks", clear the subpath and deselect "Copy only when installing". Click on the "+" sign and add all those three frameworks here aswell.
600
599
601
-
Should look like:
600
+
Your Xcode configuration should look like:
602
601
603
602

604
603
604
+
The last thing you need to setup are a couple of environment variables. On Xcode toolbar go to `Product` > `Scheme` > `Edit Scheme...`, and in the `Arguments` tab add the two following environment variables:
Finally, you should be all set! Now if you run the project (remembering to setting the build configuration to Debug or Release depending on the configuration you chose) you should see the following:
606
614
607
615

608
616
609
617
The number of extensions should be non-zero. The other logs are from the libraries, you might get different messages from those depending on your configuration.
610
618
611
-
**Note:** When using this configuration remember to keep `#include <vulkan/vulkan.h>` instead of `#define GLFW_INCLUDE_VULKAN` when creating your applications, otherwise the code won't build.
612
-
613
619
You are now all set for [the real thing](!Drawing_a_triangle/Setup/Base_code).
0 commit comments