public MethodProcessResult VisitFunction(MethodDeclarationSyntax node) { _containingTypeName = Utilities.GetFullNestedTypePrefix((SyntaxNode)node.Body ?? node.ExpressionBody, out bool _); StringBuilder sb = new StringBuilder(); string blockResult; // Visit block first in order to discover builtin variables. if (node.Body != null) { blockResult = VisitBlock(node.Body); } else if (node.ExpressionBody != null) { blockResult = VisitArrowExpressionClause(node.ExpressionBody); } else { throw new NotSupportedException("Methods without bodies cannot be shader functions."); } string functionDeclStr = GetFunctionDeclStr(); if (_shaderFunction.Type == ShaderFunctionType.ComputeEntryPoint) { sb.AppendLine(_backend.GetComputeGroupCountsDeclaration(_shaderFunction.ComputeGroupCounts)); } sb.AppendLine(functionDeclStr); sb.AppendLine(blockResult); return(new MethodProcessResult(sb.ToString(), _resourcesUsed)); }
public MethodProcessResult VisitFunction(BaseMethodDeclarationSyntax node) { _containingTypeName = Utilities.GetFullNestedTypePrefix((SyntaxNode)node.Body ?? node.ExpressionBody, out bool _); StringBuilder sb = new StringBuilder(); string blockResult; // Visit block first in order to discover builtin variables. if (node.Body != null) { _lastVertexEmit = node.Body.Statements.FirstOrDefault(); blockResult = VisitBlock(node.Body); } else if (node.ExpressionBody != null) { _lastVertexEmit = node.ExpressionBody; blockResult = VisitArrowExpressionClause(node.ExpressionBody); } else { throw new NotSupportedException("Methods without bodies cannot be shader functions."); } string functionDeclStr = GetFunctionDeclStr(); if (_shaderFunction.Type == ShaderFunctionType.ComputeEntryPoint) { sb.AppendLine(_backend.GetComputeGroupCountsDeclaration(_shaderFunction.ComputeGroupCounts)); } sb.AppendLine(functionDeclStr); sb.AppendLine(blockResult); foreach (var stream in _emittedData) { foreach (var emission in stream.Value) { ITypeSymbol type; if (emission is ILocalSymbol local) { type = local.Type; } else if (emission is IFieldSymbol field) { type = field.Type; } else { continue; } //_resourcesUsed.RemoveWhere(r => r.Name == emission.Name); _resourcesUsed.Add(new ResourceDefinition(emission.Name, 0, stream.Key, new TypeReference(type.GetFullMetadataName(), type), ShaderResourceKind.Emit)); } } return(new MethodProcessResult(sb.ToString(), _resourcesUsed)); }
public MethodProcessResult VisitFunction(BlockSyntax node) { _containingTypeName = Utilities.GetFullNestedTypePrefix(node, out bool _); StringBuilder sb = new StringBuilder(); string blockResult = VisitBlock(node); // Visit block first in order to discover builtin variables. string functionDeclStr = GetFunctionDeclStr(); if (_shaderFunction.Type == ShaderFunctionType.ComputeEntryPoint) { sb.AppendLine(_backend.GetComputeGroupCountsDeclaration(_shaderFunction.ComputeGroupCounts)); } sb.AppendLine(functionDeclStr); sb.AppendLine(blockResult); return(new MethodProcessResult(sb.ToString(), _resourcesUsed)); }