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: chap02/chap02.md
+20-6Lines changed: 20 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,9 @@ We'll be writing the contents of the constructor and the `initInstance` method.
35
35
36
36
## `VkApplicationInfo`
37
37
38
-
This object, while not required, is pretty standard in most applications. You can find it documented [here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkApplicationInfo). It is defined in the Vulkan header as:
38
+
This object, while not required, is pretty standard in most applications.
- `engineVersion` is an unsigned integer variable containing the developer-supplied version number of the engine used to create the application.
58
62
- `apiVersion` is the version of the Vulkan API against which the application expects to run (encoded). If `apiVersion` is `0` the implementation must ignore it, otherwise if the implementation does not support the requested `apiVersion` it must return `VK_ERROR_INCOMPATIBLE_DRIVER`.
59
63
60
-
Following the usage guidelines outlined in the specification, `VkApplicationInfo` usage would look something like this:
64
+
**Usage for `VkApplicationInfo`**:
61
65
62
66
```cpp
63
67
VkApplicationInfo appInfo = {};
@@ -72,7 +76,9 @@ You'll notice that for `apiVersion`, I am using `VK_MAKE_VERSION`. This allows t
72
76
73
77
## `VkInstanceCreateInfo`
74
78
75
-
This object, **is** required. You can find it documented [here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkInstanceCreateInfo). It is defined in the Vulkan header as:
79
+
This object, **is** required unlike `VkApplicationInfo`. This will be used to inform the instance of our application info, layers we'll be using, and extensions we'll be using.
- `enabledExtensionCount` is the number of global extensions to enable.
97
105
- `ppEnabledExtensionNames` is a pointer to an array of `enabledExtensionCount` null-terminated UTF-8 strings containing the names of extensions to enable.
98
106
99
-
Following the usage guidelines outlined in the specification, `VkInstanceCreateInfo` usage would look something like this:
Finally we're ready to create our instance. You can find the documentation for `vkCreateInstance`[here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#initialization-instances). Let's look at the definition:
140
+
Finally we're ready to create our instance.
141
+
142
+
**Definition for `vkCreateInstance`**:
133
143
134
144
```cpp
135
145
VkResult vkCreateInstance(
@@ -138,11 +148,15 @@ VkResult vkCreateInstance(
138
148
VkInstance* pInstance);
139
149
```
140
150
151
+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#initialization-instances) for `vkCreateInstance`**:
152
+
141
153
- `pCreateInfo` points to an instance of `VkInstanceCreateInfo` controlling creation of the instance.
142
154
- `pAllocator` controls host memory allocation.
143
155
- `pInstance` points a `VkInstance` handle in which the resulting instance is returned.
144
156
145
-
Notice this returns a `VkResult`. This value is used for many function calls in Vulkan to indicate failure during execution of the function body. In this case, the value will tell us if the instance creation was successful or if it failed. Valid usage of `vkCreateInstance` would look like this:
157
+
Notice this returns a `VkResult`. This value is used for many function calls in Vulkan to indicate failure during execution of the function body. In this case, the value will tell us if the instance creation was successful or if it failed.
158
+
159
+
**Usage for `vkCreateInstance`**:
146
160
147
161
```cpp
148
162
VkResult res = vkCreateInstance(&createInfo, NULL, &instance);
Copy file name to clipboardExpand all lines: chap03/chap03.md
+35-13Lines changed: 35 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,9 @@ A `VkPhysicalDevice` is a data type that we will use to represent each piece of
10
10
11
11
## `vkEnumeratePhysicalDevices`
12
12
13
-
To get a list of all the physical devices in the system, we can call use this method. You can find more information [in the same section](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#devsandqueues-physical-device-enumeration). The definition looks like:
13
+
To get a list of all the physical devices in the system, we can call use this method.
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#devsandqueues-physical-device-enumeration) for `vkEnumeratePhysicalDevices`**:
23
25
24
26
- `instance` is a handle to a Vulkan instance previously created with `vkCreateInstance`.
25
27
- `pPhysicalDeviceCount` is a pointer to an integer related to the number of physical devices available or queried.
26
28
- `pPhysicalDevices` is either `NULL` or a pointer to an array of `VkPhysicalDevice` structures.
27
29
28
30
Before we create allocate memory to store the physical devices, we need to figure out how many there are. We can do this by calling `vkEnumeratePhysicalDevices` with a value of `NULL` for `pPhysicalDevices`.
29
31
32
+
**Usage for `vkEnumeratePhysicalDevices`**:
33
+
30
34
```cpp
31
35
uint32_t deviceCount = 0;
32
36
VkResult result = vkEnumeratePhysicalDevices(instance, &deviceCount, NULL);
@@ -49,7 +53,9 @@ assert(result == VK_SUCCESS);
49
53
50
54
## `VkPhysicalDeviceProperties`
51
55
52
-
`VkPhysicalDeviceProperties` is a data type that we will use to represent properties of each physical device. There's not much to say here other than we will pass a pointer of this type to the implementation. The implementation will then write properties for the specified `VkPhysicalDevice`. You can find all the information you need [here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkPhysicalDeviceProperties). The definition looks like this:
56
+
`VkPhysicalDeviceProperties` is a data type that we will use to represent properties of each physical device. There's not much to say here other than we will pass a pointer of this type to the implementation. The implementation will then write properties for the specified `VkPhysicalDevice`.
-`apiVersion` is the version of Vulkan supported by the device (encoded).
71
77
-`driverVersion` is the vendor-specified version of the driver.
@@ -93,19 +99,23 @@ This may be useful if you are trying to detect if you have an integrated GPU ver
93
99
94
100
## `vkGetPhysicalDeviceProperties`
95
101
96
-
A call to this method is not necessary in most cases. However, it can be useful in retrieving information about your device. You can find more information [in the same section]https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkGetPhysicalDeviceProperties) along with the definition itself. The definition looks like:
102
+
A call to this method is not necessary in most cases. However, it can be useful in retrieving information about your device.
103
+
104
+
**Definition for `vkGetPhysicalDeviceProperties`**:
97
105
98
106
```cpp
99
107
voidvkGetPhysicalDeviceProperties(
100
108
VkPhysicalDevice physicalDevice,
101
109
VkPhysicalDeviceProperties* pProperties);
102
110
```
103
111
112
+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkGetPhysicalDeviceProperties) for `vkGetPhysicalDeviceProperties`**:
113
+
104
114
- `instance` is a handle to a Vulkan instance previously created with `vkCreateInstance`.
105
115
- `pPhysicalDeviceCount` is a pointer to an integer related to the number of physical devices available or queried.
106
116
- `pPhysicalDevices` is either `NULL` or a pointer to an array of `VkPhysicalDevice` structures.
107
117
108
-
Following the usage guidelines outlined in the specification, a call to `vkGetPhysicalDeviceProperties()` would look like this:
The next step is to create a device using `vkCreateDevice`. However, in order to do that, we must have a `VkDeviceCreateInfo` object. And, as you may have guessed having seen the specification, we need a `VkDeviceQueueCreateInfo` object. You can find the documentation for this object [here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkDeviceQueueCreateInfo). Let's look at the definition:
152
+
The next step is to create a device using `vkCreateDevice`. However, in order to do that, we must have a `VkDeviceCreateInfo` object. And, as you may have guessed having seen the specification, we need a `VkDeviceQueueCreateInfo` object.
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkDeviceQueueCreateInfo) for `VkDeviceQueueCreateInfo`**:
168
+
155
169
- `sType` is the type of this structure.
156
170
- `pNext` is NULL or a pointer to an extension-specific structure.
157
171
- `flags` is reserved for future use.
158
172
- `queueFamilyIndex` is an unsigned integer indicating the index of the queue family to create on this device. This index corresponds to the index of an element of the `pQueueFamilyProperties` array that was returned by `vkGetPhysicalDeviceQueueFamilyProperties`.
159
173
- `queueCount` is an unsigned integer specifying the number of queues to create in the queue family indicated by `queueFamilyIndex`.
160
174
- `pQueuePriorities` is an array of `queueCount` normalized floating point values, specifying priorities of work that will be submitted to each created queue.
161
175
162
-
Following the usage guidelines outlined in the specification, creating a `VkDeviceQueueCreateInfo` looks like this:
176
+
**Usage for `VkDeviceQueueCreateInfo`**:
163
177
164
178
```cpp
165
179
float priorities[] = { 1.0f };
@@ -176,7 +190,9 @@ You'll note that we create a `float` array with a single value. Each value in th
176
190
177
191
## `VkDeviceCreateInfo`
178
192
179
-
The parent of `VkDeviceQueueCreateInfo` is `VkDeviceCreateInfo`. You can find more information [here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkDeviceCreateInfo) and the definition is included below:
193
+
The parent of `VkDeviceQueueCreateInfo` is `VkDeviceCreateInfo`.
- `ppEnabledExtensionNames` is a pointer to an array of `enabledExtensionCount` null-terminated UTF-8 strings containing the names of extensions to enable for the created device.
205
223
- `pEnabledFeatures` is NULL or a pointer to a `VkPhysicalDeviceFeatures` structure that contains boolean indicators of all the features to be enabled.
206
224
207
-
Following the usage guidelines outlined in the specification, creating a `VkDeviceCreateInfo` looks like this:
Finally, to wrap up this section, we need to create a logical device. We'll use the `vkCreateDevice` which you can find [here](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkCreateDevice) in the specification. This is how it is defined:
242
+
Finally, to wrap up this section, we need to create a logical device. We'll use the `vkCreateDevice`.
243
+
244
+
**Definition for `vkCreateDevice`**:
225
245
226
246
```cpp
227
247
VkResult vkCreateDevice(
@@ -231,12 +251,14 @@ VkResult vkCreateDevice(
231
251
VkDevice* pDevice);
232
252
```
233
253
254
+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkCreateDevice) for `vkCreateDevice`**:
255
+
234
256
- `physicalDevice` must be one of the device handles returned from a call to `vkEnumeratePhysicalDevices`.
235
257
- `pCreateInfo` is a pointer to a `VkDeviceCreateInfo` structure containing information about how to create the device.
236
258
- `pAllocator` controls host memory allocation.
237
259
- `pDevice` points to a handle in which the created `VkDevice` is returned.
238
260
239
-
Following the usage guidelines outlined in the specification, calling `vkCreateDevice` looks like this:
261
+
**Usage for `vkCreateDevice`**:
240
262
241
263
```cpp
242
264
VkResult result = vkCreateDevice(physicalDevice, &deviceInfo, NULL, &logicalDevice);
0 commit comments