diff --git a/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs b/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs index e50902d4..c5db9978 100644 --- a/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs @@ -3,7 +3,7 @@ namespace ComputeSharp { /// - /// A shader that indicates that a target shader type should get an automatic constructor for all fields. + /// An attribute that indicates that a target shader type should get an automatic constructor for all fields. /// [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] public sealed class AutoConstructorAttribute : Attribute diff --git a/src/ComputeSharp.Core/Attributes/FieldAttribute.cs b/src/ComputeSharp.Core/Attributes/FieldAttribute.cs new file mode 100644 index 00000000..a61a54c5 --- /dev/null +++ b/src/ComputeSharp.Core/Attributes/FieldAttribute.cs @@ -0,0 +1,44 @@ +using System; + +namespace ComputeSharp +{ + /// + /// An attribute that indicates a field to declare in a custom struct type to use in a shader. + /// This is necessary to be used instead of manually declare fields, so that the fields can be + /// declared with the right offset into the type data, as HLSL requires precise alignment for values. + /// + [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] + public sealed class FieldAttribute : Attribute + { + /// + /// Creates a new instance with the specified parameters. + /// + /// The name of the field to declare. + /// The type of field to declare. + public FieldAttribute(string name, Type type) + { + Name = name; + Type = type; + } + + /// + /// Gets the name of the field to declare. + /// + public string Name { get; } + + /// + /// Gets the type of the field to declare. + /// + public Type Type { get; } + + /// + /// Gets the optional summary for the field to declare. + /// + public string? Summary { get; init; } + + /// + /// Gets the optional remarks for the field to declare. + /// + public string? Remarks { get; init; } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.Core/Attributes/IComputeShaderSource.cs b/src/ComputeSharp.Core/Attributes/IComputeShaderSource.cs index e0c62ded..769819aa 100644 --- a/src/ComputeSharp.Core/Attributes/IComputeShaderSource.cs +++ b/src/ComputeSharp.Core/Attributes/IComputeShaderSource.cs @@ -8,7 +8,7 @@ using System.Reflection; namespace ComputeSharp { /// - /// A shader that indicates that a target shader type should get an automatic constructor for all fields. + /// 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. /// [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] diff --git a/src/ComputeSharp.Core/Attributes/Internals/IsExternalInit.cs b/src/ComputeSharp.Core/Attributes/Internals/IsExternalInit.cs new file mode 100644 index 00000000..ac4cc2ef --- /dev/null +++ b/src/ComputeSharp.Core/Attributes/Internals/IsExternalInit.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if !NET5_0 + +using System.ComponentModel; + +namespace System.Runtime.CompilerServices +{ + /// + /// Reserved to be used by the compiler for tracking metadata. + /// This class should not be used by developers in source code. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + internal static class IsExternalInit + { + } +} + +#endif \ No newline at end of file