diff --git a/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs b/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs index b3066e31..337325d7 100644 --- a/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs +++ b/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs @@ -114,6 +114,22 @@ namespace ComputeSharp.Shaders.Renderer } } + // Shared buffers + foreach (var buffer in info.SharedBuffers) + { + builder.AppendLine(); + builder.Append("groupshared "); + builder.Append(buffer.Value.Type); + builder.Append(' '); + builder.Append(buffer.Key); + builder.Append('['); + + if (buffer.Value.Count is int count) builder.Append(count.ToString()); + else builder.Append((threadsX * threadsY * threadsZ).ToString()); + + builder.AppendLine("];"); + } + // Captured methods foreach (var function in info.MethodsInfo) { diff --git a/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs index bf21f77e..0ff336a8 100644 --- a/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs @@ -11,31 +11,36 @@ namespace ComputeSharp.Shaders.Translation /// /// Gets the generated source code for the method in the current shader. /// - public string EntryPoint { get; } + string EntryPoint { get; } /// /// Gets the collection of items for the shader fields. /// - public IReadOnlyList HlslResourceInfo { get; } + IReadOnlyList HlslResourceInfo { get; } /// /// Gets the collection of items for the shader fields. /// - public IReadOnlyList FieldsInfo { get; } + IReadOnlyList FieldsInfo { get; } /// /// Gets the collection of methods to be used in the shader. /// - public IReadOnlyCollection MethodsInfo { get; } + IReadOnlyCollection MethodsInfo { get; } /// /// Gets the collection of constants to be declared in the shader. /// - public IReadOnlyDictionary ConstantsInfo { get; } + IReadOnlyDictionary ConstantsInfo { get; } /// /// Gets the collection of declared types for the shader. /// - public IReadOnlyCollection DeclaredTypes { get; } + IReadOnlyCollection DeclaredTypes { get; } + + /// + /// Gets the collection of discovered constants. + /// + IReadOnlyDictionary SharedBuffers { get; } } } diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs index 12606154..af601973 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs @@ -104,6 +104,9 @@ namespace ComputeSharp.Shaders.Translation /// public IReadOnlyCollection DeclaredTypes => this.declaredTypes; + /// + public IReadOnlyDictionary SharedBuffers { get; private set; } + /// /// Loads and processes an input shadeer. /// @@ -131,6 +134,7 @@ namespace ComputeSharp.Shaders.Translation private void LoadMethodMetadata() { EntryPoint = Attribute.ExecuteMethod; + SharedBuffers = Attribute.SharedBuffers; this.declaredTypes.AddRange(Attribute.Types); this.methodsInfo.AddRange(Attribute.Methods);