From 5da64a84afe70621b739c52b171c87e91145b8bc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 26 Nov 2020 15:29:39 +0100 Subject: [PATCH] Added support for local shader functions --- .../Renderer/HlslShaderRenderer.cs | 7 +++++++ .../Translation/ShaderLoader{T}.cs | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs b/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs index be62d81b..82912f3b 100644 --- a/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs +++ b/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs @@ -88,6 +88,13 @@ namespace ComputeSharp.Shaders.Renderer } } + // Local functions + foreach (var function in info.LocalFunctionsList) + { + builder.AppendLine(); + builder.AppendLine(function); + } + // Entry point builder.AppendLine(); builder.Append("[NumThreads("); diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs index fbb2076f..4ae7849b 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs @@ -25,7 +25,7 @@ namespace ComputeSharp.Shaders.Translation /// /// The associated instance for the current shader type. /// - private static IComputeShaderSourceAttribute Attribute = IComputeShaderSourceAttribute.GetForType(); + private static readonly IComputeShaderSourceAttribute Attribute = IComputeShaderSourceAttribute.GetForType(); /// /// The number of constant buffers to define in the shader. @@ -238,7 +238,14 @@ namespace ComputeSharp.Shaders.Translation /// private void LoadMethodSource() { - EntryPoint = Attribute.Methods[nameof(IComputeShader.Execute)]; + foreach (var method in Attribute.Methods) + { + switch (method.Key) + { + case nameof(IComputeShader.Execute): EntryPoint = method.Value; break; + default: this.localFunctionsInfo.Add(method.Value); break; + } + } } } }