我观察到一些奇怪的行为。我有一个无符号 32 位整数数组。我使用一个整数来编码 4 个值,每个值大小为 1 个字节。然后我想将这样的缓冲区传递给顶点着色器
layout (location = 0) in uvec4 coords;
为了实现这一点,我使用VkVertexInputAttributeDescription
with format
set to VK_FORMAT_R8G8B8A8_UINT
。我已经定义了这样方便的结构
struct PackedUVec4{
unsigned char x;
unsigned char y;
unsigned char z;
unsigned char w;
};
然后我构建我的缓冲区,PackedUVec4[]
然后将此类缓冲区发送到 GPU。但是,我观察到的是字节顺序被交换了。例如,如果我有
layout (location = 0) in uvec4 coords;
void main(){
debugPrintfEXT("%v4d", coords);
}
它似乎打印了正确的输出。但是如果将格式更改为VK_FORMAT_R32_UINT
并尝试运行
layout (location = 0) in uint coords;
void main(){
uint w = coords & 255u;
uint z = coords/256 & 255u;
uint y = coords/(256*256) & 255u;
uint x = coords/(256*256*256) & 255u;
debugPrintfEXT("%v4d", uvec4(x,y,z,w));
}
我以相反的顺序得到字节。向量类型是否使用不同的字节序?