PipelineState class simplified

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-11 02:04:57 +02:00
1 親 5c07022eec
コミット 5a3ebc3338
2ファイル変更
+24 -84

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

+1 -8
ファイルの表示
@@ -201,14 +201,7 @@ namespace DirectX12GameEngine.Graphics
public void SetPipelineState(PipelineState pipelineState)
{
if (pipelineState.IsCompute)
{
SetComputeRootSignature(pipelineState.RootSignature);
}
else
{
SetGraphicsRootSignature(pipelineState.RootSignature);
}
SetComputeRootSignature(pipelineState.RootSignature);
currentCommandList.NativeCommandList.PipelineState = pipelineState.NativePipelineState;
}
+23 -76
ファイルの表示
@@ -1,88 +1,35 @@
using SharpDX.Direct3D;
using SharpDX.Direct3D12;
using SharpDX.DXGI;
using SharpDX.Direct3D12;
namespace DirectX12GameEngine.Graphics
{
public sealed class PipelineState
/// <summary>
/// A <see langword="class"/> representing a custom pipeline state for a compute operation
/// </summary>
public sealed class PipelineState : ComputePipelineStateDescription
{
public PipelineState(GraphicsDevice device, ComputePipelineStateDescription pipelineStateDescription)
{
IsCompute = true;
RootSignature = pipelineStateDescription.RootSignaturePointer;
NativePipelineState = device.NativeDevice.CreateComputePipelineState(pipelineStateDescription);
}
/// <summary>
/// Creates a new <see cref="PipelineState"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> to use</param>
/// <param name="rootSignature">The <see cref="SharpDX.Direct3D12.RootSignature"/> value for the current shader</param>
/// <param name="computeShader">The bytecode for the compute shader to run</param>
public PipelineState(GraphicsDevice device, RootSignature rootSignature, ShaderBytecode computeShader)
: this(device, CreateComputePipelineStateDescription(rootSignature, computeShader))
{
}
public PipelineState(GraphicsDevice device, GraphicsPipelineStateDescription pipelineStateDescription)
{
IsCompute = false;
RootSignature = pipelineStateDescription.RootSignature;
NativePipelineState = device.NativeDevice.CreateGraphicsPipelineState(pipelineStateDescription);
}
public PipelineState(GraphicsDevice device, InputElement[] inputElements, RootSignature rootSignature, ShaderBytecode vertexShader, ShaderBytecode pixelShader, ShaderBytecode hullShader = default, ShaderBytecode domainShader = default, ShaderBytecode geometryShader = default, RasterizerStateDescription? rasterizerStateDescription = null)
: this(device, CreateGraphicsPipelineStateDescription(device, inputElements, rootSignature, vertexShader, pixelShader, hullShader, domainShader, geometryShader, rasterizerStateDescription))
{
RootSignaturePointer = rootSignature;
ComputeShader = computeShader;
RootSignature = RootSignaturePointer;
NativePipelineState = device.NativeDevice.CreateComputePipelineState(this);
}
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D12.RootSignature"/> value for the current shader
/// </summary>
public RootSignature RootSignature { get; }
internal bool IsCompute { get; }
internal SharpDX.Direct3D12.PipelineState NativePipelineState { get; }
private static ComputePipelineStateDescription CreateComputePipelineStateDescription(RootSignature rootSignature, ShaderBytecode computeShader)
{
return new ComputePipelineStateDescription
{
RootSignaturePointer = rootSignature,
ComputeShader = computeShader
};
}
private static GraphicsPipelineStateDescription CreateGraphicsPipelineStateDescription(GraphicsDevice device, InputElement[] inputElements, RootSignature rootSignature, ShaderBytecode vertexShader, ShaderBytecode pixelShader, ShaderBytecode hullShader, ShaderBytecode domainShader, ShaderBytecode geometryShader, RasterizerStateDescription? rasterizerStateDescription)
{
RasterizerStateDescription rasterizerDescription = rasterizerStateDescription ?? RasterizerStateDescription.Default();
rasterizerDescription.IsFrontCounterClockwise = true;
rasterizerDescription.CullMode = CullMode.None;
BlendStateDescription blendStateDescription = BlendStateDescription.Default();
RenderTargetBlendDescription[] renderTargetDescriptions = blendStateDescription.RenderTarget;
for (int i = 0; i < renderTargetDescriptions.Length; i++)
{
renderTargetDescriptions[i].IsBlendEnabled = true;
renderTargetDescriptions[i].SourceBlend = BlendOption.SourceAlpha;
renderTargetDescriptions[i].DestinationBlend = BlendOption.InverseSourceAlpha;
}
DepthStencilStateDescription depthStencilStateDescription = DepthStencilStateDescription.Default();
GraphicsPipelineStateDescription pipelineStateDescription = new GraphicsPipelineStateDescription
{
InputLayout = new InputLayoutDescription(inputElements),
RootSignature = rootSignature,
VertexShader = vertexShader,
PixelShader = pixelShader,
HullShader = hullShader,
DomainShader = domainShader,
GeometryShader = geometryShader,
RasterizerState = rasterizerDescription,
BlendState = blendStateDescription,
DepthStencilState = depthStencilStateDescription,
SampleMask = int.MaxValue,
PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
RenderTargetCount = 1,
SampleDescription = new SampleDescription(1, 0),
StreamOutput = new StreamOutputDescription()
};
return pipelineStateDescription;
}
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D12.PipelineState"/> instance for the current <see cref="PipelineState"/> object
/// </summary>
public SharpDX.Direct3D12.PipelineState NativePipelineState { get; }
}
}