draw_context.c revision f4863f3923152448e27ea68d0cd04411bbe3f4c7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**************************************************************************
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * All Rights Reserved.
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Permission is hereby granted, free of charge, to any person obtaining a
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * copy of this software and associated documentation files (the
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * "Software"), to deal in the Software without restriction, including
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * without limitation the rights to use, copy, modify, merge, publish,
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * distribute, sub license, and/or sell copies of the Software, and to
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * permit persons to whom the Software is furnished to do so, subject to
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the following conditions:
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The above copyright notice and this permission notice (including the
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * next paragraph) shall be included in all copies or substantial portions
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * of the Software.
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) *
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 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->nr_planes = 6;
155   draw->clip_xy = TRUE;
156   draw->clip_z = TRUE;
157
158
159   draw->reduced_prim = ~0; /* != any of PIPE_PRIM_x */
160
161
162   if (!draw_pipeline_init( draw ))
163      return FALSE;
164
165   if (!draw_pt_init( draw ))
166      return FALSE;
167
168   if (!draw_vs_init( draw ))
169      return FALSE;
170
171   if (!draw_gs_init( draw ))
172      return FALSE;
173
174   return TRUE;
175}
176
177
178void draw_destroy( struct draw_context *draw )
179{
180   struct pipe_context *pipe;
181   int i, j;
182
183   if (!draw)
184      return;
185
186   pipe = draw->pipe;
187
188   /* free any rasterizer CSOs that we may have created.
189    */
190   for (i = 0; i < 2; i++) {
191      for (j = 0; j < 2; j++) {
192         if (draw->rasterizer_no_cull[i][j]) {
193            pipe->delete_rasterizer_state(pipe, draw->rasterizer_no_cull[i][j]);
194         }
195      }
196   }
197
198   for (i = 0; i < draw->pt.nr_vertex_buffers; i++) {
199      pipe_resource_reference(&draw->pt.vertex_buffer[i].buffer, NULL);
200   }
201
202   /* Not so fast -- we're just borrowing this at the moment.
203    *
204   if (draw->render)
205      draw->render->destroy( draw->render );
206   */
207
208   draw_pipeline_destroy( draw );
209   draw_pt_destroy( draw );
210   draw_vs_destroy( draw );
211   draw_gs_destroy( draw );
212#ifdef HAVE_LLVM
213   if (draw->llvm)
214      draw_llvm_destroy( draw->llvm );
215
216   if (draw->own_gallivm)
217      gallivm_destroy(draw->own_gallivm);
218#endif
219
220   FREE( draw );
221}
222
223
224
225void draw_flush( struct draw_context *draw )
226{
227   draw_do_flush( draw, DRAW_FLUSH_BACKEND );
228}
229
230
231/**
232 * Specify the Minimum Resolvable Depth factor for polygon offset.
233 * This factor potentially depends on the number of Z buffer bits,
234 * the rasterization algorithm and the arithmetic performed on Z
235 * values between vertex shading and rasterization.  It will vary
236 * from one driver to another.
237 */
238void draw_set_mrd(struct draw_context *draw, double mrd)
239{
240   draw->mrd = mrd;
241}
242
243
244static void update_clip_flags( struct draw_context *draw )
245{
246   draw->clip_xy = !draw->driver.bypass_clip_xy;
247   draw->guard_band_xy = (!draw->driver.bypass_clip_xy &&
248                          draw->driver.guard_band_xy);
249   draw->clip_z = (!draw->driver.bypass_clip_z &&
250                   !draw->depth_clamp);
251   draw->clip_user = (draw->nr_planes > 6);
252}
253
254/**
255 * Register new primitive rasterization/rendering state.
256 * This causes the drawing pipeline to be rebuilt.
257 */
258void draw_set_rasterizer_state( struct draw_context *draw,
259                                const struct pipe_rasterizer_state *raster,
260                                void *rast_handle )
261{
262   if (!draw->suspend_flushing) {
263      draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
264
265      draw->rasterizer = raster;
266      draw->rast_handle = rast_handle;
267
268  }
269}
270
271/* With a little more work, llvmpipe will be able to turn this off and
272 * do its own x/y clipping.
273 *
274 * Some hardware can turn off clipping altogether - in particular any
275 * hardware with a TNL unit can do its own clipping, even if it is
276 * relying on the draw module for some other reason.
277 */
278void draw_set_driver_clipping( struct draw_context *draw,
279                               boolean bypass_clip_xy,
280                               boolean bypass_clip_z,
281                               boolean guard_band_xy)
282{
283   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
284
285   draw->driver.bypass_clip_xy = bypass_clip_xy;
286   draw->driver.bypass_clip_z = bypass_clip_z;
287   draw->driver.guard_band_xy = guard_band_xy;
288   update_clip_flags(draw);
289}
290
291
292/**
293 * Plug in the primitive rendering/rasterization stage (which is the last
294 * stage in the drawing pipeline).
295 * This is provided by the device driver.
296 */
297void draw_set_rasterize_stage( struct draw_context *draw,
298                               struct draw_stage *stage )
299{
300   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
301
302   draw->pipeline.rasterize = stage;
303}
304
305
306/**
307 * Set the draw module's clipping state.
308 */
309void draw_set_clip_state( struct draw_context *draw,
310                          const struct pipe_clip_state *clip )
311{
312   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
313
314   assert(clip->nr <= PIPE_MAX_CLIP_PLANES);
315   memcpy(&draw->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0]));
316   draw->nr_planes = 6 + clip->nr;
317   draw->depth_clamp = clip->depth_clamp;
318
319   draw->pt.user.planes = (float (*) [DRAW_TOTAL_CLIP_PLANES][4]) &(draw->plane[0]);
320
321   update_clip_flags(draw);
322}
323
324
325/**
326 * Set the draw module's viewport state.
327 */
328void draw_set_viewport_state( struct draw_context *draw,
329                              const struct pipe_viewport_state *viewport )
330{
331   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
332   draw->viewport = *viewport; /* struct copy */
333   draw->identity_viewport = (viewport->scale[0] == 1.0f &&
334                              viewport->scale[1] == 1.0f &&
335                              viewport->scale[2] == 1.0f &&
336                              viewport->scale[3] == 1.0f &&
337                              viewport->translate[0] == 0.0f &&
338                              viewport->translate[1] == 0.0f &&
339                              viewport->translate[2] == 0.0f &&
340                              viewport->translate[3] == 0.0f);
341
342   draw_vs_set_viewport( draw, viewport );
343}
344
345
346
347void
348draw_set_vertex_buffers(struct draw_context *draw,
349                        unsigned count,
350                        const struct pipe_vertex_buffer *buffers)
351{
352   assert(count <= PIPE_MAX_ATTRIBS);
353
354   util_copy_vertex_buffers(draw->pt.vertex_buffer,
355                            &draw->pt.nr_vertex_buffers,
356                            buffers, count);
357}
358
359
360void
361draw_set_vertex_elements(struct draw_context *draw,
362                         unsigned count,
363                         const struct pipe_vertex_element *elements)
364{
365   assert(count <= PIPE_MAX_ATTRIBS);
366
367   memcpy(draw->pt.vertex_element, elements, count * sizeof(elements[0]));
368   draw->pt.nr_vertex_elements = count;
369}
370
371
372/**
373 * Tell drawing context where to find mapped vertex buffers.
374 */
375void
376draw_set_mapped_vertex_buffer(struct draw_context *draw,
377                              unsigned attr, const void *buffer)
378{
379   draw->pt.user.vbuffer[attr] = buffer;
380}
381
382
383void
384draw_set_mapped_constant_buffer(struct draw_context *draw,
385                                unsigned shader_type,
386                                unsigned slot,
387                                const void *buffer,
388                                unsigned size )
389{
390   debug_assert(shader_type == PIPE_SHADER_VERTEX ||
391                shader_type == PIPE_SHADER_GEOMETRY);
392   debug_assert(slot < PIPE_MAX_CONSTANT_BUFFERS);
393
394   switch (shader_type) {
395   case PIPE_SHADER_VERTEX:
396      draw->pt.user.vs_constants[slot] = buffer;
397      draw->pt.user.vs_constants_size[slot] = size;
398      draw_vs_set_constants(draw, slot, buffer, size);
399      break;
400   case PIPE_SHADER_GEOMETRY:
401      draw->pt.user.gs_constants[slot] = buffer;
402      draw->pt.user.gs_constants_size[slot] = size;
403      draw_gs_set_constants(draw, slot, buffer, size);
404      break;
405   default:
406      assert(0 && "invalid shader type in draw_set_mapped_constant_buffer");
407   }
408}
409
410
411/**
412 * Tells the draw module to draw points with triangles if their size
413 * is greater than this threshold.
414 */
415void
416draw_wide_point_threshold(struct draw_context *draw, float threshold)
417{
418   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
419   draw->pipeline.wide_point_threshold = threshold;
420}
421
422
423/**
424 * Should the draw module handle point->quad conversion for drawing sprites?
425 */
426void
427draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite)
428{
429   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
430   draw->pipeline.wide_point_sprites = draw_sprite;
431}
432
433
434/**
435 * Tells the draw module to draw lines with triangles if their width
436 * is greater than this threshold.
437 */
438void
439draw_wide_line_threshold(struct draw_context *draw, float threshold)
440{
441   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
442   draw->pipeline.wide_line_threshold = roundf(threshold);
443}
444
445
446/**
447 * Tells the draw module whether or not to implement line stipple.
448 */
449void
450draw_enable_line_stipple(struct draw_context *draw, boolean enable)
451{
452   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
453   draw->pipeline.line_stipple = enable;
454}
455
456
457/**
458 * Tells draw module whether to convert points to quads for sprite mode.
459 */
460void
461draw_enable_point_sprites(struct draw_context *draw, boolean enable)
462{
463   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
464   draw->pipeline.point_sprite = enable;
465}
466
467
468void
469draw_set_force_passthrough( struct draw_context *draw, boolean enable )
470{
471   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
472   draw->force_passthrough = enable;
473}
474
475
476
477/**
478 * Allocate an extra vertex/geometry shader vertex attribute, if it doesn't
479 * exist already.
480 *
481 * This is used by some of the optional draw module stages such
482 * as wide_point which may need to allocate additional generic/texcoord
483 * attributes.
484 */
485int
486draw_alloc_extra_vertex_attrib(struct draw_context *draw,
487                               uint semantic_name, uint semantic_index)
488{
489   int slot;
490   uint num_outputs;
491   uint n;
492
493   slot = draw_find_shader_output(draw, semantic_name, semantic_index);
494   if (slot > 0) {
495      return slot;
496   }
497
498   num_outputs = draw_current_shader_outputs(draw);
499   n = draw->extra_shader_outputs.num;
500
501   assert(n < Elements(draw->extra_shader_outputs.semantic_name));
502
503   draw->extra_shader_outputs.semantic_name[n] = semantic_name;
504   draw->extra_shader_outputs.semantic_index[n] = semantic_index;
505   draw->extra_shader_outputs.slot[n] = num_outputs + n;
506   draw->extra_shader_outputs.num++;
507
508   return draw->extra_shader_outputs.slot[n];
509}
510
511
512/**
513 * Remove all extra vertex attributes that were allocated with
514 * draw_alloc_extra_vertex_attrib().
515 */
516void
517draw_remove_extra_vertex_attribs(struct draw_context *draw)
518{
519   draw->extra_shader_outputs.num = 0;
520}
521
522
523/**
524 * If a geometry shader is present, return its info, else the vertex shader's
525 * info.
526 */
527struct tgsi_shader_info *
528draw_get_shader_info(const struct draw_context *draw)
529{
530
531   if (draw->gs.geometry_shader) {
532      return &draw->gs.geometry_shader->info;
533   } else {
534      return &draw->vs.vertex_shader->info;
535   }
536}
537
538
539/**
540 * Ask the draw module for the location/slot of the given vertex attribute in
541 * a post-transformed vertex.
542 *
543 * With this function, drivers that use the draw module should have no reason
544 * to track the current vertex/geometry shader.
545 *
546 * Note that the draw module may sometimes generate vertices with extra
547 * attributes (such as texcoords for AA lines).  The driver can call this
548 * function to find those attributes.
549 *
550 * Zero is returned if the attribute is not found since this is
551 * a don't care / undefined situtation.  Returning -1 would be a bit more
552 * work for the drivers.
553 */
554int
555draw_find_shader_output(const struct draw_context *draw,
556                        uint semantic_name, uint semantic_index)
557{
558   const struct tgsi_shader_info *info = draw_get_shader_info(draw);
559   uint i;
560
561   for (i = 0; i < info->num_outputs; i++) {
562      if (info->output_semantic_name[i] == semantic_name &&
563          info->output_semantic_index[i] == semantic_index)
564         return i;
565   }
566
567   /* Search the extra vertex attributes */
568   for (i = 0; i < draw->extra_shader_outputs.num; i++) {
569      if (draw->extra_shader_outputs.semantic_name[i] == semantic_name &&
570          draw->extra_shader_outputs.semantic_index[i] == semantic_index) {
571         return draw->extra_shader_outputs.slot[i];
572      }
573   }
574
575   return 0;
576}
577
578
579/**
580 * Return total number of the shader outputs.  This function is similar to
581 * draw_current_shader_outputs() but this function also counts any extra
582 * vertex/geometry output attributes that may be filled in by some draw
583 * stages (such as AA point, AA line).
584 *
585 * If geometry shader is present, its output will be returned,
586 * if not vertex shader is used.
587 */
588uint
589draw_num_shader_outputs(const struct draw_context *draw)
590{
591   const struct tgsi_shader_info *info = draw_get_shader_info(draw);
592   uint count;
593
594   count = info->num_outputs;
595   count += draw->extra_shader_outputs.num;
596
597   return count;
598}
599
600
601/**
602 * Provide TGSI sampler objects for vertex/geometry shaders that use
603 * texture fetches.
604 * This might only be used by software drivers for the time being.
605 */
606void
607draw_texture_samplers(struct draw_context *draw,
608                      uint shader,
609                      uint num_samplers,
610                      struct tgsi_sampler **samplers)
611{
612   if (shader == PIPE_SHADER_VERTEX) {
613      draw->vs.num_samplers = num_samplers;
614      draw->vs.samplers = samplers;
615   } else {
616      debug_assert(shader == PIPE_SHADER_GEOMETRY);
617      draw->gs.num_samplers = num_samplers;
618      draw->gs.samplers = samplers;
619   }
620}
621
622
623
624
625void draw_set_render( struct draw_context *draw,
626		      struct vbuf_render *render )
627{
628   draw->render = render;
629}
630
631
632void
633draw_set_index_buffer(struct draw_context *draw,
634                      const struct pipe_index_buffer *ib)
635{
636   if (ib)
637      memcpy(&draw->pt.index_buffer, ib, sizeof(draw->pt.index_buffer));
638   else
639      memset(&draw->pt.index_buffer, 0, sizeof(draw->pt.index_buffer));
640}
641
642
643/**
644 * Tell drawing context where to find mapped index/element buffer.
645 */
646void
647draw_set_mapped_index_buffer(struct draw_context *draw,
648                             const void *elements)
649{
650    draw->pt.user.elts = elements;
651}
652
653
654/* Revamp me please:
655 */
656void draw_do_flush( struct draw_context *draw, unsigned flags )
657{
658   if (!draw->suspend_flushing)
659   {
660      assert(!draw->flushing); /* catch inadvertant recursion */
661
662      draw->flushing = TRUE;
663
664      draw_pipeline_flush( draw, flags );
665
666      draw->reduced_prim = ~0; /* is reduced_prim needed any more? */
667
668      draw->flushing = FALSE;
669   }
670}
671
672
673/**
674 * Return the number of output attributes produced by the geometry
675 * shader, if present.  If no geometry shader, return the number of
676 * outputs from the vertex shader.
677 * \sa draw_num_shader_outputs
678 */
679uint
680draw_current_shader_outputs(const struct draw_context *draw)
681{
682   if (draw->gs.geometry_shader)
683      return draw->gs.num_gs_outputs;
684   return draw->vs.num_vs_outputs;
685}
686
687
688/**
689 * Return the index of the shader output which will contain the
690 * vertex position.
691 */
692uint
693draw_current_shader_position_output(const struct draw_context *draw)
694{
695   if (draw->gs.geometry_shader)
696      return draw->gs.position_output;
697   return draw->vs.position_output;
698}
699
700
701/**
702 * Return a pointer/handle for a driver/CSO rasterizer object which
703 * disabled culling, stippling, unfilled tris, etc.
704 * This is used by some pipeline stages (such as wide_point, aa_line
705 * and aa_point) which convert points/lines into triangles.  In those
706 * cases we don't want to accidentally cull the triangles.
707 *
708 * \param scissor  should the rasterizer state enable scissoring?
709 * \param flatshade  should the rasterizer state use flat shading?
710 * \return  rasterizer CSO handle
711 */
712void *
713draw_get_rasterizer_no_cull( struct draw_context *draw,
714                             boolean scissor,
715                             boolean flatshade )
716{
717   if (!draw->rasterizer_no_cull[scissor][flatshade]) {
718      /* create now */
719      struct pipe_context *pipe = draw->pipe;
720      struct pipe_rasterizer_state rast;
721
722      memset(&rast, 0, sizeof(rast));
723      rast.scissor = scissor;
724      rast.flatshade = flatshade;
725      rast.front_ccw = 1;
726      rast.gl_rasterization_rules = draw->rasterizer->gl_rasterization_rules;
727
728      draw->rasterizer_no_cull[scissor][flatshade] =
729         pipe->create_rasterizer_state(pipe, &rast);
730   }
731   return draw->rasterizer_no_cull[scissor][flatshade];
732}
733
734void
735draw_set_mapped_so_buffers(struct draw_context *draw,
736                           void *buffers[PIPE_MAX_SO_BUFFERS],
737                           unsigned num_buffers)
738{
739   int i;
740
741   for (i = 0; i < num_buffers; ++i) {
742      draw->so.buffers[i] = buffers[i];
743   }
744   draw->so.num_buffers = num_buffers;
745}
746
747void
748draw_set_so_state(struct draw_context *draw,
749                  struct pipe_stream_output_info *state)
750{
751   memcpy(&draw->so.state,
752          state,
753          sizeof(struct pipe_stream_output_info));
754}
755
756void
757draw_set_sampler_views(struct draw_context *draw,
758                       struct pipe_sampler_view **views,
759                       unsigned num)
760{
761   unsigned i;
762
763   debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
764
765   for (i = 0; i < num; ++i)
766      draw->sampler_views[i] = views[i];
767   for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
768      draw->sampler_views[i] = NULL;
769
770   draw->num_sampler_views = num;
771}
772
773void
774draw_set_samplers(struct draw_context *draw,
775                  struct pipe_sampler_state **samplers,
776                  unsigned num)
777{
778   unsigned i;
779
780   debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
781
782   for (i = 0; i < num; ++i)
783      draw->samplers[i] = samplers[i];
784   for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
785      draw->samplers[i] = NULL;
786
787   draw->num_samplers = num;
788
789#ifdef HAVE_LLVM
790   if (draw->llvm)
791      draw_llvm_set_sampler_state(draw);
792#endif
793}
794
795void
796draw_set_mapped_texture(struct draw_context *draw,
797                        unsigned sampler_idx,
798                        uint32_t width, uint32_t height, uint32_t depth,
799                        uint32_t first_level, uint32_t last_level,
800                        uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
801                        uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
802                        const void *data[PIPE_MAX_TEXTURE_LEVELS])
803{
804#ifdef HAVE_LLVM
805   if(draw->llvm)
806      draw_llvm_set_mapped_texture(draw,
807                                sampler_idx,
808                                width, height, depth, first_level, last_level,
809                                row_stride, img_stride, data);
810#endif
811}
812