Parcourir la source

Add measureCpuThread to Benchmark

Leonardo Jeanteur il y a 1 an
Parent
commit
7ac380e0cb
1 fichiers modifiés avec 28 ajouts et 9 suppressions
  1. 28 9
      h3d/impl/Benchmark.hx

+ 28 - 9
h3d/impl/Benchmark.hx

@@ -70,6 +70,8 @@ class Benchmark extends h2d.Graphics {
 	public var measureCpu = false;
 	public var measureCpu = false;
 	public var displayTriangleCount = true;
 	public var displayTriangleCount = true;
 
 
+	public var measureCpuThread: sys.thread.Thread = null;
+
 	var tip : h2d.Text;
 	var tip : h2d.Text;
 	var tipCurrent : StatsObject;
 	var tipCurrent : StatsObject;
 	var tipCurName : String;
 	var tipCurName : String;
@@ -161,8 +163,15 @@ class Benchmark extends h2d.Graphics {
 			if ( displayTriangleCount )
 			if ( displayTriangleCount )
 				tip.text += hxd.Math.fmt(engine.drawTriangles/1000000)+" Mtri";
 				tip.text += hxd.Math.fmt(engine.drawTriangles/1000000)+" Mtri";
 		}
 		}
-		else
-			tip.text = s.name+"( " + Std.int(s.time / 1e6) + "." + StringTools.lpad(""+(Std.int(s.time/1e4)%100),"0",2) + " ms " + s.drawCalls + " draws "+ dispatchS(s.dispatches) + ")";
+		else {
+			var t = s.name + "( " + Std.int(s.time / 1e6) + "." + StringTools.lpad(""+(Std.int(s.time/1e4)%100),"0",2) + " ms";
+			if (measureCpuThread == null) {
+				t += " " + s.drawCalls + " draws "+ dispatchS(s.dispatches);
+			}
+			t += ")";
+
+			tip.text = t;
+		}
 		var tw = tip.textWidth + 10;
 		var tw = tip.textWidth + 10;
 		var tx = s == null ? curWidth : s.xPos + ((s.xSize - tw) * .5);
 		var tx = s == null ? curWidth : s.xPos + ((s.xSize - tw) * .5);
 		if( tx + tw > curWidth ) tx = curWidth - tw;
 		if( tx + tw > curWidth ) tx = curWidth - tw;
@@ -170,7 +179,7 @@ class Benchmark extends h2d.Graphics {
 		if( hxd.Math.abs(tip.parent.x - tx) > 5 ) tip.parent.x = Std.int(tx);
 		if( hxd.Math.abs(tip.parent.x - tx) > 5 ) tip.parent.x = Std.int(tx);
 	}
 	}
 
 
-	public function begin() {
+	public function begin(withVisual=true) {
 
 
 		if( !enable ) return;
 		if( !enable ) return;
 
 
@@ -190,7 +199,7 @@ class Benchmark extends h2d.Graphics {
 		var changed = false;
 		var changed = false;
 		while( waitFrames.length > 0 ) {
 		while( waitFrames.length > 0 ) {
 			var q = waitFrames[0];
 			var q = waitFrames[0];
-			if( !q.isAvailable() )
+			if( measureCpuThread == null && !q.isAvailable() )
 				break;
 				break;
 			waitFrames.shift();
 			waitFrames.shift();
 
 
@@ -250,13 +259,15 @@ class Benchmark extends h2d.Graphics {
 			changed = true;
 			changed = true;
 		}
 		}
 
 
-		if( allocated && visible )
-			syncVisual();
+		if (withVisual) {
+			if( allocated && visible )
+				syncVisual();
+		}
 
 
 		measure("begin");
 		measure("begin");
 	}
 	}
 
 
-	function syncVisual() {
+	public function syncVisual() {
 		var s2d = getScene();
 		var s2d = getScene();
 		var old = labels;
 		var old = labels;
 		labels = null;
 		labels = null;
@@ -278,7 +289,7 @@ class Benchmark extends h2d.Graphics {
 			s = s.next;
 			s = s.next;
 		}
 		}
 
 
-		var space = 52;
+		var space = 57;
 		width -= space;
 		width -= space;
 
 
 		var count = 0;
 		var count = 0;
@@ -332,7 +343,13 @@ class Benchmark extends h2d.Graphics {
 		time.visible = true;
 		time.visible = true;
 		time.textColor = 0xFFFFFF;
 		time.textColor = 0xFFFFFF;
 		var timeMs = totalTime / 1e6;
 		var timeMs = totalTime / 1e6;
-		time.text = Std.int(timeMs) + "." + Std.int((timeMs * 10) % 10) + (measureCpu?" cpu" : " gpu");
+		var totalName = measureCpu ? "cpu" : "gpu";
+		if (measureCpuThread != null) {
+			var n = measureCpuThread.getName();
+			if (n != null)
+				totalName = n;
+		}
+		time.text = Std.int(timeMs) + "." + Std.int((timeMs * 10) % 10) + " " + totalName;
 
 
 		while( labels.length > count )
 		while( labels.length > count )
 			labels.pop().remove();
 			labels.pop().remove();
@@ -390,6 +407,8 @@ class Benchmark extends h2d.Graphics {
 		if( !enable ) return;
 		if( !enable ) return;
 		if( currentFrame != null && currentFrame.name == name )
 		if( currentFrame != null && currentFrame.name == name )
 			return;
 			return;
+		if( measureCpuThread != null && sys.thread.Thread.current() != measureCpuThread )
+			return;
 		var q = allocQuery();
 		var q = allocQuery();
 		q.name = name;
 		q.name = name;
 		q.drawCalls = engine.drawCalls;
 		q.drawCalls = engine.drawCalls;