Commit Graph

45 Commits

Author SHA1 Message Date
Ian Romanick a39a70c8d4 glsl: Parse interface array size
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-25 09:07:33 -05:00
Kenneth Graunke 34f966bdcb glsl: Parse non-array uniform block instance names in GLSL ES 3.00.
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-25 09:07:33 -05:00
Kenneth Graunke 0d2e6336a2 glsl: Refactor uniform block parser rules.
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-25 09:07:33 -05:00
Ian Romanick ed3f237e09 glsl: Don't add structure fields to the symbol table
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>
2013-01-08 13:09:31 -08:00
Kenneth Graunke 76f13f80e6 glsl: Add missing semicolon in the grammar
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-06 12:13:22 -08:00
Ian Romanick 62c0938639 glsl: Allow layout qualifiers in GLSL 3.00 ES
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-06 12:13:22 -08:00
Paul Berry 2b4aeddfb3 glsl/parser: Handle "#version 300 es" directive.
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-06 12:13:22 -08:00
Paul Berry 629b9edc99 glsl/parser: Extract version directive processing into a function.
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-06 12:13:21 -08:00
Paul Berry 534ec62152 glsl: parse GLSL ES 3.00 keywords correctly.
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-06 12:13:21 -08:00
Paul Berry 0d9bba6e43 glsl: Make use of new _mesa_glsl_parse_state::check_version() function.
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-06 12:13:21 -08:00
Paul Berry e3ded7fe62 glsl: Make use of new _mesa_glsl_parse_state::is_version() function.
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-06 12:13:21 -08:00
Paul Berry dc9f9d8e66 glsl: Compute version_string on the fly.
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-06 12:13:21 -08:00
Paul Berry d9bfaa104e glsl: Make a function to express a GLSL version ir human-readable form.
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-12-06 12:13:21 -08:00
Kenneth Graunke 9bc9895c4a glsl: Support unsigned integer constants in layout qualifiers.
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-26 21:02:45 -08:00
Dave Airlie 4c8750015b glsl: add ARB_texture_cube_map_array support (v2)
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-11-09 10:26:33 +10:00
Eric Anholt 803262a5f5 glsl: Refuse to parse uniform block declarations when UBOs aren't available.
Fixes piglit
GL_ARB_uniform_buffer_object/compiler/extension-disabled-block.frag

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-08-07 13:54:51 -07:00
Eric Anholt 551bdf25bc glsl: Add support for default layout qualifiers for uniforms.
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-31 12:06:20 -07:00
Eric Anholt 7b77c64254 glsl: Merge UBO layout qualifiers in a qualifier list.
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-31 12:06:20 -07:00
Eric Anholt fafa394c15 glsl: Incorporate all UBO language changes into GLSL 1.40.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-31 12:06:19 -07:00
Kenneth Graunke 3a90dc22d1 glsl: Refactor #version validation to be more future-proof.
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-31 11:20:49 -07:00
Kenneth Graunke 03ac5c54b5 glsl: Fix #pragma invariant(all) language version check.
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-31 10:52:54 -07:00
Oliver McFadden e72f20641a glsl: warning: pragma `invariant(all)' not supported in GLSL ES 1.00
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-26 13:09:15 +03:00
Eric Anholt f7561e8ecd glsl: Turn UBO variable declarations into ir_variables and check qualifiers.
Fixes piglit layout-*-non-uniform and layout-*-within-block.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-20 10:43:12 -07:00
Eric Anholt 2d03f48a65 glsl: Add parsing for GLSL uniform blocks.
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-09 11:13:33 -07:00
Eric Anholt 912a429bc5 glsl: Don't hide the type of struct_declaration_list.
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-09 11:12:18 -07:00
Eric Anholt f4fb6bf088 glsl: Reduce a bit of extra code in the merging of layout qualifiers.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-09 11:05:33 -07:00
Eric Anholt 60a784d56e glsl: Take advantage of the layout qualifier flags union to clean up parsing.
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-07-09 11:04:45 -07:00
Eric Anholt 56e2f97697 glsl: Mark [iu]sampler{Buffer,2DRect}as reserved in GLSL 1.40.
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-16 11:28:21 -07:00
Dave Airlie 1256a5dcc8 glsl: add support for ARB_blend_func_extended (v3)
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-13 17:19:01 +01:00
Eric Anholt 6598552521 glsl: Add support for parsing [iu]samplerBuffer types in GLSL 1.40.
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-09 14:34:06 -07:00
Eric Anholt eb7a71dea7 glsl: Drop the round-trip through ast_type_specifier for many builtin types.
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-09 14:30:46 -07:00
Kenneth Graunke b2c0df2b60 glsl: Use (const char *) in AST nodes rather than plain (char *).
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-04-09 14:30:34 -07:00
Eric Anholt ac5a5b3243 glsl: Add support for parsing #version 140.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-03-15 08:33:54 -07:00
Eric Anholt 01a5a2c9d7 glsl: Add other missing error location information for switch statements.
NOTE: This is a candidate for the 8.0 branch.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-02-03 11:06:59 +01:00
Eric Anholt 663dcbbffe glsl: Add missing location info to case labels.
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>
2012-02-03 11:06:57 +01:00
Matt Turner cb96b06130 glsl: rename VERSION to VERSION_TOK for automake
Signed-off-by: Matt Turner <mattst88@gmail.com>
2012-01-04 19:27:56 -08:00
Kenneth Graunke c87cb98bb4 glsl: Fix crashes caused by Bison error messages involving "'%'".
Invalid shaders containing the character % at an unexpected location
would cause Bison to call yyerror with a message of:

    syntax error, unexpected '%'

Bison expects yyerror() to take a string, while _mesa_glsl_error() is a
printf-style function.  This hit the classic printf string escape issue:

    _mesa_glsl_error(loc, state, "unexpected '%'");       // invalid!
    _mesa_glsl_error(loc, state, "%s", "unexpected '%'"); // correct.

This caused assertion failures after ralloc_asprintf_append called
vsnprintf to determine the length of the text that would be printed:
vsnprintf would see the invalid format and return -1, an invalid length.

The solution is to define a proper yyerror() wrapper function that calls
_mesa_glsl_error with the "%s".  Since we compile with -p "_mesa_glsl",
yyerror is defined as:

    #define yyerror         _mesa_glsl_error

So we have to #undef yyerror in order to be able to declare it.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43564
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Paul Berry <stereotype441@gmail.com>
2011-12-13 22:54:16 -08:00
Marek Olšák 6b43d6fdda glsl: finish up ARB_conservative_depth (v2)
v2: updated an error message

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2011-11-22 20:56:50 +01:00
José Fonseca b0cdeda4f2 glsl: Add missing ';' in action statement.
Addresses the warnings:

  warning: a `;' might be needed at the end of action code
  warning: future versions of Bison will not add the `;'
2011-11-14 14:14:45 +00:00
Dan McCabe 85beb39e14 glsl: Reference data structure ctors in grammar
We now tie the grammar to the ctors of the ASTs they reference.

This requires that we actually have definitions of the ctors.

In addition, we also need to define "print" and "hir" methods for the AST
classes. The Print methods are pretty simple to flesh out. However, at this
stage of the development, we simply stub out the "hir" methods and flesh
them out later.

Also, since actual class instances get returned by the productions in the
grammar, we also need to designate the type of the productions that
reference those instances.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2011-11-07 16:31:22 -08:00
Dan McCabe 80944599dc glsl: Add productions to GLSL grammar for switch statement
The grammar is modified to support switch statements. Rather than follow the
grammar in the appendix, which allows case labels to be placed ANYWHERE
as a regular statement, we follow the development of the grammar as
described in the body of the GLSL spec.

In this variation, the switch statement has a body which consists of a list
of case statements. A case statement is preceded by a list of case labels and
ends with a list of statements.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2011-11-07 16:31:21 -08:00
Chia-I Wu 2903816aad glsl: add support for GL_OES_EGL_image_external
This extension introduces a new sampler type: samplerExternalOES.
texture2D (and texture2DProj) can be used to do a texture look up in an
external texture.

Reviewed-by: Brian Paul <brianp@vmware.com>
Acked-by: Jakob Bornecrantz <jakob@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2011-11-03 15:09:44 +08:00
Kenneth Graunke b9eb4d8a59 glsl: Implement the GL_ARB_conservative_depth extension.
It's the same as GL_AMD_conservative_depth.  The specs have slight
differences in wording, but don't differ in content or behavior.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2011-08-25 08:07:21 -07:00
Chia-I Wu 547212d963 glsl: empty declarations should be valid
Unlike C++, empty declarations such as

  float;

should be valid.  The spec is not explicit about this actually.

Some apps that generate their shader sources may rely on this.  This was
noted when porting one of them to Linux from Windows.

Reviewed-by: Chad Versace <chad@chad-versace.us>

Note: this is a candidate for the 7.11 branch.
2011-08-05 12:14:24 +09:00
Kenneth Graunke 80ec97af79 glsl: Rename .lpp to .ll and .ypp to .yy.
SCons has built-in support for .ll and .yy, but not .lpp and .ypp. Since
there's no real benefit to using the old names, change them.
2011-03-01 15:49:29 -08:00
Renamed from src/glsl/glsl_parser.ypp (Browse further)