aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/glsl_parser_extras.h
Commit message (Collapse)AuthorAgeFilesLines
...
* glsl/parser: Handle "#version 300 es" directive.Paul Berry2012-12-061-1/+2
| | | | | | | | | | | | | | | 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 <[email protected]> Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl/parser: Extract version directive processing into a function.Paul Berry2012-12-061-0/+2
| | | | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl: Enable GLSL ES 3.00 features inherited from desktop GLSL.Paul Berry2012-12-061-1/+1
| | | | | | | | | | | | | | | | | | | | This patch turns on the following features for GLSL ES 3.00: - Array constructors, whole array assignment, and array comparisons. - Second and third operands of ?: may be arrays. - Use of "in" and "out" qualifiers on globals. - Bitwise and modulus operators. - Integral vertex shader inputs. - Range-checking of literal integers. - array.length method. - Function calls may be constant expressions. - Integral varyings must be qualified with "flat". - Interpolation and centroid qualifiers may not be applied to vertex shader inputs. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl: Make use of new _mesa_glsl_parse_state::check_version() function.Paul Berry2012-12-061-0/+11
| | | | | | | | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl: Add GLSL version query functions.Paul Berry2012-12-061-10/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | With the advent of GLSL 3.00 ES, the version checks we perform in the GLSL compiler (to determine which language features are present) will become more complicated. To reduce the complexity, this patch adds functions check_version() and is_version() to _mesa_glsl_parse_state. These functions take two version numbers: a desktop GLSL version and a GLSL ES version, and return a boolean indicating whether the GLSL version being compiled is at least the required version. So, for example, is_version(130, 300) returns true if the GLSL version being compiled is at least desktop GLSL 1.30 or GLSL 3.00. The check_version() function additionally produces an error message if the version check fails, informing the user of which GLSL version(s) support the given feature. [v2, idr]: Add PRINTFLIKE annotation to the new method. The numbering of th parameters is correct because GCC is silly. [v3, idr]: Fix copy-and-paste error in the comment before _mesa_glsl_parse_state::is_version. Noticed by Ken. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl: Compute version_string on the fly.Paul Berry2012-12-061-1/+10
| | | | | | | | Fixes a bug where version_string would be left uninitialized if no GLSL "#version" directive was used. Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl: Make a function to express a GLSL version ir human-readable form.Paul Berry2012-12-061-0/+3
| | | | | | | | | | | 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 <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
* glsl: add ARB_texture_cube_map_array support (v2)Dave Airlie2012-11-091-0/+2
| | | | | | | | | | | | 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 <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
* mesa/glsl: rename preprocess to glcpp_preprocessDave Airlie2012-09-151-1/+1
| | | | | | | | | | This symbol with dricore escapes into the namespace, its too generic, we should prefix it with something just to be nice. Should be applied to stable + 9.0 Acked-by: Kenneth Graunke <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
* glsl: s/class/struct/ for ast_type_qualifierBrian Paul2012-08-291-1/+1
| | | | | | To silence an MSVC compiler warning about class vs. struct. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add support for OES_standard_derivatives in GLSL ES.Tomeu Vizoso2012-08-011-0/+2
| | | | | | | | | | | Previously, we advertised the extension but the builtin functions were enabled only for GLSL and not for ES. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52003 Signed-off-by: Tomeu Vizoso <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add support for default layout qualifiers for uniforms.Eric Anholt2012-07-311-0/+7
| | | | | | | | | | | 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 <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Refactor #version validation to be more future-proof.Kenneth Graunke2012-07-311-17/+0
| | | | | | | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Eric Anholt <[email protected]> [v1]
* glsl: Translate the AST for uniform blocks into some IR structures.Eric Anholt2012-07-201-0/+4
| | | | | | | | | | We're going to need this structure to cross-validate the uniform blocks between shader stages, since unused ir_variables might get dropped. It's also the place we store the RowMajor qualifier, which is not part of the GLSL type (since that would cause a bunch of type equality checks to fail). Reviewed-by: Ian Romanick <[email protected]>
* glsl: Parser handles "#extension GL_ARB_uniform_buffer_object"Vincent Lejeune2012-07-091-0/+2
| | | | | Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Scaffolding for ARB_shader_bit_encoding.Olivier Galibert2012-06-071-0/+2
| | | | | | | | That adds support for activating the extension. It doesn't actually *do* anything yet, of course. Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: add gl_context memberDylan Noblesmith2012-05-021-1/+2
| | | | Reviewed-by: Brian Paul <[email protected]>
* glsl: Add support for parsing #version 140.Eric Anholt2012-03-151-0/+1
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add error case for switch() with two default cases.Eric Anholt2012-02-031-0/+1
| | | | | | | | Fixes piglit switch-case-duplicated.vert. NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Throw an error when faced with a duplicated switch() case label.Eric Anholt2012-02-031-0/+4
| | | | | | | | | The error message I chose matches gcc's error. Fixes piglit switch-case-duplicated.vert. NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Save and restore the whole switch state for nesting.Eric Anholt2012-02-031-6/+10
| | | | | | | | | This stuffs them all in a struct for sanity. Fixes piglit glsl-1.30/execution/switch/fs-uniform-nested. NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Generate IR for switch statementsDan McCabe2011-11-071-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now modifying the GLSL compiler has been pretty straightforward. This is where things get interesting. But still pretty straightforward. Switch statements can be thought of a series of if/then/else statements. Case labels are compared with the value of a test expression and the case statements are executed if the comparison is true. There are a couple of aspects of switch statements that complicate this simple view of the world. The primary one is that cases can fall through sequentially to subsequent case, unless a break statement is encountered, in which case, the switch statement exits completely. But break handling is further complicated by the fact that a break statement can impact the exit of a loop. Thus, we need to coordinate break processing between switch statements and loop statements. The code generated by a switch statement maintains three temporary state variables: int test_value; bool is_fallthru; bool is_break; test_value is initialized to the value of the test expression at the head of the switch statement. This is the value that case labels are compared against. is_fallthru is used to sequentially fall through to subsequent cases and is initialized to false. When a case label matches the test expression, this state variable is set to true. It will also be forced to false if a break statement has been encountered. This forcing to false on break MUST be after every case test. In practice, we defer that forcing to immediately after the last case comparison prior to executing a case statement, but that is an optimization. is_break is used to indicate that a break statement has been executed and is initialized to false. When a break statement is encountered, it is set to true. This state variable is then used to conditionally force is_fallthru to to false to prevent subsequent case statements from executing. Code generation for break statements depends on whether the break statement is inside a switch statement or inside a loop statement. If it inside a loop statement is inside a break statement, the same code as before gets generated. But if a switch statement is inside a loop statement, code is emitted to set the is_break state to true. Just as ASTs for loop statements are managed in a stack-like manner to handle nesting, we also add a bool to capture the innermost switch or loop condition. Note that we still need to maintain a loop AST stack to properly handle for-loop code generation on a continue statement. Technically, we don't (yet) need a switch AST stack, but I am using one for orthogonality with loop statements, in anticipation of future use. Note that a simple boolean stack would have sufficed. We will illustrate a switch statement with its analogous conditional code that a switch statement corresponds to by examining an example. Consider the following switch statement: switch (42) { case 0: case 1: gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0); case 2: case 3: gl_FragColor = vec4(4.0, 3.0, 2.0, 1.0); break; case 4: default: gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); } Note that case 0 and case 1 fall through to cases 2 and 3 if they occur. Note that case 4 and the default case must be reached explicitly, since cases 2 and 3 break at the end of their case. Finally, note that case 4 and the default case don't break but simply fall through to the end of the switch. For this code, the equivalent code can be expressed as: int test_val = 42; // capture value of test expression bool is_fallthru = false; // prevent initial fall through bool is_break = false; // capture the execution of a break stmt is_fallthru |= (test_val == 0); // enable fallthru on case 0 is_fallthru |= (test_val == 1); // enable fallthru on case 1 is_fallthru &= !is_break; // inhibit fallthru on previous break if (is_fallthru) { gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0); } is_fallthru |= (test_val == 2); // enable fallthru on case 2 is_fallthru |= (test_val == 3); // enable fallthru on case 3 is_fallthru &= !is_break; // inhibit fallthru on previous break if (is_fallthru) { gl_FragColor = vec4(4.0, 3.0, 2.0, 1.0); is_break = true; // inhibit all subsequent fallthru for break } is_fallthru |= (test_val == 4); // enable fallthru on case 4 is_fallthru = true; // enable fallthru for default case is_fallthru &= !is_break; // inhibit fallthru on previous break if (is_fallthru) { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); } The code generate for |= and &= uses the conditional assignment capabilities of the IR. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: add support for GL_OES_EGL_image_externalChia-I Wu2011-11-031-0/+2
| | | | | | | | | | 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 <[email protected]> Acked-by: Jakob Bornecrantz <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Implement the GL_ARB_conservative_depth extension.Kenneth Graunke2011-08-251-0/+2
| | | | | | | 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 <[email protected]>
* glsl: Emit function signatures at toplevel, even for built-ins.Paul Berry2011-08-081-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ast-to-hir conversion needs to emit function signatures in two circumstances: when a function declaration (or definition) is encountered, and when a built-in function is encountered. To avoid emitting a function signature in an illegal place (such as inside a function), emit_function() checked whether we were inside a function definition, and if so, emitted the signature before the function definition. However, this didn't cover the case of emitting function signatures for built-in functions when those built-in functions are called from inside the constant integer expression that specifies the length of a global array. This failed because when processing an array length, we are emitting IR into a dummy exec_list (see process_array_type() in ast_to_hir.cpp). process_array_type() later checks (via an assertion) that no instructions were emitted to the dummy exec_list, based on the reasonable assumption that we shouldn't need to emit instructions to calculate the value of a constant. This patch changes emit_function() so that it emits function signatures at toplevel in all cases. This partially fixes bug 38625 (https://bugs.freedesktop.org/show_bug.cgi?id=38625). The remainder of the fix is in the patch that follows. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Changed extension enable bits to bools.Paul Berry2011-06-281-22/+22
| | | | | | | | | | These were previously 1-bit-wide bitfields. Changing them to bools has a negligible performance impact, and allows them to be accessed by offset as well as by direct structure access. NOTE: This is a candidate for the 7.10 and 7.11 branches. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add compiler support for ARB_shader_texture_lod.Kenneth Graunke2011-05-091-0/+2
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Tested-by: Marek Olšák <[email protected]>
* mesa: implement AMD_shader_stencil_exportMarek Olšák2011-05-031-0/+2
| | | | | | | | It's just an alias of the ARB variant with some GLSL compiler changes. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add void to _mesa_destroy_shader_compiler() argument list.José Fonseca2011-03-251-2/+2
| | | | | At least MSVC sees a distinction between foo() and foo(void) and warns about it.
* glsl: Enable GL_OES_texture_3D extension for ES2.Kenneth Graunke2011-02-281-0/+2
|
* Use C-style system headers in C++ code to avoid issues with std:: namespaceIan Romanick2011-02-211-1/+1
|
* glsl: Reject shader versions not supported by the implementationIan Romanick2011-01-311-0/+26
| | | | | | | | Previously we'd happily compile GLSL 1.30 shaders on any driver. We'd also happily compile GLSL 1.10 and 1.20 shaders in an ES2 context. This has been a long standing FINISHME in the compiler. NOTE: This is a candidate for the 7.9 and 7.10 branches
* Convert everything from the talloc API to the ralloc API.Kenneth Graunke2011-01-311-5/+5
|
* glsl: Add support for AMD_conservative_depth to parserChad Versace2011-01-261-0/+2
| | | | | | | | | | When AMD_conservative_depth is enabled: * Let 'layout' be a token. * Extend the production rule of layout_qualifier_id to process the tokens: depth_any depth_greater depth_less depth_unchanged
* Merge branch 'draw-instanced'Brian Paul2011-01-151-0/+2
|\ | | | | | | | | | | | | | | Conflicts: src/gallium/auxiliary/draw/draw_llvm.c src/gallium/drivers/llvmpipe/lp_state_fs.c src/glsl/ir_set_program_inouts.cpp src/mesa/tnl/t_vb_program.c
| * glsl: add support for system values and GL_ARB_draw_instancedBrian Paul2010-12-081-0/+2
| |
* | glsl: Add version_string containing properly formatted GLSL versionIan Romanick2011-01-101-0/+1
| |
* | glsl: Support the 'invariant(all)' pragmaIan Romanick2011-01-061-0/+7
|/ | | | | | | | | | | | | Previously the 'STDGL invariant(all)' pragma added in GLSL 1.20 was simply ignored by the compiler. This adds support for setting all variable invariant. In GLSL 1.10 and GLSL ES 1.00 the pragma is ignored, per the specs, but a warning is generated. Fixes piglit test glsl-invariant-pragma and bugzilla #31925. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Remove useless ir_shader enumeration value.Kenneth Graunke2010-10-201-2/+1
|
* Drop GLcontext typedef and use struct gl_context insteadKristian Høgsberg2010-10-131-2/+2
|
* glsl: add support for shader stencil exportDave Airlie2010-10-131-0/+2
| | | | | This adds proper support for the GL_ARB_shader_stencil_export extension to the GLSL compiler. Thanks to Ian for pointing out where I need to add things.
* glsl: Add parser support for GL_ARB_explicit_attrib_location layoutsIan Romanick2010-10-081-0/+2
| | | | | Only layout(location=#) is supported. Setting the index requires GLSL 1.30 and GL_ARB_blend_func_extended.
* glsl: Define GL_ES preprocessor macro if API is OpenGL ES 2.0.Kenneth Graunke2010-09-071-1/+1
| | | | Also define it if #version 100 is encountered.
* glsl: Accept language version 100 and make it the default on ES2.Kenneth Graunke2010-09-071-0/+1
|
* glsl2: restructure header file for C++ and C inclusionBrian Paul2010-08-271-8/+28
| | | | As it was, the header could not be cleanly #included by a C source.
* glsl2: Free the shader compiler at dri screen destruction.Eric Anholt2010-08-181-0/+3
| | | | | | Hooray, we can valgrind again without adding suppressions. This also adds an interface for use by an implementation of glReleaseShaderCompiler().
* glsl: Garbage collect old prototype for ir_to_mesa.Eric Anholt2010-08-181-2/+0
|
* glsl2: Parser support for GL_ARB_fragment_coord_conventionsIan Romanick2010-07-281-0/+2
|
* glsl2: When a "continue" happens in a "for" loop, run the loop expression.Eric Anholt2010-07-221-0/+1
| | | | | | | Fixes: glsl1-for-loop with continue Bug #29097
* linker: Link built-in functions instead of including them in every shaderIan Romanick2010-07-211-0/+4
| | | | | | | | This is an invasive set of changes. Each user shader tracks a set of other shaders that contain built-in functions. During compilation, function prototypes are imported from these shaders. During linking, the shaders are linked with these built-in-function shaders just like with any other shader.