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_rect.h"
32 #include "util/u_surface.h"
33 #include "util/u_pack_color.h"
35 #include "lp_scene_queue.h"
41 #include "lp_rast_priv.h"
42 #include "lp_tile_soa.h"
43 #include "gallivm/lp_bld_debug.h"
45 #include "lp_tex_sample.h"
50 const struct lp_rast_state
*jit_state
= NULL
;
51 const struct lp_rasterizer_task
*jit_task
= NULL
;
56 * Begin rasterizing a scene.
57 * Called once per scene by one thread.
60 lp_rast_begin( struct lp_rasterizer
*rast
,
61 struct lp_scene
*scene
)
64 rast
->curr_scene
= scene
;
66 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
68 lp_scene_begin_rasterization( scene
);
69 lp_scene_bin_iter_begin( scene
);
74 lp_rast_end( struct lp_rasterizer
*rast
)
76 lp_scene_end_rasterization( rast
->curr_scene
);
78 rast
->curr_scene
= NULL
;
82 debug_printf("Post render scene: tile unswizzle: %u tile swizzle: %u\n",
83 lp_tile_unswizzle_count
, lp_tile_swizzle_count
);
89 * Begining rasterization of a tile.
90 * \param x window X position of the tile, in pixels
91 * \param y window Y position of the tile, in pixels
94 lp_rast_tile_begin(struct lp_rasterizer_task
*task
,
95 const struct cmd_bin
*bin
)
97 const struct lp_scene
*scene
= task
->scene
;
98 enum lp_texture_usage usage
;
100 LP_DBG(DEBUG_RAST
, "%s %d,%d\n", __FUNCTION__
, bin
->x
, bin
->y
);
103 task
->x
= bin
->x
* TILE_SIZE
;
104 task
->y
= bin
->y
* TILE_SIZE
;
106 /* reset pointers to color tile(s) */
107 memset(task
->color_tiles
, 0, sizeof(task
->color_tiles
));
109 /* get pointer to depth/stencil tile */
111 struct pipe_surface
*zsbuf
= task
->scene
->fb
.zsbuf
;
113 struct llvmpipe_resource
*lpt
= llvmpipe_resource(zsbuf
->texture
);
115 if (scene
->has_depthstencil_clear
)
116 usage
= LP_TEX_USAGE_WRITE_ALL
;
118 usage
= LP_TEX_USAGE_READ_WRITE
;
120 /* "prime" the tile: convert data from linear to tiled if necessary
121 * and update the tile's layout info.
123 (void) llvmpipe_get_texture_tile(lpt
,
124 zsbuf
->u
.tex
.first_layer
,
129 /* Get actual pointer to the tile data. Note that depth/stencil
130 * data is tiled differently than color data.
132 task
->depth_tile
= lp_rast_get_depth_block_pointer(task
,
136 assert(task
->depth_tile
);
139 task
->depth_tile
= NULL
;
146 * Clear the rasterizer's current color tile.
147 * This is a bin command called during bin processing.
150 lp_rast_clear_color(struct lp_rasterizer_task
*task
,
151 const union lp_rast_cmd_arg arg
)
153 const struct lp_scene
*scene
= task
->scene
;
154 uint8_t clear_color
[4];
159 for (i
= 0; i
< 4; ++i
) {
160 clear_color
[i
] = float_to_ubyte(arg
.clear_color
[i
]);
163 LP_DBG(DEBUG_RAST
, "%s 0x%x,0x%x,0x%x,0x%x\n", __FUNCTION__
,
170 clear_color
[0] == clear_color
[1] &&
171 clear_color
[1] == clear_color
[2] &&
172 clear_color
[2] == clear_color
[3];
174 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++) {
175 if (scene
->cbufs
[i
].unswizzled
) {
176 const struct lp_scene
*scene
= task
->scene
;
179 util_pack_color(arg
.clear_color
,
180 scene
->fb
.cbufs
[i
]->format
, &uc
);
182 util_fill_rect(scene
->cbufs
[i
].map
,
183 scene
->fb
.cbufs
[i
]->format
,
184 scene
->cbufs
[i
].stride
,
191 const unsigned chunk
= TILE_SIZE
/ 4;
195 ptr
= lp_rast_get_color_tile_pointer(task
, i
, LP_TEX_USAGE_WRITE_ALL
);
198 /* clear to grayscale value {x, x, x, x} */
200 memset(ptr
, clear_color
[0], TILE_SIZE
* TILE_SIZE
* 4);
203 * Note: if the swizzled tile layout changes (see TILE_PIXEL) this code
204 * will need to change. It'll be pretty obvious when clearing no longer
208 for (j
= 0; j
< 4 * TILE_SIZE
; j
++) {
209 memset(ptr
, clear_color
[0], chunk
);
211 memset(ptr
, clear_color
[1], chunk
);
213 memset(ptr
, clear_color
[2], chunk
);
215 memset(ptr
, clear_color
[3], chunk
);
222 LP_COUNT(nr_color_tile_clear
);
231 * Clear the rasterizer's current z/stencil tile.
232 * This is a bin command called during bin processing.
235 lp_rast_clear_zstencil(struct lp_rasterizer_task
*task
,
236 const union lp_rast_cmd_arg arg
)
238 const struct lp_scene
*scene
= task
->scene
;
239 uint32_t clear_value
= arg
.clear_zstencil
.value
;
240 uint32_t clear_mask
= arg
.clear_zstencil
.mask
;
241 const unsigned height
= TILE_SIZE
/ TILE_VECTOR_HEIGHT
;
242 const unsigned width
= TILE_SIZE
* TILE_VECTOR_HEIGHT
;
243 const unsigned block_size
= scene
->zsbuf
.blocksize
;
244 const unsigned dst_stride
= scene
->zsbuf
.stride
* TILE_VECTOR_HEIGHT
;
248 LP_DBG(DEBUG_RAST
, "%s: value=0x%08x, mask=0x%08x\n",
249 __FUNCTION__
, clear_value
, clear_mask
);
252 * Clear the area of the swizzled depth/depth buffer matching this tile, in
253 * stripes of TILE_VECTOR_HEIGHT x TILE_SIZE at a time.
255 * The swizzled depth format is such that the depths for
256 * TILE_VECTOR_HEIGHT x TILE_VECTOR_WIDTH pixels have consecutive offsets.
259 dst
= task
->depth_tile
;
261 clear_value
&= clear_mask
;
263 switch (block_size
) {
265 assert(clear_mask
== 0xff);
266 memset(dst
, (uint8_t) clear_value
, height
* width
);
269 if (clear_mask
== 0xffff) {
270 for (i
= 0; i
< height
; i
++) {
271 uint16_t *row
= (uint16_t *)dst
;
272 for (j
= 0; j
< width
; j
++)
273 *row
++ = (uint16_t) clear_value
;
278 for (i
= 0; i
< height
; i
++) {
279 uint16_t *row
= (uint16_t *)dst
;
280 for (j
= 0; j
< width
; j
++) {
281 uint16_t tmp
= ~clear_mask
& *row
;
282 *row
++ = clear_value
| tmp
;
289 if (clear_mask
== 0xffffffff) {
290 for (i
= 0; i
< height
; i
++) {
291 uint32_t *row
= (uint32_t *)dst
;
292 for (j
= 0; j
< width
; j
++)
293 *row
++ = clear_value
;
298 for (i
= 0; i
< height
; i
++) {
299 uint32_t *row
= (uint32_t *)dst
;
300 for (j
= 0; j
< width
; j
++) {
301 uint32_t tmp
= ~clear_mask
& *row
;
302 *row
++ = clear_value
| tmp
;
317 * Convert the color tile from tiled to linear layout.
318 * This is generally only done when we're flushing the scene just prior to
319 * SwapBuffers. If we didn't do this here, we'd have to convert the entire
320 * tiled color buffer to linear layout in the llvmpipe_texture_unmap()
321 * function. It's better to do it here to take advantage of
322 * threading/parallelism.
323 * This is a bin command which is stored in all bins.
326 lp_rast_store_linear_color( struct lp_rasterizer_task
*task
)
328 const struct lp_scene
*scene
= task
->scene
;
331 for (buf
= 0; buf
< scene
->fb
.nr_cbufs
; buf
++) {
332 struct pipe_surface
*cbuf
= scene
->fb
.cbufs
[buf
];
333 const unsigned layer
= cbuf
->u
.tex
.first_layer
;
334 const unsigned level
= cbuf
->u
.tex
.level
;
335 struct llvmpipe_resource
*lpt
= llvmpipe_resource(cbuf
->texture
);
337 if (scene
->cbufs
[buf
].unswizzled
|| !task
->color_tiles
[buf
])
340 llvmpipe_unswizzle_cbuf_tile(lpt
,
344 task
->color_tiles
[buf
]);
351 * Run the shader on all blocks in a tile. This is used when a tile is
352 * completely contained inside a triangle.
353 * This is a bin command called during bin processing.
356 lp_rast_shade_tile(struct lp_rasterizer_task
*task
,
357 const union lp_rast_cmd_arg arg
)
359 const struct lp_scene
*scene
= task
->scene
;
360 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
361 const struct lp_rast_state
*state
;
362 struct lp_fragment_shader_variant
*variant
;
363 const unsigned tile_x
= task
->x
, tile_y
= task
->y
;
366 if (inputs
->disable
) {
367 /* This command was partially binned and has been disabled */
371 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
378 variant
= state
->variant
;
380 /* render the whole 64x64 tile in 4x4 chunks */
381 for (y
= 0; y
< TILE_SIZE
; y
+= 4){
382 for (x
= 0; x
< TILE_SIZE
; x
+= 4) {
383 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
384 unsigned stride
[PIPE_MAX_COLOR_BUFS
];
389 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++){
390 stride
[i
] = scene
->cbufs
[i
].stride
;
392 if (scene
->cbufs
[i
].unswizzled
) {
393 color
[i
] = lp_rast_get_unswizzled_color_block_pointer(task
, i
, tile_x
+ x
, tile_y
+ y
);
395 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, tile_x
+ x
, tile_y
+ y
);
400 depth
= lp_rast_get_depth_block_pointer(task
, tile_x
+ x
, tile_y
+ y
);
402 /* run shader on 4x4 block */
403 BEGIN_JIT_CALL(state
, task
);
404 variant
->jit_function
[RAST_WHOLE
]( &state
->jit_context
,
405 tile_x
+ x
, tile_y
+ y
,
422 * Run the shader on all blocks in a tile. This is used when a tile is
423 * completely contained inside a triangle, and the shader is opaque.
424 * This is a bin command called during bin processing.
427 lp_rast_shade_tile_opaque(struct lp_rasterizer_task
*task
,
428 const union lp_rast_cmd_arg arg
)
430 const struct lp_scene
*scene
= task
->scene
;
433 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
440 /* this will prevent converting the layout from tiled to linear */
441 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++) {
442 if (!scene
->cbufs
[i
].unswizzled
) {
443 (void)lp_rast_get_color_tile_pointer(task
, i
, LP_TEX_USAGE_WRITE_ALL
);
447 lp_rast_shade_tile(task
, arg
);
452 * Compute shading for a 4x4 block of pixels inside a triangle.
453 * This is a bin command called during bin processing.
454 * \param x X position of quad in window coords
455 * \param y Y position of quad in window coords
458 lp_rast_shade_quads_mask(struct lp_rasterizer_task
*task
,
459 const struct lp_rast_shader_inputs
*inputs
,
460 unsigned x
, unsigned y
,
463 const struct lp_rast_state
*state
= task
->state
;
464 struct lp_fragment_shader_variant
*variant
= state
->variant
;
465 const struct lp_scene
*scene
= task
->scene
;
466 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
467 unsigned stride
[PIPE_MAX_COLOR_BUFS
];
474 assert(x
< scene
->tiles_x
* TILE_SIZE
);
475 assert(y
< scene
->tiles_y
* TILE_SIZE
);
476 assert(x
% TILE_VECTOR_WIDTH
== 0);
477 assert(y
% TILE_VECTOR_HEIGHT
== 0);
479 assert((x
% 4) == 0);
480 assert((y
% 4) == 0);
483 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++) {
484 stride
[i
] = scene
->cbufs
[i
].stride
;
486 if (scene
->cbufs
[i
].unswizzled
) {
487 color
[i
] = lp_rast_get_unswizzled_color_block_pointer(task
, i
, x
, y
);
489 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, x
, y
);
494 depth
= lp_rast_get_depth_block_pointer(task
, x
, y
);
497 assert(lp_check_alignment(state
->jit_context
.u8_blend_color
, 16));
499 /* run shader on 4x4 block */
500 BEGIN_JIT_CALL(state
, task
);
501 variant
->jit_function
[RAST_EDGE_TEST
](&state
->jit_context
,
518 * Begin a new occlusion query.
519 * This is a bin command put in all bins.
523 lp_rast_begin_query(struct lp_rasterizer_task
*task
,
524 const union lp_rast_cmd_arg arg
)
526 struct llvmpipe_query
*pq
= arg
.query_obj
;
528 assert(task
->query
== NULL
);
529 task
->vis_counter
= 0;
535 * End the current occlusion query.
536 * This is a bin command put in all bins.
540 lp_rast_end_query(struct lp_rasterizer_task
*task
,
541 const union lp_rast_cmd_arg arg
)
545 task
->query
->count
[task
->thread_index
] += task
->vis_counter
;
552 lp_rast_set_state(struct lp_rasterizer_task
*task
,
553 const union lp_rast_cmd_arg arg
)
555 task
->state
= arg
.state
;
561 * Set top row and left column of the tile's pixels to white. For debugging.
564 outline_tile(uint8_t *tile
)
566 const uint8_t val
= 0xff;
569 for (i
= 0; i
< TILE_SIZE
; i
++) {
570 TILE_PIXEL(tile
, i
, 0, 0) = val
;
571 TILE_PIXEL(tile
, i
, 0, 1) = val
;
572 TILE_PIXEL(tile
, i
, 0, 2) = val
;
573 TILE_PIXEL(tile
, i
, 0, 3) = val
;
575 TILE_PIXEL(tile
, 0, i
, 0) = val
;
576 TILE_PIXEL(tile
, 0, i
, 1) = val
;
577 TILE_PIXEL(tile
, 0, i
, 2) = val
;
578 TILE_PIXEL(tile
, 0, i
, 3) = val
;
584 * Draw grid of gray lines at 16-pixel intervals across the tile to
585 * show the sub-tile boundaries. For debugging.
588 outline_subtiles(uint8_t *tile
)
590 const uint8_t val
= 0x80;
591 const unsigned step
= 16;
594 for (i
= 0; i
< TILE_SIZE
; i
+= step
) {
595 for (j
= 0; j
< TILE_SIZE
; j
++) {
596 TILE_PIXEL(tile
, i
, j
, 0) = val
;
597 TILE_PIXEL(tile
, i
, j
, 1) = val
;
598 TILE_PIXEL(tile
, i
, j
, 2) = val
;
599 TILE_PIXEL(tile
, i
, j
, 3) = val
;
601 TILE_PIXEL(tile
, j
, i
, 0) = val
;
602 TILE_PIXEL(tile
, j
, i
, 1) = val
;
603 TILE_PIXEL(tile
, j
, i
, 2) = val
;
604 TILE_PIXEL(tile
, j
, i
, 3) = val
;
614 * Called when we're done writing to a color tile.
617 lp_rast_tile_end(struct lp_rasterizer_task
*task
)
620 if (LP_DEBUG
& (DEBUG_SHOW_SUBTILES
| DEBUG_SHOW_TILES
)) {
621 const struct lp_scene
*scene
= task
->scene
;
624 for (buf
= 0; buf
< scene
->fb
.nr_cbufs
; buf
++) {
625 uint8_t *color
= lp_rast_get_color_block_pointer(task
, buf
,
628 if (LP_DEBUG
& DEBUG_SHOW_SUBTILES
)
629 outline_subtiles(color
);
630 else if (LP_DEBUG
& DEBUG_SHOW_TILES
)
635 (void) outline_subtiles
;
638 lp_rast_store_linear_color(task
);
641 union lp_rast_cmd_arg dummy
= {0};
642 lp_rast_end_query(task
, dummy
);
646 memset(task
->color_tiles
, 0, sizeof(task
->color_tiles
));
647 task
->depth_tile
= NULL
;
652 static lp_rast_cmd_func dispatch
[LP_RAST_OP_MAX
] =
655 lp_rast_clear_zstencil
,
664 lp_rast_triangle_3_4
,
665 lp_rast_triangle_3_16
,
666 lp_rast_triangle_4_16
,
668 lp_rast_shade_tile_opaque
,
676 do_rasterize_bin(struct lp_rasterizer_task
*task
,
677 const struct cmd_bin
*bin
)
679 const struct cmd_block
*block
;
685 for (block
= bin
->head
; block
; block
= block
->next
) {
686 for (k
= 0; k
< block
->count
; k
++) {
687 dispatch
[block
->cmd
[k
]]( task
, block
->arg
[k
] );
695 * Rasterize commands for a single bin.
696 * \param x, y position of the bin's tile in the framebuffer
697 * Must be called between lp_rast_begin() and lp_rast_end().
701 rasterize_bin(struct lp_rasterizer_task
*task
,
702 const struct cmd_bin
*bin
)
704 lp_rast_tile_begin( task
, bin
);
706 do_rasterize_bin(task
, bin
);
708 lp_rast_tile_end(task
);
713 if (bin
->head
->count
== 1) {
714 if (bin
->head
->cmd
[0] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
715 LP_COUNT(nr_pure_shade_opaque_64
);
716 else if (bin
->head
->cmd
[0] == LP_RAST_OP_SHADE_TILE
)
717 LP_COUNT(nr_pure_shade_64
);
722 /* An empty bin is one that just loads the contents of the tile and
723 * stores them again unchanged. This typically happens when bins have
724 * been flushed for some reason in the middle of a frame, or when
725 * incremental updates are being made to a render target.
727 * Try to avoid doing pointless work in this case.
730 is_empty_bin( const struct cmd_bin
*bin
)
732 return bin
->head
== NULL
;
737 * Rasterize/execute all bins within a scene.
741 rasterize_scene(struct lp_rasterizer_task
*task
,
742 struct lp_scene
*scene
)
746 if (!task
->rast
->no_rast
) {
747 /* loop over scene bins, rasterize each */
751 for (i
= 0; i
< scene
->tiles_x
; i
++) {
752 for (j
= 0; j
< scene
->tiles_y
; j
++) {
753 struct cmd_bin
*bin
= lp_scene_get_bin(scene
, i
, j
);
754 rasterize_bin(task
, bin
, i
, j
);
763 while ((bin
= lp_scene_bin_iter_next(scene
))) {
764 if (!is_empty_bin( bin
))
765 rasterize_bin(task
, bin
);
773 lp_fence_signal(scene
->fence
);
781 * Called by setup module when it has something for us to render.
784 lp_rast_queue_scene( struct lp_rasterizer
*rast
,
785 struct lp_scene
*scene
)
787 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
789 if (rast
->num_threads
== 0) {
792 lp_rast_begin( rast
, scene
);
794 rasterize_scene( &rast
->tasks
[0], scene
);
798 rast
->curr_scene
= NULL
;
801 /* threaded rendering! */
804 lp_scene_enqueue( rast
->full_scenes
, scene
);
806 /* signal the threads that there's work to do */
807 for (i
= 0; i
< rast
->num_threads
; i
++) {
808 pipe_semaphore_signal(&rast
->tasks
[i
].work_ready
);
812 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
817 lp_rast_finish( struct lp_rasterizer
*rast
)
819 if (rast
->num_threads
== 0) {
825 /* wait for work to complete */
826 for (i
= 0; i
< rast
->num_threads
; i
++) {
827 pipe_semaphore_wait(&rast
->tasks
[i
].work_done
);
834 * This is the thread's main entrypoint.
835 * It's a simple loop:
838 * 3. signal that we're done
840 static PIPE_THREAD_ROUTINE( thread_function
, init_data
)
842 struct lp_rasterizer_task
*task
= (struct lp_rasterizer_task
*) init_data
;
843 struct lp_rasterizer
*rast
= task
->rast
;
844 boolean debug
= false;
849 debug_printf("thread %d waiting for work\n", task
->thread_index
);
850 pipe_semaphore_wait(&task
->work_ready
);
855 if (task
->thread_index
== 0) {
857 * - get next scene to rasterize
858 * - map the framebuffer surfaces
861 lp_scene_dequeue( rast
->full_scenes
, TRUE
) );
864 /* Wait for all threads to get here so that threads[1+] don't
865 * get a null rast->curr_scene pointer.
867 pipe_barrier_wait( &rast
->barrier
);
871 debug_printf("thread %d doing work\n", task
->thread_index
);
873 rasterize_scene(task
,
876 /* wait for all threads to finish with this scene */
877 pipe_barrier_wait( &rast
->barrier
);
879 /* XXX: shouldn't be necessary:
881 if (task
->thread_index
== 0) {
885 /* signal done with work */
887 debug_printf("thread %d done working\n", task
->thread_index
);
889 pipe_semaphore_signal(&task
->work_done
);
897 * Initialize semaphores and spawn the threads.
900 create_rast_threads(struct lp_rasterizer
*rast
)
904 /* NOTE: if num_threads is zero, we won't use any threads */
905 for (i
= 0; i
< rast
->num_threads
; i
++) {
906 pipe_semaphore_init(&rast
->tasks
[i
].work_ready
, 0);
907 pipe_semaphore_init(&rast
->tasks
[i
].work_done
, 0);
908 rast
->threads
[i
] = pipe_thread_create(thread_function
,
909 (void *) &rast
->tasks
[i
]);
916 * Create new lp_rasterizer. If num_threads is zero, don't create any
917 * new threads, do rendering synchronously.
918 * \param num_threads number of rasterizer threads to create
920 struct lp_rasterizer
*
921 lp_rast_create( unsigned num_threads
)
923 struct lp_rasterizer
*rast
;
926 rast
= CALLOC_STRUCT(lp_rasterizer
);
931 rast
->full_scenes
= lp_scene_queue_create();
932 if (!rast
->full_scenes
) {
936 for (i
= 0; i
< Elements(rast
->tasks
); i
++) {
937 struct lp_rasterizer_task
*task
= &rast
->tasks
[i
];
939 task
->thread_index
= i
;
942 rast
->num_threads
= num_threads
;
944 rast
->no_rast
= debug_get_bool_option("LP_NO_RAST", FALSE
);
946 create_rast_threads(rast
);
948 /* for synchronizing rasterization threads */
949 pipe_barrier_init( &rast
->barrier
, rast
->num_threads
);
951 memset(lp_swizzled_cbuf
, 0, sizeof lp_swizzled_cbuf
);
953 memset(lp_dummy_tile
, 0, sizeof lp_dummy_tile
);
966 void lp_rast_destroy( struct lp_rasterizer
*rast
)
970 /* Set exit_flag and signal each thread's work_ready semaphore.
971 * Each thread will be woken up, notice that the exit_flag is set and
972 * break out of its main loop. The thread will then exit.
974 rast
->exit_flag
= TRUE
;
975 for (i
= 0; i
< rast
->num_threads
; i
++) {
976 pipe_semaphore_signal(&rast
->tasks
[i
].work_ready
);
979 /* Wait for threads to terminate before cleaning up per-thread data */
980 for (i
= 0; i
< rast
->num_threads
; i
++) {
981 pipe_thread_wait(rast
->threads
[i
]);
984 /* Clean up per-thread data */
985 for (i
= 0; i
< rast
->num_threads
; i
++) {
986 pipe_semaphore_destroy(&rast
->tasks
[i
].work_ready
);
987 pipe_semaphore_destroy(&rast
->tasks
[i
].work_done
);
990 /* for synchronizing rasterization threads */
991 pipe_barrier_destroy( &rast
->barrier
);
993 lp_scene_queue_destroy(rast
->full_scenes
);
999 /** Return number of rasterization threads */
1001 lp_rast_get_num_threads( struct lp_rasterizer
*rast
)
1003 return rast
->num_threads
;