读取vkCreateGraphicsPipelines上的访问冲突

时间:2019-06-06 22:17:00

标签: c++ vulkan

我正在用vulkan(暂时)制作一个简单的渲染器,此刻我正在使其变得非常简单。我在vkCreateGraphicsPipelines()处遇到异常,可能是什么问题,我将如何解决。

我尝试查找尚未初始化的任何内容,但到目前为止没有任何内容。我已经检查了调用堆栈,但一无所获,因为调用管道的create函数时会引发异常。我也在google上搜索,但没有找到任何帮助。我关注的是vulkan教程网站,只是将其抽象为不同的类,多次检查了该教程。一切正常,直到我进入vkCreateGraphicsPipelines函数。

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);

着色器代码

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;
}

这是错误消息

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

控制台的输出(不是真正的格式,我只是想让事情先生效)

[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

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

该评论使我意识到我的验证层不起作用。我myslef认为他们做到了。忘记在实例创建中启用验证层。