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 boolean
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
));
187 /* Initialize the bin flags and x/y coords:
189 for (i
= 0; i
< scene
->tiles_x
; i
++) {
190 for (j
= 0; j
< scene
->tiles_y
; j
++) {
191 scene
->tile
[i
][j
].x
= i
;
192 scene
->tile
[i
][j
].y
= j
;
196 ok
= try_update_scene_state(setup
);
200 if (setup
->fb
.zsbuf
&&
201 ((setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
202 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
205 LP_DBG(DEBUG_SETUP
, "%s color: %s depth: %s\n", __FUNCTION__
,
206 (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) ? "clear": "load",
207 need_zsload
? "clear": "load");
209 if (setup
->fb
.nr_cbufs
) {
210 if (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) {
211 ok
= lp_scene_bin_everywhere( scene
,
212 LP_RAST_OP_CLEAR_COLOR
,
213 setup
->clear
.color
);
219 if (setup
->fb
.zsbuf
) {
220 if (setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
222 scene
->has_depthstencil_clear
= TRUE
;
224 ok
= lp_scene_bin_everywhere( scene
,
225 LP_RAST_OP_CLEAR_ZSTENCIL
,
227 setup
->clear
.zsvalue
,
228 setup
->clear
.zsmask
));
234 if (setup
->active_query
) {
235 ok
= lp_scene_bin_everywhere( scene
,
236 LP_RAST_OP_BEGIN_QUERY
,
237 lp_rast_arg_query(setup
->active_query
) );
242 setup
->clear
.flags
= 0;
243 setup
->clear
.zsmask
= 0;
244 setup
->clear
.zsvalue
= 0;
246 LP_DBG(DEBUG_SETUP
, "%s done\n", __FUNCTION__
);
251 /* This basically bins and then flushes any outstanding full-screen
254 * TODO: fast path for fullscreen clears and no triangles.
257 execute_clears( struct lp_setup_context
*setup
)
259 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
261 return begin_binning( setup
);
264 const char *states
[] = {
273 set_scene_state( struct lp_setup_context
*setup
,
274 enum setup_state new_state
,
277 unsigned old_state
= setup
->state
;
279 if (old_state
== new_state
)
282 if (LP_DEBUG
& DEBUG_SCENE
) {
283 debug_printf("%s old %s new %s%s%s\n",
287 (new_state
== SETUP_FLUSHED
) ? ": " : "",
288 (new_state
== SETUP_FLUSHED
) ? reason
: "");
290 if (new_state
== SETUP_FLUSHED
&& setup
->scene
)
291 lp_debug_draw_bins_by_cmd_length(setup
->scene
);
294 /* wait for a free/empty scene
296 if (old_state
== SETUP_FLUSHED
)
297 lp_setup_get_empty_scene(setup
);
304 if (!begin_binning( setup
))
309 if (old_state
== SETUP_CLEARED
)
310 if (!execute_clears( setup
))
313 lp_setup_rasterize_scene( setup
);
314 assert(setup
->scene
== NULL
);
318 assert(0 && "invalid setup state mode");
322 setup
->state
= new_state
;
327 lp_scene_end_rasterization(setup
->scene
);
331 setup
->state
= SETUP_FLUSHED
;
332 lp_setup_reset( setup
);
338 * \param flags bitmask of PIPE_FLUSH_x flags
341 lp_setup_flush( struct lp_setup_context
*setup
,
343 struct pipe_fence_handle
**fence
,
346 set_scene_state( setup
, SETUP_FLUSHED
, reason
);
349 lp_fence_reference((struct lp_fence
**)fence
, setup
->last_fence
);
355 lp_setup_bind_framebuffer( struct lp_setup_context
*setup
,
356 const struct pipe_framebuffer_state
*fb
)
358 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
360 /* Flush any old scene.
362 set_scene_state( setup
, SETUP_FLUSHED
, __FUNCTION__
);
365 * Ensure the old scene is not reused.
367 assert(!setup
->scene
);
369 /* Set new state. This will be picked up later when we next need a
372 util_copy_framebuffer_state(&setup
->fb
, fb
);
373 setup
->framebuffer
.x0
= 0;
374 setup
->framebuffer
.y0
= 0;
375 setup
->framebuffer
.x1
= fb
->width
-1;
376 setup
->framebuffer
.y1
= fb
->height
-1;
377 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
382 lp_setup_try_clear( struct lp_setup_context
*setup
,
389 uint32_t zsvalue
= 0;
390 union lp_rast_cmd_arg color_arg
;
393 LP_DBG(DEBUG_SETUP
, "%s state %d\n", __FUNCTION__
, setup
->state
);
395 if (flags
& PIPE_CLEAR_COLOR
) {
396 for (i
= 0; i
< 4; i
++)
397 color_arg
.clear_color
[i
] = float_to_ubyte(color
[i
]);
400 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
401 uint32_t zmask
= (flags
& PIPE_CLEAR_DEPTH
) ? ~0 : 0;
402 uint32_t smask
= (flags
& PIPE_CLEAR_STENCIL
) ? ~0 : 0;
404 zsvalue
= util_pack_z_stencil(setup
->fb
.zsbuf
->format
,
409 zsmask
= util_pack_mask_z_stencil(setup
->fb
.zsbuf
->format
,
416 if (setup
->state
== SETUP_ACTIVE
) {
417 struct lp_scene
*scene
= setup
->scene
;
419 /* Add the clear to existing scene. In the unusual case where
420 * both color and depth-stencil are being cleared when there's
421 * already been some rendering, we could discard the currently
422 * binned scene and start again, but I don't see that as being
425 if (flags
& PIPE_CLEAR_COLOR
) {
426 if (!lp_scene_bin_everywhere( scene
,
427 LP_RAST_OP_CLEAR_COLOR
,
432 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
433 if (!lp_scene_bin_everywhere( scene
,
434 LP_RAST_OP_CLEAR_ZSTENCIL
,
435 lp_rast_arg_clearzs(zsvalue
, zsmask
) ))
440 /* Put ourselves into the 'pre-clear' state, specifically to try
441 * and accumulate multiple clears to color and depth_stencil
442 * buffers which the app or state-tracker might issue
445 set_scene_state( setup
, SETUP_CLEARED
, __FUNCTION__
);
447 setup
->clear
.flags
|= flags
;
449 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
450 setup
->clear
.zsmask
|= zsmask
;
451 setup
->clear
.zsvalue
=
452 (setup
->clear
.zsvalue
& ~zsmask
) | (zsvalue
& zsmask
);
455 if (flags
& PIPE_CLEAR_COLOR
) {
456 memcpy(setup
->clear
.color
.clear_color
,
458 sizeof setup
->clear
.color
.clear_color
);
466 lp_setup_clear( struct lp_setup_context
*setup
,
472 if (!lp_setup_try_clear( setup
, color
, depth
, stencil
, flags
)) {
473 lp_setup_flush(setup
, 0, NULL
, __FUNCTION__
);
475 if (!lp_setup_try_clear( setup
, color
, depth
, stencil
, flags
))
485 lp_setup_set_triangle_state( struct lp_setup_context
*setup
,
487 boolean ccw_is_frontface
,
489 boolean gl_rasterization_rules
)
491 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
493 setup
->ccw_is_frontface
= ccw_is_frontface
;
494 setup
->cullmode
= cull_mode
;
495 setup
->triangle
= first_triangle
;
496 setup
->pixel_offset
= gl_rasterization_rules
? 0.5f
: 0.0f
;
498 if (setup
->scissor_test
!= scissor
) {
499 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
500 setup
->scissor_test
= scissor
;
505 lp_setup_set_line_state( struct lp_setup_context
*setup
,
508 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
510 setup
->line_width
= line_width
;
514 lp_setup_set_point_state( struct lp_setup_context
*setup
,
516 boolean point_size_per_vertex
,
517 uint sprite_coord_enable
,
518 uint sprite_coord_origin
)
520 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
522 setup
->point_size
= point_size
;
523 setup
->sprite_coord_enable
= sprite_coord_enable
;
524 setup
->sprite_coord_origin
= sprite_coord_origin
;
525 setup
->point_size_per_vertex
= point_size_per_vertex
;
529 lp_setup_set_setup_variant( struct lp_setup_context
*setup
,
530 const struct lp_setup_variant
*variant
)
532 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
534 setup
->setup
.variant
= variant
;
538 lp_setup_set_fs_variant( struct lp_setup_context
*setup
,
539 struct lp_fragment_shader_variant
*variant
)
541 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
,
543 /* FIXME: reference count */
545 setup
->fs
.current
.variant
= variant
;
546 setup
->dirty
|= LP_SETUP_NEW_FS
;
550 lp_setup_set_fs_constants(struct lp_setup_context
*setup
,
551 struct pipe_resource
*buffer
)
553 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) buffer
);
555 pipe_resource_reference(&setup
->constants
.current
, buffer
);
557 setup
->dirty
|= LP_SETUP_NEW_CONSTANTS
;
562 lp_setup_set_alpha_ref_value( struct lp_setup_context
*setup
,
563 float alpha_ref_value
)
565 LP_DBG(DEBUG_SETUP
, "%s %f\n", __FUNCTION__
, alpha_ref_value
);
567 if(setup
->fs
.current
.jit_context
.alpha_ref_value
!= alpha_ref_value
) {
568 setup
->fs
.current
.jit_context
.alpha_ref_value
= alpha_ref_value
;
569 setup
->dirty
|= LP_SETUP_NEW_FS
;
574 lp_setup_set_stencil_ref_values( struct lp_setup_context
*setup
,
575 const ubyte refs
[2] )
577 LP_DBG(DEBUG_SETUP
, "%s %d %d\n", __FUNCTION__
, refs
[0], refs
[1]);
579 if (setup
->fs
.current
.jit_context
.stencil_ref_front
!= refs
[0] ||
580 setup
->fs
.current
.jit_context
.stencil_ref_back
!= refs
[1]) {
581 setup
->fs
.current
.jit_context
.stencil_ref_front
= refs
[0];
582 setup
->fs
.current
.jit_context
.stencil_ref_back
= refs
[1];
583 setup
->dirty
|= LP_SETUP_NEW_FS
;
588 lp_setup_set_blend_color( struct lp_setup_context
*setup
,
589 const struct pipe_blend_color
*blend_color
)
591 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
595 if(memcmp(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
) != 0) {
596 memcpy(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
);
597 setup
->dirty
|= LP_SETUP_NEW_BLEND_COLOR
;
603 lp_setup_set_scissor( struct lp_setup_context
*setup
,
604 const struct pipe_scissor_state
*scissor
)
606 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
610 setup
->scissor
.x0
= scissor
->minx
;
611 setup
->scissor
.x1
= scissor
->maxx
-1;
612 setup
->scissor
.y0
= scissor
->miny
;
613 setup
->scissor
.y1
= scissor
->maxy
-1;
614 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
619 lp_setup_set_flatshade_first( struct lp_setup_context
*setup
,
620 boolean flatshade_first
)
622 setup
->flatshade_first
= flatshade_first
;
627 lp_setup_set_vertex_info( struct lp_setup_context
*setup
,
628 struct vertex_info
*vertex_info
)
630 /* XXX: just silently holding onto the pointer:
632 setup
->vertex_info
= vertex_info
;
637 * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
640 lp_setup_set_fragment_sampler_views(struct lp_setup_context
*setup
,
642 struct pipe_sampler_view
**views
)
646 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
648 assert(num
<= PIPE_MAX_SAMPLERS
);
650 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
651 struct pipe_sampler_view
*view
= i
< num
? views
[i
] : NULL
;
654 struct pipe_resource
*tex
= view
->texture
;
655 struct llvmpipe_resource
*lp_tex
= llvmpipe_resource(tex
);
656 struct lp_jit_texture
*jit_tex
;
657 jit_tex
= &setup
->fs
.current
.jit_context
.textures
[i
];
658 jit_tex
->width
= tex
->width0
;
659 jit_tex
->height
= tex
->height0
;
660 jit_tex
->depth
= tex
->depth0
;
661 jit_tex
->last_level
= tex
->last_level
;
663 /* We're referencing the texture's internal data, so save a
666 pipe_resource_reference(&setup
->fs
.current_tex
[i
], tex
);
669 /* regular texture - setup array of mipmap level pointers */
671 for (j
= 0; j
<= tex
->last_level
; j
++) {
673 llvmpipe_get_texture_image_all(lp_tex
, j
, LP_TEX_USAGE_READ
,
674 LP_TEX_LAYOUT_LINEAR
);
675 jit_tex
->row_stride
[j
] = lp_tex
->row_stride
[j
];
676 jit_tex
->img_stride
[j
] = lp_tex
->img_stride
[j
];
678 if ((LP_PERF
& PERF_TEX_MEM
) ||
680 /* out of memory - use dummy tile memory */
681 jit_tex
->data
[j
] = lp_dummy_tile
;
682 jit_tex
->width
= TILE_SIZE
/8;
683 jit_tex
->height
= TILE_SIZE
/8;
685 jit_tex
->last_level
= 0;
686 jit_tex
->row_stride
[j
] = 0;
687 jit_tex
->img_stride
[j
] = 0;
692 /* display target texture/surface */
694 * XXX: Where should this be unmapped?
696 struct llvmpipe_screen
*screen
= llvmpipe_screen(tex
->screen
);
697 struct sw_winsys
*winsys
= screen
->winsys
;
698 jit_tex
->data
[0] = winsys
->displaytarget_map(winsys
, lp_tex
->dt
,
700 jit_tex
->row_stride
[0] = lp_tex
->row_stride
[0];
701 jit_tex
->img_stride
[0] = lp_tex
->img_stride
[0];
702 assert(jit_tex
->data
[0]);
707 setup
->dirty
|= LP_SETUP_NEW_FS
;
712 * Called during state validation when LP_NEW_SAMPLER is set.
715 lp_setup_set_fragment_sampler_state(struct lp_setup_context
*setup
,
717 const struct pipe_sampler_state
**samplers
)
721 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
723 assert(num
<= PIPE_MAX_SAMPLERS
);
725 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
726 const struct pipe_sampler_state
*sampler
= i
< num
? samplers
[i
] : NULL
;
729 struct lp_jit_texture
*jit_tex
;
730 jit_tex
= &setup
->fs
.current
.jit_context
.textures
[i
];
732 jit_tex
->min_lod
= sampler
->min_lod
;
733 jit_tex
->max_lod
= sampler
->max_lod
;
734 jit_tex
->lod_bias
= sampler
->lod_bias
;
735 COPY_4V(jit_tex
->border_color
, sampler
->border_color
);
739 setup
->dirty
|= LP_SETUP_NEW_FS
;
744 * Is the given texture referenced by any scene?
745 * Note: we have to check all scenes including any scenes currently
746 * being rendered and the current scene being built.
749 lp_setup_is_resource_referenced( const struct lp_setup_context
*setup
,
750 const struct pipe_resource
*texture
)
754 /* check the render targets */
755 for (i
= 0; i
< setup
->fb
.nr_cbufs
; i
++) {
756 if (setup
->fb
.cbufs
[i
]->texture
== texture
)
757 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
759 if (setup
->fb
.zsbuf
&& setup
->fb
.zsbuf
->texture
== texture
) {
760 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
763 /* check textures referenced by the scene */
764 for (i
= 0; i
< Elements(setup
->scenes
); i
++) {
765 if (lp_scene_is_resource_referenced(setup
->scenes
[i
], texture
)) {
766 return PIPE_REFERENCED_FOR_READ
;
770 return PIPE_UNREFERENCED
;
775 * Called by vbuf code when we're about to draw something.
778 try_update_scene_state( struct lp_setup_context
*setup
)
780 boolean new_scene
= (setup
->fs
.stored
== NULL
);
781 struct lp_scene
*scene
= setup
->scene
;
785 if(setup
->dirty
& LP_SETUP_NEW_BLEND_COLOR
) {
789 stored
= lp_scene_alloc_aligned(scene
, 4 * 16, 16);
795 /* smear each blend color component across 16 ubyte elements */
796 for (i
= 0; i
< 4; ++i
) {
797 uint8_t c
= float_to_ubyte(setup
->blend_color
.current
.color
[i
]);
798 for (j
= 0; j
< 16; ++j
)
799 stored
[i
*16 + j
] = c
;
802 setup
->blend_color
.stored
= stored
;
803 setup
->fs
.current
.jit_context
.blend_color
= setup
->blend_color
.stored
;
804 setup
->dirty
|= LP_SETUP_NEW_FS
;
807 if(setup
->dirty
& LP_SETUP_NEW_CONSTANTS
) {
808 struct pipe_resource
*buffer
= setup
->constants
.current
;
811 unsigned current_size
= buffer
->width0
;
812 const void *current_data
= llvmpipe_resource_data(buffer
);
814 /* TODO: copy only the actually used constants? */
816 if(setup
->constants
.stored_size
!= current_size
||
817 !setup
->constants
.stored_data
||
818 memcmp(setup
->constants
.stored_data
,
820 current_size
) != 0) {
823 stored
= lp_scene_alloc(scene
, current_size
);
832 setup
->constants
.stored_size
= current_size
;
833 setup
->constants
.stored_data
= stored
;
837 setup
->constants
.stored_size
= 0;
838 setup
->constants
.stored_data
= NULL
;
841 setup
->fs
.current
.jit_context
.constants
= setup
->constants
.stored_data
;
842 setup
->dirty
|= LP_SETUP_NEW_FS
;
846 if (setup
->dirty
& LP_SETUP_NEW_FS
) {
847 if (!setup
->fs
.stored
||
848 memcmp(setup
->fs
.stored
,
850 sizeof setup
->fs
.current
) != 0)
852 struct lp_rast_state
*stored
;
855 /* The fs state that's been stored in the scene is different from
856 * the new, current state. So allocate a new lp_rast_state object
857 * and append it to the bin's setup data buffer.
859 stored
= (struct lp_rast_state
*) lp_scene_alloc(scene
, sizeof *stored
);
867 sizeof setup
->fs
.current
);
868 setup
->fs
.stored
= stored
;
870 /* The scene now references the textures in the rasterization
871 * state record. Note that now.
873 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
874 if (setup
->fs
.current_tex
[i
]) {
875 if (!lp_scene_add_resource_reference(scene
,
876 setup
->fs
.current_tex
[i
],
886 if (setup
->dirty
& LP_SETUP_NEW_SCISSOR
) {
887 setup
->draw_region
= setup
->framebuffer
;
888 if (setup
->scissor_test
) {
889 u_rect_possible_intersection(&setup
->scissor
,
890 &setup
->draw_region
);
896 assert(setup
->fs
.stored
);
901 lp_setup_update_state( struct lp_setup_context
*setup
,
902 boolean update_scene
)
904 /* Some of the 'draw' pipeline stages may have changed some driver state.
905 * Make sure we've processed those state changes before anything else.
907 * XXX this is the only place where llvmpipe_context is used in the
908 * setup code. This may get refactored/changed...
911 struct llvmpipe_context
*lp
= llvmpipe_context(setup
->pipe
);
913 llvmpipe_update_derived(lp
);
916 /* Will probably need to move this somewhere else, just need
917 * to know about vertex shader point size attribute.
919 setup
->psize
= lp
->psize_slot
;
921 assert(lp
->dirty
== 0);
923 assert(lp
->setup_variant
.key
.size
==
924 setup
->setup
.variant
->key
.size
);
926 assert(memcmp(&lp
->setup_variant
.key
,
927 &setup
->setup
.variant
->key
,
928 setup
->setup
.variant
->key
.size
) == 0);
932 if (!set_scene_state( setup
, SETUP_ACTIVE
, __FUNCTION__
))
936 /* Only call into update_scene_state() if we already have a
939 if (update_scene
&& setup
->scene
) {
940 assert(setup
->state
== SETUP_ACTIVE
);
942 if (try_update_scene_state(setup
))
945 /* Update failed, try to restart the scene.
947 * Cannot call lp_setup_flush_and_restart() directly here
948 * because of potential recursion.
950 if (!set_scene_state(setup
, SETUP_FLUSHED
, __FUNCTION__
))
953 if (!set_scene_state(setup
, SETUP_ACTIVE
, __FUNCTION__
))
959 return try_update_scene_state(setup
);
967 /* Only caller is lp_setup_vbuf_destroy()
970 lp_setup_destroy( struct lp_setup_context
*setup
)
974 lp_setup_reset( setup
);
976 util_unreference_framebuffer_state(&setup
->fb
);
978 for (i
= 0; i
< Elements(setup
->fs
.current_tex
); i
++) {
979 pipe_resource_reference(&setup
->fs
.current_tex
[i
], NULL
);
982 pipe_resource_reference(&setup
->constants
.current
, NULL
);
984 /* free the scenes in the 'empty' queue */
985 for (i
= 0; i
< Elements(setup
->scenes
); i
++) {
986 struct lp_scene
*scene
= setup
->scenes
[i
];
989 lp_fence_wait(scene
->fence
);
991 lp_scene_destroy(scene
);
999 * Create a new primitive tiling engine. Plug it into the backend of
1000 * the draw module. Currently also creates a rasterizer to use with
1003 struct lp_setup_context
*
1004 lp_setup_create( struct pipe_context
*pipe
,
1005 struct draw_context
*draw
)
1007 struct llvmpipe_screen
*screen
= llvmpipe_screen(pipe
->screen
);
1008 struct lp_setup_context
*setup
= CALLOC_STRUCT(lp_setup_context
);
1014 lp_setup_init_vbuf(setup
);
1016 /* Used only in update_state():
1021 setup
->num_threads
= screen
->num_threads
;
1022 setup
->vbuf
= draw_vbuf_stage(draw
, &setup
->base
);
1026 draw_set_rasterize_stage(draw
, setup
->vbuf
);
1027 draw_set_render(draw
, &setup
->base
);
1029 /* create some empty scenes */
1030 for (i
= 0; i
< MAX_SCENES
; i
++) {
1031 setup
->scenes
[i
] = lp_scene_create( pipe
);
1034 setup
->triangle
= first_triangle
;
1035 setup
->line
= first_line
;
1036 setup
->point
= first_point
;
1052 * Put a BeginQuery command into all bins.
1055 lp_setup_begin_query(struct lp_setup_context
*setup
,
1056 struct llvmpipe_query
*pq
)
1058 /* init the query to its beginning state */
1059 assert(setup
->active_query
== NULL
);
1062 if (!lp_scene_bin_everywhere(setup
->scene
,
1063 LP_RAST_OP_BEGIN_QUERY
,
1064 lp_rast_arg_query(pq
))) {
1066 if (!lp_setup_flush_and_restart(setup
))
1069 if (!lp_scene_bin_everywhere(setup
->scene
,
1070 LP_RAST_OP_BEGIN_QUERY
,
1071 lp_rast_arg_query(pq
))) {
1077 setup
->active_query
= pq
;
1082 * Put an EndQuery command into all bins.
1085 lp_setup_end_query(struct lp_setup_context
*setup
, struct llvmpipe_query
*pq
)
1087 union lp_rast_cmd_arg dummy
= { 0 };
1089 assert(setup
->active_query
== pq
);
1090 setup
->active_query
= NULL
;
1092 /* Setup will automatically re-issue any query which carried over a
1093 * scene boundary, and the rasterizer automatically "ends" queries
1094 * which are active at the end of a scene, so there is no need to
1095 * retry this commands on failure.
1098 /* pq->fence should be the fence of the *last* scene which
1099 * contributed to the query result.
1101 lp_fence_reference(&pq
->fence
, setup
->scene
->fence
);
1103 if (!lp_scene_bin_everywhere(setup
->scene
,
1104 LP_RAST_OP_END_QUERY
,
1106 lp_setup_flush(setup
, 0, NULL
, __FUNCTION__
);
1110 lp_fence_reference(&pq
->fence
, setup
->last_fence
);
1116 lp_setup_flush_and_restart(struct lp_setup_context
*setup
)
1118 if (0) debug_printf("%s\n", __FUNCTION__
);
1120 assert(setup
->state
== SETUP_ACTIVE
);
1122 if (!set_scene_state(setup
, SETUP_FLUSHED
, __FUNCTION__
))
1125 if (!lp_setup_update_state(setup
, TRUE
))