Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fed1f96

Browse files
new instructions
1 parent 67ed7fe commit fed1f96

6 files changed

Lines changed: 41 additions & 35 deletions

File tree

02_Development_environment.md

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
In this chapter we'll set up your environment for developing Vulkan applications
22
and install some useful libraries. All of the tools we'll use, with the
3-
exception of the compiler, are compatible with both Windows and Linux, but the
3+
exception of the compiler, are compatible with Windows, Linux and MacOS, but the
44
steps for installing them differ a bit, which is why they're described
55
separately here.
66

@@ -492,26 +492,33 @@ You are now all set for [the real adventure](!Drawing_a_triangle/Setup/Base_code
492492

493493
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).
494494

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+
![](/images/vulkan_sdk_download_buttons.png)
496502

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.
498504

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:
500506

501-
![](/images/cube_demo_mac.png)
507+
[](/images/cube_demo_mac.png)
502508

503509
### GLFW
504510

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.
506512

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+
```
508518

509519
### GLM
510520

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.
515522

516523
It is a header-only library that can be installed from the `glm` package:
517524

@@ -521,7 +528,7 @@ brew install glm
521528

522529
### Setting up Xcode
523530

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.
525532

526533
Start Xcode and create a new Xcode project. On the window that will open select Application > Command Line Tool.
527534

@@ -531,10 +538,10 @@ Select `Next`, write a name for the project and for `Language` select `C++`.
531538

532539
![](/images/xcode_new_project_2.png)
533540

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:
535542

536543
```c++
537-
#include <vulkan/vulkan.h>
544+
#define GLFW_INCLUDE_VULKAN
538545
#include <GLFW/glfw3.h>
539546

540547
#define GLM_FORCE_RADIANS
@@ -571,43 +578,42 @@ int main() {
571578
}
572579
```
573580

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.
575582

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`.
579587

580588
It should look like so (obviously, paths will be different depending on where you placed on your files):
581589

582590
![](/images/xcode_paths.png)
583591

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.
585595

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).
587597

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.
600599

601-
Should look like:
600+
Your Xcode configuration should look like:
602601

603602
![](/images/xcode_frameworks.png)
604603

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:
605+
606+
* VK_ICD_FILENAMES = `vulkansdk/macOS/etc/vulkan/icd.d/MoltenVK_icd.json`
607+
* VK_LAYER_PATH = `vulkansdk/macOS/etc/vulkan/explicit_layer.d`
608+
609+
It should look like so:
610+
611+
![](/images/xcode_variables.png)
612+
605613
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:
606614

607615
![](/images/xcode_output.png)
608616

609617
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.
610618

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-
613619
You are now all set for [the real thing](!Drawing_a_triangle/Setup/Base_code).

images/xcode_frameworks.png

28.1 KB
Loading

images/xcode_new_project_2.png

4.76 KB
Loading

images/xcode_output.png

-59.1 KB
Loading

images/xcode_paths.png

28.3 KB
Loading

images/xcode_variables.png

72.3 KB
Loading

0 commit comments

Comments
 (0)