From 11e7a8fbee95dba4d489356e43c3a86c787d6073 Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:05:38 +0200 Subject: [PATCH] Refactor: remove wait fences for loop --- src/main/java/net/vulkanmod/vulkan/Renderer.java | 4 ++-- src/main/java/net/vulkanmod/vulkan/Synchronization.java | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/vulkanmod/vulkan/Renderer.java b/src/main/java/net/vulkanmod/vulkan/Renderer.java index 5444fb07a..af18769a1 100644 --- a/src/main/java/net/vulkanmod/vulkan/Renderer.java +++ b/src/main/java/net/vulkanmod/vulkan/Renderer.java @@ -299,12 +299,12 @@ private void submitFrame() { submitInfo.pCommandBuffers(stack.pointers(currentCmdBuffer)); - vkResetFences(device, stack.longs(inFlightFences.get(currentFrame))); + vkResetFences(device, inFlightFences.get(currentFrame)); Synchronization.INSTANCE.waitFences(); if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().queue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) { - vkResetFences(device, stack.longs(inFlightFences.get(currentFrame))); + vkResetFences(device, inFlightFences.get(currentFrame)); throw new RuntimeException("Failed to submit draw command buffer: %s".formatted(VkResult.decode(vkResult))); } diff --git a/src/main/java/net/vulkanmod/vulkan/Synchronization.java b/src/main/java/net/vulkanmod/vulkan/Synchronization.java index 1ca14c95d..609052db3 100644 --- a/src/main/java/net/vulkanmod/vulkan/Synchronization.java +++ b/src/main/java/net/vulkanmod/vulkan/Synchronization.java @@ -38,16 +38,14 @@ public synchronized void addFence(long fence) { } public synchronized void waitFences() { - - if (idx == 0) return; + if (idx == 0) + return; VkDevice device = Vulkan.getVkDevice(); fences.limit(idx); - for (int i = 0; i < idx; i++) { - vkWaitForFences(device, fences.get(i), true, VUtil.UINT64_MAX); - } + vkWaitForFences(device, fences, true, VUtil.UINT64_MAX); this.commandBuffers.forEach(CommandPool.CommandBuffer::reset); this.commandBuffers.clear();