コード例 #1
0
        public ID3D12PipelineState GetState(GraphicsDevice device, PSODesc desc, RootSignature rootSignature)
        {
            foreach (var psoCombind in PSOCombinds)
            {
                if (psoCombind.PSODesc == desc && psoCombind.rootSignature == rootSignature)
                {
                    if (psoCombind.pipelineState == null)
                    {
                        throw new Exception("pipeline state error");
                    }
                    return(psoCombind.pipelineState);
                }
            }
            InputLayoutDescription inputLayoutDescription;

            if (device.inputLayouts.TryGetValue(desc.InputLayout, out inputLayoutDescription))
            {
            }
            else
            {
                inputLayoutDescription = new InputLayoutDescription(new InputElementDescription("POSITION", 0, Format.R32G32B32_Float, 0));
            }

            GraphicsPipelineStateDescription graphicsPipelineStateDescription = new GraphicsPipelineStateDescription();

            graphicsPipelineStateDescription.RootSignature         = rootSignature.rootSignature;
            graphicsPipelineStateDescription.VertexShader          = vertexShader;
            graphicsPipelineStateDescription.GeometryShader        = geometryShader;
            graphicsPipelineStateDescription.PixelShader           = pixelShader;
            graphicsPipelineStateDescription.PrimitiveTopologyType = PrimitiveTopologyType.Triangle;
            graphicsPipelineStateDescription.InputLayout           = inputLayoutDescription;
            graphicsPipelineStateDescription.DepthStencilFormat    = desc.DepthStencilFormat;
            graphicsPipelineStateDescription.RenderTargetFormats   = new Format[desc.RenderTargetCount];
            Array.Fill(graphicsPipelineStateDescription.RenderTargetFormats, desc.RenderTargetFormat);

            if (desc.BlendState == "Alpha")
            {
                graphicsPipelineStateDescription.BlendState = blendStateAlpha();
            }
            else if (desc.BlendState == "Add")
            {
                graphicsPipelineStateDescription.BlendState = BlendDescription.Additive;
            }
            else
            {
                graphicsPipelineStateDescription.BlendState = BlendDescription.Opaque;
            }


            graphicsPipelineStateDescription.DepthStencilState = new DepthStencilDescription(desc.DepthStencilFormat != Format.Unknown, desc.DepthStencilFormat != Format.Unknown);
            graphicsPipelineStateDescription.SampleMask        = uint.MaxValue;
            var RasterizerState = new RasterizerDescription(CullMode.None, FillMode.Solid);

            RasterizerState.DepthBias                        = desc.DepthBias;
            RasterizerState.SlopeScaledDepthBias             = desc.SlopeScaledDepthBias;
            graphicsPipelineStateDescription.RasterizerState = RasterizerState;

            var pipelineState = device.device.CreateGraphicsPipelineState <ID3D12PipelineState>(graphicsPipelineStateDescription);

            if (pipelineState == null)
            {
                throw new Exception("pipeline state error");
            }
            PSOCombinds.Add(new PSOCombind {
                PSODesc = desc, pipelineState = pipelineState, rootSignature = rootSignature
            });
            return(pipelineState);
        }
コード例 #2
0
 public void SetPipelineState(PipelineStateObject pipelineStateObject, PSODesc psoDesc)
 {
     commandList.SetPipelineState(pipelineStateObject.GetState(graphicsDevice, psoDesc, currentRootSignature));
 }