Minor code refactoring

このコミットが含まれているのは:
Sergio Pedri committed 2019-09-16 03:20:21 +02:00
1 親 90a326aef5
コミット 0be404c9b3
2ファイル変更
+35 -3

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

+4 -3
ファイルの表示
@@ -7,6 +7,7 @@ using ComputeSharp.Graphics.Buffers.Extensions;
using ComputeSharp.Shaders.Renderer;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation;
using ComputeSharp.Shaders.Translation.Models;
using Vortice.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
using PipelineState = ComputeSharp.Graphics.Commands.PipelineState;
@@ -40,7 +41,7 @@ namespace ComputeSharp.Shaders
/// <summary>
/// The mapping used to cache and reuse compiled shaders
/// </summary>
private static readonly Dictionary<(int Id, int ThreadsX, int ThreadsY, int ThreadsZ), (ShaderLoader, ShaderBytecode)> ShadersCache = new Dictionary<(int, int, int, int), (ShaderLoader, ShaderBytecode)>();
private static readonly Dictionary<(int Id, int ThreadsX, int ThreadsY, int ThreadsZ), CachedShader> ShadersCache = new Dictionary<(int, int, int, int), CachedShader>();
/// <summary>
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters
@@ -60,7 +61,7 @@ namespace ComputeSharp.Shaders
Action<ThreadIds> action)
{
// Try to get the cache shader
(ShaderLoader Loader, ShaderBytecode Bytecode) shaderData;
CachedShader shaderData;
lock (ShadersCache)
{
var key = (ShaderLoader.GetHashCode(action), threadsX, threadsY, threadsZ);
@@ -88,7 +89,7 @@ namespace ComputeSharp.Shaders
ShaderBytecode shaderBytecode = ShaderCompiler.CompileShader(shaderSource);
// Cache for later use
shaderData = (shaderLoader, shaderBytecode);
shaderData = new CachedShader(shaderLoader, shaderBytecode);
ShadersCache.Add(key, shaderData);
}
}
+31
ファイルの表示
@@ -0,0 +1,31 @@
using Vortice.Direct3D12;
namespace ComputeSharp.Shaders.Translation.Models
{
/// <summary>
/// A <see langword="struct"/> that contains info on a cached shader
/// </summary>
internal readonly struct CachedShader
{
/// <summary>
/// The <see cref="ShaderLoader"/> instance with the shader metadata
/// </summary>
public readonly ShaderLoader Loader;
/// <summary>
/// The compiled shader bytecode
/// </summary>
public readonly ShaderBytecode Bytecode;
/// <summary>
/// Creates a new <see cref="CachedShader"/> instance with the specified parameters
/// </summary>
/// <param name="loader">The <see cref="ShaderLoader"/> instance with the shader metadata</param>
/// <param name="bytecode">The compiled shader bytecode</param>
public CachedShader(ShaderLoader loader, ShaderBytecode bytecode)
{
Loader = loader;
Bytecode = bytecode;
}
}
}