summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw/draw_pt.c
blob: 3ec31ec25f3040875d1a29f4e61cc8dc321dab22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**************************************************************************
 * 
 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

 /*
  * Authors:
  *   Keith Whitwell <keith@tungstengraphics.com>
  */

#include "pipe/p_util.h"
#include "draw/draw_context.h"
#include "draw/draw_private.h"
#include "draw/draw_pt.h"


static boolean too_many_verts( struct draw_context *draw,
                               unsigned verts )
{
   return verts < 1024;
}

static boolean too_many_elts( struct draw_context *draw,
                              unsigned elts )
{
   return elts < (16 * 1024);
}


boolean
draw_pt_arrays(struct draw_context *draw, 
               unsigned prim,
               unsigned start, 
               unsigned count)
{
   const boolean pipeline = draw_need_pipeline(draw, prim);
   const boolean cliptest = !draw->rasterizer->bypass_clipping;
   const boolean shading  = !draw->rasterizer->bypass_vs;
   struct draw_pt_front_end *frontend = NULL;
   struct draw_pt_middle_end *middle = NULL;


   /* Overall we do:
    *     - frontend -- prepare fetch_elts, draw_elts - eg vcache
    *     - middle   -- fetch, shade, cliptest, viewport
    *     - pipeline -- the prim pipeline: clipping, wide lines, etc 
    *     - backend  -- the vbuf_render provided by the driver.
    */


#if 0
   if (!cliptest && !pipeline && !shading) {
      /* This is the 'passthrough' path:
       */
      /* Fetch user verts, emit hw verts:
       */
      middle = draw->pt.middle.fetch_emit;
   }
   else if (!cliptest && !pipeline) {
      /* Fetch user verts, run vertex shader, emit hw verts:
       */
      middle = draw->pt.middle.fetch_shade_emit;
   }
   else if (!pipeline) {
      /* Even though !pipeline, we have to run it to get clipping.  We
       * do know that the pipeline is just the clipping operation, but
       * that probably doesn't help much.
       *
       * This is going to be the most important path for a lot of
       * swtnl cards.
       */
      /* Fetch user verts, 
       *    run vertex shader, 
       *    cliptest and viewport trasform
       *    if no clipped vertices,
       *        emit hw verts
       *    else
       *        run pipline
       */
      middle = draw->pt.middle.fetch_shade_cliptest_pipeline_or_emit;
   }
   else if (!cliptest) {
      /* Fetch user verts, run vertex shader, run pipeline:
       */
      middle = draw->pt.middle.fetch_shade_pipeline;
   }
   else {
      /* This is what we're currently always doing:
       */
      /* Fetch user verts, run vertex shader, cliptest, run pipeline:
       */
      middle = draw->pt.middle.fetch_shade_cliptest_pipeline;
   }
#else
   if (cliptest || pipeline || shading)
      return FALSE;

   middle = draw->pt.middle.fetch_emit;
#endif


   /* If !pipeline, need to make sure we respect the driver's limited
    * capabilites to receive blocks of vertex data and elements.
    */
#if 0
   if (!pipeline) {
      unsigned vertex_mode = passthrough;
      unsigned nr_verts = count_vertices( draw, start, count );
      unsigned hw_prim = prim;

      if (is_elts(draw)) {
         frontend = draw->pt.front.vcache;
         hw_prim = reduced_prim(prim);
      }
      
      if (too_many_verts(nr_verts)) {
         /* if (is_verts(draw) && can_split(prim)) {
            draw = draw_arrays_split;
         }
         else */ {
            frontend = draw->pt.front.vcache;
            hw_prim = reduced_prim(prim);
         }
      }

      if (too_many_elts(count)) {

         /* if (is_elts(draw) && can_split(prim)) {
            draw = draw_elts_split;
         }
         else */ {
            frontend = draw->pt.front.vcache;
            hw_prim = reduced_prim(prim);
         }
      }

      if (!good_prim(hw_prim)) {
         draw = draw->pt.front.vcache;
      }
   }
#else
   frontend = draw->pt.front.vcache;
#endif   

   frontend->prepare( frontend, middle );

   frontend->run( frontend,
                  prim,
                  draw_pt_elt_func( draw ),
                  draw_pt_elt_ptr( draw, start ),
                  count );

   frontend->finish( frontend );

   return TRUE;
}


boolean draw_pt_init( struct draw_context *draw )
{
   draw->pt.middle.fetch_emit = draw_pt_fetch_emit( draw );
   if (!draw->pt.middle.fetch_emit)
      return FALSE;

   draw->pt.front.vcache = draw_pt_vcache();
   if (!draw->pt.front.vcache)
      return FALSE;

   return TRUE;
}


void draw_pt_destroy( struct draw_context *draw )
{
   if (draw->pt.middle.fetch_emit) {
      draw->pt.middle.fetch_emit->destroy( draw->pt.middle.fetch_emit );
      draw->pt.middle.fetch_emit = NULL;
   }

   if (draw->pt.front.vcache) {
      draw->pt.front.vcache->destroy( draw->pt.front.vcache );
      draw->pt.front.vcache = NULL;
   }
}