summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Demote 'type' from ir_instruction to ir_rvalue and ir_variable.Kenneth Graunke2012-04-025-6/+13
| | | | | | | | | | | | | Variables have types, expression trees have types, but statements don't. Rather than have a nonsensical field that stays NULL in the base class, just move it to where it makes sense. Fix up a few places that lazily used ir_instruction even though they actually knew the particular subclass. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Remove ir_call::get_callee() and set_callee().Kenneth Graunke2012-04-0216-38/+22
| | | | | | | | | | | | | Previously, set_callee() performed some assertions about the type of the ir_call; protecting the bare pointer ensured these checks would be run. However, ir_call no longer has a type, so the getter and setter methods don't actually do anything useful. Remove them in favor of accessing callee directly, as is done with most other fields in our IR. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Convert ir_call to be a statement rather than a value.Kenneth Graunke2012-04-0220-208/+185
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Aside from ir_call, our IR is cleanly split into two classes: - Statements (typeless; used for side effects, control flow) - Values (deeply nestable, pure, typed expression trees) Unfortunately, ir_call confused all this: - For void functions, we placed ir_call directly in the instruction stream, treating it as an untyped statement. Yet, it was a subclass of ir_rvalue, and no other ir_rvalue could be used in this way. - For functions with a return value, ir_call could be placed in arbitrary expression trees. While this fit naturally with the source language, it meant that expressions might not be pure, making it difficult to transform and optimize them. To combat this, we always emitted ir_call directly in the RHS of an ir_assignment, only using a temporary variable in expression trees. Many passes relied on this assumption; the acos and atan built-ins violated it. This patch makes ir_call a statement (ir_instruction) rather than a value (ir_rvalue). Non-void calls now take a ir_dereference of a variable, and store the return value there---effectively a call and assignment rolled into one. They cannot be embedded in expressions. All expression trees are now pure, without exception. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Split out ir_reader's ability to read ir_dereference_variables.Kenneth Graunke2012-04-021-8/+20
| | | | | | | | | | Most of the time, we just want to read an ir_dereference, so there's no need to have these in separate functions. However, the next patch will want to read an ir_dereference_variable directly. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Move constant expression handling from calls to signatures.Kenneth Graunke2012-04-022-8/+25
| | | | | | | | | | | | | | | When translating a call from AST to HIR, we need to decide whether it can be evaluated to a constant before emitting any code (namely, the temporary declaration, assignment, and call.) Soon, ir_call will become a statement taking a dereference of where to store the return value, rather than an rvalue to be used on the RHS of an assignment. It will be more convenient to try evaluation before creating a call. ir_function_signature seems like a reasonable place. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Use ir_rvalue to represent generic error_type values.Kenneth Graunke2012-04-0213-41/+80
| | | | | | | | | | | | | | | | | | | | | | Currently, ir_call can be used as either a statement (for void functions) or a value (for non-void functions). This is rather awkward, as it's the only class that can be used in both forms. A number of places use ir_call::get_error_instruction() to construct a generic value of error_type. If ir_call is to become a statement, it can no longer serve this purpose. Unfortunately, none of our classes are particularly well suited for this, and creating a new one would be rather aggrandizing. So, this patch introduces ir_rvalue::error_value(), a static method that creates an instance of the base class, ir_rvalue. This has the nice property that you can't accidentally try and access uninitialized fields (as it doesn't have any). The downside is that the base class is no longer abstract. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Combine AST-level and IR-level parameter mode checking loops.Kenneth Graunke2012-04-021-82/+85
| | | | | | | | | | | | | generate_call() and ast_function_expression::hir() both tried to verify that 'out' and 'inout' parameters used l-values. Irritatingly, it turned out that this was not redundant; both checks caught -some- cases. This patch combines the two into a single "complete" function that does all the parameter mode checking. It also adds a comment clarifying why AST-level checking is necessary in the first place. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Split up function matching and call generation a bit more.Kenneth Graunke2012-04-021-35/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We used to have one big function, match_signature_by_name, which found a matching signature, performed out-parameter conversions, and generated the ir_call. As the code for matching against built-in functions became more complicated, I split it internally, creating generate_call(). However, I left the same awkward interface. This patch splits it into three functions: 1. match_signature_by_name() This now takes a name, a list of parameters, the symbol table, and returns an ir_function_signature. Simple and one purpose: matching. 2. no_matching_function_error() Generate the "no matching function" error and list of prototypes. This was complex enough that I felt it deserved its own function. 3. generate_call() Do the out-parameter conversion and generate the ir_call. This could probably use more splitting. The caller now has a more natural workflow: find a matching signature, then either generate an error or a call. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Don't trust loop analysis in the presence of function calls.Kenneth Graunke2012-04-022-0/+34
| | | | | | | | | | | | | | | | | | | | | Function calls may have side effects that alter variables used inside the loop. In the fragment shader, they may even terminate the shader. This means our analysis about loop-constant or induction variables may be completely wrong. In general it's impossible to determine whether they actually do or not (due to the halting problem), so we'd need to perform conservative static analysis. For now, it's not worth the complexity: most functions will be inlined, at which point we can unroll them successfully. Fixes Piglit tests: - shaders/glsl-fs-unroll-out-param - shaders/glsl-fs-unroll-side-effect NOTE: This is a candidate for release branches. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* linker: Fix memory leak in count_uniform_size::visit_field.Vinson Lee2012-03-311-2/+1
| | | | | | | | | Fixes a Coverity resource leak defect. NOTE: This is a candidate for the 8.0 branch. Signed-off-by: Vinson Lee <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: fix linker error message context for frag shader output.Dave Airlie2012-03-261-3/+5
| | | | | | | | A later error prints this properly, fix this case to do the same. v2: remove attribute as per Ian's suggestion Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Make ir_dereference_variable ctor assert the variable exists.Kenneth Graunke2012-03-261-1/+3
| | | | | | | | | | | | | | This also seems like a bad idea. There were too many instances for me to thoroughly scan the code as I did with the last two patches, but a quick scan indicated that most callers newly allocate a variable, dereference it, or NULL-check. In some cases, it wasn't clear that the value would be non-NULL, but they didn't check for error_type either. At any rate, not checking for this is a bug, and assertions will trigger it earlier and more reliably than returning error_type. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Explicitly NULL-check variables before making a dereference.Kenneth Graunke2012-03-261-2/+2
| | | | | | | | The constructor currently returns a ir_dereference_variable of error type when provided NULL, but that's about to change in the next commit. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Make ir_dereference_record constructor assert the variable exists.Kenneth Graunke2012-03-261-4/+4
| | | | | | | | | | | | | | | | | | Providing a NULL pointer to the ir_dereference_record() constructor seems like a bad idea. Currently, if provided NULL, it returns a partially constructed value of error type. However, none of the callers are prepared to handle that scenario. Code inspection shows that all callers do one of the following: - Already NULL-check the argument prior to creating the dereference - Already deference the argument (and thus would crash if it were NULL) - Newly allocate the argument. Thus, it should be safe to simply assert the value passed is not NULL. This should also catch issues right away, rather than dying later. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Make ir_dereference_array constructor assert the variable exists.Kenneth Graunke2012-03-261-10/+9
| | | | | | | | | | | | | | | | | | Providing a NULL pointer to the ir_dereference_array() constructor seems like a bad idea. Currently, if provided NULL, it returns a partially constructed value of error type. However, none of the callers are prepared to handle that scenario. Code inspection shows that all callers do one of the following: - Already NULL-check the argument prior to creating the dereference - Already deference the argument (and thus would crash if it were NULL) - Newly allocate the argument. Thus, it should be safe to simply assert the value passed is not NULL. This should also catch issues right away, rather than dying later. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Comment that expression flattening is used for matrix operations.Kenneth Graunke2012-03-261-1/+4
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: fix compiling warning from gcc 4.7Dave Airlie2012-03-251-1/+1
| | | | | | | | | | | ir_validate.cpp: In member function ‘virtual ir_visitor_status ir_validate::visit_leave(ir_swizzle*)’: ir_validate.cpp:458:66: warning: narrowing conversion of ‘ir->ir_swizzle::mask.ir_swizzle_mask::x’ from ‘unsigned int’ to ‘int’ inside { } is ill-formed in C++11 [-Wnarrowing] ir_validate.cpp:458:66: warning: narrowing conversion of ‘ir->ir_swizzle::mask.ir_swizzle_mask::y’ from ‘unsigned int’ to ‘int’ inside { } is ill-formed in C++11 [-Wnarrowing] ir_validate.cpp:458:66: warning: narrowing conversion of ‘ir->ir_swizzle::mask.ir_swizzle_mask::z’ from ‘unsigned int’ to ‘int’ inside { } is ill-formed in C++11 [-Wnarrowing] ir_validate.cpp:458:66: warning: narrowing conversion of ‘ir->ir_swizzle::mask.ir_swizzle_mask::w’ from ‘unsigned int’ to ‘int’ inside { } is ill-formed in C++11 [-Wnarrowing] Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Brian Paul <[email protected]>
* glsl: initialise const force glsl extension warning in fake ctxDave Airlie2012-03-251-0/+1
| | | | | | | | | valgrind complained about an uninitialised value being used in glsl_parser_extras.cpp, and this was the one it was giving out about. Just initialise the value in the fakectx. Signed-off-by: Dave Airlie <[email protected]>
* glsl: propagate MaxUnrollIterations to the optimizer's loop unrollerBrian Paul2012-03-211-1/+3
| | | | | | | | | | Instead of the hard-coded value of 32. Note that MaxUnrollIterations defaults to 32 so there's no net change. But the gallium state tracker can override this. NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Don't require gl_Position to be written in GLSL 1.40.Eric Anholt2012-03-211-5/+30
| | | | | | | Fixes piglit glsl-1.40/execution/tf-no-position. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* Add .deps/, .libs/, and *.la to toplevel .gitignorePaul Berry2012-03-201-2/+0
| | | | | | | To avoid redundancies, this patch also removes .deps, .libs, and *.la from .gitignore files in subdirectories. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Don't include the deprecated structure types in GLSL 1.40.Eric Anholt2012-03-192-15/+17
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add GLSL 1.40 textureSize() implementations for sampler2DRect.Eric Anholt2012-03-153-2/+19
| | | | | | | | | | | | | By setting lod to 0 in the builtin function implementation, we avoid needing to update all the visitors to ignore LOD in this case, when the hardware drivers actually want to ask for LOD 0 for rectangular textures. Fixes piglit spec/GLSL-1.40/textureSize-*Rect. v2: Change style of looking for substrings. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Set up generated builtin functions handling for GLSL 1.40.Eric Anholt2012-03-151-3/+3
| | | | | | | Otherwise, when we go to use ir_reader on the generated code, we won't have the types present. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add support for integer sampler2DRect variants in GLSL 1.40.Eric Anholt2012-03-153-2/+27
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Drop ftransform() from GLSL 1.40 profile.Eric Anholt2012-03-151-2/+0
| | | | | | | | | This is the one builtin function claimed to be dropped due to the ARB_compatibility split. Fixes piglit spec/GLSL-1.40/compiler/ftransform.vert Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Copy GLSL 1.30 builtin profile to GLSL 1.40.Eric Anholt2012-03-152-0/+1946
| | | | | | All that's changed is the #version changing to 140. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: When failing to compile some builtins, print the error.Eric Anholt2012-03-151-0/+8
| | | | | | | This makes the process slightly more debuggable, though it would be nice if the build just failed immediately instead. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Let the builtin compiler process GLSL 1.40 shaders.Eric Anholt2012-03-151-3/+3
| | | | | | | This is required to put the new 1.40 builtins in place, since they require new types. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Update builtin variables for GLSL 1.40.Eric Anholt2012-03-151-109/+150
| | | | | | | | | | Mostly this is a matter of removing variables that have been moved to the compatibility profile. There's one addition: gl_InstanceID is present in the core now. This fixes the new piglit tests for GLSL 1.40 builtin variables. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Hook up the current GLSL 1.30 types and builtins for 1.40.Eric Anholt2012-03-153-1/+10
| | | | | | This gets a basic #version 140 shader compiling. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add support for parsing #version 140.Eric Anholt2012-03-153-0/+6
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Avoid extra if statements for logic and/or with no side effects.Eric Anholt2012-03-131-17/+6
| | | | | | | | | | | | | This avoids extra if statements in the common case of just comparing two expressions that don't involve assignments or function calls, along with simplifying the handling of constant expressions. Reduces i965 instructions generated in unigine tropics and sanctuary, yofrankie, warsow, gstreamer shaders, and the weston compositor. shader-db results: Total instructions: 213052 -> 212752 38/1246 programs affected (3.0%) 14309 -> 14009 instructions in affected programs (2.1% reduction)
* glsl: Refine the loop instruction counting.Eric Anholt2012-03-081-12/+36
| | | | | | | | | | | | Before, we were only counting top-level instructions. But if we have an assignment of a giant expression tree (such as the ones eventually generated by glsl-fs-unroll), we were counting the same as an assignment of a variable deref. glsl-fs-unroll-explosion now fails in a reasonable amount of time on i965 because the unrolling didn't go ridiculously far. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Make gl_InstanceID available with GL_ARB_draw_instanced extensionIan Romanick2012-02-291-1/+13
| | | | | | | | | | | Originally ARB_draw_instanced only specified that ARB decorated name. Since no vendor actually implemented that behavior and some apps use the undecorated name, the extension now specifies that both names are available. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
* glcpp: Don't strlen() the output for every token being printed.Kenneth Graunke2012-02-282-24/+28
| | | | | | | | | | | | | The ralloc string appending functions were originally intended for simple, non-hot-path uses like printing to an info log. Cuts Unigine Tropics load time by around 20% (6 seconds). v2: Avoid strlen() on every newline, too. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> [v1] Acked-by: José Fonseca <[email protected]> [v1]
* ralloc: Make rewrite_tail increase "start" by the new text's length.Kenneth Graunke2012-02-284-16/+18
| | | | | | | | | | | | | | | | | | Both callers of rewrite_tail immediately compute the new total string length by adding the (known) length of the existing string plus the length of the newly appended text. Unfortunately, callers generally won't know the length of the new text, as it's printf-formatted. Since ralloc already computes this length, it makes sense to add it in and save the caller the effort. This simplifies both existing callers, but more importantly, will allow for cheap-appending in the next commit. v2: The link_uniforms code needs both the old and new length. Apply the obvious fix (which sadly makes it less of a cleanup). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> [v1] Acked-by: José Fonseca <[email protected]> [v1]
* glsl: Avoid excessive loop unrolling.Mathias Fröhlich2012-02-091-0/+15
| | | | | | | | | | | | | | | | | | | Avoid unrollong loops that are either nested loops or where the loop body times the unroll count is huge. The change is far from being perfect but it extends the loop unrolling decision heuristic by some additional safeguard. In particular this cuts down compilation of a shader precomputing atmospheric scattering integral tables containing two nesting levels in a loop from something way beyond some minutes (I never waited for it to finish) to some fractions of a second. This fixes piglit tests glsl-fs-unroll-explosion and glsl-vs-unroll-explosion on r600g. Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Mathias Fröhlich <[email protected]>
* glsl: Fix Android buildChad Versace2012-02-081-0/+1
| | | | | | | | | | | | The build was broken by the line below, added in commit 4f82fed4. s_expression.cpp:26: #include <limits> Mesa's half of the fix is to add 'external/astl/include' to the include path. The other half of the fix requires implementing numeric_limits<float>::infinity() in astl, for which I have patches submitted upstream for review. Signed-off-by: Chad Versace <[email protected]>
* glsl: Add error case for switch() with two default cases.Eric Anholt2012-02-032-0/+16
| | | | | | | | 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-032-0/+27
| | | | | | | | | 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: Add other missing error location information for switch statements.Eric Anholt2012-02-031-0/+4
| | | | | | NOTE: This is a candidate for the 8.0 branch. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add missing location info to case labels.Eric Anholt2012-02-031-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 <[email protected]>
* glsl: Throw the required error when a case label is a non-constant.Eric Anholt2012-02-031-2/+14
| | | | | | | | | | | | It's not quite spelled out in the spec text, but the grammar indicates that only constant values are allowed as switch() case labels (and only constant values make sense, anyway). Fixes piglit glsl-1.30/compiler/switch-statement/switch-case-uniform-int.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-033-260/+255
| | | | | | | | | 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: move array_sizing_visitor class outside of link_intrastage_shaders()Brian Paul2012-02-021-16/+22
| | | | | | To silence warnings with gcc 4.4.x on Linux and llvm-g++ 4.2 on Mac. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Avoid ralloc_stealing a long-lived object to a short-lived parentCarl Worth2012-02-021-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In commit 6ecee54a9aecc120cb68b02f7e14dcac86b9eca2 a call to talloc_reference was replaced with a call to talloc_steal. This was in preparation for moving to ralloc which doesn't support reference counting. The justification for talloc_steal within token_list_append in that commit is that the tokens are being copied already. But the copies are shallow, so this does not work. Fortunately, the lifetime of these tokens is easy to understand. A token list for "replacements" is created and stored in a hash table when a function-like macro is defined. This list will live until the macro is #undefed (if ever). Meanwhile, a shallow copy of the list is created when the macro is used and the list expanded. This copy is short-lived, so is unsuitable as a new parent. So we can just let the original, longer-lived owner continue to own the underlying objects and things will work. This fixes bug #45082: "ralloc.c:78: get_header: Assertion `info->canary == 0x5A1106' failed." when using a macro in GLSL https://bugs.freedesktop.org/show_bug.cgi?id=45082 Reviewed-by: Kenneth Graunke <[email protected]> NOTE: This is a candidate for stable release branches.
* glsl: Add glcpp tests for a macro used twiceCarl Worth2012-02-022-0/+33
| | | | | | | | | | | | | This test cases exposes a bug as described in this bug report: "ralloc.c:78: get_header: Assertion `info->canary == 0x5A1106' failed." when using a macro in GLSL https://bugs.freedesktop.org/show_bug.cgi?id=45082 Clearly, some memory is getting (incorrectly) freed on the first macro invocation, leading to problems with the second macro invocation. Reviewed-by: Kenneth Graunke <[email protected]>
* glcpp: Fix so that trailing punctuation does not prevent macro expansionCarl Worth2012-02-021-1/+9
| | | | | | | | | | | | | | | | | | | | The trick here is that flex always chooses the rule that matches the most text. So with a input text of "two:" which we want to be lexed as an IDENTIFIER token "two" followed by an OTHER token ":" the previous OTHER rule would match longer as a single token of "two:" which we don't want. We prevent this by forcing the OTHER pattern to never match any characters that appear in other constructs, (no letters, numbers, #, _, whitespace, nor any punctuation that appear in CPP operators). Fixes bug #44764: GLSL preprocessor doesn't replace defines ending with ":" https://bugs.freedesktop.org/show_bug.cgi?id=44764 Reviewed-by: Kenneth Graunke <[email protected]> NOTE: This is a candidate for stable release branches.
* glcpp: Add new test showing bug where a trailing ':' prevents macro expansionCarl Worth2012-02-022-0/+15
| | | | | | | | | | | This demonstrates a bug that was recently triggered in piglit. Here is the original bug report (containing a test case almost identical to this one): https://bugs.freedesktop.org/show_bug.cgi?id=44764 Reviewed-by: Kenneth Graunke <[email protected]>