aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/ast_to_hir.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl: When assigning to a whole array, mark the array as accessed.Eric Anholt2011-08-151-10/+11
| | | | | | | | | | | | | The vs-varying-array-mat2-col-row-wr test writes a mat2[3] constant to a mat2[3] varying out array, and also statically accesses element 1 of it on the VS and FS sides. At link time it would get trimmed down to just 2 elements, and then codegen of the VS would end up generating assignments to the unallocated last entry of the array. On the new i965 VS backend, that happened to land on the vertex position. Some issues remain in this test on softpipe, i965/old-vs and i965/new-vs on visual inspection, but i965 is passing because only one green pixel is probed, not the whole split green/red quad.
* glsl: Check array size is const before asserting that no IR was generated.Paul Berry2011-08-081-5/+8
| | | | | | | | | | | | | process_array_type() contains an assertion to verify that no IR instructions are generated while processing the expression that specifies the size of the array. This assertion needs to happen _after_ checking whether the expression is constant. Otherwise we may crash on an illegal shader rather than reporting an error. Fixes piglit tests array-size-non-builtin-function.vert and array-size-with-side-effect.vert. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Emit function signatures at toplevel, even for built-ins.Paul Berry2011-08-081-17/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: empty declarations should be validChia-I Wu2011-08-051-5/+5
| | | | | | | | | | | | | | | 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 <[email protected]> Note: this is a candidate for the 7.11 branch.
* glsl: Reject shaders that contain static recursionIan Romanick2011-07-201-0/+2
| | | | | | | | | | | | | | | | | | | The GLSL 1.20 and later specs say: "Recursion is not allowed, not even statically. Static recursion is present if the static function call graph of the program contains cycles." Recursion is detected and rejected both a compile-time and at link-time. The complie-time check happens to detect some cases that may be removed by various optimization passes. The spec doesn't seem to allow this, but other vendors (e.g., NVIDIA) appear to only check at link-time after all optimizations. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=33885 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Ensure that sampler declarations are always uniform or "in" parameters.Paul Berry2011-07-181-0/+35
| | | | | | | | | | | | | | | | | | | | | | This brings us into compliance with page 17 (page 22 of the PDF) of the GLSL 1.20 spec: "[Sampler types] can only be declared as function parameters or uniform variables (see Section 4.3.5 "Uniform"). ... [Samplers] cannot be used as out or inout function parameters." The spec isn't explicit about whether this rule applies to structs/arrays containing shaders, but the intent seems to be to ensure that it can always be determined at compile time which sampler is being used in each texture lookup. So to avoid creating a loophole, the rule needs to apply to structs/arrays containing shaders as well. Fixes piglit tests spec/glsl-1.10/compiler/samplers/*.frag, and fixes bug 38987. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38987 Reviewed-by: Ian Romanick <[email protected]>
* glsl: Distinguish "type mismatch" error messages for modulus operator.Kenneth Graunke2011-06-291-3/+11
| | | | | | | | | | | | | Previously, it would simply say "type error" in three different cases: - The LHS is not an integer - The RHS is not an integer - The LHS and RHS have different base types (int vs. uint) Now the error messages state the specific problem. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: permit explicit locations on fragment shader outputs, not inputsPaul Berry2011-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | From the OpenGL docs for GL_ARB_explicit_attrib_location: This extension provides a method to pre-assign attribute locations to named vertex shader inputs and color numbers to named fragment shader outputs. This was accidentally implemented for fragment shader inputs. This patch fixes it to apply to fragment shader outputs. Fixes piglit tests spec/ARB_explicit_attrib_location/1.{10,20}/compiler/layout-{01,03,06,07,08,09,10}.frag Reviewed-by: Ian Romanick <[email protected]> NOTE: This is a candidate for the 7.10 and 7.11 branches. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38624
* glsl/ast_to_hir: Only use the local 'type' variable as a temporary.Kenneth Graunke2011-04-201-20/+4
| | | | | | | | | Lots of code (deleted by this patch) tried to make type == result->type, but not all cases did. Don't pretend; just use result->type. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Emit a warning when the left-hand operand of a comma has no effectIan Romanick2011-04-181-1/+35
| | | | | | | | | | | | | | | | | The expression x = y, 5, 3; will generate 0:7(9): warning: left-hand operand of comma expression has no effect The warning is only emitted for the left-hand operands, becuase the right-most operand is the result of the expression. This could be used in an assignment, etc. Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Perform type checking on "^^" operands.Eric Anholt2011-04-131-3/+10
| | | | | | | | | | | We were letting any old operand through, which generally resulted in assertion failures later. Fixes array-logical-xor.vert. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: When we've emitted a semantic error for ==, return a bool constant.Eric Anholt2011-04-131-3/+7
| | | | | | | | | | | This prevents later errors (including an assertion failure) from cascading the failure. Fixes invalid-equality-04.vert. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=33303 Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Chad Versace <[email protected]>
* glsl: Semantically check the RHS of `||' even when short-circuiting.Eric Anholt2011-04-131-6/+5
| | | | | | | | | | | We just do the AST-to-HIR processing, and only push the instructions if needed in the constant false case. Fixes glslparsertest/glsl2/logic-02.frag Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Semantically check the RHS of `&&' even when short-circuiting.Eric Anholt2011-04-131-6/+6
| | | | | | | | | | | We just do the AST-to-HIR processing, and only push the instructions if needed in the constant true case. Fixes glslparsertest/glsl2/logic-01.frag Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Avoid cascading errors when looking for a scalar boolean and failing.Eric Anholt2011-04-131-76/+48
| | | | | | | | | | | | | | | By always using a boolean, we should generally avoid further complaints. The failure case I see is logic_not, where the user might understandably make the mistake of using `!' on a boolean vector (like a piglit case did recently!), and then get a further complaint that the new boolean type doesn't match the bvec it gets assigned to. Fixes invalid-logic-not-06.vert (assertion failure when the bad type ends up in an expression and ir_constant_expression gets angry). Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=33314 Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Accept precision qualifiers on sampler types, but only in ES.Kenneth Graunke2011-03-261-2/+9
| | | | | | | | | | GLSL 1.30 states clearly that only float and int are allowed, while the GLSL ES specification's issues section states that sampler types may take precision qualifiers. Fixes compilation failures in 3DMarkMobileES 2.0 and GLBenchmark 2.0. NOTE: This is a candidate for stable release branches.
* glsl: Fix off-by-one error setting max_array_access for non-constant indexingIan Romanick2011-03-251-1/+1
| | | | NOTE: This is a candidate for the stable branches.
* glsl: Only allow unsized array assignment in an initializerIan Romanick2011-03-151-14/+17
| | | | | | | | | | | It should have been a tip when the spec says "However, implicitly sized arrays cannot be assigned to. Note, this is a rare case that *initializers and assignments appear to have different semantics*." (empahsis mine) Fixes bugzilla #34367. NOTE: This is a candidate for stable release branches.
* glsl: Process redeclarations before initializersIan Romanick2011-03-041-43/+44
| | | | | | | | | | | | If an array redeclaration includes an initializer, the initializer would previously be dropped on the floor. Instead, directly apply the initializer to the correct ir_variable instance and append the generated instructions. Fixes bugzilla #34374 and piglit tests glsl-{vs,fs}-array-redeclaration. NOTE: This is a candidate for stable release branches. 0292ffb8 and 8e6cb9fe are also necessary.
* glsl: Refactor AST-to-HIR code handling variable initializersIan Romanick2011-03-041-108/+125
|
* glsl: Refactor AST-to-HIR code handling variable redeclarationsIan Romanick2011-03-041-113/+133
|
* glsl: Use reralloc instead of plain realloc.Kenneth Graunke2011-02-281-5/+3
| | | | | | Plugs a memory leak when compiling shaders with user defined structures. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Set operators '%' and '%=' to be reserved when GLSL < 1.30Chad Versace2011-02-081-0/+7
| | | | | | | | | | | | | | | | | | | | | | | From section 5.9 of the GLSL 1.20 spec: The operator modulus (%) is reserved for future use. From section 5.8 of the GLSL 1.20 spec: The assignments modulus into (%=), left shift by (<<=), right shift by (>>=), inclusive or into ( |=), and exclusive or into ( ^=). These operators are reserved for future use. The GLSL ES 1.00 spec and GLSL 1.10 spec have similiar language. Fixes bug: https://bugs.freedesktop.org//show_bug.cgi?id=33916 Fixes Piglit tests: spec/glsl-1.00/compiler/arithmetic-operators/modulus-00.frag spec/glsl-1.00/compiler/assignment-operators/modulus-assign-00.frag spec/glsl-1.10/compiler/arithmetic-operators/modulus-00.frag spec/glsl-1.10/compiler/assignment-operators/modulus-assign-00.frag spec/glsl-1.20/compiler/arithmetic-operators/modulus-00.frag spec/glsl-1.20/compiler/assignment-operators/modulus-assign-00.frag
* Convert everything from the talloc API to the ralloc API.Kenneth Graunke2011-01-311-2/+2
|
* glsl: Propagate depth layout qualifier from AST to IRChad Versace2011-01-261-0/+64
|
* glsl: Don't assert when the value returned by a function has no rvalueIan Romanick2011-01-221-13/+12
| | | | | | | | | | | | | | | The rvalue of the returned value can be NULL if the shader says 'return foo();' and foo() is a function that returns void. Existing GLSL specs do *NOT* say that this is an error. The type of the return value is void. If the return type of the function is also void, then this should compile without error. I expect that future versions of the GLSL spec will fix this (wink, wink, nudge, nudge). Fixes piglit test glsl-1.10/compiler/expressions/return-01.vert and bugzilla #33308. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Improve error message when read-only vars are writtenChad Versace2011-01-211-1/+8
| | | | | | Improves the cases when: * an explicit assignment references the read-only variable * an 'out' or 'inout' function parameter references the read-only variable
* glsl: Mark 'in' variables at global scope as read-onlyChad Versace2011-01-211-1/+2
| | | | | | | Fixes Piglit tests: spec/glsl-1.30/compiler/storage-qualifiers/static-write-centroid-in-01.frag spec/glsl-1.30/compiler/storage-qualifiers/static-write-in-01.frag spec/glsl-1.30/compiler/storage-qualifiers/static-write-in-02.frag
* glsl: Fix segfault due to missing printf argumentChad Versace2011-01-181-1/+2
| | | | | | | | Fixes the following Piglit tests: glslparsertest/shaders/array2.frag glslparsertest/shaders/dataType6.frag NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Fix semantic checks on precision qualifiersChad Versace2011-01-181-9/+8
| | | | | | The check for Precision qualifiers only apply to floating point and integer types. was incomplete. It rejected only type 'bool' and structures.
* glsl: Add support for default precision statementsChad Versace2011-01-171-0/+52
| | | | | | * Add new field ast_type_specifier::is_precision_statement. * Add semantic checks in ast_type_specifier::hir(). * Alter parser rules accordingly.
* glsl: Add semantic checks for precision qualifiersChad Versace2011-01-171-0/+33
| | | | | | | | | | | * Check that precision qualifiers only appear in language versions 1.00, 1.30, and later. * Check that precision qualifiers do not apply to bools and structs. Fixes the following Piglit tests: * spec/glsl-1.30/precision-qualifiers/precision-bool-01.frag * spec/glsl-1.30/precision-qualifiers/precision-struct-01.frag * spec/glsl-1.30/precision-qualifiers/precision-struct-02.frag
* glsl: Check that 'centroid in' does not occur in vertex shaderChad Versace2011-01-171-0/+13
| | | | | | | | | | The check is performed only in GLSL versions >= 1.30. From section 4.3.4 of the GLSL 1.30 spec: "It is an error to use centroid in in a vertex shader." Fixes Piglit test spec/glsl-1.30/compiler/storage-qualifiers/vs-centroid-in-01.vert
* glsl: Check that interpolation quals only apply to vertex ins and fragment outsChad Versace2011-01-171-0/+35
| | | | | | | | The check is performed only in GLSL versions >= 1.30. Fixes the following Piglit tests: * spec/glsl-1.30/compiler/interpolation-qualifiers/fs-smooth-02.frag * spec/glsl-1.30/compiler/interpolation-qualifiers/vs-smooth-01.vert
* glsl: Check that interpolation qualifiers do not precede 'varying'Chad Versace2011-01-171-0/+26
| | | | | | | | | | | | | ... and 'centroid varying'. The check is performed only in GLSL versions >= 1.30. From page 29 (page 35 of the PDF) of the GLSL 1.30 spec: "interpolation qualifiers may only precede the qualifiers in, centroid in, out, or centroid out in a declaration. They do not apply to the deprecated storage qualifiers varying or centroid varying." Fixes Piglit test spec/glsl-1.30/compiler/interpolation-qualifiers/smooth-varying-01.frag.
* glsl: Emit errors or warnings when 'layout' is used with 'attribute' or ↵Ian Romanick2011-01-131-0/+46
| | | | | | | | | | | | | | | | | | 'varying' The specs that add 'layout' require the use of 'in' or 'out'. However, a number of implementations, including Mesa, shipped several of these extensions allowing the use of 'varying' and 'attribute'. For these extensions only a warning is emitted. This differs from the behavior of Mesa 7.10. Mesa 7.10 would only accept 'attribute' with 'layout(location)'. This behavior was clearly wrong. Rather than carrying the broken behavior forward, we're just doing the correct thing. This is related to (piglit) bugzilla #31804. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Allow 'in' and 'out' when 'layout' is also availableIan Romanick2011-01-131-2/+5
| | | | | | | | | All of the extensions that add the 'layout' keyword also enable (and required) the use of 'in' and 'out' with shader globals. This is related to (piglit) bugzilla #31804. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Track variable usage, use that to enforce semanticsIan Romanick2011-01-121-2/+16
| | | | | | | | | In particular, variables cannot be redeclared invariant after being used. Fixes piglit test invariant-05.vert and bugzilla #29164. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Disallow 'in' and 'out' on globals in GLSL 1.20Ian Romanick2011-01-101-5/+5
| | | | | | | | Fixes piglit tests glsl-1.20/compiler/qualifiers/in-01.vert and glsl-1.20/compiler/qualifiers/out-01.vert and bugzilla #32910. NOTE: This is a candidate for the 7.9 and 7.10 branches. This patch also depends on the previous two commits.
* glsl: Support the 'invariant(all)' pragmaIan Romanick2011-01-061-0/+17
| | | | | | | | | | | | | 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: Allow less restrictive uses of sampler array indexing in GLSL <= 1.20Ian Romanick2011-01-061-4/+24
| | | | | | | | | | | | | | | | | | GLSL 1.10 and 1.20 allow any sort of sampler array indexing. Restrictions were added in GLSL 1.30. Commit f0f2ec4d added support for the 1.30 restrictions, but it broke some valid 1.10/1.20 shaders. This changes the error to a warning in GLSL 1.10, GLSL 1.20, and GLSL ES 1.00. There are some spurious whitespace changes in this commit. I changed the layout (and wording) of the error message so that all three cases would be similar. The 1.10/1.20 and 1.30 text is the same. The only difference is that one is an error, and the other is a warning. The GLSL ES 1.00 wording is similar but not quite the same. Fixes piglit test spec/glsl-1.10/compiler/constant-expressions/sampler-array-index-02.frag and bugzilla #32374.
* glsl: Check that integer vertex outputs are qualified with flatChad Versace2011-01-041-0/+19
| | | | | | | | | | Perform this check in ast_declarator_list::hir(). From section 4.3.6 of the GLSL 1.30 spec: "If a vertex output is a signed or unsigned integer or integer vector, then it must be qualified with the interpolation qualifier flat."
* glsl: Allow redeclaration of gl_Color and its variants in GLSL 1.30Chad Versace2011-01-041-0/+21
| | | | | | | | | | | | | Allow redeclaration of the following built-in variables with an interpolation qualifier in language versions >= 1.30: * gl_FrontColor * gl_BackColor * gl_FrontSecondaryColor * gl_BackSecondaryColor * gl_Color * gl_SecondaryColor See section 4.3.7 of the GLSL 1.30 spec.
* glsl: Remove unused "instructions" parameter.Kenneth Graunke2011-01-011-1/+1
| | | | | | I think was used long ago, when we actually read the builtins into the shader's instruction stream directly, rather than creating a separate shader and linking the two. It doesn't seem to serve any purpose now.
* glsl: Inherrit type of declared variable from initializer after processing ↵Ian Romanick2010-12-101-8/+17
| | | | | | | | | | | assignment do_assignment may apply implicit conversions to coerce the base type of initializer to the base type of the variable being declared. Fixes piglit test glsl-implicit-conversion-02 (bugzilla #32287). This probably also fixes bugzilla #32273. NOTE: This is a candidate for the 7.9 branch and the 7.10 branch.
* glsl: Minor clean-up in validate_assignmentIan Romanick2010-12-101-6/+3
| | | | | This code has been changed around a lot, and there were some temporary variables left around from previous versions.
* glsl: In ast_to_hir, check sampler array indexingChad Versace2010-12-081-0/+14
| | | | | | | | | Raise error if a sampler array is indexed with a non-constant expression. From section 4.1.7 of the GLSL 1.30 spec: "Samplers aggregated into arrays within a shader (using square brackets [ ]) can only be indexed with integral constant expressions [...]."
* glsl: Inherrit type of declared variable from initializerIan Romanick2010-12-071-0/+18
| | | | | | | | | | | | | Types of declared variables and their initializer must match excatly except for unsized arrays. Previously the type inherritance for unsized arrays happened implicitly in the emitted assignment. However, this assignment is never emitted for uniforms. Now that type is explicitly copied unconditionally. Fixes piglit test array-compare-04.vert (bugzilla #32035) and glsl-array-uniform-length (bugzilla #31985). NOTE: This is a candidate for the 7.9 branch.
* glsl: Ensure that equality comparisons don't return a NULL IR treeIan Romanick2010-12-071-16/+19
| | | | | | | This fixes bugzilla #32035 and piglit test case array-compare-01 and array-compare-02. NOTE: This is a candidate for the 7.9 branch.
* glsl: Factor out code which emits a new function into the IR stream.Kenneth Graunke2010-12-061-18/+22
| | | | A future commit will use the newly created function in a second place.