14a49301eSmrg/**************************************************************************
24a49301eSmrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
134a49301eSmrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
174a49301eSmrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254a49301eSmrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
284a49301eSmrg /*
294a49301eSmrg  * Authors:
30af69d88dSmrg  *   Keith Whitwell <keithw@vmware.com>
314a49301eSmrg  */
324a49301eSmrg
334a49301eSmrg
34cdc920a0Smrg#include "pipe/p_context.h"
354a49301eSmrg#include "util/u_memory.h"
364a49301eSmrg#include "util/u_math.h"
373464ebd5Sriastradh#include "util/u_cpu_detect.h"
383464ebd5Sriastradh#include "util/u_inlines.h"
39af69d88dSmrg#include "util/u_helpers.h"
40af69d88dSmrg#include "util/u_prim.h"
417ec681f3Smrg#include "util/format/u_format.h"
424a49301eSmrg#include "draw_context.h"
43af69d88dSmrg#include "draw_pipe.h"
44af69d88dSmrg#include "draw_prim_assembler.h"
454a49301eSmrg#include "draw_vs.h"
46cdc920a0Smrg#include "draw_gs.h"
477ec681f3Smrg#include "draw_tess.h"
484a49301eSmrg
497ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
503464ebd5Sriastradh#include "gallivm/lp_bld_init.h"
51af69d88dSmrg#include "gallivm/lp_bld_limits.h"
523464ebd5Sriastradh#include "draw_llvm.h"
534a49301eSmrg
54af69d88dSmrgboolean
553464ebd5Sriastradhdraw_get_option_use_llvm(void)
563464ebd5Sriastradh{
5701e04c3fSmrg   return debug_get_bool_option("DRAW_USE_LLVM", TRUE);
583464ebd5Sriastradh}
59af69d88dSmrg#else
60af69d88dSmrgboolean
61af69d88dSmrgdraw_get_option_use_llvm(void)
623464ebd5Sriastradh{
63af69d88dSmrg   return FALSE;
643464ebd5Sriastradh}
65af69d88dSmrg#endif
663464ebd5Sriastradh
677ec681f3Smrgbool
687ec681f3Smrgdraw_has_llvm(void)
697ec681f3Smrg{
707ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
717ec681f3Smrg   return draw_get_option_use_llvm();
727ec681f3Smrg#else
737ec681f3Smrg   return false;
747ec681f3Smrg#endif
757ec681f3Smrg}
763464ebd5Sriastradh
773464ebd5Sriastradh/**
783464ebd5Sriastradh * Create new draw module context with gallivm state for LLVM JIT.
793464ebd5Sriastradh */
80af69d88dSmrgstatic struct draw_context *
8101e04c3fSmrgdraw_create_context(struct pipe_context *pipe, void *context,
8201e04c3fSmrg                    boolean try_llvm)
834a49301eSmrg{
844a49301eSmrg   struct draw_context *draw = CALLOC_STRUCT( draw_context );
8501e04c3fSmrg   if (!draw)
86af69d88dSmrg      goto err_out;
874a49301eSmrg
88af69d88dSmrg   /* we need correct cpu caps for disabling denorms in draw_vbo() */
89af69d88dSmrg   util_cpu_detect();
903464ebd5Sriastradh
917ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
92af69d88dSmrg   if (try_llvm && draw_get_option_use_llvm()) {
9301e04c3fSmrg      draw->llvm = draw_llvm_create(draw, (LLVMContextRef)context);
943464ebd5Sriastradh   }
953464ebd5Sriastradh#endif
963464ebd5Sriastradh
97af69d88dSmrg   draw->pipe = pipe;
987ec681f3Smrg   draw->constant_buffer_stride = (sizeof(float) * 4);
99af69d88dSmrg
1003464ebd5Sriastradh   if (!draw_init(draw))
101af69d88dSmrg      goto err_destroy;
1023464ebd5Sriastradh
103af69d88dSmrg   draw->ia = draw_prim_assembler_create(draw);
104af69d88dSmrg   if (!draw->ia)
105af69d88dSmrg      goto err_destroy;
1063464ebd5Sriastradh
1073464ebd5Sriastradh   return draw;
1083464ebd5Sriastradh
109af69d88dSmrgerr_destroy:
1103464ebd5Sriastradh   draw_destroy( draw );
111af69d88dSmrgerr_out:
1123464ebd5Sriastradh   return NULL;
1133464ebd5Sriastradh}
1143464ebd5Sriastradh
1153464ebd5Sriastradh
116af69d88dSmrg/**
117af69d88dSmrg * Create new draw module context, with LLVM JIT.
118af69d88dSmrg */
119af69d88dSmrgstruct draw_context *
120af69d88dSmrgdraw_create(struct pipe_context *pipe)
121af69d88dSmrg{
12201e04c3fSmrg   return draw_create_context(pipe, NULL, TRUE);
123af69d88dSmrg}
124af69d88dSmrg
125af69d88dSmrg
1267ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
12701e04c3fSmrgstruct draw_context *
12801e04c3fSmrgdraw_create_with_llvm_context(struct pipe_context *pipe,
12901e04c3fSmrg                              void *context)
13001e04c3fSmrg{
13101e04c3fSmrg   return draw_create_context(pipe, context, TRUE);
13201e04c3fSmrg}
13301e04c3fSmrg#endif
13401e04c3fSmrg
135af69d88dSmrg/**
136af69d88dSmrg * Create a new draw context, without LLVM JIT.
137af69d88dSmrg */
138af69d88dSmrgstruct draw_context *
139af69d88dSmrgdraw_create_no_llvm(struct pipe_context *pipe)
140af69d88dSmrg{
14101e04c3fSmrg   return draw_create_context(pipe, NULL, FALSE);
142af69d88dSmrg}
143af69d88dSmrg
1443464ebd5Sriastradh
1453464ebd5Sriastradhboolean draw_init(struct draw_context *draw)
1463464ebd5Sriastradh{
1473464ebd5Sriastradh   /*
1483464ebd5Sriastradh    * Note that several functions compute the clipmask of the predefined
1493464ebd5Sriastradh    * formats with hardcoded formulas instead of using these. So modifications
1503464ebd5Sriastradh    * here must be reflected there too.
1513464ebd5Sriastradh    */
1523464ebd5Sriastradh
1534a49301eSmrg   ASSIGN_4V( draw->plane[0], -1,  0,  0, 1 );
1544a49301eSmrg   ASSIGN_4V( draw->plane[1],  1,  0,  0, 1 );
1554a49301eSmrg   ASSIGN_4V( draw->plane[2],  0, -1,  0, 1 );
1564a49301eSmrg   ASSIGN_4V( draw->plane[3],  0,  1,  0, 1 );
1574a49301eSmrg   ASSIGN_4V( draw->plane[4],  0,  0,  1, 1 ); /* yes these are correct */
1584a49301eSmrg   ASSIGN_4V( draw->plane[5],  0,  0, -1, 1 ); /* mesa's a bit wonky */
1593464ebd5Sriastradh   draw->clip_xy = TRUE;
1603464ebd5Sriastradh   draw->clip_z = TRUE;
1614a49301eSmrg
162af69d88dSmrg   draw->pt.user.planes = (float (*) [DRAW_TOTAL_CLIP_PLANES][4]) &(draw->plane[0]);
163af69d88dSmrg   draw->pt.user.eltMax = ~0;
1644a49301eSmrg
1654a49301eSmrg   if (!draw_pipeline_init( draw ))
1663464ebd5Sriastradh      return FALSE;
1674a49301eSmrg
1684a49301eSmrg   if (!draw_pt_init( draw ))
1693464ebd5Sriastradh      return FALSE;
1704a49301eSmrg
1714a49301eSmrg   if (!draw_vs_init( draw ))
1723464ebd5Sriastradh      return FALSE;
1734a49301eSmrg
174cdc920a0Smrg   if (!draw_gs_init( draw ))
1753464ebd5Sriastradh      return FALSE;
176cdc920a0Smrg
177af69d88dSmrg   draw->quads_always_flatshade_last = !draw->pipe->screen->get_param(
178af69d88dSmrg      draw->pipe->screen, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
179af69d88dSmrg
180af69d88dSmrg   draw->floating_point_depth = false;
181af69d88dSmrg
1823464ebd5Sriastradh   return TRUE;
1834a49301eSmrg}
1844a49301eSmrg
185af69d88dSmrg/*
186af69d88dSmrg * Called whenever we're starting to draw a new instance.
187af69d88dSmrg * Some internal structures don't want to have to reset internal
188af69d88dSmrg * members on each invocation (because their state might have to persist
189af69d88dSmrg * between multiple primitive restart rendering call) but might have to
190af69d88dSmrg * for each new instance.
191af69d88dSmrg * This is particularly the case for primitive id's in geometry shader.
192af69d88dSmrg */
193af69d88dSmrgvoid draw_new_instance(struct draw_context *draw)
194af69d88dSmrg{
195af69d88dSmrg   draw_geometry_shader_new_instance(draw->gs.geometry_shader);
19601e04c3fSmrg   draw_prim_assembler_new_instance(draw->ia);
197af69d88dSmrg}
198af69d88dSmrg
1994a49301eSmrg
2004a49301eSmrgvoid draw_destroy( struct draw_context *draw )
2014a49301eSmrg{
2023464ebd5Sriastradh   struct pipe_context *pipe;
2037ec681f3Smrg   unsigned i, j, k;
204cdc920a0Smrg
2054a49301eSmrg   if (!draw)
2064a49301eSmrg      return;
2074a49301eSmrg
2083464ebd5Sriastradh   pipe = draw->pipe;
2093464ebd5Sriastradh
210cdc920a0Smrg   /* free any rasterizer CSOs that we may have created.
211cdc920a0Smrg    */
212cdc920a0Smrg   for (i = 0; i < 2; i++) {
213cdc920a0Smrg      for (j = 0; j < 2; j++) {
2147ec681f3Smrg         for (k = 0; k < 2; k++) {
2157ec681f3Smrg            if (draw->rasterizer_no_cull[i][j][k]) {
2167ec681f3Smrg               pipe->delete_rasterizer_state(pipe, draw->rasterizer_no_cull[i][j][k]);
2177ec681f3Smrg            }
218cdc920a0Smrg         }
219cdc920a0Smrg      }
220cdc920a0Smrg   }
2214a49301eSmrg
22201e04c3fSmrg   for (i = 0; i < draw->pt.nr_vertex_buffers; i++)
22301e04c3fSmrg      pipe_vertex_buffer_unreference(&draw->pt.vertex_buffer[i]);
2243464ebd5Sriastradh
2254a49301eSmrg   /* Not so fast -- we're just borrowing this at the moment.
2264a49301eSmrg    *
2274a49301eSmrg   if (draw->render)
2284a49301eSmrg      draw->render->destroy( draw->render );
2294a49301eSmrg   */
2304a49301eSmrg
231af69d88dSmrg   draw_prim_assembler_destroy(draw->ia);
2324a49301eSmrg   draw_pipeline_destroy( draw );
2334a49301eSmrg   draw_pt_destroy( draw );
2344a49301eSmrg   draw_vs_destroy( draw );
235cdc920a0Smrg   draw_gs_destroy( draw );
2367ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
2373464ebd5Sriastradh   if (draw->llvm)
2383464ebd5Sriastradh      draw_llvm_destroy( draw->llvm );
2393464ebd5Sriastradh#endif
2404a49301eSmrg
2414a49301eSmrg   FREE( draw );
2424a49301eSmrg}
2434a49301eSmrg
2444a49301eSmrg
2454a49301eSmrg
2464a49301eSmrgvoid draw_flush( struct draw_context *draw )
2474a49301eSmrg{
2484a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_BACKEND );
2494a49301eSmrg}
2504a49301eSmrg
2514a49301eSmrg
2524a49301eSmrg/**
253af69d88dSmrg * Specify the depth stencil format for the draw pipeline. This function
254af69d88dSmrg * determines the Minimum Resolvable Depth factor for polygon offset.
2554a49301eSmrg * This factor potentially depends on the number of Z buffer bits,
2564a49301eSmrg * the rasterization algorithm and the arithmetic performed on Z
257af69d88dSmrg * values between vertex shading and rasterization.
2584a49301eSmrg */
259af69d88dSmrgvoid draw_set_zs_format(struct draw_context *draw, enum pipe_format format)
2604a49301eSmrg{
261af69d88dSmrg   const struct util_format_description *desc = util_format_description(format);
262af69d88dSmrg
263af69d88dSmrg   draw->floating_point_depth =
264af69d88dSmrg      (util_get_depth_format_type(desc) == UTIL_FORMAT_TYPE_FLOAT);
265af69d88dSmrg
266af69d88dSmrg   draw->mrd = util_get_depth_format_mrd(desc);
2674a49301eSmrg}
2684a49301eSmrg
2694a49301eSmrg
27001e04c3fSmrgstatic bool
27101e04c3fSmrgdraw_is_vs_window_space(struct draw_context *draw)
27201e04c3fSmrg{
27301e04c3fSmrg   if (draw->vs.vertex_shader) {
27401e04c3fSmrg      struct tgsi_shader_info *info = &draw->vs.vertex_shader->info;
27501e04c3fSmrg
27601e04c3fSmrg      return info->properties[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION] != 0;
27701e04c3fSmrg   }
27801e04c3fSmrg   return false;
27901e04c3fSmrg}
28001e04c3fSmrg
28101e04c3fSmrg
28201e04c3fSmrgvoid
28301e04c3fSmrgdraw_update_clip_flags(struct draw_context *draw)
2843464ebd5Sriastradh{
28501e04c3fSmrg   bool window_space = draw_is_vs_window_space(draw);
28601e04c3fSmrg
28701e04c3fSmrg   draw->clip_xy = !draw->driver.bypass_clip_xy && !window_space;
288af69d88dSmrg   draw->guard_band_xy = (!draw->driver.bypass_clip_xy &&
289af69d88dSmrg                          draw->driver.guard_band_xy);
2903464ebd5Sriastradh   draw->clip_z = (!draw->driver.bypass_clip_z &&
29101e04c3fSmrg                   draw->rasterizer && draw->rasterizer->depth_clip_near) &&
29201e04c3fSmrg                  !window_space;
293af69d88dSmrg   draw->clip_user = draw->rasterizer &&
29401e04c3fSmrg                     draw->rasterizer->clip_plane_enable != 0 &&
29501e04c3fSmrg                     !window_space;
296af69d88dSmrg   draw->guard_band_points_xy = draw->guard_band_xy ||
297af69d88dSmrg                                (draw->driver.bypass_clip_points &&
298af69d88dSmrg                                (draw->rasterizer &&
299af69d88dSmrg                                 draw->rasterizer->point_tri_clip));
3003464ebd5Sriastradh}
3013464ebd5Sriastradh
30201e04c3fSmrg
30301e04c3fSmrgvoid
30401e04c3fSmrgdraw_update_viewport_flags(struct draw_context *draw)
30501e04c3fSmrg{
30601e04c3fSmrg   bool window_space = draw_is_vs_window_space(draw);
30701e04c3fSmrg
30801e04c3fSmrg   draw->bypass_viewport = window_space || draw->identity_viewport;
30901e04c3fSmrg}
31001e04c3fSmrg
31101e04c3fSmrg
3124a49301eSmrg/**
3134a49301eSmrg * Register new primitive rasterization/rendering state.
3144a49301eSmrg * This causes the drawing pipeline to be rebuilt.
3154a49301eSmrg */
3164a49301eSmrgvoid draw_set_rasterizer_state( struct draw_context *draw,
317cdc920a0Smrg                                const struct pipe_rasterizer_state *raster,
318cdc920a0Smrg                                void *rast_handle )
3194a49301eSmrg{
320cdc920a0Smrg   if (!draw->suspend_flushing) {
321cdc920a0Smrg      draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
322cdc920a0Smrg
323cdc920a0Smrg      draw->rasterizer = raster;
324cdc920a0Smrg      draw->rast_handle = rast_handle;
32501e04c3fSmrg      draw_update_clip_flags(draw);
326af69d88dSmrg   }
3274a49301eSmrg}
3284a49301eSmrg
3293464ebd5Sriastradh/* With a little more work, llvmpipe will be able to turn this off and
3303464ebd5Sriastradh * do its own x/y clipping.
3313464ebd5Sriastradh *
3323464ebd5Sriastradh * Some hardware can turn off clipping altogether - in particular any
3333464ebd5Sriastradh * hardware with a TNL unit can do its own clipping, even if it is
3343464ebd5Sriastradh * relying on the draw module for some other reason.
335af69d88dSmrg * Setting bypass_clip_points to achieve d3d-style point clipping (the driver
336af69d88dSmrg * will need to do the "vp scissoring") _requires_ the driver to implement
337af69d88dSmrg * wide points / point sprites itself (points will still be clipped if rasterizer
338af69d88dSmrg * point_tri_clip isn't set). Only relevant if bypass_clip_xy isn't set.
3393464ebd5Sriastradh */
3404a49301eSmrgvoid draw_set_driver_clipping( struct draw_context *draw,
3413464ebd5Sriastradh                               boolean bypass_clip_xy,
342af69d88dSmrg                               boolean bypass_clip_z,
343af69d88dSmrg                               boolean guard_band_xy,
344af69d88dSmrg                               boolean bypass_clip_points)
3454a49301eSmrg{
3464a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
3474a49301eSmrg
3483464ebd5Sriastradh   draw->driver.bypass_clip_xy = bypass_clip_xy;
3493464ebd5Sriastradh   draw->driver.bypass_clip_z = bypass_clip_z;
350af69d88dSmrg   draw->driver.guard_band_xy = guard_band_xy;
351af69d88dSmrg   draw->driver.bypass_clip_points = bypass_clip_points;
35201e04c3fSmrg   draw_update_clip_flags(draw);
3534a49301eSmrg}
3544a49301eSmrg
3554a49301eSmrg
3564a49301eSmrg/**
3574a49301eSmrg * Plug in the primitive rendering/rasterization stage (which is the last
3584a49301eSmrg * stage in the drawing pipeline).
3594a49301eSmrg * This is provided by the device driver.
3604a49301eSmrg */
3614a49301eSmrgvoid draw_set_rasterize_stage( struct draw_context *draw,
3624a49301eSmrg                               struct draw_stage *stage )
3634a49301eSmrg{
3644a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
3654a49301eSmrg
3664a49301eSmrg   draw->pipeline.rasterize = stage;
3674a49301eSmrg}
3684a49301eSmrg
3694a49301eSmrg
3704a49301eSmrg/**
3714a49301eSmrg * Set the draw module's clipping state.
3724a49301eSmrg */
3734a49301eSmrgvoid draw_set_clip_state( struct draw_context *draw,
3744a49301eSmrg                          const struct pipe_clip_state *clip )
3754a49301eSmrg{
376af69d88dSmrg   draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
3774a49301eSmrg
378af69d88dSmrg   memcpy(&draw->plane[6], clip->ucp, sizeof(clip->ucp));
3794a49301eSmrg}
3804a49301eSmrg
3814a49301eSmrg
3824a49301eSmrg/**
3834a49301eSmrg * Set the draw module's viewport state.
3844a49301eSmrg */
385af69d88dSmrgvoid draw_set_viewport_states( struct draw_context *draw,
386af69d88dSmrg                               unsigned start_slot,
387af69d88dSmrg                               unsigned num_viewports,
388af69d88dSmrg                               const struct pipe_viewport_state *vps )
3894a49301eSmrg{
390af69d88dSmrg   const struct pipe_viewport_state *viewport = vps;
391af69d88dSmrg   draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
392af69d88dSmrg
393af69d88dSmrg   debug_assert(start_slot < PIPE_MAX_VIEWPORTS);
394af69d88dSmrg   debug_assert((start_slot + num_viewports) <= PIPE_MAX_VIEWPORTS);
395af69d88dSmrg
396af69d88dSmrg   memcpy(draw->viewports + start_slot, vps,
397af69d88dSmrg          sizeof(struct pipe_viewport_state) * num_viewports);
398af69d88dSmrg
399af69d88dSmrg   draw->identity_viewport = (num_viewports == 1) &&
400af69d88dSmrg      (viewport->scale[0] == 1.0f &&
401af69d88dSmrg       viewport->scale[1] == 1.0f &&
402af69d88dSmrg       viewport->scale[2] == 1.0f &&
403af69d88dSmrg       viewport->translate[0] == 0.0f &&
404af69d88dSmrg       viewport->translate[1] == 0.0f &&
40501e04c3fSmrg       viewport->translate[2] == 0.0f);
40601e04c3fSmrg   draw_update_viewport_flags(draw);
4074a49301eSmrg}
4084a49301eSmrg
4094a49301eSmrg
4104a49301eSmrg
4114a49301eSmrgvoid
4124a49301eSmrgdraw_set_vertex_buffers(struct draw_context *draw,
413af69d88dSmrg                        unsigned start_slot, unsigned count,
4147ec681f3Smrg                        unsigned unbind_num_trailing_slots,
4154a49301eSmrg                        const struct pipe_vertex_buffer *buffers)
4164a49301eSmrg{
417af69d88dSmrg   assert(start_slot + count <= PIPE_MAX_ATTRIBS);
4184a49301eSmrg
419af69d88dSmrg   util_set_vertex_buffers_count(draw->pt.vertex_buffer,
420af69d88dSmrg                                 &draw->pt.nr_vertex_buffers,
4217ec681f3Smrg                                 buffers, start_slot, count,
4227ec681f3Smrg                                 unbind_num_trailing_slots, false);
4234a49301eSmrg}
4244a49301eSmrg
4254a49301eSmrg
4264a49301eSmrgvoid
4274a49301eSmrgdraw_set_vertex_elements(struct draw_context *draw,
4284a49301eSmrg                         unsigned count,
4294a49301eSmrg                         const struct pipe_vertex_element *elements)
4304a49301eSmrg{
4314a49301eSmrg   assert(count <= PIPE_MAX_ATTRIBS);
4324a49301eSmrg
433af69d88dSmrg   /* We could improve this by only flushing the frontend and the fetch part
434af69d88dSmrg    * of the middle. This would avoid recalculating the emit keys.*/
435af69d88dSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
436af69d88dSmrg
4374a49301eSmrg   memcpy(draw->pt.vertex_element, elements, count * sizeof(elements[0]));
4384a49301eSmrg   draw->pt.nr_vertex_elements = count;
4394a49301eSmrg}
4404a49301eSmrg
4414a49301eSmrg
4424a49301eSmrg/**
4434a49301eSmrg * Tell drawing context where to find mapped vertex buffers.
4444a49301eSmrg */
4454a49301eSmrgvoid
4464a49301eSmrgdraw_set_mapped_vertex_buffer(struct draw_context *draw,
447af69d88dSmrg                              unsigned attr, const void *buffer,
448af69d88dSmrg                              size_t size)
4494a49301eSmrg{
450af69d88dSmrg   draw->pt.user.vbuffer[attr].map  = buffer;
451af69d88dSmrg   draw->pt.user.vbuffer[attr].size = size;
4524a49301eSmrg}
4534a49301eSmrg
4544a49301eSmrg
4554a49301eSmrgvoid
4564a49301eSmrgdraw_set_mapped_constant_buffer(struct draw_context *draw,
45701e04c3fSmrg                                enum pipe_shader_type shader_type,
458cdc920a0Smrg                                unsigned slot,
459cdc920a0Smrg                                const void *buffer,
4604a49301eSmrg                                unsigned size )
4614a49301eSmrg{
462cdc920a0Smrg   debug_assert(shader_type == PIPE_SHADER_VERTEX ||
4637ec681f3Smrg                shader_type == PIPE_SHADER_GEOMETRY ||
4647ec681f3Smrg                shader_type == PIPE_SHADER_TESS_CTRL ||
4657ec681f3Smrg                shader_type == PIPE_SHADER_TESS_EVAL);
466cdc920a0Smrg   debug_assert(slot < PIPE_MAX_CONSTANT_BUFFERS);
467cdc920a0Smrg
468af69d88dSmrg   draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
469af69d88dSmrg
4703464ebd5Sriastradh   switch (shader_type) {
4713464ebd5Sriastradh   case PIPE_SHADER_VERTEX:
472cdc920a0Smrg      draw->pt.user.vs_constants[slot] = buffer;
4733464ebd5Sriastradh      draw->pt.user.vs_constants_size[slot] = size;
4743464ebd5Sriastradh      break;
4753464ebd5Sriastradh   case PIPE_SHADER_GEOMETRY:
476cdc920a0Smrg      draw->pt.user.gs_constants[slot] = buffer;
4773464ebd5Sriastradh      draw->pt.user.gs_constants_size[slot] = size;
4783464ebd5Sriastradh      break;
4797ec681f3Smrg   case PIPE_SHADER_TESS_CTRL:
4807ec681f3Smrg      draw->pt.user.tcs_constants[slot] = buffer;
4817ec681f3Smrg      draw->pt.user.tcs_constants_size[slot] = size;
4827ec681f3Smrg      break;
4837ec681f3Smrg   case PIPE_SHADER_TESS_EVAL:
4847ec681f3Smrg      draw->pt.user.tes_constants[slot] = buffer;
4857ec681f3Smrg      draw->pt.user.tes_constants_size[slot] = size;
4867ec681f3Smrg      break;
4873464ebd5Sriastradh   default:
4883464ebd5Sriastradh      assert(0 && "invalid shader type in draw_set_mapped_constant_buffer");
489cdc920a0Smrg   }
4904a49301eSmrg}
4914a49301eSmrg
4927ec681f3Smrgvoid
4937ec681f3Smrgdraw_set_mapped_shader_buffer(struct draw_context *draw,
4947ec681f3Smrg                              enum pipe_shader_type shader_type,
4957ec681f3Smrg                              unsigned slot,
4967ec681f3Smrg                              const void *buffer,
4977ec681f3Smrg                              unsigned size )
4987ec681f3Smrg{
4997ec681f3Smrg   debug_assert(shader_type == PIPE_SHADER_VERTEX ||
5007ec681f3Smrg                shader_type == PIPE_SHADER_GEOMETRY ||
5017ec681f3Smrg                shader_type == PIPE_SHADER_TESS_CTRL ||
5027ec681f3Smrg                shader_type == PIPE_SHADER_TESS_EVAL);
5037ec681f3Smrg   debug_assert(slot < PIPE_MAX_SHADER_BUFFERS);
5047ec681f3Smrg
5057ec681f3Smrg   draw_do_flush(draw, DRAW_FLUSH_PARAMETER_CHANGE);
5067ec681f3Smrg
5077ec681f3Smrg   switch (shader_type) {
5087ec681f3Smrg   case PIPE_SHADER_VERTEX:
5097ec681f3Smrg      draw->pt.user.vs_ssbos[slot] = buffer;
5107ec681f3Smrg      draw->pt.user.vs_ssbos_size[slot] = size;
5117ec681f3Smrg      break;
5127ec681f3Smrg   case PIPE_SHADER_GEOMETRY:
5137ec681f3Smrg      draw->pt.user.gs_ssbos[slot] = buffer;
5147ec681f3Smrg      draw->pt.user.gs_ssbos_size[slot] = size;
5157ec681f3Smrg      break;
5167ec681f3Smrg   case PIPE_SHADER_TESS_CTRL:
5177ec681f3Smrg      draw->pt.user.tcs_ssbos[slot] = buffer;
5187ec681f3Smrg      draw->pt.user.tcs_ssbos_size[slot] = size;
5197ec681f3Smrg      break;
5207ec681f3Smrg   case PIPE_SHADER_TESS_EVAL:
5217ec681f3Smrg      draw->pt.user.tes_ssbos[slot] = buffer;
5227ec681f3Smrg      draw->pt.user.tes_ssbos_size[slot] = size;
5237ec681f3Smrg      break;
5247ec681f3Smrg   default:
5257ec681f3Smrg      assert(0 && "invalid shader type in draw_set_mapped_shader_buffer");
5267ec681f3Smrg   }
5277ec681f3Smrg}
5284a49301eSmrg
5294a49301eSmrg/**
5304a49301eSmrg * Tells the draw module to draw points with triangles if their size
5314a49301eSmrg * is greater than this threshold.
5324a49301eSmrg */
5334a49301eSmrgvoid
5344a49301eSmrgdraw_wide_point_threshold(struct draw_context *draw, float threshold)
5354a49301eSmrg{
5364a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
5374a49301eSmrg   draw->pipeline.wide_point_threshold = threshold;
5384a49301eSmrg}
5394a49301eSmrg
5404a49301eSmrg
5413464ebd5Sriastradh/**
5423464ebd5Sriastradh * Should the draw module handle point->quad conversion for drawing sprites?
5433464ebd5Sriastradh */
5443464ebd5Sriastradhvoid
5453464ebd5Sriastradhdraw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite)
5463464ebd5Sriastradh{
5473464ebd5Sriastradh   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
5483464ebd5Sriastradh   draw->pipeline.wide_point_sprites = draw_sprite;
5493464ebd5Sriastradh}
5503464ebd5Sriastradh
5513464ebd5Sriastradh
5524a49301eSmrg/**
5534a49301eSmrg * Tells the draw module to draw lines with triangles if their width
5544a49301eSmrg * is greater than this threshold.
5554a49301eSmrg */
5564a49301eSmrgvoid
5574a49301eSmrgdraw_wide_line_threshold(struct draw_context *draw, float threshold)
5584a49301eSmrg{
5594a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
5603464ebd5Sriastradh   draw->pipeline.wide_line_threshold = roundf(threshold);
5614a49301eSmrg}
5624a49301eSmrg
5634a49301eSmrg
5644a49301eSmrg/**
5654a49301eSmrg * Tells the draw module whether or not to implement line stipple.
5664a49301eSmrg */
5674a49301eSmrgvoid
5684a49301eSmrgdraw_enable_line_stipple(struct draw_context *draw, boolean enable)
5694a49301eSmrg{
5704a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
5714a49301eSmrg   draw->pipeline.line_stipple = enable;
5724a49301eSmrg}
5734a49301eSmrg
5744a49301eSmrg
5754a49301eSmrg/**
5764a49301eSmrg * Tells draw module whether to convert points to quads for sprite mode.
5774a49301eSmrg */
5784a49301eSmrgvoid
5794a49301eSmrgdraw_enable_point_sprites(struct draw_context *draw, boolean enable)
5804a49301eSmrg{
5814a49301eSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
5824a49301eSmrg   draw->pipeline.point_sprite = enable;
5834a49301eSmrg}
5844a49301eSmrg
5854a49301eSmrg
5863464ebd5Sriastradh
5873464ebd5Sriastradh/**
588af69d88dSmrg * Allocate an extra vertex/geometry shader vertex attribute, if it doesn't
589af69d88dSmrg * exist already.
590af69d88dSmrg *
5913464ebd5Sriastradh * This is used by some of the optional draw module stages such
5923464ebd5Sriastradh * as wide_point which may need to allocate additional generic/texcoord
5933464ebd5Sriastradh * attributes.
5943464ebd5Sriastradh */
5953464ebd5Sriastradhint
5963464ebd5Sriastradhdraw_alloc_extra_vertex_attrib(struct draw_context *draw,
5973464ebd5Sriastradh                               uint semantic_name, uint semantic_index)
5983464ebd5Sriastradh{
599af69d88dSmrg   int slot;
600af69d88dSmrg   uint num_outputs;
601af69d88dSmrg   uint n;
602af69d88dSmrg
603af69d88dSmrg   slot = draw_find_shader_output(draw, semantic_name, semantic_index);
604af69d88dSmrg   if (slot >= 0) {
605af69d88dSmrg      return slot;
606af69d88dSmrg   }
607af69d88dSmrg
608af69d88dSmrg   num_outputs = draw_current_shader_outputs(draw);
609af69d88dSmrg   n = draw->extra_shader_outputs.num;
6103464ebd5Sriastradh
61101e04c3fSmrg   assert(n < ARRAY_SIZE(draw->extra_shader_outputs.semantic_name));
6123464ebd5Sriastradh
6133464ebd5Sriastradh   draw->extra_shader_outputs.semantic_name[n] = semantic_name;
6143464ebd5Sriastradh   draw->extra_shader_outputs.semantic_index[n] = semantic_index;
6153464ebd5Sriastradh   draw->extra_shader_outputs.slot[n] = num_outputs + n;
6163464ebd5Sriastradh   draw->extra_shader_outputs.num++;
6173464ebd5Sriastradh
6183464ebd5Sriastradh   return draw->extra_shader_outputs.slot[n];
6193464ebd5Sriastradh}
6203464ebd5Sriastradh
6213464ebd5Sriastradh
6223464ebd5Sriastradh/**
6233464ebd5Sriastradh * Remove all extra vertex attributes that were allocated with
6243464ebd5Sriastradh * draw_alloc_extra_vertex_attrib().
6253464ebd5Sriastradh */
6263464ebd5Sriastradhvoid
6273464ebd5Sriastradhdraw_remove_extra_vertex_attribs(struct draw_context *draw)
6283464ebd5Sriastradh{
6293464ebd5Sriastradh   draw->extra_shader_outputs.num = 0;
6303464ebd5Sriastradh}
6313464ebd5Sriastradh
6323464ebd5Sriastradh
633af69d88dSmrg/**
634af69d88dSmrg * If a geometry shader is present, return its info, else the vertex shader's
635af69d88dSmrg * info.
636af69d88dSmrg */
637af69d88dSmrgstruct tgsi_shader_info *
638af69d88dSmrgdraw_get_shader_info(const struct draw_context *draw)
639af69d88dSmrg{
640af69d88dSmrg
641af69d88dSmrg   if (draw->gs.geometry_shader) {
642af69d88dSmrg      return &draw->gs.geometry_shader->info;
6437ec681f3Smrg   } else if (draw->tes.tess_eval_shader) {
6447ec681f3Smrg      return &draw->tes.tess_eval_shader->info;
645af69d88dSmrg   } else {
646af69d88dSmrg      return &draw->vs.vertex_shader->info;
647af69d88dSmrg   }
648af69d88dSmrg}
649af69d88dSmrg
650af69d88dSmrg/**
651af69d88dSmrg * Prepare outputs slots from the draw module
652af69d88dSmrg *
653af69d88dSmrg * Certain parts of the draw module can emit additional
654af69d88dSmrg * outputs that can be quite useful to the backends, a good
655af69d88dSmrg * example of it is the process of decomposing primitives
656af69d88dSmrg * into wireframes (aka. lines) which normally would lose
657af69d88dSmrg * the face-side information, but using this method we can
658af69d88dSmrg * inject another shader output which passes the original
659af69d88dSmrg * face side information to the backend.
660af69d88dSmrg */
661af69d88dSmrgvoid
662af69d88dSmrgdraw_prepare_shader_outputs(struct draw_context *draw)
663af69d88dSmrg{
664af69d88dSmrg   draw_remove_extra_vertex_attribs(draw);
665af69d88dSmrg   draw_prim_assembler_prepare_outputs(draw->ia);
666af69d88dSmrg   draw_unfilled_prepare_outputs(draw, draw->pipeline.unfilled);
667af69d88dSmrg   if (draw->pipeline.aapoint)
668af69d88dSmrg      draw_aapoint_prepare_outputs(draw, draw->pipeline.aapoint);
669af69d88dSmrg   if (draw->pipeline.aaline)
670af69d88dSmrg      draw_aaline_prepare_outputs(draw, draw->pipeline.aaline);
671af69d88dSmrg}
672af69d88dSmrg
6734a49301eSmrg/**
6744a49301eSmrg * Ask the draw module for the location/slot of the given vertex attribute in
6754a49301eSmrg * a post-transformed vertex.
6764a49301eSmrg *
6774a49301eSmrg * With this function, drivers that use the draw module should have no reason
678cdc920a0Smrg * to track the current vertex/geometry shader.
6794a49301eSmrg *
6804a49301eSmrg * Note that the draw module may sometimes generate vertices with extra
6814a49301eSmrg * attributes (such as texcoords for AA lines).  The driver can call this
6824a49301eSmrg * function to find those attributes.
6834a49301eSmrg *
684af69d88dSmrg * -1 is returned if the attribute is not found since this is
685af69d88dSmrg * an undefined situation. Note, that zero is valid and can
686af69d88dSmrg * be used by any of the attributes, because position is not
687af69d88dSmrg * required to be attribute 0 or even at all present.
6884a49301eSmrg */
6894a49301eSmrgint
690cdc920a0Smrgdraw_find_shader_output(const struct draw_context *draw,
691cdc920a0Smrg                        uint semantic_name, uint semantic_index)
6924a49301eSmrg{
693af69d88dSmrg   const struct tgsi_shader_info *info = draw_get_shader_info(draw);
6944a49301eSmrg   uint i;
695cdc920a0Smrg
696cdc920a0Smrg   for (i = 0; i < info->num_outputs; i++) {
697cdc920a0Smrg      if (info->output_semantic_name[i] == semantic_name &&
698cdc920a0Smrg          info->output_semantic_index[i] == semantic_index)
6994a49301eSmrg         return i;
7004a49301eSmrg   }
7014a49301eSmrg
7023464ebd5Sriastradh   /* Search the extra vertex attributes */
7033464ebd5Sriastradh   for (i = 0; i < draw->extra_shader_outputs.num; i++) {
7043464ebd5Sriastradh      if (draw->extra_shader_outputs.semantic_name[i] == semantic_name &&
7053464ebd5Sriastradh          draw->extra_shader_outputs.semantic_index[i] == semantic_index) {
7063464ebd5Sriastradh         return draw->extra_shader_outputs.slot[i];
7073464ebd5Sriastradh      }
7084a49301eSmrg   }
709cdc920a0Smrg
710af69d88dSmrg   return -1;
7114a49301eSmrg}
7124a49301eSmrg
7134a49301eSmrg
7144a49301eSmrg/**
715cdc920a0Smrg * Return total number of the shader outputs.  This function is similar to
716cdc920a0Smrg * draw_current_shader_outputs() but this function also counts any extra
717cdc920a0Smrg * vertex/geometry output attributes that may be filled in by some draw
718cdc920a0Smrg * stages (such as AA point, AA line).
719cdc920a0Smrg *
720cdc920a0Smrg * If geometry shader is present, its output will be returned,
721cdc920a0Smrg * if not vertex shader is used.
7224a49301eSmrg */
7234a49301eSmrguint
724cdc920a0Smrgdraw_num_shader_outputs(const struct draw_context *draw)
7254a49301eSmrg{
726af69d88dSmrg   const struct tgsi_shader_info *info = draw_get_shader_info(draw);
7273464ebd5Sriastradh   uint count;
728cdc920a0Smrg
729af69d88dSmrg   count = info->num_outputs;
7303464ebd5Sriastradh   count += draw->extra_shader_outputs.num;
731cdc920a0Smrg
7324a49301eSmrg   return count;
7334a49301eSmrg}
7344a49301eSmrg
7354a49301eSmrg
736af69d88dSmrg/**
737af69d88dSmrg * Return total number of the vertex shader outputs.  This function
738af69d88dSmrg * also counts any extra vertex output attributes that may
739af69d88dSmrg * be filled in by some draw stages (such as AA point, AA line,
740af69d88dSmrg * front face).
741af69d88dSmrg */
742af69d88dSmrguint
743af69d88dSmrgdraw_total_vs_outputs(const struct draw_context *draw)
744af69d88dSmrg{
745af69d88dSmrg   const struct tgsi_shader_info *info = &draw->vs.vertex_shader->info;
746af69d88dSmrg
74701e04c3fSmrg   return info->num_outputs + draw->extra_shader_outputs.num;
748af69d88dSmrg}
749af69d88dSmrg
750af69d88dSmrg/**
751af69d88dSmrg * Return total number of the geometry shader outputs. This function
752af69d88dSmrg * also counts any extra geometry output attributes that may
753af69d88dSmrg * be filled in by some draw stages (such as AA point, AA line, front
754af69d88dSmrg * face).
755af69d88dSmrg */
756af69d88dSmrguint
757af69d88dSmrgdraw_total_gs_outputs(const struct draw_context *draw)
758af69d88dSmrg{
759af69d88dSmrg   const struct tgsi_shader_info *info;
760af69d88dSmrg
761af69d88dSmrg   if (!draw->gs.geometry_shader)
762af69d88dSmrg      return 0;
763af69d88dSmrg
764af69d88dSmrg   info = &draw->gs.geometry_shader->info;
765af69d88dSmrg
766af69d88dSmrg   return info->num_outputs + draw->extra_shader_outputs.num;
767af69d88dSmrg}
768af69d88dSmrg
7697ec681f3Smrg/**
7707ec681f3Smrg * Return total number of the tess ctrl shader outputs.
7717ec681f3Smrg */
7727ec681f3Smrguint
7737ec681f3Smrgdraw_total_tcs_outputs(const struct draw_context *draw)
7747ec681f3Smrg{
7757ec681f3Smrg   const struct tgsi_shader_info *info;
7767ec681f3Smrg
7777ec681f3Smrg   if (!draw->tcs.tess_ctrl_shader)
7787ec681f3Smrg      return 0;
7797ec681f3Smrg
7807ec681f3Smrg   info = &draw->tcs.tess_ctrl_shader->info;
7817ec681f3Smrg
7827ec681f3Smrg   return info->num_outputs;
7837ec681f3Smrg}
7847ec681f3Smrg
7857ec681f3Smrg/**
7867ec681f3Smrg * Return total number of the tess eval shader outputs.
7877ec681f3Smrg */
7887ec681f3Smrguint
7897ec681f3Smrgdraw_total_tes_outputs(const struct draw_context *draw)
7907ec681f3Smrg{
7917ec681f3Smrg   const struct tgsi_shader_info *info;
7927ec681f3Smrg
7937ec681f3Smrg   if (!draw->tes.tess_eval_shader)
7947ec681f3Smrg      return 0;
7957ec681f3Smrg
7967ec681f3Smrg   info = &draw->tes.tess_eval_shader->info;
7977ec681f3Smrg
7987ec681f3Smrg   return info->num_outputs + draw->extra_shader_outputs.num;
7997ec681f3Smrg}
800af69d88dSmrg
8014a49301eSmrg/**
802cdc920a0Smrg * Provide TGSI sampler objects for vertex/geometry shaders that use
803af69d88dSmrg * texture fetches.  This state only needs to be set once per context.
8044a49301eSmrg * This might only be used by software drivers for the time being.
8054a49301eSmrg */
8064a49301eSmrgvoid
807af69d88dSmrgdraw_texture_sampler(struct draw_context *draw,
80801e04c3fSmrg                     enum pipe_shader_type shader,
809af69d88dSmrg                     struct tgsi_sampler *sampler)
8104a49301eSmrg{
8117ec681f3Smrg   switch (shader) {
8127ec681f3Smrg   case PIPE_SHADER_VERTEX:
813af69d88dSmrg      draw->vs.tgsi.sampler = sampler;
8147ec681f3Smrg      break;
8157ec681f3Smrg   case PIPE_SHADER_GEOMETRY:
816af69d88dSmrg      draw->gs.tgsi.sampler = sampler;
8177ec681f3Smrg      break;
8187ec681f3Smrg   case PIPE_SHADER_TESS_CTRL:
8197ec681f3Smrg      draw->tcs.tgsi.sampler = sampler;
8207ec681f3Smrg      break;
8217ec681f3Smrg   case PIPE_SHADER_TESS_EVAL:
8227ec681f3Smrg      draw->tes.tgsi.sampler = sampler;
8237ec681f3Smrg      break;
8247ec681f3Smrg   default:
8257ec681f3Smrg      assert(0);
8267ec681f3Smrg      break;
8273464ebd5Sriastradh   }
8284a49301eSmrg}
8294a49301eSmrg
83001e04c3fSmrg/**
83101e04c3fSmrg * Provide TGSI image objects for vertex/geometry shaders that use
83201e04c3fSmrg * texture fetches.  This state only needs to be set once per context.
83301e04c3fSmrg * This might only be used by software drivers for the time being.
83401e04c3fSmrg */
83501e04c3fSmrgvoid
83601e04c3fSmrgdraw_image(struct draw_context *draw,
83701e04c3fSmrg           enum pipe_shader_type shader,
83801e04c3fSmrg           struct tgsi_image *image)
83901e04c3fSmrg{
8407ec681f3Smrg   switch (shader) {
8417ec681f3Smrg   case PIPE_SHADER_VERTEX:
84201e04c3fSmrg      draw->vs.tgsi.image = image;
8437ec681f3Smrg      break;
8447ec681f3Smrg   case PIPE_SHADER_GEOMETRY:
84501e04c3fSmrg      draw->gs.tgsi.image = image;
8467ec681f3Smrg      break;
8477ec681f3Smrg   case PIPE_SHADER_TESS_CTRL:
8487ec681f3Smrg      draw->tcs.tgsi.image = image;
8497ec681f3Smrg      break;
8507ec681f3Smrg   case PIPE_SHADER_TESS_EVAL:
8517ec681f3Smrg      draw->tes.tgsi.image = image;
8527ec681f3Smrg      break;
8537ec681f3Smrg   default:
8547ec681f3Smrg      assert(0);
8557ec681f3Smrg      break;
85601e04c3fSmrg   }
85701e04c3fSmrg}
8584a49301eSmrg
85901e04c3fSmrg/**
86001e04c3fSmrg * Provide TGSI buffer objects for vertex/geometry shaders that use
86101e04c3fSmrg * load/store/atomic ops.  This state only needs to be set once per context.
86201e04c3fSmrg * This might only be used by software drivers for the time being.
86301e04c3fSmrg */
86401e04c3fSmrgvoid
86501e04c3fSmrgdraw_buffer(struct draw_context *draw,
86601e04c3fSmrg            enum pipe_shader_type shader,
86701e04c3fSmrg            struct tgsi_buffer *buffer)
86801e04c3fSmrg{
8697ec681f3Smrg   switch (shader) {
8707ec681f3Smrg   case PIPE_SHADER_VERTEX:
87101e04c3fSmrg      draw->vs.tgsi.buffer = buffer;
8727ec681f3Smrg      break;
8737ec681f3Smrg   case PIPE_SHADER_GEOMETRY:
87401e04c3fSmrg      draw->gs.tgsi.buffer = buffer;
8757ec681f3Smrg      break;
8767ec681f3Smrg   case PIPE_SHADER_TESS_CTRL:
8777ec681f3Smrg      draw->tcs.tgsi.buffer = buffer;
8787ec681f3Smrg      break;
8797ec681f3Smrg   case PIPE_SHADER_TESS_EVAL:
8807ec681f3Smrg      draw->tes.tgsi.buffer = buffer;
8817ec681f3Smrg      break;
8827ec681f3Smrg   default:
8837ec681f3Smrg      assert(0);
8847ec681f3Smrg      break;
88501e04c3fSmrg   }
88601e04c3fSmrg}
8874a49301eSmrg
8884a49301eSmrg
8894a49301eSmrgvoid draw_set_render( struct draw_context *draw,
8904a49301eSmrg		      struct vbuf_render *render )
8914a49301eSmrg{
8924a49301eSmrg   draw->render = render;
8934a49301eSmrg}
8944a49301eSmrg
8954a49301eSmrg
8963464ebd5Sriastradh/**
897af69d88dSmrg * Tell the draw module where vertex indexes/elements are located, and
898af69d88dSmrg * their size (in bytes).
8993464ebd5Sriastradh */
9004a49301eSmrgvoid
901af69d88dSmrgdraw_set_indexes(struct draw_context *draw,
902af69d88dSmrg                 const void *elements, unsigned elem_size,
903af69d88dSmrg                 unsigned elem_buffer_space)
9044a49301eSmrg{
905af69d88dSmrg   assert(elem_size == 0 ||
906af69d88dSmrg          elem_size == 1 ||
907af69d88dSmrg          elem_size == 2 ||
908af69d88dSmrg          elem_size == 4);
909af69d88dSmrg   draw->pt.user.elts = elements;
910af69d88dSmrg   draw->pt.user.eltSizeIB = elem_size;
911af69d88dSmrg   if (elem_size)
912af69d88dSmrg      draw->pt.user.eltMax = elem_buffer_space / elem_size;
913af69d88dSmrg   else
914af69d88dSmrg      draw->pt.user.eltMax = 0;
9154a49301eSmrg}
9164a49301eSmrg
9173464ebd5Sriastradh
9184a49301eSmrg/* Revamp me please:
9194a49301eSmrg */
9204a49301eSmrgvoid draw_do_flush( struct draw_context *draw, unsigned flags )
9214a49301eSmrg{
9224a49301eSmrg   if (!draw->suspend_flushing)
9234a49301eSmrg   {
9244a49301eSmrg      assert(!draw->flushing); /* catch inadvertant recursion */
9254a49301eSmrg
9264a49301eSmrg      draw->flushing = TRUE;
9274a49301eSmrg
9284a49301eSmrg      draw_pipeline_flush( draw, flags );
9294a49301eSmrg
930af69d88dSmrg      draw_pt_flush( draw, flags );
931af69d88dSmrg
9324a49301eSmrg      draw->flushing = FALSE;
9334a49301eSmrg   }
9344a49301eSmrg}
935cdc920a0Smrg
936cdc920a0Smrg
937cdc920a0Smrg/**
938cdc920a0Smrg * Return the number of output attributes produced by the geometry
939cdc920a0Smrg * shader, if present.  If no geometry shader, return the number of
940cdc920a0Smrg * outputs from the vertex shader.
941cdc920a0Smrg * \sa draw_num_shader_outputs
942cdc920a0Smrg */
943cdc920a0Smrguint
944cdc920a0Smrgdraw_current_shader_outputs(const struct draw_context *draw)
945cdc920a0Smrg{
946cdc920a0Smrg   if (draw->gs.geometry_shader)
947cdc920a0Smrg      return draw->gs.num_gs_outputs;
948cdc920a0Smrg   return draw->vs.num_vs_outputs;
949cdc920a0Smrg}
950cdc920a0Smrg
951cdc920a0Smrg
952cdc920a0Smrg/**
953cdc920a0Smrg * Return the index of the shader output which will contain the
954cdc920a0Smrg * vertex position.
955cdc920a0Smrg */
956cdc920a0Smrguint
957cdc920a0Smrgdraw_current_shader_position_output(const struct draw_context *draw)
958cdc920a0Smrg{
959cdc920a0Smrg   if (draw->gs.geometry_shader)
960cdc920a0Smrg      return draw->gs.position_output;
9617ec681f3Smrg   if (draw->tes.tess_eval_shader)
9627ec681f3Smrg      return draw->tes.position_output;
963cdc920a0Smrg   return draw->vs.position_output;
964cdc920a0Smrg}
965cdc920a0Smrg
966cdc920a0Smrg
967af69d88dSmrg/**
968af69d88dSmrg * Return the index of the shader output which will contain the
969af69d88dSmrg * viewport index.
970af69d88dSmrg */
971af69d88dSmrguint
972af69d88dSmrgdraw_current_shader_viewport_index_output(const struct draw_context *draw)
973af69d88dSmrg{
974af69d88dSmrg   if (draw->gs.geometry_shader)
975af69d88dSmrg      return draw->gs.geometry_shader->viewport_index_output;
9767ec681f3Smrg   else if (draw->tes.tess_eval_shader)
9777ec681f3Smrg      return draw->tes.tess_eval_shader->viewport_index_output;
97801e04c3fSmrg   return draw->vs.vertex_shader->viewport_index_output;
979af69d88dSmrg}
980af69d88dSmrg
981af69d88dSmrg/**
982af69d88dSmrg * Returns true if there's a geometry shader bound and the geometry
983af69d88dSmrg * shader writes out a viewport index.
984af69d88dSmrg */
985af69d88dSmrgboolean
986af69d88dSmrgdraw_current_shader_uses_viewport_index(const struct draw_context *draw)
987af69d88dSmrg{
988af69d88dSmrg   if (draw->gs.geometry_shader)
989af69d88dSmrg      return draw->gs.geometry_shader->info.writes_viewport_index;
9907ec681f3Smrg   else if (draw->tes.tess_eval_shader)
9917ec681f3Smrg      return draw->tes.tess_eval_shader->info.writes_viewport_index;
99201e04c3fSmrg   return draw->vs.vertex_shader->info.writes_viewport_index;
993af69d88dSmrg}
994af69d88dSmrg
995af69d88dSmrg
996af69d88dSmrg/**
997af69d88dSmrg * Return the index of the shader output which will contain the
998af69d88dSmrg * clip vertex position.
999af69d88dSmrg * Note we don't support clipvertex output in the gs. For clipping
1000af69d88dSmrg * to work correctly hence we return ordinary position output instead.
1001af69d88dSmrg */
1002af69d88dSmrguint
1003af69d88dSmrgdraw_current_shader_clipvertex_output(const struct draw_context *draw)
1004af69d88dSmrg{
1005af69d88dSmrg   if (draw->gs.geometry_shader)
10067ec681f3Smrg      return draw->gs.clipvertex_output;
10077ec681f3Smrg   if (draw->tes.tess_eval_shader)
10087ec681f3Smrg      return draw->tes.clipvertex_output;
1009af69d88dSmrg   return draw->vs.clipvertex_output;
1010af69d88dSmrg}
1011af69d88dSmrg
1012af69d88dSmrguint
101301e04c3fSmrgdraw_current_shader_ccdistance_output(const struct draw_context *draw, int index)
1014af69d88dSmrg{
1015af69d88dSmrg   debug_assert(index < PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT);
1016af69d88dSmrg   if (draw->gs.geometry_shader)
101701e04c3fSmrg      return draw->gs.geometry_shader->ccdistance_output[index];
10187ec681f3Smrg   if (draw->tes.tess_eval_shader)
10197ec681f3Smrg      return draw->tes.tess_eval_shader->ccdistance_output[index];
102001e04c3fSmrg   return draw->vs.ccdistance_output[index];
1021af69d88dSmrg}
1022af69d88dSmrg
1023af69d88dSmrg
1024af69d88dSmrguint
1025af69d88dSmrgdraw_current_shader_num_written_clipdistances(const struct draw_context *draw)
1026af69d88dSmrg{
1027af69d88dSmrg   if (draw->gs.geometry_shader)
1028af69d88dSmrg      return draw->gs.geometry_shader->info.num_written_clipdistance;
10297ec681f3Smrg   if (draw->tes.tess_eval_shader)
10307ec681f3Smrg      return draw->tes.tess_eval_shader->info.num_written_clipdistance;
1031af69d88dSmrg   return draw->vs.vertex_shader->info.num_written_clipdistance;
1032af69d88dSmrg}
1033af69d88dSmrg
1034af69d88dSmrguint
1035af69d88dSmrgdraw_current_shader_num_written_culldistances(const struct draw_context *draw)
1036af69d88dSmrg{
1037af69d88dSmrg   if (draw->gs.geometry_shader)
1038af69d88dSmrg      return draw->gs.geometry_shader->info.num_written_culldistance;
10397ec681f3Smrg   if (draw->tes.tess_eval_shader)
10407ec681f3Smrg      return draw->tes.tess_eval_shader->info.num_written_culldistance;
1041af69d88dSmrg   return draw->vs.vertex_shader->info.num_written_culldistance;
1042af69d88dSmrg}
1043af69d88dSmrg
1044cdc920a0Smrg/**
1045cdc920a0Smrg * Return a pointer/handle for a driver/CSO rasterizer object which
1046cdc920a0Smrg * disabled culling, stippling, unfilled tris, etc.
1047cdc920a0Smrg * This is used by some pipeline stages (such as wide_point, aa_line
1048cdc920a0Smrg * and aa_point) which convert points/lines into triangles.  In those
1049cdc920a0Smrg * cases we don't want to accidentally cull the triangles.
1050cdc920a0Smrg *
1051cdc920a0Smrg * \param scissor  should the rasterizer state enable scissoring?
1052cdc920a0Smrg * \param flatshade  should the rasterizer state use flat shading?
1053cdc920a0Smrg * \return  rasterizer CSO handle
1054cdc920a0Smrg */
1055cdc920a0Smrgvoid *
1056cdc920a0Smrgdraw_get_rasterizer_no_cull( struct draw_context *draw,
10577ec681f3Smrg                             const struct pipe_rasterizer_state *base_rast )
1058cdc920a0Smrg{
10597ec681f3Smrg   if (!draw->rasterizer_no_cull[base_rast->scissor][base_rast->flatshade][base_rast->rasterizer_discard]) {
1060cdc920a0Smrg      /* create now */
1061cdc920a0Smrg      struct pipe_context *pipe = draw->pipe;
1062cdc920a0Smrg      struct pipe_rasterizer_state rast;
1063cdc920a0Smrg
1064cdc920a0Smrg      memset(&rast, 0, sizeof(rast));
10657ec681f3Smrg      rast.scissor = base_rast->scissor;
10667ec681f3Smrg      rast.flatshade = base_rast->flatshade;
10677ec681f3Smrg      rast.rasterizer_discard = base_rast->rasterizer_discard;
10683464ebd5Sriastradh      rast.front_ccw = 1;
1069af69d88dSmrg      rast.half_pixel_center = draw->rasterizer->half_pixel_center;
1070af69d88dSmrg      rast.bottom_edge_rule = draw->rasterizer->bottom_edge_rule;
1071af69d88dSmrg      rast.clip_halfz = draw->rasterizer->clip_halfz;
1072cdc920a0Smrg
10737ec681f3Smrg      draw->rasterizer_no_cull[base_rast->scissor][base_rast->flatshade][base_rast->rasterizer_discard] =
1074cdc920a0Smrg         pipe->create_rasterizer_state(pipe, &rast);
1075cdc920a0Smrg   }
10767ec681f3Smrg   return draw->rasterizer_no_cull[base_rast->scissor][base_rast->flatshade][base_rast->rasterizer_discard];
1077cdc920a0Smrg}
10783464ebd5Sriastradh
10793464ebd5Sriastradhvoid
1080af69d88dSmrgdraw_set_mapped_so_targets(struct draw_context *draw,
1081af69d88dSmrg                           int num_targets,
1082af69d88dSmrg                           struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS])
10833464ebd5Sriastradh{
10843464ebd5Sriastradh   int i;
10853464ebd5Sriastradh
1086361fc4cbSmaya   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
1087361fc4cbSmaya
1088af69d88dSmrg   for (i = 0; i < num_targets; i++)
1089af69d88dSmrg      draw->so.targets[i] = targets[i];
1090af69d88dSmrg   for (i = num_targets; i < PIPE_MAX_SO_BUFFERS; i++)
1091af69d88dSmrg      draw->so.targets[i] = NULL;
10923464ebd5Sriastradh
1093af69d88dSmrg   draw->so.num_targets = num_targets;
10943464ebd5Sriastradh}
10953464ebd5Sriastradh
10963464ebd5Sriastradhvoid
10973464ebd5Sriastradhdraw_set_sampler_views(struct draw_context *draw,
109801e04c3fSmrg                       enum pipe_shader_type shader_stage,
10993464ebd5Sriastradh                       struct pipe_sampler_view **views,
11003464ebd5Sriastradh                       unsigned num)
11013464ebd5Sriastradh{
11023464ebd5Sriastradh   unsigned i;
11033464ebd5Sriastradh
1104af69d88dSmrg   debug_assert(shader_stage < PIPE_SHADER_TYPES);
1105af69d88dSmrg   debug_assert(num <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
1106af69d88dSmrg
1107af69d88dSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
11083464ebd5Sriastradh
11093464ebd5Sriastradh   for (i = 0; i < num; ++i)
1110af69d88dSmrg      draw->sampler_views[shader_stage][i] = views[i];
111101e04c3fSmrg   for (i = num; i < draw->num_sampler_views[shader_stage]; ++i)
1112af69d88dSmrg      draw->sampler_views[shader_stage][i] = NULL;
11133464ebd5Sriastradh
1114af69d88dSmrg   draw->num_sampler_views[shader_stage] = num;
11153464ebd5Sriastradh}
11163464ebd5Sriastradh
11173464ebd5Sriastradhvoid
11183464ebd5Sriastradhdraw_set_samplers(struct draw_context *draw,
111901e04c3fSmrg                  enum pipe_shader_type shader_stage,
11203464ebd5Sriastradh                  struct pipe_sampler_state **samplers,
11213464ebd5Sriastradh                  unsigned num)
11223464ebd5Sriastradh{
11233464ebd5Sriastradh   unsigned i;
11243464ebd5Sriastradh
1125af69d88dSmrg   debug_assert(shader_stage < PIPE_SHADER_TYPES);
1126af69d88dSmrg   debug_assert(num <= PIPE_MAX_SAMPLERS);
1127af69d88dSmrg
1128af69d88dSmrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
11293464ebd5Sriastradh
11303464ebd5Sriastradh   for (i = 0; i < num; ++i)
1131af69d88dSmrg      draw->samplers[shader_stage][i] = samplers[i];
1132af69d88dSmrg   for (i = num; i < PIPE_MAX_SAMPLERS; ++i)
1133af69d88dSmrg      draw->samplers[shader_stage][i] = NULL;
11343464ebd5Sriastradh
1135af69d88dSmrg   draw->num_samplers[shader_stage] = num;
11363464ebd5Sriastradh
11377ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
11383464ebd5Sriastradh   if (draw->llvm)
1139af69d88dSmrg      draw_llvm_set_sampler_state(draw, shader_stage);
11403464ebd5Sriastradh#endif
11413464ebd5Sriastradh}
11423464ebd5Sriastradh
11437ec681f3Smrgvoid
11447ec681f3Smrgdraw_set_images(struct draw_context *draw,
11457ec681f3Smrg                enum pipe_shader_type shader_stage,
11467ec681f3Smrg                struct pipe_image_view *views,
11477ec681f3Smrg                unsigned num)
11487ec681f3Smrg{
11497ec681f3Smrg   unsigned i;
11507ec681f3Smrg
11517ec681f3Smrg   debug_assert(shader_stage < PIPE_SHADER_TYPES);
11527ec681f3Smrg   debug_assert(num <= PIPE_MAX_SHADER_IMAGES);
11537ec681f3Smrg
11547ec681f3Smrg   draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );
11557ec681f3Smrg
11567ec681f3Smrg   for (i = 0; i < num; ++i)
11577ec681f3Smrg      draw->images[shader_stage][i] = &views[i];
11587ec681f3Smrg   for (i = num; i < draw->num_sampler_views[shader_stage]; ++i)
11597ec681f3Smrg      draw->images[shader_stage][i] = NULL;
11607ec681f3Smrg
11617ec681f3Smrg   draw->num_images[shader_stage] = num;
11627ec681f3Smrg}
11637ec681f3Smrg
11643464ebd5Sriastradhvoid
11653464ebd5Sriastradhdraw_set_mapped_texture(struct draw_context *draw,
116601e04c3fSmrg                        enum pipe_shader_type shader_stage,
1167af69d88dSmrg                        unsigned sview_idx,
11683464ebd5Sriastradh                        uint32_t width, uint32_t height, uint32_t depth,
11693464ebd5Sriastradh                        uint32_t first_level, uint32_t last_level,
11707ec681f3Smrg                        uint32_t num_samples,
11717ec681f3Smrg                        uint32_t sample_stride,
1172af69d88dSmrg                        const void *base_ptr,
11733464ebd5Sriastradh                        uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
11743464ebd5Sriastradh                        uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
1175af69d88dSmrg                        uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
11763464ebd5Sriastradh{
11777ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
1178af69d88dSmrg   if (draw->llvm)
11793464ebd5Sriastradh      draw_llvm_set_mapped_texture(draw,
1180af69d88dSmrg                                   shader_stage,
1181af69d88dSmrg                                   sview_idx,
1182af69d88dSmrg                                   width, height, depth, first_level,
11837ec681f3Smrg                                   last_level, num_samples, sample_stride, base_ptr,
1184af69d88dSmrg                                   row_stride, img_stride, mip_offsets);
1185af69d88dSmrg#endif
1186af69d88dSmrg}
1187af69d88dSmrg
11887ec681f3Smrgvoid
11897ec681f3Smrgdraw_set_mapped_image(struct draw_context *draw,
11907ec681f3Smrg                      enum pipe_shader_type shader_stage,
11917ec681f3Smrg                      unsigned idx,
11927ec681f3Smrg                      uint32_t width, uint32_t height, uint32_t depth,
11937ec681f3Smrg                      const void *base_ptr,
11947ec681f3Smrg                      uint32_t row_stride,
11957ec681f3Smrg                      uint32_t img_stride,
11967ec681f3Smrg                      uint32_t num_samples,
11977ec681f3Smrg                      uint32_t sample_stride)
11987ec681f3Smrg{
11997ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
12007ec681f3Smrg   if (draw->llvm)
12017ec681f3Smrg      draw_llvm_set_mapped_image(draw,
12027ec681f3Smrg                                 shader_stage,
12037ec681f3Smrg                                 idx,
12047ec681f3Smrg                                 width, height, depth,
12057ec681f3Smrg                                 base_ptr,
12067ec681f3Smrg                                 row_stride, img_stride,
12077ec681f3Smrg                                 num_samples, sample_stride);
12087ec681f3Smrg#endif
12097ec681f3Smrg}
12107ec681f3Smrg
1211af69d88dSmrg/**
1212af69d88dSmrg * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
1213af69d88dSmrg * different ways of setting textures, and drivers typically only support one.
1214af69d88dSmrg */
1215af69d88dSmrgint
121601e04c3fSmrgdraw_get_shader_param_no_llvm(enum pipe_shader_type shader,
121701e04c3fSmrg                              enum pipe_shader_cap param)
1218af69d88dSmrg{
1219af69d88dSmrg   switch(shader) {
1220af69d88dSmrg   case PIPE_SHADER_VERTEX:
1221af69d88dSmrg   case PIPE_SHADER_GEOMETRY:
1222af69d88dSmrg      return tgsi_exec_get_shader_param(param);
1223af69d88dSmrg   default:
1224af69d88dSmrg      return 0;
1225af69d88dSmrg   }
1226af69d88dSmrg}
1227af69d88dSmrg
1228af69d88dSmrg/**
1229af69d88dSmrg * XXX: Results for PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS because there are two
1230af69d88dSmrg * different ways of setting textures, and drivers typically only support one.
1231af69d88dSmrg * Drivers requesting a draw context explicitly without llvm must call
1232af69d88dSmrg * draw_get_shader_param_no_llvm instead.
1233af69d88dSmrg */
1234af69d88dSmrgint
123501e04c3fSmrgdraw_get_shader_param(enum pipe_shader_type shader, enum pipe_shader_cap param)
1236af69d88dSmrg{
1237af69d88dSmrg
12387ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
1239af69d88dSmrg   if (draw_get_option_use_llvm()) {
1240af69d88dSmrg      switch(shader) {
1241af69d88dSmrg      case PIPE_SHADER_VERTEX:
1242af69d88dSmrg      case PIPE_SHADER_GEOMETRY:
12437ec681f3Smrg      case PIPE_SHADER_TESS_CTRL:
12447ec681f3Smrg      case PIPE_SHADER_TESS_EVAL:
1245af69d88dSmrg         return gallivm_get_shader_param(param);
1246af69d88dSmrg      default:
1247af69d88dSmrg         return 0;
1248af69d88dSmrg      }
1249af69d88dSmrg   }
12503464ebd5Sriastradh#endif
1251af69d88dSmrg
1252af69d88dSmrg   return draw_get_shader_param_no_llvm(shader, param);
1253af69d88dSmrg}
1254af69d88dSmrg
1255af69d88dSmrg/**
1256af69d88dSmrg * Enables or disables collection of statistics.
1257af69d88dSmrg *
1258af69d88dSmrg * Draw module is capable of generating statistics for the vertex
1259af69d88dSmrg * processing pipeline. Collection of that data isn't free and so
1260af69d88dSmrg * it's disabled by default. The users of the module can enable
1261af69d88dSmrg * (or disable) this functionality through this function.
1262af69d88dSmrg * The actual data will be emitted through the VBUF interface,
1263af69d88dSmrg * the 'pipeline_statistics' callback to be exact.
1264af69d88dSmrg */
1265af69d88dSmrgvoid
1266af69d88dSmrgdraw_collect_pipeline_statistics(struct draw_context *draw,
1267af69d88dSmrg                                 boolean enable)
1268af69d88dSmrg{
1269af69d88dSmrg   draw->collect_statistics = enable;
1270af69d88dSmrg}
1271af69d88dSmrg
12727ec681f3Smrg/**
12737ec681f3Smrg * Enable/disable primitives generated gathering.
12747ec681f3Smrg */
12757ec681f3Smrgvoid draw_collect_primitives_generated(struct draw_context *draw,
12767ec681f3Smrg                                       bool enable)
12777ec681f3Smrg{
12787ec681f3Smrg   draw->collect_primgen = enable;
12797ec681f3Smrg}
12807ec681f3Smrg
1281af69d88dSmrg/**
1282af69d88dSmrg * Computes clipper invocation statistics.
1283af69d88dSmrg *
1284af69d88dSmrg * Figures out how many primitives would have been
1285af69d88dSmrg * sent to the clipper given the specified
1286af69d88dSmrg * prim info data.
1287af69d88dSmrg */
1288af69d88dSmrgvoid
1289af69d88dSmrgdraw_stats_clipper_primitives(struct draw_context *draw,
1290af69d88dSmrg                              const struct draw_prim_info *prim_info)
1291af69d88dSmrg{
1292af69d88dSmrg   if (draw->collect_statistics) {
1293af69d88dSmrg      unsigned i;
1294af69d88dSmrg      for (i = 0; i < prim_info->primitive_count; i++) {
1295af69d88dSmrg         draw->statistics.c_invocations +=
1296af69d88dSmrg            u_decomposed_prims_for_vertices(prim_info->prim,
1297af69d88dSmrg                                            prim_info->primitive_lengths[i]);
1298af69d88dSmrg      }
1299af69d88dSmrg   }
1300af69d88dSmrg}
1301af69d88dSmrg
1302af69d88dSmrg
1303af69d88dSmrg/**
1304af69d88dSmrg * Returns true if the draw module will inject the frontface
1305af69d88dSmrg * info into the outputs.
1306af69d88dSmrg *
1307af69d88dSmrg * Given the specified primitive and rasterizer state
1308af69d88dSmrg * the function will figure out if the draw module
1309af69d88dSmrg * will inject the front-face information into shader
1310af69d88dSmrg * outputs. This is done to preserve the front-facing
1311af69d88dSmrg * info when decomposing primitives into wireframes.
1312af69d88dSmrg */
1313af69d88dSmrgboolean
1314af69d88dSmrgdraw_will_inject_frontface(const struct draw_context *draw)
1315af69d88dSmrg{
1316af69d88dSmrg   unsigned reduced_prim = u_reduced_prim(draw->pt.prim);
1317af69d88dSmrg   const struct pipe_rasterizer_state *rast = draw->rasterizer;
1318af69d88dSmrg
1319af69d88dSmrg   if (reduced_prim != PIPE_PRIM_TRIANGLES) {
1320af69d88dSmrg      return FALSE;
1321af69d88dSmrg   }
1322af69d88dSmrg
1323af69d88dSmrg   return (rast &&
1324af69d88dSmrg           (rast->fill_front != PIPE_POLYGON_MODE_FILL ||
1325af69d88dSmrg            rast->fill_back != PIPE_POLYGON_MODE_FILL));
13263464ebd5Sriastradh}
13277ec681f3Smrg
13287ec681f3Smrgvoid
13297ec681f3Smrgdraw_set_tess_state(struct draw_context *draw,
13307ec681f3Smrg		    const float default_outer_level[4],
13317ec681f3Smrg		    const float default_inner_level[2])
13327ec681f3Smrg{
13337ec681f3Smrg   for (unsigned i = 0; i < 4; i++)
13347ec681f3Smrg      draw->default_outer_tess_level[i] = default_outer_level[i];
13357ec681f3Smrg   for (unsigned i = 0; i < 2; i++)
13367ec681f3Smrg      draw->default_inner_tess_level[i] = default_inner_level[i];
13377ec681f3Smrg}
13387ec681f3Smrg
13397ec681f3Smrgvoid
13407ec681f3Smrgdraw_set_disk_cache_callbacks(struct draw_context *draw,
13417ec681f3Smrg                              void *data_cookie,
13427ec681f3Smrg                              void (*find_shader)(void *cookie,
13437ec681f3Smrg                                                  struct lp_cached_code *cache,
13447ec681f3Smrg                                                  unsigned char ir_sha1_cache_key[20]),
13457ec681f3Smrg                              void (*insert_shader)(void *cookie,
13467ec681f3Smrg                                                    struct lp_cached_code *cache,
13477ec681f3Smrg                                                    unsigned char ir_sha1_cache_key[20]))
13487ec681f3Smrg{
13497ec681f3Smrg   draw->disk_cache_find_shader = find_shader;
13507ec681f3Smrg   draw->disk_cache_insert_shader = insert_shader;
13517ec681f3Smrg   draw->disk_cache_cookie = data_cookie;
13527ec681f3Smrg}
13537ec681f3Smrg
13547ec681f3Smrgvoid draw_set_constant_buffer_stride(struct draw_context *draw, unsigned num_bytes)
13557ec681f3Smrg{
13567ec681f3Smrg   draw->constant_buffer_stride = num_bytes;
13577ec681f3Smrg}
1358