Exemplo n.º 1
0
        private static CachedPipeline CreateAndCachePipeline(this ResourceFactory resourceFactory, SimplePipelineDescription simplePipelineDescription)
        {
            var shaderSet           = resourceFactory.GetShaderSet(simplePipelineDescription.ShaderSettings);
            var pipelineDescription = new GraphicsPipelineDescription(
                simplePipelineDescription.FilterMode.ToBlendStateDescription(),
                DepthStencilStateDescription.DepthOnlyLessEqual,
                new RasterizerStateDescription(FaceCullMode.Back, PolygonFillMode.Solid, FrontFace.CounterClockwise, true, false),
                simplePipelineDescription.FaceType.ToPrimitiveTopology(),
                shaderSet.ShaderSetDescription,
                shaderSet.ResourceLayout,
                simplePipelineDescription.OutputDescription);

            var pipeline = resourceFactory.CreateGraphicsPipeline(ref pipelineDescription);

            var cachedPipeline = new CachedPipeline
            {
                Pipeline       = pipeline,
                ResourceLayout = shaderSet.ResourceLayout,
            };

            _cachedPipelines[resourceFactory].Add(simplePipelineDescription, cachedPipeline);
            return(cachedPipeline);
        }
Exemplo n.º 2
0
        public static CachedPipeline GetPipeline(this ResourceFactory resourceFactory, SimplePipelineDescription simplePipelineDescription)
        {
            if (!_cachedPipelines.TryGetValue(resourceFactory, out var pipelineDictionary))
            {
                pipelineDictionary = new Dictionary <SimplePipelineDescription, CachedPipeline>();
                _cachedPipelines.Add(resourceFactory, pipelineDictionary);
            }

            return(pipelineDictionary.TryGetValue(simplePipelineDescription, out var value) ? value : resourceFactory.CreateAndCachePipeline(simplePipelineDescription));
        }