1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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 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.
26 **************************************************************************/
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"
34 #include "lp_scene_queue.h"
38 #include "lp_rast_priv.h"
39 #include "lp_tile_soa.h"
40 #include "lp_bld_debug.h"
45 * Begin the rasterization phase.
46 * Map the framebuffer surfaces. Initialize the 'rast' state.
49 lp_rast_begin( struct lp_rasterizer
*rast
,
50 const struct pipe_framebuffer_state
*fb
,
52 boolean write_zstencil
)
54 struct pipe_screen
*screen
= rast
->screen
;
55 struct pipe_surface
*cbuf
, *zsbuf
;
58 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
60 util_copy_framebuffer_state(&rast
->state
.fb
, fb
);
62 rast
->state
.write_zstencil
= write_zstencil
;
63 rast
->state
.write_color
= write_color
;
65 rast
->check_for_clipped_tiles
= (fb
->width
% TILE_SIZE
!= 0 ||
66 fb
->height
% TILE_SIZE
!= 0);
69 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++) {
70 cbuf
= rast
->state
.fb
.cbufs
[i
];
72 rast
->cbuf_transfer
[i
] = screen
->get_tex_transfer(rast
->screen
,
77 PIPE_TRANSFER_READ_WRITE
,
81 if (!rast
->cbuf_transfer
[i
])
84 rast
->cbuf_map
[i
] = screen
->transfer_map(rast
->screen
,
85 rast
->cbuf_transfer
[i
]);
86 if (!rast
->cbuf_map
[i
])
91 zsbuf
= rast
->state
.fb
.zsbuf
;
93 rast
->zsbuf_transfer
= screen
->get_tex_transfer(rast
->screen
,
98 PIPE_TRANSFER_READ_WRITE
,
102 if (!rast
->zsbuf_transfer
)
105 rast
->zsbuf_map
= screen
->transfer_map(rast
->screen
,
106 rast
->zsbuf_transfer
);
107 if (!rast
->zsbuf_map
)
114 /* Unmap and release transfers?
121 * Finish the rasterization phase.
122 * Unmap framebuffer surfaces.
125 lp_rast_end( struct lp_rasterizer
*rast
)
127 struct pipe_screen
*screen
= rast
->screen
;
130 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++) {
131 if (rast
->cbuf_map
[i
])
132 screen
->transfer_unmap(screen
, rast
->cbuf_transfer
[i
]);
134 if (rast
->cbuf_transfer
[i
])
135 screen
->tex_transfer_destroy(rast
->cbuf_transfer
[i
]);
137 rast
->cbuf_transfer
[i
] = NULL
;
138 rast
->cbuf_map
[i
] = NULL
;
142 screen
->transfer_unmap(screen
, rast
->zsbuf_transfer
);
144 if (rast
->zsbuf_transfer
)
145 screen
->tex_transfer_destroy(rast
->zsbuf_transfer
);
147 rast
->zsbuf_transfer
= NULL
;
148 rast
->zsbuf_map
= NULL
;
153 * Begining rasterization of a tile.
154 * \param x window X position of the tile, in pixels
155 * \param y window Y position of the tile, in pixels
158 lp_rast_start_tile( struct lp_rasterizer
*rast
,
159 unsigned thread_index
,
160 unsigned x
, unsigned y
)
162 LP_DBG(DEBUG_RAST
, "%s %d,%d\n", __FUNCTION__
, x
, y
);
164 rast
->tasks
[thread_index
].x
= x
;
165 rast
->tasks
[thread_index
].y
= y
;
170 * Clear the rasterizer's current color tile.
171 * This is a bin command called during bin processing.
173 void lp_rast_clear_color( struct lp_rasterizer
*rast
,
174 unsigned thread_index
,
175 const union lp_rast_cmd_arg arg
)
177 const uint8_t *clear_color
= arg
.clear_color
;
178 uint8_t **color_tile
= rast
->tasks
[thread_index
].tile
.color
;
181 LP_DBG(DEBUG_RAST
, "%s 0x%x,0x%x,0x%x,0x%x\n", __FUNCTION__
,
187 if (clear_color
[0] == clear_color
[1] &&
188 clear_color
[1] == clear_color
[2] &&
189 clear_color
[2] == clear_color
[3]) {
190 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++) {
191 memset(color_tile
[i
], clear_color
[0], TILE_SIZE
* TILE_SIZE
* 4);
196 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++)
197 for (y
= 0; y
< TILE_SIZE
; y
++)
198 for (x
= 0; x
< TILE_SIZE
; x
++)
199 for (chan
= 0; chan
< 4; ++chan
)
200 TILE_PIXEL(color_tile
[i
], x
, y
, chan
) = clear_color
[chan
];
206 * Clear the rasterizer's current z/stencil tile.
207 * This is a bin command called during bin processing.
209 void lp_rast_clear_zstencil( struct lp_rasterizer
*rast
,
210 unsigned thread_index
,
211 const union lp_rast_cmd_arg arg
)
214 uint32_t *depth_tile
= rast
->tasks
[thread_index
].tile
.depth
;
216 LP_DBG(DEBUG_RAST
, "%s 0x%x\n", __FUNCTION__
, arg
.clear_zstencil
);
218 for (i
= 0; i
< TILE_SIZE
; i
++)
219 for (j
= 0; j
< TILE_SIZE
; j
++)
220 depth_tile
[i
*TILE_SIZE
+ j
] = arg
.clear_zstencil
;
225 * Load tile color from the framebuffer surface.
226 * This is a bin command called during bin processing.
228 void lp_rast_load_color( struct lp_rasterizer
*rast
,
229 unsigned thread_index
,
230 const union lp_rast_cmd_arg arg
)
232 struct lp_rasterizer_task
*task
= &rast
->tasks
[thread_index
];
233 const unsigned x
= task
->x
;
234 const unsigned y
= task
->y
;
237 LP_DBG(DEBUG_RAST
, "%s at %u, %u\n", __FUNCTION__
, x
, y
);
239 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++) {
240 struct pipe_transfer
*transfer
= rast
->cbuf_transfer
[i
];
244 if (x
>= transfer
->width
)
247 if (y
>= transfer
->height
)
249 /* XXX: require tile-size aligned render target dimensions:
251 if (x
+ w
> transfer
->width
)
252 w
-= x
+ w
- transfer
->width
;
254 if (y
+ h
> transfer
->height
)
255 h
-= y
+ h
- transfer
->height
;
259 assert(w
<= TILE_SIZE
);
260 assert(h
<= TILE_SIZE
);
262 lp_tile_read_4ub(transfer
->texture
->format
,
263 rast
->tasks
[thread_index
].tile
.color
[i
],
273 lp_tile_read_z32(uint32_t *tile
,
276 unsigned x0
, unsigned y0
, unsigned w
, unsigned h
)
279 const uint8_t *map_row
= map
+ y0
*map_stride
;
280 for (y
= 0; y
< h
; ++y
) {
281 const uint32_t *map_pixel
= (uint32_t *)(map_row
+ x0
*4);
282 for (x
= 0; x
< w
; ++x
) {
283 *tile
++ = *map_pixel
++;
285 map_row
+= map_stride
;
290 * Load tile z/stencil from the framebuffer surface.
291 * This is a bin command called during bin processing.
293 void lp_rast_load_zstencil( struct lp_rasterizer
*rast
,
294 unsigned thread_index
,
295 const union lp_rast_cmd_arg arg
)
297 const unsigned x
= rast
->tasks
[thread_index
].x
;
298 const unsigned y
= rast
->tasks
[thread_index
].y
;
299 unsigned w
= TILE_SIZE
;
300 unsigned h
= TILE_SIZE
;
302 if (x
+ w
> rast
->state
.fb
.width
)
303 w
-= x
+ w
- rast
->state
.fb
.width
;
305 if (y
+ h
> rast
->state
.fb
.height
)
306 h
-= y
+ h
- rast
->state
.fb
.height
;
308 LP_DBG(DEBUG_RAST
, "%s %d,%d %dx%d\n", __FUNCTION__
, x
, y
, w
, h
);
310 assert(rast
->zsbuf_transfer
->texture
->format
== PIPE_FORMAT_Z32_UNORM
);
311 lp_tile_read_z32(rast
->tasks
[thread_index
].tile
.depth
,
313 rast
->zsbuf_transfer
->stride
,
318 void lp_rast_set_state( struct lp_rasterizer
*rast
,
319 unsigned thread_index
,
320 const union lp_rast_cmd_arg arg
)
322 const struct lp_rast_state
*state
= arg
.set_state
;
324 LP_DBG(DEBUG_RAST
, "%s %p\n", __FUNCTION__
, (void *) state
);
326 /* just set the current state pointer for this rasterizer */
327 rast
->tasks
[thread_index
].current_state
= state
;
336 * Run the shader on all blocks in a tile. This is used when a tile is
337 * completely contained inside a triangle.
338 * This is a bin command called during bin processing.
340 void lp_rast_shade_tile( struct lp_rasterizer
*rast
,
341 unsigned thread_index
,
342 const union lp_rast_cmd_arg arg
)
344 /* Set c1,c2,c3 to large values so the in/out test always passes */
345 const int32_t c1
= INT_MIN
, c2
= INT_MIN
, c3
= INT_MIN
;
346 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
347 const unsigned tile_x
= rast
->tasks
[thread_index
].x
;
348 const unsigned tile_y
= rast
->tasks
[thread_index
].y
;
351 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
353 /* Use the existing preference for 4x4 (four quads) shading:
355 for (y
= 0; y
< TILE_SIZE
; y
+= 4)
356 for (x
= 0; x
< TILE_SIZE
; x
+= 4)
357 lp_rast_shade_quads( rast
,
367 * Compute shading for a 4x4 block of pixels.
368 * This is a bin command called during bin processing.
370 void lp_rast_shade_quads( struct lp_rasterizer
*rast
,
371 unsigned thread_index
,
372 const struct lp_rast_shader_inputs
*inputs
,
373 unsigned x
, unsigned y
,
374 int32_t c1
, int32_t c2
, int32_t c3
)
376 const struct lp_rast_state
*state
= rast
->tasks
[thread_index
].current_state
;
377 struct lp_rast_tile
*tile
= &rast
->tasks
[thread_index
].tile
;
378 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
388 assert(x
% TILE_VECTOR_WIDTH
== 0);
389 assert(y
% TILE_VECTOR_HEIGHT
== 0);
391 assert((x
% 4) == 0);
392 assert((y
% 4) == 0);
398 /* offset of the 16x16 pixel block within the tile */
399 block_offset
= ((iy
/4)*(16*16) + (ix
/4)*16);
402 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++)
403 color
[i
] = tile
->color
[i
] + 4 * block_offset
;
406 depth
= tile
->depth
+ block_offset
;
411 assert(lp_check_alignment(tile
->depth
, 16));
412 assert(lp_check_alignment(tile
->color
[0], 16));
413 assert(lp_check_alignment(state
->jit_context
.blend_color
, 16));
415 assert(lp_check_alignment(inputs
->step
[0], 16));
416 assert(lp_check_alignment(inputs
->step
[1], 16));
417 assert(lp_check_alignment(inputs
->step
[2], 16));
421 state
->jit_function( &state
->jit_context
,
429 inputs
->step
[0], inputs
->step
[1], inputs
->step
[2]);
438 * Write the rasterizer's color tile to the framebuffer.
440 static void lp_rast_store_color( struct lp_rasterizer
*rast
,
441 unsigned thread_index
)
443 const unsigned x
= rast
->tasks
[thread_index
].x
;
444 const unsigned y
= rast
->tasks
[thread_index
].y
;
447 for (i
= 0; i
< rast
->state
.fb
.nr_cbufs
; i
++) {
448 struct pipe_transfer
*transfer
= rast
->cbuf_transfer
[i
];
452 if (x
>= transfer
->width
)
455 if (y
>= transfer
->height
)
458 /* XXX: require tile-size aligned render target dimensions:
460 if (x
+ w
> transfer
->width
)
461 w
-= x
+ w
- transfer
->width
;
463 if (y
+ h
> transfer
->height
)
464 h
-= y
+ h
- transfer
->height
;
468 assert(w
<= TILE_SIZE
);
469 assert(h
<= TILE_SIZE
);
471 LP_DBG(DEBUG_RAST
, "%s [%u] %d,%d %dx%d\n", __FUNCTION__
,
472 thread_index
, x
, y
, w
, h
);
474 lp_tile_write_4ub(transfer
->texture
->format
,
475 rast
->tasks
[thread_index
].tile
.color
[i
],
485 lp_tile_write_z32(const uint32_t *src
, uint8_t *dst
, unsigned dst_stride
,
486 unsigned x0
, unsigned y0
, unsigned w
, unsigned h
)
489 uint8_t *dst_row
= dst
+ y0
*dst_stride
;
490 for (y
= 0; y
< h
; ++y
) {
491 uint32_t *dst_pixel
= (uint32_t *)(dst_row
+ x0
*4);
492 for (x
= 0; x
< w
; ++x
) {
493 *dst_pixel
++ = *src
++;
495 dst_row
+= dst_stride
;
500 * Write the rasterizer's z/stencil tile to the framebuffer.
502 static void lp_rast_store_zstencil( struct lp_rasterizer
*rast
,
503 unsigned thread_index
)
505 const unsigned x
= rast
->tasks
[thread_index
].x
;
506 const unsigned y
= rast
->tasks
[thread_index
].y
;
507 unsigned w
= TILE_SIZE
;
508 unsigned h
= TILE_SIZE
;
510 if (x
+ w
> rast
->state
.fb
.width
)
511 w
-= x
+ w
- rast
->state
.fb
.width
;
513 if (y
+ h
> rast
->state
.fb
.height
)
514 h
-= y
+ h
- rast
->state
.fb
.height
;
516 LP_DBG(DEBUG_RAST
, "%s %d,%d %dx%d\n", __FUNCTION__
, x
, y
, w
, h
);
518 assert(rast
->zsbuf_transfer
->texture
->format
== PIPE_FORMAT_Z32_UNORM
);
519 lp_tile_write_z32(rast
->tasks
[thread_index
].tile
.depth
,
521 rast
->zsbuf_transfer
->stride
,
527 * Write the rasterizer's tiles to the framebuffer.
530 lp_rast_end_tile( struct lp_rasterizer
*rast
,
531 unsigned thread_index
)
533 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
535 if (rast
->state
.write_color
)
536 lp_rast_store_color(rast
, thread_index
);
538 if (rast
->state
.write_zstencil
)
539 lp_rast_store_zstencil(rast
, thread_index
);
544 * Signal on a fence. This is called during bin execution/rasterization.
547 void lp_rast_fence( struct lp_rasterizer
*rast
,
548 unsigned thread_index
,
549 const union lp_rast_cmd_arg arg
)
551 struct lp_fence
*fence
= arg
.fence
;
553 pipe_mutex_lock( fence
->mutex
);
556 assert(fence
->count
<= fence
->rank
);
558 LP_DBG(DEBUG_RAST
, "%s count=%u rank=%u\n", __FUNCTION__
,
559 fence
->count
, fence
->rank
);
561 pipe_condvar_signal( fence
->signalled
);
563 pipe_mutex_unlock( fence
->mutex
);
568 * When all the threads are done rasterizing a scene, one thread will
569 * call this function to reset the scene and put it onto the empty queue.
572 release_scene( struct lp_rasterizer
*rast
,
573 struct lp_scene
*scene
)
575 util_unreference_framebuffer_state( &scene
->fb
);
577 lp_scene_reset( scene
);
578 lp_scene_enqueue( rast
->empty_scenes
, scene
);
579 rast
->curr_scene
= NULL
;
584 * Rasterize commands for a single bin.
585 * \param x, y position of the bin's tile in the framebuffer
586 * Must be called between lp_rast_begin() and lp_rast_end().
590 rasterize_bin( struct lp_rasterizer
*rast
,
591 unsigned thread_index
,
592 const struct cmd_bin
*bin
,
595 const struct cmd_block_list
*commands
= &bin
->commands
;
596 struct cmd_block
*block
;
599 lp_rast_start_tile( rast
, thread_index
, x
, y
);
601 /* simply execute each of the commands in the block list */
602 for (block
= commands
->head
; block
; block
= block
->next
) {
603 for (k
= 0; k
< block
->count
; k
++) {
604 block
->cmd
[k
]( rast
, thread_index
, block
->arg
[k
] );
608 lp_rast_end_tile( rast
, thread_index
);
611 /* An empty bin is one that just loads the contents of the tile and
612 * stores them again unchanged. This typically happens when bins have
613 * been flushed for some reason in the middle of a frame, or when
614 * incremental updates are being made to a render target.
616 * Try to avoid doing pointless work in this case.
619 is_empty_bin( const struct cmd_bin
*bin
)
621 const struct cmd_block
*head
= bin
->commands
.head
;
624 /* We emit at most two load-tile commands at the start of the first
625 * command block. If there are more than two commands in the
626 * block, we know that the bin is non-empty.
628 if (head
->next
!= NULL
||
632 for (i
= 0; i
< head
->count
; i
++)
633 if (head
->cmd
[i
] != lp_rast_load_color
&&
634 head
->cmd
[i
] != lp_rast_load_zstencil
)
643 * Rasterize/execute all bins within a scene.
647 rasterize_scene( struct lp_rasterizer
*rast
,
648 unsigned thread_index
,
649 struct lp_scene
*scene
,
652 /* loop over scene bins, rasterize each */
656 for (i
= 0; i
< scene
->tiles_x
; i
++) {
657 for (j
= 0; j
< scene
->tiles_y
; j
++) {
658 struct cmd_bin
*bin
= lp_get_bin(scene
, i
, j
);
659 rasterize_bin( rast
, thread_index
,
660 bin
, i
* TILE_SIZE
, j
* TILE_SIZE
);
670 while ((bin
= lp_scene_bin_iter_next(scene
, &x
, &y
))) {
671 if (!is_empty_bin( bin
))
672 rasterize_bin( rast
, thread_index
, bin
, x
* TILE_SIZE
, y
* TILE_SIZE
);
680 * Called by setup module when it has something for us to render.
683 lp_rasterize_scene( struct lp_rasterizer
*rast
,
684 struct lp_scene
*scene
,
685 const struct pipe_framebuffer_state
*fb
,
688 boolean debug
= false;
690 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
694 printf("rasterize scene:\n");
695 printf(" data size: %u\n", lp_scene_data_size(scene
));
696 for (y
= 0; y
< scene
->tiles_y
; y
++) {
697 for (x
= 0; x
< scene
->tiles_x
; x
++) {
698 printf(" bin %u, %u size: %u\n", x
, y
,
699 lp_scene_bin_size(scene
, x
, y
));
704 /* save framebuffer state in the bin */
705 util_copy_framebuffer_state(&scene
->fb
, fb
);
706 scene
->write_depth
= write_depth
;
708 if (rast
->num_threads
== 0) {
711 lp_rast_begin( rast
, fb
,
712 fb
->nr_cbufs
!= 0, /* always write color if cbufs present */
713 fb
->zsbuf
!= NULL
&& write_depth
);
715 lp_scene_bin_iter_begin( scene
);
716 rasterize_scene( rast
, 0, scene
, write_depth
);
718 release_scene( rast
, scene
);
723 /* threaded rendering! */
726 lp_scene_enqueue( rast
->full_scenes
, scene
);
728 /* signal the threads that there's work to do */
729 for (i
= 0; i
< rast
->num_threads
; i
++) {
730 pipe_semaphore_signal(&rast
->tasks
[i
].work_ready
);
733 /* wait for work to complete */
734 for (i
= 0; i
< rast
->num_threads
; i
++) {
735 pipe_semaphore_wait(&rast
->tasks
[i
].work_done
);
739 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
744 * This is the thread's main entrypoint.
745 * It's a simple loop:
748 * 3. signal that we're done
751 thread_func( void *init_data
)
753 struct lp_rasterizer_task
*task
= (struct lp_rasterizer_task
*) init_data
;
754 struct lp_rasterizer
*rast
= task
->rast
;
755 boolean debug
= false;
760 debug_printf("thread %d waiting for work\n", task
->thread_index
);
761 pipe_semaphore_wait(&task
->work_ready
);
763 if (task
->thread_index
== 0) {
765 * - get next scene to rasterize
766 * - map the framebuffer surfaces
768 const struct pipe_framebuffer_state
*fb
;
771 rast
->curr_scene
= lp_scene_dequeue( rast
->full_scenes
);
773 lp_scene_bin_iter_begin( rast
->curr_scene
);
775 fb
= &rast
->curr_scene
->fb
;
776 write_depth
= rast
->curr_scene
->write_depth
;
778 lp_rast_begin( rast
, fb
,
780 fb
->zsbuf
!= NULL
&& write_depth
);
783 /* Wait for all threads to get here so that threads[1+] don't
784 * get a null rast->curr_scene pointer.
786 pipe_barrier_wait( &rast
->barrier
);
790 debug_printf("thread %d doing work\n", task
->thread_index
);
791 rasterize_scene(rast
,
794 rast
->curr_scene
->write_depth
);
796 /* wait for all threads to finish with this scene */
797 pipe_barrier_wait( &rast
->barrier
);
799 if (task
->thread_index
== 0) {
801 * - release the scene object
802 * - unmap the framebuffer surfaces
804 release_scene( rast
, rast
->curr_scene
);
808 /* signal done with work */
810 debug_printf("thread %d done working\n", task
->thread_index
);
811 pipe_semaphore_signal(&task
->work_done
);
819 * Initialize semaphores and spawn the threads.
822 create_rast_threads(struct lp_rasterizer
*rast
)
826 rast
->num_threads
= util_cpu_caps
.nr_cpus
;
827 rast
->num_threads
= debug_get_num_option("LP_NUM_THREADS", rast
->num_threads
);
828 rast
->num_threads
= MIN2(rast
->num_threads
, MAX_THREADS
);
830 /* NOTE: if num_threads is zero, we won't use any threads */
831 for (i
= 0; i
< rast
->num_threads
; i
++) {
832 pipe_semaphore_init(&rast
->tasks
[i
].work_ready
, 0);
833 pipe_semaphore_init(&rast
->tasks
[i
].work_done
, 0);
834 rast
->threads
[i
] = pipe_thread_create(thread_func
,
835 (void *) &rast
->tasks
[i
]);
842 * Create new lp_rasterizer.
843 * \param empty the queue to put empty scenes on after we've finished
846 struct lp_rasterizer
*
847 lp_rast_create( struct pipe_screen
*screen
, struct lp_scene_queue
*empty
)
849 struct lp_rasterizer
*rast
;
852 rast
= CALLOC_STRUCT(lp_rasterizer
);
856 rast
->screen
= screen
;
858 rast
->empty_scenes
= empty
;
859 rast
->full_scenes
= lp_scene_queue_create();
861 for (i
= 0; i
< Elements(rast
->tasks
); i
++) {
862 for (cbuf
= 0; cbuf
< PIPE_MAX_COLOR_BUFS
; cbuf
++ )
863 rast
->tasks
[i
].tile
.color
[cbuf
] = align_malloc( TILE_SIZE
*TILE_SIZE
*4, 16 );
865 rast
->tasks
[i
].tile
.depth
= align_malloc( TILE_SIZE
*TILE_SIZE
*4, 16 );
866 rast
->tasks
[i
].rast
= rast
;
867 rast
->tasks
[i
].thread_index
= i
;
870 create_rast_threads(rast
);
872 /* for synchronizing rasterization threads */
873 pipe_barrier_init( &rast
->barrier
, rast
->num_threads
);
881 void lp_rast_destroy( struct lp_rasterizer
*rast
)
885 util_unreference_framebuffer_state(&rast
->state
.fb
);
887 for (i
= 0; i
< Elements(rast
->tasks
); i
++) {
888 align_free(rast
->tasks
[i
].tile
.depth
);
889 for (cbuf
= 0; cbuf
< PIPE_MAX_COLOR_BUFS
; cbuf
++ )
890 align_free(rast
->tasks
[i
].tile
.color
[cbuf
]);
893 /* for synchronizing rasterization threads */
894 pipe_barrier_destroy( &rast
->barrier
);
900 /** Return number of rasterization threads */
902 lp_rast_get_num_threads( struct lp_rasterizer
*rast
)
904 return rast
->num_threads
;