OpenGL ES 2.0 中的 swizzling 到底是什么? (特别是 PowerVR SGX。)
PowerVR 说
混合 lowp 向量的组件是昂贵的,应该是 避免。
到底什么是调酒?
color.brg // This fits the definition I'm familiar with.
但是,当 color 是 vec4 时,vec3(color.b, color.r, color.g)
或 vec3(color)
又如何呢? ?
访问或修改单个组件是否构成混淆?我真的不这么认为,但如果不是,那么您可以通过手动执行更多赋值操作来解决混合问题。我这样做没有问题,但对我来说这似乎很神奇,如果您只需编写不带 swizzle 符号的代码就可以以更快的速度获得相同的效果。
PowerVR says
Swizzling the components of lowp vectors is expensive and should be
avoided.
What exactly is swizzling?
color.brg // This fits the definition I'm familiar with.
But what about vec3(color.b, color.r, color.g)
, or vec3(color)
, when color is a vec4?
Does accessing or modifying a single component constitute a swizzle? I really wouldn't think so, but if not, then you could work around swizzling by just doing a few more assignment operations manually. I don't have a problem doing that, but it seems like magic to me, if you could get the same effect at a faster speed just by writing the code without swizzle notation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 GLSL 规范,“swizzle mask”被定义为向量类型的分量字段选择器。
.brg
是一个 swizzle 掩码,.rgba
或.b
也是如此。所有这些都在进行调配。至于PowerVR在说什么,那是他们的事了。也许
.rgb
没问题,因为它以相同的顺序选择组件。或者也许不是。According to the GLSL specification, "swizzle masks" are defined as the component field selectors for vector types.
.brg
is a swizzle mask, as is.rgba
or.b
. All of those do swizzling.As for what PowerVR is talking about, that's up to them. Maybe
.rgb
is fine, since it selects the components in the same order. Or maybe it's not.lowp 向量每个通道都是 8 位浮动,我不确定 Powervr,但一般来说,与浮动 8 位相比,在浮动 32 位寄存器(或 16 位,再次取决于架构)之间传输移动数据更有效,因为它不需要额外的掩码/移动指令。大多数 GPU 内存都是这样对齐的。
简而言之,
swizzle 告诉源的哪个通道(或源的组合)应该进入目标的哪个通道,
例如:
将 src1.r 通道移动到 dest.r 通道,将 src2.r 通道移动到 dest.g 通道和 src3。 r 通道到 dest.b 通道。
使用 swizzle 比手动移动通道更有效,因为 GPU 在硬件中支持这一点。(同样,一些 GPU 编译器可以检测到这一点,并且也可以优化移动)。
lowp vectors are 8-bit floating per channel, i am not sure about Powervr but in generally speaking transferring moving data between Floating 32-bit register(or 16-bit, again depending on architecture) is more efficient in contrast to Floating 8-bit, because it doesn't requires extra maskin/moving instructions.mostly GPU memory are alligned that way.
In simple words,
swizzle tells that which channel of source(or combination of sources)should go in which channel of destination
example:
will move src1.r channel to dest.r channel, src2.r channel to dest.g channel and src3.r channel to dest.b channel.
using swizzle is more efficient than manually moving channels because GPUs support that in hardware.(again some of the GPU compilers can detect that and can optimise the moves also).