Skip to content

Commit d1941ff

Browse files
committed
Adjust documentation
1 parent 71054d6 commit d1941ff

5 files changed

Lines changed: 97 additions & 83 deletions

File tree

attachments/19_vertex_buffer.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ class HelloTriangleApplication
375375

376376
auto bindingDescription = Vertex::getBindingDescription();
377377
auto attributeDescriptions = Vertex::getAttributeDescriptions();
378-
vk::PipelineVertexInputStateCreateInfo vertexInputInfo{.vertexBindingDescriptionCount = 1, .pVertexBindingDescriptions = &bindingDescription, .vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size()), .pVertexAttributeDescriptions = attributeDescriptions.data()};
378+
vk::PipelineVertexInputStateCreateInfo vertexInputInfo{.vertexBindingDescriptionCount = 1,
379+
.pVertexBindingDescriptions = &bindingDescription,
380+
.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size()),
381+
.pVertexAttributeDescriptions = attributeDescriptions.data()};
379382
vk::PipelineInputAssemblyStateCreateInfo inputAssembly{.topology = vk::PrimitiveTopology::eTriangleList};
380383
vk::PipelineViewportStateCreateInfo viewportState{.viewportCount = 1, .scissorCount = 1};
381384

@@ -423,11 +426,15 @@ class HelloTriangleApplication
423426

424427
void createVertexBuffer()
425428
{
426-
vk::BufferCreateInfo bufferInfo{.size = sizeof(vertices[0]) * vertices.size(), .usage = vk::BufferUsageFlagBits::eVertexBuffer, .sharingMode = vk::SharingMode::eExclusive};
429+
vk::BufferCreateInfo bufferInfo{.size = sizeof(vertices[0]) * vertices.size(),
430+
.usage = vk::BufferUsageFlagBits::eVertexBuffer,
431+
.sharingMode = vk::SharingMode::eExclusive};
427432
vertexBuffer = vk::raii::Buffer(device, bufferInfo);
428433

429434
vk::MemoryRequirements memRequirements = vertexBuffer.getMemoryRequirements();
430-
vk::MemoryAllocateInfo memoryAllocateInfo{.allocationSize = memRequirements.size, .memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent)};
435+
vk::MemoryAllocateInfo memoryAllocateInfo{
436+
.allocationSize = memRequirements.size,
437+
.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent)};
431438
vertexBufferMemory = vk::raii::DeviceMemory(device, memoryAllocateInfo);
432439

433440
vertexBuffer.bindMemory(*vertexBufferMemory, 0);

en/04_Vertex_buffers/00_Vertex_input_description.adoc

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Create a new structure called `Vertex` with the two attributes that we're going
5858

5959
[,c++]
6060
----
61-
struct Vertex {
61+
struct Vertex
62+
{
6263
glm::vec2 pos;
6364
glm::vec3 color;
6465
};
@@ -84,7 +85,7 @@ This is known as _interleaving_ vertex attributes.
8485
The next step is to tell Vulkan how to pass this data format to the vertex shader once it's been uploaded into GPU memory.
8586
There are two types of structures needed to convey this information.
8687

87-
The first structure is `VkVertexInputBindingDescription` and we'll add a member function to the `Vertex` struct to populate it with the right data.
88+
The first structure is `vk::VertexInputBindingDescription` and we'll add a member function to the `Vertex` struct to populate it with the right data.
8889

8990
[,c++]
9091
----
@@ -105,14 +106,14 @@ All of our per-vertex data is packed together in one array, so we're only going
105106
The `binding` parameter specifies the index of the binding in the array of bindings.
106107
The `stride` parameter specifies the number of bytes from one entry to the next, and the `inputRate` parameter can have one of the following values:
107108

108-
* `VK_VERTEX_INPUT_RATE_VERTEX`: Move to the next data entry after each vertex
109-
* `VK_VERTEX_INPUT_RATE_INSTANCE`: Move to the next data entry after each instance
109+
* `vk::VertexInputRate::eVertex` : Move to the next data entry after each vertex
110+
* `vk::VertexInputRate::eInstance`: Move to the next data entry after each instance
110111

111112
We're not going to use instanced rendering, so we'll stick to per-vertex data.
112113

113114
== Attribute descriptions
114115

115-
The second structure that describes how to handle vertex input is `VkVertexInputAttributeDescription`.
116+
The second structure that describes how to handle vertex input is `vk::VertexInputAttributeDescription`.
116117
We're going to add another helper function to `Vertex` to fill in these structs.
117118

118119
[,c++]
@@ -141,22 +142,20 @@ The `format` parameter describes the type of data for the attribute.
141142
A bit confusingly, the formats are specified using the same enumeration as color formats.
142143
The following shader types and formats are commonly used together:
143144

144-
* `float`: `VK_FORMAT_R32_SFLOAT`
145-
* `float2`: `VK_FORMAT_R32G32_SFLOAT`
146-
* `float3`: `VK_FORMAT_R32G32B32_SFLOAT`
147-
* `float4`: `VK_FORMAT_R32G32B32A32_SFLOAT`
145+
* `float` : `vk::Format::eR32Sfloat`
146+
* `float2`: `vk::Format::eR32G32Sfloat`
147+
* `float3`: `vk::Format::eR32G32B32Sfloat`
148+
* `float4`: `vk::Format::eR32G32B32A32Sfloat`
148149

149150
As you can see, you should use the format where the amount of color channels matches the number of components in the shader data type.
150151
It is allowed to use more channels than the number of components in the shader, but they will be silently discarded.
151152
If the number of channels is lower than the number of components, then the BGA components will use default values of `(0, 0, 1)`.
152-
The color type (`SFLOAT`, `UINT`, `SINT`) and bit width should also match the type of the shader input.
153+
The color type (`Sfloat`, `Uint`, `Sint`) and bit width should also match the type of the shader input.
153154
See the following examples:
154155

155-
* `int2`: `VK_FORMAT_R32G32_SINT`, a 2-component vector of 32-bit signed
156-
integers
157-
* `uint4`: `VK_FORMAT_R32G32B32A32_UINT`, a 4-component vector of 32-bit
158-
unsigned integers
159-
* `double`: `VK_FORMAT_R64_SFLOAT`, a double-precision (64-bit) float
156+
* `int2` : `vk::Format::eR32G32Sint`, a 2-component vector of 32-bit signed integers
157+
* `uint4` : `vk::Format::eR32G32B32A32Uint`, a 4-component vector of 32-bit unsigned integers
158+
* `double`: `vk::Format::eR64Sfloat`, a double-precision (64-bit) float
160159

161160
The `format` parameter implicitly defines the byte size of attribute data and the `offset` parameter has specified the number of bytes since the start of the per-vertex data to read from.
162161
The binding is loading one `Vertex` at a time and the position attribute (`pos`) is at an offset of `0` bytes from the beginning of this struct.
@@ -171,17 +170,18 @@ Find the `vertexInputInfo` struct and modify it to reference the two description
171170

172171
[,c++]
173172
----
174-
auto bindingDescription = Vertex::getBindingDescription();
175-
auto attributeDescriptions = Vertex::getAttributeDescriptions();
176-
vk::PipelineVertexInputStateCreateInfo vertexInputInfo { .vertexBindingDescriptionCount =1, .pVertexBindingDescriptions = &bindingDescription,
177-
.vertexAttributeDescriptionCount = attributeDescriptions.size(), .pVertexAttributeDescriptions = attributeDescriptions.data() };
173+
auto bindingDescription = Vertex::getBindingDescription();
174+
auto attributeDescriptions = Vertex::getAttributeDescriptions();
175+
vk::PipelineVertexInputStateCreateInfo vertexInputInfo{ .vertexBindingDescriptionCount = 1,
176+
.pVertexBindingDescriptions = &bindingDescription,
177+
.vertexAttributeDescriptionCount = static_cast<uint32_t>( attributeDescriptions.size() ),
178+
.pVertexAttributeDescriptions = attributeDescriptions.data() };
178179
----
179180

180181
The pipeline is now ready to accept vertex data in the format of the `vertices` container and pass it on to our vertex shader.
181-
If you run the program now with validation layers enabled, you'll see that it complains that there is no vertex buffer bound to the binding.
182182
The xref:./01_Vertex_buffer_creation.adoc[next step] is to create a vertex buffer and move the vertex data to it so the GPU is able to access it.
183183

184-
link:/attachments/18_vertex_input.cpp[C{pp} code] /
185-
link:/attachments/18_shader_vertexbuffer.slang[slang shader] /
186-
link:/attachments/18_shader_vertexbuffer.vert[GLSL Vertex shader] /
187-
link:/attachments/18_shader_vertexbuffer.frag[GLSL Fragment shader]
184+
link:/attachments/19_vertex_buffer.cpp[C{pp} code] /
185+
link:/attachments/19_shader_vertexbuffer.slang[slang shader] /
186+
link:/attachments/19_shader_vertexbuffer.vert[GLSL Vertex shader] /
187+
link:/attachments/19_shader_vertexbuffer.frag[GLSL Fragment shader]

0 commit comments

Comments
 (0)