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 **************************************************************************/
30 * Keith Whitwell <keithw@vmware.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 "util/u_format.h"
42 #include "draw_context.h"
43 #include "draw_pipe.h"
44 #include "draw_prim_assembler.h"
49 #include "gallivm/lp_bld_init.h"
50 #include "gallivm/lp_bld_limits.h"
51 #include "draw_llvm.h"
54 draw_get_option_use_llvm(void)
56 static boolean first
= TRUE
;
60 value
= debug_get_bool_option("DRAW_USE_LLVM", TRUE
);
64 /* require SSE2 due to LLVM PR6960. XXX Might be fixed by now? */
65 if (!util_cpu_caps
.has_sse2
)
75 * Create new draw module context with gallivm state for LLVM JIT.
77 static struct draw_context
*
78 draw_create_context(struct pipe_context
*pipe
, boolean try_llvm
)
80 struct draw_context
*draw
= CALLOC_STRUCT( draw_context
);
84 /* we need correct cpu caps for disabling denorms in draw_vbo() */
88 if (try_llvm
&& draw_get_option_use_llvm()) {
89 draw
->llvm
= draw_llvm_create(draw
);
100 draw
->ia
= draw_prim_assembler_create(draw
);
107 draw_destroy( draw
);
114 * Create new draw module context, with LLVM JIT.
116 struct draw_context
*
117 draw_create(struct pipe_context
*pipe
)
119 return draw_create_context(pipe
, TRUE
);
124 * Create a new draw context, without LLVM JIT.
126 struct draw_context
*
127 draw_create_no_llvm(struct pipe_context
*pipe
)
129 return draw_create_context(pipe
, FALSE
);
133 boolean
draw_init(struct draw_context
*draw
)
136 * Note that several functions compute the clipmask of the predefined
137 * formats with hardcoded formulas instead of using these. So modifications
138 * here must be reflected there too.
141 ASSIGN_4V( draw
->plane
[0], -1, 0, 0, 1 );
142 ASSIGN_4V( draw
->plane
[1], 1, 0, 0, 1 );
143 ASSIGN_4V( draw
->plane
[2], 0, -1, 0, 1 );
144 ASSIGN_4V( draw
->plane
[3], 0, 1, 0, 1 );
145 ASSIGN_4V( draw
->plane
[4], 0, 0, 1, 1 ); /* yes these are correct */
146 ASSIGN_4V( draw
->plane
[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
147 draw
->clip_xy
= TRUE
;
150 draw
->pt
.user
.planes
= (float (*) [DRAW_TOTAL_CLIP_PLANES
][4]) &(draw
->plane
[0]);
151 draw
->pt
.user
.eltMax
= ~0;
153 if (!draw_pipeline_init( draw
))
156 if (!draw_pt_init( draw
))
159 if (!draw_vs_init( draw
))
162 if (!draw_gs_init( draw
))
165 draw
->quads_always_flatshade_last
= !draw
->pipe
->screen
->get_param(
166 draw
->pipe
->screen
, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
);
168 draw
->floating_point_depth
= false;
174 * Called whenever we're starting to draw a new instance.
175 * Some internal structures don't want to have to reset internal
176 * members on each invocation (because their state might have to persist
177 * between multiple primitive restart rendering call) but might have to
178 * for each new instance.
179 * This is particularly the case for primitive id's in geometry shader.
181 void draw_new_instance(struct draw_context
*draw
)
183 draw_geometry_shader_new_instance(draw
->gs
.geometry_shader
);
187 void draw_destroy( struct draw_context
*draw
)
189 struct pipe_context
*pipe
;
197 /* free any rasterizer CSOs that we may have created.
199 for (i
= 0; i
< 2; i
++) {
200 for (j
= 0; j
< 2; j
++) {
201 if (draw
->rasterizer_no_cull
[i
][j
]) {
202 pipe
->delete_rasterizer_state(pipe
, draw
->rasterizer_no_cull
[i
][j
]);
207 for (i
= 0; i
< draw
->pt
.nr_vertex_buffers
; i
++) {
208 pipe_resource_reference(&draw
->pt
.vertex_buffer
[i
].buffer
, NULL
);
211 /* Not so fast -- we're just borrowing this at the moment.
214 draw->render->destroy( draw->render );
217 draw_prim_assembler_destroy(draw
->ia
);
218 draw_pipeline_destroy( draw
);
219 draw_pt_destroy( draw
);
220 draw_vs_destroy( draw
);
221 draw_gs_destroy( draw
);
224 draw_llvm_destroy( draw
->llvm
);
232 void draw_flush( struct draw_context
*draw
)
234 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
239 * Specify the depth stencil format for the draw pipeline. This function
240 * determines the Minimum Resolvable Depth factor for polygon offset.
241 * This factor potentially depends on the number of Z buffer bits,
242 * the rasterization algorithm and the arithmetic performed on Z
243 * values between vertex shading and rasterization.
245 void draw_set_zs_format(struct draw_context
*draw
, enum pipe_format format
)
247 const struct util_format_description
*desc
= util_format_description(format
);
249 draw
->floating_point_depth
=
250 (util_get_depth_format_type(desc
) == UTIL_FORMAT_TYPE_FLOAT
);
252 draw
->mrd
= util_get_depth_format_mrd(desc
);
256 static void update_clip_flags( struct draw_context
*draw
)
258 draw
->clip_xy
= !draw
->driver
.bypass_clip_xy
;
259 draw
->guard_band_xy
= (!draw
->driver
.bypass_clip_xy
&&
260 draw
->driver
.guard_band_xy
);
261 draw
->clip_z
= (!draw
->driver
.bypass_clip_z
&&
262 draw
->rasterizer
&& draw
->rasterizer
->depth_clip
);
263 draw
->clip_user
= draw
->rasterizer
&&
264 draw
->rasterizer
->clip_plane_enable
!= 0;
265 draw
->guard_band_points_xy
= draw
->guard_band_xy
||
266 (draw
->driver
.bypass_clip_points
&&
268 draw
->rasterizer
->point_tri_clip
));
272 * Register new primitive rasterization/rendering state.
273 * This causes the drawing pipeline to be rebuilt.
275 void draw_set_rasterizer_state( struct draw_context
*draw
,
276 const struct pipe_rasterizer_state
*raster
,
279 if (!draw
->suspend_flushing
) {
280 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
282 draw
->rasterizer
= raster
;
283 draw
->rast_handle
= rast_handle
;
284 update_clip_flags(draw
);
288 /* With a little more work, llvmpipe will be able to turn this off and
289 * do its own x/y clipping.
291 * Some hardware can turn off clipping altogether - in particular any
292 * hardware with a TNL unit can do its own clipping, even if it is
293 * relying on the draw module for some other reason.
294 * Setting bypass_clip_points to achieve d3d-style point clipping (the driver
295 * will need to do the "vp scissoring") _requires_ the driver to implement
296 * wide points / point sprites itself (points will still be clipped if rasterizer
297 * point_tri_clip isn't set). Only relevant if bypass_clip_xy isn't set.
299 void draw_set_driver_clipping( struct draw_context
*draw
,
300 boolean bypass_clip_xy
,
301 boolean bypass_clip_z
,
302 boolean guard_band_xy
,
303 boolean bypass_clip_points
)
305 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
307 draw
->driver
.bypass_clip_xy
= bypass_clip_xy
;
308 draw
->driver
.bypass_clip_z
= bypass_clip_z
;
309 draw
->driver
.guard_band_xy
= guard_band_xy
;
310 draw
->driver
.bypass_clip_points
= bypass_clip_points
;
311 update_clip_flags(draw
);
316 * Plug in the primitive rendering/rasterization stage (which is the last
317 * stage in the drawing pipeline).
318 * This is provided by the device driver.
320 void draw_set_rasterize_stage( struct draw_context
*draw
,
321 struct draw_stage
*stage
)
323 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
325 draw
->pipeline
.rasterize
= stage
;
330 * Set the draw module's clipping state.
332 void draw_set_clip_state( struct draw_context
*draw
,
333 const struct pipe_clip_state
*clip
)
335 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
337 memcpy(&draw
->plane
[6], clip
->ucp
, sizeof(clip
->ucp
));
342 * Set the draw module's viewport state.
344 void draw_set_viewport_states( struct draw_context
*draw
,
346 unsigned num_viewports
,
347 const struct pipe_viewport_state
*vps
)
349 const struct pipe_viewport_state
*viewport
= vps
;
350 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
352 debug_assert(start_slot
< PIPE_MAX_VIEWPORTS
);
353 debug_assert((start_slot
+ num_viewports
) <= PIPE_MAX_VIEWPORTS
);
355 memcpy(draw
->viewports
+ start_slot
, vps
,
356 sizeof(struct pipe_viewport_state
) * num_viewports
);
358 draw
->identity_viewport
= (num_viewports
== 1) &&
359 (viewport
->scale
[0] == 1.0f
&&
360 viewport
->scale
[1] == 1.0f
&&
361 viewport
->scale
[2] == 1.0f
&&
362 viewport
->scale
[3] == 1.0f
&&
363 viewport
->translate
[0] == 0.0f
&&
364 viewport
->translate
[1] == 0.0f
&&
365 viewport
->translate
[2] == 0.0f
&&
366 viewport
->translate
[3] == 0.0f
);
372 draw_set_vertex_buffers(struct draw_context
*draw
,
373 unsigned start_slot
, unsigned count
,
374 const struct pipe_vertex_buffer
*buffers
)
376 assert(start_slot
+ count
<= PIPE_MAX_ATTRIBS
);
378 util_set_vertex_buffers_count(draw
->pt
.vertex_buffer
,
379 &draw
->pt
.nr_vertex_buffers
,
380 buffers
, start_slot
, count
);
385 draw_set_vertex_elements(struct draw_context
*draw
,
387 const struct pipe_vertex_element
*elements
)
389 assert(count
<= PIPE_MAX_ATTRIBS
);
391 /* We could improve this by only flushing the frontend and the fetch part
392 * of the middle. This would avoid recalculating the emit keys.*/
393 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
395 memcpy(draw
->pt
.vertex_element
, elements
, count
* sizeof(elements
[0]));
396 draw
->pt
.nr_vertex_elements
= count
;
401 * Tell drawing context where to find mapped vertex buffers.
404 draw_set_mapped_vertex_buffer(struct draw_context
*draw
,
405 unsigned attr
, const void *buffer
,
408 draw
->pt
.user
.vbuffer
[attr
].map
= buffer
;
409 draw
->pt
.user
.vbuffer
[attr
].size
= size
;
414 draw_set_mapped_constant_buffer(struct draw_context
*draw
,
415 unsigned shader_type
,
420 debug_assert(shader_type
== PIPE_SHADER_VERTEX
||
421 shader_type
== PIPE_SHADER_GEOMETRY
);
422 debug_assert(slot
< PIPE_MAX_CONSTANT_BUFFERS
);
424 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
426 switch (shader_type
) {
427 case PIPE_SHADER_VERTEX
:
428 draw
->pt
.user
.vs_constants
[slot
] = buffer
;
429 draw
->pt
.user
.vs_constants_size
[slot
] = size
;
431 case PIPE_SHADER_GEOMETRY
:
432 draw
->pt
.user
.gs_constants
[slot
] = buffer
;
433 draw
->pt
.user
.gs_constants_size
[slot
] = size
;
436 assert(0 && "invalid shader type in draw_set_mapped_constant_buffer");
442 * Tells the draw module to draw points with triangles if their size
443 * is greater than this threshold.
446 draw_wide_point_threshold(struct draw_context
*draw
, float threshold
)
448 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
449 draw
->pipeline
.wide_point_threshold
= threshold
;
454 * Should the draw module handle point->quad conversion for drawing sprites?
457 draw_wide_point_sprites(struct draw_context
*draw
, boolean draw_sprite
)
459 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
460 draw
->pipeline
.wide_point_sprites
= draw_sprite
;
465 * Tells the draw module to draw lines with triangles if their width
466 * is greater than this threshold.
469 draw_wide_line_threshold(struct draw_context
*draw
, float threshold
)
471 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
472 draw
->pipeline
.wide_line_threshold
= roundf(threshold
);
477 * Tells the draw module whether or not to implement line stipple.
480 draw_enable_line_stipple(struct draw_context
*draw
, boolean enable
)
482 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
483 draw
->pipeline
.line_stipple
= enable
;
488 * Tells draw module whether to convert points to quads for sprite mode.
491 draw_enable_point_sprites(struct draw_context
*draw
, boolean enable
)
493 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
494 draw
->pipeline
.point_sprite
= enable
;
499 draw_set_force_passthrough( struct draw_context
*draw
, boolean enable
)
501 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
502 draw
->force_passthrough
= enable
;
508 * Allocate an extra vertex/geometry shader vertex attribute, if it doesn't
511 * This is used by some of the optional draw module stages such
512 * as wide_point which may need to allocate additional generic/texcoord
516 draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
517 uint semantic_name
, uint semantic_index
)
523 slot
= draw_find_shader_output(draw
, semantic_name
, semantic_index
);
528 num_outputs
= draw_current_shader_outputs(draw
);
529 n
= draw
->extra_shader_outputs
.num
;
531 assert(n
< Elements(draw
->extra_shader_outputs
.semantic_name
));
533 draw
->extra_shader_outputs
.semantic_name
[n
] = semantic_name
;
534 draw
->extra_shader_outputs
.semantic_index
[n
] = semantic_index
;
535 draw
->extra_shader_outputs
.slot
[n
] = num_outputs
+ n
;
536 draw
->extra_shader_outputs
.num
++;
538 return draw
->extra_shader_outputs
.slot
[n
];
543 * Remove all extra vertex attributes that were allocated with
544 * draw_alloc_extra_vertex_attrib().
547 draw_remove_extra_vertex_attribs(struct draw_context
*draw
)
549 draw
->extra_shader_outputs
.num
= 0;
554 * If a geometry shader is present, return its info, else the vertex shader's
557 struct tgsi_shader_info
*
558 draw_get_shader_info(const struct draw_context
*draw
)
561 if (draw
->gs
.geometry_shader
) {
562 return &draw
->gs
.geometry_shader
->info
;
564 return &draw
->vs
.vertex_shader
->info
;
569 * Prepare outputs slots from the draw module
571 * Certain parts of the draw module can emit additional
572 * outputs that can be quite useful to the backends, a good
573 * example of it is the process of decomposing primitives
574 * into wireframes (aka. lines) which normally would lose
575 * the face-side information, but using this method we can
576 * inject another shader output which passes the original
577 * face side information to the backend.
580 draw_prepare_shader_outputs(struct draw_context
*draw
)
582 draw_remove_extra_vertex_attribs(draw
);
583 draw_prim_assembler_prepare_outputs(draw
->ia
);
584 draw_unfilled_prepare_outputs(draw
, draw
->pipeline
.unfilled
);
585 if (draw
->pipeline
.aapoint
)
586 draw_aapoint_prepare_outputs(draw
, draw
->pipeline
.aapoint
);
587 if (draw
->pipeline
.aaline
)
588 draw_aaline_prepare_outputs(draw
, draw
->pipeline
.aaline
);
592 * Ask the draw module for the location/slot of the given vertex attribute in
593 * a post-transformed vertex.
595 * With this function, drivers that use the draw module should have no reason
596 * to track the current vertex/geometry shader.
598 * Note that the draw module may sometimes generate vertices with extra
599 * attributes (such as texcoords for AA lines). The driver can call this
600 * function to find those attributes.
602 * -1 is returned if the attribute is not found since this is
603 * an undefined situation. Note, that zero is valid and can
604 * be used by any of the attributes, because position is not
605 * required to be attribute 0 or even at all present.
608 draw_find_shader_output(const struct draw_context
*draw
,
609 uint semantic_name
, uint semantic_index
)
611 const struct tgsi_shader_info
*info
= draw_get_shader_info(draw
);
614 for (i
= 0; i
< info
->num_outputs
; i
++) {
615 if (info
->output_semantic_name
[i
] == semantic_name
&&
616 info
->output_semantic_index
[i
] == semantic_index
)
620 /* Search the extra vertex attributes */
621 for (i
= 0; i
< draw
->extra_shader_outputs
.num
; i
++) {
622 if (draw
->extra_shader_outputs
.semantic_name
[i
] == semantic_name
&&
623 draw
->extra_shader_outputs
.semantic_index
[i
] == semantic_index
) {
624 return draw
->extra_shader_outputs
.slot
[i
];
633 * Return total number of the shader outputs. This function is similar to
634 * draw_current_shader_outputs() but this function also counts any extra
635 * vertex/geometry output attributes that may be filled in by some draw
636 * stages (such as AA point, AA line).
638 * If geometry shader is present, its output will be returned,
639 * if not vertex shader is used.
642 draw_num_shader_outputs(const struct draw_context
*draw
)
644 const struct tgsi_shader_info
*info
= draw_get_shader_info(draw
);
647 count
= info
->num_outputs
;
648 count
+= draw
->extra_shader_outputs
.num
;
655 * Return total number of the vertex shader outputs. This function
656 * also counts any extra vertex output attributes that may
657 * be filled in by some draw stages (such as AA point, AA line,
661 draw_total_vs_outputs(const struct draw_context
*draw
)
663 const struct tgsi_shader_info
*info
= &draw
->vs
.vertex_shader
->info
;
665 return info
->num_outputs
+ draw
->extra_shader_outputs
.num
;;
669 * Return total number of the geometry shader outputs. This function
670 * also counts any extra geometry output attributes that may
671 * be filled in by some draw stages (such as AA point, AA line, front
675 draw_total_gs_outputs(const struct draw_context
*draw
)
677 const struct tgsi_shader_info
*info
;
679 if (!draw
->gs
.geometry_shader
)
682 info
= &draw
->gs
.geometry_shader
->info
;
684 return info
->num_outputs
+ draw
->extra_shader_outputs
.num
;
689 * Provide TGSI sampler objects for vertex/geometry shaders that use
690 * texture fetches. This state only needs to be set once per context.
691 * This might only be used by software drivers for the time being.
694 draw_texture_sampler(struct draw_context
*draw
,
696 struct tgsi_sampler
*sampler
)
698 if (shader
== PIPE_SHADER_VERTEX
) {
699 draw
->vs
.tgsi
.sampler
= sampler
;
701 debug_assert(shader
== PIPE_SHADER_GEOMETRY
);
702 draw
->gs
.tgsi
.sampler
= sampler
;
709 void draw_set_render( struct draw_context
*draw
,
710 struct vbuf_render
*render
)
712 draw
->render
= render
;
717 * Tell the draw module where vertex indexes/elements are located, and
718 * their size (in bytes).
720 * Note: the caller must apply the pipe_index_buffer::offset value to
721 * the address. The draw module doesn't do that.
724 draw_set_indexes(struct draw_context
*draw
,
725 const void *elements
, unsigned elem_size
,
726 unsigned elem_buffer_space
)
728 assert(elem_size
== 0 ||
732 draw
->pt
.user
.elts
= elements
;
733 draw
->pt
.user
.eltSizeIB
= elem_size
;
735 draw
->pt
.user
.eltMax
= elem_buffer_space
/ elem_size
;
737 draw
->pt
.user
.eltMax
= 0;
743 void draw_do_flush( struct draw_context
*draw
, unsigned flags
)
745 if (!draw
->suspend_flushing
)
747 assert(!draw
->flushing
); /* catch inadvertant recursion */
749 draw
->flushing
= TRUE
;
751 draw_pipeline_flush( draw
, flags
);
753 draw_pt_flush( draw
, flags
);
755 draw
->flushing
= FALSE
;
761 * Return the number of output attributes produced by the geometry
762 * shader, if present. If no geometry shader, return the number of
763 * outputs from the vertex shader.
764 * \sa draw_num_shader_outputs
767 draw_current_shader_outputs(const struct draw_context
*draw
)
769 if (draw
->gs
.geometry_shader
)
770 return draw
->gs
.num_gs_outputs
;
771 return draw
->vs
.num_vs_outputs
;
776 * Return the index of the shader output which will contain the
780 draw_current_shader_position_output(const struct draw_context
*draw
)
782 if (draw
->gs
.geometry_shader
)
783 return draw
->gs
.position_output
;
784 return draw
->vs
.position_output
;
789 * Return the index of the shader output which will contain the
793 draw_current_shader_viewport_index_output(const struct draw_context
*draw
)
795 if (draw
->gs
.geometry_shader
)
796 return draw
->gs
.geometry_shader
->viewport_index_output
;
801 * Returns true if there's a geometry shader bound and the geometry
802 * shader writes out a viewport index.
805 draw_current_shader_uses_viewport_index(const struct draw_context
*draw
)
807 if (draw
->gs
.geometry_shader
)
808 return draw
->gs
.geometry_shader
->info
.writes_viewport_index
;
814 * Return the index of the shader output which will contain the
818 draw_current_shader_clipvertex_output(const struct draw_context
*draw
)
820 return draw
->vs
.clipvertex_output
;
824 draw_current_shader_clipdistance_output(const struct draw_context
*draw
, int index
)
826 debug_assert(index
< PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
);
827 if (draw
->gs
.geometry_shader
)
828 return draw
->gs
.geometry_shader
->clipdistance_output
[index
];
829 return draw
->vs
.clipdistance_output
[index
];
834 draw_current_shader_num_written_clipdistances(const struct draw_context
*draw
)
836 if (draw
->gs
.geometry_shader
)
837 return draw
->gs
.geometry_shader
->info
.num_written_clipdistance
;
838 return draw
->vs
.vertex_shader
->info
.num_written_clipdistance
;
843 draw_current_shader_culldistance_output(const struct draw_context
*draw
, int index
)
845 debug_assert(index
< PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
);
846 if (draw
->gs
.geometry_shader
)
847 return draw
->gs
.geometry_shader
->culldistance_output
[index
];
848 return draw
->vs
.vertex_shader
->culldistance_output
[index
];
852 draw_current_shader_num_written_culldistances(const struct draw_context
*draw
)
854 if (draw
->gs
.geometry_shader
)
855 return draw
->gs
.geometry_shader
->info
.num_written_culldistance
;
856 return draw
->vs
.vertex_shader
->info
.num_written_culldistance
;
860 * Return a pointer/handle for a driver/CSO rasterizer object which
861 * disabled culling, stippling, unfilled tris, etc.
862 * This is used by some pipeline stages (such as wide_point, aa_line
863 * and aa_point) which convert points/lines into triangles. In those
864 * cases we don't want to accidentally cull the triangles.
866 * \param scissor should the rasterizer state enable scissoring?
867 * \param flatshade should the rasterizer state use flat shading?
868 * \return rasterizer CSO handle
871 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
875 if (!draw
->rasterizer_no_cull
[scissor
][flatshade
]) {
877 struct pipe_context
*pipe
= draw
->pipe
;
878 struct pipe_rasterizer_state rast
;
880 memset(&rast
, 0, sizeof(rast
));
881 rast
.scissor
= scissor
;
882 rast
.flatshade
= flatshade
;
884 rast
.half_pixel_center
= draw
->rasterizer
->half_pixel_center
;
885 rast
.bottom_edge_rule
= draw
->rasterizer
->bottom_edge_rule
;
886 rast
.clip_halfz
= draw
->rasterizer
->clip_halfz
;
888 draw
->rasterizer_no_cull
[scissor
][flatshade
] =
889 pipe
->create_rasterizer_state(pipe
, &rast
);
891 return draw
->rasterizer_no_cull
[scissor
][flatshade
];
895 draw_set_mapped_so_targets(struct draw_context
*draw
,
897 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
])
901 for (i
= 0; i
< num_targets
; i
++)
902 draw
->so
.targets
[i
] = targets
[i
];
903 for (i
= num_targets
; i
< PIPE_MAX_SO_BUFFERS
; i
++)
904 draw
->so
.targets
[i
] = NULL
;
906 draw
->so
.num_targets
= num_targets
;
910 draw_set_sampler_views(struct draw_context
*draw
,
911 unsigned shader_stage
,
912 struct pipe_sampler_view
**views
,
917 debug_assert(shader_stage
< PIPE_SHADER_TYPES
);
918 debug_assert(num
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
920 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
922 for (i
= 0; i
< num
; ++i
)
923 draw
->sampler_views
[shader_stage
][i
] = views
[i
];
924 for (i
= num
; i
< PIPE_MAX_SHADER_SAMPLER_VIEWS
; ++i
)
925 draw
->sampler_views
[shader_stage
][i
] = NULL
;
927 draw
->num_sampler_views
[shader_stage
] = num
;
931 draw_set_samplers(struct draw_context
*draw
,
932 unsigned shader_stage
,
933 struct pipe_sampler_state
**samplers
,
938 debug_assert(shader_stage
< PIPE_SHADER_TYPES
);
939 debug_assert(num
<= PIPE_MAX_SAMPLERS
);
941 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
943 for (i
= 0; i
< num
; ++i
)
944 draw
->samplers
[shader_stage
][i
] = samplers
[i
];
945 for (i
= num
; i
< PIPE_MAX_SAMPLERS
; ++i
)
946 draw
->samplers
[shader_stage
][i
] = NULL
;
948 draw
->num_samplers
[shader_stage
] = num
;
952 draw_llvm_set_sampler_state(draw
, shader_stage
);
957 draw_set_mapped_texture(struct draw_context
*draw
,
958 unsigned shader_stage
,
960 uint32_t width
, uint32_t height
, uint32_t depth
,
961 uint32_t first_level
, uint32_t last_level
,
962 const void *base_ptr
,
963 uint32_t row_stride
[PIPE_MAX_TEXTURE_LEVELS
],
964 uint32_t img_stride
[PIPE_MAX_TEXTURE_LEVELS
],
965 uint32_t mip_offsets
[PIPE_MAX_TEXTURE_LEVELS
])
969 draw_llvm_set_mapped_texture(draw
,
972 width
, height
, depth
, first_level
,
973 last_level
, base_ptr
,
974 row_stride
, img_stride
, mip_offsets
);
979 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
980 * different ways of setting textures, and drivers typically only support one.
983 draw_get_shader_param_no_llvm(unsigned shader
, enum pipe_shader_cap param
)
986 case PIPE_SHADER_VERTEX
:
987 case PIPE_SHADER_GEOMETRY
:
988 return tgsi_exec_get_shader_param(param
);
995 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
996 * different ways of setting textures, and drivers typically only support one.
999 draw_get_shader_param(unsigned shader
, enum pipe_shader_cap param
)
1003 if (draw_get_option_use_llvm()) {
1005 case PIPE_SHADER_VERTEX
:
1006 case PIPE_SHADER_GEOMETRY
:
1007 return gallivm_get_shader_param(param
);
1014 return draw_get_shader_param_no_llvm(shader
, param
);
1018 * Enables or disables collection of statistics.
1020 * Draw module is capable of generating statistics for the vertex
1021 * processing pipeline. Collection of that data isn't free and so
1022 * it's disabled by default. The users of the module can enable
1023 * (or disable) this functionality through this function.
1024 * The actual data will be emitted through the VBUF interface,
1025 * the 'pipeline_statistics' callback to be exact.
1028 draw_collect_pipeline_statistics(struct draw_context
*draw
,
1031 draw
->collect_statistics
= enable
;
1035 * Computes clipper invocation statistics.
1037 * Figures out how many primitives would have been
1038 * sent to the clipper given the specified
1042 draw_stats_clipper_primitives(struct draw_context
*draw
,
1043 const struct draw_prim_info
*prim_info
)
1045 if (draw
->collect_statistics
) {
1047 for (i
= 0; i
< prim_info
->primitive_count
; i
++) {
1048 draw
->statistics
.c_invocations
+=
1049 u_decomposed_prims_for_vertices(prim_info
->prim
,
1050 prim_info
->primitive_lengths
[i
]);
1057 * Returns true if the draw module will inject the frontface
1058 * info into the outputs.
1060 * Given the specified primitive and rasterizer state
1061 * the function will figure out if the draw module
1062 * will inject the front-face information into shader
1063 * outputs. This is done to preserve the front-facing
1064 * info when decomposing primitives into wireframes.
1067 draw_will_inject_frontface(const struct draw_context
*draw
)
1069 unsigned reduced_prim
= u_reduced_prim(draw
->pt
.prim
);
1070 const struct pipe_rasterizer_state
*rast
= draw
->rasterizer
;
1072 if (reduced_prim
!= PIPE_PRIM_TRIANGLES
) {
1077 (rast
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
1078 rast
->fill_back
!= PIPE_POLYGON_MODE_FILL
));