It bytes back

- Fix time/constant ambient light flags being written to the wrong
  offsets.
- Align uniform buffer size to 16 instead of the offset alignment.
This commit is contained in:
Jozufozu 2024-01-30 18:10:35 -08:00
parent a33a2d2940
commit b3ade312eb
2 changed files with 7 additions and 19 deletions

View File

@ -11,7 +11,7 @@ import net.minecraft.core.Vec3i;
import net.minecraft.world.phys.Vec3;
public class FrameUniforms implements UniformProvider {
public static final int SIZE = 228;
public static final int SIZE = 220;
private RenderContext context;
@ -52,9 +52,9 @@ public class FrameUniforms implements UniformProvider {
writeVec2(ptr + 192, camera.getXRot(), camera.getYRot());
MemoryUtil.memPutInt(ptr + 208, getConstantAmbientLightFlag(context));
MemoryUtil.memPutInt(ptr + 200, getConstantAmbientLightFlag(context));
writeTime(ptr + 212);
writeTime(ptr + 204);
}
private void writeTime(long ptr) {

View File

@ -4,14 +4,10 @@ import org.lwjgl.opengl.GL32;
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferUsage;
import com.jozufozu.flywheel.lib.math.MoreMath;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import net.minecraft.util.Mth;
public class UniformBuffer<T extends UniformProvider> {
private static final int OFFSET_ALIGNMENT = GL32.glGetInteger(GL32.GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
private static final boolean PO2_ALIGNMENT = Mth.isPowerOfTwo(OFFSET_ALIGNMENT);
private final int index;
private final GlBuffer buffer;
public final T provider;
@ -22,8 +18,9 @@ public class UniformBuffer<T extends UniformProvider> {
this.buffer = new GlBuffer(GlBufferUsage.DYNAMIC_DRAW);
this.provider = provider;
// renderdoc complains if the size of the buffer does not have the offset alignment
var actualBytes = align(provider.byteSize());
// renderdoc complains if the size of the buffer is not 16-byte aligned,
// though things work fine on my machine if we're short a few bytes
var actualBytes = MoreMath.align16(provider.byteSize());
this.data = MemoryBlock.mallocTracked(actualBytes);
this.data.clear();
}
@ -41,13 +38,4 @@ public class UniformBuffer<T extends UniformProvider> {
data.free();
buffer.delete();
}
// https://stackoverflow.com/questions/3407012/rounding-up-to-the-nearest-multiple-of-a-number
private static int align(int numToRound) {
if (PO2_ALIGNMENT) {
return (numToRound + OFFSET_ALIGNMENT - 1) & -OFFSET_ALIGNMENT;
} else {
return ((numToRound + OFFSET_ALIGNMENT - 1) / OFFSET_ALIGNMENT) * OFFSET_ALIGNMENT;
}
}
}