Commit graph

320 commits

Author SHA1 Message Date
Ian Romanick
3322fbaf3b glsl: Slightly change the semantic of _LinkedShaders
Previously _LinkedShaders was a compact array of the linked shaders
for each shader stage.  Now it is arranged such that each slot,
indexed by the MESA_SHADER_* defines, refers to a specific shader
stage.  As a result, some slots will be NULL.  This makes things a
little more complex in the linker, but it simplifies things in other
places.

As a side effect _NumLinkedShaders is removed.

NOTE: This may be a candidate for the 7.9 branch.  If there are other
patches that get backported to 7.9 that use _LinkedShader, this patch
should be cherry picked also.
2010-10-14 17:16:59 -07:00
Ian Romanick
4a45595cf3 linker: Reject shaders that have unresolved function calls
This really amounts to just using the return value from
link_function_calls.  All the work was being done, but the result was
being ignored.

Fixes piglit test link-unresolved-funciton.

NOTE: this is a candidate for the 7.9 branch.
2010-10-13 15:30:19 -07:00
Kristian Høgsberg
f9995b3075 Drop GLcontext typedef and use struct gl_context instead 2010-10-13 09:43:25 -04:00
Ian Romanick
68a4fc9d5a glsl: Add linker support for explicit attribute locations 2010-10-08 14:21:23 -07:00
Ian Romanick
4b5489dd6f glsl: Fail linking if assign_attribute_locations fails 2010-10-08 14:21:22 -07:00
Eric Anholt
586b4b500f glsl: Also update implicit sizes of varyings at link time.
Otherwise, we'll often end up with gl_TexCoord being 0 length, for
example.  With ir_to_mesa, things ended up working out anyway, as long
as multiple implicitly-sized arrays weren't involved.
2010-09-28 14:37:26 -07:00
Brian Paul
2b95525429 glsl2: fix typo in error msg 2010-09-21 14:57:10 -06:00
Luca Barbieri
e591c4625c glsl: add several EmitNo* options, and MaxUnrollIterations
This increases the chance that GLSL programs will actually work.

Note that continues and returns are not yet lowered, so linking
will just fail if not supported.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-09-08 20:36:37 -07:00
Kenneth Graunke
f412fac5b4 glsl: Move is_builtin flag back to ir_function_signature.
This effectively reverts b6f15869b3.

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-07 17:30:38 -07:00
Kenneth Graunke
5a81d057db linker: Fix assertion and cross-version checks for version 100.
Fixes an assert (min_version >= 110) which was no longer correct, and
also prohibits linking ES2 shaders with non-ES2 shaders.  I'm not
positive this is correct, but the specification doesn't seem to say.
2010-09-07 17:30:38 -07:00
Török Edvin
c47b289972 glsl2: check for _NumLinkedShaders being 0
Otherwise spring 0.82+.4.0 crashes when starting a game
because prog->_LinkedShaders[0] is NULL.

This also fixes piglit test cases glsl-link-empty-prog-0[12].
2010-09-07 12:27:07 -07:00
Ian Romanick
df869d9163 linker: Handle varying arrays, matrices, and arrays of matrices
Fixes piglit test case glsl-array-varying-01.
2010-08-30 16:02:51 -07:00
Ian Romanick
a2711d6968 linker: Treat sized and unsized array types as the same
If two shaders contain variables declared with array types that have
the same base type but one is sized and the other is not, linking
should succeed.  I'm not super pleased with the way this is
implemented, and I am more convinced than ever that we need more
linker tests.  We especially need "negative" tests.

Fixes bugzilla #29697 and piglit test glsl-link-array-01.
2010-08-29 22:11:35 -07:00
Kenneth Graunke
b6f15869b3 glsl: Move is_built_in flag from ir_function_signature to ir_function.
Also rename it to "is_builtin" for consistency.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-08-26 09:19:48 -07:00
Eric Anholt
0924ba0c34 ir_to_mesa: Convert this code to using linker.cpp's uniform locations.
Fixes: glsl-fs-uniform-array-4.
2010-08-25 12:38:26 -07:00
Eric Anholt
45388b5467 glsl: Make uniform linking generate separate uniforms for struct members.
This is a step towards making the linker code usable as our uniform
setup, instead of having it wedged into ir_to_mesa.cpp.
2010-08-25 12:38:26 -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
18a6023900 glsl: Count function call outvals as writing to variables for linker checks.
Fixes: glsl-vs-position-outval.  Bug #28138 (regnum online)
2010-08-23 12:57:59 -07:00
Eric Anholt
a721abfbd1 glsl: Trim the size of uniform arrays to the maximum element used.
Fixes glsl-getactiveuniform-array-size.
2010-08-23 10:34:31 -07:00
Eric Anholt
f1d5a94197 glsl: Also strdup the names of uniform list entries for >vec4 types.
Fixes double-free since the fix to free all of the uniform list.
2010-08-18 17:45:08 -07:00
Eric Anholt
5d0f430e8e mesa: Free old linked shaders when relinking new shaders. 2010-08-18 14:16:07 -07:00
Ian Romanick
40e114b5dc linker: Demote user-defined varyings in the VS-only case
Fixes piglit test case glsl-vs-ff-frag and bugzilla #29623.
2010-08-17 14:57:18 -07:00
Ian Romanick
45d97dd6d5 linker: Include compiler.h to avoid spurious warnings about INLINE 2010-08-16 13:59:34 -07:00
Eric Anholt
2f4fe15168 glsl2: Move the common optimization passes to a helper function.
These are passes that we expect all codegen to be happy with.  The
other lowering passes for Mesa IR are moved to the Mesa IR generator.
2010-08-13 17:47:00 -07:00
Ian Romanick
c33e78f62b linker: Assign attrib location 0 if gl_Vertex is not used
If gl_Vertex is not used in the shader, then attribute location 0 is
available for use.

Fixes piglit test case glsl-getattriblocation (bugzilla #29540).
2010-08-13 14:50:48 -07:00
Eric Anholt
5854d4583c glsl2: Add a pass to transform ir_binop_sub to add(op0, neg(op1))
All the current HW backends transform subtract to adding the negation,
so I haven't bothered peepholing it back out in Mesa IR.  This allows
some subtract of subtract to get removed in ir_algebraic.
2010-08-09 21:41:14 -07:00
Eric Anholt
8bebbeb7c5 glsl2: Add constant propagation.
Whereas constant folding evaluates constant expressions at rvalue
nodes, constant propagation tracks constant components of vectors
across execution to replace (possibly swizzled) variable dereferences
with constant values, triggering possible constant folding or reduced
variable liveness.
2010-08-09 19:21:18 -07:00
Eric Anholt
8d61a23b1a glsl2: Don't assert in a couple of places when encountering sampler arrays.
Fixes glean shaderAPI.
2010-08-06 00:42:59 -07:00
Eric Anholt
bc4034b243 glsl2: Add a pass to convert exp and log to exp2 and log2.
Fixes ir_to_mesa handling of unop_log, which used the weird ARB_vp LOG
opcode that doesn't do what we want.  This also lets the multiplication
coefficients in there get constant-folded, possibly.

Fixes:
glsl-fs-log
2010-08-05 15:34:00 -07:00
Eric Anholt
7f7eaf0285 ir_structure_splitting: New pass to chop structures into their components.
This doesn't do anything if your structure goes through an uninlined
function call or if whole-structure assignment occurs.  As such, the
impact is limited, at least until we do some global copy propagation
to reduce whole-structure assignment.
2010-08-05 12:56:03 -07:00
Eric Anholt
2e853ca23c glsl2: Add a pass for removing unused functions.
For a shader involving many small functions, this avoids running
optimization across all of them after they've been inlined
post-linking.

Reduces the runtime of linking and running a fragment shader from Yo
Frankie from 1.6 seconds to 0.9 seconds (-44.9%, +/- 3.3%).
2010-08-05 10:18:31 -07:00
Eric Anholt
046bef2357 glsl2: Remove the shader_in/shader_out tracking separate from var->mode.
I introduced this for ir_dead_code to distinguish function parameter
outvals from varying outputs.  Only, since ast_to_hir's
current_function is unset when setting up function parameters (they're
needed for making the function signature in the first place), all
function parameter outvals were marked as shader outputs anyway.  This
meant that an inlined function's cloned outval was marked as a shader
output and couldn't be dead-code eliminated.  Instead, since
ir_dead_code doesn't even look at function parameters, just use
var->mode.

The longest Mesa IR coming out of ir_to_mesa for Yo Frankie drops from
725 instructions to 636.
2010-08-04 20:52:33 -07:00
Eric Anholt
e3a90b8e38 glsl2: Use linked ir_constant_variable after linking, instead of unlinked. 2010-08-04 20:52:33 -07:00
Eric Anholt
b6ceddc371 glsl2: Don't try to assign locations for samplers during linking.
Mesa will do the mapping at _mesa_add_sampler() time.  Fixes assertion
failures in debug builds, which might have caught real problems with
multiple samplers linked in a row.
2010-08-04 14:28:57 -07:00
Eric Anholt
8273bd4687 glsl2: Make the clone() method take a talloc context.
In most cases, we needed to be reparenting the cloned IR to a
different context (for example, to the linked shader instead of the
unlinked shader), or optimization before the reparent would cause
memory usage of the original object to grow and grow.
2010-08-04 12:42:47 -07:00
Aras Pranckevicius
31747155ea glsl2: Give the path within src/mesa/ for headers instead of relying on -I. 2010-08-02 10:59:46 -07:00
Eric Anholt
f6b03f3235 glsl2: Do algebraic optimizations after linking as well.
Linking brings in inlining of builtins, so we weren't catching the
(rcp(/sqrt(x)) -> rsq(x)) without it.
2010-07-31 15:52:24 -07:00
Eric Anholt
784695442c glsl2: Add new tree grafting optimization pass. 2010-07-31 15:52:21 -07:00
Eric Anholt
62c4763b70 glsl2: Fix spelling of "sentinel." 2010-07-29 14:02:19 -07:00
Eric Anholt
b706283c79 glsl2: Fail linking where the FS reads a varying that the VS doesn't write.
Fixes:
glsl1-varying read but not written
glsl1-varying var mismatch
2010-07-28 14:04:54 -07:00
Eric Anholt
a6c7606ab6 glsl2: Unmark unwritten varyings as varying.
This fixes an assertion failure in ir_to_mesa, and the varying won't
take up varying space.
2010-07-28 14:04:54 -07:00
Eric Anholt
59c45e9e6c glsl2: Actually use the linked dead code eliminator.
I managed to revert the change from unlinked at some point while
cleaning up the changes.  glsl-fs-raytrace-bug27060 drops from 389
instructions to 370.
2010-07-27 14:34:53 -07:00
Eric Anholt
bf6ad0ab3d glsl2: Use ir_dead_code's linked version after linking.
glsl-fs-raytrace-bug27060 goes from 485 Mesa IR instructions to 389
before Mesa IR optimization.
2010-07-27 11:49:27 -07:00
Eric Anholt
afe125e0a1 Merge remote branch 'origin/master' into glsl2
This pulls in multiple i965 driver fixes which will help ensure better
testing coverage during development, and also gets past the conflicts
of the src/mesa/shader -> src/mesa/program move.

Conflicts:
	src/mesa/Makefile
	src/mesa/main/shaderapi.c
	src/mesa/main/shaderobj.h
2010-07-26 17:53:27 -07:00
Ian Romanick
d5be2acae3 linker: Link built-in functions instead of including them in every shader
This is an invasive set of changes.  Each user shader tracks a set of other
shaders that contain built-in functions.  During compilation, function
prototypes are imported from these shaders.  During linking, the
shaders are linked with these built-in-function shaders just like with
any other shader.
2010-07-21 15:52:58 -07:00
Ian Romanick
a7ba9a7919 linker: Do post-link lowering and optimization
The lowering code should probably be moved elsewhere.
2010-07-20 17:48:24 -07:00
Ian Romanick
7e2aa91507 glsl2: Add and use new variable mode ir_var_temporary
This is quite a large patch because breaking it into smaller pieces
would result in the tree being intermitently broken.  The big changes
are:

    * Add the ir_var_temporary variable mode

    * Change the ir_variable constructor to take the mode as a
      parameter and correctly specify the mode for all ir_varables.

    * Change the linker to not cross validate ir_var_temporary
      variables.

    * Change the linker to pull all ir_var_temporary variables from
      global scope into 'main'.
2010-07-20 17:48:24 -07:00
Ian Romanick
cd6764ed6e linker: Remove the FINISHME comment for intrastage linking 2010-07-19 14:50:43 -07:00
Ian Romanick
1a03a644d2 linker: Remove redundant check for 'main' in shaders
This is now handled in link_intrastage_shaders.
2010-07-19 14:50:43 -07:00
Ian Romanick
25f51d3b9b linker: Track and validate GLSL versions used in shaders 2010-07-19 14:50:43 -07:00