Get started on a batching engine

- An Engine is a MaterialManager and a RenderDispatcher
 - Refactor InstanceManager's ctor to use the MaterialManager interface instead of the concrete type
 - MaterialManagerImpl -> InstancingEngine
 - Add skeleton for BatchingEngine
 - Hack in InstanceWorld to switch between the 2
 - Rename/move existing MaterialManager impl to new package
This commit is contained in:
Jozufozu 2021-12-06 23:36:15 -08:00
parent 3de903ac2a
commit 5ae4e49787
8 changed files with 48 additions and 15 deletions

View file

@ -2,11 +2,14 @@ package com.simibubi.create.content.contraptions.base.flwdata;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.struct.Batched;
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.backend.struct.Writeable;
import com.jozufozu.flywheel.core.model.IModel;
import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllInstanceFormats;
public class BeltType implements Writeable<BeltData> { public class BeltType implements Writeable<BeltData>, Batched<BeltData> {
@Override @Override
public BeltData create() { public BeltData create() {
return new BeltData(); return new BeltData();
@ -21,4 +24,9 @@ public class BeltType implements Writeable<BeltData> {
public StructWriter<BeltData> getWriter(VecBuffer backing) { public StructWriter<BeltData> getWriter(VecBuffer backing) {
return new UnsafeBeltWriter(backing, this); return new UnsafeBeltWriter(backing, this);
} }
@Override
public BatchingTransformer<BeltData> getTransformer(IModel model) {
return null;
}
} }

View file

@ -2,11 +2,14 @@ package com.simibubi.create.content.contraptions.base.flwdata;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.struct.Batched;
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.backend.struct.Writeable;
import com.jozufozu.flywheel.core.model.IModel;
import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllInstanceFormats;
public class RotatingType implements Writeable<RotatingData> { public class RotatingType implements Writeable<RotatingData>, Batched<RotatingData> {
@Override @Override
public RotatingData create() { public RotatingData create() {
return new RotatingData(); return new RotatingData();
@ -21,4 +24,9 @@ public class RotatingType implements Writeable<RotatingData> {
public StructWriter<RotatingData> getWriter(VecBuffer backing) { public StructWriter<RotatingData> getWriter(VecBuffer backing) {
return new UnsafeRotatingWriter(backing, this); return new UnsafeRotatingWriter(backing, this);
} }
@Override
public BatchingTransformer<RotatingData> getTransformer(IModel model) {
return null;
}
} }

View file

@ -2,11 +2,14 @@ package com.simibubi.create.content.contraptions.components.actors.flwdata;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.struct.Batched;
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.backend.struct.Writeable;
import com.jozufozu.flywheel.core.model.IModel;
import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllInstanceFormats;
public class ActorType implements Writeable<ActorData> { public class ActorType implements Writeable<ActorData>, Batched<ActorData> {
@Override @Override
public ActorData create() { public ActorData create() {
return new ActorData(); return new ActorData();
@ -21,4 +24,9 @@ public class ActorType implements Writeable<ActorData> {
public StructWriter<ActorData> getWriter(VecBuffer backing) { public StructWriter<ActorData> getWriter(VecBuffer backing) {
return new UnsafeActorWriter(backing, this); return new UnsafeActorWriter(backing, this);
} }
@Override
public BatchingTransformer<ActorData> getTransformer(IModel model) {
return null;
}
} }

View file

@ -1,13 +1,13 @@
package com.simibubi.create.content.contraptions.components.structureMovement.render; package com.simibubi.create.content.contraptions.components.structureMovement.render;
import com.jozufozu.flywheel.backend.material.MaterialGroupImpl; import com.jozufozu.flywheel.backend.material.instancing.InstancedMaterialGroup;
import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
public class ContraptionGroup<P extends ContraptionProgram> extends MaterialGroupImpl<P> { public class ContraptionGroup<P extends ContraptionProgram> extends InstancedMaterialGroup<P> {
private final RenderedContraption contraption; private final RenderedContraption contraption;
public ContraptionGroup(RenderedContraption contraption, MaterialManagerImpl<P> owner) { public ContraptionGroup(RenderedContraption contraption, InstancingEngine<P> owner) {
super(owner); super(owner);
this.contraption = contraption; this.contraption = contraption;
@ -18,7 +18,7 @@ public class ContraptionGroup<P extends ContraptionProgram> extends MaterialGrou
contraption.setup(program); contraption.setup(program);
} }
public static <P extends ContraptionProgram> MaterialManagerImpl.GroupFactory<P> forContraption(RenderedContraption c) { public static <P extends ContraptionProgram> InstancingEngine.GroupFactory<P> forContraption(RenderedContraption c) {
return (materialManager) -> new ContraptionGroup<>(c, materialManager); return (materialManager) -> new ContraptionGroup<>(c, materialManager);
} }
} }

View file

@ -8,7 +8,7 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.backend.material.MaterialManager;
import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.AllMovementBehaviours;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
@ -23,7 +23,7 @@ public class ContraptionInstanceManager extends TileInstanceManager {
private final WeakReference<RenderedContraption> contraption; private final WeakReference<RenderedContraption> contraption;
ContraptionInstanceManager(RenderedContraption contraption, MaterialManagerImpl<?> materialManager) { ContraptionInstanceManager(RenderedContraption contraption, MaterialManager materialManager) {
super(materialManager); super(materialManager);
this.contraption = new WeakReference<>(contraption); this.contraption = new WeakReference<>(contraption);
} }

View file

@ -59,7 +59,7 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
RenderLayer renderLayer = event.getLayer(); RenderLayer renderLayer = event.getLayer();
if (renderLayer != null) { if (renderLayer != null) {
for (RenderedContraption renderer : visible) { for (RenderedContraption renderer : visible) {
renderer.materialManager.render(renderLayer, event.viewProjection, event.camX, event.camY, event.camZ); renderer.materialManager.render(event, event.buffers.bufferSource());
} }
} }
} }

View file

@ -8,7 +8,7 @@ import java.util.function.Supplier;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.backend.material.instancing.InstancingEngine;
import com.jozufozu.flywheel.backend.model.ArrayModelRenderer; import com.jozufozu.flywheel.backend.model.ArrayModelRenderer;
import com.jozufozu.flywheel.backend.model.ModelRenderer; import com.jozufozu.flywheel.backend.model.ModelRenderer;
import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.IModel;
@ -34,7 +34,7 @@ public class RenderedContraption extends ContraptionRenderInfo {
private final ContraptionLighter<?> lighter; private final ContraptionLighter<?> lighter;
public final MaterialManagerImpl<ContraptionProgram> materialManager; public final InstancingEngine<ContraptionProgram> materialManager;
public final ContraptionInstanceManager kinetics; public final ContraptionInstanceManager kinetics;
private final Map<RenderType, ModelRenderer> renderLayers = new HashMap<>(); private final Map<RenderType, ModelRenderer> renderLayers = new HashMap<>();
@ -47,11 +47,12 @@ public class RenderedContraption extends ContraptionRenderInfo {
public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) {
super(contraption, renderWorld); super(contraption, renderWorld);
this.lighter = contraption.makeLighter(); this.lighter = contraption.makeLighter();
this.materialManager = MaterialManagerImpl.builder(CreateContexts.CWORLD) this.materialManager = InstancingEngine.builder(CreateContexts.CWORLD)
.setGroupFactory(ContraptionGroup.forContraption(this)) .setGroupFactory(ContraptionGroup.forContraption(this))
.setIgnoreOriginCoordinate(true) .setIgnoreOriginCoordinate(true)
.build(); .build();
this.kinetics = new ContraptionInstanceManager(this, materialManager); this.kinetics = new ContraptionInstanceManager(this, materialManager);
this.materialManager.addListener(this.kinetics);
buildLayers(); buildLayers();
if (Backend.getInstance().canUseInstancing()) { if (Backend.getInstance().canUseInstancing()) {

View file

@ -2,11 +2,14 @@ package com.simibubi.create.content.logistics.block.flap;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.struct.Batched;
import com.jozufozu.flywheel.backend.struct.BatchingTransformer;
import com.jozufozu.flywheel.backend.struct.StructWriter; import com.jozufozu.flywheel.backend.struct.StructWriter;
import com.jozufozu.flywheel.backend.struct.Writeable; import com.jozufozu.flywheel.backend.struct.Writeable;
import com.jozufozu.flywheel.core.model.IModel;
import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllInstanceFormats;
public class FlapType implements Writeable<FlapData> { public class FlapType implements Writeable<FlapData>, Batched<FlapData> {
@Override @Override
public FlapData create() { public FlapData create() {
return new FlapData(); return new FlapData();
@ -21,4 +24,9 @@ public class FlapType implements Writeable<FlapData> {
public StructWriter<FlapData> getWriter(VecBuffer backing) { public StructWriter<FlapData> getWriter(VecBuffer backing) {
return new UnsafeFlapWriter(backing, this); return new UnsafeFlapWriter(backing, this);
} }
@Override
public BatchingTransformer<FlapData> getTransformer(IModel model) {
return null;
}
} }