1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 **************************************************************************/
31 * Builds per-tile display lists and executes them on calls to
37 #include "pipe/p_defines.h"
38 #include "util/u_framebuffer.h"
39 #include "util/u_inlines.h"
40 #include "util/u_memory.h"
41 #include "util/u_pack_color.h"
42 #include "lp_context.h"
43 #include "lp_memory.h"
45 #include "lp_texture.h"
50 #include "lp_setup_context.h"
51 #include "lp_screen.h"
53 #include "state_tracker/sw_winsys.h"
55 #include "draw/draw_context.h"
56 #include "draw/draw_vbuf.h"
59 static void set_scene_state( struct lp_setup_context
*, enum setup_state
,
61 static boolean
try_update_scene_state( struct lp_setup_context
*setup
);
65 lp_setup_get_empty_scene(struct lp_setup_context
*setup
)
67 assert(setup
->scene
== NULL
);
70 setup
->scene_idx
%= Elements(setup
->scenes
);
72 setup
->scene
= setup
->scenes
[setup
->scene_idx
];
74 if (setup
->scene
->fence
) {
75 if (LP_DEBUG
& DEBUG_SETUP
)
76 debug_printf("%s: wait for scene %d\n",
77 __FUNCTION__
, setup
->scene
->fence
->id
);
79 lp_fence_wait(setup
->scene
->fence
);
82 lp_scene_begin_binning(setup
->scene
, &setup
->fb
);
88 first_triangle( struct lp_setup_context
*setup
,
93 assert(setup
->state
== SETUP_ACTIVE
);
94 lp_setup_choose_triangle( setup
);
95 setup
->triangle( setup
, v0
, v1
, v2
);
99 first_line( struct lp_setup_context
*setup
,
100 const float (*v0
)[4],
101 const float (*v1
)[4])
103 assert(setup
->state
== SETUP_ACTIVE
);
104 lp_setup_choose_line( setup
);
105 setup
->line( setup
, v0
, v1
);
109 first_point( struct lp_setup_context
*setup
,
110 const float (*v0
)[4])
112 assert(setup
->state
== SETUP_ACTIVE
);
113 lp_setup_choose_point( setup
);
114 setup
->point( setup
, v0
);
117 static void lp_setup_reset( struct lp_setup_context
*setup
)
119 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
121 /* Reset derived state */
122 setup
->constants
.stored_size
= 0;
123 setup
->constants
.stored_data
= NULL
;
124 setup
->fs
.stored
= NULL
;
132 memset(&setup
->clear
, 0, sizeof setup
->clear
);
134 /* Have an explicit "start-binning" call and get rid of this
137 setup
->line
= first_line
;
138 setup
->point
= first_point
;
139 setup
->triangle
= first_triangle
;
143 /** Rasterize all scene's bins */
145 lp_setup_rasterize_scene( struct lp_setup_context
*setup
)
147 struct lp_scene
*scene
= setup
->scene
;
148 struct llvmpipe_screen
*screen
= llvmpipe_screen(scene
->pipe
->screen
);
150 lp_scene_end_binning(scene
);
152 lp_fence_reference(&setup
->last_fence
, scene
->fence
);
154 if (setup
->last_fence
)
155 setup
->last_fence
->issued
= TRUE
;
157 pipe_mutex_lock(screen
->rast_mutex
);
158 lp_rast_queue_scene(screen
->rast
, scene
);
159 lp_rast_finish(screen
->rast
);
160 pipe_mutex_unlock(screen
->rast_mutex
);
162 lp_scene_end_rasterization(setup
->scene
);
163 lp_setup_reset( setup
);
165 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
171 begin_binning( struct lp_setup_context
*setup
)
173 struct lp_scene
*scene
= setup
->scene
;
174 boolean need_zsload
= FALSE
;
179 assert(scene
->fence
== NULL
);
181 /* Always create a fence:
183 scene
->fence
= lp_fence_create(MAX2(1, setup
->num_threads
));
185 /* Initialize the bin flags and x/y coords:
187 for (i
= 0; i
< scene
->tiles_x
; i
++) {
188 for (j
= 0; j
< scene
->tiles_y
; j
++) {
189 scene
->tile
[i
][j
].x
= i
;
190 scene
->tile
[i
][j
].y
= j
;
194 ok
= try_update_scene_state(setup
);
197 if (setup
->fb
.zsbuf
&&
198 ((setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
199 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
202 LP_DBG(DEBUG_SETUP
, "%s color: %s depth: %s\n", __FUNCTION__
,
203 (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) ? "clear": "load",
204 need_zsload
? "clear": "load");
206 if (setup
->fb
.nr_cbufs
) {
207 if (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) {
208 ok
= lp_scene_bin_everywhere( scene
,
209 LP_RAST_OP_CLEAR_COLOR
,
210 setup
->clear
.color
);
215 if (setup
->fb
.zsbuf
) {
216 if (setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
218 scene
->has_depthstencil_clear
= TRUE
;
219 ok
= lp_scene_bin_everywhere( scene
,
220 LP_RAST_OP_CLEAR_ZSTENCIL
,
222 setup
->clear
.zsvalue
,
223 setup
->clear
.zsmask
));
228 if (setup
->active_query
) {
229 ok
= lp_scene_bin_everywhere( scene
,
230 LP_RAST_OP_BEGIN_QUERY
,
231 lp_rast_arg_query(setup
->active_query
) );
236 setup
->clear
.flags
= 0;
237 setup
->clear
.zsmask
= 0;
238 setup
->clear
.zsvalue
= 0;
240 LP_DBG(DEBUG_SETUP
, "%s done\n", __FUNCTION__
);
244 /* This basically bins and then flushes any outstanding full-screen
247 * TODO: fast path for fullscreen clears and no triangles.
250 execute_clears( struct lp_setup_context
*setup
)
252 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
254 begin_binning( setup
);
257 const char *states
[] = {
266 set_scene_state( struct lp_setup_context
*setup
,
267 enum setup_state new_state
,
270 unsigned old_state
= setup
->state
;
272 if (old_state
== new_state
)
275 if (LP_DEBUG
& DEBUG_SETUP
) {
276 debug_printf("%s old %s new %s%s%s\n",
280 (new_state
== SETUP_FLUSHED
) ? ": " : "",
281 (new_state
== SETUP_FLUSHED
) ? reason
: "");
283 if (new_state
== SETUP_FLUSHED
&& setup
->scene
)
284 lp_debug_draw_bins_by_coverage(setup
->scene
);
287 /* wait for a free/empty scene
289 if (old_state
== SETUP_FLUSHED
)
290 lp_setup_get_empty_scene(setup
);
297 begin_binning( setup
);
301 if (old_state
== SETUP_CLEARED
)
302 execute_clears( setup
);
304 lp_setup_rasterize_scene( setup
);
305 assert(setup
->scene
== NULL
);
309 assert(0 && "invalid setup state mode");
312 setup
->state
= new_state
;
317 * \param flags bitmask of PIPE_FLUSH_x flags
320 lp_setup_flush( struct lp_setup_context
*setup
,
322 struct pipe_fence_handle
**fence
,
325 set_scene_state( setup
, SETUP_FLUSHED
, reason
);
328 lp_fence_reference((struct lp_fence
**)fence
, setup
->last_fence
);
334 lp_setup_bind_framebuffer( struct lp_setup_context
*setup
,
335 const struct pipe_framebuffer_state
*fb
)
337 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
339 /* Flush any old scene.
341 set_scene_state( setup
, SETUP_FLUSHED
, __FUNCTION__
);
344 * Ensure the old scene is not reused.
346 assert(!setup
->scene
);
348 /* Set new state. This will be picked up later when we next need a
351 util_copy_framebuffer_state(&setup
->fb
, fb
);
352 setup
->framebuffer
.x0
= 0;
353 setup
->framebuffer
.y0
= 0;
354 setup
->framebuffer
.x1
= fb
->width
-1;
355 setup
->framebuffer
.y1
= fb
->height
-1;
356 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
361 lp_setup_try_clear( struct lp_setup_context
*setup
,
368 uint32_t zsvalue
= 0;
369 union lp_rast_cmd_arg color_arg
;
372 LP_DBG(DEBUG_SETUP
, "%s state %d\n", __FUNCTION__
, setup
->state
);
374 if (flags
& PIPE_CLEAR_COLOR
) {
375 for (i
= 0; i
< 4; i
++)
376 color_arg
.clear_color
[i
] = float_to_ubyte(color
[i
]);
379 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
380 unsigned zmask
= (flags
& PIPE_CLEAR_DEPTH
) ? ~0 : 0;
381 unsigned smask
= (flags
& PIPE_CLEAR_STENCIL
) ? ~0 : 0;
383 zsvalue
= util_pack_z_stencil(setup
->fb
.zsbuf
->format
,
387 zsmask
= util_pack_uint_z_stencil(setup
->fb
.zsbuf
->format
,
392 if (setup
->state
== SETUP_ACTIVE
) {
393 struct lp_scene
*scene
= setup
->scene
;
395 /* Add the clear to existing scene. In the unusual case where
396 * both color and depth-stencil are being cleared when there's
397 * already been some rendering, we could discard the currently
398 * binned scene and start again, but I don't see that as being
401 if (flags
& PIPE_CLEAR_COLOR
) {
402 if (!lp_scene_bin_everywhere( scene
,
403 LP_RAST_OP_CLEAR_COLOR
,
408 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
409 if (!lp_scene_bin_everywhere( scene
,
410 LP_RAST_OP_CLEAR_ZSTENCIL
,
411 lp_rast_arg_clearzs(zsvalue
, zsmask
) ))
416 /* Put ourselves into the 'pre-clear' state, specifically to try
417 * and accumulate multiple clears to color and depth_stencil
418 * buffers which the app or state-tracker might issue
421 set_scene_state( setup
, SETUP_CLEARED
, __FUNCTION__
);
423 setup
->clear
.flags
|= flags
;
425 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
426 setup
->clear
.zsmask
|= zsmask
;
427 setup
->clear
.zsvalue
=
428 (setup
->clear
.zsvalue
& ~zsmask
) | (zsvalue
& zsmask
);
431 if (flags
& PIPE_CLEAR_COLOR
) {
432 memcpy(setup
->clear
.color
.clear_color
,
442 lp_setup_clear( struct lp_setup_context
*setup
,
448 if (!lp_setup_try_clear( setup
, color
, depth
, stencil
, flags
)) {
449 lp_setup_flush(setup
, 0, NULL
, __FUNCTION__
);
451 if (!lp_setup_try_clear( setup
, color
, depth
, stencil
, flags
))
461 lp_setup_set_triangle_state( struct lp_setup_context
*setup
,
463 boolean ccw_is_frontface
,
465 boolean gl_rasterization_rules
)
467 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
469 setup
->ccw_is_frontface
= ccw_is_frontface
;
470 setup
->cullmode
= cull_mode
;
471 setup
->triangle
= first_triangle
;
472 setup
->pixel_offset
= gl_rasterization_rules
? 0.5f
: 0.0f
;
474 if (setup
->scissor_test
!= scissor
) {
475 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
476 setup
->scissor_test
= scissor
;
481 lp_setup_set_line_state( struct lp_setup_context
*setup
,
484 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
486 setup
->line_width
= line_width
;
490 lp_setup_set_point_state( struct lp_setup_context
*setup
,
492 boolean point_size_per_vertex
,
495 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
497 setup
->point_size
= point_size
;
498 setup
->sprite
= sprite
;
499 setup
->point_size_per_vertex
= point_size_per_vertex
;
503 lp_setup_set_fs_inputs( struct lp_setup_context
*setup
,
504 const struct lp_shader_input
*input
,
507 LP_DBG(DEBUG_SETUP
, "%s %p %u\n", __FUNCTION__
, (void *) input
, nr
);
509 memcpy( setup
->fs
.input
, input
, nr
* sizeof input
[0] );
510 setup
->fs
.nr_inputs
= nr
;
514 lp_setup_set_fs_variant( struct lp_setup_context
*setup
,
515 struct lp_fragment_shader_variant
*variant
)
517 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
,
519 /* FIXME: reference count */
521 setup
->fs
.current
.variant
= variant
;
522 setup
->dirty
|= LP_SETUP_NEW_FS
;
526 lp_setup_set_fs_constants(struct lp_setup_context
*setup
,
527 struct pipe_resource
*buffer
)
529 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) buffer
);
531 pipe_resource_reference(&setup
->constants
.current
, buffer
);
533 setup
->dirty
|= LP_SETUP_NEW_CONSTANTS
;
538 lp_setup_set_alpha_ref_value( struct lp_setup_context
*setup
,
539 float alpha_ref_value
)
541 LP_DBG(DEBUG_SETUP
, "%s %f\n", __FUNCTION__
, alpha_ref_value
);
543 if(setup
->fs
.current
.jit_context
.alpha_ref_value
!= alpha_ref_value
) {
544 setup
->fs
.current
.jit_context
.alpha_ref_value
= alpha_ref_value
;
545 setup
->dirty
|= LP_SETUP_NEW_FS
;
550 lp_setup_set_stencil_ref_values( struct lp_setup_context
*setup
,
551 const ubyte refs
[2] )
553 LP_DBG(DEBUG_SETUP
, "%s %d %d\n", __FUNCTION__
, refs
[0], refs
[1]);
555 if (setup
->fs
.current
.jit_context
.stencil_ref_front
!= refs
[0] ||
556 setup
->fs
.current
.jit_context
.stencil_ref_back
!= refs
[1]) {
557 setup
->fs
.current
.jit_context
.stencil_ref_front
= refs
[0];
558 setup
->fs
.current
.jit_context
.stencil_ref_back
= refs
[1];
559 setup
->dirty
|= LP_SETUP_NEW_FS
;
564 lp_setup_set_blend_color( struct lp_setup_context
*setup
,
565 const struct pipe_blend_color
*blend_color
)
567 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
571 if(memcmp(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
) != 0) {
572 memcpy(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
);
573 setup
->dirty
|= LP_SETUP_NEW_BLEND_COLOR
;
579 lp_setup_set_scissor( struct lp_setup_context
*setup
,
580 const struct pipe_scissor_state
*scissor
)
582 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
586 setup
->scissor
.x0
= scissor
->minx
;
587 setup
->scissor
.x1
= scissor
->maxx
-1;
588 setup
->scissor
.y0
= scissor
->miny
;
589 setup
->scissor
.y1
= scissor
->maxy
-1;
590 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
595 lp_setup_set_flatshade_first( struct lp_setup_context
*setup
,
596 boolean flatshade_first
)
598 setup
->flatshade_first
= flatshade_first
;
603 lp_setup_set_vertex_info( struct lp_setup_context
*setup
,
604 struct vertex_info
*vertex_info
)
606 /* XXX: just silently holding onto the pointer:
608 setup
->vertex_info
= vertex_info
;
613 * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
616 lp_setup_set_fragment_sampler_views(struct lp_setup_context
*setup
,
618 struct pipe_sampler_view
**views
)
622 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
624 assert(num
<= PIPE_MAX_SAMPLERS
);
626 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
627 struct pipe_sampler_view
*view
= i
< num
? views
[i
] : NULL
;
630 struct pipe_resource
*tex
= view
->texture
;
631 struct llvmpipe_resource
*lp_tex
= llvmpipe_resource(tex
);
632 struct lp_jit_texture
*jit_tex
;
633 jit_tex
= &setup
->fs
.current
.jit_context
.textures
[i
];
634 jit_tex
->width
= tex
->width0
;
635 jit_tex
->height
= tex
->height0
;
636 jit_tex
->depth
= tex
->depth0
;
637 jit_tex
->last_level
= tex
->last_level
;
639 /* We're referencing the texture's internal data, so save a
642 pipe_resource_reference(&setup
->fs
.current_tex
[i
], tex
);
645 /* regular texture - setup array of mipmap level pointers */
647 for (j
= 0; j
<= tex
->last_level
; j
++) {
649 llvmpipe_get_texture_image_all(lp_tex
, j
, LP_TEX_USAGE_READ
,
650 LP_TEX_LAYOUT_LINEAR
);
651 jit_tex
->row_stride
[j
] = lp_tex
->row_stride
[j
];
652 jit_tex
->img_stride
[j
] = lp_tex
->img_stride
[j
];
654 if (!jit_tex
->data
[j
]) {
655 /* out of memory - use dummy tile memory */
656 jit_tex
->data
[j
] = lp_dummy_tile
;
657 jit_tex
->width
= TILE_SIZE
;
658 jit_tex
->height
= TILE_SIZE
;
660 jit_tex
->last_level
= 0;
661 jit_tex
->row_stride
[j
] = 0;
662 jit_tex
->img_stride
[j
] = 0;
667 /* display target texture/surface */
669 * XXX: Where should this be unmapped?
671 struct llvmpipe_screen
*screen
= llvmpipe_screen(tex
->screen
);
672 struct sw_winsys
*winsys
= screen
->winsys
;
673 jit_tex
->data
[0] = winsys
->displaytarget_map(winsys
, lp_tex
->dt
,
675 jit_tex
->row_stride
[0] = lp_tex
->row_stride
[0];
676 jit_tex
->img_stride
[0] = lp_tex
->img_stride
[0];
677 assert(jit_tex
->data
[0]);
682 setup
->dirty
|= LP_SETUP_NEW_FS
;
687 * Is the given texture referenced by any scene?
688 * Note: we have to check all scenes including any scenes currently
689 * being rendered and the current scene being built.
692 lp_setup_is_resource_referenced( const struct lp_setup_context
*setup
,
693 const struct pipe_resource
*texture
)
697 /* check the render targets */
698 for (i
= 0; i
< setup
->fb
.nr_cbufs
; i
++) {
699 if (setup
->fb
.cbufs
[i
]->texture
== texture
)
700 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
702 if (setup
->fb
.zsbuf
&& setup
->fb
.zsbuf
->texture
== texture
) {
703 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
706 /* check textures referenced by the scene */
707 for (i
= 0; i
< Elements(setup
->scenes
); i
++) {
708 if (lp_scene_is_resource_referenced(setup
->scenes
[i
], texture
)) {
709 return PIPE_REFERENCED_FOR_READ
;
713 return PIPE_UNREFERENCED
;
718 * Called by vbuf code when we're about to draw something.
721 try_update_scene_state( struct lp_setup_context
*setup
)
723 boolean new_scene
= (setup
->fs
.stored
== NULL
);
724 struct lp_scene
*scene
= setup
->scene
;
728 if(setup
->dirty
& LP_SETUP_NEW_BLEND_COLOR
) {
732 stored
= lp_scene_alloc_aligned(scene
, 4 * 16, 16);
738 /* smear each blend color component across 16 ubyte elements */
739 for (i
= 0; i
< 4; ++i
) {
740 uint8_t c
= float_to_ubyte(setup
->blend_color
.current
.color
[i
]);
741 for (j
= 0; j
< 16; ++j
)
742 stored
[i
*16 + j
] = c
;
745 setup
->blend_color
.stored
= stored
;
746 setup
->fs
.current
.jit_context
.blend_color
= setup
->blend_color
.stored
;
747 setup
->dirty
|= LP_SETUP_NEW_FS
;
750 if(setup
->dirty
& LP_SETUP_NEW_CONSTANTS
) {
751 struct pipe_resource
*buffer
= setup
->constants
.current
;
754 unsigned current_size
= buffer
->width0
;
755 const void *current_data
= llvmpipe_resource_data(buffer
);
757 /* TODO: copy only the actually used constants? */
759 if(setup
->constants
.stored_size
!= current_size
||
760 !setup
->constants
.stored_data
||
761 memcmp(setup
->constants
.stored_data
,
763 current_size
) != 0) {
766 stored
= lp_scene_alloc(scene
, current_size
);
775 setup
->constants
.stored_size
= current_size
;
776 setup
->constants
.stored_data
= stored
;
780 setup
->constants
.stored_size
= 0;
781 setup
->constants
.stored_data
= NULL
;
784 setup
->fs
.current
.jit_context
.constants
= setup
->constants
.stored_data
;
785 setup
->dirty
|= LP_SETUP_NEW_FS
;
789 if (setup
->dirty
& LP_SETUP_NEW_FS
) {
790 if (!setup
->fs
.stored
||
791 memcmp(setup
->fs
.stored
,
793 sizeof setup
->fs
.current
) != 0)
795 struct lp_rast_state
*stored
;
798 /* The fs state that's been stored in the scene is different from
799 * the new, current state. So allocate a new lp_rast_state object
800 * and append it to the bin's setup data buffer.
802 stored
= (struct lp_rast_state
*) lp_scene_alloc(scene
, sizeof *stored
);
810 sizeof setup
->fs
.current
);
811 setup
->fs
.stored
= stored
;
813 /* The scene now references the textures in the rasterization
814 * state record. Note that now.
816 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
817 if (setup
->fs
.current_tex
[i
]) {
818 if (!lp_scene_add_resource_reference(scene
,
819 setup
->fs
.current_tex
[i
],
829 if (setup
->dirty
& LP_SETUP_NEW_SCISSOR
) {
830 setup
->draw_region
= setup
->framebuffer
;
831 if (setup
->scissor_test
) {
832 u_rect_possible_intersection(&setup
->scissor
,
833 &setup
->draw_region
);
839 assert(setup
->fs
.stored
);
844 lp_setup_update_state( struct lp_setup_context
*setup
,
845 boolean update_scene
)
847 /* Some of the 'draw' pipeline stages may have changed some driver state.
848 * Make sure we've processed those state changes before anything else.
850 * XXX this is the only place where llvmpipe_context is used in the
851 * setup code. This may get refactored/changed...
854 struct llvmpipe_context
*lp
= llvmpipe_context(setup
->pipe
);
856 llvmpipe_update_derived(lp
);
859 /* Will probably need to move this somewhere else, just need
860 * to know about vertex shader point size attribute.
862 setup
->psize
= lp
->psize_slot
;
864 assert(lp
->dirty
== 0);
868 set_scene_state( setup
, SETUP_ACTIVE
, __FUNCTION__
);
870 /* Only call into update_scene_state() if we already have a
873 if (update_scene
&& setup
->scene
) {
874 assert(setup
->state
== SETUP_ACTIVE
);
875 if (!try_update_scene_state(setup
)) {
876 lp_setup_flush_and_restart(setup
);
877 if (!try_update_scene_state(setup
))
885 /* Only caller is lp_setup_vbuf_destroy()
888 lp_setup_destroy( struct lp_setup_context
*setup
)
892 lp_setup_reset( setup
);
894 util_unreference_framebuffer_state(&setup
->fb
);
896 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
897 pipe_resource_reference(&setup
->fs
.current_tex
[i
], NULL
);
900 pipe_resource_reference(&setup
->constants
.current
, NULL
);
902 /* free the scenes in the 'empty' queue */
903 for (i
= 0; i
< Elements(setup
->scenes
); i
++) {
904 struct lp_scene
*scene
= setup
->scenes
[i
];
907 lp_fence_wait(scene
->fence
);
909 lp_scene_destroy(scene
);
917 * Create a new primitive tiling engine. Plug it into the backend of
918 * the draw module. Currently also creates a rasterizer to use with
921 struct lp_setup_context
*
922 lp_setup_create( struct pipe_context
*pipe
,
923 struct draw_context
*draw
)
925 struct llvmpipe_screen
*screen
= llvmpipe_screen(pipe
->screen
);
926 struct lp_setup_context
*setup
= CALLOC_STRUCT(lp_setup_context
);
932 lp_setup_init_vbuf(setup
);
934 /* Used only in update_state():
939 setup
->num_threads
= screen
->num_threads
;
940 setup
->vbuf
= draw_vbuf_stage(draw
, &setup
->base
);
944 draw_set_rasterize_stage(draw
, setup
->vbuf
);
945 draw_set_render(draw
, &setup
->base
);
947 /* create some empty scenes */
948 for (i
= 0; i
< MAX_SCENES
; i
++) {
949 setup
->scenes
[i
] = lp_scene_create( pipe
);
952 setup
->triangle
= first_triangle
;
953 setup
->line
= first_line
;
954 setup
->point
= first_point
;
970 * Put a BeginQuery command into all bins.
973 lp_setup_begin_query(struct lp_setup_context
*setup
,
974 struct llvmpipe_query
*pq
)
976 /* init the query to its beginning state */
977 assert(setup
->active_query
== NULL
);
980 if (!lp_scene_bin_everywhere(setup
->scene
,
981 LP_RAST_OP_BEGIN_QUERY
,
982 lp_rast_arg_query(pq
))) {
984 lp_setup_flush_and_restart(setup
);
986 if (!lp_scene_bin_everywhere(setup
->scene
,
987 LP_RAST_OP_BEGIN_QUERY
,
988 lp_rast_arg_query(pq
))) {
995 setup
->active_query
= pq
;
1000 * Put an EndQuery command into all bins.
1003 lp_setup_end_query(struct lp_setup_context
*setup
, struct llvmpipe_query
*pq
)
1005 union lp_rast_cmd_arg dummy
= { 0 };
1007 assert(setup
->active_query
== pq
);
1008 setup
->active_query
= NULL
;
1010 /* Setup will automatically re-issue any query which carried over a
1011 * scene boundary, and the rasterizer automatically "ends" queries
1012 * which are active at the end of a scene, so there is no need to
1013 * retry this commands on failure.
1016 /* pq->fence should be the fence of the *last* scene which
1017 * contributed to the query result.
1019 lp_fence_reference(&pq
->fence
, setup
->scene
->fence
);
1021 if (!lp_scene_bin_everywhere(setup
->scene
,
1022 LP_RAST_OP_END_QUERY
,
1024 lp_setup_flush(setup
, 0, NULL
, __FUNCTION__
);
1028 lp_fence_reference(&pq
->fence
, setup
->last_fence
);
1034 lp_setup_flush_and_restart(struct lp_setup_context
*setup
)
1036 if (0) debug_printf("%s\n", __FUNCTION__
);
1038 assert(setup
->state
== SETUP_ACTIVE
);
1039 set_scene_state(setup
, SETUP_FLUSHED
, __FUNCTION__
);
1040 lp_setup_update_state(setup
, TRUE
);