Esempio n. 1
0
 public static Pipeline GetPipeline(PipelineSettings settings, VulkanRenderer renderer)
 {
     if (!_pipelines.TryGetValue(settings, out _))
     {
         _pipelines.Add(settings, new Pipelines.Pipeline(settings, renderer));
     }
     return(_pipelines[settings]);
 }
Esempio n. 2
0
        private unsafe Pipeline(PipelineSettings settings, VulkanRenderer renderer)
        {
            _renderer = renderer;

            Device device = _renderer.Params.Device;
            AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer();
            Vk vk = _renderer.Vk;

            PipelineShaderStageCreateInfo *shaderStages = stackalloc PipelineShaderStageCreateInfo[2]
            {
                _renderer.Shader.VertexShaderStage,
                _renderer.Shader.FragmentShaderStage
            };
            PipelineVertexInputStateCreateInfo   vertexInputState           = VertexInputState(_bindingDescription, _attributeDescriptions);
            PipelineInputAssemblyStateCreateInfo inputAssemblyState         = InputAssemblyState(settings);
            PipelineRasterizationStateCreateInfo rasterizationState         = RasterizationState(settings);
            PipelineMultisampleStateCreateInfo   multisampleState           = MultisampleState();
            PipelineColorBlendAttachmentState    colourBlendAttachmentState = ColorBlendAttachmentState(settings);
            PipelineColorBlendStateCreateInfo    colourBlendState           = ColourBlendState(colourBlendAttachmentState);
            PipelineViewportStateCreateInfo      viewportState     = ViewportState();
            PipelineDynamicStateCreateInfo       dynamicState      = DynamicStates(DynamicState.Viewport, DynamicState.Scissor);
            PipelineDepthStencilStateCreateInfo  depthStencilState = DepthStencilState(settings);

            GraphicsPipelineCreateInfo pipelineCreateInfo = new()
            {
                SType = StructureType.GraphicsPipelineCreateInfo,

                StageCount = 2,
                PStages    = shaderStages,

                PVertexInputState   = &vertexInputState,
                PInputAssemblyState = &inputAssemblyState,
                PRasterizationState = &rasterizationState,
                PMultisampleState   = &multisampleState,
                PColorBlendState    = &colourBlendState,
                PViewportState      = &viewportState,
                PDynamicState       = &dynamicState,
                PDepthStencilState  = &depthStencilState,
                PTessellationState  = null,

                Layout = _renderer.Shader.PipelineLayout,

                RenderPass = _renderer.Params.RenderPass,
                Subpass    = _renderer.Params.SubpassIndex,

                BasePipelineIndex  = -1,
                BasePipelineHandle = default
            };

            _renderer.AssertVulkan(vk.CreateGraphicsPipelines(device, default, 1, pipelineCreateInfo, allocator, out _handle));