Example #1
0
        private void CheckPipelines(string shaderName, ShaderData shaderData)
        {
            var pd = new GraphicsPipelineDescription();

            pd.BlendState           = activeCamera.BlendState;
            pd.RasterizerState      = activeCamera.RasterizerState;
            pd.DepthStencilState    = activeCamera.DepthStencilState;
            pd.ResourceBindingModel = ResourceBindingModel.Improved;
            pd.PrimitiveTopology    = PrimitiveTopology.TriangleStrip;          // TODO: Change to TriangleList
            pd.ResourceLayouts      = shaderData.ResourceLayouts;
            pd.ShaderSet            = new ShaderSetDescription(vertexLayoutDescriptions, shaderData.Shaders);
            pd.Outputs = activeCamera.RenderTarget.OutputDescription;

            if (PipelineList.TryAdd(pd.GetHashCode(), _gd.ResourceFactory.CreateGraphicsPipeline(ref pd)))
            {
                PipelineList[pd.GetHashCode()].Name = shaderName;
            }
        }
        /// <summary>
        /// Determine and updates <see cref="CurrentState"/> from <see cref="State"/>.
        /// </summary>
        public void Update()
        {
            // Hash current state
            var hashedState = State.GetHashCode();

            // Find existing PipelineState object
            Pipeline pipelineState;

            // TODO GRAPHICS REFACTOR We could avoid lock by adding them to a ThreadLocal (or RenderContext) and merge at end of frame
            lock (cache)
            {
                //仅缓存10万个可编程渲染管线
                if (cache.Count > 100000)
                {
                    throw new Exception("over flow pipeline");
                }
                if (!cache.TryGetValue(hashedState, out pipelineState))
                {
                    cache.Add(hashedState, pipelineState = graphicsDevice.ResourceFactory.CreateGraphicsPipeline(State));
                }
            }
            CurrentPipeLine = pipelineState;
        }