scons: Set the default windows platform to be windows userspace.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast.c
1 /**************************************************************************
2 *
3 * Copyright 2009 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 #include <limits.h>
29 #include "util/u_memory.h"
30 #include "util/u_math.h"
31 #include "util/u_cpu_detect.h"
32 #include "util/u_surface.h"
33
34 #include "lp_scene_queue.h"
35 #include "lp_debug.h"
36 #include "lp_fence.h"
37 #include "lp_rast.h"
38 #include "lp_rast_priv.h"
39 #include "lp_tile_soa.h"
40 #include "lp_bld_debug.h"
41 #include "lp_scene.h"
42
43
44 /**
45 * Begin the rasterization phase.
46 * Map the framebuffer surfaces. Initialize the 'rast' state.
47 */
48 static boolean
49 lp_rast_begin( struct lp_rasterizer *rast,
50 const struct pipe_framebuffer_state *fb,
51 boolean write_color,
52 boolean write_zstencil )
53 {
54 struct pipe_screen *screen = rast->screen;
55 struct pipe_surface *cbuf, *zsbuf;
56
57 LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
58
59 util_copy_framebuffer_state(&rast->state.fb, fb);
60
61 rast->state.write_zstencil = write_zstencil;
62 rast->state.write_color = write_color;
63
64 rast->check_for_clipped_tiles = (fb->width % TILE_SIZE != 0 ||
65 fb->height % TILE_SIZE != 0);
66
67 /* XXX support multiple color buffers here */
68 cbuf = rast->state.fb.cbufs[0];
69 if (cbuf) {
70 rast->cbuf_transfer = screen->get_tex_transfer(rast->screen,
71 cbuf->texture,
72 cbuf->face,
73 cbuf->level,
74 cbuf->zslice,
75 PIPE_TRANSFER_READ_WRITE,
76 0, 0,
77 fb->width, fb->height);
78 if (!rast->cbuf_transfer)
79 return FALSE;
80
81 rast->cbuf_map = screen->transfer_map(rast->screen,
82 rast->cbuf_transfer);
83 if (!rast->cbuf_map)
84 return FALSE;
85 }
86
87 zsbuf = rast->state.fb.zsbuf;
88 if (zsbuf) {
89 rast->zsbuf_transfer = screen->get_tex_transfer(rast->screen,
90 zsbuf->texture,
91 zsbuf->face,
92 zsbuf->level,
93 zsbuf->zslice,
94 PIPE_TRANSFER_READ_WRITE,
95 0, 0,
96 fb->width, fb->height);
97 if (!rast->zsbuf_transfer)
98 return FALSE;
99
100 rast->zsbuf_map = screen->transfer_map(rast->screen,
101 rast->zsbuf_transfer);
102 if (!rast->zsbuf_map)
103 return FALSE;
104 }
105
106 return TRUE;
107 }
108
109
110 /**
111 * Finish the rasterization phase.
112 * Unmap framebuffer surfaces.
113 */
114 static void
115 lp_rast_end( struct lp_rasterizer *rast )
116 {
117 struct pipe_screen *screen = rast->screen;
118
119 if (rast->cbuf_map)
120 screen->transfer_unmap(screen, rast->cbuf_transfer);
121
122 if (rast->zsbuf_map)
123 screen->transfer_unmap(screen, rast->zsbuf_transfer);
124
125 if (rast->cbuf_transfer)
126 screen->tex_transfer_destroy(rast->cbuf_transfer);
127
128 if (rast->zsbuf_transfer)
129 screen->tex_transfer_destroy(rast->zsbuf_transfer);
130
131 rast->cbuf_transfer = NULL;
132 rast->zsbuf_transfer = NULL;
133 rast->cbuf_map = NULL;
134 rast->zsbuf_map = NULL;
135 }
136
137
138 /**
139 * Begining rasterization of a tile.
140 * \param x window X position of the tile, in pixels
141 * \param y window Y position of the tile, in pixels
142 */
143 static void
144 lp_rast_start_tile( struct lp_rasterizer *rast,
145 unsigned thread_index,
146 unsigned x, unsigned y )
147 {
148 LP_DBG(DEBUG_RAST, "%s %d,%d\n", __FUNCTION__, x, y);
149
150 rast->tasks[thread_index].x = x;
151 rast->tasks[thread_index].y = y;
152 }
153
154
155 /**
156 * Clear the rasterizer's current color tile.
157 * This is a bin command called during bin processing.
158 */
159 void lp_rast_clear_color( struct lp_rasterizer *rast,
160 unsigned thread_index,
161 const union lp_rast_cmd_arg arg )
162 {
163 const uint8_t *clear_color = arg.clear_color;
164 uint8_t *color_tile = rast->tasks[thread_index].tile.color;
165
166 LP_DBG(DEBUG_RAST, "%s 0x%x,0x%x,0x%x,0x%x\n", __FUNCTION__,
167 clear_color[0],
168 clear_color[1],
169 clear_color[2],
170 clear_color[3]);
171
172 if (clear_color[0] == clear_color[1] &&
173 clear_color[1] == clear_color[2] &&
174 clear_color[2] == clear_color[3]) {
175 memset(color_tile, clear_color[0], TILE_SIZE * TILE_SIZE * 4);
176 }
177 else {
178 unsigned x, y, chan;
179 for (y = 0; y < TILE_SIZE; y++)
180 for (x = 0; x < TILE_SIZE; x++)
181 for (chan = 0; chan < 4; ++chan)
182 TILE_PIXEL(color_tile, x, y, chan) = clear_color[chan];
183 }
184 }
185
186
187 /**
188 * Clear the rasterizer's current z/stencil tile.
189 * This is a bin command called during bin processing.
190 */
191 void lp_rast_clear_zstencil( struct lp_rasterizer *rast,
192 unsigned thread_index,
193 const union lp_rast_cmd_arg arg)
194 {
195 unsigned i, j;
196 uint32_t *depth_tile = rast->tasks[thread_index].tile.depth;
197
198 LP_DBG(DEBUG_RAST, "%s 0x%x\n", __FUNCTION__, arg.clear_zstencil);
199
200 for (i = 0; i < TILE_SIZE; i++)
201 for (j = 0; j < TILE_SIZE; j++)
202 depth_tile[i*TILE_SIZE + j] = arg.clear_zstencil;
203 }
204
205
206 /**
207 * Load tile color from the framebuffer surface.
208 * This is a bin command called during bin processing.
209 */
210 void lp_rast_load_color( struct lp_rasterizer *rast,
211 unsigned thread_index,
212 const union lp_rast_cmd_arg arg)
213 {
214 struct lp_rasterizer_task *task = &rast->tasks[thread_index];
215 const unsigned x = task->x;
216 const unsigned y = task->y;
217 int w = TILE_SIZE;
218 int h = TILE_SIZE;
219
220 LP_DBG(DEBUG_RAST, "%s at %u, %u\n", __FUNCTION__, x, y);
221
222 if (x + w > rast->state.fb.width)
223 w -= x + w - rast->state.fb.width;
224
225 if (y + h > rast->state.fb.height)
226 h -= y + h - rast->state.fb.height;
227
228 assert(w >= 0);
229 assert(h >= 0);
230 assert(w <= TILE_SIZE);
231 assert(h <= TILE_SIZE);
232
233 lp_tile_read_4ub(rast->cbuf_transfer->format,
234 rast->tasks[thread_index].tile.color,
235 rast->cbuf_map,
236 rast->cbuf_transfer->stride,
237 x, y,
238 w, h);
239 }
240
241
242 /**
243 * Load tile z/stencil from the framebuffer surface.
244 * This is a bin command called during bin processing.
245 */
246 void lp_rast_load_zstencil( struct lp_rasterizer *rast,
247 unsigned thread_index,
248 const union lp_rast_cmd_arg arg )
249 {
250 LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
251
252 /* call u_tile func to load depth (and stencil?) from surface */
253 }
254
255
256 void lp_rast_set_state( struct lp_rasterizer *rast,
257 unsigned thread_index,
258 const union lp_rast_cmd_arg arg )
259 {
260 const struct lp_rast_state *state = arg.set_state;
261
262 LP_DBG(DEBUG_RAST, "%s %p\n", __FUNCTION__, (void *) state);
263
264 /* just set the current state pointer for this rasterizer */
265 rast->tasks[thread_index].current_state = state;
266 }
267
268
269
270 /* Within a tile:
271 */
272
273 /**
274 * Run the shader on all blocks in a tile. This is used when a tile is
275 * completely contained inside a triangle.
276 * This is a bin command called during bin processing.
277 */
278 void lp_rast_shade_tile( struct lp_rasterizer *rast,
279 unsigned thread_index,
280 const union lp_rast_cmd_arg arg )
281 {
282 /* Set c1,c2,c3 to large values so the in/out test always passes */
283 const int32_t c1 = INT_MIN, c2 = INT_MIN, c3 = INT_MIN;
284 const struct lp_rast_shader_inputs *inputs = arg.shade_tile;
285 const unsigned tile_x = rast->tasks[thread_index].x;
286 const unsigned tile_y = rast->tasks[thread_index].y;
287 unsigned x, y;
288
289 LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
290
291 /* Use the existing preference for 4x4 (four quads) shading:
292 */
293 for (y = 0; y < TILE_SIZE; y += 4)
294 for (x = 0; x < TILE_SIZE; x += 4)
295 lp_rast_shade_quads( rast,
296 thread_index,
297 inputs,
298 tile_x + x,
299 tile_y + y,
300 c1, c2, c3);
301 }
302
303
304 /**
305 * Compute shading for a 4x4 block of pixels.
306 * This is a bin command called during bin processing.
307 */
308 void lp_rast_shade_quads( struct lp_rasterizer *rast,
309 unsigned thread_index,
310 const struct lp_rast_shader_inputs *inputs,
311 unsigned x, unsigned y,
312 int32_t c1, int32_t c2, int32_t c3)
313 {
314 const struct lp_rast_state *state = rast->tasks[thread_index].current_state;
315 struct lp_rast_tile *tile = &rast->tasks[thread_index].tile;
316 void *color;
317 void *depth;
318 unsigned ix, iy;
319 int block_offset;
320
321 #ifdef DEBUG
322 assert(state);
323
324 /* Sanity checks */
325 assert(x % TILE_VECTOR_WIDTH == 0);
326 assert(y % TILE_VECTOR_HEIGHT == 0);
327
328 assert((x % 4) == 0);
329 assert((y % 4) == 0);
330 #endif
331
332 ix = x % TILE_SIZE;
333 iy = y % TILE_SIZE;
334
335 /* offset of the 16x16 pixel block within the tile */
336 block_offset = ((iy/4)*(16*16) + (ix/4)*16);
337
338 /* color buffer */
339 color = tile->color + 4 * block_offset;
340
341 /* depth buffer */
342 depth = tile->depth + block_offset;
343
344 #ifdef DEBUG
345 assert(lp_check_alignment(depth, 16));
346 assert(lp_check_alignment(color, 16));
347 assert(lp_check_alignment(state->jit_context.blend_color, 16));
348
349 assert(lp_check_alignment(inputs->step[0], 16));
350 assert(lp_check_alignment(inputs->step[1], 16));
351 assert(lp_check_alignment(inputs->step[2], 16));
352 #endif
353
354 /* run shader */
355 state->jit_function( &state->jit_context,
356 x, y,
357 inputs->a0,
358 inputs->dadx,
359 inputs->dady,
360 color,
361 depth,
362 c1, c2, c3,
363 inputs->step[0], inputs->step[1], inputs->step[2]
364 );
365 }
366
367
368 /* End of tile:
369 */
370
371
372 /**
373 * Write the rasterizer's color tile to the framebuffer.
374 */
375 static void lp_rast_store_color( struct lp_rasterizer *rast,
376 unsigned thread_index)
377 {
378 const unsigned x = rast->tasks[thread_index].x;
379 const unsigned y = rast->tasks[thread_index].y;
380 int w = TILE_SIZE;
381 int h = TILE_SIZE;
382
383 if (x + w > rast->state.fb.width)
384 w -= x + w - rast->state.fb.width;
385
386 if (y + h > rast->state.fb.height)
387 h -= y + h - rast->state.fb.height;
388
389 assert(w >= 0);
390 assert(h >= 0);
391 assert(w <= TILE_SIZE);
392 assert(h <= TILE_SIZE);
393
394 LP_DBG(DEBUG_RAST, "%s [%u] %d,%d %dx%d\n", __FUNCTION__,
395 thread_index, x, y, w, h);
396
397 lp_tile_write_4ub(rast->cbuf_transfer->format,
398 rast->tasks[thread_index].tile.color,
399 rast->cbuf_map,
400 rast->cbuf_transfer->stride,
401 x, y,
402 w, h);
403 }
404
405
406 static void
407 lp_tile_write_z32(const uint32_t *src, uint8_t *dst, unsigned dst_stride,
408 unsigned x0, unsigned y0, unsigned w, unsigned h)
409 {
410 unsigned x, y;
411 uint8_t *dst_row = dst + y0*dst_stride;
412 for (y = 0; y < h; ++y) {
413 uint32_t *dst_pixel = (uint32_t *)(dst_row + x0*4);
414 for (x = 0; x < w; ++x) {
415 *dst_pixel++ = *src++;
416 }
417 dst_row += dst_stride;
418 }
419 }
420
421 /**
422 * Write the rasterizer's z/stencil tile to the framebuffer.
423 */
424 static void lp_rast_store_zstencil( struct lp_rasterizer *rast,
425 unsigned thread_index )
426 {
427 const unsigned x = rast->tasks[thread_index].x;
428 const unsigned y = rast->tasks[thread_index].y;
429 unsigned w = TILE_SIZE;
430 unsigned h = TILE_SIZE;
431
432 if (x + w > rast->state.fb.width)
433 w -= x + w - rast->state.fb.width;
434
435 if (y + h > rast->state.fb.height)
436 h -= y + h - rast->state.fb.height;
437
438 LP_DBG(DEBUG_RAST, "%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h);
439
440 assert(rast->zsbuf_transfer->format == PIPE_FORMAT_Z32_UNORM);
441 lp_tile_write_z32(rast->tasks[thread_index].tile.depth,
442 rast->zsbuf_map,
443 rast->zsbuf_transfer->stride,
444 x, y, w, h);
445 }
446
447
448 /**
449 * Write the rasterizer's tiles to the framebuffer.
450 */
451 static void
452 lp_rast_end_tile( struct lp_rasterizer *rast,
453 unsigned thread_index )
454 {
455 LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
456
457 if (rast->state.write_color)
458 lp_rast_store_color(rast, thread_index);
459
460 if (rast->state.write_zstencil)
461 lp_rast_store_zstencil(rast, thread_index);
462 }
463
464
465 /**
466 * Signal on a fence. This is called during bin execution/rasterization.
467 * Called per thread.
468 */
469 void lp_rast_fence( struct lp_rasterizer *rast,
470 unsigned thread_index,
471 const union lp_rast_cmd_arg arg )
472 {
473 struct lp_fence *fence = arg.fence;
474
475 pipe_mutex_lock( fence->mutex );
476
477 fence->count++;
478 assert(fence->count <= fence->rank);
479
480 LP_DBG(DEBUG_RAST, "%s count=%u rank=%u\n", __FUNCTION__,
481 fence->count, fence->rank);
482
483 pipe_condvar_signal( fence->signalled );
484
485 pipe_mutex_unlock( fence->mutex );
486 }
487
488
489 /**
490 * When all the threads are done rasterizing a scene, one thread will
491 * call this function to reset the scene and put it onto the empty queue.
492 */
493 static void
494 release_scene( struct lp_rasterizer *rast,
495 struct lp_scene *scene )
496 {
497 util_unreference_framebuffer_state( &scene->fb );
498
499 lp_scene_reset( scene );
500 lp_scene_enqueue( rast->empty_scenes, scene );
501 rast->curr_scene = NULL;
502 }
503
504
505 /**
506 * Rasterize commands for a single bin.
507 * \param x, y position of the bin's tile in the framebuffer
508 * Must be called between lp_rast_begin() and lp_rast_end().
509 * Called per thread.
510 */
511 static void
512 rasterize_bin( struct lp_rasterizer *rast,
513 unsigned thread_index,
514 const struct cmd_bin *bin,
515 int x, int y)
516 {
517 const struct cmd_block_list *commands = &bin->commands;
518 struct cmd_block *block;
519 unsigned k;
520
521 lp_rast_start_tile( rast, thread_index, x, y );
522
523 /* simply execute each of the commands in the block list */
524 for (block = commands->head; block; block = block->next) {
525 for (k = 0; k < block->count; k++) {
526 block->cmd[k]( rast, thread_index, block->arg[k] );
527 }
528 }
529
530 lp_rast_end_tile( rast, thread_index );
531 }
532
533
534 /**
535 * Rasterize/execute all bins within a scene.
536 * Called per thread.
537 */
538 static void
539 rasterize_scene( struct lp_rasterizer *rast,
540 unsigned thread_index,
541 struct lp_scene *scene,
542 bool write_depth )
543 {
544 /* loop over scene bins, rasterize each */
545 #if 0
546 {
547 unsigned i, j;
548 for (i = 0; i < scene->tiles_x; i++) {
549 for (j = 0; j < scene->tiles_y; j++) {
550 struct cmd_bin *bin = lp_get_bin(scene, i, j);
551 rasterize_bin( rast, thread_index,
552 bin, i * TILE_SIZE, j * TILE_SIZE );
553 }
554 }
555 }
556 #else
557 {
558 struct cmd_bin *bin;
559 int x, y;
560
561 assert(scene);
562 while ((bin = lp_scene_bin_iter_next(scene, &x, &y))) {
563 rasterize_bin( rast, thread_index, bin, x * TILE_SIZE, y * TILE_SIZE);
564 }
565 }
566 #endif
567 }
568
569
570 /**
571 * Called by setup module when it has something for us to render.
572 */
573 void
574 lp_rasterize_scene( struct lp_rasterizer *rast,
575 struct lp_scene *scene,
576 const struct pipe_framebuffer_state *fb,
577 bool write_depth )
578 {
579 boolean debug = false;
580
581 LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__);
582
583 if (debug) {
584 unsigned x, y;
585 printf("rasterize scene:\n");
586 printf(" data size: %u\n", lp_scene_data_size(scene));
587 for (y = 0; y < scene->tiles_y; y++) {
588 for (x = 0; x < scene->tiles_x; x++) {
589 printf(" bin %u, %u size: %u\n", x, y,
590 lp_scene_bin_size(scene, x, y));
591 }
592 }
593 }
594
595 /* save framebuffer state in the bin */
596 util_copy_framebuffer_state(&scene->fb, fb);
597 scene->write_depth = write_depth;
598
599 if (rast->num_threads == 0) {
600 /* no threading */
601
602 lp_rast_begin( rast, fb,
603 fb->cbufs[0]!= NULL,
604 fb->zsbuf != NULL && write_depth );
605
606 lp_scene_bin_iter_begin( scene );
607 rasterize_scene( rast, 0, scene, write_depth );
608
609 release_scene( rast, scene );
610
611 lp_rast_end( rast );
612 }
613 else {
614 /* threaded rendering! */
615 unsigned i;
616
617 lp_scene_enqueue( rast->full_scenes, scene );
618
619 /* signal the threads that there's work to do */
620 for (i = 0; i < rast->num_threads; i++) {
621 pipe_semaphore_signal(&rast->tasks[i].work_ready);
622 }
623
624 /* wait for work to complete */
625 for (i = 0; i < rast->num_threads; i++) {
626 pipe_semaphore_wait(&rast->tasks[i].work_done);
627 }
628 }
629
630 LP_DBG(DEBUG_SETUP, "%s done \n", __FUNCTION__);
631 }
632
633
634 /**
635 * This is the thread's main entrypoint.
636 * It's a simple loop:
637 * 1. wait for work
638 * 2. do work
639 * 3. signal that we're done
640 */
641 static void *
642 thread_func( void *init_data )
643 {
644 struct lp_rasterizer_task *task = (struct lp_rasterizer_task *) init_data;
645 struct lp_rasterizer *rast = task->rast;
646 boolean debug = false;
647
648 while (1) {
649 /* wait for work */
650 if (debug)
651 debug_printf("thread %d waiting for work\n", task->thread_index);
652 pipe_semaphore_wait(&task->work_ready);
653
654 if (task->thread_index == 0) {
655 /* thread[0]:
656 * - get next scene to rasterize
657 * - map the framebuffer surfaces
658 */
659 const struct pipe_framebuffer_state *fb;
660 boolean write_depth;
661
662 rast->curr_scene = lp_scene_dequeue( rast->full_scenes );
663
664 lp_scene_bin_iter_begin( rast->curr_scene );
665
666 fb = &rast->curr_scene->fb;
667 write_depth = rast->curr_scene->write_depth;
668
669 lp_rast_begin( rast, fb,
670 fb->cbufs[0] != NULL,
671 fb->zsbuf != NULL && write_depth );
672 }
673
674 /* Wait for all threads to get here so that threads[1+] don't
675 * get a null rast->curr_scene pointer.
676 */
677 pipe_barrier_wait( &rast->barrier );
678
679 /* do work */
680 if (debug)
681 debug_printf("thread %d doing work\n", task->thread_index);
682 rasterize_scene(rast,
683 task->thread_index,
684 rast->curr_scene,
685 rast->curr_scene->write_depth);
686
687 /* wait for all threads to finish with this scene */
688 pipe_barrier_wait( &rast->barrier );
689
690 if (task->thread_index == 0) {
691 /* thread[0]:
692 * - release the scene object
693 * - unmap the framebuffer surfaces
694 */
695 release_scene( rast, rast->curr_scene );
696 lp_rast_end( rast );
697 }
698
699 /* signal done with work */
700 if (debug)
701 debug_printf("thread %d done working\n", task->thread_index);
702 pipe_semaphore_signal(&task->work_done);
703 }
704
705 return NULL;
706 }
707
708
709 /**
710 * Initialize semaphores and spawn the threads.
711 */
712 static void
713 create_rast_threads(struct lp_rasterizer *rast)
714 {
715 unsigned i;
716
717 rast->num_threads = util_cpu_caps.nr_cpus;
718 rast->num_threads = debug_get_num_option("LP_NUM_THREADS", rast->num_threads);
719 rast->num_threads = MIN2(rast->num_threads, MAX_THREADS);
720
721 /* NOTE: if num_threads is zero, we won't use any threads */
722 for (i = 0; i < rast->num_threads; i++) {
723 pipe_semaphore_init(&rast->tasks[i].work_ready, 0);
724 pipe_semaphore_init(&rast->tasks[i].work_done, 0);
725 rast->threads[i] = pipe_thread_create(thread_func,
726 (void *) &rast->tasks[i]);
727 }
728 }
729
730
731
732 /**
733 * Create new lp_rasterizer.
734 * \param empty the queue to put empty scenes on after we've finished
735 * processing them.
736 */
737 struct lp_rasterizer *
738 lp_rast_create( struct pipe_screen *screen, struct lp_scene_queue *empty )
739 {
740 struct lp_rasterizer *rast;
741 unsigned i;
742
743 rast = CALLOC_STRUCT(lp_rasterizer);
744 if(!rast)
745 return NULL;
746
747 rast->screen = screen;
748
749 rast->empty_scenes = empty;
750 rast->full_scenes = lp_scene_queue_create();
751
752 for (i = 0; i < Elements(rast->tasks); i++) {
753 rast->tasks[i].tile.color = align_malloc( TILE_SIZE*TILE_SIZE*4, 16 );
754 rast->tasks[i].tile.depth = align_malloc( TILE_SIZE*TILE_SIZE*4, 16 );
755 rast->tasks[i].rast = rast;
756 rast->tasks[i].thread_index = i;
757 }
758
759 create_rast_threads(rast);
760
761 /* for synchronizing rasterization threads */
762 pipe_barrier_init( &rast->barrier, rast->num_threads );
763
764 return rast;
765 }
766
767
768 /* Shutdown:
769 */
770 void lp_rast_destroy( struct lp_rasterizer *rast )
771 {
772 unsigned i;
773
774 util_unreference_framebuffer_state(&rast->state.fb);
775
776 for (i = 0; i < Elements(rast->tasks); i++) {
777 align_free(rast->tasks[i].tile.depth);
778 align_free(rast->tasks[i].tile.color);
779 }
780
781 /* for synchronizing rasterization threads */
782 pipe_barrier_destroy( &rast->barrier );
783
784 FREE(rast);
785 }
786
787
788 /** Return number of rasterization threads */
789 unsigned
790 lp_rast_get_num_threads( struct lp_rasterizer *rast )
791 {
792 return rast->num_threads;
793 }