Bläddra i källkod

Adding "flat" qualifier on hxsl variables, i.e. not interpolated.

clementlandrin 7 månader sedan
förälder
incheckning
f674a25c60
8 ändrade filer med 23 tillägg och 4 borttagningar
  1. 1 0
      hxsl/Ast.hx
  2. 3 1
      hxsl/Checker.hx
  3. 1 0
      hxsl/Flatten.hx
  4. 2 0
      hxsl/GlslOut.hx
  5. 2 0
      hxsl/MacroParser.hx
  6. 1 0
      hxsl/Printer.hx
  7. 2 1
      hxsl/Serializer.hx
  8. 11 2
      hxsl/Splitter.hx

+ 1 - 0
hxsl/Ast.hx

@@ -102,6 +102,7 @@ enum VarQualifier {
 	Borrow( source : String );
 	Sampler( name : String );
 	Final;
+	Flat;
 }
 
 enum Prec {

+ 3 - 1
hxsl/Checker.hx

@@ -801,7 +801,7 @@ class Checker {
 					checkConst(e);
 					einit = e;
 				}
-				if( v.type == null ) error("Type required for variable declaration", e.pos);				
+				if( v.type == null ) error("Type required for variable declaration", e.pos);
 				if( isImport && v.kind == Param )
 					continue;
 
@@ -874,6 +874,7 @@ class Checker {
 			name : v.name,
 			kind : v.kind,
 			type : v.type,
+			qualifiers : v.qualifiers
 		};
 		if( parent != null )
 			tv.parent = parent;
@@ -932,6 +933,7 @@ class Checker {
 					default: error("Sampler should be on sampler type or sampler array", pos);
 					}
 				case Ignore, Doc(_):
+				case Flat: if( tv.kind != Local ) error("flat only allowed on local", pos);
 				}
 		}
 		if( tv.type != null )

+ 1 - 0
hxsl/Flatten.hx

@@ -168,6 +168,7 @@ class Flatten {
 				name : v.name,
 				type : TArray(TVec(4,VFloat),SConst(size)),
 				kind : v.kind,
+				qualifiers : v.qualifiers
 			};
 			var a = new Alloc(v2,VFloat,0,0);
 			a.v = v;

+ 2 - 0
hxsl/GlslOut.hx

@@ -746,6 +746,8 @@ class GlslOut {
 		case Input:
 			add( isES2 ? "attribute " : "in ");
 		case Var:
+			if ( Tools.hasQualifier(v, Flat) )
+				add("flat ");
 			add( isES2 ? "varying " : (isVertex ? "out " : "in "));
 		case Output:
 			if( isES2 ) {

+ 2 - 0
hxsl/MacroParser.hx

@@ -78,6 +78,8 @@ class MacroParser {
 			v.qualifiers.push(Ignore);
 		case "perInstance":
 			v.qualifiers.push(PerInstance(1));
+		case "flat":
+			v.qualifiers.push(Flat);
 		default:
 			error("Unsupported qualifier " + m.name, m.pos);
 		}

+ 1 - 0
hxsl/Printer.hx

@@ -65,6 +65,7 @@ class Printer {
 				case Borrow(s): "borrow(" + s + ")";
 				case Sampler(s): "sampler("+ s + ")";
 				case Final: "final";
+				case Flat: "flat";
 				}) + " ");
 		}
 		if( v.kind != defKind )

+ 2 - 1
hxsl/Serializer.hx

@@ -209,7 +209,7 @@ class Serializer {
 			for( q in v.qualifiers ) {
 				out.addByte(q.getIndex());
 				switch (q) {
-				case Private, Nullable, PerObject, Shared, Ignore, Final:
+				case Private, Nullable, PerObject, Shared, Ignore, Final, Flat:
 				case Const(max): out.addInt32(max == null ? 0 : max);
 				case Name(n): writeString(n);
 				case Precision(p): out.addByte(p.getIndex());
@@ -439,6 +439,7 @@ class Serializer {
 				case 11: Borrow(readString());
 				case 12: Sampler(readString());
 				case 13: Final;
+				case 14: Flat;
 				default: throw "assert";
 				}
 				v.qualifiers.push(q);

+ 11 - 2
hxsl/Splitter.hx

@@ -261,8 +261,17 @@ class Splitter {
 						kind : v.kind,
 						type : v.type,
 					};
-					if( v.qualifiers != null && v.qualifiers.indexOf(Final) >= 0 )
-						nv.qualifiers = [Final];
+					if( v.qualifiers != null ) {
+						for ( q in v.qualifiers ) {
+							switch (q) {
+							case Final, Flat:
+								if ( nv.qualifiers == null )
+									nv.qualifiers = [];
+								nv.qualifiers.push(q);
+							case Const(_), Private, Nullable, PerObject, Name(_), Shared, Precision(_), Range(_,_), Ignore, PerInstance(_), Doc(_), Borrow(_), Sampler(_):
+							}
+						}
+					}
 					uniqueName(nv);
 				}
 				varMap.set(v,nv);