Skip to content

Commit 2280a47

Browse files
committed
Refactor the whole project to fix styling
1 parent 80f3159 commit 2280a47

File tree

21 files changed

+107
-136
lines changed

21 files changed

+107
-136
lines changed

src/main/java/com/cleanroommc/kirino/KirinoCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public static void init() {
412412
}
413413
//</editor-fold>
414414

415-
KHRDebug.enable(List.of(
415+
KHRDebug.enable(LOGGER, List.of(
416416
new DebugMessageFilter(DebugMsgSource.ANY, DebugMsgType.ERROR, DebugMsgSeverity.ANY),
417417
new DebugMessageFilter(DebugMsgSource.ANY, DebugMsgType.MARKER, DebugMsgSeverity.ANY)));
418418

src/main/java/com/cleanroommc/kirino/engine/render/pipeline/post/FrameFinalizer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ public void finalizeFramebuffer() {
384384
Framebuffer.bind(MINECRAFT.getFramebuffer().framebufferObject);
385385
GL11.glViewport(0, 0, MINECRAFT.getFramebuffer().framebufferWidth, MINECRAFT.getFramebuffer().framebufferHeight);
386386
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
387+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
387388
toneMappingPass.render(null, null, new Object[]{mainFramebuffer.framebuffer});
388389
} else if (mainFramebuffer.getRatio() < 1f) {
389390
// todo: upscale impl
@@ -395,6 +396,7 @@ public void finalizeFramebuffer() {
395396
0, 0, mainFramebuffer.framebuffer.width(), mainFramebuffer.framebuffer.height(),
396397
0, 0, intermediateFramebuffer.width(), intermediateFramebuffer.height(),
397398
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
399+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
398400

399401
Framebuffer.bind(MINECRAFT.getFramebuffer().framebufferObject);
400402
GL11.glViewport(0, 0, MINECRAFT.getFramebuffer().framebufferWidth, MINECRAFT.getFramebuffer().framebufferHeight);
@@ -410,6 +412,7 @@ public void finalizeFramebuffer() {
410412
0, 0, mainFramebuffer.framebuffer.width(), mainFramebuffer.framebuffer.height(),
411413
0, 0, intermediateFramebuffer.width(), intermediateFramebuffer.height(),
412414
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
415+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
413416

414417
Framebuffer.bind(MINECRAFT.getFramebuffer().framebufferObject);
415418
GL11.glViewport(0, 0, MINECRAFT.getFramebuffer().framebufferWidth, MINECRAFT.getFramebuffer().framebufferHeight);
@@ -467,6 +470,7 @@ public void finalizeFramebuffer() {
467470
0, 0, mainFramebuffer.framebuffer.width(), mainFramebuffer.framebuffer.height(),
468471
0, 0, intermediateFramebuffer.width(), intermediateFramebuffer.height(),
469472
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
473+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
470474

471475
postProcessingPass.postProcess(true);
472476
} else if (postProcessingPass.getSubpassCount() >= 2) {
@@ -479,6 +483,7 @@ public void finalizeFramebuffer() {
479483
0, 0, mainFramebuffer.framebuffer.width(), mainFramebuffer.framebuffer.height(),
480484
0, 0, pingPongFramebuffer.width(), pingPongFramebuffer.height(),
481485
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
486+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
482487

483488
postProcessingPass.postProcess();
484489
}
@@ -493,6 +498,7 @@ public void finalizeFramebuffer() {
493498
0, 0, mainFramebuffer.framebuffer.width(), mainFramebuffer.framebuffer.height(),
494499
0, 0, intermediateFramebuffer.width(), intermediateFramebuffer.height(),
495500
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
501+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
496502

497503
postProcessingPass.postProcess(true);
498504
} else if (postProcessingPass.getSubpassCount() >= 2) {
@@ -505,6 +511,7 @@ public void finalizeFramebuffer() {
505511
0, 0, mainFramebuffer.framebuffer.width(), mainFramebuffer.framebuffer.height(),
506512
0, 0, pingPongFramebuffer.width(), pingPongFramebuffer.height(),
507513
GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);
514+
GL42.glMemoryBarrier(GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL42.GL_FRAMEBUFFER_BARRIER_BIT);
508515

509516
postProcessingPass.postProcess();
510517
}

src/main/java/com/cleanroommc/kirino/engine/render/staging/StagingBufferHandle.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import java.nio.ByteBuffer;
66

7+
/**
8+
* This is a handle for a buffer slice.
9+
*/
710
public abstract class StagingBufferHandle<T extends StagingBufferHandle<T>> {
811
protected final StagingBufferManager stagingBufferManager;
912
protected final int offset;
@@ -15,6 +18,7 @@ protected StagingBufferHandle(StagingBufferManager stagingBufferManager, int off
1518
this.maxLength = maxLength;
1619
}
1720

21+
@SuppressWarnings("unchecked")
1822
public final T write(int offset, ByteBuffer byteBuffer) {
1923
Preconditions.checkState(stagingBufferManager.active, "Must not access buffers from StagingBufferManager when the manager is inactive.");
2024

src/main/java/com/cleanroommc/kirino/engine/render/staging/StagingBufferManager.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void flushPersistent() {
9292
}
9393

9494
public void genPersistentBuffers(String key, int vboSize, int eboSize) {
95-
Preconditions.checkArgument(!persistentVbos.containsKey(key), "The key already exists.");
95+
Preconditions.checkArgument(!persistentVbos.containsKey(key), "The \"key\" already exists.");
9696

9797
VBOView vboView = new VBOView(new GLBuffer());
9898
EBOView eboView = new EBOView(new GLBuffer());
@@ -116,10 +116,10 @@ protected PersistentVBOHandle getPersistentVBOHandle(String key, int offset, int
116116
Preconditions.checkState(active, "Must not access buffers from StagingBufferManager when the manager is inactive.");
117117

118118
Triple<Integer, VBOView, ByteBuffer> entry = persistentVbos.get(key);
119-
Preconditions.checkArgument(entry != null, "Argument key is invalid.");
120-
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
121-
Preconditions.checkArgument(size >= 0, "Cannot have a negative buffer size.");
122-
Preconditions.checkArgument(offset + size <= entry.getLeft(), "Buffer slice size must be greater than or equal to offset + size.");
119+
Preconditions.checkArgument(entry != null, "Argument \"key\" is invalid.");
120+
Preconditions.checkArgument(offset >= 0, "Cannot have a negative \"offset\".");
121+
Preconditions.checkArgument(size >= 0, "Cannot have a negative \"size\".");
122+
Preconditions.checkArgument(offset + size <= entry.getLeft(), "Buffer size must be greater than or equal to \"offset + size\".");
123123

124124
return new PersistentVBOHandle(this, offset, size, entry.getRight());
125125
}
@@ -128,10 +128,10 @@ protected PersistentEBOHandle getPersistentEBOHandle(String key, int offset, int
128128
Preconditions.checkState(active, "Must not access buffers from StagingBufferManager when the manager is inactive.");
129129

130130
Triple<Integer, EBOView, ByteBuffer> entry = persistentEbos.get(key);
131-
Preconditions.checkArgument(entry != null, "Argument key is invalid.");
132-
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
133-
Preconditions.checkArgument(size >= 0, "Cannot have a negative buffer size.");
134-
Preconditions.checkArgument(offset + size <= entry.getLeft(), "Buffer slice size must be greater than or equal to offset + size.");
131+
Preconditions.checkArgument(entry != null, "Argument \"key\" is invalid.");
132+
Preconditions.checkArgument(offset >= 0, "Cannot have a negative \"offset\".");
133+
Preconditions.checkArgument(size >= 0, "Cannot have a negative \"size\".");
134+
Preconditions.checkArgument(offset + size <= entry.getLeft(), "Buffer size must be greater than or equal to \"offset + size\".");
135135

136136
return new PersistentEBOHandle(this, offset, size, entry.getRight());
137137
}
@@ -150,7 +150,7 @@ protected TemporaryVAOHandle getTemporaryVAOHandle(AttributeLayout attributeLayo
150150

151151
protected TemporaryVBOHandle getTemporaryVBOHandle(int size) {
152152
Preconditions.checkState(active, "Must not access buffers from StagingBufferManager when the manager is inactive.");
153-
Preconditions.checkArgument(size >= 0, "Cannot have a negative buffer size.");
153+
Preconditions.checkArgument(size >= 0, "Cannot have a negative \"size\".");
154154

155155
VBOView vboView = new VBOView(new GLBuffer());
156156
vboView.turnOffValidation();
@@ -163,7 +163,7 @@ protected TemporaryVBOHandle getTemporaryVBOHandle(int size) {
163163

164164
protected TemporaryEBOHandle getTemporaryEBOHandle(int size) {
165165
Preconditions.checkState(active, "Must not access buffers from StagingBufferManager when the manager is inactive.");
166-
Preconditions.checkArgument(size >= 0, "Cannot have a negative buffer size.");
166+
Preconditions.checkArgument(size >= 0, "Cannot have a negative \"size\".");
167167

168168
EBOView eboView = new EBOView(new GLBuffer());
169169
eboView.turnOffValidation();

src/main/java/com/cleanroommc/kirino/engine/render/staging/handle/PersistentEBOHandle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public PersistentEBOHandle(StagingBufferManager stagingBufferManager, int offset
1717
@Override
1818
protected void writeInternal(int offset, ByteBuffer byteBuffer) {
1919
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
20-
Preconditions.checkArgument(this.offset + offset + byteBuffer.remaining() <= maxLength, "Buffer slice size must be greater than or equal to this.offset + offset + byteBuffer.remaining().");
20+
Preconditions.checkArgument(offset + byteBuffer.remaining() <= maxLength,
21+
"Buffer slice size must be greater than or equal to \"offset + byteBuffer.remaining()\".");
2122

2223
int oldPos = this.byteBuffer.position();
2324
this.byteBuffer.position(this.offset + offset);

src/main/java/com/cleanroommc/kirino/engine/render/staging/handle/PersistentVBOHandle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public PersistentVBOHandle(StagingBufferManager stagingBufferManager, int offset
1717
@Override
1818
protected void writeInternal(int offset, ByteBuffer byteBuffer) {
1919
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
20-
Preconditions.checkArgument(this.offset + offset + byteBuffer.remaining() <= maxLength, "Buffer slice size must be greater than or equal to this.offset + offset + byteBuffer.remaining().");
20+
Preconditions.checkArgument(offset + byteBuffer.remaining() <= maxLength,
21+
"Buffer slice size must be greater than or equal to \"offset + byteBuffer.remaining()\".");
2122

2223
int oldPos = this.byteBuffer.position();
2324
this.byteBuffer.position(this.offset + offset);

src/main/java/com/cleanroommc/kirino/engine/render/staging/handle/TemporaryEBOHandle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public int getEboID() {
2727
protected void writeInternal(int offset, ByteBuffer byteBuffer) {
2828
Preconditions.checkState(generation == stagingBufferManager.getTemporaryHandleGeneration(), "This temporary handle is expired.");
2929
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
30-
Preconditions.checkArgument(offset + byteBuffer.remaining() <= maxLength, "Allocated buffer size must be greater than or equal to offset + byteBuffer.remaining().");
30+
Preconditions.checkArgument(offset + byteBuffer.remaining() <= maxLength,
31+
"Allocated buffer size must be greater than or equal to \"offset + byteBuffer.remaining()\".");
3132

3233
eboView.bind();
3334
eboView.uploadBySubData(offset, byteBuffer);

src/main/java/com/cleanroommc/kirino/engine/render/staging/handle/TemporaryVBOHandle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public int getVboID() {
2727
protected void writeInternal(int offset, ByteBuffer byteBuffer) {
2828
Preconditions.checkState(generation == stagingBufferManager.getTemporaryHandleGeneration(), "This temporary handle is expired.");
2929
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
30-
Preconditions.checkArgument(offset + byteBuffer.remaining() <= maxLength, "Allocated buffer size must be greater than or equal to offset + byteBuffer.remaining().");
30+
Preconditions.checkArgument(offset + byteBuffer.remaining() <= maxLength,
31+
"Allocated buffer size must be greater than or equal to \"offset + byteBuffer.remaining()\".");
3132

3233
vboView.bind();
3334
vboView.uploadBySubData(offset, byteBuffer);

src/main/java/com/cleanroommc/kirino/gl/buffer/RingBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public RingBuffer(ByteBuffer byteBuffer, int sliceSize, int sliceNumber) {
4545

4646
public void write(int offset, ByteBuffer byteBuffer) {
4747
Preconditions.checkArgument(offset + byteBuffer.remaining() <= sliceSize,
48-
"Slice size must be greater than or equal to offset + byteBuffer.remaining().");
48+
"Slice size must be greater than or equal to \"offset + byteBuffer.remaining()\".");
4949

5050
this.byteBuffer.position(offset + getWriteOffset());
5151
this.byteBuffer.limit(getWriteOffset() + sliceSize);

src/main/java/com/cleanroommc/kirino/gl/buffer/view/BufferView.java

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import com.cleanroommc.kirino.gl.buffer.GLBuffer;
44
import com.cleanroommc.kirino.gl.buffer.meta.BufferUploadHint;
55
import com.cleanroommc.kirino.gl.buffer.meta.MapBufferAccessBit;
6-
import com.cleanroommc.kirino.gl.exception.RuntimeGLException;
6+
import com.google.common.base.Preconditions;
77
import org.lwjgl.opengl.*;
88

99
import java.nio.ByteBuffer;
1010
import java.util.Arrays;
1111

1212
public abstract class BufferView {
13-
private boolean validation = true;
13+
private boolean validation = false;
1414

1515
public final void turnOnValidation() {
1616
validation = true;
@@ -60,7 +60,7 @@ public BufferUploadHint fetchBufferUploadHint() {
6060
} else if (usage == BufferUploadHint.STREAM_DRAW.glValue) {
6161
return BufferUploadHint.STREAM_DRAW;
6262
}
63-
throw new RuntimeGLException("Unknown GL_BUFFER_USAGE fetched.");
63+
throw new RuntimeException("Unknown GL_BUFFER_USAGE fetched.");
6464
}
6565

6666
public MapBufferAccessBit[] fetchMapBufferAccessBits() {
@@ -90,10 +90,9 @@ public int fetchMapBufferLength() {
9090
*/
9191
public void alloc(int size, BufferUploadHint hint) {
9292
if (validation) {
93-
if (size < 0) {
94-
throw new RuntimeGLException("Cannot have a negative buffer size.");
95-
}
93+
Preconditions.checkArgument(size >= 0, "Cannot have a negative buffer size.");
9694
}
95+
9796
GL15.glBufferData(target(), size, hint.glValue);
9897
}
9998

@@ -115,13 +114,11 @@ public void uploadDirectly(ByteBuffer byteBuffer) {
115114
*/
116115
public void uploadBySubData(int offset, ByteBuffer byteBuffer) {
117116
if (validation) {
118-
if (offset < 0) {
119-
throw new RuntimeGLException("Cannot have a negative buffer offset.");
120-
}
121-
if (offset + byteBuffer.remaining() > fetchBufferSize()) {
122-
throw new RuntimeGLException("Allocated buffer size must be greater than or equal to offset + byteBuffer.remaining().");
123-
}
117+
Preconditions.checkArgument(offset >= 0, "Cannot have a negative buffer offset.");
118+
Preconditions.checkArgument(offset + byteBuffer.remaining() <= fetchBufferSize(),
119+
"Allocated buffer size must be greater than or equal to \"offset + byteBuffer.remaining()\".");
124120
}
121+
125122
GL15.glBufferSubData(target(), offset, byteBuffer);
126123
}
127124

@@ -136,18 +133,12 @@ public void uploadBySubData(int offset, ByteBuffer byteBuffer) {
136133
*/
137134
public void uploadByMapBuffer(int mappingOffset, int mappingSize, int offset, ByteBuffer byteBuffer, MapBufferAccessBit... accessBits) {
138135
if (validation) {
139-
if (mappingSize < 0) {
140-
throw new RuntimeGLException("Cannot have a negative buffer size.");
141-
}
142-
if (mappingOffset < 0 || offset < 0) {
143-
throw new RuntimeGLException("Cannot have a negative offset.");
144-
}
145-
if (mappingOffset + mappingSize > fetchBufferSize()) {
146-
throw new RuntimeGLException("Allocated buffer size must be greater than or equal to mappingOffset + mappingSize.");
147-
}
148-
if (offset + byteBuffer.remaining() > mappingSize) {
149-
throw new RuntimeGLException("Parameter mappingSize must be greater than or equal to offset + byteBuffer.remaining().");
150-
}
136+
Preconditions.checkArgument(mappingSize >= 0, "Cannot have a negative buffer size.");
137+
Preconditions.checkArgument(!(mappingOffset < 0 || offset < 0), "Cannot have a negative offset.");
138+
Preconditions.checkArgument(mappingOffset + mappingSize <= fetchBufferSize(),
139+
"Allocated buffer size must be greater than or equal to \"mappingOffset + mappingSize\".");
140+
Preconditions.checkArgument(offset + byteBuffer.remaining() <= mappingSize,
141+
"Argument \"mappingSize\" must be greater than or equal to \"offset + byteBuffer.remaining()\".");
151142
}
152143

153144
int access = 0;
@@ -167,10 +158,10 @@ public void uploadByMapBuffer(int mappingOffset, int mappingSize, int offset, By
167158
mappedBuffer.put(byteBuffer);
168159
boolean success = GL15.glUnmapBuffer(target());
169160
if (!success) {
170-
throw new RuntimeGLException("Buffer unmap failed, data may be corrupted.");
161+
throw new RuntimeException("Buffer unmap failed, data may be corrupted.");
171162
}
172163
} else {
173-
throw new RuntimeGLException("Failed to map buffer.");
164+
throw new RuntimeException("Failed to map buffer.");
174165
}
175166
}
176167

@@ -182,9 +173,7 @@ public final ByteBuffer getPersistentMappedBuffer() {
182173

183174
public void allocPersistent(int size, MapBufferAccessBit... accessBits) {
184175
if (validation) {
185-
if (size < 0) {
186-
throw new RuntimeGLException("Cannot have a negative buffer size.");
187-
}
176+
Preconditions.checkArgument(size >= 0, "Cannot have a negative buffer size.");
188177
}
189178

190179
int access = 0;
@@ -197,15 +186,10 @@ public void allocPersistent(int size, MapBufferAccessBit... accessBits) {
197186

198187
public void mapPersistent(int offset, int length, MapBufferAccessBit... accessBits) {
199188
if (validation) {
200-
if (persistentMappedBuffer != null) {
201-
throw new RuntimeGLException("Buffer already mapped persistently.");
202-
}
203-
if (offset < 0) {
204-
throw new RuntimeGLException("Cannot have a negative offset.");
205-
}
206-
if (offset + length > fetchBufferSize()) {
207-
throw new RuntimeGLException("Allocated buffer size must be greater than or equal to offset + length.");
208-
}
189+
Preconditions.checkState(persistentMappedBuffer == null, "Buffer already mapped persistently.");
190+
Preconditions.checkArgument(offset >= 0, "Cannot have a negative offset.");
191+
Preconditions.checkArgument(offset + length <= fetchBufferSize(),
192+
"Allocated buffer size must be greater than or equal to \"offset + length\".");
209193
}
210194

211195
int access = 0;
@@ -216,20 +200,18 @@ public void mapPersistent(int offset, int length, MapBufferAccessBit... accessBi
216200
persistentMappedBuffer = GL44C.glMapBufferRange(target(), offset, length, access, persistentMappedBuffer);
217201

218202
if (persistentMappedBuffer == null) {
219-
throw new RuntimeGLException("Failed to map persistent buffer.");
203+
throw new RuntimeException("Failed to map persistent buffer.");
220204
}
221205
}
222206

223207
public void unmapPersistent() {
224208
if (validation) {
225-
if (persistentMappedBuffer == null) {
226-
throw new RuntimeGLException("Buffer not persistently mapped.");
227-
}
209+
Preconditions.checkState(persistentMappedBuffer != null, "Buffer not persistently mapped.");
228210
}
229211

230212
boolean success = GL15.glUnmapBuffer(target());
231213
if (!success) {
232-
throw new RuntimeGLException("Persistent buffer unmap failed, data may be corrupted.");
214+
throw new RuntimeException("Persistent buffer unmap failed, data may be corrupted.");
233215
}
234216

235217
persistentMappedBuffer = null;

0 commit comments

Comments
 (0)