Moved code to new hashcode implementation
このコミットが含まれているのは:
1 親
57ae15ab7f
コミット
64c3949962
3ファイル変更
+7
-32
検索条件に一致するファイルはありません
@@ -64,7 +64,7 @@ namespace ComputeSharp.Shaders
|
||||
CachedShader shaderData;
|
||||
lock (ShadersCache)
|
||||
{
|
||||
var key = (ShaderLoader.GetHashCode(action), threadsX, threadsY, threadsZ);
|
||||
var key = (ShaderHashCodeProvider.GetHashCode(action), threadsX, threadsY, threadsZ);
|
||||
if (!ShadersCache.TryGetValue(key, out shaderData))
|
||||
{
|
||||
// Load the input shader
|
||||
|
||||
@@ -147,31 +147,6 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
public IReadOnlyList<LocalFunctionInfo> LocalFunctionsList => _LocalFunctionsList;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique hash code for a given <see cref="Action{T}"/>
|
||||
/// </summary>
|
||||
/// <param name="action">The input <see cref="Action{T}"/> instance to inspect</param>
|
||||
[Pure]
|
||||
public static int GetHashCode(Action<ThreadIds> action)
|
||||
{
|
||||
int hashcode = action.Method.GetHashCode();
|
||||
|
||||
foreach (FieldInfo fieldInfo in action.Method.DeclaringType.GetFields())
|
||||
{
|
||||
if (fieldInfo.FieldType.IsDelegate() &&
|
||||
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)))
|
||||
{
|
||||
hashcode = unchecked(hashcode * 17 + func.Method.GetHashCode());
|
||||
}
|
||||
}
|
||||
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and processes an input <see cref="Action{T}"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -17,14 +17,14 @@ namespace ComputeSharp.Tests.Internals
|
||||
Action<ThreadIds> action1 = id => buffer[0] = value;
|
||||
|
||||
int
|
||||
hash1 = ShaderLoader.GetHashCode(action1),
|
||||
hash2 = ShaderLoader.GetHashCode(action1);
|
||||
hash1 = ShaderHashCodeProvider.GetHashCode(action1),
|
||||
hash2 = ShaderHashCodeProvider.GetHashCode(action1);
|
||||
|
||||
Assert.IsTrue(hash1 == hash2);
|
||||
|
||||
Action<ThreadIds> action2 = id => buffer[0] = value;
|
||||
|
||||
int hash3 = ShaderLoader.GetHashCode(action2);
|
||||
int hash3 = ShaderHashCodeProvider.GetHashCode(action2);
|
||||
|
||||
Assert.IsFalse(hash1 == hash3);
|
||||
}
|
||||
@@ -39,14 +39,14 @@ namespace ComputeSharp.Tests.Internals
|
||||
Action<ThreadIds> action = id => buffer[0] = f(2);
|
||||
|
||||
int
|
||||
hash1 = ShaderLoader.GetHashCode(action),
|
||||
hash2 = ShaderLoader.GetHashCode(action);
|
||||
hash1 = ShaderHashCodeProvider.GetHashCode(action),
|
||||
hash2 = ShaderHashCodeProvider.GetHashCode(action);
|
||||
|
||||
Assert.IsTrue(hash1 == hash2);
|
||||
|
||||
f = x => x + 1;
|
||||
|
||||
int hash3 = ShaderLoader.GetHashCode(action);
|
||||
int hash3 = ShaderHashCodeProvider.GetHashCode(action);
|
||||
|
||||
Assert.IsFalse(hash1 == hash3);
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする