st_atom.c File Reference

Include dependency graph for st_atom.c:

Go to the source code of this file.

Functions

void st_init_atoms (struct st_context *st)
void st_destroy_atoms (struct st_context *st)
static GLboolean check_state (const struct st_state_flags *a, const struct st_state_flags *b)
static void accumulate_state (struct st_state_flags *a, const struct st_state_flags *b)
static void xor_states (struct st_state_flags *result, const struct st_state_flags *a, const struct st_state_flags *b)
static void check_program_state (struct st_context *st)
void st_validate_state (struct st_context *st)

Variables

static struct st_tracked_stateatoms []


Function Documentation

static void accumulate_state ( struct st_state_flags a,
const struct st_state_flags b 
) [static]

Definition at line 111 of file st_atom.c.

References st_state_flags::mesa, and st_state_flags::st.

00113 {
00114    a->mesa |= b->mesa;
00115    a->st |= b->st;
00116 }

static void check_program_state ( struct st_context st  )  [static]

Definition at line 130 of file st_atom.c.

References st_fragment_program::Base, st_vertex_program::Base, st_context::ctx, st_context::dirty, st_context::fp, st_state_flags::st, ST_NEW_FRAGMENT_PROGRAM, ST_NEW_VERTEX_PROGRAM, and st_context::vp.

00131 {
00132    GLcontext *ctx = st->ctx;
00133 
00134    if (ctx->VertexProgram._Current != &st->vp->Base)
00135       st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
00136 
00137    if (ctx->FragmentProgram._Current != &st->fp->Base)
00138       st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
00139 
00140 }

static GLboolean check_state ( const struct st_state_flags a,
const struct st_state_flags b 
) [static]

Definition at line 104 of file st_atom.c.

References st_state_flags::mesa, and st_state_flags::st.

00106 {
00107    return ((a->mesa & b->mesa) ||
00108            (a->st & b->st));
00109 }

void st_destroy_atoms ( struct st_context st  ) 

Definition at line 92 of file st_atom.c.

References st_context::atoms.

00093 {
00094    if (st->atoms) {
00095       free(st->atoms);
00096       st->atoms = NULL;
00097    }
00098 }

void st_init_atoms ( struct st_context st  ) 

Definition at line 68 of file st_atom.c.

References st_context::atoms, st_context::constants, st_context::nr_atoms, PIPE_SHADER_FRAGMENT, PIPE_SHADER_VERTEX, st_update_fs_constants, and st_update_vs_constants.

00069 {
00070    GLuint i;
00071 
00072    st->atoms = malloc(sizeof(atoms));
00073    st->nr_atoms = sizeof(atoms)/sizeof(*atoms);
00074    memcpy(st->atoms, atoms, sizeof(atoms));
00075 
00076    /* Patch in a pointer to the dynamic state atom:
00077     */
00078    for (i = 0; i < st->nr_atoms; i++) {
00079       if (st->atoms[i] == &st_update_vs_constants) {
00080          st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_VERTEX];
00081          st->atoms[i][0] = st_update_vs_constants;
00082       }
00083 
00084       if (st->atoms[i] == &st_update_fs_constants) {
00085          st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_FRAGMENT];
00086          st->atoms[i][0] = st_update_fs_constants;
00087       }
00088    }
00089 }

void st_validate_state ( struct st_context st  ) 

Definition at line 147 of file st_atom.c.

References accumulate_state(), assert, st_context::atoms, check_program_state(), check_state(), st_tracked_state::dirty, st_context::dirty, st_state_flags::mesa, st_tracked_state::name, st_context::nr_atoms, st_state_flags::st, st_flush_bitmap_cache(), st_tracked_state::update, and xor_states().

00148 {
00149    struct st_state_flags *state = &st->dirty;
00150    GLuint i;
00151 
00152    /* The bitmap cache is immune to pixel unpack changes.
00153     * Note that GLUT makes several calls to glPixelStore for each
00154     * bitmap char it draws so this is an important check.
00155     */
00156    if (state->mesa & ~_NEW_PACKUNPACK)
00157       st_flush_bitmap_cache(st);
00158 
00159    check_program_state( st );
00160 
00161    if (state->st == 0)
00162       return;
00163 
00164 //   _mesa_printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);
00165 
00166    if (1) {
00167       /* Debug version which enforces various sanity checks on the
00168        * state flags which are generated and checked to help ensure
00169        * state atoms are ordered correctly in the list.
00170        */
00171       struct st_state_flags examined, prev;      
00172       memset(&examined, 0, sizeof(examined));
00173       prev = *state;
00174 
00175       for (i = 0; i < st->nr_atoms; i++) {       
00176          const struct st_tracked_state *atom = st->atoms[i];
00177          struct st_state_flags generated;
00178          
00179 //       _mesa_printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);
00180 
00181          if (!(atom->dirty.mesa || atom->dirty.st) ||
00182              !atom->update) {
00183             _mesa_printf("malformed atom %s\n", atom->name);
00184             assert(0);
00185          }
00186 
00187          if (check_state(state, &atom->dirty)) {
00188             st->atoms[i]->update( st );
00189 //          _mesa_printf("after: %x\n", atom->dirty.mesa);
00190          }
00191 
00192          accumulate_state(&examined, &atom->dirty);
00193 
00194          /* generated = (prev ^ state)
00195           * if (examined & generated)
00196           *     fail;
00197           */
00198          xor_states(&generated, &prev, state);
00199          assert(!check_state(&examined, &generated));
00200          prev = *state;
00201       }
00202 //      _mesa_printf("\n");
00203 
00204    }
00205    else {
00206       const GLuint nr = st->nr_atoms;
00207 
00208       for (i = 0; i < nr; i++) {         
00209          if (check_state(state, &st->atoms[i]->dirty))
00210             st->atoms[i]->update( st );
00211       }
00212    }
00213 
00214    memset(state, 0, sizeof(*state));
00215 }

static void xor_states ( struct st_state_flags result,
const struct st_state_flags a,
const struct st_state_flags b 
) [static]

Definition at line 119 of file st_atom.c.

References st_state_flags::mesa, and st_state_flags::st.

00122 {
00123    result->mesa = a->mesa ^ b->mesa;
00124    result->st = a->st ^ b->st;
00125 }


Variable Documentation

struct st_tracked_state* atoms[] [static]

Initial value:

Definition at line 46 of file st_atom.c.


Generated on Tue Sep 29 06:25:51 2009 for Gallium3D by  doxygen 1.5.4