Skip to content

Commit 14866cd

Browse files
committed
Adjust documentation to source changes
1 parent d436b8d commit 14866cd

15 files changed

+94
-87
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,17 @@ Or use the tuple:
150150

151151
[,c++]
152152
----
153-
auto [result, imageIndex] = swapChain->acquireNextImage( UINT64_MAX, **presentCompleteSemaphore[currentFrame], nullptr );
154-
if (result == vk::Result::eErrorOutOfDateKHR) {
155-
recreateSwapChain();
156-
return;
157-
}
158-
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR) {
159-
throw std::runtime_error("failed to acquire swap chain image!");
160-
}
153+
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
154+
155+
if (result == vk::Result::eErrorOutOfDateKHR)
156+
{
157+
recreateSwapChain();
158+
return;
159+
}
160+
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
161+
{
162+
throw std::runtime_error("failed to acquire swap chain image!");
163+
}
161164
----
162165

163166
Those examples are from later parts of our tutorial, this is just an example

en/03_Drawing_a_triangle/03_Drawing/03_Frames_in_flight.adoc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,35 @@ We will use a frame index for that purpose:
7777

7878
[,c++]
7979
----
80-
uint32_t currentFrame = 0;
80+
uint32_t frameIndex 0;
8181
----
8282

8383
The `drawFrame` function can now be modified to use the right objects:
8484

8585
[,c++]
8686
----
8787
void drawFrame() {
88-
while ( vk::Result::eTimeout == device.waitForFences( inFlightFences[currentFrame], vk::True, UINT64_MAX ) )
88+
while ( vk::Result::eTimeout == device.waitForFences( inFlightFences[frameIndex], vk::True, UINT64_MAX ) )
8989
;
90-
auto [result, imageIndex] = swapChain.acquireNextImage( UINT64_MAX, presentCompleteSemaphores[currentFrame], nullptr );
90+
auto [result, imageIndex] = swapChain.acquireNextImage( UINT64_MAX, presentCompleteSemaphores[frameIndex], nullptr );
9191
92-
device.resetFences( inFlightFences[currentFrame] );
92+
device.resetFences( inFlightFences[frameIndex] );
9393
9494
...
9595
96-
commandBuffers[currentFrame].reset();
97-
recordCommandBuffer(commandBuffers[currentFrame], imageIndex);
96+
commandBuffers[frameIndex].reset();
97+
recordCommandBuffer(commandBuffers[frameIndex], imageIndex);
9898
9999
...
100100
101101
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
102-
const vk::SubmitInfo submitInfo{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*presentCompleteSemaphores[currentFrame],
103-
.pWaitDstStageMask = &waitDestinationStageMask, .commandBufferCount = 1, .pCommandBuffers = &*commandBuffers[currentFrame],
104-
.signalSemaphoreCount = 1, .pSignalSemaphores = &*renderFinishedSemaphores[currentFrame] };
102+
const vk::SubmitInfo submitInfo{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*presentCompleteSemaphores[frameIndex],
103+
.pWaitDstStageMask = &waitDestinationStageMask, .commandBufferCount = 1, .pCommandBuffers = &*commandBuffers[frameIndex],
104+
.signalSemaphoreCount = 1, .pSignalSemaphores = &*renderFinishedSemaphores[frameIndex] };
105105
106106
...
107107
108-
graphicsQueue.submit(submitInfo, inFlightFences[currentFrame]);
108+
graphicsQueue.submit(submitInfo, inFlightFences[frameIndex]);
109109
}
110110
----
111111

@@ -116,7 +116,7 @@ Of course, we shouldn't forget to advance to the next frame every time:
116116
void drawFrame() {
117117
...
118118
119-
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
119+
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
120120
}
121121
----
122122

en/03_Drawing_a_triangle/04_Swap_chain_recreation.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Usually happens after a window resize.
8787

8888
[,c++]
8989
----
90-
auto [result, imageIndex] = swapChain.acquireNextImage( UINT64_MAX, *presentCompleteSemaphores[currentFrame], nullptr );
90+
auto [result, imageIndex] = swapChain.acquireNextImage( UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr );
9191
9292
if (result == vk::Result::eErrorOutOfDateKHR) {
9393
recreateSwapChain();
@@ -113,7 +113,7 @@ if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptima
113113
throw std::runtime_error("failed to present swap chain image!");
114114
}
115115
116-
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
116+
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
117117
----
118118

119119
The `vkQueuePresentKHR` function returns the same values with the same meaning.
@@ -135,10 +135,10 @@ The beginning of `drawFrame` should now look like this:
135135

136136
[,c++]
137137
----
138-
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
138+
vkWaitForFences(device, 1, &inFlightFences[frameIndex], VK_TRUE, UINT64_MAX);
139139
140140
uint32_t imageIndex;
141-
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
141+
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[frameIndex], VK_NULL_HANDLE, &imageIndex);
142142
143143
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
144144
recreateSwapChain();
@@ -148,7 +148,7 @@ if (result == VK_ERROR_OUT_OF_DATE_KHR) {
148148
}
149149
150150
// Only reset the fence if we are submitting work
151-
vkResetFences(device, 1, &inFlightFences[currentFrame]);
151+
vkResetFences(device, 1, &inFlightFences[frameIndex]);
152152
----
153153

154154
== Handling resizes explicitly

en/04_Vertex_buffers/01_Vertex_buffer_creation.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ We're going to extend the `recordCommandBuffer` function to do that.
230230

231231
[,c++]
232232
----
233-
commandBuffers[currentFrame].bindPipeline(vk::PipelineBindPoint::eGraphics, *graphicsPipeline);
233+
commandBuffers[frameIndex].bindPipeline(vk::PipelineBindPoint::eGraphics, *graphicsPipeline);
234234
235-
commandBuffers[currentFrame].bindVertexBuffers(0, *vertexBuffer, {0});
235+
commandBuffers[frameIndex].bindVertexBuffers(0, *vertexBuffer, {0});
236236
237-
commandBuffers[currentFrame].draw(3, 1, 0, 0);
237+
commandBuffers[frameIndex].draw(3, 1, 0, 0);
238238
----
239239

240240
The `vkCmdBindVertexBuffers` function is used to bind vertex buffers to bindings, like the one we set up in the previous chapter.

en/04_Vertex_buffers/03_Index_buffer.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ It's unfortunately not possible to use different indices for each vertex attribu
102102

103103
[,c++]
104104
----
105-
commandBuffers[currentFrame].bindVertexBuffers(0, *vertexBuffer, {0});
106-
commandBuffers[currentFrame].bindIndexBuffer( *indexBuffer, 0, vk::IndexType::eUint16 );
105+
commandBuffers[frameIndex].bindVertexBuffers(0, *vertexBuffer, {0});
106+
commandBuffers[frameIndex].bindIndexBuffer( *indexBuffer, 0, vk::IndexType::eUint16 );
107107
----
108108

109109
An index buffer is bound with `vkCmdBindIndexBuffer` which has the index buffer, a byte offset into it, and the type of index data as parameters.
@@ -114,7 +114,7 @@ Remove the `vkCmdDraw` line and replace it with `vkCmdDrawIndexed`:
114114

115115
[,c++]
116116
----
117-
commandBuffers[currentFrame].drawIndexed(indices.size(), 1, 0, 0, 0);
117+
commandBuffers[frameIndex].drawIndexed(indices.size(), 1, 0, 0, 0);
118118
----
119119

120120
A call to this function is very similar to `vkCmdDraw`.

en/05_Uniform_buffers/00_Descriptor_set_layout_and_buffer.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,17 @@ Create a new function `updateUniformBuffer` and add a call to it from the `drawF
267267
void drawFrame() {
268268
...
269269
270-
updateUniformBuffer(currentFrame);
270+
updateUniformBuffer(frameIndex);
271271
272272
...
273273
274-
const vk::SubmitInfo submitInfo{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*presentCompleteSemaphore[currentFrame],
275-
.pWaitDstStageMask = &waitDestinationStageMask, .commandBufferCount = 1, .pCommandBuffers = &*commandBuffers[currentFrame],
276-
.signalSemaphoreCount = 1, .pSignalSemaphores = &*renderFinishedSemaphore[currentFrame] };
274+
const vk::SubmitInfo submitInfo{.waitSemaphoreCount = 1,
275+
.pWaitSemaphores = &*presentCompleteSemaphores[frameIndex],
276+
.pWaitDstStageMask = &waitDestinationStageMask,
277+
.commandBufferCount = 1,
278+
.pCommandBuffers = &*commandBuffers[frameIndex],
279+
.signalSemaphoreCount = 1,
280+
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
277281
278282
...
279283
}

en/05_Uniform_buffers/01_Descriptor_pool_and_sets.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ This needs to be done before the `vkCmdDrawIndexed` call:
165165

166166
[,c++]
167167
----
168-
commandBuffers[currentFrame].bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, *descriptorSets[currentFrame], nullptr);
169-
commandBuffers[currentFrame].drawIndexed(indices.size(), 1, 0, 0, 0);
168+
commandBuffers[frameIndex].bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, *descriptorSets[frameIndex], nullptr);
169+
commandBuffers[frameIndex].drawIndexed(indices.size(), 1, 0, 0, 0);
170170
----
171171

172172
Unlike vertex and index buffers, descriptor sets are not unique to graphics pipelines.

en/08_Loading_models.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Remember to also change the `vkCmdBindIndexBuffer` parameter:
7171

7272
[,c++]
7373
----
74-
commandBuffers[currentFrame]->bindIndexBuffer( **indexBuffer, 0, vk::IndexType::eUint32 );
74+
commandBuffers[frameIndex]->bindIndexBuffer( **indexBuffer, 0, vk::IndexType::eUint32 );
7575
----
7676

7777
The tinyobjloader library is included in the same way as STB libraries.

en/11_Compute_Shader.adoc

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ This image shows the relation between these two in three dimensions:
443443

444444
image::/images/compute_space.svg[]
445445

446-
The number of dimensions for work groups (defined by `computeCommandBuffers[currentFrame]->dispatch`) and invocations depends (defined by the local sizes in the compute shader) on how input data is structured.
446+
The number of dimensions for work groups (defined by `computeCommandBuffers[frameIndex]->dispatch`) and invocations depends (defined by the local sizes in the compute shader) on how input data is structured.
447447
If you e.g.,
448448
work on a one-dimensional array, like we do in this chapter, you only have to specify the x dimension for both.
449449

@@ -534,27 +534,27 @@ We use this to index into our particle array.
534534
=== Dispatch
535535

536536
Now it's time to actually tell the GPU to do some compute.
537-
This is done by calling `computeCommandBuffers[currentFrame]->dispatch` inside a command buffer.
538-
While not perfectly true, a dispatch is for compute as a draw call like `commandBuffers[currentFrame]->draw` is for graphics.
537+
This is done by calling `computeCommandBuffers[frameIndex]->dispatch` inside a command buffer.
538+
While not perfectly true, a dispatch is for compute as a draw call like `commandBuffers[frameIndex]->draw` is for graphics.
539539
This dispatches a given number of compute work items in at max.
540540
three dimensions.
541541

542542
[,c++]
543543
----
544-
computeCommandBuffers[currentFrame]->begin({});
544+
computeCommandBuffers[frameIndex]->begin({});
545545
...
546546
547-
computeCommandBuffers[currentFrame]->bindPipeline(vk::PipelineBindPoint::eCompute, *computePipeline);
548-
computeCommandBuffers[currentFrame]->bindDescriptorSets(vk::PipelineBindPoint::eCompute, *computePipelineLayout, 0, {computeDescriptorSets[currentFrame]}, {});
547+
computeCommandBuffers[frameIndex]->bindPipeline(vk::PipelineBindPoint::eCompute, *computePipeline);
548+
computeCommandBuffers[frameIndex]->bindDescriptorSets(vk::PipelineBindPoint::eCompute, *computePipelineLayout, 0, {computeDescriptorSets[frameIndex]}, {});
549549
550-
computeCommandBuffers[currentFrame]->dispatch( PARTICLE_COUNT / 256, 1, 1 );
550+
computeCommandBuffers[frameIndex]->dispatch( PARTICLE_COUNT / 256, 1, 1 );
551551
552552
...
553553
554-
computeCommandBuffers[currentFrame]->end();
554+
computeCommandBuffers[frameIndex]->end();
555555
----
556556

557-
The `computeCommandBuffers[currentFrame]->dispatch` will dispatch `PARTICLE_COUNT / 256` local work groups in the x dimension.
557+
The `computeCommandBuffers[frameIndex]->dispatch` will dispatch `PARTICLE_COUNT / 256` local work groups in the x dimension.
558558
As our particle array is linear, we leave the other two dimensions at one, resulting in a one-dimensional dispatch.
559559
But why do we divide the number of particles (in our array) by 256?
560560
That's because in the previous paragraph, we defined that every compute shader in a work group will do 256 invocations.
@@ -574,9 +574,9 @@ As our sample does both compute and graphics operations, we'll be doing two subm
574574
[,c++]
575575
----
576576
...
577-
computeQueue->submit(submitInfo, **computeInFlightFences[currentFrame]);
577+
computeQueue->submit(submitInfo, **computeInFlightFences[frameIndex]);
578578
...
579-
graphicsQueue->submit(submitInfo, **inFlightFences[currentFrame]);
579+
graphicsQueue->submit(submitInfo, **inFlightFences[frameIndex]);
580580
----
581581

582582
The first submit to the compute queue updates the particle positions using the compute shader, and the second submit will then use that updated data to draw the particle system.
@@ -623,30 +623,30 @@ We then use these to synchronize the compute buffer submission with the graphics
623623
----
624624
{
625625
// Compute submission
626-
while ( vk::Result::eTimeout == device->waitForFences(**computeInFlightFences[currentFrame], vk::True, UINT64_MAX) )
626+
while ( vk::Result::eTimeout == device->waitForFences(**computeInFlightFences[frameIndex], vk::True, UINT64_MAX) )
627627
;
628628
629-
updateUniformBuffer(currentFrame);
630-
device->resetFences( **computeInFlightFences[currentFrame] );
631-
computeCommandBuffers[currentFrame]->reset();
629+
updateUniformBuffer(frameIndex);
630+
device->resetFences( **computeInFlightFences[frameIndex] );
631+
computeCommandBuffers[frameIndex]->reset();
632632
recordComputeCommandBuffer();
633633
634-
const vk::SubmitInfo submitInfo({}, {}, {**computeCommandBuffers[currentFrame]}, { **computeFinishedSemaphores[currentFrame]});
635-
computeQueue->submit(submitInfo, **computeInFlightFences[currentFrame]);
634+
const vk::SubmitInfo submitInfo({}, {}, {**computeCommandBuffers[frameIndex]}, { **computeFinishedSemaphores[frameIndex]});
635+
computeQueue->submit(submitInfo, **computeInFlightFences[frameIndex]);
636636
}
637637
{
638638
// Graphics submission
639-
while ( vk::Result::eTimeout == device->waitForFences(**inFlightFences[currentFrame], vk::True, UINT64_MAX))
639+
while ( vk::Result::eTimeout == device->waitForFences(**inFlightFences[frameIndex], vk::True, UINT64_MAX))
640640
...
641641
642-
device->resetFences( **inFlightFences[currentFrame] );
643-
commandBuffers[currentFrame]->reset();
642+
device->resetFences( **inFlightFences[frameIndex] );
643+
commandBuffers[frameIndex]->reset();
644644
recordCommandBuffer(imageIndex);
645645
646-
vk::Semaphore waitSemaphores[] = {**presentCompleteSemaphore[currentFrame], **computeFinishedSemaphores[currentFrame]};
646+
vk::Semaphore waitSemaphores[] = {**presentCompleteSemaphore[frameIndex], **computeFinishedSemaphores[frameIndex]};
647647
vk::PipelineStageFlags waitDestinationStageMask[] = { vk::PipelineStageFlagBits::eVertexInput, vk::PipelineStageFlagBits::eColorAttachmentOutput };
648-
const vk::SubmitInfo submitInfo( waitSemaphores, waitDestinationStageMask, {**commandBuffers[currentFrame]}, {**renderFinishedSemaphore[currentFrame]} );
649-
graphicsQueue->submit(submitInfo, **inFlightFences[currentFrame]);
648+
const vk::SubmitInfo submitInfo( waitSemaphores, waitDestinationStageMask, {**commandBuffers[frameIndex]}, {**renderFinishedSemaphore[frameIndex]} );
649+
graphicsQueue->submit(submitInfo, **inFlightFences[frameIndex]);
650650
----
651651

652652
Similar to the sample in the
@@ -724,7 +724,7 @@ vk::SubmitInfo computeSubmitInfo{
724724
.pWaitSemaphores = &*semaphore,
725725
.pWaitDstStageMask = waitStages,
726726
.commandBufferCount = 1,
727-
.pCommandBuffers = &*computeCommandBuffers[currentFrame],
727+
.pCommandBuffers = &*computeCommandBuffers[frameIndex],
728728
.signalSemaphoreCount = 1,
729729
.pSignalSemaphores = &*semaphore
730730
};
@@ -750,7 +750,7 @@ vk::SubmitInfo graphicsSubmitInfo{
750750
.pWaitSemaphores = &*semaphore,
751751
.pWaitDstStageMask = &waitStage,
752752
.commandBufferCount = 1,
753-
.pCommandBuffers = &*commandBuffers[currentFrame],
753+
.pCommandBuffers = &*commandBuffers[frameIndex],
754754
.signalSemaphoreCount = 1,
755755
.pSignalSemaphores = &*semaphore
756756
};
@@ -817,9 +817,9 @@ We then bind and draw it like we would with any vertex buffer:
817817

818818
[,c++]
819819
----
820-
commandBuffers[currentFrame]->bindVertexBuffers(0, { *shaderStorageBuffers[currentFrame] }, {0});
820+
commandBuffers[frameIndex]->bindVertexBuffers(0, { *shaderStorageBuffers[frameIndex] }, {0});
821821
822-
commandBuffers[currentFrame]->draw( PARTICLE_COUNT, 1, 0, 0 );
822+
commandBuffers[frameIndex]->draw( PARTICLE_COUNT, 1, 0, 0 );
823823
----
824824

825825
== Conclusion

en/16_Multiple_Objects.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void updateUniformBuffers() {
257257
};
258258
259259
// Copy the UBO data to the mapped memory
260-
memcpy(gameObject.uniformBuffersMapped[currentFrame], &ubo, sizeof(ubo));
260+
memcpy(gameObject.uniformBuffersMapped[frameIndex], &ubo, sizeof(ubo));
261261
}
262262
}
263263
----
@@ -274,22 +274,22 @@ void recordCommandBuffer(uint32_t imageIndex) {
274274
// ... (beginning of the method remains the same)
275275
276276
// Bind vertex and index buffers (shared by all objects)
277-
commandBuffers[currentFrame].bindVertexBuffers(0, *vertexBuffer, {0});
278-
commandBuffers[currentFrame].bindIndexBuffer(*indexBuffer, 0, vk::IndexType::eUint32);
277+
commandBuffers[frameIndex].bindVertexBuffers(0, *vertexBuffer, {0});
278+
commandBuffers[frameIndex].bindIndexBuffer(*indexBuffer, 0, vk::IndexType::eUint32);
279279
280280
// Draw each object with its own descriptor set
281281
for (const auto& gameObject : gameObjects) {
282282
// Bind the descriptor set for this object
283-
commandBuffers[currentFrame].bindDescriptorSets(
283+
commandBuffers[frameIndex].bindDescriptorSets(
284284
vk::PipelineBindPoint::eGraphics,
285285
*pipelineLayout,
286286
0,
287-
*gameObject.descriptorSets[currentFrame],
287+
*gameObject.descriptorSets[frameIndex],
288288
nullptr
289289
);
290290
291291
// Draw the object
292-
commandBuffers[currentFrame].drawIndexed(indices.size(), 1, 0, 0, 0);
292+
commandBuffers[frameIndex].drawIndexed(indices.size(), 1, 0, 0, 0);
293293
}
294294
295295
// ... (end of the method remains the same)

0 commit comments

Comments
 (0)