summaryrefslogtreecommitdiff
path: root/src/glsl/glsl_parser.yy
AgeCommit message (Collapse)AuthorFilesLines
2013-07-16glsl: Fix absurd whitespace conventions in the parser.Kenneth Graunke1-1696/+1691
Historically, we indented grammar production rules with a single 8-space tab, but code inside of blocks used Mesa's 3-space indents. This meant when editing code, you had to use an 8-space tab for the first level of indentation, and 3-spaces after that. Unless you specifically configure your editor to understand this, it will get the indentation wrong on every single line you touch, which quickly devolves into a colossal waste of time. It's also inconsistent with every other file in the entire project. This patch removes all tabs and moves to a consistent 3-space indent. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2013-07-16glsl: Fail the build if the grammar contains shift/reduce errors.Kenneth Graunke1-0/+2
When working on a parser, it's very easy to accidentally introduce new shift/reduce conflicts. Failing the build guarantees they'll be noticed and fixed. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2013-07-16glsl: Silence the last shift/reduce conflict warning in the grammar.Kenneth Graunke1-1/+3
The single remaining shift/reduce conflict was the classic ELSE problem: 292 selection_rest_statement: statement . ELSE statement 293 | statement . ELSE shift, and go to state 479 ELSE [reduce using rule 293 (selection_rest_statement)] $default reduce using rule 293 (selection_rest_statement) The correct behavior here is to shift, which is what happens by default. However, resolving it explicitly will make it possible to fail the build on new errors, making them much easier to detect. The classic way to solve this is to use right associativity: http://www.gnu.org/software/bison/manual/html_node/Non-Operators.html Since there is no THEN token in GLSL, we need to fake one. %right THEN creates a new terminal symbol; the %prec directive says to use the precedence of that terminal. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2013-07-11glsl: Add support for C-style initializers.Matt Turner1-0/+51
Required by GL_ARB_shading_language_420pack. Parts based on work done by Todd Previte and Ken Graunke, implementing basic support for C-style initializers of arrays. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-07-11glsl: Add comment explaining "row_major" parsing.Matt Turner1-0/+6
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-07-11glsl: Remove outdated FINISHME comment.Matt Turner1-3/+0
Explicit index support was added by commit 1256a5dc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-06-10glsl: Bail on parsing if the #version directive is bogus.Kenneth Graunke1-0/+6
If we didn't successfully parse the #version line, there's no point in continuing with parsing and compiling: it's already failed. Furthermore, it can actually be harmful: right after handling #version, we call _mesa_glsl_initialize_types(), which checks state->es_shader and language_version. If it isn't valid, it hits an assertion failure. Fixes Piglit's "invalid-version-es." When processing "#version 110 es", our code set state->es_shader and state->language_version = 110. It then properly determined that this was invalid and flagged an error. Since we continued anyway, we hit the assertion mentioned above. NOTE: This is a candidate for the 9.1 branch. Reviewed-by: Matt Turner <mattst88@gmail.com> Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl parser: allow in & out for interface block membersJordan Justen1-25/+12
Previously uniform blocks allowed for the 'uniform' keyword to be used with members of a uniform blocks. With interface blocks 'in' can be used on 'in' interface block members and 'out' can be used on 'out' interface block members. The basic_interface_block rule will verify that the same qualifier type is used with the block and each member. Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl parser: handle interface block member qualifierJordan Justen1-1/+43
An interface block member may specify the type: in { in vec4 in_var_with_qualifier; }; When specified with the member, it must match the same type as interface block type. It can also omit the qualifier: uniform { vec4 uniform_var_without_qualifier; }; When the type is not specified with the member, it will adopt the same type as the interface block. Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl parser: on desktop GL require GLSL 150 for instance namesJordan Justen1-5/+3
Interface blocks in GLSL 150 allow an instance name to be used. v2: * use state->check_version Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl parser: reject VS+in & FS+out interface blocksJordan Justen1-0/+14
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl: parse in/out types for interface blocksJordan Justen1-11/+40
Previously only 'uniform' was allowed for uniform blocks. Now, in/out can be parsed, but it will only be allowed for GLSL >= 150. Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl parser: rename uniform block to interface blockJordan Justen1-12/+12
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-23glsl: rename ast_uniform_block to ast_interface_blockJordan Justen1-7/+7
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-03-02glsl: add support for ARB_texture_multisampleChris Forbes1-2/+9
V2: - emit `sample` parameter properly for multisample texelFetch() - fix spurious whitespace change - introduce a new opcode ir_txf_ms rather than overloading the existing ir_txf further. This makes doing the right thing in the driver somewhat simpler. V3: - fix weird whitespace V4: - don't forget to include the new opcode in tex_opcode_strs[] (thanks Kenneth for spotting this) Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> [V2] Reviewed-by: Eric Anholt <eric@anholt.net> [V2] Reviewed-by: Paul Berry <stereotype441@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-01-25glsl: Parse interface array sizeIan Romanick1-12/+43
The size is parsed and stored in the AST, but it is not used yet. Processing of the array size is added in the patch "glsl: Handle instance array declarations" v2: Update the commit message (suggested by Carl Worth). Add a comment to ast_uniform_block::array_size (suggested by Paul Berry). Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-25glsl: Parse non-array uniform block instance names in GLSL ES 3.00.Kenneth Graunke1-2/+18
In GLSL ES 3.00 (and GLSL 1.50), uniform blocks can have an associated "instance name", which essentially namespaces the variables inside. This patch adds basic parsing for this new feature, but doesn't yet hook it up to actually do anything yet. It does not support for arrays of interface blocks; a later commit will take care of that. This change temporarily regresses the piglit test interface-name-access-without-interface-name.vert. This shader failed to compile before (the expected result), but it failed to compile for the wrong reason. This is not a real regression. v2: Add some comments to ast_uniform_block::instance_name. Suggested by Paul Berry. Reviewed-by: Carl Worth <cworth@cworth.org> Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-25glsl: Refactor uniform block parser rules.Kenneth Graunke1-21/+16
The existing code has a lot of duplication; the only difference between the two cases is whether we merge in an additional layout qualifier. Apparently creating a layout_qualifieropt rule that can be empty causes a lot of conflicts and confusion. However, refactoring out the guts of the ast_uniform_block creation works fine. Reviewed-by: Carl Worth <cworth@cworth.org> Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-08glsl: Don't add structure fields to the symbol tableIan Romanick1-1/+0
I erroneously added this back in January 2011 in commit 88421589. Looking at the commit message, I have no idea why I added it. It only added non-array structure fields to the symbol table, so array structure fields are treated correctly. Fixes piglit tests structure-and-field-have-same-name.vert and structure-and-field-have-same-name-nested.vert. It should also fix WebGL conformance tests shader-with-non-reserved-words. NOTE: This is a candidate for the stable release branches. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=57622 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-12-06glsl: Add missing semicolon in the grammarKenneth Graunke1-0/+1
This may not be strictly necessary, but every other rule in the grammar ends with a semicolon. It also appears that this was supposed to be commited with the original patch that changed this rule, but the wrong version of the patch was accidentally pushed. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-12-06glsl: Allow layout qualifiers in GLSL 3.00 ESIan Romanick1-0/+2
Note that while 'packed' is a reserved word in GLSL ES, row_major is not. This means that we have to use the string-based matching for that. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl/parser: Handle "#version 300 es" directive.Paul Berry1-1/+5
Note that GLSL 1.00 is selected using "#version 100", so "#version 100 es" is prohibited. v2: Check for GLES3 before allowing '#version 300 es' v3: Make sure a correct language_version is set in _mesa_glsl_parse_state::process_version_directive. Signed-off-by: Paul Berry <stereotype441@gmail.com> Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl/parser: Extract version directive processing into a function.Paul Berry1-42/+1
Version directive handling is going to have to be used within two parser rules, one for desktop-style version directives (e.g. "#version 130") and one for the new ES-style version directive (e.g. "#version 300 es"), so this patch moves it to a function that can be called from both rules. No functional change. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl: parse GLSL ES 3.00 keywords correctly.Paul Berry1-0/+3
GLSL ES 3.00 adds the following keywords over GLSL 1.00: uint, uvec[2-4], matNxM, centroid, flat, smooth, various samplers, layout, switch, default, and case. Additionally, it reserves a large number of keywords, some of which were already reserved in versions of desktop GL that Mesa supports, some of which are new to Mesa. A few of the reserved keywords in GLSL ES 3.00 are keywords that are supported in all other versions of GLSL: attribute, varying, sampler1D, sampler1DShador, sampler2DRect, and sampler2DRectShadow. This patch updates the lexer to handle all of the new keywords correctly when the language being parsed is GLSL 3.00 ES. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl: Make use of new _mesa_glsl_parse_state::check_version() function.Paul Berry1-18/+3
Previous to this patch, we were not very consistent about the errors we generate when a shader tried to use a feature that is prohibited in the current GLSL version. Some error messages failed to mention the GLSL version currently in use (or did so inaccurately), and some error messages failed to mention the first GLSL version in which the given feature is allowed. This patch reworks all of the error checks to use the check_version() function, which produces error messages in a standard form (approximately "$FEATURE forbidden in $CURRENT_GLSL_VERSION ($REQUIRED_GLSL_VERSION required)."). Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl: Make use of new _mesa_glsl_parse_state::is_version() function.Paul Berry1-2/+3
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl: Compute version_string on the fly.Paul Berry1-8/+5
Fixes a bug where version_string would be left uninitialized if no GLSL "#version" directive was used. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl: Make a function to express a GLSL version ir human-readable form.Paul Berry1-4/+2
This will be useful in generating more helpful error messages, especially with the addition of GLSL 3.00 ES support. [v2, idr]: Rename ctx parameter to mem_ctx Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-11-26glsl: Support unsigned integer constants in layout qualifiers.Kenneth Graunke1-1/+6
Fixes es3conform's explicit_attrib_location_integer_constants. Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-and-tested-by: Matt Turner <mattst88@gmail.com>
2012-11-09glsl: add ARB_texture_cube_map_array support (v2)Dave Airlie1-3/+9
This adds all the new builtins + the new sampler types, and hooks them up if the extension is supported. v2: fix missing signatures for grad/lod fix missing textureSize clarifications fix compare vs starts with usage Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-08-07glsl: Refuse to parse uniform block declarations when UBOs aren't available.Eric Anholt1-0/+20
Fixes piglit GL_ARB_uniform_buffer_object/compiler/extension-disabled-block.frag Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-07-31glsl: Add support for default layout qualifiers for uniforms.Eric Anholt1-38/+20
I ended up having to add rallocing of the ast_type_qualifier in order to avoid pulling in ast.h for glsl_parser_extras.h, because I wanted to track an ast_type_qualifier in the state. Fixes piglit ARB_uniform_buffer_object/row-major. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-31glsl: Merge UBO layout qualifiers in a qualifier list.Eric Anholt1-1/+23
Yes, you get to say things like "layout(row_major, column_major)" and get column major. Part of fixing piglit ARB_uniform_buffer_object/row_major. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-31glsl: Incorporate all UBO language changes into GLSL 1.40.Eric Anholt1-0/+4
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-31glsl: Refactor #version validation to be more future-proof.Kenneth Graunke1-8/+15
The previous implementation required a flag in _mesa_glsl_parse_state and line of code to initialize it for every version of the shading language we intend to support. As we look to add 150, 330, 400, 410, 420, and beyond, this gets rather unwieldy. This patch retains the switch statement (to reject, say, #version 111), but removes all the bits. Code to check for ctx->API == API_OPENGL_CORE could easily be added to the 110 and 120 cases to reject those. v2: Use _mesa_is_desktop_gl to preserve the existing behavior in the presence of the new API_OPENGL_CORE enumeration. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> [v1]
2012-07-31glsl: Fix #pragma invariant(all) language version check.Kenneth Graunke1-1/+1
It was using state->Const.GLSL_100ES, which is set if the driver supports ARB_ES2_compatibility or we're in ES2 mode. Instead, it should use state->language_version, as that represents the actual GLSL version of the shader being compiled. Since the correct logic is < 120 && !100, just make it == 110. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-26glsl: warning: pragma `invariant(all)' not supported in GLSL ES 1.00Oliver McFadden1-1/+1
The OpenGL(R) ES Shading Language Version 1.00 Revision 17 (12 May, 2009) > 4.6.1 The Invariant Qualifier > ... To force all output variables to be invariant, use the pragma > #pragma STDGL invariant(all) Signed-off-by: Oliver McFadden <oliver.mcfadden@linux.intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2012-07-20glsl: Turn UBO variable declarations into ir_variables and check qualifiers.Eric Anholt1-0/+2
Fixes piglit layout-*-non-uniform and layout-*-within-block. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-09glsl: Add parsing for GLSL uniform blocks.Eric Anholt1-0/+122
This doesn't do anything with the uniform block declarations yet, so usage of those uniforms finds them to be undeclared. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-09glsl: Don't hide the type of struct_declaration_list.Eric Anholt1-3/+3
I've been trying to derive from this for UBO support, and the slightly obfuscated types were putting me over the edge. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-09glsl: Reduce a bit of extra code in the merging of layout qualifiers.Eric Anholt1-7/+2
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-09glsl: Take advantage of the layout qualifier flags union to clean up parsing.Eric Anholt1-21/+7
The got_one variable was set iff one of the bits in flags.i was set. v2: Fix incorrect dropping of the ARB_conservative_depth warning. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1) Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-04-16glsl: Mark [iu]sampler{Buffer,2DRect}as reserved in GLSL 1.40.Eric Anholt1-2/+8
The non-integer versions were already reserved in 1.30, but apparently these were forgotten. Fixes piglit glsl-1.40/compiler/reserved/ Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-04-13glsl: add support for ARB_blend_func_extended (v3)Dave Airlie1-0/+20
This adds index support to the GLSL compiler. I'm not 100% sure of my approach here, esp without how output ordering happens wrt location, index pairs, in the "mark" function. Since current hw doesn't ever have a location > 0 with an index > 0, we don't have to work out if the output ordering the hw requires is location, index, location, index or location, location, index, index. But we have no hw to know, so punt on it for now. v2: index requires layout - catch and error setup explicit index properly. v3: drop idx_offset stuff, assume index follow location Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-04-09glsl: Add support for parsing [iu]samplerBuffer types in GLSL 1.40.Eric Anholt1-0/+1
The samplerBuffer type will be undefined in !glsl 1.40, and the keyword is marked as reserved. The [iu]samplerBuffer types are not marked as reserved pre-1.40, so they don't have separate tokens and fall through to normal type handling. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-04-09glsl: Drop the round-trip through ast_type_specifier for many builtin types.Eric Anholt1-53/+53
We have lexer recognition of a bunch of our types based on the handling. This code was mapping those recognized tokens to an enum and then to a string of their name. Just drop the enums and provide the string directly in the parser. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-04-09glsl: Use (const char *) in AST nodes rather than plain (char *).Kenneth Graunke1-1/+1
Nothing actually relied on them being mutable, and there was at least one cast which discarded const qualifiers. The next patch would have introduced many more. Casting away const qualifiers should be avoided if at all possible. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-15glsl: Add support for parsing #version 140.Eric Anholt1-0/+3
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-02-03glsl: Add other missing error location information for switch statements.Eric Anholt1-0/+4
NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-02-03glsl: Add missing location info to case labels.Eric Anholt1-0/+2
Otherwise, the upcoming error messages said the location was 0:0(0). NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>