OpenGL ES 2.0 中的 swizzling 到底是什么? (特别是 PowerVR SGX。)

发布于 2024-12-01 23:46:21 字数 425 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小兔几 2024-12-08 23:46:21

根据 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.

智商已欠费 2024-12-08 23:46:21

混合 lowp 向量的组件是昂贵的,应该是
避免。

lowp 向量每个通道都是 8 位浮动,我不确定 Powervr,但一般来说,与浮动 8 位相比,在浮动 32 位寄存器(或 16 位,再次取决于架构)之间传输移动数据更有效,因为它不需要额外的掩码/移动指令。大多数 GPU 内存都是这样对齐的。

调配到底是什么?

简而言之,

swizzle 告诉源的哪个通道(或源的组合)应该进入目标的哪个通道,

例如:

vec3 dest.rgb = vec3(src1.r, src2.r, src3.r);

将 src1.r 通道移动到 dest.r 通道,将 src2.r 通道移动到 dest.g 通道和 src3。 r 通道到 dest.b 通道。

使用 swizzle 比手动移动通道更有效,因为 GPU 在硬件中支持这一点。(同样,一些 GPU 编译器可以检测到这一点,并且也可以优化移动)。

Swizzling the components of lowp vectors is expensive and should be
avoided.

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.

What exactly is swizzling?

In simple words,

swizzle tells that which channel of source(or combination of sources)should go in which channel of destination

example:

vec3 dest.rgb = vec3(src1.r, src2.r, src3.r);

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文