From 149a9ea20b3c4a22d540bd3baa26accba4ae2302 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 19 Aug 2019 11:38:31 +0200 Subject: [PATCH] Fixed shader caching system for closures with multiple methods --- src/ComputeSharp.Shaders/ShaderRunner.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/ShaderRunner.cs b/src/ComputeSharp.Shaders/ShaderRunner.cs index 9d0b99e0..0af20faf 100644 --- a/src/ComputeSharp.Shaders/ShaderRunner.cs +++ b/src/ComputeSharp.Shaders/ShaderRunner.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using ComputeSharp.Graphics; using ComputeSharp.Graphics.Buffers.Abstract; using ComputeSharp.Graphics.Buffers.Extensions; @@ -40,7 +41,7 @@ namespace ComputeSharp.Shaders /// /// The mapping used to cache and reuse compiled shaders /// - private static readonly Dictionary<(Type type, int ThreadsX, int ThreadsY, int ThreadsZ), (ShaderLoader Loader, ShaderBytecode Bytecode)> ShadersCache = new Dictionary<(Type, int, int, int), (ShaderLoader, ShaderBytecode)>(); + private static readonly Dictionary<(MethodInfo Method, int ThreadsX, int ThreadsY, int ThreadsZ), (ShaderLoader Loader, ShaderBytecode Bytecode)> ShadersCache = new Dictionary<(MethodInfo, int, int, int), (ShaderLoader, ShaderBytecode)>(); /// /// Compiles and runs the input shader on a target instance, with the specified parameters @@ -66,7 +67,7 @@ namespace ComputeSharp.Shaders groupsZ = z / threadsZ + (z % threadsZ == 0 ? 0 : 1); // Try to get the cache shader - var key = (action.Method.DeclaringType, threadsX, threadsY, threadsZ); + var key = (action.Method, threadsX, threadsY, threadsZ); if (!ShadersCache.TryGetValue(key, out var shaderData)) { // Load the input shader