Skip to content

Update, expand and simplify development environment project setup #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions en/02_Development_environment.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The `Bin` directory also contains the binaries of the Vulkan loader and the vali
Lastly, there's the `Include` directory that contains the Vulkan headers.
Feel free to explore the other files, but we won't need them for this tutorial.

The installer also sets the system environment variable `VULKAN_SDK` to the directory where the SDK is installed. That means we can easily access it's folder by using `%VULKAN_SDK%` instead of having to explicitly specify the versioned SDK folder names. This also makes updating to a new SDK dead simple, as the installer updates that variable to point at the new SDK instead.

=== GLFW

As mentioned before, Vulkan by itself is a platform agnostic API and does not include tools for creating a window to display the rendered results.
Expand All @@ -47,8 +49,9 @@ There are other libraries available for this purpose, like https://www.libsdl.or
You can find the latest release of GLFW on the http://www.glfw.org/download.html[official website].
In this tutorial we'll be using the 64-bit binaries, but you can of course also choose to build in 32 bit mode.
In that case make sure to link with the Vulkan SDK binaries in the `Lib32` directory instead of `Lib`.
After downloading it, extract the archive to a convenient location.
I've chosen to create a `Libraries` directory in the Visual Studio directory under documents.
After downloading it, extract the archive to a convenient location like `C:\Vulkan-Tutorial`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to recommend they use git to get the Vulkan Tutorial?


Extract glfw there so that you have a path called `C:\Vulkan-Tutorial\glfw` with contents similar to this:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also think about showing how to use CMake and a packaging service such as vcpkg in windows apt in linux. This way, the project will be cleaner and easier to work with in other projects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the plan for the long run ;)


image::/images/glfw_directory.png[]

Expand All @@ -57,8 +60,13 @@ image::/images/glfw_directory.png[]
Unlike DirectX 12, Vulkan does not include a library for linear algebra operations, so we'll have to download one.
http://glm.g-truc.net/[GLM] is a nice library that is designed for use with graphics APIs and is also commonly used with OpenGL.

GLM is a header-only library, so just download the https://github.com/g-truc/glm/releases[latest version] and store it in a convenient location.
You should have a directory structure similar to the following now:
GLM is a header-only library, so just download the https://github.com/g-truc/glm/releases[latest version] and store it in a convenient location like `C:\Vulkan-Tutorial`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can even mention using submodules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't want to change too much aside from the most pressing issues. I think once we have a proper CMake setup using FetchContent we can make this whole setup chapter a lot easier :)


Extract glm there so that you have a folder called `C:\Vulkan-Tutorial\glm` with contents similar to this:

image::/images/glm_directory.png[]

After setting up glfw and glm, you should now have a directory structure similar to the following:

image::/images/library_directory.png[]

Expand Down Expand Up @@ -148,6 +156,8 @@ And add the locations of the object files for Vulkan and GLFW:

image::/images/vs_link_dirs.png[]

NOTE: The GLFW folder you need to select depends on the Visual Studio version you are using. If you're using Visual Studio 2022 you need to select the `lib-vc2022` folder and if you e.g. use Visual Studio 2017 you select the `lib-vc2017` folder, etc.

Go to `+Linker -> Input+` and press `+<Edit...>+` in the `Additional Dependencies` dropdown box.

image::/images/vs_link_input.png[]
Expand Down Expand Up @@ -182,7 +192,14 @@ You'll also need `make`.

=== Vulkan Packages

The most important components you'll need for developing Vulkan applications on Linux are the Vulkan loader, validation layers, and a couple of command-line utilities to test whether your machine is Vulkan-capable:
LunarG provides the Vulkan SDK for 64-bit Linux distribution. Installation depends on your distribution and installation:

- link:https://vulkan.lunarg.com/doc/view/latest/linux/getting_started_ubuntu.html[Getting Started with the Ubuntu Vulkan SDK]
- link:https://vulkan.lunarg.com/doc/view/latest/linux/getting_started.html[Getting Started with the Linux Tarball Vulkan SDK]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Linux, I recommend to most programmers to create a directory to hold Vulkan then a soft link so all paths are always the same after upgrades. i.e.

mkdir -p ~/Vulkan_SDK && pushd ~/Vulkan_SDK
then every time you get vulkan via new udpate even:
tar -xzf /vulkan.tar.gz
ln -s latest x.x.x

Now whenever you set the Vulkan Path anywhere in a project, you point it to ~/Vulkan_SDK/latest. You can now update/downgrade Vulkan and just update the softlink to keep the same path everywhere.


NOTE: Installing the SDK via the official guides from LunarG is the preferred way. This will install all required tools and components and also makes them globally available via the path environment variable.

If your distribution isn't supported you can try to install the required SDK components used in this tutorial from different sources, but you may need to adjust some paths that are used in this tutorial to make things work:

* `sudo apt install vulkan-tools` or `sudo dnf install vulkan-tools`: Command-line utilities, most importantly `vulkaninfo` and `vkcube`.
Run these to confirm your machine supports Vulkan.
Expand All @@ -191,8 +208,6 @@ The loader looks up the functions in the driver at runtime, similarly to GLEW fo
* `sudo apt install vulkan-validationlayers-dev spirv-tools` or `sudo dnf install mesa-vulkan-devel vulkan-validation-layers-devel`: Installs the standard validation layers and required SPIR-V tools.
These are crucial when debugging Vulkan applications, and we'll discuss them in the upcoming chapter.

On Arch Linux, you can run `sudo pacman -S vulkan-devel` to install all the required tools above.

If installation was successful, you should be all set with the Vulkan portion.
Remember to run `vkcube` and ensure you see the following pop up in a window:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ Create a `compile.bat` file with the following contents:

[,bash]
----
C:/VulkanSDK/x.x.x.x/Bin/glslc.exe shader.vert -o vert.spv
C:/VulkanSDK/x.x.x.x/Bin/glslc.exe shader.frag -o frag.spv
%VULKAN_SDK%/Bin/glslc.exe shader.vert -o vert.spv
%VULKAN_SDK%/Bin/glslc.exe shader.frag -o frag.spv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$VULKAN_SDK for bash

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly that env variable isn't set on m Ubuntu setup (WSL2), even though I've installed the SDK :/

pause
----

Expand All @@ -219,11 +219,12 @@ Create a `compile.sh` file with the following contents:

[,bash]
----
/home/user/VulkanSDK/x.x.x.x/x86_64/bin/glslc shader.vert -o vert.spv
/home/user/VulkanSDK/x.x.x.x/x86_64/bin/glslc shader.frag -o frag.spv
glslc shader.vert -o vert.spv
glslc shader.frag -o frag.spv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming it's in the path, which it might not be (one can install via tarball and not setup the path).
Instead this would work:
$VULKAN_SDK/x86_64/bin/glslc
You can confirm it's in the path with which i.e.
which glslc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will incorporate this :)

----

Replace the path to `glslc` with the path to where you installed the Vulkan SDK.
NOTE: If you have installed the Vulkan SDK tools like `glslc` are added to the path and there is no need to explicitly call them from a given path. If you have manually installed glslc you may need to prepend it's path to make this work.

Make the script executable with `chmod +x compile.sh` and run it.

*End of platform-specific instructions*
Expand Down
4 changes: 2 additions & 2 deletions en/06_Texture_mapping/00_Images.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ Add the directory with `stb_image.h` to the include directories for GCC:

[,text]
----
VULKAN_SDK_PATH = /home/user/VulkanSDK/x.x.x.x/x86_64
VULKAN_SDK_PATH = /usr/include/vulkan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be correct. I'd have to look at the instructions again if LunarG advocates to install it to the system include directory. Having the includes live in the VulkanSDK path is universally accurate and covers the case where a linux user might not have super user access.

STB_INCLUDE_PATH = /home/user/libraries/stb

...

CFLAGS = -std=c++17 -I$(VULKAN_SDK_PATH)/include -I$(STB_INCLUDE_PATH)
CFLAGS = -std=c++17 -I$(VULKAN_SDK_PATH) -I$(STB_INCLUDE_PATH)
----

== Loading an image
Expand Down
4 changes: 2 additions & 2 deletions en/08_Loading_models.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Add the directory with `tiny_obj_loader.h` to the include directories for GCC:

[,text]
----
VULKAN_SDK_PATH = /home/user/VulkanSDK/x.x.x.x/x86_64
VULKAN_SDK_PATH = /usr/include/vulkan
STB_INCLUDE_PATH = /home/user/libraries/stb
TINYOBJ_INCLUDE_PATH = /home/user/libraries/tinyobjloader

...

CFLAGS = -std=c++17 -I$(VULKAN_SDK_PATH)/include -I$(STB_INCLUDE_PATH) -I$(TINYOBJ_INCLUDE_PATH)
CFLAGS = -std=c++17 -I$(VULKAN_SDK_PATH) -I$(STB_INCLUDE_PATH) -I$(TINYOBJ_INCLUDE_PATH)
----

== Sample mesh
Expand Down
Binary file modified images/glfw_directory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glm_directory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/include_dirs_stb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/include_dirs_tinyobjloader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/library_directory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/vs_include_dirs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/vs_link_dirs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.