From 76aaf3824d7b433e320ab219308690d3971e217e Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Wed, 11 Sep 2024 22:49:00 +1000 Subject: [PATCH] AA --- src/main/java/me/cortex/voxy/client/Voxy.java | 8 ++--- .../HierarchicalOcclusionTraverser.java | 16 ++++++++- .../section/BasicSectionGeometryManager.java | 2 +- .../voxy/common/thread/ServiceThreadPool.java | 34 ++++++++++++++++--- .../voxy/common/world/SaveLoadSystem.java | 4 ++- .../me/cortex/voxy/commonImpl/VoxyCommon.java | 9 +++++ .../shaders/lod/hierarchical/traversal.comp | 11 ++---- 7 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/Voxy.java b/src/main/java/me/cortex/voxy/client/Voxy.java index a8ab9c8a..ac88d6a8 100644 --- a/src/main/java/me/cortex/voxy/client/Voxy.java +++ b/src/main/java/me/cortex/voxy/client/Voxy.java @@ -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) { - var selection = selector.getBestSelectionOrCreate(world); + var selection = SELECTOR.getBestSelectionOrCreate(world); return new VoxelCore(selection); } - - public static void breakpoint() { - int breakpoint = 0; - } } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalOcclusionTraverser.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalOcclusionTraverser.java index 8a8e8357..035c2405 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalOcclusionTraverser.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalOcclusionTraverser.java @@ -1,18 +1,20 @@ package me.cortex.voxy.client.core.rendering.hierachical2; 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.Viewport; import me.cortex.voxy.client.core.rendering.util.DownloadStream; import me.cortex.voxy.client.core.rendering.util.UploadStream; 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.GL30.GL_R32UI; import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER; import static org.lwjgl.opengl.GL42.glMemoryBarrier; 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; public class HierarchicalOcclusionTraverser { @@ -34,6 +36,10 @@ public class HierarchicalOcclusionTraverser { 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) { this.nodeManager = nodeManager; @@ -46,6 +52,10 @@ public class HierarchicalOcclusionTraverser { } + private void bindings() { + + } + public void doTraversal(Viewport viewport, int depthBuffer) { //Compute the mip chain this.hiZBuffer.buildMipChain(depthBuffer, viewport.width, viewport.height); @@ -53,6 +63,9 @@ public class HierarchicalOcclusionTraverser { this.uploadUniform(viewport); UploadStream.INSTANCE.commit(); + this.traversal.bind(); + this.bindings(); + //Use a chain of glDispatchComputeIndirect (5 times) with alternating read/write buffers // TODO: swap to persistent gpu thread instead @@ -89,6 +102,7 @@ public class HierarchicalOcclusionTraverser { } public void free() { + this.traversal.free(); this.requestBuffer.free(); this.hiZBuffer.free(); this.nodeBuffer.free(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/section/BasicSectionGeometryManager.java b/src/main/java/me/cortex/voxy/client/core/rendering/section/BasicSectionGeometryManager.java index 667b8331..26b9163d 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/section/BasicSectionGeometryManager.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/section/BasicSectionGeometryManager.java @@ -66,7 +66,7 @@ public class BasicSectionGeometryManager extends AbstractSectionGeometryManager //Invalidate the section id this.invalidatedSectionIds.add(newId); - HierarchicalOcclusionTraverser.HACKY_SECTION_COUNT = this.allocationSet.getCount(); + //HierarchicalOcclusionTraverser.HACKY_SECTION_COUNT = this.allocationSet.getCount(); return newId; } diff --git a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java index eb33262e..f7d263b0 100644 --- a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java +++ b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java @@ -11,17 +11,18 @@ import java.util.function.Supplier; // it is probably better anyway public class ServiceThreadPool { private volatile boolean running = true; - private final Thread[] workers; + private Thread[] workers = new Thread[0]; private final Semaphore jobCounter = new Semaphore(0); private volatile ServiceSlice[] serviceSlices = new ServiceSlice[0]; private final AtomicLong totalJobWeight = new AtomicLong(); private final ThreadGroup threadGroup; - public ServiceThreadPool(int workers) { + public ServiceThreadPool(int threadCount) { 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; var worker = new Thread(this.threadGroup, ()->this.worker(threadId)); worker.setDaemon(false); @@ -215,4 +216,29 @@ public class ServiceThreadPool { public int getThreadCount() { 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; + } + } + */ } diff --git a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java index 71471b3f..31eefa64 100644 --- a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java +++ b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem.java @@ -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 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 y = (i>>10)&0x1F; int z = (i>>5)&0x1F; return Integer.expand(x,0b1001001001001)|Integer.expand(y,0b10010010010010)|Integer.expand(z,0b100100100100100); + + //zyxzyxzyxzyxzyx } public static int z2lin(int i) { diff --git a/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java b/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java index 7e0c3cc1..5b257373 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java +++ b/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java @@ -20,10 +20,19 @@ public class VoxyCommon implements ModInitializer { IS_DEDICATED_SERVER = FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER; Serialization.init(); + } @Override public void onInitialize() { //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; } } diff --git a/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal.comp b/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal.comp index 7f3ed62a..1f4350a2 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal.comp +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal.comp @@ -3,7 +3,8 @@ //TODO: increase local size #define LOCAL_SIZE_BITS 5 #define LOCAL_SIZE_MSK ((1< #line 7 @@ -55,14 +56,6 @@ layout(binding = DEBUG_RENDER_NODE_INDEX, std430) restrict buffer DebugRenderNod }; #endif -/* -layout(binding = 2, std430) restrict buffer QueueData { - uint tail; - uint head; - uint top; - uint[] queue; -} queue; -*/ #import #import