完成图形管线固定功能设置
							parent
							
								
									14905da5ad
								
							
						
					
					
						commit
						a5df364c00
					
				| 
						 | 
					@ -98,7 +98,7 @@ void HelloTriangleApplication::initVulkan() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	createInstance();
 | 
						createInstance();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	showAvailableExtension();
 | 
						//showAvailableExtension();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setupDebugMessenger();
 | 
						setupDebugMessenger();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,6 +130,10 @@ void HelloTriangleApplication::mainLoop(GLFWwindow* window){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HelloTriangleApplication::cleanup(GLFWwindow* window) {
 | 
					void HelloTriangleApplication::cleanup(GLFWwindow* window) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						std::cout << "start to destroy resource" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (auto imageView : swapChainImageViews)
 | 
						for (auto imageView : swapChainImageViews)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		vkDestroyImageView(device, imageView, nullptr);
 | 
							vkDestroyImageView(device, imageView, nullptr);
 | 
				
			||||||
| 
						 | 
					@ -175,7 +179,6 @@ std::vector<const char*> HelloTriangleApplication::getRequiredExtensions() {
 | 
				
			||||||
void HelloTriangleApplication::showAvailableExtension()
 | 
					void HelloTriangleApplication::showAvailableExtension()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// show available extensions
 | 
						// show available extensions
 | 
				
			||||||
 | 
					 | 
				
			||||||
	uint32_t availableExtensionCount = 0;
 | 
						uint32_t availableExtensionCount = 0;
 | 
				
			||||||
	vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, nullptr);
 | 
						vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, nullptr);
 | 
				
			||||||
	std::vector<VkExtensionProperties> availableExtensions(availableExtensionCount);
 | 
						std::vector<VkExtensionProperties> availableExtensions(availableExtensionCount);
 | 
				
			||||||
| 
						 | 
					@ -605,7 +608,8 @@ void HelloTriangleApplication::createGraphicPipeline()
 | 
				
			||||||
	auto vertShaderCode = readFile("../../../shaders/triangleVert.spv");
 | 
						auto vertShaderCode = readFile("../../../shaders/triangleVert.spv");
 | 
				
			||||||
	auto fragShaderCode = readFile("../../..//shaders/triangleFrag.spv");
 | 
						auto fragShaderCode = readFile("../../..//shaders/triangleFrag.spv");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::cout << "vertShader size:" << vertShaderCode.size() << "\nfragShader size:" << fragShaderCode.size() << std::endl;
 | 
					
 | 
				
			||||||
 | 
						//std::cout << "vertShader size:" << vertShaderCode.size() << "\nfragShader size:" << fragShaderCode.size() << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	VkShaderModule vertShaderModule = createShaderModule(vertShaderCode);
 | 
						VkShaderModule vertShaderModule = createShaderModule(vertShaderCode);
 | 
				
			||||||
	VkShaderModule fragShaderModule = createShaderModule(fragShaderCode);
 | 
						VkShaderModule fragShaderModule = createShaderModule(fragShaderCode);
 | 
				
			||||||
| 
						 | 
					@ -626,8 +630,128 @@ void HelloTriangleApplication::createGraphicPipeline()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo,fragShaderStageInfo };
 | 
						VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo,fragShaderStageInfo };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//顶点输入
 | 
				
			||||||
 | 
						VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
 | 
				
			||||||
 | 
						vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						vertexInputInfo.vertexBindingDescriptionCount = 0;
 | 
				
			||||||
 | 
						vertexInputInfo.pVertexBindingDescriptions = nullptr;
 | 
				
			||||||
 | 
						vertexInputInfo.vertexAttributeDescriptionCount = 0;
 | 
				
			||||||
 | 
						vertexInputInfo.pVertexAttributeDescriptions = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//管道创建完成后销毁着色器模块
 | 
					
 | 
				
			||||||
 | 
						//使用动态状态并保留视口和剪刀裁剪状态
 | 
				
			||||||
 | 
						std::vector<VkDynamicState> dynamicStates = {
 | 
				
			||||||
 | 
							VK_DYNAMIC_STATE_VIEWPORT,
 | 
				
			||||||
 | 
							VK_DYNAMIC_STATE_SCISSOR
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						VkPipelineDynamicStateCreateInfo dynamicState{};
 | 
				
			||||||
 | 
						dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size());
 | 
				
			||||||
 | 
						dynamicState.pDynamicStates = dynamicStates.data();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//描述从顶点绘制哪种几何图形及是否启用primitive restart
 | 
				
			||||||
 | 
						VkPipelineInputAssemblyStateCreateInfo inputAsseblyState{};
 | 
				
			||||||
 | 
						inputAsseblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						inputAsseblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
 | 
				
			||||||
 | 
						inputAsseblyState.primitiveRestartEnable = VK_FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//视口描述将被渲染输出的帧缓冲区域
 | 
				
			||||||
 | 
						VkViewport viewport{};
 | 
				
			||||||
 | 
						viewport.x = 0.0f;
 | 
				
			||||||
 | 
						viewport.y = 0.0f;
 | 
				
			||||||
 | 
						viewport.width = (float)swapChainExtent.width;
 | 
				
			||||||
 | 
						viewport.height = (float)swapChainExtent.height;
 | 
				
			||||||
 | 
						viewport.minDepth = 0.0f;//指定深度值范围,通常为此范围
 | 
				
			||||||
 | 
						viewport.maxDepth = 1.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 剪刀矩阵,定义像素实际存储的区域
 | 
				
			||||||
 | 
						VkRect2D scissor{};
 | 
				
			||||||
 | 
						scissor.offset = { 0,0 };
 | 
				
			||||||
 | 
						scissor.extent = swapChainExtent;
 | 
				
			||||||
 | 
						// 创建viewport
 | 
				
			||||||
 | 
						VkPipelineViewportStateCreateInfo viewportState{};
 | 
				
			||||||
 | 
						viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						viewportState.viewportCount = 1;
 | 
				
			||||||
 | 
						viewportState.scissorCount = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 光栅化
 | 
				
			||||||
 | 
						VkPipelineRasterizationStateCreateInfo rasterizer{};
 | 
				
			||||||
 | 
						rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						rasterizer.depthClampEnable = VK_FALSE;// 不丢弃超出近平面和远平面的fragment
 | 
				
			||||||
 | 
						rasterizer.rasterizerDiscardEnable = VK_FALSE;// 启用则几何图形不会通过光栅化,禁用framebuffer的所有输出
 | 
				
			||||||
 | 
						rasterizer.polygonMode = VK_POLYGON_MODE_FILL;// fragment填充多边形区域
 | 
				
			||||||
 | 
						rasterizer.lineWidth = 1.0f;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;// 背面剔除
 | 
				
			||||||
 | 
						rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 根据fragment的斜率偏置深度值
 | 
				
			||||||
 | 
						rasterizer.depthBiasEnable = VK_FALSE;
 | 
				
			||||||
 | 
						rasterizer.depthBiasConstantFactor = 0.0f;
 | 
				
			||||||
 | 
						rasterizer.depthBiasClamp = 0.0f;
 | 
				
			||||||
 | 
						rasterizer.depthBiasSlopeFactor = 0.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 多重采样(禁用)
 | 
				
			||||||
 | 
						VkPipelineMultisampleStateCreateInfo multisampling{};
 | 
				
			||||||
 | 
						multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						multisampling.sampleShadingEnable = VK_FALSE;
 | 
				
			||||||
 | 
						multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
 | 
				
			||||||
 | 
						multisampling.minSampleShading = 1.0f;
 | 
				
			||||||
 | 
						multisampling.pSampleMask = nullptr;
 | 
				
			||||||
 | 
						multisampling.alphaToCoverageEnable = VK_FALSE;
 | 
				
			||||||
 | 
						multisampling.alphaToOneEnable = VK_FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 深度或模版缓冲区(暂留)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 颜色混合 color blending
 | 
				
			||||||
 | 
						//每个附加帧缓冲区的配置
 | 
				
			||||||
 | 
						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_ONE;
 | 
				
			||||||
 | 
						colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
 | 
				
			||||||
 | 
						colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
 | 
				
			||||||
 | 
						colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
 | 
				
			||||||
 | 
						colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
 | 
				
			||||||
 | 
						colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						alpha混合
 | 
				
			||||||
 | 
						colorBlendAttachment.blendEnable = VK_TRUE;
 | 
				
			||||||
 | 
						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 colorBlendState{};
 | 
				
			||||||
 | 
						colorBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
 | 
				
			||||||
 | 
						colorBlendState.logicOpEnable = VK_FALSE;
 | 
				
			||||||
 | 
						colorBlendState.logicOp = VK_LOGIC_OP_COPY;
 | 
				
			||||||
 | 
						colorBlendState.attachmentCount = 1;
 | 
				
			||||||
 | 
						colorBlendState.pAttachments = &colorBlendAttachment;
 | 
				
			||||||
 | 
						colorBlendState.blendConstants[0] = 0.0f;
 | 
				
			||||||
 | 
						colorBlendState.blendConstants[1] = 0.0f;
 | 
				
			||||||
 | 
						colorBlendState.blendConstants[2] = 0.0f;
 | 
				
			||||||
 | 
						colorBlendState.blendConstants[3] = 0.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
 | 
				
			||||||
 | 
						pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
 | 
				
			||||||
 | 
						pipelineLayoutInfo.setLayoutCount = 0;
 | 
				
			||||||
 | 
						pipelineLayoutInfo.pSetLayouts = nullptr;
 | 
				
			||||||
 | 
						pipelineLayoutInfo.pushConstantRangeCount = 0;
 | 
				
			||||||
 | 
						pipelineLayoutInfo.pPushConstantRanges = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (vkCreatePipelineLayout(device,&pipelineLayoutInfo,nullptr,&pipelineLayout) != VK_SUCCESS)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							throw std::runtime_error("failed to create pipeline Layout in createGraphicPipeline");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 管道创建完成后销毁着色器模块
 | 
				
			||||||
	vkDestroyShaderModule(device, fragShaderModule, nullptr);
 | 
						vkDestroyShaderModule(device, fragShaderModule, nullptr);
 | 
				
			||||||
	vkDestroyShaderModule(device, vertShaderModule, nullptr);
 | 
						vkDestroyShaderModule(device, vertShaderModule, nullptr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,6 +63,8 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::vector<VkImageView> swapChainImageViews;
 | 
						std::vector<VkImageView> swapChainImageViews;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						VkPipelineLayout pipelineLayout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct QueueFamilyIndices
 | 
						struct QueueFamilyIndices
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		std::optional<uint32_t> graphicsFamily;
 | 
							std::optional<uint32_t> graphicsFamily;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue