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
@@ -196,54 +196,18 @@ The number of extensions should be non-zero. Congratulations, you're all set for
196
196
## Linux
197
197
198
198
These instructions will be aimed at Ubuntu users, but you may be able to follow
199
-
along by compiling the LunarG SDK yourself and changing the `apt` commands to
200
-
the package manager commands that are appropriate for you. You should have a
201
-
compiler that supports C++17 (GCC 7+ or Clang 5+). You also need both CMake and
202
-
make.
199
+
along by changing the `apt` commands to the package manager commands that are appropriate for you. You should have a compiler that supports C++17 (GCC 7+ or Clang 5+). You'll also need make.
203
200
204
-
### Vulkan SDK
205
-
206
-
The most important component you'll need for developing Vulkan applications is
207
-
the SDK. It includes the headers, standard validation layers, debugging tools
208
-
and a loader for the Vulkan functions. The loader looks up the functions in the
209
-
driver at runtime, similarly to GLEW for OpenGL - if you're familiar with that.
210
-
211
-
The SDK can be downloaded from [the LunarG website](https://vulkan.lunarg.com/)
212
-
using the buttons at the bottom of the page. You don't have to create an
213
-
account, but it will give you access to some additional documentation that may
214
-
be useful to you.
215
-
216
-

217
-
218
-
Open a terminal in the directory where you've downloaded the `.tar.gz` archive and extract it:
201
+
### Vulkan Packages
219
202
220
-
```bash
221
-
tar -xzf vulkansdk-linux-x86_64-xxx.tar.gz
222
-
```
223
-
224
-
It will extract all of the files in the SDK to a subdirectory with the SDK version as name in the working directory. Move the directory to a convenient place and take
225
-
note of its path. Open a terminal in the root directory of the SDK, which will
226
-
contain files like `build_examples.sh`.
227
-
228
-
The samples in the SDK and one of the libraries that you will later use for your
229
-
program depend on the XCB library. This is a C library that is used to interface
230
-
with the X Window System. It can be installed in Ubuntu from the `libxcb1-dev`
231
-
package. You also need the generic X development files that come with the
232
-
`xorg-dev` package.
233
-
234
-
```bash
235
-
sudo apt install libxcb1-dev xorg-dev
236
-
```
203
+
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:
237
204
238
-
You can now build the Vulkan examples in the SDK by running:
205
+
*`sudo apt install vulkan-tools`: Command-line utilities, most importantly `vulkaninfo` and `vkcube`. Run these to confirm your machine supports Vulkan.
206
+
*`sudo apt install libvulkan-dev`: Installs Vulkan loader. The loader looks up the functions in the driver at runtime, similarly to GLEW for OpenGL - if you're familiar with that.
207
+
*`sudo apt install vulkan-validationlayers-dev`: Installs the standard validation layers. These are crucial when debugging Vulkan applications, and we'll discuss them in the upcoming chapter.
239
208
240
-
```bash
241
-
./build_examples.sh
242
-
```
243
-
244
-
If compilation was successful, then you should now have a
245
-
`./examples/build/vkcube` executable. Run it from the `examples/build` directory
246
-
with `./vkcube` and ensure that you see the following pop up in a window:
209
+
If installation was successful, you should be all set with the Vulkan portion. Remember to run
210
+
`vkcube` and ensure you see the following pop up in a window:
247
211
248
212

249
213
@@ -263,24 +227,10 @@ purpose, like [SDL](https://www.libsdl.org/), but the advantage of GLFW is that
263
227
it also abstracts away some of the other platform-specific things in Vulkan
264
228
besides just window creation.
265
229
266
-
We'll be installing GLFW from source instead of using a package, because the
267
-
Vulkan support requires a recent version. You can find the sources on the [official website](http://www.glfw.org/).
268
-
Extract the source code to a convenient directory and open a terminal in the
269
-
directory with files like `CMakeLists.txt`.
270
-
271
-
Run the following commands to generate a makefile and compile GLFW:
230
+
We'll be installing GLFW from the following command:
272
231
273
232
```bash
274
-
cmake .
275
-
make
276
-
```
277
-
278
-
You may see a warning stating `Could NOT find Vulkan`, but you can safely ignore
279
-
this message. If compilation was successful, then you can install GLFW into the
280
-
system libraries by running:
281
-
282
-
```bash
283
-
sudo make install
233
+
sudo apt install libglfw3-dev
284
234
```
285
235
286
236
### GLM
@@ -296,6 +246,16 @@ It is a header-only library that can be installed from the `libglm-dev` package:
296
246
sudo apt install libglm-dev
297
247
```
298
248
249
+
### Shader Compiler
250
+
251
+
We have just about all we need, except we'll want a program to compile shaders from the human-readable [GLSL](https://en.wikipedia.org/wiki/OpenGL_Shading_Language) to bytecode.
252
+
253
+
Two popular shader compilers are Khronos Group's `glslangValidator` and Google's `glslc`. The latter has a familiar GCC- and Clang-like usage, so we'll go with that: download Google's [unofficial binaries](https://github.com/google/shaderc/blob/main/downloads.md) and copy `glslc` to your `/usr/local/bin`. Note you may need to `sudo` depending on your permissions. To test, run `glslc` and it should rightfully complain we didn't pass any shaders to compile:
254
+
255
+
`glslc: error: no input files`
256
+
257
+
We'll cover `glslc` in depth in the [shader modules](!en/Drawing_a_triangle/Graphics_pipeline_basics/Shader_modules) chapter.
258
+
299
259
### Setting up a makefile project
300
260
301
261
Now that you have installed all of the dependencies, we can set up a basic
@@ -352,33 +312,21 @@ experience with makefiles, like how variables and rules work. If not, you can
352
312
get up to speed very quickly with [this tutorial](https://makefiletutorial.com/).
353
313
354
314
We'll first define a couple of variables to simplify the remainder of the file.
355
-
Define a `VULKAN_SDK_PATH` variable that refers to the location of the `x86_64`
Make sure to replace `user` with your own username and `x.x.x.x` with the right version. Next, define a `CFLAGS` variable that will specify the basic compiler flags:
315
+
Define a `CFLAGS` variable that will specify the basic compiler flags:
363
316
364
317
```make
365
-
CFLAGS = -std=c++17 -I$(VULKAN_SDK_PATH)/include
318
+
CFLAGS = -std=c++17 -O2
366
319
```
367
320
368
-
We're going to use modern C++ (`-std=c++17`), and we need to be
369
-
able to locate `vulkan.h` in the LunarG SDK.
321
+
We're going to use modern C++ (`-std=c++17`), and we'll set optimization level to O2. We can remove -O2 to compile programs faster, but we should remember to place it back for release builds.
370
322
371
323
Similarly, define the linker flags in a `LDFLAGS` variable:
The first flag specifies that we want to be able to find libraries like
378
-
`libvulkan.so` in the LunarG SDK's `x86_64/lib` directory. The second component
379
-
invokes `pkg-config` to automatically retrieve all of the linker flags necessary
380
-
to build an application with GLFW. Finally, `-lvulkan` links with the Vulkan
381
-
function loader that comes with the LunarG SDK.
329
+
The flag `-lglfw` is for GLFW, `-lvulkan` links with the Vulkan function loader and the remaining flags are low-level system libraries that GLFW needs.
382
330
383
331
Specifying the rule to compile `VulkanTest` is straightforward now. Make sure to
384
332
use tabs for indentation instead of spaces.
@@ -405,63 +353,25 @@ clean:
405
353
rm -f VulkanTest
406
354
```
407
355
408
-
You will find that `make clean` works perfectly fine, but `make test` will most
409
-
likely fail with the following error message:
410
-
411
-
```text
412
-
./VulkanTest: error while loading shared libraries: libvulkan.so.1: cannot open shared object file: No such file or directory
413
-
```
414
-
415
-
That's because `libvulkan.so` is not installed as system library. To alleviate
416
-
this problem, explicitly specify the library loading path using the
417
-
`LD_LIBRARY_PATH` environment variable:
356
+
Running `make test` should show the program running successfully, and displaying the number of Vulkan extensions. The application should exit with the success return code (`0`) when you close the empty window. You should now have a complete makefile that resembles the following:
You can now use this directory as a template for your Vulkan projects. Make a
456
-
copy, rename it to something like `HelloTriangle` and remove all of the code
457
-
in `main.cpp`.
458
-
459
-
Before we move on, let's explore the Vulkan SDK a bit more. There is another program in it that will be very useful for development. The `x86_64/bin/glslangValidator` and `x86_64/bin/glslc` programs will be used to compile shaders from
460
-
the human-readable [GLSL](https://en.wikipedia.org/wiki/OpenGL_Shading_Language)
461
-
to bytecode. We'll cover this in depth in the [shader modules](!en/Drawing_a_triangle/Graphics_pipeline_basics/Shader_modules)
462
-
chapter.
463
-
464
-
Feel free to explore the other files, but we won't need them for this tutorial.
374
+
You can now use this directory as a template for your Vulkan projects. Make a copy, rename it to something like `HelloTriangle` and remove all of the code in `main.cpp`.
465
375
466
376
You are now all set for [the real adventure](!en/Drawing_a_triangle/Setup/Base_code).
0 commit comments