Exemplo n.º 1
0
 private bool Equals(BuiltPipeline built)
 {
     return
         (built.ShaderSetName == shaderSetName &&
          built.Description.Outputs.Equals(OutputDescription) &&
          AreVertexLayoutsEqual(built.Description.ShaderSet.VertexLayouts) &&
          AreResourceLayoutsEqual(built.ResourceLayoutDescriptions) &&
          built.Description.RasterizerState.Equals(rasterizer) &&
          built.Description.BlendState.Equals(blendState) &&
          built.Description.DepthStencilState.Equals(depthStencil) &&
          built.Description.PrimitiveTopology == primitiveTopology);
 }
Exemplo n.º 2
0
            public IBuiltPipeline Build()
            {
                if (shaderSetName == null)
                {
                    throw new InvalidOperationException("No shader set was specified");
                }
                if (depthTarget == null && colorTargets.Count == 0)
                {
                    throw new InvalidOperationException("Neither a depth target nor a color target was specified");
                }
                if (vertexElements.Last().Count() == 0)
                {
                    throw new InvalidOperationException("Last vertex layout has no elements");
                }
                if (resLayoutElements.Last().Count() == 0)
                {
                    throw new InvalidOperationException("Last resource layout has no elements");
                }

                lock (Collection)
                {
                    var builtPipeline = Collection.pipelines.FirstOrDefault(Equals);
                    if (builtPipeline != null)
                    {
                        return(builtPipeline);
                    }

                    var vertexLayouts = vertexElements
                                        .Select(set => new VertexLayoutDescription(set.ToArray()))
                                        .Select((set, i) => { set.InstanceStepRate = vertexLayoutInstanceStepRates[i]; return(set); })
                                        .ToArray();
                    var resLayoutDescrs = resLayoutElements
                                          .Select(set => new ResourceLayoutDescription(set.ToArray()))
                                          .ToArray();
                    var resourceLayouts = resLayoutDescrs
                                          .Select(layoutDescr => Collection.Factory.CreateResourceLayout(layoutDescr))
                                          .ToArray();
                    var shaders       = Collection.LoadShaderSet(shaderSetName);
                    var pipelineDescr = new GraphicsPipelineDescription(
                        blendState,
                        depthStencil,
                        rasterizer,
                        primitiveTopology,
                        new ShaderSetDescription(vertexLayouts, shaders),
                        resourceLayouts,
                        OutputDescription);
                    var pipeline = Collection.Factory.CreateGraphicsPipeline(pipelineDescr);
                    builtPipeline = new BuiltPipeline(pipeline, pipelineDescr, resLayoutDescrs, shaderSetName);

                    Collection.pipelines.Add(builtPipeline);
                    return(builtPipeline);
                }
            }