HLSL 原始类型大小问题

HLSL Primitive type size issue

我的印象是 float2x4 类型会占用 32 个字节,但是当我声明以下 float2x4 varname[100] 时,它占用 64*100 个字节,而不是预期的 32*100 个字节。怎么会?也许我没有看到与 float2x4 的填充相关的内容。

float2x4 要求 4 个 float2。由于每个 "register" 的宽度为 16 个字节(1 个 float4),因此它使用价值 64 个字节的 space 来存储 4 个 float2。 4 个 float4 中的 Z 和 W 均未使用,用作填充。

相比之下,float4x2 需要 2 个 float4,因此完全适合两个 float4 寄存器(32 字节)。