This commit is contained in:
mcrcortex
2025-03-04 12:14:28 +10:00
parent 743c423ba5
commit ff82c2d761
4 changed files with 34 additions and 23 deletions

View File

@@ -49,7 +49,8 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
//Max sections: ~500k //Max sections: ~500k
//Max geometry: 1 gb //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 //Do something incredibly hacky, we dont need to keep the reference to this around, so just connect and discard
var router = new SectionUpdateRouter(); var router = new SectionUpdateRouter();

View File

@@ -1,6 +1,8 @@
package me.cortex.voxy.client.core.rendering.hierachical; 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.ints.IntArrayFIFOQueue;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import me.cortex.voxy.client.core.gl.GlBuffer; 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.AutoBindingShader;
import me.cortex.voxy.client.core.gl.shader.PrintfInjector; import me.cortex.voxy.client.core.gl.shader.PrintfInjector;
@@ -45,7 +47,7 @@ public class NodeCleaner {
.define("MIN_ID_BUFFER_BINDING", 0) .define("MIN_ID_BUFFER_BINDING", 0)
.define("NODE_BUFFER_BINDING", 1) .define("NODE_BUFFER_BINDING", 1)
.define("OUTPUT_BUFFER_BINDING", 2) .define("OUTPUT_BUFFER_BINDING", 2)
.define("QQQQQQ", 3) .define("VISIBILITY_BUFFER_BINDING", 3)
.add(ShaderType.COMPUTE, "voxy:lod/hierarchical/cleaner/result_transformer.comp") .add(ShaderType.COMPUTE, "voxy:lod/hierarchical/cleaner/result_transformer.comp")
.compile(); .compile();
@@ -90,10 +92,11 @@ public class NodeCleaner {
this.visibilityId++; this.visibilityId++;
this.clearIds(); this.clearIds();
if (this.shouldCleanGeometry() & false) { if (this.shouldCleanGeometry() && false ) {
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
this.outputBuffer.fill(this.nodeManager.maxNodeCount-2);//TODO: maybe dont set to zero?? this.outputBuffer.fill(this.nodeManager.maxNodeCount-2);//TODO: maybe dont set to zero??
this.sorter.bind(); this.sorter.bind();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, nodeDataBuffer.id); 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); glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 2, this.outputBuffer.id, 4*OUTPUT_COUNT, 8*OUTPUT_COUNT);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.visibilityBuffer.id); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.visibilityBuffer.id);
//this.outputBuffer.fill(0);//TODO: maybe dont set to zero??
glDispatchCompute(1,1,1); glDispatchCompute(1,1,1);
DownloadStream.INSTANCE.download(this.outputBuffer, 4*OUTPUT_COUNT, 8*OUTPUT_COUNT, this::onDownload); 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) { private void onDownload(long ptr, long size) {
//StringBuilder b = new StringBuilder(); //StringBuilder b = new StringBuilder();
Long2IntOpenHashMap aa = new Long2IntOpenHashMap();
for (int i = 0; i < OUTPUT_COUNT; i++) { for (int i = 0; i < OUTPUT_COUNT; i++) {
long pos = Integer.toUnsignedLong(MemoryUtil.memGetInt(ptr + 8 * i))<<32; long pos = Integer.toUnsignedLong(MemoryUtil.memGetInt(ptr + 8 * i))<<32;
pos |= Integer.toUnsignedLong(MemoryUtil.memGetInt(ptr + 8 * i + 4)); 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 //TODO: investigate how or what this happens
continue; continue;
} }
this.nodeManager.removeNodeGeometry(pos); this.nodeManager.removeNodeGeometry(pos);
//b.append(", ").append(WorldEngine.pprintPos(pos));//.append(((int)((pos>>32)&0xFFFFFFFFL)));// //b.append(", ").append(WorldEngine.pprintPos(pos));//.append(((int)((pos>>32)&0xFFFFFFFFL)));//
} }
int a = 0;
//System.out.println(b); //System.out.println(b);
} }

View File

@@ -13,11 +13,17 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict writeonly buffer Output
uvec2 outputBuffer[OUTPUT_SIZE]; uvec2 outputBuffer[OUTPUT_SIZE];
}; };
layout(binding = QQQQQQ, std430) restrict buffer QQQ { layout(binding = VISIBILITY_BUFFER_BINDING, std430) restrict buffer VisibilityBuffer {
uint[] qq; uint[] visibility;
}; };
void main() { void main() {
outputBuffer[gl_LocalInvocationID.x] = nodes[minVisIds[gl_LocalInvocationID.x]].xy;//Move the position of the node id into the output buffer uvec4 node = nodes[minVisIds[gl_LocalInvocationID.x]];
//outputBuffer[gl_LocalInvocationID.x].x = qq[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]];//
} }

View File

@@ -18,31 +18,29 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict volatile buffer Minimum
}; };
//Returns the id of the max value //Returns the id of the max value
uint atomicDerefMin(uint atId, uint id, uint value) { uint atomicDerefMax(uint atId, uint id, uint value) {
uint existingId = minVisIds[atId];
while (true) { while (true) {
const uint existingId = minVisIds[atId];
//Check if the value is less than the dereferenced value, if its not, return our own id //Check if the value is less than the dereferenced value, if its not, return our own id
if (visiblity[existingId] <= value) { if (visiblity[existingId] <= value) {
return id; return id;
} }
//Attempt to swap, since we know we are less than the existingId //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 //Check if we did swap, else if we failed (or got reswapped else where) recheck
uint pExistingId = existingId;
existingId = minVisIds[atId]; //We did swap, (since the original mem contents was the existing id)
if (existingId == id) { // which means existingId is now the max of the ptr
return pExistingId; if (c == existingId) {
return existingId;
} }
} }
} }
//TODO: optimize //TODO: optimize
void bubbleSort(uint start, uint id, uint value) { void bubbleSort(uint start, uint id) {
for (uint i = start; i < OUTPUT_SIZE; i++) { for (uint i = start; i < OUTPUT_SIZE; i++) {
uint nextId = atomicDerefMin(i, id, value); id = atomicDerefMax(i, id, visiblity[id]);
//Else we need to bubble the value up
id = nextId;
value = visiblity[id];
} }
} }
@@ -57,8 +55,8 @@ void main() {
} }
UnpackedNode node; UnpackedNode node;
unpackNode(node, gl_GlobalInvocationID.x); 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; return;
} }
bubbleSort(0, gl_GlobalInvocationID.x, vis); bubbleSort(0, gl_GlobalInvocationID.x);
} }