public Pipeline Build() { var stages = _stages.ToArray(); var vertexBindings = new VkVertexInputBindingDescription[_vertexBindingDescriptions.Count]; { var i = 0; foreach (var kv in _vertexBindingDescriptions) { vertexBindings[i++] = kv.Value; } } var attributeBindings = new VkVertexInputAttributeDescription[_vertexAttributeDescriptions.Count]; { var i = 0; foreach (var kv in _vertexAttributeDescriptions) { attributeBindings[i++] = kv.Value; } } var blendStates = new VkPipelineColorBlendAttachmentState[_blendAttachmentStates.Count]; foreach (var kv in _blendAttachmentStates) { blendStates[kv.Key] = kv.Value; } var viewports = _viewports.ToArray(); var scissors = _viewportScissors.ToArray(); var dynamicStates = _dynamicStates.ToArray(); try { unsafe { fixed(VkViewport *viewportPtr = viewports) fixed(VkRect2D * scissorPtr = scissors) fixed(VkDynamicState * dynamicPtr = dynamicStates) fixed(VkPipelineColorBlendAttachmentState * blendPtr = blendStates) fixed(VkVertexInputBindingDescription * vertexPtr = vertexBindings) fixed(VkVertexInputAttributeDescription * attributePtr = attributeBindings) fixed(VkPipelineShaderStageCreateInfo * stagePtr = stages) { if (_basePipeline != null) { _flags |= VkPipelineCreateFlag.Derivative; } else { _flags &= ~VkPipelineCreateFlag.Derivative; } var vertexInputState = new VkPipelineVertexInputStateCreateInfo() { SType = VkStructureType.PipelineVertexInputStateCreateInfo, PNext = IntPtr.Zero, Flags = 0, VertexBindingDescriptionCount = (uint)vertexBindings.Length, PVertexBindingDescriptions = vertexPtr, VertexAttributeDescriptionCount = (uint)attributeBindings.Length, PVertexAttributeDescriptions = attributePtr }; var assemblyState = _asmInfo; var tessState = _tessInfo; var viewportState = new VkPipelineViewportStateCreateInfo() { SType = VkStructureType.PipelineViewportStateCreateInfo, PNext = IntPtr.Zero, Flags = 0, ViewportCount = (uint)viewports.Length, PViewports = viewportPtr, ScissorCount = (uint)scissors.Length, PScissors = scissorPtr }; var rasterState = _rasterInfo; var multisampleState = _multisampleInfo; var depthStencilState = _depthStencilInfo; var colorBlendState = _colorBlendInfo; colorBlendState.AttachmentCount = (uint)blendStates.Length; colorBlendState.PAttachments = blendPtr; var dynamicState = new VkPipelineDynamicStateCreateInfo() { SType = VkStructureType.PipelineDynamicStateCreateInfo, PNext = IntPtr.Zero, Flags = 0, DynamicStateCount = (uint)dynamicStates.Length, PDynamicStates = dynamicPtr }; var info = new VkGraphicsPipelineCreateInfo() { SType = VkStructureType.GraphicsPipelineCreateInfo, PNext = IntPtr.Zero, Flags = _flags, StageCount = (uint)stages.Length, PStages = stagePtr, PVertexInputState = &vertexInputState, PInputAssemblyState = &assemblyState, PTessellationState = &tessState, PViewportState = &viewportState, PRasterizationState = &rasterState, PMultisampleState = &multisampleState, PDepthStencilState = &depthStencilState, PColorBlendState = &colorBlendState, PDynamicState = dynamicStates.Length > 0 ? &dynamicState : (VkPipelineDynamicStateCreateInfo *)0, Layout = _pipelineLayout.Handle, RenderPass = _pass.Handle, Subpass = _subpassId, BasePipelineHandle = _basePipeline?.Handle ?? VkPipeline.Null, BasePipelineIndex = _basePipelineIndex }; VkPipeline result = VkPipeline.Null; VkException.Check(VkDevice.vkCreateGraphicsPipelines(_pass.Device.Handle, VkPipelineCache.Null, 1, &info, _pass.Instance.AllocationCallbacks, &result)); Debug.Assert(result != VkPipeline.Null); return(new Pipeline(_pass.Device, VkPipelineBindPoint.Graphics, _pipelineLayout, result)); } } } finally { foreach (var pin in _pins) { pin.Free(); } foreach (var strPin in _strPins) { Marshal.FreeHGlobal(strPin); } } }
public GraphicsPipelineBuilder Flags(VkPipelineCreateFlag flags) { _flags = flags; return(this); }