首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vkCreatePipeline失败和验证层段故障

vkCreatePipeline失败和验证层段故障
EN

Stack Overflow用户
提问于 2017-08-02 12:10:20
回答 2查看 1.2K关注 0票数 0

我试着用Vulkan画一些东西给HTC Vive。

我启用了验证层,程序在vkCreateGraphicsPipeline中给了我段错误。VkLayer_core_validation.dll出现节段故障。如果这还不够奇怪的话,那么发生在vkEmurateInstanceExtensions中的部分错误的函数。因此,我在没有验证层的情况下进行了测试,然后vkCreateGraphicsPipelineVK_ERROR_VALIDATION_FAILED_EXT中失败了。

现在我已经读了几遍教程的管道部分,我没有发现任何错误。此外,我尝试了较早版本的Vulkan,但唯一的区别是在vkGetInstanceProcAddrvkCreateGraphicsPipeline中发生了该段错误。

代码语言:javascript
复制
static int loadShader(VrDevice *device,VkShaderModule *module,char *filename){
    // load the shader
         .
         .
         .
    // Create the VkShaderModule
    VkShaderModuleCreateInfo shadermodule;
    shadermodule.sType=VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
    shadermodule.flags=0;
    shadermodule.pNext=NULL;
    shadermodule.codeSize=buffersize;
    shadermodule.pCode=(const uint32_t *)buffer;
    VkResult result=vkCreateShaderModule(device->logicaldevice,&shadermodule,NULL,module);

    // Check for vulkan error and free allocated memory before exiting
    delete[] buffer;
    if(result==VK_SUCCESS) return 1;
    else return 0;
}

int renderingInit(VrDevice *device,char *appname){
     .
     .
     .

    VkApplicationInfo appinfo;
    appinfo.sType=VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appinfo.pNext=NULL;
    appinfo.apiVersion=VK_MAKE_VERSION(1,0,0);
    appinfo.pApplicationName=appname;
    appinfo.applicationVersion=1;
    appinfo.pEngineName=appname;
    appinfo.engineVersion=1;

    VkInstanceCreateInfo instanceinfo;
    instanceinfo.sType=VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    instanceinfo.pNext=NULL;
    instanceinfo.flags=0;
    instanceinfo.pApplicationInfo=&appinfo;
    instanceinfo.enabledExtensionCount=numextension;
    instanceinfo.ppEnabledExtensionNames=extensions;
    instanceinfo.enabledLayerCount=layercount;
    instanceinfo.ppEnabledLayerNames=debuglayers;

    if(vkCreateInstance(&instanceinfo,NULL,&device->instance)!=VK_SUCCESS) return 0;
     .
     .
     .

    // Graphics card related matters
    uint32_t devicecount=1;
    result=vkEnumeratePhysicalDevices(device->instance,&devicecount,&device->physicaldevice);
    if(result==VK_SUCCESS || result==VK_INCOMPLETE){       
        vkGetPhysicalDeviceProperties(device->physicaldevice,&device->physicaldeviceprop);
        vkGetPhysicalDeviceMemoryProperties(device->physicaldevice,&device->physicaldevicememprop);
        vkGetPhysicalDeviceFeatures(device->physicaldevice,&device->physicaldevicefeatures);
    }
    else return 0

    uint32_t queuecount;
    vkGetPhysicalDeviceQueueFamilyProperties(device->physicaldevice,&queuecount,NULL);
    if(queuecount>0){
        VkQueueFamilyProperties *queues=new VkQueueFamilyProperties[queuecount];
        vkGetPhysicalDeviceQueueFamilyProperties(device->physicaldevice,&queuecount,queues);
        uint32_t queue;
        for(queue=0;queue<queuecount;queue++){
            if(queues[queue].queueFlags&VK_QUEUE_GRAPHICS_BIT) break;
        }

        delete[] queues;

        device->queuefamily=queue;

    }
    else return 0;
     .
     .
     .                  
    // Make logical device
    VkDeviceQueueCreateInfo queueinfo;
    queueinfo.sType=VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
    queueinfo.pNext=NULL;
    queueinfo.flags=0;
    queueinfo.queueCount=1;
    queueinfo.queueFamilyIndex=device->queuefamily;
    float priority=1.0f;
    queueinfo.pQueuePriorities=&priority;

    VkDeviceCreateInfo createinfo;
    createinfo.sType=VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
    createinfo.pNext=NULL;
    createinfo.flags=0;
    createinfo.pQueueCreateInfos=&queueinfo;
    createinfo.queueCreateInfoCount=1;
    createinfo.ppEnabledExtensionNames=extensions;
    createinfo.enabledExtensionCount=numextensions;
    createinfo.ppEnabledLayerNames=NULL;
    createinfo.enabledLayerCount=0;
    createinfo.pEnabledFeatures=&device->physicaldevicefeatures;

    if(vkCreateDevice(device->physicaldevice,&createinfo,NULL,&device->logicaldevice)!=VK_SUCCESS) return 0;
    vkGetDeviceQueue(device->logicaldevice,device->queuefamily,0,&device->queue);

    // Create the frame image for the Vive

     .
     .
     .      

    // Create renderpass
    VkAttachmentDescription colorattachment;
    colorattachment.format = VK_FORMAT_R8G8B8A8_SRGB;
    colorattachment.samples = VK_SAMPLE_COUNT_1_BIT;
    colorattachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
    colorattachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
    colorattachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
    colorattachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
    colorattachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
    colorattachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

    VkAttachmentReference attachreferences;
    attachreferences.attachment=0;
    attachreferences.layout=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

    VkSubpassDescription subpass;
    subpass.flags=0;
    subpass.pipelineBindPoint=VK_PIPELINE_BIND_POINT_GRAPHICS;
    subpass.inputAttachmentCount=0;
    subpass.pInputAttachments=NULL;
    subpass.colorAttachmentCount=1;
    subpass.pColorAttachments=&attachreferences;
    subpass.pResolveAttachments=0;
    subpass.pDepthStencilAttachment=0;
    subpass.preserveAttachmentCount=0;
    subpass.pPreserveAttachments=0;

    VkRenderPassCreateInfo renderpassinfo;
    renderpassinfo.sType=VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
    renderpassinfo.pNext=NULL;
    renderpassinfo.flags=0;
    renderpassinfo.attachmentCount=1;
    renderpassinfo.pAttachments=&colorattachment;
    renderpassinfo.subpassCount=1;
    renderpassinfo.pSubpasses=&subpass;
    renderpassinfo.dependencyCount=0;
    renderpassinfo.pDependencies=NULL;

    if(vkCreateRenderPass(device->logicaldevice,&renderpassinfo,NULL,&device->renderpass)!=VK_SUCCESS) return 0;

    //** Load shaders and handle pipeline creation **//

    // Pipeline layout
    VkPipelineLayoutCreateInfo createinfo;
    createinfo.sType=VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
    createinfo.pNext=NULL;
    createinfo.flags=0;
    createinfo.setLayoutCount=0;
    createinfo.pSetLayouts=NULL;
    createinfo.pushConstantRangeCount=0;
    createinfo.pPushConstantRanges=NULL;
    if(vkCreatePipelineLayout(device->logicaldevice,&createinfo,NULL,&device->pipelinelayout)!=VK_SUCCESS) return 0;


    // Shader modules.
    VkPipelineShaderStageCreateInfo shaderstages[2];
    if(loadShader(device,&shaderstages[0].module,VERTEX_SHADER_NAME)==0 && loadShader(device,&shaderstages[1].module,FRAGMENT_SHADER_NAME)==0) return 0;

    shaderstages[0].sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    shaderstages[0].pNext=NULL;
    shaderstages[0].flags=0;
    shaderstages[0].stage=VK_SHADER_STAGE_VERTEX_BIT;
    shaderstages[0].pSpecializationInfo=NULL;
    shaderstages[0].pName="main";
    shaderstages[1].sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    shaderstages[1].pNext=NULL;
    shaderstages[1].flags=0;
    shaderstages[1].stage=VK_SHADER_STAGE_FRAGMENT_BIT;
    shaderstages[1].pSpecializationInfo=NULL;
    shaderstages[1].pName="main";

    // Descripte the vertex input to pipeline.
    VkPipelineVertexInputStateCreateInfo vertexinfo;
    vertexinfo.sType=VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
    vertexinfo.pNext=NULL;
    vertexinfo.flags=0;
    vertexinfo.pVertexAttributeDescriptions=NULL;
    vertexinfo.vertexAttributeDescriptionCount=0;
    vertexinfo.pVertexBindingDescriptions=NULL;
    vertexinfo.vertexBindingDescriptionCount=0;

    VkPipelineInputAssemblyStateCreateInfo inputassembly;
    inputassembly.sType=VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
    inputassembly.pNext=NULL;
    inputassembly.flags=0;
    inputassembly.topology=VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
    inputassembly.primitiveRestartEnable=VK_FALSE;

    // Viewport decide what reqion of framebuffer is used.
    VkViewport viewport = {0.0f,0.0f,(float)device->renderwidth,(float)device->renderheight,0.0f,1.0f};
    // Scissors decide how much pippeline covers the window (how much info goes to rasterizing).
    VkRect2D scissor = {0,0,device->renderwidth,device->renderheight};

    VkPipelineViewportStateCreateInfo viewportstate;
    viewportstate.sType=VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
    viewportstate.pNext=NULL;
    viewportstate.flags=0;
    viewportstate.pScissors=&scissor;
    viewportstate.scissorCount=1;
    viewportstate.pViewports=&viewport;
    viewportstate.viewportCount=1;

    // Rasterization infomration
    VkPipelineRasterizationStateCreateInfo rasterization;
    rasterization.sType=VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
    rasterization.pNext=NULL;
    rasterization.flags=0;
    rasterization.depthClampEnable=VK_FALSE;
    rasterization.rasterizerDiscardEnable=VK_FALSE;
    rasterization.polygonMode=VK_POLYGON_MODE_FILL;
    rasterization.cullMode=VK_CULL_MODE_BACK_BIT;
    rasterization.frontFace=VK_FRONT_FACE_CLOCKWISE;
    rasterization.depthBiasEnable=VK_FALSE;
    rasterization.depthBiasConstantFactor=0.0f;
    rasterization.depthBiasClamp=0.0f;
    rasterization.lineWidth=1.0f;

    // Multisampling
    VkPipelineMultisampleStateCreateInfo multisampling;
    multisampling.sType=VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
    multisampling.pNext=NULL;
    multisampling.flags=0;
    multisampling.rasterizationSamples=VK_SAMPLE_COUNT_1_BIT;
    multisampling.sampleShadingEnable=VK_FALSE;
    multisampling.minSampleShading=0.0f;
    multisampling.pSampleMask=NULL;
    multisampling.alphaToCoverageEnable=VK_FALSE;
    multisampling.alphaToOneEnable=VK_FALSE;

    // Color blending
    VkPipelineColorBlendAttachmentState colorblendattachment;
    colorblendattachment.colorWriteMask=VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
    colorblendattachment.blendEnable=VK_FALSE;
    colorblendattachment.srcAlphaBlendFactor=VK_BLEND_FACTOR_ONE;
    colorblendattachment.dstAlphaBlendFactor=VK_BLEND_FACTOR_ZERO;
    colorblendattachment.colorBlendOp=VK_BLEND_OP_ADD;
    colorblendattachment.srcColorBlendFactor=VK_BLEND_FACTOR_ONE;
    colorblendattachment.dstColorBlendFactor=VK_BLEND_FACTOR_ZERO;
    colorblendattachment.alphaBlendOp=VK_BLEND_OP_ADD;
    VkPipelineColorBlendStateCreateInfo colorblend;
    colorblend.sType=VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
    colorblend.pNext=NULL;
    colorblend.flags=0;
    colorblend.logicOpEnable=VK_FALSE;
    colorblend.logicOp=VK_LOGIC_OP_COPY;
    colorblend.attachmentCount=1;
    colorblend.pAttachments=&colorblendattachment;
    colorblend.blendConstants[0]=0;
    colorblend.blendConstants[1]=0;
    colorblend.blendConstants[2]=0;
    colorblend.blendConstants[3]=0;

    // If tuo want to change viewport, line width, blend constants you have to change it in this data type.
    VkPipelineDynamicStateCreateInfo dynamicstateinfo;
    dynamicstateinfo.sType=VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
    dynamicstateinfo.pNext=NULL;
    dynamicstateinfo.flags=0;
    dynamicstateinfo.dynamicStateCount=0;
    dynamicstateinfo.pDynamicStates=NULL;

    VkGraphicsPipelineCreateInfo pipelineinfo;
    pipelineinfo.sType=VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
    pipelineinfo.pNext=NULL;
    pipelineinfo.flags=0;
    pipelineinfo.stageCount=2;
    pipelineinfo.pStages=shaderstages;
    pipelineinfo.pVertexInputState=&vertexinfo;
    pipelineinfo.pInputAssemblyState=&inputassembly;
    pipelineinfo.pViewportState=&viewportstate;
    pipelineinfo.pRasterizationState=&rasterization;
    pipelineinfo.pMultisampleState=&multisampling;
    pipelineinfo.pDepthStencilState=NULL;
    pipelineinfo.pColorBlendState=&colorblend;
    pipelineinfo.pDynamicState=&dynamicstateinfo;
    pipelineinfo.layout=device->pipelinelayout;
    pipelineinfo.renderPass=device->renderpass;
    pipelineinfo.subpass=0;
    pipelineinfo.basePipelineHandle=VK_NULL_HANDLE;
    pipelineinfo.basePipelineIndex=0;

    // ** TODO: SEGMENT FAULT WHILE DEBUG LAYER IS ON! ** //
    if((result=vkCreateGraphicsPipelines(device->logicaldevice,VK_NULL_HANDLE,1,&pipelineinfo,NULL,&device->pipeline))!=VK_SUCCESS) return 0;

    // Destroy shaders after pipeline creation
    vkDestroyShaderModule(device->logicaldevice,shaderstages[0].module,NULL);
    vkDestroyShaderModule(device->logicaldevice,shaderstages[1].module,NULL);
}

编辑1:将调试层更改为验证层。

附加信息: Vulkan SDK版本1.0.54.0

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-03 14:22:49

层中有一个错误(可能在驱动程序中-它至少会使我的AMD崩溃)。而不是pipelineinfo.pTessellationState的未初始化值(有效,但显然崩溃),尝试NULL

如果在调试模式下编译的话,您还有其他错误应该被层捕获:

  • 未初始化的colorattachment.flags (可能应该是0)
  • dynamicstateinfo.dynamicStateCount 必须不是0 (如果要禁用动态状态,则必须完全使用pipelineinfo.pDynamicState=NULL )
  • 由于&&短路,将不会加载一个着色器模块(我认为您打算使用|| )。

请启用您的验证层("VK_LAYER_LUNARG_standard_validation") +报告和,验证它们是否正常工作。在编译器调试模式下编译和测试程序(它将通过用更可检测的模式填充未初始化的值来帮助您)。对我来说,这三人在坠机前就已经有了适当的报告。

我正在修复第一个,并希望它将在下一个版本的层。

票数 0
EN

Stack Overflow用户

发布于 2017-08-02 16:01:48

最可能的解释是,您保留了一个指针未赋值,并且包含无效的非空指针值。虽然看上去您已经尝试过填充代码中的每个struct成员字段,但还是有可能有人被忽略了。在运行代码来设置成员之前,尝试清除整个结构可能是值得的。

希望您使用“调试层”意味着启用标准验证层。标准验证层是一个元层,它支持多个与验证相关的层,包括“参数检查”和“核心验证”。

参数检查层通常会报告错误消息,如果它找到一个空指针,其中应该有一个有效的指针。所以我建议清理你的机器人。这可以使此层生成有意义的消息。

core_validation层假设参数检查“传递”,因此在取消引用之前不会总是测试NULL指针。而且它不能避免取消引用坏的非空指针。其意图是参数检查层将成功地报告一条有用的错误消息,即使应用程序稍后可能在核心验证中崩溃。然后,程序员应该处理通过参数检查报告的错误,然后允许核心验证完成它的工作。

所以,底线,我建议你的所有结构清零,然后再填入。确保您正在使用标准验证元层,其中包括参数检查。然后观察验证错误消息。

如果所有这些都失败了,那么您可能希望在验证层中捕获seg故障,以获得导致错误的数据结构的线索。看起来您的图层代码和您的符号文件之间可能存在符号不匹配。可能值得尝试解决这个问题,或者构建您自己的层,这样您就有了准确的符号。

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

https://stackoverflow.com/questions/45460516

复制
相关文章

相似问题

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