Minor code refactoring
このコミットが含まれているのは:
1 親
c231e8506a
コミット
f4bd3f87b9
3ファイル変更
+25
-8
検索条件に一致するファイルはありません
@@ -19,6 +19,16 @@ namespace ComputeSharp
|
||||
[Obsolete("This attribute is meant to be used from the source generator only")]
|
||||
public sealed class ShaderMethodSourceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The identifier for the invoke method, for late binding.
|
||||
/// </summary>
|
||||
internal const string InvokeMethodIdentifier = "__<NAME>__";
|
||||
|
||||
/// <summary>
|
||||
/// The source code for the target entry point method.
|
||||
/// </summary>
|
||||
private readonly string invokeMethod;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderMethodSourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
@@ -28,9 +38,10 @@ namespace ComputeSharp
|
||||
/// <param name="methods">The collection of processed methods.</param>
|
||||
public ShaderMethodSourceAttribute(string methodName, string[] types, string invokeMethod, string[] methods)
|
||||
{
|
||||
this.invokeMethod = invokeMethod;
|
||||
|
||||
MethodName = methodName;
|
||||
Types = types;
|
||||
InvokeMethod = invokeMethod;
|
||||
Methods = methods;
|
||||
}
|
||||
|
||||
@@ -44,16 +55,22 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<string> Types { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source code for the target entry point method.
|
||||
/// </summary>
|
||||
internal string InvokeMethod { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of processed methods.
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<string> Methods { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped source code for the current method.
|
||||
/// </summary>
|
||||
/// <param name="name">The name to bind the method to.</param>
|
||||
/// <returns>The mapped source code for the current mehtod.</returns>
|
||||
[Pure]
|
||||
internal string GetMappedInvokeMethod(string name)
|
||||
{
|
||||
return this.invokeMethod.Replace(InvokeMethodIdentifier, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the associated <see cref="ShaderMethodSourceAttribute"/> instance for a specified type.
|
||||
/// </summary>
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
var methodSource = ShaderMethodSourceAttribute.GetForDelegate(func);
|
||||
|
||||
this.declaredTypes.AddRange(methodSource.Types);
|
||||
this.methodsInfo.Add(methodSource.InvokeMethod.Replace("__<NAME>__", hlslName));
|
||||
this.methodsInfo.Add(methodSource.GetMappedInvokeMethod(hlslName));
|
||||
this.methodsInfo.AddRange(methodSource.Methods);
|
||||
}
|
||||
else ThrowHelper.ThrowArgumentException("Invalid captured variable");
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
// Rewrite the method syntax tree
|
||||
var processedMethod = shaderSourceRewriter
|
||||
.Visit(methodDeclaration)!
|
||||
.WithIdentifier(Identifier("__<NAME>__"))
|
||||
.WithIdentifier(Identifier(ShaderMethodSourceAttribute.InvokeMethodIdentifier))
|
||||
.WithoutTrivia()
|
||||
.NormalizeWhitespace()
|
||||
.ToFullString();
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする