Tinkering trying to add intel gpu support, however its multidrawindirect does not work correctly, might need to try multidrawindrectcounted
This commit is contained in:
@@ -73,17 +73,17 @@ public class VoxelCore {
|
|||||||
//Trigger the shared index buffer loading
|
//Trigger the shared index buffer loading
|
||||||
SharedIndexBuffer.INSTANCE.id();
|
SharedIndexBuffer.INSTANCE.id();
|
||||||
this.renderer = new Gl46FarWorldRenderer();
|
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.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.world.setRenderTracker(this.renderTracker);
|
||||||
this.renderTracker.setRenderGen(this.renderGen);
|
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
|
//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.distanceTracker = new DistanceTracker(this.renderTracker, 5, 16);
|
||||||
|
|
||||||
this.postProcessing = new PostProcessing();
|
this.postProcessing = null;// = new PostProcessing();
|
||||||
|
|
||||||
this.world.getMapper().setCallbacks(this::stateUpdate, this::biomeUpdate);
|
this.world.getMapper().setCallbacks(this::stateUpdate, this::biomeUpdate);
|
||||||
|
|
||||||
|
|||||||
@@ -84,19 +84,34 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
|
|||||||
glMemoryBarrier(GL_COMMAND_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT);
|
glMemoryBarrier(GL_COMMAND_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT);
|
||||||
|
|
||||||
this.lodShader.bind();
|
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);
|
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, 0, this.geometry.getSectionCount(), 0);
|
||||||
|
}
|
||||||
//ARBIndirectParameters.glMultiDrawElementsIndirectCountARB(
|
//ARBIndirectParameters.glMultiDrawElementsIndirectCountARB(
|
||||||
|
|
||||||
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT);
|
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)
|
//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);
|
glColorMask(false, false, false, false);
|
||||||
glDepthMask(false);
|
glDepthMask(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 << 16) * 6 * 2, this.geometry.getSectionCount());
|
||||||
glDepthMask(true);
|
glDepthMask(true);
|
||||||
glColorMask(true, true, true, true);
|
glColorMask(true, true, true, true);
|
||||||
|
|
||||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
|
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|||||||
@@ -328,4 +328,5 @@ public class RenderDataFactory {
|
|||||||
this.outData.clear();
|
this.outData.clear();
|
||||||
return new BuiltSectionGeometry(section.getKey(), output, null);
|
return new BuiltSectionGeometry(section.getKey(), output, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,5 +70,8 @@ layout(binding = 7, std430) readonly restrict buffer LightingBuffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vec4 getLighting(uint index) {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ uint encodeLocalLodPos(uint detail, ivec3 pos) {
|
|||||||
return (detail<<29)|(detla.x<<20)|(detla.y<<11)|(detla.z<<2);
|
return (detail<<29)|(detla.x<<20)|(detla.y<<11)|(detla.z<<2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: swap to a multidraw indirect counted
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
if (gl_GlobalInvocationID.x >= sectionCount) {
|
if (gl_GlobalInvocationID.x >= sectionCount) {
|
||||||
return;
|
return;
|
||||||
@@ -37,16 +40,14 @@ void main() {
|
|||||||
vec3 cornerPos = vec3(((ipos<<detail)-baseSectionPos)<<5)-cameraSubPos;
|
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
|
//Check the occlusion data from last frame
|
||||||
if (visibilityData[gl_GlobalInvocationID.x] != frameId - 1) {
|
bool shouldRender = visibilityData[gl_GlobalInvocationID.x] == frameId - 1;
|
||||||
shouldRender = false;
|
|
||||||
}
|
|
||||||
//Clear the occlusion data (not strictly? needed? i think???)
|
//Clear the occlusion data (not strictly? needed? i think???)
|
||||||
//visibilityData[gl_GlobalInvocationID.x] = 0;
|
//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!
|
//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
|
//This prevents overflow of the relative position encoder
|
||||||
if (shouldRender) {
|
if (shouldRender) {
|
||||||
|
|||||||
@@ -33,29 +33,39 @@ uint extractLightId(uint64_t quad) {
|
|||||||
|
|
||||||
#define Quad ivec2
|
#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) {
|
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) {
|
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) {
|
uint extractFace(ivec2 quad) {
|
||||||
return quad.y&7;
|
return Eu32v(quad, 3, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint extractStateId(ivec2 quad) {
|
uint extractStateId(ivec2 quad) {
|
||||||
return 0;
|
//Eu32(quad, 20, 26);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint extractBiomeId(ivec2 quad) {
|
uint extractBiomeId(ivec2 quad) {
|
||||||
return 0;
|
return Eu32v(quad, 9, 46);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint extractLightId(ivec2 quad) {
|
uint extractLightId(ivec2 quad) {
|
||||||
return 0;
|
return Eu32v(quad, 8, 55);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user