From 4da6f12e7efc40b51ecba1e3d77bdfa70f5a7cf9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 13:00:48 +0200 Subject: [PATCH] Initial support for static delegates in shaders --- .../Translation/ShaderLoader.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index 1c3c24cc..dd8bffd0 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -13,7 +13,6 @@ using ComputeSharp.Shaders.Renderer.Models.Functions; using ComputeSharp.Shaders.Translation.Enums; using ComputeSharp.Shaders.Translation.Models; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Vortice.Direct3D12; using ParameterInfo = ComputeSharp.Shaders.Renderer.Models.Functions.ParameterInfo; @@ -247,6 +246,30 @@ namespace ComputeSharp.Shaders.Translation LoadFieldInfo(fieldInfo, null, updatedParents); } } + else if (fieldType.IsClass && fieldType.IsGenericType && + fieldType.IsSubclassOf(typeof(Delegate)) && + memberInfo.GetValue(Action.Target) is Delegate func && func.Method.IsStatic && + fieldType.GetGenericTypeDefinition() is Type fieldTypeDefinition && ( + fieldTypeDefinition == typeof(Func<>) || + fieldTypeDefinition == typeof(Func<,>) || + fieldTypeDefinition == typeof(Func<,,>) || + fieldTypeDefinition == typeof(Func<,,,>) || + fieldTypeDefinition == typeof(Func<,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,,>) || + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,,,>))) + { + LoadStaticMethodSource(fieldName, func.Method); + } } ///