Skip to content

Commit 9463f35

Browse files
committed
Close #98
1 parent cbb3627 commit 9463f35

File tree

27 files changed

+190
-157
lines changed

27 files changed

+190
-157
lines changed

bookcontents/chapter-05/chapter-05.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public class Render {
418418
private final CmdPool[] cmdPools;
419419
private final Fence[] fences;
420420
private final Queue.GraphicsQueue graphQueue;
421-
private final Semaphore[] imageAqSemphs;
421+
private final Semaphore[] presCompleteSemphs;
422422
private final Queue.PresentQueue presentQueue;
423423
private final Semaphore[] renderCompleteSemphs;
424424
private final ScnRender scnRender;
@@ -441,7 +441,7 @@ public class Render {
441441
for (int i = 0; i < VkUtils.MAX_IN_FLIGHT; i++) {
442442
cmdPools[i] = new CmdPool(vkCtx, graphQueue.getQueueFamilyIndex(), false);
443443
cmdBuffers[i] = new CmdBuffer(vkCtx, cmdPools[i], true, true);
444-
imageAqSemphs[i] = new Semaphore(vkCtx);
444+
presCompleteSemphs[i] = new Semaphore(vkCtx);
445445
fences[i] = new Fence(vkCtx, true);
446446
}
447447
for (int i = 0; i < numSwapChainImages; i++) {
@@ -456,7 +456,7 @@ public class Render {
456456
scnRender.cleanup();
457457

458458
Arrays.asList(renderCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
459-
Arrays.asList(imageAqSemphs).forEach(i -> i.cleanup(vkCtx));
459+
Arrays.asList(presCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
460460
Arrays.asList(fences).forEach(i -> i.cleanup(vkCtx));
461461
for (int i = 0; i < cmdPools.length; i++) {
462462
cmdBuffers[i].cleanup(vkCtx, cmdPools[i]);
@@ -520,7 +520,7 @@ public class Render {
520520

521521
recordingStart(cmdPool, cmdBuffer);
522522

523-
int imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentFrame]);
523+
int imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentFrame]);
524524
if (imageIndex < 0) {
525525
return;
526526
}
@@ -547,7 +547,7 @@ The `render` loop performs the following actions:
547547
- We then call to `recordingStart` which resets the command pool and sets the command buffer in recording mode. Remember that we will not be resetting the command
548548
buffers but the pool. After this step we could start recording "A commands".
549549
- In our case, since we do not have "A commands" yet", we just acquire next swap chain image. We will see the implementation later on, but this method returns
550-
the index of the image acquired (it may not be just the next image index). The `imageAqSemphs` array is the semaphore used to synchronize image acquisition
550+
the index of the image acquired (it may not be just the next image index). The `presCompleteSemphs` array is the semaphore used to synchronize image acquisition
551551
When the image is acquired, this semaphore will be signaled. Any operation depending on this image to be acquired, can use this semaphore as a blocking mechanism.
552552
- If the `acquireNextImage` returns a negative value, this will mean that the operation failed. This could be because the window has been resized. By now, we just return.
553553
- Then we can record "B commands" which we will do by calling `scnRender.render(vkCtx, cmdBuffer, imageIndex);`
@@ -569,7 +569,7 @@ public class Render {
569569
VkSemaphoreSubmitInfo.Buffer waitSemphs = VkSemaphoreSubmitInfo.calloc(1, stack)
570570
.sType$Default()
571571
.stageMask(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT)
572-
.semaphore(imageAqSemphs[currentFrame].getVkSemaphore());
572+
.semaphore(presCompleteSemphs[currentFrame].getVkSemaphore());
573573
VkSemaphoreSubmitInfo.Buffer signalSemphs = VkSemaphoreSubmitInfo.calloc(1, stack)
574574
.sType$Default()
575575
.stageMask(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT)
@@ -589,8 +589,8 @@ since we depend on swap chain image view, we want to make sure that the image ha
589589
- `signalSemphs`: It holds a list of semaphores that will be signaled when all the commands have finished. Remember that we use semaphores for GPU-GPU synchronization. In this case, we are submitting the semaphore used in the swap chain presentation. This will provoke that the image cannot be presented until the commands have finished, that is, until
590590
render has finished. This is why we use the `VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT`, all the commands need to have finalized their journey through the pipeline.
591591

592-
Please notice that we have different array sizes for the image acquisition semaphores and the render complete semaphores. Later one (`renderCompleteSemphs`) will need to be
593-
in accessed with the swap chain acquire image index, while the first one (`imageAqSemphs`) will just need frame in flight index.
592+
Please notice that we have different array sizes for the presentation complete semaphores and the render complete semaphores. Later one (`renderCompleteSemphs`) will need to be
593+
in accessed with the swap chain acquire image index, while the first one (`presCompleteSemphs`) will just need frame in flight index.
594594

595595
Finally, we use the current `Fence` instance, this way we block the CPU from resetting command buffers that are still in use.
596596

@@ -626,7 +626,7 @@ In order to acquire an image we need to call the function `vkAcquireNextImageKHR
626626
- `swapchain`: The handle to the Vulkan swap chain.
627627
- `timeout`: It specifies the maximum time to get blocked in this call (in nanoseconds). If the value is greater than `0` and we are not able to get an image in that time, we will get a `VK_TIMEOUT` error. In our case, we just want to block indefinitely.
628628
- `semaphore`: If it is not a null handle (`VK_NULL_HANDLE`) it must point to a valid semaphore. The semaphore will be signaled when the GPU is done with the acquired image.
629-
In our case, we use the image acquisition semaphore associated to current frame.
629+
In our case, we use the presentation complete semaphore associated to current frame.
630630
- `fence`: The purpose is the same as in the `semaphore` attribute but using a `Fence`. In our case we do not need this type of synchronization so we just pass a null.
631631
- `pImageIndex`: It is a return value attribute, It contains the index of the image acquired. It is important to note that the driver may not return always the next image in the set of swap chain images. This is the reason the `acquireNextImage` method returns the image index that has been acquired.
632632

bookcontents/chapter-07/chapter-07.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ public class Render {
772772
recordingStart(cmdPool, cmdBuffer);
773773

774774
int imageIndex;
775-
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentFrame])) < 0) {
775+
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentFrame])) < 0) {
776776
resize(engCtx);
777777
return;
778778
}
@@ -799,9 +799,9 @@ public class Render {
799799
vkCtx.resize(window);
800800

801801
Arrays.asList(renderCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
802-
Arrays.asList(imageAqSemphs).forEach(i -> i.cleanup(vkCtx));
802+
Arrays.asList(presCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
803803
for (int i = 0; i < VkUtils.MAX_IN_FLIGHT; i++) {
804-
imageAqSemphs[i] = new Semaphore(vkCtx);
804+
presCompleteSemphs[i] = new Semaphore(vkCtx);
805805
}
806806
for (int i = 0; i < vkCtx.getSwapChain().getNumImages(); i++) {
807807
renderCompleteSemphs[i] = new Semaphore(vkCtx);

bookcontents/chapter-11/chapter-11.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ public class Render {
11451145
postRender.render(vkCtx, cmdBuffer, scnRender.getAttColor());
11461146

11471147
int imageIndex;
1148-
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentFrame])) < 0) {
1148+
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentFrame])) < 0) {
11491149
resize(engCtx);
11501150
return;
11511151
}

bookcontents/chapter-17/chapter-17.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ public class Render {
15161516
guiRender.render(vkCtx, cmdBuffer, currentFrame, postRender.getAttachment());
15171517

15181518
int imageIndex;
1519-
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentFrame])) < 0) {
1519+
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentFrame])) < 0) {
15201520
resize(engCtx);
15211521
return;
15221522
}

bookcontents/chapter-20/chapter-20.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class Render {
147147
guiRender.render(vkCtx, cmdBuffer, currentFrame, postRender.getAttachment());
148148

149149
int imageIndex;
150-
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentFrame])) < 0) {
150+
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentFrame])) < 0) {
151151
resize(engCtx);
152152
return;
153153
}

booksamples/appendix-01/src/main/java/org/vulkanb/eng/graph/Render.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Render {
3030
private final GlobalBuffers globalBuffers;
3131
private final Queue.GraphicsQueue graphQueue;
3232
private final GuiRender guiRender;
33-
private final Semaphore[] imageAqSemphs;
33+
private final Semaphore[] presCompleteSemphs;
3434
private final LightRender lightRender;
3535
private final MaterialsCache materialsCache;
3636
private final ModelsCache modelsCache;
@@ -53,14 +53,14 @@ public Render(EngCtx engCtx) {
5353
cmdPools = new CmdPool[VkUtils.MAX_IN_FLIGHT];
5454
cmdBuffers = new CmdBuffer[VkUtils.MAX_IN_FLIGHT];
5555
fences = new Fence[VkUtils.MAX_IN_FLIGHT];
56-
imageAqSemphs = new Semaphore[VkUtils.MAX_IN_FLIGHT];
56+
presCompleteSemphs = new Semaphore[VkUtils.MAX_IN_FLIGHT];
5757
int numSwapChainImages = vkCtx.getSwapChain().getNumImages();
5858
renderCompleteSemphs = new Semaphore[numSwapChainImages];
5959
for (int i = 0; i < VkUtils.MAX_IN_FLIGHT; i++) {
6060
cmdPools[i] = new CmdPool(vkCtx, graphQueue.getQueueFamilyIndex(), false);
6161
cmdBuffers[i] = new CmdBuffer(vkCtx, cmdPools[i], true, true);
6262
fences[i] = new Fence(vkCtx, true);
63-
imageAqSemphs[i] = new Semaphore(vkCtx);
63+
presCompleteSemphs[i] = new Semaphore(vkCtx);
6464
}
6565
for (int i = 0; i < numSwapChainImages; i++) {
6666
renderCompleteSemphs[i] = new Semaphore(vkCtx);
@@ -100,7 +100,7 @@ public void cleanup() {
100100
animationsCache.cleanup(vkCtx);
101101

102102
Arrays.asList(renderCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
103-
Arrays.asList(imageAqSemphs).forEach(i -> i.cleanup(vkCtx));
103+
Arrays.asList(presCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
104104
Arrays.asList(fences).forEach(i -> i.cleanup(vkCtx));
105105
for (int i = 0; i < cmdPools.length; i++) {
106106
cmdBuffers[i].cleanup(vkCtx, cmdPools[i]);
@@ -167,7 +167,7 @@ public void render(EngCtx engCtx, int currentRenderFrame) {
167167
guiRender.render(vkCtx, cmdBuffer, currentRenderFrame, postRender.getAttachment());
168168

169169
int imageIndex;
170-
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentRenderFrame])) < 0) {
170+
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentRenderFrame])) < 0) {
171171
resize(engCtx);
172172
return;
173173
}
@@ -192,9 +192,9 @@ private void resize(EngCtx engCtx) {
192192
vkCtx.resize(window);
193193

194194
Arrays.asList(renderCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
195-
Arrays.asList(imageAqSemphs).forEach(i -> i.cleanup(vkCtx));
195+
Arrays.asList(presCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
196196
for (int i = 0; i < VkUtils.MAX_IN_FLIGHT; i++) {
197-
imageAqSemphs[i] = new Semaphore(vkCtx);
197+
presCompleteSemphs[i] = new Semaphore(vkCtx);
198198
}
199199
for (int i = 0; i < vkCtx.getSwapChain().getNumImages(); i++) {
200200
renderCompleteSemphs[i] = new Semaphore(vkCtx);
@@ -221,7 +221,7 @@ private void submit(CmdBuffer cmdBuff, int currentFrame, int imageIndex) {
221221
VkSemaphoreSubmitInfo.Buffer waitSemphs = VkSemaphoreSubmitInfo.calloc(1, stack)
222222
.sType$Default()
223223
.stageMask(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT)
224-
.semaphore(imageAqSemphs[currentFrame].getVkSemaphore());
224+
.semaphore(presCompleteSemphs[currentFrame].getVkSemaphore());
225225
VkSemaphoreSubmitInfo.Buffer signalSemphs = VkSemaphoreSubmitInfo.calloc(1, stack)
226226
.sType$Default()
227227
.stageMask(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT)

booksamples/appendix-02/src/main/java/org/vulkanb/eng/graph/Render.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Render {
3030
private final GlobalBuffers globalBuffers;
3131
private final Queue.GraphicsQueue graphQueue;
3232
private final GuiRender guiRender;
33-
private final Semaphore[] imageAqSemphs;
33+
private final Semaphore[] presCompleteSemphs;
3434
private final LightRender lightRender;
3535
private final MaterialsCache materialsCache;
3636
private final ModelsCache modelsCache;
@@ -53,14 +53,14 @@ public Render(EngCtx engCtx) {
5353
cmdPools = new CmdPool[VkUtils.MAX_IN_FLIGHT];
5454
cmdBuffers = new CmdBuffer[VkUtils.MAX_IN_FLIGHT];
5555
fences = new Fence[VkUtils.MAX_IN_FLIGHT];
56-
imageAqSemphs = new Semaphore[VkUtils.MAX_IN_FLIGHT];
56+
presCompleteSemphs = new Semaphore[VkUtils.MAX_IN_FLIGHT];
5757
int numSwapChainImages = vkCtx.getSwapChain().getNumImages();
5858
renderCompleteSemphs = new Semaphore[numSwapChainImages];
5959
for (int i = 0; i < VkUtils.MAX_IN_FLIGHT; i++) {
6060
cmdPools[i] = new CmdPool(vkCtx, graphQueue.getQueueFamilyIndex(), false);
6161
cmdBuffers[i] = new CmdBuffer(vkCtx, cmdPools[i], true, true);
6262
fences[i] = new Fence(vkCtx, true);
63-
imageAqSemphs[i] = new Semaphore(vkCtx);
63+
presCompleteSemphs[i] = new Semaphore(vkCtx);
6464
}
6565
for (int i = 0; i < numSwapChainImages; i++) {
6666
renderCompleteSemphs[i] = new Semaphore(vkCtx);
@@ -100,7 +100,7 @@ public void cleanup() {
100100
animationsCache.cleanup(vkCtx);
101101

102102
Arrays.asList(renderCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
103-
Arrays.asList(imageAqSemphs).forEach(i -> i.cleanup(vkCtx));
103+
Arrays.asList(presCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
104104
Arrays.asList(fences).forEach(i -> i.cleanup(vkCtx));
105105
for (int i = 0; i < cmdPools.length; i++) {
106106
cmdBuffers[i].cleanup(vkCtx, cmdPools[i]);
@@ -168,7 +168,7 @@ public void render(EngCtx engCtx, int currentRenderFrame) {
168168
guiRender.render(vkCtx, cmdBuffer, currentRenderFrame, postRender.getAttachment());
169169

170170
int imageIndex;
171-
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), imageAqSemphs[currentRenderFrame])) < 0) {
171+
if (resize || (imageIndex = swapChain.acquireNextImage(vkCtx.getDevice(), presCompleteSemphs[currentRenderFrame])) < 0) {
172172
resize(engCtx);
173173
return;
174174
}
@@ -193,9 +193,9 @@ private void resize(EngCtx engCtx) {
193193
vkCtx.resize(window);
194194

195195
Arrays.asList(renderCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
196-
Arrays.asList(imageAqSemphs).forEach(i -> i.cleanup(vkCtx));
196+
Arrays.asList(presCompleteSemphs).forEach(i -> i.cleanup(vkCtx));
197197
for (int i = 0; i < VkUtils.MAX_IN_FLIGHT; i++) {
198-
imageAqSemphs[i] = new Semaphore(vkCtx);
198+
presCompleteSemphs[i] = new Semaphore(vkCtx);
199199
}
200200
for (int i = 0; i < vkCtx.getSwapChain().getNumImages(); i++) {
201201
renderCompleteSemphs[i] = new Semaphore(vkCtx);
@@ -222,7 +222,7 @@ private void submit(CmdBuffer cmdBuff, int currentFrame, int imageIndex) {
222222
VkSemaphoreSubmitInfo.Buffer waitSemphs = VkSemaphoreSubmitInfo.calloc(1, stack)
223223
.sType$Default()
224224
.stageMask(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT)
225-
.semaphore(imageAqSemphs[currentFrame].getVkSemaphore());
225+
.semaphore(presCompleteSemphs[currentFrame].getVkSemaphore());
226226
VkSemaphoreSubmitInfo.Buffer signalSemphs = VkSemaphoreSubmitInfo.calloc(1, stack)
227227
.sType$Default()
228228
.stageMask(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"name":"org.tinylog.configuration.PropertiesConfigurationLoader",
4+
"methods":[{"name":"<init>","parameterTypes":[] }]
5+
},
6+
{
7+
"name":"org.tinylog.core.TinylogLoggingProvider",
8+
"methods":[{"name":"<init>","parameterTypes":[] }]
9+
},
10+
{
11+
"name":"org.tinylog.writers.ConsoleWriter",
12+
"methods":[{"name":"<init>","parameterTypes":["java.util.Map"] }]
13+
}
14+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"resources":{
3+
"includes":[
4+
{ "pattern":"\\Qeng.properties\\E" },
5+
{ "pattern":"\\Qtinylog.properties\\E" },
6+
{ "pattern":"^(linux|windows|macos)/(x86|x64|arm32|arm64)/org/lwjgl/(lwjgl.dll|liblwjgl.so|liblwjgl.dylib)$" },
7+
{ "pattern":"^(linux|windows|macos)/(x86|x64|arm32|arm64)/org/lwjgl/glfw/(glfw.dll|libglfw.so|libglfw.dylib)$" }
8+
]},
9+
"bundles":[]
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
;physDeviceName=Intel(R) UHD Graphics
2+
physDeviceName=NVIDIA GeForce RTX 4060 Laptop GPU
3+
requestedImages=3
4+
ups=30
5+
vkValidate=true
6+
vsync=true

0 commit comments

Comments
 (0)