Merge remote-tracking branch 'origin/1.19/dev' into 1.19/fabric/dev

This commit is contained in:
PepperCode1 2024-09-01 17:32:05 -07:00
commit 9da4fc5b60
7 changed files with 3 additions and 200 deletions

View file

@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
# mod version info
mod_version = 0.6.10
mod_version = 0.6.11
artifact_minecraft_version = 1.19.2
minecraft_version = 1.19.2

View file

@ -1,41 +0,0 @@
package com.jozufozu.flywheel.backend.gl;
import static org.lwjgl.opengl.GL32.GL_ALREADY_SIGNALED;
import static org.lwjgl.opengl.GL32.GL_CONDITION_SATISFIED;
import static org.lwjgl.opengl.GL32.GL_SYNC_FLUSH_COMMANDS_BIT;
import static org.lwjgl.opengl.GL32.GL_SYNC_GPU_COMMANDS_COMPLETE;
import static org.lwjgl.opengl.GL32.GL_UNSIGNALED;
import static org.lwjgl.opengl.GL32.glClientWaitSync;
import static org.lwjgl.opengl.GL32.glDeleteSync;
import static org.lwjgl.opengl.GL32.glFenceSync;
public class GlFence {
private long fence;
public void post() {
clear();
fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
}
public void clear() {
if (fence != 0) {
glDeleteSync(fence);
fence = 0;
}
}
public void waitSync() {
if (fence != 0) {
int waitReturn = GL_UNSIGNALED;
while (waitReturn != GL_ALREADY_SIGNALED && waitReturn != GL_CONDITION_SATISFIED) {
waitReturn = glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 1);
}
glDeleteSync(fence);
}
fence = 0;
}
}

View file

@ -5,30 +5,9 @@ import java.nio.ByteBuffer;
import org.lwjgl.opengl.GL20;
import com.jozufozu.flywheel.backend.gl.GlObject;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
public abstract class GlBuffer extends GlObject {
/**
* Request a Persistent mapped buffer.
*
* <p>
* If Persistent buffers are supported, this will provide one. Otherwise it will fall back to a classic mapped
* buffer.
* </p>
*
* @param type The type of buffer you want.
* @return A buffer that will be persistent if the driver supports it.
*/
public static GlBuffer requestPersistent(GlBufferType type) {
if (GlCompat.getInstance()
.bufferStorageSupported()) {
return new PersistentGlBuffer(type);
} else {
return new MappedGlBuffer(type);
}
}
protected final GlBufferType type;
/**

View file

@ -1,84 +0,0 @@
package com.jozufozu.flywheel.backend.gl.buffer;
import static org.lwjgl.opengl.GL30.GL_MAP_WRITE_BIT;
import static org.lwjgl.opengl.GL44.GL_MAP_COHERENT_BIT;
import static org.lwjgl.opengl.GL44.GL_MAP_PERSISTENT_BIT;
import java.nio.ByteBuffer;
import org.lwjgl.opengl.GL30;
import com.jozufozu.flywheel.backend.gl.GlFence;
import com.jozufozu.flywheel.backend.gl.error.GlError;
import com.jozufozu.flywheel.backend.gl.error.GlException;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
public class PersistentGlBuffer extends GlBuffer implements Mappable {
private MappedBuffer buffer;
int flags;
long size;
GlFence fence;
public PersistentGlBuffer(GlBufferType type) {
super(type);
flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
fence = new GlFence();
}
@Override
public void doneForThisFrame() {
fence.post();
}
@Override
protected void alloc(long size) {
this.size = size;
if (buffer != null) {
deleteInternal(handle());
_create();
bind();
}
fence.clear();
GlCompat.getInstance().bufferStorage.bufferStorage(type, size, flags);
ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags);
if (byteBuffer == null) {
throw new GlException(GlError.poll(), "Could not map buffer");
}
buffer = new MappedBuffer(this, byteBuffer, 0, size);
}
@Override
public void upload(ByteBuffer directBuffer) {
throw new UnsupportedOperationException("FIXME: Nothing calls #upload on a persistent buffer as of 12/10/2021.");
}
@Override
public MappedBuffer getBuffer(long offset, long length) {
fence.waitSync();
buffer.position((int) offset);
return buffer;
}
@Override
public GlBufferType getType() {
return type;
}
@Override
public boolean isPersistent() {
return true;
}
}

View file

@ -1,46 +0,0 @@
package com.jozufozu.flywheel.backend.gl.versioned;
import org.lwjgl.opengl.ARBBufferStorage;
import org.lwjgl.opengl.GL44;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
public enum BufferStorage implements GlVersioned {
GL44CORE {
@Override
public boolean supported(GLCapabilities caps) {
return caps.OpenGL44;
}
@Override
public void bufferStorage(GlBufferType target, long size, int flags) {
GL44.glBufferStorage(target.glEnum, size, flags);
}
},
ARB {
@Override
public boolean supported(GLCapabilities caps) {
return caps.GL_ARB_buffer_storage;
}
@Override
public void bufferStorage(GlBufferType target, long size, int flags) {
ARBBufferStorage.glBufferStorage(target.glEnum, size, flags);
}
},
UNSUPPORTED {
@Override
public boolean supported(GLCapabilities caps) {
return true;
}
@Override
public void bufferStorage(GlBufferType target, long size, int flags) {
throw new UnsupportedOperationException();
}
};
public abstract void bufferStorage(GlBufferType target, long size, int flags);
}

View file

@ -30,13 +30,11 @@ public class GlCompat {
}
public final InstancedArrays instancedArrays;
public final BufferStorage bufferStorage;
public final boolean amd;
private GlCompat() {
GLCapabilities caps = GL.createCapabilities();
instancedArrays = getLatest(InstancedArrays.class, caps);
bufferStorage = getLatest(BufferStorage.class, caps);
if (Util.getPlatform() == Util.OS.WINDOWS) {
String vendor = GL20C.glGetString(GL20C.GL_VENDOR);
@ -55,10 +53,6 @@ public class GlCompat {
return instancedArrays != InstancedArrays.UNSUPPORTED;
}
public boolean bufferStorageSupported() {
return bufferStorage != BufferStorage.UNSUPPORTED;
}
/**
* Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order.
*

View file

@ -10,6 +10,7 @@ import com.jozufozu.flywheel.backend.gl.GlVertexArray;
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
import com.jozufozu.flywheel.backend.model.BufferedModel;
@ -80,7 +81,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
vao.bind();
vao.enableArrays(model.getAttributeCount() + instanceFormat.getAttributeCount());
instanceVBO = GlBuffer.requestPersistent(GlBufferType.ARRAY_BUFFER);
instanceVBO = new MappedGlBuffer(GlBufferType.ARRAY_BUFFER);
instanceVBO.setGrowthMargin(instanceFormat.getStride() * 16);
}