Added support for implicit local functions
このコミットが含まれているのは:
1 親
e512c5839e
コミット
4f58fe4f1f
5ファイル変更
+54
-1
検索条件に一致するファイルはありません
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Shaders.Renderer.Models.Functions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains info on a local shader function
|
||||
/// </summary>
|
||||
internal sealed class LocalFunctionInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the prototype for the current function
|
||||
/// </summary>
|
||||
public string FunctionPrototype => FunctionDeclaration.Split(Environment.NewLine)[0];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the declaration of the current function
|
||||
/// </summary>
|
||||
public string FunctionDeclaration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LocalFunctionInfo"/> instance with the specified parameters
|
||||
/// </summary>
|
||||
/// <param name="functionDeclaration">The declaration of the current function</param>
|
||||
public LocalFunctionInfo(string functionDeclaration)
|
||||
{
|
||||
FunctionDeclaration = functionDeclaration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,5 +51,10 @@ namespace ComputeSharp.Shaders.Renderer.Models
|
||||
/// Gets or sets the list of static functions used by the shader
|
||||
/// </summary>
|
||||
public IReadOnlyList<FunctionInfo> FunctionsList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of local (implicit) functions used by the shader
|
||||
/// </summary>
|
||||
public IReadOnlyList<LocalFunctionInfo> LocalFunctionsList { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,12 @@ cbuffer _{{FieldName}} : register(b{{BufferIndex}})
|
||||
{{ReturnType}} {{FunctionName}}({{#ParametersList}}{{ParameterModifier}} {{ParameterType}} {{ParameterName}}{{^IsLastParameter}}, {{/IsLastParameter}}{{/ParametersList}})
|
||||
{{FunctionBody}}
|
||||
{{/FunctionsList}}
|
||||
{{#LocalFunctionsList}}
|
||||
|
||||
{{!Shader implicit functions}}
|
||||
// {{FunctionPrototype}}
|
||||
{{FunctionDeclaration}}
|
||||
{{/LocalFunctionsList}}
|
||||
|
||||
{{!Shader entry point}}
|
||||
// Shader body
|
||||
|
||||
@@ -76,7 +76,8 @@ namespace ComputeSharp.Shaders
|
||||
NumThreadsZ = threadsZ,
|
||||
ThreadsIdsVariableName = shaderLoader.ThreadsIdsVariableName,
|
||||
ShaderBody = shaderLoader.MethodBody,
|
||||
FunctionsList = shaderLoader.FunctionsList
|
||||
FunctionsList = shaderLoader.FunctionsList,
|
||||
LocalFunctionsList = shaderLoader.LocalFunctionsList
|
||||
};
|
||||
string shaderSource = ShaderRenderer.Instance.Render(shaderInfo);
|
||||
|
||||
|
||||
@@ -148,6 +148,13 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
public IReadOnlyList<FunctionInfo> FunctionsList => _FunctionsList;
|
||||
|
||||
private readonly List<LocalFunctionInfo> _LocalFunctionsList = new List<LocalFunctionInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of <see cref="LocalFunctionInfo"/> items for the shader
|
||||
/// </summary>
|
||||
public IReadOnlyList<LocalFunctionInfo> LocalFunctionsList => _LocalFunctionsList;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique hash code for a given <see cref="Action{T}"/>
|
||||
/// </summary>
|
||||
@@ -295,6 +302,11 @@ namespace ComputeSharp.Shaders.Translation
|
||||
ShaderSyntaxRewriter syntaxRewriter = new ShaderSyntaxRewriter(semanticModel);
|
||||
root = (MethodDeclarationSyntax)syntaxRewriter.Visit(root);
|
||||
|
||||
// Extract the implicit local functions
|
||||
var locals = root.DescendantNodes().OfType<LocalFunctionStatementSyntax>().ToArray();
|
||||
root = root.RemoveNodes(locals, SyntaxRemoveOptions.KeepNoTrivia);
|
||||
_LocalFunctionsList.AddRange(locals.Select(local => new LocalFunctionInfo(local.ToString())));
|
||||
|
||||
// Register the captured static members
|
||||
foreach (var member in syntaxRewriter.StaticMembers)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする