From d6228da210a53684ba70ae41c4211644920fa9db Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 11 Jan 2021 18:08:25 +0100 Subject: [PATCH] Added GroupSharedAttribute type --- .../Attributes/AutoConstructorAttribute.cs | 2 +- .../Attributes/GroupSharedAttribute.cs | 46 +++++++++++++++++++ .../Attributes/ShaderMethodAttribute.cs | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs diff --git a/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs b/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs index bd4dc3e7..c5db9978 100644 --- a/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs @@ -5,7 +5,7 @@ namespace ComputeSharp /// /// An attribute that indicates that a target shader type should get an automatic constructor for all fields. /// - [AttributeUsage(AttributeTargets.Struct)] + [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] public sealed class AutoConstructorAttribute : Attribute { } diff --git a/src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs b/src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs new file mode 100644 index 00000000..06f561ba --- /dev/null +++ b/src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs @@ -0,0 +1,46 @@ +using System; + +namespace ComputeSharp +{ + /// + /// An attribute that indicates that an array static field in a shader type will be shared in a thread group. + /// + /// This attribute can be used to declare fields as follows: + /// + /// struct MyShader : IComputeShader + /// { + /// [GroupShared(32)] + /// static float[] MyBuffer; + /// } + /// + /// + /// The buffer shouldn't be manually initialized, as each shader invocation will automatically receive the + /// right buffer in use for the thread group it belongs to. If there is an assignment for the field, it + /// will just be ignored in the shader. Additionally, buffer types are not allowed as array items. + /// + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] + public sealed class GroupSharedAttribute : Attribute + { + /// + /// Creates a new instance with the specified parameters. + /// + public GroupSharedAttribute() + { + } + + /// + /// Creates a new instance with the specified parameters. + /// + /// The size of the shared buffer to declare. + public GroupSharedAttribute(int size) + { + Size = size; + } + + /// + /// Gets the size of the shared buffer being declared. + /// If , the thread group size will be used. + /// + public int? Size { get; } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs b/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs index 9eae4f37..d644045c 100644 --- a/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs @@ -9,7 +9,7 @@ namespace ComputeSharp /// 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. /// - [AttributeUsage(AttributeTargets.Method)] + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class ShaderMethodAttribute : Attribute { }