Android Vulkan顶点着色器无法获取所有输入数据

时间:2020-05-26 08:41:42

标签: glsl shader vulkan

我的Vertex数据定义如下:

website_id

我的问题是: 顶点缓冲区已读取所有数据,但顶点着色器仅获取第一个pos作为输入,其他为0.0f

顶点着色器输入

struct Vertex{
    glm::vec4 pos;
    glm::vec2 texcoord;
    glm::vec2 texcoordex;
    float alpha;
    float idx;
};

一些代码段

layout (location = 0) in vec4 pos;
layout (location = 1) in vec2 attr;
layout (location = 2) in vec2 attrex;
layout (location = 3) in float alph;
layout (location = 4) in float id;

我该如何解决问题?感谢您的帮助。


更新


我通过捕获框架从Renderdoc获得了一些信息。结果表明顶点着色器没有输出正确的数据(顶点着色器是一次通过)。 但是Renderdoc显示顶点缓冲区具有正确的数据。 同时,顶点着色器输出每次运行都会变化,并且永远不会正确。 是同步问题吗?错误可能在哪里。

vertex shader data from Renderdoc

VkVertexInputBindingDescription vertex_input_bindings{
.binding = 0,
.stride = sizeof(Vertex),
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
};

VkVertexInputAttributeDescription vertex_input_attributes[5]{
{
.binding = 0,
.location = 0,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
.offset = offsetof(Vertex, pos),
},
{
.binding = 0,
.location = 1,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof(Vertex, texcoord),
},
{
.binding = 0,
.location = 2,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof(Vertex, texcoordex),
},
{
.binding = 0,
.location = 3,
.format = VK_FORMAT_R32_SFLOAT,
.offset = offsetof(Vertex, alpha),
},
{
.binding = 0,
.location = 4,
.format = VK_FORMAT_R32_SFLOAT,
.offset = offsetof(Vertex, idx),
}};

VkPipelineVertexInputStateCreateInfo vertexInputInfo{
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pNext = nullptr,
.vertexBindingDescriptionCount = 1,
.pVertexBindingDescriptions = &vertex_input_bindings,
.vertexAttributeDescriptionCount = 5,
.pVertexAttributeDescriptions = vertex_input_attributes,
};

VkDeviceSize offset = 0;
vkCmdBindVertexBuffers(render.cmdBuffer_[bufferIndex], 0, 1, &buffers.vertexBuf_, &offset);

1 个答案:

答案 0 :(得分:0)

我已经解决了。 驱动程序优化无用的输入。我删除了与它们有关的操作以简化调试,因此驱动程序发现它们无用。