Browse Source

added trace(), disable loop unroll unless flash/webgl

ncannasse 8 years ago
parent
commit
78437ec459
5 changed files with 20 additions and 2 deletions
  1. 2 0
      hxsl/Ast.hx
  2. 7 2
      hxsl/Checker.hx
  3. 5 0
      hxsl/Dce.hx
  4. 4 0
      hxsl/Eval.hx
  5. 2 0
      hxsl/SharedShader.hx

+ 2 - 0
hxsl/Ast.hx

@@ -224,6 +224,8 @@ enum TGlobal {
 	DFdx;
 	DFdy;
 	Fwidth;
+	// debug
+	Trace;
 }
 
 enum Component {

+ 7 - 2
hxsl/Checker.hx

@@ -30,8 +30,6 @@ class Checker {
 
 	public function new() {
 		globals = new Map();
-		inline function g(gl:TGlobal, vars) {
-		}
 		var genType = [TFloat, vec2, vec3, vec4];
 		var baseType = [TFloat, TBool, TInt];
 		var genFloat = [for( t in genType ) { args : [ { name : "value", type : t } ], ret : t } ];
@@ -107,6 +105,8 @@ class Checker {
 				[ { args : [ { name : "value", type : TVec(4, VFloat) } ], ret : TVec(3, VFloat) } ];
 			case PackNormal:
 				[ { args : [ { name : "value", type : TVec(3, VFloat) } ], ret : TVec(4, VFloat) } ];
+			case Trace:
+				[];
 			}
 			if( def != null )
 				globals.set(g.toString(), { t : TFun(def), g : g } );
@@ -459,7 +459,10 @@ class Checker {
 				};
 				var old = vars.get(v.name);
 				vars.set(v.name, v);
+				var oldL = inLoop;
+				inLoop = true;
 				var block = typeExpr(block, NoValue);
+				inLoop = oldL;
 				if( old == null ) vars.remove(v.name) else vars.set(v.name, old);
 				TFor(v, it, block);
 			default:
@@ -846,6 +849,8 @@ class Checker {
 			default:
 				error("Cannot apply " + g.toString() + " to these parameters", pos);
 			}
+		case Trace:
+			type = TVoid;
 		default:
 		}
 		if( type == null )

+ 5 - 0
hxsl/Dce.hx

@@ -137,6 +137,11 @@ class Dce {
 			writeTo.pop();
 			check(eif, writeTo);
 			if( eelse != null ) check(eelse, writeTo);
+		case TFor(v, it, loop):
+			writeTo.push(null);
+			check(it, writeTo);
+			check(loop, writeTo);
+			writeTo.pop();
 		default:
 			e.iter(check.bind(_, writeTo));
 		}

+ 4 - 0
hxsl/Eval.hx

@@ -157,6 +157,10 @@ class Eval {
 	function evalCall( g : TGlobal, args : Array<TExpr> ) {
 		return switch( [g,args] ) {
 		case [ToFloat, [ { e : TConst(CInt(i)) } ]]: TConst(CFloat(i));
+		case [Trace, args]:
+			for( a in args )
+				haxe.Log.trace(Printer.toString(a), { fileName : a.p.file, lineNumber : 0, className : null, methodName : null });
+			TBlock([]);
 		default: null;
 		}
 	}

+ 2 - 0
hxsl/SharedShader.hx

@@ -69,7 +69,9 @@ class SharedShader {
 			c = c.next;
 		}
 		eval.inlineCalls = true;
+		#if (js || flash)
 		eval.unrollLoops = true;
+		#end
 		var i = new ShaderInstance(eval.eval(data));
 		#if debug
 		Printer.check(i.shader, [data]);