00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "util/u_memory.h"
00034 #include "pipe/p_inlines.h"
00035 #include "draw/draw_context.h"
00036 #include "cell_context.h"
00037 #include "cell_flush.h"
00038 #include "cell_state.h"
00039 #include "cell_texture.h"
00040 #include "cell_state_per_fragment.h"
00041
00042
00043
00044 static void *
00045 cell_create_blend_state(struct pipe_context *pipe,
00046 const struct pipe_blend_state *blend)
00047 {
00048 struct cell_blend_state *cb = MALLOC(sizeof(struct cell_blend_state));
00049
00050 (void) memcpy(cb, blend, sizeof(*blend));
00051 #if 0
00052 cell_generate_alpha_blend(cb);
00053 #endif
00054 return cb;
00055 }
00056
00057
00058 static void
00059 cell_bind_blend_state(struct pipe_context *pipe, void *state)
00060 {
00061 struct cell_context *cell = cell_context(pipe);
00062
00063 draw_flush(cell->draw);
00064
00065 cell->blend = (struct cell_blend_state *) state;
00066 cell->dirty |= CELL_NEW_BLEND;
00067 }
00068
00069
00070 static void
00071 cell_delete_blend_state(struct pipe_context *pipe, void *blend)
00072 {
00073 struct cell_blend_state *cb = (struct cell_blend_state *) blend;
00074
00075 spe_release_func(& cb->code);
00076 FREE(cb);
00077 }
00078
00079
00080 static void
00081 cell_set_blend_color(struct pipe_context *pipe,
00082 const struct pipe_blend_color *blend_color)
00083 {
00084 struct cell_context *cell = cell_context(pipe);
00085
00086 draw_flush(cell->draw);
00087
00088 cell->blend_color = *blend_color;
00089
00090 cell->dirty |= CELL_NEW_BLEND;
00091 }
00092
00093
00094
00095
00096 static void *
00097 cell_create_depth_stencil_alpha_state(struct pipe_context *pipe,
00098 const struct pipe_depth_stencil_alpha_state *depth_stencil)
00099 {
00100 struct cell_depth_stencil_alpha_state *cdsa =
00101 MALLOC(sizeof(struct cell_depth_stencil_alpha_state));
00102
00103 (void) memcpy(cdsa, depth_stencil, sizeof(*depth_stencil));
00104 #if 0
00105 cell_generate_depth_stencil_test(cdsa);
00106 #endif
00107 return cdsa;
00108 }
00109
00110
00111 static void
00112 cell_bind_depth_stencil_alpha_state(struct pipe_context *pipe,
00113 void *depth_stencil)
00114 {
00115 struct cell_context *cell = cell_context(pipe);
00116
00117 draw_flush(cell->draw);
00118
00119 cell->depth_stencil =
00120 (struct cell_depth_stencil_alpha_state *) depth_stencil;
00121 cell->dirty |= CELL_NEW_DEPTH_STENCIL;
00122 }
00123
00124
00125 static void
00126 cell_delete_depth_stencil_alpha_state(struct pipe_context *pipe, void *depth)
00127 {
00128 struct cell_depth_stencil_alpha_state *cdsa =
00129 (struct cell_depth_stencil_alpha_state *) depth;
00130
00131 spe_release_func(& cdsa->code);
00132 FREE(cdsa);
00133 }
00134
00135
00136 static void
00137 cell_set_clip_state(struct pipe_context *pipe,
00138 const struct pipe_clip_state *clip)
00139 {
00140 struct cell_context *cell = cell_context(pipe);
00141
00142
00143 draw_set_clip_state(cell->draw, clip);
00144 }
00145
00146
00147
00148
00149
00150
00151 static void
00152 cell_set_viewport_state( struct pipe_context *pipe,
00153 const struct pipe_viewport_state *viewport )
00154 {
00155 struct cell_context *cell = cell_context(pipe);
00156
00157 cell->viewport = *viewport;
00158 cell->dirty |= CELL_NEW_VIEWPORT;
00159
00160
00161 draw_set_viewport_state(cell->draw, viewport);
00162
00163
00164
00165
00166 }
00167
00168
00169 static void
00170 cell_set_scissor_state( struct pipe_context *pipe,
00171 const struct pipe_scissor_state *scissor )
00172 {
00173 struct cell_context *cell = cell_context(pipe);
00174
00175 memcpy( &cell->scissor, scissor, sizeof(*scissor) );
00176 cell->dirty |= CELL_NEW_SCISSOR;
00177 }
00178
00179
00180 static void
00181 cell_set_polygon_stipple( struct pipe_context *pipe,
00182 const struct pipe_poly_stipple *stipple )
00183 {
00184 struct cell_context *cell = cell_context(pipe);
00185
00186 memcpy( &cell->poly_stipple, stipple, sizeof(*stipple) );
00187 cell->dirty |= CELL_NEW_STIPPLE;
00188 }
00189
00190
00191
00192 static void *
00193 cell_create_rasterizer_state(struct pipe_context *pipe,
00194 const struct pipe_rasterizer_state *setup)
00195 {
00196 struct pipe_rasterizer_state *state
00197 = MALLOC(sizeof(struct pipe_rasterizer_state));
00198 memcpy(state, setup, sizeof(struct pipe_rasterizer_state));
00199 return state;
00200 }
00201
00202
00203 static void
00204 cell_bind_rasterizer_state(struct pipe_context *pipe, void *setup)
00205 {
00206 struct cell_context *cell = cell_context(pipe);
00207
00208
00209 draw_set_rasterizer_state(cell->draw, setup);
00210
00211 cell->rasterizer = (struct pipe_rasterizer_state *)setup;
00212
00213 cell->dirty |= CELL_NEW_RASTERIZER;
00214 }
00215
00216
00217 static void
00218 cell_delete_rasterizer_state(struct pipe_context *pipe, void *rasterizer)
00219 {
00220 FREE(rasterizer);
00221 }
00222
00223
00224
00225 static void *
00226 cell_create_sampler_state(struct pipe_context *pipe,
00227 const struct pipe_sampler_state *sampler)
00228 {
00229 return mem_dup(sampler, sizeof(*sampler));
00230 }
00231
00232
00233 static void
00234 cell_bind_sampler_states(struct pipe_context *pipe,
00235 unsigned num, void **samplers)
00236 {
00237 struct cell_context *cell = cell_context(pipe);
00238
00239 assert(num <= CELL_MAX_SAMPLERS);
00240
00241 draw_flush(cell->draw);
00242
00243 memcpy(cell->sampler, samplers, num * sizeof(void *));
00244 memset(&cell->sampler[num], 0, (CELL_MAX_SAMPLERS - num) *
00245 sizeof(void *));
00246 cell->num_samplers = num;
00247
00248 cell->dirty |= CELL_NEW_SAMPLER;
00249 }
00250
00251
00252 static void
00253 cell_delete_sampler_state(struct pipe_context *pipe,
00254 void *sampler)
00255 {
00256 FREE( sampler );
00257 }
00258
00259
00260
00261 static void
00262 cell_set_sampler_textures(struct pipe_context *pipe,
00263 unsigned num, struct pipe_texture **texture)
00264 {
00265 struct cell_context *cell = cell_context(pipe);
00266 uint i;
00267
00268 assert(num <= CELL_MAX_SAMPLERS);
00269
00270
00271 if (num == cell->num_textures &&
00272 !memcmp(cell->texture, texture, num * sizeof(struct pipe_texture *)))
00273 return;
00274
00275 draw_flush(cell->draw);
00276
00277 for (i = 0; i < CELL_MAX_SAMPLERS; i++) {
00278 struct pipe_texture *tex = i < num ? texture[i] : NULL;
00279
00280 pipe_texture_reference((struct pipe_texture **) &cell->texture[i], tex);
00281 }
00282 cell->num_textures = num;
00283
00284 cell_update_texture_mapping(cell);
00285
00286 cell->dirty |= CELL_NEW_TEXTURE;
00287 }
00288
00289
00290
00291 static void
00292 cell_set_framebuffer_state(struct pipe_context *pipe,
00293 const struct pipe_framebuffer_state *fb)
00294 {
00295 struct cell_context *cell = cell_context(pipe);
00296
00297 if (1 ) {
00298 struct pipe_surface *csurf = fb->cbufs[0];
00299 struct pipe_surface *zsurf = fb->zsbuf;
00300 uint i;
00301 uint flags = (PIPE_BUFFER_USAGE_GPU_WRITE |
00302 PIPE_BUFFER_USAGE_GPU_READ);
00303
00304
00305 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
00306 if (cell->framebuffer.cbufs[i] && cell->cbuf_map[i]) {
00307 pipe_surface_unmap(cell->framebuffer.cbufs[i]);
00308 cell->cbuf_map[i] = NULL;
00309 }
00310 }
00311
00312 if (cell->framebuffer.zsbuf && cell->zsbuf_map) {
00313 pipe_surface_unmap(cell->framebuffer.zsbuf);
00314 cell->zsbuf_map = NULL;
00315 }
00316
00317
00318
00319
00320 cell_flush_int(cell, CELL_FLUSH_WAIT);
00321
00322
00323
00324
00325 cell->framebuffer.width = fb->width;
00326 cell->framebuffer.height = fb->height;
00327 cell->framebuffer.num_cbufs = fb->num_cbufs;
00328 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
00329 pipe_surface_reference(&cell->framebuffer.cbufs[i], fb->cbufs[i]);
00330 }
00331 pipe_surface_reference(&cell->framebuffer.zsbuf, fb->zsbuf);
00332
00333
00334 if (csurf)
00335 cell->cbuf_map[0] = pipe_surface_map(csurf, flags);
00336
00337 if (zsurf)
00338 cell->zsbuf_map = pipe_surface_map(zsurf, flags);
00339
00340 cell->dirty |= CELL_NEW_FRAMEBUFFER;
00341 }
00342 }
00343
00344
00345
00346 void
00347 cell_init_state_functions(struct cell_context *cell)
00348 {
00349 cell->pipe.create_blend_state = cell_create_blend_state;
00350 cell->pipe.bind_blend_state = cell_bind_blend_state;
00351 cell->pipe.delete_blend_state = cell_delete_blend_state;
00352
00353 cell->pipe.create_sampler_state = cell_create_sampler_state;
00354 cell->pipe.bind_sampler_states = cell_bind_sampler_states;
00355 cell->pipe.delete_sampler_state = cell_delete_sampler_state;
00356
00357 cell->pipe.set_sampler_textures = cell_set_sampler_textures;
00358
00359 cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state;
00360 cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state;
00361 cell->pipe.delete_depth_stencil_alpha_state = cell_delete_depth_stencil_alpha_state;
00362
00363 cell->pipe.create_rasterizer_state = cell_create_rasterizer_state;
00364 cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state;
00365 cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state;
00366
00367 cell->pipe.set_blend_color = cell_set_blend_color;
00368 cell->pipe.set_clip_state = cell_set_clip_state;
00369
00370 cell->pipe.set_framebuffer_state = cell_set_framebuffer_state;
00371
00372 cell->pipe.set_polygon_stipple = cell_set_polygon_stipple;
00373 cell->pipe.set_scissor_state = cell_set_scissor_state;
00374 cell->pipe.set_viewport_state = cell_set_viewport_state;
00375 }