[Mesa-dev] Possible bug with r600g shader compiler

Martin Andersson g02maran at gmail.com
Sun Mar 31 05:51:48 PDT 2013


Hi,

I think have found a bug in the r600g shader compiler. I have a AMD 6950
and I'm running mesa from git.

The bug is exercised by the the vertex shader program in piglit
ext_transform_feedback/order.c

I have simplified the shader program so the compiled shader is easier to read:

#version 130
in uint starting_x;
flat out uint starting_x_copy;
flat out uint iteration_count;
flat out uint shift_reg_final;
uniform uint shift_count;

void main()
{
    gl_Position = vec4(0.0);
    uint x = starting_x;
    uint count = 0u;
    uint shift_reg = 1u;
    starting_x_copy = starting_x;
    uint k;
    while (x != 0u) {
        shift_reg = shift_count;
        for (k = 0u; k < shift_count; ++k)
            ++count;
        x = 0u;
    }
    iteration_count = count;
    shift_reg_final = shift_reg;
}

It compiles to, http://pastebin.com/cQ8rbKCv.

input:
shift_count 64
starting_x 0

actual output:
iteration_count 1
shift_reg 1

expected output:
iteration_count 0
shift_reg 1

When the shader is run with starting_x set to 0 the iteration_count output is 1.
That should be impossible since the ++count is inside the while loop guarded
by x != 0. That the iteration_count is 1 and not 64 is also strange, it seems
to somehow have gotten past the while guard but only executed one iteration in
the for loop before exiting again. Another thing to note is that shift_reg
is not set to 64.

If I write 64 instead of shift_count in the for loop (k < 64u) (effectivily
optimizing it to 64 add statements instead of a loop) or switch the while
to an if, the program behaves as expected. That leads me to belive that
the issue is with the two nested loops.

The docs mentions something about nested flowcontrol for PRED_SETE_64.

"The instruction can also establish a predicate result (execute or skip) for
subsequent predicated instruction execution. This additional control allows a
compiler to support one-instruction issue for if-elseif operations, or an
integer result for nested flow-control, by using single-precision operations
to manipulate a predicate counter."

But the while and for loops are compiled to PRED_SETNE_INT which does not have
that comment. Anyway, I just wanted to include that comment in case it was
relevant.

Anyone knows whats wrong or have any ideas for how I could debug it further?

//Martin


More information about the mesa-dev mailing list