r600: fix warning
[mesa.git] / src / mesa / state_tracker / st_cb_program.c
index 26609e964545995a430e4cf72b7d85da21a52eea..4398ab28392cbb190631ef7aa156fa042527b075 100644 (file)
 #include "shader/programopt.h"
 #include "shader/shader_api.h"
 
+#include "cso_cache/cso_context.h"
+#include "draw/draw_context.h"
+
 #include "st_context.h"
 #include "st_program.h"
 #include "st_atom_shader.h"
+#include "st_cb_program.h"
+
 
-#include "pipe/tgsi/mesa/tgsi_mesa.h"
+static GLuint SerialNo = 1;
 
 
 /**
@@ -84,15 +89,19 @@ static void st_use_program( GLcontext *ctx,
 
 
 
+/**
+ * Called via ctx->Driver.NewProgram() to allocate a new vertex or
+ * fragment program.
+ */
 static struct gl_program *st_new_program( GLcontext *ctx,
-                                         GLenum target, 
+                                         GLenum target,
                                          GLuint id )
 {
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB: {
-      struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program);
+      struct st_vertex_program *prog = ST_CALLOC_STRUCT(st_vertex_program);
 
-      prog->serialNo = 1;
+      prog->serialNo = SerialNo++;
 
       return _mesa_init_vertex_program( ctx, 
                                        &prog->Base,
@@ -102,9 +111,9 @@ static struct gl_program *st_new_program( GLcontext *ctx,
 
    case GL_FRAGMENT_PROGRAM_ARB:
    case GL_FRAGMENT_PROGRAM_NV: {
-      struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
+      struct st_fragment_program *prog = ST_CALLOC_STRUCT(st_fragment_program);
 
-      prog->serialNo = 1;
+      prog->serialNo = SerialNo++;
 
       return _mesa_init_fragment_program( ctx, 
                                          &prog->Base,
@@ -113,13 +122,14 @@ static struct gl_program *st_new_program( GLcontext *ctx,
    }
 
    default:
-      return _mesa_new_program(ctx, target, id);
+      assert(0);
+      return NULL;
    }
 }
 
 
-static void st_delete_program( GLcontext *ctx,
-                              struct gl_program *prog )
+void
+st_delete_program(GLcontext *ctx, struct gl_program *prog)
 {
    struct st_context *st = st_context(ctx);
 
@@ -127,20 +137,54 @@ static void st_delete_program( GLcontext *ctx,
    case GL_VERTEX_PROGRAM_ARB:
       {
          struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
-         st_remove_vertex_program(st, stvp);
+
+         if (stvp->driver_shader) {
+            cso_delete_vertex_shader(st->cso_context, stvp->driver_shader);
+            stvp->driver_shader = NULL;
+         }
+
+         if (stvp->draw_shader) {
+#if FEATURE_feedback || FEATURE_drawpix
+            /* this would only have been allocated for the RasterPos path */
+            draw_delete_vertex_shader(st->draw, stvp->draw_shader);
+            stvp->draw_shader = NULL;
+#endif
+         }
+
+         if (stvp->state.tokens) {
+            _mesa_free((void *) stvp->state.tokens);
+            stvp->state.tokens = NULL;
+         }
       }
       break;
    case GL_FRAGMENT_PROGRAM_ARB:
       {
-         struct st_fragment_program *stfp
-            = (struct st_fragment_program *) prog;
-         st_remove_fragment_program(st, stfp);
+         struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
+
+         if (stfp->driver_shader) {
+            cso_delete_fragment_shader(st->cso_context, stfp->driver_shader);
+            stfp->driver_shader = NULL;
+         }
+         
+         if (stfp->state.tokens) {
+            _mesa_free((void *) stfp->state.tokens);
+            stfp->state.tokens = NULL;
+         }
+
+         if (stfp->bitmap_program) {
+            struct gl_program *prg = &stfp->bitmap_program->Base.Base;
+            _mesa_reference_program(ctx, &prg, NULL);
+            stfp->bitmap_program = NULL;
+         }
+
+         st_free_translated_vertex_programs(st, stfp->vertex_programs);
       }
       break;
    default:
       assert(0); /* problem */
    }
 
+   /* delete base class */
    _mesa_delete_program( ctx, prog );
 }
 
@@ -164,10 +208,14 @@ static void st_program_string_notify( GLcontext *ctx,
 
       stfp->serialNo++;
 
-      if (stfp->fs) {
-         /* free the TGSI code */
-         // cso_delete(stfp->vs);
-         stfp->fs = NULL;
+      if (stfp->driver_shader) {
+         cso_delete_fragment_shader(st->cso_context, stfp->driver_shader);
+         stfp->driver_shader = NULL;
+      }
+
+      if (stfp->state.tokens) {
+         _mesa_free((void *) stfp->state.tokens);
+         stfp->state.tokens = NULL;
       }
 
       stfp->param_state = stfp->Base.Base.Parameters->StateFlags;
@@ -180,17 +228,28 @@ static void st_program_string_notify( GLcontext *ctx,
 
       stvp->serialNo++;
 
-      if (stvp->vs) {
-         /* free the TGSI code */
-         // cso_delete(stfp->vs);
-         stvp->vs = NULL;
+      if (stvp->driver_shader) {
+         cso_delete_vertex_shader(st->cso_context, stvp->driver_shader);
+         stvp->driver_shader = NULL;
+      }
+
+      if (stvp->draw_shader) {
+#if FEATURE_feedback || FEATURE_drawpix
+         /* this would only have been allocated for the RasterPos path */
+         draw_delete_vertex_shader(st->draw, stvp->draw_shader);
+         stvp->draw_shader = NULL;
+#endif
+      }
+
+      if (stvp->state.tokens) {
+         _mesa_free((void *) stvp->state.tokens);
+         stvp->state.tokens = NULL;
       }
 
       stvp->param_state = stvp->Base.Base.Parameters->StateFlags;
 
       if (st->vp == stvp)
         st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
-
    }
 }