Bug 89415 - Mesa incorrectly thinks #extension directive is in the middle of a shader
Summary: Mesa incorrectly thinks #extension directive is in the middle of a shader
Status: RESOLVED NOTABUG
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: All Linux (All)
: medium normal
Assignee: Ian Romanick
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-03 20:27 UTC by Matias N. Goldberg
Modified: 2015-03-04 23:17 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Vertex and Pixel shaders that fail compilation (1.40 KB, text/plain)
2015-03-03 20:27 UTC, Matias N. Goldberg
Details
VERTEX SHADER (2.86 KB, text/plain)
2015-03-03 22:10 UTC, Matias N. Goldberg
Details
PIXEL SHADER (324 bytes, text/plain)
2015-03-03 22:10 UTC, Matias N. Goldberg
Details
MESA's IR. (156.71 KB, text/plain)
2015-03-04 00:40 UTC, Matias N. Goldberg
Details

Description Matias N. Goldberg 2015-03-03 20:27:27 UTC
Created attachment 113961 [details]
Vertex and Pixel shaders that fail compilation

Mesa incorrectly determines the #extension keyword is in the middle of a shader, apparently because there are two blank spaces (or may be because of the #version keyword).

From the GLSL specs:
Each extension can define its allowed granularity of scope. If nothing is said, the granularity is a shader (that is, a single compilation unit), **and the extension directives must occur before any non-preprocessor tokens**.

Attached is the vertex and pixel shader. Mesa complains the vertex shader has its extension directive declared in the middle of the shader, even though it's not.

The version used was from git 3d4d77a5dc7bc9f60d7845ff1d8d5b23f988232a which is from today.
This shader compiles fine in both NVIDIA and AMD propietary drivers in both Linux and Windows.

Additionally since this is a pedantic issue, I'd suggest on this error Mesa should try to reparse the file again and only leave a warning. Since there's already a patch that enables the extension keyword to be used in the middle of a shader (see http://lists.freedesktop.org/archives/mesa-dev/2014-July/062988.html)

I can be reached for further information if needed.

Cheers
Matias
Comment 1 Ian Romanick 2015-03-03 21:04:42 UTC
Comment on attachment 113961 [details]
Vertex and Pixel shaders that fail compilation

Can you attach just the failing shader? A big glob of 7z (uploaded as text/plain) isn't ideal.
Comment 2 Matias N. Goldberg 2015-03-03 22:10:16 UTC
Created attachment 113967 [details]
VERTEX SHADER
Comment 3 Matias N. Goldberg 2015-03-03 22:10:38 UTC
Created attachment 113968 [details]
PIXEL SHADER
Comment 4 Matt Turner 2015-03-03 23:37:08 UTC
I copied both into a shader_test file that we use in our test suite (I retained the Windows newlines) and it compiles fine here.

Can you capture the output of your application when run with MESA_GLSL=dump and post it here?
Comment 5 Matias N. Goldberg 2015-03-04 00:40:57 UTC
Created attachment 113970 [details]
MESA's IR.

Attaching dump from MESA's IR.

I'm not a MESA expert, but it seems that AllowGLSLExtensionDirectiveMidShader can be toggled at compile time. If that assumption is correct, it could explain why you are not able to reproduce it.
Comment 6 Kenneth Graunke 2015-03-04 03:36:58 UTC
Those two shaders are both legal and compile successfully here, with no special options.  The extension directives are definitely in the correct place, and I don't get any complaints about that.

It must have been a different shader that broke.
Comment 7 Ian Romanick 2015-03-04 05:11:15 UTC
(In reply to Kenneth Graunke from comment #6)
> Those two shaders are both legal and compile successfully here, with no
> special options.  The extension directives are definitely in the correct
> place, and I don't get any complaints about that.
> 
> It must have been a different shader that broke.

Either that or the engine / framework / application inserts some stuff at the top of the shader that the author didn't put there.  The Second Life viewer has that problem.  Getting the output of MESA_GLSL=error should help sort that out.

I'm not sure why the output in attachment #113970 [details] has the GLSL IR but not the original GLSL code.  That's... weird.
Comment 8 Matias N. Goldberg 2015-03-04 23:16:29 UTC
Oh my!!! You're correct.

There's a vestige of old C++ code that would prepend additional GLSL code to the vertex shader at the last possible second.

Fixed on our end.

Thank you a lot!
And apologies for taking your valuable time on this.

I'm closing this report. It's not a Mesa bug.


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.