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"
44 #include "lp_scene_queue.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
);
63 lp_setup_get_current_scene(struct lp_setup_context
*setup
)
67 /* wait for a free/empty scene
69 setup
->scene
= lp_scene_dequeue(setup
->empty_scenes
, TRUE
);
71 assert(lp_scene_is_empty(setup
->scene
));
73 lp_scene_begin_binning(setup
->scene
,
81 * Check if the size of the current scene has exceeded the limit.
82 * If so, flush/render it.
85 setup_check_scene_size_and_flush(struct lp_setup_context
*setup
)
88 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
89 unsigned size
= lp_scene_get_size(scene
);
91 if (size
> LP_MAX_SCENE_SIZE
) {
92 /*printf("LLVMPIPE: scene size = %u, flushing.\n", size);*/
93 set_scene_state( setup
, SETUP_FLUSHED
);
94 /*assert(lp_scene_get_size(scene) == 0);*/
101 first_triangle( struct lp_setup_context
*setup
,
102 const float (*v0
)[4],
103 const float (*v1
)[4],
104 const float (*v2
)[4])
106 set_scene_state( setup
, SETUP_ACTIVE
);
107 lp_setup_choose_triangle( setup
);
108 setup
->triangle( setup
, v0
, v1
, v2
);
112 first_line( struct lp_setup_context
*setup
,
113 const float (*v0
)[4],
114 const float (*v1
)[4])
116 set_scene_state( setup
, SETUP_ACTIVE
);
117 lp_setup_choose_line( setup
);
118 setup
->line( setup
, v0
, v1
);
122 first_point( struct lp_setup_context
*setup
,
123 const float (*v0
)[4])
125 set_scene_state( setup
, SETUP_ACTIVE
);
126 lp_setup_choose_point( setup
);
127 setup
->point( setup
, v0
);
130 static void reset_context( struct lp_setup_context
*setup
)
132 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
134 /* Reset derived state */
135 setup
->constants
.stored_size
= 0;
136 setup
->constants
.stored_data
= NULL
;
137 setup
->fs
.stored
= NULL
;
145 setup
->clear
.flags
= 0;
146 setup
->clear
.clearzs
.clearzs_mask
= 0;
148 /* Have an explicit "start-binning" call and get rid of this
151 setup
->line
= first_line
;
152 setup
->point
= first_point
;
153 setup
->triangle
= first_triangle
;
157 /** Rasterize all scene's bins */
159 lp_setup_rasterize_scene( struct lp_setup_context
*setup
)
161 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
163 lp_scene_rasterize(scene
, setup
->rast
);
165 reset_context( setup
);
167 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
173 begin_binning( struct lp_setup_context
*setup
)
175 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
176 boolean need_zsload
= FALSE
;
177 if (setup
->fb
.zsbuf
&&
178 ((setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
179 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
182 LP_DBG(DEBUG_SETUP
, "%s color: %s depth: %s\n", __FUNCTION__
,
183 (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) ? "clear": "load",
184 need_zsload
? "clear": "load");
186 if (setup
->fb
.nr_cbufs
) {
187 if (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) {
188 lp_scene_bin_everywhere( scene
,
190 setup
->clear
.color
);
191 scene
->has_color_clear
= TRUE
;
195 if (setup
->fb
.zsbuf
) {
196 if (setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
198 scene
->has_depthstencil_clear
= TRUE
;
199 lp_scene_bin_everywhere( scene
,
200 lp_rast_clear_zstencil
,
201 lp_rast_arg_clearzs(&setup
->clear
.clearzs
) );
205 LP_DBG(DEBUG_SETUP
, "%s done\n", __FUNCTION__
);
209 /* This basically bins and then flushes any outstanding full-screen
212 * TODO: fast path for fullscreen clears and no triangles.
215 execute_clears( struct lp_setup_context
*setup
)
217 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
219 begin_binning( setup
);
220 lp_setup_rasterize_scene( setup
);
225 set_scene_state( struct lp_setup_context
*setup
,
226 enum setup_state new_state
)
228 unsigned old_state
= setup
->state
;
230 if (old_state
== new_state
)
233 LP_DBG(DEBUG_SETUP
, "%s old %d new %d\n", __FUNCTION__
, old_state
, new_state
);
237 begin_binning( setup
);
241 if (old_state
== SETUP_ACTIVE
) {
248 if (old_state
== SETUP_CLEARED
)
249 execute_clears( setup
);
251 lp_setup_rasterize_scene( setup
);
255 assert(0 && "invalid setup state mode");
258 setup
->state
= new_state
;
263 * \param flags bitmask of PIPE_FLUSH_x flags
266 lp_setup_flush( struct lp_setup_context
*setup
,
269 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
272 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
273 union lp_rast_cmd_arg dummy
= {0};
275 if (flags
& (PIPE_FLUSH_SWAPBUFFERS
|
277 /* Store colors in the linear color buffer(s).
278 * If we don't do this here, we'll end up converting the tiled
279 * data to linear in the texture_unmap() function, which will
280 * not be a parallel/threaded operation as here.
282 lp_scene_bin_everywhere(scene
, lp_rast_store_color
, dummy
);
286 set_scene_state( setup
, SETUP_FLUSHED
);
291 lp_setup_bind_framebuffer( struct lp_setup_context
*setup
,
292 const struct pipe_framebuffer_state
*fb
)
294 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
296 /* Flush any old scene.
298 set_scene_state( setup
, SETUP_FLUSHED
);
300 /* Set new state. This will be picked up later when we next need a
303 util_copy_framebuffer_state(&setup
->fb
, fb
);
308 lp_setup_clear( struct lp_setup_context
*setup
,
314 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
316 boolean full_zs_clear
= TRUE
;
319 LP_DBG(DEBUG_SETUP
, "%s state %d\n", __FUNCTION__
, setup
->state
);
322 if (flags
& PIPE_CLEAR_COLOR
) {
323 for (i
= 0; i
< 4; ++i
)
324 setup
->clear
.color
.clear_color
[i
] = float_to_ubyte(color
[i
]);
327 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
328 if (setup
->fb
.zsbuf
&&
329 ((flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
330 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
331 full_zs_clear
= FALSE
;
334 setup
->clear
.clearzs
.clearzs_value
=
335 util_pack_z_stencil(setup
->fb
.zsbuf
->format
,
338 setup
->clear
.clearzs
.clearzs_mask
= 0xffffffff;
343 if (flags
& PIPE_CLEAR_DEPTH
) {
344 tmpval
= util_pack_z(setup
->fb
.zsbuf
->format
,
346 switch (setup
->fb
.zsbuf
->format
) {
347 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
350 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
358 switch (setup
->fb
.zsbuf
->format
) {
359 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
361 tmpval
= stencil
<< 24;
363 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
372 setup
->clear
.clearzs
.clearzs_mask
|= mask
;
373 setup
->clear
.clearzs
.clearzs_value
=
374 (setup
->clear
.clearzs
.clearzs_value
& ~mask
) | (tmpval
& mask
);
378 if (setup
->state
== SETUP_ACTIVE
) {
379 /* Add the clear to existing scene. In the unusual case where
380 * both color and depth-stencil are being cleared when there's
381 * already been some rendering, we could discard the currently
382 * binned scene and start again, but I don't see that as being
385 if (flags
& PIPE_CLEAR_COLOR
) {
386 lp_scene_bin_everywhere( scene
,
388 setup
->clear
.color
);
389 scene
->has_color_clear
= TRUE
;
392 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
394 scene
->has_depthstencil_clear
= TRUE
;
396 setup
->clear
.clearzs
.clearzs_mask
= mask
;
397 lp_scene_bin_everywhere( scene
,
398 lp_rast_clear_zstencil
,
399 lp_rast_arg_clearzs(&setup
->clear
.clearzs
) );
406 /* Put ourselves into the 'pre-clear' state, specifically to try
407 * and accumulate multiple clears to color and depth_stencil
408 * buffers which the app or state-tracker might issue
411 set_scene_state( setup
, SETUP_CLEARED
);
413 setup
->clear
.flags
|= flags
;
421 struct pipe_fence_handle
*
422 lp_setup_fence( struct lp_setup_context
*setup
)
424 if (setup
->num_threads
== 0) {
428 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
429 const unsigned rank
= lp_scene_get_num_bins( scene
); /* xxx */
430 struct lp_fence
*fence
= lp_fence_create(rank
);
432 LP_DBG(DEBUG_SETUP
, "%s rank %u\n", __FUNCTION__
, rank
);
434 set_scene_state( setup
, SETUP_ACTIVE
);
436 /* insert the fence into all command bins */
437 lp_scene_bin_everywhere( scene
,
439 lp_rast_arg_fence(fence
) );
441 return (struct pipe_fence_handle
*) fence
;
447 lp_setup_set_triangle_state( struct lp_setup_context
*setup
,
449 boolean ccw_is_frontface
,
451 boolean gl_rasterization_rules
)
453 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
455 setup
->ccw_is_frontface
= ccw_is_frontface
;
456 setup
->cullmode
= cull_mode
;
457 setup
->triangle
= first_triangle
;
458 setup
->scissor_test
= scissor
;
459 setup
->pixel_offset
= gl_rasterization_rules
? 0.5f
: 0.0f
;
465 lp_setup_set_fs_inputs( struct lp_setup_context
*setup
,
466 const struct lp_shader_input
*input
,
469 LP_DBG(DEBUG_SETUP
, "%s %p %u\n", __FUNCTION__
, (void *) input
, nr
);
471 memcpy( setup
->fs
.input
, input
, nr
* sizeof input
[0] );
472 setup
->fs
.nr_inputs
= nr
;
476 lp_setup_set_fs_variant( struct lp_setup_context
*setup
,
477 struct lp_fragment_shader_variant
*variant
)
479 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
,
481 /* FIXME: reference count */
483 setup
->fs
.current
.variant
= variant
;
484 setup
->dirty
|= LP_SETUP_NEW_FS
;
488 lp_setup_set_fs_constants(struct lp_setup_context
*setup
,
489 struct pipe_resource
*buffer
)
491 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) buffer
);
493 pipe_resource_reference(&setup
->constants
.current
, buffer
);
495 setup
->dirty
|= LP_SETUP_NEW_CONSTANTS
;
500 lp_setup_set_alpha_ref_value( struct lp_setup_context
*setup
,
501 float alpha_ref_value
)
503 LP_DBG(DEBUG_SETUP
, "%s %f\n", __FUNCTION__
, alpha_ref_value
);
505 if(setup
->fs
.current
.jit_context
.alpha_ref_value
!= alpha_ref_value
) {
506 setup
->fs
.current
.jit_context
.alpha_ref_value
= alpha_ref_value
;
507 setup
->dirty
|= LP_SETUP_NEW_FS
;
512 lp_setup_set_stencil_ref_values( struct lp_setup_context
*setup
,
513 const ubyte refs
[2] )
515 LP_DBG(DEBUG_SETUP
, "%s %d %d\n", __FUNCTION__
, refs
[0], refs
[1]);
517 if (setup
->fs
.current
.jit_context
.stencil_ref_front
!= refs
[0] ||
518 setup
->fs
.current
.jit_context
.stencil_ref_back
!= refs
[1]) {
519 setup
->fs
.current
.jit_context
.stencil_ref_front
= refs
[0];
520 setup
->fs
.current
.jit_context
.stencil_ref_back
= refs
[1];
521 setup
->dirty
|= LP_SETUP_NEW_FS
;
526 lp_setup_set_blend_color( struct lp_setup_context
*setup
,
527 const struct pipe_blend_color
*blend_color
)
529 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
533 if(memcmp(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
) != 0) {
534 memcpy(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
);
535 setup
->dirty
|= LP_SETUP_NEW_BLEND_COLOR
;
541 lp_setup_set_scissor( struct lp_setup_context
*setup
,
542 const struct pipe_scissor_state
*scissor
)
544 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
548 if (memcmp(&setup
->scissor
.current
, scissor
, sizeof(*scissor
)) != 0) {
549 setup
->scissor
.current
= *scissor
; /* struct copy */
550 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
556 lp_setup_set_flatshade_first( struct lp_setup_context
*setup
,
557 boolean flatshade_first
)
559 setup
->flatshade_first
= flatshade_first
;
564 lp_setup_set_vertex_info( struct lp_setup_context
*setup
,
565 struct vertex_info
*vertex_info
)
567 /* XXX: just silently holding onto the pointer:
569 setup
->vertex_info
= vertex_info
;
574 * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
577 lp_setup_set_fragment_sampler_views(struct lp_setup_context
*setup
,
579 struct pipe_sampler_view
**views
)
583 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
585 assert(num
<= PIPE_MAX_SAMPLERS
);
587 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
588 struct pipe_sampler_view
*view
= i
< num
? views
[i
] : NULL
;
591 struct pipe_resource
*tex
= view
->texture
;
592 struct llvmpipe_resource
*lp_tex
= llvmpipe_resource(tex
);
593 struct lp_jit_texture
*jit_tex
;
594 jit_tex
= &setup
->fs
.current
.jit_context
.textures
[i
];
595 jit_tex
->width
= tex
->width0
;
596 jit_tex
->height
= tex
->height0
;
597 jit_tex
->depth
= tex
->depth0
;
598 jit_tex
->last_level
= tex
->last_level
;
600 /* We're referencing the texture's internal data, so save a
603 pipe_resource_reference(&setup
->fs
.current_tex
[i
], tex
);
606 /* regular texture - setup array of mipmap level pointers */
608 for (j
= 0; j
<= tex
->last_level
; j
++) {
610 llvmpipe_get_texture_image_all(lp_tex
, j
, LP_TEX_USAGE_READ
,
611 LP_TEX_LAYOUT_LINEAR
);
612 jit_tex
->row_stride
[j
] = lp_tex
->row_stride
[j
];
613 jit_tex
->img_stride
[j
] = lp_tex
->img_stride
[j
];
617 /* display target texture/surface */
619 * XXX: Where should this be unmapped?
622 struct llvmpipe_screen
*screen
= llvmpipe_screen(tex
->screen
);
623 struct sw_winsys
*winsys
= screen
->winsys
;
624 jit_tex
->data
[0] = winsys
->displaytarget_map(winsys
, lp_tex
->dt
,
626 jit_tex
->row_stride
[0] = lp_tex
->row_stride
[0];
627 jit_tex
->img_stride
[0] = lp_tex
->img_stride
[0];
628 assert(jit_tex
->data
[0]);
633 setup
->dirty
|= LP_SETUP_NEW_FS
;
638 * Is the given texture referenced by any scene?
639 * Note: we have to check all scenes including any scenes currently
640 * being rendered and the current scene being built.
643 lp_setup_is_resource_referenced( const struct lp_setup_context
*setup
,
644 const struct pipe_resource
*texture
)
648 /* check the render targets */
649 for (i
= 0; i
< setup
->fb
.nr_cbufs
; i
++) {
650 if (setup
->fb
.cbufs
[i
]->texture
== texture
)
651 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
653 if (setup
->fb
.zsbuf
&& setup
->fb
.zsbuf
->texture
== texture
) {
654 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
657 /* check textures referenced by the scene */
658 for (i
= 0; i
< Elements(setup
->scenes
); i
++) {
659 if (lp_scene_is_resource_referenced(setup
->scenes
[i
], texture
)) {
660 return PIPE_REFERENCED_FOR_READ
;
664 return PIPE_UNREFERENCED
;
669 * Called by vbuf code when we're about to draw something.
672 lp_setup_update_state( struct lp_setup_context
*setup
)
674 struct lp_scene
*scene
;
676 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
678 setup_check_scene_size_and_flush(setup
);
680 scene
= lp_setup_get_current_scene(setup
);
682 assert(setup
->fs
.current
.variant
);
684 /* Some of the 'draw' pipeline stages may have changed some driver state.
685 * Make sure we've processed those state changes before anything else.
687 * XXX this is the only place where llvmpipe_context is used in the
688 * setup code. This may get refactored/changed...
691 struct llvmpipe_context
*lp
= llvmpipe_context(scene
->pipe
);
693 llvmpipe_update_derived(lp
);
695 assert(lp
->dirty
== 0);
698 if(setup
->dirty
& LP_SETUP_NEW_BLEND_COLOR
) {
702 stored
= lp_scene_alloc_aligned(scene
, 4 * 16, 16);
705 /* smear each blend color component across 16 ubyte elements */
706 for (i
= 0; i
< 4; ++i
) {
707 uint8_t c
= float_to_ubyte(setup
->blend_color
.current
.color
[i
]);
708 for (j
= 0; j
< 16; ++j
)
709 stored
[i
*16 + j
] = c
;
712 setup
->blend_color
.stored
= stored
;
714 setup
->fs
.current
.jit_context
.blend_color
= setup
->blend_color
.stored
;
717 setup
->dirty
|= LP_SETUP_NEW_FS
;
720 if (setup
->dirty
& LP_SETUP_NEW_SCISSOR
) {
723 stored
= lp_scene_alloc_aligned(scene
, 4 * sizeof(int32_t), 16);
726 stored
[0] = (float) setup
->scissor
.current
.minx
;
727 stored
[1] = (float) setup
->scissor
.current
.miny
;
728 stored
[2] = (float) setup
->scissor
.current
.maxx
;
729 stored
[3] = (float) setup
->scissor
.current
.maxy
;
731 setup
->scissor
.stored
= stored
;
733 setup
->fs
.current
.jit_context
.scissor_xmin
= stored
[0];
734 setup
->fs
.current
.jit_context
.scissor_ymin
= stored
[1];
735 setup
->fs
.current
.jit_context
.scissor_xmax
= stored
[2];
736 setup
->fs
.current
.jit_context
.scissor_ymax
= stored
[3];
739 setup
->dirty
|= LP_SETUP_NEW_FS
;
742 if(setup
->dirty
& LP_SETUP_NEW_CONSTANTS
) {
743 struct pipe_resource
*buffer
= setup
->constants
.current
;
746 unsigned current_size
= buffer
->width0
;
747 const void *current_data
= llvmpipe_resource_data(buffer
);
749 /* TODO: copy only the actually used constants? */
751 if(setup
->constants
.stored_size
!= current_size
||
752 !setup
->constants
.stored_data
||
753 memcmp(setup
->constants
.stored_data
,
755 current_size
) != 0) {
758 stored
= lp_scene_alloc(scene
, current_size
);
763 setup
->constants
.stored_size
= current_size
;
764 setup
->constants
.stored_data
= stored
;
769 setup
->constants
.stored_size
= 0;
770 setup
->constants
.stored_data
= NULL
;
773 setup
->fs
.current
.jit_context
.constants
= setup
->constants
.stored_data
;
774 setup
->dirty
|= LP_SETUP_NEW_FS
;
778 if(setup
->dirty
& LP_SETUP_NEW_FS
) {
779 if(!setup
->fs
.stored
||
780 memcmp(setup
->fs
.stored
,
782 sizeof setup
->fs
.current
) != 0) {
783 /* The fs state that's been stored in the scene is different from
784 * the new, current state. So allocate a new lp_rast_state object
785 * and append it to the bin's setup data buffer.
788 struct lp_rast_state
*stored
=
789 (struct lp_rast_state
*) lp_scene_alloc(scene
, sizeof *stored
);
793 sizeof setup
->fs
.current
);
794 setup
->fs
.stored
= stored
;
796 /* put the state-set command into all bins */
797 lp_scene_bin_state_command( scene
,
799 lp_rast_arg_state(setup
->fs
.stored
) );
802 /* The scene now references the textures in the rasterization
803 * state record. Note that now.
805 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
806 if (setup
->fs
.current_tex
[i
])
807 lp_scene_add_resource_reference(scene
, setup
->fs
.current_tex
[i
]);
814 assert(setup
->fs
.stored
);
819 /* Only caller is lp_setup_vbuf_destroy()
822 lp_setup_destroy( struct lp_setup_context
*setup
)
826 reset_context( setup
);
828 util_unreference_framebuffer_state(&setup
->fb
);
830 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
831 pipe_resource_reference(&setup
->fs
.current_tex
[i
], NULL
);
834 pipe_resource_reference(&setup
->constants
.current
, NULL
);
836 /* free the scenes in the 'empty' queue */
838 struct lp_scene
*scene
= lp_scene_dequeue(setup
->empty_scenes
, FALSE
);
841 lp_scene_destroy(scene
);
844 lp_scene_queue_destroy(setup
->empty_scenes
);
846 lp_rast_destroy( setup
->rast
);
853 * Create a new primitive tiling engine. Plug it into the backend of
854 * the draw module. Currently also creates a rasterizer to use with
857 struct lp_setup_context
*
858 lp_setup_create( struct pipe_context
*pipe
,
859 struct draw_context
*draw
)
861 struct llvmpipe_screen
*screen
= llvmpipe_screen(pipe
->screen
);
862 struct lp_setup_context
*setup
= CALLOC_STRUCT(lp_setup_context
);
868 lp_setup_init_vbuf(setup
);
870 setup
->empty_scenes
= lp_scene_queue_create();
871 if (!setup
->empty_scenes
)
874 /* XXX: move this to the screen and share between contexts:
876 setup
->num_threads
= screen
->num_threads
;
877 setup
->rast
= lp_rast_create(screen
->num_threads
);
881 setup
->vbuf
= draw_vbuf_stage(draw
, &setup
->base
);
885 draw_set_rasterize_stage(draw
, setup
->vbuf
);
886 draw_set_render(draw
, &setup
->base
);
888 /* create some empty scenes */
889 for (i
= 0; i
< MAX_SCENES
; i
++) {
890 setup
->scenes
[i
] = lp_scene_create( pipe
, setup
->empty_scenes
);
892 lp_scene_enqueue(setup
->empty_scenes
, setup
->scenes
[i
]);
895 setup
->triangle
= first_triangle
;
896 setup
->line
= first_line
;
897 setup
->point
= first_point
;
905 lp_rast_destroy( setup
->rast
);
910 if (setup
->empty_scenes
)
911 lp_scene_queue_destroy(setup
->empty_scenes
);
919 * Put a BeginQuery command into all bins.
922 lp_setup_begin_query(struct lp_setup_context
*setup
,
923 struct llvmpipe_query
*pq
)
925 struct lp_scene
* scene
= lp_setup_get_current_scene(setup
);
926 union lp_rast_cmd_arg cmd_arg
;
928 /* init the query to its beginning state */
931 pq
->num_tiles
= scene
->tiles_x
* scene
->tiles_y
;
932 assert(pq
->num_tiles
> 0);
934 memset(pq
->count
, 0, sizeof(pq
->count
)); /* reset all counters */
936 cmd_arg
.query_obj
= pq
;
937 lp_scene_bin_everywhere(scene
, lp_rast_begin_query
, cmd_arg
);
943 * Put an EndQuery command into all bins.
946 lp_setup_end_query(struct lp_setup_context
*setup
, struct llvmpipe_query
*pq
)
948 struct lp_scene
* scene
= lp_setup_get_current_scene(setup
);
949 union lp_rast_cmd_arg cmd_arg
;
951 cmd_arg
.query_obj
= pq
;
952 lp_scene_bin_everywhere(scene
, lp_rast_end_query
, cmd_arg
);