More code refactoring
このコミットが含まれているのは:
1 親
072b16f2e2
コミット
8e041638db
3ファイル変更
+4
-106
検索条件に一致するファイルはありません
@@ -37,7 +37,7 @@ namespace DirectX12ComputeShaderSample
|
||||
|
||||
// Create graphics device and pipeline state
|
||||
|
||||
using GraphicsDevice device = new GraphicsDevice(SharpDX.Direct3D.FeatureLevel.Level_12_1, true);
|
||||
using GraphicsDevice device = new GraphicsDevice(true);
|
||||
|
||||
SharpDX.Direct3D12.RootParameter[] rootParameters = new SharpDX.Direct3D12.RootParameter[]
|
||||
{
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using SharpDX.Direct3D;
|
||||
using SharpDX.Direct3D12;
|
||||
using SharpDX.Mathematics.Interop;
|
||||
|
||||
namespace DirectX12GameEngine.Graphics
|
||||
{
|
||||
public sealed class CommandList : IDisposable
|
||||
{
|
||||
private const int MaxRenderTargetCount = 8;
|
||||
private const int MaxViewportAndScissorRectangleCount = 16;
|
||||
|
||||
private readonly CompiledCommandList currentCommandList;
|
||||
|
||||
public CommandList(GraphicsDevice device, CommandListType commandListType)
|
||||
@@ -30,24 +24,6 @@ namespace DirectX12GameEngine.Graphics
|
||||
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
public RawRectangle[] ScissorRectangles { get; private set; } = Array.Empty<RawRectangle>();
|
||||
|
||||
public RawViewportF[] Viewports { get; private set; } = Array.Empty<RawViewportF>();
|
||||
|
||||
public PrimitiveTopology PrimitiveTopology { set => currentCommandList.NativeCommandList.PrimitiveTopology = value; }
|
||||
|
||||
public void BeginRenderPass(int numRenderTargets, RenderPassRenderTargetDescription[] renderTargetsRef, RenderPassDepthStencilDescription? depthStencilRef, RenderPassFlags flags)
|
||||
{
|
||||
using GraphicsCommandList4 commandList = currentCommandList.NativeCommandList.QueryInterface<GraphicsCommandList4>();
|
||||
commandList.BeginRenderPass(numRenderTargets, renderTargetsRef, depthStencilRef, flags);
|
||||
}
|
||||
|
||||
public void EndRenderPass()
|
||||
{
|
||||
using GraphicsCommandList4 commandList = currentCommandList.NativeCommandList.QueryInterface<GraphicsCommandList4>();
|
||||
commandList.EndRenderPass();
|
||||
}
|
||||
|
||||
public CompiledCommandList Close()
|
||||
{
|
||||
//foreach (var renderTarget in RenderTargets)
|
||||
@@ -70,11 +46,6 @@ namespace DirectX12GameEngine.Graphics
|
||||
currentCommandList.NativeCommandList.CopyResource(destination.NativeResource, source.NativeResource);
|
||||
}
|
||||
|
||||
public void CopyTextureRegion(TextureCopyLocation source, TextureCopyLocation destination)
|
||||
{
|
||||
currentCommandList.NativeCommandList.CopyTextureRegion(destination, 0, 0, 0, source, null);
|
||||
}
|
||||
|
||||
public void Dispatch(int threadGroupCountX, int threadGroupCountY, int threadGroupCountZ)
|
||||
{
|
||||
currentCommandList.NativeCommandList.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
|
||||
@@ -103,24 +74,6 @@ namespace DirectX12GameEngine.Graphics
|
||||
currentCommandList.NativeCommandList.Dispose();
|
||||
}
|
||||
|
||||
public void DrawIndexedInstanced(int indexCountPerInstance, int instanceCount, int startIndexLocation = 0, int baseVertexLocation = 0, int startInstanceLocation = 0)
|
||||
{
|
||||
currentCommandList.NativeCommandList.DrawIndexedInstanced(indexCountPerInstance, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation);
|
||||
}
|
||||
|
||||
public void DrawInstanced(int vertexCountPerInstance, int instanceCount, int startVertexLocation = 0, int startInstanceLocation = 0)
|
||||
{
|
||||
currentCommandList.NativeCommandList.DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation);
|
||||
}
|
||||
|
||||
public void ExecuteBundle(CompiledCommandList commandList)
|
||||
{
|
||||
if (currentCommandList != commandList && commandList.Builder.CommandListType == CommandListType.Bundle)
|
||||
{
|
||||
currentCommandList.NativeCommandList.ExecuteBundle(commandList.NativeCommandList);
|
||||
}
|
||||
}
|
||||
|
||||
public void Flush(bool wait = false)
|
||||
{
|
||||
GraphicsDevice.ExecuteCommandLists(wait, Close());
|
||||
@@ -194,11 +147,6 @@ namespace DirectX12GameEngine.Graphics
|
||||
currentCommandList.NativeCommandList.SetComputeRootUnorderedAccessView(rootParameterIndex, resource.NativeResource.GPUVirtualAddress);
|
||||
}
|
||||
|
||||
public void SetIndexBuffer(IndexBufferView? indexBufferView)
|
||||
{
|
||||
currentCommandList.NativeCommandList.SetIndexBuffer(indexBufferView);
|
||||
}
|
||||
|
||||
public void SetPipelineState(PipelineState pipelineState)
|
||||
{
|
||||
SetComputeRootSignature(pipelineState.RootSignature);
|
||||
@@ -206,45 +154,6 @@ namespace DirectX12GameEngine.Graphics
|
||||
currentCommandList.NativeCommandList.PipelineState = pipelineState.NativePipelineState;
|
||||
}
|
||||
|
||||
public void SetScissorRectangles(params RawRectangle[] scissorRectangles)
|
||||
{
|
||||
if (scissorRectangles.Length > MaxViewportAndScissorRectangleCount)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(scissorRectangles), scissorRectangles.Length, $"The maximum number of scissor rectangles is {MaxViewportAndScissorRectangleCount}.");
|
||||
}
|
||||
|
||||
if (ScissorRectangles.Length != scissorRectangles.Length)
|
||||
{
|
||||
ScissorRectangles = new RawRectangle[scissorRectangles.Length];
|
||||
}
|
||||
|
||||
scissorRectangles.CopyTo(ScissorRectangles, 0);
|
||||
|
||||
currentCommandList.NativeCommandList.SetScissorRectangles(scissorRectangles);
|
||||
}
|
||||
|
||||
public void SetVertexBuffers(int startSlot, params VertexBufferView[] vertexBufferViews)
|
||||
{
|
||||
currentCommandList.NativeCommandList.SetVertexBuffers(startSlot, vertexBufferViews);
|
||||
}
|
||||
|
||||
public void SetViewports(params RawViewportF[] viewports)
|
||||
{
|
||||
if (viewports.Length > MaxViewportAndScissorRectangleCount)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(viewports), viewports.Length, $"The maximum number of viewporst is {MaxViewportAndScissorRectangleCount}.");
|
||||
}
|
||||
|
||||
if (Viewports.Length != viewports.Length)
|
||||
{
|
||||
Viewports = new RawViewportF[viewports.Length];
|
||||
}
|
||||
|
||||
viewports.CopyTo(Viewports, 0);
|
||||
|
||||
currentCommandList.NativeCommandList.SetViewports(viewports);
|
||||
}
|
||||
|
||||
private CommandAllocator GetCommandAllocator() => CommandListType switch
|
||||
{
|
||||
CommandListType.Bundle => GraphicsDevice.BundleAllocatorPool.GetCommandAllocator(),
|
||||
|
||||
@@ -8,18 +8,12 @@ namespace DirectX12GameEngine.Graphics
|
||||
public sealed class GraphicsDevice : IDisposable
|
||||
{
|
||||
private readonly AutoResetEvent fenceEvent = new AutoResetEvent(false);
|
||||
private SharpDX.Direct3D11.Device? nativeDirect3D11Device;
|
||||
|
||||
public GraphicsDevice(FeatureLevel minFeatureLevel = FeatureLevel.Level_11_0, bool enableDebugLayer = false)
|
||||
public GraphicsDevice(bool enableDebugLayer = false)
|
||||
{
|
||||
#if DEBUG
|
||||
if (enableDebugLayer)
|
||||
{
|
||||
DebugInterface.Get().EnableDebugLayer();
|
||||
}
|
||||
if (enableDebugLayer) DebugInterface.Get().EnableDebugLayer();
|
||||
#endif
|
||||
FeatureLevel = minFeatureLevel < FeatureLevel.Level_11_0 ? FeatureLevel.Level_11_0 : minFeatureLevel;
|
||||
|
||||
NativeDevice = new Device(null, FeatureLevel);
|
||||
|
||||
NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Compute));
|
||||
@@ -50,13 +44,10 @@ namespace DirectX12GameEngine.Graphics
|
||||
|
||||
public CommandList CopyCommandList { get; }
|
||||
|
||||
public FeatureLevel FeatureLevel { get; }
|
||||
public const FeatureLevel FeatureLevel = SharpDX.Direct3D.FeatureLevel.Level_12_1;
|
||||
|
||||
internal Device NativeDevice { get; }
|
||||
|
||||
internal SharpDX.Direct3D11.Device NativeDirect3D11Device => NativeDirect3D11Device ?? (nativeDirect3D11Device = SharpDX.Direct3D11.Device.CreateFromDirect3D12(
|
||||
NativeDevice, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, null, null, NativeDirectCommandQueue));
|
||||
|
||||
internal DescriptorAllocator DepthStencilViewAllocator { get; set; }
|
||||
|
||||
internal DescriptorAllocator RenderTargetViewAllocator { get; set; }
|
||||
@@ -119,8 +110,6 @@ namespace DirectX12GameEngine.Graphics
|
||||
NativeDirectFence.Dispose();
|
||||
NativeDirectFence.Dispose();
|
||||
|
||||
nativeDirect3D11Device?.Dispose();
|
||||
|
||||
NativeDevice.Dispose();
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする