From 68a17f05783a75be61d3f5016e1df8815ae9c598 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 24 Mar 2025 13:49:15 +1000 Subject: [PATCH] Fixes and tweeks for things --- .../voxy/client/core/model/TextureUtils.java | 4 +- .../building/RenderDataFactory45.java | 2 + .../rendering/hierachical/NodeCleaner.java | 42 +++++++++++-------- .../hierachical/TestNodeManager.java | 6 +-- .../cleaner/result_transformer.comp | 4 +- .../hierarchical/cleaner/sort_visibility.comp | 10 +++-- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java b/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java index c7986f50..f4506729 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java +++ b/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java @@ -92,10 +92,10 @@ public class TextureUtils { private static float u2fdepth(int depth) { float depthF = (float) ((double)depth/((1<<24)-1)); //https://registry.khronos.org/OpenGL-Refpages/gl4/html/glDepthRange.xhtml - // due to this and the unsigned bullshit, i believe the depth value needs to get multiplied by 2 + // due to this and the unsigned bullshit, believe the depth value needs to get multiplied by 2 //Shouldent be needed due to the compute bake copy - //depthF *= 2; + depthF *= 2; if (depthF > 1.00001f) { System.err.println("Warning: Depth greater than 1"); depthF = 1.0f; diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory45.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory45.java index fbae591d..68b2cf64 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory45.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory45.java @@ -359,6 +359,7 @@ public class RenderDataFactory45 { if (false) {//Non fully opaque geometry + this.blockMesher.doAuxiliaryFaceOffset = false; //Note: think is ok to just reuse.. blockMesher this.blockMesher.axis = axis; for (int layer = 0; layer < 32; layer++) { @@ -400,6 +401,7 @@ public class RenderDataFactory45 { } this.blockMesher.finish(); } + this.blockMesher.doAuxiliaryFaceOffset = true; } } } 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 9c26e817..1a88bf09 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 @@ -119,31 +119,37 @@ public class NodeCleaner { this.setIds(this.freeIds, -1); if (this.shouldCleanGeometry()) { - glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); - this.outputBuffer.fill(this.nodeManager.maxNodeCount-2);//TODO: maybe dont set to zero?? + var gm = this.nodeManager.getGeometryManager(); + + int c = (int) (((((double) gm.getUsedCapacity() / gm.geometryCapacity) - 0.75) * 4 * 10) + 1); + c = 1; + for (int i = 0; i < c; i++) { + 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); + this.sorter.bind(); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, nodeDataBuffer.id); - //TODO: choose whether this is in nodeSpace or section/geometryId space - // - glDispatchCompute((this.nodeManager.getCurrentMaxNodeId()+SORTING_WORKER_SIZE-1)/SORTING_WORKER_SIZE, 1, 1); - glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); + //TODO: choose whether this is in nodeSpace or section/geometryId space + // + glDispatchCompute((this.nodeManager.getCurrentMaxNodeId() + SORTING_WORKER_SIZE - 1) / SORTING_WORKER_SIZE, 1, 1); + glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); - this.resultTransformer.bind(); - glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, this.outputBuffer.id, 0, 4*OUTPUT_COUNT); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, nodeDataBuffer.id); - glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 2, this.outputBuffer.id, 4*OUTPUT_COUNT, 8*OUTPUT_COUNT); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.visibilityBuffer.id); - glUniform1ui(0, this.visibilityId); + this.resultTransformer.bind(); + glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, this.outputBuffer.id, 0, 4 * OUTPUT_COUNT); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, nodeDataBuffer.id); + glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 2, this.outputBuffer.id, 4 * OUTPUT_COUNT, 8 * OUTPUT_COUNT); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.visibilityBuffer.id); + glUniform1ui(0, this.visibilityId); - glDispatchCompute(1,1,1); - //glFinish(); + glDispatchCompute(1, 1, 1); + //glFinish(); - DownloadStream.INSTANCE.download(this.outputBuffer, 4*OUTPUT_COUNT, 8*OUTPUT_COUNT, this::onDownload); - //glFinish(); + DownloadStream.INSTANCE.download(this.outputBuffer, 4 * OUTPUT_COUNT, 8 * OUTPUT_COUNT, this::onDownload); + //glFinish(); + } } } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/TestNodeManager.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/TestNodeManager.java index 02a2f8d8..13cb570c 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/TestNodeManager.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/TestNodeManager.java @@ -274,8 +274,8 @@ public class TestNodeManager { public static void main(String[] args) { Logger.INSERT_CLASS = false; - int ITER_COUNT = 5000; - int INNER_ITER_COUNT = 100_000; + int ITER_COUNT = 50_000; + int INNER_ITER_COUNT = 500_000; boolean GEO_REM = true; AtomicInteger finished = new AtomicInteger(); @@ -283,7 +283,7 @@ public class TestNodeManager { Logger.SHUTUP = true; - if (true) { + if (false) { for (int q = 0; q < ITER_COUNT; q++) { //Logger.info("Iteration "+ q); if (runTest(INNER_ITER_COUNT, q, seenTraces, GEO_REM)) { 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 4153668b..c53978d1 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 @@ -22,7 +22,7 @@ void main() { uint id = minVisIds[gl_LocalInvocationID.x]; uvec4 node = nodes[id]; uvec2 res = node.xy; - if (all(equal(node, uvec4(0)))) {//If its a empty node, TODO: DONT THINK THIS IS ACTUALLY CORRECT + if (all(equal(node, uvec4(-1)))) {//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 @@ -30,6 +30,6 @@ void main() { //This is an evil hack to not spam the same node 500 times in a row //TODO: maybe instead set this to the current frame index // visibility[id] += 30; - visibility[id] = visibilityCounter; + visibility[id] = visibilityCounter + 60; } \ 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 ffdcb774..932f3acf 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,7 +18,8 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict volatile buffer Minimum }; //Returns the id of the max value -uint atomicDerefMax(uint atId, uint id, uint value) { +uint atomicDerefMaxExchange(uint atId, uint id) { + const uint value = visiblity[id]; while (true) { const uint existingId = minVisIds[atId]; //Check if the value is less than the dereferenced value, if its not, return our own id @@ -26,7 +27,7 @@ uint atomicDerefMax(uint atId, uint id, uint value) { return id; } //Attempt to swap, since we know we are less than the existingId - uint c = atomicCompSwap(minVisIds[atId], existingId, id); + const uint c = atomicCompSwap(minVisIds[atId], existingId, id); //Check if we did swap, else if we failed (or got reswapped else where) recheck //We did swap, (since the original mem contents was the existing id) @@ -40,7 +41,7 @@ uint atomicDerefMax(uint atId, uint id, uint value) { //TODO: optimize void bubbleSort(uint start, uint id) { for (uint i = start; i < OUTPUT_SIZE; i++) { - id = atomicDerefMax(i, id, visiblity[id]); + id = atomicDerefMaxExchange(i, id); } } @@ -50,6 +51,9 @@ void main() { //} //First do a min sort/set of min OUTPUT_SIZE values of the set uint vis = visiblity[gl_GlobalInvocationID.x]; + if (vis == uint(-1)) { + return; + } if (visiblity[minVisIds[OUTPUT_SIZE-1]] <= vis) { return; }