summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Properly throw compile-time errors for conflicting FS output writes.Eric Anholt2012-04-191-0/+66
| | | | | | | | | | | We were checking for these at link time previously, which is not as early as mandated, and would actually fail to detect conflicting writes if dead code removal removed some writes. Fixes failures in piglit glsl-*/compiler/fragment-outputs/write-gl_Frag* Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Track in each ir_variable whether it was ever assigned.Eric Anholt2012-04-193-13/+33
| | | | | | | This will be used for some compile-and-link-time error checking, where currently we've been doing error checking only at link time. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Convert the tests directory to automake.Eric Anholt2012-04-192-0/+3
| | | | | | | | | | | This runs optimization-test and produces the usual automake test output, which may be interesting to automated build systems. This doesn't convert the tests to be individually exposed to the automake runner, because automake doesn't like wildcards (due to being nonportable in make, not that we care). Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix up some comments in structure splitting, based on array-split work.Eric Anholt2012-04-191-3/+8
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Don't allow array splitting on function arguments.Eric Anholt2012-04-191-1/+17
| | | | | | | | | | | This is the reason the declaration member existed in the reference visitor, but I didn't copy the code from structure splitting that avoided setting it. This wasn't currently a problem, because we don't allow splitting of in/out variables. But that would be nice to change some day. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Rename the "whole_array_access" member in array splitting.Eric Anholt2012-04-191-11/+15
| | | | | | | This was carried over from structure splitting, without thinking about whether the name still made sense in this context. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix up a comment explaining what a visitor class does.Eric Anholt2012-04-191-1/+4
| | | | | | | Ken noted that some of the "actual work" was happening in the caller of this class. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Use the column_types() helper method.Eric Anholt2012-04-191-2/+1
| | | | | | Ken noted this in a review of this patch that I pushed early. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Remove unused mem_ctx field from ir_array_splitting_visitor.Kenneth Graunke2012-04-181-1/+0
| | | | | | | | Vinson reported that we failed to initialize this, which would lead to all kinds of crashes if we actually used it. Since we don't use it, we may as well just delete the broken code. Signed-off-by: Kenneth Graunke <[email protected]>
* glsl/builtins: Rework profiles to use the new '.glsl' common suffix.Kenneth Graunke2012-04-1720-4807/+1902
| | | | | | | | | | | | | | | | | | | | Deletes a lot of pointless duplication, as well as some run-time effort. Conveniently, GLSL 1.40 no longer needs a .vert variant, since it doesn't define any built-ins specific to the vertex shader stage. ARB_texture_rectangle and OES_EGL_image_external also only need a single profile, since the .vert and .frag variants were identical. I didn't bother with EXT_texture_array and OES_texture_3D because they're so tiny that the savings would be miniscule. Cuts the generated builtin_function.cpp from 1.7MB to 1.0MB (41%). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Acked-by: Ian Romanick <[email protected]>
* glsl/builtins: Support stage-agnostic built-in profiles.Kenneth Graunke2012-04-171-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The built-in subsystem uses "profiles," or GLSL shaders containing prototypes for all built-ins supported within a particular language version (or extension) and shader stage. Since profiles were stage-specific, we had to cut and paste almost all the prototypes between (e.g.) 110.vert and 110.frag. Naturally, this led to sundry cut and paste bugs, where someone fixed an issue in .frag but neglected to update .vert, or vice-versa. Geometry shaders would have only made this worse. This patch introduces support for a new '.glsl' profile suffix which contains prototypes common to all shader stages. The existing '.frag' and '.vert' profiles need only contain the few stage-specific built-ins. Not only does this remove duplication, it makes built-in setup slightly faster: we don't need to re-read the common prototypes and function bodies for both the vertex and fragment shader stage. Internally, this was trivial. We already create a list of gl_shader objects to search through for built-ins: one for the core language version/stage, and additional shaders for any extensions in use. This patch simply adds another shader to the list: core/common, core/stage, and extensions. The next patch will update the profiles to remove the duplication. It's separated out purely to make review easier. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Acked-by: Ian Romanick <[email protected]>
* glsl: Make the standalone compiler accept '.glsl' files.Kenneth Graunke2012-04-171-1/+1
| | | | | | | | | | These ought to be treated as 'any stage', but for now, they're just treated as vertex shaders. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Acked-by: Ian Romanick <[email protected]>
* glsl/builtins: Use ivec for texel offsets in textureProjGradOffset.Kenneth Graunke2012-04-173-4/+4
| | | | | | | | | | | | | | | | | The GLSL 1.30 -> 4.10 specs all erroneously say "vec2" for a few overloads of textureProjGradOffset, while most overloads and all other texturing functions use ivec types. The GLSL 4.20 specification corrects these to "ivec2", but doesn't mention this as being a conscious change in behavior. Nor does the ARB_shading_language_420pack extension. So presumably it was a typo. At any rate, our builtin functions all use ivec already, so the fact that these prototypes use plain vecs will only lead to applications dying in a fire when trying to use them. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* Revert "glsl: Refuse to link GLSL 1.40+ shaders that would use fixed function."Eric Anholt2012-04-161-14/+0
| | | | | | | | | | | | | | | | | | | | | This reverts commit 4ec449a6ed1d2cea3bf83d6518b3b352ce5daceb. I meant to not push this one. Review found that a link error is not mandated: it should link, but you get undefined rendering if you rely on a missing stage. page 42/55 section 2.11 "Vertex Shaders": "If the program object has no vertex shader, or no program object is currently in use, the results of vertex shader execution are undefined." (and similar for page 160/173 section 3.9 "Fragment Shaders" for FS, and page 45/58 section 2.11.2 "Program Objects" for program being 0) It turns out the commit was broken anyway, because it was missing a "goto done", so linkstatus got smashed back to true later and the error just showed up as a warning in the infolog.
* glsl: Refuse to link GLSL 1.40+ shaders that would use fixed function.Eric Anholt2012-04-161-0/+14
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add remaining *sampler2DRect* texture functions.Eric Anholt2012-04-163-0/+158
| | | | | | Fixes the new piglit texelFetch() tests on these. Note that the rest of the new functions are not tested (same as the non-2DRect versions of most of them).
* glsl: Fix the prototype of textureProjGradOffset(sampler2DShadow)Eric Anholt2012-04-161-1/+1
| | | | | | | Indirectly caught by Ken's review of my GLSL 1.40 changes where I copy-and-pasted this line. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Mark [iu]sampler{Buffer,2DRect}as reserved in GLSL 1.40.Eric Anholt2012-04-162-2/+14
| | | | | | | | | The non-integer versions were already reserved in 1.30, but apparently these were forgotten. Fixes piglit glsl-1.40/compiler/reserved/ Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add textureSize(*samplerBuffer) support.Eric Anholt2012-04-163-0/+9
| | | | | | Fixes the corresponding new tests in piglit. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix comment typo in 1.40 work.Eric Anholt2012-04-161-1/+1
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* 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]>