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