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 * Private data structures, etc for the draw module.
304a49301eSmrg */
314a49301eSmrg
324a49301eSmrg
334a49301eSmrg/**
344a49301eSmrg * Authors:
35af69d88dSmrg * Keith Whitwell <keithw@vmware.com>
364a49301eSmrg * Brian Paul
374a49301eSmrg */
384a49301eSmrg
394a49301eSmrg
404a49301eSmrg#ifndef DRAW_PRIVATE_H
414a49301eSmrg#define DRAW_PRIVATE_H
424a49301eSmrg
434a49301eSmrg
444a49301eSmrg#include "pipe/p_state.h"
454a49301eSmrg#include "pipe/p_defines.h"
464a49301eSmrg
474a49301eSmrg#include "tgsi/tgsi_scan.h"
484a49301eSmrg
497ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE
50af69d88dSmrgstruct gallivm_state;
513464ebd5Sriastradh#endif
523464ebd5Sriastradh
534a49301eSmrg
54af69d88dSmrg/** Sum of frustum planes and user-defined planes */
55af69d88dSmrg#define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
56af69d88dSmrg
57af69d88dSmrg/**
58af69d88dSmrg * The largest possible index of a vertex that can be fetched.
59af69d88dSmrg */
60af69d88dSmrg#define DRAW_MAX_FETCH_IDX 0xffffffff
61af69d88dSmrg
627ec681f3Smrg/**
637ec681f3Smrg * Maximum number of extra shader outputs.  These are allocated by:
647ec681f3Smrg * - draw_pipe_aaline.c (1)
657ec681f3Smrg * - draw_pipe_aapoint.c (1)
667ec681f3Smrg * - draw_pipe_unfilled.c (1)
677ec681f3Smrg * - draw_pipe_wide_point.c (up to 32)
687ec681f3Smrg * - draw_prim_assembler.c (1)
697ec681f3Smrg */
707ec681f3Smrg#define DRAW_MAX_EXTRA_SHADER_OUTPUTS 32
717ec681f3Smrg
727ec681f3Smrg/**
737ec681f3Smrg * Despite some efforts to determine the number of extra shader outputs ahead
747ec681f3Smrg * of time, the matter of fact is that this number will vary as primitives
757ec681f3Smrg * flow through the draw pipeline.  In particular, aaline/aapoint stages
767ec681f3Smrg * only allocate their extra shader outputs on the first line/point.
777ec681f3Smrg *
787ec681f3Smrg * Consequently dup_vert() ends up copying vertices larger than those
797ec681f3Smrg * allocated.
807ec681f3Smrg *
817ec681f3Smrg * Ideally we'd keep track of incoming/outgoing vertex sizes (and strides)
827ec681f3Smrg * throughout the draw pipeline, but unfortunately we recompute these all over
837ec681f3Smrg * the place, so preemptively expanding the vertex stride/size does not work
847ec681f3Smrg * as mismatches ensue.
857ec681f3Smrg *
867ec681f3Smrg * As stopgap to prevent buffer read overflows, we allocate an extra bit of
877ec681f3Smrg * padding at the end of temporary vertex buffers, allowing dup_vert() to copy
887ec681f3Smrg * more vertex attributes than allocated.
897ec681f3Smrg */
907ec681f3Smrg#define DRAW_EXTRA_VERTICES_PADDING \
917ec681f3Smrg   (DRAW_MAX_EXTRA_SHADER_OUTPUTS * sizeof(float[4]))
927ec681f3Smrg
934a49301eSmrgstruct pipe_context;
944a49301eSmrgstruct draw_vertex_shader;
954a49301eSmrgstruct draw_context;
964a49301eSmrgstruct draw_stage;
974a49301eSmrgstruct vbuf_render;
984a49301eSmrgstruct tgsi_exec_machine;
994a49301eSmrgstruct tgsi_sampler;
10001e04c3fSmrgstruct tgsi_image;
10101e04c3fSmrgstruct tgsi_buffer;
102af69d88dSmrgstruct draw_pt_front_end;
103af69d88dSmrgstruct draw_assembler;
104af69d88dSmrgstruct draw_llvm;
1057ec681f3Smrgstruct lp_cached_code;
1064a49301eSmrg
107af69d88dSmrg/**
108af69d88dSmrg * Represents the mapped vertex buffer.
109af69d88dSmrg */
110af69d88dSmrgstruct draw_vertex_buffer {
111af69d88dSmrg   const void *map;
112af69d88dSmrg   uint32_t size;
113af69d88dSmrg};
114af69d88dSmrg
1154a49301eSmrg/**
1164a49301eSmrg * Basic vertex info.
1174a49301eSmrg * Carry some useful information around with the vertices in the prim pipe.
1184a49301eSmrg */
1194a49301eSmrgstruct vertex_header {
120af69d88dSmrg   unsigned clipmask:DRAW_TOTAL_CLIP_PLANES;
1214a49301eSmrg   unsigned edgeflag:1;
12201e04c3fSmrg   unsigned pad:1;
1234a49301eSmrg   unsigned vertex_id:16;
1244a49301eSmrg
12501e04c3fSmrg   float clip_pos[4];
1264a49301eSmrg
1274a49301eSmrg   /* This will probably become float (*data)[4] soon:
1284a49301eSmrg    */
1294a49301eSmrg   float data[][4];
1304a49301eSmrg};
1314a49301eSmrg
1324a49301eSmrg/* NOTE: It should match vertex_id size above */
1334a49301eSmrg#define UNDEFINED_VERTEX_ID 0xffff
1344a49301eSmrg
1354a49301eSmrg
1363464ebd5Sriastradh/* maximum number of shader variants we can cache */
13701e04c3fSmrg#define DRAW_MAX_SHADER_VARIANTS 512
1383464ebd5Sriastradh
1394a49301eSmrg/**
1404a49301eSmrg * Private context for the drawing module.
1414a49301eSmrg */
1424a49301eSmrgstruct draw_context
1434a49301eSmrg{
144cdc920a0Smrg   struct pipe_context *pipe;
145cdc920a0Smrg
1464a49301eSmrg   /** Drawing/primitive pipeline stages */
1474a49301eSmrg   struct {
1484a49301eSmrg      struct draw_stage *first;  /**< one of the following */
1494a49301eSmrg
1504a49301eSmrg      struct draw_stage *validate;
1514a49301eSmrg
1524a49301eSmrg      /* stages (in logical order) */
1534a49301eSmrg      struct draw_stage *flatshade;
1544a49301eSmrg      struct draw_stage *clip;
1554a49301eSmrg      struct draw_stage *cull;
1567ec681f3Smrg      struct draw_stage *user_cull;
1574a49301eSmrg      struct draw_stage *twoside;
1584a49301eSmrg      struct draw_stage *offset;
1594a49301eSmrg      struct draw_stage *unfilled;
1604a49301eSmrg      struct draw_stage *stipple;
1614a49301eSmrg      struct draw_stage *aapoint;
1624a49301eSmrg      struct draw_stage *aaline;
1634a49301eSmrg      struct draw_stage *pstipple;
1644a49301eSmrg      struct draw_stage *wide_line;
1654a49301eSmrg      struct draw_stage *wide_point;
1664a49301eSmrg      struct draw_stage *rasterize;
1674a49301eSmrg
1684a49301eSmrg      float wide_point_threshold; /**< convert pnts to tris if larger than this */
1694a49301eSmrg      float wide_line_threshold;  /**< convert lines to tris if wider than this */
1703464ebd5Sriastradh      boolean wide_point_sprites; /**< convert points to tris for sprite mode */
1714a49301eSmrg      boolean line_stipple;       /**< do line stipple? */
1724a49301eSmrg      boolean point_sprite;       /**< convert points to quads for sprites? */
1734a49301eSmrg
1744a49301eSmrg      /* Temporary storage while the pipeline is being run:
1754a49301eSmrg       */
1764a49301eSmrg      char *verts;
1774a49301eSmrg      unsigned vertex_stride;
1784a49301eSmrg      unsigned vertex_count;
1794a49301eSmrg   } pipeline;
1804a49301eSmrg
1814a49301eSmrg
1824a49301eSmrg   struct vbuf_render *render;
1834a49301eSmrg
1844a49301eSmrg   /* Support prototype passthrough path:
1854a49301eSmrg    */
1864a49301eSmrg   struct {
187af69d88dSmrg      /* Current active frontend */
188af69d88dSmrg      struct draw_pt_front_end *frontend;
189af69d88dSmrg      unsigned prim;
190af69d88dSmrg      unsigned opt;     /**< bitmask of PT_x flags */
191af69d88dSmrg      unsigned eltSize; /* saved eltSize for flushing */
1927ec681f3Smrg      ubyte vertices_per_patch;
193af69d88dSmrg      boolean rebind_parameters;
194af69d88dSmrg
1954a49301eSmrg      struct {
1964a49301eSmrg         struct draw_pt_middle_end *fetch_shade_emit;
1974a49301eSmrg         struct draw_pt_middle_end *general;
1983464ebd5Sriastradh         struct draw_pt_middle_end *llvm;
1994a49301eSmrg      } middle;
2004a49301eSmrg
2014a49301eSmrg      struct {
2023464ebd5Sriastradh         struct draw_pt_front_end *vsplit;
2034a49301eSmrg      } front;
2044a49301eSmrg
2054a49301eSmrg      struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
2064a49301eSmrg      unsigned nr_vertex_buffers;
2074a49301eSmrg
2083464ebd5Sriastradh      /*
2093464ebd5Sriastradh       * This is the largest legal index value for the current set of
2103464ebd5Sriastradh       * bound vertex buffers.  Regardless of any other consideration,
2113464ebd5Sriastradh       * all vertex lookups need to be clamped to 0..max_index to
2123464ebd5Sriastradh       * prevent out-of-bound access.
2133464ebd5Sriastradh       */
2143464ebd5Sriastradh      unsigned max_index;
2153464ebd5Sriastradh
2164a49301eSmrg      struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
2174a49301eSmrg      unsigned nr_vertex_elements;
2184a49301eSmrg
2194a49301eSmrg      /* user-space vertex data, buffers */
2204a49301eSmrg      struct {
2214a49301eSmrg         /** vertex element/index buffer (ex: glDrawElements) */
2224a49301eSmrg         const void *elts;
2234a49301eSmrg         /** bytes per index (0, 1, 2 or 4) */
224af69d88dSmrg         unsigned eltSizeIB;
2254a49301eSmrg         unsigned eltSize;
226af69d88dSmrg         unsigned eltMax;
227af69d88dSmrg         int eltBias;
2284a49301eSmrg         unsigned min_index;
2294a49301eSmrg         unsigned max_index;
2307ec681f3Smrg         unsigned drawid;
2317ec681f3Smrg         bool increment_draw_id;
2327ec681f3Smrg         unsigned viewid;
2334a49301eSmrg
2344a49301eSmrg         /** vertex arrays */
235af69d88dSmrg         struct draw_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
2364a49301eSmrg
2373464ebd5Sriastradh         /** constant buffers (for vertex/geometry shader) */
238cdc920a0Smrg         const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS];
2393464ebd5Sriastradh         unsigned vs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
240cdc920a0Smrg         const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS];
2413464ebd5Sriastradh         unsigned gs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
2427ec681f3Smrg         const void *tcs_constants[PIPE_MAX_CONSTANT_BUFFERS];
2437ec681f3Smrg         unsigned tcs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
2447ec681f3Smrg         const void *tes_constants[PIPE_MAX_CONSTANT_BUFFERS];
2457ec681f3Smrg         unsigned tes_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
2467ec681f3Smrg
2477ec681f3Smrg         /** shader buffers (for vertex/geometry shader) */
2487ec681f3Smrg         const void *vs_ssbos[PIPE_MAX_SHADER_BUFFERS];
2497ec681f3Smrg         unsigned vs_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
2507ec681f3Smrg         const void *gs_ssbos[PIPE_MAX_SHADER_BUFFERS];
2517ec681f3Smrg         unsigned gs_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
2527ec681f3Smrg         const void *tcs_ssbos[PIPE_MAX_SHADER_BUFFERS];
2537ec681f3Smrg         unsigned tcs_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
2547ec681f3Smrg         const void *tes_ssbos[PIPE_MAX_SHADER_BUFFERS];
2557ec681f3Smrg         unsigned tes_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
2567ec681f3Smrg
2573464ebd5Sriastradh         /* pointer to planes */
258af69d88dSmrg         float (*planes)[DRAW_TOTAL_CLIP_PLANES][4];
2594a49301eSmrg      } user;
2604a49301eSmrg
2614a49301eSmrg      boolean test_fse;         /* enable FSE even though its not correct (eg for softpipe) */
2624a49301eSmrg      boolean no_fse;           /* disable FSE even when it is correct */
2634a49301eSmrg   } pt;
2644a49301eSmrg
2654a49301eSmrg   struct {
2663464ebd5Sriastradh      boolean bypass_clip_xy;
2673464ebd5Sriastradh      boolean bypass_clip_z;
268af69d88dSmrg      boolean guard_band_xy;
269af69d88dSmrg      boolean bypass_clip_points;
2704a49301eSmrg   } driver;
2714a49301eSmrg
272af69d88dSmrg   boolean quads_always_flatshade_last;
273af69d88dSmrg
2744a49301eSmrg   boolean flushing;         /**< debugging/sanity */
2754a49301eSmrg   boolean suspend_flushing; /**< internally set */
2763464ebd5Sriastradh
2773464ebd5Sriastradh   /* Flags set if API requires clipping in these planes and the
2783464ebd5Sriastradh    * driver doesn't indicate that it can do it for us.
2793464ebd5Sriastradh    */
2803464ebd5Sriastradh   boolean clip_xy;
2813464ebd5Sriastradh   boolean clip_z;
2823464ebd5Sriastradh   boolean clip_user;
283af69d88dSmrg   boolean guard_band_xy;
284af69d88dSmrg   boolean guard_band_points_xy;
2854a49301eSmrg
286cdc920a0Smrg   boolean dump_vs;
287cdc920a0Smrg
288af69d88dSmrg   /** Depth format and bias related settings. */
289af69d88dSmrg   boolean floating_point_depth;
2904a49301eSmrg   double mrd;  /**< minimum resolvable depth value, for polygon offset */
2914a49301eSmrg
292cdc920a0Smrg   /** Current rasterizer state given to us by the driver */
2934a49301eSmrg   const struct pipe_rasterizer_state *rasterizer;
294cdc920a0Smrg   /** Driver CSO handle for the current rasterizer state */
295cdc920a0Smrg   void *rast_handle;
296cdc920a0Smrg
297cdc920a0Smrg   /** Rasterizer CSOs without culling/stipple/etc */
2987ec681f3Smrg   void *rasterizer_no_cull[2][2][2];
299cdc920a0Smrg
300af69d88dSmrg   struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
3014a49301eSmrg   boolean identity_viewport;
30201e04c3fSmrg   boolean bypass_viewport;
3034a49301eSmrg
3043464ebd5Sriastradh   /** Vertex shader state */
3054a49301eSmrg   struct {
3064a49301eSmrg      struct draw_vertex_shader *vertex_shader;
3074a49301eSmrg      uint num_vs_outputs;  /**< convenience, from vertex_shader */
3084a49301eSmrg      uint position_output;
309cdc920a0Smrg      uint edgeflag_output;
310af69d88dSmrg      uint clipvertex_output;
31101e04c3fSmrg      uint ccdistance_output[2];
3124a49301eSmrg
313af69d88dSmrg      /** Fields for TGSI interpreter / execution */
314af69d88dSmrg      struct {
315af69d88dSmrg         struct tgsi_exec_machine *machine;
3164a49301eSmrg
317af69d88dSmrg         struct tgsi_sampler *sampler;
31801e04c3fSmrg         struct tgsi_image *image;
31901e04c3fSmrg         struct tgsi_buffer *buffer;
320af69d88dSmrg      } tgsi;
3214a49301eSmrg
3224a49301eSmrg      struct translate *fetch;
3234a49301eSmrg      struct translate_cache *fetch_cache;
3244a49301eSmrg      struct translate *emit;
3254a49301eSmrg      struct translate_cache *emit_cache;
3264a49301eSmrg   } vs;
3274a49301eSmrg
3283464ebd5Sriastradh   /** Geometry shader state */
329cdc920a0Smrg   struct {
330cdc920a0Smrg      struct draw_geometry_shader *geometry_shader;
331cdc920a0Smrg      uint num_gs_outputs;  /**< convenience, from geometry_shader */
332cdc920a0Smrg      uint position_output;
3337ec681f3Smrg      uint clipvertex_output;
334cdc920a0Smrg
335af69d88dSmrg      /** Fields for TGSI interpreter / execution */
336af69d88dSmrg      struct {
337af69d88dSmrg         struct tgsi_exec_machine *machine;
338af69d88dSmrg
339af69d88dSmrg         struct tgsi_sampler *sampler;
34001e04c3fSmrg         struct tgsi_image *image;
34101e04c3fSmrg         struct tgsi_buffer *buffer;
342af69d88dSmrg      } tgsi;
343cdc920a0Smrg
344cdc920a0Smrg   } gs;
345cdc920a0Smrg
3467ec681f3Smrg   /* Tessellation state */
3477ec681f3Smrg   struct {
3487ec681f3Smrg      struct draw_tess_ctrl_shader *tess_ctrl_shader;
3497ec681f3Smrg
3507ec681f3Smrg      /** Fields for TGSI interpreter / execution */
3517ec681f3Smrg      struct {
3527ec681f3Smrg         struct tgsi_exec_machine *machine;
3537ec681f3Smrg
3547ec681f3Smrg         struct tgsi_sampler *sampler;
3557ec681f3Smrg         struct tgsi_image *image;
3567ec681f3Smrg         struct tgsi_buffer *buffer;
3577ec681f3Smrg      } tgsi;
3587ec681f3Smrg   } tcs;
3597ec681f3Smrg
3607ec681f3Smrg   struct {
3617ec681f3Smrg      struct draw_tess_eval_shader *tess_eval_shader;
3627ec681f3Smrg      uint position_output;
3637ec681f3Smrg      uint clipvertex_output;
3647ec681f3Smrg
3657ec681f3Smrg      /** Fields for TGSI interpreter / execution */
3667ec681f3Smrg      struct {
3677ec681f3Smrg         struct tgsi_exec_machine *machine;
3687ec681f3Smrg
3697ec681f3Smrg         struct tgsi_sampler *sampler;
3707ec681f3Smrg         struct tgsi_image *image;
3717ec681f3Smrg         struct tgsi_buffer *buffer;
3727ec681f3Smrg      } tgsi;
3737ec681f3Smrg   } tes;
3747ec681f3Smrg
3753464ebd5Sriastradh   /** Fragment shader state */
3763464ebd5Sriastradh   struct {
3773464ebd5Sriastradh      struct draw_fragment_shader *fragment_shader;
3783464ebd5Sriastradh   } fs;
3793464ebd5Sriastradh
3803464ebd5Sriastradh   /** Stream output (vertex feedback) state */
3813464ebd5Sriastradh   struct {
382af69d88dSmrg      struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS];
383af69d88dSmrg      uint num_targets;
3843464ebd5Sriastradh   } so;
3853464ebd5Sriastradh
3864a49301eSmrg   /* Clip derived state:
3874a49301eSmrg    */
388af69d88dSmrg   float plane[DRAW_TOTAL_CLIP_PLANES][4];
3894a49301eSmrg
3904a49301eSmrg   /* If a prim stage introduces new vertex attributes, they'll be stored here
3914a49301eSmrg    */
3924a49301eSmrg   struct {
3933464ebd5Sriastradh      uint num;
3947ec681f3Smrg      uint semantic_name[DRAW_MAX_EXTRA_SHADER_OUTPUTS];
3957ec681f3Smrg      uint semantic_index[DRAW_MAX_EXTRA_SHADER_OUTPUTS];
3967ec681f3Smrg      uint slot[DRAW_MAX_EXTRA_SHADER_OUTPUTS];
397cdc920a0Smrg   } extra_shader_outputs;
3984a49301eSmrg
399cdc920a0Smrg   unsigned instance_id;
400af69d88dSmrg   unsigned start_instance;
401af69d88dSmrg   unsigned start_index;
4027ec681f3Smrg   unsigned constant_buffer_stride;
4033464ebd5Sriastradh   struct draw_llvm *llvm;
4043464ebd5Sriastradh
405af69d88dSmrg   /** Texture sampler and sampler view state.
406af69d88dSmrg    * Note that we have arrays indexed by shader type.  At this time
407af69d88dSmrg    * we only handle vertex and geometry shaders in the draw module, but
408af69d88dSmrg    * there may be more in the future (ex: hull and tessellation).
409af69d88dSmrg    */
410af69d88dSmrg   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
411af69d88dSmrg   unsigned num_sampler_views[PIPE_SHADER_TYPES];
412af69d88dSmrg   const struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
413af69d88dSmrg   unsigned num_samplers[PIPE_SHADER_TYPES];
414af69d88dSmrg
4157ec681f3Smrg   struct pipe_image_view *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
4167ec681f3Smrg   unsigned num_images[PIPE_SHADER_TYPES];
4177ec681f3Smrg
418af69d88dSmrg   struct pipe_query_data_pipeline_statistics statistics;
419af69d88dSmrg   boolean collect_statistics;
420af69d88dSmrg
4217ec681f3Smrg   float default_outer_tess_level[4];
4227ec681f3Smrg   float default_inner_tess_level[2];
4237ec681f3Smrg   bool collect_primgen;
4247ec681f3Smrg
425af69d88dSmrg   struct draw_assembler *ia;
4263464ebd5Sriastradh
4277ec681f3Smrg   void *disk_cache_cookie;
4287ec681f3Smrg   void (*disk_cache_find_shader)(void *cookie,
4297ec681f3Smrg                                  struct lp_cached_code *cache,
4307ec681f3Smrg                                  unsigned char ir_sha1_cache_key[20]);
4317ec681f3Smrg   void (*disk_cache_insert_shader)(void *cookie,
4327ec681f3Smrg                                    struct lp_cached_code *cache,
4337ec681f3Smrg                                    unsigned char ir_sha1_cache_key[20]);
4347ec681f3Smrg
4354a49301eSmrg   void *driver_private;
4364a49301eSmrg};
4374a49301eSmrg
4384a49301eSmrg
4393464ebd5Sriastradhstruct draw_fetch_info {
4403464ebd5Sriastradh   boolean linear;
4413464ebd5Sriastradh   unsigned start;
4423464ebd5Sriastradh   const unsigned *elts;
4433464ebd5Sriastradh   unsigned count;
4443464ebd5Sriastradh};
4453464ebd5Sriastradh
4463464ebd5Sriastradhstruct draw_vertex_info {
4473464ebd5Sriastradh   struct vertex_header *verts;
4483464ebd5Sriastradh   unsigned vertex_size;
4493464ebd5Sriastradh   unsigned stride;
4503464ebd5Sriastradh   unsigned count;
4513464ebd5Sriastradh};
4523464ebd5Sriastradh
4533464ebd5Sriastradh/* these flags are set if the primitive is a segment of a larger one */
45401e04c3fSmrg#define DRAW_SPLIT_BEFORE        0x1
45501e04c3fSmrg#define DRAW_SPLIT_AFTER         0x2
45601e04c3fSmrg#define DRAW_LINE_LOOP_AS_STRIP  0x4
4573464ebd5Sriastradh
4583464ebd5Sriastradhstruct draw_prim_info {
4593464ebd5Sriastradh   boolean linear;
4603464ebd5Sriastradh   unsigned start;
4613464ebd5Sriastradh
4623464ebd5Sriastradh   const ushort *elts;
4633464ebd5Sriastradh   unsigned count;
4643464ebd5Sriastradh
4653464ebd5Sriastradh   unsigned prim;
4663464ebd5Sriastradh   unsigned flags;
4673464ebd5Sriastradh   unsigned *primitive_lengths;
4683464ebd5Sriastradh   unsigned primitive_count;
4693464ebd5Sriastradh};
4703464ebd5Sriastradh
4713464ebd5Sriastradh
4723464ebd5Sriastradh/*******************************************************************************
4733464ebd5Sriastradh * Draw common initialization code
4743464ebd5Sriastradh */
4753464ebd5Sriastradhboolean draw_init(struct draw_context *draw);
476af69d88dSmrgvoid draw_new_instance(struct draw_context *draw);
4773464ebd5Sriastradh
4784a49301eSmrg/*******************************************************************************
4794a49301eSmrg * Vertex shader code:
4804a49301eSmrg */
4814a49301eSmrgboolean draw_vs_init( struct draw_context *draw );
4824a49301eSmrgvoid draw_vs_destroy( struct draw_context *draw );
4834a49301eSmrg
4844a49301eSmrg
485cdc920a0Smrg/*******************************************************************************
486cdc920a0Smrg * Geometry shading code:
487cdc920a0Smrg */
488cdc920a0Smrgboolean draw_gs_init( struct draw_context *draw );
489cdc920a0Smrg
4904a49301eSmrg
491cdc920a0Smrgvoid draw_gs_destroy( struct draw_context *draw );
4924a49301eSmrg
493cdc920a0Smrg/*******************************************************************************
494cdc920a0Smrg * Common shading code:
495cdc920a0Smrg */
496cdc920a0Smrguint draw_current_shader_outputs(const struct draw_context *draw);
497cdc920a0Smrguint draw_current_shader_position_output(const struct draw_context *draw);
498af69d88dSmrguint draw_current_shader_viewport_index_output(const struct draw_context *draw);
499af69d88dSmrguint draw_current_shader_clipvertex_output(const struct draw_context *draw);
50001e04c3fSmrguint draw_current_shader_ccdistance_output(const struct draw_context *draw, int index);
501af69d88dSmrguint draw_current_shader_num_written_clipdistances(const struct draw_context *draw);
502af69d88dSmrguint draw_current_shader_num_written_culldistances(const struct draw_context *draw);
5033464ebd5Sriastradhint draw_alloc_extra_vertex_attrib(struct draw_context *draw,
5043464ebd5Sriastradh                                   uint semantic_name, uint semantic_index);
5053464ebd5Sriastradhvoid draw_remove_extra_vertex_attribs(struct draw_context *draw);
506af69d88dSmrgboolean draw_current_shader_uses_viewport_index(
507af69d88dSmrg   const struct draw_context *draw);
5083464ebd5Sriastradh
5093464ebd5Sriastradh
5104a49301eSmrg/*******************************************************************************
5114a49301eSmrg * Vertex processing (was passthrough) code:
5124a49301eSmrg */
5134a49301eSmrgboolean draw_pt_init( struct draw_context *draw );
5144a49301eSmrgvoid draw_pt_destroy( struct draw_context *draw );
5154a49301eSmrgvoid draw_pt_reset_vertex_ids( struct draw_context *draw );
516af69d88dSmrgvoid draw_pt_flush( struct draw_context *draw, unsigned flags );
5174a49301eSmrg
5184a49301eSmrg
5194a49301eSmrg/*******************************************************************************
5204a49301eSmrg * Primitive processing (pipeline) code:
5214a49301eSmrg */
5224a49301eSmrg
5234a49301eSmrgboolean draw_pipeline_init( struct draw_context *draw );
5244a49301eSmrgvoid draw_pipeline_destroy( struct draw_context *draw );
5254a49301eSmrg
5264a49301eSmrg
5274a49301eSmrg
5284a49301eSmrg
5294a49301eSmrg
5303464ebd5Sriastradh/*
5313464ebd5Sriastradh * These flags are used by the pipeline when unfilled and/or line stipple modes
5323464ebd5Sriastradh * are operational.
5334a49301eSmrg */
5343464ebd5Sriastradh#define DRAW_PIPE_EDGE_FLAG_0   0x1
5353464ebd5Sriastradh#define DRAW_PIPE_EDGE_FLAG_1   0x2
5363464ebd5Sriastradh#define DRAW_PIPE_EDGE_FLAG_2   0x4
5373464ebd5Sriastradh#define DRAW_PIPE_EDGE_FLAG_ALL 0x7
5383464ebd5Sriastradh#define DRAW_PIPE_RESET_STIPPLE 0x8
5394a49301eSmrg
5404a49301eSmrgvoid draw_pipeline_run( struct draw_context *draw,
5413464ebd5Sriastradh                        const struct draw_vertex_info *vert,
5423464ebd5Sriastradh                        const struct draw_prim_info *prim);
5434a49301eSmrg
5444a49301eSmrgvoid draw_pipeline_run_linear( struct draw_context *draw,
5453464ebd5Sriastradh                               const struct draw_vertex_info *vert,
5463464ebd5Sriastradh                               const struct draw_prim_info *prim);
5473464ebd5Sriastradh
5484a49301eSmrg
5494a49301eSmrg
5504a49301eSmrg
5514a49301eSmrgvoid draw_pipeline_flush( struct draw_context *draw,
5524a49301eSmrg                          unsigned flags );
5534a49301eSmrg
5544a49301eSmrg
5554a49301eSmrg
5564a49301eSmrg/*******************************************************************************
5574a49301eSmrg * Flushing
5584a49301eSmrg */
5594a49301eSmrg
560af69d88dSmrg#define DRAW_FLUSH_PARAMETER_CHANGE 0x1  /**< Constants, viewport, etc */
561af69d88dSmrg#define DRAW_FLUSH_STATE_CHANGE     0x2  /**< Other/heavy state changes */
562af69d88dSmrg#define DRAW_FLUSH_BACKEND          0x4  /**< Flush the output buffer */
5634a49301eSmrg
5644a49301eSmrg
5654a49301eSmrgvoid draw_do_flush( struct draw_context *draw, unsigned flags );
5664a49301eSmrg
5674a49301eSmrg
5684a49301eSmrg
569cdc920a0Smrgvoid *
570cdc920a0Smrgdraw_get_rasterizer_no_cull( struct draw_context *draw,
5717ec681f3Smrg                             const struct pipe_rasterizer_state *rast );
572cdc920a0Smrg
573af69d88dSmrgvoid
574af69d88dSmrgdraw_stats_clipper_primitives(struct draw_context *draw,
575af69d88dSmrg                              const struct draw_prim_info *prim_info);
576af69d88dSmrg
57701e04c3fSmrgvoid draw_update_clip_flags(struct draw_context *draw);
57801e04c3fSmrgvoid draw_update_viewport_flags(struct draw_context *draw);
57901e04c3fSmrg
580af69d88dSmrg/**
581af69d88dSmrg * Return index i from the index buffer.
58201e04c3fSmrg * If the index buffer would overflow we return index 0.
583af69d88dSmrg */
584af69d88dSmrg#define DRAW_GET_IDX(_elts, _i)                   \
58501e04c3fSmrg   (((_i) >= draw->pt.user.eltMax) ? 0 : (_elts)[_i])
586af69d88dSmrg
587af69d88dSmrg/**
588af69d88dSmrg * Return index of the given viewport clamping it
589af69d88dSmrg * to be between 0 <= and < PIPE_MAX_VIEWPORTS
590af69d88dSmrg */
59101e04c3fSmrgstatic inline unsigned
592af69d88dSmrgdraw_clamp_viewport_idx(int idx)
593af69d88dSmrg{
594af69d88dSmrg   return ((PIPE_MAX_VIEWPORTS > idx && idx >= 0) ? idx : 0);
595af69d88dSmrg}
596af69d88dSmrg
597af69d88dSmrg/**
598af69d88dSmrg * Adds two unsigned integers and if the addition
599af69d88dSmrg * overflows then it returns the value from
60001e04c3fSmrg * the overflow_value variable.
601af69d88dSmrg */
60201e04c3fSmrgstatic inline unsigned
603af69d88dSmrgdraw_overflow_uadd(unsigned a, unsigned b,
604af69d88dSmrg                   unsigned overflow_value)
605af69d88dSmrg{
606af69d88dSmrg   unsigned res = a + b;
60701e04c3fSmrg   if (res < a) {
608af69d88dSmrg      res = overflow_value;
609af69d88dSmrg   }
610af69d88dSmrg   return res;
611af69d88dSmrg}
6124a49301eSmrg
6134a49301eSmrg#endif /* DRAW_PRIVATE_H */
614