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