brw_state_upload.c

Go to the documentation of this file.
00001 /*
00002  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
00003  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
00004  develop this 3D driver.
00005 
00006  Permission is hereby granted, free of charge, to any person obtaining
00007  a copy of this software and associated documentation files (the
00008  "Software"), to deal in the Software without restriction, including
00009  without limitation the rights to use, copy, modify, merge, publish,
00010  distribute, sublicense, and/or sell copies of the Software, and to
00011  permit persons to whom the Software is furnished to do so, subject to
00012  the following conditions:
00013 
00014  The above copyright notice and this permission notice (including the
00015  next paragraph) shall be included in all copies or substantial
00016  portions of the Software.
00017 
00018  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00021  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
00022  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00023  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00024  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025 
00026  **********************************************************************/
00027  /*
00028   * Authors:
00029   *   Keith Whitwell <keith@tungstengraphics.com>
00030   */
00031 
00032 
00033 #include "brw_context.h"
00034 #include "brw_state.h"
00035 
00036 #include "util/u_memory.h"
00037 
00038 /* This is used to initialize brw->state.atoms[].  We could use this
00039  * list directly except for a single atom, brw_constant_buffer, which
00040  * has a .dirty value which changes according to the parameters of the
00041  * current fragment and vertex programs, and so cannot be a static
00042  * value.
00043  */
00044 const struct brw_tracked_state *atoms[] =
00045 {
00046    &brw_vs_prog,
00047    &brw_gs_prog,
00048    &brw_clip_prog,
00049    &brw_sf_prog,
00050    &brw_wm_prog,
00051 
00052    /* Once all the programs are done, we know how large urb entry
00053     * sizes need to be and can decide if we need to change the urb
00054     * layout.
00055     */
00056    &brw_curbe_offsets,
00057    &brw_recalculate_urb_fence,
00058 
00059 
00060    &brw_cc_vp,
00061    &brw_cc_unit,
00062 
00063    &brw_wm_surfaces,            /* must do before samplers */
00064    &brw_wm_samplers,
00065 
00066    &brw_wm_unit,
00067    &brw_sf_vp,
00068    &brw_sf_unit,
00069    &brw_vs_unit,                /* always required, enabled or not */
00070    &brw_clip_unit,
00071    &brw_gs_unit,
00072 
00073    /* Command packets:
00074     */
00075    &brw_invarient_state,
00076    &brw_state_base_address,
00077    &brw_pipe_control,
00078 
00079    &brw_binding_table_pointers,
00080    &brw_blend_constant_color,
00081 
00082    &brw_drawing_rect,
00083    &brw_depthbuffer,
00084 
00085    &brw_polygon_stipple,
00086    &brw_line_stipple,
00087 
00088    &brw_psp_urb_cbs,
00089 
00090    &brw_constant_buffer
00091 };
00092 
00093 
00094 void brw_init_state( struct brw_context *brw )
00095 {
00096    brw_init_pools(brw);
00097    brw_init_caches(brw);
00098 
00099    brw->state.dirty.brw = ~0;
00100    brw->emit_state_always = 0;
00101 }
00102 
00103 
00104 void brw_destroy_state( struct brw_context *brw )
00105 {
00106    brw_destroy_caches(brw);
00107    brw_destroy_batch_cache(brw);
00108    brw_destroy_pools(brw);
00109 }
00110 
00111 /***********************************************************************
00112  */
00113 
00114 static boolean check_state( const struct brw_state_flags *a,
00115                               const struct brw_state_flags *b )
00116 {
00117    return ((a->brw & b->brw) ||
00118            (a->cache & b->cache));
00119 }
00120 
00121 static void accumulate_state( struct brw_state_flags *a,
00122                               const struct brw_state_flags *b )
00123 {
00124    a->brw |= b->brw;
00125    a->cache |= b->cache;
00126 }
00127 
00128 
00129 static void xor_states( struct brw_state_flags *result,
00130                              const struct brw_state_flags *a,
00131                               const struct brw_state_flags *b )
00132 {
00133    result->brw = a->brw ^ b->brw;
00134    result->cache = a->cache ^ b->cache;
00135 }
00136 
00137 
00138 /***********************************************************************
00139  * Emit all state:
00140  */
00141 void brw_validate_state( struct brw_context *brw )
00142 {
00143    struct brw_state_flags *state = &brw->state.dirty;
00144    unsigned i;
00145 
00146    if (brw->emit_state_always) 
00147       state->brw |= ~0;
00148 
00149    if (state->cache == 0 &&
00150        state->brw == 0)
00151       return;
00152 
00153    if (brw->state.dirty.brw & BRW_NEW_SCENE)
00154       brw_clear_batch_cache_flush(brw);
00155 
00156    if (BRW_DEBUG) {
00157       /* Debug version which enforces various sanity checks on the
00158        * state flags which are generated and checked to help ensure
00159        * state atoms are ordered correctly in the list.
00160        */
00161       struct brw_state_flags examined, prev;
00162       memset(&examined, 0, sizeof(examined));
00163       prev = *state;
00164 
00165       for (i = 0; i < Elements(atoms); i++) {
00166          const struct brw_tracked_state *atom = atoms[i];
00167          struct brw_state_flags generated;
00168 
00169          assert(atom->dirty.brw ||
00170                 atom->dirty.cache);
00171          assert(atom->update);
00172 
00173          if (check_state(state, &atom->dirty)) {
00174             atom->update( brw );
00175          }
00176 
00177          accumulate_state(&examined, &atom->dirty);
00178 
00179          /* generated = (prev ^ state)
00180           * if (examined & generated)
00181           *     fail;
00182           */
00183          xor_states(&generated, &prev, state);
00184          assert(!check_state(&examined, &generated));
00185          prev = *state;
00186       }
00187    }
00188    else {
00189       for (i = 0; i < Elements(atoms); i++) {
00190          const struct brw_tracked_state *atom = atoms[i];
00191 
00192          assert(atom->dirty.brw ||
00193                 atom->dirty.cache);
00194          assert(atom->update);
00195 
00196          if (check_state(state, &atom->dirty))
00197             atom->update( brw );
00198       }
00199    }
00200 
00201    memset(state, 0, sizeof(*state));
00202 }

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