Removed IDxcBlobObject type, code refactoring
このコミットが含まれているのは:
1 親
a364c676b0
コミット
b096c70d23
5ファイル変更
+55
-95
検索条件に一致するファイルはありません
@@ -4,7 +4,7 @@ using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.D3D12_DESCRIPTOR_RANGE_FLAGS;
|
||||
|
||||
#pragma warning disable IDE0052
|
||||
#pragma warning disable IDE0052, CS0414
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
{
|
||||
|
||||
@@ -5,7 +5,6 @@ using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Dispatching;
|
||||
using ComputeSharp.Shaders.Extensions;
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
using ComputeSharp.Shaders.Translation.Interop;
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
using ComputeSharp.__Internals;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
@@ -27,7 +26,7 @@ namespace ComputeSharp.Shaders
|
||||
/// <summary>
|
||||
/// The mapping used to cache and reuse compiled shaders.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<ShaderKey, CachedShader<T>> ShadersCache = new();
|
||||
private static readonly Dictionary<ShaderKey, CachedShader> ShadersCache = new();
|
||||
|
||||
/// <summary>
|
||||
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters.
|
||||
@@ -134,7 +133,7 @@ namespace ComputeSharp.Shaders
|
||||
lock (ShadersCache)
|
||||
{
|
||||
// Get or preload the shader
|
||||
if (!ShadersCache.TryGetValue(key, out CachedShader<T> shaderData))
|
||||
if (!ShadersCache.TryGetValue(key, out CachedShader? shaderData))
|
||||
{
|
||||
LoadShader(threadsX, threadsY, threadsZ, in shader, out shaderData);
|
||||
|
||||
@@ -192,7 +191,7 @@ namespace ComputeSharp.Shaders
|
||||
lock (ShadersCache)
|
||||
{
|
||||
// Get or preload the shader
|
||||
if (!ShadersCache.TryGetValue(key, out CachedShader<T> shaderData))
|
||||
if (!ShadersCache.TryGetValue(key, out CachedShader? shaderData))
|
||||
{
|
||||
LoadShader(threadsX, threadsY, 1, in shader, out shaderData);
|
||||
|
||||
@@ -234,9 +233,9 @@ namespace ComputeSharp.Shaders
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <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>
|
||||
/// <param name="shaderData">The <see cref="CachedShader{T}"/> instance to return with the cached shader data.</param>
|
||||
/// <param name="shaderData">The <see cref="CachedShader"/> instance to return with the cached shader data.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, in T shader, out CachedShader<T> shaderData)
|
||||
private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, in T shader, out CachedShader shaderData)
|
||||
{
|
||||
ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create();
|
||||
|
||||
@@ -246,19 +245,17 @@ namespace ComputeSharp.Shaders
|
||||
|
||||
builder.Dispose();
|
||||
|
||||
IDxcBlobObject shaderBytecode = new(dxcBlobBytecode.Get());
|
||||
|
||||
shaderData = new CachedShader<T>(null!, shaderBytecode); // TODO
|
||||
shaderData = new CachedShader(dxcBlobBytecode.Get());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and caches a <see cref="PipelineData"/> instance for a given shader.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader.</param>
|
||||
/// <param name="shaderData">The <see cref="CachedShader{T}"/> instance with the data on the loaded shader.</param>
|
||||
/// <param name="shaderData">The <see cref="CachedShader"/> instance with the data on the loaded shader.</param>
|
||||
/// <param name="pipelineData">The resulting <see cref="PipelineData"/> instance to use to run the shader.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void CreatePipelineData(GraphicsDevice device, in CachedShader<T> shaderData, out PipelineData pipelineData)
|
||||
private static unsafe void CreatePipelineData(GraphicsDevice device, CachedShader shaderData, out PipelineData pipelineData)
|
||||
{
|
||||
using ComPtr<ID3D12RootSignature> d3D12RootSignature = default;
|
||||
|
||||
@@ -266,7 +263,7 @@ namespace ComputeSharp.Shaders
|
||||
|
||||
default(T).LoadDispatchMetadata(ref metadataLoader, out *(IntPtr*)&d3D12RootSignature);
|
||||
|
||||
using ComPtr<ID3D12PipelineState> d3D12PipelineState = device.D3D12Device->CreateComputePipelineState(d3D12RootSignature.Get(), shaderData.Bytecode.D3D12ShaderBytecode);
|
||||
using ComPtr<ID3D12PipelineState> d3D12PipelineState = device.D3D12Device->CreateComputePipelineState(d3D12RootSignature.Get(), shaderData.D3D12ShaderBytecode);
|
||||
|
||||
pipelineData = new PipelineData(d3D12RootSignature.Get(), d3D12PipelineState.Get());
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// An object wrapping an <see cref="IDxcBlob"/> instance.
|
||||
/// </summary>
|
||||
internal sealed unsafe class IDxcBlobObject : NativeObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcBlob"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ComPtr<IDxcBlob> dxcBlob;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IDxcBlobObject"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="dxcBlob">The <see cref="IDxcBlob"/> instance to wrap.</param>
|
||||
public IDxcBlobObject(IDxcBlob* dxcBlob)
|
||||
{
|
||||
this.dxcBlob = new ComPtr<IDxcBlob>(dxcBlob);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a raw pointer to the <see cref="IDxcBlob"/> instance in use.
|
||||
/// </summary>
|
||||
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new((ID3DBlob*)this.dxcBlob.Get());
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.dxcBlob.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that contains info on a cached shader.
|
||||
/// </summary>
|
||||
internal sealed unsafe class CachedShader : NativeObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcBlob"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ComPtr<IDxcBlob> dxcBlobBytecode;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CachedShader"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="dxcBlobBytecode">The <see cref="IDxcBlob"/> bytecode instance to wrap.</param>
|
||||
public CachedShader(IDxcBlob* dxcBlobBytecode)
|
||||
{
|
||||
this.dxcBlobBytecode = new ComPtr<IDxcBlob>(dxcBlobBytecode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the map of cached <see cref="PipelineData"/> instances for each GPU in use.
|
||||
/// </summary>
|
||||
public ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a raw pointer to the <see cref="IDxcBlob"/> instance in use.
|
||||
/// </summary>
|
||||
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new((ID3DBlob*)this.dxcBlobBytecode.Get());
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.dxcBlobBytecode.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Translation.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that contains info on a cached shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of compute shader in use.</typeparam>
|
||||
internal readonly struct CachedShader<T>
|
||||
where T : struct, IShader<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ShaderLoader{T}"/> instance with the shader metadata.
|
||||
/// </summary>
|
||||
public readonly ShaderLoader<T> Loader;
|
||||
|
||||
/// <summary>
|
||||
/// The compiled shader bytecode.
|
||||
/// </summary>
|
||||
public readonly IDxcBlobObject Bytecode;
|
||||
|
||||
/// <summary>
|
||||
/// The map of cached <see cref="PipelineData"/> instances for each GPU in use.
|
||||
/// </summary>
|
||||
public readonly ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CachedShader{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="loader">The <see cref="ShaderLoader{T}"/> instance with the shader metadata.</param>
|
||||
/// <param name="bytecode">The compiled shader bytecode.</param>
|
||||
public CachedShader(ShaderLoader<T> loader, IDxcBlobObject bytecode)
|
||||
{
|
||||
Loader = loader;
|
||||
Bytecode = bytecode;
|
||||
CachedPipelines = new();
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする