From 544c1df3666df25b9d51bbfed4cd496107dee7f3 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Wed, 27 Aug 2025 18:56:06 +1000 Subject: [PATCH] Added waiting for gpu memory collection --- .../geometry/BasicSectionGeometryData.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java b/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java index f4d32eec..e1b5092f 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java @@ -1,8 +1,11 @@ package me.cortex.voxy.client.core.rendering.section.geometry; +import me.cortex.voxy.client.core.gl.Capabilities; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.common.Logger; +import static org.lwjgl.opengl.GL11C.glFinish; + public class BasicSectionGeometryData implements IGeometryData { public static final int SECTION_METADATA_SIZE = 32; private final GlBuffer sectionMetadataBuffer; @@ -20,6 +23,9 @@ public class BasicSectionGeometryData implements IGeometryData { } long start = System.currentTimeMillis(); Logger.info("Creating and zeroing " + (geometryCapacity/(1024*1024)) + "MB geometry buffer"); + if (Capabilities.INSTANCE.canQueryGpuMemory) { + Logger.info("driver states " + (Capabilities.INSTANCE.getFreeDedicatedGpuMemory()/(1024*1024)) + "MB of free memory"); + } Logger.info("if your game crashes/exits here without any other log message, try manually decreasing the geometry capacity"); this.geometryBuffer = new GlBuffer(geometryCapacity); long delta = System.currentTimeMillis() - start; @@ -53,6 +59,31 @@ public class BasicSectionGeometryData implements IGeometryData { @Override public void free() { this.sectionMetadataBuffer.free(); + + long gpuMemory = 0; + if (Capabilities.INSTANCE.canQueryGpuMemory) { + glFinish(); + gpuMemory = Capabilities.INSTANCE.getFreeDedicatedGpuMemory(); + } + glFinish(); this.geometryBuffer.free(); + glFinish(); + if (Capabilities.INSTANCE.canQueryGpuMemory) { + long releaseSize = (long) (this.geometryBuffer.size()*0.75);//if gpu memory usage drops by 75% of the expected value assume we freed it + if (Capabilities.INSTANCE.getFreeDedicatedGpuMemory()-gpuMemory<=releaseSize) { + Logger.info("Attempting to wait for gpu memory to release"); + long start = System.currentTimeMillis(); + + long TIMEOUT = 2500; + + while (System.currentTimeMillis() - start > TIMEOUT) {//Wait up to 2.5 seconds for memory to release + glFinish(); + if (Capabilities.INSTANCE.getFreeDedicatedGpuMemory() - gpuMemory > releaseSize) break; + } + if (Capabilities.INSTANCE.getFreeDedicatedGpuMemory() - gpuMemory <= releaseSize) { + Logger.warn("Failed to wait for gpu memory to be freed, this could indicate an issue with the driver"); + } + } + } } }