Bug 34203 - [GLSL] fail to call long chains across shaders
Summary: [GLSL] fail to call long chains across shaders
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: 7.10
Hardware: All Linux (All)
: medium major
Assignee: Ian Romanick
QA Contact:
Depends on:
Reported: 2011-02-12 01:09 UTC by Gordon Jin
Modified: 2011-06-07 17:53 UTC (History)
0 users

See Also:
i915 platform:
i915 features:

new piglit test case (1.24 KB, text/plain)
2011-02-12 01:11 UTC, Gordon Jin

Description Gordon Jin 2011-02-12 01:09:38 UTC
The attached case tests a long chain of function calls across shaders. It gets assertion with i965 and swrast driver:

shader_runner: ir.h:963: ir_call::ir_call(ir_function_signature*, exec_list*): Assertion `callee->return_type != __null' failed.
Aborted (core dumped)

(gdb) bt
#0  0xb7fff424 in __kernel_vsyscall ()
#1  0x42c0fd71 in raise () from /lib/libc.so.6
#2  0x42c1164a in abort () from /lib/libc.so.6
#3  0x42c08de8 in __assert_fail () from /lib/libc.so.6
#4  0xb7be9928 in ir_call (this=0x83ff690, mem_ctx=0x841cb60, ht=0x839e798)
    at ir.h:963
#5  ir_call::clone (this=0x83ff690, mem_ctx=0x841cb60, ht=0x839e798)
    at ir_clone.cpp:158
#6  0xb7c05bbc in ir_call::generate_inline (this=0x841fe68, next_ir=0x841fe68)
    at opt_function_inlining.cpp:186
#7  0xb7c05fef in ir_function_inlining_visitor::visit_enter (this=0xbffff1ac,
    ir=0x841fe68) at opt_function_inlining.cpp:295
#8  0xb7bf296e in ir_call::accept (this=0x841fe68, v=0xbffff1ac)
    at ir_hv_accept.cpp:313
#9  0xb7bf2305 in visit_list_elements (v=0xbffff1ac, l=0x846f198)
    at ir_hv_accept.cpp:48
#10 0xb7bf247b in ir_function_signature::accept (this=0x846f170, v=0xbffff1ac)
    at ir_hv_accept.cpp:120
#11 0xb7bf2305 in visit_list_elements (v=0xbffff1ac, l=0x846f0f0)
    at ir_hv_accept.cpp:48
#12 0xb7bf24d7 in ir_function::accept (this=0x846f0d8, v=0xbffff1ac)
    at ir_hv_accept.cpp:132
#13 0xb7bf2305 in visit_list_elements (v=0xbffff1ac, l=0x83a40a8)
    at ir_hv_accept.cpp:48
#14 0xb7bf22c4 in ir_hierarchical_visitor::run (this=0xbffff1ac,
    instructions=0x83a40a8) at ir_hierarchical_visitor.cpp:282
#15 0xb7c058b3 in do_function_inlining (instructions=0x83a40a8)
    at opt_function_inlining.cpp:84
#16 0xb7be4d58 in do_common_optimization (ir=0x83a40a8, linked=true,
    max_unroll_iterations=32) at glsl_parser_extras.cpp:760
#17 0xb7bf8c7f in link_shaders (ctx=0x806a908, prog=0x845a120) at linker.cpp:1630
#18 0xb7bc6e07 in _mesa_glsl_link_shader (ctx=0x806a908, prog=0x845a120)
    at program/ir_to_mesa.cpp:3244
#19 0xb7b03879 in link_program (ctx=0x806a908, program=<value optimized out>)
    at main/shaderapi.c:885
#20 0x0804c048 in link_and_use_shaders ()
    at /root/gordon/piglit/tests/shaders/shader_runner.c:497
#21 0x0804d211 in piglit_init (argc=2, argv=0xbffff464)
    at /root/gordon/piglit/tests/shaders/shader_runner.c:864
#22 0x0804f683 in main (argc=2, argv=0xbffff464)
    at /root/gordon/piglit/tests/util/piglit-framework.c:116

No sign to show it's regression.
Comment 1 Gordon Jin 2011-02-12 01:11:45 UTC
Created attachment 43284 [details]
new piglit test case
Comment 2 Ian Romanick 2011-03-07 16:25:43 UTC
After quite a bit of digging, I believe the root cause is in the linker.  I'm not sure what the exact problem is, but after linking none of the functions from the 3rd or 4th fragment shader show up in the IR.  As a result, the dead function pass removes a bunch of functions that aren't really dead.  This leads to the function-inliner generating broken inlined functions.
Comment 3 Ian Romanick 2011-03-07 16:41:47 UTC
The problem seems to stem from some of the prototypes not being in the same compilation unit as the main function.  Copying all of the prototypes to that compilation unit makes the problem go away.  This should be handled by the existing code, but something is clearly going wrong.
Comment 4 Ian Romanick 2011-03-08 12:08:37 UTC
Fixed on master by the following commit.  This is a pretty straightforward fix, so it should get cherry picked to the stable branches soon.

commit 60f898a90ebd29d2593866faa1f2d6f65961a414
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Tue Mar 8 11:41:35 2011 -0800

    linker: Add imported functions to the linked IR
    Fixes piglit test glsl-function-chain16 and bugzilla #34203.
    NOTE: This is a candidate for stable release branches.
Comment 5 Ian Romanick 2011-03-24 13:59:10 UTC
Fixed in 7.10 (55d86204f3f659fadc8e6dee694147afc35dfd97).
Comment 6 Gordon Jin 2011-06-01 18:33:16 UTC
verified on 7.10 branch

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.