Browse Source

scene profiler: also include s2d draws

trethaller 2 years ago
parent
commit
901b39f40d
5 changed files with 28 additions and 8 deletions
  1. 1 0
      h2d/RenderContext.hx
  2. 2 0
      h2d/Scene.hx
  3. 22 5
      h3d/impl/SceneProf.hx
  4. 1 1
      h3d/pass/Default.hx
  5. 2 2
      h3d/scene/Scene.hx

+ 1 - 0
h2d/RenderContext.hx

@@ -739,6 +739,7 @@ class RenderContext extends h3d.impl.RenderContext {
 
 		if( !beginDraw(obj, tile.getTexture(), true, true) ) return false;
 
+		#if sceneprof h3d.impl.SceneProf.mark(obj); #end
 		setupColor(obj);
 		baseShader.absoluteMatrixA.set(tile.width * obj.matA, tile.height * obj.matC, obj.absX + tile.dx * obj.matA + tile.dy * obj.matC);
 		baseShader.absoluteMatrixB.set(tile.width * obj.matB, tile.height * obj.matD, obj.absY + tile.dx * obj.matB + tile.dy * obj.matD);

+ 2 - 0
h2d/Scene.hx

@@ -782,7 +782,9 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		sync(ctx);
 		if( children.length == 0 ) return;
 		ctx.begin();
+		#if sceneprof h3d.impl.SceneProf.begin("2d", ctx.frame); #end
 		ctx.drawScene();
+		#if sceneprof h3d.impl.SceneProf.end(); #end
 		ctx.end();
 	}
 

+ 22 - 5
h3d/impl/SceneProf.hx

@@ -38,10 +38,12 @@ class SceneProf {
     static var curSection : String;
 
 	static var stackCache : Map<h3d.scene.Object, Array<String>>;
+	static var stackCache2d : Map<h2d.Object, Array<String>>;
 
 	public static function start() {
 		enable = true;
 		stackCache = new Map();
+		stackCache2d = new Map();
 		frames = [];
 		lastFrameId = -1;
 	}
@@ -50,14 +52,14 @@ class SceneProf {
 		enable = false;
 	}
 
-	public static function begin(section: String, ctx : h3d.scene.RenderContext) {
+	public static function begin(section: String, frame : Int) {
 		if(!enable) return;
-		if(ctx.frame != lastFrameId) {
+		if(frame != lastFrameId) {
 			var f = new Frame();
 			f.startTime = Sys.time();
 			frames.push(f);
 			curFrame = f;
-			lastFrameId = ctx.frame;
+			lastFrameId = frame;
 		}
         curSection = section;
 	}
@@ -77,13 +79,28 @@ class SceneProf {
 		return s;
 	}
 
-	public static function mark(obj: h3d.scene.Object) {
+	static function getStack2d(o: h2d.Object) : Array<String> {
+		var r = stackCache2d.get(o);
+		if(r != null)
+			return r;
+		var s = null;
+		if(o.parent != null)
+			s = getStack2d(o.parent).copy();
+		else s = [];
+
+		var name = o.name != null ? o.name : Type.getClassName(Type.getClass(o));
+		s.unshift(name);
+		stackCache2d.set(o, s);
+		return s;
+	}
+
+	public static function mark(?o3d: h3d.scene.Object, ?o2d: h2d.Object) {
 		if(!enable) return;
 		var t = Sys.time();
 		curFrame.samples.push({
 			time: t,
 			sect: curSection,
-			stack: getStack(obj)
+			stack: o3d != null ? getStack(o3d) : getStack2d(o2d)
 		});
 	}
 

+ 1 - 1
h3d/pass/Default.hx

@@ -94,7 +94,7 @@ class Default extends Base {
 	override function draw( passes : h3d.pass.PassList, ?sort : h3d.pass.PassList -> Void ) {
 		if( passes.isEmpty() )
 			return;
-		#if sceneprof h3d.impl.SceneProf.begin("draw", ctx); #end
+		#if sceneprof h3d.impl.SceneProf.begin("draw", ctx.frame); #end
 		for( g in ctx.sharedGlobals )
 			globals.fastSet(g.gid, g.value);
 		setGlobals();

+ 2 - 2
h3d/scene/Scene.hx

@@ -403,11 +403,11 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx.start();
 		renderer.start();
 
-		#if sceneprof h3d.impl.SceneProf.begin("sync", ctx); #end
+		#if sceneprof h3d.impl.SceneProf.begin("sync", ctx.frame); #end
 		syncRec(ctx);
 		#if sceneprof
 		h3d.impl.SceneProf.end();
-		h3d.impl.SceneProf.begin("emit", ctx);
+		h3d.impl.SceneProf.begin("emit", ctx.frame);
 		#end
 		emitRec(ctx);
 		#if sceneprof h3d.impl.SceneProf.end(); #end