Bläddra i källkod

move texture decls outside of buffer and assign them a register to prevent compiler reordering

Nicolas Cannasse 3 år sedan
förälder
incheckning
7b40917578
1 ändrade filer med 15 tillägg och 3 borttagningar
  1. 15 3
      hxsl/HlslOut.hx

+ 15 - 3
hxsl/HlslOut.hx

@@ -734,11 +734,15 @@ class HlslOut {
 				switch( v.type ) {
 				switch( v.type ) {
 				case TArray(t, _) if( t.isSampler() ):
 				case TArray(t, _) if( t.isSampler() ):
 					textures.push(v);
 					textures.push(v);
+					continue;
 				case TBuffer(_):
 				case TBuffer(_):
 					buffers.push(v);
 					buffers.push(v);
 					continue;
 					continue;
 				default:
 				default:
-					if( v.type.isSampler() ) textures.push(v);
+					if( v.type.isSampler() ) {
+						textures.push(v);
+						continue;
+					}
 				}
 				}
 				add("\t");
 				add("\t");
 				addVar(v);
 				addVar(v);
@@ -756,11 +760,19 @@ class HlslOut {
 		if( bufCount > 0 ) add("\n");
 		if( bufCount > 0 ) add("\n");
 
 
 		var ctx = new Samplers();
 		var ctx = new Samplers();
-		for( v in textures )
+		var texCount = 0;
+		for( v in textures ) {
+			addVar(v);
+			add(' : register(t${texCount});\n');
+			switch( v.type ) {
+			case TArray(_,SConst(n)): texCount += n;
+			default: texCount++;
+			}
 			samplers.set(v.id, ctx.make(v, []));
 			samplers.set(v.id, ctx.make(v, []));
+		}
 
 
 		if( ctx.count > 0 )
 		if( ctx.count > 0 )
-			add('SamplerState __Samplers[${ctx.count}];\n');
+			add('SamplerState __Samplers[${ctx.count}] : register(s0);\n');
 	}
 	}
 
 
 	function initStatics( s : ShaderData ) {
 	function initStatics( s : ShaderData ) {