From 68acc46bb10082c5997be979a0d1ed1c6bcfcd9d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 01:27:55 +0200 Subject: [PATCH] Fixed non public static methods in shaders --- .../Extensions/SyntaxNodeExtensions.cs | 4 ++++ tests/ComputeSharp.Tests/StaticMethodsTests.cs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs index 8628734b..dbec13e3 100644 --- a/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs @@ -95,6 +95,10 @@ namespace ComputeSharp.Shaders.Extensions isReadonly = !propertyInfo.CanWrite; memberInfo = propertyInfo; break; + case MethodInfo methodInfo: + string methodName = $"{methodInfo.DeclaringType.Name}_{methodInfo.Name}"; + method = (methodName, methodInfo); + return SyntaxFactory.IdentifierName(methodName).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()); default: throw new InvalidOperationException($"Invalid symbol kind: {memberInfos.First().GetType()}"); } diff --git a/tests/ComputeSharp.Tests/StaticMethodsTests.cs b/tests/ComputeSharp.Tests/StaticMethodsTests.cs index 38103f08..a2123fd8 100644 --- a/tests/ComputeSharp.Tests/StaticMethodsTests.cs +++ b/tests/ComputeSharp.Tests/StaticMethodsTests.cs @@ -12,6 +12,9 @@ namespace ComputeSharp.Tests [Pure] public static float Square(float x) => x * x; + [Pure] + internal static float InternalSquare(float x) => x * x; + [Pure] public static Float4 Range(float x) => new Float4(x, x + 1, x + 2, x + 3); @@ -39,6 +42,18 @@ namespace ComputeSharp.Tests Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); } + [TestMethod] + public void InternalFloatToFloatFunc() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Gpu.Default.For(1, id => buffer[0] = StaticMethodsContainer.InternalSquare(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } + [TestMethod] public void FloatToFloat4Func() {