コード例 #1
0
        private void createGraphicsPipeline(VkContext context)
        {
            var vertShaderStageInfo = new Vk.PipelineShaderStageCreateInfo();

            vertShaderStageInfo.Stage  = Vk.ShaderStageFlags.Vertex;
            vertShaderStageInfo.Module = this.vertexShader;
            vertShaderStageInfo.Name   = "main";

            var fragShaderStageInfo = new Vk.PipelineShaderStageCreateInfo();

            fragShaderStageInfo.Stage  = Vk.ShaderStageFlags.Fragment;
            fragShaderStageInfo.Module = this.fragmentShader;
            fragShaderStageInfo.Name   = "main";

            var shaderStageInfos = new Vk.PipelineShaderStageCreateInfo[] {
                vertShaderStageInfo,
                fragShaderStageInfo
            };

            var attributes = Vertex.AttributeDescriptions;
            var bindings   = new Vk.VertexInputBindingDescription[] {
                Vertex.BindingDescription
            };

            var vertexInputInfo = new Vk.PipelineVertexInputStateCreateInfo();

            vertexInputInfo.VertexBindingDescriptionCount   = (uint)bindings.Length;
            vertexInputInfo.VertexBindingDescriptions       = bindings;
            vertexInputInfo.VertexAttributeDescriptionCount = (uint)attributes.Length;
            vertexInputInfo.VertexAttributeDescriptions     = attributes;

            var inputAssemblyInfo = new Vk.PipelineInputAssemblyStateCreateInfo();

            inputAssemblyInfo.Topology = Vk.PrimitiveTopology.TriangleList;
            inputAssemblyInfo.PrimitiveRestartEnable = false;

            Vk.Viewport viewport = new Vk.Viewport();
            viewport.X        = 0.0F;
            viewport.Y        = 0.0F;
            viewport.Width    = (float)this.wrapper.Extent.Width;
            viewport.Height   = (float)this.wrapper.Extent.Height;
            viewport.MinDepth = 0.0F;
            viewport.MaxDepth = 1.0F;

            Vk.Rect2D scissorRect = new Vk.Rect2D();
            scissorRect.Offset.X = 0;
            scissorRect.Offset.Y = 0;
            scissorRect.Extent   = this.wrapper.Extent;

            var viewportStateInfo = new Vk.PipelineViewportStateCreateInfo();

            viewportStateInfo.ViewportCount = 1;
            viewportStateInfo.Viewports     = new Vk.Viewport[] { viewport };
            viewportStateInfo.ScissorCount  = 1;
            viewportStateInfo.Scissors      = new Vk.Rect2D[] { scissorRect };

            var rasteriserInfo = new Vk.PipelineRasterizationStateCreateInfo();

            rasteriserInfo.DepthClampEnable        = false;
            rasteriserInfo.RasterizerDiscardEnable = false;
            rasteriserInfo.PolygonMode             = Vk.PolygonMode.Fill;
            rasteriserInfo.LineWidth       = 1.0F;
            rasteriserInfo.CullMode        = Vk.CullModeFlags.Back;
            rasteriserInfo.FrontFace       = Vk.FrontFace.Clockwise;
            rasteriserInfo.DepthBiasEnable = false;

            var multisamplingInfo = new Vk.PipelineMultisampleStateCreateInfo();

            multisamplingInfo.SampleShadingEnable  = false;
            multisamplingInfo.RasterizationSamples = Vk.SampleCountFlags.Count1;

            var colourBlendAttachmentInfo = new Vk.PipelineColorBlendAttachmentState();

            colourBlendAttachmentInfo.ColorWriteMask =
                Vk.ColorComponentFlags.R |
                Vk.ColorComponentFlags.G |
                Vk.ColorComponentFlags.B |
                Vk.ColorComponentFlags.A;
            colourBlendAttachmentInfo.BlendEnable         = true;
            colourBlendAttachmentInfo.SrcColorBlendFactor = Vk.BlendFactor.SrcAlpha;
            colourBlendAttachmentInfo.DstColorBlendFactor = Vk.BlendFactor.OneMinusSrcAlpha;
            colourBlendAttachmentInfo.ColorBlendOp        = Vk.BlendOp.Add;
            colourBlendAttachmentInfo.SrcAlphaBlendFactor = Vk.BlendFactor.One;
            colourBlendAttachmentInfo.DstAlphaBlendFactor = Vk.BlendFactor.Zero;
            colourBlendAttachmentInfo.AlphaBlendOp        = Vk.BlendOp.Add;

            var colourBlendAttachmentInfos = new Vk.PipelineColorBlendAttachmentState[] {
                colourBlendAttachmentInfo
            };

            var colourBlendStateInfo = new Vk.PipelineColorBlendStateCreateInfo();

            colourBlendStateInfo.LogicOpEnable   = false;
            colourBlendStateInfo.LogicOp         = Vk.LogicOp.Copy;
            colourBlendStateInfo.AttachmentCount = 1;
            colourBlendStateInfo.Attachments     = colourBlendAttachmentInfos;

            var pipelineLayoutInfo = new Vk.PipelineLayoutCreateInfo();

            pipelineLayoutInfo.SetLayoutCount = 1;
            pipelineLayoutInfo.SetLayouts     = new Vk.DescriptorSetLayout[] {
                this.descriptorSetLayout
            };

            try {
                this.wrapper.PipelineLayout = context.Device.CreatePipelineLayout(pipelineLayoutInfo);
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating the pipeline layout.", result);
            }

            var depthStencil = new Vk.PipelineDepthStencilStateCreateInfo();

            depthStencil.DepthTestEnable       = true;
            depthStencil.DepthWriteEnable      = true;
            depthStencil.DepthCompareOp        = Vk.CompareOp.Less;
            depthStencil.DepthBoundsTestEnable = false;
            depthStencil.StencilTestEnable     = false;

            var pipelineInfo = new Vk.GraphicsPipelineCreateInfo();

            pipelineInfo.StageCount         = 2;
            pipelineInfo.Stages             = shaderStageInfos;
            pipelineInfo.VertexInputState   = vertexInputInfo;
            pipelineInfo.InputAssemblyState = inputAssemblyInfo;
            pipelineInfo.ViewportState      = viewportStateInfo;
            pipelineInfo.RasterizationState = rasteriserInfo;
            pipelineInfo.MultisampleState   = multisamplingInfo;
            pipelineInfo.DepthStencilState  = depthStencil;
            pipelineInfo.ColorBlendState    = colourBlendStateInfo;
            pipelineInfo.DynamicState       = null;
            pipelineInfo.Layout             = this.wrapper.PipelineLayout;
            pipelineInfo.RenderPass         = this.wrapper.RenderPass;
            pipelineInfo.Subpass            = 0;
            pipelineInfo.BasePipelineHandle = null;
            pipelineInfo.BasePipelineIndex  = -1;

            var pipelineInfos = new Vk.GraphicsPipelineCreateInfo[] {
                pipelineInfo
            };

            try {
                this.wrapper.Pipeline = context.Device.CreateGraphicsPipelines(null, pipelineInfos)[0];
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating the graphics pipeline.", result);
            }
        }
コード例 #2
0
ファイル: Structs.cs プロジェクト: yongweisun/VulkanSharp
 internal void Initialize()
 {
     m->SType = StructureType.ComputePipelineCreateInfo;
     lStage = new PipelineShaderStageCreateInfo (&m->Stage);
 }