Пример #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 SetComputeRootSignature(RootSignature rootSignature)
 {
     currentRootSignature = rootSignature;
     commandList.SetComputeRootSignature(rootSignature.rootSignature);
 }
Пример #3
0
        public void CreateRootSignature(RootSignature rootSignature, IList <RootSignatureParamP> types)
        {
            //static samplers
            StaticSamplerDescription[] samplerDescription = new StaticSamplerDescription[4];
            samplerDescription[0] = new StaticSamplerDescription(ShaderVisibility.All, 0, 0)
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = StaticBorderColor.OpaqueBlack,
                ComparisonFunction = ComparisonFunction.Never,
                Filter             = Filter.MinMagMipLinear,
                MipLODBias         = 0,
                MaxAnisotropy      = 0,
                MinLOD             = 0,
                MaxLOD             = float.MaxValue,
                ShaderVisibility   = ShaderVisibility.All,
                RegisterSpace      = 0,
                ShaderRegister     = 0,
            };
            samplerDescription[1] = samplerDescription[0];
            samplerDescription[2] = samplerDescription[0];
            samplerDescription[3] = samplerDescription[0];

            samplerDescription[1].ShaderRegister     = 1;
            samplerDescription[2].ShaderRegister     = 2;
            samplerDescription[3].ShaderRegister     = 3;
            samplerDescription[1].MaxAnisotropy      = 16;
            samplerDescription[1].Filter             = Filter.Anisotropic;
            samplerDescription[2].ComparisonFunction = ComparisonFunction.Less;
            samplerDescription[2].Filter             = Filter.ComparisonMinMagMipLinear;
            samplerDescription[3].Filter             = Filter.MinMagMipPoint;

            RootParameter1[] rootParameters = new RootParameter1[types.Count];

            int cbvCount = 0;
            int srvCount = 0;
            int uavCount = 0;

            rootSignature.cbv.Clear();
            rootSignature.srv.Clear();
            rootSignature.uav.Clear();

            for (int i = 0; i < types.Count; i++)
            {
                RootSignatureParamP t = types[i];
                switch (t)
                {
                case RootSignatureParamP.CBV:
                    rootParameters[i]           = new RootParameter1(RootParameterType.ConstantBufferView, new RootDescriptor1(cbvCount, 0), ShaderVisibility.All);
                    rootSignature.cbv[cbvCount] = i;
                    cbvCount++;
                    break;

                case RootSignatureParamP.SRV:
                    rootParameters[i]           = new RootParameter1(RootParameterType.ShaderResourceView, new RootDescriptor1(srvCount, 0), ShaderVisibility.All);
                    rootSignature.srv[srvCount] = i;
                    srvCount++;
                    break;

                case RootSignatureParamP.UAV:
                    rootParameters[i]           = new RootParameter1(RootParameterType.UnorderedAccessView, new RootDescriptor1(uavCount, 0), ShaderVisibility.All);
                    rootSignature.uav[uavCount] = i;
                    uavCount++;
                    break;

                case RootSignatureParamP.CBVTable:
                    rootParameters[i]           = new RootParameter1(new RootDescriptorTable1(new DescriptorRange1(DescriptorRangeType.ConstantBufferView, 1, cbvCount)), ShaderVisibility.All);
                    rootSignature.cbv[cbvCount] = i;
                    cbvCount++;
                    break;

                case RootSignatureParamP.SRVTable:
                    rootParameters[i]           = new RootParameter1(new RootDescriptorTable1(new DescriptorRange1(DescriptorRangeType.ShaderResourceView, 1, srvCount)), ShaderVisibility.All);
                    rootSignature.srv[srvCount] = i;
                    srvCount++;
                    break;

                case RootSignatureParamP.UAVTable:
                    rootParameters[i]           = new RootParameter1(new RootDescriptorTable1(new DescriptorRange1(DescriptorRangeType.UnorderedAccessView, 1, uavCount)), ShaderVisibility.All);
                    rootSignature.uav[uavCount] = i;
                    uavCount++;
                    break;
                }
            }

            RootSignatureDescription1 rootSignatureDescription = new RootSignatureDescription1();

            rootSignatureDescription.StaticSamplers = samplerDescription;
            rootSignatureDescription.Flags          = RootSignatureFlags.AllowInputAssemblerInputLayout;
            rootSignatureDescription.Parameters     = rootParameters;

            rootSignature.rootSignature = device.CreateRootSignature <ID3D12RootSignature>(0, rootSignatureDescription);
        }
Пример #4
0
 public void SetRootSignature(RootSignature rootSignature)
 {
     currentRootSignature = rootSignature;
     commandList.SetGraphicsRootSignature(rootSignature.rootSignature);
 }