Code refactoring
このコミットが含まれているのは:
1 親
2aaecb65cf
コミット
4e3bfb5362
2ファイル変更
+53
-22
検索条件に一致するファイルはありません
@@ -1,51 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
{
|
||||
/// <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
|
||||
{
|
||||
private readonly Queue<(CommandAllocator, long)> commandAllocatorQueue = new Queue<(CommandAllocator, long)>();
|
||||
/// <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;
|
||||
}
|
||||
|
||||
public CommandListType CommandListType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Graphics.GraphicsDevice"/> object targeted by the current instance
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
lock (commandAllocatorQueue)
|
||||
{
|
||||
foreach ((CommandAllocator commandAllocator, long _) in commandAllocatorQueue)
|
||||
{
|
||||
commandAllocator.Dispose();
|
||||
}
|
||||
|
||||
commandAllocatorQueue.Clear();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the command list type being used by the current instance
|
||||
/// </summary>
|
||||
public CommandListType CommandListType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new <see cref="CommandAllocator"/> item to the internal pool queue
|
||||
/// </summary>
|
||||
/// <param name="commandAllocator">The input <see cref="CommandAllocator"/> to enqueue</param>
|
||||
/// <param name="fenceValue">The fence value for the input <see cref="CommandAllocator"/></param>
|
||||
public void Enqueue(CommandAllocator commandAllocator, long fenceValue)
|
||||
{
|
||||
lock (commandAllocatorQueue)
|
||||
lock (CommandAllocatorQueue)
|
||||
{
|
||||
commandAllocatorQueue.Enqueue((commandAllocator, fenceValue));
|
||||
CommandAllocatorQueue.Enqueue((commandAllocator, fenceValue));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a new or reused <see cref="CommandAllocator"/> item to use to issue GPU commands
|
||||
/// </summary>
|
||||
[Pure]
|
||||
public CommandAllocator GetCommandAllocator()
|
||||
{
|
||||
lock (commandAllocatorQueue)
|
||||
lock (CommandAllocatorQueue)
|
||||
{
|
||||
if (commandAllocatorQueue.Count > 0)
|
||||
if (CommandAllocatorQueue.Count > 0)
|
||||
{
|
||||
(CommandAllocator commandAllocator, long fenceValue) = commandAllocatorQueue.Peek();
|
||||
(CommandAllocator commandAllocator, long fenceValue) = CommandAllocatorQueue.Peek();
|
||||
|
||||
long completedValue = CommandListType switch
|
||||
{
|
||||
@@ -58,14 +72,28 @@ namespace ComputeSharp.Graphics
|
||||
|
||||
if (fenceValue <= completedValue)
|
||||
{
|
||||
commandAllocatorQueue.Dequeue();
|
||||
CommandAllocatorQueue.Dequeue();
|
||||
commandAllocator.Reset();
|
||||
|
||||
return commandAllocator;
|
||||
}
|
||||
}
|
||||
|
||||
return GraphicsDevice.NativeDevice.CreateCommandAllocator((SharpDX.Direct3D12.CommandListType)CommandListType);
|
||||
return GraphicsDevice.NativeDevice.CreateCommandAllocator(CommandListType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
lock (CommandAllocatorQueue)
|
||||
{
|
||||
foreach ((CommandAllocator commandAllocator, long _) in CommandAllocatorQueue)
|
||||
{
|
||||
commandAllocator.Dispose();
|
||||
}
|
||||
|
||||
CommandAllocatorQueue.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ using SharpDX.Direct3D12;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that represents a list of commands to issue to a GPU
|
||||
/// </summary>
|
||||
public sealed class CommandList : IDisposable
|
||||
{
|
||||
private readonly CompiledCommandList currentCommandList;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする