i965: Ensure that all necessary state is re-emitted if we run out of aperture.

Prior to this patch, if we ran out of aperture space during
brw_try_draw_prims(), we would rewind the batch buffer pointer
(potentially throwing some state that may have been emitted by
brw_upload_state()), flush the batch, and then try again.  However, we
wouldn't reset the dirty bits to the state they had before the call to
brw_upload_state().  As a result, when we tried again, there was a
danger that we wouldn't re-emit all the necessary state.  (Note: prior
to the introduction of hardware contexts, this wasn't a problem
because flushing the batch forced all state to be re-emitted).

This patch fixes the problem by leaving the dirty bits set at the end
of brw_upload_state(); we only clear them after we have determined
that we don't need to rewind the batch buffer.

Cc: 10.0 9.2 <mesa-stable@lists.freedesktop.org>
mesa: Replace _mesa_program_index_to_target with _mesa_shader_stage_to_program.

In my recent zeal to refactor Mesa's handling of the gl_shader_stage
enum, I accidentally wound up with two functions that do the same
thing: _mesa_program_index_to_target(), and
_mesa_shader_stage_to_program().

This patch keeps _mesa_shader_stage_to_program(), since its name is
more consistent with other related functions.  However, it changes the
signature so that it accepts an unsigned integer instead of a
gl_shader_stage--this avoids awkward casts when the function is called
from C++ code.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: Make validate_shader_target() non-static.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
main: Allow ctx == NULL in _mesa_validate_shader_target().

This will allow this function to be used in circumstances where there
is no context available, such as when building built-in GLSL
functions.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: use _mesa_validate_shader_target() more frequently.

This patch replaces code in _mesa_new_shader() and delete_shader_cb()
that checks the type of a shader with calls to
_mesa_validate_shader_target().  This has two advantages: it allows
for a more thorough check (since _mesa_validate_shader_target()
doesn't permit shader targets that aren't supported by the back-end),
and it reduces the amount of code that will need to be modified when
adding new shader stages.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
glsl/linker: Refactor in preparation for adding more shader stages.

Rather than maintain separately named arrays and counts for vertex,
geometry, and fragment shaders, just maintain these as arrays indexed
by the gl_shader_type enum.

v2: When there is neither a vertex nor a geometry shader, set
prog->LastClipDistanceArraySize = 0, and clarify that the values is
not used.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: Replace ctx->Shader.Current{Vertex,Fragment,Geometry}Program with an array.

These are replaced with
ctx->Shader.CurrentProgram[MESA_SHADER_{VERTEX,FRAGMENT,GEOMETRY}].
In patches to follow, this will allow us to replace a lot of ad-hoc
logic with a variable index into the array.

With the exception of the changes to mtypes.h, this patch was
generated entirely by the command:

    find src -type f '(' -iname '*.c' -o -iname '*.cpp' ')' \
    -print0 | xargs -0 sed -i \
    -e 's/\.CurrentVertexProgram/.CurrentProgram[MESA_SHADER_VERTEX]/g' \
    -e 's/\.CurrentGeometryProgram/.CurrentProgram[MESA_SHADER_GEOMETRY]/g' \
    -e 's/\.CurrentFragmentProgram/.CurrentProgram[MESA_SHADER_FRAGMENT]/g'

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: Fold long lines introduced by the previous patch.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
i965: Fix comments to refer to the new ctx->Shader.CurrentProgram array.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
meta: Replace save_state::{Vertex,Geometry,Fragment}Shader with an array.

Since ctx->Shader.Current{Vertex,Geometry,Fragment}Program is an
array, this allows some meta code to be rolled up into loops.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: Remove ad-hoc arrays of gl_shader_program.

Now that we have a ctx->Shader.CurrentProgram array, we can just use
it directly.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: Change redundant code into loops in shaderapi.c.

This is possible now that ctx->Shader.CurrentProgram is an array.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: Change redundant code into loops in texstate.c.

This is possible now that ctx->Shader.CurrentProgram is an array.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
mesa/cs: Add extension enable flags for ARB_compute_shader.
mesa/cs: Add dispatch API stubs for ARB_compute_shader.
glsl/cs: Change some linker loops to use MESA_SHADER_FRAGMENT as a bound.

Linker loops that iterate through all the stages in the pipeline need
to use MESA_SHADER_FRAGMENT as a bound, so that we can add an
additional MESA_SHADER_COMPUTE stage, without it being erroneously
included in the pipeline.
mesa/cs: Add a MESA_SHADER_COMPUTE stage and update switch statements.

This patch adds MESA_SHADER_COMPUTE to the gl_shader_stage enum.
Also, where it is trivial to do so, it adds a compute shader case to
switch statements that switch based on the type of shader.  This
avoids "unhandled switch case" compiler warnings.
glsl/cs: Populate default values for ctx->Const.Program[MESA_SHADER_COMPUTE].
glsl/cs: update main.cpp to use the ".comp" extension for compute shaders.
mesa/cs: Handle compute shaders in _mesa_use_program().

v2: do cs after the ordered pipeline stages for consistency.