diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java b/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java index 76c21322..b1b3d2fd 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java @@ -38,7 +38,7 @@ public class ModelBakerySubsystem { public void tick() { //There should be a method to access the frame time IIRC, if the user framecap is unlimited lock it to like 60 fps for computation - int BUDGET = 10;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1) + int BUDGET = 20;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1) for (int i = 0; i < BUDGET && !this.blockIdQueue.isEmpty(); i++) { int blockId = -1; diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/GeometryCache.java b/src/main/java/me/cortex/voxy/client/core/rendering/GeometryCache.java new file mode 100644 index 00000000..97e73e4f --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/core/rendering/GeometryCache.java @@ -0,0 +1,38 @@ +package me.cortex.voxy.client.core.rendering; + +import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; +import me.cortex.voxy.client.core.rendering.building.BuiltSection; + +//CPU side cache for section geometry, not thread safe +public class GeometryCache { + private long maxCombinedSize; + private long currentSize; + private final Long2ObjectLinkedOpenHashMap cache = new Long2ObjectLinkedOpenHashMap<>(); + public GeometryCache(long maxSize) { + this.maxCombinedSize = maxSize; + } + + //Puts the section into the cache + public void put(BuiltSection section) { + var prev = this.cache.put(section.position, section); + this.currentSize += section.geometryBuffer.size; + if (prev != null) { + this.currentSize -= prev.geometryBuffer.size; + prev.free(); + } + + while (this.maxCombinedSize <= this.currentSize) { + var entry = this.cache.removeFirst(); + this.currentSize -= entry.geometryBuffer.size; + entry.free(); + } + } + + public BuiltSection remove(long position) { + var section = this.cache.remove(position); + if (section != null) { + this.currentSize -= section.geometryBuffer.size; + } + return section; + } +} 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 d67044e8..205fb1da 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 @@ -47,7 +47,7 @@ public class RenderService, J extends Vi //Max sections: ~500k //Max geometry: 1 gb - this.sectionRenderer = (T) createSectionRenderer(this.modelService.getStore(),1<<19, (1L<<30)-1024); + this.sectionRenderer = (T) createSectionRenderer(this.modelService.getStore(),1<<19, (1L<<31)-1024); //Do something incredibly hacky, we dont need to keep the reference to this around, so just connect and discard var router = new SectionUpdateRouter(); @@ -69,7 +69,7 @@ public class RenderService, J extends Vi this.sectionUpdateQueue.push(section); }); - this.traversal = new HierarchicalOcclusionTraverser(this.nodeManager, 256); + this.traversal = new HierarchicalOcclusionTraverser(this.nodeManager); world.setDirtyCallback(router::forward); @@ -79,7 +79,7 @@ public class RenderService, J extends Vi //this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(0, 0,0,0)); //this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, 0,0,0)); - /* + final int H_WIDTH = 10; for (int x = -H_WIDTH; x <= H_WIDTH; x++) { for (int y = -1; y <= 0; y++) { @@ -87,7 +87,7 @@ public class RenderService, J extends Vi this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, x, y, z)); } } - }*/ + } } public void setup(Camera camera) { 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 d3694d6a..adb0c1f5 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 @@ -28,9 +28,10 @@ import static org.lwjgl.opengl.GL45.*; // TODO: swap to persistent gpu threads instead of dispatching MAX_ITERATIONS of compute layers public class HierarchicalOcclusionTraverser { + public static final int REQUEST_QUEUE_SIZE = 256; + private final NodeManager2 nodeManager; - private final int maxRequestCount; private final GlBuffer requestBuffer; private final GlBuffer nodeBuffer; @@ -61,7 +62,7 @@ public class HierarchicalOcclusionTraverser { .defineIf("DEBUG", Voxy.SHADER_DEBUG) .define("MAX_ITERATIONS", MAX_ITERATIONS) .define("LOCAL_SIZE_BITS", LOCAL_WORK_SIZE_BITS) - .define("REQUEST_QUEUE_SIZE", NodeManager.REQUEST_QUEUE_SIZE) + .define("REQUEST_QUEUE_SIZE", REQUEST_QUEUE_SIZE) .define("HIZ_BINDING", 0) @@ -79,11 +80,10 @@ public class HierarchicalOcclusionTraverser { .compile(); - public HierarchicalOcclusionTraverser(NodeManager2 nodeManager, int requestBufferCount) { + public HierarchicalOcclusionTraverser(NodeManager2 nodeManager) { this.nodeManager = nodeManager; - this.requestBuffer = new GlBuffer(requestBufferCount*8L+8).zero(); + this.requestBuffer = new GlBuffer(REQUEST_QUEUE_SIZE*8L+8).zero(); this.nodeBuffer = new GlBuffer(nodeManager.maxNodeCount*16L).zero(); - this.maxRequestCount = requestBufferCount; glSamplerParameteri(this.hizSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); @@ -245,8 +245,8 @@ public class HierarchicalOcclusionTraverser { Logger.warn("Count over max buffer size, clamping, got count: " + count); count = (int) ((this.requestBuffer.size()>>3)-1); } - if (count > this.maxRequestCount) { - System.err.println("Count larger than 'maxRequestCount', overflow captured. Overflowed by " + (count-this.maxRequestCount)); + if (count > REQUEST_QUEUE_SIZE) { + System.err.println("Count larger than 'maxRequestCount', overflow captured. Overflowed by " + (count-REQUEST_QUEUE_SIZE)); } if (count != 0) { //this.nodeManager.processRequestQueue(count, ptr + 8); diff --git a/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java b/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java index 7312e2bd..7f0891ea 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java +++ b/src/main/java/me/cortex/voxy/commonImpl/VoxyCommon.java @@ -35,7 +35,7 @@ public class VoxyCommon implements ModInitializer { //This is hardcoded like this because people do not understand what they are doing - private static final boolean GlobalVerificationDisableOverride = false;//System.getProperty("voxy.verificationDisableOverride", "false").equals("true"); + private static final boolean GlobalVerificationDisableOverride = true;//System.getProperty("voxy.verificationDisableOverride", "false").equals("true"); public static boolean isVerificationFlagOn(String name) { return (!GlobalVerificationDisableOverride) && System.getProperty("voxy."+name, "true").equals("true"); } diff --git a/src/main/resources/assets/voxy/shaders/hiz/blit.fsh b/src/main/resources/assets/voxy/shaders/hiz/blit.fsh index 1052ff9e..8c3e5fa7 100644 --- a/src/main/resources/assets/voxy/shaders/hiz/blit.fsh +++ b/src/main/resources/assets/voxy/shaders/hiz/blit.fsh @@ -5,6 +5,9 @@ layout(location = 0) in vec2 uv; layout(binding = 0) uniform sampler2D depthTex; void main() { vec4 depths = textureGather(depthTex, uv, 0); // Get depth values from all surrounding texels. - //depths = mix(vec4(0), depths, lessThanEqual(vec4(0.99999999), depths)); + bvec4 cv = lessThanEqual(vec4(0.99999999), depths); + if (any(cv) && !all(cv)) { + depths = mix(vec4(0), depths, cv); + } gl_FragDepth = max(max(depths.x, depths.y), max(depths.z, depths.w)); // Write conservative depth. -} \ No newline at end of file +} diff --git a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl index ffdf9f91..45c59dd2 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl @@ -21,8 +21,6 @@ vec3 minBB; vec3 maxBB; vec2 size; -uint lod; - //Sets up screenspace with the given node id, returns true on success false on failure/should not continue //Accesses data that is setup in the main traversal and is just shared to here void setupScreenspace(in UnpackedNode node) { @@ -35,7 +33,6 @@ void setupScreenspace(in UnpackedNode node) { vec3 point = VP*(((transform.transform*vec4((node.pos<