Browse Source

added @shared params and precision qualifiers

Nicolas Cannasse 11 years ago
parent
commit
25e700dc21
6 changed files with 42 additions and 1 deletions
  1. 8 0
      hxsl/Ast.hx
  2. 9 0
      hxsl/Checker.hx
  3. 11 0
      hxsl/GlslOut.hx
  4. 4 1
      hxsl/Linker.hx
  5. 8 0
      hxsl/MacroParser.hx
  6. 2 0
      hxsl/Printer.hx

+ 8 - 0
hxsl/Ast.hx

@@ -74,6 +74,14 @@ enum VarQualifier {
 	Nullable;
 	PerObject;
 	Name( n : String );
+	Shared;
+	Precision( p : Prec );
+}
+
+enum Prec {
+	Low;
+	Medium;
+	High;
 }
 
 typedef VarDecl = {

+ 9 - 0
hxsl/Checker.hx

@@ -616,6 +616,15 @@ class Checker {
 				case Name(_):
 					if( parent != null ) error("Cannot have an explicit name for a structure variable", pos);
 					if( tv.kind != Global ) error("Explicit name is only allowed for global var", pos);
+				case Shared:
+					if( parent != null ) error("Cannot share a structure field", pos);
+					if( tv.kind != Param ) error("Can only share a @param", pos);
+				case Precision(_):
+					switch( v.type ) {
+					case TVec(_, VFloat), TFloat:
+					default:
+						error("Precision qualifier not supported on " + v.type, pos);
+					}
 				}
 		}
 		if( tv.type != null )

+ 11 - 0
hxsl/GlslOut.hx

@@ -370,6 +370,17 @@ class GlslOut {
 			case Function, Output: continue;
 			case Local:
 			}
+			if( v.qualifiers != null )
+				for( q in v.qualifiers )
+					switch( q ) {
+					case Precision(p):
+						switch( p ) {
+						case Low: add("lowp ");
+						case Medium: add("mediump ");
+						case High: add("highp ");
+						}
+					default:
+					}
 			addVar(v);
 			add(";\n");
 		}

+ 4 - 1
hxsl/Linker.hx

@@ -111,7 +111,10 @@ class Linker {
 			for( vm in v2.merged )
 				if( vm == v )
 					return v2;
-			if( v.kind == Param || v.kind == Function || (v.kind == Var && v.hasQualifier(Private)) ) {
+			inline function isUnique( v : TVar ) {
+				return (v.kind == Param && !v.hasQualifier(Shared)) || v.kind == Function || (v.kind == Var && v.hasQualifier(Private));
+			}
+			if( isUnique(v) || isUnique(v2.v) || (v.kind == Param && v2.v.kind == Param) /* two shared : one takes priority */ ) {
 				// allocate a new unique name in the shader if already in use
 				var k = 2;
 				while( true ) {

+ 8 - 0
hxsl/MacroParser.hx

@@ -39,6 +39,14 @@ class MacroParser {
 			v.qualifiers.push(Nullable);
 		case "perObject":
 			v.qualifiers.push(PerObject);
+		case "shared":
+			v.qualifiers.push(Shared);
+		case "lowp":
+			v.qualifiers.push(Precision(Low));
+		case "mediump":
+			v.qualifiers.push(Precision(Medium));
+		case "highp":
+			v.qualifiers.push(Precision(High));
 		default:
 			error("Unsupported qualifier " + m.name, m.pos);
 		}

+ 2 - 0
hxsl/Printer.hx

@@ -56,6 +56,8 @@ class Printer {
 				case Nullable: "nullable";
 				case PerObject: "perObject";
 				case Name(n): "name('" + n + "')";
+				case Shared: "shared";
+				case Precision(p): Std.string(p).toLowerCase() + "p";
 				}) + " ");
 		}
 		if( v.kind != defKind )