Ver código fonte

[OPTI] Optimizing RenderContext passes.

clandrin 3 anos atrás
pai
commit
3d570d5715
2 arquivos alterados com 27 adições e 37 exclusões
  1. 5 5
      h3d/scene/RenderContext.hx
  2. 22 32
      h3d/scene/Scene.hx

+ 5 - 5
h3d/scene/RenderContext.hx

@@ -31,7 +31,7 @@ class RenderContext extends h3d.impl.RenderContext {
 	var cachedShaderList : Array<hxsl.ShaderList>;
 	var cachedPassObjects : Array<Renderer.PassObjects>;
 	var cachedPos : Int;
-	var passes : h3d.pass.PassObject;
+	var passes : Map<Int, h3d.pass.PassObject>;
 	var lights : Light;
 	var currentManager : h3d.pass.ShaderManager;
 
@@ -54,7 +54,7 @@ class RenderContext extends h3d.impl.RenderContext {
 		sharedGlobals = [];
 		lights = null;
 		drawPass = null;
-		passes = null;
+		passes = [];
 		lights = null;
 		cachedPos = 0;
 		visibleFlag = true;
@@ -98,8 +98,8 @@ class RenderContext extends h3d.impl.RenderContext {
 			allocPool = o.nextAlloc;
 		o.pass = pass;
 		o.obj = obj;
-		o.next = passes;
-		passes = o;
+		o.next = passes.get(pass.passId);
+		passes.set(pass.passId, o);
 		return o;
 	}
 
@@ -148,7 +148,7 @@ class RenderContext extends h3d.impl.RenderContext {
 			c.s = null;
 			c.next = null;
 		}
-		passes = null;
+		passes = [];
 		lights = null;
 	}
 

+ 22 - 32
h3d/scene/Scene.hx

@@ -307,23 +307,26 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx.lightSystem = null;
 
 		var found = null;
-		var passes = new h3d.pass.PassList(@:privateAccess ctx.passes);
-
-		if( !passes.isEmpty() ) {
-			var p = hardwarePass;
-			if( p == null )
-				hardwarePass = p = new h3d.pass.HardwarePick();
-			ctx.setGlobal("depthMap", { texture : h3d.mat.Texture.fromColor(0xFF00000, 0) });
-			p.pickX = pixelX;
-			p.pickY = pixelY;
-			p.setContext(ctx);
-			p.draw(passes);
-			if( p.pickedIndex >= 0 )
-				for( po in passes )
-					if( p.pickedIndex-- == 0 ) {
-						found = po.obj;
-						break;
-					}
+		for ( passes in @:privateAccess ctx.passes ) {
+			if ( found != null )
+				break;
+			var passList = new h3d.pass.PassList(passes);
+			if( !passList.isEmpty() ) {
+				var p = hardwarePass;
+				if( p == null )
+					hardwarePass = p = new h3d.pass.HardwarePick();
+				ctx.setGlobal("depthMap", { texture : h3d.mat.Texture.fromColor(0xFF00000, 0) });
+				p.pickX = pixelX;
+				p.pickY = pixelY;
+				p.setContext(ctx);
+				p.draw(passList);
+				if( p.pickedIndex >= 0 )
+					for( po in passList )
+						if( p.pickedIndex-- == 0 ) {
+							found = po.obj;
+							break;
+						}
+			}
 		}
 
 		ctx.done();
@@ -402,23 +405,11 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 
 		syncRec(ctx);
 		emitRec(ctx);
-		// sort by pass id
-		ctx.passes = haxe.ds.ListSort.sortSingleLinked(ctx.passes, function(p1, p2) {
-			return p1.pass.passId - p2.pass.passId;
-		});
 
-		// group by pass implementation
-		var curPass = ctx.passes;
 		var passes = [];
 		var passIndex = -1;
-		while( curPass != null ) {
-			var passId = curPass.pass.passId;
-			var p = curPass, prev = null;
-			while( p != null && p.pass.passId == passId ) {
-				prev = p;
-				p = p.next;
-			}
-			prev.next = null;
+		for ( passId in ctx.passes.keys() ) {
+			var curPass = ctx.passes.get(passId);
 			var pobjs = ctx.cachedPassObjects[++passIndex];
 			if( pobjs == null ) {
 				pobjs = new Renderer.PassObjects();
@@ -427,7 +418,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 			pobjs.name = curPass.pass.name;
 			pobjs.passes.init(curPass);
 			passes.push(pobjs);
-			curPass = p;
 		}
 
 		// send to rendered