<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi, Mesa developers, <br>
<br>
According to glsl v1.0, we have loop construct:<br>
for (for-init-statement; condition(opt); expression)<br>
statement-no-new-scope<br>
<br>
Variables declared in for-init-statement or condition are only <font
color="#ff0000">in scope until the end of the<br>
statement-no-new-scope of the for loop.</font><br>
<br>
let's assume I have a fragment shader:<br>
<br>
~/testbed$ cat indvar.frag <br>
void main(void)<br>
{<br>
vec4 a[32];<br>
for(int i=0; i<10; ++i) {<br>
if (i == 9) <br>
gl_FragColor = a[i]; <br>
}<br>
}<br>
<br>
<br>
I found current glsl compiler emits HIR like this:<br>
<br>
<tt>(function main</tt><tt><br>
</tt><tt> (signature void</tt><tt><br>
</tt><tt> (parameters</tt><tt><br>
</tt><tt> )</tt><tt><br>
</tt><tt> (</tt><tt><br>
</tt><tt> (declare () int i@0x988eb84)</tt><tt><br>
</tt><tt> (declare () (array vec4 32) a@0x988ec5c)</tt><tt><br>
</tt><tt> (declare (temporary ) int assignment_tmp@0x988eaac)</tt><tt><br>
</tt><tt> (assign (constant bool (1)) (x) (var_ref
assignment_tmp@0x988eaac) (constant int (0)) ) </tt><tt><br>
</tt><tt> (assign (constant bool (1)) (x) (var_ref
i@0x988eb84) (var_ref assignment_tmp@0x988eaac) ) </tt><tt><br>
</tt><tt> (loop () () () () (</tt><tt><br>
</tt><tt> (if (expression bool ! (expression bool <
(var_ref i@0x988eb84) (constant int (10)) ) ) (</tt><tt><br>
</tt><tt> break</tt><tt><br>
</tt><tt> )</tt><tt><br>
</tt><tt> ())</tt><tt><br>
</tt><tt><br>
</tt><tt> (if (expression bool all_equal (var_ref
i@0x988eb84) (constant int (9)) ) (</tt><tt><br>
</tt><tt> (declare (temporary ) vec4
assignment_tmp@0x987cee4)</tt><tt><br>
</tt><tt> (assign (constant bool (1)) (xyzw) (var_ref
assignment_tmp@0x987cee4) (array_ref (var_ref a@0x988ec5c)
(var_ref i@0x988eb84) ) ) </tt><tt><br>
</tt><tt> (assign (constant bool (1)) (xyzw) (var_ref
gl_FragColor@0x96d8fc4) (var_ref assignment_tmp@0x987cee4) ) </tt><tt><br>
</tt><tt> )</tt><tt><br>
</tt><tt> ())</tt><tt><br>
</tt><tt><br>
</tt><tt> (declare (temporary ) int assignment_tmp@0x987cb84)</tt><tt><br>
</tt><tt> (assign (constant bool (1)) (x) (var_ref
assignment_tmp@0x987cb84) (expression int + (var_ref i@0x988eb84)
(constant int (1)) ) ) </tt><tt><br>
</tt><tt> (assign (constant bool (1)) (x) (var_ref
i@0x988eb84) (var_ref assignment_tmp@0x987cb84) ) </tt><tt><br>
</tt><tt> ))</tt><tt><br>
</tt><tt><br>
</tt><tt> ))</tt><tt><br>
</tt><tt><br>
</tt><tt>)<br>
<br>
</tt>I think glsl compiler translates AST like this<br>
<br>
int i = 0; <br>
for (;;) {<br>
if (i < 10) break;<br>
if (i == 9) gl_FragColor = a [ i ] ;<br>
i = i + 1;<br>
}<br>
<br>
Is it correct?<br>
<br>
Another question, for class ir_loop, why is ir_loop::counter
ir_variable while from/to/increment are all ir_rvalue? I create an
ir_variable for ir_loop counter, but hierarchical visitor won't
access it. I don't think ir_loop::accept(ir_hierarchical_visitor
*v) will visit ir_loop::counter at all.<br>
<br>
thanks,<br>
--lx<br>
<br>
</body>
</html>