protected override void OnTranslate(ShaderTranslationContext sc, MethodDeclarationSyntax syntax, ScopeInfo scope) { MethodInfo info = sc.GetMethodInfo(syntax); if (info != null) { MappedEntryPoint ep = null; sc.EntryPointsByMethod.TryGetValue(info, out ep); sc.Source.AppendLineBreak(); ScopeInfo mScope = sc.Source.OpenScope(ScopeType.Method, null, ep); mScope.Method = info; ShaderType returnType = ShaderType.TranslateType(sc, syntax.ReturnType.ToString()); ep?.Translator?.TranslatePrefix(sc, info, syntax, ep); sc.Source.Append($"{returnType.Translation} {syntax.Identifier.ValueText}"); sc.Complete(syntax.ReturnType); sc.Complete(syntax.ConstraintClauses); sc.Complete(syntax.AttributeLists); if (syntax.TypeParameterList != null) { sc.CompleteSelfAndChildren(syntax.TypeParameterList); } // Translate parameters before method body. sc.Runner.Translate(sc, syntax.ParameterList, 0); ep?.Translator?.TranslatePostfix(sc, info, syntax, ep); } }
protected override void OnTranslate(ShaderTranslationContext sc, ParameterSyntax syntax, ScopeInfo scope) { ScopeInfo methodScope = scope.FindOfType(ScopeType.Method); MethodInfo methodInfo = null; MappedEntryPoint ep = null; if (scope.Type == ScopeType.Parentheses) { if (scope.Items.Last() != syntax) { sc.Source.OpenScope(ScopeType.ParenthesesItem); } } if (methodScope != null) { methodInfo = methodScope.Method; sc.EntryPointsByMethod.TryGetValue(methodInfo, out ep); } // TODO pass to language variable translation, since parameters can have attributes ShaderType type = ShaderType.TranslateType(sc, syntax.Type.ToString()); bool wasAppended = false; if (ep != null) { (ParameterInfo pInfo, int pIndex) = sc.GetParameterInfo(methodInfo, syntax.Identifier.ValueText); IEnumerable <Attribute> pAttributes = pInfo.GetCustomAttributes(); ep.Translator?.TranslateParameterPrefix(sc, syntax, ep, pInfo, pAttributes, pIndex); sc.Source.Append($"{type.Translation} {syntax.Identifier.ValueText}"); ep.Translator?.TranslateParameterPostfix(sc, syntax, ep, pInfo, pAttributes, pIndex); wasAppended = true; } if (!wasAppended) { sc.Source.Append($"{type.Translation} {syntax.Identifier.ValueText}"); } sc.Complete(syntax.Type); sc.Complete(syntax.AttributeLists); }
public override void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) { HullShaderAttribute attHull = ep.Attribute as HullShaderAttribute; string patchType = attHull.PatchType.ToString().ToLower(); sc.Source.Append($"[domain(\"{patchType}\")]"); sc.Source.AppendLineBreak(); string partType = _partitionNames[attHull.Partitioning]; sc.Source.Append($"[partitioning(\"{partType}\")]"); sc.Source.AppendLineBreak(); string topology = _topologyNames[attHull.Topology]; sc.Source.Append($"[outputtopology(\"{topology}\")]"); sc.Source.AppendLineBreak(); sc.Source.Append($"[outputcontrolpoints({attHull.OutputControlPoints})]"); sc.Source.AppendLineBreak(); sc.Source.Append($"[patchconstantfunc(\"{attHull.PatchConstantCallback}\")]"); sc.Source.AppendLineBreak(); }
protected virtual void TranslateParameterAttributePostfix(ShaderTranslationContext sc, Attribute attribute, ParameterInfo pInfo, MappedEntryPoint ep) { }
public virtual void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) { }
public virtual void TranslatePostfix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) { SemanticAttribute attSemantic = info.GetCustomAttribute <SemanticAttribute>(); if (attSemantic != null) { TranslateSemantic(sc, attSemantic); } }
public virtual void TranslateParameterPostfix(ShaderTranslationContext sc, ParameterSyntax syntax, MappedEntryPoint ep, ParameterInfo pInfo, IEnumerable <Attribute> attributes, int parameterIndex) { foreach (Attribute a in attributes) { switch (a) { case SemanticAttribute attSemantic: TranslateSemantic(sc, attSemantic); break; default: TranslateParameterAttributePostfix(sc, a, pInfo, ep); break; } } }
public virtual void TranslateParameterPrefix(ShaderTranslationContext sc, ParameterSyntax syntax, MappedEntryPoint ep, ParameterInfo pInfo, IEnumerable <Attribute> attributes, int parameterIndex) { foreach (Attribute a in attributes) { TranslateParameterAttributePrefix(sc, a, pInfo, ep); } }
public override void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) { DomainShaderAttribute attHull = ep.Attribute as DomainShaderAttribute; string patchType = attHull.PatchType.ToString().ToLower(); sc.Source.Append($"[domain(\"{patchType}\")]"); sc.Source.AppendLineBreak(); base.TranslatePrefix(sc, info, syntax, ep); }
public override void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) { ComputeShaderAttribute attCompute = ep.Attribute as ComputeShaderAttribute; sc.Source.Append($"[numthreads({attCompute.ThreadsX}, {attCompute.ThreadsY}, {attCompute.ThreadsZ})]"); sc.Source.AppendLineBreak(); base.TranslatePrefix(sc, info, syntax, ep); }