Răsfoiți Sursa

use new Reg class in format

ncannasse 10 ani în urmă
părinte
comite
802137305f
2 a modificat fișierele cu 37 adăugiri și 47 ștergeri
  1. 18 18
      hxsl/AgalOptim.hx
  2. 19 29
      hxsl/AgalOut.hx

+ 18 - 18
hxsl/AgalOptim.hx

@@ -69,7 +69,7 @@ class AgalOptim {
 		for( i in 0...inputs.length )
 			if( inputs[i] ) {
 				changed = true;
-				code.push(OMov(allocTemp(4), { t : RAttr, index : i, swiz : null, access : null } ));
+				code.push(OMov(allocTemp(4), new Reg(RAttr, i, null)));
 			}
 
 		// single writes for out/varying
@@ -104,7 +104,7 @@ class AgalOptim {
 			if( writes[i] > 1 ) {
 				var ri = allocTemp(4);
 				for( op in code ) iter(op, function(r, _) if( r.t == t && r.index == i ) { r.t = RTemp; r.index = ri.index; } );
-				code.push(OMov( { t : t, index : i, access : null, swiz : null }, ri));
+				code.push(OMov( new Reg(t, i, null), ri));
 				changed = true;
 			}
 		}
@@ -172,10 +172,10 @@ class AgalOptim {
 		}
 		var access = null;
 		if( r.access != null ) {
-			access = { comp : sout[0], t : r.access.t, offset : r.access.offset };
+			access = new RegAccess(r.access.t, sout[0], r.access.offset);
 			sout = null;
 		}
-		var r = { t : RTemp, index : inf.index, swiz : sout, access : access };
+		var r = new Reg(RTemp, inf.index, sout, access);
 		if( swizBits(r) == 228 ) r.swiz = null;
 		return r;
 	}
@@ -266,7 +266,7 @@ class AgalOptim {
 	}
 
 	function allocTemp( size : Int ) : Reg {
-		var r = { t : RTemp, index : regs.length, swiz : size == 4 ? null : [for( i in 0...size ) COMPS[i]], access : null };
+		var r = new Reg(RTemp, regs.length, size == 4 ? null : [for( i in 0...size ) COMPS[i]]);
 		regs.push(null);
 		return r;
 	}
@@ -338,7 +338,7 @@ class AgalOptim {
 				//		mov c, X[b]
 				var v = i2.values[r2.access.comp.getIndex()];
 				if( v == null || (v.index == r2.index && v.t == r2.t) ) continue;
-				code[i] = OMov(r1, { t : v.t, index : v.index, swiz : r2.swiz, access : { offset : r2.access.offset, t : r2.access.t, comp : v.swiz[0] }} );
+				code[i] = OMov(r1, new Reg(v.t, v.index, r2.swiz, new RegAccess(r2.access.t, v.swiz[0], r2.access.offset)));
 				changed = true;
 
 			case OMov(r1, r2):
@@ -417,7 +417,7 @@ class AgalOptim {
 							var idx = sw2.indexOf(s);
 							sout.push(sw1[idx]);
 						}
-						return { t : RTemp, index : r1.index, swiz : sout, access : null };
+						return new Reg(RTemp, r1.index, sout);
 					});
 					code[wt] = op;
 				}
@@ -460,7 +460,7 @@ class AgalOptim {
 		if( inf.values == null ) inf.values = [];
 		for( i in 0...swiz.length ) {
 			var s = swiz[i];
-			inf.values[s.getIndex()] = { t : r2.t, index : r2.index, swiz : [swiz2[i]], access : null };
+			inf.values[s.getIndex()] = new Reg(r2.t, r2.index, [swiz2[i]]);
 		}
 		write(r1);
 		return OMov(r1, r2);
@@ -493,7 +493,7 @@ class AgalOptim {
 				inf.values = null;
 			else if( inf.values != null )
 				for( s in r.swiz )
-					inf.values[s.getIndex()] = { t : RTemp, index : r.index, swiz : [s], access : null };
+					inf.values[s.getIndex()] = new Reg(RTemp, r.index, [s]);
 			this.write(r);
 			return r;
 		}
@@ -502,7 +502,7 @@ class AgalOptim {
 			return r;
 		}
 		var swiz = swiz(r);
-		var reg = { t : null, index : 0, swiz : [], access : null };
+		var reg = new Reg(null, 0, []);
 		for( s in swiz ) {
 			var v = inf.values[s.getIndex()];
 			if( v == null ) {
@@ -581,8 +581,8 @@ class AgalOptim {
 		return a.t == b.t && a.access == null && b.access == null ? b.index - a.index : 1000;
 	}
 
-	function noSwiz( r : Reg ) {
-		return { t : r.t, swiz : null, access : null, index : r.index };
+	inline function noSwiz( r : Reg ) {
+		return new Reg(r.t, r.index, null);
 	}
 
 	function optiDup() {
@@ -594,7 +594,7 @@ class AgalOptim {
 				var op1 = code[p1];
 				if( op1 == null ) continue;
 				switch( op1 ) {
-				case OMov(_): continue;
+				case OMov(_), OTex(_): continue;
 				default:
 				}
 				for( r2 in regs ) {
@@ -638,7 +638,7 @@ class AgalOptim {
 				switch( [code[i + 1], code[i + 2]] ) {
 				case [ODp3(d2, a2, b2), ODp3(d3, a3, b3)]:
 					if( same(dst, d2) && same(dst, d3) && same(a, a2) && same(a, a3) && swizBits(a2)&63 == sa && swizBits(a3)&63 == sa && dist(b, b2) == 1 && dist(b, b3) == 2 && swizBits(d2) == 1 && swizBits(d3) == 2 && swizBits(b2)&63 == XYZ && swizBits(b3)&63 == XYZ ) {
-						var dst = Reflect.copy(dst);
+						var dst = dst.clone();
 						dst.swiz = [X, Y, Z];
 						code[i] = OM33(dst, a, noSwiz(b));
 						code[i + 1] = OUnused;
@@ -659,7 +659,7 @@ class AgalOptim {
 									m44 = true;
 							default:
 							}
-						var dst = Reflect.copy(dst);
+						var dst = dst.clone();
 						dst.swiz = m44 ? null : [X,Y,Z];
 						code[i] = (m44?OM44:OM34)(dst, sa == XYZW ? noSwiz(a) : a, noSwiz(b));
 						code[i + 1] = OUnused;
@@ -683,7 +683,7 @@ class AgalOptim {
 			reg(r, false);
 		case OMov(d, v):
 			if( v.access != null )
-				reg( { t : v.t, index : v.index, access : null, swiz : [v.access.comp] }, false );
+				reg( new Reg(v.t, v.index, [v.access.comp]), false );
 			else
 				reg(v, false);
 			reg(d, true);
@@ -785,12 +785,12 @@ class AgalOptim {
 	inline function rswiz( r : Reg, s : Array<C> ) : Reg {
 		if( r.access != null ) throw "assert";
 		var swiz = swiz(r);
-		return { t : r.t, index : r.index, swiz : [for( s in s ) swiz[s.getIndex()]], access : null };
+		return new Reg(r.t, r.index, [for( s in s ) swiz[s.getIndex()]]);
 	}
 
 	inline function offset( r : Reg, n : Int ) : Reg {
 		if( r.access != null ) throw "assert";
-		return { t : r.t, index : r.index + n, swiz : r.swiz == null ? null : r.swiz.copy(), access : null };
+		return new Reg(r.t, r.index + n, r.swiz == null ? null : r.swiz.copy());
 	}
 
 }

+ 19 - 29
hxsl/AgalOut.hx

@@ -26,7 +26,7 @@ class AgalOut {
 
 	public function compile( s : RuntimeShaderData, version ) : Data {
 		current = s;
-		nullReg = { t : RTemp, index : -1, swiz : null, access : null };
+		nullReg = new Reg(RTemp, -1, null);
 		this.version = version;
 		opcodes = [];
 		tmpCount = 0;
@@ -41,20 +41,20 @@ class AgalOut {
 			case Param, Global:
 				switch( v.type ) {
 				case TArray(TSampler2D | TSamplerCube, SConst(n)):
-					r = { t : RTexture, index : texCount, swiz : null, access : null };
+					r = new Reg(RTexture, texCount, null);
 					texCount += n;
 				default:
-					r = { t : RConst, index : paramCount, swiz : defSwiz(v.type), access : null };
+					r = new Reg(RConst, paramCount, defSwiz(v.type));
 					paramCount += regSize(v.type);
 				}
 			case Var:
-				r = { t : RVar, index : v.id, swiz : defSwiz(v.type), access : null };
+				r = new Reg(RVar, v.id, defSwiz(v.type));
 				varying.push(r);
 			case Output:
-				r = { t : ROut, index : outCount, swiz : defSwiz(v.type), access : null };
+				r = new Reg(ROut, outCount, defSwiz(v.type));
 				outCount += regSize(v.type);
 			case Input:
-				r = { t : RAttr, index : inputCount, swiz : defSwiz(v.type), access : null };
+				r = new Reg(RAttr, inputCount, defSwiz(v.type));
 				inputCount += regSize(v.type);
 			case Local, Function:
 				continue;
@@ -105,9 +105,9 @@ class AgalOut {
 			if( v.length == 0 ) continue;
 			for( i in 0...opcodes.length )
 				switch( opcodes[i] ) {
-				case OMov(dst = { t : RVar, index : idx }, val) if( idx == vid ):
-					var dst = Reflect.copy(dst);
-					var val = Reflect.copy(val);
+				case OMov(dst, val) if( dst.index == vid && dst.t == RVar ):
+					var dst = dst.clone();
+					var val = val.clone();
 					val.swiz = null;
 					dst.swiz = null;
 					opcodes[i] = OMov(dst, val);
@@ -150,22 +150,12 @@ class AgalOut {
 		var sw = sw;
 		if( r.swiz != null )
 			sw = [for( c in sw ) r.swiz[c.getIndex()]];
-		return {
-			t : r.t,
-			index : r.index,
-			swiz : sw,
-			access : null
-		};
+		return new Reg(r.t, r.index, sw);
 	}
 
 	inline function offset( r : Reg, k : Int ) : Reg {
 		if( r.access != null ) throw "assert";
-		return {
-			t : r.t,
-			index : r.index + k,
-			swiz : r.swiz == null ? null : r.swiz.copy(),
-			access : null,
-		};
+		return new Reg(r.t, r.index + k, r.swiz == null ? null : r.swiz.copy());
 	}
 
 	function getConst( v : Float ) : Reg {
@@ -178,7 +168,7 @@ class AgalOut {
 					g = g.next;
 				}
 				var p = g.pos + i;
-				return { t : RConst, index : p >> 2, swiz : [COMPS[p & 3]], access : null };
+				return new Reg(RConst, p >> 2, [COMPS[p & 3]]);
 			}
 		throw "Missing required const "+v;
 	}
@@ -201,7 +191,7 @@ class AgalOut {
 					g = g.next;
 				}
 				var p = g.pos + i;
-				return { t : RConst, index : p >> 2, swiz : defSwiz(TVec(va.length,VFloat)), access : null };
+				return new Reg(RConst, p >> 2, defSwiz(TVec(va.length,VFloat)));
 			}
 		}
 		throw "Missing required consts "+va;
@@ -271,7 +261,7 @@ class AgalOut {
 					for( i in 0...stride )
 						swiz.push(COMPS[(i + index) & 3]);
 				} else if( index & 3 != 0 ) throw "assert"; // not register-aligned !
-				return { t : r.t, index : r.index + (index>>2), swiz : swiz, access : null };
+				return new Reg(r.t, r.index + (index>>2), swiz);
 			default:
 				var r = expr(ea);
 				var delta = 0;
@@ -293,7 +283,7 @@ class AgalOut {
 				if( r.swiz != null || r.access != null ) throw "assert";
 				if( i.swiz == null || i.swiz.length != 1 || i.access != null ) throw "assert";
 				var out = allocReg();
-				op(OMov(out, { t : i.t, index : i.index, swiz : null, access : { t : r.t, offset : r.index + delta, comp : i.swiz[0] } } ));
+				op(OMov(out, new Reg(i.t, i.index, null, new RegAccess(r.t, i.swiz[0], r.index + delta))));
 				return out;
 			}
 		case TSwiz(e, regs):
@@ -378,7 +368,7 @@ class AgalOut {
 					op(OMov(swiz(r, [W]), getConst(1)));
 					r1 = r;
 				} else {
-					r1 = Reflect.copy(r1);
+					r1 = r1.clone();
 					r1.swiz = null;
 				}
 				op(ODp4(swiz(r,[X]), r1, r2));
@@ -709,7 +699,7 @@ class AgalOut {
 				throw "assert " + args[i].t;
 			}
 			for( i in 0...regs.length ) {
-				regs[i] = Reflect.copy(regs[i]);
+				regs[i] = regs[i].clone();
 				if( regs[i].swiz == null ) regs[i].swiz = defSwiz.copy();
 				if( regs[i].access != null ) throw "assert";
 			}
@@ -722,7 +712,7 @@ class AgalOut {
 					sr.push(regs[0].swiz.shift());
 				}
 				if( regs[0].swiz.length == 0 ) regs.shift();
-				var m = OMov( { t : RTemp, index : w, swiz : sw, access : null }, { t : r.t, index : r.index, swiz : sr, access : null } );
+				var m = OMov( new Reg(RTemp, w, sw), new Reg(r.t, r.index, sr) );
 				op(m);
 			}
 		}
@@ -763,7 +753,7 @@ class AgalOut {
 	}
 
 	function allocReg( ?t : Type ) : Reg {
-		var r = { t : RTemp, index : tmpCount, swiz : t == null ? null : defSwiz(t), access : null };
+		var r = new Reg(RTemp, tmpCount, t == null ? null : defSwiz(t));
 		tmpCount += t == null ? 1 : regSize(t);
 		return r;
 	}