Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VkPipeline pipeline;
- //vert/frag stages
- VkPipelineShaderStageCreateInfo vertShaderStageInfo{};
- vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
- vertShaderStageInfo.module = create_shader_module_from_file_path("Shaders/objectpicking_vert.spv");
- vertShaderStageInfo.pName = "main";
- VkPipelineShaderStageCreateInfo fragShaderStageInfo{};
- fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
- fragShaderStageInfo.module = create_shader_module_from_file_path("Shaders/objectpicking_frag.spv");
- fragShaderStageInfo.pName = "main";
- std::vector< VkPipelineShaderStageCreateInfo> shaderStages;
- shaderStages.push_back(vertShaderStageInfo);
- shaderStages.push_back(fragShaderStageInfo);
- VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
- vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
- auto bindingDescription = Vertex::get_binding_description();
- auto attributeDescriptions = Vertex::get_attribute_descriptions();
- vertexInputInfo.vertexBindingDescriptionCount = 1;
- vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
- vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
- vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
- VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
- inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
- inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
- inputAssembly.primitiveRestartEnable = VK_FALSE;
- VkViewport viewport{};
- viewport.x = 0;
- viewport.y = 0;
- viewport.width = (float)swapChainExtent.width;
- viewport.height = (float)swapChainExtent.height;
- viewport.minDepth = 0.0f;
- viewport.maxDepth = 1.0f;
- //We're going to have a dynamic scissor so this doesnt really matter
- VkRect2D scissor{};
- scissor.offset = { 0,0 };
- scissor.extent = swapChainExtent;
- VkPipelineViewportStateCreateInfo viewportState{};
- viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
- viewportState.viewportCount = 1;
- viewportState.pViewports = &viewport;
- viewportState.scissorCount = 1;
- viewportState.pScissors = &scissor;
- VkPipelineRasterizationStateCreateInfo rasterizer{};
- rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
- rasterizer.depthClampEnable = VK_FALSE;
- rasterizer.rasterizerDiscardEnable = VK_FALSE;
- rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
- rasterizer.lineWidth = 1.0f;
- rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
- rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
- rasterizer.depthBiasEnable = VK_FALSE;
- //Only one samples since this is offscreen
- VkPipelineMultisampleStateCreateInfo multisampling{};
- multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
- multisampling.sampleShadingEnable = VK_FALSE;
- multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
- VkPipelineDepthStencilStateCreateInfo depthStencil{};
- depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
- depthStencil.depthTestEnable = VK_TRUE;
- depthStencil.depthWriteEnable = VK_TRUE;
- depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
- depthStencil.depthBoundsTestEnable = VK_FALSE;
- depthStencil.stencilTestEnable = VK_FALSE;
- //blending is set to false since we don't need it here
- VkPipelineColorBlendAttachmentState colorBlendAttachment{};
- colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
- colorBlendAttachment.blendEnable = VK_FALSE;
- colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
- colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
- colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
- colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
- colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
- colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
- VkPipelineColorBlendStateCreateInfo colorBlending{};
- colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
- colorBlending.logicOpEnable = VK_FALSE;
- colorBlending.logicOp = VK_LOGIC_OP_COPY;
- colorBlending.attachmentCount = 1;
- colorBlending.pAttachments = &colorBlendAttachment;
- colorBlending.blendConstants[0] = 1.0f;
- colorBlending.blendConstants[1] = 0.0f;
- colorBlending.blendConstants[2] = 0.0f;
- colorBlending.blendConstants[3] = 0.0f;
- //we only need a dynamic state for the scissor, this means whatever we set to the scissor here will be ignored, and we'll need to use vkCmdSetScissor() every frame we use the pipeline
- std::array<VkDynamicState, 1> states = { VK_DYNAMIC_STATE_SCISSOR};
- VkPipelineDynamicStateCreateInfo dynamic_state{};
- dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
- dynamic_state.dynamicStateCount = states.size();
- dynamic_state.pDynamicStates = states.data();
- VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
- pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
- pipelineLayoutInfo.setLayoutCount = 1;
- pipelineLayoutInfo.pSetLayouts = &descriptor_set_layouts[pipelines[object_picking_pipeline].descriptor_set_index];
- if (vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &pipelines[object_picking_pipeline].pipeline_layout) != VK_SUCCESS)
- {
- throw std::runtime_error("failed to create pipeline layout!");
- }
- VkGraphicsPipelineCreateInfo pipelineInfo{};
- pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
- pipelineInfo.stageCount = shaderStages.size();
- pipelineInfo.pStages = shaderStages.data();
- pipelineInfo.pVertexInputState = &vertexInputInfo;
- pipelineInfo.pInputAssemblyState = &inputAssembly;
- pipelineInfo.pViewportState = &viewportState;
- pipelineInfo.pRasterizationState = &rasterizer;
- pipelineInfo.pMultisampleState = &multisampling;
- pipelineInfo.pDepthStencilState = &depthStencil;
- pipelineInfo.pColorBlendState = &colorBlending;
- pipelineInfo.layout = pipelines[object_picking_pipeline].pipeline_layout;
- pipelineInfo.renderPass = object_picking_pass;
- pipelineInfo.subpass = 0;
- pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
- pipelineInfo.pDynamicState = &dynamic_state;
- if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline) != VK_SUCCESS) {
- throw std::runtime_error("failed to create graphics pipeline!");
- }
- vkDestroyShaderModule(device, params.fragShaderModule, nullptr);
- vkDestroyShaderModule(device, params.vertShaderModule, nullptr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement