Tinkering trying to add intel gpu support, however its multidrawindirect does not work correctly, might need to try multidrawindrectcounted

This commit is contained in:
mcrcortex
2024-01-13 17:55:31 +10:00
parent e015632cec
commit 5d2a0e2de8
6 changed files with 55 additions and 25 deletions

View File

@@ -73,17 +73,17 @@ public class VoxelCore {
//Trigger the shared index buffer loading
SharedIndexBuffer.INSTANCE.id();
this.renderer = new Gl46FarWorldRenderer();
this.world = new WorldEngine(new File("storagefile.db"), 5, 20, 5);//"storagefile.db"//"ethoslab.db"
this.world = new WorldEngine(new File("storagefile2.db"), 5, 20, 5);//"storagefile.db"//"ethoslab.db"
this.renderTracker = new RenderTracker(this.world, this.renderer);
this.renderGen = new RenderGenerationService(this.world,10, this.renderTracker::processBuildResult);
this.renderGen = new RenderGenerationService(this.world,5, this.renderTracker::processBuildResult);
this.world.setRenderTracker(this.renderTracker);
this.renderTracker.setRenderGen(this.renderGen);
//To get to chunk scale multiply the scale by 2, the scale is after how many chunks does the lods halve
this.distanceTracker = new DistanceTracker(this.renderTracker, 5, 16);
this.postProcessing = new PostProcessing();
this.postProcessing = null;// = new PostProcessing();
this.world.getMapper().setCallbacks(this::stateUpdate, this::biomeUpdate);

View File

@@ -84,19 +84,34 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
glMemoryBarrier(GL_COMMAND_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT);
this.lodShader.bind();
if (false) {//Bloody intel gpus
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, 1000, 0);
//int count = this.geometry.getSectionCount()/1000;
//for (int i = 0; i < 10; i++) {
// glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, i*1000L*20, 1000, 0);
//}
//int rem = this.geometry.getSectionCount() - (count*1000);
//if (rem != 0) {
// glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, count*1000L*20, rem, 0);
//}
} else {
//TODO: swap to a multidraw indirect counted
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, this.geometry.getSectionCount(), 0);
}
//ARBIndirectParameters.glMultiDrawElementsIndirectCountARB(
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT);
//TODO: add gpu occlusion culling here (after the lod drawing) (maybe, finish the rest of the PoC first)
cullShader.bind();
cullShader.bind();
glColorMask(false, false, false, false);
glDepthMask(false);
glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_BYTE, (1 << 16) * 6 * 2, this.geometry.getSectionCount());
glDepthMask(true);
glColorMask(true, true, true, true);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glBindVertexArray(0);

View File

@@ -328,4 +328,5 @@ public class RenderDataFactory {
this.outData.clear();
return new BuiltSectionGeometry(section.getKey(), output, null);
}
}

View File

@@ -70,5 +70,8 @@ layout(binding = 7, std430) readonly restrict buffer LightingBuffer {
};
vec4 getLighting(uint index) {
return vec4((uvec4(lightData[index])>>uvec4(16,8,0,24))&uvec4(0xFF))*vec4(1f/255.0f);
uvec4 arr = uvec4(lightData[index]);
arr = arr>>uvec4(16,8,0,24);
arr = arr & uvec4(0xFF);
return vec4(arr)*vec4(1.0f/255.0f);
}

View File

@@ -26,6 +26,9 @@ uint encodeLocalLodPos(uint detail, ivec3 pos) {
return (detail<<29)|(detla.x<<20)|(detla.y<<11)|(detla.z<<2);
}
//TODO: swap to a multidraw indirect counted
void main() {
if (gl_GlobalInvocationID.x >= sectionCount) {
return;
@@ -37,16 +40,14 @@ void main() {
vec3 cornerPos = vec3(((ipos<<detail)-baseSectionPos)<<5)-cameraSubPos;
bool shouldRender = testFrustum(frustum, cornerPos, cornerPos+vec3(1<<(detail+5)));
//Check the occlusion data from last frame
if (visibilityData[gl_GlobalInvocationID.x] != frameId - 1) {
shouldRender = false;
}
bool shouldRender = visibilityData[gl_GlobalInvocationID.x] == frameId - 1;
//Clear the occlusion data (not strictly? needed? i think???)
//visibilityData[gl_GlobalInvocationID.x] = 0;
//TODO: need to make it check that only if it was also in the frustum last frame does it apply the visibilityData check!
// this fixes temporal coherance
//This prevents overflow of the relative position encoder
if (shouldRender) {

View File

@@ -33,29 +33,39 @@ uint extractLightId(uint64_t quad) {
#define Quad ivec2
#define Eu32(data, amountBits, shift) (uint((data)>>(shift))&((1u<<(amountBits))-1))
//#define Eu32(data, amountBits, shift) (uint((data)>>(shift))&((1u<<(amountBits))-1))
uint Eu32v(ivec2 data, int amount, int shift) {
if (shift > 31) {
shift -= 32;
return (uint(data.y)>>uint(shift))&((1u<<uint(amount))-1);
} else {
return (uint(data.x)>>uint(shift))&((1u<<uint(amount))-1);
}
}
vec3 extractPos(ivec2 quad) {
return vec3(0);
return vec3(Eu32v(quad, 5, 21), Eu32v(quad, 5, 16), Eu32v(quad, 5, 11));
}
ivec2 extractSize(ivec2 quad) {
return ivec2(0);
return ivec2(Eu32v(quad, 4, 3), Eu32v(quad, 4, 7)) + ivec2(1);//the + 1 is cause you cant actually have a 0 size quad
}
uint extractFace(ivec2 quad) {
return quad.y&7;
return Eu32v(quad, 3, 0);
}
uint extractStateId(ivec2 quad) {
return 0;
//Eu32(quad, 20, 26);
return 1;
}
uint extractBiomeId(ivec2 quad) {
return 0;
return Eu32v(quad, 9, 46);
}
uint extractLightId(ivec2 quad) {
return 0;
return Eu32v(quad, 8, 55);
}
#endif