Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/**************************************************************************
2
 *
3
 * Copyright 2003 VMware, Inc.
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 VMWARE 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 
30
#include "main/glheader.h"
31
#include "main/context.h"
32
 
33
#include "pipe/p_defines.h"
34
#include "st_context.h"
35
#include "st_atom.h"
36
#include "st_cb_bitmap.h"
37
#include "st_program.h"
38
#include "st_manager.h"
39
 
40
 
41
/**
42
 * This is used to initialize st->atoms[].
43
 */
44
static 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_gp,
52
   &st_update_vp,
53
 
54
   &st_update_rasterizer,
55
   &st_update_polygon_stipple,
56
   &st_update_viewport,
57
   &st_update_scissor,
58
   &st_update_blend,
59
   &st_update_vertex_texture,
60
   &st_update_fragment_texture,
61
   &st_update_geometry_texture,
62
   &st_update_sampler, /* depends on update_*_texture for swizzle */
63
   &st_update_framebuffer,
64
   &st_update_msaa,
65
   &st_update_sample_shading,
66
   &st_update_vs_constants,
67
   &st_update_gs_constants,
68
   &st_update_fs_constants,
69
   &st_bind_vs_ubos,
70
   &st_bind_fs_ubos,
71
   &st_bind_gs_ubos,
72
   &st_update_pixel_transfer,
73
 
74
   /* this must be done after the vertex program update */
75
   &st_update_array
76
};
77
 
78
 
79
void st_init_atoms( struct st_context *st )
80
{
81
   /* no-op */
82
}
83
 
84
 
85
void st_destroy_atoms( struct st_context *st )
86
{
87
   /* no-op */
88
}
89
 
90
 
91
/***********************************************************************
92
 */
93
 
94
static GLboolean check_state( const struct st_state_flags *a,
95
			      const struct st_state_flags *b )
96
{
97
   return ((a->mesa & b->mesa) ||
98
	   (a->st & b->st));
99
}
100
 
101
static void accumulate_state( struct st_state_flags *a,
102
			      const struct st_state_flags *b )
103
{
104
   a->mesa |= b->mesa;
105
   a->st |= b->st;
106
}
107
 
108
 
109
static void xor_states( struct st_state_flags *result,
110
			     const struct st_state_flags *a,
111
			      const struct st_state_flags *b )
112
{
113
   result->mesa = a->mesa ^ b->mesa;
114
   result->st = a->st ^ b->st;
115
}
116
 
117
 
118
/* Too complex to figure out, just check every time:
119
 */
120
static void check_program_state( struct st_context *st )
121
{
122
   struct gl_context *ctx = st->ctx;
123
 
124
   if (ctx->VertexProgram._Current != &st->vp->Base)
125
      st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
126
 
127
   if (ctx->FragmentProgram._Current != &st->fp->Base)
128
      st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
129
 
130
   if (ctx->GeometryProgram._Current != &st->gp->Base)
131
      st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM;
132
}
133
 
134
static void check_attrib_edgeflag(struct st_context *st)
135
{
136
   const struct gl_client_array **arrays = st->ctx->Array._DrawArrays;
137
   GLboolean vertdata_edgeflags, edgeflag_culls_prims, edgeflags_enabled;
138
 
139
   if (!arrays)
140
      return;
141
 
142
   edgeflags_enabled = st->ctx->Polygon.FrontMode != GL_FILL ||
143
                       st->ctx->Polygon.BackMode != GL_FILL;
144
 
145
   vertdata_edgeflags = edgeflags_enabled &&
146
                        arrays[VERT_ATTRIB_EDGEFLAG]->StrideB != 0;
147
   if (vertdata_edgeflags != st->vertdata_edgeflags) {
148
      st->vertdata_edgeflags = vertdata_edgeflags;
149
      st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
150
   }
151
 
152
   edgeflag_culls_prims = edgeflags_enabled && !vertdata_edgeflags &&
153
                          !st->ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0];
154
   if (edgeflag_culls_prims != st->edgeflag_culls_prims) {
155
      st->edgeflag_culls_prims = edgeflag_culls_prims;
156
      st->dirty.st |= ST_NEW_RASTERIZER;
157
   }
158
}
159
 
160
 
161
/***********************************************************************
162
 * Update all derived state:
163
 */
164
 
165
void st_validate_state( struct st_context *st )
166
{
167
   struct st_state_flags *state = &st->dirty;
168
   GLuint i;
169
 
170
   /* Get Mesa driver state. */
171
   st->dirty.st |= st->ctx->NewDriverState;
172
   st->ctx->NewDriverState = 0;
173
 
174
   check_attrib_edgeflag(st);
175
 
176
   if (state->mesa)
177
      st_flush_bitmap_cache(st);
178
 
179
   check_program_state( st );
180
 
181
   st_manager_validate_framebuffers(st);
182
 
183
   if (state->st == 0)
184
      return;
185
 
186
   /*printf("%s %x/%x\n", __func__, state->mesa, state->st);*/
187
 
188
#ifdef DEBUG
189
   if (1) {
190
#else
191
   if (0) {
192
#endif
193
      /* Debug version which enforces various sanity checks on the
194
       * state flags which are generated and checked to help ensure
195
       * state atoms are ordered correctly in the list.
196
       */
197
      struct st_state_flags examined, prev;
198
      memset(&examined, 0, sizeof(examined));
199
      prev = *state;
200
 
201
      for (i = 0; i < ARRAY_SIZE(atoms); i++) {
202
	 const struct st_tracked_state *atom = atoms[i];
203
	 struct st_state_flags generated;
204
 
205
	 /*printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);*/
206
 
207
	 if (!(atom->dirty.mesa || atom->dirty.st) ||
208
	     !atom->update) {
209
	    printf("malformed atom %s\n", atom->name);
210
	    assert(0);
211
	 }
212
 
213
	 if (check_state(state, &atom->dirty)) {
214
	    atoms[i]->update( st );
215
	    /*printf("after: %x\n", atom->dirty.mesa);*/
216
	 }
217
 
218
	 accumulate_state(&examined, &atom->dirty);
219
 
220
	 /* generated = (prev ^ state)
221
	  * if (examined & generated)
222
	  *     fail;
223
	  */
224
	 xor_states(&generated, &prev, state);
225
	 assert(!check_state(&examined, &generated));
226
	 prev = *state;
227
      }
228
      /*printf("\n");*/
229
 
230
   }
231
   else {
232
      for (i = 0; i < ARRAY_SIZE(atoms); i++) {
233
	 if (check_state(state, &atoms[i]->dirty))
234
	    atoms[i]->update( st );
235
      }
236
   }
237
 
238
   memset(state, 0, sizeof(*state));
239
}
240