Jarvis, Optimise my shit

This commit is contained in:
Halbear 2026-09-25 23:37:22 +01:00
parent d1abde919d
commit 9424b29d0a
50 changed files with 1469 additions and 1232 deletions

View file

@ -3,10 +3,10 @@
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
const int CHUNK_SIZE = 16;
const int CHUNK_AREA = CHUNK_SIZE * CHUNK_SIZE;
const int VOXEL_COUNT = CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE;
const int SCRATCH_SIZE = CHUNK_SIZE + 2;
const int SCRATCH_AREA = SCRATCH_SIZE * SCRATCH_SIZE;
const int SCRATCH_VOXEL_COUNT = SCRATCH_SIZE * SCRATCH_SIZE * SCRATCH_SIZE;
const uint VERTICES_PER_FACE = 6u;
const uint MAX_VISIBLE_FACES_PER_CHUNK = uint(CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE * 6);
layout(std430, binding = 0) readonly buffer VoxelData {
@ -17,19 +17,8 @@ layout(std430, binding = 1) buffer FaceBuffer {
uint faces[];
};
struct DrawCommand {
uint vertexCount;
uint instanceCount;
uint firstVertex;
uint firstInstance;
};
layout(std430, binding = 2) buffer DrawCommands {
DrawCommand drawCmds[];
};
layout(std430, binding = 3) buffer Counters {
uint faceCount;
layout(std430, binding = 2) buffer Counters {
uint faceCount[];
} counters;
struct Voxel {
@ -52,23 +41,23 @@ layout(push_constant) uniform ChunkInfo {
int slot;
uint faceOffset;
uint voxelTypeCount;
uint indirectCommandIndex;
uint biomeCount;
uint structureCount;
uint worldSeed;
};
uint flatten(ivec3 pos) {
return uint((pos.x * CHUNK_AREA) + (pos.y * CHUNK_SIZE) + pos.z);
pos += ivec3(1);
return uint(slot * SCRATCH_VOXEL_COUNT + pos.x * SCRATCH_AREA + pos.y * SCRATCH_SIZE + pos.z);
}
bool isSeeThrough(Voxel voxel, uint type) {
if (type == 0u || voxel.BlockType == 3u || type > voxelTypeCount) return true;
return voxelReg.materials[type - 1u].BlockType >= 1u;
}
uint getVoxel(ivec3 pos) {
if (pos.x < 0 || pos.x >= CHUNK_SIZE) return 0u;
if (pos.y < 0 || pos.y >= CHUNK_SIZE) return 0u;
if (pos.z < 0 || pos.z >= CHUNK_SIZE) return 0u;
if (pos.x < -1 || pos.x > CHUNK_SIZE) return 0u;
if (pos.y < -1 || pos.y > CHUNK_SIZE) return 0u;
if (pos.z < -1 || pos.z > CHUNK_SIZE) return 0u;
return voxels[flatten(pos)];
}
@ -175,7 +164,7 @@ void emitFace(ivec3 voxelPos, uint faceIndex, uint voxelType) {
return;
}
uint localFace = atomicAdd(counters.faceCount, 1u);
uint localFace = atomicAdd(counters.faceCount[slot], 1u);
if (localFace >= MAX_VISIBLE_FACES_PER_CHUNK) {
return;
@ -183,8 +172,6 @@ void emitFace(ivec3 voxelPos, uint faceIndex, uint voxelType) {
Voxel voxel = voxelReg.materials[voxelType - 1u];
faces[faceOffset + localFace] = packFace(uvec3(voxelPos), faceIndex, voxel);
atomicAdd(drawCmds[indirectCommandIndex].vertexCount, VERTICES_PER_FACE);
}
void main() {