Bug 95164 - GLSL compiler (linker I think) emits assertion upon call to glAttachShader
Summary: GLSL compiler (linker I think) emits assertion upon call to glAttachShader
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Kenneth Graunke
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-27 05:36 UTC by bugReporter92
Modified: 2016-04-29 23:06 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
API trace of the crash. Only 2 frames long. (56.64 KB, text/plain)
2016-04-27 05:36 UTC, bugReporter92
Details
Shaders that linked together cause the crash (1.84 KB, application/x-xz)
2016-04-28 02:52 UTC, bugReporter92
Details
Patch #1 (4.61 KB, patch)
2016-04-28 04:13 UTC, Kenneth Graunke
Details | Splinter Review
Patch #2 (1.03 KB, patch)
2016-04-28 04:13 UTC, Kenneth Graunke
Details | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description bugReporter92 2016-04-27 05:36:17 UTC
Created attachment 123291 [details]
API trace of the crash. Only 2 frames long.

After building the very latest code for GLideN64 (https://github.com/gonetz/GLideN64) on the experimental_blend branch, I get the following assertion from a debug build of mesa:

brw_fs_channel_expressions.cpp:435: virtual ir_visitor_status ir_channel_expressions_visitor::visit_leave(ir_assignment*): Assertion `!"should have been lowered"' failed.

I have attached an apitrace of the event which contains the shader code (kind of auto generated by c++, so hard to get otherwise). I couldn't reproduce the problem with the standalone src/glsl/glsl_compiler because some of the shaders wouldn't build because of something that looked like a bug in the standalone. This same assertion happens when I build 11.1.3 from source.
All the shaders (as logged using MESA_DEBUG=log) compiled fine with glslang, but I think the crash was during linking so that probably isn't relevant.

Using the version 11.1.3 from my distro (without assertions) (Debian Testing), then the shader compiles and creates totally mangled rendering results. This may be unrelated.

Even if the shader is totally invalid (it works well for other contributers on a variety of machines), it should probably not be triggering an assertion.

Let me know what other information would be helpful.
Comment 1 Kenneth Graunke 2016-04-27 07:06:58 UTC
This ought to be a really simple bug to fix, but I can't seem to reproduce it with your apitrace.  I compiled Mesa 11.1.3 in debug mode and your apitrace didn't seem to trigger any assertions...
Comment 2 bugReporter92 2016-04-27 12:59:42 UTC
I actually didn't try to get the assert to happen by replaying. I'll figure out what conditions (env vars possibly) cause it to crash by using the replay function when I get home from work tonight.
Comment 3 bugReporter92 2016-04-28 02:45:44 UTC
Seeing as glAttachShader was the last call in the apitrace output, I assumed that it was the one crashing. After doing a proper gdb session, it was actually in the glLinkShader call that crashes, and it is not recorded in the apitrace, which is why we aren't seeing it in the apitrace that I attached. (I tried and failed to reproduce using replay, for reasons now obvious)

I'm just going to attach the three shaders that are being linked (I think, from the trace) to cause the crash. I can't get src/glsl/glsl_compiler to compile the shaders, for a reason that looks unrelated, but if I could maybe the crash could be re-produced that way.

If you don't have any better ideas, Kenneth, then I'll write a small GL program that reads in these three shaders and attempts to link them. It will take me a couple of days to find time for that though.

Thanks for your help!
Comment 4 bugReporter92 2016-04-28 02:52:09 UTC
Created attachment 123312 [details]
Shaders that linked together cause the crash
Comment 5 Kenneth Graunke 2016-04-28 03:02:03 UTC
Thanks!  I can reproduce the problem now.
Comment 6 Kenneth Graunke 2016-04-28 04:13:35 UTC
Created attachment 123314 [details] [review]
Patch #1
Comment 7 Kenneth Graunke 2016-04-28 04:13:56 UTC
Created attachment 123315 [details] [review]
Patch #2
Comment 8 Kenneth Graunke 2016-04-28 04:15:25 UTC
Can you try and apply the two patches I attached (git am 000*) and see if that fixes the assertion?  (It might also fix the misrendering...)
Comment 9 bugReporter92 2016-04-28 11:00:20 UTC
Amazing.

Fixes both the missing compilation and the rendering issues.

This defect can be closed once those are committed. Thank-you very much for your help, Kenneth!
Do you know if this is likely to make stable branch?
Comment 10 Matt Turner 2016-04-28 18:17:35 UTC
(Don't close bugs until the patches are upstream)
Comment 11 bugReporter92 2016-04-29 04:03:46 UTC
Duly noted. Thanks.
Comment 12 Kenneth Graunke 2016-04-29 23:06:26 UTC
Fixed in master with the following commits:

commit 750c38fad1f19e2403b4960674006c5f932075ad
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Wed Apr 27 21:07:07 2016 -0700

    glsl: Lower vector_extracts to swizzles after lower_vector_derefs.

commit 1cd600dbb975cce616da376a680692afb2da47f9
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Wed Apr 27 20:51:36 2016 -0700

    glsl: Convert lower_vec_index_to_swizzle to a rvalue visitor.

Both are CC'd to stable, so they should show up in an upcoming point release.


bug/show.html.tmpl processed on Feb 22, 2017 at 10:43:30.
(provided by the Example extension).