Commit graph

37181 commits

Author SHA1 Message Date
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
81996ae861 i965: More s/stderr/stdout/ for program debug. 2010-08-09 18:24:23 -07:00
Eric Anholt
2dd3ae0d4a glsl2: Teach copy propagation about "if" and "loop" instructions.
This lets us track copies across basic block boundaries.  The loop
doesn't get a filled out list of available copies into it yet, though.

glsl-fs-raytrace drops from 585 to 535 Mesa IR instructions out of the
compiler, and it appears that Yo Frankie's largest shaders decrease in
Mesa IR count by about 10% as well.
2010-08-09 17:14:31 -07:00
Kenneth Graunke
8aa7dbacaf glsl2: Refresh autogenerated file builtin_function.cpp. 2010-08-09 12:45:25 -07:00
Kenneth Graunke
2eed82ebc0 texture_builtins.py: Fix cut and paste errors in function names.
Some signatures were being generated with the wrong function name.
2010-08-09 12:41:39 -07:00
Kenneth Graunke
dbff7b541e glsl2: Use gl_DepthRange's proper name.
It was being incorrectly added as gl_DepthRangeParameters, which is the
type name, not the variable name.
2010-08-09 11:42:37 -07:00
Ian Romanick
c88e60a27b ir_algebraic: Support other comparisons in ir_unop_logic_not 2010-08-09 10:46:38 -07:00
Ian Romanick
fe277089c7 ir_algebraic: Convert ir_unop_logic_not handler to use a switch statement
Currently only ir_binop_equal and ir_binop_nequal are supported, but
soon all of the relational operators will be added.  Making this
change now will simplify those commits.
2010-08-09 10:19:39 -07:00
Aras Pranckevicius
3adce986c4 glsl2: do not use __retval name; two underscores is reserved word according to GLSL spec (and Win7 ATI drivers do complain about that) 2010-08-09 09:08:03 -07:00
Aras Pranckevicius
5023edaf5d glsl: fix missing return in ir_structure_splitting 2010-08-09 09:04:32 -07:00
Eric Anholt
f8d2cfe4a6 glsl2: Handle plain variable copies in struct splitting.
glsl-fs-raytrace goes from 620 Mesa IR instructions out of the
compiler to 585.
2010-08-08 23:45:58 -07:00
Kenneth Graunke
b7e63c34e7 glsl2: Add the 1.30 reserved keywords. 2010-08-07 00:51:30 -07:00
Aras Pranckevicius
58f1ffdd7c ir_function_inlining: Fix missing iter.next() in inlining sampler params.
Fixes glsl-fs-function-samplers.
2010-08-06 14:17:40 -07:00
Aras Pranckevicius
63cddb27d7 copy_propagation: do propagation into non-out call params 2010-08-06 14:13:15 -07:00
Eric Anholt
925b49ff31 glsl2: Move gl_program->InputsRead/OutputsWritten setting to an ir pass.
This lets us handle arrays much better than trying to work backwards
from assembly.

Fixes fbo-drawbuffers-maxtargets on swrast (i965 needs loop unrolling)
2010-08-06 13:22:31 -07:00
Eric Anholt
c234d0b25f ir_to_mesa: Add support for sampler arrays.
Support for samplers in general is still incomplete -- anything in a
uniform struct will still be broken.  But that doesn't appear to be
any different from master.

Fixes:
glsl-fs-uniform-sampler-array.shader_test
2010-08-06 00:51:42 -07:00
Eric Anholt
199c441239 glsl2: Fix inlining with sampler array or struct dereferences as arguments.
Previously, we'd replace an argument of mysampler[2] with a plain
reference to mysampler by using the cloning hash table.  Instead, use
a visitor to clone whatever complicated sampler dereference into the
sampler parameter derefs in the inlined function body.
2010-08-06 00:51:08 -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
658e25987f ir_to_mesa: Give the expected size for _mesa_add_attribute().
Fixes a failure in glean shaderAPI.
2010-08-06 00:23:48 -07:00
Ian Romanick
0a86d766ef ir_to_mesa: Handle texture-array samplers
Fixes piglit test array_texture.
2010-08-05 17:57:48 -07:00
Ian Romanick
4f397e1d64 glsl2: Enable all supported extensions in stand-alone compiler 2010-08-05 17:50:13 -07:00
Ian Romanick
0a09d679ca glsl_type: Don't have two versions of a type with the same name
Previously some sampler types were duplicated in GLSL 1.30 and
GL_EXT_texture_array.  This resulted in not being able to find the
built-in sampler functions when the extension was used.  When the
built-in functions were compiled, they bound to the 1.30 version.
This caused a type mismatch when trying to find the function.  It also
resulted in a confusing error message:

0:0(0): error: no matching function for call to `texture2DArray(sampler2DArray, vec3)'
0:0(0): error: candidates are: vec4 texture2DArray(sampler2DArray, vec3)

0:0(0): error:                 vec4 texture2DArray(sampler2DArray, vec3, float)
2010-08-05 17:29:15 -07:00
Ian Romanick
1e0f0459e0 glsl2: Log a better error message when a matching function cannot be found 2010-08-05 17:21:39 -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
8048226b7b glsl2: Insert global declarations at the top of the instruction stream.
Fixes use-before-decl in glslparsertest shaders.

Fixes:
CorrectFull.frag
CorrectModule.frag
2010-08-05 14:41:09 -07:00
Eric Anholt
0a0ab121f8 ir_structure_splitting: Massive fixing to this.
I'd missed putting in the actual "find structures to split" part, so
most of the code didn't do anything.  I was running on too large of an
app and assuming the lack of progress was elsewhere.
2010-08-05 13:40:09 -07:00
Eric Anholt
748f81a8ea glsl2: Make the HV actually call ir_texture's visit_leave. 2010-08-05 13:34:02 -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
c314c8f231 glsl2: Fix the dereferences_variable check in ir_tree_grafting.
The HV doesn't descend into ir_variable, which is generally a good
thing (allowing one to distinguish between variable declarations and
refs), but here we never saw tree grafting opportunities killed
because we were looking for the ir_variable child of a dereference to
get visited.

Fixes:
glsl1-function call with inout params
2010-08-05 12:56:03 -07:00
Eric Anholt
b259eb2804 glsl2: Don't tree-grafting out assignment to an out variable.
Fixes:
glsl-deadcode-varying.
2010-08-05 12:56:03 -07:00
Eric Anholt
9f82806c7b glsl2: Don't dead-code eliminate a call where the return value is unused.
This showed up since the disabling of inlining at compile time, which
I apparently didn't regenerate piglit summary for.

Fixes:
glsl-deadcode-call.
2010-08-05 12:56:03 -07:00
Eric Anholt
3bd7e70bf7 glsl2: Add some easy-to-enable debug printfs to ir_dead_code.cpp. 2010-08-05 12:56:02 -07:00
Eric Anholt
e995f0e10c ir_to_mesa: Don't do function inlining until linking.
Optimizations at compile time should generally be done with the goal
of reducing instruction count so that other work, particularly
linking, is less time-consuming if the shader is used multiple times.
However, function inlining increases instruction count for the inlined
function bodies without removing the original function body, since we
don't know if it will be used at link time or not.

Reduces the runtime of linking and executing a Yo Frankie fragment
shader from 0.9 seconds to 0.5 seconds (-45.9%, +/- 2.2%, n=5).
2010-08-05 10:18:45 -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
c5b9cab499 glsl2: Catch pointless copies in copy propagation.
We wouldn't want to go rewriting dereferences to variables to point at
the same variable it did before.  While I didn't find a way to trigger
that, a shader in Yo Frankie managed to produce a self-assignment by
passing a constant to a function doing self assignment like this.

Cleans up the IR for glsl-deadcode-self-assign.shader_test
2010-08-05 09:17:45 -07:00
Eric Anholt
8f6a0c9ed9 glsl2: Don't try to dump GLSL IR for a shader that didn't compile. 2010-08-05 09:17:45 -07:00
Eric Anholt
9de2c4fc8e ir_to_mesa: Remove debug force-enablement of EmitNoIfs. 2010-08-05 09:17:45 -07:00
Kenneth Graunke
f4239872c9 glcpp: Ignore #if and #elif expressions when skipping.
Fixes glcpp test cases 073 and 074, as well as piglit test
xonotic-vs-generic-diffuse.vert.
2010-08-04 23:37:19 -07:00
Kenneth Graunke
d65135a766 glcpp/tests: Add a corollary to testcase 073 for testing #elif. 2010-08-04 23:37:19 -07:00
Kenneth Graunke
c52b2be166 glcpp/tests: Fix 073-if-in-ifdef.c to use #ifdef, not #if.
The original intention was to use #ifdef.
2010-08-04 23:37:19 -07:00
Kenneth Graunke
16b4eed59a glcpp: Refactor HASH_IF and HASH_ELIF expansion to reuse code. 2010-08-04 23:37:18 -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
a08f27940a glsl2: Remove a dead cut and paste member from ir_variable_refcount_visitor. 2010-08-04 20:52:33 -07:00
Eric Anholt
72fd0568db i965: Settle on printing our program debug to stdout.
Mixing stderr (_mesa_print_program, _mesa_print_instruction,
_mesa_print_alu) with stdout means that when writing both to a file,
there isn't a consistent ordering between the two.
2010-08-04 20:52:33 -07:00
Eric Anholt
455290e428 ir_to_mesa: Print shader source and compiled IR under MESA_GLSL=dump.
While the Mesa IR dumping includes some corresponding GLSL IR for
correlating Mesa IR to GLSL IR, it doesn't completely express it.
This printing includes things like variable declarations and control
flow structure that is hard to read otherwise.
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
022f79e496 glsl2: Return progress from ir_vec_index_to_swizzle. 2010-08-04 20:52:33 -07:00
Ian Romanick
83cb310dbb glsl2: Generate masked assignments in some expanded matrix operations 2010-08-04 16:47:28 -07:00
Ian Romanick
3d58be6135 glsl2: Generate masked assignments in vector and matrix constructors
Previously the in-line matrix and vector constructors would generate
swizzles in the LHS.  The code is actually more clear if it just
generates the masked assignments instead of relying on the
ir_assignment constructor to convert the swizzles to write masks.
2010-08-04 16:47:28 -07:00