This commit is contained in:
mcrcortex
2024-09-11 22:49:00 +10:00
parent 756431b581
commit 76aaf3824d
7 changed files with 62 additions and 22 deletions

View File

@@ -24,14 +24,10 @@ public class Voxy implements ClientModInitializer {
} }
private static final ContextSelectionSystem selector = new ContextSelectionSystem(); private static final ContextSelectionSystem SELECTOR = new ContextSelectionSystem();
public static VoxelCore createVoxelCore(ClientWorld world) { public static VoxelCore createVoxelCore(ClientWorld world) {
var selection = selector.getBestSelectionOrCreate(world); var selection = SELECTOR.getBestSelectionOrCreate(world);
return new VoxelCore(selection); return new VoxelCore(selection);
} }
public static void breakpoint() {
int breakpoint = 0;
}
} }

View File

@@ -1,18 +1,20 @@
package me.cortex.voxy.client.core.rendering.hierachical2; package me.cortex.voxy.client.core.rendering.hierachical2;
import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.client.core.gl.shader.Shader;
import me.cortex.voxy.client.core.gl.shader.ShaderType;
import me.cortex.voxy.client.core.rendering.util.HiZBuffer; import me.cortex.voxy.client.core.rendering.util.HiZBuffer;
import me.cortex.voxy.client.core.rendering.Viewport; import me.cortex.voxy.client.core.rendering.Viewport;
import me.cortex.voxy.client.core.rendering.util.DownloadStream; import me.cortex.voxy.client.core.rendering.util.DownloadStream;
import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.client.core.rendering.util.UploadStream;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import static me.cortex.voxy.client.core.rendering.PrintfDebugUtil.PRINTF_object;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT; import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
import static org.lwjgl.opengl.GL30.GL_R32UI; import static org.lwjgl.opengl.GL30.GL_R32UI;
import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER; import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER;
import static org.lwjgl.opengl.GL42.glMemoryBarrier; import static org.lwjgl.opengl.GL42.glMemoryBarrier;
import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BARRIER_BIT; import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BARRIER_BIT;
import static org.lwjgl.opengl.GL43.glDispatchComputeIndirect;
import static org.lwjgl.opengl.GL45.nglClearNamedBufferSubData; import static org.lwjgl.opengl.GL45.nglClearNamedBufferSubData;
public class HierarchicalOcclusionTraverser { public class HierarchicalOcclusionTraverser {
@@ -34,6 +36,10 @@ public class HierarchicalOcclusionTraverser {
private final HiZBuffer hiZBuffer = new HiZBuffer(); private final HiZBuffer hiZBuffer = new HiZBuffer();
private final Shader traversal = Shader.make(PRINTF_object)
.add(ShaderType.COMPUTE, "voxy:lod/hierarchical/traversal.comp")
.compile();
public HierarchicalOcclusionTraverser(HierarchicalNodeManager nodeManager, int requestBufferCount) { public HierarchicalOcclusionTraverser(HierarchicalNodeManager nodeManager, int requestBufferCount) {
this.nodeManager = nodeManager; this.nodeManager = nodeManager;
@@ -46,6 +52,10 @@ public class HierarchicalOcclusionTraverser {
} }
private void bindings() {
}
public void doTraversal(Viewport<?> viewport, int depthBuffer) { public void doTraversal(Viewport<?> viewport, int depthBuffer) {
//Compute the mip chain //Compute the mip chain
this.hiZBuffer.buildMipChain(depthBuffer, viewport.width, viewport.height); this.hiZBuffer.buildMipChain(depthBuffer, viewport.width, viewport.height);
@@ -53,6 +63,9 @@ public class HierarchicalOcclusionTraverser {
this.uploadUniform(viewport); this.uploadUniform(viewport);
UploadStream.INSTANCE.commit(); UploadStream.INSTANCE.commit();
this.traversal.bind();
this.bindings();
//Use a chain of glDispatchComputeIndirect (5 times) with alternating read/write buffers //Use a chain of glDispatchComputeIndirect (5 times) with alternating read/write buffers
// TODO: swap to persistent gpu thread instead // TODO: swap to persistent gpu thread instead
@@ -89,6 +102,7 @@ public class HierarchicalOcclusionTraverser {
} }
public void free() { public void free() {
this.traversal.free();
this.requestBuffer.free(); this.requestBuffer.free();
this.hiZBuffer.free(); this.hiZBuffer.free();
this.nodeBuffer.free(); this.nodeBuffer.free();

View File

@@ -66,7 +66,7 @@ public class BasicSectionGeometryManager extends AbstractSectionGeometryManager
//Invalidate the section id //Invalidate the section id
this.invalidatedSectionIds.add(newId); this.invalidatedSectionIds.add(newId);
HierarchicalOcclusionTraverser.HACKY_SECTION_COUNT = this.allocationSet.getCount(); //HierarchicalOcclusionTraverser.HACKY_SECTION_COUNT = this.allocationSet.getCount();
return newId; return newId;
} }

View File

@@ -11,17 +11,18 @@ import java.util.function.Supplier;
// it is probably better anyway // it is probably better anyway
public class ServiceThreadPool { public class ServiceThreadPool {
private volatile boolean running = true; private volatile boolean running = true;
private final Thread[] workers; private Thread[] workers = new Thread[0];
private final Semaphore jobCounter = new Semaphore(0); private final Semaphore jobCounter = new Semaphore(0);
private volatile ServiceSlice[] serviceSlices = new ServiceSlice[0]; private volatile ServiceSlice[] serviceSlices = new ServiceSlice[0];
private final AtomicLong totalJobWeight = new AtomicLong(); private final AtomicLong totalJobWeight = new AtomicLong();
private final ThreadGroup threadGroup; private final ThreadGroup threadGroup;
public ServiceThreadPool(int workers) { public ServiceThreadPool(int threadCount) {
this.threadGroup = new ThreadGroup("Service job workers"); this.threadGroup = new ThreadGroup("Service job workers");
this.workers = new Thread[workers];
for (int i = 0; i < workers; i++) { this.workers = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
int threadId = i; int threadId = i;
var worker = new Thread(this.threadGroup, ()->this.worker(threadId)); var worker = new Thread(this.threadGroup, ()->this.worker(threadId));
worker.setDaemon(false); worker.setDaemon(false);
@@ -215,4 +216,29 @@ public class ServiceThreadPool {
public int getThreadCount() { public int getThreadCount() {
return this.workers.length; return this.workers.length;
} }
/*
public void setThreadCount(int threadCount) {
if (threadCount == this.workers.length) {
return;//No change
}
if (threadCount < this.workers.length) {
//Need to remove workers
} else {
//Need to add new workers
}
this.workers = new Thread[threadCount];
for (int i = 0; i < workers; i++) {
int threadId = i;
var worker = new Thread(this.threadGroup, ()->this.worker(threadId));
worker.setDaemon(false);
worker.setName("Service worker #" + i);
worker.start();
worker.setUncaughtExceptionHandler(this::handleUncaughtException);
this.workers[i] = worker;
}
}
*/
} }

View File

@@ -16,11 +16,13 @@ public class SaveLoadSystem {
public static final boolean VERIFY_HASH_ON_LOAD = System.getProperty("voxy.verifySectionOnLoad", "true").equals("true"); public static final boolean VERIFY_HASH_ON_LOAD = System.getProperty("voxy.verifySectionOnLoad", "true").equals("true");
public static final int BIGGEST_SERIALIZED_SECTION_SIZE = 32 * 32 * 32 * 8 * 2 + 8; public static final int BIGGEST_SERIALIZED_SECTION_SIZE = 32 * 32 * 32 * 8 * 2 + 8;
public static int lin2z(int i) { public static int lin2z(int i) {//y,z,x
int x = i&0x1F; int x = i&0x1F;
int y = (i>>10)&0x1F; int y = (i>>10)&0x1F;
int z = (i>>5)&0x1F; int z = (i>>5)&0x1F;
return Integer.expand(x,0b1001001001001)|Integer.expand(y,0b10010010010010)|Integer.expand(z,0b100100100100100); return Integer.expand(x,0b1001001001001)|Integer.expand(y,0b10010010010010)|Integer.expand(z,0b100100100100100);
//zyxzyxzyxzyxzyx
} }
public static int z2lin(int i) { public static int z2lin(int i) {

View File

@@ -20,10 +20,19 @@ public class VoxyCommon implements ModInitializer {
IS_DEDICATED_SERVER = FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER; IS_DEDICATED_SERVER = FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER;
Serialization.init(); Serialization.init();
} }
@Override @Override
public void onInitialize() { public void onInitialize() {
//this.serviceThreadPool = new ServiceThreadPool(VoxyConfig.CONFIG.serviceThreads); //this.serviceThreadPool = new ServiceThreadPool(VoxyConfig.CONFIG.serviceThreads);
//TODO: need to have a common config with server/client configs deriving from it
// maybe server/client extend it? or something? cause like client needs server config (at least partially sometimes)
// but server doesnt need client config
}
public static void breakpoint() {
int breakpoint = 0;
} }
} }

View File

@@ -3,7 +3,8 @@
//TODO: increase local size //TODO: increase local size
#define LOCAL_SIZE_BITS 5 #define LOCAL_SIZE_BITS 5
#define LOCAL_SIZE_MSK ((1<<LOCAL_SIZE_BITS)-1) #define LOCAL_SIZE_MSK ((1<<LOCAL_SIZE_BITS)-1)
layout(local_size_x=(1<<LOCAL_SIZE_BITS), local_size_y=1) in; #define LOCAL_SIZE (1<<LOCAL_SIZE_BITS)
layout(local_size_x=LOCAL_SIZE) in;//, local_size_y=1
#import <voxy:lod/hierarchical/binding_points.glsl> #import <voxy:lod/hierarchical/binding_points.glsl>
#line 7 #line 7
@@ -55,14 +56,6 @@ layout(binding = DEBUG_RENDER_NODE_INDEX, std430) restrict buffer DebugRenderNod
}; };
#endif #endif
/*
layout(binding = 2, std430) restrict buffer QueueData {
uint tail;
uint head;
uint top;
uint[] queue;
} queue;
*/
#import <voxy:lod/hierarchical/transform.glsl> #import <voxy:lod/hierarchical/transform.glsl>
#import <voxy:lod/hierarchical/node.glsl> #import <voxy:lod/hierarchical/node.glsl>