Skip to content

Commit 768722e

Browse files
committed
Trying to somehow fix the mess that this chapter is...
1 parent 6cf840a commit 768722e

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

en/03_Drawing_a_triangle/03_Drawing/02_Rendering_and_presentation.adoc

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void createSyncObjects() {
192192
}
193193
----
194194

195-
Creating semaphores requires filling in the `VkSemaphoreCreateInfo`, but in the current version of the API it doesn't actually have any required fields besides `sType`:
195+
Creating semaphores requires filling in the `vk::SemaphoreCreateInfo`, but in the current version of the API it doesn't actually have any fields relevant to the tutorial:
196196

197197
[,c++]
198198
----
@@ -210,12 +210,12 @@ Onto the main drawing function!
210210
== Waiting for the previous frame
211211

212212
At the start of the frame, we want to wait until the previous frame has finished, so that the command buffer and semaphores are available to use.
213-
To do that, we call `vkWaitForFences`:
213+
To do that, we call `device.waitForFences`:
214214

215215
[,c++]
216216
----
217217
void drawFrame() {
218-
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
218+
auto fenceResult = device.waitForFences(*drawFence, vk::True, UINT64_MAX);
219219
}
220220
----
221221

@@ -234,14 +234,13 @@ void drawFrame() {
234234
}
235235
----
236236

237-
The first two parameters of `vkAcquireNextImageKHR` are the logical device and the swap chain from which we wish to acquire an image.
238-
The third parameter specifies a timeout in nanoseconds for an image to become available.
237+
The first parameter specifies a timeout in nanoseconds for an image to become available.
239238
Using the maximum value of a 64-bit unsigned integer means we effectively disable the timeout.
240239

241240
The next two parameters specify synchronization objects that are to be signaled when the presentation engine is finished using the image.
242241
That's the point in time where we can start drawing to it.
243242
It is possible to specify a semaphore, fence or both.
244-
We're going to use our `imageAvailableSemaphore` for that purpose here.
243+
We're going to use our `presentCompleteSemaphores` for that purpose here.
245244

246245
The last parameter specifies a variable to output the index of the swap chain image that has become available.
247246
The index refers to the `VkImage` in our `swapChainImages` array.
@@ -263,19 +262,26 @@ already happened, so we know to wait on it later.
263262

264263
[,c++]
265264
----
266-
device.resetFences( *drawFence );
265+
device.resetFences(*drawFence);
267266
----
268267

269268
With a fully recorded command buffer, we can now submit it.
270269

271270
== Submitting the command buffer
272271

273-
Queue submission and synchronization is configured through parameters in the `VkSubmitInfo` structure.
272+
Queue submission and synchronization is configured through parameters in the `vk::SubmitInfo` structure.
274273

275274
[,c++]
276275
----
277276
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
278-
const vk::SubmitInfo submitInfo( **presentCompleteSemaphore, waitDestinationStageMask, **commandBuffer, **renderFinishedSemaphore );
277+
const vk::SubmitInfo submitInfo{
278+
.waitSemaphoreCount = 1,
279+
.pWaitSemaphores = &*presentCompleteSemaphore,
280+
.pWaitDstStageMask = &waitDestinationStageMask,
281+
.commandBufferCount = 1,
282+
.pCommandBuffers = &*commandBuffer,
283+
.signalSemaphoreCount = 1,
284+
.pSignalSemaphores = &*renderFinishedSemaphore};
279285
----
280286

281287
The first three parameters specify which semaphores to wait on before execution begins and in which stage(s) of the pipeline to wait.
@@ -295,18 +301,10 @@ In our case we're using the `renderFinishedSemaphore` for that purpose.
295301
graphicsQueue.submit(submitInfo, *drawFence);
296302
----
297303

298-
We can now submit the command buffer to the graphics queue using `vkQueueSubmit`.
299-
The function takes an array of `VkSubmitInfo` structures as argument for efficiency when the workload is much larger.
304+
We can now submit the command buffer to the graphics queue using `submit`.
305+
The function takes an array of `vk::SubmitInfo` structures as argument for efficiency when the workload is much larger.
300306
The last parameter references an optional fence that will be signaled when the command buffers finish execution.
301-
This allows us to know when it is safe for the command buffer to be reused, thus we want to give it `drawFence`.
302-
Now we want the CPU to wait while the GPU finishes rendering that frame we
303-
just submitted:
304-
305-
[,c++]
306-
----
307-
while ( vk::Result::eTimeout == device.waitForFences( *drawFence, vk::True, UINT64_MAX ) )
308-
;
309-
----
307+
This allows us to know when it is safe for the command buffer to be reused, thus we want to give it `drawFence`, which is waited on in the next frame.
310308

311309
== Subpass dependencies
312310

@@ -365,14 +363,19 @@ link:/attachments/15_hello_triangle.cpp[demo code.]
365363
== Presentation
366364

367365
The last step of drawing a frame is submitting the result back to the swap chain to have it eventually show up on the screen.
368-
Presentation is configured through a `VkPresentInfoKHR` structure at the end of the `drawFrame` function.
366+
Presentation is configured through a `vk::PresentInfoKHR` structure at the end of the `drawFrame` function.
369367

370368
[,c++]
371369
----
372-
const vk::PresentInfoKHR presentInfoKHR( **renderFinishedSemaphore, **swapChain, imageIndex );
370+
const vk::PresentInfoKHR presentInfoKHR{
371+
.waitSemaphoreCount = 1,
372+
.pWaitSemaphores = &*renderFinishedSemaphore,
373+
.swapchainCount = 1,
374+
.pSwapchains = &*swapChain,
375+
.pImageIndices = &imageIndex};
373376
----
374377

375-
The first two parameters specify which semaphores to wait on before presentation can happen, just like `VkSubmitInfo`.
378+
The first two parameters specify which semaphores to wait on before presentation can happen, just like `vk::SubmitInfo`.
376379
Since we want to wait on the command buffer to finish execution, thus our triangle being drawn, we take the semaphores which will be signaled and wait on them, thus we use `signalSemaphores`.
377380

378381
The next two parameters specify the swap chains to present images to and the index of the image for each swap chain.
@@ -384,16 +387,16 @@ presentInfo.pResults = nullptr; // Optional
384387
----
385388

386389
There is one last optional parameter called `pResults`.
387-
It allows you to specify an array of `VkResult` values to check for every swap chain if presentation was successful.
390+
It allows you to specify an array of `vk::Result` values to check for every swap chain if presentation was successful.
388391
It's not necessary if you're only using a single swap chain, because you can use the return value of the present function.
389392

390393
[,c++]
391394
----
392-
result = presentQueue.presentKHR( presentInfoKHR );
395+
result = presentQueue.presentKHR(presentInfoKHR);
393396
----
394397

395-
The `vkQueuePresentKHR` function submits the request to present an image to the swap chain.
396-
We'll add error handling for both `vkAcquireNextImageKHR` and `vkQueuePresentKHR` in the next chapter, because their failure does not necessarily mean that the program should terminate, unlike the functions we've seen so far.
398+
The `presentKHR` function submits the request to present an image to the swap chain.
399+
We'll add error handling for both `swapChain.acquireNextImage` and `queue.presentKHR` in the next chapter, because their failure does not necessarily mean that the program should terminate, unlike the functions we've seen so far.
397400

398401
If you did everything correctly up to this point, then you should now see something resembling the following when you run your program:
399402

0 commit comments

Comments
 (0)