dfa8927bc0808f63c44c980ba91addee5a64784a
[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 static 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_samplers(struct draw_context *draw,
585 uint shader,
586 uint num_samplers,
587 struct tgsi_sampler **samplers)
588 {
589 if (shader == PIPE_SHADER_VERTEX) {
590 draw->vs.tgsi.num_samplers = num_samplers;
591 draw->vs.tgsi.samplers = samplers;
592 } else {
593 debug_assert(shader == PIPE_SHADER_GEOMETRY);
594 draw->gs.tgsi.num_samplers = num_samplers;
595 draw->gs.tgsi.samplers = samplers;
596 }
597 }
598
599
600
601
602 void draw_set_render( struct draw_context *draw,
603 struct vbuf_render *render )
604 {
605 draw->render = render;
606 }
607
608
609 /**
610 * Tell the draw module where vertex indexes/elements are located, and
611 * their size (in bytes).
612 *
613 * Note: the caller must apply the pipe_index_buffer::offset value to
614 * the address. The draw module doesn't do that.
615 */
616 void
617 draw_set_indexes(struct draw_context *draw,
618 const void *elements, unsigned elem_size)
619 {
620 assert(elem_size == 0 ||
621 elem_size == 1 ||
622 elem_size == 2 ||
623 elem_size == 4);
624 draw->pt.user.elts = elements;
625 draw->pt.user.eltSizeIB = elem_size;
626 }
627
628
629 /* Revamp me please:
630 */
631 void draw_do_flush( struct draw_context *draw, unsigned flags )
632 {
633 if (!draw->suspend_flushing)
634 {
635 assert(!draw->flushing); /* catch inadvertant recursion */
636
637 draw->flushing = TRUE;
638
639 draw_pipeline_flush( draw, flags );
640
641 draw_pt_flush( draw, flags );
642
643 draw->flushing = FALSE;
644 }
645 }
646
647
648 /**
649 * Return the number of output attributes produced by the geometry
650 * shader, if present. If no geometry shader, return the number of
651 * outputs from the vertex shader.
652 * \sa draw_num_shader_outputs
653 */
654 uint
655 draw_current_shader_outputs(const struct draw_context *draw)
656 {
657 if (draw->gs.geometry_shader)
658 return draw->gs.num_gs_outputs;
659 return draw->vs.num_vs_outputs;
660 }
661
662
663 /**
664 * Return the index of the shader output which will contain the
665 * vertex position.
666 */
667 uint
668 draw_current_shader_position_output(const struct draw_context *draw)
669 {
670 if (draw->gs.geometry_shader)
671 return draw->gs.position_output;
672 return draw->vs.position_output;
673 }
674
675
676 /**
677 * Return the index of the shader output which will contain the
678 * vertex position.
679 */
680 uint
681 draw_current_shader_clipvertex_output(const struct draw_context *draw)
682 {
683 return draw->vs.clipvertex_output;
684 }
685
686 uint
687 draw_current_shader_clipdistance_output(const struct draw_context *draw, int index)
688 {
689 return draw->vs.clipdistance_output[index];
690 }
691
692 /**
693 * Return a pointer/handle for a driver/CSO rasterizer object which
694 * disabled culling, stippling, unfilled tris, etc.
695 * This is used by some pipeline stages (such as wide_point, aa_line
696 * and aa_point) which convert points/lines into triangles. In those
697 * cases we don't want to accidentally cull the triangles.
698 *
699 * \param scissor should the rasterizer state enable scissoring?
700 * \param flatshade should the rasterizer state use flat shading?
701 * \return rasterizer CSO handle
702 */
703 void *
704 draw_get_rasterizer_no_cull( struct draw_context *draw,
705 boolean scissor,
706 boolean flatshade )
707 {
708 if (!draw->rasterizer_no_cull[scissor][flatshade]) {
709 /* create now */
710 struct pipe_context *pipe = draw->pipe;
711 struct pipe_rasterizer_state rast;
712
713 memset(&rast, 0, sizeof(rast));
714 rast.scissor = scissor;
715 rast.flatshade = flatshade;
716 rast.front_ccw = 1;
717 rast.gl_rasterization_rules = draw->rasterizer->gl_rasterization_rules;
718
719 draw->rasterizer_no_cull[scissor][flatshade] =
720 pipe->create_rasterizer_state(pipe, &rast);
721 }
722 return draw->rasterizer_no_cull[scissor][flatshade];
723 }
724
725 void
726 draw_set_mapped_so_targets(struct draw_context *draw,
727 int num_targets,
728 struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS])
729 {
730 int i;
731
732 for (i = 0; i < num_targets; i++)
733 draw->so.targets[i] = targets[i];
734 for (i = num_targets; i < PIPE_MAX_SO_BUFFERS; i++)
735 draw->so.targets[i] = NULL;
736
737 draw->so.num_targets = num_targets;
738 }
739
740 void
741 draw_set_mapped_so_buffers(struct draw_context *draw,
742 void *buffers[PIPE_MAX_SO_BUFFERS],
743 unsigned num_buffers)
744 {
745 }
746
747 void
748 draw_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
756 void
757 draw_set_sampler_views(struct draw_context *draw,
758 unsigned shader_stage,
759 struct pipe_sampler_view **views,
760 unsigned num)
761 {
762 unsigned i;
763
764 debug_assert(shader_stage < PIPE_SHADER_TYPES);
765 debug_assert(num <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
766
767 for (i = 0; i < num; ++i)
768 draw->sampler_views[shader_stage][i] = views[i];
769 for (i = num; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; ++i)
770 draw->sampler_views[shader_stage][i] = NULL;
771
772 draw->num_sampler_views[shader_stage] = num;
773 }
774
775 void
776 draw_set_samplers(struct draw_context *draw,
777 unsigned shader_stage,
778 struct pipe_sampler_state **samplers,
779 unsigned num)
780 {
781 unsigned i;
782
783 debug_assert(shader_stage < PIPE_SHADER_TYPES);
784 debug_assert(num <= PIPE_MAX_SAMPLERS);
785
786 for (i = 0; i < num; ++i)
787 draw->samplers[shader_stage][i] = samplers[i];
788 for (i = num; i < PIPE_MAX_SAMPLERS; ++i)
789 draw->samplers[shader_stage][i] = NULL;
790
791 draw->num_samplers[shader_stage] = num;
792
793 #ifdef HAVE_LLVM
794 if (draw->llvm && shader_stage == PIPE_SHADER_VERTEX)
795 draw_llvm_set_sampler_state(draw);
796 #endif
797 }
798
799 void
800 draw_set_mapped_texture(struct draw_context *draw,
801 unsigned shader_stage,
802 unsigned sampler_idx,
803 uint32_t width, uint32_t height, uint32_t depth,
804 uint32_t first_level, uint32_t last_level,
805 const void *base_ptr,
806 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
807 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
808 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
809 {
810 if (shader_stage == PIPE_SHADER_VERTEX) {
811 #ifdef HAVE_LLVM
812 if (draw->llvm)
813 draw_llvm_set_mapped_texture(draw,
814 sampler_idx,
815 width, height, depth, first_level,
816 last_level, base_ptr,
817 row_stride, img_stride, mip_offsets);
818 #endif
819 }
820 }
821
822 /**
823 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
824 * different ways of setting textures, and drivers typically only support one.
825 */
826 int
827 draw_get_shader_param_no_llvm(unsigned shader, enum pipe_shader_cap param)
828 {
829 switch(shader) {
830 case PIPE_SHADER_VERTEX:
831 case PIPE_SHADER_GEOMETRY:
832 return tgsi_exec_get_shader_param(param);
833 default:
834 return 0;
835 }
836 }
837
838 /**
839 * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
840 * different ways of setting textures, and drivers typically only support one.
841 */
842 int
843 draw_get_shader_param(unsigned shader, enum pipe_shader_cap param)
844 {
845
846 #ifdef HAVE_LLVM
847 if (draw_get_option_use_llvm()) {
848 switch(shader) {
849 case PIPE_SHADER_VERTEX:
850 case PIPE_SHADER_GEOMETRY:
851 return gallivm_get_shader_param(param);
852 default:
853 return 0;
854 }
855 }
856 #endif
857
858 return draw_get_shader_param_no_llvm(shader, param);
859 }
860