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

Ian Romanick idr at freedesktop.org
Mon Feb 9 10:55:54 PST 2015


On 02/08/2015 04:10 PM, Matt Turner 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?

That sounds reasonable enough.  It would just be changing a restriction
specific to the IR, and it should affect the behavior observed by
applications.

I agree with Connor.  Adding and, or, and xor functions similar to the
existing not and comparitor functions would be the right way to expose this.

> 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
> 
`


More information about the mesa-dev mailing list