More code refactoring

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-13 22:42:33 +02:00
1 親 4e3bfb5362
コミット 0d885e18d6
9ファイル変更
+81 -59

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

+1
ファイルの表示
@@ -4,6 +4,7 @@ using System.Runtime.CompilerServices;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Helpers;
using SharpDX.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp.Graphics.Buffers
{
+1
ファイルの表示
@@ -4,6 +4,7 @@ using System.Runtime.CompilerServices;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Helpers;
using SharpDX.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp.Graphics.Buffers
{
+35
ファイルの表示
@@ -0,0 +1,35 @@
using System;
using SharpDX.Direct3D12;
namespace ComputeSharp.Graphics.Commands.Abstract
{
/// <summary>
/// A base <see langword="class"/> for an instance that deals with GPU commands in some way
/// </summary>
internal abstract class CommandController : IDisposable
{
/// <summary>
/// Creates a new <see cref="CommandAllocatorPool"/> instance with the specified parameters
/// </summary>
/// <param name="device">The input <see cref="Graphics.GraphicsDevice"/> to use to perform requested operations</param>
/// <param name="commandListType">The type of command list to use for the current instance</param>
protected CommandController(GraphicsDevice device, CommandListType commandListType)
{
GraphicsDevice = device;
CommandListType = commandListType;
}
/// <summary>
/// Gets the <see cref="Graphics.GraphicsDevice"/> object targeted by the current instance
/// </summary>
public GraphicsDevice GraphicsDevice { get; }
/// <summary>
/// Gets the command list type being used by the current instance
/// </summary>
public CommandListType CommandListType { get; }
/// <inheritdoc/>
public abstract void Dispose();
}
}
@@ -1,40 +1,23 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using ComputeSharp.Graphics.Commands.Abstract;
using SharpDX.Direct3D12;
namespace ComputeSharp.Graphics
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A <see langword="class"/> that acts as a pool to get new <see cref="CommandAllocator"/> instances wheen needed
/// </summary>
internal sealed class CommandAllocatorPool : IDisposable
internal sealed class CommandAllocatorPool : CommandController
{
/// <summary>
/// The queue of currently pooled <see cref="CommandAllocator"/> instances
/// </summary>
private readonly Queue<(CommandAllocator CommandAllocator, long FenceValue)> CommandAllocatorQueue = new Queue<(CommandAllocator, long)>();
/// <summary>
/// Creates a new <see cref="CommandAllocatorPool"/> instance with the specified parameters
/// </summary>
/// <param name="device">The input <see cref="Graphics.GraphicsDevice"/> to use to perform requested operations</param>
/// <param name="commandListType">The type of command list to use for the current instance</param>
public CommandAllocatorPool(GraphicsDevice device, CommandListType commandListType)
{
GraphicsDevice = device;
CommandListType = commandListType;
}
/// <summary>
/// Gets the <see cref="Graphics.GraphicsDevice"/> object targeted by the current instance
/// </summary>
public GraphicsDevice GraphicsDevice { get; }
/// <summary>
/// Gets the command list type being used by the current instance
/// </summary>
public CommandListType CommandListType { get; }
/// <inheritdoc/>
public CommandAllocatorPool(GraphicsDevice device, CommandListType commandListType) : base(device, commandListType) { }
/// <summary>
/// Adds a new <see cref="CommandAllocator"/> item to the internal pool queue
@@ -84,7 +67,7 @@ namespace ComputeSharp.Graphics
}
/// <inheritdoc/>
public void Dispose()
public override void Dispose()
{
lock (CommandAllocatorQueue)
{
@@ -1,21 +1,20 @@
using System;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Commands.Abstract;
using SharpDX.Direct3D12;
namespace ComputeSharp.Graphics
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A <see langword="class"/> that represents a list of commands to issue to a GPU
/// </summary>
public sealed class CommandList : IDisposable
internal sealed class CommandList : CommandController
{
private readonly CompiledCommandList currentCommandList;
public CommandList(GraphicsDevice device, CommandListType commandListType)
/// <inheritdoc/>
public CommandList(GraphicsDevice device, CommandListType commandListType) : base(device, commandListType)
{
GraphicsDevice = device;
CommandListType = commandListType;
CommandAllocator commandAllocator = GetCommandAllocator();
GraphicsCommandList nativeCommandList = GraphicsDevice.NativeDevice.CreateCommandList((SharpDX.Direct3D12.CommandListType)CommandListType, commandAllocator, null);
@@ -24,10 +23,6 @@ namespace ComputeSharp.Graphics
SetDescriptorHeaps(GraphicsDevice.ShaderResourceViewAllocator.DescriptorHeap);
}
public CommandListType CommandListType { get; }
public GraphicsDevice GraphicsDevice { get; }
public CompiledCommandList Close()
{
//foreach (var renderTarget in RenderTargets)
@@ -55,29 +50,6 @@ namespace ComputeSharp.Graphics
currentCommandList.NativeCommandList.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
}
public void Dispose()
{
switch (CommandListType)
{
case CommandListType.Bundle:
GraphicsDevice.BundleAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextDirectFenceValue - 1);
break;
case CommandListType.Direct:
GraphicsDevice.DirectAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextDirectFenceValue - 1);
break;
case CommandListType.Compute:
GraphicsDevice.ComputeAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextComputeFenceValue - 1);
break;
case CommandListType.Copy:
GraphicsDevice.CopyAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextCopyFenceValue - 1);
break;
default:
throw new NotSupportedException("This command list type is not supported.");
}
currentCommandList.NativeCommandList.Dispose();
}
public void Flush(bool wait = false)
{
GraphicsDevice.ExecuteCommandLists(wait, Close());
@@ -168,5 +140,29 @@ namespace ComputeSharp.Graphics
CommandListType.Direct => GraphicsDevice.DirectAllocatorPool.GetCommandAllocator(),
_ => throw new NotSupportedException("This command list type is not supported.")
};
/// <inheritdoc/>
public override void Dispose()
{
switch (CommandListType)
{
case CommandListType.Bundle:
GraphicsDevice.BundleAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextDirectFenceValue - 1);
break;
case CommandListType.Direct:
GraphicsDevice.DirectAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextDirectFenceValue - 1);
break;
case CommandListType.Compute:
GraphicsDevice.ComputeAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextComputeFenceValue - 1);
break;
case CommandListType.Copy:
GraphicsDevice.CopyAllocatorPool.Enqueue(currentCommandList.NativeCommandAllocator, GraphicsDevice.NextCopyFenceValue - 1);
break;
default:
throw new NotSupportedException("This command list type is not supported.");
}
currentCommandList.NativeCommandList.Dispose();
}
}
}
+1
ファイルの表示
@@ -1,4 +1,5 @@
using SharpDX.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp.Graphics
{
+4 -2
ファイルの表示
@@ -1,8 +1,10 @@
using System;
using System.Threading;
using ComputeSharp.Graphics.Commands;
using SharpDX.Direct3D;
using SharpDX.Direct3D12;
using SharpDX.DXGI;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
using Device = SharpDX.Direct3D12.Device;
namespace ComputeSharp.Graphics
@@ -56,9 +58,9 @@ namespace ComputeSharp.Graphics
/// </summary>
public int WavefrontSize { get; }
public CommandList CommandList { get; }
internal CommandList CommandList { get; }
public CommandList CopyCommandList { get; }
internal CommandList CopyCommandList { get; }
public const FeatureLevel FeatureLevel = SharpDX.Direct3D.FeatureLevel.Level_12_1;
+3
ファイルの表示
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("ComputeSharp.Shaders")]
+1 -1
ファイルの表示
@@ -5,7 +5,7 @@ using ComputeSharp.Shaders.Renderer;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation;
using SharpDX.Direct3D12;
using CommandList = ComputeSharp.Graphics.CommandList;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
using PipelineState = ComputeSharp.Graphics.PipelineState;
namespace ComputeSharp.Shaders