Commit Graph

73 Commits

Author SHA1 Message Date
Francisco Jerez 26db3b933f glsl: Add new atomic_uint built-in GLSL type.
v2: Fix GLSL version in which the type became available.  Add
    contains_atomic() convenience method.  Split off atomic counter
    comparison error checking to a separate patch that will handle all
    opaque types.  Include new ir_variable fields for atomic types.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-10-29 12:40:55 -07:00
Paul Berry 99512dc40d glsl: Keep track of centroid/interpolation mode for interface block members.
Fixes piglit tests:
- interface-block-interpolation-{array,named,unnamed}
- glsl-1.50-interface-block-centroid {array,named,unnamed}

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
2013-10-24 22:01:10 -07:00
Paul Berry 6a157f2e33 glsl: Account for location field when comparing interface blocks.
In commit e2660770731b018411fbe1620cacddaf8dff5287 (glsl: Keep track
of location for interface block fields), I neglected to update
glsl_type::record_key_compare to account for the fact that interface
types now contain location information.  As a result, interface types
that differ only by their location information would not be properly
distinguished.

At the moment this is not a problem, because the only interface block
in which location information != -1 is gl_PerVertex, and gl_PerVertex
is always created in the same way.  However, in the patches that
follow, we'll be adding new ways to create gl_PerVertex (by
redeclaring it), so we'll need location information to be handled
properly.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-10-10 14:27:03 -07:00
Paul Berry 8cf35c3d2f glsl: Rename the fourth argument to get_interface_instance.
Interface declarations have two names associated with them: the block
name and the instance name.  It's the block name that needs to be
passed to get_interface_instance().  This patch renames the argument
so that there's no confusion.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-10-09 16:49:16 -07:00
Paul Berry 378ff1dbac glsl: Keep track of location for interface block fields.
This patch adds a "location" element to struct glsl_struct_field, so
that we can keep track of the gl_varying_slot associated with each
built-in geometry shader input.

In lower_named_interface_blocks, we use this value to populate the
"location" field in the ir_variable that stores each geometry shader
input.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2013-10-08 12:44:01 -07:00
Kenneth Graunke 694be9115d glsl: Add a new glsl_type::sampler_coordinate_components() function.
This computes the number of components necessary to address a sampler
based on its dimensionality.  It will be useful for texturing built-ins.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2013-09-11 22:48:32 -07:00
Paul Berry 7d95d2b4c9 glsl: Expand count_attribute_slots() to cover structs.
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-08-01 20:19:22 -07:00
Paul Berry 0026ad4994 Move count_attribute_slots() out of the linker and into glsl_type.
Our previous justification for leaving this function out of glsl_type
was that it implemented counting rules that were specific to GLSL
1.50.  However, these counting rules also describe the number of
varying slots that Mesa will assign to a varying in the absence of
varying packing.  That's useful to be able to compute from outside of
the linker code (a future patch will use it from
ir_set_program_inouts.cpp).  So go ahead and move it to glsl_type.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-08-01 20:19:02 -07:00
Ian Romanick 803f755ede glsl: Less const for glsl_type convenience accessors
The second 'const' says that the pointer itself is constant.  This in
unenforcible in C++, so GCC emits a warning (see) below for each of
these functions in every file that includes glsl_types.h.  It's a lot of
warning spam.

../../../src/glsl/glsl_types.h:176:58: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Cc: mesa-stable@lists.freedesktop.org
2013-07-27 12:13:03 -07:00
Kenneth Graunke 4563dfe23a glsl: Streamline the built-in type handling code.
Over the last few years, the compiler has grown to support 7 different
language versions and 6 extensions that add new built-in types.  With
more and more features being added, some of our core code has devolved
into an unmaintainable spaghetti of sorts.

A few problems with the old code:
1. Built-in types are declared...where exactly?

   The types in builtin_types.h were organized in arrays by the language
   version or extension they were introduced in.  It's factored out to
   avoid duplicates---every type only exists in one array.  But that
   means that sampler1D is declared in 110, sampler2D is in core types,
   sampler3D is a unique global not in a list...and so on.

2. Spaghetti call-chains with weird parameters:

   generate_300ES_types calls generate_130_types which calls
   generate_120_types and generate_EXT_texture_array_types, which calls
   generate_110_types, which calls generate_100ES_types...and more

   Except that ES doesn't want 1D types, so we have a skip_1d parameter.
   add_deprecated also falls into this category.

3. Missing type accessors.

   Common types have convenience pointers (like glsl_type::vec4_type),
   but others may not be accessible at all without a symbol table (for
   example, sampler types).

4. Global variable declarations in a header file?

   #include "builtin_types.h" in two C++ files would break the build.

The new code addresses these problems.  All built-in types are declared
together in a single table, independent of when they were introduced.
The macro that declares a new built-in type also creates a convenience
pointer, so every type is available and it won't get out of sync.

The code to populate a symbol table with the appropriate types for a
particular language version and set of extensions is now a single
table-driven function.  The table lists the type name and GL/ES versions
when it was introduced (similar to how the lexer handles reserved
words).  A single loop adds types based on the language version.
Explicit extension checks then add additional types.  If they were
already added based on the language version, glsl_symbol_table simply
ignores the request to add them a second time, meaning we don't need
to worry about duplicates and can simply list types where they belong.

v2: Mark uvecs and shadow samplers as ES3 only, and 1DArrayShadow as
    unsupported in ES entirely.  Add a touch more doxygen.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
2013-06-26 11:25:12 -07:00
Kenneth Graunke 4530ed4f26 glsl: Stop being clever with pointer arithmetic when fetching types.
Currently, vector types are linked together closely: the glsl_type
objects for float, vec2, vec3, and vec4 are all elements of the same
array, in that exact order.  This makes it possible to obtain vector
types via pointer arithmetic on the scalar type's convenience pointer.
For example, float_type + (3 - 1) = vec3.

However, relying on this is extremely fragile.  There's no particular
reason the underlying type objects need to be stored in an array.  They
could be individual class members, possibly with padding between them.
Then the pointer arithmetic would break, and we'd get bad pointers to
non-heap allocated data, causing subtle breakage that can't be detected
by valgrind.  Cue insanity.

Or someone could simply reorder the type variables, causing us to get
the wrong type entirely.  Also cue insanity.

Writing this explicitly is much safer.  With the new helper functions,
it's a bit less code even.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
2013-06-26 11:25:12 -07:00
Kenneth Graunke d367a1cbdb glsl: Add simple vector type accessor helpers.
This patch introduces new functions to quickly grab a pointer to a
vector type.  For example:

   glsl_type::bvec(4)   returns   glsl_type::bvec4_type
   glsl_type::ivec(3)   returns   glsl_type::ivec3_type
   glsl_type::uvec(2)   returns   glsl_type::uvec2_type
   glsl_type::vec(1)    returns   glsl_type::float_type

This is less wordy than glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1),
which can help avoid extra word wrapping.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
2013-06-26 11:25:12 -07:00
Paul Berry 5b0bd8ece8 glsl: Fix (and validate) comment above glsl_type::name.
The comment above glsl_type::name claimed that it could sometimes be
NULL.  This was wrong--it is never NULL.  Many error handling paths
would segfault if it were.  (Anonymous structs are assigned names like
"#anon_struct_0001"--see the ast_struct_specifier constructor in
glsl_parser_extras.cpp.)

Fix the comment and add assertions to validate that it really is never
NULL.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-04-11 09:25:24 -07:00
Ian Romanick c770faea0a glsl: Add missing bool case in glsl_type::get_scalar_type
Since the case was missing bec4->get_scalar_type() would return bvec4,
but vec4->get_scalar_type() would return float.

NOTE: This is a candidate for stable branches.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2013-03-29 12:01:01 -07:00
Kenneth Graunke bcdda04349 glsl: Add sampler2DMS/sampler2DMSArray types to GLSL 1.50.
GLSL 1.50 includes support for the new sampler types introduced by
the ARB_texture_multisample extension.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2013-03-20 10:38:38 -07:00
Chris Forbes ffb53b4f03 glsl: add support for ARB_texture_multisample
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-03-02 11:33:54 +13:00
Jordan Justen 500b69e797 glsl: allow GLSL compiler version to be overridden to 1.50
Although GLSL 1.50 compiler support is not available,
this change will allow MESA_GLSL_VERSION_OVERRIDE=150 to be
used while 1.50 support is being developed.

Since no drivers claim 1.50 GLSL support, this change should
only impact Mesa when MESA_GLSL_VERSION_OVERRIDE=150 is set.

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-02-28 21:49:59 -08:00
Paul Berry 93c913485e glsl: don't allow non-flat integral types in varying structs/arrays.
In the GLSL 1.30 spec, section 4.3.6 ("Outputs") says:

    "If a vertex output is a signed or unsigned integer or integer
    vector, then it must be qualified with the interpolation qualifier
    flat."

The GLSL ES 3.00 spec further clarifies, in section 4.3.6 ("Output
Variables"):

    "Vertex shader outputs that are, *or contain*, signed or unsigned
    integers or integer vectors must be qualified with the
    interpolation qualifier flat."

(Emphasis mine.)

The language in the GLSL ES 3.00 spec is clearly correct and should be
applied to all shading language versions, since varyings that contain
ints can't be interpolated, regardless of which shading language
version is in use.

(Note that in GLSL 1.50 the restriction is changed to apply to
fragment shader inputs rather than vertex shader outputs, to
accommodate the fact that in the presence of geometry shaders, vertex
shader outputs are not necessarily interpolated.  That will be
addressed by a future patch).

NOTE: This is a candidate for stable branches.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
2013-02-13 07:58:01 -08:00
Vinson Lee 85a9a7f09c glsl: Ensure glsl_type constructors initialize gl_type.
Fixes uninitialized scalar field defects reported by Coverity.

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
2013-02-08 18:50:08 -08:00
Ian Romanick 11d42de681 glsl: Make the align function available elsewhere in the linker
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
2013-01-25 09:07:35 -05:00
Ian Romanick 491364e1f3 glsl: Add GLSL_TYPE_INTERFACE
Interfaces are structurally identical to structures from the compiler's
point of view.  They have some additional restrictions, and generally
GPUs use different instructions to access them.  Using a different base
type should make this a bit easier.

This commit also adds the glsl_type::interface_packing fields.  For
GLSL_TYPE_INTERFACE types, this will track the specified packing mode.
It is analogous to gl_uniform_buffer::_Packing.

v2: Add serveral missing GLSL_TYPE_INTERFACE cases in switch-statements.

v3: Add information about glsl_type::interface_packing.  Move row_major
checking in glsl_type::record_key_compare from this patch to the
previous patch.  Both suggested by Paul Berry.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-25 09:07:33 -05:00
Ian Romanick 7f96a8471e glsl: Add row_major field to glsl_struct_field
For now, this will always be false.  In the near future, an "interface"
type will be added that shares a lot of infrastructure with structures.

v2: Move row_major checking in glsl_type::record_key_compare from the
next patch to this patch.  Suggested by Paul Berry.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-25 09:07:33 -05:00
Ian Romanick ecfb404e8d glsl: Replace most default cases in switches on GLSL type
This makes it easier to find switch-statements that need to be updated
after a new GLSL_TYPE_* is added because the compiler will generate a
warning.

Switch-statements that only had a small number of cases (e.g.,
everything in ir_constant_expression.cpp) were not modified.  I may
regret that decision when we eventually add support for doubles.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-01-25 09:07:32 -05:00
Paul Berry d7949eefcb glsl: Populate built-in types correctly for GLSL 3.00 ES.
This patch implements all of the built-in types for GLSL 3.00 ES.
This is almost exactly the same as the set of built-in types for GLSL
1.30, except ate 1D samplers are skipped, and samplerCubeShadow is
added.

This patch also addes an assertion so that when we add new GLSL
versions, we'll notice that we need to update the types.

In review, Eric noted:

    "This change looks correct.  The overall interaction of profiles is
    getting ugly, though.  I'm imagining a restructure of the symbol
    table population so that there's a big list of types, and each
    #version has a nice list of strings of type names copy and pasted
    out of its spec."

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06 12:13:22 -08:00
Paul Berry e3ded7fe62 glsl: Make use of new _mesa_glsl_parse_state::is_version() function.
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06 12:13:21 -08:00
Dave Airlie 4c8750015b glsl: add ARB_texture_cube_map_array support (v2)
This adds all the new builtins + the new sampler types,
and hooks them up if the extension is supported.

v2: fix missing signatures for grad/lod
fix missing textureSize clarifications
fix compare vs starts with usage

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-11-09 10:26:33 +10:00
Eric Anholt ffb2d43059 glsl: Fix calculation of std140 offset alignment for mat2s.
We were getting the base offset of a vec2, not of a vec2[2] like the quoted
spec text says we should.

v2: Fix swapped then/else cases.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-08-07 13:54:50 -07:00
Eric Anholt 8ab5842a6d glsl: Assign locations for uniforms in UBOs using the std140 rules.
Fixes piglit layout-std140.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-07-20 10:44:04 -07:00
Eric Anholt 6598552521 glsl: Add support for parsing [iu]samplerBuffer types in GLSL 1.40.
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 <kenneth@whitecape.org>
2012-04-09 14:34:06 -07:00
Eric Anholt 0225a15b69 glsl: Don't include the deprecated structure types in GLSL 1.40.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-03-19 22:14:02 -07:00
Eric Anholt 3645b77b71 glsl: Add support for integer sampler2DRect variants in GLSL 1.40.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-03-15 16:24:50 -07:00
Eric Anholt c5ff9a8b9e glsl: Hook up the current GLSL 1.30 types and builtins for 1.40.
This gets a basic #version 140 shader compiling.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-03-15 08:33:54 -07:00
Vinson Lee e9bcf4d56b glsl: Fix 'control reaches end of non-void function' warning.
Fix this GCC warning on non-debug builds.
glsl_types.cpp: In member function 'gl_texture_index
glsl_type::sampler_index() const':
glsl_types.cpp:157: warning: control reaches end of non-void function

NOTE: This is a candidate for the 8.0 branch.

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-01-20 23:53:59 -08:00
Ian Romanick 32be81de39 glsl: Add glsl_type::sampler_index
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2012-01-11 12:51:24 -08:00
Chia-I Wu 2903816aad glsl: add support for GL_OES_EGL_image_external
This extension introduces a new sampler type: samplerExternalOES.
texture2D (and texture2DProj) can be used to do a texture look up in an
external texture.

Reviewed-by: Brian Paul <brianp@vmware.com>
Acked-by: Jakob Bornecrantz <jakob@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2011-11-03 15:09:44 +08:00
Paul Berry fa0066ae2b mesa: Add glsl_type::get_scalar_type() function.
This function is similar to get_base_type(), but when called on
arrays, it returns the scalar type composing the array.  For example,
glsl_type(vec4[]) => float_type.

Acked-by: Kenneth Graunke <kenneth@whitecape.org>
2011-10-31 11:29:14 -07:00
Chad Versace 200e4972c1 glsl: Add method glsl_type::can_implicitly_convert_to()
This method checks if a source type is identical to or can be implicitly
converted to a target type according to the GLSL 1.20 spec, Section 4.1.10
Implicit Conversions.

The following commits use the method for a bugfix:
    glsl: Fix implicit conversions in non-constructor function calls
    glsl: Fix implicit conversions in array constructors

Note: This is a candidate for the 7.10 and 7.11 branches.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Chad Versace <chad@chad-versace.us>
2011-07-30 07:26:59 -07:00
Paul Berry ddc1c96390 glsl: Move type_contains_sampler() into glsl_type for later reuse.
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.
2011-07-18 10:48:27 -07:00
Kenneth Graunke 0a163cf56d glsl: Enable GL_OES_texture_3D extension for ES2. 2011-02-28 10:35:57 -08:00
Ian Romanick 497baf4e4a Use C-style system headers in C++ code to avoid issues with std:: namespace 2011-02-21 13:07:29 -08:00
Kenneth Graunke d3073f58c1 Convert everything from the talloc API to the ralloc API. 2011-01-31 10:17:09 -08:00
Kenneth Graunke 5c229e5fbd glsl: Expose a public glsl_type::void_type const pointer.
This is analogous to glsl_type::int_type and all the others.
2010-12-17 10:55:17 -08:00
Kenneth Graunke 5dc74e9c77 glsl: Convert glsl_type::base_type from #define'd constants to an enum.
This is nice because printing type->base_type in GDB will now give you a
readable name instead of a number.
2010-11-15 13:33:57 -08:00
Kenneth Graunke 76deef138e glsl: Split out types that are in 1.10 but not GLSL ES 1.00. 2010-09-07 17:30:37 -07:00
Ian Romanick 4d6221f90d glsl2: Remove unused method glsl_type::generate_constructor 2010-09-01 20:39:09 -07:00
Kenneth Graunke e9c7ceed27 glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.

However, in 1.10, variables and functions can share the same name in the
same scope.  Structure types, however, conflict with/hide both.

Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-26 09:19:48 -07:00
Vinson Lee e5df3cc286 glsl: Silence unused variable warning.
The variable is used but only in the body of an assert.
2010-08-23 22:27:49 -07:00
Chia-I Wu bfd7c9ac22 glsl: Include main/core.h.
Make glsl include only main/core.h from core mesa.
2010-08-24 11:27:29 +08:00
Eric Anholt 8dd619ba68 glsl: Rely on talloc_autofree_context() instead of trying to free on our own.
Because the static types talloc their names at dlopen time,
talloc_freeing the types at DRI driver screen teardown means that if
the screen gets brought back up again, the names will point at freed
memory.  talloc_autofree_context() exists to do just what we want
here: Free memory referenced across the program's lifetime so that we
avoid noise in memory leak checkers.

Fixes: bug #29722 (assertion failure in unigine).
2010-08-23 17:25:38 -07:00
Ian Romanick 6dad5a4e8d glsl2: Include imports.h to get snprintf wrapper for MSVC
Signed-off-by: José Fonseca <jfonseca@vmware.com>
2010-08-23 20:55:50 +01:00