繁体   English   中英

vkCreateGraphicsPipelines在共享库中的段错误,但不在静态库中

[英]vkCreateGraphicsPipelines segfault's in shared library but not in static library

我正在尝试编写一个共享库(在c中),它应该启动vulkan(除其他外)。 通过启动我的意思是它应该完成从实例创建到管道创建的整个设置链。

当我将上述函数称为静态库函数时 - >一切正常并且vkCreateGraphicsPipelines中没有发生段错误。 但是,当我构建与共享(.so)库相同的功能并调用它时 - > vkCreateGraphicsPipelines segfault。

更新07.03.19

验证层现在正在全力运行。

使用静态lib编译:

gcc test.c -lvulkan -lglfw -lvui_static

关于管道创建的回调输出(函数正常退出):

creating pipeline!
Thread 0, Frame 0:
vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines) returns VkResult VK_SUCCESS (0):
    device:                         VkDevice = 0x559b52daf3a0
    pipelineCache:                  VkPipelineCache = 0
    createInfoCount:                uint32_t = 1
    pCreateInfos:                   const VkGraphicsPipelineCreateInfo* = 0x559b52cd57f8
        pCreateInfos[0]:                const VkGraphicsPipelineCreateInfo = 0x559b52cd57f8:
            sType:                          VkStructureType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO (28)
            pNext:                          const void* = NULL
            flags:                          VkPipelineCreateFlags = 0
            stageCount:                     uint32_t = 2
            pStages:                        const VkPipelineShaderStageCreateInfo* = 0x559b52cd8058
                pStages[0]:                     const VkPipelineShaderStageCreateInfo = 0x559b52cd8058:
                    sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO (18)
                    pNext:                          const void* = NULL
                    flags:                          VkPipelineShaderStageCreateFlags = 0
                    stage:                          VkShaderStageFlagBits = 1 (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_ALL)
                    module:                         VkShaderModule = 0x559b52cd8910
                    pName:                          const char* = "main"
                    pSpecializationInfo:            const VkSpecializationInfo* = NULL
                pStages[1]:                     const VkPipelineShaderStageCreateInfo = 0x559b52cd8088:
                    sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO (18)
                    pNext:                          const void* = NULL
                    flags:                          VkPipelineShaderStageCreateFlags = 0
                    stage:                          VkShaderStageFlagBits = 16 (VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_ALL)
                    module:                         VkShaderModule = 0x559b52dcc6b0
                    pName:                          const char* = "main"
                    pSpecializationInfo:            const VkSpecializationInfo* = NULL
            pVertexInputState:              const VkPipelineVertexInputStateCreateInfo* = 0x559b52dcf790:
                sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO (19)
                pNext:                          const void* = NULL
                flags:                          VkPipelineVertexInputStateCreateFlags = 0
                vertexBindingDescriptionCount:  uint32_t = 0
                pVertexBindingDescriptions:     const VkVertexInputBindingDescription* = NULL
                vertexAttributeDescriptionCount: uint32_t = 0
                pVertexAttributeDescriptions:   const VkVertexInputAttributeDescription* = NULL
            pInputAssemblyState:            const VkPipelineInputAssemblyStateCreateInfo* = 0x559b52dcf030:
                sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO (20)
                pNext:                          const void* = NULL
                flags:                          VkPipelineInputAssemblyStateCreateFlags = 0
                topology:                       VkPrimitiveTopology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST (3)
                primitiveRestartEnable:         VkBool32 = 0
            pTessellationState:             const VkPipelineTessellationStateCreateInfo* = NULL
            pViewportState:                 const VkPipelineViewportStateCreateInfo* = 0x559b52dcf140:
                sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO (22)
                pNext:                          const void* = NULL
                flags:                          VkPipelineViewportStateCreateFlags = 0
                viewportCount:                  uint32_t = 1
                pViewports:                     const VkViewport* = 0x559b52dc8e70
                    pViewports[0]:                  const VkViewport = 0x559b52dc8e70:
                        x:                              float = 0
                        y:                              float = 0
                        width:                          float = 500
                        height:                         float = 500
                        minDepth:                       float = 0
                        maxDepth:                       float = 1
                scissorCount:                   uint32_t = 1
                pScissors:                      const VkRect2D* = 0x559b52dc94f0
                    pScissors[0]:                   const VkRect2D = 0x559b52dc94f0:
                        offset:                         VkOffset2D = 0x559b52dc94f0:
                            x:                              int32_t = 0
                            y:                              int32_t = 0
                        extent:                         VkExtent2D = 0x559b52dc94f8:
                            width:                          uint32_t = 500
                            height:                         uint32_t = 500
            pRasterizationState:            const VkPipelineRasterizationStateCreateInfo* = 0x559b52dca7a0:
                sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO (23)
                pNext:                          const void* = NULL
                flags:                          VkPipelineRasterizationStateCreateFlags = 0
                depthClampEnable:               VkBool32 = 0
                rasterizerDiscardEnable:        VkBool32 = 0
                polygonMode:                    VkPolygonMode = VK_POLYGON_MODE_FILL (0)
                cullMode:                       VkCullModeFlags = 2 (VK_CULL_MODE_BACK_BIT | VK_CULL_MODE_FRONT_AND_BACK)
                frontFace:                      VkFrontFace = VK_FRONT_FACE_CLOCKWISE (1)
                depthBiasEnable:                VkBool32 = 0
                depthBiasConstantFactor:        float = 0
                depthBiasClamp:                 float = 0
                depthBiasSlopeFactor:           float = 0
                lineWidth:                      float = 1
            pMultisampleState:              const VkPipelineMultisampleStateCreateInfo* = 0x559b52dc93e0:
                sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO (24)
                pNext:                          const void* = NULL
                flags:                          VkPipelineMultisampleStateCreateFlags = 0
                rasterizationSamples:           VkSampleCountFlagBits = 1 (VK_SAMPLE_COUNT_1_BIT)
                sampleShadingEnable:            VkBool32 = 0
                minSampleShading:               float = 0
                pSampleMask:                    const VkSampleMask* = NULL
                alphaToCoverageEnable:          VkBool32 = 0
                alphaToOneEnable:               VkBool32 = 0
            pDepthStencilState:             const VkPipelineDepthStencilStateCreateInfo* = NULL
            pColorBlendState:               const VkPipelineColorBlendStateCreateInfo* = 0x559b52cd6f90:
                sType:                          VkStructureType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO (26)
                pNext:                          const void* = NULL
                flags:                          VkPipelineColorBlendStateCreateFlags = 0
                logicOpEnable:                  VkBool32 = 0
                logicOp:                        VkLogicOp = VK_LOGIC_OP_COPY (3)
                attachmentCount:                uint32_t = 1
                pAttachments:                   const VkPipelineColorBlendAttachmentState* = 0x559b52dcf0a0
                    pAttachments[0]:                const VkPipelineColorBlendAttachmentState = 0x559b52dcf0a0:
                        blendEnable:                    VkBool32 = 0
                        srcColorBlendFactor:            VkBlendFactor = VK_BLEND_FACTOR_ZERO (0)
                        dstColorBlendFactor:            VkBlendFactor = VK_BLEND_FACTOR_ZERO (0)
                        colorBlendOp:                   VkBlendOp = VK_BLEND_OP_ADD (0)
                        srcAlphaBlendFactor:            VkBlendFactor = VK_BLEND_FACTOR_ZERO (0)
                        dstAlphaBlendFactor:            VkBlendFactor = VK_BLEND_FACTOR_ZERO (0)
                        alphaBlendOp:                   VkBlendOp = VK_BLEND_OP_ADD (0)
                        colorWriteMask:                 VkColorComponentFlags = 15 (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT)
                blendConstants:                 float[4] = 0x559b52cd6fb8
                    blendConstants[0]:              float = 0
                    blendConstants[1]:              float = 0
                    blendConstants[2]:              float = 0
                    blendConstants[3]:              float = 0
            pDynamicState:                  const VkPipelineDynamicStateCreateInfo* = NULL
            layout:                         VkPipelineLayout = 0x559b52cd6de0
            renderPass:                     VkRenderPass = 0x559b52c582d0
            subpass:                        uint32_t = 0
            basePipelineHandle:             VkPipeline = 0
            basePipelineIndex:              int32_t = 0
    pAllocator:                     const VkAllocationCallbacks* = NULL
    pPipelines:                     VkPipeline* = 0x559b528e53e0
        pPipelines[0]:                  VkPipeline = 0x559b52dcaa60

pipeline created!

使用共享库进行编译:

gcc test.c -lvulkan -lglfw -lvui

关于管道创建的回调输出(函数异常退出 - >没有api转储):

creating pipeline!
Segmentation fault (core dumped)

gdb回溯:

Thread 1 "a.out" received signal SIGSEGV, Segmentation fault.
0x00007ffff7d1549a in crc32 () from /usr/local/lib/libvui.so.0
(gdb) bt
#0  0x00007ffff7d1549a in crc32 () from /usr/local/lib/libvui.so.0
#1  0x00007ffff5fb252f in ?? () from /usr/lib/libvulkan_intel.so
#2  0x00007ffff5fac515 in ?? () from /usr/lib/libvulkan_intel.so
#3  0x00007ffff5e42d13 in ?? () from /usr/lib/libvulkan_intel.so
#4  0x00007ffff5e403d3 in ?? () from /usr/lib/libvulkan_intel.so
#5  0x00007ffff5e41bbb in ?? () from /usr/lib/libvulkan_intel.so
#6  0x00007ffff5e6ce44 in ?? () from /usr/lib/libvulkan_intel.so
#7  0x00007ffff5454aff in vkCreateGraphicsPipelines ()

vui_vulkanInit.c(调用vkCreateGraphicsPipeline()):

#include "../vui_vulkanInit.h"
#include "../vui_debug.h"

#include <GLFW/glfw3.h>
#include <vulkan/vulkan.h>

#include <stdint.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

void initVulkan() 
{
// handles 
    GLFWwindow* window;
    VkInstance *instance               = malloc(sizeof(VkInstance));
    VkSurfaceKHR *surface              = malloc(sizeof(VkSurfaceKHR));
    VkPhysicalDevice *physicalDevice   = malloc(sizeof(VkPhysicalDevice));
    VkDevice *device                   = malloc(sizeof(VkDevice));
    VkQueue *graphicsQueue             = malloc(sizeof(VkQueue));
    VkSwapchainKHR *swapChain          = malloc(sizeof(VkSwapchainKHR));
    VkImage *swapChainImages           = malloc(sizeof(VkImage) * 3);
    VkFormat *swapChainImageFormat     = malloc(sizeof(VkFormat));
    VkExtent2D *swapChainExtent        = malloc(sizeof(VkExtent2D));
    VkImageView *swapChainImageViews   = malloc(sizeof(VkImageView) * 3);
    VkRenderPass *renderPass           = malloc(sizeof(VkRenderPass));
    VkPipelineLayout *pipelineLayout   = malloc(sizeof(VkPipelineLayout));
    VkPipeline *graphicsPipeline       = malloc(sizeof(VkPipeline));
    VkDebugUtilsMessengerEXT *callback = malloc(sizeof(VkDebugUtilsMessengerEXT));

    if (errno == ENOMEM)
        exit(EXIT_FAILURE);

// glfw window
    glfwInit();
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    window = glfwCreateWindow(500, 500, "Vulkan", VK_NULL_HANDLE, VK_NULL_HANDLE);

    if (!window)
        exit(EXIT_FAILURE);

// instance
    VkApplicationInfo appInfo = {};
    appInfo.sType              = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appInfo.pApplicationName   = "Hello Triangle";
    appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
    appInfo.pEngineName        = "No Engine";
    appInfo.engineVersion      = VK_MAKE_VERSION(1, 0, 0);
    appInfo.apiVersion         = VK_API_VERSION_1_1;

    VkInstanceCreateInfo instanceInfo = {};
    instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    instanceInfo.pApplicationInfo = &appInfo;

    // validation layers
        const char *validationLayers[2] = {"VK_LAYER_LUNARG_standard_validation", "VK_LAYER_LUNARG_api_dump"};
        instanceInfo.enabledLayerCount   = 2;
        instanceInfo.ppEnabledLayerNames = validationLayers;

    // extensions
        char *ext1_p = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;

        uint32_t glfwExtensionCount = 0;
        glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
        uint32_t totalExtensionCount = glfwExtensionCount + 1;
        const char **glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);

        const char *extensions[totalExtensionCount];
        extensions[0] = ext1_p;
        for (int i = 1; i < glfwExtensionCount + 1; ++i)
            extensions[i] = glfwExtensions[i - 1];

        instanceInfo.enabledExtensionCount   = totalExtensionCount;
        instanceInfo.ppEnabledExtensionNames = extensions;

    VK_ASSERT(vkCreateInstance(&instanceInfo, VK_NULL_HANDLE, instance));

// validation callback
    vui_createVulkanMessenger(*instance, callback);

// surface
    VK_ASSERT(glfwCreateWindowSurface(*instance, window, VK_NULL_HANDLE, surface));

// physical device
    uint32_t deviceCount = 0;
    vkEnumeratePhysicalDevices(*instance, &deviceCount, VK_NULL_HANDLE);
    VkPhysicalDevice devices[deviceCount];
    vkEnumeratePhysicalDevices(*instance, &deviceCount, devices);
    // there is only one device possible because I have no dedicated gpu
    for (int i = 0; i < deviceCount; ++i) {
        physicalDevice = &(devices[i]);
        break;
    }

// device
    uint32_t queueFamilyIndex = 0;

    float queuePriority = 1.0f;
    VkDeviceQueueCreateInfo queueCreateInfo = {};
    queueCreateInfo.sType            = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
    queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
    queueCreateInfo.queueCount       = 1;
    queueCreateInfo.pQueuePriorities = &queuePriority;

    VkPhysicalDeviceFeatures deviceFeatures = {};
    const char *deviceExtensions = VK_KHR_SWAPCHAIN_EXTENSION_NAME;

    VkDeviceCreateInfo deviceInfo = {};
    deviceInfo.sType                   = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
    deviceInfo.queueCreateInfoCount    = 1;
    deviceInfo.pQueueCreateInfos       = &queueCreateInfo;
    deviceInfo.pEnabledFeatures        = &deviceFeatures;
    deviceInfo.enabledExtensionCount   = 1;
    deviceInfo.ppEnabledExtensionNames = &deviceExtensions;
    deviceInfo.enabledLayerCount       = 0;

    VK_ASSERT(vkCreateDevice(*physicalDevice, &deviceInfo, VK_NULL_HANDLE, device));
    vkGetDeviceQueue(*device, queueFamilyIndex, 0, graphicsQueue);

// swapchain
    VkSurfaceCapabilitiesKHR capabilities;
    vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*physicalDevice, *surface, &capabilities);
    uint32_t formatCount;
    vkGetPhysicalDeviceSurfaceFormatsKHR(*physicalDevice, *surface, &formatCount, VK_NULL_HANDLE);
    VkSurfaceFormatKHR formats[formatCount];
    if (formatCount != 0)
        vkGetPhysicalDeviceSurfaceFormatsKHR(*physicalDevice, *surface, &formatCount, formats);

    // these assumptions are fine for the purpose of debugging
    VkSurfaceFormatKHR surfaceFormat = formats[1];
    VkPresentModeKHR presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
    VkExtent2D extent = capabilities.currentExtent;
    uint32_t imageCount = 3;

    VkSwapchainCreateInfoKHR swapchainInfo = {};
    swapchainInfo.sType                 = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    swapchainInfo.surface               = *surface;
    swapchainInfo.minImageCount         = imageCount;
    swapchainInfo.imageFormat           = surfaceFormat.format;
    swapchainInfo.imageColorSpace       = surfaceFormat.colorSpace;
    swapchainInfo.imageExtent           = extent;
    swapchainInfo.imageArrayLayers      = 1;
    swapchainInfo.imageUsage            = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
    swapchainInfo.imageSharingMode      = VK_SHARING_MODE_EXCLUSIVE;
    swapchainInfo.queueFamilyIndexCount = 1;
    swapchainInfo.pQueueFamilyIndices   = &queueFamilyIndex;
    swapchainInfo.preTransform          = capabilities.currentTransform;
    swapchainInfo.compositeAlpha        = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
    swapchainInfo.presentMode           = presentMode;
    swapchainInfo.clipped               = VK_TRUE;
    swapchainInfo.oldSwapchain          = VK_NULL_HANDLE;

    VK_ASSERT(vkCreateSwapchainKHR(*device, &swapchainInfo, VK_NULL_HANDLE, swapChain));
    vkGetSwapchainImagesKHR(*device, *swapChain, &imageCount, VK_NULL_HANDLE);
    vkGetSwapchainImagesKHR(*device, *swapChain, &imageCount, swapChainImages);
    *swapChainImageFormat = surfaceFormat.format;
    *swapChainExtent      = extent;

// render pass

    // ! Please note: structs abstracted.

    VK_ASSERT(vkCreateRenderPass(*device, &renderPassInfo, VK_NULL_HANDLE, renderPass));

// pipeline layout
    VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
    pipelineLayoutInfo.sType                  = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
    pipelineLayoutInfo.setLayoutCount         = 0;
    pipelineLayoutInfo.pushConstantRangeCount = 0;

    VK_ASSERT(vkCreatePipelineLayout(*device, &pipelineLayoutInfo, VK_NULL_HANDLE, pipelineLayout));

// pipeline
    const uint32_t vs_code[] = 
    {
        #include "absPath"
    };
    VkShaderModule vertShaderModule = createShaderModule(*device, vs_code, sizeof(vs_code));
    const uint32_t fs_code[] = 
    {
        #include "absPath"
    };
    VkShaderModule fragShaderModule = createShaderModule(*device, fs_code, sizeof(fs_code));

    VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
    vertShaderStageInfo.sType  = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    vertShaderStageInfo.stage  = VK_SHADER_STAGE_VERTEX_BIT;
    vertShaderStageInfo.module = vertShaderModule;
    vertShaderStageInfo.pName  = "main";

    VkPipelineShaderStageCreateInfo fragShaderStageInfo = {};
    fragShaderStageInfo.sType  = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
    fragShaderStageInfo.stage  = VK_SHADER_STAGE_FRAGMENT_BIT;
    fragShaderStageInfo.module = fragShaderModule;
    fragShaderStageInfo.pName  = "main";

    VkPipelineShaderStageCreateInfo shaderStages[] = {vertShaderStageInfo, fragShaderStageInfo};

    VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
    vertexInputInfo.sType                           = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
    vertexInputInfo.vertexBindingDescriptionCount   = 0;
    vertexInputInfo.vertexAttributeDescriptionCount = 0;

    VkPipelineInputAssemblyStateCreateInfo inputAssembly = {};
    inputAssembly.sType                  = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
    inputAssembly.topology               = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
    inputAssembly.primitiveRestartEnable = VK_FALSE;

    VkViewport viewport = {};
    viewport.x        = 0.0f;
    viewport.y        = 0.0f;
    viewport.width    = (float) (*swapChainExtent).width;
    viewport.height   = (float) (*swapChainExtent).height;
    viewport.minDepth = 0.0f;
    viewport.maxDepth = 1.0f;

    VkOffset2D offset;
    offset.x = 0;
    offset.y = 0;
    VkRect2D scissor = {};
    scissor.offset = offset;
    scissor.extent = *swapChainExtent;

    VkPipelineViewportStateCreateInfo viewportState = {};
    viewportState.sType         = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
    viewportState.viewportCount = 1;
    viewportState.pViewports    = &viewport;
    viewportState.scissorCount  = 1;
    viewportState.pScissors     = &scissor;

    VkPipelineRasterizationStateCreateInfo rasterizer = {};
    rasterizer.sType                   = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
    rasterizer.depthClampEnable        = VK_FALSE;
    rasterizer.rasterizerDiscardEnable = VK_FALSE;
    rasterizer.polygonMode             = VK_POLYGON_MODE_FILL;
    rasterizer.lineWidth               = 1.0f;
    rasterizer.cullMode                = VK_CULL_MODE_BACK_BIT;
    rasterizer.frontFace               = VK_FRONT_FACE_CLOCKWISE;
    rasterizer.depthBiasEnable         = VK_FALSE;

    VkPipelineMultisampleStateCreateInfo multisampling = {};
    multisampling.sType                = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
    multisampling.sampleShadingEnable  = VK_FALSE;
    multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;

    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;

    VkPipelineColorBlendStateCreateInfo colorBlending = {};
    colorBlending.sType             = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
    colorBlending.logicOpEnable     = VK_FALSE;
    colorBlending.logicOp           = VK_LOGIC_OP_COPY;
    colorBlending.attachmentCount   = 1;
    colorBlending.pAttachments      = &colorBlendAttachment;
    colorBlending.blendConstants[0] = 0.0f;
    colorBlending.blendConstants[1] = 0.0f;
    colorBlending.blendConstants[2] = 0.0f;
    colorBlending.blendConstants[3] = 0.0f;

    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.pColorBlendState    = &colorBlending;
    pipelineInfo.layout              = *pipelineLayout;
    pipelineInfo.renderPass          = *renderPass;
    pipelineInfo.subpass             = 0;
    pipelineInfo.basePipelineHandle  = VK_NULL_HANDLE;

    printf("creating pipeline!\n");
    VK_ASSERT(vkCreateGraphicsPipelines(*device, VK_NULL_HANDLE, 1, &pipelineInfo, VK_NULL_HANDLE, graphicsPipeline));
    printf("pipeline created!\n");
}

VkShaderModule createShaderModule(VkDevice device, const uint32_t *code, size_t size) {
    VkShaderModule module;
    VkShaderModuleCreateInfo shaderCreateInfo = 
    {
        .sType    = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
        .pNext    = VK_NULL_HANDLE,
        .flags    = 0,
        .codeSize = size,
        .pCode    = code,
    };
    vkCreateShaderModule(device, &shaderCreateInfo, VK_NULL_HANDLE, &module);
    return module;
}

static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData) 
{
    printf("%s\n", pCallbackData->pMessage);
    return VK_FALSE;
}

static void vui_createVulkanMessenger(VkInstance instance, VkDebugUtilsMessengerEXT *callback) 
{
    PFN_vkCreateDebugUtilsMessengerEXT funcPointer = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
    EXIT_ON_NULL(funcPointer);
    VkDebugUtilsMessengerCreateInfoEXT debugUtilsMessengerInfo = 
    {
        .sType           = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
        .pNext           = VK_NULL_HANDLE,
        .flags           = 0,
        .messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,
        .messageType     = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
        .pfnUserCallback = debugCallback,
        .pUserData       = VK_NULL_HANDLE
    };
    VK_ASSERT(funcPointer(instance, &debugUtilsMessengerInfo, VK_NULL_HANDLE, callback));
}

谢谢你读这个,Ojad

中的段错误

#0  0x00007ffff7fc37db in crc32 () from /usr/local/lib/libvui.so.0

是由声明冲突引起的。 基本上,我包含一个包含一个名为crc32的函数的lib。 在libvulkan_intel.so中必须有一个具有相同声明的函数,或者至少在某个地方作为外部依赖。 无论哪种方式,当编译为共享库时,我有效地重写crc32,一旦crc32被调用就会导致段错误。不是我最骄傲的bug,但它发生了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM