Skip to content

Commit

Permalink
scene profiler: also include s2d draws
Browse files Browse the repository at this point in the history
  • Loading branch information
trethaller committed Oct 4, 2022
1 parent ab5adbd commit 901b39f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions h2d/RenderContext.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions h2d/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
27 changes: 22 additions & 5 deletions h3d/impl/SceneProf.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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)
});
}

Expand Down
2 changes: 1 addition & 1 deletion h3d/pass/Default.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions h3d/scene/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 901b39f

Please sign in to comment.