@@ -182,8 +182,8 @@ private void createSyncObjects() {
182182 for (int i = 0 ; i < framesNum ; i ++) {
183183
184184 if (vkCreateSemaphore (device , semaphoreInfo , null , pImageAvailableSemaphore ) != VK_SUCCESS
185- || vkCreateSemaphore (device , semaphoreInfo , null , pRenderFinishedSemaphore ) != VK_SUCCESS
186- || vkCreateFence (device , fenceInfo , null , pFence ) != VK_SUCCESS ) {
185+ || vkCreateSemaphore (device , semaphoreInfo , null , pRenderFinishedSemaphore ) != VK_SUCCESS
186+ || vkCreateFence (device , fenceInfo , null , pFence ) != VK_SUCCESS ) {
187187
188188 throw new RuntimeException ("Failed to create synchronization objects for the frame: " + i );
189189 }
@@ -206,7 +206,7 @@ public void preInitFrame() {
206206 // runTick might be called recursively,
207207 // this check forces sync to avoid upload corruption
208208 if (lastReset == currentFrame ) {
209- Synchronization . INSTANCE . waitFences ();
209+ waitFences ();
210210 }
211211 lastReset = currentFrame ;
212212
@@ -256,7 +256,7 @@ public void beginFrame() {
256256 IntBuffer pImageIndex = stack .mallocInt (1 );
257257
258258 int vkResult = vkAcquireNextImageKHR (device , swapChain .getId (), VUtil .UINT64_MAX ,
259- imageAvailableSemaphores .get (currentFrame ), VK_NULL_HANDLE , pImageIndex );
259+ imageAvailableSemaphores .get (currentFrame ), VK_NULL_HANDLE , pImageIndex );
260260
261261 if (vkResult == VK_SUBOPTIMAL_KHR || vkResult == VK_ERROR_OUT_OF_DATE_KHR || swapChainUpdate ) {
262262 swapChainUpdate = true ;
@@ -303,10 +303,7 @@ public void endFrame() {
303303
304304 mainPass .end (currentCmdBuffer );
305305
306- // Make sure there are no uploads/transitions scheduled
307- ImageUploadHelper .INSTANCE .submitCommands ();
308- Synchronization .INSTANCE .waitFences ();
309- Vulkan .getStagingBuffer ().reset ();
306+ waitFences ();
310307
311308 submitFrame ();
312309 recordingCmds = false ;
@@ -362,7 +359,7 @@ private void submitFrame() {
362359 }
363360
364361 /**
365- * Called in case draw results are needed before the of the frame
362+ * Called in case draw results are needed before the of the frame
366363 */
367364 public void flushCmds () {
368365 if (!this .recordingCmds )
@@ -381,7 +378,7 @@ public void flushCmds() {
381378
382379 vkResetFences (device , inFlightFences .get (currentFrame ));
383380
384- Synchronization . INSTANCE . waitFences ();
381+ waitFences ();
385382
386383 if ((vkResult = vkQueueSubmit (DeviceManager .getGraphicsQueue ().queue (), submitInfo , inFlightFences .get (currentFrame ))) != VK_SUCCESS ) {
387384 vkResetFences (device , inFlightFences .get (currentFrame ));
@@ -437,6 +434,13 @@ public void removeUsedPipeline(Pipeline pipeline) {
437434 usedPipelines .remove (pipeline );
438435 }
439436
437+ private void waitFences () {
438+ // Make sure there are no uploads/transitions scheduled
439+ ImageUploadHelper .INSTANCE .submitCommands ();
440+ Synchronization .INSTANCE .waitFences ();
441+ Vulkan .getStagingBuffer ().reset ();
442+ }
443+
440444 private void resetDescriptors () {
441445 for (Pipeline pipeline : usedPipelines ) {
442446 pipeline .resetDescriptorPool (currentFrame );
@@ -454,9 +458,9 @@ void waitForSwapChain() {
454458 try (MemoryStack stack = MemoryStack .stackPush ()) {
455459 //Empty Submit
456460 VkSubmitInfo info = VkSubmitInfo .calloc (stack )
457- .sType$Default ()
458- .pWaitSemaphores (stack .longs (imageAvailableSemaphores .get (currentFrame )))
459- .pWaitDstStageMask (stack .ints (VK_PIPELINE_STAGE_ALL_COMMANDS_BIT ));
461+ .sType$Default ()
462+ .pWaitSemaphores (stack .longs (imageAvailableSemaphores .get (currentFrame )))
463+ .pWaitDstStageMask (stack .ints (VK_PIPELINE_STAGE_ALL_COMMANDS_BIT ));
460464
461465 vkQueueSubmit (DeviceManager .getGraphicsQueue ().queue (), info , inFlightFences .get (currentFrame ));
462466 vkWaitForFences (device , inFlightFences .get (currentFrame ), true , -1 );
@@ -465,7 +469,7 @@ void waitForSwapChain() {
465469
466470 @ SuppressWarnings ("UnreachableCode" )
467471 private void recreateSwapChain () {
468- Synchronization . INSTANCE . waitFences ();
472+ waitFences ();
469473 Vulkan .waitIdle ();
470474
471475 commandBuffers .forEach (commandBuffer -> vkResetCommandBuffer (commandBuffer , 0 ));
0 commit comments