Skip to content

Commit da731f8

Browse files
Updated formatting: definition, documentation, usage
1 parent 097f654 commit da731f8

File tree

11 files changed

+607
-298
lines changed

11 files changed

+607
-298
lines changed

book.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
# Generate the .epub version of the book
4+
echo "Generating EPUB"
45
pandoc book.md \
56
chap02/chap02.md \
67
chap03/chap03.md \
@@ -19,6 +20,7 @@ pandoc book.md \
1920
-o VulkanApiBook.epub
2021

2122
# Generate the .pdf version of the book
23+
echo "Generating PDF"
2224
pandoc book.md \
2325
chap02/chap02.md \
2426
chap03/chap03.md \
@@ -38,5 +40,6 @@ pandoc book.md \
3840
--variable sansfont="Fira Sans" \
3941
--variable monofont="Fira Mono" \
4042
--variable fontsize="11pt" \
41-
-V geometry:margin="1.5cm" \
43+
-V geometry:margin="2.0cm" \
44+
--highlight-style tango \
4245
-o VulkanApiBook.pdf

chap02/chap02.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ We'll be writing the contents of the constructor and the `initInstance` method.
3535

3636
## `VkApplicationInfo`
3737

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.
39+
40+
**Definition for `VkApplicationInfo`**:
3941

4042
```cpp
4143
typedef struct VkApplicationInfo {
@@ -49,6 +51,8 @@ typedef struct VkApplicationInfo {
4951
} VkApplicationInfo;
5052
```
5153
54+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkApplicationInfo) for `VkApplicationInfo`**:
55+
5256
- `sType` is the type of this structure.
5357
- `pNext` is `NULL` or a pointer to an extension-specific structure.
5458
- `pApplicationName` is a pointer to a null-terminated UTF-8 string containing the name of the application.
@@ -57,7 +61,7 @@ typedef struct VkApplicationInfo {
5761
- `engineVersion` is an unsigned integer variable containing the developer-supplied version number of the engine used to create the application.
5862
- `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`.
5963
60-
Following the usage guidelines outlined in the specification, `VkApplicationInfo` usage would look something like this:
64+
**Usage for `VkApplicationInfo`**:
6165
6266
```cpp
6367
VkApplicationInfo appInfo = {};
@@ -72,7 +76,9 @@ You'll notice that for `apiVersion`, I am using `VK_MAKE_VERSION`. This allows t
7276

7377
## `VkInstanceCreateInfo`
7478

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.
80+
81+
**Definition for `VkInstanceCreateInfo`**:
7682

7783
```cpp
7884
typedef struct VkInstanceCreateInfo {
@@ -87,6 +93,8 @@ typedef struct VkInstanceCreateInfo {
8793
} VkInstanceCreateInfo;
8894
```
8995
96+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkInstanceCreateInfo) for `VkInstanceCreateInfo`**:
97+
9098
- `sType` is the type of this structure.
9199
- `pNext` is `NULL` or a pointer to an extension-specific structure.
92100
- `flags` is reserved for future use.
@@ -96,7 +104,7 @@ typedef struct VkInstanceCreateInfo {
96104
- `enabledExtensionCount` is the number of global extensions to enable.
97105
- `ppEnabledExtensionNames` is a pointer to an array of `enabledExtensionCount` null-terminated UTF-8 strings containing the names of extensions to enable.
98106
99-
Following the usage guidelines outlined in the specification, `VkInstanceCreateInfo` usage would look something like this:
107+
**Usage for `VkInstanceCreateInfo`**:
100108
101109
```cpp
102110
VkInstanceCreateInfo createInfo = {};
@@ -129,7 +137,9 @@ createInfo.ppEnabledExtensionNames = enabledExtensions.data();
129137

130138
## `vkCreateInstance`
131139

132-
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`**:
133143

134144
```cpp
135145
VkResult vkCreateInstance(
@@ -138,11 +148,15 @@ VkResult vkCreateInstance(
138148
VkInstance* pInstance);
139149
```
140150
151+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#initialization-instances) for `vkCreateInstance`**:
152+
141153
- `pCreateInfo` points to an instance of `VkInstanceCreateInfo` controlling creation of the instance.
142154
- `pAllocator` controls host memory allocation.
143155
- `pInstance` points a `VkInstance` handle in which the resulting instance is returned.
144156
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`**:
146160
147161
```cpp
148162
VkResult res = vkCreateInstance(&createInfo, NULL, &instance);

chap03/chap03.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ A `VkPhysicalDevice` is a data type that we will use to represent each piece of
1010

1111
## `vkEnumeratePhysicalDevices`
1212

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.
14+
15+
**Definition for `vkEnumeratePhysicalDevices`**:
1416

1517
```cpp
1618
VkResult vkEnumeratePhysicalDevices(
@@ -19,14 +21,16 @@ VkResult vkEnumeratePhysicalDevices(
1921
VkPhysicalDevice* pPhysicalDevices);
2022
```
2123
22-
The arguments are documented as follows:
24+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#devsandqueues-physical-device-enumeration) for `vkEnumeratePhysicalDevices`**:
2325
2426
- `instance` is a handle to a Vulkan instance previously created with `vkCreateInstance`.
2527
- `pPhysicalDeviceCount` is a pointer to an integer related to the number of physical devices available or queried.
2628
- `pPhysicalDevices` is either `NULL` or a pointer to an array of `VkPhysicalDevice` structures.
2729
2830
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`.
2931
32+
**Usage for `vkEnumeratePhysicalDevices`**:
33+
3034
```cpp
3135
uint32_t deviceCount = 0;
3236
VkResult result = vkEnumeratePhysicalDevices(instance, &deviceCount, NULL);
@@ -49,7 +53,9 @@ assert(result == VK_SUCCESS);
4953
5054
## `VkPhysicalDeviceProperties`
5155
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`.
57+
58+
**Definition for `VkPhysicalDeviceProperties**:
5359
5460
```cpp
5561
typedef struct VkPhysicalDeviceProperties {
@@ -65,7 +71,7 @@ typedef struct VkPhysicalDeviceProperties {
6571
} VkPhysicalDeviceProperties;
6672
```
6773

68-
Here is the documentation for each field we get back:
74+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkPhysicalDeviceProperties) for `VkPhysicalDeviceProperties**:
6975

7076
- `apiVersion` is the version of Vulkan supported by the device (encoded).
7177
- `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
9399

94100
## `vkGetPhysicalDeviceProperties`
95101

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`**:
97105

98106
```cpp
99107
void vkGetPhysicalDeviceProperties(
100108
VkPhysicalDevice physicalDevice,
101109
VkPhysicalDeviceProperties* pProperties);
102110
```
103111
112+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkGetPhysicalDeviceProperties) for `vkGetPhysicalDeviceProperties`**:
113+
104114
- `instance` is a handle to a Vulkan instance previously created with `vkCreateInstance`.
105115
- `pPhysicalDeviceCount` is a pointer to an integer related to the number of physical devices available or queried.
106116
- `pPhysicalDevices` is either `NULL` or a pointer to an array of `VkPhysicalDevice` structures.
107117
108-
Following the usage guidelines outlined in the specification, a call to `vkGetPhysicalDeviceProperties()` would look like this:
118+
**Usage for `vkGetPhysicalDeviceProperties`**:
109119
110120
```cpp
111121
VkPhysicalDeviceProperties physicalProperties = {};
@@ -128,7 +138,7 @@ As I mentioned before, the API version is encoded. So if we want, we can use thr
128138
- `VK_VERSION_MINOR(version)`
129139
- `VK_VERSION_PATCH(version)`
130140
131-
So,, to output the API version, you can use this:
141+
So, to output the API version, you can use this:
132142
133143
```cpp
134144
fprintf(stdout, "API Version: %d.%d.%d\n",
@@ -139,7 +149,9 @@ fprintf(stdout, "API Version: %d.%d.%d\n",
139149

140150
## `VkDeviceQueueCreateInfo`
141151

142-
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.
153+
154+
**Definition for `VkDeviceQueueCreateInfo`**:
143155

144156
```cpp
145157
typedef struct VkDeviceQueueCreateInfo {
@@ -152,14 +164,16 @@ typedef struct VkDeviceQueueCreateInfo {
152164
} VkDeviceQueueCreateInfo;
153165
```
154166
167+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkDeviceQueueCreateInfo) for `VkDeviceQueueCreateInfo`**:
168+
155169
- `sType` is the type of this structure.
156170
- `pNext` is NULL or a pointer to an extension-specific structure.
157171
- `flags` is reserved for future use.
158172
- `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`.
159173
- `queueCount` is an unsigned integer specifying the number of queues to create in the queue family indicated by `queueFamilyIndex`.
160174
- `pQueuePriorities` is an array of `queueCount` normalized floating point values, specifying priorities of work that will be submitted to each created queue.
161175
162-
Following the usage guidelines outlined in the specification, creating a `VkDeviceQueueCreateInfo` looks like this:
176+
**Usage for `VkDeviceQueueCreateInfo`**:
163177
164178
```cpp
165179
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
176190

177191
## `VkDeviceCreateInfo`
178192

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`.
194+
195+
**Definition for `VkDeviceCreateInfo`**:
180196

181197
```cpp
182198
typedef struct VkDeviceCreateInfo {
@@ -193,6 +209,8 @@ typedef struct VkDeviceCreateInfo {
193209
} VkDeviceCreateInfo;
194210
```
195211
212+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#VkDeviceCreateInfo) for `VkDeviceCreateInfo`**:
213+
196214
- `sType` is the type of this structure.
197215
- `pNext` is `NULL` or a pointer to an extension-specific structure.
198216
- `flags` is reserved for future use.
@@ -204,7 +222,7 @@ typedef struct VkDeviceCreateInfo {
204222
- `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.
205223
- `pEnabledFeatures` is NULL or a pointer to a `VkPhysicalDeviceFeatures` structure that contains boolean indicators of all the features to be enabled.
206224
207-
Following the usage guidelines outlined in the specification, creating a `VkDeviceCreateInfo` looks like this:
225+
**Usage for `VkDeviceCreateInfo`**:
208226
209227
```cpp
210228
std::vector<const char *> enabledExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
@@ -221,7 +239,9 @@ deviceInfo.pEnabledFeatures = NULL;
221239

222240
## `vkCreateDevice`
223241

224-
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`**:
225245

226246
```cpp
227247
VkResult vkCreateDevice(
@@ -231,12 +251,14 @@ VkResult vkCreateDevice(
231251
VkDevice* pDevice);
232252
```
233253
254+
**[Documentation](https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkCreateDevice) for `vkCreateDevice`**:
255+
234256
- `physicalDevice` must be one of the device handles returned from a call to `vkEnumeratePhysicalDevices`.
235257
- `pCreateInfo` is a pointer to a `VkDeviceCreateInfo` structure containing information about how to create the device.
236258
- `pAllocator` controls host memory allocation.
237259
- `pDevice` points to a handle in which the created `VkDevice` is returned.
238260
239-
Following the usage guidelines outlined in the specification, calling `vkCreateDevice` looks like this:
261+
**Usage for `vkCreateDevice`**:
240262
241263
```cpp
242264
VkResult result = vkCreateDevice(physicalDevice, &deviceInfo, NULL, &logicalDevice);

0 commit comments

Comments
 (0)