Skip to content

Commit e379481

Browse files
committed
Refactor tutorial phrasing and modernize Vulkan instance creation.
Updated tutorial text to use inclusive language ("we" instead of "I") and improved readability. Modernized Vulkan instance creation using RAII and cleaner initialization code in compliance with up-to-date Vulkan best practices.
1 parent 6ced724 commit e379481

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

en/03_Drawing_a_triangle/00_Setup/00_Base_code.adoc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ Just like each chunk of memory allocated with `malloc` requires a call to
8383
`free`, every Vulkan object that we create needs to be explicitly destroyed when
8484
we no longer need it. In c{pp} it is possible to perform automatic resource
8585
management using https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization[RAII]
86-
or smart pointers provided in the `<memory>` header. In an attempt to make
87-
Vulkan easier to work with, and demonstrate modern Vulkan programming. This
88-
tutorial will not only use RAII with smart pointers, it will endeavor to
89-
demonstrate the latest methods and extensions which should hopefully make
90-
Vulkan a joy to use. Just because we enjoy working with low level graphics
91-
APIs, we shouldn't make the bar too high to learn how to do so. Where
92-
appropriate, we will discuss concerns for resource management for freeing
93-
resources. However, for this tutorial, we'll demonstrate
94-
that we can get pretty far with a basic destructor to clean up after
95-
our work.
86+
or smart pointers provided in the `<memory>` header. This tutorial is an attempt
87+
to make Vulkan easier to work with, and demonstrate modern Vulkan
88+
programming. This tutorial will not only use RAII with smart pointers, it
89+
will endeavor to demonstrate the latest methods and extensions which should
90+
hopefully make Vulkan a joy to use. Just because we enjoy working with
91+
low level graphics APIs, we shouldn't make the bar too high to learn how
92+
to do so. Where appropriate, we will discuss concerns for resource
93+
management for freeing resources. However, for this tutorial, we'll
94+
demonstrate that we can get pretty far with a basic destructor to clean up
95+
after our work.
9696

9797
Vulkan objects are either created directly with functions like `vkCreateXXX`, or
9898
allocated through another object with functions like `vkAllocateXXX`. After
@@ -158,7 +158,7 @@ specification and everything else works perfectly fine.
158158
#include <GLFW/glfw3.h>
159159
----
160160

161-
That way GLFW will include its own definitions and automatically load the Vulkan
161+
That way, GLFW will include its own definitions and automatically load the Vulkan
162162
C header with it. Add a `initWindow` function and add a call to it from the
163163
`run` function before the other calls. We'll use that function to initialize
164164
GLFW and create a window.

en/03_Drawing_a_triangle/00_Setup/01_Instance.adoc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,6 @@ for (const auto& extension : extensions) {
197197
}
198198
----
199199

200-
You can add this code to the `createInstance` function if you'd like to provide some details about the Vulkan support.
201-
As a challenge, try to create a function that checks if all the extensions returned by `glfwGetRequiredInstanceExtensions` are included in the supported extensions list.
202-
203-
== Cleaning up
204-
205-
The `VkInstance` should be only destroyed right before the program exits.
206-
It can be destroyed in `cleanup` with the `vkDestroyInstance` function:
207-
208-
[,c++]
209-
----
210-
void cleanup() {
211-
vkDestroyInstance(instance, nullptr);
212-
----
213-
214200
You can add this code to the `createInstance` function if you'd like to provide
215201
some details about the Vulkan support. As a challenge, try to create a function
216202
that checks if all the extensions returned by

en/03_Drawing_a_triangle/00_Setup/02_Validation_layers.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ specifying their name. All the useful standard validation is bundled into a
8484
layer included in the SDK that is known as `VK_LAYER_KHRONOS_validation`.
8585

8686
Let's first add two configuration variables to the program to specify the layers
87-
to enable and whether to enable them or not. I've chosen to base that value on
87+
to enable and whether to enable them or not. We've chosen to base that value on
8888
whether the program is being compiled in debug mode or not. The `NDEBUG` macro
8989
is part of the c{pp} standard and means "not debug".
9090

@@ -188,7 +188,7 @@ std::vector<const char*> getRequiredExtensions() {
188188

189189
The extensions specified by GLFW are always required, as we're working with
190190
the GLFW dependency for windowing, but the debug messenger extension is
191-
conditionally added. Note that I've used the
191+
conditionally added. Note that We've used the
192192
`VK_EXT_DEBUG_UTILS_EXTENSION_NAME` macro here which is equal to the literal
193193
string "VK_EXT_debug_utils". Using this macro lets you avoid typos.
194194

@@ -299,13 +299,13 @@ debugMessenger = std::make_unique<vk::raii::DebugUtilsMessengerEXT>( *instance,
299299
----
300300

301301
The `messageSeverity` field allows you to specify all the types of
302-
severities you would like your callback to be called for. I've specified
302+
severities you would like your callback to be called for. We've specified
303303
all types except for `VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT` here to
304304
receive notifications about possible problems while leaving out verbose
305305
general debug info.
306306

307307
Similarly, the `messageType` field lets you filter which types of messages
308-
your callback is notified about. I've simply enabled all types here. You
308+
your callback is notified about. We've simply enabled all types here. You
309309
can always disable some if they're not useful to you.
310310

311311
Finally, the `pfnUserCallback` field specifies the pointer to the callback
@@ -344,11 +344,11 @@ to the Vulkan SDK and go to the `Config` directory. There you will find a
344344

345345
To configure the layer settings for your own application, copy the file to the
346346
`Debug` and `Release` directories of your project and follow the instructions to
347-
set the desired behavior. However, for the remainder of this tutorial, I'll
347+
set the desired behavior. However, for the remainder of this tutorial, We will
348348
assume that you're using the default settings.
349349

350-
Throughout this tutorial, I'll be making a couple of intentional mistakes to show
351-
you how helpful the validation layers are with catching them and to teach you
350+
Throughout this tutorial, we will be making a couple of intentional mistakes
351+
to show you how helpful the validation layers are with catching them and to teach you
352352
how important it is to know exactly what you're doing with Vulkan. Now it's time
353353
to look at link:03_Physical_devices_and_queue_families.adoc[Vulkan devices in the system].
354354

en/90_FAQ.adoc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@ for(uint32_t i = 0; i < glfwExtensionCount; i++) {
4242
requiredExtensions.emplace_back(glfwExtensions[i]);
4343
}
4444
45-
requiredExtensions.emplace_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
45+
requiredExtensions.emplace_back(vk::KHRPortabilityEnumerationExtensionName);
4646
47-
createInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
48-
49-
createInfo.enabledExtensionCount = (uint32_t) requiredExtensions.size();
50-
createInfo.ppEnabledExtensionNames = requiredExtensions.data();
51-
52-
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
53-
throw std::runtime_error("failed to create instance!");
54-
}
47+
vk::InstanceCreateInfo createInfo(vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR, &appInfo, {}, requiredExtensions);
48+
instance = std::make_unique<vk::raii::Instance>(context, createInfo);
5549
----

0 commit comments

Comments
 (0)