summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* glsl: If an "if" has no "then" or "else" code left, remove it.Eric Anholt2012-04-131-0/+8
| | | | | | | Cuts 8/1068 instructions from glyphy's fragment shaders on i965. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add a helper for generating temporary variables in ir_builder.Eric Anholt2012-04-132-0/+12
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add a helper for ir_builder to make dereferences for assignments.Eric Anholt2012-04-132-0/+42
| | | | | | v2: Fix writemask setup for non-vec4 assignments. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Make a little tracking class for emitting IR lists.Eric Anholt2012-04-132-0/+14
| | | | | | | This lets us significantly shorten p->instructions->push_tail(ir), and will be used in a few more places. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add common swizzles to ir_builder.Eric Anholt2012-04-132-0/+92
| | | | | | | | | | Now we can fold a bunch of our expression setup in ff_fragment_shader into single-line, parseable commits. v2: Make it actually work. I wasn't setting num_components in the mask structure, and not setting up a mask structure is way easier. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Let ir_builder expressions take un-dereferenced variables.Eric Anholt2012-04-132-16/+40
| | | | | | | | | | | Having to explicitly dereference is irritating and bloats the code, when the compiler can detect and do the right thing. v2: Use a little shim class to produce the automatic dereference generation at compile time as opposed to runtime, while also allowing compile-time type checking. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Create an ir_builder helper for hand-generating IR.Eric Anholt2012-04-133-0/+105
| | | | | | | | | | | | | | The C++ constructors with placement new, while functional, are extremely verbose, leading to generation of simple GLSL IR expressions like (a * b + c * d) expanding to many lines of code and using lots of temporary variables. By creating a new ir_builder.h that puts simple generators in our namespace and taking advantage of ralloc_parent(), we can generate much more compact code, at a minor runtime cost. v2: Replace ir_instruction usage with just ir_rvalue. v3: Drop remaining missed as_rvalue() in v2. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: add support for ARB_blend_func_extended (v3)Dave Airlie2012-04-138-7/+57
| | | | | | | | | | | | | | | | | | | This adds index support to the GLSL compiler. I'm not 100% sure of my approach here, esp without how output ordering happens wrt location, index pairs, in the "mark" function. Since current hw doesn't ever have a location > 0 with an index > 0, we don't have to work out if the output ordering the hw requires is location, index, location, index or location, location, index, index. But we have no hw to know, so punt on it for now. v2: index requires layout - catch and error setup explicit index properly. v3: drop idx_offset stuff, assume index follow location Signed-off-by: Dave Airlie <[email protected]>
* mesa: add support for ARB_blend_func_extended (v4)Dave Airlie2012-04-131-0/+5
| | | | | | | | | | | | | | | | | | | | Add implementations of the two API functions, Add a new strings to uint mapping for index bindings Add the blending mode validation for SRC1 + SRC_ALPHA_SATURATE Add get for MAX_DUAL_SOURCE_DRAW_BUFFERS v2: Add check in valid_to_render to address case in spec ERRORS. v3: Add index to ir.h so this patch compiles on its own fixup comment v4: fixup Brian's comments The GLSL patch will setup the indices. Signed-off-by: Dave Airlie <[email protected]>
* glsl: Extend the array splitting optimization pass to matrices.Eric Anholt2012-04-111-11/+18
| | | | | | | | | | | | | | This should fit in well with our lower_mat_op_to_vec code: now, in addition to having expressions on each column of a matrix, we also split the columns to separate variables so they can be tracked individually by the copy propagation, dead code, and other passes. This optimizes out some more code generation in unigine and gstreamer shaders. Total instructions: 269342 -> 269270 14/2148 programs affected (0.7%) 2226 -> 2154 instructions in affected programs (3.2% reduction)
* glsl: Add an array splitting pass.Eric Anholt2012-04-114-0/+380
| | | | | | | | | | | | | | | | | I've had this code laying around almost done for a long time. The idea is like opt_structure_splitting, that we've got a bunch of transforms at the GLSL IR level that only understand scalars and vectors, which just skip complicated dereferences. While driver backends may manage some optimization after they split matrices up themselves, it would be better to bring all of our optimization to bear on the problem. While I wasn't expecting changes quite yet, a few programs end up winning: a gstreamer convolution shader, and the Humus dynamic branching demo: Total instructions: 269430 -> 269342 3/2148 programs affected (0.1%) 1498 -> 1410 instructions in affected programs (5.9% reduction)
* glsl: Don't apply optimization passes to builtins.Eric Anholt2012-04-111-1/+1
| | | | | | The builtins we have are generally optimized, having been hand-written. This avoids generating bad code when an optimization pass prints debug output.
* glsl: fix variable ordering in the output_read_removerVadim Girlin2012-04-091-1/+17
| | | | | | | Use the hash of the variable name instead of the pointer value. Signed-off-by: Vadim Girlin <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add texelFetch(*samplerBuffer) entrypoints to GLSL 1.40.Eric Anholt2012-04-093-4/+15
| | | | | | | | Fix texelFetch(sampler2DRect) and textureSize(samplerBuffer) generation to not reference a LOD at the same time because it's easier than not fixing it. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add support for parsing [iu]samplerBuffer types in GLSL 1.40.Eric Anholt2012-04-092-1/+5
| | | | | | | | | The samplerBuffer type will be undefined in !glsl 1.40, and the keyword is marked as reserved. The [iu]samplerBuffer types are not marked as reserved pre-1.40, so they don't have separate tokens and fall through to normal type handling. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Drop the round-trip through ast_type_specifier for many builtin types.Eric Anholt2012-04-094-186/+58
| | | | | | | | | | We have lexer recognition of a bunch of our types based on the handling. This code was mapping those recognized tokens to an enum and then to a string of their name. Just drop the enums and provide the string directly in the parser. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Use (const char *) in AST nodes rather than plain (char *).Kenneth Graunke2012-04-093-11/+11
| | | | | | | | | | | Nothing actually relied on them being mutable, and there was at least one cast which discarded const qualifiers. The next patch would have introduced many more. Casting away const qualifiers should be avoided if at all possible. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* 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)