st_atom.c revision 298be2b028263b2c343a707662c6fbfa18293cb2
1/************************************************************************** 2 * 3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 29#include "main/glheader.h" 30#include "main/context.h" 31 32#include "pipe/p_defines.h" 33#include "st_context.h" 34#include "st_atom.h" 35#include "st_cb_bitmap.h" 36#include "st_program.h" 37 38#include "pipe/p_context.h" 39 40 41/** 42 * This is used to initialize st->atoms[]. 43 */ 44static const struct st_tracked_state *atoms[] = 45{ 46 &st_update_depth_stencil_alpha, 47 &st_update_clip, 48 49 &st_finalize_textures, 50 &st_update_fp, 51 &st_update_vp, 52 53 &st_update_rasterizer, 54 &st_update_polygon_stipple, 55 &st_update_viewport, 56 &st_update_scissor, 57 &st_update_blend, 58 &st_update_sampler, 59 &st_update_texture, 60 &st_update_framebuffer, 61 &st_update_vs_constants, 62 &st_update_fs_constants, 63 &st_update_pixel_transfer 64}; 65 66 67void st_init_atoms( struct st_context *st ) 68{ 69 /* no-op */ 70} 71 72 73void st_destroy_atoms( struct st_context *st ) 74{ 75 /* no-op */ 76} 77 78 79/*********************************************************************** 80 */ 81 82static GLboolean check_state( const struct st_state_flags *a, 83 const struct st_state_flags *b ) 84{ 85 return ((a->mesa & b->mesa) || 86 (a->st & b->st)); 87} 88 89static void accumulate_state( struct st_state_flags *a, 90 const struct st_state_flags *b ) 91{ 92 a->mesa |= b->mesa; 93 a->st |= b->st; 94} 95 96 97static void xor_states( struct st_state_flags *result, 98 const struct st_state_flags *a, 99 const struct st_state_flags *b ) 100{ 101 result->mesa = a->mesa ^ b->mesa; 102 result->st = a->st ^ b->st; 103} 104 105 106/* Too complex to figure out, just check every time: 107 */ 108static void check_program_state( struct st_context *st ) 109{ 110 GLcontext *ctx = st->ctx; 111 112 if (ctx->VertexProgram._Current != &st->vp->Base) 113 st->dirty.st |= ST_NEW_VERTEX_PROGRAM; 114 115 if (ctx->FragmentProgram._Current != &st->fp->Base) 116 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; 117 118} 119 120 121/*********************************************************************** 122 * Update all derived state: 123 */ 124 125void st_validate_state( struct st_context *st ) 126{ 127 struct st_state_flags *state = &st->dirty; 128 GLuint i; 129 130 /* The bitmap cache is immune to pixel unpack changes. 131 * Note that GLUT makes several calls to glPixelStore for each 132 * bitmap char it draws so this is an important check. 133 */ 134 if (state->mesa & ~_NEW_PACKUNPACK) 135 st_flush_bitmap_cache(st); 136 137 check_program_state( st ); 138 139 if (st->pipe->screen->update_buffer) 140 st->pipe->screen->update_buffer(st->pipe->screen, 141 st->pipe->priv); 142 143 if (state->st == 0) 144 return; 145 146 /*printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);*/ 147 148 if (1) { 149 /* Debug version which enforces various sanity checks on the 150 * state flags which are generated and checked to help ensure 151 * state atoms are ordered correctly in the list. 152 */ 153 struct st_state_flags examined, prev; 154 memset(&examined, 0, sizeof(examined)); 155 prev = *state; 156 157 for (i = 0; i < Elements(atoms); i++) { 158 const struct st_tracked_state *atom = atoms[i]; 159 struct st_state_flags generated; 160 161 /*printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);*/ 162 163 if (!(atom->dirty.mesa || atom->dirty.st) || 164 !atom->update) { 165 printf("malformed atom %s\n", atom->name); 166 assert(0); 167 } 168 169 if (check_state(state, &atom->dirty)) { 170 atoms[i]->update( st ); 171 /*printf("after: %x\n", atom->dirty.mesa);*/ 172 } 173 174 accumulate_state(&examined, &atom->dirty); 175 176 /* generated = (prev ^ state) 177 * if (examined & generated) 178 * fail; 179 */ 180 xor_states(&generated, &prev, state); 181 assert(!check_state(&examined, &generated)); 182 prev = *state; 183 } 184 /*printf("\n");*/ 185 186 } 187 else { 188 for (i = 0; i < Elements(atoms); i++) { 189 if (check_state(state, &atoms[i]->dirty)) 190 atoms[i]->update( st ); 191 } 192 } 193 194 memset(state, 0, sizeof(*state)); 195} 196 197 198 199