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"
46 #include "gallivm/lp_bld_init.h"
47 #include "gallivm/lp_bld_limits.h"
48 #include "draw_llvm.h"
51 draw_get_option_use_llvm(void)
53 static boolean first
= TRUE
;
57 value
= debug_get_bool_option("DRAW_USE_LLVM", TRUE
);
61 /* require SSE2 due to LLVM PR6960. */
62 if (!util_cpu_caps
.has_sse2
)
72 * Create new draw module context with gallivm state for LLVM JIT.
74 static struct draw_context
*
75 draw_create_context(struct pipe_context
*pipe
, boolean try_llvm
)
77 struct draw_context
*draw
= CALLOC_STRUCT( draw_context
);
82 if (try_llvm
&& draw_get_option_use_llvm()) {
83 draw
->llvm
= draw_llvm_create(draw
);
104 * Create new draw module context, with LLVM JIT.
106 struct draw_context
*
107 draw_create(struct pipe_context
*pipe
)
109 return draw_create_context(pipe
, TRUE
);
114 * Create a new draw context, without LLVM JIT.
116 struct draw_context
*
117 draw_create_no_llvm(struct pipe_context
*pipe
)
119 return draw_create_context(pipe
, FALSE
);
123 boolean
draw_init(struct draw_context
*draw
)
126 * Note that several functions compute the clipmask of the predefined
127 * formats with hardcoded formulas instead of using these. So modifications
128 * here must be reflected there too.
131 ASSIGN_4V( draw
->plane
[0], -1, 0, 0, 1 );
132 ASSIGN_4V( draw
->plane
[1], 1, 0, 0, 1 );
133 ASSIGN_4V( draw
->plane
[2], 0, -1, 0, 1 );
134 ASSIGN_4V( draw
->plane
[3], 0, 1, 0, 1 );
135 ASSIGN_4V( draw
->plane
[4], 0, 0, 1, 1 ); /* yes these are correct */
136 ASSIGN_4V( draw
->plane
[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
137 draw
->clip_xy
= TRUE
;
140 draw
->pt
.user
.planes
= (float (*) [DRAW_TOTAL_CLIP_PLANES
][4]) &(draw
->plane
[0]);
141 draw
->pt
.user
.eltMax
= ~0;
143 if (!draw_pipeline_init( draw
))
146 if (!draw_pt_init( draw
))
149 if (!draw_vs_init( draw
))
152 if (!draw_gs_init( draw
))
155 draw
->quads_always_flatshade_last
= !draw
->pipe
->screen
->get_param(
156 draw
->pipe
->screen
, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
);
162 * Called whenever we're starting to draw a new instance.
163 * Some internal structures don't want to have to reset internal
164 * members on each invocation (because their state might have to persist
165 * between multiple primitive restart rendering call) but might have to
166 * for each new instance.
167 * This is particularly the case for primitive id's in geometry shader.
169 void draw_new_instance(struct draw_context
*draw
)
171 draw_geometry_shader_new_instance(draw
->gs
.geometry_shader
);
175 void draw_destroy( struct draw_context
*draw
)
177 struct pipe_context
*pipe
;
185 /* free any rasterizer CSOs that we may have created.
187 for (i
= 0; i
< 2; i
++) {
188 for (j
= 0; j
< 2; j
++) {
189 if (draw
->rasterizer_no_cull
[i
][j
]) {
190 pipe
->delete_rasterizer_state(pipe
, draw
->rasterizer_no_cull
[i
][j
]);
195 for (i
= 0; i
< draw
->pt
.nr_vertex_buffers
; i
++) {
196 pipe_resource_reference(&draw
->pt
.vertex_buffer
[i
].buffer
, NULL
);
199 /* Not so fast -- we're just borrowing this at the moment.
202 draw->render->destroy( draw->render );
205 draw_pipeline_destroy( draw
);
206 draw_pt_destroy( draw
);
207 draw_vs_destroy( draw
);
208 draw_gs_destroy( draw
);
211 draw_llvm_destroy( draw
->llvm
);
219 void draw_flush( struct draw_context
*draw
)
221 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
226 * Specify the Minimum Resolvable Depth factor for polygon offset.
227 * This factor potentially depends on the number of Z buffer bits,
228 * the rasterization algorithm and the arithmetic performed on Z
229 * values between vertex shading and rasterization. It will vary
230 * from one driver to another.
232 void draw_set_mrd(struct draw_context
*draw
, double mrd
)
238 static void update_clip_flags( struct draw_context
*draw
)
240 draw
->clip_xy
= !draw
->driver
.bypass_clip_xy
;
241 draw
->guard_band_xy
= (!draw
->driver
.bypass_clip_xy
&&
242 draw
->driver
.guard_band_xy
);
243 draw
->clip_z
= (!draw
->driver
.bypass_clip_z
&&
244 draw
->rasterizer
&& draw
->rasterizer
->depth_clip
);
245 draw
->clip_user
= draw
->rasterizer
&&
246 draw
->rasterizer
->clip_plane_enable
!= 0;
250 * Register new primitive rasterization/rendering state.
251 * This causes the drawing pipeline to be rebuilt.
253 void draw_set_rasterizer_state( struct draw_context
*draw
,
254 const struct pipe_rasterizer_state
*raster
,
257 if (!draw
->suspend_flushing
) {
258 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
260 draw
->rasterizer
= raster
;
261 draw
->rast_handle
= rast_handle
;
262 update_clip_flags(draw
);
266 /* With a little more work, llvmpipe will be able to turn this off and
267 * do its own x/y clipping.
269 * Some hardware can turn off clipping altogether - in particular any
270 * hardware with a TNL unit can do its own clipping, even if it is
271 * relying on the draw module for some other reason.
273 void draw_set_driver_clipping( struct draw_context
*draw
,
274 boolean bypass_clip_xy
,
275 boolean bypass_clip_z
,
276 boolean guard_band_xy
)
278 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
280 draw
->driver
.bypass_clip_xy
= bypass_clip_xy
;
281 draw
->driver
.bypass_clip_z
= bypass_clip_z
;
282 draw
->driver
.guard_band_xy
= guard_band_xy
;
283 update_clip_flags(draw
);
288 * Plug in the primitive rendering/rasterization stage (which is the last
289 * stage in the drawing pipeline).
290 * This is provided by the device driver.
292 void draw_set_rasterize_stage( struct draw_context
*draw
,
293 struct draw_stage
*stage
)
295 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
297 draw
->pipeline
.rasterize
= stage
;
302 * Set the draw module's clipping state.
304 void draw_set_clip_state( struct draw_context
*draw
,
305 const struct pipe_clip_state
*clip
)
307 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
309 memcpy(&draw
->plane
[6], clip
->ucp
, sizeof(clip
->ucp
));
314 * Set the draw module's viewport state.
316 void draw_set_viewport_states( struct draw_context
*draw
,
318 unsigned num_viewports
,
319 const struct pipe_viewport_state
*vps
)
321 const struct pipe_viewport_state
*viewport
= vps
;
322 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
324 debug_assert(start_slot
< PIPE_MAX_VIEWPORTS
);
325 debug_assert((start_slot
+ num_viewports
) <= PIPE_MAX_VIEWPORTS
);
327 memcpy(draw
->viewports
+ start_slot
, vps
,
328 sizeof(struct pipe_viewport_state
) * num_viewports
);
330 draw
->identity_viewport
= (num_viewports
== 1) &&
331 (viewport
->scale
[0] == 1.0f
&&
332 viewport
->scale
[1] == 1.0f
&&
333 viewport
->scale
[2] == 1.0f
&&
334 viewport
->scale
[3] == 1.0f
&&
335 viewport
->translate
[0] == 0.0f
&&
336 viewport
->translate
[1] == 0.0f
&&
337 viewport
->translate
[2] == 0.0f
&&
338 viewport
->translate
[3] == 0.0f
);
344 draw_set_vertex_buffers(struct draw_context
*draw
,
345 unsigned start_slot
, unsigned count
,
346 const struct pipe_vertex_buffer
*buffers
)
348 assert(start_slot
+ count
<= PIPE_MAX_ATTRIBS
);
350 util_set_vertex_buffers_count(draw
->pt
.vertex_buffer
,
351 &draw
->pt
.nr_vertex_buffers
,
352 buffers
, start_slot
, count
);
357 draw_set_vertex_elements(struct draw_context
*draw
,
359 const struct pipe_vertex_element
*elements
)
361 assert(count
<= PIPE_MAX_ATTRIBS
);
363 /* We could improve this by only flushing the frontend and the fetch part
364 * of the middle. This would avoid recalculating the emit keys.*/
365 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
367 memcpy(draw
->pt
.vertex_element
, elements
, count
* sizeof(elements
[0]));
368 draw
->pt
.nr_vertex_elements
= count
;
373 * Tell drawing context where to find mapped vertex buffers.
376 draw_set_mapped_vertex_buffer(struct draw_context
*draw
,
377 unsigned attr
, const void *buffer
,
380 draw
->pt
.user
.vbuffer
[attr
].map
= buffer
;
381 draw
->pt
.user
.vbuffer
[attr
].size
= size
;
386 draw_set_mapped_constant_buffer(struct draw_context
*draw
,
387 unsigned shader_type
,
392 debug_assert(shader_type
== PIPE_SHADER_VERTEX
||
393 shader_type
== PIPE_SHADER_GEOMETRY
);
394 debug_assert(slot
< PIPE_MAX_CONSTANT_BUFFERS
);
396 draw_do_flush(draw
, DRAW_FLUSH_PARAMETER_CHANGE
);
398 switch (shader_type
) {
399 case PIPE_SHADER_VERTEX
:
400 draw
->pt
.user
.vs_constants
[slot
] = buffer
;
401 draw
->pt
.user
.vs_constants_size
[slot
] = size
;
403 case PIPE_SHADER_GEOMETRY
:
404 draw
->pt
.user
.gs_constants
[slot
] = buffer
;
405 draw
->pt
.user
.gs_constants_size
[slot
] = size
;
408 assert(0 && "invalid shader type in draw_set_mapped_constant_buffer");
414 * Tells the draw module to draw points with triangles if their size
415 * is greater than this threshold.
418 draw_wide_point_threshold(struct draw_context
*draw
, float threshold
)
420 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
421 draw
->pipeline
.wide_point_threshold
= threshold
;
426 * Should the draw module handle point->quad conversion for drawing sprites?
429 draw_wide_point_sprites(struct draw_context
*draw
, boolean draw_sprite
)
431 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
432 draw
->pipeline
.wide_point_sprites
= draw_sprite
;
437 * Tells the draw module to draw lines with triangles if their width
438 * is greater than this threshold.
441 draw_wide_line_threshold(struct draw_context
*draw
, float threshold
)
443 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
444 draw
->pipeline
.wide_line_threshold
= roundf(threshold
);
449 * Tells the draw module whether or not to implement line stipple.
452 draw_enable_line_stipple(struct draw_context
*draw
, boolean enable
)
454 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
455 draw
->pipeline
.line_stipple
= enable
;
460 * Tells draw module whether to convert points to quads for sprite mode.
463 draw_enable_point_sprites(struct draw_context
*draw
, boolean enable
)
465 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
466 draw
->pipeline
.point_sprite
= enable
;
471 draw_set_force_passthrough( struct draw_context
*draw
, boolean enable
)
473 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
474 draw
->force_passthrough
= enable
;
480 * Allocate an extra vertex/geometry shader vertex attribute, if it doesn't
483 * This is used by some of the optional draw module stages such
484 * as wide_point which may need to allocate additional generic/texcoord
488 draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
489 uint semantic_name
, uint semantic_index
)
495 slot
= draw_find_shader_output(draw
, semantic_name
, semantic_index
);
500 num_outputs
= draw_current_shader_outputs(draw
);
501 n
= draw
->extra_shader_outputs
.num
;
503 assert(n
< Elements(draw
->extra_shader_outputs
.semantic_name
));
505 draw
->extra_shader_outputs
.semantic_name
[n
] = semantic_name
;
506 draw
->extra_shader_outputs
.semantic_index
[n
] = semantic_index
;
507 draw
->extra_shader_outputs
.slot
[n
] = num_outputs
+ n
;
508 draw
->extra_shader_outputs
.num
++;
510 return draw
->extra_shader_outputs
.slot
[n
];
515 * Remove all extra vertex attributes that were allocated with
516 * draw_alloc_extra_vertex_attrib().
519 draw_remove_extra_vertex_attribs(struct draw_context
*draw
)
521 draw
->extra_shader_outputs
.num
= 0;
526 * If a geometry shader is present, return its info, else the vertex shader's
529 struct tgsi_shader_info
*
530 draw_get_shader_info(const struct draw_context
*draw
)
533 if (draw
->gs
.geometry_shader
) {
534 return &draw
->gs
.geometry_shader
->info
;
536 return &draw
->vs
.vertex_shader
->info
;
542 * Ask the draw module for the location/slot of the given vertex attribute in
543 * a post-transformed vertex.
545 * With this function, drivers that use the draw module should have no reason
546 * to track the current vertex/geometry shader.
548 * Note that the draw module may sometimes generate vertices with extra
549 * attributes (such as texcoords for AA lines). The driver can call this
550 * function to find those attributes.
552 * -1 is returned if the attribute is not found since this is
553 * an undefined situation. Note, that zero is valid and can
554 * be used by any of the attributes, because position is not
555 * required to be attribute 0 or even at all present.
558 draw_find_shader_output(const struct draw_context
*draw
,
559 uint semantic_name
, uint semantic_index
)
561 const struct tgsi_shader_info
*info
= draw_get_shader_info(draw
);
564 for (i
= 0; i
< info
->num_outputs
; i
++) {
565 if (info
->output_semantic_name
[i
] == semantic_name
&&
566 info
->output_semantic_index
[i
] == semantic_index
)
570 /* Search the extra vertex attributes */
571 for (i
= 0; i
< draw
->extra_shader_outputs
.num
; i
++) {
572 if (draw
->extra_shader_outputs
.semantic_name
[i
] == semantic_name
&&
573 draw
->extra_shader_outputs
.semantic_index
[i
] == semantic_index
) {
574 return draw
->extra_shader_outputs
.slot
[i
];
583 * Return total number of the shader outputs. This function is similar to
584 * draw_current_shader_outputs() but this function also counts any extra
585 * vertex/geometry output attributes that may be filled in by some draw
586 * stages (such as AA point, AA line).
588 * If geometry shader is present, its output will be returned,
589 * if not vertex shader is used.
592 draw_num_shader_outputs(const struct draw_context
*draw
)
594 const struct tgsi_shader_info
*info
= draw_get_shader_info(draw
);
597 count
= info
->num_outputs
;
598 count
+= draw
->extra_shader_outputs
.num
;
605 * Provide TGSI sampler objects for vertex/geometry shaders that use
606 * texture fetches. This state only needs to be set once per context.
607 * This might only be used by software drivers for the time being.
610 draw_texture_sampler(struct draw_context
*draw
,
612 struct tgsi_sampler
*sampler
)
614 if (shader
== PIPE_SHADER_VERTEX
) {
615 draw
->vs
.tgsi
.sampler
= sampler
;
617 debug_assert(shader
== PIPE_SHADER_GEOMETRY
);
618 draw
->gs
.tgsi
.sampler
= sampler
;
625 void draw_set_render( struct draw_context
*draw
,
626 struct vbuf_render
*render
)
628 draw
->render
= render
;
633 * Tell the draw module where vertex indexes/elements are located, and
634 * their size (in bytes).
636 * Note: the caller must apply the pipe_index_buffer::offset value to
637 * the address. The draw module doesn't do that.
640 draw_set_indexes(struct draw_context
*draw
,
641 const void *elements
, unsigned elem_size
,
642 unsigned elem_buffer_space
)
644 assert(elem_size
== 0 ||
648 draw
->pt
.user
.elts
= elements
;
649 draw
->pt
.user
.eltSizeIB
= elem_size
;
651 draw
->pt
.user
.eltMax
= elem_buffer_space
/ elem_size
;
653 draw
->pt
.user
.eltMax
= 0;
659 void draw_do_flush( struct draw_context
*draw
, unsigned flags
)
661 if (!draw
->suspend_flushing
)
663 assert(!draw
->flushing
); /* catch inadvertant recursion */
665 draw
->flushing
= TRUE
;
667 draw_pipeline_flush( draw
, flags
);
669 draw_pt_flush( draw
, flags
);
671 draw
->flushing
= FALSE
;
677 * Return the number of output attributes produced by the geometry
678 * shader, if present. If no geometry shader, return the number of
679 * outputs from the vertex shader.
680 * \sa draw_num_shader_outputs
683 draw_current_shader_outputs(const struct draw_context
*draw
)
685 if (draw
->gs
.geometry_shader
)
686 return draw
->gs
.num_gs_outputs
;
687 return draw
->vs
.num_vs_outputs
;
692 * Return the index of the shader output which will contain the
696 draw_current_shader_position_output(const struct draw_context
*draw
)
698 if (draw
->gs
.geometry_shader
)
699 return draw
->gs
.position_output
;
700 return draw
->vs
.position_output
;
705 * Return the index of the shader output which will contain the
709 draw_current_shader_viewport_index_output(const struct draw_context
*draw
)
711 if (draw
->gs
.geometry_shader
)
712 return draw
->gs
.geometry_shader
->viewport_index_output
;
717 * Returns true if there's a geometry shader bound and the geometry
718 * shader writes out a viewport index.
721 draw_current_shader_uses_viewport_index(const struct draw_context
*draw
)
723 if (draw
->gs
.geometry_shader
)
724 return draw
->gs
.geometry_shader
->info
.writes_viewport_index
;
730 * Return the index of the shader output which will contain the
734 draw_current_shader_clipvertex_output(const struct draw_context
*draw
)
736 return draw
->vs
.clipvertex_output
;
740 draw_current_shader_clipdistance_output(const struct draw_context
*draw
, int index
)
742 debug_assert(index
< PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
);
743 if (draw
->gs
.geometry_shader
)
744 return draw
->gs
.geometry_shader
->clipdistance_output
[index
];
745 return draw
->vs
.clipdistance_output
[index
];
750 draw_current_shader_num_written_clipdistances(const struct draw_context
*draw
)
752 if (draw
->gs
.geometry_shader
)
753 return draw
->gs
.geometry_shader
->info
.num_written_clipdistance
;
754 return draw
->vs
.vertex_shader
->info
.num_written_clipdistance
;
759 draw_current_shader_culldistance_output(const struct draw_context
*draw
, int index
)
761 debug_assert(index
< PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
);
762 if (draw
->gs
.geometry_shader
)
763 return draw
->gs
.geometry_shader
->culldistance_output
[index
];
764 return draw
->vs
.vertex_shader
->culldistance_output
[index
];
768 draw_current_shader_num_written_culldistances(const struct draw_context
*draw
)
770 if (draw
->gs
.geometry_shader
)
771 return draw
->gs
.geometry_shader
->info
.num_written_culldistance
;
772 return draw
->vs
.vertex_shader
->info
.num_written_culldistance
;
776 * Return a pointer/handle for a driver/CSO rasterizer object which
777 * disabled culling, stippling, unfilled tris, etc.
778 * This is used by some pipeline stages (such as wide_point, aa_line
779 * and aa_point) which convert points/lines into triangles. In those
780 * cases we don't want to accidentally cull the triangles.
782 * \param scissor should the rasterizer state enable scissoring?
783 * \param flatshade should the rasterizer state use flat shading?
784 * \return rasterizer CSO handle
787 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
791 if (!draw
->rasterizer_no_cull
[scissor
][flatshade
]) {
793 struct pipe_context
*pipe
= draw
->pipe
;
794 struct pipe_rasterizer_state rast
;
796 memset(&rast
, 0, sizeof(rast
));
797 rast
.scissor
= scissor
;
798 rast
.flatshade
= flatshade
;
800 rast
.half_pixel_center
= draw
->rasterizer
->half_pixel_center
;
801 rast
.bottom_edge_rule
= draw
->rasterizer
->bottom_edge_rule
;
802 rast
.clip_halfz
= draw
->rasterizer
->clip_halfz
;
804 draw
->rasterizer_no_cull
[scissor
][flatshade
] =
805 pipe
->create_rasterizer_state(pipe
, &rast
);
807 return draw
->rasterizer_no_cull
[scissor
][flatshade
];
811 * Sets the mapped so targets.
813 * The append bitmask specifies which of the buffers are in
814 * the append mode. The append mode means that the buffer
815 * should be appended to, rather than written to from the start.
816 * i.e. the outputs should be written starting from the last
817 * location to which the previous
818 * pass of stream output wrote to in this buffer.
819 * If the buffer is not in an append mode (which is more common)
820 * the writing begins from the start of the buffer.
824 draw_set_mapped_so_targets(struct draw_context
*draw
,
826 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
],
827 unsigned append_bitmask
)
831 for (i
= 0; i
< num_targets
; i
++) {
832 draw
->so
.targets
[i
] = targets
[i
];
833 /* if we're not appending then lets reset the internal
834 data of our so target */
835 if (!(append_bitmask
& (1 << i
)) && draw
->so
.targets
[i
]) {
836 draw
->so
.targets
[i
]->internal_offset
= 0;
837 draw
->so
.targets
[i
]->emitted_vertices
= 0;
840 for (i
= num_targets
; i
< PIPE_MAX_SO_BUFFERS
; i
++)
841 draw
->so
.targets
[i
] = NULL
;
843 draw
->so
.num_targets
= num_targets
;
847 draw_set_sampler_views(struct draw_context
*draw
,
848 unsigned shader_stage
,
849 struct pipe_sampler_view
**views
,
854 debug_assert(shader_stage
< PIPE_SHADER_TYPES
);
855 debug_assert(num
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
857 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
859 for (i
= 0; i
< num
; ++i
)
860 draw
->sampler_views
[shader_stage
][i
] = views
[i
];
861 for (i
= num
; i
< PIPE_MAX_SHADER_SAMPLER_VIEWS
; ++i
)
862 draw
->sampler_views
[shader_stage
][i
] = NULL
;
864 draw
->num_sampler_views
[shader_stage
] = num
;
868 draw_set_samplers(struct draw_context
*draw
,
869 unsigned shader_stage
,
870 struct pipe_sampler_state
**samplers
,
875 debug_assert(shader_stage
< PIPE_SHADER_TYPES
);
876 debug_assert(num
<= PIPE_MAX_SAMPLERS
);
878 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
880 for (i
= 0; i
< num
; ++i
)
881 draw
->samplers
[shader_stage
][i
] = samplers
[i
];
882 for (i
= num
; i
< PIPE_MAX_SAMPLERS
; ++i
)
883 draw
->samplers
[shader_stage
][i
] = NULL
;
885 draw
->num_samplers
[shader_stage
] = num
;
889 draw_llvm_set_sampler_state(draw
, shader_stage
);
894 draw_set_mapped_texture(struct draw_context
*draw
,
895 unsigned shader_stage
,
897 uint32_t width
, uint32_t height
, uint32_t depth
,
898 uint32_t first_level
, uint32_t last_level
,
899 const void *base_ptr
,
900 uint32_t row_stride
[PIPE_MAX_TEXTURE_LEVELS
],
901 uint32_t img_stride
[PIPE_MAX_TEXTURE_LEVELS
],
902 uint32_t mip_offsets
[PIPE_MAX_TEXTURE_LEVELS
])
906 draw_llvm_set_mapped_texture(draw
,
909 width
, height
, depth
, first_level
,
910 last_level
, base_ptr
,
911 row_stride
, img_stride
, mip_offsets
);
916 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
917 * different ways of setting textures, and drivers typically only support one.
920 draw_get_shader_param_no_llvm(unsigned shader
, enum pipe_shader_cap param
)
923 case PIPE_SHADER_VERTEX
:
924 case PIPE_SHADER_GEOMETRY
:
925 return tgsi_exec_get_shader_param(param
);
932 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
933 * different ways of setting textures, and drivers typically only support one.
936 draw_get_shader_param(unsigned shader
, enum pipe_shader_cap param
)
940 if (draw_get_option_use_llvm()) {
942 case PIPE_SHADER_VERTEX
:
943 case PIPE_SHADER_GEOMETRY
:
944 return gallivm_get_shader_param(param
);
951 return draw_get_shader_param_no_llvm(shader
, param
);
955 * Enables or disables collection of statistics.
957 * Draw module is capable of generating statistics for the vertex
958 * processing pipeline. Collection of that data isn't free and so
959 * it's disabled by default. The users of the module can enable
960 * (or disable) this functionality through this function.
961 * The actual data will be emitted through the VBUF interface,
962 * the 'pipeline_statistics' callback to be exact.
965 draw_collect_pipeline_statistics(struct draw_context
*draw
,
968 draw
->collect_statistics
= enable
;
972 * Computes clipper invocation statistics.
974 * Figures out how many primitives would have been
975 * sent to the clipper given the specified
979 draw_stats_clipper_primitives(struct draw_context
*draw
,
980 const struct draw_prim_info
*prim_info
)
982 if (draw
->collect_statistics
) {
985 i
< prim_info
->primitive_count
;
986 start
+= prim_info
->primitive_lengths
[i
], i
++)
988 draw
->statistics
.c_invocations
+=
989 u_decomposed_prims_for_vertices(prim_info
->prim
,
990 prim_info
->primitive_lengths
[i
]);