Set up most of the pipeline, seg fault
This commit is contained in:
127
cve_pipeline.cpp
127
cve_pipeline.cpp
@@ -10,6 +10,12 @@ namespace cve {
|
|||||||
createGraphicsPipeline(vertFilepath, fragFilepath, configInfo);
|
createGraphicsPipeline(vertFilepath, fragFilepath, configInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CvePipeline::~CvePipeline() {
|
||||||
|
vkDestroyShaderModule(cveDevice.device(), vertShaderModule, nullptr);
|
||||||
|
vkDestroyPipeline(cveDevice.device(), graphicsPipeline, nullptr);
|
||||||
|
vkDestroyShaderModule(cveDevice.device(), fragShaderModule, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<char> CvePipeline::readFile(const std::string& filepath) {
|
std::vector<char> CvePipeline::readFile(const std::string& filepath) {
|
||||||
std::ifstream file{filepath, std::ios::ate | std::ios::binary};
|
std::ifstream file{filepath, std::ios::ate | std::ios::binary};
|
||||||
|
|
||||||
@@ -32,8 +38,57 @@ namespace cve {
|
|||||||
auto vertCode = readFile(vertFilepath);
|
auto vertCode = readFile(vertFilepath);
|
||||||
auto fragCode = readFile(fragFilepath);
|
auto fragCode = readFile(fragFilepath);
|
||||||
|
|
||||||
std::cout << "Vertex shader code size: " << vertCode.size() << '\n';
|
createShaderModule(vertCode, &vertShaderModule);
|
||||||
std::cout << "Fragment shader code size: " << fragCode.size() << '\n';
|
createShaderModule(fragCode, &fragShaderModule);
|
||||||
|
|
||||||
|
VkPipelineShaderStageCreateInfo shaderStages[2];
|
||||||
|
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||||
|
shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
|
shaderStages[0].module = vertShaderModule;
|
||||||
|
shaderStages[0].pName = "main";
|
||||||
|
shaderStages[0].flags = 0;
|
||||||
|
shaderStages[0].pName = nullptr;
|
||||||
|
shaderStages[0].pSpecializationInfo = nullptr;
|
||||||
|
|
||||||
|
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||||
|
shaderStages[0].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
shaderStages[0].module = fragShaderModule;
|
||||||
|
shaderStages[0].pName = "main";
|
||||||
|
shaderStages[0].flags = 0;
|
||||||
|
shaderStages[0].pName = nullptr;
|
||||||
|
shaderStages[0].pSpecializationInfo = nullptr;
|
||||||
|
|
||||||
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
||||||
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
|
vertexInputInfo.vertexBindingDescriptionCount = 0;
|
||||||
|
vertexInputInfo.vertexAttributeDescriptionCount = 0;
|
||||||
|
vertexInputInfo.pVertexBindingDescriptions = nullptr;
|
||||||
|
vertexInputInfo.pVertexAttributeDescriptions = nullptr;
|
||||||
|
|
||||||
|
VkGraphicsPipelineCreateInfo pipelineInfo{};
|
||||||
|
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||||
|
pipelineInfo.stageCount = 2;
|
||||||
|
pipelineInfo.pStages = shaderStages;
|
||||||
|
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
||||||
|
pipelineInfo.pInputAssemblyState = &configInfo.inputAssemblyInfo;
|
||||||
|
pipelineInfo.pViewportState = &configInfo.viewportInfo;
|
||||||
|
pipelineInfo.pRasterizationState = &configInfo.rasterizationInfo;
|
||||||
|
pipelineInfo.pMultisampleState = &configInfo.multisampleInfo;
|
||||||
|
pipelineInfo.pColorBlendState = &configInfo.colorBlendInfo;
|
||||||
|
pipelineInfo.pDepthStencilState = &configInfo.depthStencilInfo;
|
||||||
|
pipelineInfo.pDynamicState = nullptr;
|
||||||
|
|
||||||
|
pipelineInfo.layout = configInfo.pipelineLayout;
|
||||||
|
pipelineInfo.renderPass = configInfo.renderPass;
|
||||||
|
pipelineInfo.subpass = configInfo.subpass;
|
||||||
|
|
||||||
|
pipelineInfo.basePipelineIndex = -1;
|
||||||
|
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
if (vkCreateGraphicsPipelines(cveDevice.device(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline)
|
||||||
|
!= VK_SUCCESS) {
|
||||||
|
throw std::runtime_error("Failed to create graphics pipeline.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CvePipeline::createShaderModule(const std::vector<char>& code, VkShaderModule *shaderModule) {
|
void CvePipeline::createShaderModule(const std::vector<char>& code, VkShaderModule *shaderModule) {
|
||||||
@@ -54,6 +109,74 @@ namespace cve {
|
|||||||
configInfo.inputAssemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
configInfo.inputAssemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||||
configInfo.inputAssemblyInfo.primitiveRestartEnable = VK_FALSE;
|
configInfo.inputAssemblyInfo.primitiveRestartEnable = VK_FALSE;
|
||||||
|
|
||||||
|
configInfo.viewport.x = 0.0f;
|
||||||
|
configInfo.viewport.y = 0.0f;
|
||||||
|
configInfo.viewport.width = static_cast<float>(width);
|
||||||
|
configInfo.viewport.height = static_cast<float>(height);
|
||||||
|
configInfo.viewport.minDepth = 0.0f;
|
||||||
|
configInfo.viewport.maxDepth = 1.0f;
|
||||||
|
|
||||||
|
configInfo.scissor.offset = {0, 0};
|
||||||
|
configInfo.scissor.extent = {width, height};
|
||||||
|
|
||||||
|
configInfo.viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||||
|
configInfo.viewportInfo.viewportCount = 1;
|
||||||
|
configInfo.viewportInfo.pViewports = &configInfo.viewport;
|
||||||
|
configInfo.viewportInfo.scissorCount = 1;
|
||||||
|
configInfo.viewportInfo.pScissors = &configInfo.scissor;
|
||||||
|
|
||||||
|
configInfo.rasterizationInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
||||||
|
configInfo.rasterizationInfo.depthClampEnable = VK_FALSE;
|
||||||
|
configInfo.rasterizationInfo.rasterizerDiscardEnable = VK_FALSE;
|
||||||
|
configInfo.rasterizationInfo.polygonMode = VK_POLYGON_MODE_FILL;
|
||||||
|
configInfo.rasterizationInfo.lineWidth = 1.0f;
|
||||||
|
configInfo.rasterizationInfo.cullMode = VK_CULL_MODE_NONE;
|
||||||
|
configInfo.rasterizationInfo.frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||||
|
configInfo.rasterizationInfo.depthBiasEnable = VK_FALSE;
|
||||||
|
configInfo.rasterizationInfo.depthBiasConstantFactor = 0.0f;
|
||||||
|
configInfo.rasterizationInfo.depthBiasClamp = 0.0f;
|
||||||
|
configInfo.rasterizationInfo.depthBiasSlopeFactor = 0.0f;
|
||||||
|
|
||||||
|
configInfo.multisampleInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||||
|
configInfo.multisampleInfo.sampleShadingEnable = VK_FALSE;
|
||||||
|
configInfo.multisampleInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
configInfo.multisampleInfo.minSampleShading = 1.0f; // Optional
|
||||||
|
configInfo.multisampleInfo.pSampleMask = nullptr; // Optional
|
||||||
|
configInfo.multisampleInfo.alphaToCoverageEnable = VK_FALSE; // Optional
|
||||||
|
configInfo.multisampleInfo.alphaToOneEnable = VK_FALSE; // Optional
|
||||||
|
|
||||||
|
configInfo.colorBlendAttachment.colorWriteMask =
|
||||||
|
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT |
|
||||||
|
VK_COLOR_COMPONENT_A_BIT;
|
||||||
|
configInfo.colorBlendAttachment.blendEnable = VK_FALSE;
|
||||||
|
configInfo.colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; // Optional
|
||||||
|
configInfo.colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO; // Optional
|
||||||
|
configInfo.colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; // Optional
|
||||||
|
configInfo.colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; // Optional
|
||||||
|
configInfo.colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; // Optional
|
||||||
|
configInfo.colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; // Optional
|
||||||
|
|
||||||
|
configInfo.colorBlendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||||
|
configInfo.colorBlendInfo.logicOpEnable = VK_FALSE;
|
||||||
|
configInfo.colorBlendInfo.logicOp = VK_LOGIC_OP_COPY; // Optional
|
||||||
|
configInfo.colorBlendInfo.attachmentCount = 1;
|
||||||
|
configInfo.colorBlendInfo.pAttachments = &configInfo.colorBlendAttachment;
|
||||||
|
configInfo.colorBlendInfo.blendConstants[0] = 0.0f; // Optional
|
||||||
|
configInfo.colorBlendInfo.blendConstants[1] = 0.0f; // Optional
|
||||||
|
configInfo.colorBlendInfo.blendConstants[2] = 0.0f; // Optional
|
||||||
|
configInfo.colorBlendInfo.blendConstants[3] = 0.0f; // Optional
|
||||||
|
|
||||||
|
configInfo.depthStencilInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||||
|
configInfo.depthStencilInfo.depthTestEnable = VK_TRUE;
|
||||||
|
configInfo.depthStencilInfo.depthWriteEnable = VK_TRUE;
|
||||||
|
configInfo.depthStencilInfo.depthCompareOp = VK_COMPARE_OP_LESS;
|
||||||
|
configInfo.depthStencilInfo.depthBoundsTestEnable = VK_FALSE;
|
||||||
|
configInfo.depthStencilInfo.minDepthBounds = 0.0f; // Optional
|
||||||
|
configInfo.depthStencilInfo.maxDepthBounds = 1.0f; // Optional
|
||||||
|
configInfo.depthStencilInfo.stencilTestEnable = VK_FALSE;
|
||||||
|
configInfo.depthStencilInfo.front = {}; // Optional
|
||||||
|
configInfo.depthStencilInfo.back = {}; // Optional
|
||||||
|
|
||||||
return configInfo;
|
return configInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,24 @@
|
|||||||
|
|
||||||
namespace cve {
|
namespace cve {
|
||||||
struct PipelineConfigInfo {
|
struct PipelineConfigInfo {
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo{};
|
VkViewport viewport;
|
||||||
|
VkRect2D scissor;
|
||||||
|
VkPipelineViewportStateCreateInfo viewportInfo;
|
||||||
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo;
|
||||||
|
VkPipelineRasterizationStateCreateInfo rasterizationInfo;
|
||||||
|
VkPipelineMultisampleStateCreateInfo multisampleInfo;
|
||||||
|
VkPipelineColorBlendAttachmentState colorBlendAttachment;
|
||||||
|
VkPipelineColorBlendStateCreateInfo colorBlendInfo;
|
||||||
|
VkPipelineDepthStencilStateCreateInfo depthStencilInfo;
|
||||||
|
VkPipelineLayout pipelineLayout = nullptr;
|
||||||
|
VkRenderPass renderPass = nullptr;
|
||||||
|
uint32_t subpass = 0;
|
||||||
};
|
};
|
||||||
class CvePipeline {
|
class CvePipeline {
|
||||||
public:
|
public:
|
||||||
CvePipeline(CveDevice &device, const std::string& vertFilepath,
|
CvePipeline(CveDevice &device, const std::string& vertFilepath,
|
||||||
const std::string& fragFilepath, const PipelineConfigInfo &configInfo);
|
const std::string& fragFilepath, const PipelineConfigInfo &configInfo);
|
||||||
~CvePipeline() {};
|
~CvePipeline();
|
||||||
|
|
||||||
CvePipeline(const CvePipeline&) = delete;
|
CvePipeline(const CvePipeline&) = delete;
|
||||||
void operator=(const CvePipeline&) = delete;
|
void operator=(const CvePipeline&) = delete;
|
||||||
|
|||||||
Reference in New Issue
Block a user