mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Add more debug info
- Flywheel version - Vertex/Instance count - Origin coordinate for Instancing Engine
This commit is contained in:
parent
84432fb837
commit
24423c56a8
16 changed files with 133 additions and 31 deletions
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
|
||||
import com.jozufozu.flywheel.config.EngineArgument;
|
||||
import com.jozufozu.flywheel.config.FlwCommands;
|
||||
|
@ -13,17 +14,27 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.forgespi.language.IModFileInfo;
|
||||
|
||||
@Mod(Flywheel.ID)
|
||||
public class Flywheel {
|
||||
|
||||
public static final String ID = "flywheel";
|
||||
public static final Logger LOGGER = LogManager.getLogger(Flywheel.class);
|
||||
public static ArtifactVersion VERSION;
|
||||
|
||||
public Flywheel() {
|
||||
IModFileInfo modFileById = ModList.get()
|
||||
.getModFileById(ID);
|
||||
|
||||
VERSION = modFileById.getMods()
|
||||
.get(0)
|
||||
.getVersion();
|
||||
|
||||
FMLJavaModLoadingContext.get()
|
||||
.getModEventBus()
|
||||
.addListener(this::setup);
|
||||
|
|
|
@ -18,7 +18,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|||
public class FlywheelClient {
|
||||
|
||||
public static void clientInit() {
|
||||
CrashReportCallables.registerCrashCallable("Flywheel Backend", Backend::getBackendDescriptor);
|
||||
CrashReportCallables.registerCrashCallable("Flywheel Backend", () -> Backend.getEngine().getProperName());
|
||||
|
||||
OptifineHandler.init();
|
||||
Backend.init();
|
||||
|
|
|
@ -25,14 +25,6 @@ public class Backend {
|
|||
|
||||
private static final Loader loader = new Loader();
|
||||
|
||||
/**
|
||||
* Get a string describing the Flywheel backend. When there are eventually multiple backends
|
||||
* (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use.
|
||||
*/
|
||||
public static String getBackendDescriptor() {
|
||||
return engine == null ? "" : engine.getProperName();
|
||||
}
|
||||
|
||||
public static FlwEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
|
|
@ -62,12 +62,12 @@ public abstract class AbstractInstancer<D extends InstanceData> implements Insta
|
|||
return modelData.vertexCount();
|
||||
}
|
||||
|
||||
public int numInstances() {
|
||||
public int getInstanceCount() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
public int getTotalVertexCount() {
|
||||
return getModelVertexCount() * numInstances();
|
||||
public int getVertexCount() {
|
||||
return getModelVertexCount() * getInstanceCount();
|
||||
}
|
||||
|
||||
protected void removeDeletedInstances() {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jozufozu.flywheel.api.MaterialManager;
|
||||
|
||||
public interface Engine extends RenderDispatcher, MaterialManager {
|
||||
void addDebugInfo(List<String> info);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,15 @@ public abstract class InstanceManager<T> implements InstancingEngine.OriginShift
|
|||
this.tickableInstances = new Object2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of game objects that are currently being instanced.
|
||||
*
|
||||
* @return The object count.
|
||||
*/
|
||||
public int getObjectCount() {
|
||||
return instances.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given object capable of being instanced at all?
|
||||
*
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
|
@ -74,7 +77,7 @@ public class InstanceWorld {
|
|||
* Free all acquired resources and invalidate this instance world.
|
||||
*/
|
||||
public void delete() {
|
||||
this.taskEngine.stopWorkers();
|
||||
taskEngine.stopWorkers();
|
||||
engine.delete();
|
||||
entityInstanceManager.detachLightListeners();
|
||||
blockEntityInstanceManager.detachLightListeners();
|
||||
|
@ -133,4 +136,11 @@ public class InstanceWorld {
|
|||
world.entitiesForRendering()
|
||||
.forEach(entityInstanceManager::add);
|
||||
}
|
||||
|
||||
public void getDebugString(List<String> debug) {
|
||||
debug.add("");
|
||||
debug.add("Flywheel: " + Flywheel.VERSION);
|
||||
debug.add("B: " + blockEntityInstanceManager.getObjectCount() + ", E: " + entityInstanceManager.getObjectCount());
|
||||
engine.addDebugInfo(debug);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.jozufozu.flywheel.backend.instancing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||
|
@ -113,4 +115,8 @@ public class InstancedRenderDispatcher {
|
|||
.loadEntities(world);
|
||||
}
|
||||
|
||||
public static void getDebugString(List<String> debug) {
|
||||
instanceWorlds.get(Minecraft.getInstance().level)
|
||||
.getDebugString(debug);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ public class BatchedMaterialGroup implements MaterialGroup {
|
|||
protected final RenderType state;
|
||||
|
||||
private final Map<Batched<? extends InstanceData>, BatchedMaterial<?>> materials = new HashMap<>();
|
||||
private int vertexCount;
|
||||
private int instanceCount;
|
||||
|
||||
public BatchedMaterialGroup(RenderType state) {
|
||||
this.state = state;
|
||||
|
@ -37,11 +39,13 @@ public class BatchedMaterialGroup implements MaterialGroup {
|
|||
|
||||
public void render(PoseStack stack, BatchDrawingTracker source, TaskEngine pool) {
|
||||
|
||||
int vertexCount = 0;
|
||||
vertexCount = 0;
|
||||
instanceCount = 0;
|
||||
for (BatchedMaterial<?> material : materials.values()) {
|
||||
for (CPUInstancer<?> instancer : material.models.values()) {
|
||||
instancer.setup();
|
||||
vertexCount += instancer.getTotalVertexCount();
|
||||
vertexCount += instancer.getVertexCount();
|
||||
instanceCount += instancer.getInstanceCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,4 +69,20 @@ public class BatchedMaterialGroup implements MaterialGroup {
|
|||
public void delete() {
|
||||
materials.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of instances drawn last frame.
|
||||
* @return The instance count.
|
||||
*/
|
||||
public int getInstanceCount() {
|
||||
return instanceCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of vertices drawn last frame.
|
||||
* @return The vertex count.
|
||||
*/
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching;
|
|||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jozufozu.flywheel.api.MaterialGroup;
|
||||
|
@ -10,6 +11,7 @@ import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker;
|
|||
import com.jozufozu.flywheel.backend.instancing.Engine;
|
||||
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||
import com.jozufozu.flywheel.util.FlwUtil;
|
||||
import com.mojang.blaze3d.platform.Lighting;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
||||
|
@ -28,7 +30,6 @@ public class BatchingEngine implements Engine {
|
|||
for (RenderLayer value : RenderLayer.values()) {
|
||||
layers.put(value, new HashMap<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,4 +71,18 @@ public class BatchingEngine implements Engine {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugInfo(List<String> info) {
|
||||
info.add("Batching");
|
||||
info.add("Instances: " + layers.values()
|
||||
.stream()
|
||||
.flatMap(FlwUtil::mapValues)
|
||||
.mapToInt(BatchedMaterialGroup::getInstanceCount)
|
||||
.sum());
|
||||
info.add("Vertices: " + layers.values()
|
||||
.stream()
|
||||
.flatMap(FlwUtil::mapValues)
|
||||
.mapToInt(BatchedMaterialGroup::getVertexCount)
|
||||
.sum());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
|||
}
|
||||
|
||||
void submitTasks(PoseStack stack, TaskEngine pool, DirectVertexConsumer consumer) {
|
||||
int instances = numInstances();
|
||||
int instances = getInstanceCount();
|
||||
|
||||
while (instances > 0) {
|
||||
int end = instances;
|
||||
|
|
|
@ -46,6 +46,14 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
|
|||
});
|
||||
}
|
||||
|
||||
public int getInstanceCount() {
|
||||
return models.values().stream().mapToInt(GPUInstancer::getInstanceCount).sum();
|
||||
}
|
||||
|
||||
public int getVertexCount() {
|
||||
return models.values().stream().mapToInt(GPUInstancer::getVertexCount).sum();
|
||||
}
|
||||
|
||||
public boolean nothingToRender() {
|
||||
return models.size() > 0 && models.values()
|
||||
.stream()
|
||||
|
|
|
@ -34,6 +34,9 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
|||
private final Map<Instanced<? extends InstanceData>, InstancedMaterial<?>> materials = new HashMap<>();
|
||||
private final ModelAllocator allocator;
|
||||
|
||||
private int vertexCount;
|
||||
private int instanceCount;
|
||||
|
||||
public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) {
|
||||
this.owner = owner;
|
||||
this.type = type;
|
||||
|
@ -54,6 +57,22 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of instances drawn last frame.
|
||||
* @return The instance count.
|
||||
*/
|
||||
public int getInstanceCount() {
|
||||
return instanceCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of vertices drawn last frame.
|
||||
* @return The vertex count.
|
||||
*/
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
}
|
||||
|
||||
public void render(Matrix4f viewProjection, double camX, double camY, double camZ, RenderLayer layer) {
|
||||
type.setupRenderState();
|
||||
Textures.bindActiveTextures();
|
||||
|
@ -75,6 +94,9 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
|||
pool.flush();
|
||||
}
|
||||
|
||||
vertexCount = 0;
|
||||
instanceCount = 0;
|
||||
|
||||
for (Map.Entry<Instanced<? extends InstanceData>, InstancedMaterial<?>> entry : materials.entrySet()) {
|
||||
InstancedMaterial<?> material = entry.getValue();
|
||||
if (material.nothingToRender()) continue;
|
||||
|
@ -90,6 +112,8 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
|||
|
||||
for (GPUInstancer<?> instancer : material.getAllInstancers()) {
|
||||
instancer.render();
|
||||
vertexCount += instancer.getVertexCount();
|
||||
instanceCount += instancer.getInstanceCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.instancing;
|
|||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -14,6 +15,7 @@ import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
|||
import com.jozufozu.flywheel.core.compile.ProgramCompiler;
|
||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||
import com.jozufozu.flywheel.util.FlwUtil;
|
||||
import com.jozufozu.flywheel.util.WeakHashSet;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
||||
|
@ -101,8 +103,7 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
|||
} else {
|
||||
return layers.values()
|
||||
.stream()
|
||||
.flatMap(it -> it.values()
|
||||
.stream());
|
||||
.flatMap(FlwUtil::mapValues);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,6 +151,14 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugInfo(List<String> info) {
|
||||
info.add("GL33 Instanced Arrays");
|
||||
info.add("Origin: " + originCoordinate.getX() + ", " + originCoordinate.getY() + ", " + originCoordinate.getZ());
|
||||
info.add("Instances: " + getGroupsToRender(null).mapToInt(InstancedMaterialGroup::getInstanceCount).sum());
|
||||
info.add("Vertices: " + getGroupsToRender(null).mapToInt(InstancedMaterialGroup::getVertexCount).sum());
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface OriginShiftListener {
|
||||
void onOriginShift();
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.jozufozu.flywheel.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
import com.jozufozu.flywheel.light.LightUpdater;
|
||||
import com.jozufozu.flywheel.util.WorldAttached;
|
||||
|
||||
|
@ -22,16 +21,7 @@ public class ForgeEvents {
|
|||
|
||||
if (Minecraft.getInstance().options.renderDebug) {
|
||||
|
||||
ArrayList<String> right = event.getRight();
|
||||
|
||||
String text = "Flywheel: " + Backend.getBackendDescriptor();
|
||||
if (right.size() < 10) {
|
||||
right.add("");
|
||||
right.add(text);
|
||||
} else {
|
||||
right.add(9, "");
|
||||
right.add(10, text);
|
||||
}
|
||||
InstancedRenderDispatcher.getDebugString(event.getLeft());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel.util;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.jozufozu.flywheel.mixin.BlockEntityRenderDispatcherAccessor;
|
||||
|
||||
|
@ -68,4 +69,8 @@ public class FlwUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <R> Stream<R> mapValues(Map<?, R> map) {
|
||||
return map.values().stream();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue