re-add GPU upload config including "none"

This commit is contained in:
James Seibel
2025-11-10 07:33:03 -06:00
parent 767753c004
commit 6eb24ecde1
7 changed files with 41 additions and 10 deletions
@@ -1083,6 +1083,13 @@ public class Config
+ "")
.build();
public static ConfigEntry<EDhApiGpuUploadMethod> glUploadMode = new ConfigEntry.Builder<EDhApiGpuUploadMethod>()
.set(EDhApiGpuUploadMethod.AUTO)
.comment(""
+ "\n"
+ "")
.build();
}
public static class ColumnBuilderDebugging
@@ -65,7 +65,7 @@ public class ColumnRenderBufferBuilder
{
DhBlockPos minBlockPos = new DhBlockPos(DhSectionPos.getMinCornerBlockX(pos), clientLevel.getLevelWrapper().getMinHeight(), DhSectionPos.getMinCornerBlockZ(pos));
LodBufferContainer bufferContainer = new LodBufferContainer(pos, minBlockPos);
CompletableFuture<LodBufferContainer> uploadFuture = bufferContainer.makeAndUploadBuffersAsync(quadBuilder, GLProxy.getInstance().getGpuUploadMethod());
CompletableFuture<LodBufferContainer> uploadFuture = bufferContainer.makeAndUploadBuffersAsync(quadBuilder);
uploadFuture.whenComplete((uploadedBuffer, exception) ->
{
// clean up if not uploaded
@@ -82,7 +82,7 @@ public class LodBufferContainer implements AutoCloseable
//==================//
/** Should be run on a DH thread. */
public synchronized CompletableFuture<LodBufferContainer> makeAndUploadBuffersAsync(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod)
public synchronized CompletableFuture<LodBufferContainer> makeAndUploadBuffersAsync(LodQuadBuilder builder)
{
// separate variable to prevent race condition when checking null
CompletableFuture<LodBufferContainer> future = this.uploadFuture;
@@ -117,6 +117,8 @@ public class LodBufferContainer implements AutoCloseable
throw new InterruptedException();
}
EDhApiGpuUploadMethod gpuUploadMethod = GLProxy.getInstance().getGpuUploadMethod();
// upload on the render thread
uploadBuffersDirect(this.vbos, opaqueBuffers, gpuUploadMethod);
uploadBuffersDirect(this.vbosTransparent, transparentBuffers, gpuUploadMethod);
@@ -177,7 +179,9 @@ public class LodBufferContainer implements AutoCloseable
}
return newVbos;
}
private static void uploadBuffersDirect(GLVertexBuffer[] vbos, ArrayList<ByteBuffer> byteBuffers, EDhApiGpuUploadMethod method) throws InterruptedException
private static void uploadBuffersDirect(
GLVertexBuffer[] vbos, ArrayList<ByteBuffer> byteBuffers,
EDhApiGpuUploadMethod uploadMethod) throws InterruptedException
{
int vboIndex = 0;
for (int i = 0; i < byteBuffers.size(); i++)
@@ -191,7 +195,7 @@ public class LodBufferContainer implements AutoCloseable
// get or create the VBO
if (vbos[vboIndex] == null)
{
vbos[vboIndex] = new GLVertexBuffer(method.useBufferStorage);
vbos[vboIndex] = new GLVertexBuffer(uploadMethod.useBufferStorage);
}
GLVertexBuffer vbo = vbos[vboIndex];
@@ -202,13 +206,13 @@ public class LodBufferContainer implements AutoCloseable
try
{
vbo.bind();
vbo.uploadBuffer(buffer, size / LodUtil.LOD_VERTEX_FORMAT.getByteSize(), method, FULL_SIZED_BUFFER);
vbo.uploadBuffer(buffer, size / LodUtil.LOD_VERTEX_FORMAT.getByteSize(), uploadMethod, FULL_SIZED_BUFFER);
}
catch (Exception e)
{
vbos[vboIndex] = null;
vbo.close();
LOGGER.error("Failed to upload buffer: ", e);
LOGGER.error("Failed to upload buffer. Error: ["+e.getMessage()+"].", e);
}
vboIndex++;
@@ -220,7 +220,16 @@ public class GLProxy
return instance;
}
public EDhApiGpuUploadMethod getGpuUploadMethod() { return this.preferredUploadMethod; }
public EDhApiGpuUploadMethod getGpuUploadMethod()
{
EDhApiGpuUploadMethod uploadOverride = Config.Client.Advanced.Debugging.OpenGl.glUploadMode.get();
if (uploadOverride == EDhApiGpuUploadMethod.AUTO)
{
return this.preferredUploadMethod;
}
return uploadOverride;
}
public boolean runningOnRenderThread()
{
@@ -27,7 +27,6 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.ThreadUtil;
import com.seibel.distanthorizons.core.util.math.UnitBytes;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GL44;
@@ -187,7 +186,6 @@ public class GLBuffer implements AutoCloseable
{
LodUtil.assertNotReach("maxExpansionSize is [" + maxExpansionSize + "] but buffer size is [" + bbSize + "]!");
}
GLProxy.LOGGER.debug("Uploading buffer with ["+new UnitBytes(bbSize)+"].");
// Don't upload an empty buffer
if (bbSize == 0)
@@ -200,6 +198,8 @@ public class GLBuffer implements AutoCloseable
switch (uploadMethod)
{
case NONE:
return;
case AUTO:
LodUtil.assertNotReach("GpuUploadMethod AUTO must be resolved before call to uploadBuffer()!");
case BUFFER_STORAGE:
@@ -379,6 +379,7 @@ public class GLBuffer implements AutoCloseable
{
int id = PHANTOM_TO_BUFFER_ID.get(phantomRef);
destroyBufferIdAsync(id);
LOGGER.warn("Buffer Phantom collected, ID: ["+id+"]");
}
phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
@@ -386,7 +387,7 @@ public class GLBuffer implements AutoCloseable
}
catch (Exception e)
{
LOGGER.error("Unexpected error in cleanup thread: [" + e.getMessage() + "].", e);
LOGGER.error("Unexpected error in buffer cleanup thread: [" + e.getMessage() + "].", e);
}
}
}
@@ -509,6 +509,10 @@
"Validate Buffer IDs Before Rendering",
"distanthorizons.config.client.advanced.debugging.openGl.validateBufferIdsBeforeRendering.@tooltip":
"Massively reduces FPS. \nShould only be used if mysterious EXCEPTION_ACCESS_VIOLATION crashes are happening in DH's rendering code and you're attempting to troubleshoot it.",
"distanthorizons.config.client.advanced.debugging.openGl.glUploadMode":
"Uploade Mode",
"distanthorizons.config.client.advanced.debugging.openGl.glUploadMode.@tooltip":
"Only for debugging",
@@ -1046,6 +1050,8 @@
"distanthorizons.config.enum.EDhApiGpuUploadMethod.AUTO":
"Auto",
"distanthorizons.config.enum.EDhApiGpuUploadMethod.NONE":
"None",
"distanthorizons.config.enum.EDhApiGpuUploadMethod.BUFFER_STORAGE":
"Buffer storage",
"distanthorizons.config.enum.EDhApiGpuUploadMethod.SUB_DATA":