Removed ShaderHashCodeProvider, switched to interface method

このコミットが含まれているのは:
Sergio Pedri committed 2021-07-12 15:58:51 +02:00
1 親 bcc3364403
コミット ae07384417
4ファイル変更
+12 -90

検索条件に一致するファイルはありません

+9 -11
ファイルの表示
@@ -1,9 +1,7 @@
using System;
using System.Diagnostics.Contracts;
using ComputeSharp.Shaders;
using ComputeSharp.__Internals;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Resources;
using ComputeSharp.Shaders;
#pragma warning disable CS0618
namespace ComputeSharp
{
@@ -20,7 +18,7 @@ namespace ComputeSharp
/// <param name="x">The number of iterations to run on the X axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IShader<T>
{
ShaderRunner<T>.Run(device, x, 1, 1, in shader);
}
@@ -34,7 +32,7 @@ namespace ComputeSharp
/// <param name="y">The number of iterations to run on the Y axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, int y, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IShader<T>
{
ShaderRunner<T>.Run(device, x, y, 1, in shader);
}
@@ -49,7 +47,7 @@ namespace ComputeSharp
/// <param name="z">The number of iterations to run on the Z axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, int y, int z, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IShader<T>
{
ShaderRunner<T>.Run(device, x, y, z, in shader);
}
@@ -67,7 +65,7 @@ namespace ComputeSharp
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, int y, int z, int threadsX, int threadsY, int threadsZ, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IShader<T>
{
ShaderRunner<T>.Run(device, x, y, z, threadsX, threadsY, threadsZ, in shader);
}
@@ -80,7 +78,7 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader.</param>
/// <param name="texture">The target texture to apply the pixel shader to.</param>
public static void ForEach<T, TPixel>(this GraphicsDevice device, IReadWriteTexture2D<TPixel> texture)
where T : struct, IPixelShader<TPixel>
where T : struct, IPixelShader<TPixel>, IShader<T>
where TPixel : unmanaged
{
ShaderRunner<T>.Run(device, texture, default);
@@ -95,7 +93,7 @@ namespace ComputeSharp
/// <param name="texture">The target texture to apply the pixel shader to.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the pixel shader to run.</param>
public static void ForEach<T, TPixel>(this GraphicsDevice device, IReadWriteTexture2D<TPixel> texture, in T shader)
where T : struct, IPixelShader<TPixel>
where T : struct, IPixelShader<TPixel>, IShader<T>
where TPixel : unmanaged
{
ShaderRunner<T>.Run(device, texture, in shader);
+3 -3
ファイルの表示
@@ -23,7 +23,7 @@ namespace ComputeSharp.Shaders
/// </summary>
/// <typeparam name="T">The type of compute shader to run.</typeparam>
internal static class ShaderRunner<T>
where T : struct
where T : struct, IShader<T>
{
/// <summary>
/// The mapping used to cache and reuse compiled shaders.
@@ -131,7 +131,7 @@ namespace ComputeSharp.Shaders
Guard.IsBetweenOrEqualTo(groupsZ, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
// Create the shader key
ShaderKey key = new(ShaderHashCodeProvider.GetHashCode(in shader), threadsX, threadsY, threadsZ);
ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, threadsZ);
CachedShader<T> shaderData;
PipelineData? pipelineData;
@@ -202,7 +202,7 @@ namespace ComputeSharp.Shaders
Guard.IsBetweenOrEqualTo(groupsY, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
// Create the shader key
ShaderKey key = new(ShaderHashCodeProvider.GetHashCode(in shader), threadsX, threadsY, 1);
ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, 1);
CachedShader<T> shaderData;
PipelineData? pipelineData;
-75
ファイルの表示
@@ -1,75 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace ComputeSharp.Shaders.Translation
{
/// <summary>
/// A <see langword="static"/> <see langword="class"/> that handles the cache system for the generated shaders.
/// </summary>
internal static class ShaderHashCodeProvider
{
/// <summary>
/// A type containing static info for a given shader type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of compute shader currently in use.</typeparam>
private static class TypeInfo<T>
where T : struct
{
/// <summary>
/// The id of the compute shader type in use.
/// </summary>
public static readonly int Id;
/// <summary>
/// The optional <see cref="Hasher{T}"/> instance, if needed.
/// </summary>
public static readonly Hasher<T>? Hasher;
/// <summary>
/// Initializes the static members of the <see cref="TypeInfo{T}"/> type.
/// </summary>
static TypeInfo()
{
Id = HashCode.Combine(typeof(T));
// Get the generated hasher, if one if present
if (typeof(T).Assembly.GetType("ComputeSharp.__Internals.HashCodeProvider") is Type type &&
type.GetMethod("CombineHash", new[] { typeof(int), typeof(T).MakeByRefType() }) is MethodInfo method)
{
Hasher = method.CreateDelegate<Hasher<T>>();
}
}
}
/// <summary>
/// Gets a unique hashcode for the input compute shader instance.
/// </summary>
/// <typeparam name="T">The type of compute shader currently in use.</typeparam>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the shader to run.</param>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetHashCode<T>(in T shader)
where T : struct
{
int hash = TypeInfo<T>.Id;
Hasher<T>? hasher = TypeInfo<T>.Hasher;
if (hasher != null) hash = hasher(hash, in shader);
return hash;
}
/// <summary>
/// A <see langword="delegate"/> that represents an aggregate hash function for a given <typeparamref name="T"/> instance.
/// </summary>
/// <typeparam name="T">The type of compute shader currently in use.</typeparam>
/// <param name="hash">The initial hash value.</param>
/// <param name="shader">The compute shader instance to use to compute the final hash value.</param>
/// <returns>The final hash value for the input closure.</returns>
private delegate int Hasher<T>(int hash, in T shader)
where T : struct;
}
}
-1
ファイルの表示
@@ -1,4 +1,3 @@
using System;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;