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"
34 #include "util/u_string.h"
35 #include "util/u_thread.h"
36 #include "util/u_memset.h"
37 #include "util/os_time.h"
39 #include "lp_scene_queue.h"
40 #include "lp_context.h"
46 #include "lp_rast_priv.h"
47 #include "gallivm/lp_bld_format.h"
48 #include "gallivm/lp_bld_debug.h"
50 #include "lp_tex_sample.h"
55 const struct lp_rast_state
*jit_state
= NULL
;
56 const struct lp_rasterizer_task
*jit_task
= NULL
;
61 * Begin rasterizing a scene.
62 * Called once per scene by one thread.
65 lp_rast_begin( struct lp_rasterizer
*rast
,
66 struct lp_scene
*scene
)
68 rast
->curr_scene
= scene
;
70 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
72 lp_scene_begin_rasterization( scene
);
73 lp_scene_bin_iter_begin( scene
);
78 lp_rast_end( struct lp_rasterizer
*rast
)
80 lp_scene_end_rasterization( rast
->curr_scene
);
82 rast
->curr_scene
= NULL
;
87 * Beginning rasterization of a tile.
88 * \param x window X position of the tile, in pixels
89 * \param y window Y position of the tile, in pixels
92 lp_rast_tile_begin(struct lp_rasterizer_task
*task
,
93 const struct cmd_bin
*bin
,
97 struct lp_scene
*scene
= task
->scene
;
99 LP_DBG(DEBUG_RAST
, "%s %d,%d\n", __FUNCTION__
, x
, y
);
102 task
->x
= x
* TILE_SIZE
;
103 task
->y
= y
* TILE_SIZE
;
104 task
->width
= TILE_SIZE
+ x
* TILE_SIZE
> task
->scene
->fb
.width
?
105 task
->scene
->fb
.width
- x
* TILE_SIZE
: TILE_SIZE
;
106 task
->height
= TILE_SIZE
+ y
* TILE_SIZE
> task
->scene
->fb
.height
?
107 task
->scene
->fb
.height
- y
* TILE_SIZE
: TILE_SIZE
;
109 task
->thread_data
.vis_counter
= 0;
110 task
->thread_data
.ps_invocations
= 0;
112 for (i
= 0; i
< task
->scene
->fb
.nr_cbufs
; i
++) {
113 if (task
->scene
->fb
.cbufs
[i
]) {
114 task
->color_tiles
[i
] = scene
->cbufs
[i
].map
+
115 scene
->cbufs
[i
].stride
* task
->y
+
116 scene
->cbufs
[i
].format_bytes
* task
->x
;
119 if (task
->scene
->fb
.zsbuf
) {
120 task
->depth_tile
= scene
->zsbuf
.map
+
121 scene
->zsbuf
.stride
* task
->y
+
122 scene
->zsbuf
.format_bytes
* task
->x
;
128 * Clear the rasterizer's current color tile.
129 * This is a bin command called during bin processing.
130 * Clear commands always clear all bound layers.
133 lp_rast_clear_color(struct lp_rasterizer_task
*task
,
134 const union lp_rast_cmd_arg arg
)
136 const struct lp_scene
*scene
= task
->scene
;
137 unsigned cbuf
= arg
.clear_rb
->cbuf
;
139 enum pipe_format format
;
141 /* we never bin clear commands for non-existing buffers */
142 assert(cbuf
< scene
->fb
.nr_cbufs
);
143 assert(scene
->fb
.cbufs
[cbuf
]);
145 format
= scene
->fb
.cbufs
[cbuf
]->format
;
146 uc
= arg
.clear_rb
->color_val
;
149 * this is pretty rough since we have target format (bunch of bytes...) here.
150 * dump it as raw 4 dwords.
152 LP_DBG(DEBUG_RAST
, "%s clear value (target format %d) raw 0x%x,0x%x,0x%x,0x%x\n",
153 __FUNCTION__
, format
, uc
.ui
[0], uc
.ui
[1], uc
.ui
[2], uc
.ui
[3]);
156 util_fill_box(scene
->cbufs
[cbuf
].map
,
158 scene
->cbufs
[cbuf
].stride
,
159 scene
->cbufs
[cbuf
].layer_stride
,
165 scene
->fb_max_layer
+ 1,
168 /* this will increase for each rb which probably doesn't mean much */
169 LP_COUNT(nr_color_tile_clear
);
174 * Clear the rasterizer's current z/stencil tile.
175 * This is a bin command called during bin processing.
176 * Clear commands always clear all bound layers.
179 lp_rast_clear_zstencil(struct lp_rasterizer_task
*task
,
180 const union lp_rast_cmd_arg arg
)
182 const struct lp_scene
*scene
= task
->scene
;
183 uint64_t clear_value64
= arg
.clear_zstencil
.value
;
184 uint64_t clear_mask64
= arg
.clear_zstencil
.mask
;
185 uint32_t clear_value
= (uint32_t) clear_value64
;
186 uint32_t clear_mask
= (uint32_t) clear_mask64
;
187 const unsigned height
= task
->height
;
188 const unsigned width
= task
->width
;
189 const unsigned dst_stride
= scene
->zsbuf
.stride
;
194 LP_DBG(DEBUG_RAST
, "%s: value=0x%08x, mask=0x%08x\n",
195 __FUNCTION__
, clear_value
, clear_mask
);
198 * Clear the area of the depth/depth buffer matching this tile.
201 if (scene
->fb
.zsbuf
) {
203 uint8_t *dst_layer
= task
->depth_tile
;
204 block_size
= util_format_get_blocksize(scene
->fb
.zsbuf
->format
);
206 clear_value
&= clear_mask
;
208 for (layer
= 0; layer
<= scene
->fb_max_layer
; layer
++) {
211 switch (block_size
) {
213 assert(clear_mask
== 0xff);
214 for (i
= 0; i
< height
; i
++) {
215 uint8_t *row
= (uint8_t *)dst
;
216 memset(row
, (uint8_t) clear_value
, width
);
221 if (clear_mask
== 0xffff) {
222 for (i
= 0; i
< height
; i
++) {
223 uint16_t *row
= (uint16_t *)dst
;
224 for (j
= 0; j
< width
; j
++)
225 *row
++ = (uint16_t) clear_value
;
230 for (i
= 0; i
< height
; i
++) {
231 uint16_t *row
= (uint16_t *)dst
;
232 for (j
= 0; j
< width
; j
++) {
233 uint16_t tmp
= ~clear_mask
& *row
;
234 *row
++ = clear_value
| tmp
;
241 if (clear_mask
== 0xffffffff) {
242 for (i
= 0; i
< height
; i
++) {
243 util_memset32(dst
, clear_value
, width
);
248 for (i
= 0; i
< height
; i
++) {
249 uint32_t *row
= (uint32_t *)dst
;
250 for (j
= 0; j
< width
; j
++) {
251 uint32_t tmp
= ~clear_mask
& *row
;
252 *row
++ = clear_value
| tmp
;
259 clear_value64
&= clear_mask64
;
260 if (clear_mask64
== 0xffffffffffULL
) {
261 for (i
= 0; i
< height
; i
++) {
262 uint64_t *row
= (uint64_t *)dst
;
263 for (j
= 0; j
< width
; j
++)
264 *row
++ = clear_value64
;
269 for (i
= 0; i
< height
; i
++) {
270 uint64_t *row
= (uint64_t *)dst
;
271 for (j
= 0; j
< width
; j
++) {
272 uint64_t tmp
= ~clear_mask64
& *row
;
273 *row
++ = clear_value64
| tmp
;
284 dst_layer
+= scene
->zsbuf
.layer_stride
;
292 * Run the shader on all blocks in a tile. This is used when a tile is
293 * completely contained inside a triangle.
294 * This is a bin command called during bin processing.
297 lp_rast_shade_tile(struct lp_rasterizer_task
*task
,
298 const union lp_rast_cmd_arg arg
)
300 const struct lp_scene
*scene
= task
->scene
;
301 const struct lp_rast_shader_inputs
*inputs
= arg
.shade_tile
;
302 const struct lp_rast_state
*state
;
303 struct lp_fragment_shader_variant
*variant
;
304 const unsigned tile_x
= task
->x
, tile_y
= task
->y
;
307 if (inputs
->disable
) {
308 /* This command was partially binned and has been disabled */
312 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
319 variant
= state
->variant
;
321 /* render the whole 64x64 tile in 4x4 chunks */
322 for (y
= 0; y
< task
->height
; y
+= 4){
323 for (x
= 0; x
< task
->width
; x
+= 4) {
324 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
325 unsigned stride
[PIPE_MAX_COLOR_BUFS
];
326 uint8_t *depth
= NULL
;
327 unsigned depth_stride
= 0;
331 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++){
332 if (scene
->fb
.cbufs
[i
]) {
333 stride
[i
] = scene
->cbufs
[i
].stride
;
334 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, tile_x
+ x
,
335 tile_y
+ y
, inputs
->layer
);
344 if (scene
->zsbuf
.map
) {
345 depth
= lp_rast_get_depth_block_pointer(task
, tile_x
+ x
,
346 tile_y
+ y
, inputs
->layer
);
347 depth_stride
= scene
->zsbuf
.stride
;
350 /* Propagate non-interpolated raster state. */
351 task
->thread_data
.raster_state
.viewport_index
= inputs
->viewport_index
;
353 /* run shader on 4x4 block */
354 BEGIN_JIT_CALL(state
, task
);
355 variant
->jit_function
[RAST_WHOLE
]( &state
->jit_context
,
356 tile_x
+ x
, tile_y
+ y
,
374 * Run the shader on all blocks in a tile. This is used when a tile is
375 * completely contained inside a triangle, and the shader is opaque.
376 * This is a bin command called during bin processing.
379 lp_rast_shade_tile_opaque(struct lp_rasterizer_task
*task
,
380 const union lp_rast_cmd_arg arg
)
382 LP_DBG(DEBUG_RAST
, "%s\n", __FUNCTION__
);
389 lp_rast_shade_tile(task
, arg
);
394 * Compute shading for a 4x4 block of pixels inside a triangle.
395 * This is a bin command called during bin processing.
396 * \param x X position of quad in window coords
397 * \param y Y position of quad in window coords
400 lp_rast_shade_quads_mask(struct lp_rasterizer_task
*task
,
401 const struct lp_rast_shader_inputs
*inputs
,
402 unsigned x
, unsigned y
,
405 const struct lp_rast_state
*state
= task
->state
;
406 struct lp_fragment_shader_variant
*variant
= state
->variant
;
407 const struct lp_scene
*scene
= task
->scene
;
408 uint8_t *color
[PIPE_MAX_COLOR_BUFS
];
409 unsigned stride
[PIPE_MAX_COLOR_BUFS
];
410 uint8_t *depth
= NULL
;
411 unsigned depth_stride
= 0;
417 assert(x
< scene
->tiles_x
* TILE_SIZE
);
418 assert(y
< scene
->tiles_y
* TILE_SIZE
);
419 assert(x
% TILE_VECTOR_WIDTH
== 0);
420 assert(y
% TILE_VECTOR_HEIGHT
== 0);
422 assert((x
% 4) == 0);
423 assert((y
% 4) == 0);
426 for (i
= 0; i
< scene
->fb
.nr_cbufs
; i
++) {
427 if (scene
->fb
.cbufs
[i
]) {
428 stride
[i
] = scene
->cbufs
[i
].stride
;
429 color
[i
] = lp_rast_get_color_block_pointer(task
, i
, x
, y
,
439 if (scene
->zsbuf
.map
) {
440 depth_stride
= scene
->zsbuf
.stride
;
441 depth
= lp_rast_get_depth_block_pointer(task
, x
, y
, inputs
->layer
);
444 assert(lp_check_alignment(state
->jit_context
.u8_blend_color
, 16));
447 * The rasterizer may produce fragments outside our
448 * allocated 4x4 blocks hence need to filter them out here.
450 if ((x
% TILE_SIZE
) < task
->width
&& (y
% TILE_SIZE
) < task
->height
) {
451 /* Propagate non-interpolated raster state. */
452 task
->thread_data
.raster_state
.viewport_index
= inputs
->viewport_index
;
454 /* run shader on 4x4 block */
455 BEGIN_JIT_CALL(state
, task
);
456 variant
->jit_function
[RAST_EDGE_TEST
](&state
->jit_context
,
475 * Begin a new occlusion query.
476 * This is a bin command put in all bins.
480 lp_rast_begin_query(struct lp_rasterizer_task
*task
,
481 const union lp_rast_cmd_arg arg
)
483 struct llvmpipe_query
*pq
= arg
.query_obj
;
486 case PIPE_QUERY_OCCLUSION_COUNTER
:
487 case PIPE_QUERY_OCCLUSION_PREDICATE
:
488 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
489 pq
->start
[task
->thread_index
] = task
->thread_data
.vis_counter
;
491 case PIPE_QUERY_PIPELINE_STATISTICS
:
492 pq
->start
[task
->thread_index
] = task
->thread_data
.ps_invocations
;
502 * End the current occlusion query.
503 * This is a bin command put in all bins.
507 lp_rast_end_query(struct lp_rasterizer_task
*task
,
508 const union lp_rast_cmd_arg arg
)
510 struct llvmpipe_query
*pq
= arg
.query_obj
;
513 case PIPE_QUERY_OCCLUSION_COUNTER
:
514 case PIPE_QUERY_OCCLUSION_PREDICATE
:
515 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
516 pq
->end
[task
->thread_index
] +=
517 task
->thread_data
.vis_counter
- pq
->start
[task
->thread_index
];
518 pq
->start
[task
->thread_index
] = 0;
520 case PIPE_QUERY_TIMESTAMP
:
521 pq
->end
[task
->thread_index
] = os_time_get_nano();
523 case PIPE_QUERY_PIPELINE_STATISTICS
:
524 pq
->end
[task
->thread_index
] +=
525 task
->thread_data
.ps_invocations
- pq
->start
[task
->thread_index
];
526 pq
->start
[task
->thread_index
] = 0;
536 lp_rast_set_state(struct lp_rasterizer_task
*task
,
537 const union lp_rast_cmd_arg arg
)
539 task
->state
= arg
.state
;
545 * Called when we're done writing to a color tile.
548 lp_rast_tile_end(struct lp_rasterizer_task
*task
)
552 for (i
= 0; i
< task
->scene
->num_active_queries
; ++i
) {
553 lp_rast_end_query(task
, lp_rast_arg_query(task
->scene
->active_queries
[i
]));
557 memset(task
->color_tiles
, 0, sizeof(task
->color_tiles
));
558 task
->depth_tile
= NULL
;
563 static lp_rast_cmd_func dispatch
[LP_RAST_OP_MAX
] =
566 lp_rast_clear_zstencil
,
575 lp_rast_triangle_3_4
,
576 lp_rast_triangle_3_16
,
577 lp_rast_triangle_4_16
,
579 lp_rast_shade_tile_opaque
,
583 lp_rast_triangle_32_1
,
584 lp_rast_triangle_32_2
,
585 lp_rast_triangle_32_3
,
586 lp_rast_triangle_32_4
,
587 lp_rast_triangle_32_5
,
588 lp_rast_triangle_32_6
,
589 lp_rast_triangle_32_7
,
590 lp_rast_triangle_32_8
,
591 lp_rast_triangle_32_3_4
,
592 lp_rast_triangle_32_3_16
,
593 lp_rast_triangle_32_4_16
598 do_rasterize_bin(struct lp_rasterizer_task
*task
,
599 const struct cmd_bin
*bin
,
602 const struct cmd_block
*block
;
606 lp_debug_bin(bin
, x
, y
);
608 for (block
= bin
->head
; block
; block
= block
->next
) {
609 for (k
= 0; k
< block
->count
; k
++) {
610 dispatch
[block
->cmd
[k
]]( task
, block
->arg
[k
] );
618 * Rasterize commands for a single bin.
619 * \param x, y position of the bin's tile in the framebuffer
620 * Must be called between lp_rast_begin() and lp_rast_end().
624 rasterize_bin(struct lp_rasterizer_task
*task
,
625 const struct cmd_bin
*bin
, int x
, int y
)
627 lp_rast_tile_begin( task
, bin
, x
, y
);
629 do_rasterize_bin(task
, bin
, x
, y
);
631 lp_rast_tile_end(task
);
636 if (bin
->head
->count
== 1) {
637 if (bin
->head
->cmd
[0] == LP_RAST_OP_SHADE_TILE_OPAQUE
)
638 LP_COUNT(nr_pure_shade_opaque_64
);
639 else if (bin
->head
->cmd
[0] == LP_RAST_OP_SHADE_TILE
)
640 LP_COUNT(nr_pure_shade_64
);
646 /* An empty bin is one that just loads the contents of the tile and
647 * stores them again unchanged. This typically happens when bins have
648 * been flushed for some reason in the middle of a frame, or when
649 * incremental updates are being made to a render target.
651 * Try to avoid doing pointless work in this case.
654 is_empty_bin( const struct cmd_bin
*bin
)
656 return bin
->head
== NULL
;
661 * Rasterize/execute all bins within a scene.
665 rasterize_scene(struct lp_rasterizer_task
*task
,
666 struct lp_scene
*scene
)
670 /* Clear the cache tags. This should not always be necessary but
672 #if LP_USE_TEXTURE_CACHE
673 memset(task
->thread_data
.cache
->cache_tags
, 0,
674 sizeof(task
->thread_data
.cache
->cache_tags
));
675 #if LP_BUILD_FORMAT_CACHE_DEBUG
676 task
->thread_data
.cache
->cache_access_total
= 0;
677 task
->thread_data
.cache
->cache_access_miss
= 0;
681 if (!task
->rast
->no_rast
) {
682 /* loop over scene bins, rasterize each */
688 while ((bin
= lp_scene_bin_iter_next(scene
, &i
, &j
))) {
689 if (!is_empty_bin( bin
))
690 rasterize_bin(task
, bin
, i
, j
);
696 #if LP_BUILD_FORMAT_CACHE_DEBUG
698 uint64_t total
, miss
;
699 total
= task
->thread_data
.cache
->cache_access_total
;
700 miss
= task
->thread_data
.cache
->cache_access_miss
;
702 debug_printf("thread %d cache access %llu miss %llu hit rate %f\n",
703 task
->thread_index
, (long long unsigned)total
,
704 (long long unsigned)miss
,
705 (float)(total
- miss
)/(float)total
);
711 lp_fence_signal(scene
->fence
);
719 * Called by setup module when it has something for us to render.
722 lp_rast_queue_scene( struct lp_rasterizer
*rast
,
723 struct lp_scene
*scene
)
725 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
727 if (rast
->num_threads
== 0) {
729 unsigned fpstate
= util_fpstate_get();
731 /* Make sure that denorms are treated like zeros. This is
732 * the behavior required by D3D10. OpenGL doesn't care.
734 util_fpstate_set_denorms_to_zero(fpstate
);
736 lp_rast_begin( rast
, scene
);
738 rasterize_scene( &rast
->tasks
[0], scene
);
742 util_fpstate_set(fpstate
);
744 rast
->curr_scene
= NULL
;
747 /* threaded rendering! */
750 lp_scene_enqueue( rast
->full_scenes
, scene
);
752 /* signal the threads that there's work to do */
753 for (i
= 0; i
< rast
->num_threads
; i
++) {
754 pipe_semaphore_signal(&rast
->tasks
[i
].work_ready
);
758 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
763 lp_rast_finish( struct lp_rasterizer
*rast
)
765 if (rast
->num_threads
== 0) {
771 /* wait for work to complete */
772 for (i
= 0; i
< rast
->num_threads
; i
++) {
773 pipe_semaphore_wait(&rast
->tasks
[i
].work_done
);
780 * This is the thread's main entrypoint.
781 * It's a simple loop:
784 * 3. signal that we're done
787 thread_function(void *init_data
)
789 struct lp_rasterizer_task
*task
= (struct lp_rasterizer_task
*) init_data
;
790 struct lp_rasterizer
*rast
= task
->rast
;
791 boolean debug
= false;
792 char thread_name
[16];
795 snprintf(thread_name
, sizeof thread_name
, "llvmpipe-%u", task
->thread_index
);
796 u_thread_setname(thread_name
);
798 /* Make sure that denorms are treated like zeros. This is
799 * the behavior required by D3D10. OpenGL doesn't care.
801 fpstate
= util_fpstate_get();
802 util_fpstate_set_denorms_to_zero(fpstate
);
807 debug_printf("thread %d waiting for work\n", task
->thread_index
);
808 pipe_semaphore_wait(&task
->work_ready
);
813 if (task
->thread_index
== 0) {
815 * - get next scene to rasterize
816 * - map the framebuffer surfaces
819 lp_scene_dequeue( rast
->full_scenes
, TRUE
) );
822 /* Wait for all threads to get here so that threads[1+] don't
823 * get a null rast->curr_scene pointer.
825 util_barrier_wait( &rast
->barrier
);
829 debug_printf("thread %d doing work\n", task
->thread_index
);
831 rasterize_scene(task
,
834 /* wait for all threads to finish with this scene */
835 util_barrier_wait( &rast
->barrier
);
837 /* XXX: shouldn't be necessary:
839 if (task
->thread_index
== 0) {
843 /* signal done with work */
845 debug_printf("thread %d done working\n", task
->thread_index
);
847 pipe_semaphore_signal(&task
->work_done
);
851 pipe_semaphore_signal(&task
->work_done
);
859 * Initialize semaphores and spawn the threads.
862 create_rast_threads(struct lp_rasterizer
*rast
)
866 /* NOTE: if num_threads is zero, we won't use any threads */
867 for (i
= 0; i
< rast
->num_threads
; i
++) {
868 pipe_semaphore_init(&rast
->tasks
[i
].work_ready
, 0);
869 pipe_semaphore_init(&rast
->tasks
[i
].work_done
, 0);
870 rast
->threads
[i
] = u_thread_create(thread_function
,
871 (void *) &rast
->tasks
[i
]);
872 if (!rast
->threads
[i
]) {
873 rast
->num_threads
= i
; /* previous thread is max */
882 * Create new lp_rasterizer. If num_threads is zero, don't create any
883 * new threads, do rendering synchronously.
884 * \param num_threads number of rasterizer threads to create
886 struct lp_rasterizer
*
887 lp_rast_create( unsigned num_threads
)
889 struct lp_rasterizer
*rast
;
892 rast
= CALLOC_STRUCT(lp_rasterizer
);
897 rast
->full_scenes
= lp_scene_queue_create();
898 if (!rast
->full_scenes
) {
902 for (i
= 0; i
< MAX2(1, num_threads
); i
++) {
903 struct lp_rasterizer_task
*task
= &rast
->tasks
[i
];
905 task
->thread_index
= i
;
906 task
->thread_data
.cache
= align_malloc(sizeof(struct lp_build_format_cache
),
908 if (!task
->thread_data
.cache
) {
909 goto no_thread_data_cache
;
913 rast
->num_threads
= num_threads
;
915 rast
->no_rast
= debug_get_bool_option("LP_NO_RAST", FALSE
);
917 create_rast_threads(rast
);
919 /* for synchronizing rasterization threads */
920 if (rast
->num_threads
> 0) {
921 util_barrier_init( &rast
->barrier
, rast
->num_threads
);
924 memset(lp_dummy_tile
, 0, sizeof lp_dummy_tile
);
928 no_thread_data_cache
:
929 for (i
= 0; i
< MAX2(1, rast
->num_threads
); i
++) {
930 if (rast
->tasks
[i
].thread_data
.cache
) {
931 align_free(rast
->tasks
[i
].thread_data
.cache
);
935 lp_scene_queue_destroy(rast
->full_scenes
);
945 void lp_rast_destroy( struct lp_rasterizer
*rast
)
949 /* Set exit_flag and signal each thread's work_ready semaphore.
950 * Each thread will be woken up, notice that the exit_flag is set and
951 * break out of its main loop. The thread will then exit.
953 rast
->exit_flag
= TRUE
;
954 for (i
= 0; i
< rast
->num_threads
; i
++) {
955 pipe_semaphore_signal(&rast
->tasks
[i
].work_ready
);
958 /* Wait for threads to terminate before cleaning up per-thread data.
959 * We don't actually call pipe_thread_wait to avoid dead lock on Windows
960 * per https://bugs.freedesktop.org/show_bug.cgi?id=76252 */
961 for (i
= 0; i
< rast
->num_threads
; i
++) {
963 pipe_semaphore_wait(&rast
->tasks
[i
].work_done
);
965 thrd_join(rast
->threads
[i
], NULL
);
969 /* Clean up per-thread data */
970 for (i
= 0; i
< rast
->num_threads
; i
++) {
971 pipe_semaphore_destroy(&rast
->tasks
[i
].work_ready
);
972 pipe_semaphore_destroy(&rast
->tasks
[i
].work_done
);
974 for (i
= 0; i
< MAX2(1, rast
->num_threads
); i
++) {
975 align_free(rast
->tasks
[i
].thread_data
.cache
);
978 /* for synchronizing rasterization threads */
979 if (rast
->num_threads
> 0) {
980 util_barrier_destroy( &rast
->barrier
);
983 lp_scene_queue_destroy(rast
->full_scenes
);