gpt4 book ai didi

c++ - vkCreateGraphicsPipelines 上的读取访问冲突

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:38:36 25 4
gpt4 key购买 nike

我正在 vulkan 中(暂时)制作一个简单的渲染器,目前我正在让它变得非常简单。我在 vkCreateGraphicsPipelines() 中遇到异常,可能是什么问题,我该如何解决。

我试过寻找任何尚未初始化的东西,但到目前为止什么都没有。我已经检查了调用堆栈,但没有得到任何结果,因为在调用管道的创建函数时抛出了异常。我也在谷歌上搜索过,但没有找到任何帮助。我正在关注 vulkan-tutorial 网站,只是将它抽象到不同的类中,多次检查教程。一切正常,直到我进入 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

感谢您的帮助。

最佳答案

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

关于c++ - vkCreateGraphicsPipelines 上的读取访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56485744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com