Read access violation on vkCreateGraphicsPipelines

2

I'm making a simple renderer (temporarily) in vulkan and at the moment I'm making it really simple. I'm getting an exception at the vkCreateGraphicsPipelines(), what could the problem be and how would I possibly fix it.

I've tried finding anything that haven't been initialized but so far there's nothing. I have checked the call stack but got nothing as the exception is thrown when calling the create function for the pipeline. I also searched on google, but found nothing which helped. I'm following the vulkan-tutorial website, just abstracting it away in different classes, checked the tutorial multiple times. Everything works until i get to the vkCreateGraphicsPipelines function.

VkPipelineShaderStageCreateInfo shaderStages[] = { p_Model->shader.vertShaderStageInfo, p_Model->shader.fragShaderStageInfo };

VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;

vertexInputInfo.vertexBindingDescriptionCount       = 1;
vertexInputInfo.vertexAttributeDescriptionCount     = static_cast<uint32_t>(p_Model->mesh.vao.getAttributeDescriptions().size());
vertexInputInfo.pVertexBindingDescriptions          = &p_Model->mesh.vao.getBindingDescription();
vertexInputInfo.pVertexAttributeDescriptions        = p_Model->mesh.vao.getAttributeDescriptions().data();

//Set info for graphics pipeline creation
VkPipelineInputAssemblyStateCreateInfo  inputAssembly           = getInputAssemblyInfo();
VkViewport                              viewport                = getViewport();
VkRect2D                                scissor                 = getScissor();
VkPipelineViewportStateCreateInfo       viewportState           = getViewportStateInfo(viewport, scissor);
VkPipelineRasterizationStateCreateInfo  rasterizer              = getRasterizerInfo();
VkPipelineMultisampleStateCreateInfo    multiSampling           = getMultiSamplingInfo();
VkPipelineColorBlendAttachmentState     colorBlendAttachment    = getColorBlendAttachmentState();
VkPipelineColorBlendStateCreateInfo     colorBlending           = getColorBlendStateInfo(colorBlendAttachment);
VkPipelineDynamicStateCreateInfo        dynamicState            = getDynamicStateInfo();
VkPipelineLayoutCreateInfo              pipelineLayoutInfo      = getPipelineLayoutInfo();

//Filling pipeline info 
VkGraphicsPipelineCreateInfo pipelineInfo = {};
pipelineInfo.sType                  = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.stageCount             = 2;
pipelineInfo.pStages                = shaderStages;
pipelineInfo.pVertexInputState      = &vertexInputInfo;
pipelineInfo.pInputAssemblyState    = &inputAssembly;
pipelineInfo.pViewportState         = &viewportState;
pipelineInfo.pRasterizationState    = &rasterizer;
pipelineInfo.pMultisampleState      = &multiSampling;
pipelineInfo.pDepthStencilState     = nullptr;
pipelineInfo.pColorBlendState       = &colorBlending;
pipelineInfo.pDynamicState          = &dynamicState;
pipelineInfo.layout                 = pipelineLayout;
pipelineInfo.renderPass             = renderPass;
pipelineInfo.subpass                = 0;
pipelineInfo.basePipelineHandle     = VK_NULL_HANDLE;
pipelineInfo.basePipelineIndex      = -1;

if (vkCreatePipelineLayout(m_Context->device, &pipelineLayoutInfo, nullptr, &pipelineLayout) != VK_SUCCESS)
    Utils::Logger::logMSG("Failed to create pipeline layout\n", "Rendering", Utils::Category::Error);

if (vkCreateGraphicsPipelines(m_Context->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS)
    Utils::Logger::logMSG("Failed to create graphics pipeline\n", "Rendering", Utils::Category::Error);

Shader code

std::vector<char> VulkanShader::readFile(const std::string& filename)
{
    std::ifstream file(filename, std::ios::ate | std::ios::binary);

    if (!file.is_open())
        throw std::runtime_error("failed to open file");

    size_t fileSize = (size_t)file.tellg();
    std::vector<char> buffer(fileSize);

    file.seekg(0);
    file.read(buffer.data(), fileSize);

    file.close();

    return buffer;
}

void VulkanShader::setShader(std::string p_VertexShader, std::string p_FragmentShader)
{
    auto vertShaderCode = readFile(p_VertexShader);
    auto fragShaderCode = readFile(p_FragmentShader);

    vertShaderModule = createShaderModule(vertShaderCode);
    fragShaderModule = createShaderModule(fragShaderCode);

    vertShaderStageInfo = {};
    vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;

    vertShaderStageInfo.module = vertShaderModule;
    vertShaderStageInfo.pName = "main";

    fragShaderStageInfo = {};
    fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;

    fragShaderStageInfo.module = fragShaderModule;
    fragShaderStageInfo.pName = "main";
}

VkShaderModule VulkanShader::createShaderModule(const std::vector<char>& p_Code)
{
    VkShaderModuleCreateInfo createInfo = {};
    createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
    createInfo.codeSize = p_Code.size();
    createInfo.pCode = reinterpret_cast<const uint32_t*>(p_Code.data());

    VkShaderModule shaderModule;
    if (vkCreateShaderModule(vkContextSingleton::getInstance().device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS)
        Utils::Logger::logMSG("Failed to create shader module\n", "Shader", Utils::Category::Error);

    return shaderModule;
}

Here's the error message

Exception thrown at 0x00007FFC0171261B (amdvlk64.dll) in vulkan.exe: 
0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

Output from console (not really formatted, I'm just trying to make things work first)

[Run time : 1.12007s][Application]Info:    application version : 4194304
[Run time : 1.18842s][Application]Info: engine version : 4194304
[Run time : 1.18947s][Application]Info: api version : 4194304
[Run time : 1.56738s][Validation Layers]Info: Validation layers available
[Run time : 1.75403s][Extensions]Info: VK_KHR_surface
[Run time : 1.76841s][Extensions]Info: VK_KHR_win32_surface
[Run time : 1.76916s][Extensions]Info: VK_EXT_debug_utils
[Run time : 2.28795s][Vulkan Instance]Info : Succesfully created instance
[Run time : 2.31040s][Window 'Vulkan']Info: Succesfully created window surface
[Run time : 2.31151s][GPU]Info: Found atleast one GPU with vulkan support
[Run time : 2.31251s][GPU]Info: [AMD Radeon R5 M200 Series]
[Run time : 2.31330s][GPU]Info: score : 35816
[Run time : 2.31405s][GPU]Info: device type : discrete
[Run time : 2.31503s][GPU]Info: driver version : 8388676
[Run time : 2.31573s][GPU]Info: vulkan version : 4198496
[Run time : 2.31641s][GPU]Info: max viewports : 16
[Run time : 2.31954s][GPU]Info: max tesselation level : 64
[Run time : 2.32045s][GPU]Info: memory heap count : 3
[Run time : 2.32130s][GPU]Info: system ram : 12GB
[Run time : 2.32295s][GPU]Info: vendor id : 4098
[Run time : 2.32666s][GPU]Info: [AMD Radeon(TM) R4 Graphics]
[Run time : 2.32926s][GPU]Info: score : 34816
[Run time : 2.33013s][GPU]Info: device type : integrated
[Run time : 2.33097s][GPU]Info: driver version : 8388676
[Run time : 2.33181s][GPU]Info: vulkan version : 4198496
[Run time : 2.33320s][GPU]Info: max viewports : 16
[Run time : 2.33407s][GPU]Info: max tesselation level : 64
[Run time : 2.33491s][GPU]Info: memory heap count : 3
[Run time : 2.33594s][GPU]Info: system ram : 12GB
[Run time : 2.34614s][GPU]Info: vendor id : 4098
[Run time : 2.35299s][GPU]Info: Using discrete graphics[AMD Radeon R5 M200 Series]
[Run time : 2.42335s][Logical Device]Info: Succesfully created logical device
[Run time : 2.48880s][Swap Chain]Info: Succesfully created swap chain
[Run time : 2.49036s][Swap Chain]Info: Succesfully created image views for swap chain
[Run time : 2.49286s][Rendering]Info: Succesfully created renderpass for windowVulkan

Thanks for any help.

c++
vulkan
asked on Stack Overflow Jun 6, 2019 by Peter Bjergert • edited Jun 6, 2019 by R.J. Dunnill

1 Answer

0

The comment helped me realize that my validation layers wasn't working. I myslef thought they did. Forgot to enable the validation layers in the instance creation.

answered on Stack Overflow Jun 7, 2019 by Peter Bjergert • edited Jun 7, 2019 by double-beep

User contributions licensed under CC BY-SA 3.0