Skip to content

Commit ca42702

Browse files
authored
Use aggregate initialization for bufferInfo to match demo code and rest of tutorial (#183)
Update instructions to match new initialization Fix physicalDevice is not a pointer Use aggregate initialization for memoryAllocateInfo to match demo code and rest of tutorial Fix wrong information for bindMemory function call
1 parent a1b7048 commit ca42702

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

en/04_Vertex_buffers/01_Vertex_buffer_creation.adoc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,22 @@ Creating a buffer requires us to fill a `VkBufferCreateInfo` structure.
4141

4242
[,c++]
4343
----
44-
vk::BufferCreateInfo bufferInfo({}, sizeof(vertices[0]) * vertices.size(), vk::BufferUsageFlagBits::eVertexBuffer, vk::SharingMode::eExclusive);
44+
vk::BufferCreateInfo bufferInfo{ .size = sizeof(vertices[0]) * vertices.size(), .usage = vk::BufferUsageFlagBits::eVertexBuffer, .sharingMode = vk::SharingMode::eExclusive };
4545
----
4646

47-
The first field of the constructor is the flags, used to configure sparse buffer memory, which is not relevant right now.
48-
We'll leave it at the default value of `0`.
49-
Next is `size`, which specifies the size of the buffer in bytes. Calculating
47+
The `size` field specifies the size of the buffer in bytes. Calculating
5048
the byte size of the vertex data is straightforward with `sizeof`.
5149

52-
The third field is `usage`, which indicates for which purposes the data in the
50+
The `usage` field indicates for which purposes the data in the
5351
buffer is going to be used. It is possible to specify multiple purposes using
5452
a bitwise or. Our use case will be a vertex buffer, we'll look at other
5553
types of usage in future chapters.
5654

5755
Just like the images in the swap chain, buffers can also be owned by a specific queue family or be shared between multiple at the same time.
5856
The buffer will only be used from the graphics queue, so we can stick to exclusive access.
5957

60-
The `flags` parameter is used to configure sparse buffer memory, which is not relevant right now.
61-
We'll leave it at the default value of `0`.
58+
There is also a `flags` field, which is used to configure sparse buffer memory. It's not relevant right now, so
59+
we'll leave it at the default value of `0`.
6260

6361
We can now create the buffer with `vkCreateBuffer`.
6462
Define a class member to hold the buffer handle and call it `vertexBuffer`.
@@ -110,7 +108,7 @@ First we need to query info about the available types of memory using `vkGetPhys
110108

111109
[,c++]
112110
----
113-
vk::PhysicalDeviceMemoryProperties memProperties = physicalDevice->getMemoryProperties();
111+
vk::PhysicalDeviceMemoryProperties memProperties = physicalDevice.getMemoryProperties();
114112
----
115113

116114
The `VkPhysicalDeviceMemoryProperties` structure has two arrays `memoryTypes` and `memoryHeaps`.
@@ -162,7 +160,7 @@ We now have a way to determine the right memory type, so we can actually allocat
162160

163161
[,c++]
164162
----
165-
vk::MemoryAllocateInfo memoryAllocateInfo( memRequirements.size, findMemoryType(memRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent) );
163+
vk::MemoryAllocateInfo memoryAllocateInfo{ .allocationSize = memRequirements.size, .memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent) };
166164
----
167165

168166
Memory allocation is now as simple as specifying the size and type, both of which are derived from the memory requirements of the vertex buffer and the desired property.
@@ -185,7 +183,7 @@ If memory allocation was successful, then we can now associate this memory with
185183
vertexBuffer.bindMemory( *vertexBufferMemory, 0 );
186184
----
187185

188-
The first three parameters are self-explanatory, and the fourth parameter is the offset within the region of memory.
186+
The first parameter is self-explanatory, and the second parameter is the offset within the region of memory.
189187
Since this memory is allocated specifically for this the vertex buffer, the offset is simply `0`.
190188
If the offset is non-zero, then it is required to be divisible by `memRequirements.alignment`.
191189

0 commit comments

Comments
 (0)