mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 06:57:02 +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.
|
||||
*/
|
||||
public void bindForCrumbling() {
|
||||
multiBind(3, 3);
|
||||
multiBind(1, 4);
|
||||
}
|
||||
|
||||
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 + 8, mesh.firstIndex()); // firstIndex
|
||||
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
|
||||
|
||||
|
|
|
@ -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.engine.CommonCrumbling;
|
||||
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.LightStorage;
|
||||
import dev.engine_room.flywheel.backend.engine.MaterialRenderState;
|
||||
|
@ -204,15 +205,21 @@ public class IndirectDrawManager extends DrawManager<IndirectInstancer<?>> {
|
|||
// Scratch memory for writing draw commands.
|
||||
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());
|
||||
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BufferBindings.DRAW, crumblingDrawBuffer.handle(), 0, IndirectBuffers.DRAW_COMMAND_STRIDE);
|
||||
|
||||
for (var groupEntry : byType.entrySet()) {
|
||||
var byProgress = groupEntry.getValue();
|
||||
|
||||
// Set up the crumbling program buffers. Nothing changes here between draws.
|
||||
cullingGroups.get(groupEntry.getKey())
|
||||
.bindWithContextShader(ContextShader.CRUMBLING);
|
||||
GroupKey<?> groupKey = groupEntry.getKey();
|
||||
IndirectCullingGroup<?> cullingGroup = cullingGroups.get(groupKey.instanceType());
|
||||
|
||||
if (cullingGroup == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cullingGroup.bindWithContextShader(ContextShader.CRUMBLING);
|
||||
|
||||
for (var progressEntry : byProgress.int2ObjectEntrySet()) {
|
||||
Samplers.CRUMBLING.makeActive();
|
||||
|
|
|
@ -144,4 +144,8 @@ public class IndirectInstancer<I extends Instance> extends AbstractInstancer<I>
|
|||
public int 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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
void main() {
|
||||
#if __VERSION__ < 460
|
||||
uint drawIndex = gl_DrawIDARB + _flw_baseDraw;
|
||||
#define flw_baseInstance gl_BaseInstanceARB
|
||||
#define flw_drawId gl_DrawIDARB
|
||||
#else
|
||||
uint drawIndex = gl_DrawID + _flw_baseDraw;
|
||||
#define flw_baseInstance gl_BaseInstance
|
||||
#define flw_drawId gl_DrawID
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
uint drawIndex = flw_drawId + _flw_baseDraw;
|
||||
MeshDrawCommand draw = _flw_drawCommands[drawIndex];
|
||||
|
||||
_flw_uberMaterialVertexIndex = draw.materialVertexIndex;
|
||||
|
@ -42,11 +46,12 @@ void main() {
|
|||
// _flw_normalMatrix = mat3(1.);
|
||||
#endif
|
||||
|
||||
#if __VERSION__ < 460
|
||||
uint instanceIndex = _flw_instanceIndices[gl_BaseInstanceARB + gl_InstanceID];
|
||||
#else
|
||||
uint instanceIndex = _flw_instanceIndices[gl_BaseInstance + gl_InstanceID];
|
||||
#endif
|
||||
#ifdef _FLW_CRUMBLING
|
||||
uint instanceIndex = flw_baseInstance;
|
||||
#else
|
||||
uint instanceIndex = _flw_instanceIndices[flw_baseInstance + gl_InstanceID];
|
||||
#endif
|
||||
|
||||
FlwInstance instance = _flw_unpackInstance(instanceIndex);
|
||||
|
||||
_flw_main(instance, instanceIndex);
|
||||
|
|
Loading…
Reference in a new issue