vk_pipeline.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "vk_pipeline.h"
  2. #include <iostream>
  3. using namespace Coral3D;
  4. VkPipeline PipelineBuilder::build_pipeline(VkDevice device, VkRenderPass renderPass)
  5. {
  6. VkPipelineViewportStateCreateInfo viewportState{};
  7. viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
  8. viewportState.pNext = nullptr;
  9. // One viewport
  10. viewportState.viewportCount = 1;
  11. viewportState.pViewports = &m_Viewport;
  12. viewportState.scissorCount = 1;
  13. viewportState.pScissors = &m_Scissor;
  14. // Setup color blending. We are not using blending yet.
  15. VkPipelineColorBlendStateCreateInfo colorBlending{};
  16. colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
  17. colorBlending.pNext = nullptr;
  18. // No blending
  19. colorBlending.logicOpEnable = VK_FALSE;
  20. colorBlending.logicOp = VK_LOGIC_OP_COPY;
  21. colorBlending.attachmentCount = 1;
  22. colorBlending.pAttachments = &m_ColorBlendAttachment;
  23. // Build the pipeline
  24. VkGraphicsPipelineCreateInfo pipelineInfo{};
  25. pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
  26. pipelineInfo.pNext = nullptr;
  27. // Pipeline shaders
  28. pipelineInfo.stageCount = static_cast<uint32_t>(m_ShaderStages.size());
  29. pipelineInfo.pStages = m_ShaderStages.data();
  30. // Vertex input
  31. pipelineInfo.pVertexInputState = &m_VertexInputInfo;
  32. // Depth state
  33. pipelineInfo.pDepthStencilState = &m_DepthStencil;
  34. // Input assembly
  35. pipelineInfo.pInputAssemblyState = &m_InputAssembly;
  36. // Viewport state
  37. pipelineInfo.pViewportState = &viewportState;
  38. // Rasterizer
  39. pipelineInfo.pRasterizationState = &m_Rasterizer;
  40. // Multisampling
  41. pipelineInfo.pMultisampleState = &m_Multisampling;
  42. // Color blending
  43. pipelineInfo.pColorBlendState = &colorBlending;
  44. // Pipeline layout
  45. pipelineInfo.layout = m_PipelineLayout;
  46. // Render pass
  47. pipelineInfo.renderPass = renderPass;
  48. pipelineInfo.subpass = 0;
  49. // Pipeline derivatives : None
  50. pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
  51. VkPipeline pipeline;
  52. if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline) != VK_SUCCESS)
  53. {
  54. std::cout << "Error: failed to create graphics pipeline!\n";
  55. return VK_NULL_HANDLE;
  56. }
  57. else
  58. return pipeline;
  59. }