public static string SimpleFunctionCallTest() { using (HlslProgram program = new HlslProgram()) { Type vsData = CreateVSType(program); Type f1 = TypeRegistry.GetFloatType(); Type f4 = TypeRegistry.GetVectorType(f1, 4); DeclExpr wvpMatrixDecl = new DeclExpr(TypeRegistry.GetMatrixType(f4, 4), "WorldViewProjection"); program.AddGlobal(wvpMatrixDecl); UserDefinedFunction udf = new UserDefinedFunction("vs_main"); Value argValue = udf.AddArgument(vsData); DeclExpr output = new DeclExpr(vsData); udf.AddExpr(output); // Initialize the position element -- multiply input position by WVP matrix. Function fn = program.GetFunctionByName("mul"); CallExpr wvpMul = new CallExpr(fn, new Expr[] { new StructMemberExpr(argValue, "position"), wvpMatrixDecl }); udf.AddExpr(new AssignmentExpr(new StructMemberExpr(output.Value, "position").Value, wvpMul.Value)); // Initialize the rest of the struct to zero. StructMemberExpr[] otherMembers = new StructMemberExpr[] { new StructMemberExpr(output.Value, 1), new StructMemberExpr(output.Value, 2), new StructMemberExpr(output.Value, 3), new StructMemberExpr(output.Value, 4), }; udf.AddExpr(new CommentExpr("Ensuring that a valid comment is being emitted.")); udf.AddExpr(new CommentExpr("Even one that consists of multiple lines.")); udf.AddExpr(new CommentExpr(string.Format("Or embedded newlines.{0}Like this!", Environment.NewLine))); udf.AddExpr(new CommentExpr("Or this.\n(not a proper newline.)")); foreach (StructMemberExpr SME in otherMembers) udf.AddExpr(new AssignmentExpr(SME.Value, new LiteralExpr(SME.Value.ValueType).Value)); udf.AddExpr(new ReturnExpr(output)); program.AddFunction(udf); return program.EmitRawShaderCode(); } }
public static string SimpleStructMemberTest() { using (HlslProgram program = new HlslProgram()) { Type vsData = CreateVSType(program); UserDefinedFunction udf = new UserDefinedFunction("vs_main"); Value argValue = udf.AddArgument(vsData); DeclExpr output = new DeclExpr(vsData); udf.AddExpr(output); udf.AddExpr(new AssignmentExpr( new StructMemberExpr(output.Value, "position").Value, new StructMemberExpr(argValue, "position").Value)); StructMemberExpr[] otherMembers = new StructMemberExpr[] { new StructMemberExpr(output.Value, 1), new StructMemberExpr(output.Value, 2), new StructMemberExpr(output.Value, 3), new StructMemberExpr(output.Value, 4), }; foreach (StructMemberExpr SME in otherMembers) udf.AddExpr(new AssignmentExpr(SME.Value, new LiteralExpr(SME.Value.ValueType).Value)); udf.AddExpr(new ReturnExpr(output)); program.AddFunction(udf); return program.EmitRawShaderCode(); } }