mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 15:06:28 +01:00
Crumbling grumbling
- Fix crumbling on indirect - Directly use the baseInstance as instance index without indirection - #define base instance and draw id variables to simplify usage - Fix null pointer looking up culling group - Add method to map an instancer's local instance index to a global index in the page file
This commit is contained in:
parent
b7b7cca992
commit
cb58f6075e
6 changed files with 33 additions and 13 deletions
|
@ -113,7 +113,7 @@ public class IndirectBuffers {
|
||||||
* Bind all buffers except the draw command buffer.
|
* Bind all buffers except the draw command buffer.
|
||||||
*/
|
*/
|
||||||
public void bindForCrumbling() {
|
public void bindForCrumbling() {
|
||||||
multiBind(3, 3);
|
multiBind(1, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void multiBind(int base, int count) {
|
private void multiBind(int base, int count) {
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class IndirectDraw {
|
||||||
MemoryUtil.memPutInt(ptr + 4, 1); // instanceCount - only drawing one instance
|
MemoryUtil.memPutInt(ptr + 4, 1); // instanceCount - only drawing one instance
|
||||||
MemoryUtil.memPutInt(ptr + 8, mesh.firstIndex()); // firstIndex
|
MemoryUtil.memPutInt(ptr + 8, mesh.firstIndex()); // firstIndex
|
||||||
MemoryUtil.memPutInt(ptr + 12, mesh.baseVertex()); // baseVertex
|
MemoryUtil.memPutInt(ptr + 12, mesh.baseVertex()); // baseVertex
|
||||||
MemoryUtil.memPutInt(ptr + 16, instancer.baseInstance() + instanceIndex); // baseInstance
|
MemoryUtil.memPutInt(ptr + 16, instancer.local2GlobalInstanceIndex(instanceIndex)); // baseInstance
|
||||||
|
|
||||||
MemoryUtil.memPutInt(ptr + 20, instancer.modelIndex()); // modelIndex
|
MemoryUtil.memPutInt(ptr + 20, instancer.modelIndex()); // modelIndex
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import dev.engine_room.flywheel.backend.compile.ContextShader;
|
||||||
import dev.engine_room.flywheel.backend.compile.IndirectPrograms;
|
import dev.engine_room.flywheel.backend.compile.IndirectPrograms;
|
||||||
import dev.engine_room.flywheel.backend.engine.CommonCrumbling;
|
import dev.engine_room.flywheel.backend.engine.CommonCrumbling;
|
||||||
import dev.engine_room.flywheel.backend.engine.DrawManager;
|
import dev.engine_room.flywheel.backend.engine.DrawManager;
|
||||||
|
import dev.engine_room.flywheel.backend.engine.GroupKey;
|
||||||
import dev.engine_room.flywheel.backend.engine.InstancerKey;
|
import dev.engine_room.flywheel.backend.engine.InstancerKey;
|
||||||
import dev.engine_room.flywheel.backend.engine.LightStorage;
|
import dev.engine_room.flywheel.backend.engine.LightStorage;
|
||||||
import dev.engine_room.flywheel.backend.engine.MaterialRenderState;
|
import dev.engine_room.flywheel.backend.engine.MaterialRenderState;
|
||||||
|
@ -204,15 +205,21 @@ public class IndirectDrawManager extends DrawManager<IndirectInstancer<?>> {
|
||||||
// Scratch memory for writing draw commands.
|
// Scratch memory for writing draw commands.
|
||||||
var block = MemoryBlock.malloc(IndirectBuffers.DRAW_COMMAND_STRIDE);
|
var block = MemoryBlock.malloc(IndirectBuffers.DRAW_COMMAND_STRIDE);
|
||||||
|
|
||||||
|
// Set up the crumbling program buffers. Nothing changes here between draws.
|
||||||
GlBufferType.DRAW_INDIRECT_BUFFER.bind(crumblingDrawBuffer.handle());
|
GlBufferType.DRAW_INDIRECT_BUFFER.bind(crumblingDrawBuffer.handle());
|
||||||
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BufferBindings.DRAW, crumblingDrawBuffer.handle(), 0, IndirectBuffers.DRAW_COMMAND_STRIDE);
|
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BufferBindings.DRAW, crumblingDrawBuffer.handle(), 0, IndirectBuffers.DRAW_COMMAND_STRIDE);
|
||||||
|
|
||||||
for (var groupEntry : byType.entrySet()) {
|
for (var groupEntry : byType.entrySet()) {
|
||||||
var byProgress = groupEntry.getValue();
|
var byProgress = groupEntry.getValue();
|
||||||
|
|
||||||
// Set up the crumbling program buffers. Nothing changes here between draws.
|
GroupKey<?> groupKey = groupEntry.getKey();
|
||||||
cullingGroups.get(groupEntry.getKey())
|
IndirectCullingGroup<?> cullingGroup = cullingGroups.get(groupKey.instanceType());
|
||||||
.bindWithContextShader(ContextShader.CRUMBLING);
|
|
||||||
|
if (cullingGroup == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
cullingGroup.bindWithContextShader(ContextShader.CRUMBLING);
|
||||||
|
|
||||||
for (var progressEntry : byProgress.int2ObjectEntrySet()) {
|
for (var progressEntry : byProgress.int2ObjectEntrySet()) {
|
||||||
Samplers.CRUMBLING.makeActive();
|
Samplers.CRUMBLING.makeActive();
|
||||||
|
|
|
@ -144,4 +144,8 @@ public class IndirectInstancer<I extends Instance> extends AbstractInstancer<I>
|
||||||
public int baseInstance() {
|
public int baseInstance() {
|
||||||
return baseInstance;
|
return baseInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int local2GlobalInstanceIndex(int instanceIndex) {
|
||||||
|
return mapping.objectIndex2GlobalIndex(instanceIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,5 +216,9 @@ public class ObjectStorage extends AbstractArena {
|
||||||
|
|
||||||
pages = Arrays.copyOf(pages, neededPages);
|
pages = Arrays.copyOf(pages, neededPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int objectIndex2GlobalIndex(int objectIndex) {
|
||||||
|
return (pages[objectIndex2PageIndex(objectIndex)] << LOG_2_PAGE_SIZE) + (objectIndex & PAGE_MASK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,16 @@ uniform uint _flw_baseDraw;
|
||||||
|
|
||||||
flat out uvec3 _flw_packedMaterial;
|
flat out uvec3 _flw_packedMaterial;
|
||||||
|
|
||||||
void main() {
|
|
||||||
#if __VERSION__ < 460
|
#if __VERSION__ < 460
|
||||||
uint drawIndex = gl_DrawIDARB + _flw_baseDraw;
|
#define flw_baseInstance gl_BaseInstanceARB
|
||||||
|
#define flw_drawId gl_DrawIDARB
|
||||||
#else
|
#else
|
||||||
uint drawIndex = gl_DrawID + _flw_baseDraw;
|
#define flw_baseInstance gl_BaseInstance
|
||||||
|
#define flw_drawId gl_DrawID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uint drawIndex = flw_drawId + _flw_baseDraw;
|
||||||
MeshDrawCommand draw = _flw_drawCommands[drawIndex];
|
MeshDrawCommand draw = _flw_drawCommands[drawIndex];
|
||||||
|
|
||||||
_flw_uberMaterialVertexIndex = draw.materialVertexIndex;
|
_flw_uberMaterialVertexIndex = draw.materialVertexIndex;
|
||||||
|
@ -42,11 +46,12 @@ void main() {
|
||||||
// _flw_normalMatrix = mat3(1.);
|
// _flw_normalMatrix = mat3(1.);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __VERSION__ < 460
|
#ifdef _FLW_CRUMBLING
|
||||||
uint instanceIndex = _flw_instanceIndices[gl_BaseInstanceARB + gl_InstanceID];
|
uint instanceIndex = flw_baseInstance;
|
||||||
#else
|
#else
|
||||||
uint instanceIndex = _flw_instanceIndices[gl_BaseInstance + gl_InstanceID];
|
uint instanceIndex = _flw_instanceIndices[flw_baseInstance + gl_InstanceID];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FlwInstance instance = _flw_unpackInstance(instanceIndex);
|
FlwInstance instance = _flw_unpackInstance(instanceIndex);
|
||||||
|
|
||||||
_flw_main(instance, instanceIndex);
|
_flw_main(instance, instanceIndex);
|
||||||
|
|
Loading…
Reference in a new issue