From c3701ad903ff57a4918fd7d4b38b9635d1bf43fa Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sun, 15 Dec 2024 12:59:34 +1000 Subject: [PATCH] gl debug utils --- build.gradle | 16 ++++-- .../cortex/voxy/client/core/gl/GlBuffer.java | 4 ++ .../cortex/voxy/client/core/gl/GlDebug.java | 49 +++++++++++++++++++ .../voxy/client/core/gl/GlFramebuffer.java | 5 ++ .../core/gl/GlPersistentMappedBuffer.java | 4 ++ .../cortex/voxy/client/core/gl/GlTexture.java | 4 ++ .../voxy/client/core/gl/shader/Shader.java | 5 ++ .../voxy/client/core/model/ModelStore.java | 6 +-- .../client/core/model/ModelTextureBakery.java | 13 ++--- .../building/RenderDataFactory4.java | 25 +++++++--- .../client/core/rendering/util/HiZBuffer.java | 7 +-- .../rendering/util/RawDownloadStream.java | 2 +- .../core/rendering/util/UploadStream.java | 2 +- .../common/voxelization/VoxelizedSection.java | 7 +++ .../world/service/VoxelIngestService.java | 3 +- 15 files changed, 124 insertions(+), 28 deletions(-) create mode 100644 src/main/java/me/cortex/voxy/client/core/gl/GlDebug.java diff --git a/build.gradle b/build.gradle index 7b4fe72c..97aa5a72 100644 --- a/build.gradle +++ b/build.gradle @@ -25,15 +25,20 @@ repositories { def gitCommitHash = { -> def stdout = new ByteArrayOutputStream() - exec { + ExecResult result = exec ()->{ commandLine 'git', 'rev-parse', '--short', 'HEAD' standardOutput = stdout ignoreExitValue = true } - return stdout.toString().trim() -} -def buildtime = System.currentTimeSeconds() + if (result.getExitValue() != 0) { + return ""; + } else { + return stdout.toString().trim(); + } +} + +def buildtime = {System.currentTimeSeconds()} processResources { inputs.properties("version": project.version, "commit": gitCommitHash, "buildtime": buildtime) @@ -128,6 +133,7 @@ repositories { mavenCentral() } + dependencies { implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion") @@ -141,8 +147,8 @@ dependencies { include(runtimeOnly "org.lwjgl:lwjgl-lmdb:$lwjglVersion:natives-linux") include(runtimeOnly "org.lwjgl:lwjgl-zstd:$lwjglVersion:natives-linux") - include(implementation 'org.rocksdb:rocksdbjni:8.10.0') include(implementation 'redis.clients:jedis:5.1.0') + include(implementation('org.rocksdb:rocksdbjni:8.10.0')) include(implementation 'org.apache.commons:commons-pool2:2.12.0') //implementation 'org.rocksdb:rocksdbjni:8.10.0' //implementation 'redis.clients:jedis:5.1.0' diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java b/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java index 9a9df49e..d8184a54 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java @@ -53,4 +53,8 @@ public class GlBuffer extends TrackedObject { public static long getTotalSize() { return TOTAL_SIZE; } + + public GlBuffer name(String name) { + return GlDebug.name(name, this); + } } diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlDebug.java b/src/main/java/me/cortex/voxy/client/core/gl/GlDebug.java new file mode 100644 index 00000000..8fc9621f --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlDebug.java @@ -0,0 +1,49 @@ +package me.cortex.voxy.client.core.gl; + +import me.cortex.voxy.client.core.gl.shader.Shader; + +import static org.lwjgl.opengl.GL43C.*; + +public class GlDebug { + public static final boolean GL_DEBUG = System.getProperty("voxy.glDebug", "false").equals("true"); + + + public static void push() { + //glPushDebugGroup() + } + + public static GlBuffer name(String name, GlBuffer buffer) { + if (GL_DEBUG) { + glObjectLabel(GL_BUFFER, buffer.id, name); + } + return buffer; + } + + public static T name(String name, T shader) { + if (GL_DEBUG) { + glObjectLabel(GL_PROGRAM, shader.id(), name); + } + return shader; + } + + public static GlFramebuffer name(String name, GlFramebuffer framebuffer) { + if (GL_DEBUG) { + glObjectLabel(GL_FRAMEBUFFER, framebuffer.id, name); + } + return framebuffer; + } + + public static GlTexture name(String name, GlTexture texture) { + if (GL_DEBUG) { + glObjectLabel(GL_TEXTURE, texture.id, name); + } + return texture; + } + + public static GlPersistentMappedBuffer name(String name, GlPersistentMappedBuffer buffer) { + if (GL_DEBUG) { + glObjectLabel(GL_BUFFER, buffer.id, name); + } + return buffer; + } +} diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java b/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java index 44cb73ea..81eff80e 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java @@ -37,4 +37,9 @@ public class GlFramebuffer extends TrackedObject { } return this; } + + + public GlFramebuffer name(String name) { + return GlDebug.name(name, this); + } } diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlPersistentMappedBuffer.java b/src/main/java/me/cortex/voxy/client/core/gl/GlPersistentMappedBuffer.java index 20dc98db..80399741 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/GlPersistentMappedBuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlPersistentMappedBuffer.java @@ -31,4 +31,8 @@ public class GlPersistentMappedBuffer extends TrackedObject { public long addr() { return this.addr; } + + public GlPersistentMappedBuffer name(String name) { + return GlDebug.name(name, this); + } } diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlTexture.java b/src/main/java/me/cortex/voxy/client/core/gl/GlTexture.java index e979b541..7eb7eeda 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/GlTexture.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlTexture.java @@ -51,4 +51,8 @@ public class GlTexture extends TrackedObject { super.free0(); glDeleteTextures(this.id); } + + public GlTexture name(String name) { + return GlDebug.name(name, this); + } } diff --git a/src/main/java/me/cortex/voxy/client/core/gl/shader/Shader.java b/src/main/java/me/cortex/voxy/client/core/gl/shader/Shader.java index f2eac42e..19bbf96e 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/shader/Shader.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/shader/Shader.java @@ -1,5 +1,7 @@ package me.cortex.voxy.client.core.gl.shader; +import me.cortex.voxy.client.core.gl.GlBuffer; +import me.cortex.voxy.client.core.gl.GlDebug; import me.cortex.voxy.common.util.TrackedObject; import org.lwjgl.opengl.GL20C; @@ -29,6 +31,9 @@ public class Shader extends TrackedObject { } + public Shader name(String name) { + return GlDebug.name(name, this); + } public static Builder make(IShaderProcessor... processor) { diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java b/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java index beaf3615..1a80f374 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java @@ -22,9 +22,9 @@ public class ModelStore { public final int blockSampler = glGenSamplers(); public ModelStore() { - this.modelBuffer = new GlBuffer(MODEL_SIZE * (1<<16)); - this.modelColourBuffer = new GlBuffer(4 * (1<<16)); - this.textures = new GlTexture().store(GL_RGBA8, 4, ModelFactory.MODEL_TEXTURE_SIZE*3*256,ModelFactory.MODEL_TEXTURE_SIZE*2*256); + this.modelBuffer = new GlBuffer(MODEL_SIZE * (1<<16)).name("ModelData"); + this.modelColourBuffer = new GlBuffer(4 * (1<<16)).name("ModelColour"); + this.textures = new GlTexture().store(GL_RGBA8, 4, ModelFactory.MODEL_TEXTURE_SIZE*3*256,ModelFactory.MODEL_TEXTURE_SIZE*2*256).name("ModelTextures"); diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java b/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java index 35e8c9a1..b5579a5a 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java @@ -2,7 +2,6 @@ package me.cortex.voxy.client.core.model; import com.mojang.blaze3d.platform.GlStateManager; import me.cortex.voxy.client.core.gl.GlFramebuffer; -import me.cortex.voxy.client.core.gl.GlRenderBuffer; import me.cortex.voxy.client.core.gl.GlTexture; import me.cortex.voxy.client.core.gl.shader.Shader; import me.cortex.voxy.client.core.gl.shader.ShaderType; @@ -66,7 +65,8 @@ public class ModelTextureBakery { private final Shader rasterShader = Shader.make() .add(ShaderType.VERTEX, "voxy:bakery/position_tex.vsh") .add(ShaderType.FRAGMENT, "voxy:bakery/position_tex.fsh") - .compile(); + .compile() + .name("ModelBaker"); private final Shader copyOutShader; @@ -78,11 +78,11 @@ public class ModelTextureBakery { this.width = width; this.height = height; - this.colourTex = new GlTexture().store(GL_RGBA8, 1, width, height); - this.depthTex = new GlTexture().store(GL_DEPTH24_STENCIL8, 1, width, height); + this.colourTex = new GlTexture().store(GL_RGBA8, 1, width, height).name("ModelBakeryColour"); + this.depthTex = new GlTexture().store(GL_DEPTH24_STENCIL8, 1, width, height).name("ModelBakeryDepth"); this.depthTexView = this.depthTex.createView(); - this.framebuffer = new GlFramebuffer().bind(GL_COLOR_ATTACHMENT0, this.colourTex).bind(GL_DEPTH_STENCIL_ATTACHMENT, this.depthTex).verify(); + this.framebuffer = new GlFramebuffer().bind(GL_COLOR_ATTACHMENT0, this.colourTex).bind(GL_DEPTH_STENCIL_ATTACHMENT, this.depthTex).verify().name("ModelFramebuffer"); glTextureParameteri(this.depthTex.id, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); glTextureParameteri(this.depthTexView.id, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX); @@ -91,7 +91,8 @@ public class ModelTextureBakery { .define("WIDTH", width) .define("HEIGHT", height) .add(ShaderType.COMPUTE, "voxy:bakery/buffercopy.comp") - .compile(); + .compile() + .name("ModelBakeryOut"); //This is done to help make debugging easier FACE_VIEWS.clear(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory4.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory4.java index 3134f755..edc37626 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory4.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory4.java @@ -160,7 +160,7 @@ public class RenderDataFactory4 { int modelId = this.modelMan.getModelId(Mapper.getBlockId(block)); long modelMetadata = this.modelMan.getModelMetadataFromClientId(modelId); - sectionData[i * 2] = modelId | ((long) (Mapper.getLightId(block)) << 16) | (((long) (Mapper.getBiomeId(block))) << 24); + sectionData[i * 2] = modelId | ((long) (Mapper.getLightId(block)) << 16) | (ModelQueries.isBiomeColoured(modelMetadata)?(((long) (Mapper.getBiomeId(block))) << 24):0); sectionData[i * 2 + 1] = modelMetadata; boolean isFullyOpaque = ModelQueries.isFullyOpaque(modelMetadata); @@ -221,7 +221,11 @@ public class RenderDataFactory4 { long nextModel = facingForward == 1 ? B : A; //Example thing thats just wrong but as example - this.blockMesher.putNext((long) facingForward | ((selfModel & 0xFFFF) << 26) | (((nextModel>>16)&0xFF) << 55)); + this.blockMesher.putNext(((long) facingForward) |//Facing + ((selfModel & 0xFFFF) << 26) | //ModelId + (((nextModel>>16)&0xFF) << 55) |//Lighting + ((selfModel&(0x1FFL<<24))<<(46-24))//biomeId + ); } } this.blockMesher.endRow(); @@ -258,7 +262,11 @@ public class RenderDataFactory4 { long A = this.sectionData[idx * 2]; //Example thing thats just wrong but as example - this.blockMesher.putNext((long) (side == 0 ? 0L : 1L) | ((A & 0xFFFFL) << 26) | (((0xFFL) & 0xFF) << 55)); + this.blockMesher.putNext((long) (side == 0 ? 0L : 1L) | + ((A & 0xFFFFL) << 26) | + (((0xFFL) & 0xFF) << 55) | + ((A&(0x1FFL<<24))<<(46-24)) + ); } } this.blockMesher.endRow(); @@ -370,8 +378,11 @@ public class RenderDataFactory4 { long nextModel = facingForward==1?B:A; //Example thing thats just wrong but as example - mesher.putNext((long) facingForward | ((selfModel&0xFFFF)<<26) | (((nextModel>>16)&0xFF)<<55)); - //mesher.emitQuad(y, z, 1, 1,(long) facingForward | ((selfModel&0xFFFF)<<26) | (0xFFL<<55)); + mesher.putNext(((long) facingForward) |//Facing + ((selfModel & 0xFFFF) << 26) | //ModelId + (((nextModel>>16)&0xFF) << 55) |//Lighting + ((selfModel&(0x1FFL<<24))<<(46-24))//biomeId + ); } } } @@ -418,7 +429,7 @@ public class RenderDataFactory4 { long A = this.sectionData[(i<<5) * 2]; - ma.putNext(0L | ((A&0xFFFF)<<26) | (((0xFFL)&0xFF)<<55)); + ma.putNext(0L | ((A&0xFFFF)<<26) | (((0xFFL)&0xFF)<<55)|((A&(0x1FFL<<24))<<(46-24))); } else {skipA++;} if ((msk & (1<<31)) != 0) { @@ -426,7 +437,7 @@ public class RenderDataFactory4 { long A = this.sectionData[(i*32+31) * 2]; - mb.putNext(1L | ((A&0xFFFF)<<26) | (((0xFFL)&0xFF)<<55)); + mb.putNext(1L | ((A&0xFFFF)<<26) | (((0xFFL)&0xFF)<<55)|((A&(0x1FFL<<24))<<(46-24))); } else {skipB++;} } ma.skip(skipA); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java b/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java index 03205562..43774425 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java @@ -23,8 +23,9 @@ public class HiZBuffer { private final Shader hiz = Shader.make() .add(ShaderType.VERTEX, "voxy:hiz/blit.vsh") .add(ShaderType.FRAGMENT, "voxy:hiz/blit.fsh") - .compile(); - private final GlFramebuffer fb = new GlFramebuffer(); + .compile() + .name("HiZ Builder"); + private final GlFramebuffer fb = new GlFramebuffer().name("HiZ"); private final int sampler = glGenSamplers(); private GlTexture texture; private int levels; @@ -42,7 +43,7 @@ public class HiZBuffer { // (could probably increase it to be defined by a max meshlet coverage computation thing) //GL_DEPTH_COMPONENT32F //Cant use this as it does not match the depth format of the provided depth buffer - this.texture = new GlTexture().store(GL_DEPTH24_STENCIL8, this.levels, width, height); + this.texture = new GlTexture().store(GL_DEPTH24_STENCIL8, this.levels, width, height).name("HiZ"); glTextureParameteri(this.texture.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTextureParameteri(this.texture.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTextureParameteri(this.texture.id, GL_TEXTURE_COMPARE_MODE, GL_NONE); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/util/RawDownloadStream.java b/src/main/java/me/cortex/voxy/client/core/rendering/util/RawDownloadStream.java index e1f9c5b5..5bad0d0a 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/util/RawDownloadStream.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/util/RawDownloadStream.java @@ -27,7 +27,7 @@ public class RawDownloadStream { private final Deque frames = new ArrayDeque<>(); public RawDownloadStream(int size) { - this.downloadBuffer = new GlPersistentMappedBuffer(size, GL_MAP_READ_BIT|GL_MAP_COHERENT_BIT); + this.downloadBuffer = new GlPersistentMappedBuffer(size, GL_MAP_READ_BIT|GL_MAP_COHERENT_BIT).name("RawDownloadStream"); this.allocationArena.setLimit(size); } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/util/UploadStream.java b/src/main/java/me/cortex/voxy/client/core/rendering/util/UploadStream.java index d440d875..0fb586cf 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/util/UploadStream.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/util/UploadStream.java @@ -30,7 +30,7 @@ public class UploadStream { private final Deque uploadList = new ArrayDeque<>(); public UploadStream(long size) { - this.uploadBuffer = new GlPersistentMappedBuffer(size,GL_MAP_WRITE_BIT|GL_MAP_UNSYNCHRONIZED_BIT|GL_MAP_COHERENT_BIT); + this.uploadBuffer = new GlPersistentMappedBuffer(size,GL_MAP_WRITE_BIT|GL_MAP_UNSYNCHRONIZED_BIT|GL_MAP_COHERENT_BIT).name("UploadStream"); this.allocationArena.setLimit(size); } diff --git a/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java b/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java index 6b9db0a4..72a594b4 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/VoxelizedSection.java @@ -3,6 +3,8 @@ package me.cortex.voxy.common.voxelization; import me.cortex.voxy.common.world.other.Mapper; +import java.util.Arrays; + //16x16x16 block section public class VoxelizedSection { public int x; @@ -39,4 +41,9 @@ public class VoxelizedSection { public static VoxelizedSection createEmpty() { return new VoxelizedSection(new long[16*16*16 + 8*8*8 + 4*4*4 + 2*2*2 + 1]); } + + public VoxelizedSection zero() { + Arrays.fill(this.section, 0); + return this; + } } diff --git a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java index ac9ae893..6d2a765b 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java @@ -34,8 +34,7 @@ public class VoxelIngestService { i++; var lighting = this.captureLightMap.remove(ChunkSectionPos.from(chunk.getPos(), i).asLong()); if (section.isEmpty() && lighting==null) {//If the chunk section has lighting data, propagate it - //TODO: add local cache so that it doesnt constantly create new sections - this.world.insertUpdate(VoxelizedSection.createEmpty().setPosition(chunk.getPos().x, i, chunk.getPos().z)); + this.world.insertUpdate(SECTION_CACHE.get().zero().setPosition(chunk.getPos().x, i, chunk.getPos().z)); } else { VoxelizedSection csec = WorldConversionFactory.convert( SECTION_CACHE.get().setPosition(chunk.getPos().x, i, chunk.getPos().z),