1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
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 "util/u_viewport.h"
43 #include "draw/draw_pipe.h"
44 #include "util/os_time.h"
45 #include "lp_context.h"
46 #include "lp_memory.h"
48 #include "lp_texture.h"
53 #include "lp_setup_context.h"
54 #include "lp_screen.h"
56 #include "state_tracker/sw_winsys.h"
58 #include "draw/draw_context.h"
59 #include "draw/draw_vbuf.h"
62 static boolean
set_scene_state( struct lp_setup_context
*, enum setup_state
,
64 static boolean
try_update_scene_state( struct lp_setup_context
*setup
);
68 lp_setup_get_empty_scene(struct lp_setup_context
*setup
)
70 assert(setup
->scene
== NULL
);
73 setup
->scene_idx
%= ARRAY_SIZE(setup
->scenes
);
75 setup
->scene
= setup
->scenes
[setup
->scene_idx
];
77 if (setup
->scene
->fence
) {
78 if (LP_DEBUG
& DEBUG_SETUP
)
79 debug_printf("%s: wait for scene %d\n",
80 __FUNCTION__
, setup
->scene
->fence
->id
);
82 lp_fence_wait(setup
->scene
->fence
);
85 lp_scene_begin_binning(setup
->scene
, &setup
->fb
);
91 first_triangle( struct lp_setup_context
*setup
,
96 assert(setup
->state
== SETUP_ACTIVE
);
97 lp_setup_choose_triangle( setup
);
98 setup
->triangle( setup
, v0
, v1
, v2
);
102 first_line( struct lp_setup_context
*setup
,
103 const float (*v0
)[4],
104 const float (*v1
)[4])
106 assert(setup
->state
== SETUP_ACTIVE
);
107 lp_setup_choose_line( setup
);
108 setup
->line( setup
, v0
, v1
);
112 first_point( struct lp_setup_context
*setup
,
113 const float (*v0
)[4])
115 assert(setup
->state
== SETUP_ACTIVE
);
116 lp_setup_choose_point( setup
);
117 setup
->point( setup
, v0
);
120 void lp_setup_reset( struct lp_setup_context
*setup
)
124 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
126 /* Reset derived state */
127 for (i
= 0; i
< ARRAY_SIZE(setup
->constants
); ++i
) {
128 setup
->constants
[i
].stored_size
= 0;
129 setup
->constants
[i
].stored_data
= NULL
;
131 setup
->fs
.stored
= NULL
;
139 memset(&setup
->clear
, 0, sizeof setup
->clear
);
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
= setup
->scene
;
155 struct llvmpipe_screen
*screen
= llvmpipe_screen(scene
->pipe
->screen
);
157 scene
->num_active_queries
= setup
->active_binned_queries
;
158 memcpy(scene
->active_queries
, setup
->active_queries
,
159 scene
->num_active_queries
* sizeof(scene
->active_queries
[0]));
161 lp_scene_end_binning(scene
);
163 lp_fence_reference(&setup
->last_fence
, scene
->fence
);
165 if (setup
->last_fence
)
166 setup
->last_fence
->issued
= TRUE
;
168 mtx_lock(&screen
->rast_mutex
);
170 /* FIXME: We enqueue the scene then wait on the rasterizer to finish.
171 * This means we never actually run any vertex stuff in parallel to
172 * rasterization (not in the same context at least) which is what the
173 * multiple scenes per setup is about - when we get a new empty scene
174 * any old one is already empty again because we waited here for
175 * raster tasks to be finished. Ideally, we shouldn't need to wait here
176 * and rely on fences elsewhere when waiting is necessary.
177 * Certainly, lp_scene_end_rasterization() would need to be deferred too
178 * and there's probably other bits why this doesn't actually work.
180 lp_rast_queue_scene(screen
->rast
, scene
);
181 lp_rast_finish(screen
->rast
);
182 mtx_unlock(&screen
->rast_mutex
);
184 lp_scene_end_rasterization(setup
->scene
);
185 lp_setup_reset( setup
);
187 LP_DBG(DEBUG_SETUP
, "%s done \n", __FUNCTION__
);
193 begin_binning( struct lp_setup_context
*setup
)
195 struct lp_scene
*scene
= setup
->scene
;
196 boolean need_zsload
= FALSE
;
200 assert(scene
->fence
== NULL
);
202 /* Always create a fence:
204 scene
->fence
= lp_fence_create(MAX2(1, setup
->num_threads
));
208 ok
= try_update_scene_state(setup
);
212 if (setup
->fb
.zsbuf
&&
213 ((setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
) &&
214 util_format_is_depth_and_stencil(setup
->fb
.zsbuf
->format
))
217 LP_DBG(DEBUG_SETUP
, "%s color clear bufs: %x depth: %s\n", __FUNCTION__
,
218 setup
->clear
.flags
>> 2,
219 need_zsload
? "clear": "load");
221 if (setup
->clear
.flags
& PIPE_CLEAR_COLOR
) {
223 for (cbuf
= 0; cbuf
< setup
->fb
.nr_cbufs
; cbuf
++) {
224 assert(PIPE_CLEAR_COLOR0
== 1 << 2);
225 if (setup
->clear
.flags
& (1 << (2 + cbuf
))) {
226 union lp_rast_cmd_arg clearrb_arg
;
227 struct lp_rast_clear_rb
*cc_scene
=
228 (struct lp_rast_clear_rb
*)
229 lp_scene_alloc(scene
, sizeof(struct lp_rast_clear_rb
));
235 cc_scene
->cbuf
= cbuf
;
236 cc_scene
->color_val
= setup
->clear
.color_val
[cbuf
];
237 clearrb_arg
.clear_rb
= cc_scene
;
239 if (!lp_scene_bin_everywhere(scene
,
240 LP_RAST_OP_CLEAR_COLOR
,
247 if (setup
->fb
.zsbuf
) {
248 if (setup
->clear
.flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
249 ok
= lp_scene_bin_everywhere( scene
,
250 LP_RAST_OP_CLEAR_ZSTENCIL
,
252 setup
->clear
.zsvalue
,
253 setup
->clear
.zsmask
));
259 setup
->clear
.flags
= 0;
260 setup
->clear
.zsmask
= 0;
261 setup
->clear
.zsvalue
= 0;
263 scene
->had_queries
= !!setup
->active_binned_queries
;
265 LP_DBG(DEBUG_SETUP
, "%s done\n", __FUNCTION__
);
270 /* This basically bins and then flushes any outstanding full-screen
273 * TODO: fast path for fullscreen clears and no triangles.
276 execute_clears( struct lp_setup_context
*setup
)
278 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
280 return begin_binning( setup
);
283 const char *states
[] = {
291 set_scene_state( struct lp_setup_context
*setup
,
292 enum setup_state new_state
,
295 unsigned old_state
= setup
->state
;
297 if (old_state
== new_state
)
300 if (LP_DEBUG
& DEBUG_SCENE
) {
301 debug_printf("%s old %s new %s%s%s\n",
305 (new_state
== SETUP_FLUSHED
) ? ": " : "",
306 (new_state
== SETUP_FLUSHED
) ? reason
: "");
308 if (new_state
== SETUP_FLUSHED
&& setup
->scene
)
309 lp_debug_draw_bins_by_cmd_length(setup
->scene
);
312 /* wait for a free/empty scene
314 if (old_state
== SETUP_FLUSHED
)
315 lp_setup_get_empty_scene(setup
);
322 if (!begin_binning( setup
))
327 if (old_state
== SETUP_CLEARED
)
328 if (!execute_clears( setup
))
331 lp_setup_rasterize_scene( setup
);
332 assert(setup
->scene
== NULL
);
336 assert(0 && "invalid setup state mode");
340 setup
->state
= new_state
;
345 lp_scene_end_rasterization(setup
->scene
);
349 setup
->state
= SETUP_FLUSHED
;
350 lp_setup_reset( setup
);
356 lp_setup_flush( struct lp_setup_context
*setup
,
357 struct pipe_fence_handle
**fence
,
360 set_scene_state( setup
, SETUP_FLUSHED
, reason
);
363 lp_fence_reference((struct lp_fence
**)fence
, setup
->last_fence
);
365 *fence
= (struct pipe_fence_handle
*)lp_fence_create(0);
371 lp_setup_bind_framebuffer( struct lp_setup_context
*setup
,
372 const struct pipe_framebuffer_state
*fb
)
374 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
376 /* Flush any old scene.
378 set_scene_state( setup
, SETUP_FLUSHED
, __FUNCTION__
);
381 * Ensure the old scene is not reused.
383 assert(!setup
->scene
);
385 /* Set new state. This will be picked up later when we next need a
388 util_copy_framebuffer_state(&setup
->fb
, fb
);
389 setup
->framebuffer
.x0
= 0;
390 setup
->framebuffer
.y0
= 0;
391 setup
->framebuffer
.x1
= fb
->width
-1;
392 setup
->framebuffer
.y1
= fb
->height
-1;
393 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
398 * Try to clear one color buffer of the attached fb, either by binning a clear
399 * command or queuing up the clear for later (when binning is started).
402 lp_setup_try_clear_color_buffer(struct lp_setup_context
*setup
,
403 const union pipe_color_union
*color
,
406 union lp_rast_cmd_arg clearrb_arg
;
408 enum pipe_format format
= setup
->fb
.cbufs
[cbuf
]->format
;
410 LP_DBG(DEBUG_SETUP
, "%s state %d\n", __FUNCTION__
, setup
->state
);
412 if (util_format_is_pure_integer(format
)) {
414 * We expect int/uint clear values here, though some APIs
415 * might disagree (but in any case util_pack_color()
416 * couldn't handle it)...
418 if (util_format_is_pure_sint(format
)) {
419 util_format_write_4i(format
, color
->i
, 0, &uc
, 0, 0, 0, 1, 1);
422 assert(util_format_is_pure_uint(format
));
423 util_format_write_4ui(format
, color
->ui
, 0, &uc
, 0, 0, 0, 1, 1);
427 util_pack_color(color
->f
, format
, &uc
);
430 if (setup
->state
== SETUP_ACTIVE
) {
431 struct lp_scene
*scene
= setup
->scene
;
433 /* Add the clear to existing scene. In the unusual case where
434 * both color and depth-stencil are being cleared when there's
435 * already been some rendering, we could discard the currently
436 * binned scene and start again, but I don't see that as being
439 struct lp_rast_clear_rb
*cc_scene
=
440 (struct lp_rast_clear_rb
*)
441 lp_scene_alloc_aligned(scene
, sizeof(struct lp_rast_clear_rb
), 8);
447 cc_scene
->cbuf
= cbuf
;
448 cc_scene
->color_val
= uc
;
449 clearrb_arg
.clear_rb
= cc_scene
;
451 if (!lp_scene_bin_everywhere(scene
,
452 LP_RAST_OP_CLEAR_COLOR
,
457 /* Put ourselves into the 'pre-clear' state, specifically to try
458 * and accumulate multiple clears to color and depth_stencil
459 * buffers which the app or state-tracker might issue
462 set_scene_state( setup
, SETUP_CLEARED
, __FUNCTION__
);
464 assert(PIPE_CLEAR_COLOR0
== (1 << 2));
465 setup
->clear
.flags
|= 1 << (cbuf
+ 2);
466 setup
->clear
.color_val
[cbuf
] = uc
;
473 lp_setup_try_clear_zs(struct lp_setup_context
*setup
,
479 uint64_t zsvalue
= 0;
482 enum pipe_format format
= setup
->fb
.zsbuf
->format
;
484 LP_DBG(DEBUG_SETUP
, "%s state %d\n", __FUNCTION__
, setup
->state
);
486 zmask32
= (flags
& PIPE_CLEAR_DEPTH
) ? ~0 : 0;
487 smask8
= (flags
& PIPE_CLEAR_STENCIL
) ? ~0 : 0;
489 zsvalue
= util_pack64_z_stencil(format
, depth
, stencil
);
491 zsmask
= util_pack64_mask_z_stencil(format
, zmask32
, smask8
);
495 if (format
== PIPE_FORMAT_Z24X8_UNORM
||
496 format
== PIPE_FORMAT_X8Z24_UNORM
) {
498 * Make full mask if there's "X" bits so we can do full
499 * clear (without rmw).
501 uint32_t zsmask_full
= 0;
502 zsmask_full
= util_pack_mask_z_stencil(format
, ~0, ~0);
503 zsmask
|= ~zsmask_full
;
506 if (setup
->state
== SETUP_ACTIVE
) {
507 struct lp_scene
*scene
= setup
->scene
;
509 /* Add the clear to existing scene. In the unusual case where
510 * both color and depth-stencil are being cleared when there's
511 * already been some rendering, we could discard the currently
512 * binned scene and start again, but I don't see that as being
515 if (!lp_scene_bin_everywhere(scene
,
516 LP_RAST_OP_CLEAR_ZSTENCIL
,
517 lp_rast_arg_clearzs(zsvalue
, zsmask
)))
521 /* Put ourselves into the 'pre-clear' state, specifically to try
522 * and accumulate multiple clears to color and depth_stencil
523 * buffers which the app or state-tracker might issue
526 set_scene_state( setup
, SETUP_CLEARED
, __FUNCTION__
);
528 setup
->clear
.flags
|= flags
;
530 setup
->clear
.zsmask
|= zsmask
;
531 setup
->clear
.zsvalue
=
532 (setup
->clear
.zsvalue
& ~zsmask
) | (zsvalue
& zsmask
);
539 lp_setup_clear( struct lp_setup_context
*setup
,
540 const union pipe_color_union
*color
,
548 * Note any of these (max 9) clears could fail (but at most there should
549 * be just one failure!). This avoids doing the previous succeeded
550 * clears again (we still clear tiles twice if a clear command succeeded
551 * partially for one buffer).
553 if (flags
& PIPE_CLEAR_DEPTHSTENCIL
) {
554 unsigned flagszs
= flags
& PIPE_CLEAR_DEPTHSTENCIL
;
555 if (!lp_setup_try_clear_zs(setup
, depth
, stencil
, flagszs
)) {
556 lp_setup_flush(setup
, NULL
, __FUNCTION__
);
558 if (!lp_setup_try_clear_zs(setup
, depth
, stencil
, flagszs
))
563 if (flags
& PIPE_CLEAR_COLOR
) {
564 assert(PIPE_CLEAR_COLOR0
== (1 << 2));
565 for (i
= 0; i
< setup
->fb
.nr_cbufs
; i
++) {
566 if ((flags
& (1 << (2 + i
))) && setup
->fb
.cbufs
[i
]) {
567 if (!lp_setup_try_clear_color_buffer(setup
, color
, i
)) {
568 lp_setup_flush(setup
, NULL
, __FUNCTION__
);
570 if (!lp_setup_try_clear_color_buffer(setup
, color
, i
))
581 lp_setup_set_triangle_state( struct lp_setup_context
*setup
,
583 boolean ccw_is_frontface
,
585 boolean half_pixel_center
,
586 boolean bottom_edge_rule
)
588 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
590 setup
->ccw_is_frontface
= ccw_is_frontface
;
591 setup
->cullmode
= cull_mode
;
592 setup
->triangle
= first_triangle
;
593 setup
->pixel_offset
= half_pixel_center
? 0.5f
: 0.0f
;
594 setup
->bottom_edge_rule
= bottom_edge_rule
;
596 if (setup
->scissor_test
!= scissor
) {
597 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
598 setup
->scissor_test
= scissor
;
603 lp_setup_set_line_state( struct lp_setup_context
*setup
,
606 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
608 setup
->line_width
= line_width
;
612 lp_setup_set_point_state( struct lp_setup_context
*setup
,
614 boolean point_size_per_vertex
,
615 uint sprite_coord_enable
,
616 uint sprite_coord_origin
)
618 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
620 setup
->point_size
= point_size
;
621 setup
->sprite_coord_enable
= sprite_coord_enable
;
622 setup
->sprite_coord_origin
= sprite_coord_origin
;
623 setup
->point_size_per_vertex
= point_size_per_vertex
;
627 lp_setup_set_setup_variant( struct lp_setup_context
*setup
,
628 const struct lp_setup_variant
*variant
)
630 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
632 setup
->setup
.variant
= variant
;
636 lp_setup_set_fs_variant( struct lp_setup_context
*setup
,
637 struct lp_fragment_shader_variant
*variant
)
639 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
,
641 /* FIXME: reference count */
643 setup
->fs
.current
.variant
= variant
;
644 setup
->dirty
|= LP_SETUP_NEW_FS
;
648 lp_setup_set_fs_constants(struct lp_setup_context
*setup
,
650 struct pipe_constant_buffer
*buffers
)
654 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) buffers
);
656 assert(num
<= ARRAY_SIZE(setup
->constants
));
658 for (i
= 0; i
< num
; ++i
) {
659 util_copy_constant_buffer(&setup
->constants
[i
].current
, &buffers
[i
]);
661 for (; i
< ARRAY_SIZE(setup
->constants
); i
++) {
662 util_copy_constant_buffer(&setup
->constants
[i
].current
, NULL
);
664 setup
->dirty
|= LP_SETUP_NEW_CONSTANTS
;
668 lp_setup_set_fs_ssbos(struct lp_setup_context
*setup
,
670 struct pipe_shader_buffer
*buffers
)
674 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) buffers
);
676 assert(num
<= ARRAY_SIZE(setup
->ssbos
));
678 for (i
= 0; i
< num
; ++i
) {
679 util_copy_shader_buffer(&setup
->ssbos
[i
].current
, &buffers
[i
]);
681 for (; i
< ARRAY_SIZE(setup
->ssbos
); i
++) {
682 util_copy_shader_buffer(&setup
->ssbos
[i
].current
, NULL
);
684 setup
->dirty
|= LP_SETUP_NEW_SSBOS
;
688 lp_setup_set_fs_images(struct lp_setup_context
*setup
,
690 struct pipe_image_view
*images
)
694 LP_DBG(DEBUG_SETUP
, "%s %p\n", __FUNCTION__
, (void *) images
);
696 assert(num
<= ARRAY_SIZE(setup
->images
));
698 for (i
= 0; i
< num
; ++i
) {
699 struct pipe_image_view
*image
= &images
[i
];
700 util_copy_image_view(&setup
->images
[i
].current
, &images
[i
]);
702 struct pipe_resource
*res
= image
->resource
;
703 struct llvmpipe_resource
*lp_res
= llvmpipe_resource(res
);
704 struct lp_jit_image
*jit_image
;
706 jit_image
= &setup
->fs
.current
.jit_context
.images
[i
];
710 /* regular texture - setup array of mipmap level offsets */
711 if (llvmpipe_resource_is_texture(res
)) {
712 jit_image
->base
= lp_res
->tex_data
;
714 jit_image
->base
= lp_res
->data
;
716 jit_image
->width
= res
->width0
;
717 jit_image
->height
= res
->height0
;
718 jit_image
->depth
= res
->depth0
;
720 if (llvmpipe_resource_is_texture(res
)) {
721 uint32_t mip_offset
= lp_res
->mip_offsets
[image
->u
.tex
.level
];
723 jit_image
->width
= u_minify(jit_image
->width
, image
->u
.tex
.level
);
724 jit_image
->height
= u_minify(jit_image
->height
, image
->u
.tex
.level
);
726 if (res
->target
== PIPE_TEXTURE_1D_ARRAY
||
727 res
->target
== PIPE_TEXTURE_2D_ARRAY
||
728 res
->target
== PIPE_TEXTURE_3D
||
729 res
->target
== PIPE_TEXTURE_CUBE
||
730 res
->target
== PIPE_TEXTURE_CUBE_ARRAY
) {
732 * For array textures, we don't have first_layer, instead
733 * adjust last_layer (stored as depth) plus the mip level offsets
734 * (as we have mip-first layout can't just adjust base ptr).
735 * XXX For mip levels, could do something similar.
737 jit_image
->depth
= image
->u
.tex
.last_layer
- image
->u
.tex
.first_layer
+ 1;
738 mip_offset
+= image
->u
.tex
.first_layer
* lp_res
->img_stride
[image
->u
.tex
.level
];
740 jit_image
->depth
= u_minify(jit_image
->depth
, image
->u
.tex
.level
);
742 jit_image
->row_stride
= lp_res
->row_stride
[image
->u
.tex
.level
];
743 jit_image
->img_stride
= lp_res
->img_stride
[image
->u
.tex
.level
];
744 jit_image
->base
= (uint8_t *)jit_image
->base
+ mip_offset
;
747 unsigned view_blocksize
= util_format_get_blocksize(image
->format
);
748 jit_image
->width
= image
->u
.buf
.size
/ view_blocksize
;
749 jit_image
->base
= (uint8_t *)jit_image
->base
+ image
->u
.buf
.offset
;
753 for (; i
< ARRAY_SIZE(setup
->images
); i
++) {
754 util_copy_image_view(&setup
->images
[i
].current
, NULL
);
756 setup
->dirty
|= LP_SETUP_NEW_IMAGES
;
760 lp_setup_set_alpha_ref_value( struct lp_setup_context
*setup
,
761 float alpha_ref_value
)
763 LP_DBG(DEBUG_SETUP
, "%s %f\n", __FUNCTION__
, alpha_ref_value
);
765 if(setup
->fs
.current
.jit_context
.alpha_ref_value
!= alpha_ref_value
) {
766 setup
->fs
.current
.jit_context
.alpha_ref_value
= alpha_ref_value
;
767 setup
->dirty
|= LP_SETUP_NEW_FS
;
772 lp_setup_set_stencil_ref_values( struct lp_setup_context
*setup
,
773 const ubyte refs
[2] )
775 LP_DBG(DEBUG_SETUP
, "%s %d %d\n", __FUNCTION__
, refs
[0], refs
[1]);
777 if (setup
->fs
.current
.jit_context
.stencil_ref_front
!= refs
[0] ||
778 setup
->fs
.current
.jit_context
.stencil_ref_back
!= refs
[1]) {
779 setup
->fs
.current
.jit_context
.stencil_ref_front
= refs
[0];
780 setup
->fs
.current
.jit_context
.stencil_ref_back
= refs
[1];
781 setup
->dirty
|= LP_SETUP_NEW_FS
;
786 lp_setup_set_blend_color( struct lp_setup_context
*setup
,
787 const struct pipe_blend_color
*blend_color
)
789 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
793 if(memcmp(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
) != 0) {
794 memcpy(&setup
->blend_color
.current
, blend_color
, sizeof *blend_color
);
795 setup
->dirty
|= LP_SETUP_NEW_BLEND_COLOR
;
801 lp_setup_set_scissors( struct lp_setup_context
*setup
,
802 const struct pipe_scissor_state
*scissors
)
805 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
809 for (i
= 0; i
< PIPE_MAX_VIEWPORTS
; ++i
) {
810 setup
->scissors
[i
].x0
= scissors
[i
].minx
;
811 setup
->scissors
[i
].x1
= scissors
[i
].maxx
-1;
812 setup
->scissors
[i
].y0
= scissors
[i
].miny
;
813 setup
->scissors
[i
].y1
= scissors
[i
].maxy
-1;
815 setup
->dirty
|= LP_SETUP_NEW_SCISSOR
;
820 lp_setup_set_flatshade_first(struct lp_setup_context
*setup
,
821 boolean flatshade_first
)
823 setup
->flatshade_first
= flatshade_first
;
827 lp_setup_set_rasterizer_discard(struct lp_setup_context
*setup
,
828 boolean rasterizer_discard
)
830 if (setup
->rasterizer_discard
!= rasterizer_discard
) {
831 setup
->rasterizer_discard
= rasterizer_discard
;
832 setup
->line
= first_line
;
833 setup
->point
= first_point
;
834 setup
->triangle
= first_triangle
;
839 lp_setup_set_vertex_info(struct lp_setup_context
*setup
,
840 struct vertex_info
*vertex_info
)
842 /* XXX: just silently holding onto the pointer:
844 setup
->vertex_info
= vertex_info
;
849 * Called during state validation when LP_NEW_VIEWPORT is set.
852 lp_setup_set_viewports(struct lp_setup_context
*setup
,
853 unsigned num_viewports
,
854 const struct pipe_viewport_state
*viewports
)
856 struct llvmpipe_context
*lp
= llvmpipe_context(setup
->pipe
);
859 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
861 assert(num_viewports
<= PIPE_MAX_VIEWPORTS
);
865 * For use in lp_state_fs.c, propagate the viewport values for all viewports.
867 for (i
= 0; i
< num_viewports
; i
++) {
870 util_viewport_zmin_zmax(&viewports
[i
], lp
->rasterizer
->clip_halfz
,
871 &min_depth
, &max_depth
);
873 if (setup
->viewports
[i
].min_depth
!= min_depth
||
874 setup
->viewports
[i
].max_depth
!= max_depth
) {
875 setup
->viewports
[i
].min_depth
= min_depth
;
876 setup
->viewports
[i
].max_depth
= max_depth
;
877 setup
->dirty
|= LP_SETUP_NEW_VIEWPORTS
;
884 * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
887 lp_setup_set_fragment_sampler_views(struct lp_setup_context
*setup
,
889 struct pipe_sampler_view
**views
)
891 unsigned i
, max_tex_num
;
893 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
895 assert(num
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
897 max_tex_num
= MAX2(num
, setup
->fs
.current_tex_num
);
899 for (i
= 0; i
< max_tex_num
; i
++) {
900 struct pipe_sampler_view
*view
= i
< num
? views
[i
] : NULL
;
903 struct pipe_resource
*res
= view
->texture
;
904 struct llvmpipe_resource
*lp_tex
= llvmpipe_resource(res
);
905 struct lp_jit_texture
*jit_tex
;
906 jit_tex
= &setup
->fs
.current
.jit_context
.textures
[i
];
908 /* We're referencing the texture's internal data, so save a
911 pipe_resource_reference(&setup
->fs
.current_tex
[i
], res
);
914 /* regular texture - setup array of mipmap level offsets */
916 unsigned first_level
= 0;
917 unsigned last_level
= 0;
919 if (llvmpipe_resource_is_texture(res
)) {
920 first_level
= view
->u
.tex
.first_level
;
921 last_level
= view
->u
.tex
.last_level
;
922 assert(first_level
<= last_level
);
923 assert(last_level
<= res
->last_level
);
924 jit_tex
->base
= lp_tex
->tex_data
;
927 jit_tex
->base
= lp_tex
->data
;
930 if (LP_PERF
& PERF_TEX_MEM
) {
931 /* use dummy tile memory */
932 jit_tex
->base
= lp_dummy_tile
;
933 jit_tex
->width
= TILE_SIZE
/8;
934 jit_tex
->height
= TILE_SIZE
/8;
936 jit_tex
->first_level
= 0;
937 jit_tex
->last_level
= 0;
938 jit_tex
->mip_offsets
[0] = 0;
939 jit_tex
->row_stride
[0] = 0;
940 jit_tex
->img_stride
[0] = 0;
943 jit_tex
->width
= res
->width0
;
944 jit_tex
->height
= res
->height0
;
945 jit_tex
->depth
= res
->depth0
;
946 jit_tex
->first_level
= first_level
;
947 jit_tex
->last_level
= last_level
;
949 if (llvmpipe_resource_is_texture(res
)) {
950 for (j
= first_level
; j
<= last_level
; j
++) {
951 jit_tex
->mip_offsets
[j
] = lp_tex
->mip_offsets
[j
];
952 jit_tex
->row_stride
[j
] = lp_tex
->row_stride
[j
];
953 jit_tex
->img_stride
[j
] = lp_tex
->img_stride
[j
];
956 if (res
->target
== PIPE_TEXTURE_1D_ARRAY
||
957 res
->target
== PIPE_TEXTURE_2D_ARRAY
||
958 res
->target
== PIPE_TEXTURE_CUBE
||
959 res
->target
== PIPE_TEXTURE_CUBE_ARRAY
) {
961 * For array textures, we don't have first_layer, instead
962 * adjust last_layer (stored as depth) plus the mip level offsets
963 * (as we have mip-first layout can't just adjust base ptr).
964 * XXX For mip levels, could do something similar.
966 jit_tex
->depth
= view
->u
.tex
.last_layer
- view
->u
.tex
.first_layer
+ 1;
967 for (j
= first_level
; j
<= last_level
; j
++) {
968 jit_tex
->mip_offsets
[j
] += view
->u
.tex
.first_layer
*
969 lp_tex
->img_stride
[j
];
971 if (view
->target
== PIPE_TEXTURE_CUBE
||
972 view
->target
== PIPE_TEXTURE_CUBE_ARRAY
) {
973 assert(jit_tex
->depth
% 6 == 0);
975 assert(view
->u
.tex
.first_layer
<= view
->u
.tex
.last_layer
);
976 assert(view
->u
.tex
.last_layer
< res
->array_size
);
981 * For buffers, we don't have "offset", instead adjust
982 * the size (stored as width) plus the base pointer.
984 unsigned view_blocksize
= util_format_get_blocksize(view
->format
);
985 /* probably don't really need to fill that out */
986 jit_tex
->mip_offsets
[0] = 0;
987 jit_tex
->row_stride
[0] = 0;
988 jit_tex
->img_stride
[0] = 0;
990 /* everything specified in number of elements here. */
991 jit_tex
->width
= view
->u
.buf
.size
/ view_blocksize
;
992 jit_tex
->base
= (uint8_t *)jit_tex
->base
+ view
->u
.buf
.offset
;
993 /* XXX Unsure if we need to sanitize parameters? */
994 assert(view
->u
.buf
.offset
+ view
->u
.buf
.size
<= res
->width0
);
999 /* display target texture/surface */
1001 * XXX: Where should this be unmapped?
1003 struct llvmpipe_screen
*screen
= llvmpipe_screen(res
->screen
);
1004 struct sw_winsys
*winsys
= screen
->winsys
;
1005 jit_tex
->base
= winsys
->displaytarget_map(winsys
, lp_tex
->dt
,
1006 PIPE_TRANSFER_READ
);
1007 jit_tex
->row_stride
[0] = lp_tex
->row_stride
[0];
1008 jit_tex
->img_stride
[0] = lp_tex
->img_stride
[0];
1009 jit_tex
->mip_offsets
[0] = 0;
1010 jit_tex
->width
= res
->width0
;
1011 jit_tex
->height
= res
->height0
;
1012 jit_tex
->depth
= res
->depth0
;
1013 jit_tex
->first_level
= jit_tex
->last_level
= 0;
1014 assert(jit_tex
->base
);
1018 pipe_resource_reference(&setup
->fs
.current_tex
[i
], NULL
);
1021 setup
->fs
.current_tex_num
= num
;
1023 setup
->dirty
|= LP_SETUP_NEW_FS
;
1028 * Called during state validation when LP_NEW_SAMPLER is set.
1031 lp_setup_set_fragment_sampler_state(struct lp_setup_context
*setup
,
1033 struct pipe_sampler_state
**samplers
)
1037 LP_DBG(DEBUG_SETUP
, "%s\n", __FUNCTION__
);
1039 assert(num
<= PIPE_MAX_SAMPLERS
);
1041 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
1042 const struct pipe_sampler_state
*sampler
= i
< num
? samplers
[i
] : NULL
;
1045 struct lp_jit_sampler
*jit_sam
;
1046 jit_sam
= &setup
->fs
.current
.jit_context
.samplers
[i
];
1048 jit_sam
->min_lod
= sampler
->min_lod
;
1049 jit_sam
->max_lod
= sampler
->max_lod
;
1050 jit_sam
->lod_bias
= sampler
->lod_bias
;
1051 COPY_4V(jit_sam
->border_color
, sampler
->border_color
.f
);
1055 setup
->dirty
|= LP_SETUP_NEW_FS
;
1060 * Is the given texture referenced by any scene?
1061 * Note: we have to check all scenes including any scenes currently
1062 * being rendered and the current scene being built.
1065 lp_setup_is_resource_referenced( const struct lp_setup_context
*setup
,
1066 const struct pipe_resource
*texture
)
1070 /* check the render targets */
1071 for (i
= 0; i
< setup
->fb
.nr_cbufs
; i
++) {
1072 if (setup
->fb
.cbufs
[i
] && setup
->fb
.cbufs
[i
]->texture
== texture
)
1073 return LP_REFERENCED_FOR_READ
| LP_REFERENCED_FOR_WRITE
;
1075 if (setup
->fb
.zsbuf
&& setup
->fb
.zsbuf
->texture
== texture
) {
1076 return LP_REFERENCED_FOR_READ
| LP_REFERENCED_FOR_WRITE
;
1079 /* check textures referenced by the scene */
1080 for (i
= 0; i
< ARRAY_SIZE(setup
->scenes
); i
++) {
1081 if (lp_scene_is_resource_referenced(setup
->scenes
[i
], texture
)) {
1082 return LP_REFERENCED_FOR_READ
;
1086 for (i
= 0; i
< ARRAY_SIZE(setup
->ssbos
); i
++) {
1087 if (setup
->ssbos
[i
].current
.buffer
== texture
)
1088 return LP_REFERENCED_FOR_READ
| LP_REFERENCED_FOR_WRITE
;
1091 for (i
= 0; i
< ARRAY_SIZE(setup
->images
); i
++) {
1092 if (setup
->images
[i
].current
.resource
== texture
)
1093 return LP_REFERENCED_FOR_READ
| LP_REFERENCED_FOR_WRITE
;
1096 return LP_UNREFERENCED
;
1101 * Called by vbuf code when we're about to draw something.
1103 * This function stores all dirty state in the current scene's display list
1104 * memory, via lp_scene_alloc(). We can not pass pointers of mutable state to
1105 * the JIT functions, as the JIT functions will be called later on, most likely
1106 * on a different thread.
1108 * When processing dirty state it is imperative that we don't refer to any
1109 * pointers previously allocated with lp_scene_alloc() in this function (or any
1110 * function) as they may belong to a scene freed since then.
1113 try_update_scene_state( struct lp_setup_context
*setup
)
1115 static const float fake_const_buf
[4];
1116 boolean new_scene
= (setup
->fs
.stored
== NULL
);
1117 struct lp_scene
*scene
= setup
->scene
;
1122 if (setup
->dirty
& LP_SETUP_NEW_VIEWPORTS
) {
1124 * Record new depth range state for changes due to viewport updates.
1126 * TODO: Collapse the existing viewport and depth range information
1127 * into one structure, for access by JIT.
1129 struct lp_jit_viewport
*stored
;
1131 stored
= (struct lp_jit_viewport
*)
1132 lp_scene_alloc(scene
, sizeof setup
->viewports
);
1139 memcpy(stored
, setup
->viewports
, sizeof setup
->viewports
);
1141 setup
->fs
.current
.jit_context
.viewports
= stored
;
1142 setup
->dirty
|= LP_SETUP_NEW_FS
;
1145 if(setup
->dirty
& LP_SETUP_NEW_BLEND_COLOR
) {
1151 /* Alloc u8_blend_color (16 x i8) and f_blend_color (4 or 8 x f32) */
1152 size
= 4 * 16 * sizeof(uint8_t);
1153 size
+= (LP_MAX_VECTOR_LENGTH
/ 4) * sizeof(float);
1154 stored
= lp_scene_alloc_aligned(scene
, size
, LP_MIN_VECTOR_ALIGN
);
1161 /* Store floating point colour */
1162 fstored
= (float*)(stored
+ 4*16);
1163 for (i
= 0; i
< (LP_MAX_VECTOR_LENGTH
/ 4); ++i
) {
1164 fstored
[i
] = setup
->blend_color
.current
.color
[i
% 4];
1167 /* smear each blend color component across 16 ubyte elements */
1168 for (i
= 0; i
< 4; ++i
) {
1169 uint8_t c
= float_to_ubyte(setup
->blend_color
.current
.color
[i
]);
1170 for (j
= 0; j
< 16; ++j
)
1171 stored
[i
*16 + j
] = c
;
1174 setup
->blend_color
.stored
= stored
;
1175 setup
->fs
.current
.jit_context
.u8_blend_color
= stored
;
1176 setup
->fs
.current
.jit_context
.f_blend_color
= fstored
;
1177 setup
->dirty
|= LP_SETUP_NEW_FS
;
1180 if (setup
->dirty
& LP_SETUP_NEW_CONSTANTS
) {
1181 for (i
= 0; i
< ARRAY_SIZE(setup
->constants
); ++i
) {
1182 struct pipe_resource
*buffer
= setup
->constants
[i
].current
.buffer
;
1183 const unsigned current_size
= MIN2(setup
->constants
[i
].current
.buffer_size
,
1184 LP_MAX_TGSI_CONST_BUFFER_SIZE
);
1185 const ubyte
*current_data
= NULL
;
1188 STATIC_ASSERT(DATA_BLOCK_SIZE
>= LP_MAX_TGSI_CONST_BUFFER_SIZE
);
1191 /* resource buffer */
1192 current_data
= (ubyte
*) llvmpipe_resource_data(buffer
);
1194 else if (setup
->constants
[i
].current
.user_buffer
) {
1195 /* user-space buffer */
1196 current_data
= (ubyte
*) setup
->constants
[i
].current
.user_buffer
;
1200 current_data
+= setup
->constants
[i
].current
.buffer_offset
;
1202 /* TODO: copy only the actually used constants? */
1204 if (setup
->constants
[i
].stored_size
!= current_size
||
1205 !setup
->constants
[i
].stored_data
||
1206 memcmp(setup
->constants
[i
].stored_data
,
1208 current_size
) != 0) {
1211 stored
= lp_scene_alloc(scene
, current_size
);
1220 setup
->constants
[i
].stored_size
= current_size
;
1221 setup
->constants
[i
].stored_data
= stored
;
1223 setup
->fs
.current
.jit_context
.constants
[i
] =
1224 setup
->constants
[i
].stored_data
;
1227 setup
->constants
[i
].stored_size
= 0;
1228 setup
->constants
[i
].stored_data
= NULL
;
1229 setup
->fs
.current
.jit_context
.constants
[i
] = fake_const_buf
;
1233 DIV_ROUND_UP(setup
->constants
[i
].stored_size
, (sizeof(float) * 4));
1234 setup
->fs
.current
.jit_context
.num_constants
[i
] = num_constants
;
1235 setup
->dirty
|= LP_SETUP_NEW_FS
;
1239 if (setup
->dirty
& LP_SETUP_NEW_SSBOS
) {
1240 for (i
= 0; i
< ARRAY_SIZE(setup
->ssbos
); ++i
) {
1241 struct pipe_resource
*buffer
= setup
->ssbos
[i
].current
.buffer
;
1242 const ubyte
*current_data
= NULL
;
1246 /* resource buffer */
1247 current_data
= (ubyte
*) llvmpipe_resource_data(buffer
);
1249 current_data
+= setup
->ssbos
[i
].current
.buffer_offset
;
1251 setup
->fs
.current
.jit_context
.ssbos
[i
] = (const uint32_t *)current_data
;
1252 setup
->fs
.current
.jit_context
.num_ssbos
[i
] = setup
->ssbos
[i
].current
.buffer_size
;
1254 setup
->fs
.current
.jit_context
.ssbos
[i
] = NULL
;
1255 setup
->fs
.current
.jit_context
.num_ssbos
[i
] = 0;
1257 setup
->dirty
|= LP_SETUP_NEW_FS
;
1260 if (setup
->dirty
& LP_SETUP_NEW_FS
) {
1261 if (!setup
->fs
.stored
||
1262 memcmp(setup
->fs
.stored
,
1264 sizeof setup
->fs
.current
) != 0)
1266 struct lp_rast_state
*stored
;
1268 /* The fs state that's been stored in the scene is different from
1269 * the new, current state. So allocate a new lp_rast_state object
1270 * and append it to the bin's setup data buffer.
1272 stored
= (struct lp_rast_state
*) lp_scene_alloc(scene
, sizeof *stored
);
1280 sizeof setup
->fs
.current
);
1281 setup
->fs
.stored
= stored
;
1283 /* The scene now references the textures in the rasterization
1284 * state record. Note that now.
1286 for (i
= 0; i
< ARRAY_SIZE(setup
->fs
.current_tex
); i
++) {
1287 if (setup
->fs
.current_tex
[i
]) {
1288 if (!lp_scene_add_resource_reference(scene
,
1289 setup
->fs
.current_tex
[i
],
1299 if (setup
->dirty
& LP_SETUP_NEW_SCISSOR
) {
1301 for (i
= 0; i
< PIPE_MAX_VIEWPORTS
; ++i
) {
1302 setup
->draw_regions
[i
] = setup
->framebuffer
;
1303 if (setup
->scissor_test
) {
1304 u_rect_possible_intersection(&setup
->scissors
[i
],
1305 &setup
->draw_regions
[i
]);
1312 assert(setup
->fs
.stored
);
1317 lp_setup_update_state( struct lp_setup_context
*setup
,
1318 boolean update_scene
)
1320 /* Some of the 'draw' pipeline stages may have changed some driver state.
1321 * Make sure we've processed those state changes before anything else.
1323 * XXX this is the only place where llvmpipe_context is used in the
1324 * setup code. This may get refactored/changed...
1327 struct llvmpipe_context
*lp
= llvmpipe_context(setup
->pipe
);
1329 llvmpipe_update_derived(lp
);
1332 if (lp
->setup
->dirty
) {
1333 llvmpipe_update_setup(lp
);
1336 assert(setup
->setup
.variant
);
1338 /* Will probably need to move this somewhere else, just need
1339 * to know about vertex shader point size attribute.
1341 setup
->psize_slot
= lp
->psize_slot
;
1342 setup
->viewport_index_slot
= lp
->viewport_index_slot
;
1343 setup
->layer_slot
= lp
->layer_slot
;
1344 setup
->face_slot
= lp
->face_slot
;
1346 assert(lp
->dirty
== 0);
1348 assert(lp
->setup_variant
.key
.size
==
1349 setup
->setup
.variant
->key
.size
);
1351 assert(memcmp(&lp
->setup_variant
.key
,
1352 &setup
->setup
.variant
->key
,
1353 setup
->setup
.variant
->key
.size
) == 0);
1356 if (update_scene
&& setup
->state
!= SETUP_ACTIVE
) {
1357 if (!set_scene_state( setup
, SETUP_ACTIVE
, __FUNCTION__
))
1361 /* Only call into update_scene_state() if we already have a
1364 if (update_scene
&& setup
->scene
) {
1365 assert(setup
->state
== SETUP_ACTIVE
);
1367 if (try_update_scene_state(setup
))
1370 /* Update failed, try to restart the scene.
1372 * Cannot call lp_setup_flush_and_restart() directly here
1373 * because of potential recursion.
1375 if (!set_scene_state(setup
, SETUP_FLUSHED
, __FUNCTION__
))
1378 if (!set_scene_state(setup
, SETUP_ACTIVE
, __FUNCTION__
))
1384 return try_update_scene_state(setup
);
1392 /* Only caller is lp_setup_vbuf_destroy()
1395 lp_setup_destroy( struct lp_setup_context
*setup
)
1399 lp_setup_reset( setup
);
1401 util_unreference_framebuffer_state(&setup
->fb
);
1403 for (i
= 0; i
< ARRAY_SIZE(setup
->fs
.current_tex
); i
++) {
1404 pipe_resource_reference(&setup
->fs
.current_tex
[i
], NULL
);
1407 for (i
= 0; i
< ARRAY_SIZE(setup
->constants
); i
++) {
1408 pipe_resource_reference(&setup
->constants
[i
].current
.buffer
, NULL
);
1411 for (i
= 0; i
< ARRAY_SIZE(setup
->ssbos
); i
++) {
1412 pipe_resource_reference(&setup
->ssbos
[i
].current
.buffer
, NULL
);
1415 /* free the scenes in the 'empty' queue */
1416 for (i
= 0; i
< ARRAY_SIZE(setup
->scenes
); i
++) {
1417 struct lp_scene
*scene
= setup
->scenes
[i
];
1420 lp_fence_wait(scene
->fence
);
1422 lp_scene_destroy(scene
);
1425 lp_fence_reference(&setup
->last_fence
, NULL
);
1432 * Create a new primitive tiling engine. Plug it into the backend of
1433 * the draw module. Currently also creates a rasterizer to use with
1436 struct lp_setup_context
*
1437 lp_setup_create( struct pipe_context
*pipe
,
1438 struct draw_context
*draw
)
1440 struct llvmpipe_screen
*screen
= llvmpipe_screen(pipe
->screen
);
1441 struct lp_setup_context
*setup
;
1444 setup
= CALLOC_STRUCT(lp_setup_context
);
1449 lp_setup_init_vbuf(setup
);
1451 /* Used only in update_state():
1456 setup
->num_threads
= screen
->num_threads
;
1457 setup
->vbuf
= draw_vbuf_stage(draw
, &setup
->base
);
1462 draw_set_rasterize_stage(draw
, setup
->vbuf
);
1463 draw_set_render(draw
, &setup
->base
);
1465 /* create some empty scenes */
1466 for (i
= 0; i
< MAX_SCENES
; i
++) {
1467 setup
->scenes
[i
] = lp_scene_create( pipe
);
1468 if (!setup
->scenes
[i
]) {
1473 setup
->triangle
= first_triangle
;
1474 setup
->line
= first_line
;
1475 setup
->point
= first_point
;
1479 /* Initialize empty default fb correctly, so the rect is empty */
1480 setup
->framebuffer
.x1
= -1;
1481 setup
->framebuffer
.y1
= -1;
1486 for (i
= 0; i
< MAX_SCENES
; i
++) {
1487 if (setup
->scenes
[i
]) {
1488 lp_scene_destroy(setup
->scenes
[i
]);
1492 setup
->vbuf
->destroy(setup
->vbuf
);
1501 * Put a BeginQuery command into all bins.
1504 lp_setup_begin_query(struct lp_setup_context
*setup
,
1505 struct llvmpipe_query
*pq
)
1508 set_scene_state(setup
, SETUP_ACTIVE
, "begin_query");
1510 if (!(pq
->type
== PIPE_QUERY_OCCLUSION_COUNTER
||
1511 pq
->type
== PIPE_QUERY_OCCLUSION_PREDICATE
||
1512 pq
->type
== PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
||
1513 pq
->type
== PIPE_QUERY_PIPELINE_STATISTICS
))
1516 /* init the query to its beginning state */
1517 assert(setup
->active_binned_queries
< LP_MAX_ACTIVE_BINNED_QUERIES
);
1518 /* exceeding list size so just ignore the query */
1519 if (setup
->active_binned_queries
>= LP_MAX_ACTIVE_BINNED_QUERIES
) {
1522 assert(setup
->active_queries
[setup
->active_binned_queries
] == NULL
);
1523 setup
->active_queries
[setup
->active_binned_queries
] = pq
;
1524 setup
->active_binned_queries
++;
1526 assert(setup
->scene
);
1528 if (!lp_scene_bin_everywhere(setup
->scene
,
1529 LP_RAST_OP_BEGIN_QUERY
,
1530 lp_rast_arg_query(pq
))) {
1532 if (!lp_setup_flush_and_restart(setup
))
1535 if (!lp_scene_bin_everywhere(setup
->scene
,
1536 LP_RAST_OP_BEGIN_QUERY
,
1537 lp_rast_arg_query(pq
))) {
1541 setup
->scene
->had_queries
|= TRUE
;
1547 * Put an EndQuery command into all bins.
1550 lp_setup_end_query(struct lp_setup_context
*setup
, struct llvmpipe_query
*pq
)
1552 set_scene_state(setup
, SETUP_ACTIVE
, "end_query");
1554 assert(setup
->scene
);
1556 /* pq->fence should be the fence of the *last* scene which
1557 * contributed to the query result.
1559 lp_fence_reference(&pq
->fence
, setup
->scene
->fence
);
1561 if (pq
->type
== PIPE_QUERY_OCCLUSION_COUNTER
||
1562 pq
->type
== PIPE_QUERY_OCCLUSION_PREDICATE
||
1563 pq
->type
== PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
||
1564 pq
->type
== PIPE_QUERY_PIPELINE_STATISTICS
||
1565 pq
->type
== PIPE_QUERY_TIMESTAMP
) {
1566 if (pq
->type
== PIPE_QUERY_TIMESTAMP
&&
1567 !(setup
->scene
->tiles_x
| setup
->scene
->tiles_y
)) {
1569 * If there's a zero width/height framebuffer, there's no bins and
1570 * hence no rast task is ever run. So fill in something here instead.
1572 pq
->end
[0] = os_time_get_nano();
1575 if (!lp_scene_bin_everywhere(setup
->scene
,
1576 LP_RAST_OP_END_QUERY
,
1577 lp_rast_arg_query(pq
))) {
1578 if (!lp_setup_flush_and_restart(setup
))
1581 if (!lp_scene_bin_everywhere(setup
->scene
,
1582 LP_RAST_OP_END_QUERY
,
1583 lp_rast_arg_query(pq
))) {
1587 setup
->scene
->had_queries
|= TRUE
;
1591 lp_fence_reference(&pq
->fence
, setup
->last_fence
);
1595 /* Need to do this now not earlier since it still needs to be marked as
1596 * active when binning it would cause a flush.
1598 if (pq
->type
== PIPE_QUERY_OCCLUSION_COUNTER
||
1599 pq
->type
== PIPE_QUERY_OCCLUSION_PREDICATE
||
1600 pq
->type
== PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
||
1601 pq
->type
== PIPE_QUERY_PIPELINE_STATISTICS
) {
1604 /* remove from active binned query list */
1605 for (i
= 0; i
< setup
->active_binned_queries
; i
++) {
1606 if (setup
->active_queries
[i
] == pq
)
1609 assert(i
< setup
->active_binned_queries
);
1610 if (i
== setup
->active_binned_queries
)
1612 setup
->active_binned_queries
--;
1613 setup
->active_queries
[i
] = setup
->active_queries
[setup
->active_binned_queries
];
1614 setup
->active_queries
[setup
->active_binned_queries
] = NULL
;
1620 lp_setup_flush_and_restart(struct lp_setup_context
*setup
)
1622 if (0) debug_printf("%s\n", __FUNCTION__
);
1624 assert(setup
->state
== SETUP_ACTIVE
);
1626 if (!set_scene_state(setup
, SETUP_FLUSHED
, __FUNCTION__
))
1629 if (!lp_setup_update_state(setup
, TRUE
))