public void Generate(CodeWriter writer, IntrinsicDescription intrinsic) { LocalVariableNamesByType.Clear(); StaticVariableTypes.Clear(); GenerateLocalAndStaticVariables(intrinsic); writer.WriteIndentedLine("[Shader.UnitTest][Shader.Pixel]"); writer.WriteIndentation(); writer.Write("struct "); writer.Write(intrinsic.IntrinsicName); writer.WriteLine("Test"); writer.BeginScope(); DeclareStaticVariables(writer, intrinsic); writer.WriteIndentedLine("[Shader.EntryPoint]"); writer.WriteIndentedLine("public void Main()"); writer.BeginScope(); DeclareLocalVariables(writer, intrinsic); foreach (var signature in intrinsic.Signatures) { Generate(writer, intrinsic, signature); } writer.EndScope(); writer.EndScope(); }
public void Generate(IntrinsicDescription intrinsic, IntrinsicSignature signature) { WriteComments(intrinsic, signature); Writer.WriteIndentation(); // If this intrinsic is disabled, comment it out if (intrinsic.Disabled) { Writer.Write("//"); } WriteAttributes(intrinsic, signature); Writer.Write(signature.Qualifiers); Writer.Write(" "); Writer.Write(signature.ReturnTypeName.ToString()); Writer.Write(" "); Writer.Write(intrinsic.FunctionName); Writer.Write("("); for (var i = 0; i < signature.Parameters.Count; ++i) { var param = signature.Parameters[i]; Writer.Write(param.GetDeclaration()); if (i != signature.Parameters.Count - 1) { Writer.Write(", "); } } Writer.Write(");\n"); }
void DeclareLocalVariables(CodeWriter writer, IntrinsicDescription intrinsic) { foreach (var pair in LocalVariableNamesByType) { writer.WriteIndentation(); writer.DeclareVariable(pair.Value, GenerateDefaultValue(pair.Key)); } }
void DeclareStaticVariables(CodeWriter writer, IntrinsicDescription intrinsic) { foreach (var pair in StaticVariableTypes) { writer.WriteIndentation(); writer.DeclareMemberVariable("public static", pair.Key, pair.Value, null); } }
public void Generate(IntrinsicDescription intrinsic) { foreach (var signature in intrinsic.Signatures) { Generate(intrinsic, signature); } Writer.WriteLine(); }
public IntrinsicDescription Build(string intrinsicName, string functionName, IAttributesGenerator attributes) { var intrinsic = new IntrinsicDescription() { IntrinsicName = intrinsicName, FunctionName = functionName, Attributes = attributes }; Intrinsics.Add(intrinsic); return(intrinsic); }
public void Generate(CodeWriter writer, IntrinsicDescription intrinsic, IntrinsicSignature signature) { writer.WriteIndentation(); writer.Write(GetVariableName(signature.ReturnTypeName)); writer.Write(" = Shader.Intrinsics."); writer.Write(intrinsic.FunctionName); writer.Write("("); for (var i = 0; i < signature.Parameters.Count; ++i) { var param = signature.Parameters[i]; writer.Write(GetVariableName(param.TypeName)); if (i != signature.Parameters.Count - 1) { writer.Write(", "); } } writer.WriteLine(");"); }
void WriteAttributes(IntrinsicDescription intrinsic, IntrinsicSignature signature) { string attributes = null; if (signature.Attributes != null) { attributes = signature.Attributes.GetAttributes(); } else if (intrinsic.Attributes != null) { attributes = intrinsic.Attributes.GetAttributes(); } if (!string.IsNullOrEmpty(attributes)) { Writer.Write(attributes); Writer.Write(" "); } }
void WriteComments(IntrinsicDescription intrinsic, IntrinsicSignature signature) { List <string> comments = null; if (signature.Comments != null) { comments = signature.Comments; } else { comments = intrinsic.Comments; } if (comments != null) { foreach (var comment in comments) { Writer.WriteIndentation(); Writer.Write("// "); Writer.WriteLine(comment); } } }
void GenerateLocalAndStaticVariables(IntrinsicDescription intrinsic) { var variableList = new List <TypeName>(); var variableSet = new HashSet <TypeName>(); AddTypeNameDelegate AddTypeName = (TypeName typeName, HashSet <TypeName> variableSet, List <TypeName> variableList) => { if (variableSet.Contains(typeName)) { return; } variableList.Add(typeName); variableSet.Add(typeName); }; foreach (var signature in intrinsic.Signatures) { AddTypeName(signature.ReturnTypeName, variableSet, variableList); foreach (var param in signature.Parameters) { AddTypeName(param.TypeName, variableSet, variableList); } } foreach (var varType in variableList) { var varName = GenerateLocalVariableName(varType); if (varType.ForcedStatic) { StaticVariableTypes.Add(varType, varName); } else { LocalVariableNamesByType.Add(varType, varName); } } }