made it 62 quad in size

This commit is contained in:
mcrcortex
2024-04-14 04:05:07 +10:00
parent 2b8efbfb8f
commit cce96fc867
6 changed files with 55 additions and 22 deletions

View File

@@ -58,7 +58,7 @@ public class Gl46MeshletsFarWorldRenderer extends AbstractFarWorldRenderer<Gl46M
private final GlBuffer meshletBuffer;
public Gl46MeshletsFarWorldRenderer(int geometrySize, int maxSections) {
super(new DefaultGeometryManager(alignUp(geometrySize*8L, 8*128), maxSections, 8*128));
super(new DefaultGeometryManager(alignUp(geometrySize*8L, 8*64), maxSections, 8*64));
this.glDrawIndirect = new GlBuffer(4*5);
this.meshletBuffer = new GlBuffer(4*1000000);//TODO: Make max meshlet count configurable, not just 1 million (even tho thats a max of 126 million quads per frame)
}
@@ -74,7 +74,7 @@ public class Gl46MeshletsFarWorldRenderer extends AbstractFarWorldRenderer<Gl46M
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, this.models.getColourBufferId());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, this.lightDataBuffer.id);//Lighting LUT
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bindToDrawIndirect?this.glDrawIndirect.id:0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE.id());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BYTE.id());
//Bind the texture atlas
glBindSampler(0, this.models.getSamplerId());
@@ -132,8 +132,7 @@ public class Gl46MeshletsFarWorldRenderer extends AbstractFarWorldRenderer<Gl46M
this.lodShader.bind();
this.bindResources(viewport, true);
glDisable(GL_CULL_FACE);
//glDrawElementsInstanced(GL_TRIANGLES, 6*126, GL_UNSIGNED_SHORT, 0, 40000);
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0);
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_BYTE, 0);
glEnable(GL_CULL_FACE);
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT);
@@ -142,7 +141,7 @@ public class Gl46MeshletsFarWorldRenderer extends AbstractFarWorldRenderer<Gl46M
this.bindResources(viewport, false);
glDepthMask(false);
glColorMask(false, false, false, false);
glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_BYTE, (1 << 16) * 6 * 2, this.geometry.getSectionCount());
glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_BYTE, (1 << 8) * 6, this.geometry.getSectionCount());
glColorMask(true, true, true, true);
glDepthMask(true);

View File

@@ -10,6 +10,7 @@ import org.lwjgl.system.MemoryUtil;
//Has a base index buffer of 16380 quads, and also a 1 cube byte index buffer at the end
public class SharedIndexBuffer {
public static final SharedIndexBuffer INSTANCE = new SharedIndexBuffer();
public static final SharedIndexBuffer INSTANCE_BYTE = new SharedIndexBuffer(true);
private final GlBuffer indexBuffer;
@@ -26,6 +27,19 @@ public class SharedIndexBuffer {
cubeBuff.free();
}
private SharedIndexBuffer(boolean type2) {
this.indexBuffer = new GlBuffer((1<<8)*6 + 6*2*3);
var quadIndexBuff = IndexUtil.generateQuadIndicesByte(63);
var cubeBuff = generateCubeIndexBuffer();
long ptr = UploadStream.INSTANCE.upload(this.indexBuffer, 0, this.indexBuffer.size());
quadIndexBuff.cpyTo(ptr);
cubeBuff.cpyTo((1<<8)*6 + ptr);
quadIndexBuff.free();
cubeBuff.free();
}
private static MemoryBuffer generateCubeIndexBuffer() {
var buffer = new MemoryBuffer(6*2*3);
long ptr = buffer.address;

View File

@@ -53,6 +53,7 @@ public class RenderDataFactory {
// can do funny stuff like double rendering
private static final boolean USE_UINT64 = false;//FIXME: replace with automatic detection of uint64 shader extension support
private static final int QUADS_PER_MESHLET = 62;
private static void writePos(long ptr, long pos) {
if (USE_UINT64) {
MemoryUtil.memPutLong(ptr, pos);
@@ -88,10 +89,10 @@ public class RenderDataFactory {
int bufferSize;
if (this.generateMeshlets) {
bufferSize = getMeshletHoldingCount(this.doubleSidedQuadCollector.size(), 126, 128) +
getMeshletHoldingCount(this.translucentQuadCollector.size(), 126, 128);
bufferSize = getMeshletHoldingCount(this.doubleSidedQuadCollector.size(), QUADS_PER_MESHLET, QUADS_PER_MESHLET+2) +
getMeshletHoldingCount(this.translucentQuadCollector.size(), QUADS_PER_MESHLET, QUADS_PER_MESHLET+2);
for (var collector : this.directionalQuadCollectors) {
bufferSize += getMeshletHoldingCount(collector.size(), 126, 128);
bufferSize += getMeshletHoldingCount(collector.size(), QUADS_PER_MESHLET, QUADS_PER_MESHLET+2);
}
} else {
bufferSize = this.doubleSidedQuadCollector.size() + this.translucentQuadCollector.size();
@@ -122,11 +123,11 @@ public class RenderDataFactory {
//Write out meshlet header
//Write out the section position
writePos(ptr + meshlet * 8L * 128L, key);
MemoryUtil.memPutLong(ptr + meshlet * 8L * 128L + 8, 0);
writePos(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2), key);
MemoryUtil.memPutLong(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2) + 8, 0);
}
MemoryUtil.memPutLong(ptr + meshlet * 8L * 128 + (2 + innerQuadCount++) * 8L, data);
if (innerQuadCount == 126) {
MemoryUtil.memPutLong(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2) + (2 + innerQuadCount++) * 8L, data);
if (innerQuadCount == QUADS_PER_MESHLET) {
innerQuadCount = 0;
meshlet++;
}
@@ -143,11 +144,11 @@ public class RenderDataFactory {
//Write out meshlet header
//Write out the section position
writePos(ptr + meshlet * 8L * 128L, key);
MemoryUtil.memPutLong(ptr + meshlet * 8L * 128L + 8, 0);
writePos(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2), key);
MemoryUtil.memPutLong(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2) + 8, 0);
}
MemoryUtil.memPutLong(ptr + meshlet * 8L * 128 + (2 + innerQuadCount++) * 8L, data);
if (innerQuadCount == 126) {
MemoryUtil.memPutLong(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2) + (2 + innerQuadCount++) * 8L, data);
if (innerQuadCount == QUADS_PER_MESHLET) {
innerQuadCount = 0;
meshlet++;
}
@@ -165,11 +166,11 @@ public class RenderDataFactory {
//Write out meshlet header
//Write out the section position
writePos(ptr + meshlet * 8L * 128L, key);
MemoryUtil.memPutLong(ptr + meshlet * 8L * 128L + 8, 0);
writePos(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2), key);
MemoryUtil.memPutLong(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2) + 8, 0);
}
MemoryUtil.memPutLong(ptr + meshlet * 8L * 128 + (2 + innerQuadCount++) * 8L, data);
if (innerQuadCount == 126) {
MemoryUtil.memPutLong(ptr + meshlet * 8L * (QUADS_PER_MESHLET+2) + (2 + innerQuadCount++) * 8L, data);
if (innerQuadCount == QUADS_PER_MESHLET) {
innerQuadCount = 0;
meshlet++;
}

View File

@@ -4,6 +4,25 @@ import me.cortex.voxy.common.util.MemoryBuffer;
import org.lwjgl.system.MemoryUtil;
public class IndexUtil {
public static MemoryBuffer generateQuadIndicesByte(int quadCount) {
if ((quadCount*4) >= 1<<8) {
throw new IllegalArgumentException("Quad count to large");
}
MemoryBuffer buffer = new MemoryBuffer(quadCount * 6L);
long ptr = buffer.address;
for(int i = 0; i < quadCount*4; i += 4) {
MemoryUtil.memPutByte(ptr + (0), (byte) i);
MemoryUtil.memPutByte(ptr + (1), (byte) (i + 1));
MemoryUtil.memPutByte(ptr + (2), (byte) (i + 2));
MemoryUtil.memPutByte(ptr + (3), (byte) (i + 1));
MemoryUtil.memPutByte(ptr + (4), (byte) (i + 3));
MemoryUtil.memPutByte(ptr + (5), (byte) (i + 2));
ptr += 6;
}
return buffer;
}
public static MemoryBuffer generateQuadIndicesShort(int quadCount) {
if ((quadCount*4) >= 1<<16) {
throw new IllegalArgumentException("Quad count to large");

View File

@@ -7,7 +7,7 @@
#import <voxy:lod/section.glsl>
#define extractMeshletStart extractQuadStart
layout(local_size_x = 64) in;
#define QUADS_PER_MESHLET 126
#define QUADS_PER_MESHLET 62
void emitMeshlets(inout uint mli, inout uint meshletPtr, uint mskedCnt, uint cnt) {
for (;mskedCnt != 0; mskedCnt--,mli++) {

View File

@@ -1,8 +1,8 @@
#version 450
#extension GL_ARB_gpu_shader_int64 : enable
#define QUADS_PER_MESHLET 62
#define MESHLET_ACCESS readonly
#define QUADS_PER_MESHLET 126
//There are 16 bytes of metadata at the start of the meshlet
#define MESHLET_SIZE (QUADS_PER_MESHLET+2)
#import <voxy:lod/quad_format.glsl>