summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* 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: Move type_contains_sampler() into glsl_type for later reuse.Paul Berry2011-07-183-16/+23
| | | | | | | The new location, as a member function of glsl_type, is more consistent with queries like is_sampler(), is_boolean(), is_float(), etc. Placing the function inside glsl_type also makes it available to any code that uses glsl_types.
* linker: Only over-ride built-ins when a prototype has been seenIan Romanick2011-07-172-5/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | The GLSL spec says: "If a built-in function is redeclared in a shader (i.e., a prototype is visible) before a call to it, then the linker will only attempt to resolve that call within the set of shaders that are linked with it." This patch enforces this behavior. When a function call is processed a flag is set in the ir_call to indicate whether the previously seen prototype is the built-in or not. At link time a call will only bind to an instance of a function that matches the "want built-in" setting in the ir_call. This has the odd side effect that first call to abs() in the shader below will call the built-in and the second will not: float foo(float x) { return abs(x); } float abs(float x) { return -x; } float bar(float x) { return abs(x); } This seems insane, but it matches what the spec says. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=31744
* glsl: Reject ambiguous function calls (multiple inexact matches).Kenneth Graunke2011-07-111-6/+27
| | | | | | | | | | | | | | | | | | | According to the GLSL 1.20 specification, "it is a semantic error if there are multiple ways to apply [implicit] conversions [...] such that the call can be made to match multiple signatures." Fixes a regression caused by 60eb63a855cb89962f2d5bb91e238ff2d1ab8702, which implemented the wrong policy of finding a "closest" match. However, this is not a revert, since the original code failed to continue looking for an exact match once it found two inexact matches. It's OK to have multiple inexact matches if there's also an exact match. NOTE: This is a candidate for the 7.10 and 7.11 branches. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38971 Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Lower break instructions when necessary at the end of a loop.Paul Berry2011-07-081-1/+54
| | | | | | | | | | | | | | | | | | Normally lower_jumps.cpp doesn't need to lower a break instruction that occurs at the end of a loop, because all back-ends can produce proper GPU instructions for a break instruction in this "canonical" location. However, if other break instructions within the loop are already being lowered, then a break instruction at the end of the loop needs to be lowered too, since after the optimization is complete a new conditional break will be inserted at the end of the loop. Without this patch, lower_jumps.cpp may require multiple passes in order to lower all jumps. This results in sub-optimal output because lower_jumps.cpp produces a brand new set of temporary variables each time it is run, and the redundant temporary variables are not guaranteed to be eliminated by later optimization passes. Fixes unit test test_lower_breaks_6.
* glsl: In lower_jumps.cpp, lower both branches of a conditional.Paul Berry2011-07-081-1/+4
| | | | | | | | | | | | | | | Previously, lower_jumps.cpp would break out of its loop after lowering a jump instruction in just the then- or else-branch of a conditional, and it would fail to lower a jump instruction occurring in the other branch. Without this patch, lower_jumps.cpp may require multiple passes in order to lower all jumps. This results in sub-optimal output because lower_jumps.cpp produces a brand new set of temporary variables each time it is run, and the redundant temporary variables are not guaranteed to be eliminated by later optimization passes. Fixes unit test test_lower_returns_4.
* glsl: Use foreach_list in lower_jumps.cppPaul Berry2011-07-081-1/+12
| | | | | | | | | | | | | | | | | | | | | | | The visitor class in lower_jumps.cpp never removes or replaces the instruction being visited, but it frequently alters or removes the instructions that follow it. Therefore, to make sure the altered IR is visited, it needs to iterate through exec_lists using foreach_list rather than visit_exec_list(). Without this patch, lower_jumps.cpp may require multiple passes in order to lower all jumps. This results in sub-optimal output because lower_jumps.cpp produces a brand new set of temporary variables each time it is run, and the redundant temporary variables are not guaranteed to be eliminated by later optimization passes. Also, certain invariants assumed by lower_jumps.cpp may fail to hold, causing assertion failures. Fixes unit tests test_lower_pulled_out_jump, test_lower_unified_returns, test_lower_guarded_conditional_break, test_lower_return_non_void_at_end_of_loop, and test_lower_returns_3. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: lower unconditional returns and continues in loops.Paul Berry2011-07-081-8/+54
| | | | | | | | | | | | | | | | | Previously, lower_jumps.cpp would only lower return and continue statements that appeared inside conditionals. This patch makes it lower unconditional returns and continue statements that occur inside a loop. Such unconditional flow control statements would be unlikely to be explicitly coded by a reasonable user, however they might arise as a result of other optimizations. Without this patch, lower_jumps.cpp might not lower certain return and continue statements, causing some backends to fail. Fixes unit tests test_lower_return_void_at_end_of_loop and test_remove_continue_at_end_of_loop.
* glsl: Lower unconditional return statements.Paul Berry2011-07-081-0/+14
| | | | | | | | | | Previously, lower_jumps.cpp only lowered return statements that appeared inside of an if statement. Without this patch, lower_jumps.cpp might not lower certain return statements, causing some back-ends to fail (as in bug #36669). Fixes unit test test_lower_returns_1.
* glsl: Refactor logic for determining whether to lower return statements.Paul Berry2011-07-081-7/+12
| | | | | | | | Previously, do_lower_jumps.cpp determined whether to lower return statements in ir_lower_jumps_visitor::should_lower_jumps(). Moved this logic to ir_lower_jumps_visitor::visit(ir_function_signature *), so that it can be used in determining whether to lower a return statement at the end of a function.
* glsl: Add explanatory comments to lower_jumps.cpp.Paul Berry2011-07-081-14/+322
| | | | | | No functional change. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Make ir_reader able to read plain (return) statements.Paul Berry2011-07-081-11/+13
| | | | | | | | | Previously ir_reader was only able to handle return of non-void. This patch is necessary in order to allow optimization passes to be tested in isolation. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Remove unused function prototypes.Paul Berry2011-07-081-2/+0
| | | | | No functional change. Remove prototypes for do_mod_to_fract() and do_sub_to_add_neg(), which haven't existed since November 2010.
* glsl: use casts to silence warningBrian Paul2011-07-071-1/+1
|
* linker: Assign locations for fragment shader outputIan Romanick2011-07-061-33/+75
| | | | | | | | | | | | | | | | | | | | | Fixes an assertion failure in the piglib out-01.frag ARB_explicit_attrib_location test. The locations set via the layout qualifier in fragment shader were not being applied to the shader outputs. As a result all of these variables still had a location of -1 set. This may need some more work for pre-3.0 contexts. The problem is dealing with generic outputs that lack a layout qualifier. There is no way for the application to specify a location (glBindFragDataLocation is not supported) or query the location assigned by the linker (glGetFragDataLocation is not supported). NOTE: This is a candidate for the 7.10 and 7.11 branches. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38624 Reviewed-by: Eric Anholt <[email protected]> Cc: Kenneth Graunke <[email protected]> Cc: Vinson Lee <[email protected]>
* glsl: Don't choke when printing an anonymous function parameterIan Romanick2011-07-061-0/+10
| | | | | | | NOTE: This is a candidate for the 7.10 and 7.11 branches. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38584 Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Track initial mask in constant propagation live setIan Romanick2011-07-061-3/+14
| | | | | | | | | | | | | The set of values initially available (before any kills) must be tracked with each constant in the set. Otherwise the wrong component can be selected after earlier components have been killed. NOTE: This is a candidate for the 7.10 and 7.11 branches. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37383 Reviewed-by: Eric Anholt <[email protected]> Cc: Kenneth Graunke <[email protected]> Cc: Matthias Bentrup <[email protected]>
* glsl: Suppress warning from matching_signature change.Eric Anholt2011-07-061-1/+1
| | | | | gcc isn't smart enough to see that we only look at matched_score after we've initialized it (because match != NULL happens at the same time)
* glsl: Fix make clean for dricore.Eric Anholt2011-07-061-1/+1
|
* glsl: Don't use MOD_TO_FRACT lowering on GLSL 1.30's % operator.Kenneth Graunke2011-06-291-1/+1
| | | | | | | | | | | | | MOD_TO_FRACT was designed to lower the GLSL 1.20 mod() function, which operates on floating point values. However, we also use ir_binop_mod for GLSL 1.30's % operator, which operates on integers. For now, make MOD_TO_FRACT only apply to floating-point mod operations. In the future, we may want to add a lowering pass for integer-based mod. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Fix DIV_TO_MUL_RCP lowering for uint result types.Kenneth Graunke2011-06-291-2/+7
| | | | | | | | f2i results in an int/ivec; we need i2u to get a uint/uvec. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[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: Find the "closest" signature when there are multiple matches.Kenneth Graunke2011-06-291-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | Previously, ir_function::matching_signature had a fatal bug: if a function had more than one non-exact match, it would simply return NULL. This occured, for example, when looking for max(uvec3, uvec3): - max(vec3, vec3) -> score 1 (found first) - max(ivec3, ivec3) -> score 1 (found second...used to return NULL here) - max(uvec3, uvec3) -> score 0 (exact match...the right answer) This did not occur for max(ivec3, ivec3) since the second match found was an exact match. The new behavior is to return a match with the lowest score. If there is an exact match, that will be returned. Otherwise, a match with the least number of implicit conversions is chosen. Fixes piglit tests max-uvec3.vert and glsl-inexact-overloads.shader_test. NOTE: This is a candidate for the 7.10 and 7.11 branches. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Use i2u and u2i to implement constructor conversions.Kenneth Graunke2011-06-291-6/+29
| | | | | | | | | | | | | | Inspired by a patch from Bryan Cain <[email protected]>. Fixes piglit tests: - ctor-int-uint.vert - ctor-ivec4-uvec4.vert - ctor-uint-int.vert - ctor-uvec4-ivec4.vert Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Revert "fix conversions from uint to bool and from..."Kenneth Graunke2011-06-291-3/+3
| | | | | | | | | | Reverts commit f41e1db3273a31285360241c4342f0a403ee0b03 "fix conversions from uint to bool and from float/bool to uint" f2i, b2i, and b2i should not accept uint types. Use i2u and u2i. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Add ir_unop_i2u and ir_unop_u2i operations.Bryan Cain2011-06-294-1/+30
| | | | | | | | | | | | | | | | | These are necessary to handle int/uint constructor conversions. For example, the following code currently results in a type mismatch: int x = 7; uint y = uint(x); In particular, uint(x) still has type int. This commit simply adds the new operations; it does not generate them, nor does it add backend support for them. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Use the default values of ir_assignment() in lower_mat_op_to_vec.Eric Anholt2011-06-291-24/+8
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Allow ir_assignment() constructor to not specify condition.Eric Anholt2011-06-291-1/+1
| | | | | | | | | | | We almost never want to specify a condition, and when we do we're already thinking about it (because we're writing a lowering pass generating the condition), so a default argument should make the code more pleasant to read. NOTE: This is a candidate for the 7.11 branch (we want to be able to cherry-pick future code). Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Avoid making a temporary for lower_mat_op_to_vec if not needed.Eric Anholt2011-06-291-0/+11
| | | | | | | | | | | | | Our copy propagation tends to be bad at handling the later array accesses of the matrix argument we moved to a temporary. Generally we don't need to move it to a temporary, though, so this avoids needing more copy propagation complexity. Reduces instruction count of some Unigine Tropics and Sanctuary fragment shaders that do operations on uniform matrix arrays by 5.9% on gen6. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Make lower_mat_op_to_vec track derefs, not variables.Eric Anholt2011-06-291-71/+56
| | | | | | | We were constrained to using temporaries because we were assuming variables all over. This simplifies things a bit. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Rename lower_mat_op_to_vec operands/results to be less hungarian.Eric Anholt2011-06-291-74/+74
| | | | | | | | | | | This awkward typing was to avoid shadowing the function argument (the matrix) with the temporary deref (the column) before the get_column()/get_element()s were moved into the expression/assignment constructors. They're about to become not-variables, so the current names had to go. This change is almost mechanical (other than column_expr), so it should make the next diff clearer. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Move get_{column,element} to expression args.Eric Anholt2011-06-291-43/+22
| | | | | | | | I think this makes the code more obvious by moving the declarations to their single usage (now that we aren't using them to get at the ->type field for expression constructors). Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Drop explicit types of lower_mat_op_to_vec expressions.Eric Anholt2011-06-291-27/+6
| | | | | | The constructor can figure it out for us these days. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Rewrote _mesa_glsl_process_extension to use table-driven logic.Paul Berry2011-06-281-109/+218
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of using a chain of manually maintained if/else blocks to handle "#extension" directives, we now consult a table that specifies, for each extension, the circumstances under which it is available, and what flags in _mesa_glsl_parse_state need to be set in order to activate it. This makes it easier to add new GLSL extensions in the future, and fixes the following bugs: - Previously, _mesa_glsl_process_extension would sometimes set the "_enable" and "_warn" flags for an extension before checking whether the extension was supported by the driver; as a result, specifying "enable" behavior for an unsupported extension would sometimes cause front-end support for that extension to be switched on in spite of the fact that back-end support was not available, leading to strange failures, such as those in https://bugs.freedesktop.org/show_bug.cgi?id=38015. - "#extension all: warn" and "#extension all: disable" had no effect. Notes: - All extensions are currently marked as unavailable in geometry shaders. This should not have any adverse effects since geometry shaders aren't supported yet. When we return to working on geometry shader support, we'll need to update the table for those extensions that are available in geometry shaders. - Previous to this commit, if a shader mentioned ARB_shader_texture_lod, extension ARB_texture_rectangle would be automatically turned on in order to ensure that the types sampler2DRect and sampler2DRectShadow would be defined. This was unnecessary, because (a) ARB_shader_texture_lod works perfectly well without those types provided that the builtin functions that reference them are not called, and (b) ARB_texture_rectangle is enabled by default in non-ES contexts anyway. I eliminated this unnecessary behavior in order to make the behavior of all extensions consistent. NOTE: This is a candidate for the 7.10 and 7.11 branches. Reviewed-by: Ian Romanick <[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: 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: Fix depth unbalancing problem in if-statement flatteningIan Romanick2011-06-271-3/+1
| | | | | | | | | | | | | | | | | | | | | | Previously, if max_depth were 1, the following code would see the first if-statement (correctly) not get flattened, but the second if-statement would (incorrectly) get flattened: void main() { if (a) gl_Position = vec4(0); if (b) gl_Position = vec4(1); } This is because the visit_leave(ir_if*) method would not decrement the depth before returning on the first if-statement. NOTE: This is a candidate for the 7.10 and 7.11 branches. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Flagged extension EXT_texture3D as "supported" in the builtin compiler.Paul Berry2011-06-231-0/+1
| | | | | | | Previously, the builtins in OES_texture_3D.{frag,vert} were only compiling properly as a consequence of bug 38015, which allows unsupported extensions to be enabled. This fix eliminates the builtin compiler's reliance on bug 38015, so that bug 38015 can be fixed.
* linker: Reject shaders that use too many varyingsIan Romanick2011-06-201-5/+36
| | | | | | | | | | | | Previously it was up to the driver or later code generator to reject these shaders. It turns out that nobody did this. This will need changes to support geometry shaders. NOTE: This is a candidate for the stable branches. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37743 Reviewed-by: Kenneth Graunke <[email protected]>
* scons: make embedding orthogonal to the platformJosé Fonseca2011-06-171-2/+2
| | | | To enable embedding in platforms other than linux.
* glsl/builtins: Actually implement int/ivec variants of abs().Kenneth Graunke2011-06-141-0/+20
| | | | | | | Signed-off-by: Kenneth Graunke <[email protected]> NOTE: This is a candidate for stable release branches (and don't forget to re-run "make builtins" after cherry-picking.)
* glsl/generate_builtins.py: Remove regexp to kill pointer addresses.Kenneth Graunke2011-06-141-4/+0
| | | | | | | | | Commit 56ef62d9885f805bbfb2243dc860ff425d5b4d3b "glsl: Generate readable unique names at print time." changed ir_print_visitor to not generate @0x1234567 suffixes except where necessary. So there's no need to manually remove them. Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Fix incorrect optimization of instructions before discard statements.Eric Anholt2011-06-101-3/+17
| | | | | | | | The function was named "find_unconditional_discard", but didn't actually check that the discard statement found was unconditional. Fixes piglit glsl-fs-discard-04. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: fixed printing of structure constants.Paul Berry2011-06-031-1/+1
| | | | | | | | ir_print_visitor::visit(ir_constant *) was failing to index properly into ir->type->fields.structure, so the first field name was being reprinted for every field in the structure. Signed-off-by: Brian Paul <[email protected]>
* AST dump: fixed printing of conditionals.Paul Berry2011-06-031-1/+1
| | | | | | | ast_expression::print() had an incorrect index into the subexpressions array, so (a ? b : c) was being incorrectly rendered as (a ? b : b). Signed-off-by: Brian Paul <[email protected]>
* mesa: check that flex/bison are installedBrian Paul2011-05-181-4/+4
| | | | | | Fixes https://bugs.freedesktop.org/show_bug.cgi?id=36651 NOTE: This is a candidate for the 7.10 branch.
* glsl: Add compiler support for ARB_shader_texture_lod.Kenneth Graunke2011-05-096-0/+188
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Tested-by: Marek Olšák <[email protected]>
* glsl: Remove extra newline from error messageIan Romanick2011-05-031-1/+1
|
* mesa: implement AMD_shader_stencil_exportMarek Olšák2011-05-033-0/+32
| | | | | | | | 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: Fix typos in comments.Bryan Cain2011-04-231-6/+6
|