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

Connor Abbott cwabbott0 at gmail.com
Sun Feb 8 17:38:18 PST 2015


Yeah, I find it really surprising that GLSL doesn't have per-compoent
and or, and xor, given that it already has per-component not. I didn't
even realize this was the case until I just looked at the spec. At the
very least, we can relax the restriction as long as st/glsl_to_tgsi
will work. NIR should definitely be fine with it. An extension with
and(), or(), and xor() functions like the existing not() sounds like a
good idea too.

On Sun, Feb 8, 2015 at 7:10 PM, Matt Turner <mattst88 at gmail.com> wrote:
> 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
> booleans.
>
> 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
> order?
>
> Sounds like something like this would simplify some code Ilia's working on.
>
>
> [require]
> 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]
> vertex/float/2
> -1.0 -1.0
>  1.0 -1.0
>  1.0  1.0
> -1.0  1.0
>
> [test]
> 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
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list