From f50e25c914dbf5da78d9f06c0c85a58acf1f9e5b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 13:05:27 +0200 Subject: [PATCH] Added type parameters validation for captured functions --- src/ComputeSharp.Shaders/Translation/ShaderLoader.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index dd8bffd0..6c727f3f 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -266,10 +266,14 @@ namespace ComputeSharp.Shaders.Translation fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,>) || fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,>) || fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,,>) || - fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,,,>))) + fieldTypeDefinition == typeof(Func<,,,,,,,,,,,,,,,,>)) && + fieldType.GenericTypeArguments.All(type => HlslKnownTypes.IsKnownScalarType(type) || + HlslKnownTypes.IsKnownVectorType(type))) { + // Captured static Func (and available generic type combinations) LoadStaticMethodSource(fieldName, func.Method); } + else throw new InvalidOperationException($"Invalid captured variable \"{fieldName}\" of type {fieldType}"); } ///