首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >vkCreateGraphicsPipelines上的读访问冲突

vkCreateGraphicsPipelines上的读访问冲突
EN

Stack Overflow用户
提问于 2019-06-07 06:17:01
回答 1查看 710关注 0票数 3

我正在用vulkan (临时)创建一个简单的渲染器,目前我正在让它变得非常简单。我在vkCreateGraphicsPipelines()上得到了一个异常,问题可能是什么,我该如何修复它。

我试图找到任何尚未初始化的东西,但到目前为止什么都没有。我检查了调用堆栈,但什么也没有得到,因为在调用管道的create函数时抛出了异常。我也在谷歌上搜索,但没有找到任何有帮助的东西。我正在关注vulkan-tutorial网站,只是把它抽象到不同的类中,多次查看教程。在我使用vkCreateGraphicsPipelines函数之前,一切都会正常工作。

代码语言:javascript
运行
复制
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);

着色器代码

代码语言:javascript
运行
复制
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;
}

下面是错误消息

代码语言:javascript
运行
复制
Exception thrown at 0x00007FFC0171261B (amdvlk64.dll) in vulkan.exe: 
0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

控制台的输出(不是真正格式化的,我只是想先让它正常工作)

代码语言:javascript
运行
复制
[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

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2019-06-07 20:00:25

这条评论帮助我意识到我的验证层不起作用。我自己也是这么想的。在创建实例时忘记启用验证层。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56485744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档