[Mesa-dev] glsl: Making logical operations per-component?

Matt Turner mattst88 at gmail.com
Sun Feb 8 16:10:49 PST 2015

The GLSL IR ir_binop_logic_* operations match the source language
operators in that they only operate on scalars.

In talking to Ilia, I realized that the vectorizer pass doesn't know
about that, and so it will happily vectorize the vertex shader in the
piglit test below.

The i965 driver emits perfectly fine code for this and passes the
test, but ir_validate asserts that the operands to && are scalar

Should we relax this restriction and let the logical and/or/xor/not
operations operate per-component? Perhaps a small GLSL extension
codifying this and allowing it in the source language should be in

Sounds like something like this would simplify some code Ilia's working on.

GLSL >= 1.30

[vertex shader]
in vec4 vertex;
out vec4 color;

uniform bvec4 a, b;

void main() {
gl_Position = vertex;

color.x = float(a.x && b.x);
color.y = float(a.y && b.y);
color.z = float(a.z && b.z);
color.w = float(a.w && b.w);

[fragment shader]
in vec4 color;
out vec4 frag_color;

void main()
frag_color = color;

[vertex data]
-1.0 -1.0
 1.0 -1.0
 1.0  1.0
-1.0  1.0

uniform ivec4 a 1 1 1 1
uniform ivec4 b 1 0 0 1
draw arrays GL_TRIANGLE_FAN 0 4
probe all rgba 1.0 0.0 0.0 1.0

More information about the mesa-dev mailing list