You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vulkan vkCmdBindVertexBuffers2调用崩溃,求助排查问题

使用vkCmdBindVertexBuffers2绑定顶点缓冲时程序崩溃

尝试使用vkCmdBindVertexBuffers2绑定顶点缓冲,该API与标准vkCmdBindVertexBuffers功能基本一致,仅新增动态步长设置支持。但测试程序持续崩溃,验证层无任何提示,无法定位问题。

使用标准vkCmdBindVertexBuffers时程序完全正常,仅绘制一个三角带四边形。当前使用Vulkan版本1.3.236,按官方文档无需启用扩展,尝试手动启用相关扩展后仍崩溃。崩溃发生在vkCmdBindVertexBuffers2调用时刻,确认所有指针和句柄均有效,崩溃截图如下:
崩溃截图


相关代码

顶点数组

const std::vector<Vertex> vertices =
{
    {{0.0f, 0.0f},  {0.21f, 0.41f, 0.61f}},
    {{0.0f, 1.0f},  {0.21f, 0.41f, 0.61f}},
    {{1.0f, 0.0f},  {0.21f, 0.41f, 0.61f}},
    {{1.0f, 1.0f},  {0.21f, 0.41f, 0.61f}},
};

顶点属性与描述

struct Vertex {
    glm::vec2 pos;
    glm::vec3 color;

    static VkVertexInputBindingDescription getBindingDescription() {
        VkVertexInputBindingDescription bindingDescription{};
        bindingDescription.binding = 0;
        bindingDescription.stride = sizeof(Vertex);
        bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
        return bindingDescription;
    }

    static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions() {
        std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
        attributeDescriptions[0].binding = 0;
        attributeDescriptions[0].location = 0;
        attributeDescriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
        attributeDescriptions[0].offset = offsetof(Vertex, pos);
        attributeDescriptions[1].binding = 0;
        attributeDescriptions[1].location = 1;
        attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
        attributeDescriptions[1].offset = offsetof(Vertex, color);
        return attributeDescriptions;
    }
};

绑定顶点缓冲代码

VkBuffer vertexBuffers[] = {vertexBuffer};
            VkDeviceSize offsets[] = {0};

            // 5 floats x 4 vertices
            VkDeviceSize    sizes[] = {sizeof(float) * 5 * 4};
            VkDeviceSize    strides[] = { sizeof(Vertex) };

#if 0
            // 此代码可正常运行
            vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets);
#else
            // 此代码会导致崩溃 :(
            vkCmdBindVertexBuffers2(commandBuffer, 0, 1, vertexBuffers, offsets, sizes, strides);
#endif

            vkCmdDraw(commandBuffer, static_cast<uint32_t>(vertices.size()), 1, 0, 0);

内容的提问来源于stack exchange,提问作者gmmo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 00:23:21