1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include "pipe/p_defines.h"
33 #include "st_context.h"
35 #include "st_program.h"
39 /* This is used to initialize st->atoms[]. We could use this list
40 * directly except for a single atom, st_update_constants, which has a
41 * .dirty value which changes according to the parameters of the
42 * current fragment and vertex programs, and so cannot be a static
45 static const struct st_tracked_state
*atoms
[] =
47 &st_update_framebuffer
,
48 &st_update_depth_stencil_alpha
,
53 &st_update_rasterizer
,
54 &st_update_polygon_stipple
,
60 &st_update_vs_constants
,
61 &st_update_fs_constants
,
62 &st_update_pixel_transfer
66 void st_init_atoms( struct st_context
*st
)
70 st
->atoms
= malloc(sizeof(atoms
));
71 st
->nr_atoms
= sizeof(atoms
)/sizeof(*atoms
);
72 memcpy(st
->atoms
, atoms
, sizeof(atoms
));
74 /* Patch in a pointer to the dynamic state atom:
76 for (i
= 0; i
< st
->nr_atoms
; i
++) {
77 if (st
->atoms
[i
] == &st_update_vs_constants
) {
78 st
->atoms
[i
] = &st
->constants
.tracked_state
[PIPE_SHADER_VERTEX
];
79 st
->atoms
[i
][0] = st_update_vs_constants
;
82 if (st
->atoms
[i
] == &st_update_fs_constants
) {
83 st
->atoms
[i
] = &st
->constants
.tracked_state
[PIPE_SHADER_FRAGMENT
];
84 st
->atoms
[i
][0] = st_update_fs_constants
;
90 void st_destroy_atoms( struct st_context
*st
)
99 /***********************************************************************
102 static GLboolean
check_state( const struct st_state_flags
*a
,
103 const struct st_state_flags
*b
)
105 return ((a
->mesa
& b
->mesa
) ||
109 static void accumulate_state( struct st_state_flags
*a
,
110 const struct st_state_flags
*b
)
117 static void xor_states( struct st_state_flags
*result
,
118 const struct st_state_flags
*a
,
119 const struct st_state_flags
*b
)
121 result
->mesa
= a
->mesa
^ b
->mesa
;
122 result
->st
= a
->st
^ b
->st
;
126 /* Too complex to figure out, just check every time:
128 static void check_program_state( struct st_context
*st
)
130 GLcontext
*ctx
= st
->ctx
;
132 if (ctx
->VertexProgram
._Current
!= &st
->vp
->Base
)
133 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
135 if (ctx
->FragmentProgram
._Current
!= &st
->fp
->Base
)
136 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
141 /***********************************************************************
142 * Update all derived state:
145 void st_validate_state( struct st_context
*st
)
147 struct st_state_flags
*state
= &st
->dirty
;
150 check_program_state( st
);
155 // _mesa_printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);
158 /* Debug version which enforces various sanity checks on the
159 * state flags which are generated and checked to help ensure
160 * state atoms are ordered correctly in the list.
162 struct st_state_flags examined
, prev
;
163 memset(&examined
, 0, sizeof(examined
));
166 for (i
= 0; i
< st
->nr_atoms
; i
++) {
167 const struct st_tracked_state
*atom
= st
->atoms
[i
];
168 struct st_state_flags generated
;
170 // _mesa_printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);
172 if (!(atom
->dirty
.mesa
|| atom
->dirty
.st
) ||
174 _mesa_printf("malformed atom %s\n", atom
->name
);
178 if (check_state(state
, &atom
->dirty
)) {
179 st
->atoms
[i
]->update( st
);
180 // _mesa_printf("after: %x\n", atom->dirty.mesa);
183 accumulate_state(&examined
, &atom
->dirty
);
185 /* generated = (prev ^ state)
186 * if (examined & generated)
189 xor_states(&generated
, &prev
, state
);
190 assert(!check_state(&examined
, &generated
));
193 // _mesa_printf("\n");
197 const GLuint nr
= st
->nr_atoms
;
199 for (i
= 0; i
< nr
; i
++) {
200 if (check_state(state
, &st
->atoms
[i
]->dirty
))
201 st
->atoms
[i
]->update( st
);
205 memset(state
, 0, sizeof(*state
));