[Mesa-dev] glsl2: assignment write masks vs. swizzles

Eric Anholt eric at anholt.net
Thu Aug 5 10:39:36 PDT 2010

On Thu, 5 Aug 2010 18:21:11 +0200, Aras Pranckevicius <aras at unity3d.com> wrote:
> Hi,
> Since commit 5a7758efbe14dee026245a4f4f4fb3ccf7b2c23b (Add
> ir_assignment::write_mask and associated methods) I'm somewhat
> confused about types and swizzles.
> Expression like this:
>     gl_Position.zw = gl_Vertex.xy*2.0;
> now produces IR that has vec4 node types:
>     (declare (temporary ) vec2 tmpvar_1)
>     (assign (constant bool (1))
>         (xy)
>         (var_ref tmpvar_1)
>         (expression vec2 * (swiz xy (var_ref gl_Vertex))(constant
> float (2.0)) ) )
>     (assign (constant bool (1))
>         (zw)
>         (var_ref gl_Position)
>         (swiz xxxy (var_ref tmpvar_1) ))
> in the last two lines line, var_ref gl_Position has vec4 type, also
> the xxxy swizzle has vec4 type.
> Is that expected behavior, or something ir_assignment::set_lhs and
> friends don't handle correctly?

A lot of graphics hardware operates on vec4 types only.  As an example,
i915 fragment shader is only vec4s, and r200 and i965 vertex shaders are
only vec4s.  The 965 fragment shader has no types except for floats and
ints (approximately), so it all gets chopped up at codegen anyway. The
software rasterizer is all vec4s.

So when you say those types are vec2s above, I saw, before and after, a
masked operation on the two vec4s involved when it came to actual code

> If the behavior is expected, how a "xxxy" swizzle should be
> interpreted? First two components ignored because a write mask is .zw
> up above? Also, why vec4 node types come into play when everything in
> the source was vec2?

The write mask means "write only those channels out of the rhs."  so the
swizzle could be any ??xy in that example above, and only those last 2
channels are used.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20100805/ec7f8e98/attachment.pgp>

More information about the mesa-dev mailing list