Move things to correct viewport

This commit is contained in:
mcrcortex
2025-05-26 18:08:29 +10:00
parent 28f2e1e881
commit 50e0634a94
6 changed files with 40 additions and 36 deletions

View File

@@ -157,10 +157,10 @@ public class RenderService<T extends AbstractSectionRenderer<J, Q>, J extends Vi
glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT | GL_PIXEL_BUFFER_BARRIER_BIT);
int depthBuffer = glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
if (depthBuffer == 0) {
depthBuffer = glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
}
int depthBuffer = glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
//if (depthBuffer == 0) {
// depthBuffer = glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
//}
TimingStatistics.I.start();
this.traversal.doTraversal(viewport, depthBuffer);
@@ -181,7 +181,7 @@ public class RenderService<T extends AbstractSectionRenderer<J, Q>, J extends Vi
TimingStatistics.H.stop();
TimingStatistics.G.start();
this.sectionRenderer.renderTemporal(depthBoundTexture);
this.sectionRenderer.renderTemporal(viewport, depthBoundTexture);
TimingStatistics.G.stop();
}

View File

@@ -1,12 +1,14 @@
package me.cortex.voxy.client.core.rendering;
import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.client.core.rendering.util.HiZBuffer;
import net.minecraft.util.math.MathHelper;
import org.joml.*;
import java.lang.reflect.Field;
public abstract class Viewport <A extends Viewport<A>> {
public final HiZBuffer hiZBuffer = new HiZBuffer();
private static final Field planesField;
static {
try {
@@ -46,7 +48,9 @@ public abstract class Viewport <A extends Viewport<A>> {
this.delete0();
}
protected abstract void delete0();
protected void delete0() {
this.hiZBuffer.free();
}
public A setProjection(Matrix4f projection) {
this.projection = projection;

View File

@@ -67,7 +67,6 @@ public class HierarchicalOcclusionTraverser {
private static final int RENDER_TRACKER_BINDING = BINDING_COUNTER++;
private static final int STATISTICS_BUFFER_BINDING = BINDING_COUNTER++;
private final HiZBuffer hiZBuffer = new HiZBuffer();
private final int hizSampler = glGenSamplers();
private final AutoBindingShader traversal = Shader.makeAuto(PRINTF_processor)
@@ -199,14 +198,14 @@ public class HierarchicalOcclusionTraverser {
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, this.queueMetaBuffer.id);
//Bind the hiz buffer
glBindTextureUnit(0, this.hiZBuffer.getHizTextureId());
glBindTextureUnit(0, viewport.hiZBuffer.getHizTextureId());
glBindSampler(0, this.hizSampler);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, RENDER_QUEUE_BINDING, viewport.getRenderList().id);
}
public void doTraversal(Viewport<?> viewport, int depthBuffer) {
//Compute the mip chain
this.hiZBuffer.buildMipChain(depthBuffer, viewport.width, viewport.height);
viewport.hiZBuffer.buildMipChain(depthBuffer, viewport.width, viewport.height);
this.uploadUniform(viewport);
//UploadStream.INSTANCE.commit(); //Done inside traversal
@@ -344,7 +343,6 @@ public class HierarchicalOcclusionTraverser {
public void free() {
this.traversal.free();
this.requestBuffer.free();
this.hiZBuffer.free();
this.nodeBuffer.free();
this.uniformBuffer.free();
this.statisticsBuffer.free();

View File

@@ -19,7 +19,7 @@ public abstract class AbstractSectionRenderer <T extends Viewport<T>, J extends
public abstract void renderOpaque(T viewport, GlTexture depthBoundTexture);
public abstract void buildDrawCalls(T viewport);
public abstract void renderTemporal(GlTexture depthBoundTexture);
public abstract void renderTemporal(T viewport, GlTexture depthBoundTexture);
public abstract void renderTranslucent(T viewport, GlTexture depthBoundTexture);
public abstract T createViewport();
public abstract void free();

View File

@@ -84,9 +84,6 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
//TODO: needs to be in the viewport, since it contains the compute indirect call/values
private final GlBuffer distanceCountBuffer = new GlBuffer(1024*4+100_000*4).zero();
private final GlBuffer drawCountCallBuffer = new GlBuffer(1024).zero();
private final GlBuffer drawCallBuffer = new GlBuffer(5*4*(400_000+100_000+100_000)).zero();//400k draw calls
private final GlBuffer positionScratchBuffer = new GlBuffer(8*400000).zero();//400k positions
//Statistics
private final GlBuffer statisticsBuffer = new GlBuffer(1024).zero();
@@ -115,28 +112,28 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
}
private void bindRenderingBuffers(GlTexture depthBoundTexture) {
private void bindRenderingBuffers(MDICViewport viewport, GlTexture depthBoundTexture) {
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniform.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, this.geometryManager.getGeometryBuffer().id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.geometryManager.getMetadataBuffer().id);
this.modelStore.bind(3, 4, 0);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, this.positionScratchBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, viewport.positionScratchBuffer.id);
LightMapHelper.bind(1);
glBindTextureUnit(2, depthBoundTexture.id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE.id());
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, this.drawCallBuffer.id);
glBindBuffer(GL_PARAMETER_BUFFER_ARB, this.drawCountCallBuffer.id);
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, viewport.drawCallBuffer.id);
glBindBuffer(GL_PARAMETER_BUFFER_ARB, viewport.drawCountCallBuffer.id);
}
private void renderTerrain(GlTexture depthBoundTexture, long indirectOffset, long drawCountOffset, int maxDrawCount) {
private void renderTerrain(MDICViewport viewport, GlTexture depthBoundTexture, long indirectOffset, long drawCountOffset, int maxDrawCount) {
//RenderLayer.getCutoutMipped().startDrawing();
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
this.terrainShader.bind();
glBindVertexArray(RenderService.STATIC_VAO);//Needs to be before binding
this.bindRenderingBuffers(depthBoundTexture);
this.bindRenderingBuffers(viewport, depthBoundTexture);
glMemoryBarrier(GL_COMMAND_BARRIER_BIT|GL_SHADER_STORAGE_BARRIER_BIT);//Barrier everything is needed
glMultiDrawElementsIndirectCountARB(GL_TRIANGLES, GL_UNSIGNED_SHORT, indirectOffset, drawCountOffset, maxDrawCount, 0);
@@ -157,7 +154,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
this.uploadUniformBuffer(viewport);
this.renderTerrain(dbt, 0, 4*3, Math.min((int)(this.geometryManager.getSectionCount()*4.4+128), 400_000));
this.renderTerrain(viewport, dbt, 0, 4*3, Math.min((int)(this.geometryManager.getSectionCount()*4.4+128), 400_000));
}
@Override
@@ -170,7 +167,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
glEnable(GL_DEPTH_TEST);
this.terrainShader.bind();
glBindVertexArray(RenderService.STATIC_VAO);//Needs to be before binding
this.bindRenderingBuffers(depthBoundTexture);
this.bindRenderingBuffers(viewport, depthBoundTexture);
glMultiDrawElementsIndirectCountARB(GL_TRIANGLES, GL_UNSIGNED_SHORT, TRANSLUCENT_OFFSET*5*4, 4*4, Math.min(this.geometryManager.getSectionCount(), 100_000), 0);
@@ -195,7 +192,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
{//Dispatch prep
this.prepShader.bind();
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniform.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, this.drawCountCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, viewport.drawCountCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, viewport.getRenderList().id);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glDispatchCompute(1,1,1);
@@ -209,7 +206,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, this.geometryManager.getMetadataBuffer().id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, viewport.visibilityBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, viewport.indirectLookupBuffer.id);
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, this.drawCountCallBuffer.id);
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, viewport.drawCountCallBuffer.id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE.id());
glEnable(GL_DEPTH_TEST);
glColorMask(false, false, false, false);
@@ -226,12 +223,12 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
this.distanceCountBuffer.zeroRange(0, 1024*4);
this.commandGenShader.bind();
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniform.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, this.drawCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.drawCountCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, viewport.drawCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, viewport.drawCountCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.geometryManager.getMetadataBuffer().id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, viewport.visibilityBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, viewport.indirectLookupBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, this.positionScratchBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, viewport.positionScratchBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, this.distanceCountBuffer.id);
if (RenderStatistics.enabled) {
@@ -239,7 +236,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, STATISTICS_BUFFER_BINDING, this.statisticsBuffer.id);
}
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, this.drawCountCallBuffer.id);
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, viewport.drawCountCallBuffer.id);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glDispatchComputeIndirect(0);
glMemoryBarrier(GL_COMMAND_BARRIER_BIT|GL_SHADER_STORAGE_BARRIER_BIT);
@@ -267,13 +264,13 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
this.translucentGenShader.bind();
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniform.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, this.drawCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.drawCountCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, viewport.drawCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, viewport.drawCountCallBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.geometryManager.getMetadataBuffer().id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, viewport.indirectLookupBuffer.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, this.distanceCountBuffer.id);
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, this.drawCountCallBuffer.id);//This isnt great but its a nice trick to bound it, even if its inefficent ;-;
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, viewport.drawCountCallBuffer.id);//This isnt great but its a nice trick to bound it, even if its inefficent ;-;
glMemoryBarrier(GL_COMMAND_BARRIER_BIT|GL_SHADER_STORAGE_BARRIER_BIT|GL_UNIFORM_BARRIER_BIT);
glDispatchComputeIndirect(0);
glMemoryBarrier(GL_COMMAND_BARRIER_BIT|GL_SHADER_STORAGE_BARRIER_BIT);
@@ -282,10 +279,10 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
}
@Override
public void renderTemporal(GlTexture dbt) {
public void renderTemporal(MDICViewport viewport, GlTexture dbt) {
if (this.geometryManager.getSectionCount() == 0) return;
//Render temporal
this.renderTerrain(dbt, TEMPORAL_OFFSET*5*4, 4*5, Math.min(this.geometryManager.getSectionCount(), 100_000));
this.renderTerrain(viewport, dbt, TEMPORAL_OFFSET*5*4, 4*5, Math.min(this.geometryManager.getSectionCount(), 100_000));
}
@Override
@@ -309,9 +306,6 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
this.prepShader.free();
this.translucentGenShader.free();
this.prefixSumShader.free();
this.drawCallBuffer.free();
this.drawCountCallBuffer.free();
this.positionScratchBuffer.free();
this.statisticsBuffer.free();
}
}

View File

@@ -3,8 +3,12 @@ package me.cortex.voxy.client.core.rendering.section;
import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.client.core.rendering.Viewport;
import me.cortex.voxy.client.core.rendering.hierachical.HierarchicalOcclusionTraverser;
import me.cortex.voxy.client.core.rendering.util.HiZBuffer;
public class MDICViewport extends Viewport<MDICViewport> {
public final GlBuffer drawCountCallBuffer = new GlBuffer(1024).zero();
public final GlBuffer drawCallBuffer = new GlBuffer(5*4*(400_000+100_000+100_000)).zero();//400k draw calls
public final GlBuffer positionScratchBuffer = new GlBuffer(8*400000).zero();//400k positions
public final GlBuffer indirectLookupBuffer = new GlBuffer(HierarchicalOcclusionTraverser.MAX_QUEUE_SIZE *4+4);
public final GlBuffer visibilityBuffer;
@@ -14,8 +18,12 @@ public class MDICViewport extends Viewport<MDICViewport> {
@Override
protected void delete0() {
super.delete0();
this.visibilityBuffer.free();
this.indirectLookupBuffer.free();
this.drawCountCallBuffer.free();
this.drawCallBuffer.free();
this.positionScratchBuffer.free();
}
@Override