small performance gains
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-22 19:06:40 -04:00
parent 90e9492c18
commit cb3ccbef0b
8 changed files with 88 additions and 15 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file #maven.buildNumber.plugin properties file
#Tue May 20 18:51:57 EDT 2025 #Thu May 22 18:46:40 EDT 2025
buildNumber=629 buildNumber=630

View File

@ -1937,6 +1937,8 @@ Debug view of entity colliders
Fix lookup bug in debug physics ui Fix lookup bug in debug physics ui
Floating point starting to play nice with engine Floating point starting to play nice with engine
Fix geom-body collision sending wrong vector to body Fix geom-body collision sending wrong vector to body
Per-mesh draw calls in batched static draw calls
Main content pipeline tracking

View File

@ -31,6 +31,9 @@ public class ImGuiRenderer {
shadowMapPipeline.setFarPlane(farPlaneArr[0]); shadowMapPipeline.setFarPlane(farPlaneArr[0]);
} }
} }
if(ImGui.collapsingHeader("Main Content Pipeline")){
ImGui.textWrapped(Globals.renderingEngine.getMainContentPipeline().getTrackingInfo());
}
if(ImGui.collapsingHeader("Post Processing Pipeline")){ if(ImGui.collapsingHeader("Post Processing Pipeline")){
PostProcessingPipeline postProcessingPipeline = Globals.renderingEngine.getPostProcessingPipeline(); PostProcessingPipeline postProcessingPipeline = Globals.renderingEngine.getPostProcessingPipeline();
if(ImGui.button("Toggle Blur")){ if(ImGui.button("Toggle Blur")){

View File

@ -27,4 +27,13 @@ public class DrawableUtils {
} }
} }
/**
* Checks if the entity has a unique model
* @param entity The entity
* @return true if it has a unique model, false otherwise
*/
public static boolean hasUniqueModel(Entity entity){
return entity.containsKey(EntityDataStrings.HAS_UNIQUE_MODEL);
}
} }

View File

@ -304,6 +304,25 @@ public class Model {
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }
/**
* Draws a specific mesh
* @param i The index of the mesh
*/
public void drawMesh(RenderPipelineState renderPipelineState, OpenGLState openGLState, int i){
if(i < 0 || i >= this.meshes.size()){
throw new Error("Invalid mesh! " + i);
}
this.meshes.get(i).complexDraw(renderPipelineState, openGLState);
}
/**
* Gets the number of meshes in the model
* @return The number of meshes
*/
public int getMeshCount(){
return this.meshes.size();
}
/** /**
* Determines the correct shader to use for a given mesh * Determines the correct shader to use for a given mesh
* @param shaderMask The shader mask * @param shaderMask The shader mask

View File

@ -44,9 +44,15 @@ public class MainContentPipeline implements RenderPipeline {
*/ */
private List<Entity> standardDrawCall = new LinkedList<Entity>(); private List<Entity> standardDrawCall = new LinkedList<Entity>();
/**
* Number of terrain chunks rendered
*/
private int terrainChunks = 0;
@Override @Override
public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) {
Globals.profiler.beginCpuSample("MainContentPipeline.render"); Globals.profiler.beginCpuSample("MainContentPipeline.render");
this.clearTrackingData();
Matrix4d modelTransformMatrix = new Matrix4d(); Matrix4d modelTransformMatrix = new Matrix4d();
@ -107,6 +113,11 @@ public class MainContentPipeline implements RenderPipeline {
currentActor.applySpatialData(new Matrix4d(modelTransformMatrix),new Vector3d(position)); currentActor.applySpatialData(new Matrix4d(modelTransformMatrix),new Vector3d(position));
//draw //draw
currentActor.draw(renderPipelineState,openGLState); currentActor.draw(renderPipelineState,openGLState);
//tracking
if(currentEntity.containsKey(EntityDataStrings.TERRAIN_IS_TERRAIN)){
this.terrainChunks++;
}
} }
} }
for(ModelAccumulatorData accumulator : this.drawTargetAccumulator.getCalls()){ for(ModelAccumulatorData accumulator : this.drawTargetAccumulator.getCalls()){
@ -116,12 +127,14 @@ public class MainContentPipeline implements RenderPipeline {
List<Matrix4d> transforms = accumulator.getTransforms(); List<Matrix4d> transforms = accumulator.getTransforms();
List<Vector3d> positions = accumulator.getPositions(); List<Vector3d> positions = accumulator.getPositions();
model.setMeshMask(null); model.setMeshMask(null);
for(int i = 0; i < count; i++){ for(int meshIndex = 0; meshIndex < model.getMeshCount(); meshIndex++){
Vector3d position = positions.get(i); for(int i = 0; i < count; i++){
Matrix4d transform = transforms.get(i); Vector3d position = positions.get(i);
model.setWorldPos(position); Matrix4d transform = transforms.get(i);
model.setModelMatrix(transform); model.setWorldPos(position);
model.draw(renderPipelineState, openGLState); model.setModelMatrix(transform);
model.drawMesh(renderPipelineState, openGLState, meshIndex);
}
} }
} }
} }
@ -327,6 +340,13 @@ public class MainContentPipeline implements RenderPipeline {
; ;
} }
/**
* Clears the tracking data
*/
private void clearTrackingData(){
this.terrainChunks = 0;
}
/** /**
* Get the first person pipeline * Get the first person pipeline
* @param firstPersonItemsPipeline the first person pipeline * @param firstPersonItemsPipeline the first person pipeline
@ -350,5 +370,19 @@ public class MainContentPipeline implements RenderPipeline {
public List<Entity> getStandardEntityQueue(){ public List<Entity> getStandardEntityQueue(){
return standardDrawCall; return standardDrawCall;
} }
/**
* Gets the tracking info
* @return The tracking info
*/
public String getTrackingInfo(){
String message = "" +
"Terrain entities:" + this.terrainChunks + "\n" +
"";
for(DrawTargetAccumulator.ModelAccumulatorData data : this.drawTargetAccumulator.getCalls()){
message = message + data.getModelPath() + ": " + data.getCount() + "\n";
}
return message;
}
} }

View File

@ -147,12 +147,14 @@ public class ShadowMapPipeline implements RenderPipeline {
List<Matrix4d> transforms = accumulator.getTransforms(); List<Matrix4d> transforms = accumulator.getTransforms();
List<Vector3d> positions = accumulator.getPositions(); List<Vector3d> positions = accumulator.getPositions();
model.setMeshMask(null); model.setMeshMask(null);
for(int i = 0; i < count; i++){ for(int meshIndex = 0; meshIndex < model.getMeshCount(); meshIndex++){
Vector3d position = positions.get(i); for(int i = 0; i < count; i++){
Matrix4d transform = transforms.get(i); Vector3d position = positions.get(i);
model.setWorldPos(position); Matrix4d transform = transforms.get(i);
model.setModelMatrix(transform); model.setWorldPos(position);
model.draw(renderPipelineState, openGLState); model.setModelMatrix(transform);
model.drawMesh(renderPipelineState, openGLState, meshIndex);
}
} }
} }
} }

View File

@ -8,6 +8,7 @@ import org.joml.Vector3d;
import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.entity.camera.CameraEntityUtils;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.DrawableUtils;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityTags; import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
@ -23,6 +24,7 @@ public class DrawTargetEvaluator {
* Evaluates the draw targets * Evaluates the draw targets
*/ */
public static void evaluate(){ public static void evaluate(){
Globals.profiler.beginCpuSample("DrawTargetEvaluator.evaluate");
//main content pipeline structures //main content pipeline structures
DrawTargetAccumulator mainAccumulator = Globals.renderingEngine.getMainContentPipeline().getDrawTargetAccumulator(); DrawTargetAccumulator mainAccumulator = Globals.renderingEngine.getMainContentPipeline().getDrawTargetAccumulator();
List<Entity> mainQueue = Globals.renderingEngine.getMainContentPipeline().getStandardEntityQueue(); List<Entity> mainQueue = Globals.renderingEngine.getMainContentPipeline().getStandardEntityQueue();
@ -52,7 +54,7 @@ public class DrawTargetEvaluator {
Vector3d position = EntityUtils.getPosition(currentEntity); Vector3d position = EntityUtils.getPosition(currentEntity);
//fetch actor //fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity); Actor currentActor = EntityUtils.getActor(currentEntity);
if(currentActor.isStaticDrawCall()){ if(!DrawableUtils.hasUniqueModel(currentEntity) && currentActor.isStaticDrawCall()){
//calculate camera-modified vector3d //calculate camera-modified vector3d
Vector3d cameraModifiedPosition = positionVec.set(position).sub(cameraCenter); Vector3d cameraModifiedPosition = positionVec.set(position).sub(cameraCenter);
//calculate and apply model transform //calculate and apply model transform
@ -106,6 +108,8 @@ public class DrawTargetEvaluator {
// } // }
// } // }
// } // }
Globals.profiler.endCpuSample();
} }
} }