Bug 32031 - [GLSL] loop in function causes assertion
Summary: [GLSL] loop in function causes assertion
Status: CLOSED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: 7.9
Hardware: All All
: medium major
Assignee: Ian Romanick
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-01 17:11 UTC by jiajia
Modified: 2011-01-03 16:38 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
attach this shader test case (427 bytes, text/plain)
2010-12-01 17:13 UTC, jiajia
Details
glsl: fix lowering conditional returns in subroutines (1.22 KB, patch)
2010-12-02 03:12 UTC, Fabian Bieler
Details | Splinter Review

Description jiajia 2010-12-01 17:11:35 UTC
Below shader causes assertion on Calpella (i965) with mesa master:
shader_runner: loop_analysis.cpp:141: virtual ir_visitor_status loop_analysis::visit(ir_loop_jump*): Assertion `!this->state.is_empty()' failed.
Aborted (core dumped)

[require]
GL >= 2.0
GLSL >= 1.10

[vertex shader]
bool myFunc(void)
{
        int i;
        for(i = 0; i < 2; i++)
        {
                if(i < 1)
                        return true;
                else
                        return false;
        }
}

void main(void)
{
        if (myFunc())
                gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0); // green
        else
                gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0); // red

        gl_Position = gl_Vertex;
}

[test]
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
Comment 1 jiajia 2010-12-01 17:13:33 UTC
Created attachment 40721 [details]
attach this shader test case
Comment 2 Fabian Bieler 2010-12-02 03:12:16 UTC
Created attachment 40736 [details] [review]
glsl: fix lowering conditional returns in subroutines

As described in
http://lists.freedesktop.org/archives/mesa-dev/2010-December/004279.html
This patch should fix this bug.
Comment 3 Vinson Lee 2010-12-03 23:09:29 UTC
Test case attachment id=40721 committed to piglit.

commit e69936110f0a586c0c24f7fb53d3e7477ae0c026
Author: jiajia <jiajia.zheng@intel.com>
Date:   Fri Dec 3 23:08:04 2010 -0800

    loopfunc: Add test case from FDO bug 32031.
Comment 4 Vinson Lee 2010-12-04 14:32:54 UTC
(gdb) bt
#0  0x00c8d416 in __kernel_vsyscall ()
#1  0x0059c941 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0x0059fe42 in abort () at abort.c:92
#3  0x005958e8 in __assert_fail (assertion=0x4a12a9 "!this->state.is_empty()", file=0x4a1297 "loop_analysis.cpp", line=141, 
    function=0x4a1660 "virtual ir_visitor_status loop_analysis::visit(ir_loop_jump*)") at assert.c:81
#4  0x0029f435 in loop_analysis::visit (this=0xbf824714, ir=0x95e5750) at loop_analysis.cpp:141
#5  0x00291aa8 in ir_loop_jump::accept (this=0x95e5750, v=0xbf824714) at ir_hv_accept.cpp:105
#6  0x00291957 in visit_list_elements (v=0xbf824714, l=0x982b788) at ir_hv_accept.cpp:48
#7  0x002922e8 in ir_if::accept (this=0x982b770, v=0xbf824714) at ir_hv_accept.cpp:366
#8  0x00291957 in visit_list_elements (v=0xbf824714, l=0x982f128) at ir_hv_accept.cpp:48
#9  0x00291b1b in ir_function_signature::accept (this=0x982f100, v=0xbf824714) at ir_hv_accept.cpp:120
#10 0x00291957 in visit_list_elements (v=0xbf824714, l=0x9641808) at ir_hv_accept.cpp:48
#11 0x00291b87 in ir_function::accept (this=0x96417f0, v=0xbf824714) at ir_hv_accept.cpp:132
#12 0x00291957 in visit_list_elements (v=0xbf824714, l=0x950bff0) at ir_hv_accept.cpp:48
#13 0x002918c4 in ir_hierarchical_visitor::run (this=0xbf824714, instructions=0x950bff0) at ir_hierarchical_visitor.cpp:282
#14 0x0029ff51 in analyze_loop_variables (instructions=0x950bff0) at loop_analysis.cpp:495
#15 0x0028532e in do_common_optimization (ir=0x950bff0, linked=false, max_unroll_iterations=32)
    at glsl_parser_extras.cpp:741
#16 0x0026c553 in _mesa_glsl_compile_shader (ctx=0x9497548, shader=0x9502b50) at program/ir_to_mesa.cpp:2975
#17 0x0021270a in compile_shader (shaderObj=1) at main/shaderapi.c:853
#18 _mesa_CompileShaderARB (shaderObj=1) at main/shaderapi.c:1184
#19 0x0804b5a5 in compile_glsl (target=35633, release_text=false)
    at piglit/tests/shaders/shader_runner.c:119
#20 0x0804c0dc in leave_state (state=vertex_shader, 
    line=0x9502adc "[test]\r\ndraw rect -1 -1 2 2\r\nprobe all rgba 0.0 1.0 0.0 1.0\r\n\r\n")
    at piglit/tests/shaders/shader_runner.c:433
#21 0x0804c4af in process_test_script (script_name=0xbf82650d "tests/shaders/loopfunc.shader_test")
    at piglit/tests/shaders/shader_runner.c:563
#22 0x0804d486 in piglit_init (argc=2, argv=0xbf8249c4) at piglit/tests/shaders/shader_runner.c:863
#23 0x0804f977 in main (argc=2, argv=0xbf8249c4) at piglit/tests/util/piglit-framework.c:116
(gdb) frame 4
#4  0x0029f435 in loop_analysis::visit (this=0xbf824714, ir=0x95e5750) at loop_analysis.cpp:141
141	   assert(!this->state.is_empty());
Comment 5 Vinson Lee 2010-12-04 14:40:15 UTC
*** Bug 32103 has been marked as a duplicate of this bug. ***
Comment 6 Ian Romanick 2010-12-09 14:50:50 UTC
Fixed by the following commit.  This commit will need to be cherry picked back to the 7.9 branch.  I'm leaving the bug open, but I'm changing the version to 7.9.

commit ef534f3838f23d757a40426728789183ed36c3bb
Author: Fabian Bieler <der.fabe@gmx.net>
Date:   Wed Dec 1 14:44:58 2010 +0100

    glsl: fix lowering conditional returns in subroutines
    
    this fix applies to the lower_sub_return 'branch' of the lower_jumps pass
    
    Fixes piglit tests glsl-functions-5 and glsl-functions-6.
Comment 7 jiajia 2010-12-12 17:52:40 UTC
verified
Comment 8 jiajia 2010-12-12 18:00:03 UTC
reopen this bug for version 7.9
Comment 9 Gordon Jin 2010-12-12 19:29:50 UTC
not marking 7.9 bugs as P1
Comment 10 Ian Romanick 2011-01-03 14:24:45 UTC
commit 9d1c6dd79b2f6f16f650b72b96a2e53fac39d4d5
Author: Fabian Bieler <der.fabe@gmx.net>
Date:   Wed Dec 1 14:44:58 2010 +0100

    glsl: fix lowering conditional returns in subroutines
    
    this fix applies to the lower_sub_return 'branch' of the lower_jumps pass
    
    Fixes piglit tests glsl-functions-5 and glsl-functions-6.
    (cherry picked from commit ef534f3838f23d757a40426728789183ed36c3bb)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.