OSDN Git Service

gallium: Add a new clip_halfz rasterizer state.
[android-x86/external-mesa.git] / src / gallium / auxiliary / draw / draw_context.c
1 /**************************************************************************
2  * 
3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * All Rights Reserved.
5  * 
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:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
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.
25  * 
26  **************************************************************************/
27
28  /*
29   * Authors:
30   *   Keith Whitwell <keith@tungstengraphics.com>
31   */
32
33
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 "draw_context.h"
41 #include "draw_vs.h"
42 #include "draw_gs.h"
43
44 #if HAVE_LLVM
45 #include "gallivm/lp_bld_init.h"
46 #include "gallivm/lp_bld_limits.h"
47 #include "draw_llvm.h"
48
49 boolean
50 draw_get_option_use_llvm(void)
51 {
52    static boolean first = TRUE;
53    static boolean value;
54    if (first) {
55       first = FALSE;
56       value = debug_get_bool_option("DRAW_USE_LLVM", TRUE);
57
58 #ifdef PIPE_ARCH_X86
59       util_cpu_detect();
60       /* require SSE2 due to LLVM PR6960. */
61       if (!util_cpu_caps.has_sse2)
62          value = FALSE;
63 #endif
64    }
65    return value;
66 }
67 #endif
68
69
70 /**
71  * Create new draw module context with gallivm state for LLVM JIT.
72  */
73 static struct draw_context *
74 draw_create_context(struct pipe_context *pipe, boolean try_llvm)
75 {
76    struct draw_context *draw = CALLOC_STRUCT( draw_context );
77    if (draw == NULL)
78       goto err_out;
79
80 #if HAVE_LLVM
81    if (try_llvm && draw_get_option_use_llvm()) {
82       draw->llvm = draw_llvm_create(draw);
83       if (!draw->llvm)
84          goto err_destroy;
85    }
86 #endif
87
88    draw->pipe = pipe;
89
90    if (!draw_init(draw))
91       goto err_destroy;
92
93    return draw;
94
95 err_destroy:
96    draw_destroy( draw );
97 err_out:
98    return NULL;
99 }
100
101
102 /**
103  * Create new draw module context, with LLVM JIT.
104  */
105 struct draw_context *
106 draw_create(struct pipe_context *pipe)
107 {
108    return draw_create_context(pipe, TRUE);
109 }
110
111
112 /**
113  * Create a new draw context, without LLVM JIT.
114  */
115 struct draw_context *
116 draw_create_no_llvm(struct pipe_context *pipe)
117 {
118    return draw_create_context(pipe, FALSE);
119 }
120
121
122 boolean draw_init(struct draw_context *draw)
123 {
124    /*
125     * Note that several functions compute the clipmask of the predefined
126     * formats with hardcoded formulas instead of using these. So modifications
127     * here must be reflected there too.
128     */
129
130    ASSIGN_4V( draw->plane[0], -1,  0,  0, 1 );
131    ASSIGN_4V( draw->plane[1],  1,  0,  0, 1 );
132    ASSIGN_4V( draw->plane[2],  0, -1,  0, 1 );
133    ASSIGN_4V( draw->plane[3],  0,  1,  0, 1 );
134    ASSIGN_4V( draw->plane[4],  0,  0,  1, 1 ); /* yes these are correct */
135    ASSIGN_4V( draw->plane[5],  0,  0, -1, 1 ); /* mesa's a bit wonky */
136    draw->clip_xy = TRUE;
137    draw->clip_z = TRUE;
138
139    draw->pt.user.planes = (float (*) [DRAW_TOTAL_CLIP_PLANES][4]) &(draw->plane[0]);
140
141    if (!draw_pipeline_init( draw ))
142       return FALSE;
143
144    if (!draw_pt_init( draw ))
145       return FALSE;
146
147    if (!draw_vs_init( draw ))
148       return FALSE;
149
150    if (!draw_gs_init( draw ))
151       return FALSE;
152
153    draw->quads_always_flatshade_last = !draw->pipe->screen->get_param(
154       draw->pipe->screen, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
155
156    return TRUE;
157 }
158
159
160 void draw_destroy( struct draw_context *draw )
161 {
162    struct pipe_context *pipe;
163    unsigned i, j;
164
165    if (!draw)
166       return;
167
168    pipe = draw->pipe;
169
170    /* free any rasterizer CSOs that we may have created.
171     */
172    for (i = 0; i < 2; i++) {
173       for (j = 0; j < 2; j++) {
174          if (draw->rasterizer_no_cull[i][j]) {
175             pipe->delete_rasterizer_state(pipe, draw->rasterizer_no_cull[i][j]);
176          }
177       }
178    }
179
180    for (i = 0; i < draw->pt.nr_vertex_buffers; i++) {
181       pipe_resource_reference(&draw->pt.vertex_buffer[i].buffer, NULL);
182    }
183
184    /* Not so fast -- we're just borrowing this at the moment.
185     * 
186    if (draw->render)
187       draw->render->destroy( draw->render );
188    */
189
190    draw_pipeline_destroy( draw );
191    draw_pt_destroy( draw );
192    draw_vs_destroy( draw );
193    draw_gs_destroy( draw );
194 #ifdef HAVE_LLVM
195    if (draw->llvm)
196       draw_llvm_destroy( draw->llvm );
197 #endif
198
199    FREE( draw );
200 }
201
202
203
204 void draw_flush( struct draw_context *draw )
205 {
206    draw_do_flush( draw, DRAW_FLUSH_BACKEND );
207 }
208
209
210 /**
211  * Specify the Minimum Resolvable Depth factor for polygon offset.
212  * This factor potentially depends on the number of Z buffer bits,
213  * the rasterization algorithm and the arithmetic performed on Z
214  * values between vertex shading and rasterization.  It will vary
215  * from one driver to another.
216  */
217 void draw_set_mrd(struct draw_context *draw, double mrd)
218 {
219    draw->mrd = mrd;
220 }
221
222
223 static void update_clip_flags( struct draw_context *draw )
224 {
225    draw->clip_xy = !draw->driver.bypass_clip_xy;
226    draw->guard_band_xy = (!draw->driver.bypass_clip_xy &&
227                           draw->driver.guard_band_xy);
228    draw->clip_z = (!draw->driver.bypass_clip_z &&
229                    draw->rasterizer && draw->rasterizer->depth_clip);
230    draw->clip_user = draw->rasterizer &&
231                      draw->rasterizer->clip_plane_enable != 0;
232 }
233
234 /**
235  * Register new primitive rasterization/rendering state.
236  * This causes the drawing pipeline to be rebuilt.
237  */
238 void draw_set_rasterizer_state( struct draw_context *draw,
239                                 const struct pipe_rasterizer_state *raster,
240                                 void *rast_handle )
241 {
242    if (!draw->suspend_flushing) {
243       draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
244
245       draw->rasterizer = raster;
246       draw->rast_handle = rast_handle;
247       update_clip_flags(draw);
248    }
249 }
250
251 /* With a little more work, llvmpipe will be able to turn this off and
252  * do its own x/y clipping.  
253  *
254  * Some hardware can turn off clipping altogether - in particular any
255  * hardware with a TNL unit can do its own clipping, even if it is
256  * relying on the draw module for some other reason.
257  */
258 void draw_set_driver_clipping( struct draw_context *draw,
259                                boolean bypass_clip_xy,
260                                boolean bypass_clip_z,
261                                boolean guard_band_xy)
262 {
263    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
264
265    draw->driver.bypass_clip_xy = bypass_clip_xy;
266    draw->driver.bypass_clip_z = bypass_clip_z;
267    draw->driver.guard_band_xy = guard_band_xy;
268    update_clip_flags(draw);
269 }
270
271
272 /** 
273  * Plug in the primitive rendering/rasterization stage (which is the last
274  * stage in the drawing pipeline).
275  * This is provided by the device driver.
276  */
277 void draw_set_rasterize_stage( struct draw_context *draw,
278                                struct draw_stage *stage )
279 {
280    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
281
282    draw->pipeline.rasterize = stage;
283 }
284
285
286 /**
287  * Set the draw module's clipping state.
288  */
289 void draw_set_clip_state( struct draw_context *draw,
290                           const struct pipe_clip_state *clip )
291 {
292    draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
293
294    memcpy(&draw->plane[6], clip->ucp, sizeof(clip->ucp));
295 }
296
297
298 /**
299  * Set the draw module's viewport state.
300  */
301 void draw_set_viewport_state( struct draw_context *draw,
302                               const struct pipe_viewport_state *viewport )
303 {
304    draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
305    draw->viewport = *viewport; /* struct copy */
306    draw->identity_viewport = (viewport->scale[0] == 1.0f &&
307                               viewport->scale[1] == 1.0f &&
308                               viewport->scale[2] == 1.0f &&
309                               viewport->scale[3] == 1.0f &&
310                               viewport->translate[0] == 0.0f &&
311                               viewport->translate[1] == 0.0f &&
312                               viewport->translate[2] == 0.0f &&
313                               viewport->translate[3] == 0.0f);
314
315    draw_vs_set_viewport( draw, viewport );
316 }
317
318
319
320 void
321 draw_set_vertex_buffers(struct draw_context *draw,
322                         unsigned start_slot, unsigned count,
323                         const struct pipe_vertex_buffer *buffers)
324 {
325    assert(start_slot + count <= PIPE_MAX_ATTRIBS);
326
327    util_set_vertex_buffers_count(draw->pt.vertex_buffer,
328                                  &draw->pt.nr_vertex_buffers,
329                                  buffers, start_slot, count);
330 }
331
332
333 void
334 draw_set_vertex_elements(struct draw_context *draw,
335                          unsigned count,
336                          const struct pipe_vertex_element *elements)
337 {
338    assert(count <= PIPE_MAX_ATTRIBS);
339
340    /* We could improve this by only flushing the frontend and the fetch part
341     * of the middle. This would avoid recalculating the emit keys.*/
342    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
343
344    memcpy(draw->pt.vertex_element, elements, count * sizeof(elements[0]));
345    draw->pt.nr_vertex_elements = count;
346 }
347
348
349 /**
350  * Tell drawing context where to find mapped vertex buffers.
351  */
352 void
353 draw_set_mapped_vertex_buffer(struct draw_context *draw,
354                               unsigned attr, const void *buffer)
355 {
356    draw->pt.user.vbuffer[attr] = buffer;
357 }
358
359
360 void
361 draw_set_mapped_constant_buffer(struct draw_context *draw,
362                                 unsigned shader_type,
363                                 unsigned slot,
364                                 const void *buffer,
365                                 unsigned size )
366 {
367    debug_assert(shader_type == PIPE_SHADER_VERTEX ||
368                 shader_type == PIPE_SHADER_GEOMETRY);
369    debug_assert(slot < PIPE_MAX_CONSTANT_BUFFERS);
370
371    draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
372
373    switch (shader_type) {
374    case PIPE_SHADER_VERTEX:
375       draw->pt.user.vs_constants[slot] = buffer;
376       draw->pt.user.vs_constants_size[slot] = size;
377       break;
378    case PIPE_SHADER_GEOMETRY:
379       draw->pt.user.gs_constants[slot] = buffer;
380       draw->pt.user.gs_constants_size[slot] = size;
381       break;
382    default:
383       assert(0 && "invalid shader type in draw_set_mapped_constant_buffer");
384    }
385 }
386
387
388 /**
389  * Tells the draw module to draw points with triangles if their size
390  * is greater than this threshold.
391  */
392 void
393 draw_wide_point_threshold(struct draw_context *draw, float threshold)
394 {
395    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
396    draw->pipeline.wide_point_threshold = threshold;
397 }
398
399
400 /**
401  * Should the draw module handle point->quad conversion for drawing sprites?
402  */
403 void
404 draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite)
405 {
406    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
407    draw->pipeline.wide_point_sprites = draw_sprite;
408 }
409
410
411 /**
412  * Tells the draw module to draw lines with triangles if their width
413  * is greater than this threshold.
414  */
415 void
416 draw_wide_line_threshold(struct draw_context *draw, float threshold)
417 {
418    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
419    draw->pipeline.wide_line_threshold = roundf(threshold);
420 }
421
422
423 /**
424  * Tells the draw module whether or not to implement line stipple.
425  */
426 void
427 draw_enable_line_stipple(struct draw_context *draw, boolean enable)
428 {
429    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
430    draw->pipeline.line_stipple = enable;
431 }
432
433
434 /**
435  * Tells draw module whether to convert points to quads for sprite mode.
436  */
437 void
438 draw_enable_point_sprites(struct draw_context *draw, boolean enable)
439 {
440    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
441    draw->pipeline.point_sprite = enable;
442 }
443
444
445 void
446 draw_set_force_passthrough( struct draw_context *draw, boolean enable )
447 {
448    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
449    draw->force_passthrough = enable;
450 }
451
452
453
454 /**
455  * Allocate an extra vertex/geometry shader vertex attribute, if it doesn't
456  * exist already.
457  *
458  * This is used by some of the optional draw module stages such
459  * as wide_point which may need to allocate additional generic/texcoord
460  * attributes.
461  */
462 int
463 draw_alloc_extra_vertex_attrib(struct draw_context *draw,
464                                uint semantic_name, uint semantic_index)
465 {
466    int slot;
467    uint num_outputs;
468    uint n;
469
470    slot = draw_find_shader_output(draw, semantic_name, semantic_index);
471    if (slot > 0) {
472       return slot;
473    }
474
475    num_outputs = draw_current_shader_outputs(draw);
476    n = draw->extra_shader_outputs.num;
477
478    assert(n < Elements(draw->extra_shader_outputs.semantic_name));
479
480    draw->extra_shader_outputs.semantic_name[n] = semantic_name;
481    draw->extra_shader_outputs.semantic_index[n] = semantic_index;
482    draw->extra_shader_outputs.slot[n] = num_outputs + n;
483    draw->extra_shader_outputs.num++;
484
485    return draw->extra_shader_outputs.slot[n];
486 }
487
488
489 /**
490  * Remove all extra vertex attributes that were allocated with
491  * draw_alloc_extra_vertex_attrib().
492  */
493 void
494 draw_remove_extra_vertex_attribs(struct draw_context *draw)
495 {
496    draw->extra_shader_outputs.num = 0;
497 }
498
499
500 /**
501  * If a geometry shader is present, return its info, else the vertex shader's
502  * info.
503  */
504 struct tgsi_shader_info *
505 draw_get_shader_info(const struct draw_context *draw)
506 {
507
508    if (draw->gs.geometry_shader) {
509       return &draw->gs.geometry_shader->info;
510    } else {
511       return &draw->vs.vertex_shader->info;
512    }
513 }
514
515
516 /**
517  * Ask the draw module for the location/slot of the given vertex attribute in
518  * a post-transformed vertex.
519  *
520  * With this function, drivers that use the draw module should have no reason
521  * to track the current vertex/geometry shader.
522  *
523  * Note that the draw module may sometimes generate vertices with extra
524  * attributes (such as texcoords for AA lines).  The driver can call this
525  * function to find those attributes.
526  *
527  * Zero is returned if the attribute is not found since this is
528  * a don't care / undefined situtation.  Returning -1 would be a bit more
529  * work for the drivers.
530  */
531 int
532 draw_find_shader_output(const struct draw_context *draw,
533                         uint semantic_name, uint semantic_index)
534 {
535    const struct tgsi_shader_info *info = draw_get_shader_info(draw);
536    uint i;
537
538    for (i = 0; i < info->num_outputs; i++) {
539       if (info->output_semantic_name[i] == semantic_name &&
540           info->output_semantic_index[i] == semantic_index)
541          return i;
542    }
543
544    /* Search the extra vertex attributes */
545    for (i = 0; i < draw->extra_shader_outputs.num; i++) {
546       if (draw->extra_shader_outputs.semantic_name[i] == semantic_name &&
547           draw->extra_shader_outputs.semantic_index[i] == semantic_index) {
548          return draw->extra_shader_outputs.slot[i];
549       }
550    }
551
552    return 0;
553 }
554
555
556 /**
557  * Return total number of the shader outputs.  This function is similar to
558  * draw_current_shader_outputs() but this function also counts any extra
559  * vertex/geometry output attributes that may be filled in by some draw
560  * stages (such as AA point, AA line).
561  *
562  * If geometry shader is present, its output will be returned,
563  * if not vertex shader is used.
564  */
565 uint
566 draw_num_shader_outputs(const struct draw_context *draw)
567 {
568    const struct tgsi_shader_info *info = draw_get_shader_info(draw);
569    uint count;
570
571    count = info->num_outputs;
572    count += draw->extra_shader_outputs.num;
573
574    return count;
575 }
576
577
578 /**
579  * Provide TGSI sampler objects for vertex/geometry shaders that use
580  * texture fetches.  This state only needs to be set once per context.
581  * This might only be used by software drivers for the time being.
582  */
583 void
584 draw_texture_sampler(struct draw_context *draw,
585                      uint shader,
586                      struct tgsi_sampler *sampler)
587 {
588    if (shader == PIPE_SHADER_VERTEX) {
589       draw->vs.tgsi.sampler = sampler;
590    } else {
591       debug_assert(shader == PIPE_SHADER_GEOMETRY);
592       draw->gs.tgsi.sampler = sampler;
593    }
594 }
595
596
597
598
599 void draw_set_render( struct draw_context *draw, 
600                       struct vbuf_render *render )
601 {
602    draw->render = render;
603 }
604
605
606 /**
607  * Tell the draw module where vertex indexes/elements are located, and
608  * their size (in bytes).
609  *
610  * Note: the caller must apply the pipe_index_buffer::offset value to
611  * the address.  The draw module doesn't do that.
612  */
613 void
614 draw_set_indexes(struct draw_context *draw,
615                  const void *elements, unsigned elem_size)
616 {
617    assert(elem_size == 0 ||
618           elem_size == 1 ||
619           elem_size == 2 ||
620           elem_size == 4);
621    draw->pt.user.elts = elements;
622    draw->pt.user.eltSizeIB = elem_size;
623 }
624
625
626 /* Revamp me please:
627  */
628 void draw_do_flush( struct draw_context *draw, unsigned flags )
629 {
630    if (!draw->suspend_flushing)
631    {
632       assert(!draw->flushing); /* catch inadvertant recursion */
633
634       draw->flushing = TRUE;
635
636       draw_pipeline_flush( draw, flags );
637
638       draw_pt_flush( draw, flags );
639
640       draw->flushing = FALSE;
641    }
642 }
643
644
645 /**
646  * Return the number of output attributes produced by the geometry
647  * shader, if present.  If no geometry shader, return the number of
648  * outputs from the vertex shader.
649  * \sa draw_num_shader_outputs
650  */
651 uint
652 draw_current_shader_outputs(const struct draw_context *draw)
653 {
654    if (draw->gs.geometry_shader)
655       return draw->gs.num_gs_outputs;
656    return draw->vs.num_vs_outputs;
657 }
658
659
660 /**
661  * Return the index of the shader output which will contain the
662  * vertex position.
663  */
664 uint
665 draw_current_shader_position_output(const struct draw_context *draw)
666 {
667    if (draw->gs.geometry_shader)
668       return draw->gs.position_output;
669    return draw->vs.position_output;
670 }
671
672
673 /**
674  * Return the index of the shader output which will contain the
675  * vertex position.
676  */
677 uint
678 draw_current_shader_clipvertex_output(const struct draw_context *draw)
679 {
680    return draw->vs.clipvertex_output;
681 }
682
683 uint
684 draw_current_shader_clipdistance_output(const struct draw_context *draw, int index)
685 {
686    return draw->vs.clipdistance_output[index];
687 }
688
689 /**
690  * Return a pointer/handle for a driver/CSO rasterizer object which
691  * disabled culling, stippling, unfilled tris, etc.
692  * This is used by some pipeline stages (such as wide_point, aa_line
693  * and aa_point) which convert points/lines into triangles.  In those
694  * cases we don't want to accidentally cull the triangles.
695  *
696  * \param scissor  should the rasterizer state enable scissoring?
697  * \param flatshade  should the rasterizer state use flat shading?
698  * \return  rasterizer CSO handle
699  */
700 void *
701 draw_get_rasterizer_no_cull( struct draw_context *draw,
702                              boolean scissor,
703                              boolean flatshade )
704 {
705    if (!draw->rasterizer_no_cull[scissor][flatshade]) {
706       /* create now */
707       struct pipe_context *pipe = draw->pipe;
708       struct pipe_rasterizer_state rast;
709
710       memset(&rast, 0, sizeof(rast));
711       rast.scissor = scissor;
712       rast.flatshade = flatshade;
713       rast.front_ccw = 1;
714       rast.gl_rasterization_rules = draw->rasterizer->gl_rasterization_rules;
715       rast.clip_halfz = draw->rasterizer->clip_halfz;
716
717       draw->rasterizer_no_cull[scissor][flatshade] =
718          pipe->create_rasterizer_state(pipe, &rast);
719    }
720    return draw->rasterizer_no_cull[scissor][flatshade];
721 }
722
723 void
724 draw_set_mapped_so_targets(struct draw_context *draw,
725                            int num_targets,
726                            struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS])
727 {
728    int i;
729
730    for (i = 0; i < num_targets; i++)
731       draw->so.targets[i] = targets[i];
732    for (i = num_targets; i < PIPE_MAX_SO_BUFFERS; i++)
733       draw->so.targets[i] = NULL;
734
735    draw->so.num_targets = num_targets;
736 }
737
738 void
739 draw_set_sampler_views(struct draw_context *draw,
740                        unsigned shader_stage,
741                        struct pipe_sampler_view **views,
742                        unsigned num)
743 {
744    unsigned i;
745
746    debug_assert(shader_stage < PIPE_SHADER_TYPES);
747    debug_assert(num <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
748
749    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
750
751    for (i = 0; i < num; ++i)
752       draw->sampler_views[shader_stage][i] = views[i];
753    for (i = num; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; ++i)
754       draw->sampler_views[shader_stage][i] = NULL;
755
756    draw->num_sampler_views[shader_stage] = num;
757 }
758
759 void
760 draw_set_samplers(struct draw_context *draw,
761                   unsigned shader_stage,
762                   struct pipe_sampler_state **samplers,
763                   unsigned num)
764 {
765    unsigned i;
766
767    debug_assert(shader_stage < PIPE_SHADER_TYPES);
768    debug_assert(num <= PIPE_MAX_SAMPLERS);
769
770    draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
771
772    for (i = 0; i < num; ++i)
773       draw->samplers[shader_stage][i] = samplers[i];
774    for (i = num; i < PIPE_MAX_SAMPLERS; ++i)
775       draw->samplers[shader_stage][i] = NULL;
776
777    draw->num_samplers[shader_stage] = num;
778
779 #ifdef HAVE_LLVM
780    if (draw->llvm)
781       draw_llvm_set_sampler_state(draw, shader_stage);
782 #endif
783 }
784
785 void
786 draw_set_mapped_texture(struct draw_context *draw,
787                         unsigned shader_stage,
788                         unsigned sview_idx,
789                         uint32_t width, uint32_t height, uint32_t depth,
790                         uint32_t first_level, uint32_t last_level,
791                         const void *base_ptr,
792                         uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
793                         uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
794                         uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
795 {
796 #ifdef HAVE_LLVM
797    if (draw->llvm)
798       draw_llvm_set_mapped_texture(draw,
799                                    shader_stage,
800                                    sview_idx,
801                                    width, height, depth, first_level,
802                                    last_level, base_ptr,
803                                    row_stride, img_stride, mip_offsets);
804 #endif
805 }
806
807 /**
808  * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
809  * different ways of setting textures, and drivers typically only support one.
810  */
811 int
812 draw_get_shader_param_no_llvm(unsigned shader, enum pipe_shader_cap param)
813 {
814    switch(shader) {
815    case PIPE_SHADER_VERTEX:
816    case PIPE_SHADER_GEOMETRY:
817       return tgsi_exec_get_shader_param(param);
818    default:
819       return 0;
820    }
821 }
822
823 /**
824  * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
825  * different ways of setting textures, and drivers typically only support one.
826  */
827 int
828 draw_get_shader_param(unsigned shader, enum pipe_shader_cap param)
829 {
830
831 #ifdef HAVE_LLVM
832    if (draw_get_option_use_llvm()) {
833       switch(shader) {
834       case PIPE_SHADER_VERTEX:
835       case PIPE_SHADER_GEOMETRY:
836          return gallivm_get_shader_param(param);
837       default:
838          return 0;
839       }
840    }
841 #endif
842
843    return draw_get_shader_param_no_llvm(shader, param);
844 }
845
846 /**
847  * Enables or disables collection of statistics.
848  *
849  * Draw module is capable of generating statistics for the vertex
850  * processing pipeline. Collection of that data isn't free and so
851  * it's disabled by default. The users of the module can enable
852  * (or disable) this functionality through this function.
853  * The actual data will be emitted through the VBUF interface,
854  * the 'pipeline_statistics' callback to be exact.
855  */
856 void
857 draw_collect_pipeline_statistics(struct draw_context *draw,
858                                  boolean enable)
859 {
860    draw->collect_statistics = enable;
861 }