소스 검색

added hxsl.Debug and use debug macro to prevent args evaluation

Nicolas Cannasse 8 달 전
부모
커밋
9c0bafa4c8
4개의 변경된 파일57개의 추가작업 그리고 51개의 파일을 삭제
  1. 19 24
      hxsl/Cache.hx
  2. 2 19
      hxsl/Dce.hx
  3. 35 0
      hxsl/Debug.hx
  4. 1 8
      hxsl/Linker.hx

+ 19 - 24
hxsl/Cache.hx

@@ -55,11 +55,6 @@ class SearchMap {
 
 class Cache {
 
-	#if shader_debug_dump
-	public static var DEBUG_IDS = false;
-	public static var TRACE = true;
-	#end
-
 	var linkCache : SearchMap;
 	var linkShaders : Map<String, Shader>;
 	var batchShaders : Map<RuntimeShader, { shader : SharedShader, params : RuntimeShader.AllocParam, size : Int }>;
@@ -256,7 +251,7 @@ class Cache {
 			dbg.writeString("----- DATAS ----\n\n");
 			for( s in shaderDatas ) {
 				dbg.writeString("\t\t**** " + s.inst.shader.name + (s.p == 0 ? "" : " P="+s.p)+ " *****\n");
-				dbg.writeString(Printer.shaderToString(s.inst.shader,DEBUG_IDS)+"\n\n");
+				dbg.writeString(Printer.shaderToString(s.inst.shader,Debug.VAR_IDS)+"\n\n");
 			}
 		}
 		//TRACE = shaderId == 0;
@@ -289,17 +284,17 @@ class Cache {
 				checkRec(v);
 		}
 
-		#if debug
-		Printer.check(s,[for( s in shaderDatas ) s.inst.shader]);
-		#end
-
 		#if shader_debug_dump
 		if( dbg != null ) {
 			dbg.writeString("----- LINK ----\n\n");
-			dbg.writeString(Printer.shaderToString(s,DEBUG_IDS)+"\n\n");
+			dbg.writeString(Printer.shaderToString(s,Debug.VAR_IDS)+"\n\n");
 		}
 		#end
 
+		#if debug
+		Printer.check(s,[for( s in shaderDatas ) s.inst.shader]);
+		#end
+
 		var prev = s;
 		var splitter = new hxsl.Splitter();
 		var sl = try splitter.split(s, mode == Batch ) catch( e : Error ) { e.msg += "\n\nin\n\n"+Printer.shaderToString(s); throw e; };
@@ -318,35 +313,35 @@ class Cache {
 			}
 
 
-		#if debug
-		for( s in sl )
-			Printer.check(s,[prev]);
-		#end
-
 		#if shader_debug_dump
 		if( dbg != null ) {
 			dbg.writeString("----- SPLIT ----\n\n");
 			for( s in sl )
-				dbg.writeString(Printer.shaderToString(s, DEBUG_IDS) + "\n\n");
+				dbg.writeString(Printer.shaderToString(s, Debug.VAR_IDS) + "\n\n");
 		}
 		#end
 
-		var prev = sl;
-		var sl = new hxsl.Dce().dce(sl);
-
 		#if debug
-		for( i => s in sl )
-			Printer.check(s,[prev[i]]);
+		for( s in sl )
+			Printer.check(s,[prev]);
 		#end
 
+		var prev = sl;
+		var sl = new hxsl.Dce().dce(sl);
+
 		#if shader_debug_dump
 		if( dbg != null ) {
 			dbg.writeString("----- DCE ----\n\n");
 			for( s in sl )
-				dbg.writeString(Printer.shaderToString(s, DEBUG_IDS) + "\n\n");
+				dbg.writeString(Printer.shaderToString(s, Debug.VAR_IDS) + "\n\n");
 		}
 		#end
 
+		#if debug
+		for( i => s in sl )
+			Printer.check(s,[prev[i]]);
+		#end
+
 		var r = buildRuntimeShader(sl, paramVars);
 		r.mode = mode;
 
@@ -354,7 +349,7 @@ class Cache {
 		if( dbg != null ) {
 			dbg.writeString("----- FLATTEN ----\n\n");
 			for( s in r.getShaders() )
-				dbg.writeString(Printer.shaderToString(s.data, DEBUG_IDS) + "\n\n");
+				dbg.writeString(Printer.shaderToString(s.data, Debug.VAR_IDS) + "\n\n");
 		}
 		#end
 

+ 2 - 19
hxsl/Dce.hx

@@ -1,5 +1,6 @@
 package hxsl;
 using hxsl.Ast;
+import hxsl.Debug.trace in debug;
 
 private class Exit {
 	public function new() {
@@ -65,13 +66,6 @@ class Dce {
 	public function new() {
 	}
 
-	inline function debug( msg : String, ?pos : haxe.PosInfos ) {
-		#if shader_debug_dump
-		if( Cache.TRACE )
-			haxe.Log.trace(msg, pos);
-		#end
-	}
-
 	public function dce( shaders : Array<ShaderData> ) {
 		// collect vars dependencies
 		used = new Map();
@@ -145,19 +139,8 @@ class Dce {
 		return vd;
 	}
 
-	function swizStr( bits : Int ) {
-		if( bits == 15 )
-			return "";
-		var str = ".";
-		if( bits & 1 != 0 ) str += "x";
-		if( bits & 2 != 0 ) str += "y";
-		if( bits & 4 != 0 ) str += "z";
-		if( bits & 8 != 0 ) str += "w";
-		return str;
-	}
-
 	function varName( v : TVar, bits = 15 ) {
-		return v.name+swizStr(bits) #if shader_debug_dump +(hxsl.Cache.DEBUG_IDS?"@"+v.id:"") #end;
+		return Debug.varName(v, bits);
 	}
 
 	function markRec( v : VarDeps, bits : Int ) {

+ 35 - 0
hxsl/Debug.hx

@@ -0,0 +1,35 @@
+package hxsl;
+
+class Debug {
+
+	public static var VAR_IDS = true;
+	public static var TRACE = true;
+
+	public static macro function trace(str) {
+		return macro if( hxsl.Debug.TRACE ) trace($str);
+	}
+
+	public static function varName( v : Ast.TVar, swizBits = 15 ) {
+		var name = v.name;
+		if( swizBits != 15 ) name += swizStr(swizBits);
+		return VAR_IDS ? v.name+"@"+v.id : v.name;
+	}
+
+	static function swizStr( bits : Int ) {
+		var str = ".";
+		if( bits & 1 != 0 ) str += "x";
+		if( bits & 2 != 0 ) str += "y";
+		if( bits & 4 != 0 ) str += "z";
+		if( bits & 8 != 0 ) str += "w";
+		return str;
+	}
+
+	public static macro function traceDepth(str) {
+		return macro if( hxsl.Debug.TRACE ) {
+			var msg = $str;
+			for( i in 0...debugDepth ) msg = "    " + msg;
+			trace(msg);
+		};
+	}
+
+}

+ 1 - 8
hxsl/Linker.hx

@@ -1,5 +1,6 @@
 package hxsl;
 using hxsl.Ast;
+import hxsl.Debug.traceDepth in debug;
 
 private class AllocatedVar {
 	public var id : Int;
@@ -62,14 +63,6 @@ class Linker {
 		this.mode = mode;
 	}
 
-	inline function debug( msg : String, ?pos : haxe.PosInfos ) {
-		#if shader_debug_dump
-		if( Cache.TRACE ) {
-			for( i in 0...debugDepth ) msg = "    " + msg; haxe.Log.trace(msg, pos);
-		}
-		#end
-	}
-
 	function error( msg : String, p : Position ) : Dynamic {
 		return Error.t(msg, p);
 	}