Read Access Violation in vkCreateGraphicsPipelines

Started by
2 comments, last by Balma Alparisi 5 years, 4 months ago

It has been 2 day figuring out what's wrong but stil no success. Here's the code.


VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = {};
    pipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
 
    VkPipelineLayout pipelineLayout;
 
    vkRes = vkCreatePipelineLayout(device.GetVkDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout);
    if (vkRes != VK_SUCCESS)
    {
        std::cout << "Failed to create pipelineLayout \n";
        return -1;
    }
 
    VkPipelineColorBlendAttachmentState colorBlendAttachmentState = {};
    colorBlendAttachmentState.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
 
    VkPipelineColorBlendStateCreateInfo colorBlendStates = {};
    colorBlendStates.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
    colorBlendStates.attachmentCount = 1;
    colorBlendStates.pAttachments = &colorBlendAttachmentState;
 
    VkVertexInputBindingDescription vertexInputBindingDesc = {};
    vertexInputBindingDesc.binding = 0;
    vertexInputBindingDesc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
    vertexInputBindingDesc.stride = sizeof(float) * 6;
 
    VkVertexInputAttributeDescription vertexInputAttribDescs[2] = {};
    vertexInputAttribDescs[0].binding = 0;
    vertexInputAttribDescs[0].format = VK_FORMAT_R32G32B32_SFLOAT;
    vertexInputAttribDescs[0].location = 0;
    vertexInputAttribDescs[0].offset = 0;
 
    vertexInputAttribDescs[1].binding = 0;
    vertexInputAttribDescs[1].format = VK_FORMAT_R32G32B32_SFLOAT;
    vertexInputAttribDescs[1].location = 1;
    vertexInputAttribDescs[1].offset = sizeof(float) * 3;
 
    VkPipelineVertexInputStateCreateInfo vertexInputState = {};
    vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
    vertexInputState.vertexBindingDescriptionCount = 1;
    vertexInputState.pVertexBindingDescriptions = &vertexInputBindingDesc;
    vertexInputState.vertexAttributeDescriptionCount = 2;
    vertexInputState.pVertexAttributeDescriptions = vertexInputAttribDescs;
 
    VkPipelineViewportStateCreateInfo viewportState = {};
    viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
    viewportState.viewportCount = 1;
    viewportState.scissorCount = 1;
 
    VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = {};
    inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
    inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
 
    VkPipelineRasterizationStateCreateInfo rasterizerState = {};
    rasterizerState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
    rasterizerState.cullMode = VK_CULL_MODE_NONE;
    rasterizerState.polygonMode = VK_POLYGON_MODE_FILL;
    rasterizerState.lineWidth = 1.0f;
    rasterizerState.frontFace = VK_FRONT_FACE_CLOCKWISE;
 
    VkPipelineMultisampleStateCreateInfo multisampleState = {};
    multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
    multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_8_BIT;
 
    VkDynamicState dynamicState[2] = { VK_DYNAMIC_STATE_VIEWPORT,VK_DYNAMIC_STATE_SCISSOR };
 
    VkPipelineDynamicStateCreateInfo dynamicPipelineState = {};
    dynamicPipelineState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
    dynamicPipelineState.dynamicStateCount = 2;
    dynamicPipelineState.pDynamicStates = dynamicState;
 
    VkShaderModule shaders[2];
 
    std::ifstream inputFile("Shaders/color.vert.spv");
    inputFile.seekg(0, std::ios_base::end);
    UINT64 fileSize = inputFile.tellg();
    inputFile.seekg(0, std::ios_base::beg);
 
    std::vector<char> byteCode(fileSize);
    inputFile.read(byteCode.data(), fileSize);
    inputFile.close();
 
    VkShaderModuleCreateInfo shaderModuleCreateInfo = {};
    shaderModuleCreateInfo.codeSize = fileSize;
    shaderModuleCreateInfo.pCode = (UINT*)byteCode.data();
 
    vkRes = vkCreateShaderModule(device.GetVkDevice(), &shaderModuleCreateInfo, nullptr, &shaders[0]);
    if (vkRes != VK_SUCCESS)
    {
        std::cout << "Failed to create shader\n";
        return -1;
    }
 
    inputFile.open("Shaders/color.frag.spv");
    inputFile.seekg(0, std::ios_base::end);
    fileSize = inputFile.tellg();
    inputFile.seekg(0, std::ios_base::beg);
 
    byteCode.resize(fileSize);
    inputFile.read(byteCode.data(), fileSize);
    inputFile.close();
 
    shaderModuleCreateInfo.codeSize = fileSize;
    shaderModuleCreateInfo.pCode = (UINT*)byteCode.data();
 
    vkRes = vkCreateShaderModule(device.GetVkDevice(), &shaderModuleCreateInfo, nullptr, &shaders[1]);
    if (vkRes != VK_SUCCESS)
    {
        std::cout << "Failed to create shader\n";
        return -1;
    }
 
    VkPipelineShaderStageCreateInfo shaderStages[2];
    shaderStages[0] = {};
    shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    shaderStages[0].module = shaders[0];
    shaderStages[0].pName = "main";
    shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
 
    shaderStages[1] = {};
    shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    shaderStages[1].module = shaders[1];
    shaderStages[1].pName = "main";
    shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
 
    VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo[1] = {};
    graphicsPipelineCreateInfo[0].sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
    graphicsPipelineCreateInfo[0].layout = pipelineLayout;
    graphicsPipelineCreateInfo[0].pColorBlendState = &colorBlendStates;
    graphicsPipelineCreateInfo[0].stageCount = 2;
    graphicsPipelineCreateInfo[0].pStages = shaderStages;
    graphicsPipelineCreateInfo[0].pDynamicState = &dynamicPipelineState;
    graphicsPipelineCreateInfo[0].pInputAssemblyState = &inputAssemblyState;
    graphicsPipelineCreateInfo[0].pRasterizationState = &rasterizerState;
    graphicsPipelineCreateInfo[0].pVertexInputState = &vertexInputState;
    graphicsPipelineCreateInfo[0].pMultisampleState = &multisampleState;
    graphicsPipelineCreateInfo[0].renderPass = renderPass;
    graphicsPipelineCreateInfo[0].pViewportState = &viewportState;
 
    VkPipeline pipeline;
 
    vkRes = vkCreateGraphicsPipelines(device.GetVkDevice(), VK_NULL_HANDLE, 1, graphicsPipelineCreateInfo, nullptr, &pipeline);
    if (vkRes != VK_SUCCESS)
    {
        std::cout << "Failed to create pipeline\n";
        return -1;
    }

 

Untitled.png

I'm just a noob

Advertisement

First of all, do you have the validation layer enabled? It helps a lot when debugging Vulkan errors.

I let it run on my system and a few things came up:

You forgot to set the type of the VkShaderModuleCreateInfo:


shaderModuleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;

And you are not setting the subpass-index in the VkGraphicsPipelineCreateInfo so it defaults to 0, which is probably what you want but you should set it explicitly just to be sure.


graphicsPipelineCreateInfo[0].subpass = ??;

Additionally, you are not setting the pDepthStencilState. You should definitely set this if you are actually using a depth/stencil attachment in the subpass. Without any information on how the RenderPass was created, it's hard to tell if that is the main problem.

I only has one subpass with no depth/stencil. So i dont need pDepthStencilState according the vulkan documentation. i have enabled the validation layer and fix VkShaderModule::sType but still no luck, The validation reports nothing. And lastly this is mu rendepass creation 


VkAttachmentDescription attachmentDescriptions[2] = {};
	attachmentDescriptions[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
	attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
	attachmentDescriptions[0].format = VK_FORMAT_B8G8R8A8_UNORM;
	attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_8_BIT;
	attachmentDescriptions[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
	attachmentDescriptions[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
	attachmentDescriptions[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
	attachmentDescriptions[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;

	attachmentDescriptions[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
	attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
	attachmentDescriptions[1].format = VK_FORMAT_B8G8R8A8_UNORM;
	attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
	attachmentDescriptions[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
	attachmentDescriptions[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
	attachmentDescriptions[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
	attachmentDescriptions[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;

	VkAttachmentReference colorAttachmentReference = { 0,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
	VkAttachmentReference resolveAttachmentReference = { 1,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };

	VkSubpassDescription subpassDesc = {};
	subpassDesc.colorAttachmentCount = 1;
	subpassDesc.pColorAttachments = &colorAttachmentReference;
	subpassDesc.pResolveAttachments = &resolveAttachmentReference;

	VkRenderPassCreateInfo renderPassCreateInfo = {};
	renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
	renderPassCreateInfo.attachmentCount = 2;
	renderPassCreateInfo.pAttachments = attachmentDescriptions;
	renderPassCreateInfo.subpassCount = 1;
	renderPassCreateInfo.pSubpasses = &subpassDesc;

	VkRenderPass renderPass;
	vkCreateRenderPass(device.GetVkDevice(), &renderPassCreateInfo, nullptr, &renderPass);

 

I'm just a noob

This topic is closed to new replies.

Advertisement