Selaa lähdekoodia

started texture work

ncannasse 8 vuotta sitten
vanhempi
commit
a4ee95dc57
3 muutettua tiedostoa jossa 84 lisäystä ja 17 poistoa
  1. 24 3
      h3d/impl/DirectXDriver.hx
  2. 9 0
      hxsl/Ast.hx
  3. 51 14
      hxsl/HlslOut.hx

+ 24 - 3
h3d/impl/DirectXDriver.hx

@@ -51,10 +51,7 @@ class DirectXDriver extends h3d.impl.Driver {
 		var depthDesc = new Texture2dDesc();
 		depthDesc.width = width;
 		depthDesc.height = height;
-		depthDesc.mipLevels = 1;
-		depthDesc.arraySize = 1;
 		depthDesc.format = D24_UNORM_S8_UINT;
-		depthDesc.sampleCount = 1;
 		depthDesc.bind = DepthStencil;
 		var depth = Driver.createTexture2d(depthDesc);
 		depthView = Driver.createDepthStencilView(depth,depthDesc.format);
@@ -85,6 +82,12 @@ class DirectXDriver extends h3d.impl.Driver {
 		desc.depthClipEnable = true;
 		var rs = Driver.createRasterizerState(desc);
 		Driver.rsSetState(rs);
+
+		var desc = new SamplerStateDesc();
+		var ss = Driver.createSamplerState(desc);
+		var sarr = new hl.NativeArray(1);
+		sarr[0] = ss;
+		Driver.psSetSamplers(0, 1, sarr);
 	}
 
 	override function isDisposed() {
@@ -120,6 +123,24 @@ class DirectXDriver extends h3d.impl.Driver {
 		return dx.Driver.createBuffer(count << 1, Default, IndexBuffer, None, None, 0, null);
 	}
 
+	override function allocTexture(t:h3d.mat.Texture):Texture {
+		var desc = new Texture2dDesc();
+		desc.width = t.width;
+		desc.height = t.height;
+		desc.format = R8G8B8A8_UNORM;
+		desc.usage = Default;
+		desc.bind = ShaderResource;
+		var tex = Driver.createTexture2d(desc);
+		return tex;
+	}
+
+	override function disposeTexture( t : h3d.mat.Texture ) {
+		var tt = t.t;
+		if( tt == null ) return;
+		t.t = null;
+		tt.release();
+	}
+
 	override function disposeVertexes(v:VertexBuffer) {
 		v.release();
 	}

+ 9 - 0
hxsl/Ast.hx

@@ -346,6 +346,15 @@ class Tools {
 		return false;
 	}
 
+	public static function isSampler( t : Type ) {
+		return switch( t ) {
+		case TSampler2D, TSamplerCube:
+			true;
+		default:
+			false;
+		}
+	}
+
 	public static function toString( t : Type ) {
 		return switch( t ) {
 		case TVec(size, t):

+ 51 - 14
hxsl/HlslOut.hx

@@ -1,5 +1,5 @@
 package hxsl;
-import hxsl.Ast;
+using hxsl.Ast;
 
 class HlslOut {
 
@@ -86,10 +86,8 @@ class HlslOut {
 			add("float4x4");
 		case TMat3x4:
 			add("float4x3");
-		case TSampler2D:
-			add("sampler2D");
-		case TSamplerCube:
-			add("samplerCube");
+		case TSampler2D, TSamplerCube:
+			add("SamplerState");
 		case TStruct(vl):
 			add("struct { ");
 			for( v in vl ) {
@@ -105,8 +103,6 @@ class HlslOut {
 			switch( size ) {
 			case SVar(v):
 				ident(v);
-			case SConst(1):
-				add(2); // intel HD driver fix
 			case SConst(v):
 				add(v);
 			}
@@ -114,6 +110,15 @@ class HlslOut {
 		}
 	}
 
+	function addArraySize( size ) {
+		add("[");
+		switch( size ) {
+		case SVar(v): ident(v);
+		case SConst(n): add(n);
+		}
+		add("]");
+	}
+
 	function addVar( v : TVar ) {
 		switch( v.type ) {
 		case TArray(t, size):
@@ -121,13 +126,7 @@ class HlslOut {
 			v.type = t;
 			addVar(v);
 			v.type = old;
-			add("[");
-			switch( size ) {
-			case SVar(v): ident(v);
-			case SConst(1): add(2); // intel HD driver fix
-			case SConst(n): add(n);
-			}
-			add("]");
+			addArraySize(size);
 		default:
 			addType(v.type);
 			add(" ");
@@ -194,6 +193,24 @@ class HlslOut {
 			var acc = varAccess.get(v.id);
 			if( acc != null ) add(acc);
 			ident(v);
+		case TCall({ e : TGlobal(Texture2D) }, args):
+			switch( args[0].e ) {
+			case TArray(e,index):
+				addValue(e, tabs);
+				add("Tex[");
+				addValue(index, tabs);
+				add("]");
+			default:
+				addValue(args[0], tabs);
+				add("Tex");
+			}
+			add(".Sample(");
+			addValue(args[0],tabs);
+			for( i in 1...args.length ) {
+				add(",");
+				addValue(args[i],tabs);
+			}
+			add(")");
 		case TGlobal(g):
 			switch( g ) {
 			case Mat3x4:
@@ -464,15 +481,35 @@ class HlslOut {
 		add("};\n\n");
 
 
+		var textures = [];
 		add("cbuffer _params : register(b1) {\n");
 		for( v in s.vars )
 			if( v.kind == Param ) {
+				switch( v.type ) {
+				case TArray(t, _) if( t.isSampler() ):
+					textures.push(v);
+					continue;
+				default:
+				}
 				add("\t");
 				addVar(v);
 				add(";\n");
 			}
 		add("};\n\n");
 
+		for( v in textures ) {
+			switch( v.type ) {
+			case TArray(t, size):
+				add("Texture2D ");
+				add(v.name+"Tex");
+				addArraySize(size);
+				add(";\n");
+				addVar(v);
+				add(";\n");
+			default:
+			}
+		}
+
 		add("static s_input _in;\n");
 		add("static s_output _out;\n");