Exemplo n.º 1
0
        protected void init(GraphicPipelineConfig cfg)
        {
            if (state != ActivableState.Activated)
            {
                Layout.Activate();
                RenderPass.Activate();
                Cache?.Activate();

                List <VkPipelineShaderStageCreateInfo> shaderStages = new List <VkPipelineShaderStageCreateInfo> ();
                foreach (ShaderInfo shader in cfg.Shaders)
                {
                    shaderStages.Add(shader.Info);
                }

                using (PinnedObjects pctx = new PinnedObjects()) {
                    VkPipelineColorBlendStateCreateInfo colorBlendInfo = VkPipelineColorBlendStateCreateInfo.New();
                    colorBlendInfo.logicOpEnable = cfg.ColorBlendLogicOpEnable;
                    colorBlendInfo.logicOp       = cfg.ColorBlendLogicOp;
                    unsafe {
                        colorBlendInfo.blendConstants[0] = cfg.ColorBlendConstants.X;
                        colorBlendInfo.blendConstants[1] = cfg.ColorBlendConstants.Y;
                        colorBlendInfo.blendConstants[2] = cfg.ColorBlendConstants.Z;
                        colorBlendInfo.blendConstants[3] = cfg.ColorBlendConstants.W;
                    }
                    colorBlendInfo.attachmentCount = (uint)cfg.blendAttachments.Count;
                    colorBlendInfo.pAttachments    = cfg.blendAttachments.Pin(pctx);

                    VkPipelineDynamicStateCreateInfo dynStatesInfo = VkPipelineDynamicStateCreateInfo.New();
                    dynStatesInfo.dynamicStateCount = (uint)cfg.dynamicStates.Count;
                    dynStatesInfo.pDynamicStates    = cfg.dynamicStates.Cast <int> ().ToArray().Pin(pctx);

                    VkPipelineVertexInputStateCreateInfo vertInputInfo = VkPipelineVertexInputStateCreateInfo.New();
                    vertInputInfo.vertexBindingDescriptionCount   = (uint)cfg.vertexBindings.Count;
                    vertInputInfo.pVertexBindingDescriptions      = cfg.vertexBindings.Pin(pctx);
                    vertInputInfo.vertexAttributeDescriptionCount = (uint)cfg.vertexAttributes.Count;
                    vertInputInfo.pVertexAttributeDescriptions    = cfg.vertexAttributes.Pin(pctx);

                    VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New();
                    if (cfg.Viewports.Count > 0)
                    {
                        viewportState.viewportCount = (uint)cfg.Viewports.Count;
                        viewportState.pViewports    = cfg.Viewports.Pin(pctx);
                    }
                    else
                    {
                        viewportState.viewportCount = 1;
                    }

                    if (cfg.Scissors.Count > 0)
                    {
                        viewportState.scissorCount = (uint)cfg.Scissors.Count;
                        viewportState.pScissors    = cfg.Scissors.Pin(pctx);
                    }
                    else
                    {
                        viewportState.scissorCount = 1;
                    }

                    VkGraphicsPipelineCreateInfo info = VkGraphicsPipelineCreateInfo.New();
                    info.renderPass          = RenderPass.handle;
                    info.layout              = Layout.handle;
                    info.pVertexInputState   = vertInputInfo.Pin(pctx);
                    info.pInputAssemblyState = cfg.inputAssemblyState.Pin(pctx);
                    info.pRasterizationState = cfg.rasterizationState.Pin(pctx);
                    info.pColorBlendState    = colorBlendInfo.Pin(pctx);
                    info.pMultisampleState   = cfg.multisampleState.Pin(pctx);
                    info.pViewportState      = viewportState.Pin(pctx);
                    info.pDepthStencilState  = cfg.depthStencilState.Pin(pctx);
                    info.pDynamicState       = dynStatesInfo.Pin(pctx);
                    info.stageCount          = (uint)cfg.Shaders.Count;
                    info.pStages             = shaderStages.Pin(pctx);
                    info.subpass             = cfg.SubpassIndex;

                    Utils.CheckResult(vkCreateGraphicsPipelines(Dev.VkDev, Cache == null ? VkPipelineCache.Null : Cache.handle, 1, ref info, IntPtr.Zero, out handle));
                }
            }
            base.Activate();
        }
Exemplo n.º 2
0
        protected void init(GraphicPipelineConfig cfg)
        {
            if (state != ActivableState.Activated)
            {
                Layout.Activate();
                RenderPass.Activate();
                Cache?.Activate();

                List <VkPipelineShaderStageCreateInfo> shaderStages = new List <VkPipelineShaderStageCreateInfo> ();
                foreach (ShaderInfo shader in cfg.shaders)
                {
                    shaderStages.Add(shader.GetStageCreateInfo(Dev));
                }

                VkPipelineColorBlendStateCreateInfo colorBlendInfo = VkPipelineColorBlendStateCreateInfo.New();
                colorBlendInfo.attachmentCount = (uint)cfg.blendAttachments.Count;
                colorBlendInfo.pAttachments    = cfg.blendAttachments.Pin();

                VkPipelineDynamicStateCreateInfo dynStatesInfo = VkPipelineDynamicStateCreateInfo.New();
                dynStatesInfo.dynamicStateCount = (uint)cfg.dynamicStates.Count;
                dynStatesInfo.pDynamicStates    = cfg.dynamicStates.Pin();

                VkPipelineVertexInputStateCreateInfo vertInputInfo = VkPipelineVertexInputStateCreateInfo.New();
                vertInputInfo.vertexBindingDescriptionCount   = (uint)cfg.vertexBindings.Count;
                vertInputInfo.pVertexBindingDescriptions      = cfg.vertexBindings.Pin();
                vertInputInfo.vertexAttributeDescriptionCount = (uint)cfg.vertexAttributes.Count;
                vertInputInfo.pVertexAttributeDescriptions    = cfg.vertexAttributes.Pin();

                VkGraphicsPipelineCreateInfo info = VkGraphicsPipelineCreateInfo.New();
                info.renderPass          = RenderPass.handle;
                info.layout              = Layout.handle;
                info.pVertexInputState   = vertInputInfo.Pin();
                info.pInputAssemblyState = cfg.inputAssemblyState.Pin();
                info.pRasterizationState = cfg.rasterizationState.Pin();
                info.pColorBlendState    = colorBlendInfo.Pin();
                info.pMultisampleState   = cfg.multisampleState.Pin();
                info.pViewportState      = cfg.viewportState.Pin();
                info.pDepthStencilState  = cfg.depthStencilState.Pin();
                info.pDynamicState       = dynStatesInfo.Pin();
                info.stageCount          = (uint)cfg.shaders.Count;
                info.pStages             = shaderStages.Pin();
                info.subpass             = cfg.SubpassIndex;

                Utils.CheckResult(vkCreateGraphicsPipelines(Dev.VkDev, Cache == null ? VkPipelineCache.Null : Cache.handle, 1, ref info, IntPtr.Zero, out handle));

                for (int i = 0; i < cfg.shaders.Count; i++)
                {
                    Dev.DestroyShaderModule(shaderStages[i].module);
                }

                vertInputInfo.Unpin();
                cfg.inputAssemblyState.Unpin();
                cfg.rasterizationState.Unpin();
                colorBlendInfo.Unpin();
                cfg.multisampleState.Unpin();
                cfg.viewportState.Unpin();
                cfg.depthStencilState.Unpin();
                dynStatesInfo.Unpin();
                shaderStages.Unpin();

                cfg.vertexAttributes.Unpin();
                cfg.vertexBindings.Unpin();
                cfg.dynamicStates.Unpin();
                cfg.blendAttachments.Unpin();
            }
            base.Activate();
        }