From ff82c2d7615e3b05b9762036863aca755e53efe6 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 4 Mar 2025 12:14:28 +1000 Subject: [PATCH] Tinker --- .../client/core/rendering/RenderService.java | 3 ++- .../rendering/hierachical/NodeCleaner.java | 14 +++++++--- .../cleaner/result_transformer.comp | 14 +++++++--- .../hierarchical/cleaner/sort_visibility.comp | 26 +++++++++---------- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java index ca553ca0..b37da893 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java @@ -49,7 +49,8 @@ public class RenderService, J extends Vi //Max sections: ~500k //Max geometry: 1 gb - this.sectionRenderer = (T) createSectionRenderer(this.modelService.getStore(),1<<20, (1L<<31)-1024); + this.sectionRenderer = (T) createSectionRenderer(this.modelService.getStore(),1<<20, (1L<<32)-1024); + Logger.info("Using renderer: " + this.sectionRenderer.getClass().getSimpleName()); //Do something incredibly hacky, we dont need to keep the reference to this around, so just connect and discard var router = new SectionUpdateRouter(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeCleaner.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeCleaner.java index f1af6508..fc15b797 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeCleaner.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeCleaner.java @@ -1,6 +1,8 @@ package me.cortex.voxy.client.core.rendering.hierachical; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue; +import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.gl.shader.AutoBindingShader; import me.cortex.voxy.client.core.gl.shader.PrintfInjector; @@ -45,7 +47,7 @@ public class NodeCleaner { .define("MIN_ID_BUFFER_BINDING", 0) .define("NODE_BUFFER_BINDING", 1) .define("OUTPUT_BUFFER_BINDING", 2) - .define("QQQQQQ", 3) + .define("VISIBILITY_BUFFER_BINDING", 3) .add(ShaderType.COMPUTE, "voxy:lod/hierarchical/cleaner/result_transformer.comp") .compile(); @@ -90,10 +92,11 @@ public class NodeCleaner { this.visibilityId++; this.clearIds(); - if (this.shouldCleanGeometry() & false) { + if (this.shouldCleanGeometry() && false ) { glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); this.outputBuffer.fill(this.nodeManager.maxNodeCount-2);//TODO: maybe dont set to zero?? + this.sorter.bind(); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, nodeDataBuffer.id); @@ -108,7 +111,6 @@ public class NodeCleaner { glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 2, this.outputBuffer.id, 4*OUTPUT_COUNT, 8*OUTPUT_COUNT); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.visibilityBuffer.id); - //this.outputBuffer.fill(0);//TODO: maybe dont set to zero?? glDispatchCompute(1,1,1); DownloadStream.INSTANCE.download(this.outputBuffer, 4*OUTPUT_COUNT, 8*OUTPUT_COUNT, this::onDownload); @@ -122,16 +124,20 @@ public class NodeCleaner { private void onDownload(long ptr, long size) { //StringBuilder b = new StringBuilder(); + Long2IntOpenHashMap aa = new Long2IntOpenHashMap(); for (int i = 0; i < OUTPUT_COUNT; i++) { long pos = Integer.toUnsignedLong(MemoryUtil.memGetInt(ptr + 8 * i))<<32; pos |= Integer.toUnsignedLong(MemoryUtil.memGetInt(ptr + 8 * i + 4)); - if (pos == 0) { + aa.addTo(pos, 1); + if (pos == -1) { //TODO: investigate how or what this happens continue; } this.nodeManager.removeNodeGeometry(pos); //b.append(", ").append(WorldEngine.pprintPos(pos));//.append(((int)((pos>>32)&0xFFFFFFFFL)));// } + int a = 0; + //System.out.println(b); } diff --git a/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/result_transformer.comp b/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/result_transformer.comp index aedfba09..024984c5 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/result_transformer.comp +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/result_transformer.comp @@ -13,11 +13,17 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict writeonly buffer Output uvec2 outputBuffer[OUTPUT_SIZE]; }; -layout(binding = QQQQQQ, std430) restrict buffer QQQ { - uint[] qq; +layout(binding = VISIBILITY_BUFFER_BINDING, std430) restrict buffer VisibilityBuffer { + uint[] visibility; }; void main() { - outputBuffer[gl_LocalInvocationID.x] = nodes[minVisIds[gl_LocalInvocationID.x]].xy;//Move the position of the node id into the output buffer - //outputBuffer[gl_LocalInvocationID.x].x = qq[minVisIds[gl_LocalInvocationID.x]];// + uvec4 node = nodes[minVisIds[gl_LocalInvocationID.x]]; + uvec2 res = node.xy; + if (all(equal(node, uvec4(0)))) {//If its a empty node, TODO: DONT THINK THIS IS ACTUALLY CORRECT + res = uvec2(-1); + } + outputBuffer[gl_LocalInvocationID.x] = res;//Move the position of the node id into the output buffer + + //outputBuffer[gl_LocalInvocationID.x].x = visibility[minVisIds[gl_LocalInvocationID.x]];// } \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/sort_visibility.comp b/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/sort_visibility.comp index 3e65a478..14ee039e 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/sort_visibility.comp +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/cleaner/sort_visibility.comp @@ -18,31 +18,29 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict volatile buffer Minimum }; //Returns the id of the max value -uint atomicDerefMin(uint atId, uint id, uint value) { - uint existingId = minVisIds[atId]; +uint atomicDerefMax(uint atId, uint id, uint value) { while (true) { + const uint existingId = minVisIds[atId]; //Check if the value is less than the dereferenced value, if its not, return our own id if (visiblity[existingId] <= value) { return id; } //Attempt to swap, since we know we are less than the existingId - atomicCompSwap(minVisIds[atId], existingId, id); + uint c = atomicCompSwap(minVisIds[atId], existingId, id); //Check if we did swap, else if we failed (or got reswapped else where) recheck - uint pExistingId = existingId; - existingId = minVisIds[atId]; - if (existingId == id) { - return pExistingId; + + //We did swap, (since the original mem contents was the existing id) + // which means existingId is now the max of the ptr + if (c == existingId) { + return existingId; } } } //TODO: optimize -void bubbleSort(uint start, uint id, uint value) { +void bubbleSort(uint start, uint id) { for (uint i = start; i < OUTPUT_SIZE; i++) { - uint nextId = atomicDerefMin(i, id, value); - //Else we need to bubble the value up - id = nextId; - value = visiblity[id]; + id = atomicDerefMax(i, id, visiblity[id]); } } @@ -57,8 +55,8 @@ void main() { } UnpackedNode node; unpackNode(node, gl_GlobalInvocationID.x); - if (isEmptyMesh(node) || (!hasMesh(node)) || (!hasChildren(node)) || all(equal(node.pos, ivec3(0)))) { + if (isEmptyMesh(node) || (!hasMesh(node))) {//|| (!hasChildren(node)) return; } - bubbleSort(0, gl_GlobalInvocationID.x, vis); + bubbleSort(0, gl_GlobalInvocationID.x); } \ No newline at end of file