/// <summary> /// Function to copy the contents of a pipeline state to another pipeline state. /// </summary> /// <param name="pipelineState">The pipeline state to copy.</param> internal void CopyTo(GorgonPipelineState pipelineState) { if (RasterState != null) { if (pipelineState.RasterState == null) { pipelineState.RasterState = new GorgonRasterState(); } pipelineState.RasterState.IsAntialiasedLineEnabled = RasterState.IsAntialiasedLineEnabled; pipelineState.RasterState.CullMode = RasterState.CullMode; pipelineState.RasterState.DepthBias = RasterState.DepthBias; pipelineState.RasterState.DepthBiasClamp = RasterState.DepthBiasClamp; pipelineState.RasterState.IsDepthClippingEnabled = RasterState.IsDepthClippingEnabled; pipelineState.RasterState.FillMode = RasterState.FillMode; pipelineState.RasterState.ForcedReadWriteViewSampleCount = RasterState.ForcedReadWriteViewSampleCount; pipelineState.RasterState.IsFrontCounterClockwise = RasterState.IsFrontCounterClockwise; pipelineState.RasterState.IsMultisamplingEnabled = RasterState.IsMultisamplingEnabled; pipelineState.RasterState.RwScissorRectangles.AddRange(RasterState.RwScissorRectangles); pipelineState.RasterState.SlopeScaledDepthBias = RasterState.SlopeScaledDepthBias; pipelineState.RasterState.UseConservativeRasterization = RasterState.UseConservativeRasterization; } if (DepthStencilState != null) { if (pipelineState.DepthStencilState == null) { pipelineState.DepthStencilState = new GorgonDepthStencilState(); } pipelineState.DepthStencilState.BackFaceStencilOp.Comparison = DepthStencilState.BackFaceStencilOp.Comparison; pipelineState.DepthStencilState.BackFaceStencilOp.DepthFailOperation = DepthStencilState.BackFaceStencilOp.DepthFailOperation; pipelineState.DepthStencilState.BackFaceStencilOp.FailOperation = DepthStencilState.BackFaceStencilOp.FailOperation; pipelineState.DepthStencilState.BackFaceStencilOp.PassOperation = DepthStencilState.BackFaceStencilOp.PassOperation; pipelineState.DepthStencilState.FrontFaceStencilOp.Comparison = DepthStencilState.FrontFaceStencilOp.Comparison; pipelineState.DepthStencilState.FrontFaceStencilOp.DepthFailOperation = DepthStencilState.FrontFaceStencilOp.DepthFailOperation; pipelineState.DepthStencilState.FrontFaceStencilOp.FailOperation = DepthStencilState.FrontFaceStencilOp.FailOperation; pipelineState.DepthStencilState.FrontFaceStencilOp.PassOperation = DepthStencilState.FrontFaceStencilOp.PassOperation; pipelineState.DepthStencilState.DepthComparison = DepthStencilState.DepthComparison; pipelineState.DepthStencilState.IsDepthWriteEnabled = DepthStencilState.IsDepthWriteEnabled; pipelineState.DepthStencilState.IsDepthEnabled = DepthStencilState.IsDepthEnabled; pipelineState.DepthStencilState.IsStencilEnabled = DepthStencilState.IsStencilEnabled; pipelineState.DepthStencilState.StencilReadMask = DepthStencilState.StencilReadMask; pipelineState.DepthStencilState.StencilWriteMask = DepthStencilState.StencilWriteMask; } pipelineState.IsIndependentBlendingEnabled = IsIndependentBlendingEnabled; pipelineState.IsAlphaToCoverageEnabled = IsAlphaToCoverageEnabled; pipelineState.PixelShader = PixelShader; pipelineState.VertexShader = VertexShader; pipelineState.GeometryShader = GeometryShader; pipelineState.DomainShader = DomainShader; pipelineState.HullShader = HullShader; pipelineState.PrimitiveType = PrimitiveType; RwBlendStates.CopyTo(pipelineState.RwBlendStates); }
/// <summary> /// Function to build the D3D11 blend state. /// </summary> /// <param name="device">The device used to create the blend state.</param> internal void BuildD3D11BlendState(D3D11.Device5 device) { Debug.Assert(D3DBlendState == null, "D3D Blend state already assigned to this pipeline state."); (int start, int count) = RwBlendStates.GetDirtyItems(); var desc = new D3D11.BlendStateDescription1 { AlphaToCoverageEnable = IsAlphaToCoverageEnabled, IndependentBlendEnable = IsIndependentBlendingEnabled }; for (int i = 0; i < count; ++i) { GorgonBlendState state = RwBlendStates[start + i]; if (state == null) { continue; } desc.RenderTarget[i] = new D3D11.RenderTargetBlendDescription1 { AlphaBlendOperation = (D3D11.BlendOperation)state.AlphaBlendOperation, BlendOperation = (D3D11.BlendOperation)state.ColorBlendOperation, IsLogicOperationEnabled = state.LogicOperation != LogicOperation.Noop, IsBlendEnabled = state.IsBlendingEnabled, RenderTargetWriteMask = (D3D11.ColorWriteMaskFlags)state.WriteMask, LogicOperation = (D3D11.LogicOperation)state.LogicOperation, SourceAlphaBlend = (D3D11.BlendOption)state.SourceAlphaBlend, SourceBlend = (D3D11.BlendOption)state.SourceColorBlend, DestinationAlphaBlend = (D3D11.BlendOption)state.DestinationAlphaBlend, DestinationBlend = (D3D11.BlendOption)state.DestinationColorBlend }; } for (int i = count; i < D3D11.OutputMergerStage.SimultaneousRenderTargetCount; ++i) { desc.RenderTarget[i] = new D3D11.RenderTargetBlendDescription1 { AlphaBlendOperation = D3D11.BlendOperation.Add, BlendOperation = D3D11.BlendOperation.Add, IsLogicOperationEnabled = false, IsBlendEnabled = false, RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All, LogicOperation = D3D11.LogicOperation.Noop, SourceAlphaBlend = D3D11.BlendOption.One, SourceBlend = D3D11.BlendOption.One, DestinationAlphaBlend = D3D11.BlendOption.Zero, DestinationBlend = D3D11.BlendOption.Zero }; } D3DBlendState = new D3D11.BlendState1(device, desc) { DebugName = nameof(GorgonBlendState) }; }
/// <summary> /// Function to clear the pipeline state. /// </summary> internal void Clear() { D3DBlendState = null; D3DDepthStencilState = null; D3DRasterState = null; RasterState = null; DepthStencilState = null; IsIndependentBlendingEnabled = false; IsAlphaToCoverageEnabled = false; PixelShader = null; VertexShader = null; GeometryShader = null; DomainShader = null; HullShader = null; PrimitiveType = PrimitiveType.None; RwBlendStates.Clear(); }