gallium: Update calls to the simple shader functions
[mesa.git] / src / mesa / state_tracker / st_atom.c
index 02720804d400cd4e1dd5eceb8322485c87f74a16..0e22a2fa6e74546563ac9bd883ae2ee8140566cf 100644 (file)
 #include "glheader.h"
 #include "context.h"
 
+#include "pipe/p_defines.h"
 #include "st_context.h"
 #include "st_atom.h"
+#include "st_program.h"
 
        
 
 static const struct st_tracked_state *atoms[] =
 {
    &st_update_framebuffer,
-   &st_update_cbuf,
+   &st_update_depth_stencil_alpha,
    &st_update_clip,
-   &st_update_fs,
-   &st_update_setup,
+
+   &st_update_shader,
+
+   &st_update_rasterizer,
+   &st_update_polygon_stipple,
    &st_update_viewport,
    &st_update_scissor,
    &st_update_blend,
-   &st_update_stencil,
-   /* will be patched out at runtime */
-/*    &st_update_constants */
+   &st_update_sampler,
+   &st_update_texture,
+   &st_update_vs_constants,
+   &st_update_fs_constants,
+   &st_update_pixel_transfer
 };
 
 
@@ -66,13 +73,17 @@ void st_init_atoms( struct st_context *st )
 
    /* Patch in a pointer to the dynamic state atom:
     */
-   for (i = 0; i < st->nr_atoms; i++)
-      if (st->atoms[i] == &st_update_constants)
-        st->atoms[i] = &st->constants.tracked_state;
+   for (i = 0; i < st->nr_atoms; i++) {
+      if (st->atoms[i] == &st_update_vs_constants) {
+        st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_VERTEX];
+        st->atoms[i][0] = st_update_vs_constants;
+      }
 
-   memcpy(&st->constants.tracked_state, 
-          &st_update_constants,
-          sizeof(st_update_constants));
+      if (st->atoms[i] == &st_update_fs_constants) {
+        st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_FRAGMENT];
+        st->atoms[i][0] = st_update_fs_constants;
+      }
+   }
 }
 
 
@@ -112,6 +123,21 @@ static void xor_states( struct st_state_flags *result,
 }
 
 
+/* Too complex to figure out, just check every time:
+ */
+static void check_program_state( struct st_context *st )
+{
+   GLcontext *ctx = st->ctx;
+
+   if (ctx->VertexProgram._Current != &st->vp->Base)
+      st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
+
+   if (ctx->FragmentProgram._Current != &st->fp->Base)
+      st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
+
+}
+
+
 /***********************************************************************
  * Update all derived state:
  */
@@ -121,9 +147,13 @@ void st_validate_state( struct st_context *st )
    struct st_state_flags *state = &st->dirty;
    GLuint i;
 
+   check_program_state( st );
+
    if (state->st == 0)
       return;
 
+//   _mesa_printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);
+
    if (1) {
       /* Debug version which enforces various sanity checks on the
        * state flags which are generated and checked to help ensure
@@ -136,13 +166,18 @@ void st_validate_state( struct st_context *st )
       for (i = 0; i < st->nr_atoms; i++) {      
         const struct st_tracked_state *atom = st->atoms[i];
         struct st_state_flags generated;
+        
+//      _mesa_printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);
 
-        assert(atom->dirty.mesa ||
-               atom->dirty.st);
-        assert(atom->update);
+        if (!(atom->dirty.mesa || atom->dirty.st) ||
+            !atom->update) {
+           _mesa_printf("malformed atom %s\n", atom->name);
+           assert(0);
+        }
 
         if (check_state(state, &atom->dirty)) {
            st->atoms[i]->update( st );
+//         _mesa_printf("after: %x\n", atom->dirty.mesa);
         }
 
         accumulate_state(&examined, &atom->dirty);
@@ -155,6 +190,8 @@ void st_validate_state( struct st_context *st )
         assert(!check_state(&examined, &generated));
         prev = *state;
       }
+//      _mesa_printf("\n");
+
    }
    else {
       const GLuint nr = st->nr_atoms;