Added initial attributes to track methods
このコミットが含まれているのは:
1 親
b6b80141c2
コミット
3a7e7559c3
5ファイル変更
+91
-3
検索条件に一致するファイルはありません
@@ -5,7 +5,7 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a target shader type should get an automatic constructor for all fields.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
[AttributeUsage(AttributeTargets.Struct)]
|
||||
public sealed class AutoConstructorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ using System.Reflection;
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a target shader type should get an automatic constructor for all fields.
|
||||
/// This attribute is not meant to be directly used by applications using ComputeSharp.
|
||||
/// An attribute that contains info on a processed compute shader that can be executed.
|
||||
/// </summary>
|
||||
/// <remarks>This attribute is not meant to be directly used by applications using ComputeSharp.</remarks>
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This attribute is meant to be used from the source generator only")]
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a method will be indirectly used in a compute shader.
|
||||
/// This method is necessary for methods that are captured and used within a given shader
|
||||
/// through a <see cref="Delegate"/> field (of some custom type). In order to be processed
|
||||
/// correctly, wrapped methods need to have this attribute manually applied to them.
|
||||
/// Methods also need to be static, though this can only be tested at runtime.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class ShaderMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that contains info on a processed shader method that can be executed within a shader.
|
||||
/// Instances of this attribute are generated from method annotated with <see cref="ShaderMethodAttribute"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This attribute is not meant to be directly used by applications using ComputeSharp.</remarks>
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This attribute is meant to be used from the source generator only")]
|
||||
public sealed class ShaderMethodSourceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderMethodSourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="methodName">The fully qualified name of the current method.</param>
|
||||
/// <param name="types">The collection of custom types.</param>
|
||||
/// <param name="methods">The collection of processed methods.</param>
|
||||
public ShaderMethodSourceAttribute(string methodName, string[] types, string[] methods)
|
||||
{
|
||||
MethodName = methodName;
|
||||
Types = types;
|
||||
Methods = methods;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified name of the shader type.
|
||||
/// </summary>
|
||||
internal string MethodName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of processed custom types.
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<string> Types { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of processed methods.
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<string> Methods { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the associated <see cref="ShaderMethodSourceAttribute"/> instance for a specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The shader type to get the attribute for.</typeparam>
|
||||
/// <returns>The associated <see cref="IComputeShaderSourceAttribute"/> instance for type <typeparamref name="T"/>.</returns>
|
||||
[Pure]
|
||||
internal static ShaderMethodSourceAttribute GetForDelegate(Delegate function)
|
||||
{
|
||||
Guard.IsTrue(function.Method.IsStatic, "Captured delegates need to wrap static methods");
|
||||
|
||||
Type declaringType = function.Method.DeclaringType;
|
||||
string methodName = $"{declaringType.FullName}.{function.Method.Name}";
|
||||
|
||||
return (
|
||||
from attribute in function.Method.DeclaringType.Assembly.GetCustomAttributes<ShaderMethodSourceAttribute>()
|
||||
where attribute.MethodName == methodName
|
||||
select attribute).Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,10 @@ namespace ComputeSharp.SourceGenerators
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type;
|
||||
|
||||
// Delegate types are not included and are processed separately
|
||||
if (typeSymbol.TypeKind == TypeKind.Delegate) continue;
|
||||
|
||||
string typeName = HlslKnownTypes.GetMappedName(typeSymbol);
|
||||
|
||||
_ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする