Skip to content

Commit 12a8198

Browse files
Study fix synch (#27)
* Fix: print swapchain image * Fix: remove additional fences * Fix: remove comments
1 parent e3ddb8a commit 12a8198

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/first_app.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ void FirstApp::run() {
148148
.count();
149149

150150
currentTime = newTime;
151-
152151
frameTime = glm::min(frameTime, MAX_FRAME_TIME);
153152

154153
cameraController.moveInPlaneXZ(lveWindow.getGLFWwindow(), frameTime,

src/lve_swap_chain.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,15 @@ VkResult LveSwapChain::acquireNextImage(uint32_t *imageIndex) {
7575
imageAvailableSemaphores[currentFrame], // must be a not signaled
7676
// semaphore
7777
VK_NULL_HANDLE, imageIndex);
78+
// std::cout << "frame: " << currentFrame << " SwapChain image: " <<
79+
// *imageIndex
80+
// << " Result: " << result << std::endl;
7881

7982
return result;
8083
}
8184

8285
VkResult LveSwapChain::submitCommandBuffers(const VkCommandBuffer *buffers,
8386
uint32_t *imageIndex) {
84-
if (imagesInFlight[*imageIndex] != VK_NULL_HANDLE) {
85-
vkWaitForFences(device.device(), 1, &imagesInFlight[*imageIndex], VK_TRUE,
86-
UINT64_MAX);
87-
}
88-
imagesInFlight[*imageIndex] = inFlightFences[currentFrame];
89-
9087
VkSubmitInfo submitInfo = {};
9188
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
9289

@@ -143,6 +140,11 @@ void LveSwapChain::createSwapChain() {
143140
imageCount > swapChainSupport.capabilities.maxImageCount) {
144141
imageCount = swapChainSupport.capabilities.maxImageCount;
145142
}
143+
std::cout << "swapChainSupport maxImageCount: "
144+
<< swapChainSupport.capabilities.maxImageCount << std::endl;
145+
std::cout << "swapChainSupport minImageCount: "
146+
<< swapChainSupport.capabilities.minImageCount << std::endl;
147+
std::cout << "imageCount: " << imageCount << std::endl;
146148

147149
VkSwapchainCreateInfoKHR createInfo = {};
148150
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
@@ -188,10 +190,18 @@ void LveSwapChain::createSwapChain() {
188190
// we'll first query the final number of images with vkGetSwapchainImagesKHR,
189191
// then resize the container and finally call it again to retrieve the
190192
// handles.
191-
vkGetSwapchainImagesKHR(device.device(), swapChain, &imageCount, nullptr);
193+
VkResult getSwapChainRes;
194+
getSwapChainRes =
195+
vkGetSwapchainImagesKHR(device.device(), swapChain, &imageCount, nullptr);
196+
197+
std::cout << "First getSwapChainImages Result: " << getSwapChainRes
198+
<< ", imageCount: " << imageCount << std::endl;
192199
swapChainImages.resize(imageCount);
193-
vkGetSwapchainImagesKHR(device.device(), swapChain, &imageCount,
194-
swapChainImages.data());
200+
201+
getSwapChainRes = vkGetSwapchainImagesKHR(
202+
device.device(), swapChain, &imageCount, swapChainImages.data());
203+
std::cout << "Second getSwapChainImages Result: " << getSwapChainRes
204+
<< ", imageCount: " << imageCount << std::endl;
195205

196206
swapChainImageFormat = surfaceFormat.format;
197207
swapChainExtent = extent;
@@ -336,7 +346,7 @@ void LveSwapChain::createSyncObjects() {
336346
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
337347
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
338348
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
339-
imagesInFlight.resize(imageCount(), VK_NULL_HANDLE);
349+
std::cout << "image count : " << imageCount() << std::endl;
340350

341351
VkSemaphoreCreateInfo semaphoreInfo = {};
342352
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;

src/lve_swap_chain.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class LveSwapChain {
8989
std::vector<VkSemaphore> imageAvailableSemaphores;
9090
std::vector<VkSemaphore> renderFinishedSemaphores;
9191
std::vector<VkFence> inFlightFences;
92-
std::vector<VkFence> imagesInFlight;
9392
size_t currentFrame = 0;
9493
};
9594

0 commit comments

Comments
 (0)