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_scene_queue.h"
46 #include "lp_texture.h"
51 #include "lp_setup_context.h"
52 #include "lp_screen.h"
54 #include "state_tracker/sw_winsys.h"
56 #include "draw/draw_context.h"
57 #include "draw/draw_vbuf.h"
60 static void set_scene_state( struct lp_setup_context
*, enum setup_state
);
64 lp_setup_get_current_scene(struct lp_setup_context
*setup
)
67 set_scene_state( setup
, SETUP_EMPTY
);
74 * Check if the size of the current scene has exceeded the limit.
75 * If so, flush/render it.
78 setup_check_scene_size_and_flush(struct lp_setup_context
*setup
)
81 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
82 unsigned size
= lp_scene_get_size(scene
);
84 if (size
> LP_MAX_SCENE_SIZE
) {
85 /*printf("LLVMPIPE: scene size = %u, flushing.\n", size);*/
86 set_scene_state( setup
, SETUP_FLUSHED
);
87 /*assert(lp_scene_get_size(scene) == 0);*/
94 first_triangle( struct lp_setup_context
*setup
,
99 set_scene_state( setup
, SETUP_ACTIVE
);
100 lp_setup_choose_triangle( setup
);
101 setup
->triangle( setup
, v0
, v1
, v2
);
105 first_line( struct lp_setup_context
*setup
,
106 const float (*v0
)[4],
107 const float (*v1
)[4])
109 set_scene_state( setup
, SETUP_ACTIVE
);
110 lp_setup_choose_line( setup
);
111 setup
->line( setup
, v0
, v1
);
115 first_point( struct lp_setup_context
*setup
,
116 const float (*v0
)[4])
118 set_scene_state( setup
, SETUP_ACTIVE
);
119 lp_setup_choose_point( setup
);
120 setup
->point( setup
, v0
);
123 static void reset_context( struct lp_setup_context
*setup
)
125 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
127 /* Reset derived state */
128 setup
->constants
.stored_size
= 0;
129 setup
->constants
.stored_data
= NULL
;
130 setup
->fs
.stored
= NULL
;
138 setup
->clear
.flags
= 0;
139 setup
->clear
.clearzs
.clearzs_mask
= 0;
141 /* Have an explicit "start-binning" call and get rid of this
144 setup
->line
= first_line
;
145 setup
->point
= first_point
;
146 setup
->triangle
= first_triangle
;
150 /** Rasterize all scene's bins */
152 lp_setup_rasterize_scene( struct lp_setup_context
*setup
)
154 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
155 struct llvmpipe_screen
*screen
= llvmpipe_screen(scene
->pipe
->screen
);
157 pipe_mutex_lock(screen
->rast_mutex
);
158 lp_scene_rasterize(scene
, screen
->rast
);
159 pipe_mutex_unlock(screen
->rast_mutex
);
161 reset_context( setup
);
163 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
169 begin_binning( struct lp_setup_context
*setup
)
171 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
172 boolean need_zsload
= FALSE
;
173 if (setup
->fb
.zsbuf
&&
174 ((setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
175 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
178 LP_DBG(DEBUG_SETUP
, "%s color: %s depth: %s\n", __FUNCTION__
,
179 (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) ? "clear": "load",
180 need_zsload
? "clear": "load");
182 if (setup
->fb
.nr_cbufs
) {
183 if (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) {
184 lp_scene_bin_everywhere( scene
,
186 setup
->clear
.color
);
187 scene
->has_color_clear
= TRUE
;
191 if (setup
->fb
.zsbuf
) {
192 if (setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
194 scene
->has_depthstencil_clear
= TRUE
;
195 lp_scene_bin_everywhere( scene
,
196 lp_rast_clear_zstencil
,
197 lp_rast_arg_clearzs(&setup
->clear
.clearzs
) );
201 LP_DBG(DEBUG_SETUP
, "%s done\n", __FUNCTION__
);
205 /* This basically bins and then flushes any outstanding full-screen
208 * TODO: fast path for fullscreen clears and no triangles.
211 execute_clears( struct lp_setup_context
*setup
)
213 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
215 begin_binning( setup
);
216 lp_setup_rasterize_scene( setup
);
221 set_scene_state( struct lp_setup_context
*setup
,
222 enum setup_state new_state
)
224 unsigned old_state
= setup
->state
;
226 if (old_state
== new_state
)
229 LP_DBG(DEBUG_SETUP
, "%s old %d new %d\n", __FUNCTION__
, old_state
, new_state
);
233 assert(old_state
== SETUP_FLUSHED
);
234 assert(setup
->scene
== NULL
);
236 /* wait for a free/empty scene
238 setup
->scene
= lp_scene_dequeue(setup
->empty_scenes
, TRUE
);
239 assert(lp_scene_is_empty(setup
->scene
));
240 lp_scene_begin_binning(setup
->scene
,
245 assert(old_state
== SETUP_EMPTY
);
246 assert(setup
->scene
!= NULL
);
250 assert(old_state
== SETUP_EMPTY
||
251 old_state
== SETUP_CLEARED
);
252 assert(setup
->scene
!= NULL
);
253 begin_binning( setup
);
257 if (old_state
== SETUP_CLEARED
)
258 execute_clears( setup
);
260 lp_setup_rasterize_scene( setup
);
261 assert(setup
->scene
== NULL
);
265 assert(0 && "invalid setup state mode");
268 setup
->state
= new_state
;
273 * \param flags bitmask of PIPE_FLUSH_x flags
276 lp_setup_flush( struct lp_setup_context
*setup
,
278 struct pipe_fence_handle
**fence
,
281 LP_DBG(DEBUG_SETUP
, "%s %s\n", __FUNCTION__
, reason
);
285 /* if we're going to flush the setup/rasterization modules, emit
288 *fence
= lp_setup_fence( setup
);
291 if (setup
->scene
->fence
)
292 setup
->scene
->fence
->issued
= TRUE
;
295 set_scene_state( setup
, SETUP_FLUSHED
);
300 lp_setup_bind_framebuffer( struct lp_setup_context
*setup
,
301 const struct pipe_framebuffer_state
*fb
)
303 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
305 /* Flush any old scene.
307 set_scene_state( setup
, SETUP_FLUSHED
);
310 * Ensure the old scene is not reused.
312 assert(!setup
->scene
);
314 /* Set new state. This will be picked up later when we next need a
317 util_copy_framebuffer_state(&setup
->fb
, fb
);
318 setup
->framebuffer
.x0
= 0;
319 setup
->framebuffer
.y0
= 0;
320 setup
->framebuffer
.x1
= fb
->width
-1;
321 setup
->framebuffer
.y1
= fb
->height
-1;
322 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
327 lp_setup_clear( struct lp_setup_context
*setup
,
333 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
335 boolean full_zs_clear
= TRUE
;
338 LP_DBG(DEBUG_SETUP
, "%s state %d\n", __FUNCTION__
, setup
->state
);
341 if (flags
& PIPE_CLEAR_COLOR
) {
342 for (i
= 0; i
< 4; ++i
)
343 setup
->clear
.color
.clear_color
[i
] = float_to_ubyte(color
[i
]);
346 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
347 if (setup
->fb
.zsbuf
&&
348 ((flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
349 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
350 full_zs_clear
= FALSE
;
353 setup
->clear
.clearzs
.clearzs_value
=
354 util_pack_z_stencil(setup
->fb
.zsbuf
->format
,
357 setup
->clear
.clearzs
.clearzs_mask
= 0xffffffff;
362 if (flags
& PIPE_CLEAR_DEPTH
) {
363 tmpval
= util_pack_z(setup
->fb
.zsbuf
->format
,
365 switch (setup
->fb
.zsbuf
->format
) {
366 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
369 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
377 switch (setup
->fb
.zsbuf
->format
) {
378 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
380 tmpval
= stencil
<< 24;
382 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
391 setup
->clear
.clearzs
.clearzs_mask
|= mask
;
392 setup
->clear
.clearzs
.clearzs_value
=
393 (setup
->clear
.clearzs
.clearzs_value
& ~mask
) | (tmpval
& mask
);
397 if (setup
->state
== SETUP_ACTIVE
) {
398 /* Add the clear to existing scene. In the unusual case where
399 * both color and depth-stencil are being cleared when there's
400 * already been some rendering, we could discard the currently
401 * binned scene and start again, but I don't see that as being
404 if (flags
& PIPE_CLEAR_COLOR
) {
405 lp_scene_bin_everywhere( scene
,
407 setup
->clear
.color
);
408 scene
->has_color_clear
= TRUE
;
411 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
413 scene
->has_depthstencil_clear
= TRUE
;
415 setup
->clear
.clearzs
.clearzs_mask
= mask
;
416 lp_scene_bin_everywhere( scene
,
417 lp_rast_clear_zstencil
,
418 lp_rast_arg_clearzs(&setup
->clear
.clearzs
) );
425 /* Put ourselves into the 'pre-clear' state, specifically to try
426 * and accumulate multiple clears to color and depth_stencil
427 * buffers which the app or state-tracker might issue
430 set_scene_state( setup
, SETUP_CLEARED
);
432 setup
->clear
.flags
|= flags
;
440 struct pipe_fence_handle
*
441 lp_setup_fence( struct lp_setup_context
*setup
)
443 if (setup
->scene
== NULL
)
445 else if (setup
->num_threads
== 0)
449 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
450 const unsigned rank
= setup
->num_threads
;
452 set_scene_state( setup
, SETUP_ACTIVE
);
454 assert(scene
->fence
== NULL
);
456 /* The caller gets a reference, we keep a copy too, so need to
459 lp_fence_reference(&scene
->fence
, lp_fence_create(rank
));
461 LP_DBG(DEBUG_SETUP
, "%s rank %u\n", __FUNCTION__
, rank
);
463 return (struct pipe_fence_handle
*) scene
->fence
;
469 lp_setup_set_triangle_state( struct lp_setup_context
*setup
,
471 boolean ccw_is_frontface
,
473 boolean gl_rasterization_rules
)
475 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
477 setup
->ccw_is_frontface
= ccw_is_frontface
;
478 setup
->cullmode
= cull_mode
;
479 setup
->triangle
= first_triangle
;
480 setup
->pixel_offset
= gl_rasterization_rules
? 0.5f
: 0.0f
;
482 if (setup
->scissor_test
!= scissor
) {
483 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
484 setup
->scissor_test
= scissor
;
489 lp_setup_set_line_state( struct lp_setup_context
*setup
,
492 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
494 setup
->line_width
= line_width
;
498 lp_setup_set_fs_inputs( struct lp_setup_context
*setup
,
499 const struct lp_shader_input
*input
,
502 LP_DBG(DEBUG_SETUP
, "%s %p %u\n", __FUNCTION__
, (void *) input
, nr
);
504 memcpy( setup
->fs
.input
, input
, nr
* sizeof input
[0] );
505 setup
->fs
.nr_inputs
= nr
;
509 lp_setup_set_fs_variant( struct lp_setup_context
*setup
,
510 struct lp_fragment_shader_variant
*variant
)
512 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
,
514 /* FIXME: reference count */
516 setup
->fs
.current
.variant
= variant
;
517 setup
->dirty
|= LP_SETUP_NEW_FS
;
521 lp_setup_set_fs_constants(struct lp_setup_context
*setup
,
522 struct pipe_resource
*buffer
)
524 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) buffer
);
526 pipe_resource_reference(&setup
->constants
.current
, buffer
);
528 setup
->dirty
|= LP_SETUP_NEW_CONSTANTS
;
533 lp_setup_set_alpha_ref_value( struct lp_setup_context
*setup
,
534 float alpha_ref_value
)
536 LP_DBG(DEBUG_SETUP
, "%s %f\n", __FUNCTION__
, alpha_ref_value
);
538 if(setup
->fs
.current
.jit_context
.alpha_ref_value
!= alpha_ref_value
) {
539 setup
->fs
.current
.jit_context
.alpha_ref_value
= alpha_ref_value
;
540 setup
->dirty
|= LP_SETUP_NEW_FS
;
545 lp_setup_set_stencil_ref_values( struct lp_setup_context
*setup
,
546 const ubyte refs
[2] )
548 LP_DBG(DEBUG_SETUP
, "%s %d %d\n", __FUNCTION__
, refs
[0], refs
[1]);
550 if (setup
->fs
.current
.jit_context
.stencil_ref_front
!= refs
[0] ||
551 setup
->fs
.current
.jit_context
.stencil_ref_back
!= refs
[1]) {
552 setup
->fs
.current
.jit_context
.stencil_ref_front
= refs
[0];
553 setup
->fs
.current
.jit_context
.stencil_ref_back
= refs
[1];
554 setup
->dirty
|= LP_SETUP_NEW_FS
;
559 lp_setup_set_blend_color( struct lp_setup_context
*setup
,
560 const struct pipe_blend_color
*blend_color
)
562 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
566 if(memcmp(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
) != 0) {
567 memcpy(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
);
568 setup
->dirty
|= LP_SETUP_NEW_BLEND_COLOR
;
574 lp_setup_set_scissor( struct lp_setup_context
*setup
,
575 const struct pipe_scissor_state
*scissor
)
577 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
581 setup
->scissor
.x0
= scissor
->minx
;
582 setup
->scissor
.x1
= scissor
->maxx
-1;
583 setup
->scissor
.y0
= scissor
->miny
;
584 setup
->scissor
.y1
= scissor
->maxy
-1;
585 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
590 lp_setup_set_flatshade_first( struct lp_setup_context
*setup
,
591 boolean flatshade_first
)
593 setup
->flatshade_first
= flatshade_first
;
598 lp_setup_set_vertex_info( struct lp_setup_context
*setup
,
599 struct vertex_info
*vertex_info
)
601 /* XXX: just silently holding onto the pointer:
603 setup
->vertex_info
= vertex_info
;
608 * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
611 lp_setup_set_fragment_sampler_views(struct lp_setup_context
*setup
,
613 struct pipe_sampler_view
**views
)
617 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
619 assert(num
<= PIPE_MAX_SAMPLERS
);
621 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
622 struct pipe_sampler_view
*view
= i
< num
? views
[i
] : NULL
;
625 struct pipe_resource
*tex
= view
->texture
;
626 struct llvmpipe_resource
*lp_tex
= llvmpipe_resource(tex
);
627 struct lp_jit_texture
*jit_tex
;
628 jit_tex
= &setup
->fs
.current
.jit_context
.textures
[i
];
629 jit_tex
->width
= tex
->width0
;
630 jit_tex
->height
= tex
->height0
;
631 jit_tex
->depth
= tex
->depth0
;
632 jit_tex
->last_level
= tex
->last_level
;
634 /* We're referencing the texture's internal data, so save a
637 pipe_resource_reference(&setup
->fs
.current_tex
[i
], tex
);
640 /* regular texture - setup array of mipmap level pointers */
642 for (j
= 0; j
<= tex
->last_level
; j
++) {
644 llvmpipe_get_texture_image_all(lp_tex
, j
, LP_TEX_USAGE_READ
,
645 LP_TEX_LAYOUT_LINEAR
);
646 jit_tex
->row_stride
[j
] = lp_tex
->row_stride
[j
];
647 jit_tex
->img_stride
[j
] = lp_tex
->img_stride
[j
];
649 if (!jit_tex
->data
[j
]) {
650 /* out of memory - use dummy tile memory */
651 jit_tex
->data
[j
] = lp_dummy_tile
;
652 jit_tex
->width
= TILE_SIZE
;
653 jit_tex
->height
= TILE_SIZE
;
655 jit_tex
->last_level
= 0;
656 jit_tex
->row_stride
[j
] = 0;
657 jit_tex
->img_stride
[j
] = 0;
662 /* display target texture/surface */
664 * XXX: Where should this be unmapped?
666 struct llvmpipe_screen
*screen
= llvmpipe_screen(tex
->screen
);
667 struct sw_winsys
*winsys
= screen
->winsys
;
668 jit_tex
->data
[0] = winsys
->displaytarget_map(winsys
, lp_tex
->dt
,
670 jit_tex
->row_stride
[0] = lp_tex
->row_stride
[0];
671 jit_tex
->img_stride
[0] = lp_tex
->img_stride
[0];
672 assert(jit_tex
->data
[0]);
677 setup
->dirty
|= LP_SETUP_NEW_FS
;
682 * Is the given texture referenced by any scene?
683 * Note: we have to check all scenes including any scenes currently
684 * being rendered and the current scene being built.
687 lp_setup_is_resource_referenced( const struct lp_setup_context
*setup
,
688 const struct pipe_resource
*texture
)
692 /* check the render targets */
693 for (i
= 0; i
< setup
->fb
.nr_cbufs
; i
++) {
694 if (setup
->fb
.cbufs
[i
]->texture
== texture
)
695 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
697 if (setup
->fb
.zsbuf
&& setup
->fb
.zsbuf
->texture
== texture
) {
698 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
701 /* check textures referenced by the scene */
702 for (i
= 0; i
< Elements(setup
->scenes
); i
++) {
703 if (lp_scene_is_resource_referenced(setup
->scenes
[i
], texture
)) {
704 return PIPE_REFERENCED_FOR_READ
;
708 return PIPE_UNREFERENCED
;
713 * Called by vbuf code when we're about to draw something.
716 lp_setup_update_state( struct lp_setup_context
*setup
)
718 struct lp_scene
*scene
;
720 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
722 setup_check_scene_size_and_flush(setup
);
724 scene
= lp_setup_get_current_scene(setup
);
726 assert(setup
->fs
.current
.variant
);
728 /* Some of the 'draw' pipeline stages may have changed some driver state.
729 * Make sure we've processed those state changes before anything else.
731 * XXX this is the only place where llvmpipe_context is used in the
732 * setup code. This may get refactored/changed...
735 struct llvmpipe_context
*lp
= llvmpipe_context(scene
->pipe
);
737 llvmpipe_update_derived(lp
);
739 assert(lp
->dirty
== 0);
742 if(setup
->dirty
& LP_SETUP_NEW_BLEND_COLOR
) {
746 stored
= lp_scene_alloc_aligned(scene
, 4 * 16, 16);
749 /* smear each blend color component across 16 ubyte elements */
750 for (i
= 0; i
< 4; ++i
) {
751 uint8_t c
= float_to_ubyte(setup
->blend_color
.current
.color
[i
]);
752 for (j
= 0; j
< 16; ++j
)
753 stored
[i
*16 + j
] = c
;
756 setup
->blend_color
.stored
= stored
;
758 setup
->fs
.current
.jit_context
.blend_color
= setup
->blend_color
.stored
;
761 setup
->dirty
|= LP_SETUP_NEW_FS
;
764 if(setup
->dirty
& LP_SETUP_NEW_CONSTANTS
) {
765 struct pipe_resource
*buffer
= setup
->constants
.current
;
768 unsigned current_size
= buffer
->width0
;
769 const void *current_data
= llvmpipe_resource_data(buffer
);
771 /* TODO: copy only the actually used constants? */
773 if(setup
->constants
.stored_size
!= current_size
||
774 !setup
->constants
.stored_data
||
775 memcmp(setup
->constants
.stored_data
,
777 current_size
) != 0) {
780 stored
= lp_scene_alloc(scene
, current_size
);
785 setup
->constants
.stored_size
= current_size
;
786 setup
->constants
.stored_data
= stored
;
791 setup
->constants
.stored_size
= 0;
792 setup
->constants
.stored_data
= NULL
;
795 setup
->fs
.current
.jit_context
.constants
= setup
->constants
.stored_data
;
796 setup
->dirty
|= LP_SETUP_NEW_FS
;
800 if(setup
->dirty
& LP_SETUP_NEW_FS
) {
801 if(!setup
->fs
.stored
||
802 memcmp(setup
->fs
.stored
,
804 sizeof setup
->fs
.current
) != 0) {
805 /* The fs state that's been stored in the scene is different from
806 * the new, current state. So allocate a new lp_rast_state object
807 * and append it to the bin's setup data buffer.
810 struct lp_rast_state
*stored
=
811 (struct lp_rast_state
*) lp_scene_alloc(scene
, sizeof *stored
);
815 sizeof setup
->fs
.current
);
816 setup
->fs
.stored
= stored
;
819 /* The scene now references the textures in the rasterization
820 * state record. Note that now.
822 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
823 if (setup
->fs
.current_tex
[i
])
824 lp_scene_add_resource_reference(scene
, 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 /* Only caller is lp_setup_vbuf_destroy()
847 lp_setup_destroy( struct lp_setup_context
*setup
)
851 reset_context( setup
);
853 util_unreference_framebuffer_state(&setup
->fb
);
855 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
856 pipe_resource_reference(&setup
->fs
.current_tex
[i
], NULL
);
859 pipe_resource_reference(&setup
->constants
.current
, NULL
);
861 /* free the scenes in the 'empty' queue */
863 struct lp_scene
*scene
= lp_scene_dequeue(setup
->empty_scenes
, FALSE
);
866 lp_scene_destroy(scene
);
869 lp_scene_queue_destroy(setup
->empty_scenes
);
876 * Create a new primitive tiling engine. Plug it into the backend of
877 * the draw module. Currently also creates a rasterizer to use with
880 struct lp_setup_context
*
881 lp_setup_create( struct pipe_context
*pipe
,
882 struct draw_context
*draw
)
884 struct llvmpipe_screen
*screen
= llvmpipe_screen(pipe
->screen
);
885 struct lp_setup_context
*setup
= CALLOC_STRUCT(lp_setup_context
);
891 lp_setup_init_vbuf(setup
);
893 setup
->empty_scenes
= lp_scene_queue_create();
894 if (!setup
->empty_scenes
)
897 setup
->num_threads
= screen
->num_threads
;
898 setup
->vbuf
= draw_vbuf_stage(draw
, &setup
->base
);
902 draw_set_rasterize_stage(draw
, setup
->vbuf
);
903 draw_set_render(draw
, &setup
->base
);
905 /* create some empty scenes */
906 for (i
= 0; i
< MAX_SCENES
; i
++) {
907 setup
->scenes
[i
] = lp_scene_create( pipe
, setup
->empty_scenes
);
909 lp_scene_enqueue(setup
->empty_scenes
, setup
->scenes
[i
]);
912 setup
->triangle
= first_triangle
;
913 setup
->line
= first_line
;
914 setup
->point
= first_point
;
924 if (setup
->empty_scenes
)
925 lp_scene_queue_destroy(setup
->empty_scenes
);
933 * Put a BeginQuery command into all bins.
936 lp_setup_begin_query(struct lp_setup_context
*setup
,
937 struct llvmpipe_query
*pq
)
939 struct lp_scene
* scene
= lp_setup_get_current_scene(setup
);
940 union lp_rast_cmd_arg cmd_arg
;
942 /* init the query to its beginning state */
945 pq
->num_tiles
= scene
->tiles_x
* scene
->tiles_y
;
946 assert(pq
->num_tiles
> 0);
948 memset(pq
->count
, 0, sizeof(pq
->count
)); /* reset all counters */
950 set_scene_state( setup
, SETUP_ACTIVE
);
952 cmd_arg
.query_obj
= pq
;
953 lp_scene_bin_everywhere(scene
, lp_rast_begin_query
, cmd_arg
);
959 * Put an EndQuery command into all bins.
962 lp_setup_end_query(struct lp_setup_context
*setup
, struct llvmpipe_query
*pq
)
964 struct lp_scene
* scene
= lp_setup_get_current_scene(setup
);
965 union lp_rast_cmd_arg cmd_arg
;
967 set_scene_state( setup
, SETUP_ACTIVE
);
969 cmd_arg
.query_obj
= pq
;
970 lp_scene_bin_everywhere(scene
, lp_rast_end_query
, cmd_arg
);