gallium: implement full reference counting for vertex/fragment programs

Use _mesa_reference_vert/fragprog() wherever we assign program pointers.
Fixes a memory corruption bug found with glean/api2 test.
Another memory bug involving shaders yet to be fixed...

Picked from gallium-0.1
diff --git a/src/mesa/shader/prog_cache.c b/src/mesa/shader/prog_cache.c
index dd0241e..36a2537 100644
--- a/src/mesa/shader/prog_cache.c
+++ b/src/mesa/shader/prog_cache.c
@@ -30,6 +30,7 @@
 #include "main/mtypes.h"
 #include "main/imports.h"
 #include "shader/prog_cache.h"
+#include "shader/program.h"
 
 
 struct cache_item
@@ -109,7 +110,7 @@
       for (c = cache->items[i]; c; c = next) {
 	 next = c->next;
 	 _mesa_free(c->key);
-	 ctx->Driver.DeleteProgram(ctx, c->program);
+         _mesa_reference_program(ctx, &c->program, NULL);
 	 _mesa_free(c);
       }
       cache->items[i] = NULL;
@@ -177,7 +178,7 @@
    c->key = _mesa_malloc(keysize);
    memcpy(c->key, key, keysize);
 
-   c->program = program;
+   c->program = program;  /* no refcount change */
 
    if (cache->n_items > cache->size * 1.5) {
       if (cache->size < 1000)