From 4745214fc8bf3a9ee5be4506557d377a2de22639 Mon Sep 17 00:00:00 2001 From: zbx1425 Date: Tue, 27 Dec 2022 13:05:39 +0800 Subject: [PATCH] Add static for Blaze3D faces --- .../cn/zbx1425/mtrsteamloco/render/RenderUtil.java | 4 +++- .../main/java/cn/zbx1425/sowcer/util/Profiler.java | 8 ++++++++ .../java/cn/zbx1425/sowcerext/model/ModelCluster.java | 11 ++++++----- .../main/java/cn/zbx1425/sowcerext/model/RawMesh.java | 4 +++- .../java/cn/zbx1425/sowcerext/model/RawModel.java | 6 ++++-- .../cn/zbx1425/sowcerext/reuse/DrawScheduler.java | 6 +++--- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java index 105c4ebe..e40e8e73 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/render/RenderUtil.java @@ -30,7 +30,7 @@ public static boolean shouldSkipRenderTrain(TrainClient train) { } public static String getRenderStatusMessage() { - return "=== NTE Rendering Status ===\n" + return "\n=== NTE Rendering Status ===\n" + "Draw Calls: " + MainClient.profiler.drawCallCount + ", Batches: " + MainClient.profiler.batchCount + "\n" @@ -38,6 +38,8 @@ public static String getRenderStatusMessage() { + ", " + MainClient.profiler.instancedFaceCount + " instanced" + ", " + (MainClient.profiler.singleFaceCount + MainClient.profiler.instancedFaceCount) + " total" + "\n" + + "Faces via Blaze3D: " + MainClient.profiler.blazeFaceCount + + "\n" + "Loaded Models: " + MainClient.modelManager.loadedRawModels.size() + ", Uploaded VAOs: " + MainClient.modelManager.uploadedVertArraysCount ; diff --git a/common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java b/common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java index 7e87f898..f705d49a 100644 --- a/common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java +++ b/common/src/main/java/cn/zbx1425/sowcer/util/Profiler.java @@ -6,21 +6,25 @@ public class Profiler { public int batchCount = 0; public int singleFaceCount = 0; public int instancedFaceCount = 0; + public int blazeFaceCount; private int drawCallCountCF = 0; private int batchCountCF = 0; private int singleFaceCountCF = 0; private int instancedFaceCountCF = 0; + private int blazeFaceCountCF = 0; public void beginFrame() { drawCallCount = drawCallCountCF; batchCount = batchCountCF; singleFaceCount = singleFaceCountCF; instancedFaceCount = instancedFaceCountCF; + blazeFaceCount = blazeFaceCountCF; drawCallCountCF = 0; batchCountCF = 0; singleFaceCountCF = 0; instancedFaceCountCF = 0; + blazeFaceCountCF = 0; } public void recordBatches(int batchCount) { @@ -35,4 +39,8 @@ public void recordDrawCall(int faceCount, boolean instanced) { singleFaceCountCF += faceCount; } } + + public void recordBlazeAction(int faceCount) { + blazeFaceCountCF += faceCount; + } } diff --git a/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java b/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java index f0f03e34..f66a6207 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/model/ModelCluster.java @@ -5,6 +5,7 @@ import cn.zbx1425.sowcer.batch.ShaderProp; import cn.zbx1425.sowcer.model.VertArrays; import cn.zbx1425.sowcer.util.AttrUtil; +import cn.zbx1425.sowcer.util.Profiler; import cn.zbx1425.sowcer.vertex.VertAttrMapping; import cn.zbx1425.sowcer.vertex.VertAttrState; import cn.zbx1425.sowcer.math.Matrix4f; @@ -32,7 +33,7 @@ public ModelCluster(RawModel source, VertAttrMapping mapping) { this.uploadedOpaqueParts = VertArrays.createAll(opaqueParts.upload(mapping), mapping, null); } - public void renderOpaqueOptimized(BatchManager batchManager, Matrix4f pose, int light) { + public void renderOpaqueOptimized(BatchManager batchManager, Matrix4f pose, int light, Profiler profiler) { // KHRDebug.glDebugMessageInsert(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, KHRDebug.GL_DEBUG_TYPE_MARKER, // 0, KHRDebug.GL_DEBUG_SEVERITY_NOTIFICATION, "RenderOptimized " + (source.sourceLocation == null ? "unknown" : source.sourceLocation.toString())); int shaderLightmapUV = AttrUtil.exchangeLightmapUVBits(light); @@ -41,12 +42,12 @@ public void renderOpaqueOptimized(BatchManager batchManager, Matrix4f pose, int ), ShaderProp.DEFAULT); } - public void renderOpaqueUnoptimized(MultiBufferSource vertexConsumers, Matrix4f pose, int light) { - opaqueParts.writeBlazeBuffer(vertexConsumers, pose, light); + public void renderOpaqueUnoptimized(MultiBufferSource vertexConsumers, Matrix4f pose, int light, Profiler profiler) { + opaqueParts.writeBlazeBuffer(vertexConsumers, pose, light, profiler); } - public void renderTranslucent(MultiBufferSource vertexConsumers, Matrix4f pose, int light) { - translucentParts.writeBlazeBuffer(vertexConsumers, pose, light); + public void renderTranslucent(MultiBufferSource vertexConsumers, Matrix4f pose, int light, Profiler profiler) { + translucentParts.writeBlazeBuffer(vertexConsumers, pose, light, profiler); } @Override diff --git a/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java b/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java index c5e020db..6348c17c 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java @@ -5,6 +5,7 @@ import cn.zbx1425.sowcer.object.IndexBuf; import cn.zbx1425.sowcer.object.VertBuf; import cn.zbx1425.sowcer.util.OffHeapAllocator; +import cn.zbx1425.sowcer.util.Profiler; import cn.zbx1425.sowcer.vertex.VertAttrMapping; import cn.zbx1425.sowcer.vertex.VertAttrSrc; import cn.zbx1425.sowcer.vertex.VertAttrType; @@ -318,7 +319,8 @@ public void setRenderType(String type) { } } - public void writeBlazeBuffer(VertexConsumer vertexConsumer, Matrix4f matrix, int color, int light) { + public void writeBlazeBuffer(VertexConsumer vertexConsumer, Matrix4f matrix, int color, int light, Profiler profiler) { + if (profiler != null) profiler.recordBlazeAction(faces.size()); for (Face face : faces) { assert face.vertices.length == 3; for (int vertIndex : face.vertices) { diff --git a/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java b/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java index b7726e30..4580a81b 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/model/RawModel.java @@ -3,6 +3,7 @@ import cn.zbx1425.sowcer.batch.MaterialProp; import cn.zbx1425.sowcer.model.Model; import cn.zbx1425.sowcer.util.AttrUtil; +import cn.zbx1425.sowcer.util.Profiler; import cn.zbx1425.sowcer.vertex.VertAttrMapping; import cn.zbx1425.sowcer.math.Matrix4f; import cn.zbx1425.sowcer.math.Vector3f; @@ -148,7 +149,7 @@ public void clearAttrStates() { } } - public void writeBlazeBuffer(MultiBufferSource vertexConsumers, Matrix4f matrix, int light) { + public void writeBlazeBuffer(MultiBufferSource vertexConsumers, Matrix4f matrix, int light, Profiler profiler) { if (meshList.isEmpty()) return; for (Map.Entry entry : meshList.entrySet()) { RenderType renderType = entry.getKey().getBlazeRenderType(); @@ -169,7 +170,8 @@ public void writeBlazeBuffer(MultiBufferSource vertexConsumers, Matrix4f matrix, AttrUtil.zeroRotation(resultMatrix); } - entry.getValue().writeBlazeBuffer(vertexConsumers.getBuffer(renderType), resultMatrix, resultColor, resultLight); + entry.getValue().writeBlazeBuffer(vertexConsumers.getBuffer(renderType), + resultMatrix, resultColor, resultLight, profiler); } } diff --git a/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java b/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java index ab95590d..374a5002 100644 --- a/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java +++ b/common/src/main/java/cn/zbx1425/sowcerext/reuse/DrawScheduler.java @@ -33,9 +33,9 @@ public void commit(MultiBufferSource vertexConsumers, boolean isOptimized, Profi if (drawCalls.size() < 1) return; for (DrawCallCluster drawCall : drawCalls) { if (isOptimized) { - drawCall.model.renderOpaqueOptimized(batchManager, drawCall.pose, drawCall.light); + drawCall.model.renderOpaqueOptimized(batchManager, drawCall.pose, drawCall.light, profiler); } else { - drawCall.model.renderOpaqueUnoptimized(vertexConsumers, drawCall.pose, drawCall.light); + drawCall.model.renderOpaqueUnoptimized(vertexConsumers, drawCall.pose, drawCall.light, profiler); } } if (isOptimized) { @@ -44,7 +44,7 @@ public void commit(MultiBufferSource vertexConsumers, boolean isOptimized, Profi GlStateTracker.restore(); } for (DrawCallCluster drawCall : drawCalls) { - drawCall.model.renderTranslucent(vertexConsumers, drawCall.pose, drawCall.light); + drawCall.model.renderTranslucent(vertexConsumers, drawCall.pose, drawCall.light, profiler); } drawCalls.clear(); }