Added waiting for gpu memory collection
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user