[Mesa-dev] [PATCH 0/2] glsl: fix order of functions emitted by the linker.

Paul Berry stereotype441 at gmail.com
Wed Aug 3 17:07:40 PDT 2011


This is a follow-up to the email thread discussing [PATCH 1/4] Revert
"glsl: Skip processing the first function's body in
do_dead_functions().".

As mentioned in that thread, since the linker emits functions at the
head of the final linked program, they come before any global variable
declarations, thus those functions can't access any global variables
without violating IR rules.  This bug was typically papered over by
the fact that (a) this scenario only arises when linking several
shaders together, which doesn't happen very often, and (b) linking is
followed by inlining, which usually (but not always) is able to merge
everything into main() in one pass, yielding valid IR again.

Although I wasn't able to find a set of shaders that crashes Mesa or
produces incorrect pixels because of this bug, the situation seemed
fragile enough to be worth fixing.  So patch 1 in the series adds a
validation step, to make sure that the IR output by the linker is
valid, and patch 2 fixes the bug by changing the linker to emit
functions at the tail of the final linked program rather than the
head.

These patches need to be applied after [PATCH 1/4] Revert "glsl: Skip
processing the first function's body in do_dead_functions().", since
reverting that patch makes do_dead_functions() independent of the
ordering of functions in the IR.

[PATCH 1/2] glsl: validate IR after linking (debug builds only)
[PATCH 2/2] glsl: When linking, emit functions at the tail of the final linked program.


More information about the mesa-dev mailing list