From 09eea2ddd591f356bf09978a16d3374d7b7c227a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 16:46:55 +0200 Subject: [PATCH 01/11] Minor code tweaks --- src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs | 10 ++++++++++ src/ComputeSharp.Shaders/Translation/ShaderLoader.cs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs index 852dd8b1..3b82188e 100644 --- a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; +using System.Runtime.CompilerServices; namespace ComputeSharp.Shaders.Extensions { @@ -10,6 +11,15 @@ namespace ComputeSharp.Shaders.Extensions /// internal static class TypeExtensions { + /// + /// Gets whether or not the input represents a + /// + /// The input type to analyze + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsDelegate(this Type type) => type.IsClass && + type.IsSubclassOf(typeof(Delegate)); + /// /// The mapping of supported known types to display string /// diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index d75d8439..56c4f75b 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -159,7 +159,7 @@ namespace ComputeSharp.Shaders.Translation foreach (FieldInfo fieldInfo in action.Method.DeclaringType.GetFields()) { - if (fieldInfo.FieldType.IsClass && fieldInfo.FieldType.IsGenericType && + if (fieldInfo.FieldType.IsDelegate() && fieldInfo.GetValue(action.Target) is Delegate func && func.Method.IsStatic && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldInfo.FieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || @@ -270,7 +270,7 @@ namespace ComputeSharp.Shaders.Translation LoadFieldInfo(fieldInfo, null, updatedParents); } } - else if (fieldType.IsClass && fieldType.IsGenericType && + else if (fieldType.IsDelegate() && memberInfo.GetValue(Action.Target) is Delegate func && func.Method.IsStatic && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || From c1fe54c63e15557591966116a49a84691e8f3de2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 17:10:16 +0200 Subject: [PATCH 02/11] Fixed checks for delegates with no captured variables --- src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs | 9 +++++++++ src/ComputeSharp.Shaders/Translation/ShaderLoader.cs | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs index 3b82188e..77f693d5 100644 --- a/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/TypeExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; namespace ComputeSharp.Shaders.Extensions @@ -20,6 +21,14 @@ namespace ComputeSharp.Shaders.Extensions public static bool IsDelegate(this Type type) => type.IsClass && type.IsSubclassOf(typeof(Delegate)); + /// + /// Gets whether or not the input represents a with no captured variables + /// + /// The input type to analyze + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsStatelessDelegateContainer(this Type type) => type.GetFields(BindingFlags.Static | BindingFlags.Public).Length > 0; + /// /// The mapping of supported known types to display string /// diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index 56c4f75b..30c5ddc4 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -160,7 +160,8 @@ namespace ComputeSharp.Shaders.Translation foreach (FieldInfo fieldInfo in action.Method.DeclaringType.GetFields()) { if (fieldInfo.FieldType.IsDelegate() && - fieldInfo.GetValue(action.Target) is Delegate func && func.Method.IsStatic && + fieldInfo.GetValue(action.Target) is Delegate func && + (func.Method.IsStatic || func.Method.DeclaringType.IsStatelessDelegateContainer()) && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldInfo.FieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || HlslKnownTypes.IsKnownVectorType(type))) @@ -271,7 +272,8 @@ namespace ComputeSharp.Shaders.Translation } } else if (fieldType.IsDelegate() && - memberInfo.GetValue(Action.Target) is Delegate func && func.Method.IsStatic && + memberInfo.GetValue(Action.Target) is Delegate func && + (func.Method.IsStatic || func.Method.DeclaringType.IsStatelessDelegateContainer()) && (HlslKnownTypes.IsKnownScalarType(func.Method.ReturnType) || HlslKnownTypes.IsKnownVectorType(func.Method.ReturnType)) && fieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || HlslKnownTypes.IsKnownVectorType(type))) From d4e3e20048859cc4b2b26d5e853f151c4d65f742 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 17:10:31 +0200 Subject: [PATCH 03/11] Fixed decompile error for methods with invalid C# names --- src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs index a6a0b3dc..a0bd0703 100644 --- a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs @@ -207,9 +207,10 @@ namespace ComputeSharp.Shaders.Translation private string GetSyntaxTreeForStaticMethod(MethodInfo methodInfo) { string - sourceCode = DecompileMethodOrDeclaringType(methodInfo), - prototype = sourceCode.Split(Environment.NewLine)[0], - commentedSourceCode = $"// {methodInfo.Name}{Environment.NewLine}{sourceCode}", + sourceCode = DecompileMethodOrDeclaringType(methodInfo, true), + methodFixedCode = sourceCode.Replace(methodInfo.Name, methodInfo.Name.Replace("<", string.Empty).Replace(">", "_")), + prototype = methodFixedCode.Split(Environment.NewLine)[0], + commentedSourceCode = $"// {methodInfo.Name}{Environment.NewLine}{methodFixedCode}", inFixedSourceCode = Regex.Replace(commentedSourceCode, @"(? Date: Thu, 5 Sep 2019 17:10:47 +0200 Subject: [PATCH 04/11] Added tests for custom delegates and inline functions --- .../StaticFunctionsTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs index 5a5ad8b7..d067c8f8 100644 --- a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs +++ b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs @@ -75,5 +75,37 @@ namespace ComputeSharp.Tests Assert.IsTrue(MathF.Abs(result[0] - expected) < 0.0001f); } + + public delegate float Squarer(float x); + + [TestMethod] + public void CustomStaticDelegate() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Squarer square = StaticMethodsContainer.Square; + + Gpu.Default.For(1, id => buffer[0] = square(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } + + [TestMethod] + public void InlineStatelessDelegate() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Func f = x => x * x; + + Func invert = x => -x; + + Gpu.Default.For(1, id => buffer[0] = f(3) + invert(8)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 1) < 0.0001f); + } } } From a91b44a3290a471e85dcde39f48c5eec2da528b1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 17:24:46 +0200 Subject: [PATCH 05/11] UI tweaks to the mustache template --- .../Renderer/Templates/ShaderTemplate.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache b/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache index 189fa50d..2be993e2 100644 --- a/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache +++ b/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache @@ -38,10 +38,10 @@ cbuffer _{{FieldName}} : register(b{{BufferIndex}}) {{&FieldHlslType}} {{FieldName}} : register(u{{BufferIndex}}); {{/IsReadWriteBuffer}} {{/BuffersList}} +{{#FunctionsList}} {{!Shader private functions}} -{{#FunctionsList}} -// {{FunctionCsharpReturnType}} {{FunctionFullName}}({{FunctionCsharpParameters}}) +// {{FunctionCsharpReturnType}} {{&FunctionFullName}}({{FunctionCsharpParameters}}) {{ReturnType}} {{FunctionName}}({{#ParametersList}}{{ParameterModifier}} {{ParameterType}} {{ParameterName}}{{^IsLastParameter}}, {{/IsLastParameter}}{{/ParametersList}}) {{FunctionBody}} {{/FunctionsList}} From e512c5839e8d70bf2cbc0fcd26a12c789ff6f40a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 17:33:41 +0200 Subject: [PATCH 06/11] Added support for captured local functions cast to delegates --- .../Translation/MethodDecompiler.cs | 2 +- .../StaticFunctionsTests.cs | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs index a0bd0703..0a543835 100644 --- a/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/MethodDecompiler.cs @@ -208,7 +208,7 @@ namespace ComputeSharp.Shaders.Translation { string sourceCode = DecompileMethodOrDeclaringType(methodInfo, true), - methodFixedCode = sourceCode.Replace(methodInfo.Name, methodInfo.Name.Replace("<", string.Empty).Replace(">", "_")), + methodFixedCode = sourceCode.Replace(methodInfo.Name, Regex.Replace(methodInfo.Name, "[<>|]", "_")), prototype = methodFixedCode.Split(Environment.NewLine)[0], commentedSourceCode = $"// {methodInfo.Name}{Environment.NewLine}{methodFixedCode}", inFixedSourceCode = Regex.Replace(commentedSourceCode, @"(? f = x => x * x; - Func invert = x => -x; - - Gpu.Default.For(1, id => buffer[0] = f(3) + invert(8)); + Gpu.Default.For(1, id => buffer[0] = f(3)); float[] result = buffer.GetData(); - Assert.IsTrue(MathF.Abs(result[0] - 1) < 0.0001f); + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } + + [TestMethod] + public void StatelessLocalFunctionToDelegate() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + float Func(float x) => x * x; + + Func f = Func; + + Gpu.Default.For(1, id => buffer[0] = f(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); } } } From 4f58fe4f1f8062b2a63d9a4cc176f2cf2fd3b996 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 18:09:58 +0200 Subject: [PATCH 07/11] Added support for implicit local functions --- .../Models/Functions/LocalFunctionInfo.cs | 29 +++++++++++++++++++ .../Renderer/Models/ShaderInfo.cs | 5 ++++ .../Templates/ShaderTemplate.mustache | 6 ++++ src/ComputeSharp.Shaders/ShaderRunner.cs | 3 +- .../Translation/ShaderLoader.cs | 12 ++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/ComputeSharp.Shaders/Renderer/Models/Functions/LocalFunctionInfo.cs diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Functions/LocalFunctionInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Functions/LocalFunctionInfo.cs new file mode 100644 index 00000000..4dfd45f9 --- /dev/null +++ b/src/ComputeSharp.Shaders/Renderer/Models/Functions/LocalFunctionInfo.cs @@ -0,0 +1,29 @@ +using System; + +namespace ComputeSharp.Shaders.Renderer.Models.Functions +{ + /// + /// A that contains info on a local shader function + /// + internal sealed class LocalFunctionInfo + { + /// + /// Gets the prototype for the current function + /// + public string FunctionPrototype => FunctionDeclaration.Split(Environment.NewLine)[0]; + + /// + /// Gets the declaration of the current function + /// + public string FunctionDeclaration { get; } + + /// + /// Creates a new instance with the specified parameters + /// + /// The declaration of the current function + public LocalFunctionInfo(string functionDeclaration) + { + FunctionDeclaration = functionDeclaration; + } + } +} diff --git a/src/ComputeSharp.Shaders/Renderer/Models/ShaderInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/ShaderInfo.cs index 306dd3f7..fd6e92ed 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/ShaderInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/ShaderInfo.cs @@ -51,5 +51,10 @@ namespace ComputeSharp.Shaders.Renderer.Models /// Gets or sets the list of static functions used by the shader /// public IReadOnlyList FunctionsList { get; set; } + + /// + /// Gets or sets the list of local (implicit) functions used by the shader + /// + public IReadOnlyList LocalFunctionsList { get; set; } } } diff --git a/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache b/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache index 2be993e2..62515497 100644 --- a/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache +++ b/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache @@ -45,6 +45,12 @@ cbuffer _{{FieldName}} : register(b{{BufferIndex}}) {{ReturnType}} {{FunctionName}}({{#ParametersList}}{{ParameterModifier}} {{ParameterType}} {{ParameterName}}{{^IsLastParameter}}, {{/IsLastParameter}}{{/ParametersList}}) {{FunctionBody}} {{/FunctionsList}} +{{#LocalFunctionsList}} + +{{!Shader implicit functions}} +// {{FunctionPrototype}} +{{FunctionDeclaration}} +{{/LocalFunctionsList}} {{!Shader entry point}} // Shader body diff --git a/src/ComputeSharp.Shaders/ShaderRunner.cs b/src/ComputeSharp.Shaders/ShaderRunner.cs index c149e409..038d4b8a 100644 --- a/src/ComputeSharp.Shaders/ShaderRunner.cs +++ b/src/ComputeSharp.Shaders/ShaderRunner.cs @@ -76,7 +76,8 @@ namespace ComputeSharp.Shaders NumThreadsZ = threadsZ, ThreadsIdsVariableName = shaderLoader.ThreadsIdsVariableName, ShaderBody = shaderLoader.MethodBody, - FunctionsList = shaderLoader.FunctionsList + FunctionsList = shaderLoader.FunctionsList, + LocalFunctionsList = shaderLoader.LocalFunctionsList }; string shaderSource = ShaderRenderer.Instance.Render(shaderInfo); diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index 30c5ddc4..13576969 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -148,6 +148,13 @@ namespace ComputeSharp.Shaders.Translation /// public IReadOnlyList FunctionsList => _FunctionsList; + private readonly List _LocalFunctionsList = new List(); + + /// + /// Gets the collection of items for the shader + /// + public IReadOnlyList LocalFunctionsList => _LocalFunctionsList; + /// /// Gets a unique hash code for a given /// @@ -295,6 +302,11 @@ namespace ComputeSharp.Shaders.Translation ShaderSyntaxRewriter syntaxRewriter = new ShaderSyntaxRewriter(semanticModel); root = (MethodDeclarationSyntax)syntaxRewriter.Visit(root); + // Extract the implicit local functions + var locals = root.DescendantNodes().OfType().ToArray(); + root = root.RemoveNodes(locals, SyntaxRemoveOptions.KeepNoTrivia); + _LocalFunctionsList.AddRange(locals.Select(local => new LocalFunctionInfo(local.ToString()))); + // Register the captured static members foreach (var member in syntaxRewriter.StaticMembers) { From 9533515fa60de72c3e035ae18c02cee64b9846d2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 18:10:06 +0200 Subject: [PATCH 08/11] Minor code tweaks --- .../Renderer/Models/Functions/FunctionInfo.cs | 2 +- .../Renderer/Models/Functions/ParameterInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Functions/FunctionInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Functions/FunctionInfo.cs index 3af27abe..387e08e5 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Functions/FunctionInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Functions/FunctionInfo.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.Shaders.Renderer.Models.Functions /// /// A that contains info on a shader function /// - internal class FunctionInfo + internal sealed class FunctionInfo { /// /// Gets the return type of the current function in the C# source diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Functions/ParameterInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Functions/ParameterInfo.cs index f5cc5172..a424aaf2 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Functions/ParameterInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Functions/ParameterInfo.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.Shaders.Renderer.Models.Functions /// /// A that contains info on a function parameter /// - internal class ParameterInfo + internal sealed class ParameterInfo { /// /// Gets the modifier to use for the current parameter From c706e6494086c11099ec74bdfbb3dbf6f7248693 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 18:10:16 +0200 Subject: [PATCH 09/11] Added test for implicit local function --- tests/ComputeSharp.Tests/StaticFunctionsTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs index d1d9a515..fbcd1c53 100644 --- a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs +++ b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs @@ -121,5 +121,19 @@ namespace ComputeSharp.Tests Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); } + + [TestMethod] + public void StatelessLocalFunction() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + float f(float x) => x * x; + + Gpu.Default.For(1, id => buffer[0] = f(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } } } From 9956ad348351a6dc0539d6ecac139b828c99b83c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 18:21:47 +0200 Subject: [PATCH 10/11] Improved formatting for implicitly captured local functions --- .../Extensions/StringExtensions.cs | 28 +++++++++++++++++++ .../Translation/ShaderLoader.cs | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/ComputeSharp.Shaders/Extensions/StringExtensions.cs diff --git a/src/ComputeSharp.Shaders/Extensions/StringExtensions.cs b/src/ComputeSharp.Shaders/Extensions/StringExtensions.cs new file mode 100644 index 00000000..401321a3 --- /dev/null +++ b/src/ComputeSharp.Shaders/Extensions/StringExtensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Diagnostics.Contracts; +using System.Linq; +using System.Text.RegularExpressions; + +namespace ComputeSharp.Shaders.Extensions +{ + /// + /// A that provides extension methods for the type + /// + internal static class StringExtensions + { + /// + /// Removes the left padding for an input multiline + /// + /// The input to process + /// A left-aligned with the same text as the input + [Pure] + public static string RemoveLeftPadding(this string text) + { + string[] lines = text.Split(Environment.NewLine); + int spaces = text.TakeWhile(c => c == ' ').Count(); + Regex regex = new Regex($"^{new string(Enumerable.Repeat(' ', spaces).ToArray())}"); + + return lines.Aggregate(string.Empty, (result, line) => $"{result}{Environment.NewLine}{regex.Replace(line, string.Empty)}"); + } + } +} diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index 13576969..d9010301 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -305,7 +305,7 @@ namespace ComputeSharp.Shaders.Translation // Extract the implicit local functions var locals = root.DescendantNodes().OfType().ToArray(); root = root.RemoveNodes(locals, SyntaxRemoveOptions.KeepNoTrivia); - _LocalFunctionsList.AddRange(locals.Select(local => new LocalFunctionInfo(local.ToString()))); + _LocalFunctionsList.AddRange(locals.Select(local => new LocalFunctionInfo(local.ToFullString().RemoveLeftPadding().Trim(' ', '\r', '\n')))); // Register the captured static members foreach (var member in syntaxRewriter.StaticMembers) From d6d2a5e2b3dd380c8c975c901a0867e0691ea9e8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 18:24:57 +0200 Subject: [PATCH 11/11] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b70760dc..08fb7c30 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ If the shader in C# is capturing some local variable, those will be automaticall ✅ `static` properties, same as with fields -✅ `Func` or any delegate with a valid HLSL signature, with the target method being `static` +✅ `Func`s or delegates with a valid HLSL signature, with the target method being `static` + +✅ `Func`s, local methods or delegates with no captured variables ## Advanced usage