From 5202f315dbe29d78b6016fc200ecd57ffdc81245 Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:16:41 +0200 Subject: [PATCH 1/4] Fix wrong initial size --- src/main/java/net/vulkanmod/render/chunk/buffer/AreaBuffer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/vulkanmod/render/chunk/buffer/AreaBuffer.java b/src/main/java/net/vulkanmod/render/chunk/buffer/AreaBuffer.java index f0b609832..20faff433 100644 --- a/src/main/java/net/vulkanmod/render/chunk/buffer/AreaBuffer.java +++ b/src/main/java/net/vulkanmod/render/chunk/buffer/AreaBuffer.java @@ -33,7 +33,7 @@ public AreaBuffer(Usage usage, int elementCount, int elementSize) { this.size = elementCount * elementSize; this.buffer = this.allocateBuffer(); - Segment s = new Segment(0, elementCount); + Segment s = new Segment(0, this.size); segments++; last = first = s; From 155d3eedbba2504e6472239f6c026f5d62efff43 Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:17:20 +0200 Subject: [PATCH 2/4] Add error decoding --- src/main/java/net/vulkanmod/vulkan/Renderer.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/vulkanmod/vulkan/Renderer.java b/src/main/java/net/vulkanmod/vulkan/Renderer.java index 9f8e677a8..5444fb07a 100644 --- a/src/main/java/net/vulkanmod/vulkan/Renderer.java +++ b/src/main/java/net/vulkanmod/vulkan/Renderer.java @@ -23,6 +23,7 @@ import net.vulkanmod.vulkan.shader.layout.PushConstants; import net.vulkanmod.vulkan.texture.VTextureSelector; import net.vulkanmod.vulkan.util.VUtil; +import net.vulkanmod.vulkan.util.VkResult; import org.lwjgl.PointerBuffer; import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryUtil; @@ -285,7 +286,6 @@ private void submitFrame() { return; try (MemoryStack stack = stackPush()) { - int vkResult; VkSubmitInfo submitInfo = VkSubmitInfo.calloc(stack); @@ -305,7 +305,7 @@ private void submitFrame() { if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().queue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) { vkResetFences(device, stack.longs(inFlightFences.get(currentFrame))); - throw new RuntimeException("Failed to submit draw command buffer: " + vkResult); + throw new RuntimeException("Failed to submit draw command buffer: %s".formatted(VkResult.decode(vkResult))); } VkPresentInfoKHR presentInfo = VkPresentInfoKHR.calloc(stack); @@ -385,7 +385,6 @@ public void preInitFrame() { WorldRenderer.getInstance().uploadSections(); UploadManager.INSTANCE.submitUploads(); - UploadManager.INSTANCE.waitUploads(); } public void addUsedPipeline(Pipeline pipeline) { @@ -437,7 +436,6 @@ private void recreateSwapChain() { if (framesNum != newFramesNum) { UploadManager.INSTANCE.submitUploads(); - UploadManager.INSTANCE.waitUploads(); framesNum = newFramesNum; MemoryManager.createInstance(newFramesNum); From 66893b76cb2d25b60c52dee1562a1cc1033f00d3 Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:16:40 +0200 Subject: [PATCH 3/4] Fix memory leak when uploading on dismissed areas --- .../net/vulkanmod/render/chunk/ChunkAreaManager.java | 4 ++++ .../vulkanmod/render/chunk/build/TaskDispatcher.java | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/vulkanmod/render/chunk/ChunkAreaManager.java b/src/main/java/net/vulkanmod/render/chunk/ChunkAreaManager.java index 6dfe06040..aa17b5047 100644 --- a/src/main/java/net/vulkanmod/render/chunk/ChunkAreaManager.java +++ b/src/main/java/net/vulkanmod/render/chunk/ChunkAreaManager.java @@ -177,6 +177,10 @@ public ChunkArea getChunkArea(RenderSection section, int x, int y, int z) { return chunkArea; } + public ChunkArea getChunkArea(int idx) { + return idx >= 0 && idx < chunkAreasArr.length ? this.chunkAreasArr[idx] : null; + } + public void updateFrustumVisibility(VFrustum frustum) { FrustumOctree.updateFrustumVisibility(frustum, this.chunkAreasArr); } diff --git a/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java b/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java index 86ec4542c..ae43f3544 100644 --- a/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java +++ b/src/main/java/net/vulkanmod/render/chunk/build/TaskDispatcher.java @@ -2,8 +2,9 @@ import com.google.common.collect.Queues; import net.vulkanmod.render.chunk.ChunkArea; +import net.vulkanmod.render.chunk.ChunkAreaManager; import net.vulkanmod.render.chunk.RenderSection; -import net.vulkanmod.render.chunk.buffer.UploadManager; +import net.vulkanmod.render.chunk.WorldRenderer; import net.vulkanmod.render.chunk.buffer.DrawBuffers; import net.vulkanmod.render.chunk.build.task.ChunkTask; import net.vulkanmod.render.chunk.build.task.CompileResult; @@ -12,8 +13,7 @@ import net.vulkanmod.render.vertex.TerrainRenderType; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.EnumMap; + import java.util.Queue; public class TaskDispatcher { @@ -153,6 +153,11 @@ private void doSectionUpdate(CompileResult compileResult) { ChunkArea renderArea = section.getChunkArea(); DrawBuffers drawBuffers = renderArea.getDrawBuffers(); + // Check if area has been dismissed before uploading + ChunkAreaManager chunkAreaManager = WorldRenderer.getInstance().getChunkAreaManager(); + if (chunkAreaManager.getChunkArea(renderArea.index) != renderArea) + return; + if(compileResult.fullUpdate) { var renderLayers = compileResult.renderedLayers; for(TerrainRenderType renderType : TerrainRenderType.VALUES) { From 10d52c256da874a7536249e40de2598f97fe3422 Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:16:59 +0200 Subject: [PATCH 4/4] Update initial sizes --- .../java/net/vulkanmod/render/chunk/buffer/DrawBuffers.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/vulkanmod/render/chunk/buffer/DrawBuffers.java b/src/main/java/net/vulkanmod/render/chunk/buffer/DrawBuffers.java index c99ca9c1b..8556e0426 100644 --- a/src/main/java/net/vulkanmod/render/chunk/buffer/DrawBuffers.java +++ b/src/main/java/net/vulkanmod/render/chunk/buffer/DrawBuffers.java @@ -69,9 +69,8 @@ private AreaBuffer getAreaBufferOrAlloc(TerrainRenderType renderType) { this.allocated = true; int initialSize = switch (renderType) { - case SOLID -> 30000; - case CUTOUT -> 100000; - case CUTOUT_MIPPED -> 300000; + case SOLID, CUTOUT -> 100000; + case CUTOUT_MIPPED -> 250000; case TRANSLUCENT, TRIPWIRE -> 60000; };