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 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "pipe/p_context.h"
35 #include "util/u_memory.h"
36 #include "util/u_math.h"
37 #include "util/u_cpu_detect.h"
38 #include "util/u_inlines.h"
39 #include "util/u_helpers.h"
40 #include "util/u_prim.h"
41 #include "draw_context.h"
42 #include "draw_pipe.h"
47 #include "gallivm/lp_bld_init.h"
48 #include "gallivm/lp_bld_limits.h"
49 #include "draw_llvm.h"
52 draw_get_option_use_llvm(void)
54 static boolean first
= TRUE
;
58 value
= debug_get_bool_option("DRAW_USE_LLVM", TRUE
);
62 /* require SSE2 due to LLVM PR6960. XXX Might be fixed by now? */
63 if (!util_cpu_caps
.has_sse2
)
73 * Create new draw module context with gallivm state for LLVM JIT.
75 static struct draw_context
*
76 draw_create_context(struct pipe_context
*pipe
, boolean try_llvm
)
78 struct draw_context
*draw
= CALLOC_STRUCT( draw_context
);
82 /* we need correct cpu caps for disabling denorms in draw_vbo() */
86 if (try_llvm
&& draw_get_option_use_llvm()) {
87 draw
->llvm
= draw_llvm_create(draw
);
101 draw_destroy( draw
);
108 * Create new draw module context, with LLVM JIT.
110 struct draw_context
*
111 draw_create(struct pipe_context
*pipe
)
113 return draw_create_context(pipe
, TRUE
);
118 * Create a new draw context, without LLVM JIT.
120 struct draw_context
*
121 draw_create_no_llvm(struct pipe_context
*pipe
)
123 return draw_create_context(pipe
, FALSE
);
127 boolean
draw_init(struct draw_context
*draw
)
130 * Note that several functions compute the clipmask of the predefined
131 * formats with hardcoded formulas instead of using these. So modifications
132 * here must be reflected there too.
135 ASSIGN_4V( draw
->plane
[0], -1, 0, 0, 1 );
136 ASSIGN_4V( draw
->plane
[1], 1, 0, 0, 1 );
137 ASSIGN_4V( draw
->plane
[2], 0, -1, 0, 1 );
138 ASSIGN_4V( draw
->plane
[3], 0, 1, 0, 1 );
139 ASSIGN_4V( draw
->plane
[4], 0, 0, 1, 1 ); /* yes these are correct */
140 ASSIGN_4V( draw
->plane
[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
141 draw
->clip_xy
= TRUE
;
144 draw
->pt
.user
.planes
= (float (*) [DRAW_TOTAL_CLIP_PLANES
][4]) &(draw
->plane
[0]);
145 draw
->pt
.user
.eltMax
= ~0;
147 if (!draw_pipeline_init( draw
))
150 if (!draw_pt_init( draw
))
153 if (!draw_vs_init( draw
))
156 if (!draw_gs_init( draw
))
159 draw
->quads_always_flatshade_last
= !draw
->pipe
->screen
->get_param(
160 draw
->pipe
->screen
, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
);
166 * Called whenever we're starting to draw a new instance.
167 * Some internal structures don't want to have to reset internal
168 * members on each invocation (because their state might have to persist
169 * between multiple primitive restart rendering call) but might have to
170 * for each new instance.
171 * This is particularly the case for primitive id's in geometry shader.
173 void draw_new_instance(struct draw_context
*draw
)
175 draw_geometry_shader_new_instance(draw
->gs
.geometry_shader
);
179 void draw_destroy( struct draw_context
*draw
)
181 struct pipe_context
*pipe
;
189 /* free any rasterizer CSOs that we may have created.
191 for (i
= 0; i
< 2; i
++) {
192 for (j
= 0; j
< 2; j
++) {
193 if (draw
->rasterizer_no_cull
[i
][j
]) {
194 pipe
->delete_rasterizer_state(pipe
, draw
->rasterizer_no_cull
[i
][j
]);
199 for (i
= 0; i
< draw
->pt
.nr_vertex_buffers
; i
++) {
200 pipe_resource_reference(&draw
->pt
.vertex_buffer
[i
].buffer
, NULL
);
203 /* Not so fast -- we're just borrowing this at the moment.
206 draw->render->destroy( draw->render );
209 draw_pipeline_destroy( draw
);
210 draw_pt_destroy( draw
);
211 draw_vs_destroy( draw
);
212 draw_gs_destroy( draw
);
215 draw_llvm_destroy( draw
->llvm
);
223 void draw_flush( struct draw_context
*draw
)
225 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
230 * Specify the Minimum Resolvable Depth factor for polygon offset.
231 * This factor potentially depends on the number of Z buffer bits,
232 * the rasterization algorithm and the arithmetic performed on Z
233 * values between vertex shading and rasterization. It will vary
234 * from one driver to another.
236 void draw_set_mrd(struct draw_context
*draw
, double mrd
)
242 static void update_clip_flags( struct draw_context
*draw
)
244 draw
->clip_xy
= !draw
->driver
.bypass_clip_xy
;
245 draw
->guard_band_xy
= (!draw
->driver
.bypass_clip_xy
&&
246 draw
->driver
.guard_band_xy
);
247 draw
->clip_z
= (!draw
->driver
.bypass_clip_z
&&
248 draw
->rasterizer
&& draw
->rasterizer
->depth_clip
);
249 draw
->clip_user
= draw
->rasterizer
&&
250 draw
->rasterizer
->clip_plane_enable
!= 0;
254 * Register new primitive rasterization/rendering state.
255 * This causes the drawing pipeline to be rebuilt.
257 void draw_set_rasterizer_state( struct draw_context
*draw
,
258 const struct pipe_rasterizer_state
*raster
,
261 if (!draw
->suspend_flushing
) {
262 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
264 draw
->rasterizer
= raster
;
265 draw
->rast_handle
= rast_handle
;
266 update_clip_flags(draw
);
270 /* With a little more work, llvmpipe will be able to turn this off and
271 * do its own x/y clipping.
273 * Some hardware can turn off clipping altogether - in particular any
274 * hardware with a TNL unit can do its own clipping, even if it is
275 * relying on the draw module for some other reason.
277 void draw_set_driver_clipping( struct draw_context
*draw
,
278 boolean bypass_clip_xy
,
279 boolean bypass_clip_z
,
280 boolean guard_band_xy
)
282 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
284 draw
->driver
.bypass_clip_xy
= bypass_clip_xy
;
285 draw
->driver
.bypass_clip_z
= bypass_clip_z
;
286 draw
->driver
.guard_band_xy
= guard_band_xy
;
287 update_clip_flags(draw
);
292 * Plug in the primitive rendering/rasterization stage (which is the last
293 * stage in the drawing pipeline).
294 * This is provided by the device driver.
296 void draw_set_rasterize_stage( struct draw_context
*draw
,
297 struct draw_stage
*stage
)
299 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
301 draw
->pipeline
.rasterize
= stage
;
306 * Set the draw module's clipping state.
308 void draw_set_clip_state( struct draw_context
*draw
,
309 const struct pipe_clip_state
*clip
)
311 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
313 memcpy(&draw
->plane
[6], clip
->ucp
, sizeof(clip
->ucp
));
318 * Set the draw module's viewport state.
320 void draw_set_viewport_states( struct draw_context
*draw
,
322 unsigned num_viewports
,
323 const struct pipe_viewport_state
*vps
)
325 const struct pipe_viewport_state
*viewport
= vps
;
326 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
328 debug_assert(start_slot
< PIPE_MAX_VIEWPORTS
);
329 debug_assert((start_slot
+ num_viewports
) <= PIPE_MAX_VIEWPORTS
);
331 memcpy(draw
->viewports
+ start_slot
, vps
,
332 sizeof(struct pipe_viewport_state
) * num_viewports
);
334 draw
->identity_viewport
= (num_viewports
== 1) &&
335 (viewport
->scale
[0] == 1.0f
&&
336 viewport
->scale
[1] == 1.0f
&&
337 viewport
->scale
[2] == 1.0f
&&
338 viewport
->scale
[3] == 1.0f
&&
339 viewport
->translate
[0] == 0.0f
&&
340 viewport
->translate
[1] == 0.0f
&&
341 viewport
->translate
[2] == 0.0f
&&
342 viewport
->translate
[3] == 0.0f
);
348 draw_set_vertex_buffers(struct draw_context
*draw
,
349 unsigned start_slot
, unsigned count
,
350 const struct pipe_vertex_buffer
*buffers
)
352 assert(start_slot
+ count
<= PIPE_MAX_ATTRIBS
);
354 util_set_vertex_buffers_count(draw
->pt
.vertex_buffer
,
355 &draw
->pt
.nr_vertex_buffers
,
356 buffers
, start_slot
, count
);
361 draw_set_vertex_elements(struct draw_context
*draw
,
363 const struct pipe_vertex_element
*elements
)
365 assert(count
<= PIPE_MAX_ATTRIBS
);
367 /* We could improve this by only flushing the frontend and the fetch part
368 * of the middle. This would avoid recalculating the emit keys.*/
369 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
371 memcpy(draw
->pt
.vertex_element
, elements
, count
* sizeof(elements
[0]));
372 draw
->pt
.nr_vertex_elements
= count
;
377 * Tell drawing context where to find mapped vertex buffers.
380 draw_set_mapped_vertex_buffer(struct draw_context
*draw
,
381 unsigned attr
, const void *buffer
,
384 draw
->pt
.user
.vbuffer
[attr
].map
= buffer
;
385 draw
->pt
.user
.vbuffer
[attr
].size
= size
;
390 draw_set_mapped_constant_buffer(struct draw_context
*draw
,
391 unsigned shader_type
,
396 debug_assert(shader_type
== PIPE_SHADER_VERTEX
||
397 shader_type
== PIPE_SHADER_GEOMETRY
);
398 debug_assert(slot
< PIPE_MAX_CONSTANT_BUFFERS
);
400 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
402 switch (shader_type
) {
403 case PIPE_SHADER_VERTEX
:
404 draw
->pt
.user
.vs_constants
[slot
] = buffer
;
405 draw
->pt
.user
.vs_constants_size
[slot
] = size
;
407 case PIPE_SHADER_GEOMETRY
:
408 draw
->pt
.user
.gs_constants
[slot
] = buffer
;
409 draw
->pt
.user
.gs_constants_size
[slot
] = size
;
412 assert(0 && "invalid shader type in draw_set_mapped_constant_buffer");
418 * Tells the draw module to draw points with triangles if their size
419 * is greater than this threshold.
422 draw_wide_point_threshold(struct draw_context
*draw
, float threshold
)
424 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
425 draw
->pipeline
.wide_point_threshold
= threshold
;
430 * Should the draw module handle point->quad conversion for drawing sprites?
433 draw_wide_point_sprites(struct draw_context
*draw
, boolean draw_sprite
)
435 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
436 draw
->pipeline
.wide_point_sprites
= draw_sprite
;
441 * Tells the draw module to draw lines with triangles if their width
442 * is greater than this threshold.
445 draw_wide_line_threshold(struct draw_context
*draw
, float threshold
)
447 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
448 draw
->pipeline
.wide_line_threshold
= roundf(threshold
);
453 * Tells the draw module whether or not to implement line stipple.
456 draw_enable_line_stipple(struct draw_context
*draw
, boolean enable
)
458 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
459 draw
->pipeline
.line_stipple
= enable
;
464 * Tells draw module whether to convert points to quads for sprite mode.
467 draw_enable_point_sprites(struct draw_context
*draw
, boolean enable
)
469 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
470 draw
->pipeline
.point_sprite
= enable
;
475 draw_set_force_passthrough( struct draw_context
*draw
, boolean enable
)
477 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
478 draw
->force_passthrough
= enable
;
484 * Allocate an extra vertex/geometry shader vertex attribute, if it doesn't
487 * This is used by some of the optional draw module stages such
488 * as wide_point which may need to allocate additional generic/texcoord
492 draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
493 uint semantic_name
, uint semantic_index
)
499 slot
= draw_find_shader_output(draw
, semantic_name
, semantic_index
);
504 num_outputs
= draw_current_shader_outputs(draw
);
505 n
= draw
->extra_shader_outputs
.num
;
507 assert(n
< Elements(draw
->extra_shader_outputs
.semantic_name
));
509 draw
->extra_shader_outputs
.semantic_name
[n
] = semantic_name
;
510 draw
->extra_shader_outputs
.semantic_index
[n
] = semantic_index
;
511 draw
->extra_shader_outputs
.slot
[n
] = num_outputs
+ n
;
512 draw
->extra_shader_outputs
.num
++;
514 return draw
->extra_shader_outputs
.slot
[n
];
519 * Remove all extra vertex attributes that were allocated with
520 * draw_alloc_extra_vertex_attrib().
523 draw_remove_extra_vertex_attribs(struct draw_context
*draw
)
525 draw
->extra_shader_outputs
.num
= 0;
530 * If a geometry shader is present, return its info, else the vertex shader's
533 struct tgsi_shader_info
*
534 draw_get_shader_info(const struct draw_context
*draw
)
537 if (draw
->gs
.geometry_shader
) {
538 return &draw
->gs
.geometry_shader
->info
;
540 return &draw
->vs
.vertex_shader
->info
;
545 * Prepare outputs slots from the draw module
547 * Certain parts of the draw module can emit additional
548 * outputs that can be quite useful to the backends, a good
549 * example of it is the process of decomposing primitives
550 * into wireframes (aka. lines) which normally would lose
551 * the face-side information, but using this method we can
552 * inject another shader output which passes the original
553 * face side information to the backend.
556 draw_prepare_shader_outputs(struct draw_context
*draw
)
558 draw_ia_prepare_outputs(draw
, draw
->pipeline
.ia
);
559 draw_unfilled_prepare_outputs(draw
, draw
->pipeline
.unfilled
);
563 * Ask the draw module for the location/slot of the given vertex attribute in
564 * a post-transformed vertex.
566 * With this function, drivers that use the draw module should have no reason
567 * to track the current vertex/geometry shader.
569 * Note that the draw module may sometimes generate vertices with extra
570 * attributes (such as texcoords for AA lines). The driver can call this
571 * function to find those attributes.
573 * -1 is returned if the attribute is not found since this is
574 * an undefined situation. Note, that zero is valid and can
575 * be used by any of the attributes, because position is not
576 * required to be attribute 0 or even at all present.
579 draw_find_shader_output(const struct draw_context
*draw
,
580 uint semantic_name
, uint semantic_index
)
582 const struct tgsi_shader_info
*info
= draw_get_shader_info(draw
);
585 for (i
= 0; i
< info
->num_outputs
; i
++) {
586 if (info
->output_semantic_name
[i
] == semantic_name
&&
587 info
->output_semantic_index
[i
] == semantic_index
)
591 /* Search the extra vertex attributes */
592 for (i
= 0; i
< draw
->extra_shader_outputs
.num
; i
++) {
593 if (draw
->extra_shader_outputs
.semantic_name
[i
] == semantic_name
&&
594 draw
->extra_shader_outputs
.semantic_index
[i
] == semantic_index
) {
595 return draw
->extra_shader_outputs
.slot
[i
];
604 * Return total number of the shader outputs. This function is similar to
605 * draw_current_shader_outputs() but this function also counts any extra
606 * vertex/geometry output attributes that may be filled in by some draw
607 * stages (such as AA point, AA line).
609 * If geometry shader is present, its output will be returned,
610 * if not vertex shader is used.
613 draw_num_shader_outputs(const struct draw_context
*draw
)
615 const struct tgsi_shader_info
*info
= draw_get_shader_info(draw
);
618 count
= info
->num_outputs
;
619 count
+= draw
->extra_shader_outputs
.num
;
626 * Return total number of the vertex shader outputs. This function
627 * also counts any extra vertex output attributes that may
628 * be filled in by some draw stages (such as AA point, AA line,
632 draw_total_vs_outputs(const struct draw_context
*draw
)
634 const struct tgsi_shader_info
*info
= &draw
->vs
.vertex_shader
->info
;
636 return info
->num_outputs
+ draw
->extra_shader_outputs
.num
;;
640 * Return total number of the geometry shader outputs. This function
641 * also counts any extra geometry output attributes that may
642 * be filled in by some draw stages (such as AA point, AA line, front
646 draw_total_gs_outputs(const struct draw_context
*draw
)
648 const struct tgsi_shader_info
*info
;
650 if (!draw
->gs
.geometry_shader
)
653 info
= &draw
->gs
.geometry_shader
->info
;
655 return info
->num_outputs
+ draw
->extra_shader_outputs
.num
;
660 * Provide TGSI sampler objects for vertex/geometry shaders that use
661 * texture fetches. This state only needs to be set once per context.
662 * This might only be used by software drivers for the time being.
665 draw_texture_sampler(struct draw_context
*draw
,
667 struct tgsi_sampler
*sampler
)
669 if (shader
== PIPE_SHADER_VERTEX
) {
670 draw
->vs
.tgsi
.sampler
= sampler
;
672 debug_assert(shader
== PIPE_SHADER_GEOMETRY
);
673 draw
->gs
.tgsi
.sampler
= sampler
;
680 void draw_set_render( struct draw_context
*draw
,
681 struct vbuf_render
*render
)
683 draw
->render
= render
;
688 * Tell the draw module where vertex indexes/elements are located, and
689 * their size (in bytes).
691 * Note: the caller must apply the pipe_index_buffer::offset value to
692 * the address. The draw module doesn't do that.
695 draw_set_indexes(struct draw_context
*draw
,
696 const void *elements
, unsigned elem_size
,
697 unsigned elem_buffer_space
)
699 assert(elem_size
== 0 ||
703 draw
->pt
.user
.elts
= elements
;
704 draw
->pt
.user
.eltSizeIB
= elem_size
;
706 draw
->pt
.user
.eltMax
= elem_buffer_space
/ elem_size
;
708 draw
->pt
.user
.eltMax
= 0;
714 void draw_do_flush( struct draw_context
*draw
, unsigned flags
)
716 if (!draw
->suspend_flushing
)
718 assert(!draw
->flushing
); /* catch inadvertant recursion */
720 draw
->flushing
= TRUE
;
722 draw_pipeline_flush( draw
, flags
);
724 draw_pt_flush( draw
, flags
);
726 draw
->flushing
= FALSE
;
732 * Return the number of output attributes produced by the geometry
733 * shader, if present. If no geometry shader, return the number of
734 * outputs from the vertex shader.
735 * \sa draw_num_shader_outputs
738 draw_current_shader_outputs(const struct draw_context
*draw
)
740 if (draw
->gs
.geometry_shader
)
741 return draw
->gs
.num_gs_outputs
;
742 return draw
->vs
.num_vs_outputs
;
747 * Return the index of the shader output which will contain the
751 draw_current_shader_position_output(const struct draw_context
*draw
)
753 if (draw
->gs
.geometry_shader
)
754 return draw
->gs
.position_output
;
755 return draw
->vs
.position_output
;
760 * Return the index of the shader output which will contain the
764 draw_current_shader_viewport_index_output(const struct draw_context
*draw
)
766 if (draw
->gs
.geometry_shader
)
767 return draw
->gs
.geometry_shader
->viewport_index_output
;
772 * Returns true if there's a geometry shader bound and the geometry
773 * shader writes out a viewport index.
776 draw_current_shader_uses_viewport_index(const struct draw_context
*draw
)
778 if (draw
->gs
.geometry_shader
)
779 return draw
->gs
.geometry_shader
->info
.writes_viewport_index
;
785 * Return the index of the shader output which will contain the
789 draw_current_shader_clipvertex_output(const struct draw_context
*draw
)
791 return draw
->vs
.clipvertex_output
;
795 draw_current_shader_clipdistance_output(const struct draw_context
*draw
, int index
)
797 debug_assert(index
< PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
);
798 if (draw
->gs
.geometry_shader
)
799 return draw
->gs
.geometry_shader
->clipdistance_output
[index
];
800 return draw
->vs
.clipdistance_output
[index
];
805 draw_current_shader_num_written_clipdistances(const struct draw_context
*draw
)
807 if (draw
->gs
.geometry_shader
)
808 return draw
->gs
.geometry_shader
->info
.num_written_clipdistance
;
809 return draw
->vs
.vertex_shader
->info
.num_written_clipdistance
;
814 draw_current_shader_culldistance_output(const struct draw_context
*draw
, int index
)
816 debug_assert(index
< PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
);
817 if (draw
->gs
.geometry_shader
)
818 return draw
->gs
.geometry_shader
->culldistance_output
[index
];
819 return draw
->vs
.vertex_shader
->culldistance_output
[index
];
823 draw_current_shader_num_written_culldistances(const struct draw_context
*draw
)
825 if (draw
->gs
.geometry_shader
)
826 return draw
->gs
.geometry_shader
->info
.num_written_culldistance
;
827 return draw
->vs
.vertex_shader
->info
.num_written_culldistance
;
831 * Return a pointer/handle for a driver/CSO rasterizer object which
832 * disabled culling, stippling, unfilled tris, etc.
833 * This is used by some pipeline stages (such as wide_point, aa_line
834 * and aa_point) which convert points/lines into triangles. In those
835 * cases we don't want to accidentally cull the triangles.
837 * \param scissor should the rasterizer state enable scissoring?
838 * \param flatshade should the rasterizer state use flat shading?
839 * \return rasterizer CSO handle
842 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
846 if (!draw
->rasterizer_no_cull
[scissor
][flatshade
]) {
848 struct pipe_context
*pipe
= draw
->pipe
;
849 struct pipe_rasterizer_state rast
;
851 memset(&rast
, 0, sizeof(rast
));
852 rast
.scissor
= scissor
;
853 rast
.flatshade
= flatshade
;
855 rast
.half_pixel_center
= draw
->rasterizer
->half_pixel_center
;
856 rast
.bottom_edge_rule
= draw
->rasterizer
->bottom_edge_rule
;
857 rast
.clip_halfz
= draw
->rasterizer
->clip_halfz
;
859 draw
->rasterizer_no_cull
[scissor
][flatshade
] =
860 pipe
->create_rasterizer_state(pipe
, &rast
);
862 return draw
->rasterizer_no_cull
[scissor
][flatshade
];
866 draw_set_mapped_so_targets(struct draw_context
*draw
,
868 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
])
872 for (i
= 0; i
< num_targets
; i
++)
873 draw
->so
.targets
[i
] = targets
[i
];
874 for (i
= num_targets
; i
< PIPE_MAX_SO_BUFFERS
; i
++)
875 draw
->so
.targets
[i
] = NULL
;
877 draw
->so
.num_targets
= num_targets
;
881 draw_set_sampler_views(struct draw_context
*draw
,
882 unsigned shader_stage
,
883 struct pipe_sampler_view
**views
,
888 debug_assert(shader_stage
< PIPE_SHADER_TYPES
);
889 debug_assert(num
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
891 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
893 for (i
= 0; i
< num
; ++i
)
894 draw
->sampler_views
[shader_stage
][i
] = views
[i
];
895 for (i
= num
; i
< PIPE_MAX_SHADER_SAMPLER_VIEWS
; ++i
)
896 draw
->sampler_views
[shader_stage
][i
] = NULL
;
898 draw
->num_sampler_views
[shader_stage
] = num
;
902 draw_set_samplers(struct draw_context
*draw
,
903 unsigned shader_stage
,
904 struct pipe_sampler_state
**samplers
,
909 debug_assert(shader_stage
< PIPE_SHADER_TYPES
);
910 debug_assert(num
<= PIPE_MAX_SAMPLERS
);
912 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
914 for (i
= 0; i
< num
; ++i
)
915 draw
->samplers
[shader_stage
][i
] = samplers
[i
];
916 for (i
= num
; i
< PIPE_MAX_SAMPLERS
; ++i
)
917 draw
->samplers
[shader_stage
][i
] = NULL
;
919 draw
->num_samplers
[shader_stage
] = num
;
923 draw_llvm_set_sampler_state(draw
, shader_stage
);
928 draw_set_mapped_texture(struct draw_context
*draw
,
929 unsigned shader_stage
,
931 uint32_t width
, uint32_t height
, uint32_t depth
,
932 uint32_t first_level
, uint32_t last_level
,
933 const void *base_ptr
,
934 uint32_t row_stride
[PIPE_MAX_TEXTURE_LEVELS
],
935 uint32_t img_stride
[PIPE_MAX_TEXTURE_LEVELS
],
936 uint32_t mip_offsets
[PIPE_MAX_TEXTURE_LEVELS
])
940 draw_llvm_set_mapped_texture(draw
,
943 width
, height
, depth
, first_level
,
944 last_level
, base_ptr
,
945 row_stride
, img_stride
, mip_offsets
);
950 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
951 * different ways of setting textures, and drivers typically only support one.
954 draw_get_shader_param_no_llvm(unsigned shader
, enum pipe_shader_cap param
)
957 case PIPE_SHADER_VERTEX
:
958 case PIPE_SHADER_GEOMETRY
:
959 return tgsi_exec_get_shader_param(param
);
966 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
967 * different ways of setting textures, and drivers typically only support one.
970 draw_get_shader_param(unsigned shader
, enum pipe_shader_cap param
)
974 if (draw_get_option_use_llvm()) {
976 case PIPE_SHADER_VERTEX
:
977 case PIPE_SHADER_GEOMETRY
:
978 return gallivm_get_shader_param(param
);
985 return draw_get_shader_param_no_llvm(shader
, param
);
989 * Enables or disables collection of statistics.
991 * Draw module is capable of generating statistics for the vertex
992 * processing pipeline. Collection of that data isn't free and so
993 * it's disabled by default. The users of the module can enable
994 * (or disable) this functionality through this function.
995 * The actual data will be emitted through the VBUF interface,
996 * the 'pipeline_statistics' callback to be exact.
999 draw_collect_pipeline_statistics(struct draw_context
*draw
,
1002 draw
->collect_statistics
= enable
;
1006 * Computes clipper invocation statistics.
1008 * Figures out how many primitives would have been
1009 * sent to the clipper given the specified
1013 draw_stats_clipper_primitives(struct draw_context
*draw
,
1014 const struct draw_prim_info
*prim_info
)
1016 if (draw
->collect_statistics
) {
1019 i
< prim_info
->primitive_count
;
1020 start
+= prim_info
->primitive_lengths
[i
], i
++)
1022 draw
->statistics
.c_invocations
+=
1023 u_decomposed_prims_for_vertices(prim_info
->prim
,
1024 prim_info
->primitive_lengths
[i
]);
1031 * Returns true if the draw module will inject the frontface
1032 * info into the outputs.
1034 * Given the specified primitive and rasterizer state
1035 * the function will figure out if the draw module
1036 * will inject the front-face information into shader
1037 * outputs. This is done to preserve the front-facing
1038 * info when decomposing primitives into wireframes.
1041 draw_will_inject_frontface(const struct draw_context
*draw
)
1043 unsigned reduced_prim
= u_reduced_prim(draw
->pt
.prim
);
1044 const struct pipe_rasterizer_state
*rast
= draw
->rasterizer
;
1046 if (reduced_prim
!= PIPE_PRIM_TRIANGLES
) {
1051 (rast
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
1052 rast
->fill_back
!= PIPE_POLYGON_MODE_FILL
));