summaryrefslogtreecommitdiff
path: root/src/glsl/ir_reader.cpp
AgeCommit message (Collapse)AuthorFilesLines
2013-10-06glsl: Add support for specifying the component in textureGatherChris Forbes1-1/+9
ARB_gpu_shader5 introduces new variants of textureGather* which have an explicit component selector, rather than relying purely on the sampler's swizzle state. This patch adds the GLSL plumbing for the extra parameter. Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-10-05glsl: add plumbing for GL_ARB_texture_query_levelsChris Forbes1-1/+7
Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> Reviewed-by: Matt Turner <mattst88@gmail.com>
2013-10-03glsl: add texture gather changesMaxence Le Dore1-1/+5
V2 [Chris Forbes]: - Add new pattern, fixup parameter reading. V3: Rebase onto new builtins machinery Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-09-23glsl: Hide many classes local to individual .cpp files in anon namespaces.Eric Anholt1-0/+4
This gives the compiler the chance to inline and not export class symbols even in the absence of LTO. Saves about 60kb on disk. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@.intel.com>
2013-09-09glsl: Pass _mesa_glsl_parse_state into matching_signature and such.Kenneth Graunke1-2/+3
During compilation, we'll use this to determine built-in availability. The plan is to have a single shader containing every built-in in every version of the language, but filter out the ones that aren't actually available to the shader being compiled. At link time, we don't actually need this filtering capability: we've already imported prototypes for every built-in that the shader actually calls, and they're flagged as is_builtin(). The linker doesn't import any additional prototypes, so it won't pull in any unavailable built-ins. When resolving prototypes to function definitions, the linker ensures the values of is_builtin() match, which means that a shader can't trick the linker into importing the body of an unavailable built-in by defining a suspiciously similar prototype. In other words, during linking, we can just pass in NULL. It will work out fine. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-09-09glsl: Store a predicate for whether a built-in signature is available.Kenneth Graunke1-2/+11
For the upcoming built-in function rewrite, we'll need to be able to answer "Is this built-in function signature available?". This is actually a somewhat complex question, since it depends on the language version, GLSL vs. GLSL ES, enabled extensions, and the current shader stage. Storing such a set of constraints in a structure would be painful, so instead we store a function pointer. When creating a signature, we simply point to a predicate that inspects _mesa_glsl_parse_state and answers whether the signature is available in the current shader. Unfortunately, IR reader doesn't actually know when built-in functions are available, so this patch makes it lie and say that they're always present. This allows us to hook up the new functionality; it just won't be useful until real data is populated. In the meantime, the existing profile mechanism ensures built-ins are available in the right places. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-08-01glsl: add ir_emit_vertex and ir_end_primitive instruction typesBryan Cain1-0/+30
These correspond to the EmitVertex and EndPrimitive functions in GLSL. v2 (Paul Berry <stereotype441@gmail.com>): Add stub implementations of new pure visitor functions to i965's vec4_visitor and fs_visitor classes. v3 (Paul Berry <stereotype441@gmail.com>): Rename classes to be more consistent with the names used in the GL spec. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-06-13glsl: Fix null check in read_dereference.Vinson Lee1-1/+1
Fixes "Logically dead code" defect reported by Coverity. Signed-off-by: Vinson Lee <vlee@freedesktop.org> Reviewed-by: Brian Paul <brianp@vmware.com>
2013-05-06glsl: Rework ir_reader to handle expressions with four operands.Matt Turner1-4/+6
Needed to support the bitfieldInsert() built-in added by ARB_gpu_shader5. Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2013-03-29glsl: Implement ARB_texture_query_lodDave Airlie1-5/+9
v2 [mattst88]: - Rebase. - #define GL_ARB_texture_query_lod to 1. - Remove comma after ir_lod in ir.h for MSVC. - Handled ir_lod in ir_hv_accept.cpp, ir_rvalue_visitor.cpp, opt_tree_grafting.cpp. - Rename textureQueryLOD to textureQueryLod, see https://www.khronos.org/bugzilla/show_bug.cgi?id=821 - Fix ir_reader of (lod ...). v3 [mattst88]: - Rename textureQueryLod to textureQueryLOD, pending resolution of Khronos 821. - Add ir_lod case to ir_to_mesa.cpp. Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-03-02glsl: add support for ARB_texture_multisampleChris Forbes1-9/+23
V2: - emit `sample` parameter properly for multisample texelFetch() - fix spurious whitespace change - introduce a new opcode ir_txf_ms rather than overloading the existing ir_txf further. This makes doing the right thing in the driver somewhat simpler. V3: - fix weird whitespace V4: - don't forget to include the new opcode in tex_opcode_strs[] (thanks Kenneth for spotting this) Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> [V2] Reviewed-by: Eric Anholt <eric@anholt.net> [V2] Reviewed-by: Paul Berry <stereotype441@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-02-28glsl: Rework ir_reader to handle expressions with three operands.Kenneth Graunke1-26/+19
Reviewed-by: Matt Turner <mattst88@gmail.com> Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-24glsl: Eliminate ambiguity between function ins/outs and shader ins/outsPaul Berry1-3/+7
This patch replaces the three ir_variable_mode enums: - ir_var_in - ir_var_out - ir_var_inout with the following five: - ir_var_shader_in - ir_var_shader_out - ir_var_function_in - ir_var_function_out - ir_var_function_inout This eliminates a frustrating ambiguity: it used to be impossible to tell whether an ir_var_{in,out} variable was a shader in/out or a function in/out without seeing where the variable was declared in the IR. This complicated some optimization and lowering passes, and would have become a problem for implementing varying structs. In the lisp-style serialization of GLSL IR to strings performed by ir_print_visitor.cpp and ir_reader.cpp, I've retained the names "in", "out", and "inout" for function parameters, to avoid introducing code churn to the src/glsl/builtins/ir/ directory. Note: a couple of comments in the code seemed to indicate that we were planning for a possible future in which geometry shaders could have shader-scope inout variables. Our GLSL grammar rejects shader-scope inout variables, and I've been unable to find any evidence in the GLSL standards documents (or extensions) that this will ever be allowed, so I've eliminated these comments. Reviewed-by: Carl Worth <cworth@cworth.org> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2012-04-24glsl: Make ir_reader parse the "temporary" variable qualifier.Eric Anholt1-0/+2
This lets ir_reader eat the output of builtin_compiler on actual function definitions. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-04-02glsl: Convert ir_call to be a statement rather than a value.Kenneth Graunke1-7/+25
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 <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-04-02glsl: Split out ir_reader's ability to read ir_dereference_variables.Kenneth Graunke1-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 <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2011-10-28glsl: Remove pointless uses of glsl_type::get_base_type().Kenneth Graunke1-4/+2
These are effectively doing type->get_base_type()->base_type, which is equivalent to type->base_type. Just use that, as it's simpler. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2011-10-27mesa: Expose GLSL interpolation qualifiers in gl_fragment_program.Paul Berry1-3/+3
This patch makes GLSL interpolation qualifiers visible to drivers via the array InterpQualifier[] in gl_fragment_program, so that they can easily be used by driver back-ends to select the correct interpolation mode. Previous to this patch, the GLSL compiler was using the enum ir_variable_interpolation to represent interpolation types. Rather than make a duplicate enum in core mesa to represent the same thing, I moved the enum into mtypes.h and renamed it to be more consistent with the other enums defined there. Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net>
2011-09-23glsl: Free all S-Expressions immediately after reading IR.Kenneth Graunke1-2/+3
For some reason I thought subexpressions were chained off the top-level one. This isn't the case, so just create a temporary context and free it. All of this memory would be eventually freed, but now is freed much sooner. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2011-09-07glsl: s/int/unsigned/ to silence warningBrian Paul1-2/+2
2011-09-07glsl/ir_reader: Make sure constants have the right number of components.Kenneth Graunke1-0/+5
The list of numbers in (constant type (<numbers>)) needs to contain exactly type->components() numbers (16 for a mat4, 3 for a vec3, etc.) Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2011-08-23glsl: Add a new ir_txs (textureSize) opcode to ir_texture.Kenneth Graunke1-15/+22
One unique aspect of TXS is that it doesn't have a coordinate. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Dave Airlie <airlied@redhat.com>
2011-07-08glsl: Make ir_reader able to read plain (return) statements.Paul Berry1-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 <kenneth@whitecape.org>
2011-03-14glsl: Explicitly specify a type when reading/printing ir_texture.Kenneth Graunke1-4/+13
This is necessary for GLSL 1.30+ shadow sampling functions, which return a single float rather than splatting the value to a vec4 based on GL_DEPTH_TEXTURE_MODE.
2011-01-31glsl: Introduce a new "const_in" variable mode.Kenneth Graunke1-0/+2
This annotation is for an "in" function parameter for which it is only legal to pass constant expressions. The only known example of this, currently, is the textureOffset functions. This should never be used for globals.
2011-01-31glsl: Change texel offsets to a single vector rvalue.Kenneth Graunke1-12/+9
Having these as actual integer values makes it difficult to implement the texture*Offset built-in functions, since the offset is actually a function parameter (which doesn't have a constant value). The original rationale was that some hardware needs these offset baked into the instruction opcode. However, at least i965 should be able to support non-constant offsets. Others should be able to rely on inlining and constant propagation.
2011-01-31Convert everything from the talloc API to the ralloc API.Kenneth Graunke1-10/+8
2011-01-25glsl: silence uninitialized var warning in read_texture()Brian Paul1-1/+4
And generate an error if the texture pattern is not matched.
2011-01-21glsl, i965: Remove unnecessary talloc includes.Kenneth Graunke1-4/+0
These are already picked up by ir.h or glsl_types.h.
2011-01-12ir_reader: Make assignment conditions optional.Kenneth Graunke1-8/+13
You can now simply write (assign (xy) <lhs> <rhs>) instead of the verbose (assign (constant bool (1)) (xy) <lhs> <rhs>).
2011-01-12ir_reader: Convert to a class.Kenneth Graunke1-238/+241
This makes it unnecessary to pass _mesa_glsl_parse_state around everywhere, making at least the prototypes a lot easier to read. It's also more C++-ish than a pile of static C functions.
2011-01-12ir_reader: Combine the three dereference reading functions into one.Kenneth Graunke1-83/+36
These used to be more complicated, but now are so simple there's no real point in keeping them separate.
2011-01-12ir_reader: Relax requirement that function arguments be s_lists.Kenneth Graunke1-85/+78
All of these functions used to take s_list pointers so they wouldn't all need SX_AS_LIST conversions and error checking. However, the new pattern matcher conveniently does this for us in one centralized place. So there's no need to insist on s_list. Switching to s_expression saves a bit of code and is somewhat cleaner.
2011-01-12ir_reader: Remove s_list::length() method.Kenneth Graunke1-7/+8
Most code now relies on the pattern matcher rather than this function, and for the only remaining case, not using this saves an iteration.
2011-01-12ir_reader: Add a pattern matching system and use it everywhere.Kenneth Graunke1-308/+210
Previously, the IR reader was riddled with code that: 1. Checked for the right number of list elements (via a linked list walk) 2. Retrieved references to each component (via ->next->next pointers) 3. Downcasted as necessary to make sure that each sub-component was the right type (i.e. symbol, int, list). 4. Checking that the tag (i.e. "declare") was correct. This was all very ad-hoc and a bit ugly. Error checking had to be done at both steps 1, 3, and 4. Most code didn't even check the tag, relying on the caller to do so. Not all callers did. The new pattern matching module performs the whole process in a single straightforward function call, resulting in shorter, more readable code. Unfortunately, MSVC does not support C99-style anonymous arrays, so the pattern must be declared outside of the match call.
2010-11-29glsl: Make the symbol table's add_variable just use the variable's name.Eric Anholt1-1/+1
2010-11-29glsl: Make the symbol table's add_function just use the function's name.Eric Anholt1-1/+1
2010-11-03ir_reader: Fix some potential NULL pointer dereferences.Kenneth Graunke1-4/+4
Found by inspection.
2010-11-03ir_reader: Remove useless error check.Kenneth Graunke1-6/+0
It's already been determined that length == 3, so clearly swiz->next is a valid S-Expression.
2010-11-03ir_reader: Return a specific ir_dereference variant.Kenneth Graunke1-6/+9
There's really no reason to return the base class when we have more specific information about what type it is.
2010-09-07glsl: Move is_builtin flag back to ir_function_signature.Kenneth Graunke1-1/+1
This effectively reverts b6f15869b324ae64a00d0fe46fa3c8c62c1edb6c. In desktop GLSL, defining a function with the same name as a built-in hides that built-in function completely, so there would never be built-in and user function signatures in the same ir_function. However, in GLSL ES, overloading built-ins is allowed, and does not hide the built-in signatures - so we're back to needing this.
2010-09-05ir_reader: Only validate IR when a global 'debug' flag is set.Kenneth Graunke1-1/+4
This extra validation is very useful when working on the built-ins, but in general overkill - the results should stay the same unless the built-ins or ir_validate have changed. Also, validating all the built-in functions in every test case makes piglit run unacceptably slow.
2010-09-04ir_reader: Run ir_validate on the generated IR.Kenneth Graunke1-0/+2
It's just too easy to get something wrong in hand-written IR.
2010-09-04ir_reader: Emit global variables at the top of the instruction list.Kenneth Graunke1-2/+11
Since functions are emitted when scanning for prototypes, functions always come first, even if the original IR listed the variable declarations first. Fixes an ir_validate error (to be turned on in the next commit).
2010-09-04ir_reader: Drop support for reading the old assignment format.Kenneth Graunke1-6/+4
2010-09-04ir_reader: Read the new assignment format (with write mask).Kenneth Graunke1-6/+46
This preserves the ability to read the old format, for momentary compatibility with all the existing IR implementations of built-ins.
2010-09-04ir_reader: Track the current function and report it in error messages.Kenneth Graunke1-0/+6
2010-08-29glsl: Initialize data in read_constant.Vinson Lee1-1/+1
Completely initialize data that is passed into a ir_constant constructor. Fixes piglit glsl-fs-mix valgrind uninitialized variable error on softpipe and llvmpipe.
2010-08-26glsl: Move is_built_in flag from ir_function_signature to ir_function.Kenneth Graunke1-1/+1
Also rename it to "is_builtin" for consistency. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-08-13glsl2: Rework builtin function generation.Kenneth Graunke1-8/+16
Each language version/extension and target now has a "profile" containing all of the available builtin function prototypes. These are written in GLSL, and come directly out of the GLSL spec (except for expanding genType). A new builtins/ir/ folder contains the hand-written IR for each builtin, regardless of what version includes it. Only those definitions that have prototypes in the profile will be included. The autogenerated IR for texture builtins is no longer written to disk, so there's no longer any confusion as to what's hand-written or generated. All scripts are now in python instead of perl.